rt2x00: Remove debugfs CSR access wrappers
authorIvo van Doorn <ivdoorn@gmail.com>
Wed, 29 Oct 2008 18:41:03 +0000 (19:41 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 10 Nov 2008 20:17:35 +0000 (15:17 -0500)
Move calculation of CSR register offset into rt2x00debug.c
and remove the wrapper functions from each individual driver.
(Except rt2500usb, which still needs to wrap for the
different value type argument).

Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
13 files changed:
drivers/net/wireless/rt2x00/rt2400pci.c
drivers/net/wireless/rt2x00/rt2400pci.h
drivers/net/wireless/rt2x00/rt2500pci.c
drivers/net/wireless/rt2x00/rt2500pci.h
drivers/net/wireless/rt2x00/rt2500usb.c
drivers/net/wireless/rt2x00/rt2500usb.h
drivers/net/wireless/rt2x00/rt2x00debug.c
drivers/net/wireless/rt2x00/rt2x00debug.h
drivers/net/wireless/rt2x00/rt2x00pci.h
drivers/net/wireless/rt2x00/rt61pci.c
drivers/net/wireless/rt2x00/rt61pci.h
drivers/net/wireless/rt2x00/rt73usb.c
drivers/net/wireless/rt2x00/rt73usb.h

index e1891ebe5e5c197929dbec13ad277dbfa632ea48..42bd38ac7a1db249b3a309d3ec6d89550e3f9c6b 100644 (file)
@@ -188,43 +188,34 @@ static void rt2400pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
 }
 
 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
