pwm: dwc: allow suspend/resume for 16 channels
PATCH 1/1 pwm: dwc: allow suspend/resume for 16 channels
With 16 channel pwm support, we're registering two instances of pwm_chip with 8 channels each. We need to update PM functions to use both instances of pwm_chip during power state transitions.
Introduce struct dwc_pwm_drvdata and use it as driver_data, which will maintain both instances of pwm_chip along with dwc_pwm_info and allow us to use them inside suspend/resume handles.
--- drivers/pwm/pwm-dwc-core.c | 1 - drivers/pwm/pwm-dwc.c | 82 +++++++++++++++++++++++++------------- drivers/pwm/pwm-dwc.h | 6 +++ 3 files changed, 60 insertions(+), 29 deletions(-)
drivers/pwm/pwm-dwc-core.c +0 -1
@@ -172,7 +172,6 @@ struct pwm_chip *dwc_pwm_alloc(struct device *dev) dwc->clk_ns =10 ; chip->ops = &dwc_pwm_ops; -dev_set_drvdata (dev, chip);return chip; }EXPORT_SYMBOL_GPL (dwc_pwm_alloc);
drivers/pwm/pwm-dwc.c +54 -28
130 lines not on this page · raw message
drivers/pwm/pwm-dwc.h +6 -0
@@ -38,6 +38,12 @@ struct dwc_pwm_info {unsigned int size; }; +struct dwc_pwm_drvdata { +const struct dwc_pwm_info *info; +void __iomem *io_base; +struct pwm_chip *chips[]; +}; +struct dwc_pwm_ctx {u32 cnt;u32 cnt2;
Signature · 1 line
2.35.3
Hello,
drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 43
Quoted 11 lines · Raag Jadav
drivers/pwm/pwm-dwc.h +3
-0@@ -38,6 +38,12 @@ struct dwc_pwm_info {unsigned int size; }; +struct dwc_pwm_drvdata { +const struct dwc_pwm_info *info; +void __iomem *io_base;
.io_base is only used during init time and so doesn't need to be tracked in driver data.
Otherwise I (only slightly) dislike
drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 44
Quoted 1 line
drivers/pwm/pwm-dwc.h +1
-0+struct dwc_pwm_drvdata *data;
because "data" is very generic. I'd call it ddata. But I don't feel strong here. I'm happy if you change to "ddata" in v2, I will silently apply anyhow if you prefer "data".
drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 49
Quoted 6 lines
drivers/pwm/pwm-dwc.h +3
-0+struct pwm_chip *chips[]; +}; +struct dwc_pwm_ctx {u32 cnt;u32 cnt2;
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Quoted 1 line · Uwe Kleine-König
On Fri, Apr 12, 2024 at 11:38:12AM +0530, Raag Jadav wrote:
...
Quoted 6 lines
drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 43
Quoted 3 lines
drivers/pwm/pwm-dwc.h +3
-0+struct dwc_pwm_drvdata { +const struct dwc_pwm_info *info; +void __iomem *io_base;.io_base is only used during init time and so doesn't need to be tracked in driver data.
It's me who asked for this specific change and I think it's still beneficial as it allows to simplify the code.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hello,
Quoted 12 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König
On Fri, Apr 12, 2024 at 11:38:12AM +0530, Raag Jadav wrote:
...
Quoted 6 lines
drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 43
Quoted 3 lines
drivers/pwm/pwm-dwc.h +3
-0+struct dwc_pwm_drvdata { +const struct dwc_pwm_info *info; +void __iomem *io_base;.io_base is only used during init time and so doesn't need to be tracked in driver data.
Quoted 2 lines
It's me who asked for this specific change and I think it's still beneficial as it allows to simplify the code.
Ok then, feel free to keep it for v2 then.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Quoted 11 lines · Uwe Kleine-König
Hello,
Quoted 8 lines · Raag Jadav
drivers/pwm/pwm-dwc.h +0
-0@@ -38,6 +38,12 @@ struct dwc_pwm_info {unsigned int size; };
Quoted 6 lines
drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 43
Quoted 3 lines
drivers/pwm/pwm-dwc.h +3
-0+struct dwc_pwm_drvdata { +const struct dwc_pwm_info *info; +void __iomem *io_base;.io_base is only used during init time and so doesn't need to be tracked in driver data.
It will be useful for other features which are WIP.
Quoted 5 lines
Otherwise I (only slightly) dislike
drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 44
Quoted 1 line
drivers/pwm/pwm-dwc.h +1
-0+struct dwc_pwm_drvdata *data;because "data" is very generic. I'd call it ddata. But I don't feel strong here. I'm happy if you change to "ddata" in v2, I will silently apply anyhow if you prefer "data".
I think "data" is more readable, something like "ddata" would make me re-adjust my glasses ;)
Raag
Quoted 2 lines · Raag Jadav
Quoted 1 line · Uwe Kleine-König
On Fri, Apr 12, 2024 at 11:38:12AM +0530, Raag Jadav wrote:
...
Quoted 8 lines
Quoted 5 lines
Otherwise I (only slightly) dislike
drivers/pwm/pwm-dwc.c static const struct dwc_pwm_info ehl_pwm_info = { · line 59
Quoted 1 line
drivers/pwm/pwm-dwc.c +1
-0+struct dwc_pwm_drvdata *data;because "data" is very generic. I'd call it ddata. But I don't feel strong here. I'm happy if you change to "ddata" in v2, I will silently apply anyhow if you prefer "data".
I think "data" is more readable, something like "ddata" would make me re-adjust my glasses ;)
ddata is _kinda_ idiomatic, there at least several drivers use this name (as of my knowledge). I am bending towards Uwe's suggestion here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 12 lines · Andy Shevchenko
Quoted 2 lines · Raag Jadav
Quoted 1 line · Uwe Kleine-König
On Fri, Apr 12, 2024 at 11:38:12AM +0530, Raag Jadav wrote:
...
Quoted 6 lines
Quoted 5 lines
Otherwise I (only slightly) dislike
drivers/pwm/pwm-dwc.c static const struct dwc_pwm_info ehl_pwm_info = { · line 59
Quoted 1 line
drivers/pwm/pwm-dwc.c +1
-0+struct dwc_pwm_drvdata *data;because "data" is very generic. I'd call it ddata. But I don't feel strong here. I'm happy if you change to "ddata" in v2, I will silently apply anyhow if you prefer "data".
Quoted 5 lines
Quoted 2 lines
I think "data" is more readable, something like "ddata" would make me re-adjust my glasses ;)
ddata is _kinda_ idiomatic, there at least several drivers use this name (as of my knowledge). I am bending towards Uwe's suggestion here.
Will update in v2.
Raag
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
Quoted 7 lines · Raag Jadav
With 16 channel pwm support, we're registering two instances of
pwm_chipwith 8 channels each. We need to update PM functions to use both instances ofpwm_chipduring power state transitions.Introduce struct
dwc_pwm_drvdataand use it asdriver_data, which will maintain both instances ofpwm_chipalong withdwc_pwm_infoand allow us to use them inside suspend/resume handles.
...
drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) · line 76
Quoted 3 lines
drivers/pwm/pwm-dwc.c +3
-0+ data =devm_kzalloc (dev,struct_size (data, chips, info->nr),GFP_KERNEL ); +if (!data) +return dev_err_probe (dev, -ENOMEM ,"Failed to allocate drvdata\n" );
Haven't noticed before, but we do not print messages for -ENOMEM. Just return the code.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Raag Jadav
With 16 channel pwm support, we're registering two instances of
pwm_chipwith 8 channels each. We need to update PM functions to use both instances ofpwm_chipduring power state transitions.Introduce struct
dwc_pwm_drvdataand use it asdriver_data, which will maintain both instances ofpwm_chipalong withdwc_pwm_infoand allow us to use them inside suspend/resume handles.
Quoted 8 lines
...
drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) · line 76
Quoted 3 lines
drivers/pwm/pwm-dwc.c +3
-0+ data =devm_kzalloc (dev,struct_size (data, chips, info->nr),GFP_KERNEL ); +if (!data) +return dev_err_probe (dev, -ENOMEM ,"Failed to allocate drvdata\n" );Haven't noticed before, but we do not print messages for
-ENOMEM. Just return the code.
Any special case for -ENOMEM?
I found a few drivers which still do.
Raag
Quoted 2 lines · Raag Jadav
Quoted 1 line · Andy Shevchenko
On Fri, Apr 12, 2024 at 11:38:12AM +0530, Raag Jadav wrote:
...
Quoted 8 lines
Quoted 6 lines
drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) · line 76
Quoted 3 lines
drivers/pwm/pwm-dwc.c +3
-0+ data =devm_kzalloc (dev,struct_size (data, chips, info->nr),GFP_KERNEL ); +if (!data) +return dev_err_probe (dev, -ENOMEM ,"Failed to allocate drvdata\n" );Haven't noticed before, but we do not print messages for
-ENOMEM. Just return the code.Any special case for
-ENOMEM?
Yes. But I have no link to the discussion at hand. Just believe me, or look into Git history for changes that drop that messaging. Perhaps one or two will give a hint where it starts from...
Quoted 1 line
I found a few drivers which still do.
They should be fixed.
Signature · 2 lines
With Best Regards, Andy Shevchenko