From patchwork Tue Nov 29 11:58:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 5375 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 5866323E19 for ; Tue, 29 Nov 2011 11:59:28 +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 1C4EBA18088 for ; Tue, 29 Nov 2011 11:59:28 +0000 (UTC) Received: by laah2 with SMTP id h2so1292127laa.11 for ; Tue, 29 Nov 2011 03:59:27 -0800 (PST) Received: by 10.152.135.225 with SMTP id pv1mr31015528lab.19.1322567967720; Tue, 29 Nov 2011 03:59:27 -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 h6cs37857lal; Tue, 29 Nov 2011 03:59:27 -0800 (PST) Received: by 10.213.3.136 with SMTP id 8mr244090ebn.0.1322567965568; Tue, 29 Nov 2011 03:59:25 -0800 (PST) Received: from eu1sys200aog102.obsmtp.com (eu1sys200aog102.obsmtp.com. [207.126.144.113]) by mx.google.com with SMTP id 62si8165852eei.182.2011.11.29.03.59.12 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 29 Nov 2011 03:59:25 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.113 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.113; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.113 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-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob102.postini.com ([207.126.147.11]) with SMTP ID DSNKTtTJDkXpk2VvnEF/n1qhcMnkwWO9hiCA@postini.com; Tue, 29 Nov 2011 11:59:22 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id EAA81B5; Tue, 29 Nov 2011 11:50:40 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 3BD6896D; Tue, 29 Nov 2011 11:59:06 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id B9DFEA8083; Tue, 29 Nov 2011 12:59:00 +0100 (CET) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 29 Nov 2011 12:59:04 +0100 From: Linus Walleij To: Cc: Stephen Warren , Grant Likely , Barry Song <21cnbao@gmail.com>, Shawn Guo , Thomas Abraham , Dong Aisheng , Rajendra Nayak , Arnd Bergmann , Linus Walleij Subject: [PATCH] pinctrl: make a deep copy of pinmux map Date: Tue, 29 Nov 2011 12:58:58 +0100 Message-ID: <1322567938-28321-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.3.2 MIME-Version: 1.0 From: Linus Walleij This makes a deep copy of the pinmux function map instead of keeping the copy supplied from the platform around. This makes it possible to tag the platforms map with __initdata as is also done as part of this patch. Rationale: a certain target platform (PXA) has numerous pinmux maps, many of which will be lying around unused after boot in a multi-platform binary. Instead, deep-copy the one we're going to use and tag them all __initdata so they go away after boot. Suggested-by: Arnd Bergmann Signed-off-by: Linus Walleij --- Documentation/pinctrl.txt | 4 +- arch/arm/mach-u300/core.c | 2 +- drivers/pinctrl/pinmux.c | 67 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 720dfea..d9d57c8 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt @@ -784,7 +784,7 @@ spi on the second function mapping: #include -static struct pinmux_map pmx_mapping[] = { +static struct pinmux_map __initdata pmx_mapping[] = { { .ctrl_dev_name = "pinctrl.0", .function = "spi0", @@ -821,7 +821,7 @@ Since the above construct is pretty common there is a helper macro to make it even more compact which assumes you want to use pinctrl.0 and position 0 for mapping, for example: -static struct pinmux_map pmx_mapping[] = { +static struct pinmux_map __initdata pmx_mapping[] = { PINMUX_MAP_PRIMARY("I2CMAP", "i2c0", "foo-i2c.0"), }; diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index f399862..06bdae7 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -1613,7 +1613,7 @@ static struct platform_device pinmux_device = { }; /* Pinmux settings */ -static struct pinmux_map u300_pinmux_map[] = { +static struct pinmux_map __initdata u300_pinmux_map[] = { /* anonymous maps for chip power and EMIFs */ PINMUX_MAP_PRIMARY_SYS_HOG("POWER", "power"), PINMUX_MAP_PRIMARY_SYS_HOG("EMIF0", "emif0"), diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 15ae972..e791566 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,7 @@ static DEFINE_MUTEX(pinmux_hoglist_mutex); static LIST_HEAD(pinmux_hoglist); /* Global pinmux maps, we allow one set only */ -static struct pinmux_map const *pinmux_maps; +static struct pinmux_map *pinmux_maps; static unsigned pinmux_maps_num; /** @@ -337,7 +338,9 @@ EXPORT_SYMBOL_GPL(pinmux_gpio_direction_output); /** * pinmux_register_mappings() - register a set of pinmux mappings - * @maps: the pinmux mappings table to register + * @maps: the pinmux mappings table to register, this should be marked with + * __initdata so it can be discarded after boot, this function will + * perform a deep copy (including strings) for the mapping entries. * @num_maps: the number of maps in the mapping table * * Only call this once during initialization of your machine, the function is @@ -348,32 +351,66 @@ EXPORT_SYMBOL_GPL(pinmux_gpio_direction_output); int __init pinmux_register_mappings(struct pinmux_map const *maps, unsigned num_maps) { + int ret = 0; int i; - if (pinmux_maps != NULL) { + 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); + + /* Allocate a deep copy of the map array */ + pinmux_maps = kzalloc(sizeof(struct pinmux_map) * num_maps, + GFP_KERNEL); + if (!pinmux_maps) + return -ENOMEM; + for (i = 0; i < num_maps; i++) { - /* Sanity check the mapping */ + /* Sanity check the mapping while copying it */ if (!maps[i].name) { pr_err("failed to register map %d: " "no map name given\n", i); - return -EINVAL; + ret = -EINVAL; + goto err_out_free; } + pinmux_maps[i].name = kstrdup(maps[i].name, GFP_KERNEL); + if (!pinmux_maps[i].name) { + ret = -ENOMEM; + goto err_out_free; + } + 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); - return -EINVAL; + ret = -EINVAL; + goto err_out_free; + } + if (maps[i].ctrl_dev) + pinmux_maps[i].ctrl_dev = maps[i].ctrl_dev; + if (maps[i].ctrl_dev_name) { + pinmux_maps[i].ctrl_dev_name = + kstrdup(maps[i].ctrl_dev_name, GFP_KERNEL); + if (!pinmux_maps[i].ctrl_dev_name) { + ret = -ENOMEM; + goto err_out_free; + } } + if (!maps[i].function) { pr_err("failed to register map %s (%d): " "no function ID given\n", maps[i].name, i); - return -EINVAL; + ret = -EINVAL; + goto err_out_free; + } + pinmux_maps[i].function = + kstrdup(maps[i].function, GFP_KERNEL); + if (!pinmux_maps[i].function) { + ret = -ENOMEM; + goto err_out_free; } if (!maps[i].dev && !maps[i].dev_name) @@ -384,12 +421,22 @@ 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 = maps; - pinmux_maps_num = num_maps; + pinmux_maps_num++; + } return 0; + +err_out_free: + for (i = 0; i < pinmux_maps_num; i++) { + kfree(pinmux_maps[i].name); + kfree(pinmux_maps[i].ctrl_dev_name); + kfree(pinmux_maps[i].dev_name); + } + kfree(pinmux_maps); + pinmux_maps = NULL; + pinmux_maps_num = 0; + return ret; } /**