devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: dt-bindings: rpi-panel: Add regulator for 7" Raspberry Pi 720x1280
@ 2025-06-09  0:06 Marek Vasut
  2025-06-09  0:06 ` [PATCH 2/2] regulator: rpi-panel-v2: " Marek Vasut
  2025-06-09 15:12 ` [PATCH 1/2] regulator: dt-bindings: rpi-panel: " Mark Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Marek Vasut @ 2025-06-09  0:06 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Marek Vasut, Broadcom internal kernel review list, Conor Dooley,
	Dave Stevenson, Florian Fainelli, Krzysztof Kozlowski,
	Liam Girdwood, Mark Brown, Rob Herring, devicetree,
	linux-renesas-soc, linux-rpi-kernel

Document regulator compatible string for the 7" Raspberry Pi 720x1280 DSI
panel based on ili9881. This is the Raspberry Pi DSI Panel V2. The newer
Raspberry Pi 5" and 7" panels have a slightly different register map to
the original one and offers PWM backlight control.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
Cc: Florian Fainelli <florian.fainelli@broadcom.com>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Rob Herring <robh@kernel.org>
Cc: devicetree@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-rpi-kernel@lists.infradead.org
---
 .../raspberrypi,7inch-touchscreen-panel-regulator.yaml     | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/raspberrypi,7inch-touchscreen-panel-regulator.yaml b/Documentation/devicetree/bindings/regulator/raspberrypi,7inch-touchscreen-panel-regulator.yaml
index 41678400e63f..18944d39d08f 100644
--- a/Documentation/devicetree/bindings/regulator/raspberrypi,7inch-touchscreen-panel-regulator.yaml
+++ b/Documentation/devicetree/bindings/regulator/raspberrypi,7inch-touchscreen-panel-regulator.yaml
@@ -12,14 +12,17 @@ maintainers:
 description: |
   The RaspberryPi 7" display has an ATTINY88-based regulator/backlight
   controller on the PCB, which is used to turn the display unit on/off
-  and control the backlight.
+  and control the backlight. The V2 supports 5" and 7" panels and also
+  offers PWM backlight control.
 
 allOf:
   - $ref: regulator.yaml#
 
 properties:
   compatible:
-    const: raspberrypi,7inch-touchscreen-panel-regulator
+    enum:
+      - raspberrypi,7inch-touchscreen-panel-regulator
+      - raspberrypi,touchscreen-panel-regulator-v2
 
   reg:
     maxItems: 1
-- 
2.47.2


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

* [PATCH 2/2] regulator: rpi-panel-v2: Add regulator for 7" Raspberry Pi 720x1280
  2025-06-09  0:06 [PATCH 1/2] regulator: dt-bindings: rpi-panel: Add regulator for 7" Raspberry Pi 720x1280 Marek Vasut
@ 2025-06-09  0:06 ` Marek Vasut
  2025-06-11  9:55   ` Geert Uytterhoeven
  2025-06-11 20:30   ` Uwe Kleine-König
  2025-06-09 15:12 ` [PATCH 1/2] regulator: dt-bindings: rpi-panel: " Mark Brown
  1 sibling, 2 replies; 6+ messages in thread
From: Marek Vasut @ 2025-06-09  0:06 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Dave Stevenson, Marek Vasut, Broadcom internal kernel review list,
	Conor Dooley, Florian Fainelli, Krzysztof Kozlowski,
	Liam Girdwood, Mark Brown, Rob Herring, devicetree,
	linux-renesas-soc, linux-rpi-kernel

From: Dave Stevenson <dave.stevenson@raspberrypi.com>

Add regulator for the 7" Raspberry Pi 720x1280 DSI panel based on ili9881.
This is the Raspberry Pi DSI Panel V2. The newer Raspberry Pi 5" and 7"
panels have a slightly different register map to the original one. Add a
new driver for this "regulator" chip, this time by exposing two GPIOs and
one PWM controller, both of which can be consumed by panel driver and
pwm-backlight respectively.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Loosely based on:
https://github.com/raspberrypi/linux 3c07b87e877e ("regulator: Add a regulator for the new LCD panels")]
https://github.com/raspberrypi/linux 68c59b9e6275 ("regulator: rpi_panel_v2: Add remove and shutdown hooks")]
---
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
Cc: Florian Fainelli <florian.fainelli@broadcom.com>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Rob Herring <robh@kernel.org>
Cc: devicetree@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-rpi-kernel@lists.infradead.org
---
 drivers/regulator/Kconfig                  |  10 ++
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/rpi-panel-v2-regulator.c | 114 +++++++++++++++++++++
 3 files changed, 125 insertions(+)
 create mode 100644 drivers/regulator/rpi-panel-v2-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 6d8988387da4..21ad6d938e4d 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -1153,6 +1153,16 @@ config REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY
 	  touchscreen unit. The regulator is used to enable power to the
 	  TC358762, display and to control backlight.
 
