Skip to contentSkip to conversation

Initial support for ImgTec PWM DAC and PDM DAC

PATCH RESEND Superseded [email protected] 5 participants 15 messages Nov 22, 2014 – Nov 27, 2014

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Initial support for ImgTec PWM DAC and PDM DAC

From: Naidu Tellapati <[email protected]>

The Pistachio SOC from Imagination Technologies includes – 4x PDM blocks and 1x “basic PWM� block with four output channels. These share 4 MFIO pins, each PWM channel being muxed with each PDM block output (0-3 muxed with 0-3) using the CR_PERIP_PWM_PDM_CONTROL register in the peripheral wrapper register bank (offset 0x140). The PDM and PWM outputs are used to control targets such as LCD backlight.

The PWM driver uses Linux PWM framework. Since the PDM does not fit into PWM framework we have implemented it as a MISC driver.

The series is based on v3.18-rc5.

I am re-sending the series with gmail SMTP as we had some problems with the mail server we used in the previous rounds.

Please review and provide your comments.

Changes from v3:

* Addressed couple of comments given in v3.

Changes from v2:

* Added depends on MIPS || COMPILE_TEST.

* Corrected the logic while calculating time base steps.

* Addressed few other minor comments given in v2.

Changes from v1:

* Used regmap_update_bits at some places in the driver.

* Placed some #defines next to their register.

* Added depends on HAS_IOMEM in Kconfig.

* Removed unnecessary paragraph from file header.

* Defined register masks in a readable way.

* Renamed clk-names with clock-names.

* Added system interface clock in DT binding document.

* Addressed few other minor review comments given in v1.

Naidu Tellapati (4):
pwm: Imagination Technologies PWM DAC driver
DT: pwm: Add binding document for IMG PWM DAC
pdm: Imagination Technologies PDM DAC driver
DT: pdm: Add binding document for IMG PDM DAC

 Documentation/devicetree/bindings/misc/img-pdm.txt |   54 ++
 Documentation/devicetree/bindings/pwm/img-pwm.txt  |   23 +
 drivers/misc/Kconfig                               |   12 +
 drivers/misc/Makefile                              |    1 +
 drivers/misc/img-pdm.c                             |  676 ++++++++++++++++++++
 drivers/pwm/Kconfig                                |   12 +
 drivers/pwm/Makefile                               |    1 +
 drivers/pwm/pwm-img.c                              |  270 ++++++++
 include/linux/img_pdm.h                            |   35 +
 9 files changed, 1084 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/misc/img-pdm.txt
 create mode 100644 Documentation/devicetree/bindings/pwm/img-pwm.txt
 create mode 100644 drivers/misc/img-pdm.c
 create mode 100644 drivers/pwm/pwm-img.c
 create mode 100644 include/linux/img_pdm.h
#1 lore raw

PATCH RESEND v4 1/4 pwm: Imagination Technologies PWM DAC driver

From: Naidu Tellapati <[email protected]>

The Pistachio SOC from Imagination Technologies includes a Pulse Width Modulation DAC which produces 1 to 4 digital bit-outputs which represent digital waveforms. These PWM outputs are primarily in charge of controlling backlight LED devices.

---
 drivers/pwm/Kconfig   |   12 ++
 drivers/pwm/Makefile  |    1 +
 drivers/pwm/pwm-img.c |  270 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 283 insertions(+), 0 deletions(-)
 create mode 100644 drivers/pwm/pwm-img.c
drivers/pwm/Kconfig +12 -0
index ef2dd2e..6b4581a 100644
@@ -110,6 +110,18 @@ config PWM_FSL_FTM
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-fsl-ftm.
 
+config PWM_IMG
+	tristate "Imagination Technologies PWM driver"
+	depends on MFD_SYSCON
+	depends on HAS_IOMEM
+	depends on MIPS || COMPILE_TEST
+	help
+	  Generic PWM framework driver for Imagination Technologies
+	  PWM block which supports 4 channels.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-img.
+
 config PWM_IMX
 	tristate "i.MX PWM support"
 	depends on ARCH_MXC
drivers/pwm/Makefile +1 -0
index c458606..29655fd 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_PWM_BFIN)		+= pwm-bfin.o
 obj-$(CONFIG_PWM_CLPS711X)	+= pwm-clps711x.o
 obj-$(CONFIG_PWM_EP93XX)	+= pwm-ep93xx.o
 obj-$(CONFIG_PWM_FSL_FTM)	+= pwm-fsl-ftm.o
+obj-$(CONFIG_PWM_IMG)		+= pwm-img.o
 obj-$(CONFIG_PWM_IMX)		+= pwm-imx.o
 obj-$(CONFIG_PWM_JZ4740)	+= pwm-jz4740.o
 obj-$(CONFIG_PWM_LP3943)	+= pwm-lp3943.o
drivers/pwm/pwm-img.c new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

Quoted 21 lines · On Sat, Nov 22, 2014 at 07:23:29AM +0530, [email protected] wrote:

From: Naidu Tellapati <[email protected]>

The Pistachio SOC from Imagination Technologies includes a Pulse Width Modulation DAC which produces 1 to 4 digital bit-outputs which represent digital waveforms. These PWM outputs are primarily in charge of controlling backlight LED devices.

---
 drivers/pwm/Kconfig   |   12 ++
 drivers/pwm/Makefile  |    1 +
 drivers/pwm/pwm-img.c |  270 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 283 insertions(+), 0 deletions(-)
 create mode 100644 drivers/pwm/pwm-img.c
drivers/pwm/Kconfig +0 -0
index ef2dd2e..6b4581a 100644

drivers/pwm/Kconfig config PWM_FSL_FTM · line 113

Quoted 4 lines
drivers/pwm/Kconfig +1 -0
@@ -110,6 +110,18 @@ config PWM_FSL_FTM
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-fsl-ftm.
 
+config PWM_IMG

This sounds really generic to me. Basically this says that every PWM IP developed by Imagination Technologies will be compatible with this one. It's typical to name modules after <vendor>-<soc> to avoid this type of ambiguity.

