From patchwork Wed Nov 30 12:33:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 5400 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5FC7323E03 for ; Wed, 30 Nov 2011 12:33:31 +0000 (UTC) Received: from mail-lpp01m010-f52.google.com (mail-lpp01m010-f52.google.com [209.85.215.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3F88DA18218 for ; Wed, 30 Nov 2011 12:33:31 +0000 (UTC) Received: by mail-lpp01m010-f52.google.com with SMTP id h2so252845laa.11 for ; Wed, 30 Nov 2011 04:33:31 -0800 (PST) Received: by 10.152.135.179 with SMTP id pt19mr1115466lab.47.1322656411143; Wed, 30 Nov 2011 04:33:31 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs10809lal; Wed, 30 Nov 2011 04:33:30 -0800 (PST) Received: by 10.14.18.132 with SMTP id l4mr262426eel.144.1322656409107; Wed, 30 Nov 2011 04:33:29 -0800 (PST) Received: from eu1sys200aog105.obsmtp.com (eu1sys200aog105.obsmtp.com. [207.126.144.119]) by mx.google.com with SMTP id o19si581442eea.98.2011.11.30.04.33.21 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 30 Nov 2011 04:33:28 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.119 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.119; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.119 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob105.postini.com ([207.126.147.11]) with SMTP ID DSNKTtYikerVNKXQwdm1WZK/B0ZKy6mus7hf@postini.com; Wed, 30 Nov 2011 12:33:28 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DEF56FB; Wed, 30 Nov 2011 12:33:06 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 325EB1DD7; Wed, 30 Nov 2011 12:33:06 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 0D747A8065; Wed, 30 Nov 2011 13:33:01 +0100 (CET) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 30 Nov 2011 13:33:05 +0100 From: Linus Walleij To: Cc: Stephen Warren , Grant Likely , Barry Song <21cnbao@gmail.com>, Shawn Guo , Thomas Abraham , Dong Aisheng , Rajendra Nayak , Haojian Zhuang , Arnd Bergmann , Linus Walleij Subject: [PATCH 2/2] pinctrl: make it possible to add multiple maps Date: Wed, 30 Nov 2011 13:33:01 +0100 Message-ID: <1322656381-6496-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.3.2 MIME-Version: 1.0 From: Linus Walleij Since we now anyway make a copy of the platform-supplied pinmux map, we can just as well make it possible to call the function adding maps several times, so as to simplify cases (as PXA) where several sets of disparate mappings need to be added depending on target platform. Signed-off-by: Linus Walleij --- drivers/pinctrl/pinmux.c | 58 ++++++++++++++++++++++----------------------- 1 files changed, 28 insertions(+), 30 deletions(-) diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 680f690..54fc27b 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -351,48 +351,30 @@ EXPORT_SYMBOL_GPL(pinmux_gpio_direction_output); int __init pinmux_register_mappings(struct pinmux_map const *maps, unsigned num_maps) { - int ret = 0; + void *tmp_maps; int i; - if (pinmux_maps_num != 0) { - pr_err("pinmux mappings already registered, you can only " - "register one set of maps\n"); - return -EINVAL; - } - pr_debug("add %d pinmux maps\n", num_maps); - /* - * Make a copy of the map array - string pointers will end up in the - * kernel const section anyway so these do not need to be deep copied. - */ - pinmux_maps = kmemdup(maps, sizeof(struct pinmux_map) * num_maps, - GFP_KERNEL); - if (!pinmux_maps) - return -ENOMEM; - + /* First sanity check the new mapping */ for (i = 0; i < num_maps; i++) { - /* Sanity check the mapping while copying it */ if (!maps[i].name) { pr_err("failed to register map %d: " "no map name given\n", i); - ret = -EINVAL; - goto err_out_free; + return -EINVAL; } if (!maps[i].ctrl_dev && !maps[i].ctrl_dev_name) { pr_err("failed to register map %s (%d): " "no pin control device given\n", maps[i].name, i); - ret = -EINVAL; - goto err_out_free; + return -EINVAL; } if (!maps[i].function) { pr_err("failed to register map %s (%d): " "no function ID given\n", maps[i].name, i); - ret = -EINVAL; - goto err_out_free; + return -EINVAL; } if (!maps[i].dev && !maps[i].dev_name) @@ -403,17 +385,33 @@ int __init pinmux_register_mappings(struct pinmux_map const *maps, pr_debug("register map %s, function %s\n", maps[i].name, maps[i].function); + } - pinmux_maps_num++; + /* + * Make a copy of the map array - string pointers will end up in the + * kernel const section anyway so these do not need to be deep copied. + */ + if (!pinmux_maps_num) { + /* On first call, just copy them */ + tmp_maps = kmemdup(maps, + sizeof(struct pinmux_map) * num_maps, + GFP_KERNEL); + if (!tmp_maps) + return -ENOMEM; + } else { + /* Subsequent calls, reallocate array to new size */ + size_t oldsize = sizeof(struct pinmux_map) * pinmux_maps_num; + size_t newsize = sizeof(struct pinmux_map) * num_maps; + + tmp_maps = krealloc(pinmux_maps, oldsize + newsize, GFP_KERNEL); + if (!tmp_maps) + return -ENOMEM; + memcpy((tmp_maps + oldsize), maps, newsize); } + pinmux_maps = tmp_maps; + pinmux_maps_num += num_maps; return 0; - -err_out_free: - kfree(pinmux_maps); - pinmux_maps = NULL; - pinmux_maps_num = 0; - return ret; } /**