Skip to contentSkip to conversation

pwm: dwc: allow suspend/resume for 16 channels

PATCH Superseded Raag Jadav 3 participants 10 messages Apr 12, 2024 PWM

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Raag Jadav

author
#0 lore raw

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.

Fixes ebf2c89eb95e ("pwm: dwc: Add 16 channel support for Intel Elkhart Lake")
---
 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
index 043736972cb9..c8425493b95d 100644
@@ -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
index a8b074841ae8..c6e2df5a6122 100644
@@ -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
#1 lore raw

Hello,

drivers/pwm/pwm-dwc.h struct dwc_pwm_info { · line 43

Quoted 11 lines · Raag Jadav
drivers/pwm/pwm-dwc.h +3 -0
index a8b074841ae8..c6e2df5a6122 100644
@@ -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/ |
#2 lore raw
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
#3 lore raw

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/ |
author
#4 lore raw
In reply to Uwe Kleine-König
Quoted 11 lines · Uwe Kleine-König

Hello,

Quoted 8 lines · Raag Jadav
drivers/pwm/pwm-dwc.h +0 -0
index a8b074841ae8..c6e2df5a6122 100644
@@ -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

#5 lore raw
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
author
#6 lore raw
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
#7 lore raw
In reply to Raag Jadav
Quoted 7 lines · Raag Jadav

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.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
author
#8 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Raag Jadav

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.

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

#9 lore raw
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