[v2,2/5] pwm: dwc: Add 16 channel support for Intel Elkhart Lake

Message ID 20240208070529.28562-3-raag.jadav@intel.com
State New
Headers
Series DesignWare PWM improvements |

Commit Message

Raag Jadav Feb. 8, 2024, 7:05 a.m. UTC
  Intel Elkhart Lake PSE includes two instances of PWM as a single PCI
function with 8 channels each. Add support for the remaining channels.

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
Tested-by: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>
---
 drivers/pwm/pwm-dwc.c | 33 +++++++++++++++++++++++++--------
 drivers/pwm/pwm-dwc.h |  5 +++++
 2 files changed, 30 insertions(+), 8 deletions(-)
  

Comments

Andy Shevchenko Feb. 8, 2024, 5:20 p.m. UTC | #1
On Thu, Feb 08, 2024 at 12:35:26PM +0530, Raag Jadav wrote:
> Intel Elkhart Lake PSE includes two instances of PWM as a single PCI
> function with 8 channels each. Add support for the remaining channels.

Side Q: Have you used --histogram diff algo when prepared the series?
If no, it's better to start using it.
  
Raag Jadav Feb. 9, 2024, 7:18 p.m. UTC | #2
On Thu, Feb 08, 2024 at 07:20:59PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 08, 2024 at 12:35:26PM +0530, Raag Jadav wrote:
> > Intel Elkhart Lake PSE includes two instances of PWM as a single PCI
> > function with 8 channels each. Add support for the remaining channels.
> 
> Side Q: Have you used --histogram diff algo when prepared the series?
> If no, it's better to start using it.

I used it for a few weeks, but I think I've grown a bit too comfortable
with patience.

I'll use histogram for pinctrl stuff if you insist :)

Raag
  
Andy Shevchenko Feb. 9, 2024, 7:41 p.m. UTC | #3
On Fri, Feb 09, 2024 at 09:18:41PM +0200, Raag Jadav wrote:
> On Thu, Feb 08, 2024 at 07:20:59PM +0200, Andy Shevchenko wrote:
> > On Thu, Feb 08, 2024 at 12:35:26PM +0530, Raag Jadav wrote:
> > > Intel Elkhart Lake PSE includes two instances of PWM as a single PCI
> > > function with 8 channels each. Add support for the remaining channels.
> > 
> > Side Q: Have you used --histogram diff algo when prepared the series?
> > If no, it's better to start using it.
> 
> I used it for a few weeks, but I think I've grown a bit too comfortable
> with patience.
> 
> I'll use histogram for pinctrl stuff if you insist :)

It's recommended by Torvalds:
https://lore.kernel.org/linux-gpio/CAHk-=wiVNOFP1dzKdCqXvoery5p8QoBB5THiJUMbZ1TxJb7FhQ@mail.gmail.com/
  
Uwe Kleine-König Feb. 10, 2024, 5:19 p.m. UTC | #4
Hello,

On Fri, Feb 09, 2024 at 09:41:50PM +0200, Andy Shevchenko wrote:
> On Fri, Feb 09, 2024 at 09:18:41PM +0200, Raag Jadav wrote:
> > On Thu, Feb 08, 2024 at 07:20:59PM +0200, Andy Shevchenko wrote:
> > > On Thu, Feb 08, 2024 at 12:35:26PM +0530, Raag Jadav wrote:
> > > > Intel Elkhart Lake PSE includes two instances of PWM as a single PCI
> > > > function with 8 channels each. Add support for the remaining channels.
> > > 
> > > Side Q: Have you used --histogram diff algo when prepared the series?
> > > If no, it's better to start using it.
> > 
> > I used it for a few weeks, but I think I've grown a bit too comfortable
> > with patience.
> > 
> > I'll use histogram for pinctrl stuff if you insist :)
> 
> It's recommended by Torvalds:
> https://lore.kernel.org/linux-gpio/CAHk-=wiVNOFP1dzKdCqXvoery5p8QoBB5THiJUMbZ1TxJb7FhQ@mail.gmail.com/

BTW, the magic to use it by default is:

	git config --global diff.algorithm histogram

Best regards
Uwe
  
Andy Shevchenko Feb. 12, 2024, 11:53 a.m. UTC | #5
On Sat, Feb 10, 2024 at 06:19:53PM +0100, Uwe Kleine-König wrote:
> On Fri, Feb 09, 2024 at 09:41:50PM +0200, Andy Shevchenko wrote:
> > On Fri, Feb 09, 2024 at 09:18:41PM +0200, Raag Jadav wrote:
> > > On Thu, Feb 08, 2024 at 07:20:59PM +0200, Andy Shevchenko wrote:
> > > > On Thu, Feb 08, 2024 at 12:35:26PM +0530, Raag Jadav wrote:

..

> > > > Side Q: Have you used --histogram diff algo when prepared the series?
> > > > If no, it's better to start using it.
> > > 
> > > I used it for a few weeks, but I think I've grown a bit too comfortable
> > > with patience.
> > > 
> > > I'll use histogram for pinctrl stuff if you insist :)
> > 
> > It's recommended by Torvalds:
> > https://lore.kernel.org/linux-gpio/CAHk-=wiVNOFP1dzKdCqXvoery5p8QoBB5THiJUMbZ1TxJb7FhQ@mail.gmail.com/
> 
> BTW, the magic to use it by default is:
> 
> 	git config --global diff.algorithm histogram

Yep, that's what I have on my machines for development.
  

Patch

diff --git a/drivers/pwm/pwm-dwc.c b/drivers/pwm/pwm-dwc.c
index 596a0bb35c40..47d76f5367fe 100644
--- a/drivers/pwm/pwm-dwc.c
+++ b/drivers/pwm/pwm-dwc.c
@@ -25,16 +25,31 @@ 
 
 #include "pwm-dwc.h"
 
-static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
+/* Elkhart Lake */
+static const struct dwc_pwm_info ehl_pwm_info = {
+	.nr = 2,
+	.size = 0x1000,
+};
+
+static int dwc_pwm_init_one(struct device *dev, void __iomem *base, unsigned int offset)
 {
-	struct device *dev = &pci->dev;
 	struct dwc_pwm *dwc;
-	int ret;
 
 	dwc = dwc_pwm_alloc(dev);
 	if (!dwc)
 		return -ENOMEM;
 
+	dwc->base = base + offset;
+
+	return devm_pwmchip_add(dev, &dwc->chip);
+}
+
+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;
+	int i, ret;
+
 	ret = pcim_enable_device(pci);
 	if (ret) {
 		dev_err(dev, "Failed to enable device (%pe)\n", ERR_PTR(ret));
@@ -49,11 +64,13 @@  static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
 		return ret;
 	}
 
-	dwc->base = pcim_iomap_table(pci)[0];
+	info = (const struct dwc_pwm_info *)id->driver_data;
 
-	ret = devm_pwmchip_add(dev, &dwc->chip);
-	if (ret)
-		return ret;
+	for (i = 0; i < info->nr; i++) {
+		ret = dwc_pwm_init_one(dev, pcim_iomap_table(pci)[0], i * info->size);
+		if (ret)
+			return ret;
+	}
 
 	pm_runtime_put(dev);
 	pm_runtime_allow(dev);
@@ -105,7 +122,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);
diff --git a/drivers/pwm/pwm-dwc.h b/drivers/pwm/pwm-dwc.h
index 64795247c54c..c9bbfc77b568 100644
--- a/drivers/pwm/pwm-dwc.h
+++ b/drivers/pwm/pwm-dwc.h
@@ -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;