reset: add support for non-DT systems
PATCH 1/1 reset: add support for non-DT systems
From: Bartosz Golaszewski <[email protected]>
The reset framework only supports device-tree. There are some platforms however, which need to use it even in legacy, board-file based mode.
An example of such architecture is the DaVinci family of SoCs which supports both device tree and legacy boot modes and we don't want to introduce any regressions.
We're currently working on converting the platform from its hand-crafted clock API to using the common clock framework. Part of the overhaul will be representing the chip's power sleep controller's reset lines using the reset framework.
This changeset extends the core reset code with a new field in the reset controller struct which contains an array of lookup entries. Each entry contains the device name and an additional, optional identifier string.
Drivers can register a set of reset lines using this lookup table and concerned devices can access them using the regular reset_control API.
This new function is only called as a fallback in case the of_node field is NULL and doesn't change anything for current users.
Tested with a dummy reset driver with several lookup entries.
An example lookup table can look like this:
static const struct reset_lookup foobar_reset_lookup[] = {
[FOO_RESET] = { .dev = "foo", .id = "foo_id" },
[BAR_RESET] = { .dev = "bar", .id = NULL },
{ }
};where FOO_RESET and BAR_RESET will correspond with the id parameters of reset callbacks.
--- drivers/reset/core.c | 43 ++++++++++++++++++++++++++++++++++++++-- include/linux/reset-controller.h | 13 ++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-)
drivers/reset/core.c +41 -2
@@ -493,12 +493,51 @@ struct reset_control *__of_reset_control_get(struct device_node *node, }EXPORT_SYMBOL_GPL (__of_reset_control_get); +static struct reset_control * +__reset_control_get_lookup (struct device *dev,const char *id, +bool shared,bool optional) +{ +struct reset_controller_dev *rcdev; +const char *dev_id =dev_name (dev); +struct reset_control *rstc =NULL ; +const struct reset_lookup *lookup; +int index; + +mutex_lock (&reset_list_mutex); + +list_for_each_entry (rcdev, &reset_controller_list, list) { +if (!rcdev->lookup) +continue ; + + lookup = rcdev->lookup; +for (index =0 ; lookup->dev; index++, lookup++) { +if (strcmp (dev_id, lookup->dev)) +continue ; + +if ((!id && !lookup->id) || + (id && lookup->id && !strcmp (id, lookup->id))) { + rstc =__reset_control_get_internal (rcdev, + index, shared); + } + } + } + +mutex_unlock (&reset_list_mutex); + +if (!rstc) +return optional ?NULL :ERR_PTR (-ENOENT ); + +return rstc; +} +struct reset_control *__reset_control_get (struct device *dev,const char *id,int index,bool shared,bool optional) {if (dev->of_node) -return __of_reset_control_get (dev->of_node, id, index, shared, - optional); +return __of_reset_control_get (dev->of_node, id, + index, shared, optional); +else +return __reset_control_get_lookup (dev, id, shared, optional);return optional ?NULL :ERR_PTR (-EINVAL ); }
include/linux/reset-controller.h +13 -0
@@ -22,6 +22,17 @@ struct reset_control_ops {int (*status)(struct reset_controller_dev *rcdev,unsigned long id); }; +/** +* struct reset_lookup - a single entry in a reset lookup table +* +* @dev: name of the device associated with this reset +* @id: additional reset identifier (if the device uses multiple reset lines) +*/ +struct reset_lookup { +const char *dev; +const char *id; +}; +struct module ;struct device_node ;struct of_phandle_args ;
@@ -34,6 +45,7 @@ struct of_phandle_args;* @list: internal list of reset controller devices * @reset_control_head: head of internal list of requested reset controls * @of_node: corresponding device tree node as phandle target +* @lookup: array of lookup entries associated with this request controller * @of_reset_n_cells: number of cells in reset line specifiers * @of_xlate: translation function to translate from specifier as found in the * device tree to id as given to the reset control ops
@@ -45,6 +57,7 @@ struct reset_controller_dev {struct list_head list;struct list_head reset_control_head;struct device_node *of_node; +const struct reset_lookup *lookup;int of_reset_n_cells;int (*of_xlate)(struct reset_controller_dev *rcdev,const struct of_phandle_args *reset_spec);
Signature · 1 line
2.16.1
Quoted 35 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
The reset framework only supports device-tree. There are some platforms however, which need to use it even in legacy, board-file based mode.
An example of such architecture is the DaVinci family of SoCs which supports both device tree and legacy boot modes and we don't want to introduce any regressions.
We're currently working on converting the platform from its hand-crafted clock API to using the common clock framework. Part of the overhaul will be representing the chip's power sleep controller's reset lines using the reset framework.
This changeset extends the core reset code with a new field in the reset controller struct which contains an array of lookup entries. Each entry contains the device name and an additional, optional identifier string.
Drivers can register a set of reset lines using this lookup table and concerned devices can access them using the regular
reset_controlAPI.This new function is only called as a fallback in case the
of_nodefield is NULL and doesn't change anything for current users.Tested with a dummy reset driver with several lookup entries.
An example lookup table can look like this:
static const struct reset_lookup foobar_reset_lookup[] = { [FOO_RESET] = { .dev = "foo", .id = "foo_id" }, [BAR_RESET] = { .dev = "bar", .id = NULL }, { } };
Quoted 8 lines
where
FOO_RESETandBAR_RESETwill correspond with the id parameters of reset callbacks.Cc Sekhar Nori <[email protected]>Cc Kevin Hilman <[email protected]>Cc David Lechner <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>---
Looks good to me. I just made a few very minor comments. I will try to use this in PSC driver later today.
Quoted 9 lines
drivers/reset/core.c | 43 ++++++++++++++++++++++++++++++++++++++-- include/linux/reset-controller.h | 13 ++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-)drivers/reset/core.c +0
-0
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 497
Quoted 5 lines
drivers/reset/core.c +2
-0@@ -493,12 +493,51 @@ struct reset_control *__of_reset_control_get(struct device_node *node, }EXPORT_SYMBOL_GPL (__of_reset_control_get); +static struct reset_control * +__reset_control_get_lookup(struct device *dev, const char *id,
Based on the name of the function, I expected this to return struct reset_lookup. Perhaps __reset_control_lookup() or __reset_control_match_lookup() would be a slightly better name?
Quoted 33 lines
drivers/reset/core.c +33
-0+ bool shared, bool optional) +{ +struct reset_controller_dev *rcdev; +const char *dev_id =dev_name (dev); +struct reset_control *rstc =NULL ; +const struct reset_lookup *lookup; +int index; + +mutex_lock (&reset_list_mutex); + +list_for_each_entry (rcdev, &reset_controller_list, list) { +if (!rcdev->lookup) +continue ; + + lookup = rcdev->lookup; +for (index =0 ; lookup->dev; index++, lookup++) { +if (strcmp (dev_id, lookup->dev)) +continue ; + +if ((!id && !lookup->id) || + (id && lookup->id && !strcmp (id, lookup->id))) { + rstc =__reset_control_get_internal (rcdev, + index, shared); + } + } + } + +mutex_unlock (&reset_list_mutex); + +if (!rstc) +return optional ?NULL :ERR_PTR (-ENOENT ); + +return rstc;
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 538
Quoted 10 lines
drivers/reset/core.c +4
-2+} +struct reset_control *__reset_control_get (struct device *dev,const char *id,int index,bool shared,bool optional) {if (dev->of_node) -return __of_reset_control_get (dev->of_node, id, index, shared, - optional); +return __of_reset_control_get (dev->of_node, id, + index, shared, optional);
I don't understand why this line is changed. It is just being rearranged?
Quoted 28 lines
drivers/reset/core.c +2
-0+else +return __reset_control_get_lookup (dev, id, shared, optional);return optional ?NULL :ERR_PTR (-EINVAL ); }include/linux/reset-controller.h +11
-0@@ -22,6 +22,17 @@ struct reset_control_ops {int (*status)(struct reset_controller_dev *rcdev,unsigned long id); }; +/** +* struct reset_lookup - a single entry in a reset lookup table +* +* @dev: name of the device associated with this reset +* @id: additional reset identifier (if the device uses multiple reset lines) +*/ +struct reset_lookup { +const char *dev; +const char *id; +}; +struct module ;struct device_node ;struct of_phandle_args ;
include/linux/reset-controller.h struct of_phandle_args; · line 48
Quoted 4 lines
include/linux/reset-controller.h +1
-0@@ -34,6 +45,7 @@ struct of_phandle_args;* @list: internal list of reset controller devices * @reset_control_head: head of internal list of requested reset controls * @of_node: corresponding device tree node as phandle target +* @lookup: array of lookup entries associated with this request controller
Might be nice to mention that this array must end with an empty struct (i.e. lookup->dev == NULL)
Quoted 12 lines
include/linux/reset-controller.h +1
-0* @of_reset_n_cells: number of cells in reset line specifiers * @of_xlate: translation function to translate from specifier as found in the * device tree to id as given to the reset control ops @@ -45,6 +57,7 @@ struct reset_controller_dev {struct list_head list;struct list_head reset_control_head;struct device_node *of_node; +const struct reset_lookup *lookup;int of_reset_n_cells;int (*of_xlate)(struct reset_controller_dev *rcdev,const struct of_phandle_args *reset_spec);
2018-02-13 18:17 GMT+01:00 David Lechner <[email protected]>:
Quoted 47 lines · Bartosz Golaszewski
Quoted 36 lines
From: Bartosz Golaszewski <[email protected]>
The reset framework only supports device-tree. There are some platforms however, which need to use it even in legacy, board-file based mode.
An example of such architecture is the DaVinci family of SoCs which supports both device tree and legacy boot modes and we don't want to introduce any regressions.
We're currently working on converting the platform from its hand-crafted clock API to using the common clock framework. Part of the overhaul will be representing the chip's power sleep controller's reset lines using the reset framework.
This changeset extends the core reset code with a new field in the reset controller struct which contains an array of lookup entries. Each entry contains the device name and an additional, optional identifier string.
Drivers can register a set of reset lines using this lookup table and concerned devices can access them using the regular
reset_controlAPI.This new function is only called as a fallback in case the
of_nodefield is NULL and doesn't change anything for current users.Tested with a dummy reset driver with several lookup entries.
An example lookup table can look like this:
static const struct reset_lookup foobar_reset_lookup[] = { [FOO_RESET] = { .dev = "foo", .id = "foo_id" }, [BAR_RESET] = { .dev = "bar", .id = NULL }, { } };Quoted 8 lines
where
FOO_RESETandBAR_RESETwill correspond with the id parameters of reset callbacks.Cc Sekhar Nori <[email protected]>Cc Kevin Hilman <[email protected]>Cc David Lechner <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>---
Quoted 3 lines
Looks good to me. I just made a few very minor comments. I will try to use this in PSC driver later today.
Cool, if it works for you - feel free to include it in your series.
Quoted 40 lines
Quoted 11 lines
drivers/reset/core.c | 43 ++++++++++++++++++++++++++++++++++++++-- include/linux/reset-controller.h | 13 ++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-)drivers/reset/core.c +0
-0drivers/reset/core.c struct reset_control *__of_reset_control_get(struct · line 497
Quoted 5 lines
drivers/reset/core.c +1
-0@@ -493,12 +493,51 @@ struct reset_control *__of_reset_control_get(structdevice_node *node, }EXPORT_SYMBOL_GPL (__of_reset_control_get ); +static struct reset_control * +__reset_control_get_lookup(struct device *dev, const char *id,Based on the name of the function, I expected this to return struct
reset_lookup. Perhaps__reset_control_lookup()or__reset_control_match_lookup()would be a slightly better name?Quoted 17 lines
drivers/reset/core.c +17
-0+ bool shared, bool optional) +{ +struct reset_controller_dev *rcdev; +const char *dev_id =dev_name (dev); +struct reset_control *rstc =NULL ; +const struct reset_lookup *lookup; +int index; + +mutex_lock (&reset_list_mutex); + +list_for_each_entry (rcdev, &reset_controller_list, list) { +if (!rcdev->lookup) +continue ; + + lookup = rcdev->lookup; +for (index =0 ; lookup->dev; index++, lookup++) { +if (strcmp (dev_id, lookup->dev))
Quoted 8 lines
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node,
Quoted 8 lines
drivers/reset/core.c +6
-0+continue ; + +if ((!id && !lookup->id) || + (id && lookup->id && !strcmp (id, lookup->id))) { + rstc =__reset_control_get_internal (rcdev, + index, shared);
Ugh, I noticed that this needs a break here, otherwise we'll always iterate over all the entries.
Quoted 18 lines
Quoted 18 lines
drivers/reset/core.c +12
-0+ } + } + } + +mutex_unlock (&reset_list_mutex); + +if (!rstc) +return optional ?NULL :ERR_PTR (-ENOENT ); + +return rstc; +} +struct reset_control *__reset_control_get (struct device *dev,const char *id,int index,bool shared,bool optional) {if (dev->of_node)
Quoted 9 lines
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 538
Quoted 5 lines
- return __of_reset_control_get(dev->of_node, id, index,
shared,drivers/reset/core.c +2
-1- optional); +return __of_reset_control_get (dev->of_node, id, + index, shared, optional);I don't understand why this line is changed. It is just being rearranged?
Yes, but I can leave it out of this patch.
Quoted 43 lines
Quoted 33 lines
drivers/reset/core.c +2
-0+else + return __reset_control_get_lookup(dev, id, shared,optional); return optional ? NULL : ERR_PTR(-EINVAL);}
include/linux/reset-controller.h +10
-0@@ -22,6 +22,17 @@ struct reset_control_ops {int (*status)(struct reset_controller_dev *rcdev,unsigned long id); }; +/** +* struct reset_lookup - a single entry in a reset lookup table +* +* @dev: name of the device associated with this reset +* @id: additional reset identifier (if the device uses multiple reset lines) +*/ +struct reset_lookup { + const char *dev; +const char *id; +}; +struct module ;struct device_node ;struct of_phandle_args ;@@ -34,6 +45,7 @@ struct of_phandle_args;* @list: internal list of reset controller devices * @reset_control_head: head of internal list of requested reset Quoted 4 lines
controls
* @of_node: corresponding device tree node as phandle target
+ * @lookup: array of lookup entries associated with this request controllerMight be nice to mention that this array must end with an empty struct (i.e.
lookup->dev== NULL)
Quoted 14 lines
include/linux/reset-controller.h struct reset_controller_dev { · line 63
Quoted 13 lines
* @of_reset_n_cells: number of cells in reset line specifiers
* @of_xlate: translation function to translate from specifier as found
in the
* device tree to id as given to the reset control opsinclude/linux/reset-controller.h +1
-0@@ -45,6 +57,7 @@ struct reset_controller_dev {struct list_head list;struct list_head reset_control_head;struct device_node *of_node; +const struct reset_lookup *lookup;int of_reset_n_cells;int (*of_xlate)(struct reset_controller_dev *rcdev,const struct of_phandle_args *reset_spec);
Bartosz