Is there any reason why this can't be called PWM_IMG_PISTACHIO?

drivers/pwm/Kconfig config PWM_FSL_FTM · line 116

Quoted 3 lines
drivers/pwm/Kconfig +3 -0
+	tristate "Imagination Technologies PWM driver"
+	depends on MFD_SYSCON
+	depends on HAS_IOMEM

I think you'll need at least COMMON_CLK here as well.

Quoted 1 line
drivers/pwm/pwm-img.c +0 -0

[...]

drivers/pwm/pwm-img.c line 36

Quoted 12 lines
drivers/pwm/pwm-img.c +12 -0
+/* PWM registers */
+#define CR_PWM_CTRL_CFG				0x0000
+#define CR_PWM_CTRL_CFG_NO_SUB_DIV		0
+#define CR_PWM_CTRL_CFG_SUB_DIV0		1
+#define CR_PWM_CTRL_CFG_SUB_DIV1		2
+#define CR_PWM_CTRL_CFG_SUB_DIV0_DIV1		3
+#define CR_PWM_CTRL_CFG_DIV_SHIFT(ch)		((ch) * 2 + 4)
+#define CR_PWM_CTRL_CFG_DIV_MASK		0x3
+
+#define CR_PWM_CH_CFG(ch)			(0x4 + (ch) * 4)
+#define CR_PWM_CH_CFG_TMBASE_SHIFT		0
+#define CR_PWM_CH_CFG_DUTY_SHIFT		16

What's with the CR_ prefix here? What does it stand for? Can't you just drop it?

drivers/pwm/pwm-img.c line 42

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+#define CR_PERIP_PWM_PDM_CONTROL		0x0140
+#define CR_PERIP_PWM_PDM_CONTROL_CH_MASK	0x1
+#define CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(ch)	((ch) * 4)
+
+#define IMG_NUM_PWM				4

I don't think you need this. See below for more details.

drivers/pwm/pwm-img.c line 69

Quoted 11 lines
drivers/pwm/pwm-img.c +11 -0
+static inline void img_pwm_writel(struct img_pwm_chip *chip,
+				  unsigned int reg, unsigned long val)
+{
+	writel(val, chip->base + reg);
+}
+
+static inline unsigned int img_pwm_readl(struct img_pwm_chip *chip,
+					 unsigned int reg)
+{
+	return readl(chip->base + reg);
+}

readl() and writel() deal with u32 data, please use consistent types.

drivers/pwm/pwm-img.c line 80

Quoted 10 lines
drivers/pwm/pwm-img.c +10 -0
+static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
+			  int duty_ns, int period_ns)
+{
+	unsigned int div;
+	unsigned int duty_steps;
+	unsigned int tmbase_steps;
+	unsigned long val;
+	unsigned long mul;
+	unsigned long output_clk_hz;
+	unsigned long input_clk_hz;

Many of these can be folded into single lines. And again, val is used to store register contents and should be u32.

drivers/pwm/pwm-img.c line 93

Quoted 13 lines
drivers/pwm/pwm-img.c +13 -0
+	struct img_pwm_chip *pwm_chip;
+
+	pwm_chip = to_img_pwm_chip(chip);
+
+	input_clk_hz = clk_get_rate(pwm_chip->pwm_clk);
+	output_clk_hz = DIV_ROUND_UP(NSEC_PER_SEC, period_ns);
+
+	mul = DIV_ROUND_UP(input_clk_hz, output_clk_hz);
+	if (mul > MAX_TMBASE_STEPS * 512) {
+		dev_err(chip->dev,
+			"failed to configure timebase steps/divider value.\n");
+		return -EINVAL;
+	}

I think it'd be more readable if this was the final else in the block of if/else if below.

Quoted 12 lines
drivers/pwm/pwm-img.c +12 -0
+
+	if (mul <= MAX_TMBASE_STEPS) {
+		div = CR_PWM_CTRL_CFG_NO_SUB_DIV;
+		tmbase_steps = DIV_ROUND_UP(mul, 1);
+	} else if (mul <= MAX_TMBASE_STEPS * 8) {
+		div = CR_PWM_CTRL_CFG_SUB_DIV0;
+		tmbase_steps = DIV_ROUND_UP(mul, 8);
+	} else if (mul <= MAX_TMBASE_STEPS * 64) {
+		div = CR_PWM_CTRL_CFG_SUB_DIV1;
+		tmbase_steps = DIV_ROUND_UP(mul, 64);
+	} else if (mul <= MAX_TMBASE_STEPS * 512) {
+		div = CR_PWM_CTRL_CFG_SUB_DIV0_DIV1;

drivers/pwm/pwm-img.c line 115

Quoted 10 lines
drivers/pwm/pwm-img.c +10 -0
+		tmbase_steps = DIV_ROUND_UP(mul, 512);
+	}
+
+	duty_steps = DIV_ROUND_UP(tmbase_steps * duty_ns, period_ns);
+
+	val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+	val &= ~(CR_PWM_CTRL_CFG_DIV_MASK <<
+					CR_PWM_CTRL_CFG_DIV_SHIFT(pwm->hwpwm));
+	val |= (div & CR_PWM_CTRL_CFG_DIV_MASK) <<
+					CR_PWM_CTRL_CFG_DIV_SHIFT(pwm->hwpwm);

If you leave out the CR_ prefix these will actually fit on a single line.

drivers/pwm/pwm-img.c line 119

Quoted 4 lines
drivers/pwm/pwm-img.c +4 -0
+	img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+	val = (duty_steps << CR_PWM_CH_CFG_DUTY_SHIFT) |
+				(tmbase_steps << CR_PWM_CH_CFG_TMBASE_SHIFT);

I prefer subsequent lines to be aligned with the first, like so:

	val = (duty_steps ...) |
	      (tmbase_steps ...);

Also I'd leave out the _steps suffix, it doesn't really add information.

drivers/pwm/pwm-img.c line 127

Quoted 3 lines
drivers/pwm/pwm-img.c +3 -0
+static int img_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+	unsigned int val;

Should be u32 as well. There are other occurrences like this in the remainder of the driver, but I haven't commented on all of them explicitly. Please fix them all up to be consistent.

drivers/pwm/pwm-img.c line 83

Quoted 3 lines
drivers/pwm/pwm-img.c +3 -0
+	struct img_pwm_chip *pwm_chip;
+
+	pwm_chip = to_img_pwm_chip(chip);

The above can be a single line.

drivers/pwm/pwm-img.c line 138

Quoted 8 lines
drivers/pwm/pwm-img.c +8 -0
+
+	val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+	val |= BIT(pwm->hwpwm);
+	img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+	regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+			   CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+			   CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0);

