* [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction
@ 2023-07-08 18:29 Christian Marangi
2023-07-08 18:29 ` [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells Christian Marangi
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Christian Marangi @ 2023-07-08 18:29 UTC (permalink / raw)
To: Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Shayne Chen,
Sean Wang, Kalle Valo, Matthias Brugger,
AngeloGioacchino Del Regno, linux-wireless, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: Christian Marangi
In preparation for NVMEM support, split get_of_eeprom() in subfunction
to tidy the code and facilitate the addition of alternative method to
get eeprom data. No behaviour change intended.
While at it also drop OF ifdef checks as OF have stubs and calling
of_get_property would result in the same error returned.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/wireless/mediatek/mt76/eeprom.c | 51 ++++++++++++++-------
1 file changed, 35 insertions(+), 16 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
index dce851d42e08..c3a762074be8 100644
--- a/drivers/net/wireless/mediatek/mt76/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
@@ -9,31 +9,35 @@
#include <linux/etherdevice.h>
#include "mt76.h"
-int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
+static int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len)
{
-#if defined(CONFIG_OF) && defined(CONFIG_MTD)
struct device_node *np = dev->dev->of_node;
- struct mtd_info *mtd;
- const __be32 *list;
const void *data;
- const char *part;
- phandle phandle;
int size;
- size_t retlen;
- int ret;
- if (!np)
+ data = of_get_property(np, "mediatek,eeprom-data", &size);
+ if (!data)
return -ENOENT;
- data = of_get_property(np, "mediatek,eeprom-data", &size);
- if (data) {
- if (size > len)
- return -EINVAL;
+ if (size > len)
+ return -EINVAL;
- memcpy(eep, data, size);
+ memcpy(eep, data, size);
- return 0;
- }
+ return 0;
+}
+
+static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len)
+{
+#ifdef CONFIG_MTD
+ struct device_node *np = dev->dev->of_node;
+ struct mtd_info *mtd;
+ const __be32 *list;
+ const char *part;
+ phandle phandle;
+ size_t retlen;
+ int size;
+ int ret;
list = of_get_property(np, "mediatek,mtd-eeprom", &size);
if (!list)
@@ -100,6 +104,21 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
return -ENOENT;
#endif
}
+
+int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
+{
+ struct device_node *np = dev->dev->of_node;
+ int ret;
+
+ if (!np)
+ return -ENOENT;
+
+ ret = mt76_get_of_eeprom_data(dev, eep, len);
+ if (!ret)
+ return 0;
+
+ return mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
+}
EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
void
--
2.40.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells
2023-07-08 18:29 [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Christian Marangi
@ 2023-07-08 18:29 ` Christian Marangi
2023-07-13 2:47 ` Daniel Golle
2023-07-28 17:45 ` Rafał Miłecki
2023-07-13 2:46 ` [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Daniel Golle
2023-07-28 17:45 ` Rafał Miłecki
2 siblings, 2 replies; 6+ messages in thread
From: Christian Marangi @ 2023-07-08 18:29 UTC (permalink / raw)
To: Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Shayne Chen,
Sean Wang, Kalle Valo, Matthias Brugger,
AngeloGioacchino Del Regno, linux-wireless, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: Christian Marangi
Add support for providing eeprom in nvmem cells by adding nvmem cell as
an alternative source for mt76_get_of_eeprom().
Nvmem cells will follow standard nvmem cell definition and needs to be
called 'eeprom' to be correctly identified.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/wireless/mediatek/mt76/eeprom.c | 38 ++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
index c3a762074be8..36564930aef1 100644
--- a/drivers/net/wireless/mediatek/mt76/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
@@ -6,6 +6,7 @@
#include <linux/of_net.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/nvmem-consumer.h>
#include <linux/etherdevice.h>
#include "mt76.h"
@@ -105,6 +106,37 @@ static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offs
#endif
}
+static int mt76_get_of_epprom_from_nvmem(struct mt76_dev *dev, void *eep, int len)
+{
+ struct device_node *np = dev->dev->of_node;
+ struct nvmem_cell *cell;
+ const void *data;
+ size_t retlen;
+ int ret = 0;
+
+ 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) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ memcpy(eep, data, len);
+
+exit:
+ kfree(data);
+
+ return ret;
+}
+
int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
{
struct device_node *np = dev->dev->of_node;
@@ -117,7 +149,11 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
if (!ret)
return 0;
- return mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
+ ret = mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
+ if (!ret)
+ return 0;
+
+ return mt76_get_of_epprom_from_nvmem(dev, eep, len);
}
EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
--
2.40.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells
2023-07-08 18:29 ` [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells Christian Marangi
@ 2023-07-13 2:47 ` Daniel Golle
2023-07-28 17:45 ` Rafał Miłecki
1 sibling, 0 replies; 6+ messages in thread
From: Daniel Golle @ 2023-07-13 2:47 UTC (permalink / raw)
To: Christian Marangi
Cc: Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Shayne Chen,
Sean Wang, Kalle Valo, Matthias Brugger,
AngeloGioacchino Del Regno, linux-wireless, linux-kernel,
linux-arm-kernel, linux-mediatek
On Sat, Jul 08, 2023 at 08:29:36PM +0200, Christian Marangi wrote:
> Add support for providing eeprom in nvmem cells by adding nvmem cell as
> an alternative source for mt76_get_of_eeprom().
>
> Nvmem cells will follow standard nvmem cell definition and needs to be
> called 'eeprom' to be correctly identified.
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
Tested-by: Daniel Golle <daniel@makrotopia.org>
> ---
> drivers/net/wireless/mediatek/mt76/eeprom.c | 38 ++++++++++++++++++++-
> 1 file changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
> index c3a762074be8..36564930aef1 100644
> --- a/drivers/net/wireless/mediatek/mt76/eeprom.c
> +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
> @@ -6,6 +6,7 @@
> #include <linux/of_net.h>
> #include <linux/mtd/mtd.h>
> #include <linux/mtd/partitions.h>
> +#include <linux/nvmem-consumer.h>
> #include <linux/etherdevice.h>
> #include "mt76.h"
>
> @@ -105,6 +106,37 @@ static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offs
> #endif
> }
>
> +static int mt76_get_of_epprom_from_nvmem(struct mt76_dev *dev, void *eep, int len)
> +{
> + struct device_node *np = dev->dev->of_node;
> + struct nvmem_cell *cell;
> + const void *data;
> + size_t retlen;
> + int ret = 0;
> +
> + 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) {
> + ret = -EINVAL;
> + goto exit;
> + }
> +
> + memcpy(eep, data, len);
> +
> +exit:
> + kfree(data);
> +
> + return ret;
> +}
> +
> int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
> {
> struct device_node *np = dev->dev->of_node;
> @@ -117,7 +149,11 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
> if (!ret)
> return 0;
>
> - return mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
> + ret = mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
> + if (!ret)
> + return 0;
> +
> + return mt76_get_of_epprom_from_nvmem(dev, eep, len);
> }
> EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
>
> --
> 2.40.1
>
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells
2023-07-08 18:29 ` [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells Christian Marangi
2023-07-13 2:47 ` Daniel Golle
@ 2023-07-28 17:45 ` Rafał Miłecki
1 sibling, 0 replies; 6+ messages in thread
From: Rafał Miłecki @ 2023-07-28 17:45 UTC (permalink / raw)
To: Christian Marangi, Felix Fietkau, Lorenzo Bianconi, Ryder Lee,
Shayne Chen, Sean Wang, Kalle Valo, Matthias Brugger,
AngeloGioacchino Del Regno, linux-wireless, linux-kernel,
linux-arm-kernel, linux-mediatek
On 8.07.2023 20:29, Christian Marangi wrote:
> Add support for providing eeprom in nvmem cells by adding nvmem cell as
> an alternative source for mt76_get_of_eeprom().
>
> Nvmem cells will follow standard nvmem cell definition and needs to be
> called 'eeprom' to be correctly identified.
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Rafał Miłecki <rafal@milecki.pl>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction
2023-07-08 18:29 [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Christian Marangi
2023-07-08 18:29 ` [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells Christian Marangi
@ 2023-07-13 2:46 ` Daniel Golle
2023-07-28 17:45 ` Rafał Miłecki
2 siblings, 0 replies; 6+ messages in thread
From: Daniel Golle @ 2023-07-13 2:46 UTC (permalink / raw)
To: Christian Marangi
Cc: Felix Fietkau, Lorenzo Bianconi, Ryder Lee, Shayne Chen,
Sean Wang, Kalle Valo, Matthias Brugger,
AngeloGioacchino Del Regno, linux-wireless, linux-kernel,
linux-arm-kernel, linux-mediatek
On Sat, Jul 08, 2023 at 08:29:35PM +0200, Christian Marangi wrote:
> In preparation for NVMEM support, split get_of_eeprom() in subfunction
> to tidy the code and facilitate the addition of alternative method to
> get eeprom data. No behaviour change intended.
>
> While at it also drop OF ifdef checks as OF have stubs and calling
> of_get_property would result in the same error returned.
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
Tested-by: Daniel Golle <daniel@makrotopia.org>
> ---
> drivers/net/wireless/mediatek/mt76/eeprom.c | 51 ++++++++++++++-------
> 1 file changed, 35 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
> index dce851d42e08..c3a762074be8 100644
> --- a/drivers/net/wireless/mediatek/mt76/eeprom.c
> +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
> @@ -9,31 +9,35 @@
> #include <linux/etherdevice.h>
> #include "mt76.h"
>
> -int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
> +static int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len)
> {
> -#if defined(CONFIG_OF) && defined(CONFIG_MTD)
> struct device_node *np = dev->dev->of_node;
> - struct mtd_info *mtd;
> - const __be32 *list;
> const void *data;
> - const char *part;
> - phandle phandle;
> int size;
> - size_t retlen;
> - int ret;
>
> - if (!np)
> + data = of_get_property(np, "mediatek,eeprom-data", &size);
> + if (!data)
> return -ENOENT;
>
> - data = of_get_property(np, "mediatek,eeprom-data", &size);
> - if (data) {
> - if (size > len)
> - return -EINVAL;
> + if (size > len)
> + return -EINVAL;
>
> - memcpy(eep, data, size);
> + memcpy(eep, data, size);
>
> - return 0;
> - }
> + return 0;
> +}
> +
> +static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len)
> +{
> +#ifdef CONFIG_MTD
> + struct device_node *np = dev->dev->of_node;
> + struct mtd_info *mtd;
> + const __be32 *list;
> + const char *part;
> + phandle phandle;
> + size_t retlen;
> + int size;
> + int ret;
>
> list = of_get_property(np, "mediatek,mtd-eeprom", &size);
> if (!list)
> @@ -100,6 +104,21 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
> return -ENOENT;
> #endif
> }
> +
> +int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
> +{
> + struct device_node *np = dev->dev->of_node;
> + int ret;
> +
> + if (!np)
> + return -ENOENT;
> +
> + ret = mt76_get_of_eeprom_data(dev, eep, len);
> + if (!ret)
> + return 0;
> +
> + return mt76_get_of_epprom_from_mtd(dev, eep, offset, len);
> +}
> EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
>
> void
> --
> 2.40.1
>
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction
2023-07-08 18:29 [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Christian Marangi
2023-07-08 18:29 ` [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells Christian Marangi
2023-07-13 2:46 ` [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Daniel Golle
@ 2023-07-28 17:45 ` Rafał Miłecki
2 siblings, 0 replies; 6+ messages in thread
From: Rafał Miłecki @ 2023-07-28 17:45 UTC (permalink / raw)
To: Christian Marangi, Felix Fietkau, Lorenzo Bianconi, Ryder Lee,
Shayne Chen, Sean Wang, Kalle Valo, Matthias Brugger,
AngeloGioacchino Del Regno, linux-wireless, linux-kernel,
linux-arm-kernel, linux-mediatek
On 8.07.2023 20:29, Christian Marangi wrote:
> In preparation for NVMEM support, split get_of_eeprom() in subfunction
> to tidy the code and facilitate the addition of alternative method to
> get eeprom data. No behaviour change intended.
>
> While at it also drop OF ifdef checks as OF have stubs and calling
> of_get_property would result in the same error returned.
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Rafał Miłecki <rafal@milecki.pl>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-28 17:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-08 18:29 [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Christian Marangi
2023-07-08 18:29 ` [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells Christian Marangi
2023-07-13 2:47 ` Daniel Golle
2023-07-28 17:45 ` Rafał Miłecki
2023-07-13 2:46 ` [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Daniel Golle
2023-07-28 17:45 ` Rafał Miłecki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).