From patchwork Sat Dec 15 22:50:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1883591 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id E2F4CDF2EF for ; Sat, 15 Dec 2012 22:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752538Ab2LOWu7 (ORCPT ); Sat, 15 Dec 2012 17:50:59 -0500 Received: from perceval.ideasonboard.com ([95.142.166.194]:40119 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752265Ab2LOWu7 (ORCPT ); Sat, 15 Dec 2012 17:50:59 -0500 Received: from avalon.quadriga.com (unknown [194.136.87.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3810635A9D; Sat, 15 Dec 2012 23:50:58 +0100 (CET) From: Laurent Pinchart To: linux-sh@vger.kernel.org Cc: Paul Mundt , Magnus Damm , Simon Horman , Linus Walleij , Kuninori Morimoto , Phil Edworthy , Nobuhiro Iwamatsu Subject: [PATCH v3 21/81] sh-pfc: Support passing resources through platform device Date: Sat, 15 Dec 2012 23:50:55 +0100 Message-Id: <1355611915-25060-22-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1355611915-25060-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1355611915-25060-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Resources should be passed through the platform device, not through platform data. Default to platform device resources and fall back to platform data resources if not available. Support for platform data resources will be removed when arch code will be converted. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt --- drivers/sh/pfc/core.c | 26 +++++++++++++++++++------- drivers/sh/pfc/core.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index cd8f09d..b2e121d 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -26,21 +26,33 @@ #include "core.h" -static int sh_pfc_ioremap(struct sh_pfc *pfc) +static int sh_pfc_ioremap(struct sh_pfc *pfc, struct platform_device *pdev) { + unsigned int num_resources; struct resource *res; int k; - if (!pfc->pdata->num_resources) + if (pdev->num_resources) { + num_resources = pdev->num_resources; + res = pdev->resource; + } else { + num_resources = pfc->pdata->num_resources; + res = pfc->pdata->resource; + } + + if (num_resources == 0) { + pfc->num_windows = 0; return 0; + } - pfc->window = devm_kzalloc(pfc->dev, pfc->pdata->num_resources * + pfc->window = devm_kzalloc(pfc->dev, num_resources * sizeof(*pfc->window), GFP_NOWAIT); if (!pfc->window) return -ENOMEM; - for (k = 0; k < pfc->pdata->num_resources; k++) { - res = pfc->pdata->resource + k; + pfc->num_windows = num_resources; + + for (k = 0; k < num_resources; k++, res++) { WARN_ON(resource_type(res) != IORESOURCE_MEM); pfc->window[k].phys = res->start; pfc->window[k].size = resource_size(res); @@ -60,7 +72,7 @@ static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, int k; /* scan through physical windows and convert address */ - for (k = 0; k < pfc->pdata->num_resources; k++) { + for (k = 0; k < pfc->num_windows; k++) { window = pfc->window + k; if (address < window->phys) @@ -498,7 +510,7 @@ static int sh_pfc_probe(struct platform_device *pdev) pfc->pdata = pdata; pfc->dev = &pdev->dev; - ret = sh_pfc_ioremap(pfc); + ret = sh_pfc_ioremap(pfc, pdev); if (unlikely(ret < 0)) return ret; diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h index d6a40bc..87ae5fd 100644 --- a/drivers/sh/pfc/core.h +++ b/drivers/sh/pfc/core.h @@ -28,7 +28,9 @@ struct sh_pfc { struct sh_pfc_platform_data *pdata; spinlock_t lock; + unsigned int num_windows; struct sh_pfc_window *window; + struct sh_pfc_chip *gpio; struct sh_pfc_pinctrl *pinctrl; };