This smells like pinmux and should probably be a separate driver.

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+	unsigned int val;
+	struct img_pwm_chip *pwm_chip;
+

drivers/pwm/pwm-img.c line 157

Quoted 10 lines
drivers/pwm/pwm-img.c +10 -0
+	pwm_chip = to_img_pwm_chip(chip);
+
+	val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+	val &= ~BIT(pwm->hwpwm);
+	img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+	regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+			   CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+			   CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 1);
+}

Same comments as for img_pwm_enable().

Quoted 2 lines
drivers/pwm/pwm-img.c +2 -0
+static int img_pwm_probe(struct platform_device *pdev)
+{

[...]

drivers/pwm/pwm-img.c line 215

Quoted 4 lines
drivers/pwm/pwm-img.c +4 -0
+	pwm->chip.dev = &pdev->dev;
+	pwm->chip.ops = &img_pwm_ops;
+	pwm->chip.base = -1;
+	pwm->chip.npwm = IMG_NUM_PWM;

You can directly substitute 4 here since it's the only place you need it.

drivers/pwm/pwm-img.c line 238

Quoted 6 lines
drivers/pwm/pwm-img.c +6 -0
+static int img_pwm_remove(struct platform_device *pdev)
+{
+	unsigned int i;
+	unsigned int val;
+
+	struct img_pwm_chip *pwm_chip = platform_get_drvdata(pdev);

This should go at the very top of the variable declarations.

drivers/pwm/pwm-img.c line 240

Quoted 2 lines
drivers/pwm/pwm-img.c +2 -0
+
+	for (i = 0; i < IMG_NUM_PWM; i++) {

This would better be pwm_chip->chip.npwm.

Thierry

#3 lore raw

RE: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

Hi Thierry,

Many thanks for the review.

Quoted 25 lines · On Sat, Nov 22, 2014 at 07:23:29AM +0530, [email protected] wrote:
Quoted 24 lines

From: Naidu Tellapati <[email protected]>

The Pistachio SOC from Imagination Technologies includes a Pulse Width Modulation DAC which produces 1 to 4 digital bit-outputs which represent digital waveforms. These PWM outputs are primarily in charge of controlling backlight LED devices.

---
 drivers/pwm/Kconfig   |   12 ++
 drivers/pwm/Makefile  |    1 +
 drivers/pwm/pwm-img.c |  270 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 283 insertions(+), 0 deletions(-)
 create mode 100644 drivers/pwm/pwm-img.c
drivers/pwm/Kconfig +0 -0
index ef2dd2e..6b4581a 100644
@@ -110,6 +110,18 @@ config PWM_FSL_FTM
        To compile this driver as a module, choose M here: the module
        will be called pwm-fsl-ftm.
 
Quoted 8 lines

drivers/pwm/Kconfig config PWM_FSL_FTM · line 113

Quoted 1 line
drivers/pwm/Kconfig +1 -0
+config PWM_IMG

This sounds really generic to me. Basically this says that every PWM IP developed by Imagination Technologies will be compatible with this one. It's typical to name modules after <vendor>-<soc> to avoid this type of ambiguity.

Is there any reason why this can't be called PWM_IMG_PISTACHIO?

At this moment, this IP Block is available at least on one more SOC from Imagination Technologies. It is possible that the IP will be available on more SOCs in future.

Shall we go ahead with PWM_IMG?

Quoted 5 lines

drivers/pwm/Kconfig config PWM_FSL_FTM · line 116

Quoted 3 lines
drivers/pwm/Kconfig +3 -0
+     tristate "Imagination Technologies PWM driver"
+     depends on MFD_SYSCON
+     depends on HAS_IOMEM

I think you'll need at least COMMON_CLK here as well.

OK. Will address in the next Patch set.

Quoted 1 line
Quoted 1 line
drivers/pwm/pwm-img.c +0 -0

[...]

Quoted 7 lines
Quoted 7 lines
drivers/pwm/pwm-img.c +7 -0
+/* PWM registers */
+#define CR_PWM_CTRL_CFG                              0x0000
+#define CR_PWM_CTRL_CFG_NO_SUB_DIV           0
+#define CR_PWM_CTRL_CFG_SUB_DIV0             1
+#define CR_PWM_CTRL_CFG_SUB_DIV1             2
+#define CR_PWM_CTRL_CFG_SUB_DIV0_DIV1                3
+#define CR_PWM_CTRL_CFG_DIV_SHIFT(ch)                ((ch) * 2 + 4)
Quoted 8 lines

drivers/pwm/pwm-img.c line 36

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+#define CR_PWM_CTRL_CFG_DIV_MASK             0x3
+
+#define CR_PWM_CH_CFG(ch)                    (0x4 + (ch) * 4)
+#define CR_PWM_CH_CFG_TMBASE_SHIFT           0
+#define CR_PWM_CH_CFG_DUTY_SHIFT             16

What's with the CR_ prefix here? What does it stand for? Can't you just drop it?

CR stands for Control Register. We have picked it from the datasheet and wanted to make the register names compatible with the same in the datasheet.

Hope Andrew agrees with Thierry's comments here. Hope we can drop it.

Andrew, any comments here, please.

Quoted 7 lines

drivers/pwm/pwm-img.c line 42

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+#define CR_PERIP_PWM_PDM_CONTROL             0x0140
+#define CR_PERIP_PWM_PDM_CONTROL_CH_MASK     0x1
+#define CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(ch)        ((ch) * 4)
+
+#define IMG_NUM_PWM                          4

I don't think you need this. See below for more details.

OK. Will address in the next patch set.

Quoted 5 lines
Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+static inline void img_pwm_writel(struct img_pwm_chip *chip,
+                               unsigned int reg, unsigned long val)
+{
+     writel(val, chip->base + reg);
+}
Quoted 8 lines

drivers/pwm/pwm-img.c line 69

Quoted 6 lines
drivers/pwm/pwm-img.c +6 -0
+
+static inline unsigned int img_pwm_readl(struct img_pwm_chip *chip,
+                                      unsigned int reg)
+{
+     return readl(chip->base + reg);
+}

readl() and writel() deal with u32 data, please use consistent types.

OK. Will address in the next patch set.

Quoted 5 lines
Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
+                       int duty_ns, int period_ns)
+{
+     unsigned int div;
+     unsigned int duty_steps;
Quoted 8 lines

drivers/pwm/pwm-img.c line 80

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+     unsigned int tmbase_steps;
+     unsigned long val;
+     unsigned long mul;
+     unsigned long output_clk_hz;
+     unsigned long input_clk_hz;

Many of these can be folded into single lines. And again, val is used to store register contents and should be u32.

Agree. Will address in the next patch set.

Quoted 8 lines
Quoted 8 lines
drivers/pwm/pwm-img.c +8 -0
+     struct img_pwm_chip *pwm_chip;
+
+     pwm_chip = to_img_pwm_chip(chip);
+
+     input_clk_hz = clk_get_rate(pwm_chip->pwm_clk);
+     output_clk_hz = DIV_ROUND_UP(NSEC_PER_SEC, period_ns);
+
+     mul = DIV_ROUND_UP(input_clk_hz, output_clk_hz);
Quoted 8 lines

drivers/pwm/pwm-img.c line 93

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+     if (mul > MAX_TMBASE_STEPS * 512) {
+             dev_err(chip->dev,
+                     "failed to configure timebase steps/divider value.\n");
+             return -EINVAL;
+     }

I think it'd be more readable if this was the final else in the block of if/else if below.

OK. Will address in the next patch set.

Quoted 17 lines
Quoted 17 lines
drivers/pwm/pwm-img.c +17 -0
+
+     if (mul <= MAX_TMBASE_STEPS) {
+             div = CR_PWM_CTRL_CFG_NO_SUB_DIV;
+             tmbase_steps = DIV_ROUND_UP(mul, 1);
+     } else if (mul <= MAX_TMBASE_STEPS * 8) {
+             div = CR_PWM_CTRL_CFG_SUB_DIV0;
+             tmbase_steps = DIV_ROUND_UP(mul, 8);
+     } else if (mul <= MAX_TMBASE_STEPS * 64) {
+             div = CR_PWM_CTRL_CFG_SUB_DIV1;
+             tmbase_steps = DIV_ROUND_UP(mul, 64);
+     } else if (mul <= MAX_TMBASE_STEPS * 512) {
+             div = CR_PWM_CTRL_CFG_SUB_DIV0_DIV1;
+             tmbase_steps = DIV_ROUND_UP(mul, 512);
+     }
+
+     duty_steps = DIV_ROUND_UP(tmbase_steps * duty_ns, period_ns);
+
Quoted 8 lines

drivers/pwm/pwm-img.c line 115

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val &= ~(CR_PWM_CTRL_CFG_DIV_MASK <<
+                                     CR_PWM_CTRL_CFG_DIV_SHIFT(pwm->hwpwm));
+     val |= (div & CR_PWM_CTRL_CFG_DIV_MASK) <<
+                                     CR_PWM_CTRL_CFG_DIV_SHIFT(pwm->hwpwm);

If you leave out the CR_ prefix these will actually fit on a single line.

OK. Will address in the next patch set.

Quoted 6 lines

drivers/pwm/pwm-img.c line 119

Quoted 4 lines
drivers/pwm/pwm-img.c +4 -0
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     val = (duty_steps << CR_PWM_CH_CFG_DUTY_SHIFT) |
+                             (tmbase_steps << CR_PWM_CH_CFG_TMBASE_SHIFT);

I prefer subsequent lines to be aligned with the first, like so:

OK. Will address in the next patch set.

Quoted 4 lines
       val = (duty_steps ...) |
             (tmbase_steps ...);

Also I'd leave out the _steps suffix, it doesn't really add information.

OK. Will address in the next patch set.

Quoted 7 lines

drivers/pwm/pwm-img.c line 127

Quoted 3 lines
drivers/pwm/pwm-img.c +3 -0
+static int img_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+     unsigned int val;

Should be u32 as well. There are other occurrences like this in the remainder of the driver, but I haven't commented on all of them explicitly. Please fix them all up to be consistent.

OK. Will fix the issue at all the places in the driver.

Quoted 5 lines

drivers/pwm/pwm-img.c line 83

Quoted 3 lines
drivers/pwm/pwm-img.c +3 -0
+     struct img_pwm_chip *pwm_chip;
+
+     pwm_chip = to_img_pwm_chip(chip);

The above can be a single line.

OK. Will address in the next patch set.

Quoted 10 lines

drivers/pwm/pwm-img.c line 138

Quoted 8 lines
drivers/pwm/pwm-img.c +8 -0
+
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val |= BIT(pwm->hwpwm);
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+                        CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+                        CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0);

This smells like pinmux and should probably be a separate driver.

Hope you are suggesting us to have a separate driver for pin muxing (might already have one for Pistachio) and call the pin muxing driver APIs from here.

Please correct me if my understanding is wrong?

Quoted 9 lines
Quoted 9 lines
drivers/pwm/pwm-img.c +9 -0
+static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+     unsigned int val;
+     struct img_pwm_chip *pwm_chip;
+
+     pwm_chip = to_img_pwm_chip(chip);
+
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val &= ~BIT(pwm->hwpwm);
Quoted 8 lines

drivers/pwm/pwm-img.c line 157

Quoted 6 lines
drivers/pwm/pwm-img.c +6 -0
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+                        CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+                        CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 1);
+}

