aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-03-01 20:48:32 -0500
committerLinus Walleij <linus.walleij@linaro.org>2012-03-02 10:18:24 -0500
commit46919ae63d4820e76724beb655274ce143f0da0b (patch)
treea16dfab490eb0d68db9d633f172bab98b1035485
parentd4e3198736d9d64e4ba4d2b46ab75cbcf5d0a4e0 (diff)
pinctrl: introduce PINCTRL_STATE_DEFAULT, define hogs as that state
This provides a single centralized name for the default state. Update PIN_MAP_* macros to use this state name, instead of requiring the user to pass a state name in. With this change, hog entries in the mapping table are defined as those with state name PINCTRL_STATE_DEFAULT, i.e. all entries have the same name. This interacts badly with the nested iteration over mapping table entries in pinctrl_hog_maps() and pinctrl_hog_map() which would now attempt to claim each hog mapping table entry multiple times. Replacing the custom hog code with a simple pinctrl_get()/pinctrl_enable(). Update documentation and mapping tables to use this. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Dong Aisheng <dong.aisheng@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--Documentation/pinctrl.txt8
-rw-r--r--arch/arm/mach-u300/core.c6
-rw-r--r--drivers/pinctrl/core.c145
-rw-r--r--drivers/pinctrl/core.h4
-rw-r--r--include/linux/pinctrl/machine.h13
-rw-r--r--include/linux/pinctrl/pinctrl.h2
6 files changed, 26 insertions, 152 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt
index 5e314cecab77..6fe3232e798e 100644
--- a/Documentation/pinctrl.txt
+++ b/Documentation/pinctrl.txt
@@ -814,7 +814,7 @@ it even more compact which assumes you want to use pinctrl-foo and position
8140 for mapping, for example: 8140 for mapping, for example:
815 815
816static struct pinctrl_map __initdata mapping[] = { 816static struct pinctrl_map __initdata mapping[] = {
817 PIN_MAP("I2CMAP", "pinctrl-foo", "i2c0", "foo-i2c.0"), 817 PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0", "foo-i2c.0"),
818}; 818};
819 819
820 820
@@ -930,7 +930,7 @@ foo_probe()
930 /* Allocate a state holder named "state" etc */ 930 /* Allocate a state holder named "state" etc */
931 struct pinctrl p; 931 struct pinctrl p;
932 932
933 p = pinctrl_get(&device, NULL); 933 p = pinctrl_get(&device, PINCTRL_STATE_DEFAULT);
934 if IS_ERR(p) 934 if IS_ERR(p)
935 return PTR_ERR(p); 935 return PTR_ERR(p);
936 pinctrl_enable(p); 936 pinctrl_enable(p);
@@ -989,7 +989,7 @@ of the pin controller itself, like this:
989 989
990{ 990{
991 .dev_name = "pinctrl-foo", 991 .dev_name = "pinctrl-foo",
992 .name = "POWERMAP" 992 .name = PINCTRL_STATE_DEFAULT,
993 .ctrl_dev_name = "pinctrl-foo", 993 .ctrl_dev_name = "pinctrl-foo",
994 .function = "power_func", 994 .function = "power_func",
995}, 995},
@@ -998,7 +998,7 @@ Since it may be common to request the core to hog a few always-applicable
998mux settings on the primary pin controller, there is a convenience macro for 998mux settings on the primary pin controller, there is a convenience macro for
999this: 999this:
1000 1000
1001PIN_MAP_PRIMARY_SYS_HOG("POWERMAP", "pinctrl-foo", "power_func") 1001PIN_MAP_SYS_HOG("pinctrl-foo", "power_func")
1002 1002
1003This gives the exact same result as the above construction. 1003This gives the exact same result as the above construction.
1004 1004
diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c
index 030b2c0d322d..ea6c79076a91 100644
--- a/arch/arm/mach-u300/core.c
+++ b/arch/arm/mach-u300/core.c
@@ -1608,9 +1608,9 @@ static struct platform_device dma_device = {
1608/* Pinmux settings */ 1608/* Pinmux settings */
1609static struct pinctrl_map __initdata u300_pinmux_map[] = { 1609static struct pinctrl_map __initdata u300_pinmux_map[] = {
1610 /* anonymous maps for chip power and EMIFs */ 1610 /* anonymous maps for chip power and EMIFs */
1611 PIN_MAP_SYS_HOG("POWER", "pinctrl-u300", "power"), 1611 PIN_MAP_SYS_HOG("pinctrl-u300", "power"),
1612 PIN_MAP_SYS_HOG("EMIF0", "pinctrl-u300", "emif0"), 1612 PIN_MAP_SYS_HOG("pinctrl-u300", "emif0"),
1613 PIN_MAP_SYS_HOG("EMIF1", "pinctrl-u300", "emif1"), 1613 PIN_MAP_SYS_HOG("pinctrl-u300", "emif1"),
1614 /* per-device maps for MMC/SD, SPI and UART */ 1614 /* per-device maps for MMC/SD, SPI and UART */
1615 PIN_MAP("MMCSD", "pinctrl-u300", "mmc0", "mmci"), 1615 PIN_MAP("MMCSD", "pinctrl-u300", "mmc0", "mmci"),
1616 PIN_MAP("SPI", "pinctrl-u300", "spi0", "pl022"), 1616 PIN_MAP("SPI", "pinctrl-u300", "spi0", "pl022"),
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 376cede29662..f25307b0e00a 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -44,18 +44,6 @@ struct pinctrl_maps {
44 unsigned num_maps; 44 unsigned num_maps;
45}; 45};
46 46
47/**
48 * struct pinctrl_hog - a list item to stash control hogs
49 * @node: pin control hog list node
50 * @map: map entry responsible for this hogging
51 * @pmx: the pin control hogged by this item
52 */
53struct pinctrl_hog {
54 struct list_head node;
55 struct pinctrl_map const *map;
56 struct pinctrl *p;
57};
58
59/* Global list of pin control devices */ 47/* Global list of pin control devices */
60static DEFINE_MUTEX(pinctrldev_list_mutex); 48static DEFINE_MUTEX(pinctrldev_list_mutex);
61static LIST_HEAD(pinctrldev_list); 49static LIST_HEAD(pinctrldev_list);
@@ -702,103 +690,6 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps,
702 return 0; 690 return 0;
703} 691}
704 692
705/* Hog a single map entry and add to the hoglist */
706static int pinctrl_hog_map(struct pinctrl_dev *pctldev,
707 struct pinctrl_map const *map)
708{
709 struct pinctrl_hog *hog;
710 struct pinctrl *p;
711 int ret;
712
713 hog = kzalloc(sizeof(*hog), GFP_KERNEL);
714 if (!hog) {
715 dev_err(pctldev->dev, "failed to alloc struct pinctrl_hog\n");
716 return -ENOMEM;
717 }
718
719 p = pinctrl_get_locked(pctldev->dev, map->name);
720 if (IS_ERR(p)) {
721 kfree(hog);
722 dev_err(pctldev->dev,
723 "could not get the %s pin control mapping for hogging\n",
724 map->name);
725 return PTR_ERR(p);
726 }
727
728 ret = pinctrl_enable(p);
729 if (ret) {
730 pinctrl_put(p);
731 kfree(hog);
732 dev_err(pctldev->dev,
733 "could not enable the %s pin control mapping for hogging\n",
734 map->name);
735 return ret;
736 }
737
738 hog->map = map;
739 hog->p = p;
740
741 dev_info(pctldev->dev, "hogged map %s, function %s\n", map->name,
742 map->function);
743 list_add_tail(&hog->node, &pctldev->pinctrl_hogs);
744
745 return 0;
746}
747
748/**
749 * pinctrl_hog_maps() - hog specific map entries on controller device
750 * @pctldev: the pin control device to hog entries on
751 *
752 * When the pin controllers are registered, there may be some specific pinmux
753 * map entries that need to be hogged, i.e. get+enabled until the system shuts
754 * down.
755 */
756static int pinctrl_hog_maps(struct pinctrl_dev *pctldev)
757{
758 struct device *dev = pctldev->dev;
759 const char *devname = dev_name(dev);
760 int ret;
761 struct pinctrl_maps *maps_node;
762 int i;
763 struct pinctrl_map const *map;
764
765 INIT_LIST_HEAD(&pctldev->pinctrl_hogs);
766
767 mutex_lock(&pinctrl_maps_mutex);
768 for_each_maps(maps_node, i, map) {
769 if (!strcmp(map->ctrl_dev_name, devname) &&
770 !strcmp(map->dev_name, devname)) {
771 /* OK time to hog! */
772 ret = pinctrl_hog_map(pctldev, map);
773 if (ret) {
774 mutex_unlock(&pinctrl_maps_mutex);
775 return ret;
776 }
777 }
778 }
779 mutex_unlock(&pinctrl_maps_mutex);
780
781 return 0;
782}
783
784/**
785 * pinctrl_unhog_maps() - unhog specific map entries on controller device
786 * @pctldev: the pin control device to unhog entries on
787 */
788static void pinctrl_unhog_maps(struct pinctrl_dev *pctldev)
789{
790 struct list_head *node, *tmp;
791
792 list_for_each_safe(node, tmp, &pctldev->pinctrl_hogs) {
793 struct pinctrl_hog *hog =
794 list_entry(node, struct pinctrl_hog, node);
795 pinctrl_disable(hog->p);
796 pinctrl_put(hog->p);
797 list_del(node);
798 kfree(hog);
799 }
800}
801
802#ifdef CONFIG_DEBUG_FS 693#ifdef CONFIG_DEBUG_FS
803 694
804static int pinctrl_pins_show(struct seq_file *s, void *what) 695static int pinctrl_pins_show(struct seq_file *s, void *what)
@@ -889,19 +780,6 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
889 return 0; 780 return 0;
890} 781}
891 782
892static int pinmux_hogs_show(struct seq_file *s, void *what)
893{
894 struct pinctrl_dev *pctldev = s->private;
895 struct pinctrl_hog *hog;
896
897 seq_puts(s, "Pin control map hogs held by device\n");
898
899 list_for_each_entry(hog, &pctldev->pinctrl_hogs, node)
900 seq_printf(s, "%s\n", hog->map->name);
901
902 return 0;
903}
904
905static int pinctrl_devices_show(struct seq_file *s, void *what) 783static int pinctrl_devices_show(struct seq_file *s, void *what)
906{ 784{
907 struct pinctrl_dev *pctldev; 785 struct pinctrl_dev *pctldev;
@@ -988,11 +866,6 @@ static int pinctrl_gpioranges_open(struct inode *inode, struct file *file)
988 return single_open(file, pinctrl_gpioranges_show, inode->i_private); 866 return single_open(file, pinctrl_gpioranges_show, inode->i_private);
989} 867}
990 868
991static int pinmux_hogs_open(struct inode *inode, struct file *file)
992{
993 return single_open(file, pinmux_hogs_show, inode->i_private);
994}
995
996static int pinctrl_devices_open(struct inode *inode, struct file *file) 869static int pinctrl_devices_open(struct inode *inode, struct file *file)
997{ 870{
998 return single_open(file, pinctrl_devices_show, NULL); 871 return single_open(file, pinctrl_devices_show, NULL);
@@ -1029,13 +902,6 @@ static const struct file_operations pinctrl_gpioranges_ops = {
1029 .release = single_release, 902 .release = single_release,
1030}; 903};
1031 904
1032static const struct file_operations pinmux_hogs_ops = {
1033 .open = pinmux_hogs_open,
1034 .read = seq_read,
1035 .llseek = seq_lseek,
1036 .release = single_release,
1037};
1038
1039static const struct file_operations pinctrl_devices_ops = { 905static const struct file_operations pinctrl_devices_ops = {
1040 .open = pinctrl_devices_open, 906 .open = pinctrl_devices_open,
1041 .read = seq_read, 907 .read = seq_read,
@@ -1078,8 +944,6 @@ static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1078 device_root, pctldev, &pinctrl_groups_ops); 944 device_root, pctldev, &pinctrl_groups_ops);
1079 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO, 945 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
1080 device_root, pctldev, &pinctrl_gpioranges_ops); 946 device_root, pctldev, &pinctrl_gpioranges_ops);
1081 debugfs_create_file("pinmux-hogs", S_IFREG | S_IRUGO,
1082 device_root, pctldev, &pinmux_hogs_ops);
1083 pinmux_init_device_debugfs(device_root, pctldev); 947 pinmux_init_device_debugfs(device_root, pctldev);
1084 pinconf_init_device_debugfs(device_root, pctldev); 948 pinconf_init_device_debugfs(device_root, pctldev);
1085} 949}
@@ -1188,7 +1052,9 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
1188 mutex_lock(&pinctrldev_list_mutex); 1052 mutex_lock(&pinctrldev_list_mutex);
1189 list_add_tail(&pctldev->node, &pinctrldev_list); 1053 list_add_tail(&pctldev->node, &pinctrldev_list);
1190 mutex_unlock(&pinctrldev_list_mutex); 1054 mutex_unlock(&pinctrldev_list_mutex);
1191 pinctrl_hog_maps(pctldev); 1055 pctldev->p = pinctrl_get(pctldev->dev, PINCTRL_STATE_DEFAULT);
1056 if (!IS_ERR(pctldev->p))
1057 pinctrl_enable(pctldev->p);
1192 pinctrl_init_device_debugfs(pctldev); 1058 pinctrl_init_device_debugfs(pctldev);
1193 1059
1194 return pctldev; 1060 return pctldev;
@@ -1211,7 +1077,10 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)
1211 return; 1077 return;
1212 1078
1213 pinctrl_remove_device_debugfs(pctldev); 1079 pinctrl_remove_device_debugfs(pctldev);
1214 pinctrl_unhog_maps(pctldev); 1080 if (!IS_ERR(pctldev->p)) {
1081 pinctrl_disable(pctldev->p);
1082 pinctrl_put(pctldev->p);
1083 }
1215 /* TODO: check that no pinmuxes are still active? */ 1084 /* TODO: check that no pinmuxes are still active? */
1216 mutex_lock(&pinctrldev_list_mutex); 1085 mutex_lock(&pinctrldev_list_mutex);
1217 list_del(&pctldev->node); 1086 list_del(&pctldev->node);
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index 8164e7b4182b..97f8124b4381 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -27,7 +27,7 @@ struct pinctrl_gpio_range;
27 * @owner: module providing the pin controller, used for refcounting 27 * @owner: module providing the pin controller, used for refcounting
28 * @driver_data: driver data for drivers registering to the pin controller 28 * @driver_data: driver data for drivers registering to the pin controller
29 * subsystem 29 * subsystem
30 * @pinctrl_hogs: list of pin control maps hogged by this device 30 * @p: result of pinctrl_get() for this device
31 * @device_root: debugfs root for this device 31 * @device_root: debugfs root for this device
32 */ 32 */
33struct pinctrl_dev { 33struct pinctrl_dev {
@@ -39,7 +39,7 @@ struct pinctrl_dev {
39 struct device *dev; 39 struct device *dev;
40 struct module *owner; 40 struct module *owner;
41 void *driver_data; 41 void *driver_data;
42 struct list_head pinctrl_hogs; 42 struct pinctrl *p;
43#ifdef CONFIG_DEBUG_FS 43#ifdef CONFIG_DEBUG_FS
44 struct dentry *device_root; 44 struct dentry *device_root;
45#endif 45#endif
diff --git a/include/linux/pinctrl/machine.h b/include/linux/pinctrl/machine.h
index 73fbb2745301..20e97353d5f9 100644
--- a/include/linux/pinctrl/machine.h
+++ b/include/linux/pinctrl/machine.h
@@ -12,6 +12,8 @@
12#ifndef __LINUX_PINCTRL_MACHINE_H 12#ifndef __LINUX_PINCTRL_MACHINE_H
13#define __LINUX_PINCTRL_MACHINE_H 13#define __LINUX_PINCTRL_MACHINE_H
14 14
15#include "pinctrl.h"
16
15/** 17/**
16 * struct pinctrl_map - boards/machines shall provide this map for devices 18 * struct pinctrl_map - boards/machines shall provide this map for devices
17 * @dev_name: the name of the device using this specific mapping, the name 19 * @dev_name: the name of the device using this specific mapping, the name
@@ -49,17 +51,18 @@ struct pinctrl_map {
49 * Convenience macro to map a system function onto a certain pinctrl device, 51 * Convenience macro to map a system function onto a certain pinctrl device,
50 * to be hogged by the pin control core until the system shuts down. 52 * to be hogged by the pin control core until the system shuts down.
51 */ 53 */
52#define PIN_MAP_SYS_HOG(a, b, c) \ 54#define PIN_MAP_SYS_HOG(a, b) \
53 { .name = a, .ctrl_dev_name = b, .dev_name = b, .function = c, } 55 { .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = a, .dev_name = a, \
56 .function = b, }
54 57
55/* 58/*
56 * Convenience macro to map a system function onto a certain pinctrl device 59 * Convenience macro to map a system function onto a certain pinctrl device
57 * using a specified group, to be hogged by the pin control core until the 60 * using a specified group, to be hogged by the pin control core until the
58 * system shuts down. 61 * system shuts down.
59 */ 62 */
60#define PIN_MAP_SYS_HOG_GROUP(a, b, c, d) \ 63#define PIN_MAP_SYS_HOG_GROUP(a, b, c) \
61 { .name = a, .ctrl_dev_name = b, .dev_name = b, .function = c, \ 64 { .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = a, .dev_name = a, \
62 .group = d, } 65 .function = b, .group = c, }
63 66
64#ifdef CONFIG_PINMUX 67#ifdef CONFIG_PINMUX
65 68
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index 8bd22ee7aa09..411fe232adf1 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -19,6 +19,8 @@
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/seq_file.h> 20#include <linux/seq_file.h>
21 21
22#define PINCTRL_STATE_DEFAULT "default"
23
22struct pinctrl_dev; 24struct pinctrl_dev;
23struct pinmux_ops; 25struct pinmux_ops;
24struct pinconf_ops; 26struct pinconf_ops;