diff mbox

[v2] memory: omap-gpmc: use OneNAND base address from FDT

Message ID 20171008213317.iwlf65zbhcjg5b62@lenoch (mailing list archive)
State New, archived
Headers show

Commit Message

Ladislav Michl Oct. 8, 2017, 9:33 p.m. UTC
OneNAND base address from FDT is ignored, so driver only works
for bootloader configured chipselect. Make gpmc_probe_onenand_child
closer to gpmc_probe_generic_child and let it read base address from
FDT.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 Changes:
 -v2: drop resource dev_warn
      use platform_device_add_resources to pass address

 As noted previously, this is done just to make driver work,
 platform data will be removed later, once omap-onenand driver
 gets FDT support.

 arch/arm/mach-omap2/gpmc-onenand.c | 43 ++-----------------
 drivers/memory/omap-gpmc.c         | 86 ++++++++++++++++++++++++++++++++++----
 include/linux/omap-gpmc.h          |  8 +---
 3 files changed, 84 insertions(+), 53 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

kernel test robot Oct. 9, 2017, 2:24 p.m. UTC | #1
Hi Ladislav,

[auto build test WARNING on linus/master]
[also build test WARNING on v4.14-rc4 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Ladislav-Michl/memory-omap-gpmc-use-OneNAND-base-address-from-FDT/20171009-164338
config: arm-allyesconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers/memory/omap-gpmc.c: In function 'gpmc_probe':
>> drivers/memory/omap-gpmc.c:1952:3: warning: 'cs' may be used uninitialized in this function [-Wmaybe-uninitialized]
      dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/memory/omap-gpmc.c:1929:6: note: 'cs' was declared here
     u32 cs, val;
         ^~

vim +/cs +1952 drivers/memory/omap-gpmc.c

  1924	
  1925	#if IS_ENABLED(CONFIG_MTD_ONENAND)
  1926	static int gpmc_probe_onenand_child(struct platform_device *pdev,
  1927					 struct device_node *child)
  1928	{
  1929		u32 cs, val;
  1930		int ret;
  1931		unsigned long base;
  1932		struct resource res;
  1933		struct platform_device *onenand_pdev;
  1934		struct omap_onenand_platform_data *gpmc_onenand_data;
  1935	
  1936		if (of_property_read_u32(child, "reg", &val) < 0) {
  1937			dev_err(&pdev->dev, "%pOF has no 'reg' property\n",
  1938				child);
  1939			return -ENODEV;
  1940		}
  1941	
  1942		memset(&res, 0, sizeof(res));
  1943		res.flags = IORESOURCE_MEM;
  1944		if (of_address_to_resource(child, 0, &res) < 0) {
  1945			dev_err(&pdev->dev, "%pOF has malformed 'reg' property\n",
  1946				child);
  1947			return -ENODEV;
  1948		}
  1949	
  1950		ret = gpmc_cs_request(cs, resource_size(&res), &base);
  1951		if (ret < 0) {
> 1952			dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs);
  1953			return ret;
  1954		}
  1955		gpmc_cs_set_name(cs, child->name);
  1956	
  1957		/* CS must be disabled while making changes to gpmc configuration */
  1958		gpmc_cs_disable_mem(cs);
  1959	
  1960		ret = gpmc_cs_remap(cs, res.start);
  1961		if (ret < 0) {
  1962			dev_err(&pdev->dev, "cannot remap GPMC CS %d to 0x%x\n",
  1963				cs, res.start);
  1964			if (res.start < GPMC_MEM_START) {
  1965				dev_info(&pdev->dev,
  1966					 "GPMC CS %d start cannot be lesser than 0x%x\n",
  1967					 cs, GPMC_MEM_START);
  1968			} else if (res.end > GPMC_MEM_END) {
  1969				dev_info(&pdev->dev,
  1970					 "GPMC CS %d end cannot be greater than 0x%x\n",
  1971					 cs, GPMC_MEM_END);
  1972			}
  1973			return ret;
  1974		}
  1975	
  1976		/* Enable CS region */
  1977		gpmc_cs_enable_mem(cs);
  1978	
  1979		gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
  1980						 GFP_KERNEL);
  1981		if (!gpmc_onenand_data) {
  1982			ret = -ENOMEM;
  1983			goto out_free_cs;
  1984		}
  1985	
  1986		if (!of_property_read_u32(child, "dma-channel", &val))
  1987			gpmc_onenand_data->dma_channel = val;
  1988		else
  1989			gpmc_onenand_data->dma_channel = -1;
  1990	
  1991		gpmc_onenand_data->cs = cs;
  1992		gpmc_onenand_data->of_node = child;
  1993	
  1994		onenand_pdev = platform_device_alloc("omap2-onenand", cs);
  1995		if (!onenand_pdev) {
  1996			ret = -ENOMEM;
  1997			goto out_free_cs;
  1998		}
  1999	
  2000		ret = platform_device_add_resources(onenand_pdev, &res, 1);
  2001		if (ret)
  2002			goto out_free_pdev;
  2003	
  2004		onenand_pdev->dev.platform_data = gpmc_onenand_data;
  2005	
  2006		ret = platform_device_add(onenand_pdev);
  2007		if (ret)
  2008			goto out_free_pdev;
  2009	
  2010		gpmc_onenand_init(gpmc_onenand_data);
  2011	
  2012		return 0;
  2013	
  2014	out_free_pdev:
  2015		platform_device_put(onenand_pdev);
  2016	
  2017	out_free_cs:
  2018		gpmc_cs_free(cs);
  2019		return ret;
  2020	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/arch/arm/mach-omap2/gpmc-onenand.c b/arch/arm/mach-omap2/gpmc-onenand.c