Same comments as for img_pwm_enable().

OK.

Quoted 2 lines
Quoted 2 lines
drivers/pwm/pwm-img.c +2 -0
+static int img_pwm_probe(struct platform_device *pdev)
+{

[...]

Quoted 7 lines

drivers/pwm/pwm-img.c line 215

Quoted 4 lines
drivers/pwm/pwm-img.c +4 -0
+     pwm->chip.dev = &pdev->dev;
+     pwm->chip.ops = &img_pwm_ops;
+     pwm->chip.base = -1;
+     pwm->chip.npwm = IMG_NUM_PWM;

You can directly substitute 4 here since it's the only place you need it.

OK. Will address in the next patch set.

Quoted 8 lines

drivers/pwm/pwm-img.c line 238

Quoted 6 lines
drivers/pwm/pwm-img.c +6 -0
+static int img_pwm_remove(struct platform_device *pdev)
+{
+     unsigned int i;
+     unsigned int val;
+
+     struct img_pwm_chip *pwm_chip = platform_get_drvdata(pdev);

This should go at the very top of the variable declarations.

OK. Will address in the next patch set.

Quoted 4 lines

drivers/pwm/pwm-img.c line 240

Quoted 2 lines
drivers/pwm/pwm-img.c +2 -0
+
+     for (i = 0; i < IMG_NUM_PWM; i++) {

This would better be pwm_chip->chip.npwm.

OK. Will address in the next patch set.

Quoted 1 line

Thierry

Thanks and regards,
Naidu.

#4 lore raw

Re: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

Quoted 36 lines · Naidu Tellapati

Hi Thierry,

Many thanks for the review.

Quoted 31 lines · On Sat, Nov 22, 2014 at 07:23:29AM +0530, [email protected] wrote:
Quoted 21 lines

From: Naidu Tellapati <[email protected]>

The Pistachio SOC from Imagination Technologies includes a Pulse Width Modulation DAC which produces 1 to 4 digital bit-outputs which represent digital waveforms. These PWM outputs are primarily in charge of controlling backlight LED devices.

---
 drivers/pwm/Kconfig   |   12 ++
 drivers/pwm/Makefile  |    1 +
 drivers/pwm/pwm-img.c |  270 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 283 insertions(+), 0 deletions(-)
 create mode 100644 drivers/pwm/pwm-img.c
drivers/pwm/Kconfig +0 -0
index ef2dd2e..6b4581a 100644

drivers/pwm/Kconfig config PWM_FSL_FTM · line 113

Quoted 4 lines
drivers/pwm/Kconfig +1 -0
@@ -110,6 +110,18 @@ config PWM_FSL_FTM
        To compile this driver as a module, choose M here: the module
        will be called pwm-fsl-ftm.
 
+config PWM_IMG

This sounds really generic to me. Basically this says that every PWM IP developed by Imagination Technologies will be compatible with this one. It's typical to name modules after <vendor>-<soc> to avoid this type of ambiguity.

Quoted 6 lines
Quoted 1 line

Is there any reason why this can't be called PWM_IMG_PISTACHIO?

At this moment, this IP Block is available at least on one more SOC from Imagination Technologies. It is possible that the IP will be available on more SOCs in future.

Shall we go ahead with PWM_IMG?

Alright, if ever there's a different PWM IP block from Imagination Technologies, the driver for that can have a more specific name.

Quoted 11 lines
Quoted 10 lines

drivers/pwm/Kconfig config PWM_FSL_FTM · line 121

Quoted 8 lines
drivers/pwm/Kconfig +8 -0
+
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val |= BIT(pwm->hwpwm);
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+                        CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+                        CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0);

This smells like pinmux and should probably be a separate driver.

Quoted 4 lines

Hope you are suggesting us to have a separate driver for pin muxing (might already have one for Pistachio) and call the pin muxing driver APIs from here.

Please correct me if my understanding is wrong?

I don't think you need to call the pinmux API from here. Rather I'll assume that the muxing is fixed on a given board, so this configuration would be part of the static board-level pinmux so it will automatically be applied at boot time.

Thierry

#5 lore raw

RE: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

Hi James,

Quoted 61 lines · Naidu Tellapati
Quoted 36 lines

Hi Thierry,

Many thanks for the review.

Quoted 31 lines · On Sat, Nov 22, 2014 at 07:23:29AM +0530, [email protected] wrote:
Quoted 7 lines

From: Naidu Tellapati <[email protected]>

The Pistachio SOC from Imagination Technologies includes a Pulse Width Modulation DAC which produces 1 to 4 digital bit-outputs which represent digital waveforms. These PWM outputs are primarily in charge of controlling backlight LED devices.

Quoted 6 lines

---

Quoted 1 line
 drivers/pwm/Kconfig   |   12 ++
 drivers/pwm/Makefile  |    1 +
 drivers/pwm/pwm-img.c |  270 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 283 insertions(+), 0 deletions(-)

drivers/pwm/Kconfig config PWM_FSL_FTM · line 113

Quoted 11 lines
 create mode 100644 drivers/pwm/pwm-img.c
drivers/pwm/Kconfig +1 -0
index ef2dd2e..6b4581a 100644
@@ -110,6 +110,18 @@ config PWM_FSL_FTM
        To compile this driver as a module, choose M here: the module
        will be called pwm-fsl-ftm.
 
+config PWM_IMG

This sounds really generic to me. Basically this says that every PWM IP developed by Imagination Technologies will be compatible with this one. It's typical to name modules after <vendor>-<soc> to avoid this type of ambiguity.

Quoted 6 lines
Quoted 1 line

Is there any reason why this can't be called PWM_IMG_PISTACHIO?

At this moment, this IP Block is available at least on one more SOC from Imagination Technologies. It is possible that the IP will be available on more SOCs in future.

Shall we go ahead with PWM_IMG?

Alright, if ever there's a different PWM IP block from Imagination Technologies, the driver for that can have a more specific name.

Quoted 14 lines
Quoted 10 lines

drivers/pwm/Kconfig config PWM_FSL_FTM · line 121

Quoted 8 lines
drivers/pwm/Kconfig +8 -0
+
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val |= BIT(pwm->hwpwm);
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+                        CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+                        CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0);

This smells like pinmux and should probably be a separate driver.

Hope you are suggesting us to have a separate driver for pin muxing (might already have one for Pistachio) and call the pin muxing driver APIs from here.

Quoted 6 lines
Quoted 1 line

Please correct me if my understanding is wrong?

I don't think you need to call the pinmux API from here. Rather I'll assume that the muxing is fixed on a given board, so this configuration would be part of the static board-level pinmux so it will automatically be applied at boot time.

Could you please suggest us on the output pin muxing between PWM & PDM.

As of now we are configuring the mux control register from the PWM & PDM drivers.

Regards,
Naidu.

#6 lore raw

Re: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

In reply to Thierry Reding
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

drivers/pwm/pwm-img.c line 138

Quoted 7 lines
drivers/pwm/pwm-img.c new file +7 -0
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val |= BIT(pwm->hwpwm);
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+                        CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+                        CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0);

