Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: tps6105x: add driver for MFD chip LED mode

This driver adds support for the LED operational mode of the
tps6105x MFD device.

Acked-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>

authored by

Sven Van Asbroeck and committed by
Pavel
b3b42b4a b0ff9860

+100
+10
drivers/leds/Kconfig
··· 836 836 Say Y to enable the LM36274 LED driver for TI LMU devices. 837 837 This supports the LED device LM36274. 838 838 839 + config LEDS_TPS6105X 840 + tristate "LED support for TI TPS6105X" 841 + depends on LEDS_CLASS 842 + depends on TPS6105X 843 + default y if TPS6105X 844 + help 845 + This driver supports TPS61050/TPS61052 LED chips. 846 + It is a single boost converter primarily for white LEDs and 847 + audio amplifiers. 848 + 839 849 comment "LED Triggers" 840 850 source "drivers/leds/trigger/Kconfig" 841 851
+1
drivers/leds/Makefile
··· 85 85 obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o 86 86 obj-$(CONFIG_LEDS_LM3697) += leds-lm3697.o 87 87 obj-$(CONFIG_LEDS_LM36274) += leds-lm36274.o 88 + obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o 88 89 89 90 # LED SPI Drivers 90 91 obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o
+89
drivers/leds/leds-tps6105x.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2019 Sven Van Asbroeck 4 + */ 5 + 6 + #include <linux/leds.h> 7 + #include <linux/module.h> 8 + #include <linux/platform_device.h> 9 + #include <linux/mfd/tps6105x.h> 10 + #include <linux/regmap.h> 11 + 12 + struct tps6105x_priv { 13 + struct regmap *regmap; 14 + struct led_classdev cdev; 15 + struct fwnode_handle *fwnode; 16 + }; 17 + 18 + static void tps6105x_handle_put(void *data) 19 + { 20 + struct tps6105x_priv *priv = data; 21 + 22 + fwnode_handle_put(priv->fwnode); 23 + } 24 + 25 + static int tps6105x_brightness_set(struct led_classdev *cdev, 26 + enum led_brightness brightness) 27 + { 28 + struct tps6105x_priv *priv = container_of(cdev, struct tps6105x_priv, 29 + cdev); 30 + 31 + return regmap_update_bits(priv->regmap, TPS6105X_REG_0, 32 + TPS6105X_REG0_TORCHC_MASK, 33 + brightness << TPS6105X_REG0_TORCHC_SHIFT); 34 + } 35 + 36 + static int tps6105x_led_probe(struct platform_device *pdev) 37 + { 38 + struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev); 39 + struct tps6105x_platform_data *pdata = tps6105x->pdata; 40 + struct led_init_data init_data = { }; 41 + struct tps6105x_priv *priv; 42 + int ret; 43 + 44 + /* This instance is not set for torch mode so bail out */ 45 + if (pdata->mode != TPS6105X_MODE_TORCH) { 46 + dev_info(&pdev->dev, 47 + "chip not in torch mode, exit probe"); 48 + return -EINVAL; 49 + } 50 + 51 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 52 + if (!priv) 53 + return -ENOMEM; 54 + /* fwnode/devicetree is optional. NULL is allowed for priv->fwnode */ 55 + priv->fwnode = device_get_next_child_node(pdev->dev.parent, NULL); 56 + ret = devm_add_action_or_reset(&pdev->dev, tps6105x_handle_put, priv); 57 + if (ret) 58 + return ret; 59 + priv->regmap = tps6105x->regmap; 60 + priv->cdev.brightness_set_blocking = tps6105x_brightness_set; 61 + priv->cdev.max_brightness = 7; 62 + init_data.devicename = "tps6105x"; 63 + init_data.default_label = ":torch"; 64 + init_data.fwnode = priv->fwnode; 65 + 66 + ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, 67 + TPS6105X_REG0_MODE_MASK | 68 + TPS6105X_REG0_TORCHC_MASK, 69 + TPS6105X_REG0_MODE_TORCH << 70 + TPS6105X_REG0_MODE_SHIFT); 71 + if (ret) 72 + return ret; 73 + 74 + return devm_led_classdev_register_ext(&pdev->dev, &priv->cdev, 75 + &init_data); 76 + } 77 + 78 + static struct platform_driver led_driver = { 79 + .probe = tps6105x_led_probe, 80 + .driver = { 81 + .name = "tps6105x-leds", 82 + }, 83 + }; 84 + 85 + module_platform_driver(led_driver); 86 + 87 + MODULE_DESCRIPTION("TPS6105x LED driver"); 88 + MODULE_AUTHOR("Sven Van Asbroeck <TheSven73@gmail.com>"); 89 + MODULE_LICENSE("GPL v2");