aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/core.h
diff options
context:
space:
mode:
authorPatrice Chotard <patrice.chotard@st.com>2013-04-11 05:01:27 -0400
committerLinus Walleij <linus.walleij@linaro.org>2013-04-26 11:01:35 -0400
commit42fed7ba44e4e8c1fb27b28ad14490cb1daff3c7 (patch)
tree3caafd69ed9807e9a15f14d6c482fa1f1a697a8b /drivers/pinctrl/core.h
parentcb6d315dc36ce56bc017051befa9ac9391300eb9 (diff)
pinctrl: move subsystem mutex to pinctrl_dev struct
This mutex avoids deadlock in case of use of multiple pin controllers. Before this modification, by using a global mutex, deadlock appeared when, for example, a call to pinctrl_pins_show() locked the pinctrl_mutex, called the ops->pin_dbg_show of a particular pin controller. If this pin controller needs I2C access to retrieve configuration information and I2C driver is using pinctrl to drive its pins, a call to pinctrl_select_state() try to lock again pinctrl_mutex which leads to a deadlock. Notice that the mutex grab from the two direction functions was moved into pinctrl_gpio_direction(). For several cases, we can't replace pinctrl_mutex by pctldev->mutex, because at this stage, pctldev is not accessible : - pinctrl_get()/pinctrl_put() - pinctrl_register_maps() So add respectively pinctrl_list_mutex and pinctrl_maps_mutex in order to protect pinctrl_list and pinctrl_maps list instead. Reintroduce pinctrldev_list_mutex in find_pinctrl_by_of_node(), pinctrl_find_and_add_gpio_range() pinctrl_request_gpio(), pinctrl_free_gpio(), pinctrl_gpio_direction(), pinctrl_devices_show(), pinctrl_register() and pinctrl_unregister() to protect pinctrldev_list. Changes v2->v3: - Fix a missing EXPORT_SYMBOL_GPL() for pinctrl_select_state(). Changes v1->v2: - pinctrl_select_state_locked() is removed, all lock mechanism is located inside pinctrl_select_state(). When parsing the state->setting list, take the per-pin-controller driver lock. (Patrice). - Introduce pinctrldev_list_mutex to protect pinctrldev_list in all functions which parse or modify pictrldev_list. (Patrice). - move find_pinctrl_by_of_node() from pinctrl/devicetree.c to pinctrl/core.c in order to protect pinctrldev_list. (Patrice). - Sink mutex:es into some functions and remove some _locked variants down to where the lists are actually accessed to make things simpler. (Linus) - Drop *all* mutexes completely from pinctrl_lookup_state() and pinctrl_select_state() - no relevant mutex was taken and it was unclear what this was protecting against. (Linus) Reported by : Seraphin Bonnaffe <seraphin.bonnaffe@stericsson.com> Signed-off-by: Patrice Chotard <patrice.chotard@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/core.h')
-rw-r--r--drivers/pinctrl/core.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index 6d3d40036d1b..75476b3d87da 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -33,6 +33,7 @@ struct pinctrl_gpio_range;
33 * @p: result of pinctrl_get() for this device 33 * @p: result of pinctrl_get() for this device
34 * @hog_default: default state for pins hogged by this device 34 * @hog_default: default state for pins hogged by this device
35 * @hog_sleep: sleep state for pins hogged by this device 35 * @hog_sleep: sleep state for pins hogged by this device
36 * @mutex: mutex taken on each pin controller specific action
36 * @device_root: debugfs root for this device 37 * @device_root: debugfs root for this device
37 */ 38 */
38struct pinctrl_dev { 39struct pinctrl_dev {
@@ -46,6 +47,7 @@ struct pinctrl_dev {
46 struct pinctrl *p; 47 struct pinctrl *p;
47 struct pinctrl_state *hog_default; 48 struct pinctrl_state *hog_default;
48 struct pinctrl_state *hog_sleep; 49 struct pinctrl_state *hog_sleep;
50 struct mutex mutex;
49#ifdef CONFIG_DEBUG_FS 51#ifdef CONFIG_DEBUG_FS
50 struct dentry *device_root; 52 struct dentry *device_root;
51#endif 53#endif
@@ -168,6 +170,7 @@ struct pinctrl_maps {
168}; 170};
169 171
170struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); 172struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
173struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np);
171int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); 174int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
172const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin); 175const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin);
173int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, 176int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
@@ -186,8 +189,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map);
186extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); 189extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev);
187extern int pinctrl_force_default(struct pinctrl_dev *pctldev); 190extern int pinctrl_force_default(struct pinctrl_dev *pctldev);
188 191
189extern struct mutex pinctrl_mutex; 192extern struct mutex pinctrl_maps_mutex;
190extern struct list_head pinctrldev_list;
191extern struct list_head pinctrl_maps; 193extern struct list_head pinctrl_maps;
192 194
193#define for_each_maps(_maps_node_, _i_, _map_) \ 195#define for_each_maps(_maps_node_, _i_, _map_) \