diff mbox series

[4/6] leds: tahvo: Driver for Tahvo/Betty ASIC LEDPWM output

Message ID 20211224215635.1585808-4-peter.vasil@gmail.com
State New
Headers show
Series None | expand

Commit Message

peter.vasil@gmail.com Dec. 24, 2021, 9:56 p.m. UTC
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

Comments

Tony Lindgren Feb. 3, 2022, 7:13 a.m. UTC | #1
* 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
diff mbox series

Patch

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");