From: Rafał Miłecki Date: Wed, 10 Dec 2014 21:24:11 +0000 (+0000) Subject: bcm53xx: use bcma callback in SPROM driver to fill the SPROM X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=ba81966001af4ff028795b6edbf25ce49596d654;p=openwrt%2Fstaging%2Fstintel.git bcm53xx: use bcma callback in SPROM driver to fill the SPROM This is required because it has to be called at very precise moment. See comment in driver for details. Signed-off-by: Rafał Miłecki SVN-Revision: 43611 --- diff --git a/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c b/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c index e36abc8a45..4970a5b460 100644 --- a/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c +++ b/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -640,21 +641,26 @@ static int bcm47xx_sprom_getenv(const struct bcm47xx_sprom_fill *fill, return bcm47xx_nvram_getenv(name, val, val_len); }; -static int bcm47xx_sprom_probe(struct platform_device *pdev) +/* FIXME: This should not be static, but some callback argument */ +static struct platform_device *sprom_pdev = NULL; + +/* + * This function has to be called in a very precise moment. It has to be done: + * 1) After bcma registers flash cores, so we can read NVRAM. + * 2) Before any code needs SPROM content. + * + * This can be achieved only by using bcma callback. + */ +static int bcm47xx_sprom_init(struct bcma_bus *bus, struct ssb_sprom *out) { + struct platform_device *pdev = sprom_pdev; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - struct ssb_sprom *sprom; const __be32 *handle; struct device_node *nvram_node; struct platform_device *nvram_dev; struct bcm47xx_sprom_fill fill; - /* Alloc */ - sprom = devm_kzalloc(dev, sizeof(*sprom), GFP_KERNEL); - if (!sprom) - return -ENOMEM; - handle = of_get_property(np, "nvram", NULL); if (!handle) return -ENOMEM; @@ -673,11 +679,17 @@ static int bcm47xx_sprom_probe(struct platform_device *pdev) fill.getenv = bcm47xx_sprom_getenv; fill.priv = nvram_dev; - bcm47xx_sprom_fill(sprom, &fill); - - platform_set_drvdata(pdev, sprom); + bcm47xx_sprom_fill(out, &fill); return 0; +}; + +static int bcm47xx_sprom_probe(struct platform_device *pdev) +{ + /* This is the only way to make pdev accessible to the callback */ + sprom_pdev = pdev; + + return bcma_arch_register_fallback_sprom(&bcm47xx_sprom_init); } static const struct of_device_id bcm47xx_sprom_of_match_table[] = { diff --git a/target/linux/bcm53xx/patches-3.14/123-bcma-get-sprom-from-devicetree.patch b/target/linux/bcm53xx/patches-3.14/123-bcma-get-sprom-from-devicetree.patch deleted file mode 100644 index fbc75ceff3..0000000000 --- a/target/linux/bcm53xx/patches-3.14/123-bcma-get-sprom-from-devicetree.patch +++ /dev/null @@ -1,88 +0,0 @@ -From bd9106f5907080b467026bdaaea979fac8c7badb Mon Sep 17 00:00:00 2001 -From: Hauke Mehrtens -Date: Sun, 4 May 2014 14:34:31 +0200 -Subject: [PATCH 06/17] bcma: get sprom from devicetree - -This patch make it possible to device an sprom provider in device tree -and get the sprom from this driver. Every time there is such a provider -it gets asked for a sprom. - -Signed-off-by: Hauke Mehrtens ---- - drivers/bcma/sprom.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 50 insertions(+), 1 deletion(-) - ---- a/drivers/bcma/sprom.c -+++ b/drivers/bcma/sprom.c -@@ -15,6 +15,8 @@ - #include - #include - #include -+#include -+#include - - static int(*get_fallback_sprom)(struct bcma_bus *dev, struct ssb_sprom *out); - -@@ -46,6 +48,46 @@ int bcma_arch_register_fallback_sprom(in - return 0; - } - -+#ifdef CONFIG_OF -+static int bcma_fill_sprom_with_dt(struct bcma_bus *bus, -+ struct ssb_sprom *out) -+{ -+ const __be32 *handle; -+ struct device_node *sprom_node; -+ struct platform_device *sprom_dev; -+ struct ssb_sprom *sprom; -+ -+ if (!bus->host_pdev || !bus->host_pdev->dev.of_node) -+ return -ENOENT; -+ -+ handle = of_get_property(bus->host_pdev->dev.of_node, "sprom", NULL); -+ if (!handle) -+ return -ENOENT; -+ -+ sprom_node = of_find_node_by_phandle(be32_to_cpup(handle)); -+ if (!sprom_node) -+ return -ENOENT; -+ -+ sprom_dev = of_find_device_by_node(sprom_node); -+ if (!sprom_dev) -+ return -ENOENT; -+ -+ sprom = platform_get_drvdata(sprom_dev); -+ if (!sprom) -+ return -ENOENT; -+ -+ memcpy(out, sprom, sizeof(*out)); -+ -+ return 0; -+} -+#else -+static int bcma_fill_sprom_with_dt(struct bcma_bus *bus, -+ struct ssb_sprom *out) -+{ -+ return -ENOENT; -+} -+#endif -+ - static int bcma_fill_sprom_with_fallback(struct bcma_bus *bus, - struct ssb_sprom *out) - { -@@ -580,7 +622,14 @@ int bcma_sprom_get(struct bcma_bus *bus) - u16 *sprom; - size_t sprom_sizes[] = { SSB_SPROMSIZE_WORDS_R4, - SSB_SPROMSIZE_WORDS_R10, }; -- int i, err = 0; -+ int i, err; -+ -+ err = bcma_fill_sprom_with_dt(bus, &bus->sprom); -+ if (err == 0) { -+ bcma_info(bus, "Found sprom from device tree provider\n"); -+ return 0; -+ } -+ err = 0; - - if (!bus->drv_cc.core) - return -EOPNOTSUPP; diff --git a/target/linux/bcm53xx/patches-3.18/123-bcma-get-sprom-from-devicetree.patch b/target/linux/bcm53xx/patches-3.18/123-bcma-get-sprom-from-devicetree.patch deleted file mode 100644 index fbc75ceff3..0000000000 --- a/target/linux/bcm53xx/patches-3.18/123-bcma-get-sprom-from-devicetree.patch +++ /dev/null @@ -1,88 +0,0 @@ -From bd9106f5907080b467026bdaaea979fac8c7badb Mon Sep 17 00:00:00 2001 -From: Hauke Mehrtens -Date: Sun, 4 May 2014 14:34:31 +0200 -Subject: [PATCH 06/17] bcma: get sprom from devicetree - -This patch make it possible to device an sprom provider in device tree -and get the sprom from this driver. Every time there is such a provider -it gets asked for a sprom. - -Signed-off-by: Hauke Mehrtens ---- - drivers/bcma/sprom.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 50 insertions(+), 1 deletion(-) - ---- a/drivers/bcma/sprom.c -+++ b/drivers/bcma/sprom.c -@@ -15,6 +15,8 @@ - #include - #include - #include -+#include -+#include - - static int(*get_fallback_sprom)(struct bcma_bus *dev, struct ssb_sprom *out); - -@@ -46,6 +48,46 @@ int bcma_arch_register_fallback_sprom(in - return 0; - } - -+#ifdef CONFIG_OF -+static int bcma_fill_sprom_with_dt(struct bcma_bus *bus, -+ struct ssb_sprom *out) -+{ -+ const __be32 *handle; -+ struct device_node *sprom_node; -+ struct platform_device *sprom_dev; -+ struct ssb_sprom *sprom; -+ -+ if (!bus->host_pdev || !bus->host_pdev->dev.of_node) -+ return -ENOENT; -+ -+ handle = of_get_property(bus->host_pdev->dev.of_node, "sprom", NULL); -+ if (!handle) -+ return -ENOENT; -+ -+ sprom_node = of_find_node_by_phandle(be32_to_cpup(handle)); -+ if (!sprom_node) -+ return -ENOENT; -+ -+ sprom_dev = of_find_device_by_node(sprom_node); -+ if (!sprom_dev) -+ return -ENOENT; -+ -+ sprom = platform_get_drvdata(sprom_dev); -+ if (!sprom) -+ return -ENOENT; -+ -+ memcpy(out, sprom, sizeof(*out)); -+ -+ return 0; -+} -+#else -+static int bcma_fill_sprom_with_dt(struct bcma_bus *bus, -+ struct ssb_sprom *out) -+{ -+ return -ENOENT; -+} -+#endif -+ - static int bcma_fill_sprom_with_fallback(struct bcma_bus *bus, - struct ssb_sprom *out) - { -@@ -580,7 +622,14 @@ int bcma_sprom_get(struct bcma_bus *bus) - u16 *sprom; - size_t sprom_sizes[] = { SSB_SPROMSIZE_WORDS_R4, - SSB_SPROMSIZE_WORDS_R10, }; -- int i, err = 0; -+ int i, err; -+ -+ err = bcma_fill_sprom_with_dt(bus, &bus->sprom); -+ if (err == 0) { -+ bcma_info(bus, "Found sprom from device tree provider\n"); -+ return 0; -+ } -+ err = 0; - - if (!bus->drv_cc.core) - return -EOPNOTSUPP;