Add generic pinctrl helpers for managing groups and functions
Subsystems (3)
Tony Lindgren
maintainercover Add generic pinctrl helpers for managing groups and functions
Hi all,
Here are some changes to add generic helpers for managing pinctrl groups and functions.
Regards,
Tony
Tony Lindgren (5):
pinctrl: core: Use delayed work for hogs
pinctrl: core: Add generic pinctrl functions for managing groups
pinctrl: core: Add generic pinctrl functions for managing groups
pinctrl: single: Use generic pinctrl helpers for managing groups
pinctrl: single: Use generic pinmux helpers for managing functions
drivers/pinctrl/Kconfig | 11 +- drivers/pinctrl/core.c | 233 ++++++++++++++++++++++++++++--- drivers/pinctrl/core.h | 67 +++++++++ drivers/pinctrl/pinctrl-single.c | 289 ++++----------------------------------- drivers/pinctrl/pinmux.c | 173 +++++++++++++++++++++++ drivers/pinctrl/pinmux.h | 42 ++++++ 6 files changed, 532 insertions(+), 283 deletions(-)
Signature · 1 line
2.9.3
Tony Lindgren
maintainerPATCH 1/5 pinctrl: core: Use delayed work for hogs
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct pinctrl_dev handle.
Let's fix this issue by adding deferred work for hogs. This is needed to be able to add pinctrl generic helper functions.
Note that the pinctrl functions already take care of the necessary locking.
--- drivers/pinctrl/core.c | 53 +++++++++++++++++++++++++++++++------------------- drivers/pinctrl/core.h | 2 ++ 2 files changed, 35 insertions(+), 20 deletions(-)
drivers/pinctrl/core.c +33 -20
@@ -1738,6 +1738,35 @@ static int pinctrl_check_ops(struct pinctrl_dev *pctldev) }/** +* pinctrl_hog_work() - delayed work to set pincontroller self-claimed pins +* @work: work struct +*/ +static void pinctrl_hog_work (struct work_struct *work) +{ +struct pinctrl_dev *pctldev; + + pctldev = container_of(work, struct pinctrl_dev, hog_work.work); + + pctldev->p =pinctrl_get (pctldev->dev); +if (IS_ERR (pctldev->p)) +return ; + + pctldev->hog_default = +pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); +if (IS_ERR (pctldev->hog_default)) { +dev_dbg (pctldev->dev,"failed to lookup the default state\n" ); + }else { +if (pinctrl_select_state (pctldev->p, pctldev->hog_default)) +dev_err (pctldev->dev,"failed to select default state\n" ); + } + + pctldev->hog_sleep =pinctrl_lookup_state (pctldev->p, +PINCTRL_STATE_SLEEP ); +if (IS_ERR (pctldev->hog_sleep)) +dev_dbg (pctldev->dev,"failed to lookup the sleep state\n" ); +} + +/** * pinctrl_register() - register a pin controller device * @pctldesc: descriptor for this pin controller * @dev: parent device for this pin controller
@@ -1766,6 +1795,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, pctldev->driver_data = driver_data;INIT_RADIX_TREE (&pctldev->pin_desc_tree,GFP_KERNEL );INIT_LIST_HEAD (&pctldev->gpio_ranges); +INIT_DELAYED_WORK (&pctldev->hog_work, pinctrl_hog_work); pctldev->dev = dev;mutex_init (&pctldev->mutex);
@@ -1804,26 +1834,8 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,list_add_tail (&pctldev->node, &pinctrldev_list);mutex_unlock (&pinctrldev_list_mutex); - pctldev->p =pinctrl_get (pctldev->dev); - -if (!IS_ERR (pctldev->p)) { - pctldev->hog_default = -pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); -if (IS_ERR (pctldev->hog_default)) { -dev_dbg (dev,"failed to lookup the default state\n" ); - }else { -if (pinctrl_select_state (pctldev->p, - pctldev->hog_default)) -dev_err (dev, -"failed to select default state\n" ); - } - - pctldev->hog_sleep = -pinctrl_lookup_state (pctldev->p, -PINCTRL_STATE_SLEEP ); -if (IS_ERR (pctldev->hog_sleep)) -dev_dbg (dev,"failed to lookup the sleep state\n" ); - } +schedule_delayed_work (&pctldev->hog_work, +msecs_to_jiffies (100 ));pinctrl_init_device_debugfs (pctldev);
@@ -1848,6 +1860,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)if (pctldev ==NULL )return ; +cancel_delayed_work_sync (&pctldev->hog_work);mutex_lock (&pctldev->mutex);pinctrl_remove_device_debugfs (pctldev);mutex_unlock (&pctldev->mutex);
drivers/pinctrl/core.h +2 -0
@@ -33,6 +33,7 @@ struct pinctrl_gpio_range;* @p: result of pinctrl_get() for this device * @hog_default: default state for pins hogged by this device * @hog_sleep: sleep state for pins hogged by this device +* @hog_work: delayed work for pin controller device claimed hog pins * @mutex: mutex taken on each pin controller specific action * @device_root: debugfs root for this device */
@@ -47,6 +48,7 @@ struct pinctrl_dev {struct pinctrl *p;struct pinctrl_state *hog_default;struct pinctrl_state *hog_sleep; +struct delayed_work hog_work;struct mutex mutex;#ifdef CONFIG_DEBUG_FS struct dentry *device_root;
Signature · 1 line
2.9.3
Tony Lindgren
maintainerPATCH 2/5 pinctrl: core: Add generic pinctrl functions for managing groups
In reply to Tony LindgrenWe can add generic helpers for pin group handling for cases where the pin controller driver does not need to use static arrays.
--- drivers/pinctrl/Kconfig | 3 + drivers/pinctrl/core.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/pinctrl/core.h | 47 +++++++++++++ 3 files changed, 228 insertions(+)
drivers/pinctrl/Kconfig +3 -0
@@ -8,6 +8,9 @@ config PINCTRL menu "Pin controllers" depends on PINCTRL +config GENERIC_PINCTRL + bool + config PINMUX bool "Support pin multiplexing controllers" if COMPILE_TEST
drivers/pinctrl/core.c +178 -0
196 lines not on this page · raw message
drivers/pinctrl/core.h +47 -0
71 lines not on this page · raw message
Signature · 1 line
2.9.3
Tony Lindgren
maintainerPATCH 3/5 pinctrl: core: Add generic pinctrl functions for managing groups
In reply to Tony LindgrenWe can add generic helpers for function handling for cases where the pin controller driver does not need to use static arrays.
--- drivers/pinctrl/Kconfig | 4 ++ drivers/pinctrl/core.c | 2 + drivers/pinctrl/core.h | 18 +++++ drivers/pinctrl/pinmux.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pinctrl/pinmux.h | 42 ++++++++++++ 5 files changed, 239 insertions(+)
drivers/pinctrl/Kconfig +4 -0
@@ -14,6 +14,10 @@ config GENERIC_PINCTRL config PINMUX bool "Support pin multiplexing controllers" if COMPILE_TEST +config GENERIC_PINMUX + bool + select PINMUX + config PINCONF bool "Support pin configuration controllers" if COMPILE_TEST
drivers/pinctrl/core.c +2 -0
@@ -1971,6 +1971,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, pctldev->driver_data = driver_data;INIT_RADIX_TREE (&pctldev->pin_desc_tree,GFP_KERNEL );INIT_RADIX_TREE (&pctldev->pin_group_tree,GFP_KERNEL ); +INIT_RADIX_TREE (&pctldev->pin_function_tree,GFP_KERNEL );INIT_LIST_HEAD (&pctldev->gpio_ranges);INIT_DELAYED_WORK (&pctldev->hog_work, pinctrl_hog_work); pctldev->dev = dev;
@@ -2049,6 +2050,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)mutex_lock (&pctldev->mutex);/* TODO: check that no pinmuxes are still active? */ list_del (&pctldev->node); +pinmux_generic_free_functions (pctldev);pinctrl_generic_free_groups (pctldev);/* Destroy descriptor tree */ pinctrl_free_pindescs(pctldev, pctldev->desc->pins,
drivers/pinctrl/core.h +18 -0
@@ -25,7 +25,9 @@ struct pinctrl_gpio_range;* @pin_desc_tree: each pin descriptor for this pin controller is stored in * this radix tree * @pin_group_tree: optionally each pin group can be stored in this radix tree +* @pin_function_tree: optionally each function can be stored in this radix tree * @num_groups: optionally number of groups can be kept here +* @num_functions: optionally number of functions can be kept here * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller, * ranges are added to this list at runtime * @dev: the device entry for this pin controller
@@ -44,7 +46,9 @@ struct pinctrl_dev {struct pinctrl_desc *desc;struct radix_tree_root pin_desc_tree;struct radix_tree_root pin_group_tree; +struct radix_tree_root pin_function_tree;unsigned int num_groups; +unsigned int num_functions;struct list_head gpio_ranges;struct device *dev;struct module *owner;
@@ -180,6 +184,20 @@ struct group_desc { };/** +* struct function_desc - generic function descriptor +* @name: name of the function +* @group_names: array of pin group names +* @num_group_names: number of pin group names +* @data: pin controller driver specific data +*/ +struct function_desc { +const char *name; +const char **group_names; +int num_group_names; +void *data; +}; + +/** * struct pinctrl_maps - a list item containing part of the mapping table * @node: mapping table list node * @maps: array of mapping table entries
drivers/pinctrl/pinmux.c +173 -0
176 lines not on this page · raw message
drivers/pinctrl/pinmux.h +42 -0
45 lines not on this page · raw message
Signature · 1 line
2.9.3
Tony Lindgren
maintainerPATCH 4/5 pinctrl: single: Use generic pinctrl helpers for managing groups
In reply to Tony LindgrenWe can now drop the driver specific code for managing groups.
--- drivers/pinctrl/Kconfig | 2 +- drivers/pinctrl/pinctrl-single.c | 155 +++------------------------------------ 2 files changed, 11 insertions(+), 146 deletions(-)
drivers/pinctrl/Kconfig +1 -1
@@ -157,8 +157,8 @@ config PINCTRL_ROCKCHIP config PINCTRL_SINGLE tristate "One-register-per-pin type device tree based pinctrl driver" depends on OF + select GENERIC_PINCTRL select PINMUX - select PINCONF select GENERIC_PINCONF help This selects the device tree based generic pinctrl driver.
drivers/pinctrl/pinctrl-single.c +10 -145
271 lines not on this page · raw message
Signature · 1 line
2.9.3
Tony Lindgren
maintainerPATCH 5/5 pinctrl: single: Use generic pinmux helpers for managing functions
In reply to Tony LindgrenWe can now drop the driver specific code for managing functions.
--- drivers/pinctrl/Kconfig | 2 +- drivers/pinctrl/pinctrl-single.c | 134 ++++++--------------------------------- 2 files changed, 19 insertions(+), 117 deletions(-)
drivers/pinctrl/Kconfig +1 -1
@@ -158,7 +158,7 @@ config PINCTRL_SINGLE tristate "One-register-per-pin type device tree based pinctrl driver" depends on OF select GENERIC_PINCTRL - select PINMUX + select GENERIC_PINMUX select GENERIC_PINCONF help This selects the device tree based generic pinctrl driver.
drivers/pinctrl/pinctrl-single.c +18 -116
250 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
In reply to Tony LindgrenQuoted 11 lines · Tony Lindgren
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for hogs. This is needed to be able to add pinctrl generic helper functions.
Note that the pinctrl functions already take care of the necessary locking.
Signed-off-by Tony Lindgren <[email protected]>
I don't see why this is necessary?
The hogging was placed inside pinctrl_register() so that any hogs would be taken before it returns, so nothing else can take it before the controller itself has the first chance. This semantic needs to be preserved I think.
drivers/pinctrl/core.c struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, · line 1838
Quoted 2 lines
drivers/pinctrl/core.c +2
-0+schedule_delayed_work (&pctldev->hog_work, +msecs_to_jiffies (100 ));
If we arbitrarily delay, something else can go in and take the pins used by the hogs before the pinctrl core? That is what we want to avoid.
Hm, 100ms seems arbitrarily chosen BTW. Can it be 1 ms? 1 ns?
I'm pretty sure that whatever it is that needs to happen before the hog work runs can race with this delayed work under some circumstances (such as slow external expanders on i2c). It should be impossible for that to happen and I don't think it is?
Yours,
Linus Walleij
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 9 lines · Linus Walleij
Quoted 7 lines · Tony Lindgren
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for hogs. This is needed to be able to add pinctrl generic helper functions.
Quoted 6 lines
Quoted 4 lines
Note that the pinctrl functions already take care of the necessary locking.
Signed-off-by Tony Lindgren <[email protected]>I don't see why this is necessary?
It's needed because the pin controller driver has not yet finished it's probe at this point. We end up calling functions in the device driver where no struct pinctrl_dev is yet known to the driver. Asking a device driver to do something before it's probe is done does not quite follow the Linux driver model :)
Quoted 8 lines
The hogging was placed inside
pinctrl_register()so that any hogs would be taken before it returns, so nothing else can take it before the controller itself has the first chance. This semantic needs to be preserved I think.drivers/pinctrl/core.c struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, · line 1838
Quoted 2 lines
drivers/pinctrl/core.c +2
-0+schedule_delayed_work (&pctldev->hog_work, +msecs_to_jiffies (100 ));
Quoted 6 lines
If we arbitrarily delay, something else can go in and take the pins used by the hogs before the pinctrl core? That is what we want to avoid.
Hm, 100ms seems arbitrarily chosen BTW. Can it be 1 ms? 1 ns?
Yeah well seems like it should not matter but the race we need to remove somehow.
Quoted 5 lines
I'm pretty sure that whatever it is that needs to happen before the hog work runs can race with this delayed work under some circumstances (such as slow external expanders on i2c). It should be impossible for that to happen and I don't think it is?
Yes it's totally possible even with delay set to 0.
Maybe we could add some trigger on the first consumer request and if that does not happen use the timer?
Regards,
Tony
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 15 lines · Tony Lindgren
Quoted 14 lines · Linus Walleij
Quoted 11 lines · Tony Lindgren
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for hogs. This is needed to be able to add pinctrl generic helper functions.
Note that the pinctrl functions already take care of the necessary locking.
Signed-off-by Tony Lindgren <[email protected]>
Quoted 7 lines
Quoted 1 line
I don't see why this is necessary?
It's needed because the pin controller driver has not yet finished it's probe at this point. We end up calling functions in the device driver where no struct
pinctrl_devis yet known to the driver. Asking a device driver to do something before it's probe is done does not quite follow the Linux driver model :)
To clarify, that's an issue with multiple instances of the same driver probing as there's no static pointer to driver specific data.
Regards,
Tony
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 24 lines · Tony Lindgren
Quoted 15 lines · Tony Lindgren
Quoted 14 lines · Linus Walleij
Quoted 11 lines · Tony Lindgren
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for hogs. This is needed to be able to add pinctrl generic helper functions.
Note that the pinctrl functions already take care of the necessary locking.
Signed-off-by Tony Lindgren <[email protected]>Quoted 7 lines
Quoted 1 line
I don't see why this is necessary?
It's needed because the pin controller driver has not yet finished it's probe at this point. We end up calling functions in the device driver where no struct
pinctrl_devis yet known to the driver. Asking a device driver to do something before it's probe is done does not quite follow the Linux driver model :)
Quoted 3 lines
To clarify, that's an issue with multiple instances of the same driver probing as there's no static pointer to driver specific data.
To clarify even more, the following patches in this series need struct pinctrl_dev to pass to the generic functions :)
Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
In reply to Tony LindgrenQuoted 36 lines · Tony Lindgren
Quoted 4 lines · Linus Walleij
Quoted 1 line · Tony Lindgren
Signed-off-by Tony Lindgren <[email protected]>I don't see why this is necessary?
It's needed because the pin controller driver has not yet finished it's probe at this point. We end up calling functions in the device driver where no struct
pinctrl_devis yet known to the driver. Asking a device driver to do something before it's probe is done does not quite follow the Linux driver model :)Quoted 8 lines
The hogging was placed inside
pinctrl_register()so that any hogs would be taken before it returns, so nothing else can take it before the controller itself has the first chance. This semantic needs to be preserved I think.Review
Quoted 2 lines
(quoted diff) +2
-0+ schedule_delayed_work(&pctldev->hog_work, + msecs_to_jiffies(100));Quoted 6 lines
If we arbitrarily delay, something else can go in and take the pins used by the hogs before the pinctrl core? That is what we want to avoid.
Hm, 100ms seems arbitrarily chosen BTW. Can it be 1 ms? 1 ns?
Yeah well seems like it should not matter but the race we need to remove somehow.
Quoted 5 lines
I'm pretty sure that whatever it is that needs to happen before the hog work runs can race with this delayed work under some circumstances (such as slow external expanders on i2c). It should be impossible for that to happen and I don't think it is?
Quoted 4 lines
Yes it's totally possible even with delay set to 0.
Maybe we could add some trigger on the first consumer request and if that does not happen use the timer?
Below is what I came up with for removing the race for hogs. We can do it by not registering the pctldev until in the deferred work, does that seem OK to you?
Regards,
Tony
8<-----------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogs
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct pinctrl_dev handle.
Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct pinctrl_dev handle. Note that we now need to call create_pinctrl() directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed.
--- drivers/pinctrl/core.c | 66 ++++++++++++++++++++++++++++++-------------------- drivers/pinctrl/core.h | 2 ++ 2 files changed, 42 insertions(+), 26 deletions(-)
drivers/pinctrl/core.c +40 -26
@@ -1911,6 +1911,43 @@ static int pinctrl_check_ops(struct pinctrl_dev *pctldev) }/** +* pinctrl_late_init() - finish pin controller device registration +* @work: work struct +*/ +static void pinctrl_late_init (struct work_struct *work) +{ +struct pinctrl_dev *pctldev; + + pctldev = container_of(work, struct pinctrl_dev, late_init.work); + + pctldev->p =create_pinctrl (pctldev->dev); +if (IS_ERR (pctldev->p)) +return ; + +kref_get (&pctldev->p->users); + + pctldev->hog_default = +pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); +if (IS_ERR (pctldev->hog_default)) { +dev_dbg (pctldev->dev,"failed to lookup the default state\n" ); + }else { +if (pinctrl_select_state (pctldev->p, pctldev->hog_default)) +dev_err (pctldev->dev,"failed to select default state\n" ); + } + + pctldev->hog_sleep =pinctrl_lookup_state (pctldev->p, +PINCTRL_STATE_SLEEP ); +if (IS_ERR (pctldev->hog_sleep)) +dev_dbg (pctldev->dev,"failed to lookup the sleep state\n" ); + +mutex_lock (&pinctrldev_list_mutex); +list_add_tail (&pctldev->node, &pinctrldev_list); +mutex_unlock (&pinctrldev_list_mutex); + +pinctrl_init_device_debugfs (pctldev); +} + +/** * pinctrl_register() - register a pin controller device * @pctldesc: descriptor for this pin controller * @dev: parent device for this pin controller
@@ -1941,6 +1978,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,INIT_RADIX_TREE (&pctldev->pin_group_tree,GFP_KERNEL );INIT_RADIX_TREE (&pctldev->pin_function_tree,GFP_KERNEL );INIT_LIST_HEAD (&pctldev->gpio_ranges); +INIT_DELAYED_WORK (&pctldev->late_init, pinctrl_late_init); pctldev->dev = dev;mutex_init (&pctldev->mutex);
@@ -1975,32 +2013,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, goto out_err; } -mutex_lock (&pinctrldev_list_mutex); -list_add_tail (&pctldev->node, &pinctrldev_list); -mutex_unlock (&pinctrldev_list_mutex); - - pctldev->p =pinctrl_get (pctldev->dev); - -if (!IS_ERR (pctldev->p)) { - pctldev->hog_default = -pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); -if (IS_ERR (pctldev->hog_default)) { -dev_dbg (dev,"failed to lookup the default state\n" ); - }else { -if (pinctrl_select_state (pctldev->p, - pctldev->hog_default)) -dev_err (dev, -"failed to select default state\n" ); - } - - pctldev->hog_sleep = -pinctrl_lookup_state (pctldev->p, -PINCTRL_STATE_SLEEP ); -if (IS_ERR (pctldev->hog_sleep)) -dev_dbg (dev,"failed to lookup the sleep state\n" ); - } - -pinctrl_init_device_debugfs (pctldev); +schedule_delayed_work (&pctldev->late_init,0 );return pctldev;
@@ -2023,6 +2036,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)if (pctldev ==NULL )return ; +cancel_delayed_work_sync (&pctldev->late_init);mutex_lock (&pctldev->mutex);pinctrl_remove_device_debugfs (pctldev);mutex_unlock (&pctldev->mutex);
drivers/pinctrl/core.h +2 -0
@@ -37,6 +37,7 @@ struct pinctrl_gpio_range;* @p: result of pinctrl_get() for this device * @hog_default: default state for pins hogged by this device * @hog_sleep: sleep state for pins hogged by this device +* @late_init: delayed work for pin controller to finish registration * @mutex: mutex taken on each pin controller specific action * @device_root: debugfs root for this device */
@@ -55,6 +56,7 @@ struct pinctrl_dev {struct pinctrl *p;struct pinctrl_state *hog_default;struct pinctrl_state *hog_sleep; +struct delayed_work late_init;struct mutex mutex;#ifdef CONFIG_DEBUG_FS struct dentry *device_root;
Signature · 1 line
2.10.2
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 37 lines · Tony Lindgren
Quoted 36 lines · Tony Lindgren
Quoted 4 lines · Linus Walleij
Quoted 1 line · Tony Lindgren
Signed-off-by Tony Lindgren <[email protected]>I don't see why this is necessary?
It's needed because the pin controller driver has not yet finished it's probe at this point. We end up calling functions in the device driver where no struct
pinctrl_devis yet known to the driver. Asking a device driver to do something before it's probe is done does not quite follow the Linux driver model :)Quoted 8 lines
The hogging was placed inside
pinctrl_register()so that any hogs would be taken before it returns, so nothing else can take it before the controller itself has the first chance. This semantic needs to be preserved I think.Review
Quoted 2 lines
(quoted diff) +2
-0+ schedule_delayed_work(&pctldev->hog_work, + msecs_to_jiffies(100));Quoted 6 lines
If we arbitrarily delay, something else can go in and take the pins used by the hogs before the pinctrl core? That is what we want to avoid.
Hm, 100ms seems arbitrarily chosen BTW. Can it be 1 ms? 1 ns?
Yeah well seems like it should not matter but the race we need to remove somehow.
Quoted 5 lines
I'm pretty sure that whatever it is that needs to happen before the hog work runs can race with this delayed work under some circumstances (such as slow external expanders on i2c). It should be impossible for that to happen and I don't think it is?
Quoted 8 lines
Quoted 4 lines
Yes it's totally possible even with delay set to 0.
Maybe we could add some trigger on the first consumer request and if that does not happen use the timer?
Below is what I came up with for removing the race for hogs. We can do it by not registering the pctldev until in the deferred work, does that seem OK to you?
Oops, that does not yet work, will have to look into it more.
Regards,
Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 40 lines · Tony Lindgren
Quoted 39 lines · Tony Lindgren
Quoted 38 lines · Tony Lindgren
Quoted 4 lines · Linus Walleij
Quoted 1 line · Tony Lindgren
Signed-off-by Tony Lindgren <[email protected]>I don't see why this is necessary?
It's needed because the pin controller driver has not yet finished it's probe at this point. We end up calling functions in the device driver where no struct
pinctrl_devis yet known to the driver. Asking a device driver to do something before it's probe is done does not quite follow the Linux driver model :)Quoted 8 lines
The hogging was placed inside
pinctrl_register()so that any hogs would be taken before it returns, so nothing else can take it before the controller itself has the first chance. This semantic needs to be preserved I think.Review
Quoted 2 lines
(quoted diff) +2
-0+ schedule_delayed_work(&pctldev->hog_work, + msecs_to_jiffies(100));Quoted 6 lines
If we arbitrarily delay, something else can go in and take the pins used by the hogs before the pinctrl core? That is what we want to avoid.
Hm, 100ms seems arbitrarily chosen BTW. Can it be 1 ms? 1 ns?
Yeah well seems like it should not matter but the race we need to remove somehow.
Quoted 5 lines
I'm pretty sure that whatever it is that needs to happen before the hog work runs can race with this delayed work under some circumstances (such as slow external expanders on i2c). It should be impossible for that to happen and I don't think it is?
Yes it's totally possible even with delay set to 0.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Maybe we could add some trigger on the first consumer request and if that does not happen use the timer?
Below is what I came up with for removing the race for hogs. We can do it by not registering the pctldev until in the deferred work, does that seem OK to you?
Oops, that does not yet work, will have to look into it more.
We need to pass pctldev to the parsers if we want to not add the the controller to the list until hogs are claimed. Otherwise the device tree parsers won't find the controller. The patch below has that added.
Regards,
Tony
8< --------------------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogs
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct pinctrl_dev handle.
Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct pinctrl_dev handle. Note that we now need to call create_pinctrl() directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed. We also need to pass the pinctrl_dev to the device tree parser functions as they otherwise won't find the right controller at this point.
--- drivers/pinctrl/core.c | 87 ++++++++++++++++++++++++++++---------------- drivers/pinctrl/core.h | 2 + drivers/pinctrl/devicetree.c | 13 ++++--- drivers/pinctrl/devicetree.h | 5 ++- 4 files changed, 68 insertions(+), 39 deletions(-)
drivers/pinctrl/core.c +55 -32
@@ -720,7 +720,8 @@ static struct pinctrl_state *create_state(struct pinctrl *p,return state; } -static int add_setting (struct pinctrl *p,struct pinctrl_map const *map) +static int add_setting (struct pinctrl *p,struct pinctrl_dev *pctldev, +struct pinctrl_map const *map) {struct pinctrl_state *state;struct pinctrl_setting *setting;
@@ -744,7 +745,11 @@ static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) setting->type = map->type; - setting->pctldev =get_pinctrl_dev_from_devname (map->ctrl_dev_name); +if (pctldev) + setting->pctldev = pctldev; +else + setting->pctldev = +get_pinctrl_dev_from_devname (map->ctrl_dev_name);if (setting->pctldev ==NULL ) {kfree (setting);/* Do not defer probing of hogs (circular loop) */
@@ -800,7 +805,8 @@ static struct pinctrl *find_pinctrl(struct device *dev)static void pinctrl_free (struct pinctrl *p,bool inlist); -static struct pinctrl *create_pinctrl (struct device *dev) +static struct pinctrl *create_pinctrl (struct device *dev, +struct pinctrl_dev *pctldev) {struct pinctrl *p;const char *devname;
@@ -823,7 +829,7 @@ static struct pinctrl *create_pinctrl(struct device *dev)INIT_LIST_HEAD (&p->states);INIT_LIST_HEAD (&p->dt_maps); - ret =pinctrl_dt_to_map (p); + ret =pinctrl_dt_to_map (p, pctldev);if (ret <0 ) {kfree (p);return ERR_PTR (ret);
@@ -838,7 +844,7 @@ static struct pinctrl *create_pinctrl(struct device *dev)if (strcmp (map->dev_name, devname))continue ; - ret =add_setting (p, map); + ret =add_setting (p, pctldev, map);/* * At this point the adding of a setting may: *
@@ -899,7 +905,7 @@ struct pinctrl *pinctrl_get(struct device *dev)return p; } -return create_pinctrl (dev); +return create_pinctrl (dev,NULL ); }EXPORT_SYMBOL_GPL (pinctrl_get);
@@ -1738,6 +1744,46 @@ static int pinctrl_check_ops(struct pinctrl_dev *pctldev) }/** +* pinctrl_late_init() - finish pin controller device registration +* @work: work struct +*/ +static void pinctrl_late_init (struct work_struct *work) +{ +struct pinctrl_dev *pctldev; + + pctldev = container_of(work, struct pinctrl_dev, late_init.work); + + pctldev->p =create_pinctrl (pctldev->dev, pctldev); +if (!IS_ERR (pctldev->p)) { +kref_get (&pctldev->p->users); + pctldev->hog_default = +pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); +if (IS_ERR (pctldev->hog_default)) { +dev_dbg (pctldev->dev, +"failed to lookup the default state\n" ); + }else { +if (pinctrl_select_state (pctldev->p, + pctldev->hog_default)) +dev_err (pctldev->dev, +"failed to select default state\n" ); + } + + pctldev->hog_sleep = +pinctrl_lookup_state (pctldev->p, +PINCTRL_STATE_SLEEP ); +if (IS_ERR (pctldev->hog_sleep)) +dev_dbg (pctldev->dev, +"failed to lookup the sleep state\n" ); + } + +mutex_lock (&pinctrldev_list_mutex); +list_add_tail (&pctldev->node, &pinctrldev_list); +mutex_unlock (&pinctrldev_list_mutex); + +pinctrl_init_device_debugfs (pctldev); +} + +/** * pinctrl_register() - register a pin controller device * @pctldesc: descriptor for this pin controller * @dev: parent device for this pin controller
@@ -1766,6 +1812,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, pctldev->driver_data = driver_data;INIT_RADIX_TREE (&pctldev->pin_desc_tree,GFP_KERNEL );INIT_LIST_HEAD (&pctldev->gpio_ranges); +INIT_DELAYED_WORK (&pctldev->late_init, pinctrl_late_init); pctldev->dev = dev;mutex_init (&pctldev->mutex);
@@ -1800,32 +1847,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, goto out_err; } -mutex_lock (&pinctrldev_list_mutex); -list_add_tail (&pctldev->node, &pinctrldev_list); -mutex_unlock (&pinctrldev_list_mutex); - - pctldev->p =pinctrl_get (pctldev->dev); - -if (!IS_ERR (pctldev->p)) { - pctldev->hog_default = -pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); -if (IS_ERR (pctldev->hog_default)) { -dev_dbg (dev,"failed to lookup the default state\n" ); - }else { -if (pinctrl_select_state (pctldev->p, - pctldev->hog_default)) -dev_err (dev, -"failed to select default state\n" ); - } - - pctldev->hog_sleep = -pinctrl_lookup_state (pctldev->p, -PINCTRL_STATE_SLEEP ); -if (IS_ERR (pctldev->hog_sleep)) -dev_dbg (dev,"failed to lookup the sleep state\n" ); - } - -pinctrl_init_device_debugfs (pctldev); +schedule_delayed_work (&pctldev->late_init,0 );return pctldev;
@@ -1848,6 +1870,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)if (pctldev ==NULL )return ; +cancel_delayed_work_sync (&pctldev->late_init);mutex_lock (&pctldev->mutex);pinctrl_remove_device_debugfs (pctldev);mutex_unlock (&pctldev->mutex);
drivers/pinctrl/core.h +2 -0
@@ -33,6 +33,7 @@ struct pinctrl_gpio_range;* @p: result of pinctrl_get() for this device * @hog_default: default state for pins hogged by this device * @hog_sleep: sleep state for pins hogged by this device +* @late_init: delayed work for pin controller to finish registration * @mutex: mutex taken on each pin controller specific action * @device_root: debugfs root for this device */
@@ -47,6 +48,7 @@ struct pinctrl_dev {struct pinctrl *p;struct pinctrl_state *hog_default;struct pinctrl_state *hog_sleep; +struct delayed_work late_init;struct mutex mutex;#ifdef CONFIG_DEBUG_FS struct dentry *device_root;
drivers/pinctrl/devicetree.c +8 -5
@@ -100,11 +100,12 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np)return get_pinctrl_dev_from_of_node (np); } -static int dt_to_map_one_config (struct pinctrl *p,const char *statename, +static int dt_to_map_one_config (struct pinctrl *p, +struct pinctrl_dev *pctldev, +const char *statename,struct device_node *np_config) {struct device_node *np_pctldev; -struct pinctrl_dev *pctldev;const struct pinctrl_ops *ops;int ret;struct pinctrl_map *map;
@@ -121,7 +122,8 @@ static int dt_to_map_one_config(struct pinctrl *p, const char *statename,/* OK let's just assume this will appear later then */ return -EPROBE_DEFER ; } - pctldev =get_pinctrl_dev_from_of_node (np_pctldev); +if (!pctldev) + pctldev =get_pinctrl_dev_from_of_node (np_pctldev);if (pctldev)break ;/* Do not defer probing of hogs (circular loop) */
@@ -166,7 +168,7 @@ static int dt_remember_dummy_state(struct pinctrl *p, const char *statename)return dt_remember_or_free_map (p, statename,NULL , map,1 ); } -int pinctrl_dt_to_map (struct pinctrl *p) +int pinctrl_dt_to_map (struct pinctrl *p,struct pinctrl_dev *pctldev) {struct device_node *np = p->dev->of_node;int state, ret;
@@ -233,7 +235,8 @@ int pinctrl_dt_to_map(struct pinctrl *p) }/* Parse the node */ - ret =dt_to_map_one_config (p, statename, np_config); + ret =dt_to_map_one_config (p, pctldev, statename, + np_config);of_node_put (np_config);if (ret <0 ) goto err;
drivers/pinctrl/devicetree.h +3 -2
@@ -21,7 +21,7 @@ struct of_phandle_args;#ifdef CONFIG_OF void pinctrl_dt_free_maps (struct pinctrl *p); -int pinctrl_dt_to_map (struct pinctrl *p); +int pinctrl_dt_to_map (struct pinctrl *p,struct pinctrl_dev *pctldev);int pinctrl_count_index_with_args (const struct device_node *np,const char *list_name);
@@ -32,7 +32,8 @@ int pinctrl_parse_index_with_args(const struct device_node *np,#else -static inline int pinctrl_dt_to_map (struct pinctrl *p) +static inline int pinctrl_dt_to_map (struct pinctrl *p, +struct pinctrl_dev *pctldev) {return 0 ; }
Signature · 1 line
2.10.2
Re: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 18 lines · Tony Lindgren
8< --------------------------------
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogsHaving the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct
pinctrl_devhandle. Note that we now need to callcreate_pinctrl()directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed. We also need to pass thepinctrl_devto the device tree parser functions as they otherwise won't find the right controller at this point.
Quoted 1 line
Signed-off-by Tony Lindgren <[email protected]>
This looks a lot better!
So if I understand correctly, we can guarantee that the delayed work will not execute until the device driver probe() has finished, and it *will* execute immediately after that?
So:
- Device driver probes
- Delayed work is called
- Next initcall
I'm not 100% familiar with how delayed work works... :/
Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 28 lines · Linus Walleij
Quoted 18 lines · Tony Lindgren
8< --------------------------------
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogsHaving the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct
pinctrl_devhandle. Note that we now need to callcreate_pinctrl()directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed. We also need to pass thepinctrl_devto the device tree parser functions as they otherwise won't find the right controller at this point.Quoted 1 line
Signed-off-by Tony Lindgren <[email protected]>This looks a lot better!
So if I understand correctly, we can guarantee that the delayed work will not execute until the device driver
probe()has finished, and it *will* execute immediately after that?
Quoted 6 lines
So:
- Device driver probes
- Delayed work is called
- Next initcallI'm not 100% familiar with how delayed work works... :/
Yeah well the delayed work gets scheduled for next jiffy but may be pre-empted as it runs in process context.
So in the worst case it could that we still may need to fix few drivers to support -EPROBE_DEFER. I wonder if we should check for hogs in probe already and only defer if hogs are defined?
Regards,
Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 34 lines · Tony Lindgren
Quoted 33 lines · Linus Walleij
Quoted 18 lines · Tony Lindgren
8< --------------------------------
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogsHaving the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct
pinctrl_devhandle. Note that we now need to callcreate_pinctrl()directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed. We also need to pass thepinctrl_devto the device tree parser functions as they otherwise won't find the right controller at this point.Quoted 1 line
Signed-off-by Tony Lindgren <[email protected]>This looks a lot better!
So if I understand correctly, we can guarantee that the delayed work will not execute until the device driver
probe()has finished, and it *will* execute immediately after that?So:
- Device driver probes
- Delayed work is called
- Next initcall
Quoted 8 lines
Quoted 1 line
I'm not 100% familiar with how delayed work works... :/
Yeah well the delayed work gets scheduled for next jiffy but may be pre-empted as it runs in process context.
So in the worst case it could that we still may need to fix few drivers to support -EPROBE_DEFER. I wonder if we should check for hogs in probe already and only defer if hogs are defined?
Below is a version using delayed_work only if pinctrl_dt_has_hogs().
Not sure if testing only for pinctrl-0 is enough there though?
Regards,
Tony
8< --------------------------------
Quoted 1 line
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogs
Having the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct pinctrl_dev handle.
Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct pinctrl_dev handle. Note that we now need to call create_pinctrl() directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed. We also need to pass the pinctrl_dev to the device tree parser functions as they otherwise won't find the right controller at this point.
--- drivers/pinctrl/core.c | 90 ++++++++++++++++++++++++++++---------------- drivers/pinctrl/core.h | 2 + drivers/pinctrl/devicetree.c | 28 +++++++++++--- drivers/pinctrl/devicetree.h | 12 +++++- 4 files changed, 93 insertions(+), 39 deletions(-)
drivers/pinctrl/core.c +58 -32
@@ -720,7 +720,8 @@ static struct pinctrl_state *create_state(struct pinctrl *p,return state; } -static int add_setting (struct pinctrl *p,struct pinctrl_map const *map) +static int add_setting (struct pinctrl *p,struct pinctrl_dev *pctldev, +struct pinctrl_map const *map) {struct pinctrl_state *state;struct pinctrl_setting *setting;
@@ -744,7 +745,11 @@ static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) setting->type = map->type; - setting->pctldev =get_pinctrl_dev_from_devname (map->ctrl_dev_name); +if (pctldev) + setting->pctldev = pctldev; +else + setting->pctldev = +get_pinctrl_dev_from_devname (map->ctrl_dev_name);if (setting->pctldev ==NULL ) {kfree (setting);/* Do not defer probing of hogs (circular loop) */
@@ -800,7 +805,8 @@ static struct pinctrl *find_pinctrl(struct device *dev)static void pinctrl_free (struct pinctrl *p,bool inlist); -static struct pinctrl *create_pinctrl (struct device *dev) +static struct pinctrl *create_pinctrl (struct device *dev, +struct pinctrl_dev *pctldev) {struct pinctrl *p;const char *devname;
@@ -823,7 +829,7 @@ static struct pinctrl *create_pinctrl(struct device *dev)INIT_LIST_HEAD (&p->states);INIT_LIST_HEAD (&p->dt_maps); - ret =pinctrl_dt_to_map (p); + ret =pinctrl_dt_to_map (p, pctldev);if (ret <0 ) {kfree (p);return ERR_PTR (ret);
@@ -838,7 +844,7 @@ static struct pinctrl *create_pinctrl(struct device *dev)if (strcmp (map->dev_name, devname))continue ; - ret =add_setting (p, map); + ret =add_setting (p, pctldev, map);/* * At this point the adding of a setting may: *
@@ -899,7 +905,7 @@ struct pinctrl *pinctrl_get(struct device *dev)return p; } -return create_pinctrl (dev); +return create_pinctrl (dev,NULL ); }EXPORT_SYMBOL_GPL (pinctrl_get);
@@ -1738,6 +1744,46 @@ static int pinctrl_check_ops(struct pinctrl_dev *pctldev) }/** +* pinctrl_late_init() - finish pin controller device registration +* @work: work struct +*/ +static void pinctrl_late_init (struct work_struct *work) +{ +struct pinctrl_dev *pctldev; + + pctldev = container_of(work, struct pinctrl_dev, late_init.work); + + pctldev->p =create_pinctrl (pctldev->dev, pctldev); +if (!IS_ERR (pctldev->p)) { +kref_get (&pctldev->p->users); + pctldev->hog_default = +pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); +if (IS_ERR (pctldev->hog_default)) { +dev_dbg (pctldev->dev, +"failed to lookup the default state\n" ); + }else { +if (pinctrl_select_state (pctldev->p, + pctldev->hog_default)) +dev_err (pctldev->dev, +"failed to select default state\n" ); + } + + pctldev->hog_sleep = +pinctrl_lookup_state (pctldev->p, +PINCTRL_STATE_SLEEP ); +if (IS_ERR (pctldev->hog_sleep)) +dev_dbg (pctldev->dev, +"failed to lookup the sleep state\n" ); + } + +mutex_lock (&pinctrldev_list_mutex); +list_add_tail (&pctldev->node, &pinctrldev_list); +mutex_unlock (&pinctrldev_list_mutex); + +pinctrl_init_device_debugfs (pctldev); +} + +/** * pinctrl_register() - register a pin controller device * @pctldesc: descriptor for this pin controller * @dev: parent device for this pin controller
@@ -1766,6 +1812,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, pctldev->driver_data = driver_data;INIT_RADIX_TREE (&pctldev->pin_desc_tree,GFP_KERNEL );INIT_LIST_HEAD (&pctldev->gpio_ranges); +INIT_DELAYED_WORK (&pctldev->late_init, pinctrl_late_init); pctldev->dev = dev;mutex_init (&pctldev->mutex);
@@ -1800,32 +1847,10 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, goto out_err; } -mutex_lock (&pinctrldev_list_mutex); -list_add_tail (&pctldev->node, &pinctrldev_list); -mutex_unlock (&pinctrldev_list_mutex); - - pctldev->p =pinctrl_get (pctldev->dev); - -if (!IS_ERR (pctldev->p)) { - pctldev->hog_default = -pinctrl_lookup_state (pctldev->p,PINCTRL_STATE_DEFAULT ); -if (IS_ERR (pctldev->hog_default)) { -dev_dbg (dev,"failed to lookup the default state\n" ); - }else { -if (pinctrl_select_state (pctldev->p, - pctldev->hog_default)) -dev_err (dev, -"failed to select default state\n" ); - } - - pctldev->hog_sleep = -pinctrl_lookup_state (pctldev->p, -PINCTRL_STATE_SLEEP ); -if (IS_ERR (pctldev->hog_sleep)) -dev_dbg (dev,"failed to lookup the sleep state\n" ); - } - -pinctrl_init_device_debugfs (pctldev); +if (pinctrl_dt_has_hogs (pctldev)) +schedule_delayed_work (&pctldev->late_init,0 ); +else +pinctrl_late_init (&pctldev->late_init.work);return pctldev;
@@ -1848,6 +1873,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)if (pctldev ==NULL )return ; +cancel_delayed_work_sync (&pctldev->late_init);mutex_lock (&pctldev->mutex);pinctrl_remove_device_debugfs (pctldev);mutex_unlock (&pctldev->mutex);
drivers/pinctrl/core.h +2 -0
@@ -33,6 +33,7 @@ struct pinctrl_gpio_range;* @p: result of pinctrl_get() for this device * @hog_default: default state for pins hogged by this device * @hog_sleep: sleep state for pins hogged by this device +* @late_init: delayed work for pin controller to finish registration * @mutex: mutex taken on each pin controller specific action * @device_root: debugfs root for this device */
@@ -47,6 +48,7 @@ struct pinctrl_dev {struct pinctrl *p;struct pinctrl_state *hog_default;struct pinctrl_state *hog_sleep; +struct delayed_work late_init;struct mutex mutex;#ifdef CONFIG_DEBUG_FS struct dentry *device_root;
drivers/pinctrl/devicetree.c +23 -5
@@ -100,11 +100,12 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np)return get_pinctrl_dev_from_of_node (np); } -static int dt_to_map_one_config (struct pinctrl *p,const char *statename, +static int dt_to_map_one_config (struct pinctrl *p, +struct pinctrl_dev *pctldev, +const char *statename,struct device_node *np_config) {struct device_node *np_pctldev; -struct pinctrl_dev *pctldev;const struct pinctrl_ops *ops;int ret;struct pinctrl_map *map;
@@ -121,7 +122,8 @@ static int dt_to_map_one_config(struct pinctrl *p, const char *statename,/* OK let's just assume this will appear later then */ return -EPROBE_DEFER ; } - pctldev =get_pinctrl_dev_from_of_node (np_pctldev); +if (!pctldev) + pctldev =get_pinctrl_dev_from_of_node (np_pctldev);if (pctldev)break ;/* Do not defer probing of hogs (circular loop) */
@@ -166,7 +168,22 @@ static int dt_remember_dummy_state(struct pinctrl *p, const char *statename)return dt_remember_or_free_map (p, statename,NULL , map,1 ); } -int pinctrl_dt_to_map (struct pinctrl *p) +bool pinctrl_dt_has_hogs (struct pinctrl_dev *pctldev) +{ +struct device_node *np; +struct property *prop; +int size; + + np = pctldev->dev->of_node; +if (!np) +return false; + + prop =of_find_property (np,"pinctrl-0" , &size); + +return prop ? true : false; +} + +int pinctrl_dt_to_map (struct pinctrl *p,struct pinctrl_dev *pctldev) {struct device_node *np = p->dev->of_node;int state, ret;
@@ -233,7 +250,8 @@ int pinctrl_dt_to_map(struct pinctrl *p) }/* Parse the node */ - ret =dt_to_map_one_config (p, statename, np_config); + ret =dt_to_map_one_config (p, pctldev, statename, + np_config);of_node_put (np_config);if (ret <0 ) goto err;
drivers/pinctrl/devicetree.h +10 -2
@@ -20,8 +20,10 @@ struct of_phandle_args;#ifdef CONFIG_OF +bool pinctrl_dt_has_hogs (struct pinctrl_dev *pctldev); +void pinctrl_dt_free_maps (struct pinctrl *p); -int pinctrl_dt_to_map (struct pinctrl *p); +int pinctrl_dt_to_map (struct pinctrl *p,struct pinctrl_dev *pctldev);int pinctrl_count_index_with_args (const struct device_node *np,const char *list_name);
@@ -32,7 +34,13 @@ int pinctrl_parse_index_with_args(const struct device_node *np,#else -static inline int pinctrl_dt_to_map (struct pinctrl *p) +static inline bool pinctrl_dt_has_hogs (struct pinctrl_dev *pctldev) +{ +return false; +} + +static inline int pinctrl_dt_to_map (struct pinctrl *p, +struct pinctrl_dev *pctldev) {return 0 ; }
Signature · 1 line
2.10.2
Re: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 40 lines · Tony Lindgren
Quoted 39 lines · Tony Lindgren
Quoted 28 lines · Linus Walleij
Quoted 18 lines · Tony Lindgren
8< --------------------------------
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogsHaving the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct
pinctrl_devhandle. Note that we now need to callcreate_pinctrl()directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed. We also need to pass thepinctrl_devto the device tree parser functions as they otherwise won't find the right controller at this point.Quoted 1 line
Signed-off-by Tony Lindgren <[email protected]>This looks a lot better!
So if I understand correctly, we can guarantee that the delayed work will not execute until the device driver
probe()has finished, and it *will* execute immediately after that?Quoted 6 lines
So:
- Device driver probes
- Delayed work is called
- Next initcallI'm not 100% familiar with how delayed work works... :/
Yeah well the delayed work gets scheduled for next jiffy but may be pre-empted as it runs in process context.
Quoted 7 lines
Quoted 3 lines
So in the worst case it could that we still may need to fix few drivers to support -EPROBE_DEFER. I wonder if we should check for hogs in probe already and only defer if hogs are defined?
Below is a version using
delayed_workonly ifpinctrl_dt_has_hogs().Not sure if testing only for pinctrl-0 is enough there though?
Sorry for the lack of attention to this patch set on my part. :(
Do you think you could resend these last 5 patches after the release of v4.10-rc1 so we merge it early for the next cycle and people get a chance to test and see if it works well for everyone?
I'm worried about adding it to the tree this late in the kernel cycle...
However I like the look of the series overall a lot.
Yours,
Linus Walleij
Tony Lindgren
maintainerRe: [PATCH 1/5] pinctrl: core: Use delayed work for hogs
Quoted 47 lines · Linus Walleij
Quoted 46 lines · Tony Lindgren
Quoted 34 lines · Tony Lindgren
Quoted 33 lines · Linus Walleij
Quoted 18 lines · Tony Lindgren
8< --------------------------------
From tony Mon Sep 17 00:00:00 2001
From: Tony Lindgren <[email protected]>
Date: Tue, 25 Oct 2016 08:33:35 -0700
Subject: [PATCH] pinctrl: core: Use delayed work for hogsHaving the pin control framework call pin controller functions before it's probe has finished is not nice as the pin controller device driver does not yet have struct
pinctrl_devhandle.Let's fix this issue by adding deferred work for late init. This is needed to be able to add pinctrl generic helper functions that expect to know struct
pinctrl_devhandle. Note that we now need to callcreate_pinctrl()directly as we don't want to add the pin controller to the list of controllers until the hogs are claimed. We also need to pass thepinctrl_devto the device tree parser functions as they otherwise won't find the right controller at this point.Quoted 1 line
Signed-off-by Tony Lindgren <[email protected]>This looks a lot better!
So if I understand correctly, we can guarantee that the delayed work will not execute until the device driver
probe()has finished, and it *will* execute immediately after that?So:
- Device driver probes
- Delayed work is called
- Next initcallQuoted 8 lines
Quoted 1 line
I'm not 100% familiar with how delayed work works... :/
Yeah well the delayed work gets scheduled for next jiffy but may be pre-empted as it runs in process context.
So in the worst case it could that we still may need to fix few drivers to support -EPROBE_DEFER. I wonder if we should check for hogs in probe already and only defer if hogs are defined?
Below is a version using
delayed_workonly ifpinctrl_dt_has_hogs().
Quoted 8 lines
Quoted 1 line
Not sure if testing only for pinctrl-0 is enough there though?
Sorry for the lack of attention to this patch set on my part. :(
Do you think you could resend these last 5 patches after the release of v4.10-rc1 so we merge it early for the next cycle and people get a chance to test and see if it works well for everyone?
Yeah no problem, too late to do anything with them right now :)
Quoted 2 lines
I'm worried about adding it to the tree this late in the kernel cycle...
Yup me too.
Quoted 1 line
However I like the look of the series overall a lot.
OK good to hear.
Tony