This smells like pinmux and should probably be a separate driver.

Hope you are suggesting us to have a separate driver for pin muxing (might already have one for Pistachio) and call the pin muxing driver APIs from here.

Quoted 6 lines
Quoted 1 line

Please correct me if my understanding is wrong?

I don't think you need to call the pinmux API from here. Rather I'll assume that the muxing is fixed on a given board, so this configuration would be part of the static board-level pinmux so it will automatically be applied at boot time.

The issue here is that this register does not belong to the pinmux/pinctrl block on this SoC and instead is part of the "peripheral control" block which primarily provides system interface gate clocks and resets (for which I was planning to write a clock provider driver), but also has a bunch of control registers for various IP blocks thrown together (like this one) which we're using syscon to access. I'm not sure it makes sense to create a pinmux driver for these 4 bits, but I'll defer to others on that...

Another option would be to have the main pinctrl driver for Pistachio control these bits, but that doesn't seem quite right since these bits are completely separate from the pinctrl block.

#7 lore raw

Re: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

Quoted 29 lines · Andrew Bresticker
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

drivers/pwm/pwm-img.c line 138

Quoted 7 lines
drivers/pwm/pwm-img.c new file +7 -0
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val |= BIT(pwm->hwpwm);
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+                        CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+                        CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0);

