diff options
author | Olof Johansson <olof@lixom.net> | 2012-05-10 02:42:14 -0400 |
---|---|---|
committer | Olof Johansson <olof@lixom.net> | 2012-05-10 02:42:14 -0400 |
commit | b664ae6ff92f7ba5c597d4f1b74d478d712c01c4 (patch) | |
tree | b7751d3ee14c1bdbb0274ed2d22fca7b0ef51ff3 /drivers/pinctrl | |
parent | ca731a5da08926f669360342bcad50353fbe141a (diff) | |
parent | dcb5dbc305b975cccf40942feba40964069541d3 (diff) |
Merge tag 'pinctrl-mergebase-20120418' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl into next/pinctrl
By Stephen Warren (12) and others
via Linus Walleij
* tag 'pinctrl-mergebase-20120418' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl: (24 commits)
pinctrl: show pin name for pingroups in sysfs
pinctrl: show pin name when request pins
pinctrl: implement devm_pinctrl_get()/put()
pinctrl: a minor fix of pin config debug information
pinctrl: pinconf: fix compilation error if PINCONF is not selected
pinctrl: allow pctldevs to decode pin config in debugfs
pinctrl: ifdef CONFIG_DEBUG_FS cleanup
pinctrl: mark non-EXPERIMENTAL
pinctrl: tegra: Add complete device tree support
dt: Document Tegra20/30 pinctrl binding
dt: Move Tegra20 pin mux binding into new pinctrl directory
dt: pinctrl: Document device tree binding
dt: add property iteration helpers
pinctrl: implement pinctrl deferred probing
pinctrl: add some error checking for user interfaces
pinctrl: fix pinmux_check_ops error checking
pinctrl: replace list_*() with get_*_count()
pinctrl: mark const init data with __initconst instead of __initdata
Documentation: pinctrl: add missing spi0_0 grp in example
pinctrl: fix build when CONFIG_OF && !CONFIG_PINCTRL
...
Resolved conflicts in drivers/pinctrl/core.c due to same patch being
applied in two branches.
Signed-off-by: Olof Johansson <olof@lixom.net>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r-- | drivers/pinctrl/Kconfig | 1 | ||||
-rw-r--r-- | drivers/pinctrl/Makefile | 3 | ||||
-rw-r--r-- | drivers/pinctrl/core.c | 175 | ||||
-rw-r--r-- | drivers/pinctrl/core.h | 12 | ||||
-rw-r--r-- | drivers/pinctrl/devicetree.c | 249 | ||||
-rw-r--r-- | drivers/pinctrl/devicetree.h | 35 | ||||
-rw-r--r-- | drivers/pinctrl/pinconf.c | 42 | ||||
-rw-r--r-- | drivers/pinctrl/pinconf.h | 17 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-coh901.c | 4 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-pxa3xx.c | 24 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-sirf.c | 20 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-tegra.c | 245 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-u300.c | 20 | ||||
-rw-r--r-- | drivers/pinctrl/pinmux.c | 33 | ||||
-rw-r--r-- | drivers/pinctrl/pinmux.h | 18 |
15 files changed, 766 insertions, 132 deletions
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index b25ac41f7939..de6e68459605 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig | |||
@@ -4,7 +4,6 @@ | |||
4 | 4 | ||
5 | config PINCTRL | 5 | config PINCTRL |
6 | bool | 6 | bool |
7 | depends on EXPERIMENTAL | ||
8 | 7 | ||
9 | if PINCTRL | 8 | if PINCTRL |
10 | 9 | ||
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index 2febd7608050..03c97e2052bb 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile | |||
@@ -5,6 +5,9 @@ ccflags-$(CONFIG_DEBUG_PINCTRL) += -DDEBUG | |||
5 | obj-$(CONFIG_PINCTRL) += core.o | 5 | obj-$(CONFIG_PINCTRL) += core.o |
6 | obj-$(CONFIG_PINMUX) += pinmux.o | 6 | obj-$(CONFIG_PINMUX) += pinmux.o |
7 | obj-$(CONFIG_PINCONF) += pinconf.o | 7 | obj-$(CONFIG_PINCONF) += pinconf.o |
8 | ifeq ($(CONFIG_OF),y) | ||
9 | obj-$(CONFIG_PINCTRL) += devicetree.o | ||
10 | endif | ||
8 | obj-$(CONFIG_GENERIC_PINCONF) += pinconf-generic.o | 11 | obj-$(CONFIG_GENERIC_PINCONF) += pinconf-generic.o |
9 | obj-$(CONFIG_PINCTRL_PXA3xx) += pinctrl-pxa3xx.o | 12 | obj-$(CONFIG_PINCTRL_PXA3xx) += pinctrl-pxa3xx.o |
10 | obj-$(CONFIG_PINCTRL_MMP2) += pinctrl-mmp2.o | 13 | obj-$(CONFIG_PINCTRL_MMP2) += pinctrl-mmp2.o |
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index df6296c5f47b..5cd5a5a3a403 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c | |||
@@ -23,9 +23,11 @@ | |||
23 | #include <linux/sysfs.h> | 23 | #include <linux/sysfs.h> |
24 | #include <linux/debugfs.h> | 24 | #include <linux/debugfs.h> |
25 | #include <linux/seq_file.h> | 25 | #include <linux/seq_file.h> |
26 | #include <linux/pinctrl/consumer.h> | ||
26 | #include <linux/pinctrl/pinctrl.h> | 27 | #include <linux/pinctrl/pinctrl.h> |
27 | #include <linux/pinctrl/machine.h> | 28 | #include <linux/pinctrl/machine.h> |
28 | #include "core.h" | 29 | #include "core.h" |
30 | #include "devicetree.h" | ||
29 | #include "pinmux.h" | 31 | #include "pinmux.h" |
30 | #include "pinconf.h" | 32 | #include "pinconf.h" |
31 | 33 | ||
@@ -45,7 +47,7 @@ struct pinctrl_maps { | |||
45 | DEFINE_MUTEX(pinctrl_mutex); | 47 | DEFINE_MUTEX(pinctrl_mutex); |
46 | 48 | ||
47 | /* Global list of pin control devices (struct pinctrl_dev) */ | 49 | /* Global list of pin control devices (struct pinctrl_dev) */ |
48 | static LIST_HEAD(pinctrldev_list); | 50 | LIST_HEAD(pinctrldev_list); |
49 | 51 | ||
50 | /* List of pin controller handles (struct pinctrl) */ | 52 | /* List of pin controller handles (struct pinctrl) */ |
51 | static LIST_HEAD(pinctrl_list); | 53 | static LIST_HEAD(pinctrl_list); |
@@ -124,6 +126,25 @@ int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name) | |||
124 | } | 126 | } |
125 | 127 | ||
126 | /** | 128 | /** |
129 | * pin_get_name_from_id() - look up a pin name from a pin id | ||
130 | * @pctldev: the pin control device to lookup the pin on | ||
131 | * @name: the name of the pin to look up | ||
132 | */ | ||
133 | const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin) | ||
134 | { | ||
135 | const struct pin_desc *desc; | ||
136 | |||
137 | desc = pin_desc_get(pctldev, pin); | ||
138 | if (desc == NULL) { | ||
139 | dev_err(pctldev->dev, "failed to get pin(%d) name\n", | ||
140 | pin); | ||
141 | return NULL; | ||
142 | } | ||
143 | |||
144 | return desc->name; | ||
145 | } | ||
146 | |||
147 | /** | ||
127 | * pin_is_valid() - check if pin exists on controller | 148 | * pin_is_valid() - check if pin exists on controller |
128 | * @pctldev: the pin control device to check the pin on | 149 | * @pctldev: the pin control device to check the pin on |
129 | * @pin: pin to check, use the local pin controller index number | 150 | * @pin: pin to check, use the local pin controller index number |
@@ -318,9 +339,10 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, | |||
318 | const char *pin_group) | 339 | const char *pin_group) |
319 | { | 340 | { |
320 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | 341 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
342 | unsigned ngroups = pctlops->get_groups_count(pctldev); | ||
321 | unsigned group_selector = 0; | 343 | unsigned group_selector = 0; |
322 | 344 | ||
323 | while (pctlops->list_groups(pctldev, group_selector) >= 0) { | 345 | while (group_selector < ngroups) { |
324 | const char *gname = pctlops->get_group_name(pctldev, | 346 | const char *gname = pctlops->get_group_name(pctldev, |
325 | group_selector); | 347 | group_selector); |
326 | if (!strcmp(gname, pin_group)) { | 348 | if (!strcmp(gname, pin_group)) { |
@@ -516,11 +538,14 @@ static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) | |||
516 | 538 | ||
517 | setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name); | 539 | setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name); |
518 | if (setting->pctldev == NULL) { | 540 | if (setting->pctldev == NULL) { |
519 | dev_err(p->dev, "unknown pinctrl device %s in map entry", | 541 | dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe", |
520 | map->ctrl_dev_name); | 542 | map->ctrl_dev_name); |
521 | kfree(setting); | 543 | kfree(setting); |
522 | /* Eventually, this should trigger deferred probe */ | 544 | /* |
523 | return -ENODEV; | 545 | * OK let us guess that the driver is not there yet, and |
546 | * let's defer obtaining this pinctrl handle to later... | ||
547 | */ | ||
548 | return -EPROBE_DEFER; | ||
524 | } | 549 | } |
525 | 550 | ||
526 | switch (map->type) { | 551 | switch (map->type) { |
@@ -579,6 +604,13 @@ static struct pinctrl *create_pinctrl(struct device *dev) | |||
579 | } | 604 | } |
580 | p->dev = dev; | 605 | p->dev = dev; |
581 | INIT_LIST_HEAD(&p->states); | 606 | INIT_LIST_HEAD(&p->states); |
607 | INIT_LIST_HEAD(&p->dt_maps); | ||
608 | |||
609 | ret = pinctrl_dt_to_map(p); | ||
610 | if (ret < 0) { | ||
611 | kfree(p); | ||
612 | return ERR_PTR(ret); | ||
613 | } | ||
582 | 614 | ||
583 | devname = dev_name(dev); | 615 | devname = dev_name(dev); |
584 | 616 | ||
@@ -662,6 +694,8 @@ static void pinctrl_put_locked(struct pinctrl *p, bool inlist) | |||
662 | kfree(state); | 694 | kfree(state); |
663 | } | 695 | } |
664 | 696 | ||
697 | pinctrl_dt_free_maps(p); | ||
698 | |||
665 | if (inlist) | 699 | if (inlist) |
666 | list_del(&p->node); | 700 | list_del(&p->node); |
667 | kfree(p); | 701 | kfree(p); |
@@ -787,15 +821,63 @@ int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) | |||
787 | } | 821 | } |
788 | EXPORT_SYMBOL_GPL(pinctrl_select_state); | 822 | EXPORT_SYMBOL_GPL(pinctrl_select_state); |
789 | 823 | ||
824 | static void devm_pinctrl_release(struct device *dev, void *res) | ||
825 | { | ||
826 | pinctrl_put(*(struct pinctrl **)res); | ||
827 | } | ||
828 | |||
790 | /** | 829 | /** |
791 | * pinctrl_register_mappings() - register a set of pin controller mappings | 830 | * struct devm_pinctrl_get() - Resource managed pinctrl_get() |
792 | * @maps: the pincontrol mappings table to register. This should probably be | 831 | * @dev: the device to obtain the handle for |
793 | * marked with __initdata so it can be discarded after boot. This | 832 | * |
794 | * function will perform a shallow copy for the mapping entries. | 833 | * If there is a need to explicitly destroy the returned struct pinctrl, |
795 | * @num_maps: the number of maps in the mapping table | 834 | * devm_pinctrl_put() should be used, rather than plain pinctrl_put(). |
796 | */ | 835 | */ |
797 | int pinctrl_register_mappings(struct pinctrl_map const *maps, | 836 | struct pinctrl *devm_pinctrl_get(struct device *dev) |
798 | unsigned num_maps) | 837 | { |
838 | struct pinctrl **ptr, *p; | ||
839 | |||
840 | ptr = devres_alloc(devm_pinctrl_release, sizeof(*ptr), GFP_KERNEL); | ||
841 | if (!ptr) | ||
842 | return ERR_PTR(-ENOMEM); | ||
843 | |||
844 | p = pinctrl_get(dev); | ||
845 | if (!IS_ERR(p)) { | ||
846 | *ptr = p; | ||
847 | devres_add(dev, ptr); | ||
848 | } else { | ||
849 | devres_free(ptr); | ||
850 | } | ||
851 | |||
852 | return p; | ||
853 | } | ||
854 | EXPORT_SYMBOL_GPL(devm_pinctrl_get); | ||
855 | |||
856 | static int devm_pinctrl_match(struct device *dev, void *res, void *data) | ||
857 | { | ||
858 | struct pinctrl **p = res; | ||
859 | |||
860 | return *p == data; | ||
861 | } | ||
862 | |||
863 | /** | ||
864 | * devm_pinctrl_put() - Resource managed pinctrl_put() | ||
865 | * @p: the pinctrl handle to release | ||
866 | * | ||
867 | * Deallocate a struct pinctrl obtained via devm_pinctrl_get(). Normally | ||
868 | * this function will not need to be called and the resource management | ||
869 | * code will ensure that the resource is freed. | ||
870 | */ | ||
871 | void devm_pinctrl_put(struct pinctrl *p) | ||
872 | { | ||
873 | WARN_ON(devres_destroy(p->dev, devm_pinctrl_release, | ||
874 | devm_pinctrl_match, p)); | ||
875 | pinctrl_put(p); | ||
876 | } | ||
877 | EXPORT_SYMBOL_GPL(devm_pinctrl_put); | ||
878 | |||
879 | int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, | ||
880 | bool dup, bool locked) | ||
799 | { | 881 | { |
800 | int i, ret; | 882 | int i, ret; |
801 | struct pinctrl_maps *maps_node; | 883 | struct pinctrl_maps *maps_node; |
@@ -851,20 +933,52 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps, | |||
851 | } | 933 | } |
852 | 934 | ||
853 | maps_node->num_maps = num_maps; | 935 | maps_node->num_maps = num_maps; |
854 | maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, GFP_KERNEL); | 936 | if (dup) { |
855 | if (!maps_node->maps) { | 937 | maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, |
856 | pr_err("failed to duplicate mapping table\n"); | 938 | GFP_KERNEL); |
857 | kfree(maps_node); | 939 | if (!maps_node->maps) { |
858 | return -ENOMEM; | 940 | pr_err("failed to duplicate mapping table\n"); |
941 | kfree(maps_node); | ||
942 | return -ENOMEM; | ||
943 | } | ||
944 | } else { | ||
945 | maps_node->maps = maps; | ||
859 | } | 946 | } |
860 | 947 | ||
861 | mutex_lock(&pinctrl_mutex); | 948 | if (!locked) |
949 | mutex_lock(&pinctrl_mutex); | ||
862 | list_add_tail(&maps_node->node, &pinctrl_maps); | 950 | list_add_tail(&maps_node->node, &pinctrl_maps); |
863 | mutex_unlock(&pinctrl_mutex); | 951 | if (!locked) |
952 | mutex_unlock(&pinctrl_mutex); | ||
864 | 953 | ||
865 | return 0; | 954 | return 0; |
866 | } | 955 | } |
867 | 956 | ||
957 | /** | ||
958 | * pinctrl_register_mappings() - register a set of pin controller mappings | ||
959 | * @maps: the pincontrol mappings table to register. This should probably be | ||
960 | * marked with __initdata so it can be discarded after boot. This | ||
961 | * function will perform a shallow copy for the mapping entries. | ||
962 | * @num_maps: the number of maps in the mapping table | ||
963 | */ | ||
964 | int pinctrl_register_mappings(struct pinctrl_map const *maps, | ||
965 | unsigned num_maps) | ||
966 | { | ||
967 | return pinctrl_register_map(maps, num_maps, true, false); | ||
968 | } | ||
969 | |||
970 | void pinctrl_unregister_map(struct pinctrl_map const *map) | ||
971 | { | ||
972 | struct pinctrl_maps *maps_node; | ||
973 | |||
974 | list_for_each_entry(maps_node, &pinctrl_maps, node) { | ||
975 | if (maps_node->maps == map) { | ||
976 | list_del(&maps_node->node); | ||
977 | return; | ||
978 | } | ||
979 | } | ||
980 | } | ||
981 | |||
868 | #ifdef CONFIG_DEBUG_FS | 982 | #ifdef CONFIG_DEBUG_FS |
869 | 983 | ||
870 | static int pinctrl_pins_show(struct seq_file *s, void *what) | 984 | static int pinctrl_pins_show(struct seq_file *s, void *what) |
@@ -906,15 +1020,17 @@ static int pinctrl_groups_show(struct seq_file *s, void *what) | |||
906 | { | 1020 | { |
907 | struct pinctrl_dev *pctldev = s->private; | 1021 | struct pinctrl_dev *pctldev = s->private; |
908 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; | 1022 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; |
909 | unsigned selector = 0; | 1023 | unsigned ngroups, selector = 0; |
910 | 1024 | ||
1025 | ngroups = ops->get_groups_count(pctldev); | ||
911 | mutex_lock(&pinctrl_mutex); | 1026 | mutex_lock(&pinctrl_mutex); |
912 | 1027 | ||
913 | seq_puts(s, "registered pin groups:\n"); | 1028 | seq_puts(s, "registered pin groups:\n"); |
914 | while (ops->list_groups(pctldev, selector) >= 0) { | 1029 | while (selector < ngroups) { |
915 | const unsigned *pins; | 1030 | const unsigned *pins; |
916 | unsigned num_pins; | 1031 | unsigned num_pins; |
917 | const char *gname = ops->get_group_name(pctldev, selector); | 1032 | const char *gname = ops->get_group_name(pctldev, selector); |
1033 | const char *pname; | ||
918 | int ret; | 1034 | int ret; |
919 | int i; | 1035 | int i; |
920 | 1036 | ||
@@ -924,10 +1040,14 @@ static int pinctrl_groups_show(struct seq_file *s, void *what) | |||
924 | seq_printf(s, "%s [ERROR GETTING PINS]\n", | 1040 | seq_printf(s, "%s [ERROR GETTING PINS]\n", |
925 | gname); | 1041 | gname); |
926 | else { | 1042 | else { |
927 | seq_printf(s, "group: %s, pins = [ ", gname); | 1043 | seq_printf(s, "group: %s\n", gname); |
928 | for (i = 0; i < num_pins; i++) | 1044 | for (i = 0; i < num_pins; i++) { |
929 | seq_printf(s, "%d ", pins[i]); | 1045 | pname = pin_get_name(pctldev, pins[i]); |
930 | seq_puts(s, "]\n"); | 1046 | if (WARN_ON(!pname)) |
1047 | return -EINVAL; | ||
1048 | seq_printf(s, "pin %d (%s)\n", pins[i], pname); | ||
1049 | } | ||
1050 | seq_puts(s, "\n"); | ||
931 | } | 1051 | } |
932 | selector++; | 1052 | selector++; |
933 | } | 1053 | } |
@@ -1226,11 +1346,14 @@ static int pinctrl_check_ops(struct pinctrl_dev *pctldev) | |||
1226 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; | 1346 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; |
1227 | 1347 | ||
1228 | if (!ops || | 1348 | if (!ops || |
1229 | !ops->list_groups || | 1349 | !ops->get_groups_count || |
1230 | !ops->get_group_name || | 1350 | !ops->get_group_name || |
1231 | !ops->get_group_pins) | 1351 | !ops->get_group_pins) |
1232 | return -EINVAL; | 1352 | return -EINVAL; |
1233 | 1353 | ||
1354 | if (ops->dt_node_to_map && !ops->dt_free_map) | ||
1355 | return -EINVAL; | ||
1356 | |||
1234 | return 0; | 1357 | return 0; |
1235 | } | 1358 | } |
1236 | 1359 | ||
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 17ecf651b123..1f40ff68a8c4 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h | |||
@@ -52,12 +52,15 @@ struct pinctrl_dev { | |||
52 | * @dev: the device using this pin control handle | 52 | * @dev: the device using this pin control handle |
53 | * @states: a list of states for this device | 53 | * @states: a list of states for this device |
54 | * @state: the current state | 54 | * @state: the current state |
55 | * @dt_maps: the mapping table chunks dynamically parsed from device tree for | ||
56 | * this device, if any | ||
55 | */ | 57 | */ |
56 | struct pinctrl { | 58 | struct pinctrl { |
57 | struct list_head node; | 59 | struct list_head node; |
58 | struct device *dev; | 60 | struct device *dev; |
59 | struct list_head states; | 61 | struct list_head states; |
60 | struct pinctrl_state *state; | 62 | struct pinctrl_state *state; |
63 | struct list_head dt_maps; | ||
61 | }; | 64 | }; |
62 | 65 | ||
63 | /** | 66 | /** |
@@ -100,7 +103,8 @@ struct pinctrl_setting_configs { | |||
100 | * struct pinctrl_setting - an individual mux or config setting | 103 | * struct pinctrl_setting - an individual mux or config setting |
101 | * @node: list node for struct pinctrl_settings's @settings field | 104 | * @node: list node for struct pinctrl_settings's @settings field |
102 | * @type: the type of setting | 105 | * @type: the type of setting |
103 | * @pctldev: pin control device handling to be programmed | 106 | * @pctldev: pin control device handling to be programmed. Not used for |
107 | * PIN_MAP_TYPE_DUMMY_STATE. | ||
104 | * @data: Data specific to the setting type | 108 | * @data: Data specific to the setting type |
105 | */ | 109 | */ |
106 | struct pinctrl_setting { | 110 | struct pinctrl_setting { |
@@ -144,6 +148,7 @@ struct pin_desc { | |||
144 | 148 | ||
145 | struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); | 149 | struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); |
146 | int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); | 150 | int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); |
151 | const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin); | ||
147 | int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, | 152 | int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, |
148 | const char *pin_group); | 153 | const char *pin_group); |
149 | 154 | ||
@@ -153,4 +158,9 @@ static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev, | |||
153 | return radix_tree_lookup(&pctldev->pin_desc_tree, pin); | 158 | return radix_tree_lookup(&pctldev->pin_desc_tree, pin); |
154 | } | 159 | } |
155 | 160 | ||
161 | int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, | ||
162 | bool dup, bool locked); | ||
163 | void pinctrl_unregister_map(struct pinctrl_map const *map); | ||
164 | |||
156 | extern struct mutex pinctrl_mutex; | 165 | extern struct mutex pinctrl_mutex; |
166 | extern struct list_head pinctrldev_list; | ||
diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c new file mode 100644 index 000000000000..fcb1de45473c --- /dev/null +++ b/drivers/pinctrl/devicetree.c | |||
@@ -0,0 +1,249 @@ | |||
1 | /* | ||
2 | * Device tree integration for the pin control subsystem | ||
3 | * | ||
4 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/pinctrl/pinctrl.h> | ||
22 | #include <linux/slab.h> | ||
23 | |||
24 | #include "core.h" | ||
25 | #include "devicetree.h" | ||
26 | |||
27 | /** | ||
28 | * struct pinctrl_dt_map - mapping table chunk parsed from device tree | ||
29 | * @node: list node for struct pinctrl's @dt_maps field | ||
30 | * @pctldev: the pin controller that allocated this struct, and will free it | ||
31 | * @maps: the mapping table entries | ||
32 | */ | ||
33 | struct pinctrl_dt_map { | ||
34 | struct list_head node; | ||
35 | struct pinctrl_dev *pctldev; | ||
36 | struct pinctrl_map *map; | ||
37 | unsigned num_maps; | ||
38 | }; | ||
39 | |||
40 | static void dt_free_map(struct pinctrl_dev *pctldev, | ||
41 | struct pinctrl_map *map, unsigned num_maps) | ||
42 | { | ||
43 | if (pctldev) { | ||
44 | struct pinctrl_ops *ops = pctldev->desc->pctlops; | ||
45 | ops->dt_free_map(pctldev, map, num_maps); | ||
46 | } else { | ||
47 | /* There is no pctldev for PIN_MAP_TYPE_DUMMY_STATE */ | ||
48 | kfree(map); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void pinctrl_dt_free_maps(struct pinctrl *p) | ||
53 | { | ||
54 | struct pinctrl_dt_map *dt_map, *n1; | ||
55 | |||
56 | list_for_each_entry_safe(dt_map, n1, &p->dt_maps, node) { | ||
57 | pinctrl_unregister_map(dt_map->map); | ||
58 | list_del(&dt_map->node); | ||
59 | dt_free_map(dt_map->pctldev, dt_map->map, | ||
60 | dt_map->num_maps); | ||
61 | kfree(dt_map); | ||
62 | } | ||
63 | |||
64 | of_node_put(p->dev->of_node); | ||
65 | } | ||
66 | |||
67 | static int dt_remember_or_free_map(struct pinctrl *p, const char *statename, | ||
68 | struct pinctrl_dev *pctldev, | ||
69 | struct pinctrl_map *map, unsigned num_maps) | ||
70 | { | ||
71 | int i; | ||
72 | struct pinctrl_dt_map *dt_map; | ||
73 | |||
74 | /* Initialize common mapping table entry fields */ | ||
75 | for (i = 0; i < num_maps; i++) { | ||
76 | map[i].dev_name = dev_name(p->dev); | ||
77 | map[i].name = statename; | ||
78 | if (pctldev) | ||
79 | map[i].ctrl_dev_name = dev_name(pctldev->dev); | ||
80 | } | ||
81 | |||
82 | /* Remember the converted mapping table entries */ | ||
83 | dt_map = kzalloc(sizeof(*dt_map), GFP_KERNEL); | ||
84 | if (!dt_map) { | ||
85 | dev_err(p->dev, "failed to alloc struct pinctrl_dt_map\n"); | ||
86 | dt_free_map(pctldev, map, num_maps); | ||
87 | return -ENOMEM; | ||
88 | } | ||
89 | |||
90 | dt_map->pctldev = pctldev; | ||
91 | dt_map->map = map; | ||
92 | dt_map->num_maps = num_maps; | ||
93 | list_add_tail(&dt_map->node, &p->dt_maps); | ||
94 | |||
95 | return pinctrl_register_map(map, num_maps, false, true); | ||
96 | } | ||
97 | |||
98 | static struct pinctrl_dev *find_pinctrl_by_of_node(struct device_node *np) | ||
99 | { | ||
100 | struct pinctrl_dev *pctldev; | ||
101 | |||
102 | list_for_each_entry(pctldev, &pinctrldev_list, node) | ||
103 | if (pctldev->dev->of_node == np) | ||
104 | return pctldev; | ||
105 | |||
106 | return NULL; | ||
107 | } | ||
108 | |||
109 | static int dt_to_map_one_config(struct pinctrl *p, const char *statename, | ||
110 | struct device_node *np_config) | ||
111 | { | ||
112 | struct device_node *np_pctldev; | ||
113 | struct pinctrl_dev *pctldev; | ||
114 | struct pinctrl_ops *ops; | ||
115 | int ret; | ||
116 | struct pinctrl_map *map; | ||
117 | unsigned num_maps; | ||
118 | |||
119 | /* Find the pin controller containing np_config */ | ||
120 | np_pctldev = of_node_get(np_config); | ||
121 | for (;;) { | ||
122 | np_pctldev = of_get_next_parent(np_pctldev); | ||
123 | if (!np_pctldev || of_node_is_root(np_pctldev)) { | ||
124 | dev_info(p->dev, "could not find pctldev for node %s, deferring probe\n", | ||
125 | np_config->full_name); | ||
126 | of_node_put(np_pctldev); | ||
127 | /* OK let's just assume this will appear later then */ | ||
128 | return -EPROBE_DEFER; | ||
129 | } | ||
130 | pctldev = find_pinctrl_by_of_node(np_pctldev); | ||
131 | if (pctldev) | ||
132 | break; | ||
133 | } | ||
134 | of_node_put(np_pctldev); | ||
135 | |||
136 | /* | ||
137 | * Call pinctrl driver to parse device tree node, and | ||
138 | * generate mapping table entries | ||
139 | */ | ||
140 | ops = pctldev->desc->pctlops; | ||
141 | if (!ops->dt_node_to_map) { | ||
142 | dev_err(p->dev, "pctldev %s doesn't support DT\n", | ||
143 | dev_name(pctldev->dev)); | ||
144 | return -ENODEV; | ||
145 | } | ||
146 | ret = ops->dt_node_to_map(pctldev, np_config, &map, &num_maps); | ||
147 | if (ret < 0) | ||
148 | return ret; | ||
149 | |||
150 | /* Stash the mapping table chunk away for later use */ | ||
151 | return dt_remember_or_free_map(p, statename, pctldev, map, num_maps); | ||
152 | } | ||
153 | |||
154 | static int dt_remember_dummy_state(struct pinctrl *p, const char *statename) | ||
155 | { | ||
156 | struct pinctrl_map *map; | ||
157 | |||
158 | map = kzalloc(sizeof(*map), GFP_KERNEL); | ||
159 | if (!map) { | ||
160 | dev_err(p->dev, "failed to alloc struct pinctrl_map\n"); | ||
161 | return -ENOMEM; | ||
162 | } | ||
163 | |||
164 | /* There is no pctldev for PIN_MAP_TYPE_DUMMY_STATE */ | ||
165 | map->type = PIN_MAP_TYPE_DUMMY_STATE; | ||
166 | |||
167 | return dt_remember_or_free_map(p, statename, NULL, map, 1); | ||
168 | } | ||
169 | |||
170 | int pinctrl_dt_to_map(struct pinctrl *p) | ||
171 | { | ||
172 | struct device_node *np = p->dev->of_node; | ||
173 | int state, ret; | ||
174 | char *propname; | ||
175 | struct property *prop; | ||
176 | const char *statename; | ||
177 | const __be32 *list; | ||
178 | int size, config; | ||
179 | phandle phandle; | ||
180 | struct device_node *np_config; | ||
181 | |||
182 | /* CONFIG_OF enabled, p->dev not instantiated from DT */ | ||
183 | if (!np) { | ||
184 | dev_dbg(p->dev, "no of_node; not parsing pinctrl DT\n"); | ||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | /* We may store pointers to property names within the node */ | ||
189 | of_node_get(np); | ||
190 | |||
191 | /* For each defined state ID */ | ||
192 | for (state = 0; ; state++) { | ||
193 | /* Retrieve the pinctrl-* property */ | ||
194 | propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state); | ||
195 | prop = of_find_property(np, propname, &size); | ||
196 | kfree(propname); | ||
197 | if (!prop) | ||
198 | break; | ||
199 | list = prop->value; | ||
200 | size /= sizeof(*list); | ||
201 | |||
202 | /* Determine whether pinctrl-names property names the state */ | ||
203 | ret = of_property_read_string_index(np, "pinctrl-names", | ||
204 | state, &statename); | ||
205 | /* | ||
206 | * If not, statename is just the integer state ID. But rather | ||
207 | * than dynamically allocate it and have to free it later, | ||
208 | * just point part way into the property name for the string. | ||
209 | */ | ||
210 | if (ret < 0) { | ||
211 | /* strlen("pinctrl-") == 8 */ | ||
212 | statename = prop->name + 8; | ||
213 | } | ||
214 | |||
215 | /* For every referenced pin configuration node in it */ | ||
216 | for (config = 0; config < size; config++) { | ||
217 | phandle = be32_to_cpup(list++); | ||
218 | |||
219 | /* Look up the pin configuration node */ | ||
220 | np_config = of_find_node_by_phandle(phandle); | ||
221 | if (!np_config) { | ||
222 | dev_err(p->dev, | ||
223 | "prop %s index %i invalid phandle\n", | ||
224 | prop->name, config); | ||
225 | ret = -EINVAL; | ||
226 | goto err; | ||
227 | } | ||
228 | |||
229 | /* Parse the node */ | ||
230 | ret = dt_to_map_one_config(p, statename, np_config); | ||
231 | of_node_put(np_config); | ||
232 | if (ret < 0) | ||
233 | goto err; | ||
234 | } | ||
235 | |||
236 | /* No entries in DT? Generate a dummy state table entry */ | ||
237 | if (!size) { | ||
238 | ret = dt_remember_dummy_state(p, statename); | ||
239 | if (ret < 0) | ||
240 | goto err; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | return 0; | ||
245 | |||
246 | err: | ||
247 | pinctrl_dt_free_maps(p); | ||
248 | return ret; | ||
249 | } | ||
diff --git a/drivers/pinctrl/devicetree.h b/drivers/pinctrl/devicetree.h new file mode 100644 index 000000000000..760bc4960f58 --- /dev/null +++ b/drivers/pinctrl/devicetree.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * Internal interface to pinctrl device tree integration | ||
3 | * | ||
4 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifdef CONFIG_OF | ||
20 | |||
21 | void pinctrl_dt_free_maps(struct pinctrl *p); | ||
22 | int pinctrl_dt_to_map(struct pinctrl *p); | ||
23 | |||
24 | #else | ||
25 | |||
26 | static inline int pinctrl_dt_to_map(struct pinctrl *p) | ||
27 | { | ||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | static inline void pinctrl_dt_free_maps(struct pinctrl *p) | ||
32 | { | ||
33 | } | ||
34 | |||
35 | #endif | ||
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index 7321e8601294..14f48c96b20d 100644 --- a/drivers/pinctrl/pinconf.c +++ b/drivers/pinctrl/pinconf.c | |||
@@ -379,8 +379,16 @@ int pinconf_apply_setting(struct pinctrl_setting const *setting) | |||
379 | 379 | ||
380 | void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map) | 380 | void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map) |
381 | { | 381 | { |
382 | struct pinctrl_dev *pctldev; | ||
383 | const struct pinconf_ops *confops; | ||
382 | int i; | 384 | int i; |
383 | 385 | ||
386 | pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name); | ||
387 | if (pctldev) | ||
388 | confops = pctldev->desc->confops; | ||
389 | else | ||
390 | confops = NULL; | ||
391 | |||
384 | switch (map->type) { | 392 | switch (map->type) { |
385 | case PIN_MAP_TYPE_CONFIGS_PIN: | 393 | case PIN_MAP_TYPE_CONFIGS_PIN: |
386 | seq_printf(s, "pin "); | 394 | seq_printf(s, "pin "); |
@@ -394,8 +402,15 @@ void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map) | |||
394 | 402 | ||
395 | seq_printf(s, "%s\n", map->data.configs.group_or_pin); | 403 | seq_printf(s, "%s\n", map->data.configs.group_or_pin); |
396 | 404 | ||
397 | for (i = 0; i < map->data.configs.num_configs; i++) | 405 | for (i = 0; i < map->data.configs.num_configs; i++) { |
398 | seq_printf(s, "config %08lx\n", map->data.configs.configs[i]); | 406 | seq_printf(s, "config "); |
407 | if (confops && confops->pin_config_config_dbg_show) | ||
408 | confops->pin_config_config_dbg_show(pctldev, s, | ||
409 | map->data.configs.configs[i]); | ||
410 | else | ||
411 | seq_printf(s, "%08lx", map->data.configs.configs[i]); | ||
412 | seq_printf(s, "\n"); | ||
413 | } | ||
399 | } | 414 | } |
400 | 415 | ||
401 | void pinconf_show_setting(struct seq_file *s, | 416 | void pinconf_show_setting(struct seq_file *s, |
@@ -403,6 +418,7 @@ void pinconf_show_setting(struct seq_file *s, | |||
403 | { | 418 | { |
404 | struct pinctrl_dev *pctldev = setting->pctldev; | 419 | struct pinctrl_dev *pctldev = setting->pctldev; |
405 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | 420 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
421 | const struct pinconf_ops *confops = pctldev->desc->confops; | ||
406 | struct pin_desc *desc; | 422 | struct pin_desc *desc; |
407 | int i; | 423 | int i; |
408 | 424 | ||
@@ -428,8 +444,15 @@ void pinconf_show_setting(struct seq_file *s, | |||
428 | * FIXME: We should really get the pin controler to dump the config | 444 | * FIXME: We should really get the pin controler to dump the config |
429 | * values, so they can be decoded to something meaningful. | 445 | * values, so they can be decoded to something meaningful. |
430 | */ | 446 | */ |
431 | for (i = 0; i < setting->data.configs.num_configs; i++) | 447 | for (i = 0; i < setting->data.configs.num_configs; i++) { |
432 | seq_printf(s, " %08lx", setting->data.configs.configs[i]); | 448 | seq_printf(s, " "); |
449 | if (confops && confops->pin_config_config_dbg_show) | ||
450 | confops->pin_config_config_dbg_show(pctldev, s, | ||
451 | setting->data.configs.configs[i]); | ||
452 | else | ||
453 | seq_printf(s, "%08lx", | ||
454 | setting->data.configs.configs[i]); | ||
455 | } | ||
433 | 456 | ||
434 | seq_printf(s, "\n"); | 457 | seq_printf(s, "\n"); |
435 | } | 458 | } |
@@ -448,10 +471,14 @@ static void pinconf_dump_pin(struct pinctrl_dev *pctldev, | |||
448 | static int pinconf_pins_show(struct seq_file *s, void *what) | 471 | static int pinconf_pins_show(struct seq_file *s, void *what) |
449 | { | 472 | { |
450 | struct pinctrl_dev *pctldev = s->private; | 473 | struct pinctrl_dev *pctldev = s->private; |
474 | const struct pinconf_ops *ops = pctldev->desc->confops; | ||
451 | unsigned i, pin; | 475 | unsigned i, pin; |
452 | 476 | ||
477 | if (!ops || !ops->pin_config_get) | ||
478 | return 0; | ||
479 | |||
453 | seq_puts(s, "Pin config settings per pin\n"); | 480 | seq_puts(s, "Pin config settings per pin\n"); |
454 | seq_puts(s, "Format: pin (name): pinmux setting array\n"); | 481 | seq_puts(s, "Format: pin (name): configs\n"); |
455 | 482 | ||
456 | mutex_lock(&pinctrl_mutex); | 483 | mutex_lock(&pinctrl_mutex); |
457 | 484 | ||
@@ -495,17 +522,18 @@ static int pinconf_groups_show(struct seq_file *s, void *what) | |||
495 | struct pinctrl_dev *pctldev = s->private; | 522 | struct pinctrl_dev *pctldev = s->private; |
496 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | 523 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
497 | const struct pinconf_ops *ops = pctldev->desc->confops; | 524 | const struct pinconf_ops *ops = pctldev->desc->confops; |
525 | unsigned ngroups = pctlops->get_groups_count(pctldev); | ||
498 | unsigned selector = 0; | 526 | unsigned selector = 0; |
499 | 527 | ||
500 | if (!ops || !ops->pin_config_group_get) | 528 | if (!ops || !ops->pin_config_group_get) |
501 | return 0; | 529 | return 0; |
502 | 530 | ||
503 | seq_puts(s, "Pin config settings per pin group\n"); | 531 | seq_puts(s, "Pin config settings per pin group\n"); |
504 | seq_puts(s, "Format: group (name): pinmux setting array\n"); | 532 | seq_puts(s, "Format: group (name): configs\n"); |
505 | 533 | ||
506 | mutex_lock(&pinctrl_mutex); | 534 | mutex_lock(&pinctrl_mutex); |
507 | 535 | ||
508 | while (pctlops->list_groups(pctldev, selector) >= 0) { | 536 | while (selector < ngroups) { |
509 | const char *gname = pctlops->get_group_name(pctldev, selector); | 537 | const char *gname = pctlops->get_group_name(pctldev, selector); |
510 | 538 | ||
511 | seq_printf(s, "%u (%s):", selector, gname); | 539 | seq_printf(s, "%u (%s):", selector, gname); |
diff --git a/drivers/pinctrl/pinconf.h b/drivers/pinctrl/pinconf.h index 54510de5e8c6..e3ed8cb072a5 100644 --- a/drivers/pinctrl/pinconf.h +++ b/drivers/pinctrl/pinconf.h | |||
@@ -19,11 +19,6 @@ int pinconf_map_to_setting(struct pinctrl_map const *map, | |||
19 | struct pinctrl_setting *setting); | 19 | struct pinctrl_setting *setting); |
20 | void pinconf_free_setting(struct pinctrl_setting const *setting); | 20 | void pinconf_free_setting(struct pinctrl_setting const *setting); |
21 | int pinconf_apply_setting(struct pinctrl_setting const *setting); | 21 | int pinconf_apply_setting(struct pinctrl_setting const *setting); |
22 | void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map); | ||
23 | void pinconf_show_setting(struct seq_file *s, | ||
24 | struct pinctrl_setting const *setting); | ||
25 | void pinconf_init_device_debugfs(struct dentry *devroot, | ||
26 | struct pinctrl_dev *pctldev); | ||
27 | 22 | ||
28 | /* | 23 | /* |
29 | * You will only be interested in these if you're using PINCONF | 24 | * You will only be interested in these if you're using PINCONF |
@@ -61,6 +56,18 @@ static inline int pinconf_apply_setting(struct pinctrl_setting const *setting) | |||
61 | return 0; | 56 | return 0; |
62 | } | 57 | } |
63 | 58 | ||
59 | #endif | ||
60 | |||
61 | #if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS) | ||
62 | |||
63 | void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map); | ||
64 | void pinconf_show_setting(struct seq_file *s, | ||
65 | struct pinctrl_setting const *setting); | ||
66 | void pinconf_init_device_debugfs(struct dentry *devroot, | ||
67 | struct pinctrl_dev *pctldev); | ||
68 | |||
69 | #else | ||
70 | |||
64 | static inline void pinconf_show_map(struct seq_file *s, | 71 | static inline void pinconf_show_map(struct seq_file *s, |
65 | struct pinctrl_map const *map) | 72 | struct pinctrl_map const *map) |
66 | { | 73 | { |
diff --git a/drivers/pinctrl/pinctrl-coh901.c b/drivers/pinctrl/pinctrl-coh901.c index 0797eba3e33a..55697a5d7482 100644 --- a/drivers/pinctrl/pinctrl-coh901.c +++ b/drivers/pinctrl/pinctrl-coh901.c | |||
@@ -174,7 +174,7 @@ struct u300_gpio_confdata { | |||
174 | 174 | ||
175 | 175 | ||
176 | /* Initial configuration */ | 176 | /* Initial configuration */ |
177 | static const struct __initdata u300_gpio_confdata | 177 | static const struct __initconst u300_gpio_confdata |
178 | bs335_gpio_config[BS335_GPIO_NUM_PORTS][U300_GPIO_PINS_PER_PORT] = { | 178 | bs335_gpio_config[BS335_GPIO_NUM_PORTS][U300_GPIO_PINS_PER_PORT] = { |
179 | /* Port 0, pins 0-7 */ | 179 | /* Port 0, pins 0-7 */ |
180 | { | 180 | { |
@@ -255,7 +255,7 @@ bs335_gpio_config[BS335_GPIO_NUM_PORTS][U300_GPIO_PINS_PER_PORT] = { | |||
255 | } | 255 | } |
256 | }; | 256 | }; |
257 | 257 | ||
258 | static const struct __initdata u300_gpio_confdata | 258 | static const struct __initconst u300_gpio_confdata |
259 | bs365_gpio_config[BS365_GPIO_NUM_PORTS][U300_GPIO_PINS_PER_PORT] = { | 259 | bs365_gpio_config[BS365_GPIO_NUM_PORTS][U300_GPIO_PINS_PER_PORT] = { |
260 | /* Port 0, pins 0-7 */ | 260 | /* Port 0, pins 0-7 */ |
261 | { | 261 | { |
diff --git a/drivers/pinctrl/pinctrl-pxa3xx.c b/drivers/pinctrl/pinctrl-pxa3xx.c index 079dce0e93e9..7644e42ac211 100644 --- a/drivers/pinctrl/pinctrl-pxa3xx.c +++ b/drivers/pinctrl/pinctrl-pxa3xx.c | |||
@@ -25,20 +25,18 @@ static struct pinctrl_gpio_range pxa3xx_pinctrl_gpio_range = { | |||
25 | .pin_base = 0, | 25 | .pin_base = 0, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | static int pxa3xx_list_groups(struct pinctrl_dev *pctrldev, unsigned selector) | 28 | static int pxa3xx_get_groups_count(struct pinctrl_dev *pctrldev) |
29 | { | 29 | { |
30 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); | 30 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); |
31 | if (selector >= info->num_grps) | 31 | |
32 | return -EINVAL; | 32 | return info->num_grps; |
33 | return 0; | ||
34 | } | 33 | } |
35 | 34 | ||
36 | static const char *pxa3xx_get_group_name(struct pinctrl_dev *pctrldev, | 35 | static const char *pxa3xx_get_group_name(struct pinctrl_dev *pctrldev, |
37 | unsigned selector) | 36 | unsigned selector) |
38 | { | 37 | { |
39 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); | 38 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); |
40 | if (selector >= info->num_grps) | 39 | |
41 | return NULL; | ||
42 | return info->grps[selector].name; | 40 | return info->grps[selector].name; |
43 | } | 41 | } |
44 | 42 | ||
@@ -48,25 +46,23 @@ static int pxa3xx_get_group_pins(struct pinctrl_dev *pctrldev, | |||
48 | unsigned *num_pins) | 46 | unsigned *num_pins) |
49 | { | 47 | { |
50 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); | 48 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); |
51 | if (selector >= info->num_grps) | 49 | |
52 | return -EINVAL; | ||
53 | *pins = info->grps[selector].pins; | 50 | *pins = info->grps[selector].pins; |
54 | *num_pins = info->grps[selector].npins; | 51 | *num_pins = info->grps[selector].npins; |
55 | return 0; | 52 | return 0; |
56 | } | 53 | } |
57 | 54 | ||
58 | static struct pinctrl_ops pxa3xx_pctrl_ops = { | 55 | static struct pinctrl_ops pxa3xx_pctrl_ops = { |
59 | .list_groups = pxa3xx_list_groups, | 56 | .get_groups_count = pxa3xx_get_groups_count, |
60 | .get_group_name = pxa3xx_get_group_name, | 57 | .get_group_name = pxa3xx_get_group_name, |
61 | .get_group_pins = pxa3xx_get_group_pins, | 58 | .get_group_pins = pxa3xx_get_group_pins, |
62 | }; | 59 | }; |
63 | 60 | ||
64 | static int pxa3xx_pmx_list_func(struct pinctrl_dev *pctrldev, unsigned func) | 61 | static int pxa3xx_pmx_get_funcs_count(struct pinctrl_dev *pctrldev) |
65 | { | 62 | { |
66 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); | 63 | struct pxa3xx_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev); |
67 | if (func >= info->num_funcs) | 64 | |
68 | return -EINVAL; | 65 | return info->num_funcs; |
69 | return 0; | ||
70 | } | 66 | } |
71 | 67 | ||
72 | static const char *pxa3xx_pmx_get_func_name(struct pinctrl_dev *pctrldev, | 68 | static const char *pxa3xx_pmx_get_func_name(struct pinctrl_dev *pctrldev, |
@@ -170,7 +166,7 @@ static int pxa3xx_pmx_request_gpio(struct pinctrl_dev *pctrldev, | |||
170 | } | 166 | } |
171 | 167 | ||
172 | static struct pinmux_ops pxa3xx_pmx_ops = { | 168 | static struct pinmux_ops pxa3xx_pmx_ops = { |
173 | .list_functions = pxa3xx_pmx_list_func, | 169 | .get_functions_count = pxa3xx_pmx_get_funcs_count, |
174 | .get_function_name = pxa3xx_pmx_get_func_name, | 170 | .get_function_name = pxa3xx_pmx_get_func_name, |
175 | .get_function_groups = pxa3xx_pmx_get_groups, | 171 | .get_function_groups = pxa3xx_pmx_get_groups, |
176 | .enable = pxa3xx_pmx_enable, | 172 | .enable = pxa3xx_pmx_enable, |
diff --git a/drivers/pinctrl/pinctrl-sirf.c b/drivers/pinctrl/pinctrl-sirf.c index 6b3534cc051a..ba15b1a29e52 100644 --- a/drivers/pinctrl/pinctrl-sirf.c +++ b/drivers/pinctrl/pinctrl-sirf.c | |||
@@ -853,18 +853,14 @@ static const struct sirfsoc_pin_group sirfsoc_pin_groups[] = { | |||
853 | SIRFSOC_PIN_GROUP("gpsgrp", gps_pins), | 853 | SIRFSOC_PIN_GROUP("gpsgrp", gps_pins), |
854 | }; | 854 | }; |
855 | 855 | ||
856 | static int sirfsoc_list_groups(struct pinctrl_dev *pctldev, unsigned selector) | 856 | static int sirfsoc_get_groups_count(struct pinctrl_dev *pctldev) |
857 | { | 857 | { |
858 | if (selector >= ARRAY_SIZE(sirfsoc_pin_groups)) | 858 | return ARRAY_SIZE(sirfsoc_pin_groups); |
859 | return -EINVAL; | ||
860 | return 0; | ||
861 | } | 859 | } |
862 | 860 | ||
863 | static const char *sirfsoc_get_group_name(struct pinctrl_dev *pctldev, | 861 | static const char *sirfsoc_get_group_name(struct pinctrl_dev *pctldev, |
864 | unsigned selector) | 862 | unsigned selector) |
865 | { | 863 | { |
866 | if (selector >= ARRAY_SIZE(sirfsoc_pin_groups)) | ||
867 | return NULL; | ||
868 | return sirfsoc_pin_groups[selector].name; | 864 | return sirfsoc_pin_groups[selector].name; |
869 | } | 865 | } |
870 | 866 | ||
@@ -872,8 +868,6 @@ static int sirfsoc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector | |||
872 | const unsigned **pins, | 868 | const unsigned **pins, |
873 | unsigned *num_pins) | 869 | unsigned *num_pins) |
874 | { | 870 | { |
875 | if (selector >= ARRAY_SIZE(sirfsoc_pin_groups)) | ||
876 | return -EINVAL; | ||
877 | *pins = sirfsoc_pin_groups[selector].pins; | 871 | *pins = sirfsoc_pin_groups[selector].pins; |
878 | *num_pins = sirfsoc_pin_groups[selector].num_pins; | 872 | *num_pins = sirfsoc_pin_groups[selector].num_pins; |
879 | return 0; | 873 | return 0; |
@@ -886,7 +880,7 @@ static void sirfsoc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s | |||
886 | } | 880 | } |
887 | 881 | ||
888 | static struct pinctrl_ops sirfsoc_pctrl_ops = { | 882 | static struct pinctrl_ops sirfsoc_pctrl_ops = { |
889 | .list_groups = sirfsoc_list_groups, | 883 | .get_groups_count = sirfsoc_get_groups_count, |
890 | .get_group_name = sirfsoc_get_group_name, | 884 | .get_group_name = sirfsoc_get_group_name, |
891 | .get_group_pins = sirfsoc_get_group_pins, | 885 | .get_group_pins = sirfsoc_get_group_pins, |
892 | .pin_dbg_show = sirfsoc_pin_dbg_show, | 886 | .pin_dbg_show = sirfsoc_pin_dbg_show, |
@@ -1033,11 +1027,9 @@ static void sirfsoc_pinmux_disable(struct pinctrl_dev *pmxdev, unsigned selector | |||
1033 | sirfsoc_pinmux_endisable(spmx, selector, false); | 1027 | sirfsoc_pinmux_endisable(spmx, selector, false); |
1034 | } | 1028 | } |
1035 | 1029 | ||
1036 | static int sirfsoc_pinmux_list_funcs(struct pinctrl_dev *pmxdev, unsigned selector) | 1030 | static int sirfsoc_pinmux_get_funcs_count(struct pinctrl_dev *pmxdev) |
1037 | { | 1031 | { |
1038 | if (selector >= ARRAY_SIZE(sirfsoc_pmx_functions)) | 1032 | return ARRAY_SIZE(sirfsoc_pmx_functions); |
1039 | return -EINVAL; | ||
1040 | return 0; | ||
1041 | } | 1033 | } |
1042 | 1034 | ||
1043 | static const char *sirfsoc_pinmux_get_func_name(struct pinctrl_dev *pctldev, | 1035 | static const char *sirfsoc_pinmux_get_func_name(struct pinctrl_dev *pctldev, |
@@ -1074,9 +1066,9 @@ static int sirfsoc_pinmux_request_gpio(struct pinctrl_dev *pmxdev, | |||
1074 | } | 1066 | } |
1075 | 1067 | ||
1076 | static struct pinmux_ops sirfsoc_pinmux_ops = { | 1068 | static struct pinmux_ops sirfsoc_pinmux_ops = { |
1077 | .list_functions = sirfsoc_pinmux_list_funcs, | ||
1078 | .enable = sirfsoc_pinmux_enable, | 1069 | .enable = sirfsoc_pinmux_enable, |
1079 | .disable = sirfsoc_pinmux_disable, | 1070 | .disable = sirfsoc_pinmux_disable, |
1071 | .get_functions_count = sirfsoc_pinmux_get_funcs_count, | ||
1080 | .get_function_name = sirfsoc_pinmux_get_func_name, | 1072 | .get_function_name = sirfsoc_pinmux_get_func_name, |
1081 | .get_function_groups = sirfsoc_pinmux_get_groups, | 1073 | .get_function_groups = sirfsoc_pinmux_get_groups, |
1082 | .gpio_request_enable = sirfsoc_pinmux_request_gpio, | 1074 | .gpio_request_enable = sirfsoc_pinmux_request_gpio, |
diff --git a/drivers/pinctrl/pinctrl-tegra.c b/drivers/pinctrl/pinctrl-tegra.c index 9b329688120c..2c98fba01ca5 100644 --- a/drivers/pinctrl/pinctrl-tegra.c +++ b/drivers/pinctrl/pinctrl-tegra.c | |||
@@ -23,9 +23,11 @@ | |||
23 | #include <linux/io.h> | 23 | #include <linux/io.h> |
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/of_device.h> | 25 | #include <linux/of_device.h> |
26 | #include <linux/pinctrl/machine.h> | ||
26 | #include <linux/pinctrl/pinctrl.h> | 27 | #include <linux/pinctrl/pinctrl.h> |
27 | #include <linux/pinctrl/pinmux.h> | 28 | #include <linux/pinctrl/pinmux.h> |
28 | #include <linux/pinctrl/pinconf.h> | 29 | #include <linux/pinctrl/pinconf.h> |
30 | #include <linux/slab.h> | ||
29 | 31 | ||
30 | #include <mach/pinconf-tegra.h> | 32 | #include <mach/pinconf-tegra.h> |
31 | 33 | ||
@@ -53,15 +55,11 @@ static inline void pmx_writel(struct tegra_pmx *pmx, u32 val, u32 bank, u32 reg) | |||
53 | writel(val, pmx->regs[bank] + reg); | 55 | writel(val, pmx->regs[bank] + reg); |
54 | } | 56 | } |
55 | 57 | ||
56 | static int tegra_pinctrl_list_groups(struct pinctrl_dev *pctldev, | 58 | static int tegra_pinctrl_get_groups_count(struct pinctrl_dev *pctldev) |
57 | unsigned group) | ||
58 | { | 59 | { |
59 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); | 60 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); |
60 | 61 | ||
61 | if (group >= pmx->soc->ngroups) | 62 | return pmx->soc->ngroups; |
62 | return -EINVAL; | ||
63 | |||
64 | return 0; | ||
65 | } | 63 | } |
66 | 64 | ||
67 | static const char *tegra_pinctrl_get_group_name(struct pinctrl_dev *pctldev, | 65 | static const char *tegra_pinctrl_get_group_name(struct pinctrl_dev *pctldev, |
@@ -69,9 +67,6 @@ static const char *tegra_pinctrl_get_group_name(struct pinctrl_dev *pctldev, | |||
69 | { | 67 | { |
70 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); | 68 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); |
71 | 69 | ||
72 | if (group >= pmx->soc->ngroups) | ||
73 | return NULL; | ||
74 | |||
75 | return pmx->soc->groups[group].name; | 70 | return pmx->soc->groups[group].name; |
76 | } | 71 | } |
77 | 72 | ||
@@ -82,9 +77,6 @@ static int tegra_pinctrl_get_group_pins(struct pinctrl_dev *pctldev, | |||
82 | { | 77 | { |
83 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); | 78 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); |
84 | 79 | ||
85 | if (group >= pmx->soc->ngroups) | ||
86 | return -EINVAL; | ||
87 | |||
88 | *pins = pmx->soc->groups[group].pins; | 80 | *pins = pmx->soc->groups[group].pins; |
89 | *num_pins = pmx->soc->groups[group].npins; | 81 | *num_pins = pmx->soc->groups[group].npins; |
90 | 82 | ||
@@ -98,22 +90,221 @@ static void tegra_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev, | |||
98 | seq_printf(s, " " DRIVER_NAME); | 90 | seq_printf(s, " " DRIVER_NAME); |
99 | } | 91 | } |
100 | 92 | ||
93 | static int reserve_map(struct pinctrl_map **map, unsigned *reserved_maps, | ||
94 | unsigned *num_maps, unsigned reserve) | ||
95 | { | ||
96 | unsigned old_num = *reserved_maps; | ||
97 | unsigned new_num = *num_maps + reserve; | ||
98 | struct pinctrl_map *new_map; | ||
99 | |||
100 | if (old_num >= new_num) | ||
101 | return 0; | ||
102 | |||
103 | new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL); | ||
104 | if (!new_map) | ||
105 | return -ENOMEM; | ||
106 | |||
107 | memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map)); | ||
108 | |||
109 | *map = new_map; | ||
110 | *reserved_maps = new_num; | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static int add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps, | ||
116 | unsigned *num_maps, const char *group, | ||
117 | const char *function) | ||
118 | { | ||
119 | if (*num_maps == *reserved_maps) | ||
120 | return -ENOSPC; | ||
121 | |||
122 | (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP; | ||
123 | (*map)[*num_maps].data.mux.group = group; | ||
124 | (*map)[*num_maps].data.mux.function = function; | ||
125 | (*num_maps)++; | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static int add_map_configs(struct pinctrl_map **map, unsigned *reserved_maps, | ||
131 | unsigned *num_maps, const char *group, | ||
132 | unsigned long *configs, unsigned num_configs) | ||
133 | { | ||
134 | unsigned long *dup_configs; | ||
135 | |||
136 | if (*num_maps == *reserved_maps) | ||
137 | return -ENOSPC; | ||
138 | |||
139 | dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs), | ||
140 | GFP_KERNEL); | ||
141 | if (!dup_configs) | ||
142 | return -ENOMEM; | ||
143 | |||
144 | (*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP; | ||
145 | (*map)[*num_maps].data.configs.group_or_pin = group; | ||
146 | (*map)[*num_maps].data.configs.configs = dup_configs; | ||
147 | (*map)[*num_maps].data.configs.num_configs = num_configs; | ||
148 | (*num_maps)++; | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static int add_config(unsigned long **configs, unsigned *num_configs, | ||
154 | unsigned long config) | ||
155 | { | ||
156 | unsigned old_num = *num_configs; | ||
157 | unsigned new_num = old_num + 1; | ||
158 | unsigned long *new_configs; | ||
159 | |||
160 | new_configs = krealloc(*configs, sizeof(*new_configs) * new_num, | ||
161 | GFP_KERNEL); | ||
162 | if (!new_configs) | ||
163 | return -ENOMEM; | ||
164 | |||
165 | new_configs[old_num] = config; | ||
166 | |||
167 | *configs = new_configs; | ||
168 | *num_configs = new_num; | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | void tegra_pinctrl_dt_free_map(struct pinctrl_dev *pctldev, | ||
174 | struct pinctrl_map *map, unsigned num_maps) | ||
175 | { | ||
176 | int i; | ||
177 | |||
178 | for (i = 0; i < num_maps; i++) | ||
179 | if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP) | ||
180 | kfree(map[i].data.configs.configs); | ||
181 | |||
182 | kfree(map); | ||
183 | } | ||
184 | |||
185 | static const struct cfg_param { | ||
186 | const char *property; | ||
187 | enum tegra_pinconf_param param; | ||
188 | } cfg_params[] = { | ||
189 | {"nvidia,pull", TEGRA_PINCONF_PARAM_PULL}, | ||
190 | {"nvidia,tristate", TEGRA_PINCONF_PARAM_TRISTATE}, | ||
191 | {"nvidia,enable-input", TEGRA_PINCONF_PARAM_ENABLE_INPUT}, | ||
192 | {"nvidia,open-drain", TEGRA_PINCONF_PARAM_OPEN_DRAIN}, | ||
193 | {"nvidia,lock", TEGRA_PINCONF_PARAM_LOCK}, | ||
194 | {"nvidia,io-reset", TEGRA_PINCONF_PARAM_IORESET}, | ||
195 | {"nvidia,high-speed-mode", TEGRA_PINCONF_PARAM_HIGH_SPEED_MODE}, | ||
196 | {"nvidia,schmitt", TEGRA_PINCONF_PARAM_SCHMITT}, | ||
197 | {"nvidia,low-power-mode", TEGRA_PINCONF_PARAM_LOW_POWER_MODE}, | ||
198 | {"nvidia,pull-down-strength", TEGRA_PINCONF_PARAM_DRIVE_DOWN_STRENGTH}, | ||
199 | {"nvidia,pull-up-strength", TEGRA_PINCONF_PARAM_DRIVE_UP_STRENGTH}, | ||
200 | {"nvidia,slew-rate-falling", TEGRA_PINCONF_PARAM_SLEW_RATE_FALLING}, | ||
201 | {"nvidia,slew-rate-rising", TEGRA_PINCONF_PARAM_SLEW_RATE_RISING}, | ||
202 | }; | ||
203 | |||
204 | int tegra_pinctrl_dt_subnode_to_map(struct device_node *np, | ||
205 | struct pinctrl_map **map, | ||
206 | unsigned *reserved_maps, | ||
207 | unsigned *num_maps) | ||
208 | { | ||
209 | int ret, i; | ||
210 | const char *function; | ||
211 | u32 val; | ||
212 | unsigned long config; | ||
213 | unsigned long *configs = NULL; | ||
214 | unsigned num_configs = 0; | ||
215 | unsigned reserve; | ||
216 | struct property *prop; | ||
217 | const char *group; | ||
218 | |||
219 | ret = of_property_read_string(np, "nvidia,function", &function); | ||
220 | if (ret < 0) | ||
221 | function = NULL; | ||
222 | |||
223 | for (i = 0; i < ARRAY_SIZE(cfg_params); i++) { | ||
224 | ret = of_property_read_u32(np, cfg_params[i].property, &val); | ||
225 | if (!ret) { | ||
226 | config = TEGRA_PINCONF_PACK(cfg_params[i].param, val); | ||
227 | ret = add_config(&configs, &num_configs, config); | ||
228 | if (ret < 0) | ||
229 | goto exit; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | reserve = 0; | ||
234 | if (function != NULL) | ||
235 | reserve++; | ||
236 | if (num_configs) | ||
237 | reserve++; | ||
238 | ret = of_property_count_strings(np, "nvidia,pins"); | ||
239 | if (ret < 0) | ||
240 | goto exit; | ||
241 | reserve *= ret; | ||
242 | |||
243 | ret = reserve_map(map, reserved_maps, num_maps, reserve); | ||
244 | if (ret < 0) | ||
245 | goto exit; | ||
246 | |||
247 | of_property_for_each_string(np, "nvidia,pins", prop, group) { | ||
248 | if (function) { | ||
249 | ret = add_map_mux(map, reserved_maps, num_maps, | ||
250 | group, function); | ||
251 | if (ret < 0) | ||
252 | goto exit; | ||
253 | } | ||
254 | |||
255 | if (num_configs) { | ||
256 | ret = add_map_configs(map, reserved_maps, num_maps, | ||
257 | group, configs, num_configs); | ||
258 | if (ret < 0) | ||
259 | goto exit; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | ret = 0; | ||
264 | |||
265 | exit: | ||
266 | kfree(configs); | ||
267 | return ret; | ||
268 | } | ||
269 | |||
270 | int tegra_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, | ||
271 | struct device_node *np_config, | ||
272 | struct pinctrl_map **map, unsigned *num_maps) | ||
273 | { | ||
274 | unsigned reserved_maps; | ||
275 | struct device_node *np; | ||
276 | int ret; | ||
277 | |||
278 | reserved_maps = 0; | ||
279 | *map = NULL; | ||
280 | *num_maps = 0; | ||
281 | |||
282 | for_each_child_of_node(np_config, np) { | ||
283 | ret = tegra_pinctrl_dt_subnode_to_map(np, map, &reserved_maps, | ||
284 | num_maps); | ||
285 | if (ret < 0) { | ||
286 | tegra_pinctrl_dt_free_map(pctldev, *map, *num_maps); | ||
287 | return ret; | ||
288 | } | ||
289 | } | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
101 | static struct pinctrl_ops tegra_pinctrl_ops = { | 294 | static struct pinctrl_ops tegra_pinctrl_ops = { |
102 | .list_groups = tegra_pinctrl_list_groups, | 295 | .get_groups_count = tegra_pinctrl_get_groups_count, |
103 | .get_group_name = tegra_pinctrl_get_group_name, | 296 | .get_group_name = tegra_pinctrl_get_group_name, |
104 | .get_group_pins = tegra_pinctrl_get_group_pins, | 297 | .get_group_pins = tegra_pinctrl_get_group_pins, |
105 | .pin_dbg_show = tegra_pinctrl_pin_dbg_show, | 298 | .pin_dbg_show = tegra_pinctrl_pin_dbg_show, |
299 | .dt_node_to_map = tegra_pinctrl_dt_node_to_map, | ||
300 | .dt_free_map = tegra_pinctrl_dt_free_map, | ||
106 | }; | 301 | }; |
107 | 302 | ||
108 | static int tegra_pinctrl_list_funcs(struct pinctrl_dev *pctldev, | 303 | static int tegra_pinctrl_get_funcs_count(struct pinctrl_dev *pctldev) |
109 | unsigned function) | ||
110 | { | 304 | { |
111 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); | 305 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); |
112 | 306 | ||
113 | if (function >= pmx->soc->nfunctions) | 307 | return pmx->soc->nfunctions; |
114 | return -EINVAL; | ||
115 | |||
116 | return 0; | ||
117 | } | 308 | } |
118 | 309 | ||
119 | static const char *tegra_pinctrl_get_func_name(struct pinctrl_dev *pctldev, | 310 | static const char *tegra_pinctrl_get_func_name(struct pinctrl_dev *pctldev, |
@@ -121,9 +312,6 @@ static const char *tegra_pinctrl_get_func_name(struct pinctrl_dev *pctldev, | |||
121 | { | 312 | { |
122 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); | 313 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); |
123 | 314 | ||
124 | if (function >= pmx->soc->nfunctions) | ||
125 | return NULL; | ||
126 | |||
127 | return pmx->soc->functions[function].name; | 315 | return pmx->soc->functions[function].name; |
128 | } | 316 | } |
129 | 317 | ||
@@ -134,9 +322,6 @@ static int tegra_pinctrl_get_func_groups(struct pinctrl_dev *pctldev, | |||
134 | { | 322 | { |
135 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); | 323 | struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev); |
136 | 324 | ||
137 | if (function >= pmx->soc->nfunctions) | ||
138 | return -EINVAL; | ||
139 | |||
140 | *groups = pmx->soc->functions[function].groups; | 325 | *groups = pmx->soc->functions[function].groups; |
141 | *num_groups = pmx->soc->functions[function].ngroups; | 326 | *num_groups = pmx->soc->functions[function].ngroups; |
142 | 327 | ||
@@ -151,8 +336,6 @@ static int tegra_pinctrl_enable(struct pinctrl_dev *pctldev, unsigned function, | |||
151 | int i; | 336 | int i; |
152 | u32 val; | 337 | u32 val; |
153 | 338 | ||
154 | if (group >= pmx->soc->ngroups) | ||
155 | return -EINVAL; | ||
156 | g = &pmx->soc->groups[group]; | 339 | g = &pmx->soc->groups[group]; |
157 | 340 | ||
158 | if (g->mux_reg < 0) | 341 | if (g->mux_reg < 0) |
@@ -180,8 +363,6 @@ static void tegra_pinctrl_disable(struct pinctrl_dev *pctldev, | |||
180 | const struct tegra_pingroup *g; | 363 | const struct tegra_pingroup *g; |
181 | u32 val; | 364 | u32 val; |
182 | 365 | ||
183 | if (group >= pmx->soc->ngroups) | ||
184 | return; | ||
185 | g = &pmx->soc->groups[group]; | 366 | g = &pmx->soc->groups[group]; |
186 | 367 | ||
187 | if (g->mux_reg < 0) | 368 | if (g->mux_reg < 0) |
@@ -194,7 +375,7 @@ static void tegra_pinctrl_disable(struct pinctrl_dev *pctldev, | |||
194 | } | 375 | } |
195 | 376 | ||
196 | static struct pinmux_ops tegra_pinmux_ops = { | 377 | static struct pinmux_ops tegra_pinmux_ops = { |
197 | .list_functions = tegra_pinctrl_list_funcs, | 378 | .get_functions_count = tegra_pinctrl_get_funcs_count, |
198 | .get_function_name = tegra_pinctrl_get_func_name, | 379 | .get_function_name = tegra_pinctrl_get_func_name, |
199 | .get_function_groups = tegra_pinctrl_get_func_groups, | 380 | .get_function_groups = tegra_pinctrl_get_func_groups, |
200 | .enable = tegra_pinctrl_enable, | 381 | .enable = tegra_pinctrl_enable, |
@@ -324,8 +505,6 @@ static int tegra_pinconf_group_get(struct pinctrl_dev *pctldev, | |||
324 | s16 reg; | 505 | s16 reg; |
325 | u32 val, mask; | 506 | u32 val, mask; |
326 | 507 | ||
327 | if (group >= pmx->soc->ngroups) | ||
328 | return -EINVAL; | ||
329 | g = &pmx->soc->groups[group]; | 508 | g = &pmx->soc->groups[group]; |
330 | 509 | ||
331 | ret = tegra_pinconf_reg(pmx, g, param, &bank, ®, &bit, &width); | 510 | ret = tegra_pinconf_reg(pmx, g, param, &bank, ®, &bit, &width); |
@@ -353,8 +532,6 @@ static int tegra_pinconf_group_set(struct pinctrl_dev *pctldev, | |||
353 | s16 reg; | 532 | s16 reg; |
354 | u32 val, mask; | 533 | u32 val, mask; |
355 | 534 | ||
356 | if (group >= pmx->soc->ngroups) | ||
357 | return -EINVAL; | ||
358 | g = &pmx->soc->groups[group]; | 535 | g = &pmx->soc->groups[group]; |
359 | 536 | ||
360 | ret = tegra_pinconf_reg(pmx, g, param, &bank, ®, &bit, &width); | 537 | ret = tegra_pinconf_reg(pmx, g, param, &bank, ®, &bit, &width); |
diff --git a/drivers/pinctrl/pinctrl-u300.c b/drivers/pinctrl/pinctrl-u300.c index 26eb8ccd72d5..05d029911be6 100644 --- a/drivers/pinctrl/pinctrl-u300.c +++ b/drivers/pinctrl/pinctrl-u300.c | |||
@@ -836,18 +836,14 @@ static const struct u300_pin_group u300_pin_groups[] = { | |||
836 | }, | 836 | }, |
837 | }; | 837 | }; |
838 | 838 | ||
839 | static int u300_list_groups(struct pinctrl_dev *pctldev, unsigned selector) | 839 | static int u300_get_groups_count(struct pinctrl_dev *pctldev) |
840 | { | 840 | { |
841 | if (selector >= ARRAY_SIZE(u300_pin_groups)) | 841 | return ARRAY_SIZE(u300_pin_groups); |
842 | return -EINVAL; | ||
843 | return 0; | ||
844 | } | 842 | } |
845 | 843 | ||
846 | static const char *u300_get_group_name(struct pinctrl_dev *pctldev, | 844 | static const char *u300_get_group_name(struct pinctrl_dev *pctldev, |
847 | unsigned selector) | 845 | unsigned selector) |
848 | { | 846 | { |
849 | if (selector >= ARRAY_SIZE(u300_pin_groups)) | ||
850 | return NULL; | ||
851 | return u300_pin_groups[selector].name; | 847 | return u300_pin_groups[selector].name; |
852 | } | 848 | } |
853 | 849 | ||
@@ -855,8 +851,6 @@ static int u300_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector, | |||
855 | const unsigned **pins, | 851 | const unsigned **pins, |
856 | unsigned *num_pins) | 852 | unsigned *num_pins) |
857 | { | 853 | { |
858 | if (selector >= ARRAY_SIZE(u300_pin_groups)) | ||
859 | return -EINVAL; | ||
860 | *pins = u300_pin_groups[selector].pins; | 854 | *pins = u300_pin_groups[selector].pins; |
861 | *num_pins = u300_pin_groups[selector].num_pins; | 855 | *num_pins = u300_pin_groups[selector].num_pins; |
862 | return 0; | 856 | return 0; |
@@ -869,7 +863,7 @@ static void u300_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, | |||
869 | } | 863 | } |
870 | 864 | ||
871 | static struct pinctrl_ops u300_pctrl_ops = { | 865 | static struct pinctrl_ops u300_pctrl_ops = { |
872 | .list_groups = u300_list_groups, | 866 | .get_groups_count = u300_get_groups_count, |
873 | .get_group_name = u300_get_group_name, | 867 | .get_group_name = u300_get_group_name, |
874 | .get_group_pins = u300_get_group_pins, | 868 | .get_group_pins = u300_get_group_pins, |
875 | .pin_dbg_show = u300_pin_dbg_show, | 869 | .pin_dbg_show = u300_pin_dbg_show, |
@@ -991,11 +985,9 @@ static void u300_pmx_disable(struct pinctrl_dev *pctldev, unsigned selector, | |||
991 | u300_pmx_endisable(upmx, selector, false); | 985 | u300_pmx_endisable(upmx, selector, false); |
992 | } | 986 | } |
993 | 987 | ||
994 | static int u300_pmx_list_funcs(struct pinctrl_dev *pctldev, unsigned selector) | 988 | static int u300_pmx_get_funcs_count(struct pinctrl_dev *pctldev) |
995 | { | 989 | { |
996 | if (selector >= ARRAY_SIZE(u300_pmx_functions)) | 990 | return ARRAY_SIZE(u300_pmx_functions); |
997 | return -EINVAL; | ||
998 | return 0; | ||
999 | } | 991 | } |
1000 | 992 | ||
1001 | static const char *u300_pmx_get_func_name(struct pinctrl_dev *pctldev, | 993 | static const char *u300_pmx_get_func_name(struct pinctrl_dev *pctldev, |
@@ -1014,7 +1006,7 @@ static int u300_pmx_get_groups(struct pinctrl_dev *pctldev, unsigned selector, | |||
1014 | } | 1006 | } |
1015 | 1007 | ||
1016 | static struct pinmux_ops u300_pmx_ops = { | 1008 | static struct pinmux_ops u300_pmx_ops = { |
1017 | .list_functions = u300_pmx_list_funcs, | 1009 | .get_functions_count = u300_pmx_get_funcs_count, |
1018 | .get_function_name = u300_pmx_get_func_name, | 1010 | .get_function_name = u300_pmx_get_func_name, |
1019 | .get_function_groups = u300_pmx_get_groups, | 1011 | .get_function_groups = u300_pmx_get_groups, |
1020 | .enable = u300_pmx_enable, | 1012 | .enable = u300_pmx_enable, |
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 4e62783a573a..fa0357bd88ff 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c | |||
@@ -33,10 +33,12 @@ | |||
33 | int pinmux_check_ops(struct pinctrl_dev *pctldev) | 33 | int pinmux_check_ops(struct pinctrl_dev *pctldev) |
34 | { | 34 | { |
35 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | 35 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
36 | unsigned nfuncs; | ||
36 | unsigned selector = 0; | 37 | unsigned selector = 0; |
37 | 38 | ||
38 | /* Check that we implement required operations */ | 39 | /* Check that we implement required operations */ |
39 | if (!ops->list_functions || | 40 | if (!ops || |
41 | !ops->get_functions_count || | ||
40 | !ops->get_function_name || | 42 | !ops->get_function_name || |
41 | !ops->get_function_groups || | 43 | !ops->get_function_groups || |
42 | !ops->enable || | 44 | !ops->enable || |
@@ -44,11 +46,12 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev) | |||
44 | return -EINVAL; | 46 | return -EINVAL; |
45 | 47 | ||
46 | /* Check that all functions registered have names */ | 48 | /* Check that all functions registered have names */ |
47 | while (ops->list_functions(pctldev, selector) >= 0) { | 49 | nfuncs = ops->get_functions_count(pctldev); |
50 | while (selector < nfuncs) { | ||
48 | const char *fname = ops->get_function_name(pctldev, | 51 | const char *fname = ops->get_function_name(pctldev, |
49 | selector); | 52 | selector); |
50 | if (!fname) { | 53 | if (!fname) { |
51 | pr_err("pinmux ops has no name for function%u\n", | 54 | dev_err(pctldev->dev, "pinmux ops has no name for function%u\n", |
52 | selector); | 55 | selector); |
53 | return -EINVAL; | 56 | return -EINVAL; |
54 | } | 57 | } |
@@ -85,8 +88,6 @@ static int pin_request(struct pinctrl_dev *pctldev, | |||
85 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | 88 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
86 | int status = -EINVAL; | 89 | int status = -EINVAL; |
87 | 90 | ||
88 | dev_dbg(pctldev->dev, "request pin %d for %s\n", pin, owner); | ||
89 | |||
90 | desc = pin_desc_get(pctldev, pin); | 91 | desc = pin_desc_get(pctldev, pin); |
91 | if (desc == NULL) { | 92 | if (desc == NULL) { |
92 | dev_err(pctldev->dev, | 93 | dev_err(pctldev->dev, |
@@ -94,6 +95,9 @@ static int pin_request(struct pinctrl_dev *pctldev, | |||
94 | goto out; | 95 | goto out; |
95 | } | 96 | } |
96 | 97 | ||
98 | dev_dbg(pctldev->dev, "request pin %d (%s) for %s\n", | ||
99 | pin, desc->name, owner); | ||
100 | |||
97 | if (gpio_range) { | 101 | if (gpio_range) { |
98 | /* There's no need to support multiple GPIO requests */ | 102 | /* There's no need to support multiple GPIO requests */ |
99 | if (desc->gpio_owner) { | 103 | if (desc->gpio_owner) { |
@@ -287,10 +291,11 @@ static int pinmux_func_name_to_selector(struct pinctrl_dev *pctldev, | |||
287 | const char *function) | 291 | const char *function) |
288 | { | 292 | { |
289 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | 293 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
294 | unsigned nfuncs = ops->get_functions_count(pctldev); | ||
290 | unsigned selector = 0; | 295 | unsigned selector = 0; |
291 | 296 | ||
292 | /* See if this pctldev has this function */ | 297 | /* See if this pctldev has this function */ |
293 | while (ops->list_functions(pctldev, selector) >= 0) { | 298 | while (selector < nfuncs) { |
294 | const char *fname = ops->get_function_name(pctldev, | 299 | const char *fname = ops->get_function_name(pctldev, |
295 | selector); | 300 | selector); |
296 | 301 | ||
@@ -319,6 +324,11 @@ int pinmux_map_to_setting(struct pinctrl_map const *map, | |||
319 | const unsigned *pins; | 324 | const unsigned *pins; |
320 | unsigned num_pins; | 325 | unsigned num_pins; |
321 | 326 | ||
327 | if (!pmxops) { | ||
328 | dev_err(pctldev->dev, "does not support mux function\n"); | ||
329 | return -EINVAL; | ||
330 | } | ||
331 | |||
322 | setting->data.mux.func = | 332 | setting->data.mux.func = |
323 | pinmux_func_name_to_selector(pctldev, map->data.mux.function); | 333 | pinmux_func_name_to_selector(pctldev, map->data.mux.function); |
324 | if (setting->data.mux.func < 0) | 334 | if (setting->data.mux.func < 0) |
@@ -477,11 +487,15 @@ static int pinmux_functions_show(struct seq_file *s, void *what) | |||
477 | { | 487 | { |
478 | struct pinctrl_dev *pctldev = s->private; | 488 | struct pinctrl_dev *pctldev = s->private; |
479 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; | 489 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; |
490 | unsigned nfuncs; | ||
480 | unsigned func_selector = 0; | 491 | unsigned func_selector = 0; |
481 | 492 | ||
482 | mutex_lock(&pinctrl_mutex); | 493 | if (!pmxops) |
494 | return 0; | ||
483 | 495 | ||
484 | while (pmxops->list_functions(pctldev, func_selector) >= 0) { | 496 | mutex_lock(&pinctrl_mutex); |
497 | nfuncs = pmxops->get_functions_count(pctldev); | ||
498 | while (func_selector < nfuncs) { | ||
485 | const char *func = pmxops->get_function_name(pctldev, | 499 | const char *func = pmxops->get_function_name(pctldev, |
486 | func_selector); | 500 | func_selector); |
487 | const char * const *groups; | 501 | const char * const *groups; |
@@ -515,6 +529,9 @@ static int pinmux_pins_show(struct seq_file *s, void *what) | |||
515 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; | 529 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; |
516 | unsigned i, pin; | 530 | unsigned i, pin; |
517 | 531 | ||
532 | if (!pmxops) | ||
533 | return 0; | ||
534 | |||
518 | seq_puts(s, "Pinmux settings per pin\n"); | 535 | seq_puts(s, "Pinmux settings per pin\n"); |
519 | seq_puts(s, "Format: pin (name): mux_owner gpio_owner hog?\n"); | 536 | seq_puts(s, "Format: pin (name): mux_owner gpio_owner hog?\n"); |
520 | 537 | ||
diff --git a/drivers/pinctrl/pinmux.h b/drivers/pinctrl/pinmux.h index 6fc47003e95d..d1a98b1c9fce 100644 --- a/drivers/pinctrl/pinmux.h +++ b/drivers/pinctrl/pinmux.h | |||
@@ -31,12 +31,6 @@ void pinmux_free_setting(struct pinctrl_setting const *setting); | |||
31 | int pinmux_enable_setting(struct pinctrl_setting const *setting); | 31 | int pinmux_enable_setting(struct pinctrl_setting const *setting); |
32 | void pinmux_disable_setting(struct pinctrl_setting const *setting); | 32 | void pinmux_disable_setting(struct pinctrl_setting const *setting); |
33 | 33 | ||
34 | void pinmux_show_map(struct seq_file *s, struct pinctrl_map const *map); | ||
35 | void pinmux_show_setting(struct seq_file *s, | ||
36 | struct pinctrl_setting const *setting); | ||
37 | void pinmux_init_device_debugfs(struct dentry *devroot, | ||
38 | struct pinctrl_dev *pctldev); | ||
39 | |||
40 | #else | 34 | #else |
41 | 35 | ||
42 | static inline int pinmux_check_ops(struct pinctrl_dev *pctldev) | 36 | static inline int pinmux_check_ops(struct pinctrl_dev *pctldev) |
@@ -89,6 +83,18 @@ static inline void pinmux_disable_setting( | |||
89 | { | 83 | { |
90 | } | 84 | } |
91 | 85 | ||
86 | #endif | ||
87 | |||
88 | #if defined(CONFIG_PINMUX) && defined(CONFIG_DEBUG_FS) | ||
89 | |||
90 | void pinmux_show_map(struct seq_file *s, struct pinctrl_map const *map); | ||
91 | void pinmux_show_setting(struct seq_file *s, | ||
92 | struct pinctrl_setting const *setting); | ||
93 | void pinmux_init_device_debugfs(struct dentry *devroot, | ||
94 | struct pinctrl_dev *pctldev); | ||
95 | |||
96 | #else | ||
97 | |||
92 | static inline void pinmux_show_map(struct seq_file *s, | 98 | static inline void pinmux_show_map(struct seq_file *s, |
93 | struct pinctrl_map const *map) | 99 | struct pinctrl_map const *map) |
94 | { | 100 | { |