reset: Add a managed API
v2 cover reset: Add a managed API
Hi,
This is the 4th of a few series that are re-rolls of Jean-Jacques' earlier efforts. The goal is to facilitate porting drivers from the Linux kernel.
This particular series is about reset controllers. It adds a managed API, close to that of Linux. The main difference is that bulk and reset_ctl are handled with different functions.
Changes in v2:
- Fix test build failing because of missing function prototypes and includes.
- Drop NULL checks from the reset core. For now let drivers handle them. We can always add the checks back if we think they are a better idea.
- Rebase on latest master.
Jean-Jacques Hiblot (2):
drivers: reset: Add a managed API to get reset controllers from the DT
test: reset: Add tests for the managed API
arch/sandbox/include/asm/reset.h | 3 + drivers/reset/reset-uclass.c | 118 ++++++++++++++++++++++++- drivers/reset/sandbox-reset-test.c | 51 +++++++++-- drivers/reset/sandbox-reset.c | 19 ++++ include/reset.h | 135 ++++++++++++++++++++++++++++- test/dm/reset.c | 60 +++++++++++++ 6 files changed, 375 insertions(+), 11 deletions(-)
--
2.27.0
PATCH v2 1/2 drivers: reset: Add a managed API to get reset controllers from the DT
From: Jean-Jacques Hiblot <[email protected]>
Add managed functions to get a reset_ctl from the device-tree, based on a name or an index.
Also add a managed functions to get a reset_ctl_bulk (array of reset_ctl) from the device-tree.
When the device is unbound, the reset controllers are automatically released and the data structure is freed.
--- drivers/reset/reset-uclass.c | 118 ++++++++++++++++++++++++++++-- include/reset.h | 135 ++++++++++++++++++++++++++++++++++- 2 files changed, 248 insertions(+), 5 deletions(-)
drivers/reset/reset-uclass.c +114 -4
@@ -11,6 +11,7 @@#include <reset.h> #include <reset-uclass.h> #include <dm/devres.h> +#include <dm/lists.h> static inline struct reset_ops *reset_dev_ops (struct udevice *dev) {
@@ -100,13 +101,14 @@ int reset_get_by_index_nodev(ofnode node, int index, index > 0, reset_ctl); } -int reset_get_bulk (struct udevice *dev,struct reset_ctl_bulk *bulk) +static int __reset_get_bulk (struct udevice *dev,ofnode node, +struct reset_ctl_bulk *bulk) {int i, ret, err, count; - + bulk->count =0 ; - count =dev_count_phandle_with_args (dev,"resets" ,"#reset-cells" ); + count =ofnode_count_phandle_with_args (node,"resets" ,"#reset-cells" );if (count <1 )return count;
@@ -116,7 +118,7 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk)return -ENOMEM ;for (i =0 ; i < count; i++) { - ret =reset_get_by_index (dev, i, &bulk->resets[i]); + ret =reset_get_by_index_nodev (node, i, &bulk->resets[i]);if (ret <0 ) goto bulk_get_err;
@@ -134,6 +136,11 @@ bulk_get_err:return ret; } +int reset_get_bulk (struct udevice *dev,struct reset_ctl_bulk *bulk) +{ +return __reset_get_bulk (dev,dev_ofnode (dev), bulk); +} +int reset_get_by_name (struct udevice *dev,const char *name,struct reset_ctl *reset_ctl) {
@@ -246,6 +253,109 @@ int reset_release_all(struct reset_ctl *reset_ctl, int count)return 0 ; } +static void devm_reset_release (struct udevice *dev,void *res) +{ +reset_free (res); +} + +struct reset_ctl *devm_reset_control_get_by_index (struct udevice *dev, +int index) +{ +int rc; +struct reset_ctl *reset_ctl; + + reset_ctl =devres_alloc (devm_reset_release,sizeof (struct reset_ctl ), + __GFP_ZERO); +if (unlikely (!reset_ctl)) +return ERR_PTR (-ENOMEM ); + + rc =reset_get_by_index (dev, index, reset_ctl); +if (rc) +return ERR_PTR (rc); + +devres_add (dev, reset_ctl); +return reset_ctl; +} + +struct reset_ctl *devm_reset_control_get (struct udevice *dev,const char *id) +{ +int rc; +struct reset_ctl *reset_ctl; + + reset_ctl =devres_alloc (devm_reset_release,sizeof (struct reset_ctl ), + __GFP_ZERO); +if (unlikely (!reset_ctl)) +return ERR_PTR (-ENOMEM ); + + rc =reset_get_by_name (dev, id, reset_ctl); +if (rc) +return ERR_PTR (rc); + +devres_add (dev, reset_ctl); +return reset_ctl; +} + +struct reset_ctl *devm_reset_control_get_optional (struct udevice *dev, +const char *id) +{ +struct reset_ctl *r =devm_reset_control_get (dev, id); + +if (IS_ERR (r)) +return NULL ; + +return r; +} + +static void devm_reset_bulk_release (struct udevice *dev,void *res) +{ +struct reset_ctl_bulk *bulk = res; + +reset_release_all (bulk->resets, bulk->count); +} + +struct reset_ctl_bulk *devm_reset_bulk_get_by_node (struct udevice *dev, +ofnode node) +{ +int rc; +struct reset_ctl_bulk *bulk; + + bulk =devres_alloc (devm_reset_bulk_release, +sizeof (struct reset_ctl_bulk ), + __GFP_ZERO); +if (unlikely (!bulk)) +return ERR_PTR (-ENOMEM ); + + rc =__reset_get_bulk (dev, node, bulk); +if (rc) +return ERR_PTR (rc); + +devres_add (dev, bulk); +return bulk; +} + +struct reset_ctl_bulk *devm_reset_bulk_get_optional_by_node (struct udevice *dev, +ofnode node) +{ +struct reset_ctl_bulk *bulk; + + bulk =devm_reset_bulk_get_by_node (dev, node); + +if (IS_ERR (bulk)) +return NULL ; + +return bulk; +} + +struct reset_ctl_bulk *devm_reset_bulk_get (struct udevice *dev) +{ +return devm_reset_bulk_get_by_node (dev,dev_ofnode (dev)); +} + +struct reset_ctl_bulk *devm_reset_bulk_get_optional (struct udevice *dev) +{ +return devm_reset_bulk_get_optional_by_node (dev,dev_ofnode (dev)); +} +UCLASS_DRIVER (reset) = { .id =UCLASS_RESET , .name ="reset" ,
include/reset.h +134 -1
154 lines not on this page · raw message
--
2.27.0
PATCH v2 2/2 test: reset: Add tests for the managed API
In reply to Pratyush YadavFrom: Jean-Jacques Hiblot <[email protected]>
The tests are basically the same as for the regular API. Except that the reset are initialized using the managed API, and no freed manually.
--- arch/sandbox/include/asm/reset.h | 3 ++ drivers/reset/sandbox-reset-test.c | 51 ++++++++++++++++++++++--- drivers/reset/sandbox-reset.c | 19 ++++++++++ test/dm/reset.c | 60 ++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 6 deletions(-)
arch/sandbox/include/asm/reset.h +3 -0
@@ -11,9 +11,12 @@struct udevice ;int sandbox_reset_query (struct udevice *dev,unsigned long id); +int sandbox_reset_is_requested (struct udevice *dev,unsigned long id);int sandbox_reset_test_get (struct udevice *dev); +int sandbox_reset_test_get_devm (struct udevice *dev);int sandbox_reset_test_get_bulk (struct udevice *dev); +int sandbox_reset_test_get_bulk_devm (struct udevice *dev);int sandbox_reset_test_assert (struct udevice *dev);int sandbox_reset_test_assert_bulk (struct udevice *dev);int sandbox_reset_test_deassert (struct udevice *dev);
drivers/reset/sandbox-reset-test.c +45 -6
111 lines not on this page · raw message
drivers/reset/sandbox-reset.c +19 -0
@@ -15,6 +15,7 @@struct sandbox_reset_signal {bool asserted; +bool requested; };struct sandbox_reset {
@@ -23,18 +24,24 @@ struct sandbox_reset {static int sandbox_reset_request (struct reset_ctl *reset_ctl) { +struct sandbox_reset *sbr =dev_get_priv (reset_ctl->dev); +debug ("%s(reset_ctl=%p)\n" , __func__, reset_ctl);if (reset_ctl->id >=SANDBOX_RESET_SIGNALS )return -EINVAL ; + sbr->signals[reset_ctl->id].requested = true;return 0 ; }static int sandbox_reset_free (struct reset_ctl *reset_ctl) { +struct sandbox_reset *sbr =dev_get_priv (reset_ctl->dev); +debug ("%s(reset_ctl=%p)\n" , __func__, reset_ctl); + sbr->signals[reset_ctl->id].requested = false;return 0 ; }
@@ -107,3 +114,15 @@ int sandbox_reset_query(struct udevice *dev, unsigned long id)return sbr->signals[id].asserted; } + +int sandbox_reset_is_requested (struct udevice *dev,unsigned long id) +{ +struct sandbox_reset *sbr =dev_get_priv (dev); + +debug ("%s(dev=%p, id=%ld)\n" , __func__, dev, id); + +if (id >=SANDBOX_RESET_SIGNALS ) +return -EINVAL ; + +return sbr->signals[id].requested; +}
test/dm/reset.c +60 -0
81 lines not on this page · raw message
--
2.27.0
PATCH v2 2/2 test: reset: Add tests for the managed API
Quoted 6 lines · Pratyush Yadav
From: Jean-Jacques Hiblot <[email protected]>
The tests are basically the same as for the regular API. Except that the reset are initialized using the managed API, and no freed manually.
Quoted 9 lines
Signed-off-by Jean-Jacques Hiblot <[email protected]>Signed-off-by Pratyush Yadav <[email protected]>--- arch/sandbox/include/asm/reset.h | 3 ++ drivers/reset/sandbox-reset-test.c | 51 ++++++++++++++++++++++--- drivers/reset/sandbox-reset.c | 19 ++++++++++ test/dm/reset.c | 60 ++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 6 deletions(-)
v2 cover reset: Add a managed API
In reply to Pratyush YadavHi Simon,
Quoted 9 lines · Pratyush Yadav
Hi,
This is the 4th of a few series that are re-rolls of Jean-Jacques' earlier efforts. The goal is to facilitate porting drivers from the Linux kernel.
This particular series is about reset controllers. It adds a managed API, close to that of Linux. The main difference is that bulk and
reset_ctlare handled with different functions.
I don't see this series in v2020.10-rc1. Has it fell through the cracks somehow?
Quoted 22 lines
Changes in v2:
- Fix test build failing because of missing function prototypes and includes.
- Drop NULL checks from the reset core. For now let drivers handle them. We can always add the checks back if we think they are a better idea.
- Rebase on latest master.Jean-Jacques Hiblot (2):
drivers: reset: Add a managed API to get reset controllers from the DT
test: reset: Add tests for the managed APIarch/sandbox/include/asm/reset.h | 3 + drivers/reset/reset-uclass.c | 118 ++++++++++++++++++++++++- drivers/reset/sandbox-reset-test.c | 51 +++++++++-- drivers/reset/sandbox-reset.c | 19 ++++ include/reset.h | 135 ++++++++++++++++++++++++++++- test/dm/reset.c | 60 +++++++++++++ 6 files changed, 375 insertions(+), 11 deletions(-)--
2.27.0
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments India
v2 cover reset: Add a managed API
Hi Pratyush,
Quoted 10 lines · Pratyush Yadav
Hi Simon,
Quoted 6 lines · Pratyush Yadav
Hi,
This is the 4th of a few series that are re-rolls of Jean-Jacques' earlier efforts. The goal is to facilitate porting drivers from the Linux kernel.
Quoted 6 lines
Quoted 3 lines
This particular series is about reset controllers. It adds a managed API, close to that of Linux. The main difference is that bulk and
reset_ctlare handled with different functions.I don't see this series in v2020.10-rc1. Has it fell through the cracks somehow?
I'm not sure...can you check patchwork?
Regards,
Simon