This smells like pinmux and should probably be a separate driver.

Hope you are suggesting us to have a separate driver for pin muxing (might already have one for Pistachio) and call the pin muxing driver APIs from here.

Quoted 6 lines
Quoted 1 line

Please correct me if my understanding is wrong?

I don't think you need to call the pinmux API from here. Rather I'll assume that the muxing is fixed on a given board, so this configuration would be part of the static board-level pinmux so it will automatically be applied at boot time.

The issue here is that this register does not belong to the pinmux/pinctrl block on this SoC and instead is part of the "peripheral control" block which primarily provides system interface gate clocks and resets (for which I was planning to write a clock provider driver), but also has a bunch of control registers for various IP blocks thrown together (like this one) which we're using syscon to access. I'm not sure it makes sense to create a pinmux driver for these 4 bits, but I'll defer to others on that...

Quoted 3 lines

Another option would be to have the main pinctrl driver for Pistachio control these bits, but that doesn't seem quite right since these bits are completely separate from the pinctrl block.

I would think the pinctrl driver should deal with this - yes it's a separate set of registers, but the config is expected to be static and can be represented in the DT.

James.

#8 lore raw

RE: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

Hi James, Andrew, Thierry and all,

Quoted 31 lines · Andrew Bresticker
Quoted 30 lines
Quoted 14 lines
Quoted 14 lines
Quoted 10 lines

drivers/pwm/pwm-img.c line 138

Quoted 8 lines
drivers/pwm/pwm-img.c new file +7 -0
+     val = img_pwm_readl(pwm_chip, CR_PWM_CTRL_CFG);
+     val |= BIT(pwm->hwpwm);
+     img_pwm_writel(pwm_chip, CR_PWM_CTRL_CFG, val);
+
+     regmap_update_bits(pwm_chip->periph_regs, CR_PERIP_PWM_PDM_CONTROL,
+                        CR_PERIP_PWM_PDM_CONTROL_CH_MASK <<
+                        CR_PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0);

This smells like pinmux and should probably be a separate driver.

Hope you are suggesting us to have a separate driver for pin muxing (might already have one for Pistachio) and call the pin muxing driver APIs from here.

Quoted 6 lines
Quoted 1 line

Please correct me if my understanding is wrong?

I don't think you need to call the pinmux API from here. Rather I'll assume that the muxing is fixed on a given board, so this configuration would be part of the static board-level pinmux so it will automatically be applied at boot time.

The issue here is that this register does not belong to the pinmux/pinctrl block on this SoC and instead is part of the "peripheral control" block which primarily provides system interface gate clocks and resets (for which I was planning to write a clock provider driver), but also has a bunch of control registers for various IP blocks thrown together (like this one) which we're using syscon to access. I'm not sure it makes sense to create a pinmux driver for these 4 bits, but I'll defer to others on that...

Quoted 8 lines
Quoted 3 lines

Another option would be to have the main pinctrl driver for Pistachio control these bits, but that doesn't seem quite right since these bits are completely separate from the pinctrl block.

I would think the pinctrl driver should deal with this - yes it's a separate set of registers, but the config is expected to be static and can be represented in the DT.

James.

I have discussed with the hardware team one more time today and discovered that the value we configure to CR_PERIP_PWM_PDM_CONTROL not only configures PWM/PDM output mux, but also enables control signal for PDM blocks.

As an example, if the PDM user wants to enable PDM block 2, he needs to set bit 8 to 1 in the register CR_PERIP_PWM_PDM_CONTROL. Please also note that setting bit 8 to 1 not only configures the output PWM/PDM mux, but also enables control signal for PDM block 2. He needs access to this register from the PDM driver at least to configure (enable/disable) PDM control signal.

