]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
media: move ttpci-eeprom to common
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 31 May 2021 15:05:45 +0000 (17:05 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 2 Jun 2021 09:16:15 +0000 (11:16 +0200)
The ttpci-eeprom is actually an independent driver that
doesn't depend on the stuff under drivers/media/pci/ttpci/.

Also, it is used by an USB driver (pctv452e).

So, move it to the common directory.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/common/Kconfig
drivers/media/common/Makefile
drivers/media/common/ttpci-eeprom.c [new file with mode: 0644]
drivers/media/common/ttpci-eeprom.h [new file with mode: 0644]
drivers/media/pci/ttpci/Makefile
drivers/media/pci/ttpci/ttpci-eeprom.c [deleted file]
drivers/media/pci/ttpci/ttpci-eeprom.h [deleted file]
drivers/media/usb/Kconfig
drivers/media/usb/dvb-usb/Makefile

index 4ea03b7899a8fe708f9e83fd5fbbbd9b7afc76f0..0f6bde0f793ee9ef47983676c53d858b2a96938a 100644 (file)
@@ -13,6 +13,10 @@ config VIDEO_TVEEPROM
        tristate
        depends on I2C
 
+config TTPCI_EEPROM
+        tristate
+        depends on I2C
+
 config CYPRESS_FIRMWARE
        tristate
        depends on USB
index b71e4b62eea5e6b0b8fad8c9b0b30a80d0eba8cd..55b5a1900124890c37a85bcb22b1b11a9ad5db67 100644 (file)
@@ -3,3 +3,4 @@ obj-y += b2c2/ saa7146/ siano/ v4l2-tpg/ videobuf2/
 obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
 obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
 obj-$(CONFIG_CYPRESS_FIRMWARE) += cypress_firmware.o
+obj-$(CONFIG_TTPCI_EEPROM) += ttpci-eeprom.o
diff --git a/drivers/media/common/ttpci-eeprom.c b/drivers/media/common/ttpci-eeprom.c
new file mode 100644 (file)
index 0000000..ef87466
--- /dev/null
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+    Retrieve encoded MAC address from 24C16 serial 2-wire EEPROM,
+    decode it and store it in the associated adapter struct for
+    use by dvb_net.c
+
+    This card appear to have the 24C16 write protect held to ground,
+    thus permitting normal read/write operation. Theoretically it
+    would be possible to write routines to burn a different (encoded)
+    MAC address into the EEPROM.
+
+    Robert Schlabbach  GMX
+    Michael Glaum      KVH Industries
+    Holger Waechtler   Convergence
+
+    Copyright (C) 2002-2003 Ralph Metzler <rjkm@metzlerbros.de>
+                           Metzler Brothers Systementwicklung GbR
+
+
+*/
+
+#include <asm/errno.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/i2c.h>
+#include <linux/etherdevice.h>
+
+#include "ttpci-eeprom.h"
+
+#if 1
+#define dprintk(x...) do { printk(x); } while (0)
+#else
+#define dprintk(x...) do { } while (0)
+#endif
+
+
+static int check_mac_tt(u8 *buf)
+{
+       int i;
+       u16 tmp = 0xffff;
+
+       for (i = 0; i < 8; i++) {
+               tmp  = (tmp << 8) | ((tmp >> 8) ^ buf[i]);
+               tmp ^= (tmp >> 4) & 0x0f;
+               tmp ^= (tmp << 12) ^ ((tmp & 0xff) << 5);
+       }
+       tmp ^= 0xffff;
+       return (((tmp >> 8) ^ buf[8]) | ((tmp & 0xff) ^ buf[9]));
+}
+
+static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
+{
+       u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
+                      0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
+                      0x1d, 0x36, 0x64, 0x78};
+       u8 data[20];
+       int i;
+
+       /* In case there is a sig check failure have the orig contents available */
+       memcpy(data, encodedMAC, 20);
+
+       for (i = 0; i < 20; i++)
+               data[i] ^= xor[i];
+       for (i = 0; i < 10; i++)
+               data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
+                       >> ((data[2 * i + 1] >> 6) & 3);
+
+       if (check_mac_tt(data))
+               return -ENODEV;
+
+       decodedMAC[0] = data[2]; decodedMAC[1] = data[1]; decodedMAC[2] = data[0];
+       decodedMAC[3] = data[6]; decodedMAC[4] = data[5]; decodedMAC[5] = data[4];
+       return 0;
+}
+
+int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC)
+{
+       u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
+                      0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
+                      0x1d, 0x36, 0x64, 0x78};
+       u8 data[20];
+       int i;
+
+       memcpy(data, encodedMAC, 20);
+
+       for (i = 0; i < 20; i++)
+               data[i] ^= xor[i];
+       for (i = 0; i < 10; i++)
+               data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
+                       >> ((data[2 * i + 1] >> 6) & 3);
+
+       if (check_mac_tt(data))
+               return -ENODEV;
+
+       decodedMAC[0] = data[2];
+       decodedMAC[1] = data[1];
+       decodedMAC[2] = data[0];
+       decodedMAC[3] = data[6];
+       decodedMAC[4] = data[5];
+       decodedMAC[5] = data[4];
+       return 0;
+}
+EXPORT_SYMBOL(ttpci_eeprom_decode_mac);
+
+static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encodedMAC)
+{
+       int ret;
+       u8 b0[] = { 0xcc };
+
+       struct i2c_msg msg[] = {
+               { .addr = 0x50, .flags = 0, .buf = b0, .len = 1 },
+               { .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
+       };
+
+       /* dprintk("%s\n", __func__); */
+
+       ret = i2c_transfer(adapter, msg, 2);
+
+       if (ret != 2)           /* Assume EEPROM isn't there */
+               return (-ENODEV);
+
+       return 0;
+}
+
+
+int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *proposed_mac)
+{
+       int ret;
+       u8 encodedMAC[20];
+       u8 decodedMAC[6];
+
+       ret = ttpci_eeprom_read_encodedMAC(adapter, encodedMAC);
+
+       if (ret != 0) {         /* Will only be -ENODEV */
+               dprintk("Couldn't read from EEPROM: not there?\n");
+               eth_zero_addr(proposed_mac);
+               return ret;
+       }
+
+       ret = getmac_tt(decodedMAC, encodedMAC);
+       if( ret != 0 ) {
+               dprintk("adapter failed MAC signature check\n");
+               dprintk("encoded MAC from EEPROM was %*phC",
+                       (int)sizeof(encodedMAC), &encodedMAC);
+               eth_zero_addr(proposed_mac);
+               return ret;
+       }
+
+       memcpy(proposed_mac, decodedMAC, 6);
+       dprintk("adapter has MAC addr = %pM\n", decodedMAC);
+       return 0;
+}
+
+EXPORT_SYMBOL(ttpci_eeprom_parse_mac);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, others");
+MODULE_DESCRIPTION("Decode dvb_net MAC address from EEPROM of PCI DVB cards made by Siemens, Technotrend, Hauppauge");
diff --git a/drivers/media/common/ttpci-eeprom.h b/drivers/media/common/ttpci-eeprom.h
new file mode 100644 (file)
index 0000000..ee74186
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+    Retrieve encoded MAC address from ATMEL ttpci_eeprom serial 2-wire EEPROM,
+    decode it and store it in associated adapter net device
+
+    Robert Schlabbach  GMX
+    Michael Glaum      KVH Industries
+    Holger Waechtler   Convergence
+
+
+*/
+
+#ifndef __TTPCI_EEPROM_H__
+#define __TTPCI_EEPROM_H__
+
+#include <linux/types.h>
+#include <linux/i2c.h>
+
+extern int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC);
+extern int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *propsed_mac);
+
+#endif
index 9b44c479fcdd945479e7ca49c7397f46ac49d1af..61001fa5a93e1e0621e2cca52e494958699c6cf4 100644 (file)
@@ -10,7 +10,6 @@ ifdef CONFIG_DVB_AV7110_IR
 dvb-ttpci-objs += av7110_ir.o
 endif
 
