mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/8] PWM: misc fixes
@ 2020-02-06 11:23 Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 1/8] PWM: pxa: remove unused struct members Ahmad Fatoum
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Some stuff I ran into while refactoring barebox PWM to be more
welcoming for porting kernel drivers using the kernel atomic
PWM API. Driver will follow soon.

Cheers,
Ahmad Fatoum (8):
  PWM: pxa: remove unused struct members
  PWM: pxa: make MMIO writes always little endian
  regmap: forward declare structs used in header
  video: backlight-pwm: remove duplicate assignment to object
  led: pwm: don't test if pointer is smaller than zero
  led: pwm: fail if required max-brightness option is missing
  led: pwm: support active-low property
  PWM: core: constify chip->ops pointer

 drivers/led/led-pwm.c         | 10 ++++++++--
 drivers/pwm/pxa_pwm.c         | 11 +++--------
 drivers/video/backlight-pwm.c |  2 --
 include/pwm.h                 |  2 +-
 include/regmap.h              |  3 +++
 5 files changed, 15 insertions(+), 13 deletions(-)

-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/8] PWM: pxa: remove unused struct members
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 2/8] PWM: pxa: make MMIO writes always little endian Ahmad Fatoum
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Both duty_ns and period_ns are stored to, but never read. Drop them.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/pwm/pxa_pwm.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/pwm/pxa_pwm.c b/drivers/pwm/pxa_pwm.c
index c7130c225ebe..90899fd3c985 100644
--- a/drivers/pwm/pxa_pwm.c
+++ b/drivers/pwm/pxa_pwm.c
@@ -34,8 +34,6 @@ struct pxa_pwm_chip {
 	struct pwm_chip chip;
 	void __iomem *iobase;
 	int id;
-	int duty_ns;
-	int period_ns;
 };
 
 static struct pxa_pwm_chip *to_pxa_pwm_chip(struct pwm_chip *chip)
@@ -72,9 +70,6 @@ static int pxa_pwm_config(struct pwm_chip *chip, int duty_ns, int period_ns)
 	else
 		dc = (pv + 1) * duty_ns / period_ns;
 
-	pxa_pwm->duty_ns = duty_ns;
-	pxa_pwm->period_ns = period_ns;
-
 	/* NOTE: the clock to PWM has to be enabled first
 	 * before writing to the registers
 	 */
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/8] PWM: pxa: make MMIO writes always little endian
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 1/8] PWM: pxa: remove unused struct members Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 3/8] regmap: forward declare structs used in header Ahmad Fatoum
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Even when the processor runs in big-endian mode, the peripheral is
little-endian and is used as such in Linux. Do here likewise.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/pwm/pxa_pwm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pwm/pxa_pwm.c b/drivers/pwm/pxa_pwm.c
index 90899fd3c985..4575817e946c 100644
--- a/drivers/pwm/pxa_pwm.c
+++ b/drivers/pwm/pxa_pwm.c
@@ -73,9 +73,9 @@ static int pxa_pwm_config(struct pwm_chip *chip, int duty_ns, int period_ns)
 	/* NOTE: the clock to PWM has to be enabled first
 	 * before writing to the registers
 	 */
-	__raw_writel(prescale, pxa_pwm->iobase + PWMCR);
-	__raw_writel(dc, pxa_pwm->iobase + PWMDCR);
-	__raw_writel(pv, pxa_pwm->iobase + PWMPCR);
+	writel(prescale, pxa_pwm->iobase + PWMCR);
+	writel(dc, pxa_pwm->iobase + PWMDCR);
+	writel(pv, pxa_pwm->iobase + PWMPCR);
 
 	return 0;
 }
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/8] regmap: forward declare structs used in header
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 1/8] PWM: pxa: remove unused struct members Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 2/8] PWM: pxa: make MMIO writes always little endian Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 4/8] video: backlight-pwm: remove duplicate assignment to object Ahmad Fatoum
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Both the device_d and device_node struct are used opaquely in this
header. Forward declare them to avoid compilation errors on different
include order.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/regmap.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/regmap.h b/include/regmap.h
index 09b7b57d52f3..049ac0210e43 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -37,6 +37,9 @@ struct regmap_bus {
 	regmap_hw_reg_read reg_read;
 };
 
