Skip to contentSkip to conversation

pwm: lpss: Deduplicate board info data structures

PATCH Superseded Andy Shevchenko 2 participants 18 messages Sep 6, 2022 – Sep 8, 2022

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/9 pwm: lpss: Deduplicate board info data structures

With help of __maybe_unused, that allows to avoid compilation warnings, move the board info structures from the C files to the common header and hence deduplicate configuration data.

---
 drivers/pwm/pwm-lpss-pci.c      | 29 -----------------------------
 drivers/pwm/pwm-lpss-platform.c | 23 -----------------------
 drivers/pwm/pwm-lpss.h          | 30 ++++++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 52 deletions(-)
drivers/pwm/pwm-lpss-pci.c +0 -29
index c893ec3d2fb4..75b778e839b3 100644
@@ -14,35 +14,6 @@
 
 #include "pwm-lpss.h"
 
-/* BayTrail */
-static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
-	.clk_rate = 25000000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-};
-
-/* Braswell */
-static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
-	.clk_rate = 19200000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-};
-
-/* Broxton */
-static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
-	.clk_rate = 19200000,
-	.npwm = 4,
-	.base_unit_bits = 22,
-	.bypass = true,
-};
-
-/* Tangier */
-static const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
-	.clk_rate = 19200000,
-	.npwm = 4,
-	.base_unit_bits = 22,
-};
-
 static int pwm_lpss_probe_pci(struct pci_dev *pdev,
 			      const struct pci_device_id *id)
 {
drivers/pwm/pwm-lpss-platform.c +0 -23
index 928570430cef..fcd80cca2f6d 100644
@@ -15,29 +15,6 @@
 
 #include "pwm-lpss.h"
 
-/* BayTrail */
-static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
-	.clk_rate = 25000000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-};
-
-/* Braswell */
-static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
-	.clk_rate = 19200000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-	.other_devices_aml_touches_pwm_regs = true,
-};
-
-/* Broxton */
-static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
-	.clk_rate = 19200000,
-	.npwm = 4,
-	.base_unit_bits = 22,
-	.bypass = true,
-};
-
 static int pwm_lpss_probe_platform(struct platform_device *pdev)
 {
 	const struct pwm_lpss_boardinfo *info;
drivers/pwm/pwm-lpss.h +30 -0
index 8b3476f25e06..3864f32c2487 100644
@@ -33,6 +33,36 @@ struct pwm_lpss_boardinfo {
 	bool other_devices_aml_touches_pwm_regs;
 };
 
+/* BayTrail */
+static __maybe_unused const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
+	.clk_rate = 25000000,
+	.npwm = 1,
+	.base_unit_bits = 16,
+};
+
+/* Braswell */
+static __maybe_unused const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
+	.clk_rate = 19200000,
+	.npwm = 1,
+	.base_unit_bits = 16,
+	.other_devices_aml_touches_pwm_regs = true,
+};
+
+/* Broxton */
+static __maybe_unused const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
+	.clk_rate = 19200000,
+	.npwm = 4,
+	.base_unit_bits = 22,
+	.bypass = true,
+};
+
+/* Tangier */
+static __maybe_unused const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
+	.clk_rate = 19200000,
+	.npwm = 4,
+	.base_unit_bits = 22,
+};
+
 struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
 				     const struct pwm_lpss_boardinfo *info);
 
Signature · 1 line
2.35.1
author reviewer
#1 lore raw

PATCH 2/9 pwm: lpss: Move exported symbols to PWM_LPSS namespace

Avoid unnecessary pollution of the global symbol namespace by moving library functions in to a specific namespace and import that into the drivers that make use of the functions.

For more info: https://lwn.net/Articles/760045/

---
 drivers/pwm/pwm-lpss-pci.c      | 1 +
 drivers/pwm/pwm-lpss-platform.c | 1 +
 drivers/pwm/pwm-lpss.c          | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lpss-pci.c +1 -0
index 75b778e839b3..9f2c666b95ec 100644
@@ -92,3 +92,4 @@ module_pci_driver(pwm_lpss_driver_pci);
 
 MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(PWM_LPSS);