index 2944af820558..c1522f412aa0 100644
--- a/arch/arm/mach-omap2/gpmc-onenand.c
+++ b/arch/arm/mach-omap2/gpmc-onenand.c
@@ -35,17 +35,6 @@  static unsigned latency;
 
 static struct omap_onenand_platform_data *gpmc_onenand_data;
 
-static struct resource gpmc_onenand_resource = {
-	.flags		= IORESOURCE_MEM,
-};
-
-static struct platform_device gpmc_onenand_device = {
-	.name		= "omap2-onenand",
-	.id		= -1,
-	.num_resources	= 1,
-	.resource	= &gpmc_onenand_resource,
-};
-
 static struct gpmc_settings onenand_async = {
 	.device_width	= GPMC_DEVWIDTH_16BIT,
 	.mux_add_data	= GPMC_MUX_AD,
@@ -348,13 +337,12 @@  static int omap2_onenand_setup_sync(void __iomem *onenand_base, int *freq_ptr)
 
 static int gpmc_onenand_setup(void __iomem *onenand_base, int *freq_ptr)
 {
-	struct device *dev = &gpmc_onenand_device.dev;
 	unsigned l = ONENAND_SYNC_READ | ONENAND_SYNC_READWRITE;
 	int ret;
 
 	ret = omap2_onenand_setup_async(onenand_base);
 	if (ret) {
-		dev_err(dev, "unable to set to async mode\n");
+		pr_err("OneNAND: unable to set to async mode\n");
 		return ret;
 	}
 
@@ -363,22 +351,18 @@  static int gpmc_onenand_setup(void __iomem *onenand_base, int *freq_ptr)
 
 	ret = omap2_onenand_setup_sync(onenand_base, freq_ptr);
 	if (ret)
-		dev_err(dev, "unable to set to sync mode\n");
+		pr_err("OneNAND: unable to set to sync mode\n");
 	return ret;
 }
 
-int gpmc_onenand_init(struct omap_onenand_platform_data *_onenand_data)
+void gpmc_onenand_init(struct omap_onenand_platform_data *_onenand_data)
 {
-	int err;
-	struct device *dev = &gpmc_onenand_device.dev;
-
 	gpmc_onenand_data = _onenand_data;
 	gpmc_onenand_data->onenand_setup = gpmc_onenand_setup;
-	gpmc_onenand_device.dev.platform_data = gpmc_onenand_data;
 
 	if (cpu_is_omap24xx() &&
 			(gpmc_onenand_data->flags & ONENAND_SYNC_READWRITE)) {
-		dev_warn(dev, "OneNAND using only SYNC_READ on 24xx\n");
+		pr_warn("OneNAND: using only SYNC_READ on 24xx\n");
 		gpmc_onenand_data->flags &= ~ONENAND_SYNC_READWRITE;
 		gpmc_onenand_data->flags |= ONENAND_SYNC_READ;
 	}
@@ -387,23 +371,4 @@  int gpmc_onenand_init(struct omap_onenand_platform_data *_onenand_data)
 		gpmc_onenand_data->flags |= ONENAND_IN_OMAP34XX;
 	else
 		gpmc_onenand_data->flags &= ~ONENAND_IN_OMAP34XX;
-
-	err = gpmc_cs_request(gpmc_onenand_data->cs, ONENAND_IO_SIZE,
-				(unsigned long *)&gpmc_onenand_resource.start);
-	if (err < 0) {
-		dev_err(dev, "Cannot request GPMC CS %d, error %d\n",
-			gpmc_onenand_data->cs, err);
-		return err;
-	}
-
-	gpmc_onenand_resource.end = gpmc_onenand_resource.start +
-							ONENAND_IO_SIZE - 1;
-
-	err = platform_device_register(&gpmc_onenand_device);
-	if (err) {
-		dev_err(dev, "Unable to register OneNAND device\n");
-		gpmc_cs_free(gpmc_onenand_data->cs);
-	}
-
-	return err;
 }
diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c
index 7059bbda2fac..16f3c068cf8c 100644
--- a/drivers/memory/omap-gpmc.c
+++ b/drivers/memory/omap-gpmc.c
@@ -1926,7 +1926,11 @@  static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
 static int gpmc_probe_onenand_child(struct platform_device *pdev,
 				 struct device_node *child)
 {
-	u32 val;
+	u32 cs, val;
+	int ret;
+	unsigned long base;
+	struct resource res;
+	struct platform_device *onenand_pdev;
 	struct omap_onenand_platform_data *gpmc_onenand_data;
 
 	if (of_property_read_u32(child, "reg", &val) < 0) {
@@ -1935,19 +1939,85 @@  static int gpmc_probe_onenand_child(struct platform_device *pdev,
 		return -ENODEV;
 	}
 
+	memset(&res, 0, sizeof(res));
+	res.flags = IORESOURCE_MEM;
+	if (of_address_to_resource(child, 0, &res) < 0) {
+		dev_err(&pdev->dev, "%pOF has malformed 'reg' property\n",
+			child);
+		return -ENODEV;
+	}
+
+	ret = gpmc_cs_request(cs, resource_size(&res), &base);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs);
+		return ret;
+	}
+	gpmc_cs_set_name(cs, child->name);
+
+	/* CS must be disabled while making changes to gpmc configuration */
+	gpmc_cs_disable_mem(cs);
+
+	ret = gpmc_cs_remap(cs, res.start);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "cannot remap GPMC CS %d to 0x%x\n",
+			cs, res.start);
+		if (res.start < GPMC_MEM_START) {
+			dev_info(&pdev->dev,
+				 "GPMC CS %d start cannot be lesser than 0x%x\n",
+				 cs, GPMC_MEM_START);
+		} else if (res.end > GPMC_MEM_END) {
+			dev_info(&pdev->dev,
+				 "GPMC CS %d end cannot be greater than 0x%x\n",
+				 cs, GPMC_MEM_END);
+		}
+		return ret;
+	}
+
+	/* Enable CS region */
+	gpmc_cs_enable_mem(cs);
+
 	gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
 					 GFP_KERNEL);