+config REGULATOR_RASPBERRYPI_TOUCHSCREEN_V2
+	tristate "Raspberry Pi 7-inch touchscreen panel V2 regulator"
+	depends on I2C
+	select GPIO_REGMAP
+	select REGMAP_I2C
+	help
+	  This driver supports regulator on the V2 Raspberry Pi touchscreen
+	  unit. The regulator is used to enable power to the display and to
+	  control backlight PWM.
+
 config REGULATOR_RC5T583
 	tristate "RICOH RC5T583 Power regulators"
 	depends on MFD_RC5T583
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index c0bc7a0f4e67..be98b29d6675 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -136,6 +136,7 @@ obj-$(CONFIG_REGULATOR_PBIAS) += pbias-regulator.o
 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
 obj-$(CONFIG_REGULATOR_RAA215300) += raa215300.o
 obj-$(CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY)  += rpi-panel-attiny-regulator.o
+obj-$(CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_V2)  += rpi-panel-v2-regulator.o
 obj-$(CONFIG_REGULATOR_RC5T583)  += rc5t583-regulator.o
 obj-$(CONFIG_REGULATOR_RK808)   += rk808-regulator.o
 obj-$(CONFIG_REGULATOR_RN5T618) += rn5t618-regulator.o
diff --git a/drivers/regulator/rpi-panel-v2-regulator.c b/drivers/regulator/rpi-panel-v2-regulator.c
new file mode 100644
index 000000000000..b77383584a3a
--- /dev/null
+++ b/drivers/regulator/rpi-panel-v2-regulator.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 Raspberry Pi Ltd.
+ * Copyright (C) 2025 Marek Vasut
+ */
+
+#include <linux/err.h>
+#include <linux/gpio/driver.h>
+#include <linux/gpio/regmap.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/pwm.h>
+#include <linux/regmap.h>
+
+/* I2C registers of the microcontroller. */
+#define REG_ID		0x01
+#define REG_POWERON	0x02
+#define REG_PWM		0x03
+
+/* Bits for poweron register */
+#define LCD_RESET_BIT	BIT(0)
+#define CTP_RESET_BIT	BIT(1)
+
+/* Bits for the PWM register */
+#define PWM_BL_ENABLE	BIT(7)
+#define PWM_BL_MASK	GENMASK(4, 0)
+
+/* Treat LCD_RESET and CTP_RESET as GPIOs */
+#define NUM_GPIO	2
+
+static const struct regmap_config rpi_panel_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = REG_PWM,
+	.can_sleep = true,
+};
+
+static int rpi_panel_v2_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+				  const struct pwm_state *state)
+{
+	struct regmap *regmap = pwmchip_get_drvdata(chip);
+	unsigned int duty;
+
+	if (state->polarity != PWM_POLARITY_NORMAL)
+		return -EINVAL;
+
+	if (!state->enabled)
+		return regmap_write(regmap, REG_PWM, 0);
+
+	duty = pwm_get_relative_duty_cycle(state, PWM_BL_MASK);
+	return regmap_write(regmap, REG_PWM, duty | PWM_BL_ENABLE);
+}
+
+static const struct pwm_ops rpi_panel_v2_pwm_ops = {
+	.apply = rpi_panel_v2_pwm_apply,
+};
+
+/*
+ * I2C driver interface functions
+ */
+static int rpi_panel_v2_i2c_probe(struct i2c_client *i2c)
+{
+	struct gpio_regmap_config gconfig = {
+		.ngpio		= NUM_GPIO,
+		.ngpio_per_reg	= NUM_GPIO,
+		.parent		= &i2c->dev,
+		.reg_set_base	= REG_POWERON,
+	};
+	struct regmap *regmap;
+	struct pwm_chip *pc;
+	int ret;
+
+	pc = devm_pwmchip_alloc(&i2c->dev, 1, 0);
+	if (IS_ERR(pc))
+		return PTR_ERR(pc);
+
+	pc->ops = &rpi_panel_v2_pwm_ops;
+
+	regmap = devm_regmap_init_i2c(i2c, &rpi_panel_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(&i2c->dev, PTR_ERR(regmap), "Failed to allocate regmap\n");
+
+	pwmchip_set_drvdata(pc, regmap);
+
+	regmap_write(regmap, REG_POWERON, 0);
+
+	gconfig.regmap = regmap;
+	ret = PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&i2c->dev, &gconfig));
+	if (ret)
+		return dev_err_probe(&i2c->dev, ret, "Failed to create gpiochip\n");
+
+	return devm_pwmchip_add(&i2c->dev, pc);
+}
+
+static const struct of_device_id rpi_panel_v2_dt_ids[] = {
+	{ .compatible = "raspberrypi,touchscreen-panel-regulator-v2" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, rpi_panel_v2_dt_ids);
+
+static struct i2c_driver rpi_panel_v2_regulator_driver = {
+	.driver = {
+		.name = "rpi_touchscreen_v2",
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+		.of_match_table = of_match_ptr(rpi_panel_v2_dt_ids),
+	},
+	.probe = rpi_panel_v2_i2c_probe,
+};
+
+module_i2c_driver(rpi_panel_v2_regulator_driver);
+
+MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
+MODULE_DESCRIPTION("Regulator device driver for Raspberry Pi 7-inch V2 touchscreen");
+MODULE_LICENSE("GPL");
-- 
2.47.2


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

* Re: [PATCH 1/2] regulator: dt-bindings: rpi-panel: Add regulator for 7" Raspberry Pi 720x1280
  2025-06-09  0:06 [PATCH 1/2] regulator: dt-bindings: rpi-panel: Add regulator for 7" Raspberry Pi 720x1280 Marek Vasut
  2025-06-09  0:06 ` [PATCH 2/2] regulator: rpi-panel-v2: " Marek Vasut
@ 2025-06-09 15:12 ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2025-06-09 15:12 UTC (permalink / raw)
  To: linux-arm-kernel, Marek Vasut
  Cc: Broadcom internal kernel review list, Conor Dooley,
	Dave Stevenson, Florian Fainelli, Krzysztof Kozlowski,
	Liam Girdwood, Rob Herring, devicetree, linux-renesas-soc,
	linux-rpi-kernel

On Mon, 09 Jun 2025 02:06:41 +0200, Marek Vasut wrote:
> Document regulator compatible string for the 7" Raspberry Pi 720x1280 DSI
> panel based on ili9881. This is the Raspberry Pi DSI Panel V2. The newer
> Raspberry Pi 5" and 7" panels have a slightly different register map to
> the original one and offers PWM backlight control.
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/2] regulator: dt-bindings: rpi-panel: Add regulator for 7" Raspberry Pi 720x1280
      commit: 6d09c6e474bd27a86352deaf73d02c8c21eeec7c
[2/2] regulator: rpi-panel-v2: Add regulator for 7" Raspberry Pi 720x1280
      commit: d49305862fdc4d9ff1b1093b4ed7d8e0cb9971b4

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

* Re: [PATCH 2/2] regulator: rpi-panel-v2: Add regulator for 7" Raspberry Pi 720x1280
  2025-06-09  0:06 ` [PATCH 2/2] regulator: rpi-panel-v2: " Marek Vasut
@ 2025-06-11  9:55   ` Geert Uytterhoeven
  2025-06-11 20:30   ` Uwe Kleine-König
  1 sibling, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2025-06-11  9:55 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-arm-kernel, Dave Stevenson,
	Broadcom internal kernel review list, Conor Dooley,
	Florian Fainelli, Krzysztof Kozlowski, Liam Girdwood, Mark Brown,
	Rob Herring, devicetree, linux-renesas-soc, linux-rpi-kernel,
	Uwe Kleine-König, Linux PWM List

CC pwm

On Wed, 11 Jun 2025 at 10:19, Marek Vasut
<marek.vasut+renesas@mailbox.org> wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.com>
>
> Add regulator for the 7" Raspberry Pi 720x1280 DSI panel based on ili9881.
> This is the Raspberry Pi DSI Panel V2. The newer Raspberry Pi 5" and 7"
> panels have a slightly different register map to the original one. Add a
> new driver for this "regulator" chip, this time by exposing two GPIOs and
> one PWM controller, both of which can be consumed by panel driver and
> pwm-backlight respectively.
>
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
> ---
> Loosely based on:
> https://github.com/raspberrypi/linux 3c07b87e877e ("regulator: Add a regulator for the new LCD panels")]
> https://github.com/raspberrypi/linux 68c59b9e6275 ("regulator: rpi_panel_v2: Add remove and shutdown hooks")]
> ---
> Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
> Cc: Conor Dooley <conor+dt@kernel.org>
> Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
> Cc: Florian Fainelli <florian.fainelli@broadcom.com>
> Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Rob Herring <robh@kernel.org>
> Cc: devicetree@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-renesas-soc@vger.kernel.org
> Cc: linux-rpi-kernel@lists.infradead.org
> ---
>  drivers/regulator/Kconfig                  |  10 ++
>  drivers/regulator/Makefile                 |   1 +
>  drivers/regulator/rpi-panel-v2-regulator.c | 114 +++++++++++++++++++++
>  3 files changed, 125 insertions(+)
>  create mode 100644 drivers/regulator/rpi-panel-v2-regulator.c
>
> diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
> index 6d8988387da4..21ad6d938e4d 100644
> --- a/drivers/regulator/Kconfig
> +++ b/drivers/regulator/Kconfig
> @@ -1153,6 +1153,16 @@ config REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY
>           touchscreen unit. The regulator is used to enable power to the
>           TC358762, display and to control backlight.
>
> +config REGULATOR_RASPBERRYPI_TOUCHSCREEN_V2
> +       tristate "Raspberry Pi 7-inch touchscreen panel V2 regulator"
> +       depends on I2C
> +       select GPIO_REGMAP
> +       select REGMAP_I2C
> +       help
> +         This driver supports regulator on the V2 Raspberry Pi touchscreen
> +         unit. The regulator is used to enable power to the display and to
> +         control backlight PWM.
> +
>  config REGULATOR_RC5T583
>         tristate "RICOH RC5T583 Power regulators"
>         depends on MFD_RC5T583
> diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
> index c0bc7a0f4e67..be98b29d6675 100644
> --- a/drivers/regulator/Makefile
> +++ b/drivers/regulator/Makefile
> @@ -136,6 +136,7 @@ obj-$(CONFIG_REGULATOR_PBIAS) += pbias-regulator.o
>  obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
>  obj-$(CONFIG_REGULATOR_RAA215300) += raa215300.o
>  obj-$(CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY)  += rpi-panel-attiny-regulator.o
> +obj-$(CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_V2)  += rpi-panel-v2-regulator.o
>  obj-$(CONFIG_REGULATOR_RC5T583)  += rc5t583-regulator.o
>  obj-$(CONFIG_REGULATOR_RK808)   += rk808-regulator.o
>  obj-$(CONFIG_REGULATOR_RN5T618) += rn5t618-regulator.o
> diff --git a/drivers/regulator/rpi-panel-v2-regulator.c b/drivers/regulator/rpi-panel-v2-regulator.c
> new file mode 100644
> index 000000000000..b77383584a3a
> --- /dev/null
> +++ b/drivers/regulator/rpi-panel-v2-regulator.c
> @@ -0,0 +1,114 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2022 Raspberry Pi Ltd.
> + * Copyright (C) 2025 Marek Vasut
> + */
> +
> +#include <linux/err.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/gpio/regmap.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/pwm.h>
> +#include <linux/regmap.h>
> +
> +/* I2C registers of the microcontroller. */
> +#define REG_ID         0x01
> +#define REG_POWERON    0x02
> +#define REG_PWM                0x03
> +
> +/* Bits for poweron register */
> +#define LCD_RESET_BIT  BIT(0)
> +#define CTP_RESET_BIT  BIT(1)
> +
> +/* Bits for the PWM register */
> +#define PWM_BL_ENABLE  BIT(7)
> +#define PWM_BL_MASK    GENMASK(4, 0)
> +
> +/* Treat LCD_RESET and CTP_RESET as GPIOs */
> +#define NUM_GPIO       2
> +
> +static const struct regmap_config rpi_panel_regmap_config = {
> +       .reg_bits = 8,
> +       .val_bits = 8,
> +       .max_register = REG_PWM,
> +       .can_sleep = true,
> +};
> +
> +static int rpi_panel_v2_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> +                                 const struct pwm_state *state)
> +{
> +       struct regmap *regmap = pwmchip_get_drvdata(chip);
> +       unsigned int duty;
> +
> +       if (state->polarity != PWM_POLARITY_NORMAL)
> +               return -EINVAL;
> +
> +       if (!state->enabled)
> +               return regmap_write(regmap, REG_PWM, 0);
> +
> +       duty = pwm_get_relative_duty_cycle(state, PWM_BL_MASK);
> +       return regmap_write(regmap, REG_PWM, duty | PWM_BL_ENABLE);
> +}
> +
> +static const struct pwm_ops rpi_panel_v2_pwm_ops = {
> +       .apply = rpi_panel_v2_pwm_apply,
> +};
> +
> +/*
> + * I2C driver interface functions
> + */
> +static int rpi_panel_v2_i2c_probe(struct i2c_client *i2c)
> +{
> +       struct gpio_regmap_config gconfig = {
> +               .ngpio          = NUM_GPIO,
> +               .ngpio_per_reg  = NUM_GPIO,
> +               .parent         = &i2c->dev,
> +               .reg_set_base   = REG_POWERON,
> +       };
> +       struct regmap *regmap;
> +       struct pwm_chip *pc;
> +       int ret;
> +
> +       pc = devm_pwmchip_alloc(&i2c->dev, 1, 0);
> +       if (IS_ERR(pc))
> +               return PTR_ERR(pc);
> +
> +       pc->ops = &rpi_panel_v2_pwm_ops;
> +
> +       regmap = devm_regmap_init_i2c(i2c, &rpi_panel_regmap_config);
> +       if (IS_ERR(regmap))
> +               return dev_err_probe(&i2c->dev, PTR_ERR(regmap), "Failed to allocate regmap\n");
> +
> +       pwmchip_set_drvdata(pc, regmap);
> +
> +       regmap_write(regmap, REG_POWERON, 0);
> +
> +       gconfig.regmap = regmap;
> +       ret = PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&i2c->dev, &gconfig));
> +       if (ret)
> +               return dev_err_probe(&i2c->dev, ret, "Failed to create gpiochip\n");
> +
> +       return devm_pwmchip_add(&i2c->dev, pc);
> +}
> +
> +static const struct of_device_id rpi_panel_v2_dt_ids[] = {
> +       { .compatible = "raspberrypi,touchscreen-panel-regulator-v2" },
> +       { },
> +};
> +MODULE_DEVICE_TABLE(of, rpi_panel_v2_dt_ids);
> +
> +static struct i2c_driver rpi_panel_v2_regulator_driver = {
> +       .driver = {
> +               .name = "rpi_touchscreen_v2",
> +               .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> +               .of_match_table = of_match_ptr(rpi_panel_v2_dt_ids),
> +       },
> +       .probe = rpi_panel_v2_i2c_probe,
> +};
> +
> +module_i2c_driver(rpi_panel_v2_regulator_driver);
> +
> +MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
> +MODULE_DESCRIPTION("Regulator device driver for Raspberry Pi 7-inch V2 touchscreen");
> +MODULE_LICENSE("GPL");
> --
> 2.47.2

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