And also because of the reasons explained by Andrew above, I think it is better to use syscon (instead of handling it in Pinctrl driver) to access this register both in PWM and PDM drivers.

Please let us know comments and suggestions.

Thanks and regards,
Naidu.

#9 lore raw

Re: [PATCH RESEND v4 1/4] pwm: Imagination Technologies PWM DAC driver

In reply to Naidu Tellapati
Quoted 18 lines
Quoted 1 line
Quoted 1 line
drivers/pwm/pwm-img.c +0 -0

[...]

Quoted 7 lines
Quoted 7 lines
drivers/pwm/pwm-img.c +7 -0
+/* PWM registers */
+#define CR_PWM_CTRL_CFG                              0x0000
+#define CR_PWM_CTRL_CFG_NO_SUB_DIV           0
+#define CR_PWM_CTRL_CFG_SUB_DIV0             1
+#define CR_PWM_CTRL_CFG_SUB_DIV1             2
+#define CR_PWM_CTRL_CFG_SUB_DIV0_DIV1                3
+#define CR_PWM_CTRL_CFG_DIV_SHIFT(ch)                ((ch) * 2 + 4)
Quoted 8 lines

drivers/pwm/pwm-img.c line 36

Quoted 5 lines
drivers/pwm/pwm-img.c +5 -0
+#define CR_PWM_CTRL_CFG_DIV_MASK             0x3
+
+#define CR_PWM_CH_CFG(ch)                    (0x4 + (ch) * 4)
+#define CR_PWM_CH_CFG_TMBASE_SHIFT           0
+#define CR_PWM_CH_CFG_DUTY_SHIFT             16

What's with the CR_ prefix here? What does it stand for? Can't you just drop it?

Quoted 6 lines

CR stands for Control Register. We have picked it from the datasheet and wanted to make the register names compatible with the same in the datasheet.

Hope Andrew agrees with Thierry's comments here. Hope we can drop it.

Andrew, any comments here, please.

I didn't think the CR_ prefix was totally necessary, but it matches what's in the TRM, so I didn't have an issue with it. I'm fine with dropping it.

#10 lore raw

PATCH RESEND v4 2/4 DT: pwm: Add binding document for IMG PWM DAC

In reply to [email protected]

From: Naidu Tellapati <[email protected]>

Add binding document for IMG Pulse Width Modulator (PWM) DAC present on the Pistachio SOC. The PWM DAC has four channels.

---
No changes from v3.

---
 Documentation/devicetree/bindings/pwm/img-pwm.txt |   23 +++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pwm/img-pwm.txt
Documentation/devicetree/bindings/pwm/img-pwm.txt new file +23 -0
new file mode 100644
index 0000000..d3828dd
@@ -0,0 +1,23 @@
+*Imagination Technologies PWM DAC driver
+
+Required properties:
+  - compatible: Should be "img,pistachio-pwm"
+  - reg: Should contain physical base address and length of pwm registers.
+  - clocks: Must contain an entry for each entry in clock-names.
+	See ../clock/clock-bindings.txt for details.
+  - clock-names: input clock names.
+	Required elements: "pwm" and "sys".
+  - #pwm-cells: Should be 2. See pwm.txt in this directory for the
+	description of the cells format.
+  - img,cr-periph: Must contain a phandle to the peripheral control
+	syscon node which contains PWM control registers.
+
+Example:
+	pwm: pwm@18101300 {
+		compatible = "img,pistachio-pwm";
+		reg = <0x18101300 0x100>;
+		clocks = <&pwm_clk>, <&system_clk>;
+		clock-names = "pwm", "sys";
+		#pwm-cells = <2>;
+		img,cr-periph = <&cr_periph>;
+	};
Signature · 1 line
1.7.0.4
#11 lore raw

Re: [PATCH RESEND v4 2/4] DT: pwm: Add binding document for IMG PWM DAC

Quoted 21 lines · On Sat, Nov 22, 2014 at 07:23:30AM +0530, [email protected] wrote:

From: Naidu Tellapati <[email protected]>

Add binding document for IMG Pulse Width Modulator (PWM) DAC present on the Pistachio SOC. The PWM DAC has four channels.

---
No changes from v3.

---
 Documentation/devicetree/bindings/pwm/img-pwm.txt |   23 +++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pwm/img-pwm.txt
Documentation/devicetree/bindings/pwm/img-pwm.txt new file +0 -0
new file mode 100644
index 0000000..d3828dd

Documentation/devicetree/bindings/pwm/img-pwm.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/pwm/img-pwm.txt new file +9 -0
@@ -0,0 +1,23 @@
+*Imagination Technologies PWM DAC driver
+
+Required properties:
+  - compatible: Should be "img,pistachio-pwm"
+  - reg: Should contain physical base address and length of pwm registers.
+  - clocks: Must contain an entry for each entry in clock-names.
+	See ../clock/clock-bindings.txt for details.
+  - clock-names: input clock names.
+	Required elements: "pwm" and "sys".

I think it'd be useful to explain at least what the "sys" clock is. "pwm" I'd assume that it clocks the IP block, but what does "sys" do?

Thierry

#12 lore raw

RE: [PATCH RESEND v4 2/4] DT: pwm: Add binding document for IMG PWM DAC

Hi Thierry,

Many thanks for your review comments.

Quoted 26 lines · On Sat, Nov 22, 2014 at 07:23:30AM +0530, [email protected] wrote:
Quoted 25 lines

From: Naidu Tellapati <[email protected]>

Add binding document for IMG Pulse Width Modulator (PWM) DAC present on the Pistachio SOC. The PWM DAC has four channels.

---
No changes from v3.

---
 Documentation/devicetree/bindings/pwm/img-pwm.txt |   23 +++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pwm/img-pwm.txt
Documentation/devicetree/bindings/pwm/img-pwm.txt new file +4 -0
new file mode 100644
index 0000000..d3828dd
@@ -0,0 +1,23 @@
+*Imagination Technologies PWM DAC driver
+
+Required properties:
+  - compatible: Should be "img,pistachio-pwm"
Quoted 8 lines

