Skip to contentSkip to conversation

DesignWare PWM improvements

PATCH Superseded Raag Jadav 4 participants 19 messages Jan 22, 2024 – Feb 7, 2024 PWM

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Raag Jadav

author
#0 lore raw

cover DesignWare PWM improvements

This series adds 16 channel support for Intel Elkhart Lake and simplifies code using standard helpers in DesignWare PWM driver.

Raag Jadav (3):
pwm: dwc: Add 16 channel support for Intel Elkhart Lake
pwm: dwc: simplify error handling
pwm: dwc: use to_pci_dev() helper

 drivers/pwm/pwm-dwc.c | 71 +++++++++++++++++++++++++++++--------------
 drivers/pwm/pwm-dwc.h |  5 +++
 2 files changed, 54 insertions(+), 22 deletions(-)

base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d

Signature · 1 line
2.35.3
author
#1 lore raw

PATCH 1/3 pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Intel Elkhart Lake PSE includes two instances of PWM as a single PCI function with 8 channels each. Add support for the remaining channels.

---
 drivers/pwm/pwm-dwc.c | 51 +++++++++++++++++++++++++++++++++++--------
 drivers/pwm/pwm-dwc.h |  5 +++++
 2 files changed, 47 insertions(+), 9 deletions(-)
drivers/pwm/pwm-dwc.c +42 -9
index 4929354f8cd9..fd64313cb38d 100644
@@ -25,16 +25,48 @@
 
 #include "pwm-dwc.h"
 