-obj-$(CONFIG_TTPCI_EEPROM) += ttpci-eeprom.o
 obj-$(CONFIG_DVB_BUDGET_CORE) += budget-core.o
 obj-$(CONFIG_DVB_BUDGET) += budget.o
 obj-$(CONFIG_DVB_BUDGET_AV) += budget-av.o
@@ -20,3 +19,4 @@ obj-$(CONFIG_DVB_AV7110) += dvb-ttpci.o
 
 ccflags-y += -I $(srctree)/drivers/media/dvb-frontends/
 ccflags-y += -I $(srctree)/drivers/media/tuners
+ccflags-y += -I $(srctree)/drivers/media/common
diff --git a/drivers/media/pci/ttpci/ttpci-eeprom.c b/drivers/media/pci/ttpci/ttpci-eeprom.c
deleted file mode 100644 (file)
index ef87466..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
-    Retrieve encoded MAC address from 24C16 serial 2-wire EEPROM,
-    decode it and store it in the associated adapter struct for
-    use by dvb_net.c
-
-    This card appear to have the 24C16 write protect held to ground,
-    thus permitting normal read/write operation. Theoretically it
-    would be possible to write routines to burn a different (encoded)
-    MAC address into the EEPROM.
-
-    Robert Schlabbach  GMX
-    Michael Glaum      KVH Industries
-    Holger Waechtler   Convergence
-
-    Copyright (C) 2002-2003 Ralph Metzler <rjkm@metzlerbros.de>
-                           Metzler Brothers Systementwicklung GbR
-
-
-*/
-
-#include <asm/errno.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/string.h>
-#include <linux/i2c.h>
-#include <linux/etherdevice.h>
-
-#include "ttpci-eeprom.h"
-
-#if 1
-#define dprintk(x...) do { printk(x); } while (0)
-#else
-#define dprintk(x...) do { } while (0)
-#endif
-
-
-static int check_mac_tt(u8 *buf)
-{
-       int i;
-       u16 tmp = 0xffff;
-
-       for (i = 0; i < 8; i++) {
-               tmp  = (tmp << 8) | ((tmp >> 8) ^ buf[i]);
-               tmp ^= (tmp >> 4) & 0x0f;
-               tmp ^= (tmp << 12) ^ ((tmp & 0xff) << 5);
-       }
-       tmp ^= 0xffff;
-       return (((tmp >> 8) ^ buf[8]) | ((tmp & 0xff) ^ buf[9]));
-}
-
-static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
-{
-       u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
-                      0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
-                      0x1d, 0x36, 0x64, 0x78};
-       u8 data[20];
-       int i;
-
-       /* In case there is a sig check failure have the orig contents available */
-       memcpy(data, encodedMAC, 20);
-
-       for (i = 0; i < 20; i++)
-               data[i] ^= xor[i];
-       for (i = 0; i < 10; i++)
-               data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
-                       >> ((data[2 * i + 1] >> 6) & 3);
-
-       if (check_mac_tt(data))
-               return -ENODEV;
-
-       decodedMAC[0] = data[2]; decodedMAC[1] = data[1]; decodedMAC[2] = data[0];
-       decodedMAC[3] = data[6]; decodedMAC[4] = data[5]; decodedMAC[5] = data[4];
-       return 0;
-}
-
-int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC)
-{
-       u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
-                      0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
-                      0x1d, 0x36, 0x64, 0x78};
-       u8 data[20];
-       int i;
-
-       memcpy(data, encodedMAC, 20);
-
-       for (i = 0; i < 20; i++)
-               data[i] ^= xor[i];
-       for (i = 0; i < 10; i++)
-               data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
-                       >> ((data[2 * i + 1] >> 6) & 3);
-
-       if (check_mac_tt(data))
-               return -ENODEV;
-
-       decodedMAC[0] = data[2];
-       decodedMAC[1] = data[1];
-       decodedMAC[2] = data[0];
-       decodedMAC[3] = data[6];
-       decodedMAC[4] = data[5];
-       decodedMAC[5] = data[4];
-       return 0;
-}
-EXPORT_SYMBOL(ttpci_eeprom_decode_mac);
-
-static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encodedMAC)
-{
-       int ret;
-       u8 b0[] = { 0xcc };
-
-       struct i2c_msg msg[] = {
-               { .addr = 0x50, .flags = 0, .buf = b0, .len = 1 },
-               { .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
-       };
-
-       /* dprintk("%s\n", __func__); */
-
-       ret = i2c_transfer(adapter, msg, 2);
-
-       if (ret != 2)           /* Assume EEPROM isn't there */
-               return (-ENODEV);
-
-       return 0;
-}
-
-
-int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *proposed_mac)
-{
-       int ret;
-       u8 encodedMAC[20];
-       u8 decodedMAC[6];
-
-       ret = ttpci_eeprom_read_encodedMAC(adapter, encodedMAC);
-
-       if (ret != 0) {         /* Will only be -ENODEV */
-               dprintk("Couldn't read from EEPROM: not there?\n");
-               eth_zero_addr(proposed_mac);
-               return ret;
-       }
-
-       ret = getmac_tt(decodedMAC, encodedMAC);
-       if( ret != 0 ) {
-               dprintk("adapter failed MAC signature check\n");
-               dprintk("encoded MAC from EEPROM was %*phC",
-                       (int)sizeof(encodedMAC), &encodedMAC);
-               eth_zero_addr(proposed_mac);
-               return ret;
-       }
-
-       memcpy(proposed_mac, decodedMAC, 6);
-       dprintk("adapter has MAC addr = %pM\n", decodedMAC);
-       return 0;
-}
-
-EXPORT_SYMBOL(ttpci_eeprom_parse_mac);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, others");
-MODULE_DESCRIPTION("Decode dvb_net MAC address from EEPROM of PCI DVB cards made by Siemens, Technotrend, Hauppauge");
diff --git a/drivers/media/pci/ttpci/ttpci-eeprom.h b/drivers/media/pci/ttpci/ttpci-eeprom.h
deleted file mode 100644 (file)
index ee74186..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
-    Retrieve encoded MAC address from ATMEL ttpci_eeprom serial 2-wire EEPROM,
-    decode it and store it in associated adapter net device
-
-    Robert Schlabbach  GMX
-    Michael Glaum      KVH Industries
-    Holger Waechtler   Convergence
-
-
-*/
-
-#ifndef __TTPCI_EEPROM_H__
-#define __TTPCI_EEPROM_H__
-
-#include <linux/types.h>
-#include <linux/i2c.h>
-
-extern int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC);
-extern int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *propsed_mac);
-
-#endif
index 00feadb217d8ca952292f8454a443cb9ac60d1ae..f97153df3c84815daf2d181d6a990242256870a2 100644 (file)
@@ -1,10 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-# This Kconfig option is also used by the legacy av7110 driver
-config TTPCI_EEPROM
-       tristate
-       depends on I2C
-
 if USB && MEDIA_SUPPORT
 
 menuconfig MEDIA_USB_SUPPORT
index 28e4806a87cd3d5290bee9be461a361a6ed0029d..c22514948db288e175e4ae67fa758fd3c7fb1f4b 100644 (file)
@@ -83,4 +83,4 @@ obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o
 ccflags-y += -I$(srctree)/drivers/media/dvb-frontends/
 # due to tuner-xc3028
 ccflags-y += -I$(srctree)/drivers/media/tuners
-ccflags-y += -I$(srctree)/drivers/media/pci/ttpci
+ccflags-y += -I$(srctree)/drivers/media/common