From patchwork Sat Feb 11 13:03:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 9567977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4227D60572 for ; Sat, 11 Feb 2017 13:03:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 314031FF1E for ; Sat, 11 Feb 2017 13:03:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2631E28467; Sat, 11 Feb 2017 13:03:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7703D1FF1E for ; Sat, 11 Feb 2017 13:03:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753435AbdBKND0 (ORCPT ); Sat, 11 Feb 2017 08:03:26 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:52408 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753198AbdBKND0 (ORCPT ); Sat, 11 Feb 2017 08:03:26 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992136AbdBKNDZGFc6p (ORCPT ); Sat, 11 Feb 2017 14:03:25 +0100 Date: Sat, 11 Feb 2017 14:03:24 +0100 From: Ladislav Michl To: Roger Quadros Cc: Tony Lindgren , linux-omap@vger.kernel.org, Javier Martinez Canillas , Enrico Butera , Eduard Gavin , Enric Balletbo i Serra , =?iso-8859-2?Q?Agust=ED?= Fontquerni Subject: [PATCH 4/4] memory: omap-gpmc: honour OneNAND base address from FDT Message-ID: <20170211130324.m3tb2e4dnyo7pktt@lenoch> References: <20160814084313.GA699@localhost.localdomain> <9706512a-a5ad-17c7-0867-4f592529fc8a@ti.com> <20160816185043.GA12255@localhost.localdomain> <20160817144922.3jwrwj67qjdsa2n7@atomide.com> <31d58234-8f57-b988-689a-bbcf6f56cb68@ti.com> <20170211125916.inojzppkuvsees2r@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170211125916.inojzppkuvsees2r@lenoch> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP OneNAND base address from FDT is ignored, so driver only works for bootloader configured chipselect. Bring gpmc_probe_onenand_child closer to gpmc_probe_generic_child to honour FDT configured base address and to make future merge with gpmc_probe_generic_child easier. Signed-off-by: Ladislav Michl --- arch/arm/mach-omap2/gpmc-onenand.c | 52 ++++++++++++------------- drivers/memory/omap-gpmc.c | 48 +++++++++++++++++++++-- include/linux/platform_data/mtd-onenand-omap2.h | 1 + 3 files changed, 70 insertions(+), 31 deletions(-) diff --git a/arch/arm/mach-omap2/gpmc-onenand.c b/arch/arm/mach-omap2/gpmc-onenand.c index 2944af820558..3dd7db3a2b46 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,21 @@ 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) { int err; - struct device *dev = &gpmc_onenand_device.dev; + struct platform_device *pdev; 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; } @@ -388,22 +375,31 @@ int gpmc_onenand_init(struct omap_onenand_platform_data *_onenand_data) 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; + pdev = platform_device_alloc("omap2-onenand", gpmc_onenand_data->cs); + if (!pdev) { + err = -ENOMEM; + goto out_free_cs; } - gpmc_onenand_resource.end = gpmc_onenand_resource.start + - ONENAND_IO_SIZE - 1; + err = platform_device_add_resources(pdev, + gpmc_onenand_data->resource, 1); + if (err) + goto out_free_pdev; - err = platform_device_register(&gpmc_onenand_device); + pdev->dev.platform_data = gpmc_onenand_data; + + err = platform_device_add(pdev); if (err) { - dev_err(dev, "Unable to register OneNAND device\n"); - gpmc_cs_free(gpmc_onenand_data->cs); + dev_err(&pdev->dev, "Unable to register OneNAND device\n"); + goto out_free_pdev; } + return 0; + +out_free_pdev: + platform_device_put(pdev); +out_free_cs: + gpmc_cs_free(gpmc_onenand_data->cs); + return err; } diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c index bf0fe0137dfe..725fceb2146a 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c @@ -1926,21 +1926,63 @@ 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 omap_onenand_platform_data *gpmc_onenand_data; - if (of_property_read_u32(child, "reg", &val) < 0) { + if (of_property_read_u32(child, "reg", &cs) < 0) { dev_err(&pdev->dev, "%s has no 'reg' property\n", child->full_name); return -ENODEV; } + memset(&res, 0, sizeof(res)); + res.flags = IORESOURCE_MEM; + if (of_address_to_resource(child, 0, &res) < 0) { + dev_err(&pdev->dev, "%s has malformed 'reg' property\n", + child->full_name); + 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); + + dev_warn(&pdev->dev, "OneNAND: 0x%x-0x%x\n", res.start, res.end); + /* 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->cs = cs; + gpmc_onenand_data->resource = &res; gpmc_onenand_data->of_node = child; gpmc_onenand_data->dma_channel = -1; diff --git a/include/linux/platform_data/mtd-onenand-omap2.h b/include/linux/platform_data/mtd-onenand-omap2.h index 56ff0e6f5ad1..1c8363d3253b 100644 --- a/include/linux/platform_data/mtd-onenand-omap2.h +++ b/include/linux/platform_data/mtd-onenand-omap2.h @@ -19,6 +19,7 @@ struct omap_onenand_platform_data { int cs; + struct resource *resource; int gpio_irq; struct mtd_partition *parts; int nr_parts;