+/* Elkhart Lake */
+static const struct dwc_pwm_info ehl_pwm_info = {
+	.nr = 2,
+	.size = 0x1000,
+};
+
+static int dwc_pwm_init(struct device *dev, const struct dwc_pwm_info *info, void __iomem *base)
+{
+	/* Default values for single instance devices */
+	unsigned int nr = 1, size = 0;
+	int i, ret;
+
+	/* Fill up values from driver_data, if any */
+	if (info) {
+		nr = info->nr;
+		size = info->size;
+	}
+
+	for (i = 0; i < nr; i++) {
+		struct dwc_pwm *dwc;
+
+		dwc = dwc_pwm_alloc(dev);
+		if (!dwc)
+			return -ENOMEM;
+
+		dwc->base = base + (i * size);
+
+		ret = devm_pwmchip_add(dev, &dwc->chip);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
 {
+	const struct dwc_pwm_info *info;
 	struct device *dev = &pci->dev;
-	struct dwc_pwm *dwc;
+	void __iomem *base;
 	int ret;
 
-	dwc = dwc_pwm_alloc(dev);
-	if (!dwc)
-		return -ENOMEM;
-
 	ret = pcim_enable_device(pci);
 	if (ret) {
 		dev_err(dev, "Failed to enable device (%pe)\n", ERR_PTR(ret));
@@ -49,13 +81,14 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
 		return ret;
 	}
 
-	dwc->base = pcim_iomap_table(pci)[0];
-	if (!dwc->base) {
+	base = pcim_iomap_table(pci)[0];
+	if (!base) {
 		dev_err(dev, "Base address missing\n");
 		return -ENOMEM;
 	}
 
-	ret = devm_pwmchip_add(dev, &dwc->chip);
+	info = (const struct dwc_pwm_info *)id->driver_data;
+	ret = dwc_pwm_init(dev, info, base);
 	if (ret)
 		return ret;
 
@@ -109,7 +142,7 @@ static int dwc_pwm_resume(struct device *dev)
 static DEFINE_SIMPLE_DEV_PM_OPS(dwc_pwm_pm_ops, dwc_pwm_suspend, dwc_pwm_resume);
 
 static const struct pci_device_id dwc_pwm_id_table[] = {
-	{ PCI_VDEVICE(INTEL, 0x4bb7) }, /* Elkhart Lake */
+	{ PCI_VDEVICE(INTEL, 0x4bb7), (kernel_ulong_t)&ehl_pwm_info },
 	{  }	/* Terminating Entry */
 };
 MODULE_DEVICE_TABLE(pci, dwc_pwm_id_table);
drivers/pwm/pwm-dwc.h +5 -0
index 64795247c54c..c9bbfc77b568 100644
@@ -33,6 +33,11 @@ MODULE_IMPORT_NS(dwc_pwm);
 #define DWC_TIM_CTRL_INT_MASK	BIT(2)
 #define DWC_TIM_CTRL_PWM	BIT(3)
 
+struct dwc_pwm_info {
+	unsigned int nr;
+	unsigned int size;
+};
+
 struct dwc_pwm_ctx {
 	u32 cnt;
 	u32 cnt2;
Signature · 1 line
2.35.3
#2 lore raw

Re: [PATCH v1 1/3] pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Quoted 2 lines · Raag Jadav

Intel Elkhart Lake PSE includes two instances of PWM as a single PCI function with 8 channels each. Add support for the remaining channels.

...

Quoted 18 lines
drivers/pwm/pwm-dwc.c +18 -0
+static int dwc_pwm_init(struct device *dev, const struct dwc_pwm_info *info, void __iomem *base)
+{
+	/* Default values for single instance devices */
+	unsigned int nr = 1, size = 0;
+	int i, ret;
+
+	/* Fill up values from driver_data, if any */
+	if (info) {
+		nr = info->nr;
+		size = info->size;
+	}
+
+	for (i = 0; i < nr; i++) {
+		struct dwc_pwm *dwc;
+
+		dwc = dwc_pwm_alloc(dev);
+		if (!dwc)
+			return -ENOMEM;

drivers/pwm/pwm-dwc.c line 61

Quoted 10 lines
drivers/pwm/pwm-dwc.c +10 -0
+
+		dwc->base = base + (i * size);
+
+		ret = devm_pwmchip_add(dev, &dwc->chip);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}

Why not doing this slightly differently?

First option: Always provide driver data (info is never NULL).

Second option, have the body of the for-loop be factored to a helper dwc_pwm_init_one() and here

	if (!info)
		return dwc_pwm_init_one(..., 1, 0);

	for (i = 0; i < info->nr; i++) {
		ret = dwc_pwm_init_one(...);
		if (ret)
			return ret;
	}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw

Re: [PATCH v1 1/3] pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Quoted 37 lines · Andy Shevchenko
Quoted 2 lines · Raag Jadav

Intel Elkhart Lake PSE includes two instances of PWM as a single PCI function with 8 channels each. Add support for the remaining channels.

...

Quoted 18 lines
drivers/pwm/pwm-dwc.c +18 -0
+static int dwc_pwm_init(struct device *dev, const struct dwc_pwm_info *info, void __iomem *base)
+{
+	/* Default values for single instance devices */
+	unsigned int nr = 1, size = 0;
+	int i, ret;
+
+	/* Fill up values from driver_data, if any */
+	if (info) {
+		nr = info->nr;
+		size = info->size;
+	}
+
+	for (i = 0; i < nr; i++) {
+		struct dwc_pwm *dwc;
+
+		dwc = dwc_pwm_alloc(dev);
+		if (!dwc)
+			return -ENOMEM;

drivers/pwm/pwm-dwc.c line 61

Quoted 10 lines
drivers/pwm/pwm-dwc.c +10 -0
+
+		dwc->base = base + (i * size);
+
+		ret = devm_pwmchip_add(dev, &dwc->chip);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}

Why not doing this slightly differently?

Quoted 1 line

First option: Always provide driver data (info is never NULL).

Allowing empty driver_data would save us from adding dummy info for single instance devices in the future.

Quoted 11 lines

Second option, have the body of the for-loop be factored to a helper dwc_pwm_init_one() and here

	if (!info)
		return dwc_pwm_init_one(..., 1, 0);

	for (i = 0; i < info->nr; i++) {
		ret = dwc_pwm_init_one(...);
		if (ret)
			return ret;
	}

Considering above, we're looking at something like this.

static int dwc_pwm_init_one(struct device *dev, void __iomem *base, unsigned int size)

{
        struct dwc_pwm *dwc;

        dwc = dwc_pwm_alloc(dev);
        if (!dwc)
                return -ENOMEM;

        dwc->base = base + size;

        return devm_pwmchip_add(dev, &dwc->chip);
}
	...

        if (info) {
                for (i = 0; i < info->nr; i++) {
                        ret = dwc_pwm_init_one(dev, base, i * info->size);
                        if (ret)
                                return ret;
                }
        } else {
                ret = dwc_pwm_init_one(dev, base, 0);
                if (ret)
                        return ret;
        }
	...

Raag

#4 lore raw

Re: [PATCH v1 1/3] pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Quoted 4 lines · Raag Jadav
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Raag Jadav

Intel Elkhart Lake PSE includes two instances of PWM as a single PCI function with 8 channels each. Add support for the remaining channels.

...

Quoted 4 lines
Quoted 1 line

First option: Always provide driver data (info is never NULL).

Allowing empty driver_data would save us from adding dummy info for single instance devices in the future.

Which may be too premature "optimisation". Why? Because if we ever have something like pci_dev_get_match_data(), the empty will mean NULL, and we may not get difference between empty and missing one.

Quoted 6 lines
Quoted 6 lines

Second option, have the body of the for-loop be factored to a helper dwc_pwm_init_one() and here

	if (!info)
		return dwc_pwm_init_one(..., 1, 0);
Quoted 7 lines
Quoted 5 lines
	for (i = 0; i < info->nr; i++) {
		ret = dwc_pwm_init_one(...);
		if (ret)
			return ret;
	}

Considering above, we're looking at something like this.

As one option, yes.

Quoted 12 lines

static int dwc_pwm_init_one(struct device *dev, void __iomem *base, unsigned int size)

{
        struct dwc_pwm *dwc;

        dwc = dwc_pwm_alloc(dev);
        if (!dwc)
                return -ENOMEM;

        dwc->base = base + size;

        return devm_pwmchip_add(dev, &dwc->chip);
}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#5 lore raw

Re: [PATCH v1 1/3] pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Raag Jadav
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Raag Jadav

Intel Elkhart Lake PSE includes two instances of PWM as a single PCI function with 8 channels each. Add support for the remaining channels.

...

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

First option: Always provide driver data (info is never NULL).

Allowing empty driver_data would save us from adding dummy info for single instance devices in the future.

Which may be too premature "optimisation". Why? Because if we ever have something like pci_dev_get_match_data(), the empty will mean NULL, and we may not get difference between empty and missing one.

Not sure if I'm able to find such a helper as of now, but fair. I can change it in v2 if Jarkko is okay with it.

Raag

author
#6 lore raw

Re: [PATCH v1 1/3] pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Quoted 14 lines · Raag Jadav
Quoted 13 lines · Andy Shevchenko
Quoted 4 lines · Raag Jadav
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Raag Jadav

Intel Elkhart Lake PSE includes two instances of PWM as a single PCI function with 8 channels each. Add support for the remaining channels.

...

Quoted 4 lines
Quoted 1 line

First option: Always provide driver data (info is never NULL).

Allowing empty driver_data would save us from adding dummy info for single instance devices in the future.

Quoted 6 lines
Quoted 3 lines

Which may be too premature "optimisation". Why? Because if we ever have something like pci_dev_get_match_data(), the empty will mean NULL, and we may not get difference between empty and missing one.

Not sure if I'm able to find such a helper as of now, but fair. I can change it in v2 if Jarkko is okay with it.

Hi Jarkko,

If you agree with Andy's comments, please let me know. Will send out a v2 accordingly.

Raag

#7 lore raw

Re: [PATCH v1 1/3] pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Quoted 19 lines · Raag Jadav
Quoted 18 lines · Raag Jadav
Quoted 16 lines · Andy Shevchenko
Quoted 4 lines · Raag Jadav
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Raag Jadav

Intel Elkhart Lake PSE includes two instances of PWM as a single PCI function with 8 channels each. Add support for the remaining channels.

...

Quoted 4 lines
Quoted 1 line

First option: Always provide driver data (info is never NULL).

Allowing empty driver_data would save us from adding dummy info for single instance devices in the future.

Which may be too premature "optimisation". Why? Because if we ever have something like pci_dev_get_match_data(), the empty will mean NULL, and we may not get difference between empty and missing one.

Quoted 8 lines
Quoted 2 lines

Not sure if I'm able to find such a helper as of now, but fair. I can change it in v2 if Jarkko is okay with it.

Hi Jarkko,

If you agree with Andy's comments, please let me know. Will send out a v2 accordingly.

Ah, sorry, I didn't have opinion.

author
#8 lore raw

PATCH 2/3 pwm: dwc: simplify error handling

In reply to Raag Jadav

Simplify error handling in ->probe() function using dev_err_probe() helper.

---
 drivers/pwm/pwm-dwc.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/pwm/pwm-dwc.c +6 -12
index fd64313cb38d..8f8035b047c1 100644
@@ -68,24 +68,18 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
 	int ret;
 
 	ret = pcim_enable_device(pci);
-	if (ret) {
-		dev_err(dev, "Failed to enable device (%pe)\n", ERR_PTR(ret));
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to enable device (%pe)\n", ERR_PTR(ret));
 
 	pci_set_master(pci);
 
 	ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
-	if (ret) {
-		dev_err(dev, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
 
 	base = pcim_iomap_table(pci)[0];
-	if (!base) {
-		dev_err(dev, "Base address missing\n");
-		return -ENOMEM;
-	}
+	if (!base)
+		return dev_err_probe(dev, -ENOMEM, "Base address missing\n");
 
 	info = (const struct dwc_pwm_info *)id->driver_data;
 	ret = dwc_pwm_init(dev, info, base);
Signature · 1 line
2.35.3
#9 lore raw

Re: [PATCH v1 2/3] pwm: dwc: simplify error handling

Quoted 1 line · Raag Jadav

Simplify error handling in ->probe() function using dev_err_probe() helper.

...

Quoted 6 lines
drivers/pwm/pwm-dwc.c +1 -4
 	ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
-	if (ret) {
-		dev_err(dev, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
-		return ret;
-	}
+	if (ret)

drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)

Quoted 10 lines
drivers/pwm/pwm-dwc.c +3 -4
+		return dev_err_probe(dev, ret, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
 
 	base = pcim_iomap_table(pci)[0];
 
-	if (!base) {
-		dev_err(dev, "Base address missing\n");
-		return -ENOMEM;
-	}
+	if (!base)
+		return dev_err_probe(dev, -ENOMEM, "Base address missing\n");

This check is bogus. Just remove it completely.

The pcim_iomap_table() fails IFF pcim_iomap_regions() fails. You have checked the latter already.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

Re: [PATCH v1 2/3] pwm: dwc: simplify error handling

Hello,

Quoted 15 lines · Andy Shevchenko
Quoted 1 line · Raag Jadav

Simplify error handling in ->probe() function using dev_err_probe() helper.

...

Quoted 9 lines
drivers/pwm/pwm-dwc.c +2 -4
 	ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
-	if (ret) {
-		dev_err(dev, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
 
 	base = pcim_iomap_table(pci)[0];
Quoted 8 lines

drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) · line 82

Quoted 6 lines
drivers/pwm/pwm-dwc.c +2 -4
-	if (!base) {
-		dev_err(dev, "Base address missing\n");
-		return -ENOMEM;
-	}
+	if (!base)
+		return dev_err_probe(dev, -ENOMEM, "Base address missing\n");

This check is bogus. Just remove it completely.

This would be a separate patch though. IMHO mechanically converting to dev_err_probe() is fine.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#11 lore raw

Re: [PATCH v1 2/3] pwm: dwc: simplify error handling

Quoted 3 lines · Uwe Kleine-König
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Raag Jadav

Simplify error handling in ->probe() function using dev_err_probe() helper.

...

Quoted 19 lines
Quoted 10 lines
Quoted 9 lines
drivers/pwm/pwm-dwc.c +2 -4
 	ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
-	if (ret) {
-		dev_err(dev, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
 
 	base = pcim_iomap_table(pci)[0];
Quoted 8 lines

drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) · line 82

Quoted 6 lines
drivers/pwm/pwm-dwc.c +2 -4
-	if (!base) {
-		dev_err(dev, "Base address missing\n");
-		return -ENOMEM;
-	}
+	if (!base)
+		return dev_err_probe(dev, -ENOMEM, "Base address missing\n");

This check is bogus. Just remove it completely.

Quoted 2 lines

This would be a separate patch though. IMHO mechanically converting to dev_err_probe() is fine.

Sure, that's what I meant. First patch to remove, followed by dev_err_probe() conversion.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#12 lore raw

Re: [PATCH v1 2/3] pwm: dwc: simplify error handling

In reply to Andy Shevchenko
Quoted 24 lines · Andy Shevchenko
Quoted 1 line · Raag Jadav

Simplify error handling in ->probe() function using dev_err_probe() helper.

...

Quoted 6 lines
drivers/pwm/pwm-dwc.c +1 -4
 	ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
-	if (ret) {
-		dev_err(dev, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
-		return ret;
-	}
+	if (ret)

drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)

Quoted 10 lines
drivers/pwm/pwm-dwc.c +3 -4
+		return dev_err_probe(dev, ret, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
 
 	base = pcim_iomap_table(pci)[0];
 
-	if (!base) {
-		dev_err(dev, "Base address missing\n");
-		return -ENOMEM;
-	}
+	if (!base)
+		return dev_err_probe(dev, -ENOMEM, "Base address missing\n");

This check is bogus. Just remove it completely.

Quoted 2 lines

The pcim_iomap_table() fails IFF pcim_iomap_regions() fails. You have checked the latter already.

I'm no expert on devres but I found a few NULL returns in alloc_dr() call path. In the interest of learning more about iomap, wouldn't we need to handle them (just in some odd case)?

Raag

#13 lore raw

Re: [PATCH v1 2/3] pwm: dwc: simplify error handling

Quoted 3 lines · Raag Jadav
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Raag Jadav

Simplify error handling in ->probe() function using dev_err_probe() helper.

...

Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
drivers/pwm/pwm-dwc.c +1 -4
 	ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
-	if (ret) {
-		dev_err(dev, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
-		return ret;
-	}
+	if (ret)

drivers/pwm/pwm-dwc.c static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)

Quoted 10 lines
drivers/pwm/pwm-dwc.c +3 -4
+		return dev_err_probe(dev, ret, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
 
 	base = pcim_iomap_table(pci)[0];
 
-	if (!base) {
-		dev_err(dev, "Base address missing\n");
-		return -ENOMEM;
-	}
+	if (!base)
+		return dev_err_probe(dev, -ENOMEM, "Base address missing\n");

This check is bogus. Just remove it completely.

Quoted 6 lines
Quoted 2 lines

The pcim_iomap_table() fails IFF pcim_iomap_regions() fails. You have checked the latter already.

I'm no expert on devres but I found a few NULL returns in alloc_dr() call path. In the interest of learning more about iomap, wouldn't we need to handle them (just in some odd case)?

It has nothing to do with devres. The logic is implemented in PCI core.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#14 lore raw

PATCH 3/3 pwm: dwc: use to_pci_dev() helper

In reply to Raag Jadav

Use to_pci_dev() helper to get pci device reference.

---
 drivers/pwm/pwm-dwc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/pwm-dwc.c +2 -2
index 8f8035b047c1..f5fcea4e69e2 100644
@@ -100,7 +100,7 @@ static void dwc_pwm_remove(struct pci_dev *pci)
 
 static int dwc_pwm_suspend(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;
 
@@ -120,7 +120,7 @@ static int dwc_pwm_suspend(struct device *dev)
 
 static int dwc_pwm_resume(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;
 
Signature · 1 line
2.35.3
#15 lore raw

Re: [PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper

Quoted 1 line · Raag Jadav

Use to_pci_dev() helper to get pci device reference.

PCI

...

Quoted 8 lines

static int dwc_pwm_suspend(struct device *dev)
{

drivers/pwm/pwm-dwc.c +1 -1
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;

drivers/pwm/pwm-dwc.c static int dwc_pwm_suspend(struct device *dev) · line 125

Quoted 7 lines
drivers/pwm/pwm-dwc.c +1 -1
@@ -120,7 +120,7 @@ static int dwc_pwm_suspend(struct device *dev)
 
 static int dwc_pwm_resume(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;

I don't see how pdev is being used. That said, why dev_get_drvdata() is not suffice?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper

Hello,

Quoted 16 lines · Andy Shevchenko
Quoted 1 line · Raag Jadav

Use to_pci_dev() helper to get pci device reference.

PCI

...

Quoted 9 lines

static int dwc_pwm_suspend(struct device *dev)
{

drivers/pwm/pwm-dwc.c +1 -1
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;
@@ -120,7 +120,7 @@ static int dwc_pwm_suspend(struct device *dev)
 
Quoted 9 lines

drivers/pwm/pwm-dwc.c static int dwc_pwm_suspend(struct device *dev) · line 125

Quoted 6 lines
drivers/pwm/pwm-dwc.c +1 -1
 static int dwc_pwm_resume(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;

I don't see how pdev is being used. That said, why dev_get_drvdata() is not suffice?

I would even consider using dev_get_drvdata() a nice cleanup given that pci_get_drvdata() works because dwc_pwm_alloc() called dev_set_drvdata() (and not pci_set_drvdata()).

Not so long ago (i.e. before commit a357d1493f0c ("pwm: dwc: Move memory allocation to own function")) the dwc driver was pci only and used pci_set_drvdata(). Then the upside of first converting the struct device to a struct pci_dev was not to hard code knowledge about the implementation of pci_[gs]et_drvdata().

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
author
#17 lore raw

Re: [PATCH v1 3/3] pwm: dwc: use to_pci_dev() helper

Quoted 29 lines · Uwe Kleine-König

Hello,

Quoted 16 lines · Andy Shevchenko
Quoted 1 line · Raag Jadav

Use to_pci_dev() helper to get pci device reference.

PCI

...

Quoted 9 lines

static int dwc_pwm_suspend(struct device *dev)
{

drivers/pwm/pwm-dwc.c +1 -1
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;
@@ -120,7 +120,7 @@ static int dwc_pwm_suspend(struct device *dev)
 
Quoted 9 lines

drivers/pwm/pwm-dwc.c static int dwc_pwm_suspend(struct device *dev) · line 125

Quoted 6 lines
drivers/pwm/pwm-dwc.c +1 -1
 static int dwc_pwm_resume(struct device *dev)
 {
-	struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	struct dwc_pwm *dwc = pci_get_drvdata(pdev);
 	int i;

I don't see how pdev is being used. That said, why dev_get_drvdata() is not suffice?

Quoted 3 lines

I would even consider using dev_get_drvdata() a nice cleanup given that pci_get_drvdata() works because dwc_pwm_alloc() called dev_set_drvdata() (and not pci_set_drvdata()).

Makes sense. Will update in v2.

Raag

Reviewed-by Tested-by on the v1 series
#18 lore raw
In reply to Raag Jadav
Quoted 12 lines · Raag Jadav

This series adds 16 channel support for Intel Elkhart Lake and simplifies code using standard helpers in DesignWare PWM driver.

Raag Jadav (3):
pwm: dwc: Add 16 channel support for Intel Elkhart Lake
pwm: dwc: simplify error handling
pwm: dwc: use to_pci_dev() helper

  drivers/pwm/pwm-dwc.c | 71 +++++++++++++++++++++++++++++--------------
  drivers/pwm/pwm-dwc.h |  5 +++
  2 files changed, 54 insertions(+), 22 deletions(-)

For the patchset: