aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/core.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@wwwdotorg.org>2012-03-23 12:29:46 -0400
committerLinus Walleij <linus.walleij@linaro.org>2012-04-18 07:53:10 -0400
commit57291ce295c0aca738dd284c4a9c591c09ebee71 (patch)
tree6e687f329e7adf08b5d7dcaa3d6616ff1a9b8c27 /drivers/pinctrl/core.c
parentd26bc49fa401be2b71838b6a4b387196cd12a534 (diff)
pinctrl: core device tree mapping table parsing support
During pinctrl_get(), if the client device has a device tree node, look for the common pinctrl properties there. If found, parse the referenced device tree nodes, with the help of the pinctrl drivers, and generate mapping table entries from them. During pinctrl_put(), free any results of device tree parsing. Acked-by: Dong Aisheng <dong.aisheng@linaro.org> Signed-off-by: Stephen Warren <swarren@wwwdotorg.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/core.c')
-rw-r--r--drivers/pinctrl/core.c72
1 files changed, 55 insertions, 17 deletions
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index df6296c5f47b..832f71dcd8c4 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -26,6 +26,7 @@
26#include <linux/pinctrl/pinctrl.h> 26#include <linux/pinctrl/pinctrl.h>
27#include <linux/pinctrl/machine.h> 27#include <linux/pinctrl/machine.h>
28#include "core.h" 28#include "core.h"
29#include "devicetree.h"
29#include "pinmux.h" 30#include "pinmux.h"
30#include "pinconf.h" 31#include "pinconf.h"
31 32
@@ -45,7 +46,7 @@ struct pinctrl_maps {
45DEFINE_MUTEX(pinctrl_mutex); 46DEFINE_MUTEX(pinctrl_mutex);
46 47
47/* Global list of pin control devices (struct pinctrl_dev) */ 48/* Global list of pin control devices (struct pinctrl_dev) */
48static LIST_HEAD(pinctrldev_list); 49LIST_HEAD(pinctrldev_list);
49 50
50/* List of pin controller handles (struct pinctrl) */ 51/* List of pin controller handles (struct pinctrl) */
51static LIST_HEAD(pinctrl_list); 52static LIST_HEAD(pinctrl_list);
@@ -579,6 +580,13 @@ static struct pinctrl *create_pinctrl(struct device *dev)
579 } 580 }
580 p->dev = dev; 581 p->dev = dev;
581 INIT_LIST_HEAD(&p->states); 582 INIT_LIST_HEAD(&p->states);
583 INIT_LIST_HEAD(&p->dt_maps);
584
585 ret = pinctrl_dt_to_map(p);
586 if (ret < 0) {
587 kfree(p);
588 return ERR_PTR(ret);
589 }
582 590
583 devname = dev_name(dev); 591 devname = dev_name(dev);
584 592
@@ -662,6 +670,8 @@ static void pinctrl_put_locked(struct pinctrl *p, bool inlist)
662 kfree(state); 670 kfree(state);
663 } 671 }
664 672
673 pinctrl_dt_free_maps(p);
674
665 if (inlist) 675 if (inlist)
666 list_del(&p->node); 676 list_del(&p->node);
667 kfree(p); 677 kfree(p);
@@ -787,15 +797,8 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
787} 797}
788EXPORT_SYMBOL_GPL(pinctrl_select_state); 798EXPORT_SYMBOL_GPL(pinctrl_select_state);
789 799
790/** 800int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
791 * pinctrl_register_mappings() - register a set of pin controller mappings 801 bool dup, bool locked)
792 * @maps: the pincontrol mappings table to register. This should probably be
793 * marked with __initdata so it can be discarded after boot. This
794 * function will perform a shallow copy for the mapping entries.
795 * @num_maps: the number of maps in the mapping table
796 */
797int pinctrl_register_mappings(struct pinctrl_map const *maps,
798 unsigned num_maps)
799{ 802{
800 int i, ret; 803 int i, ret;
801 struct pinctrl_maps *maps_node; 804 struct pinctrl_maps *maps_node;
@@ -851,20 +854,52 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps,
851 } 854 }
852 855
853 maps_node->num_maps = num_maps; 856 maps_node->num_maps = num_maps;
854 maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, GFP_KERNEL); 857 if (dup) {
855 if (!maps_node->maps) { 858 maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps,
856 pr_err("failed to duplicate mapping table\n"); 859 GFP_KERNEL);
857 kfree(maps_node); 860 if (!maps_node->maps) {
858 return -ENOMEM; 861 pr_err("failed to duplicate mapping table\n");
862 kfree(maps_node);
863 return -ENOMEM;
864 }
865 } else {
866 maps_node->maps = maps;
859 } 867 }
860 868
861 mutex_lock(&pinctrl_mutex); 869 if (!locked)
870 mutex_lock(&pinctrl_mutex);
862 list_add_tail(&maps_node->node, &pinctrl_maps); 871 list_add_tail(&maps_node->node, &pinctrl_maps);
863 mutex_unlock(&pinctrl_mutex); 872 if (!locked)
873 mutex_unlock(&pinctrl_mutex);
864 874
865 return 0; 875 return 0;
866} 876}
867 877
878/**
879 * pinctrl_register_mappings() - register a set of pin controller mappings
880 * @maps: the pincontrol mappings table to register. This should probably be
881 * marked with __initdata so it can be discarded after boot. This
882 * function will perform a shallow copy for the mapping entries.
883 * @num_maps: the number of maps in the mapping table
884 */
885int pinctrl_register_mappings(struct pinctrl_map const *maps,
886 unsigned num_maps)
887{
888 return pinctrl_register_map(maps, num_maps, true, false);
889}
890
891void pinctrl_unregister_map(struct pinctrl_map const *map)
892{
893 struct pinctrl_maps *maps_node;
894
895 list_for_each_entry(maps_node, &pinctrl_maps, node) {
896 if (maps_node->maps == map) {
897 list_del(&maps_node->node);
898 return;
899 }
900 }
901}
902
868#ifdef CONFIG_DEBUG_FS 903#ifdef CONFIG_DEBUG_FS
869 904
870static int pinctrl_pins_show(struct seq_file *s, void *what) 905static int pinctrl_pins_show(struct seq_file *s, void *what)
@@ -1231,6 +1266,9 @@ static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
1231 !ops->get_group_pins) 1266 !ops->get_group_pins)
1232 return -EINVAL; 1267 return -EINVAL;
1233 1268
1269 if (ops->dt_node_to_map && !ops->dt_free_map)
1270 return -EINVAL;
1271
1234 return 0; 1272 return 0;
1235} 1273}
1236 1274