* Re: [PATCH 2/2] regulator: rpi-panel-v2: Add regulator for 7" Raspberry Pi 720x1280
  2025-06-09  0:06 ` [PATCH 2/2] regulator: rpi-panel-v2: " Marek Vasut
  2025-06-11  9:55   ` Geert Uytterhoeven
@ 2025-06-11 20:30   ` Uwe Kleine-König
  2025-06-17  0:52     ` Marek Vasut
  1 sibling, 1 reply; 6+ messages in thread
From: Uwe Kleine-König @ 2025-06-11 20:30 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-arm-kernel, Dave Stevenson,
	Broadcom internal kernel review list, Conor Dooley,
	Florian Fainelli, Krzysztof Kozlowski, Liam Girdwood, Mark Brown,
	Rob Herring, devicetree, linux-renesas-soc, linux-rpi-kernel

[-- Attachment #1: Type: text/plain, Size: 2289 bytes --]

Hello Marek,

On Mon, Jun 09, 2025 at 02:06:42AM +0200, Marek Vasut wrote:
> +static int rpi_panel_v2_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> +				  const struct pwm_state *state)
> +{
> +	struct regmap *regmap = pwmchip_get_drvdata(chip);
> +	unsigned int duty;
> +
> +	if (state->polarity != PWM_POLARITY_NORMAL)
> +		return -EINVAL;
> +
> +	if (!state->enabled)
> +		return regmap_write(regmap, REG_PWM, 0);

I would swap these two if blocks to ensure that disable works even if
the wrong polarity is passed.

> +	duty = pwm_get_relative_duty_cycle(state, PWM_BL_MASK);

This is not how it works. I assume this one can only do a single period
length? Then duty should be calculated as:

	duty_cycle = state->duty_cycle > RPI_PANEL_PWM_PERIOD ?  RPI_PANEL_PWM_PERIOD : state->duty_cycle

	duty = duty_cycle * PWM_BL_MASK / RPI_PANEL_PWM_PERIOD;

> +	return regmap_write(regmap, REG_PWM, duty | PWM_BL_ENABLE);
> +}
> +
> +static const struct pwm_ops rpi_panel_v2_pwm_ops = {
> +	.apply = rpi_panel_v2_pwm_apply,
> +};