+struct device_d;
+struct device_node;
+
 struct regmap *regmap_init(struct device_d *dev,
 			     const struct regmap_bus *bus,
 			     void *bus_context,
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/8] video: backlight-pwm: remove duplicate assignment to object
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2020-02-06 11:23 ` [PATCH 3/8] regmap: forward declare structs used in header Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 5/8] led: pwm: don't test if pointer is smaller than zero Ahmad Fatoum
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

pwm_backlight->period is assigned pwm_get_period(pwm), which is the same
value just a few lines earlier. Remove the superfluous reassignment.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/video/backlight-pwm.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
index 997235a74a30..9111a42d7544 100644
--- a/drivers/video/backlight-pwm.c
+++ b/drivers/video/backlight-pwm.c
@@ -204,8 +204,6 @@ static int backlight_pwm_of_probe(struct device_d *dev)
 		return PTR_ERR(pwm_backlight->power);
 	}
 
-	pwm_backlight->period = pwm_get_period(pwm_backlight->pwm);
-
 	pwm_backlight->backlight.slew_time_ms = 100;
 	pwm_backlight->backlight.brightness_set = backlight_pwm_set;
 	pwm_backlight->backlight.node = dev->device_node;
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/8] led: pwm: don't test if pointer is smaller than zero
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2020-02-06 11:23 ` [PATCH 4/8] video: backlight-pwm: remove duplicate assignment to object Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 6/8] led: pwm: fail if required max-brightness option is missing Ahmad Fatoum
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

of_pwm_request returns either the valid or an error pointer.
Revise the error check to reflect this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/led/led-pwm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/led/led-pwm.c b/drivers/led/led-pwm.c
index 16d22b55695e..2b53614ed388 100644
--- a/drivers/led/led-pwm.c
+++ b/drivers/led/led-pwm.c
@@ -54,7 +54,7 @@ static int led_pwm_of_probe(struct device_d *dev)
 		struct pwm_device *pwm;
 
 		pwm = of_pwm_request(child, NULL);