Documentation/devicetree/bindings/pwm/img-pwm.txt line 9

Quoted 5 lines
Documentation/devicetree/bindings/pwm/img-pwm.txt new file +5 -0
+  - reg: Should contain physical base address and length of pwm registers.
+  - clocks: Must contain an entry for each entry in clock-names.
+     See ../clock/clock-bindings.txt for details.
+  - clock-names: input clock names.
+     Required elements: "pwm" and "sys".

I think it'd be useful to explain at least what the "sys" clock is. "pwm" I'd assume that it clocks the IP block, but what does "sys" do?

OK. Will add the description in the next patch set.

The sys clock enables access to Internal configuration registers of PWM block.

Quoted 1 line

Thierry

Regards,
Naidu.

#13 lore raw

PATCH RESEND v4 3/4 pdm: Imagination Technologies PDM DAC driver

In reply to [email protected]

From: Naidu Tellapati <[email protected]>

The Pistachio SOC from Imagination Technologies includes a Pulse Density Modulation DAC which produces a form of analogue output according to the relative density of output pulses to the intended analogue signal amplitude. Four PDM outputs are provided that can be used to control targets such as LCD backlight.

---
 drivers/misc/Kconfig    |   12 +
 drivers/misc/Makefile   |    1 +
 drivers/misc/img-pdm.c  |  676 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/img_pdm.h |   35 +++
 4 files changed, 724 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/img-pdm.c
 create mode 100644 include/linux/img_pdm.h
drivers/misc/Kconfig +12 -0
index bbeb451..5157fa9 100644
@@ -515,6 +515,18 @@ config VEXPRESS_SYSCFG
 	  bus. System Configuration interface is one of the possible means
 	  of generating transactions on this bus.
 
+config IMG_PDM
+	tristate "Imagination Technologies PDM driver"
+	depends on MFD_SYSCON
+	depends on HAS_IOMEM
+	depends on MIPS || COMPILE_TEST
+	help
+	  PDM driver for Imagination Technologies PDM block which supports 4
+	  channels.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called img-pdm.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index 7d5c4cd..d8c7d55 100644
@@ -56,3 +56,4 @@ obj-$(CONFIG_GENWQE)		+= genwqe/
 obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
+obj-$(CONFIG_IMG_PDM)		+= img-pdm.o
drivers/misc/img-pdm.c new file +676 -0

676 lines not on this page · raw message

include/linux/img_pdm.h new file +35 -0
new file mode 100644
index 0000000..0203951
@@ -0,0 +1,35 @@
+/**
+ * Imagination Technologies Pulse Density Modulator driver
+ *
+ * Copyright (C) 2014 Imagination Technologies Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __IMG_PDM_H
+#define __IMG_PDM_H
+
+struct img_pdm_device {
+	struct clk *clk;
+	struct kobject **pdm_kobj;
+	struct regmap *periph_regs;
+	struct platform_device *pdev;
+};
+
+struct img_pdm_channel {
+	unsigned int pdm_id;
+	unsigned long flags;
+	struct img_pdm_device *pdm_dev;
+};
+
+void img_pdm_channel_put(struct device *dev);
+struct img_pdm_channel *img_pdm_channel_get(struct device *dev);
+int img_pdm_channel_enable_set(struct img_pdm_channel *chan, bool state);
+int img_pdm_channel_enable_get(struct img_pdm_channel *chan);
+int img_pdm_channel_pulse_in_get(struct img_pdm_channel *chan);
+int img_pdm_channel_pulse_in_set(struct img_pdm_channel *chan,
+				 unsigned int val);
+
+#endif /* ifndef _IMG_PDM_H */
Signature · 1 line
1.7.0.4
#14 lore raw

PATCH RESEND v4 4/4 DT: pdm: Add binding document for IMG PDM DAC

In reply to [email protected]

From: Naidu Tellapati <[email protected]>

Add binding document for the Pulse Density Modulator (PDM) DAC present on the Pistachio SOC.

---
 Documentation/devicetree/bindings/misc/img-pdm.txt |   54 ++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/misc/img-pdm.txt
Documentation/devicetree/bindings/misc/img-pdm.txt new file +54 -0
new file mode 100644
index 0000000..730d38a
@@ -0,0 +1,54 @@
+*Imagination Technologies Pulse Density Modulator (PDM) DAC.
+
+Required properties:
+  - compatible: Must be "img,pistachio-pdm"
+  - clocks: Must contain an entry for each entry in clock-names.
+  - clock-names: Must include the following entry:
+	Required elements: "pdm"
+  - img,cr-periph: Must contain a phandle to the peripheral control
+	syscon node which contains PDM control registers.
+  - #pdm-cells: Must be 2.
+  - The first cell is the PDM channel number (valid values: 0, 1, 2, 3)
+  - The second cell is 12-bit pulse-in value
+
+Specifying PDM information for devices
+======================================
+
+1. PDM User nodes
+
+PDM properties should be named "pdms". The exact meaning of each pdms property
+is described above.
+
+	pdm-specifier : array of #pdm-cells specifying the given PDM
+						(controller specific)
+
+The following example could be used to describe a PDM-based backlight device:
+
+	pdm: pdm {
+		#pdm-cells = <2>;
+	};
+
+	[...]
+
+	bl: backlight {
+		pdms = <&pdm 2 0>;
+	};
+
+pdm-specifier typically encodes the chip-relative PDM channel number and the
+12-bit pulse-in value.
+
+2. PDM Controller nodes
+
+PDM controller nodes must specify the number of cells used for the specifier
+using the '#pdm-cells' property.
+
+An example PDM controller might look like this:
+
+Example:
+	pdm: pdm@18148000 {
+		compatible = "img,pistachio-pdm";
+		clocks = <&pdm_clk>;
+		clk-names = "pdm";
+		img,cr-periph = <&cr_periph>;
+		#pdm-cells = <2>;
+	};
Signature · 1 line
1.7.0.4