From patchwork Sun Oct 15 23:20:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10007331 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 AFDC960230 for ; Sun, 15 Oct 2017 23:21:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97365269A3 for ; Sun, 15 Oct 2017 23:21:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89B4726CFF; Sun, 15 Oct 2017 23:21:24 +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 949F7269A3 for ; Sun, 15 Oct 2017 23:20:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751398AbdJOXUv (ORCPT ); Sun, 15 Oct 2017 19:20:51 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:44780 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751235AbdJOXUv (ORCPT ); Sun, 15 Oct 2017 19:20:51 -0400 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23990398AbdJOXUuPSXLK (ORCPT ); Mon, 16 Oct 2017 01:20:50 +0200 Date: Mon, 16 Oct 2017 01:20:49 +0200 From: Ladislav Michl To: linux-omap@vger.kernel.org Cc: Roger Quadros , Tony Lindgren Subject: [PATCH 07/11] memory: omap-gpmc: Merge gpmc_probe_onenand_child into gpmc_probe_child Message-ID: <20171015232049.rzz7p2mtpmyn452k@lenoch> References: <20171015231641.zt5fz6fidp5eczf6@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171015231641.zt5fz6fidp5eczf6@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 Generic probe function can deal with OneNAND node, remove now useless gpmc_probe_onenand_child function. Signed-off-by: Ladislav Michl --- drivers/memory/omap-gpmc.c | 111 ++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 42 deletions(-) diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c index f2aef0b87bc6..fc7c3c2a0b04 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c @@ -1921,52 +1921,22 @@ static void __maybe_unused gpmc_read_timings_dt(struct device_node *np, of_property_read_bool(np, "gpmc,time-para-granularity"); } -#if IS_ENABLED(CONFIG_MTD_ONENAND) -static int gpmc_probe_onenand_child(struct platform_device *pdev, - struct device_node *child) -{ - u32 val; - struct omap_onenand_platform_data *gpmc_onenand_data; - - if (of_property_read_u32(child, "reg", &val) < 0) { - dev_err(&pdev->dev, "%pOF has no 'reg' property\n", - child); - return -ENODEV; - } - - 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 (!of_property_read_u32(child, "dma-channel", &val)) - gpmc_onenand_data->dma_channel = val; - - return gpmc_onenand_init(gpmc_onenand_data); -} -#else -static int gpmc_probe_onenand_child(struct platform_device *pdev, - struct device_node *child) -{ - return 0; -} -#endif +extern int +gpmc_omap_onenand_init(struct omap_onenand_platform_data *_onenand_data); /** - * gpmc_probe_generic_child - configures the gpmc for a child device + * gpmc_probe_child - configures the gpmc for a child device * @pdev: pointer to gpmc platform device * @child: pointer to device-tree node for child device * * Allocates and configures a GPMC chip-select for a child device. * Returns 0 on success and appropriate negative error code on failure. */ -static int gpmc_probe_generic_child(struct platform_device *pdev, +static int gpmc_probe_child(struct platform_device *pdev, struct device_node *child) { + struct omap_onenand_platform_data *gpmc_onenand_data; + struct platform_device *child_dev; struct gpmc_settings gpmc_s; struct gpmc_timings gpmc_t; struct resource res; @@ -2058,6 +2028,33 @@ static int gpmc_probe_generic_child(struct platform_device *pdev, } } + if (of_node_cmp(child->name, "onenand") == 0) { + /* + * Warn about older DT blobs with no compatible property + * and fix them for now + */ + if (!of_property_read_bool(child, "compatible")) { + struct property *prop; + + dev_warn(&pdev->dev, + "Incompatible OneNAND node, fixing."); + + prop = kzalloc(sizeof(*prop), GFP_KERNEL); + if (!prop) { + ret = -ENOMEM; + goto err; + } + + prop->name = "compatible"; + /* See FIXME about device-tree migration bellow */ + prop->value = (gpmc_capability & GPMC_HAS_WR_ACCESS) ? + "ti,omap3-onenand" : "ti,omap2-onenand"; + prop->length = 14; + + of_update_property(child, prop); + } + } + if (of_device_is_compatible(child, "ti,omap2-nand")) { /* NAND specific setup */ val = 8; @@ -2079,6 +2076,30 @@ static int gpmc_probe_generic_child(struct platform_device *pdev, /* disable write protect */ gpmc_configure(GPMC_CONFIG_WP, 0); gpmc_s.device_nand = true; + } else if (of_device_is_compatible(child, "ti,omap2-onenand") || + of_device_is_compatible(child, "ti,omap3-onenand")) { + gpmc_onenand_data = devm_kzalloc(&pdev->dev, + sizeof(*gpmc_onenand_data), + GFP_KERNEL); + if (!gpmc_onenand_data) { + ret = -ENOMEM; + goto err; + } + + gpmc_onenand_data->cs = cs; + gpmc_onenand_data->of_node = child; + if (!of_property_read_u32(child, "dma-channel", &val)) + gpmc_onenand_data->dma_channel = val; + else + gpmc_onenand_data->dma_channel = -1; + + ret = gpmc_omap_onenand_init(gpmc_onenand_data); + if (ret) + goto err; + + /* OneNAND driver handles timings on its own */ + gpmc_cs_enable_mem(cs); + goto no_timings; } else { ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width); @@ -2126,9 +2147,19 @@ static int gpmc_probe_generic_child(struct platform_device *pdev, no_timings: /* create platform device, NULL on error or when disabled */ - if (!of_platform_device_create(child, NULL, &pdev->dev)) + child_dev = of_platform_device_create(child, NULL, &pdev->dev); + if (!child_dev) goto err_child_fail; + /* Use platform data until OneNAND driver is DT aware */ + if (gpmc_onenand_data) { + child_dev->name = "omap2-onenand"; + child_dev->dev.platform_data = gpmc_onenand_data; + ret = platform_device_add_resources(child_dev, &res, 1); + if (ret) + goto err_child_fail; + } + /* is child a common bus? */ if (of_match_node(of_default_bus_match_table, child)) /* create children and other common bus children */ @@ -2193,11 +2224,7 @@ static void gpmc_probe_dt_children(struct platform_device *pdev) if (!child->name) continue; - if (of_node_cmp(child->name, "onenand") == 0) - ret = gpmc_probe_onenand_child(pdev, child); - else - ret = gpmc_probe_generic_child(pdev, child); - + ret = gpmc_probe_child(pdev, child); if (ret) { dev_err(&pdev->dev, "failed to probe DT child '%s': %d\n", child->name, ret);