-		if (pwm < 0)
+		if (IS_ERR(pwm))
 			continue;
 
 		pwmled = xzalloc(sizeof(*pwmled));
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/8] led: pwm: fail if required max-brightness option is missing
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2020-02-06 11:23 ` [PATCH 5/8] led: pwm: don't test if pointer is smaller than zero Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 7/8] led: pwm: support active-low property Ahmad Fatoum
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

If we leave max_value at the default value of zero led_pwm_set above
will divide by zero in do_div. The binding makes max-brightness
a mandatory property, so have the driver treat it as such as well.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/led/led-pwm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/led/led-pwm.c b/drivers/led/led-pwm.c
index 2b53614ed388..419d96eed392 100644
--- a/drivers/led/led-pwm.c
+++ b/drivers/led/led-pwm.c
@@ -61,7 +61,9 @@ static int led_pwm_of_probe(struct device_d *dev)
 		pwmled->led.name = xstrdup(child->name);
 		pwmled->pwm = pwm;
 
-		of_property_read_u32(child, "max-brightness", &pwmled->led.max_value);
+		ret = of_property_read_u32(child, "max-brightness", &pwmled->led.max_value);
+		if (ret)
+			return ret;
 
 		pwmled->period = pwm_get_period(pwmled->pwm);
 
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 7/8] led: pwm: support active-low property
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
                   ` (5 preceding siblings ...)
  2020-02-06 11:23 ` [PATCH 6/8] led: pwm: fail if required max-brightness option is missing Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-06 11:23 ` [PATCH 8/8] PWM: core: constify chip->ops pointer Ahmad Fatoum
  2020-02-10  8:16 ` [PATCH 0/8] PWM: misc fixes Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

active-low is an optional property to describe PWMs where the LED is wired
to supply rather than ground. Add barebox support for it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/led/led-pwm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/led/led-pwm.c b/drivers/led/led-pwm.c
index 419d96eed392..8a358dde88b3 100644
--- a/drivers/led/led-pwm.c
+++ b/drivers/led/led-pwm.c
@@ -41,6 +41,9 @@ static void led_pwm_set(struct led *led, unsigned int brightness)
         duty *= brightness;
         do_div(duty, max);
 
+	if (pwmled->active_low)
+		duty = pwmled->period - duty;
+
 	pwm_config(pwmled->pwm, duty, pwmled->period);
 }
 
@@ -66,6 +69,7 @@ static int led_pwm_of_probe(struct device_d *dev)
 			return ret;
 
 		pwmled->period = pwm_get_period(pwmled->pwm);
+		pwmled->active_low = of_property_read_bool(child, "active-low");
 
 		pwmled->led.set = led_pwm_set;
 
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 8/8] PWM: core: constify chip->ops pointer
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
                   ` (6 preceding siblings ...)
  2020-02-06 11:23 ` [PATCH 7/8] led: pwm: support active-low property Ahmad Fatoum
@ 2020-02-06 11:23 ` Ahmad Fatoum
  2020-02-10  8:16 ` [PATCH 0/8] PWM: misc fixes Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2020-02-06 11:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

There's no reason,users of the member would want to change the
pointee. Make it const.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/pwm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/pwm.h b/include/pwm.h
index 911c760839fa..3dce2859136c 100644
--- a/include/pwm.h
+++ b/include/pwm.h
@@ -66,7 +66,7 @@ struct pwm_ops {
 struct pwm_chip {
 	int			id;
 	const char		*devname;
-	struct pwm_ops		*ops;
+	const struct pwm_ops	*ops;
 	int			duty_ns;
 	int			period_ns;
 };
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/8] PWM: misc fixes
  2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
                   ` (7 preceding siblings ...)
  2020-02-06 11:23 ` [PATCH 8/8] PWM: core: constify chip->ops pointer Ahmad Fatoum
@ 2020-02-10  8:16 ` Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2020-02-10  8:16 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Feb 06, 2020 at 12:23:26PM +0100, Ahmad Fatoum wrote:
> Some stuff I ran into while refactoring barebox PWM to be more
> welcoming for porting kernel drivers using the kernel atomic
> PWM API. Driver will follow soon.
> 
> Cheers,
> Ahmad Fatoum (8):
>   PWM: pxa: remove unused struct members
>   PWM: pxa: make MMIO writes always little endian
>   regmap: forward declare structs used in header
>   video: backlight-pwm: remove duplicate assignment to object
>   led: pwm: don't test if pointer is smaller than zero
>   led: pwm: fail if required max-brightness option is missing
>   led: pwm: support active-low property
>   PWM: core: constify chip->ops pointer
> 
>  drivers/led/led-pwm.c         | 10 ++++++++--
>  drivers/pwm/pxa_pwm.c         | 11 +++--------
>  drivers/video/backlight-pwm.c |  2 --
>  include/pwm.h                 |  2 +-
>  include/regmap.h              |  3 +++
>  5 files changed, 15 insertions(+), 13 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-02-10  8:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 11:23 [PATCH 0/8] PWM: misc fixes Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 1/8] PWM: pxa: remove unused struct members Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 2/8] PWM: pxa: make MMIO writes always little endian Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 3/8] regmap: forward declare structs used in header Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 4/8] video: backlight-pwm: remove duplicate assignment to object Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 5/8] led: pwm: don't test if pointer is smaller than zero Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 6/8] led: pwm: fail if required max-brightness option is missing Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 7/8] led: pwm: support active-low property Ahmad Fatoum
2020-02-06 11:23 ` [PATCH 8/8] PWM: core: constify chip->ops pointer Ahmad Fatoum
2020-02-10  8:16 ` [PATCH 0/8] PWM: misc fixes Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox