linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laxman Dewangan <ldewangan@nvidia.com>
To: <grant.likely@linaro.org>, <linus.walleij@linaro.org>
Cc: <rob.herring@calxeda.com>, <rob@landley.net>,
	<sameo@linux.intel.com>, <lee.jones@linaro.org>,
	<devicetree-discuss@lists.ozlabs.org>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<gg@slimlogic.co.uk>, <kishon@ti.com>, <swarren@nvidia.com>,
	<devicetree@vger.kernel.org>,
	Laxman Dewangan <ldewangan@nvidia.com>
Subject: [PATCH 1/2] pinctrl: pinconf_generic: add utility functions for add map/configs
Date: Fri, 26 Jul 2013 15:45:53 +0530	[thread overview]
Message-ID: <1374833754-19659-2-git-send-email-ldewangan@nvidia.com> (raw)
In-Reply-To: <1374833754-19659-1-git-send-email-ldewangan@nvidia.com>

Some of pincontrol driver needs the utility function to create map
list. The utility function needed for adding mux, configs etc.

In place of duplicating this in each driver, add the common utility
function in pin_conf and use from device specific driver. This will
reduce the duplicating of code across drivers.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
 drivers/pinctrl/pinconf-generic.c       |  105 +++++++++++++++++++++++++++++++
 include/linux/pinctrl/pinconf-generic.h |   52 +++++++++++++++
 2 files changed, 157 insertions(+), 0 deletions(-)

diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
index 8594f03..d9eae95 100644
--- a/drivers/pinctrl/pinconf-generic.c
+++ b/drivers/pinctrl/pinconf-generic.c
@@ -236,4 +236,109 @@ out:
 	kfree(cfg);
 	return ret;
 }
+
+int pinconf_generic_reserve_map(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, unsigned reserve)
+{
+	unsigned old_num = *reserved_maps;
+	unsigned new_num = *num_maps + reserve;
+	struct pinctrl_map *new_map;
+
+	if (old_num >= new_num)
+		return 0;
+
+	new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
+	if (!new_map) {
+		dev_err(dev, "krealloc(map) failed\n");
+		return -ENOMEM;
+	}
+
+	memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
+
+	*map = new_map;
+	*reserved_maps = new_num;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_reserve_map);
+
+int pinconf_generic_add_map_mux(struct pinctrl_map **map,
+		unsigned *reserved_maps, unsigned *num_maps,
+		const char *group, const char *function)
+{
+	if (WARN_ON(*num_maps == *reserved_maps))
+		return -ENOSPC;
+
+	(*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
+	(*map)[*num_maps].data.mux.group = group;
+	(*map)[*num_maps].data.mux.function = function;
+	(*num_maps)++;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_add_map_mux);
+
+int pinconf_generic_add_map_configs(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, const char *group,
+		unsigned long *configs, unsigned num_configs)
+{
+	unsigned long *dup_configs;
+
+	if (WARN_ON(*num_maps == *reserved_maps))
+		return -ENOSPC;
+
+	dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
+			      GFP_KERNEL);
+	if (!dup_configs) {
+		dev_err(dev, "kmemdup(configs) failed\n");
+		return -ENOMEM;
+	}
+
+	(*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
+	(*map)[*num_maps].data.configs.group_or_pin = group;
+	(*map)[*num_maps].data.configs.configs = dup_configs;
+	(*map)[*num_maps].data.configs.num_configs = num_configs;
+	(*num_maps)++;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_add_map_configs);
+
+int pinconf_generic_add_config(struct device *dev, unsigned long **configs,
+		      unsigned *num_configs, unsigned long config)
+{
+	unsigned old_num = *num_configs;
+	unsigned new_num = old_num + 1;
+	unsigned long *new_configs;
+
+	new_configs = krealloc(*configs, sizeof(*new_configs) * new_num,
+			       GFP_KERNEL);
+	if (!new_configs) {
+		dev_err(dev, "krealloc(configs) failed\n");
+		return -ENOMEM;
+	}
+
+	new_configs[old_num] = config;
+
+	*configs = new_configs;
+	*num_configs = new_num;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_add_config);
+
+void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
+		      struct pinctrl_map *map, unsigned num_maps)
+{
+	int i;
+
+	for (i = 0; i < num_maps; i++)
+		if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
+			kfree(map[i].data.configs.configs);
+
+	kfree(map);
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_dt_free_map);
+
 #endif
diff --git a/include/linux/pinctrl/pinconf-generic.h b/include/linux/pinctrl/pinconf-generic.h
index bf7e989..694ea5c 100644
--- a/include/linux/pinctrl/pinconf-generic.h
+++ b/include/linux/pinctrl/pinconf-generic.h
@@ -137,6 +137,58 @@ static inline unsigned long pinconf_to_config_packed(enum pin_config_param param
 	return PIN_CONF_PACKED(param, argument);
 }
 
+int pinconf_generic_reserve_map(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, unsigned reserve);
+
+int pinconf_generic_add_map_mux(struct pinctrl_map **map,
+		unsigned *reserved_maps, unsigned *num_maps,
+		const char *group, const char *function);
+
+int pinconf_generic_add_map_configs(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, const char *group,
+		unsigned long *configs, unsigned num_configs);
+
+int pinconf_generic_add_config(struct device *dev, unsigned long **configs,
+		unsigned *num_configs, unsigned long config);
+
+void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
+		struct pinctrl_map *map, unsigned num_maps);
+#else
+static inline int pinconf_generic_reserve_map(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, unsigned reserve)
+{
+	return -ENOTSUPP;
+}
+
+static inline int pinconf_generic_add_map_mux(struct pinctrl_map **map,
+		unsigned *reserved_maps, unsigned *num_maps,
+		const char *group, const char *function)
+{
+	return -ENOTSUPP;
+}
+
+static inline int pinconf_generic_add_map_configs(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, const char *group,
+		unsigned long *configs, unsigned num_configs)
+{
+	return -ENOTSUPP;
+}
+
+static inline int pinconf_generic_add_config(struct device *dev,
+		unsigned long **configs, unsigned *num_configs,
+		unsigned long config)
+{
+	return -ENOTSUPP;
+}
+
+static inline void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
+		struct pinctrl_map *map, unsigned num_maps)
+{
+}
 #endif /* CONFIG_GENERIC_PINCONF */
 
 #endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */
-- 
1.7.1.1


  reply	other threads:[~2013-07-26 10:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-26 10:15 [PATCH 0/2] pinctrl: palmas: add pincontrol driver Laxman Dewangan
2013-07-26 10:15 ` Laxman Dewangan [this message]
2013-07-26 17:36   ` [PATCH 1/2] pinctrl: pinconf_generic: add utility functions for add map/configs Stephen Warren
2013-07-27 10:14     ` Laxman Dewangan
2013-07-29 16:38       ` Stephen Warren
2013-08-07 18:27     ` Linus Walleij
2013-08-08  7:23       ` Laxman Dewangan
2013-07-26 10:15 ` [PATCH 2/2] pinctrl: palmas: add pincontrol driver Laxman Dewangan
2013-07-26 16:41   ` Mark Brown
2013-07-27 10:23     ` Laxman Dewangan
2013-07-28 12:20       ` Mark Brown
2013-07-26 19:09   ` Stephen Warren
2013-07-27 12:11     ` Laxman Dewangan
2013-07-29 16:45       ` Stephen Warren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1374833754-19659-2-git-send-email-ldewangan@nvidia.com \
    --to=ldewangan@nvidia.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gg@slimlogic.co.uk \
    --cc=grant.likely@linaro.org \
    --cc=kishon@ti.com \
    --cc=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=sameo@linux.intel.com \
    --cc=swarren@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).