drivers/pwm/pwm-lpss-platform.c +1 -0
index fcd80cca2f6d..96fde1b2b967 100644
@@ -87,4 +87,5 @@ module_platform_driver(pwm_lpss_driver_platform);
 
 MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(PWM_LPSS);
 MODULE_ALIAS("platform:pwm-lpss");
drivers/pwm/pwm-lpss.c +1 -1
index 36d4e83e6b79..a82a57eb2482 100644
@@ -250,7 +250,7 @@ struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
 
 	return lpwm;
 }
-EXPORT_SYMBOL_GPL(pwm_lpss_probe);
+EXPORT_SYMBOL_NS_GPL(pwm_lpss_probe, PWM_LPSS);
 
 MODULE_DESCRIPTION("PWM driver for Intel LPSS");
 MODULE_AUTHOR("Mika Westerberg <[email protected]>");
Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH v1 2/9] pwm: lpss: Move exported symbols to PWM_LPSS namespace

Hello Andy,

Quoted 27 lines · Andy Shevchenko

Avoid unnecessary pollution of the global symbol namespace by moving library functions in to a specific namespace and import that into the drivers that make use of the functions.

For more info: https://lwn.net/Articles/760045/

---
 drivers/pwm/pwm-lpss-pci.c      | 1 +
 drivers/pwm/pwm-lpss-platform.c | 1 +
 drivers/pwm/pwm-lpss.c          | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lpss-pci.c +1 -0
index 75b778e839b3..9f2c666b95ec 100644
@@ -92,3 +92,4 @@ module_pci_driver(pwm_lpss_driver_pci);
 
 MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(PWM_LPSS);
drivers/pwm/pwm-lpss-platform.c +0 -0
index fcd80cca2f6d..96fde1b2b967 100644

drivers/pwm/pwm-lpss-platform.c module_platform_driver(pwm_lpss_driver_platform); · line 91

Quoted 5 lines
drivers/pwm/pwm-lpss-platform.c +1 -0
@@ -87,4 +87,5 @@ module_platform_driver(pwm_lpss_driver_platform);
 
 MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(PWM_LPSS);
 MODULE_ALIAS("platform:pwm-lpss");

While it's not wrong to add the IMPORT_NS statement to each file, I'd had added it to pwm-lpss.h. IMHO that makes sense as every includer of that header needs that IMPORT_NS to actually use the symbols declared there.

drivers/pwm/pwm-lpss.c struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r, · line 253

Quoted 10 lines
drivers/pwm/pwm-lpss.c +1 -1
index 36d4e83e6b79..a82a57eb2482 100644
@@ -250,7 +250,7 @@ struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
 
 	return lpwm;
 }
-EXPORT_SYMBOL_GPL(pwm_lpss_probe);
+EXPORT_SYMBOL_NS_GPL(pwm_lpss_probe, PWM_LPSS);

There is something possible with more magic:

	#define DEFAULT_SYMBOL_NAMESPACE PWM_LPSS

which you only need once in pwm-lpss.c and then all exports use that namespace. (And if you pick up my suggestion for patch 1 you also benefit from that.)

Best regards
Uwe

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

Re: [PATCH v1 2/9] pwm: lpss: Move exported symbols to PWM_LPSS namespace

Quoted 11 lines · Uwe Kleine-König
Quoted 4 lines · Andy Shevchenko

MODULE_DESCRIPTION("PWM platform driver for Intel LPSS"); MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(PWM_LPSS);
MODULE_ALIAS("platform:pwm-lpss");

While it's not wrong to add the IMPORT_NS statement to each file, I'd had added it to pwm-lpss.h. IMHO that makes sense as every includer of that header needs that IMPORT_NS to actually use the symbols declared there.

If you have an optional dependency you may not need to include namespace to avoid dragging it for peanuts.

...

Quoted 4 lines

drivers/pwm/pwm-lpss.c struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r, · line 253

