wifi: rt2x00: add nvmem eeprom support
PATCH 1/1 wifi: rt2x00: add nvmem eeprom support
Some embedded platforms have eeproms located in flash. Add nvmem support to handle this. Support is added for PCI and SOC backends.
Signed-off-by Rosen Penev <[email protected]>
--- .../net/wireless/ralink/rt2x00/rt2800lib.c | 31 +++++++++++++++++++ .../net/wireless/ralink/rt2x00/rt2800lib.h | 2 ++ .../net/wireless/ralink/rt2x00/rt2800pci.c | 3 ++ .../net/wireless/ralink/rt2x00/rt2800soc.c | 6 +++- 4 files changed, 41 insertions(+), 1 deletion(-)
drivers/net/wireless/ralink/rt2x00/rt2800lib.c +31 -0
@@ -24,6 +24,7 @@#include <linux/clk.h> #include <linux/crc-ccitt.h> #include <linux/module.h> +#include <linux/nvmem-consumer.h> #include "rt2x00.h" #include "rt2800lib.h"
@@ -10961,6 +10962,36 @@ int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev) }EXPORT_SYMBOL_GPL (rt2800_read_eeprom_efuse); +int rt2800_read_eeprom_nvmem (struct rt2x00_dev *rt2x00dev) +{ +struct device_node *np = rt2x00dev->dev->of_node; +unsigned int len = rt2x00dev->ops->eeprom_size; +struct nvmem_cell *cell; +const void *data; +size_t retlen; + + cell =of_nvmem_cell_get (np,"eeprom" ); +if (IS_ERR (cell)) +return PTR_ERR (cell); + + data =nvmem_cell_read (cell, &retlen); +nvmem_cell_put (cell); + +if (IS_ERR (data)) +return PTR_ERR (data); + +if (retlen != len) { +dev_err (rt2x00dev->dev,"invalid eeprom size, required: 0x%04x\n" , len); +kfree (data); +return -EINVAL ; + } + +memcpy (rt2x00dev->eeprom, data, len); +kfree (data); +return 0 ; +} +EXPORT_SYMBOL_GPL (rt2800_read_eeprom_nvmem); +static u8 rt2800_get_txmixer_gain_24g (struct rt2x00_dev *rt2x00dev) {u16 word;
drivers/net/wireless/ralink/rt2x00/rt2800lib.h +2 -0
@@ -248,6 +248,8 @@ void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);int rt2800_efuse_detect (struct rt2x00_dev *rt2x00dev);int rt2800_read_eeprom_efuse (struct rt2x00_dev *rt2x00dev); +int rt2800_read_eeprom_nvmem (struct rt2x00_dev *rt2x00dev); +int rt2800_probe_hw (struct rt2x00_dev *rt2x00dev); void rt2800_get_key_seq(struct ieee80211_hw *hw,
drivers/net/wireless/ralink/rt2x00/rt2800pci.c +3 -0
@@ -274,6 +274,9 @@ static int rt2800pci_read_eeprom(struct rt2x00_dev *rt2x00dev) {int retval; +if (!rt2800_read_eeprom_nvmem (rt2x00dev)) +return 0 ; +if (rt2800pci_efuse_detect (rt2x00dev)) retval =rt2800pci_read_eeprom_efuse (rt2x00dev);else
drivers/net/wireless/ralink/rt2x00/rt2800soc.c +5 -1
@@ -89,8 +89,12 @@ static int rt2800soc_set_device_state(struct rt2x00_dev *rt2x00dev,static int rt2800soc_read_eeprom (struct rt2x00_dev *rt2x00dev) { -void __iomem *base_addr =ioremap (0x1F040000 ,EEPROM_SIZE ); +void __iomem *base_addr; +if (!rt2800_read_eeprom_nvmem (rt2x00dev)) +return 0 ; + + base_addr =ioremap (0x1F040000 ,EEPROM_SIZE );if (!base_addr)return -ENOMEM ;
Signature · 1 line
2.51.1
Please always tag patches with the tree they should apply to (e.g. '[PATCH wireless-next]') and make sure they actually _do_ apply.
johannes
Quoted 3 lines · Johannes Berg
Please always tag patches with the tree they should apply to (e.g. '[PATCH wireless-next]') and make sure they actually _do_ apply.
That's embarrassing. Will resend with both issues fixed.
Quoted 2 lines
johannes