I would prefer to see new pwm drivers use the waveform stuff.

> +/*
> + * I2C driver interface functions
> + */
> +static int rpi_panel_v2_i2c_probe(struct i2c_client *i2c)
> +{
> +	struct gpio_regmap_config gconfig = {
> +		.ngpio		= NUM_GPIO,
> +		.ngpio_per_reg	= NUM_GPIO,
> +		.parent		= &i2c->dev,
> +		.reg_set_base	= REG_POWERON,
> +	};
> +	struct regmap *regmap;
> +	struct pwm_chip *pc;
> +	int ret;
> +
> +	pc = devm_pwmchip_alloc(&i2c->dev, 1, 0);
> +	if (IS_ERR(pc))
> +		return PTR_ERR(pc);
> +
> +	pc->ops = &rpi_panel_v2_pwm_ops;
> +
> +	regmap = devm_regmap_init_i2c(i2c, &rpi_panel_regmap_config);
> +	if (IS_ERR(regmap))
> +		return dev_err_probe(&i2c->dev, PTR_ERR(regmap), "Failed to allocate regmap\n");
> +
> +	pwmchip_set_drvdata(pc, regmap);
> +
> +	regmap_write(regmap, REG_POWERON, 0);
> +
> +	gconfig.regmap = regmap;
> +	ret = PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&i2c->dev, &gconfig));
> +	if (ret)
> +		return dev_err_probe(&i2c->dev, ret, "Failed to create gpiochip\n");
> +
> +	return devm_pwmchip_add(&i2c->dev, pc);

	ret = devm_pwmchip_add(&i2c->dev, pc);
	if (ret < 0)
		return dev_err_probe(...);