Quoted 2 lines
drivers/pwm/pwm-lpss.c +1 -1
-EXPORT_SYMBOL_GPL(pwm_lpss_probe);
+EXPORT_SYMBOL_NS_GPL(pwm_lpss_probe, PWM_LPSS);

There is something possible with more magic:

I know.

Quoted 5 lines
	#define DEFAULT_SYMBOL_NAMESPACE PWM_LPSS

which you only need once in pwm-lpss.c and then all exports use that namespace. (And if you pick up my suggestion for patch 1 you also benefit from that.)

For a single export (even for a few of them) it's an overkill.

Taking above into consideration I don't think we need to alter a proposed change.

Thanks for review!

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

Re: [PATCH v1 2/9] pwm: lpss: Move exported symbols to PWM_LPSS namespace

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

On Tue, Sep 06, 2022 at 10:57:28PM +0300, Andy Shevchenko wrote:

...

Quoted 11 lines
Quoted 9 lines

drivers/pwm/pwm-lpss.c struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r, · line 253

Quoted 2 lines
drivers/pwm/pwm-lpss.c +1 -1
-EXPORT_SYMBOL_GPL(pwm_lpss_probe);
+EXPORT_SYMBOL_NS_GPL(pwm_lpss_probe, PWM_LPSS);

There is something possible with more magic:

	#define DEFAULT_SYMBOL_NAMESPACE PWM_LPSS

which you only need once in pwm-lpss.c and then all exports use that namespace. (And if you pick up my suggestion for patch 1 you also benefit from that.)

For a single export (even for a few of them) it's an overkill.

Ah, you adding there 4 more. But still I think it's an overkill. It's so small driver that duplicating namespace in each of the exported symbols is not an issue, is it?

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

Re: [PATCH v1 2/9] pwm: lpss: Move exported symbols to PWM_LPSS namespace

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

On Tue, Sep 06, 2022 at 10:57:28PM +0300, Andy Shevchenko wrote:

...

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

drivers/pwm/pwm-lpss.c struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r, · line 253

Quoted 2 lines
drivers/pwm/pwm-lpss.c +1 -1
-EXPORT_SYMBOL_GPL(pwm_lpss_probe);
+EXPORT_SYMBOL_NS_GPL(pwm_lpss_probe, PWM_LPSS);

There is something possible with more magic:

	#define DEFAULT_SYMBOL_NAMESPACE PWM_LPSS

which you only need once in pwm-lpss.c and then all exports use that namespace. (And if you pick up my suggestion for patch 1 you also benefit from that.)

Quoted 5 lines
Quoted 1 line

For a single export (even for a few of them) it's an overkill.

Ah, you adding there 4 more. But still I think it's an overkill. It's so small driver that duplicating namespace in each of the exported symbols is not an issue, is it?

Okay, now looking at the patch organization (I forgot that I moved NS one to be not the first one) your suggestion makes a point. We won't change the code we just introduced.

That said, I would like to get your SoB or what you agree with to the patch 1 and I make this one as you suggested.

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

PATCH 3/9 pwm: lpss: Move resource mapping to the glue drivers

In reply to Andy Shevchenko

Move resource mapping to the glue drivers which helps to transform pwm_lpss_probe() to pure library function that may be used by others without need of specific resource management.

---
 drivers/pwm/pwm-lpss-pci.c      | 6 +++++-
 drivers/pwm/pwm-lpss-platform.c | 9 ++++++---
 drivers/pwm/pwm-lpss.c          | 7 ++-----
 drivers/pwm/pwm-lpss.h          | 2 +-
 4 files changed, 14 insertions(+), 10 deletions(-)
drivers/pwm/pwm-lpss-pci.c +5 -1
index 9f2c666b95ec..f3367e844e61 100644
@@ -25,8 +25,12 @@ static int pwm_lpss_probe_pci(struct pci_dev *pdev,
 	if (err < 0)
 		return err;
 
+	err = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
+	if (err)
+		return err;
+
 	info = (struct pwm_lpss_boardinfo *)id->driver_data;
-	lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info);
+	lpwm = pwm_lpss_probe(&pdev->dev, pcim_iomap_table(pdev)[0], info);
 	if (IS_ERR(lpwm))
 		return PTR_ERR(lpwm);
 
drivers/pwm/pwm-lpss-platform.c +6 -3
index 96fde1b2b967..af57472f3ddc 100644
@@ -20,16 +20,19 @@ static int pwm_lpss_probe_platform(struct platform_device *pdev)
 	const struct pwm_lpss_boardinfo *info;
 	const struct acpi_device_id *id;
 	struct pwm_lpss_chip *lpwm;
-	struct resource *r;
+	void __iomem *base;
 
 	id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev);
 	if (!id)
 		return -ENODEV;
 
 	info = (const struct pwm_lpss_boardinfo *)id->driver_data;
-	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-	lpwm = pwm_lpss_probe(&pdev->dev, r, info);
+	base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	lpwm = pwm_lpss_probe(&pdev->dev, base, info);
 	if (IS_ERR(lpwm))
 		return PTR_ERR(lpwm);
 
drivers/pwm/pwm-lpss.c +2 -5
index a82a57eb2482..44f9bb80611d 100644
@@ -207,7 +207,7 @@ static const struct pwm_ops pwm_lpss_ops = {
 	.owner = THIS_MODULE,
 };
 
-struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
+struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, void __iomem *base,
 				     const struct pwm_lpss_boardinfo *info)
 {
 	struct pwm_lpss_chip *lpwm;
@@ -222,10 +222,7 @@ struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
 	if (!lpwm)
 		return ERR_PTR(-ENOMEM);
 
-	lpwm->regs = devm_ioremap_resource(dev, r);
-	if (IS_ERR(lpwm->regs))
-		return ERR_CAST(lpwm->regs);
-
+	lpwm->regs = base;
 	lpwm->info = info;
 
 	c = lpwm->info->clk_rate;
drivers/pwm/pwm-lpss.h +1 -1
index 3864f32c2487..5995b6b750a8 100644
@@ -63,7 +63,7 @@ static __maybe_unused const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
 	.base_unit_bits = 22,
 };
 
-struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
+struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, void __iomem *base,
 				     const struct pwm_lpss_boardinfo *info);
 
 #endif	/* __PWM_LPSS_H */
Signature · 1 line
2.35.1
author reviewer
#7 lore raw

PATCH 4/9 pwm: lpss: Include headers we are direct user of

In reply to Andy Shevchenko

For the sake of integrity, include headers we are direct user of.

While at it, replace device.h with a forward declaration.

---
 drivers/pwm/pwm-lpss.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lpss.h +5 -1
index 5995b6b750a8..832cb86996d7 100644
@@ -10,11 +10,15 @@
 #ifndef __PWM_LPSS_H
 #define __PWM_LPSS_H
 
-#include <linux/device.h>
 #include <linux/pwm.h>
+#include <linux/types.h>
 
 #define MAX_PWMS			4
 
