tps6105x add devicetree and leds support
Subsystems (3)
v3 cover tps6105x add devicetree and leds support
v2 -> v3:
Removed tps6105x regulator patch - it was accepted (Mark Brown).
Removed devicetree/platdata bindings for tps6105x led naming. I can test only with a 4.19 vendor kernel, which does not have the latest led naming infrastructure (function/color). Drop devicetree/ fwnode/pdata led naming in favour of hard-coding to "tps6105x::torch", so the patch can be tested by me, yet remains acceptable to upstream.
v1 -> v2:
Select chip operational mode by looking at subnode name, _not_ its compatible property. Suggested by Mark Brown.
I needed led operation for this mfd chip, so I added a very simple driver for this.
My platform (arm imx6q) is devicetree-based, so I added optional devicetree support for this chip and its sub-drivers.
Sven Van Asbroeck (3):
tps6105x: add optional devicetree support
leds: tps6105x: add driver for mfd chip led mode
dt-bindings: mfd: update TI tps6105x chip bindings
.../devicetree/bindings/mfd/tps6105x.txt | 39 ++++++++++- drivers/leds/Kconfig | 10 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-tps6105x.c | 67 +++++++++++++++++++ drivers/mfd/tps6105x.c | 34 +++++++++- 5 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 drivers/leds/leds-tps6105x.c
Signature · 1 line
2.17.1
PATCH v3 1/3 tps6105x: add optional devicetree support
This driver currently requires platform data to specify the operational mode and regulator init data (in case of regulator mode).
Optionally specify the operational mode by looking at the name of the devicetree child node.
Example: put chip in regulator mode:
i2c0 {
tps61052@33 {
compatible = "ti,tps61052";
reg = <0x33>;
regulator {
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
regulator-always-on;
};
};
};Tree: linux-next
--- drivers/mfd/tps6105x.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
drivers/mfd/tps6105x.c +31 -3
@@ -91,6 +91,32 @@ static int tps6105x_add_device(struct tps6105x *tps6105x, PLATFORM_DEVID_AUTO, cell, 1, NULL, 0, NULL); } +static struct tps6105x_platform_data *tps6105x_parse_dt (struct device *dev) +{ +struct device_node *np = dev->of_node; +struct tps6105x_platform_data *pdata; +struct device_node *child; + +if (!np) +return ERR_PTR (-EINVAL ); +if (of_get_available_child_count (np) >1 ) { +dev_err (dev,"cannot support multiple operational modes" ); +return ERR_PTR (-EINVAL ); + } + pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + pdata->mode =TPS6105X_MODE_SHUTDOWN ; +for_each_available_child_of_node (np, child) { +if (child->name && !of_node_cmp (child->name,"regulator" )) + pdata->mode =TPS6105X_MODE_VOLTAGE ; +else if (child->name && !of_node_cmp (child->name,"led" )) + pdata->mode =TPS6105X_MODE_TORCH ; + } + +return pdata; +} +static int tps6105x_probe (struct i2c_client *client,const struct i2c_device_id *id) {
@@ -99,9 +125,11 @@ static int tps6105x_probe(struct i2c_client *client,int ret; pdata =dev_get_platdata (&client->dev); -if (!pdata) { -dev_err (&client->dev,"missing platform data\n" ); -return -ENODEV ; +if (!pdata) + pdata =tps6105x_parse_dt (&client->dev); +if (IS_ERR (pdata)) { +dev_err (&client->dev,"No platform data or DT found" ); +return PTR_ERR (pdata); } tps6105x =devm_kmalloc (&client->dev,sizeof (*tps6105x),GFP_KERNEL );
Signature · 1 line
2.17.1
PATCH v3 2/3 leds: tps6105x: add driver for mfd chip led mode
In reply to Sven Van AsbroeckThis driver adds support for the led operational mode of the tps6105x mfd device.
Example usage, devicetree:
i2c0 {
tps61052@33 {
compatible = "ti,tps61052";
reg = <0x33>;
led {
};
};
};Tree: next-20191118
--- drivers/leds/Kconfig | 10 ++++++ drivers/leds/Makefile | 1 + drivers/leds/leds-tps6105x.c | 67 ++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 drivers/leds/leds-tps6105x.c
drivers/leds/Kconfig +10 -0
@@ -836,6 +836,16 @@ config LEDS_LM36274 Say Y to enable the LM36274 LED driver for TI LMU devices. This supports the LED device LM36274. +config LEDS_TPS6105X + tristate "LED support for TI TPS6105X" + depends on LEDS_CLASS + depends on TPS6105X + default y if TPS6105X + help + This driver supports TPS61050/TPS61052 led chips. + It is a single boost converter primarily for white LEDs and + audio amplifiers. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig"
drivers/leds/Makefile +1 -0
@@ -85,6 +85,7 @@ obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o obj-$(CONFIG_LEDS_LM3697) += leds-lm3697.o obj-$(CONFIG_LEDS_LM36274) += leds-lm36274.o +obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o # LED SPI Drivers obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o
drivers/leds/leds-tps6105x.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 2/3] leds: tps6105x: add driver for mfd chip led mode
Hi Sven,
Quoted 5 lines · Sven Van Asbroeck
This driver adds support for the led operational mode of the tps6105x mfd device.
Example usage, devicetree:
Quoted 9 lines
i2c0 {
tps61052@33 {
compatible = "ti,tps61052";
reg = <0x33>;
led {
};
};
};This is covered in DT bindings, it is redundant in the commit message.
Quoted 82 lines
Tree: next-20191118
Signed-off-by Sven Van Asbroeck <[email protected]>--- drivers/leds/Kconfig | 10 ++++++ drivers/leds/Makefile | 1 + drivers/leds/leds-tps6105x.c | 67 ++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 drivers/leds/leds-tps6105x.cdrivers/leds/Kconfig +10
-0@@ -836,6 +836,16 @@ config LEDS_LM36274 Say Y to enable the LM36274 LED driver for TI LMU devices. This supports the LED device LM36274. +config LEDS_TPS6105X + tristate "LED support for TI TPS6105X" + depends on LEDS_CLASS + depends on TPS6105X + default y if TPS6105X + help + This driver supports TPS61050/TPS61052 led chips. + It is a single boost converter primarily for white LEDs and + audio amplifiers. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig"drivers/leds/Makefile +1
-0@@ -85,6 +85,7 @@ obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o obj-$(CONFIG_LEDS_LM3697) += leds-lm3697.o obj-$(CONFIG_LEDS_LM36274) += leds-lm36274.o +obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o # LED SPI Drivers obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.odrivers/leds/leds-tps6105x.c new file +33
-0@@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/mfd/tps6105x.h> +#include <linux/regmap.h> + +struct tps6105x_priv { +struct regmap *regmap; +struct led_classdev cdev; +}; + +static int tps6105x_brightness_set (struct led_classdev *cdev, +enum led_brightness brightness) +{ + struct tps6105x_priv *priv = container_of(cdev, struct tps6105x_priv, + cdev); + +return regmap_update_bits (priv->regmap,TPS6105X_REG_0 , +TPS6105X_REG0_TORCHC_MASK , + brightness <<TPS6105X_REG0_TORCHC_SHIFT ); +} + +static int tps6105x_led_probe (struct platform_device *pdev) +{ +struct tps6105x *tps6105x =dev_get_platdata (&pdev->dev); +struct tps6105x_platform_data *pdata = tps6105x->pdata; +struct tps6105x_priv *priv; +int ret; + +/* This instance is not set for torch mode so bail out */ +if (pdata->mode !=TPS6105X_MODE_TORCH ) {
drivers/leds/leds-tps6105x.c line 43
Quoted 10 lines
drivers/leds/leds-tps6105x.c new file +10
-0+dev_info (&pdev->dev, +"chip not in torch mode, exit probe" ); +return -EINVAL ; + } + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->regmap = tps6105x->regmap; + priv->cdev.name ="tps6105x::torch" ;
Please remove above line.
drivers/leds/leds-tps6105x.c line 51
Quoted 9 lines
drivers/leds/leds-tps6105x.c new file +8
-0+ priv->cdev.brightness_set_blocking = tps6105x_brightness_set; + priv->cdev.max_brightness =7 ; + + ret =regmap_update_bits (tps6105x->regmap,TPS6105X_REG_0 , +TPS6105X_REG0_MODE_MASK |TPS6105X_REG0_TORCHC_MASK , +TPS6105X_REG0_MODE_TORCH <<TPS6105X_REG0_MODE_SHIFT ); +if (ret) +return ret;
And use new LED registration API like below:
struct led_init_data init_data = {
.devicename = "tps6105x",
.default_label = ":torch" };return devm_led_classdev_register_ext(&pdev->dev, &priv->cdev, &init_data);
This way you will make the driver capable of using LED core mechanism for composing LED names, which will allow to use function and color properties in DT, and automatically override the defaults from the driver. If both properties are missing in DT, then you will get the LED named tps6105x::torch.
Quoted 16 lines
drivers/leds/leds-tps6105x.c new file +15
-0+return devm_led_classdev_register (&pdev->dev, &priv->cdev); +} + +static struct platform_driver led_driver = { + .probe = tps6105x_led_probe, + .driver = { + .name ="tps6105x-leds" , + }, +}; + +module_platform_driver (led_driver); + +MODULE_DESCRIPTION ("TPS6105x led driver" ); +MODULE_AUTHOR ("Sven Van Asbroeck <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH v3 2/3] leds: tps6105x: add driver for mfd chip led mode
Hi Jacek,
Quoted 1 line · Jacek Anaszewski
This is covered in DT bindings, it is redundant in the commit message.
Ok, I will remove it from the commit message.
Quoted 11 lines
Quoted 1 line
+
priv->cdev.name= "tps6105x::torch";Please remove above line.
And use new LED registration API like below:
struct led_init_data init_data = { .devicename = "tps6105x", .default_label = ":torch" };return
devm_led_classdev_register_ext(&pdev->dev, &priv->cdev, &init_data);
I would love to do that, but my platform (with a tps6105x) can only boot a lts vendor kernel (4.14). classdev_register_ext() is not available there.
I can make the change you suggest, but cannot test to check if it will actually work. Is that ok for you?
Re: [PATCH v3 2/3] leds: tps6105x: add driver for mfd chip led mode
Quoted 18 lines · Sven Van Asbroeck
Hi Jacek,
Quoted 1 line · Jacek Anaszewski
This is covered in DT bindings, it is redundant in the commit message.
Ok, I will remove it from the commit message.
Quoted 10 lines
Quoted 1 line
+
priv->cdev.name= "tps6105x::torch";Please remove above line.
And use new LED registration API like below:
struct led_init_data init_data = { .devicename = "tps6105x", .default_label = ":torch" };
Quoted 7 lines
Quoted 1 line
return
devm_led_classdev_register_ext(&pdev->dev, &priv->cdev, &init_data);I would love to do that, but my platform (with a tps6105x) can only boot a lts vendor kernel (4.14).
classdev_register_ext()is not available there.I can make the change you suggest, but cannot test to check if it will actually work. Is that ok for you?
Can't you backport also the LED core patches with *ext API?
Signature · 2 lines
Best regards, Jacek Anaszewski
PATCH v3 3/3 dt-bindings: mfd: update TI tps6105x chip bindings
In reply to Sven Van AsbroeckThe driver has been extended to optionally get its operational mode, regulator init data and led label from the devicetree.
Tree: next-20191118
--- .../devicetree/bindings/mfd/tps6105x.txt | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mfd/tps6105x.txt +38 -1
@@ -7,11 +7,48 @@ Required properties: - compatible: "ti,tps61050" or "ti,tps61052" - reg: Specifies the I2C slave address -Example: +Optional sub-node: + +This subnode selects the chip's operational mode. +There can be at most one single available subnode. + +- regulator: presence of this sub-node puts the chip in regulator mode. + see Documentation/devicetree/bindings/regulator/regulator.txt + +- led: presence of this sub-node puts the chip in led mode. + +Example (GPIO operation only): + +i2c0 { + tps61052@33 { + compatible = "ti,tps61052"; + reg = <0x33>; + }; +}; + +Example (GPIO + regulator operation): i2c0 { tps61052@33 { compatible = "ti,tps61052"; reg = <0x33>; + + regulator { + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + regulator-always-on; + }; + }; +}; + +Example (GPIO + led operation): + +i2c0 { + tps61052@33 { + compatible = "ti,tps61052"; + reg = <0x33>; + + led { + }; }; };
Signature · 1 line
2.17.1