linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/6] ARM: dts: omap2420-n810: Add Tahvo/Betty LEDPWM and Vcore bindings
@ 2021-12-24 21:56 peter.vasil
  2021-12-24 21:56 ` [PATCH 4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output peter.vasil
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: peter.vasil @ 2021-12-24 21:56 UTC (permalink / raw)
  To: linux-omap; +Cc: peter.vasil

From: Peter Vasil <peter.vasil@gmail.com>

Nokia Tahvo/Betty ASIC provides PWM output for LED control and voltage
regulator for adjustable Vcore output.
These are both used on N8x0 devices for display control; LEDPWM for
backlight and Vcore for framebuffer IC power.
---
 arch/arm/boot/dts/omap2420-n810.dts         | 13 +++++++++++++
 arch/arm/boot/dts/omap2420-n8x0-common.dtsi |  8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/omap2420-n810.dts b/arch/arm/boot/dts/omap2420-n810.dts
index 09c1dbc0bb69..30f9f9e1a377 100644
--- a/arch/arm/boot/dts/omap2420-n810.dts
+++ b/arch/arm/boot/dts/omap2420-n810.dts
@@ -22,6 +22,19 @@ v28_aic: v28_aic {
 	};
 };
 
+&tahvo {
+	tahvo_ledpwm: tahvo_ledpwm {
+		compatible = "nokia,tahvo-ledpwm";
+	};
+	tahvo_vcore: tahvo_vcore {
+		compatible = "nokia,tahvo-vcore-regulator";
+		regulator-name = "tornado_vcore";
+		regulator-min-microvolt = <1005000>;
+		regulator-max-microvolt = <1475000>;
+		regulator-always-on;
+	};
+};
+
 &omap2420_pmx {
 	mcbsp2_pins: mcbsp2_pins {
 		pinctrl-single,pins = <
diff --git a/arch/arm/boot/dts/omap2420-n8x0-common.dtsi b/arch/arm/boot/dts/omap2420-n8x0-common.dtsi
index 63b0b4921e4e..88d44f5a5f63 100644
--- a/arch/arm/boot/dts/omap2420-n8x0-common.dtsi
+++ b/arch/arm/boot/dts/omap2420-n8x0-common.dtsi
@@ -22,9 +22,15 @@ &gpio3 0 GPIO_ACTIVE_HIGH /* gpio64 sel */
 			#size-cells = <0>;
 			retu: retu@1 {
 				compatible = "nokia,retu";
+				reg = <0x1>;
 				interrupt-parent = <&gpio4>;
 				interrupts = <12 IRQ_TYPE_EDGE_RISING>;
-				reg = <0x1>;
+			};
+			tahvo: tahvo@2 {
+				compatible = "nokia,tahvo";
+				reg = <0x2>;
+				interrupt-parent = <&gpio4>;
+				interrupts = <15 IRQ_TYPE_EDGE_RISING>;
 			};
 		};
 	};
-- 
2.25.1


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

* [PATCH 4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output
  2021-12-24 21:56 [PATCH 3/6] ARM: dts: omap2420-n810: Add Tahvo/Betty LEDPWM and Vcore bindings peter.vasil
@ 2021-12-24 21:56 ` peter.vasil
  2022-02-03  7:13   ` Tony Lindgren
  2021-12-24 21:56 ` [PATCH 5/6] regulator: tahvo-vcore: Add basic Tahvo/Betty ASIC Vcore output support peter.vasil
  2021-12-24 21:56 ` [PATCH 6/6] mfd: retu: Add support for LEDPWM and Vcore regulator MFD cells peter.vasil
  2 siblings, 1 reply; 5+ messages in thread
From: peter.vasil @ 2021-12-24 21:56 UTC (permalink / raw)
  To: linux-omap; +Cc: peter.vasil

From: Peter Vasil <peter.vasil@gmail.com>

Nokia Tahvo/Betty ASIC is a companion chip for mobile devices. One of
its outputs is a 127-levels PWM, usually used for LED or backlight
control.
Register control code has been written based on original Nokia kernel
sources for N810 display driver.
Driver expects a regmap device as parent, usually retu-mfd driver bound
to the Tahvo ASIC.
---
 drivers/leds/Kconfig      | 12 ++++++
 drivers/leds/Makefile     |  1 +
 drivers/leds/leds-tahvo.c | 85 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 drivers/leds/leds-tahvo.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index ed800f5da7d8..010d455a2151 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -871,6 +871,18 @@ config LEDS_ACER_A500
 	  This option enables support for the Power Button LED of
 	  Acer Iconia Tab A500.
 
+config LEDS_TAHVO
+	tristate "Tahvo PWM led support"
+	depends on LEDS_CLASS && MFD_RETU
+	help
+	  Tahvo PWM LED driver for Nokia Internet Tablets (770, N800,
+	  N810). At least on N810 the LCD backlight is controlled by
+	  Tahvo/Betty MFD.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called leds-tahvo.
+
+
 source "drivers/leds/blink/Kconfig"
 
 comment "Flash and Torch LED drivers"
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index c636ec069612..30832d3bc947 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_LEDS_TURRIS_OMNIA)		+= leds-turris-omnia.o
 obj-$(CONFIG_LEDS_WM831X_STATUS)	+= leds-wm831x-status.o
 obj-$(CONFIG_LEDS_WM8350)		+= leds-wm8350.o
 obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
+obj-$(CONFIG_LEDS_TAHVO)		+= leds-tahvo.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_CR0014114)		+= leds-cr0014114.o
diff --git a/drivers/leds/leds-tahvo.c b/drivers/leds/leds-tahvo.c
new file mode 100644
index 000000000000..53feb0749e76
--- /dev/null
+++ b/drivers/leds/leds-tahvo.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tahvo LED PWM driver
+ *
+ * Copyright (C) 2004, 2005 Nokia Corporation
+ *
+ * Based on original 2.6 kernel driver for Nokia N8x0 LCD panel.
+ * Rewritten by Peter Vasil.
+ */
+
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+
+#define TAHVO_REG_LEDPWM 0x05
+
+/* Maximum power/brightness value */
+#define TAHVO_LEDPWM_MAX 127
+
+struct tahvo_led {
+	struct led_classdev cdev;
+	struct regmap *regmap;
+};
+
+static int tahvo_led_brightness_set(struct led_classdev *cdev,
+				    enum led_brightness brightness)
+{
+	struct tahvo_led *led = container_of(cdev, struct tahvo_led, cdev);
+
+	return regmap_write(led->regmap, TAHVO_REG_LEDPWM, brightness);
+}
+
+static int tahvo_led_probe(struct platform_device *pdev)
+{
+	struct tahvo_led *led;
+	struct led_init_data init_data;
+	int ret;
+
+	led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
+	if (!led)
+		return -ENOMEM;
+
+	if (pdev->dev.of_node && pdev->dev.of_node->name) {
+		led->cdev.name = pdev->dev.of_node->name;
+	} else {
+		dev_warn(&pdev->dev, "No OF node found, using default name!\n");
+		led->cdev.name = "tahvo:led";
+	}
+
+	led->cdev.max_brightness = TAHVO_LEDPWM_MAX;
+	led->cdev.brightness_set_blocking = tahvo_led_brightness_set;
+
+	led->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+
+	init_data.fwnode = of_fwnode_handle(pdev->dev.of_node);
+
+	ret = devm_led_classdev_register_ext(&pdev->dev, &led->cdev, &init_data);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register PWM LED (%d)\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id of_tahvo_leds_match[] = {
+	{ .compatible = "nokia,tahvo-ledpwm", },
+	{},
+};
+
+static struct platform_driver tahvo_led_driver = {
+	.probe		= tahvo_led_probe,
+	.driver		= {
+		.name	= "tahvo-ledpwm",
+		.of_match_table = of_match_ptr(of_tahvo_leds_match),
+	},
+};
+module_platform_driver(tahvo_led_driver);
+
+MODULE_ALIAS("platform:tahvo-ledpwm");
+MODULE_DESCRIPTION("Tahvo LED PWM");
+MODULE_AUTHOR("Peter Vasil <peter.vasil@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.25.1


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

* [PATCH 5/6] regulator: tahvo-vcore: Add basic Tahvo/Betty ASIC Vcore output support
  2021-12-24 21:56 [PATCH 3/6] ARM: dts: omap2420-n810: Add Tahvo/Betty LEDPWM and Vcore bindings peter.vasil
  2021-12-24 21:56 ` [PATCH 4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output peter.vasil
@ 2021-12-24 21:56 ` peter.vasil
  2021-12-24 21:56 ` [PATCH 6/6] mfd: retu: Add support for LEDPWM and Vcore regulator MFD cells peter.vasil
  2 siblings, 0 replies; 5+ messages in thread
From: peter.vasil @ 2021-12-24 21:56 UTC (permalink / raw)
  To: linux-omap; +Cc: peter.vasil

From: Peter Vasil <peter.vasil@gmail.com>

Nokia Tahvo/Betty ASIC is a companion chip for mobile devices. One of
its outputs is a Vcore adjustable voltage regulator.
Register control code has been written based on original Nokia kernel
sources for N810 display driver.
Driver expects a regmap device as parent, usually retu-mfd driver bound
to the Tahvo ASIC.
---
 drivers/regulator/Kconfig                 |   8 ++
 drivers/regulator/Makefile                |   1 +
 drivers/regulator/tahvo-vcore-regulator.c | 104 ++++++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 drivers/regulator/tahvo-vcore-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 6be9b1c8a615..16c684c742cf 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -1404,6 +1404,14 @@ config REGULATOR_WM8994
 	  This driver provides support for the voltage regulators on the
 	  WM8994 CODEC.
 
+config REGULATOR_TAHVO_VCORE
+	tristate "Tahvo/Betty Vcore regulator support"
+	depends on MFD_RETU
+	help
+	  This driver supports Vcore voltage control on Nokia's Tahvo/Betty
+	  ASIC chip. The regulator controls framebuffer supply voltage in
+	  Nokia internet tablets (for sure at least N810).
+
 config REGULATOR_QCOM_LABIBB
 	tristate "QCOM LAB/IBB regulator support"
 	depends on SPMI || COMPILE_TEST
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index b07d2a22df0b..ed64d2cf8a42 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -170,5 +170,6 @@ obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
 obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
 obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
 obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o
+obj-$(CONFIG_REGULATOR_TAHVO_VCORE) += tahvo-vcore-regulator.o
 
 ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/tahvo-vcore-regulator.c b/drivers/regulator/tahvo-vcore-regulator.c
new file mode 100644
index 000000000000..a7c92aa7a148
--- /dev/null
+++ b/drivers/regulator/tahvo-vcore-regulator.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Copyright (C) 2004, 2005 Nokia Corporation
+//
+// Based on original 2.6 kernel driver for Nokia N8x0 LCD panel.
+// Rewritten in 2021 by Peter Vasil <petervasil@gmail.com>.
+//
+// Driver for Nokia Betty/Tahvo Vcore regulator
+// The only known voltages are currently 1.005V==0x0f and 1.475V==0x00 with mask 0x0f
+// Whether the sequence is actually linear is only a guess.
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+
+#define TAHVO_REG_VCORE		0x07
+
+// Values in this table are simply interpolated from the only known min/max.
+static const unsigned int tahvo_vcore_voltages[] = {
+	1475000, 1443667, 1412333, 1381000, 1349667, 1318333, 1287000, 1255667,
+	1224333, 1193000, 1161667, 1130333, 1099000, 1067667, 1036333, 1005000,
+};
+
+static const struct regulator_ops tahvo_vcore_regulator_voltage_ops = {
+	.list_voltage = regulator_list_voltage_table,
+	.map_voltage = regulator_map_voltage_iterate,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+};
+
+static const struct regulator_desc vcore_regulator = {
+	.name		= "vcore",
+	.ops		= &tahvo_vcore_regulator_voltage_ops,
+	.type		= REGULATOR_VOLTAGE,
+	.owner		= THIS_MODULE,
+	.volt_table	= tahvo_vcore_voltages,
+	.n_voltages	= ARRAY_SIZE(tahvo_vcore_voltages),
+	.vsel_reg	= TAHVO_REG_VCORE,
+	.vsel_mask	= 0x0f,
+};
+
+static const struct regmap_config tahvo_vcore_regmap_config = {
+	.reg_bits	= 8,
+	.reg_stride	= 1,
+	.val_bits	= 16,
+};
+
+static int tahvo_vcore_regulator_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct regulator_init_data *init_data;
+	struct regulator_config cfg = {};
+	struct regulator_dev *rdev;
+
+	init_data = of_get_regulator_init_data(dev, dev->of_node,
+					       &vcore_regulator);
+	if (!init_data) {
+		dev_err(dev, "Failed to init regulator data!\n");
+		return -EINVAL;
+	}
+
+	cfg.dev = dev;
+	cfg.init_data = init_data;
+	cfg.of_node = dev->of_node;
+
+	cfg.regmap = dev_get_regmap(dev->parent, NULL);
+	if (!cfg.regmap) {
+		dev_err(dev, "failed to locate regmap\n");
+		return -ENODEV;
+	}
+
+	rdev = devm_regulator_register(dev, &vcore_regulator, &cfg);
+	if (IS_ERR(rdev)) {
+		dev_err(dev, "Failed to register regulator: %ld\n",
+			PTR_ERR(rdev));
+		return PTR_ERR(rdev);
+	}
+	platform_set_drvdata(pdev, rdev);
+
+	return 0;
+}
+
+static const struct of_device_id regulator_tahvo_vcore_of_match[] = {
+	{ .compatible = "nokia,tahvo-vcore-regulator", },
+	{},
+};
+
+static struct platform_driver tahvo_vcore_regulator_driver = {
+	.probe = tahvo_vcore_regulator_probe,
+	.driver = {
+		.name = "tahvo-vcore-regulator",
+		.of_match_table = of_match_ptr(regulator_tahvo_vcore_of_match),
+	},
+};
+module_platform_driver(tahvo_vcore_regulator_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Peter Vasil <petervasil@gmail.com>");
+MODULE_DESCRIPTION("Tahvo/Betty Vcore voltage regulator");
-- 
2.25.1


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

* [PATCH 6/6] mfd: retu: Add support for LEDPWM and Vcore regulator MFD cells
  2021-12-24 21:56 [PATCH 3/6] ARM: dts: omap2420-n810: Add Tahvo/Betty LEDPWM and Vcore bindings peter.vasil
  2021-12-24 21:56 ` [PATCH 4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output peter.vasil
  2021-12-24 21:56 ` [PATCH 5/6] regulator: tahvo-vcore: Add basic Tahvo/Betty ASIC Vcore output support peter.vasil
@ 2021-12-24 21:56 ` peter.vasil
  2 siblings, 0 replies; 5+ messages in thread
From: peter.vasil @ 2021-12-24 21:56 UTC (permalink / raw)
  To: linux-omap; +Cc: peter.vasil

From: Peter Vasil <peter.vasil@gmail.com>

Add MFD cells for new Tahvo ASIC LEDPWM and Vcore regulator drivers.
---
 drivers/mfd/retu-mfd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/mfd/retu-mfd.c b/drivers/mfd/retu-mfd.c
index c748fd29a220..3a4f3c64ae72 100644
--- a/drivers/mfd/retu-mfd.c
+++ b/drivers/mfd/retu-mfd.c
@@ -99,6 +99,14 @@ static const struct mfd_cell tahvo_devs[] = {
 		.resources	= tahvo_usb_res,
 		.num_resources	= ARRAY_SIZE(tahvo_usb_res),
 	},
+	{
+		.name		= "tahvo-ledpwm",
+		.of_compatible	= "nokia,tahvo-ledpwm"
+	},
+	{
+		.name		= "tahvo-vcore-regulator",
+		.of_compatible	= "nokia,tahvo-vcore-regulator"
+	},
 };
 
 static struct regmap_irq tahvo_irqs[] = {
-- 
2.25.1


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

* Re: [PATCH 4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output
  2021-12-24 21:56 ` [PATCH 4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output peter.vasil
@ 2022-02-03  7:13   ` Tony Lindgren
  0 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2022-02-03  7:13 UTC (permalink / raw)
  To: peter.vasil; +Cc: linux-omap

* peter.vasil@gmail.com <peter.vasil@gmail.com> [211224 21:58]:
> From: Peter Vasil <peter.vasil@gmail.com>
> 
> Nokia Tahvo/Betty ASIC is a companion chip for mobile devices. One of
> its outputs is a 127-levels PWM, usually used for LED or backlight
> control.
> Register control code has been written based on original Nokia kernel
> sources for N810 display driver.
> Driver expects a regmap device as parent, usually retu-mfd driver bound
> to the Tahvo ASIC.

The drivers should be sent to the driver maintainers as separate
patches as listed in the MAINTAINERS file. Seems once you have the
bindings can be merged separately to the subsystem trees. And at that
point I can also pick up the dts patch.

Regards,

Tony

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

end of thread, other threads:[~2022-02-03  7:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-24 21:56 [PATCH 3/6] ARM: dts: omap2420-n810: Add Tahvo/Betty LEDPWM and Vcore bindings peter.vasil
2021-12-24 21:56 ` [PATCH 4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output peter.vasil
2022-02-03  7:13   ` Tony Lindgren
2021-12-24 21:56 ` [PATCH 5/6] regulator: tahvo-vcore: Add basic Tahvo/Betty ASIC Vcore output support peter.vasil
2021-12-24 21:56 ` [PATCH 6/6] mfd: retu: Add support for LEDPWM and Vcore regulator MFD cells peter.vasil

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).