-#define CSR_OFFSET(__word)     ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
-
-static void rt2400pci_read_csr(struct rt2x00_dev *rt2x00dev,
-                              const unsigned int word, u32 *data)
-{
-       rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
-}
-
-static void rt2400pci_write_csr(struct rt2x00_dev *rt2x00dev,
-                               const unsigned int word, u32 data)
-{
-       rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
-}
-
 static const struct rt2x00debug rt2400pci_rt2x00debug = {
        .owner  = THIS_MODULE,
        .csr    = {
-               .read           = rt2400pci_read_csr,
-               .write          = rt2400pci_write_csr,
+               .read           = rt2x00pci_register_read,
+               .write          = rt2x00pci_register_write,
+               .flags          = RT2X00DEBUGFS_OFFSET,
+               .word_base      = CSR_REG_BASE,
                .word_size      = sizeof(u32),
                .word_count     = CSR_REG_SIZE / sizeof(u32),
        },
        .eeprom = {
                .read           = rt2x00_eeprom_read,
                .write          = rt2x00_eeprom_write,
+               .word_base      = EEPROM_BASE,
                .word_size      = sizeof(u16),
                .word_count     = EEPROM_SIZE / sizeof(u16),
        },
        .bbp    = {
                .read           = rt2400pci_bbp_read,
                .write          = rt2400pci_bbp_write,
+               .word_base      = BBP_BASE,
                .word_size      = sizeof(u8),
                .word_count     = BBP_SIZE / sizeof(u8),
        },
        .rf     = {
                .read           = rt2x00_rf_read,
                .write          = rt2400pci_rf_write,
+               .word_base      = RF_BASE,
                .word_size      = sizeof(u32),
                .word_count     = RF_SIZE / sizeof(u32),
        },
index bbff381ce3963d11e28b9b261c5c44ab88d3da5b..9aefda4ab3c263c4163543fff32a7853b8139ec8 100644 (file)
@@ -46,7 +46,9 @@
 #define CSR_REG_SIZE                   0x014c
 #define EEPROM_BASE                    0x0000
 #define EEPROM_SIZE                    0x0100
+#define BBP_BASE                       0x0000
 #define BBP_SIZE                       0x0020
+#define RF_BASE                                0x0000
 #define RF_SIZE                                0x0010
 
 /*
index 66a94c2f1b3c7b0667024b4ab6dfcd002a4a4a04..928452f30c25d53fdff254a6a2f5a740822ed22b 100644 (file)
@@ -188,43 +188,34 @@ static void rt2500pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
 }
 
 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
-#define CSR_OFFSET(__word)     ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
-
-static void rt2500pci_read_csr(struct rt2x00_dev *rt2x00dev,
-                              const unsigned int word, u32 *data)
-{
-       rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
-}
-
-static void rt2500pci_write_csr(struct rt2x00_dev *rt2x00dev,
-                               const unsigned int word, u32 data)
-{
-       rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
-}
-
 static const struct rt2x00debug rt2500pci_rt2x00debug = {
        .owner  = THIS_MODULE,
        .csr    = {
-               .read           = rt2500pci_read_csr,
-               .write          = rt2500pci_write_csr,
+               .read           = rt2x00pci_register_read,
+               .write          = rt2x00pci_register_write,
+               .flags          = RT2X00DEBUGFS_OFFSET,
+               .word_base      = CSR_REG_BASE,
                .word_size      = sizeof(u32),
                .word_count     = CSR_REG_SIZE / sizeof(u32),
        },
        .eeprom = {
                .read           = rt2x00_eeprom_read,
                .write          = rt2x00_eeprom_write,
+               .word_base      = EEPROM_BASE,
                .word_size      = sizeof(u16),
                .word_count     = EEPROM_SIZE / sizeof(u16),
        },
        .bbp    = {
                .read           = rt2500pci_bbp_read,
                .write          = rt2500pci_bbp_write,
+               .word_base      = BBP_BASE,
                .word_size      = sizeof(u8),
                .word_count     = BBP_SIZE / sizeof(u8),
        },
        .rf     = {
                .read           = rt2x00_rf_read,
                .write          = rt2500pci_rf_write,
+               .word_base      = RF_BASE,
                .word_size      = sizeof(u32),
                .word_count     = RF_SIZE / sizeof(u32),
        },
index 8c26bef6cf49cc23d0eecafe635e20f93b89f052..e135247f7f89d6aae25fefc4bdb7673e54bfc706 100644 (file)
@@ -57,7 +57,9 @@
 #define CSR_REG_SIZE                   0x0174
 #define EEPROM_BASE                    0x0000
 #define EEPROM_SIZE                    0x0200
+#define BBP_BASE                       0x0000
 #define BBP_SIZE                       0x0040
+#define RF_BASE                                0x0000
 #define RF_SIZE                                0x0014
 
 /*
index 19970de9463910889ac7a63535566575b08a9e3a..639d5a2f84e241de460aba6babe686d71355b899 100644 (file)
@@ -245,43 +245,48 @@ rf_write:
 }
 
 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
-#define CSR_OFFSET(__word)     ( CSR_REG_BASE + ((__word) * sizeof(u16)) )
-
-static void rt2500usb_read_csr(struct rt2x00_dev *rt2x00dev,
-                              const unsigned int word, u32 *data)
+static void _rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
+                                    const unsigned int offset,
+                                    u32 *value)
 {
-       rt2500usb_register_read(rt2x00dev, CSR_OFFSET(word), (u16 *) data);
+       rt2500usb_register_read(rt2x00dev, offset, (u16 *)value);
 }
 
-static void rt2500usb_write_csr(struct rt2x00_dev *rt2x00dev,
-                               const unsigned int word, u32 data)
+static void _rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
+                                     const unsigned int offset,
+                                     u32 value)
 {
-       rt2500usb_register_write(rt2x00dev, CSR_OFFSET(word), data);
+       rt2500usb_register_write(rt2x00dev, offset, value);
 }
 
 static const struct rt2x00debug rt2500usb_rt2x00debug = {
        .owner  = THIS_MODULE,
        .csr    = {
-               .read           = rt2500usb_read_csr,
-               .write          = rt2500usb_write_csr,
+               .read           = _rt2500usb_register_read,
+               .write          = _rt2500usb_register_write,
+               .flags          = RT2X00DEBUGFS_OFFSET,
+               .word_base      = CSR_REG_BASE,
                .word_size      = sizeof(u16),
                .word_count     = CSR_REG_SIZE / sizeof(u16),
        },
        .eeprom = {
                .read           = rt2x00_eeprom_read,
                .write          = rt2x00_eeprom_write,
+               .word_base      = EEPROM_BASE,
                .word_size      = sizeof(u16),
                .word_count     = EEPROM_SIZE / sizeof(u16),
        },
        .bbp    = {
                .read           = rt2500usb_bbp_read,
                .write          = rt2500usb_bbp_write,
+               .word_base      = BBP_BASE,
                .word_size      = sizeof(u8),
                .word_count     = BBP_SIZE / sizeof(u8),
        },
        .rf     = {
                .read           = rt2x00_rf_read,
                .write          = rt2500usb_rf_write,
+               .word_base      = RF_BASE,
                .word_size      = sizeof(u32),
                .word_count     = RF_SIZE / sizeof(u32),
        },
index 89e5ed24e4f7906a95ae0feaacc992e022840e34..dbb5d689e23dd6dc9f13382149e32ab5b2cace87 100644 (file)
@@ -57,7 +57,9 @@
 #define CSR_REG_SIZE                   0x0100
 #define EEPROM_BASE                    0x0000
 #define EEPROM_SIZE                    0x006a
+#define BBP_BASE                       0x0000
 #define BBP_SIZE                       0x0060
+#define RF_BASE                                0x0000
 #define RF_SIZE                                0x0014
 
 /*
index a31418a700c1f6de6e6fe958ed4c48f0cdc43c53..54dd10060bf1a56a8b318ee5e135463b796cc358 100644 (file)
@@ -424,16 +424,21 @@ static ssize_t rt2x00debug_read_##__name(struct file *file,       \
        const struct rt2x00debug *debug = intf->debug;          \
        char line[16];                                          \
        size_t size;                                            \
+       unsigned int index = intf->offset_##__name;             \
        __type value;                                           \
                                                                \
        if (*offset)                                            \
                return 0;                                       \
                                                                \
-       if (intf->offset_##__name >= debug->__name.word_count)  \
+       if (index >= debug->__name.word_count)                  \
                return -EINVAL;                                 \
                                                                \
-       debug->__name.read(intf->rt2x00dev,                     \
-                          intf->offset_##__name, &value);      \
+       if (debug->__name.flags & RT2X00DEBUGFS_OFFSET)         \
+               index *= debug->__name.word_size;               \
+                                                               \
+       index += debug->__name.word_base;                       \
+                                                               \
+       debug->__name.read(intf->rt2x00dev, index, &value);     \
                                                                \
        size = sprintf(line, __format, value);                  \
                                                                \
@@ -454,12 +459,13 @@ static ssize_t rt2x00debug_write_##__name(struct file *file,      \
        const struct rt2x00debug *debug = intf->debug;          \
        char line[16];                                          \
        size_t size;                                            \
+       unsigned int index = intf->offset_##__name;             \
        __type value;                                           \
                                                                \
        if (*offset)                                            \
                return 0;                                       \
                                                                \
-       if (intf->offset_##__name >= debug->__name.word_count)  \
+       if (index >= debug->__name.word_count)                  \
                return -EINVAL;                                 \
                                                                \
        if (copy_from_user(line, buf, length))                  \
@@ -468,8 +474,12 @@ static ssize_t rt2x00debug_write_##__name(struct file *file,       \
        size = strlen(line);                                    \
        value = simple_strtoul(line, NULL, 0);                  \
                                                                \
-       debug->__name.write(intf->rt2x00dev,                    \
-                           intf->offset_##__name, value);      \
+       if (debug->__name.flags & RT2X00DEBUGFS_OFFSET)         \
+               index *= debug->__name.word_size;               \
+                                                               \
+       index += debug->__name.word_base;                       \
+                                                               \
+       debug->__name.write(intf->rt2x00dev, index, value);     \
                                                                \
        *offset += size;                                        \
        return size;                                            \
index c4ce895aa1c70776100b66536fe54064d2368125..a92104dfee9a6836d90b7ee2270b3c407fc873e8 100644 (file)
 
 struct rt2x00_dev;
 
+/**
+ * enum rt2x00debugfs_entry_flags: Flags for debugfs registry entry
+ *
+ * @RT2X00DEBUGFS_OFFSET: rt2x00lib should pass the register offset
+ *     as argument when using the callback function read()/write()
+ */
+enum rt2x00debugfs_entry_flags {
+       RT2X00DEBUGFS_OFFSET    = (1 << 0),
+};
+
 #define RT2X00DEBUGFS_REGISTER_ENTRY(__name, __type)           \
 struct reg##__name {                                           \
        void (*read)(struct rt2x00_dev *rt2x00dev,              \
@@ -35,6 +45,9 @@ struct reg##__name {                                          \
        void (*write)(struct rt2x00_dev *rt2x00dev,             \
                      const unsigned int word, __type data);    \
                                                                \
+       unsigned int flags;                                     \
+                                                               \
+       unsigned int word_base;                                 \
        unsigned int word_size;                                 \
        unsigned int word_count;                                \
 } __name
index 80bf97c03e2d159395f46d9933db3be0275948c8..a83f45f784f28274fa7664e8bcb1d303a27357a0 100644 (file)
@@ -58,7 +58,7 @@
  * Register access.
  */
 static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev,
-                                          const unsigned long offset,
+                                          const unsigned int offset,
                                           u32 *value)
 {
        *value = readl(rt2x00dev->csr.base + offset);
@@ -66,14 +66,14 @@ static inline void rt2x00pci_register_read(struct rt2x00_dev *rt2x00dev,
 
 static inline void
 rt2x00pci_register_multiread(struct rt2x00_dev *rt2x00dev,
-                            const unsigned long offset,
+                            const unsigned int offset,
                             void *value, const u16 length)
 {
        memcpy_fromio(value, rt2x00dev->csr.base + offset, length);
 }
 
 static inline void rt2x00pci_register_write(struct rt2x00_dev *rt2x00dev,
-                                           const unsigned long offset,
+                                           const unsigned int offset,
                                            u32 value)
 {
        writel(value, rt2x00dev->csr.base + offset);
@@ -81,7 +81,7 @@ static inline void rt2x00pci_register_write(struct rt2x00_dev *rt2x00dev,
 
 static inline void
 rt2x00pci_register_multiwrite(struct rt2x00_dev *rt2x00dev,
-                             const unsigned long offset,
+                             const unsigned int offset,
                              const void *value, const u16 length)
 {
        memcpy_toio(rt2x00dev->csr.base + offset, value, length);
index bd4a6e1ec9ddcca1e8041f04a9c2733b6e15d1d9..3f272793412a6d8bc47f093af8ca5d5c40d01bfe 100644 (file)
@@ -228,43 +228,34 @@ static void rt61pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
 }
 
 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
-#define CSR_OFFSET(__word)     ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
-
-static void rt61pci_read_csr(struct rt2x00_dev *rt2x00dev,
-                            const unsigned int word, u32 *data)
-{
-       rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
-}
-
-static void rt61pci_write_csr(struct rt2x00_dev *rt2x00dev,
-                             const unsigned int word, u32 data)
-{
-       rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
-}
-
 static const struct rt2x00debug rt61pci_rt2x00debug = {
        .owner  = THIS_MODULE,
        .csr    = {
-               .read           = rt61pci_read_csr,
-               .write          = rt61pci_write_csr,
+               .read           = rt2x00pci_register_read,
+               .write          = rt2x00pci_register_write,
+               .flags          = RT2X00DEBUGFS_OFFSET,
+               .word_base      = CSR_REG_BASE,
                .word_size      = sizeof(u32),
                .word_count     = CSR_REG_SIZE / sizeof(u32),
        },
        .eeprom = {
                .read           = rt2x00_eeprom_read,
                .write          = rt2x00_eeprom_write,
+               .word_base      = EEPROM_BASE,
                .word_size      = sizeof(u16),
                .word_count     = EEPROM_SIZE / sizeof(u16),
        },
        .bbp    = {
                .read           = rt61pci_bbp_read,
                .write          = rt61pci_bbp_write,
+               .word_base      = BBP_BASE,
                .word_size      = sizeof(u8),
                .word_count     = BBP_SIZE / sizeof(u8),
        },
        .rf     = {
                .read           = rt2x00_rf_read,
                .write          = rt61pci_rf_write,
+               .word_base      = RF_BASE,
                .word_size      = sizeof(u32),
                .word_count     = RF_SIZE / sizeof(u32),
        },
index 8ec1451308ccea2700ce05e03f0be2229a3c2779..65fe3332364aa8cb414793ec0f0a057e40038252 100644 (file)
@@ -48,7 +48,9 @@
 #define CSR_REG_SIZE                   0x04b0
 #define EEPROM_BASE                    0x0000
 #define EEPROM_SIZE                    0x0100
+#define BBP_BASE                       0x0000
 #define BBP_SIZE                       0x0080
+#define RF_BASE                                0x0000
 #define RF_SIZE                                0x0014
 
 /*
index 5be49ed4ecf91bf6d58a2c0ba0858a879689d36d..767e3c98184c2a8e62f8047471af21be5a31d78a 100644 (file)
@@ -249,43 +249,34 @@ rf_write:
 }
 
 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
-#define CSR_OFFSET(__word)     ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
-
-static void rt73usb_read_csr(struct rt2x00_dev *rt2x00dev,
-                            const unsigned int word, u32 *data)
-{
-       rt73usb_register_read(rt2x00dev, CSR_OFFSET(word), data);
-}
-
-static void rt73usb_write_csr(struct rt2x00_dev *rt2x00dev,
-                             const unsigned int word, u32 data)
-{
-       rt73usb_register_write(rt2x00dev, CSR_OFFSET(word), data);
-}
-
 static const struct rt2x00debug rt73usb_rt2x00debug = {
        .owner  = THIS_MODULE,
        .csr    = {
-               .read           = rt73usb_read_csr,
-               .write          = rt73usb_write_csr,
+               .read           = rt73usb_register_read,
+               .write          = rt73usb_register_write,
+               .flags          = RT2X00DEBUGFS_OFFSET,
+               .word_base      = CSR_REG_BASE,
                .word_size      = sizeof(u32),
                .word_count     = CSR_REG_SIZE / sizeof(u32),
        },
        .eeprom = {
                .read           = rt2x00_eeprom_read,
                .write          = rt2x00_eeprom_write,
+               .word_base      = EEPROM_BASE,
                .word_size      = sizeof(u16),
                .word_count     = EEPROM_SIZE / sizeof(u16),
        },
        .bbp    = {
                .read           = rt73usb_bbp_read,
                .write          = rt73usb_bbp_write,
+               .word_base      = BBP_BASE,
                .word_size      = sizeof(u8),
                .word_count     = BBP_SIZE / sizeof(u8),
        },
        .rf     = {
                .read           = rt2x00_rf_read,
                .write          = rt73usb_rf_write,
+               .word_base      = RF_BASE,
                .word_size      = sizeof(u32),
                .word_count     = RF_SIZE / sizeof(u32),
        },
index 868386c457f65c39c4e15d11ef92cefbebb534a4..46e1405eb0e21ae7d643e5b6d17a011101199d30 100644 (file)
@@ -48,7 +48,9 @@
 #define CSR_REG_SIZE                   0x04b0
 #define EEPROM_BASE                    0x0000
 #define EEPROM_SIZE                    0x0100
+#define BBP_BASE                       0x0000
 #define BBP_SIZE                       0x0080
+#define RF_BASE                                0x0000
 #define RF_SIZE                                0x0014
 
 /*