-	if (!gpmc_onenand_data)
-		return -ENOMEM;
-
-	gpmc_onenand_data->cs = val;
-	gpmc_onenand_data->of_node = child;
-	gpmc_onenand_data->dma_channel = -1;
+	if (!gpmc_onenand_data) {
+		ret = -ENOMEM;
+		goto out_free_cs;
+	}
 
 	if (!of_property_read_u32(child, "dma-channel", &val))
 		gpmc_onenand_data->dma_channel = val;
+	else
+		gpmc_onenand_data->dma_channel = -1;
+
+	gpmc_onenand_data->cs = cs;
+	gpmc_onenand_data->of_node = child;
+
+	onenand_pdev = platform_device_alloc("omap2-onenand", cs);
+	if (!onenand_pdev) {
+		ret = -ENOMEM;
+		goto out_free_cs;
+	}
+
+	ret = platform_device_add_resources(onenand_pdev, &res, 1);
+	if (ret)
+		goto out_free_pdev;
+
+	onenand_pdev->dev.platform_data = gpmc_onenand_data;
+
+	ret = platform_device_add(onenand_pdev);
+	if (ret)
+		goto out_free_pdev;
+
+	gpmc_onenand_init(gpmc_onenand_data);
+
+	return 0;
+
+out_free_pdev:
+	platform_device_put(onenand_pdev);
+
+out_free_cs:
+	gpmc_cs_free(cs);
+	return ret;
 
-	return gpmc_onenand_init(gpmc_onenand_data);
 }
 #else
 static int gpmc_probe_onenand_child(struct platform_device *pdev,
diff --git a/include/linux/omap-gpmc.h b/include/linux/omap-gpmc.h
index fd0de00c0d77..4c4d8856f443 100644
--- a/include/linux/omap-gpmc.h
+++ b/include/linux/omap-gpmc.h
@@ -77,11 +77,7 @@  struct omap_nand_platform_data;
 struct omap_onenand_platform_data;
 
 #if IS_ENABLED(CONFIG_MTD_ONENAND_OMAP2)
-extern int gpmc_onenand_init(struct omap_onenand_platform_data *d);
+extern void gpmc_onenand_init(struct omap_onenand_platform_data *d);
 #else
-#define board_onenand_data	NULL
-static inline int gpmc_onenand_init(struct omap_onenand_platform_data *d)
-{
-	return 0;
-}
+static inline void gpmc_onenand_init(struct omap_onenand_platform_data *d) { }
 #endif