> +}
> 

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 2/2] regulator: rpi-panel-v2: Add regulator for 7" Raspberry Pi 720x1280
  2025-06-11 20:30   ` Uwe Kleine-König
@ 2025-06-17  0:52     ` Marek Vasut
  0 siblings, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2025-06-17  0:52 UTC (permalink / raw)
  To: Uwe Kleine-König, Marek Vasut
  Cc: linux-arm-kernel, Dave Stevenson,
	Broadcom internal kernel review list, Conor Dooley,
	Florian Fainelli, Krzysztof Kozlowski, Liam Girdwood, Mark Brown,
	Rob Herring, devicetree, linux-renesas-soc, linux-rpi-kernel

On 6/11/25 10:30 PM, Uwe Kleine-König wrote:
> Hello Marek,

Hi,

> On Mon, Jun 09, 2025 at 02:06:42AM +0200, Marek Vasut wrote:
>> +static int rpi_panel_v2_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>> +				  const struct pwm_state *state)
>> +{
>> +	struct regmap *regmap = pwmchip_get_drvdata(chip);
>> +	unsigned int duty;
>> +
>> +	if (state->polarity != PWM_POLARITY_NORMAL)
>> +		return -EINVAL;
>> +
>> +	if (!state->enabled)
>> +		return regmap_write(regmap, REG_PWM, 0);
> 
> I would swap these two if blocks to ensure that disable works even if
> the wrong polarity is passed.
I have now sent the conversion to waveform ops patch, so I hope that 
addresses all the topics in this feedback. Thanks!

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

end of thread, other threads:[~2025-06-17  0:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09  0:06 [PATCH 1/2] regulator: dt-bindings: rpi-panel: Add regulator for 7" Raspberry Pi 720x1280 Marek Vasut
2025-06-09  0:06 ` [PATCH 2/2] regulator: rpi-panel-v2: " Marek Vasut
2025-06-11  9:55   ` Geert Uytterhoeven
2025-06-11 20:30   ` Uwe Kleine-König
2025-06-17  0:52     ` Marek Vasut
2025-06-09 15:12 ` [PATCH 1/2] regulator: dt-bindings: rpi-panel: " Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).