+struct device;
+
+struct pwm_lpss_boardinfo;
+
 struct pwm_lpss_chip {
 	struct pwm_chip chip;
 	void __iomem *regs;
Signature · 1 line
2.35.1
#8 lore raw

Re: [PATCH v1 4/9] pwm: lpss: Include headers we are direct user of

Quoted 16 lines · Andy Shevchenko

For the sake of integrity, include headers we are direct user of.

While at it, replace device.h with a forward declaration.

---
 drivers/pwm/pwm-lpss.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lpss.h +0 -0
index 5995b6b750a8..832cb86996d7 100644
@@ -10,11 +10,15 @@
 #ifndef __PWM_LPSS_H
 #define __PWM_LPSS_H

drivers/pwm/pwm-lpss.h line 20

Quoted 10 lines
drivers/pwm/pwm-lpss.h +4 -1
 
-#include <linux/device.h>
 #include <linux/pwm.h>
+#include <linux/types.h>
 
 #define MAX_PWMS			4
 
+struct device;
+
+struct pwm_lpss_boardinfo;

the commit log doesn't explain the pwm_lpss_boardinfo part?!

Best regards
Uwe

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

Re: [PATCH v1 4/9] pwm: lpss: Include headers we are direct user of

Quoted 4 lines · Uwe Kleine-König
Quoted 3 lines · Andy Shevchenko

For the sake of integrity, include headers we are direct user of.

While at it, replace device.h with a forward declaration.

...

Quoted 3 lines
Quoted 1 line

+struct pwm_lpss_boardinfo;

the commit log doesn't explain the pwm_lpss_boardinfo part?!

Indeed, during one of amendment I rephrased it forgetting about this small detail. (It was written in generic way to cover all forward declarations)

I will add a word or two about this.

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

PATCH 5/9 pwm: lpss: Use device_get_match_data to get device data

In reply to Andy Shevchenko

device_get_match_data() in ACPI case calls similar to the acpi_match_device(). We may simplify the code and make it generic by replacing the latter with the former.

---
 drivers/pwm/pwm-lpss-platform.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/pwm/pwm-lpss-platform.c +4 -6
index af57472f3ddc..beb707d67b99 100644
@@ -7,27 +7,25 @@
  * Derived from the original pwm-lpss.c
  */
 
-#include <linux/acpi.h>
 #include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 
 #include "pwm-lpss.h"
 
 static int pwm_lpss_probe_platform(struct platform_device *pdev)
 {
 	const struct pwm_lpss_boardinfo *info;
-	const struct acpi_device_id *id;
 	struct pwm_lpss_chip *lpwm;
 	void __iomem *base;
 
-	id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev);
-	if (!id)
+	info = device_get_match_data(&pdev->dev);
+	if (!info)
 		return -ENODEV;
 
-	info = (const struct pwm_lpss_boardinfo *)id->driver_data;
-
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
 		return PTR_ERR(base);
Signature · 1 line
2.35.1
author reviewer
#11 lore raw

PATCH 6/9 pwm: lpss: Use DEFINE_RUNTIME_DEV_PM_OPS() and pm_ptr() macros

In reply to Andy Shevchenko

Using these new macros allows the compiler to remove the unused dev_pm_ops structure and related functions if !CONFIG_PM without the need to mark the functions __maybe_unused.

---
 drivers/pwm/pwm-lpss-pci.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/pwm/pwm-lpss-pci.c +5 -7
index f3367e844e61..98413d364338 100644
@@ -48,7 +48,6 @@ static void pwm_lpss_remove_pci(struct pci_dev *pdev)
 	pm_runtime_get_sync(&pdev->dev);
 }
 
-#ifdef CONFIG_PM
 static int pwm_lpss_runtime_suspend_pci(struct device *dev)
 {
 	/*
@@ -62,12 +61,11 @@ static int pwm_lpss_runtime_resume_pci(struct device *dev)
 {
 	return 0;
 }
-#endif
 
-static const struct dev_pm_ops pwm_lpss_pci_pm = {
-	SET_RUNTIME_PM_OPS(pwm_lpss_runtime_suspend_pci,
-			   pwm_lpss_runtime_resume_pci, NULL)
-};
+static DEFINE_RUNTIME_DEV_PM_OPS(pwm_lpss_pci_pm,
+				 pwm_lpss_runtime_suspend_pci,
+				 pwm_lpss_runtime_resume_pci,
+				 NULL);
 
 static const struct pci_device_id pwm_lpss_pci_ids[] = {
 	{ PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info},
@@ -89,7 +87,7 @@ static struct pci_driver pwm_lpss_driver_pci = {
 	.probe = pwm_lpss_probe_pci,
 	.remove = pwm_lpss_remove_pci,
 	.driver = {
-		.pm = &pwm_lpss_pci_pm,
+		.pm = pm_ptr(&pwm_lpss_pci_pm),
 	},
 };
 module_pci_driver(pwm_lpss_driver_pci);
Signature · 1 line
2.35.1
author reviewer
#12 lore raw

PATCH 7/9 pwm: lpss: Make use of bits.h macros for all masks

In reply to Andy Shevchenko

Make use of the GENMASK() (far less error-prone, far more concise).

---
 drivers/pwm/pwm-lpss.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lpss.c +2 -1
index 44f9bb80611d..276b7a3a34ff 100644
@@ -10,6 +10,7 @@
  * Author: Alan Cox <[email protected]>
  */
 
+#include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
@@ -24,7 +25,7 @@
 #define PWM_ENABLE			BIT(31)
 #define PWM_SW_UPDATE			BIT(30)
 #define PWM_BASE_UNIT_SHIFT		8
-#define PWM_ON_TIME_DIV_MASK		0x000000ff
+#define PWM_ON_TIME_DIV_MASK		GENMASK(7, 0)
 
 /* Size of each PWM register space if multiple */
 #define PWM_SIZE			0x400
Signature · 1 line
2.35.1
author reviewer
#13 lore raw

PATCH 8/9 pwm: lpss: Add a comment to the bypass field

In reply to Andy Shevchenko

Add a comment to the bypass field based on the commit b997e3edca4f ("pwm: lpss: Set enable-bit before waiting for update-bit to go low").

---
 drivers/pwm/pwm-lpss.h | 5 +++++
 1 file changed, 5 insertions(+)
drivers/pwm/pwm-lpss.h +5 -0
index 832cb86996d7..35e570067fc6 100644
@@ -29,6 +29,11 @@ struct pwm_lpss_boardinfo {
 	unsigned long clk_rate;
 	unsigned int npwm;
 	unsigned long base_unit_bits;
+	/*
+	 * Some versions of the IP may stuck in the state machine if enable
+	 * bit is not set, and hence update bit will show busy status till
+	 * the reset. For the rest it may be otherwise.
+	 */
 	bool bypass;
 	/*
 	 * On some devices the _PS0/_PS3 AML code of the GPU (GFX0) device
Signature · 1 line
2.35.1
author reviewer
#14 lore raw

PATCH 9/9 pwm: lpss: Allow other drivers to enable PWM LPSS

In reply to Andy Shevchenko

The PWM LPSS device can be embedded in another device. In order to enable it, allow that drivers to probe a corresponding device.

---
 drivers/pwm/pwm-lpss.h                     | 26 ++---------------
 include/linux/platform_data/x86/pwm-lpss.h | 33 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 24 deletions(-)
 create mode 100644 include/linux/platform_data/x86/pwm-lpss.h
drivers/pwm/pwm-lpss.h +2 -24
index 35e570067fc6..41cb4b6246bb 100644
@@ -13,11 +13,9 @@
 #include <linux/pwm.h>
 #include <linux/types.h>
 
-#define MAX_PWMS			4
-
-struct device;
+#include <linux/platform_data/x86/pwm-lpss.h>
 
-struct pwm_lpss_boardinfo;
+#define MAX_PWMS			4
 
 struct pwm_lpss_chip {
 	struct pwm_chip chip;
@@ -25,23 +23,6 @@ struct pwm_lpss_chip {
 	const struct pwm_lpss_boardinfo *info;
 };
 
-struct pwm_lpss_boardinfo {
-	unsigned long clk_rate;
-	unsigned int npwm;
-	unsigned long base_unit_bits;
-	/*
-	 * Some versions of the IP may stuck in the state machine if enable
-	 * bit is not set, and hence update bit will show busy status till
-	 * the reset. For the rest it may be otherwise.
-	 */
-	bool bypass;
-	/*
-	 * On some devices the _PS0/_PS3 AML code of the GPU (GFX0) device
-	 * messes with the PWM0 controllers state,
-	 */
-	bool other_devices_aml_touches_pwm_regs;
-};
-
 /* BayTrail */
 static __maybe_unused const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
 	.clk_rate = 25000000,
@@ -72,7 +53,4 @@ static __maybe_unused const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
 	.base_unit_bits = 22,
 };
 
-struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, void __iomem *base,
-				     const struct pwm_lpss_boardinfo *info);
-
 #endif	/* __PWM_LPSS_H */
include/linux/platform_data/x86/pwm-lpss.h new file +33 -0
new file mode 100644
index 000000000000..296bd837ddbb
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Intel Low Power Subsystem PWM controller driver */
+
+#ifndef __PLATFORM_DATA_X86_PWM_LPSS_H
+#define __PLATFORM_DATA_X86_PWM_LPSS_H
+
+#include <linux/types.h>
+
+struct device;
+
+struct pwm_lpss_chip;
+
+struct pwm_lpss_boardinfo {
+	unsigned long clk_rate;
+	unsigned int npwm;
+	unsigned long base_unit_bits;
+	/*
+	 * Some versions of the IP may stuck in the state machine if enable
+	 * bit is not set, and hence update bit will show busy status till
+	 * the reset. For the rest it may be otherwise.
+	 */
+	bool bypass;
+	/*
+	 * On some devices the _PS0/_PS3 AML code of the GPU (GFX0) device
+	 * messes with the PWM0 controllers state,
+	 */
+	bool other_devices_aml_touches_pwm_regs;
+};
+
+struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, void __iomem *base,
+				     const struct pwm_lpss_boardinfo *info);
+
+#endif	/* __PLATFORM_DATA_X86_PWM_LPSS_H */
Signature · 1 line
2.35.1
#15 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

With help of __maybe_unused, that allows to avoid compilation warnings, move the board info structures from the C files to the common header and hence deduplicate configuration data.

---
 drivers/pwm/pwm-lpss-pci.c      | 29 -----------------------------
 drivers/pwm/pwm-lpss-platform.c | 23 -----------------------
 drivers/pwm/pwm-lpss.h          | 30 ++++++++++++++++++++++++++++++

Given that both the pci driver and the platform driver alread depend on pwm-lpss.o, I'd prefer something like the patch below to really deduplicate the data.

One thing to note is that the two pwm_lpss_bsw_info are not identical. I didn't check how that is relevant. Did you check that?

Best regards
Uwe

drivers/pwm/pwm-lpss-pci.c +0 -29
index c893ec3d2fb4..75b778e839b3 100644
@@ -14,35 +14,6 @@
 
 #include "pwm-lpss.h"
 
-/* BayTrail */
-static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
-	.clk_rate = 25000000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-};
-
-/* Braswell */
-static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
-	.clk_rate = 19200000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-};
-
-/* Broxton */
-static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
-	.clk_rate = 19200000,
-	.npwm = 4,
-	.base_unit_bits = 22,
-	.bypass = true,
-};
-
-/* Tangier */
-static const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
-	.clk_rate = 19200000,
-	.npwm = 4,
-	.base_unit_bits = 22,
-};
-
 static int pwm_lpss_probe_pci(struct pci_dev *pdev,
 			      const struct pci_device_id *id)
 {
drivers/pwm/pwm-lpss-platform.c +0 -22
index 928570430cef..834423c34f48 100644
@@ -15,28 +15,6 @@
 
 #include "pwm-lpss.h"
 
-/* BayTrail */
-static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
-	.clk_rate = 25000000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-};
-
-/* Braswell */
-static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
-	.clk_rate = 19200000,
-	.npwm = 1,
-	.base_unit_bits = 16,
-	.other_devices_aml_touches_pwm_regs = true,
-};
-
-/* Broxton */
-static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
-	.clk_rate = 19200000,
-	.npwm = 4,
-	.base_unit_bits = 22,
-	.bypass = true,
-};
 
 static int pwm_lpss_probe_platform(struct platform_device *pdev)
 {
drivers/pwm/pwm-lpss.c +33 -0
index 36d4e83e6b79..e8b16b67bfd4 100644
@@ -29,6 +29,39 @@
 /* Size of each PWM register space if multiple */
 #define PWM_SIZE			0x400
 
+/* BayTrail */
+const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
+	.clk_rate = 25000000,
+	.npwm = 1,
+	.base_unit_bits = 16,
+};
+EXPORT_SYMBOL_GPL(pwm_lpss_byt_info);
+
+/* Braswell */
+const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
+	.clk_rate = 19200000,
+	.npwm = 1,
+	.base_unit_bits = 16,
+};
+EXPORT_SYMBOL_GPL(pwm_lpss_bsw_info);
+
+/* Broxton */
+const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
+	.clk_rate = 19200000,
+	.npwm = 4,
+	.base_unit_bits = 22,
+	.bypass = true,
+};
+EXPORT_SYMBOL_GPL(pwm_lpss_bxt_info);
+
+/* Tangier */
+const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
+	.clk_rate = 19200000,
+	.npwm = 4,
+	.base_unit_bits = 22,
+};
+EXPORT_SYMBOL_GPL(pwm_lpss_tng_info);
+
 static inline struct pwm_lpss_chip *to_lpwm(struct pwm_chip *chip)
 {
 	return container_of(chip, struct pwm_lpss_chip, chip);
drivers/pwm/pwm-lpss.h +5 -0
index 8b3476f25e06..918d2f177109 100644
@@ -33,6 +33,11 @@ struct pwm_lpss_boardinfo {
 	bool other_devices_aml_touches_pwm_regs;
 };
 
+extern const struct pwm_lpss_boardinfo pwm_lpss_tng_info;
+extern const struct pwm_lpss_boardinfo pwm_lpss_bxt_info;
+extern const struct pwm_lpss_boardinfo pwm_lpss_bsw_info;
+extern const struct pwm_lpss_boardinfo pwm_lpss_byt_info;
+
 struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
 				     const struct pwm_lpss_boardinfo *info);
 
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
author reviewer
#16 lore raw
Quoted 11 lines · Uwe Kleine-König
Quoted 9 lines · Andy Shevchenko

With help of __maybe_unused, that allows to avoid compilation warnings, move the board info structures from the C files to the common header and hence deduplicate configuration data.

---
 drivers/pwm/pwm-lpss-pci.c      | 29 -----------------------------
 drivers/pwm/pwm-lpss-platform.c | 23 -----------------------
 drivers/pwm/pwm-lpss.h          | 30 ++++++++++++++++++++++++++++++
Quoted 3 lines

Given that both the pci driver and the platform driver alread depend on pwm-lpss.o, I'd prefer something like the patch below to really deduplicate the data.

Why not? I can use yours in v2. Can I get your SoB tag?

Quoted 2 lines

One thing to note is that the two pwm_lpss_bsw_info are not identical. I didn't check how that is relevant. Did you check that?

Yes, ACPI version should be used. Because switch to ACPI/PCI is done in BIOS while quite likely the rest of AML code is the same, meaning similar issue might be observed. The no bug report is due to no PCI enabled device in the wild, I think, and only reference boards can be tested, so nobody really cares about PCI Braswell case.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Uwe Kleine-König
Quoted 9 lines · Andy Shevchenko

With help of __maybe_unused, that allows to avoid compilation warnings, move the board info structures from the C files to the common header and hence deduplicate configuration data.

---
 drivers/pwm/pwm-lpss-pci.c      | 29 -----------------------------
 drivers/pwm/pwm-lpss-platform.c | 23 -----------------------
 drivers/pwm/pwm-lpss.h          | 30 ++++++++++++++++++++++++++++++
Quoted 5 lines
Quoted 3 lines

Given that both the pci driver and the platform driver alread depend on pwm-lpss.o, I'd prefer something like the patch below to really deduplicate the data.

Why not? I can use yours in v2. Can I get your SoB tag?

Sure:

Quoted 8 lines
Quoted 2 lines

One thing to note is that the two pwm_lpss_bsw_info are not identical. I didn't check how that is relevant. Did you check that?

Yes, ACPI version should be used. Because switch to ACPI/PCI is done in BIOS while quite likely the rest of AML code is the same, meaning similar issue might be observed. The no bug report is due to no PCI enabled device in the wild, I think, and only reference boards can be tested, so nobody really cares about PCI Braswell case.

I'm willing to believe that; please mention that in the commit log.

Best regards
Uwe

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