From patchwork Wed Jun 11 08:56:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 31725 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f198.google.com (mail-ig0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 18E43203C2 for ; Wed, 11 Jun 2014 08:59:09 +0000 (UTC) Received: by mail-ig0-f198.google.com with SMTP id uq10sf1791095igb.1 for ; Wed, 11 Jun 2014 01:59:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=TiYkoCy2rH3C0CyILkE8B1LomtA7RAGT3LyOlPGifs8=; b=c29SanIkax4T/Us0eu8DNjmpXFhtYwmIB29QPiqwz0EYkHYfAzu37eqMh31D3O5ibu WdCGAR50ehjLthIYmnNVa499S5v3gKVPRaodmzzLF8rgUMc5+461LFQL3JXLW+yFpiRg EgZkLGcj5TXYZrthRY5IAuNYgeJzVySdg8QNYr4cRaanfXeZCS+Rl33jpm36N2ECnewU wPPrr0QvhdEnTVxAlmgUtHLD+HrNQWEJS5nDVqP7D0yB89UoJ7Wk0q28t+VW54XaVjnr nZdbBfeJH/S3+W1Kk6qlffL2tBkzaw6oOBcFcCyVIYoBeDgIaEwHy7trBww2D2rZU9// PFpw== X-Gm-Message-State: ALoCoQkknfAsj0uMAdExmC5ntRq8G0ODyDWFDlr6nfqWAd/T/TaRisGEYxLbrZu9YQoUq1Ha+ibU X-Received: by 10.42.123.148 with SMTP id s20mr1175981icr.8.1402477148665; Wed, 11 Jun 2014 01:59:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.4 with SMTP id i4ls2420403qgf.78.gmail; Wed, 11 Jun 2014 01:59:08 -0700 (PDT) X-Received: by 10.52.159.226 with SMTP id xf2mr2261213vdb.14.1402477148500; Wed, 11 Jun 2014 01:59:08 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id 5si13982989vdy.104.2014.06.11.01.59.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Jun 2014 01:59:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.180 as permitted sender) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id jw12so7199461veb.25 for ; Wed, 11 Jun 2014 01:59:08 -0700 (PDT) X-Received: by 10.58.152.234 with SMTP id vb10mr15475228veb.21.1402477148411; Wed, 11 Jun 2014 01:59:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp286484vcb; Wed, 11 Jun 2014 01:59:08 -0700 (PDT) X-Received: by 10.68.164.229 with SMTP id yt5mr3413934pbb.28.1402477147601; Wed, 11 Jun 2014 01:59:07 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vj3si37358394pbc.59.2014.06.11.01.59.06; Wed, 11 Jun 2014 01:59:07 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932513AbaFKI6y (ORCPT + 27 others); Wed, 11 Jun 2014 04:58:54 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:33115 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755735AbaFKI6s (ORCPT ); Wed, 11 Jun 2014 04:58:48 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s5B8wHe4003570; Wed, 11 Jun 2014 03:58:17 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5B8wHow022024; Wed, 11 Jun 2014 03:58:17 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Wed, 11 Jun 2014 03:58:17 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5B8uiSx020510; Wed, 11 Jun 2014 03:58:14 -0500 From: Roger Quadros To: , , CC: , , , , , , , , , Roger Quadros Subject: [PATCH 25/36] ARM: OMAP2+: gpmc: Support multiple Chip Selects per device Date: Wed, 11 Jun 2014 11:56:30 +0300 Message-ID: <1402477001-31132-26-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1402477001-31132-1-git-send-email-rogerq@ti.com> References: <1402477001-31132-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Some devices (e.g. tusb6010) need 2 chip selects to work with 2 separate IOMEM resources. Allow such use case. The user just needs to call gpmc_generic_init() for as many chip selects with the same platform_device pointer. The GPMC driver will take care of fixing up the memory resources. Signed-off-by: Roger Quadros --- arch/arm/mach-omap2/gpmc.c | 134 ++++++++++++++++++++++++++++++--------------- 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c index 5563360..34545ca 100644 --- a/arch/arm/mach-omap2/gpmc.c +++ b/arch/arm/mach-omap2/gpmc.c @@ -1388,9 +1388,14 @@ static int gpmc_nand_setup(struct platform_device *parent_pdev, static void gpmc_probe_legacy(struct platform_device *pdev) { - int i, rc; + int i, rc, j; struct device *dev = &pdev->dev; struct gpmc_omap_platform_data *gpmc_pdata; + struct resource *mem_res; + unsigned long cs_base; + resource_size_t size; + struct gpmc_timings gpmc_timings; + struct gpmc_omap_cs_data *cs; gpmc_pdata = dev->platform_data; gpmc_cs_num = GPMC_CS_NUM; @@ -1400,52 +1405,10 @@ static void gpmc_probe_legacy(struct platform_device *pdev) return; for (i = 0; i < GPMC_CS_NUM; i++) { - struct resource *mem_res; - unsigned long cs_base; - resource_size_t size; - struct gpmc_timings gpmc_timings; - struct gpmc_omap_cs_data *cs; - cs = &gpmc_pdata->cs[i]; if (!cs->valid) continue; - /* - * Request a CS space. Use size from - * platform device's MEM resource - */ - if (!cs->pdev) - goto skip_mem; - - mem_res = cs->pdev->resource; - if (cs->pdev->num_resources < 1 || - resource_type(mem_res) != IORESOURCE_MEM) { - dev_err(dev, "Invalid IOMEM resource for CS %d\n", i); - continue; - } - - size = mem_res->end - mem_res->start + 1; - if (gpmc_cs_request(i, size, &cs_base)) { - dev_err(dev, "Couldn't request resource for CS %d\n", - i); - continue; - } - - mem_res->start = cs_base; - mem_res->end = cs_base + size - 1; - - /* FIXME: When do we need to call gpmc_cs_remap()? */ -skip_mem: - - /* Customized NAND setup */ - if (cs->is_nand) { - if (gpmc_nand_setup(pdev, cs)) { - dev_err(dev, "Error setting up NAND on CS %d\n", - i); - continue; - } - } - if (cs->settings) { if (gpmc_cs_program_settings(i, cs->settings)) { dev_err(dev, @@ -1474,10 +1437,95 @@ skip_mem: continue; } } + } + + /* + * All Chip Selects must be configured before platform devices are + * created as some devices (e.g. tusb6010) can use multiple + * Chip selects. + */ + + /* Fixup Memory resources */ + for (i = 0; i < GPMC_CS_NUM; i++) { + int required_resources; + + cs = &gpmc_pdata->cs[i]; + if (!cs->valid) + continue; if (!cs->pdev) continue; + /* Customized NAND setup */ + if (cs->is_nand) { + if (gpmc_nand_setup(pdev, cs)) { + dev_err(dev, "Error setting up NAND on CS %d\n", + i); + continue; + } + } + + mem_res = cs->pdev->resource; + + /* + * If device is present multiple times, fix the subsequent + * resources + */ + required_resources = 1; + for (j = 0; j < i; j++) { + if (gpmc_pdata->cs[j].pdev == cs->pdev) { + mem_res++; + required_resources++; + } + } + + if (cs->pdev->num_resources < required_resources || + resource_type(mem_res) != IORESOURCE_MEM) { + dev_err(dev, "Invalid IOMEM resource for CS %d\n", i); + continue; + } + + /* + * Request a CS space. Use size from + * platform device's MEM resource + */ + size = mem_res->end - mem_res->start + 1; + if (gpmc_cs_request(i, size, &cs_base)) { + dev_err(dev, "Couldn't request resource for CS %d\n", + i); + continue; + } + + mem_res->start = cs_base; + mem_res->end = cs_base + size - 1; + } + + /* create the platform devices */ + for (i = 0; i < GPMC_CS_NUM; i++) { + bool registered; + + cs = &gpmc_pdata->cs[i]; + if (!cs->valid) + continue; + + if (!cs->pdev) + continue; + + /* + * same device can be present on multiple CS, don't + * register device more than once. + */ + registered = false; + for (j = 0; j < i; j++) { + if (gpmc_pdata->cs[j].pdev == cs->pdev) { + registered = true; + break; + } + } + + if (registered) + continue; + cs->pdev->dev.parent = dev; rc = platform_device_register(cs->pdev); if (rc < 0) {