mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
Merge tag 'leds-next-6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds
Pull LED updates from Lee Jones: - Allow struct bin_attribute instances to be placed in read-only memory for enhanced protection - Fix a memory leak in the cht-wcove driver by using devm_led_classdev_register() - Fix an OF node reference leak in the netxbig driver - Ensure PWM is disabled properly in pwm-multicolor suspend - Add support for Texas Instruments LP8864, LP8864S, LP8866 LED-backlight drivers - Add support for STMicroelectronics's LED1202 12-channel LED driver - Convert LP8860 bindings to YAML format - Add bindings for the TI LP8864/LP8866 LED drivers - Add LED1202 LED controller bindings - Fix path to color definitions in leds-class-multicolor.yaml - Add pm660l compatible to qcom,spmi-flash-led bindings - Extend cznic,turris-omnia-leds binding with interrupts property - Add documentation for the STMicroelectronics LED1202 driver - Add entry for AAEON UP board FPGA drivers in MAINTAINERS - Fix a wrong format specifier in the ledtrig-activity driver - Fix a bug in the lp8860 driver where only half of the EEPROM was written * tag 'leds-next-6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds: (28 commits) leds: triggers: Constify 'struct bin_attribute' leds: cht-wcove: Use devm_led_classdev_register() to avoid memory leak leds: lp8864: Add support for Texas Instruments LP8864, LP8864S, LP8866 LED-backlights dt-bindings: leds: Convert LP8860 into YAML format leds: Add LED1202 I2C driver dt-bindings: leds: Add LED1202 LED Controller Documentation:leds: Add leds-st1202.rst leds: pwm-multicolor: Disable PWM when going to suspend leds: netxbig: Fix an OF node reference leak in netxbig_leds_get_of_pdata() turris-omnia-mcu-interface.h: Move macro definitions outside of enums MAINTAINERS: Add entry for AAEON UP board FPGA drivers leds: Add AAEON UP board LED driver leds: trigger: netdev: Check offload ability on interface up leds: turris-omnia: Use uppercase first letter in all comments leds: turris-omnia: Use dev_err_probe() where appropriate leds: turris-omnia: Inform about missing LED gamma correction feature in the MCU driver platform: cznic: turris-omnia-mcu: Inform about missing LED panel brightness change interrupt feature leds: turris-omnia: Notify sysfs on MCU global LEDs brightness change leds: turris-omnia: Document driver private structures dt-bindings: leds: cznic,turris-omnia-leds: Allow interrupts property ...
This commit is contained in:
@@ -23,6 +23,12 @@ properties:
|
||||
description: I2C slave address of the microcontroller.
|
||||
maxItems: 1
|
||||
|
||||
interrupts:
|
||||
description:
|
||||
Specifier for the global LED brightness changed by front button press
|
||||
interrupt.
|
||||
maxItems: 1
|
||||
|
||||
"#address-cells":
|
||||
const: 1
|
||||
|
||||
@@ -56,6 +62,7 @@ additionalProperties: false
|
||||
examples:
|
||||
- |
|
||||
|
||||
#include <dt-bindings/interrupt-controller/irq.h>
|
||||
#include <dt-bindings/leds/common.h>
|
||||
|
||||
i2c {
|
||||
@@ -65,6 +72,7 @@ examples:
|
||||
led-controller@2b {
|
||||
compatible = "cznic,turris-omnia-leds";
|
||||
reg = <0x2b>;
|
||||
interrupts-extended = <&mcu 11 IRQ_TYPE_NONE>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ properties:
|
||||
description: |
|
||||
For multicolor LED support this property should be defined as either
|
||||
LED_COLOR_ID_RGB or LED_COLOR_ID_MULTI which can be found in
|
||||
include/linux/leds/common.h.
|
||||
include/dt-bindings/leds/common.h.
|
||||
enum: [ 8, 9 ]
|
||||
|
||||
required:
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
* Texas Instruments - lp8860 4-Channel LED Driver
|
||||
|
||||
The LP8860-Q1 is an high-efficiency LED
|
||||
driver with boost controller. It has 4 high-precision
|
||||
current sinks that can be controlled by a PWM input
|
||||
signal, a SPI/I2C master, or both.
|
||||
|
||||
Required properties:
|
||||
- compatible :
|
||||
"ti,lp8860"
|
||||
- reg : I2C slave address
|
||||
- #address-cells : 1
|
||||
- #size-cells : 0
|
||||
|
||||
Optional properties:
|
||||
- enable-gpios : gpio pin to enable (active high)/disable the device.
|
||||
- vled-supply : LED supply
|
||||
|
||||
Required child properties:
|
||||
- reg : 0
|
||||
|
||||
Optional child properties:
|
||||
- function : see Documentation/devicetree/bindings/leds/common.txt
|
||||
- color : see Documentation/devicetree/bindings/leds/common.txt
|
||||
- label : see Documentation/devicetree/bindings/leds/common.txt (deprecated)
|
||||
- linux,default-trigger :
|
||||
see Documentation/devicetree/bindings/leds/common.txt
|
||||
|
||||
Example:
|
||||
|
||||
#include <dt-bindings/leds/common.h>
|
||||
|
||||
led-controller@2d {
|
||||
compatible = "ti,lp8860";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
reg = <0x2d>;
|
||||
enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>;
|
||||
vled-supply = <&vbatt>;
|
||||
|
||||
led@0 {
|
||||
reg = <0>;
|
||||
function = LED_FUNCTION_BACKLIGHT;
|
||||
color = <LED_COLOR_ID_WHITE>;
|
||||
linux,default-trigger = "backlight";
|
||||
};
|
||||
}
|
||||
|
||||
For more product information please see the link below:
|
||||
https://www.ti.com/product/lp8860-q1
|
||||
@@ -23,6 +23,7 @@ properties:
|
||||
items:
|
||||
- enum:
|
||||
- qcom,pm6150l-flash-led
|
||||
- qcom,pm660l-flash-led
|
||||
- qcom,pm8150c-flash-led
|
||||
- qcom,pm8150l-flash-led
|
||||
- qcom,pm8350c-flash-led
|
||||
|
||||
90
Documentation/devicetree/bindings/leds/ti,lp8860.yaml
Normal file
90
Documentation/devicetree/bindings/leds/ti,lp8860.yaml
Normal file
@@ -0,0 +1,90 @@
|
||||
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
|
||||
%YAML 1.2
|
||||
---
|
||||
$id: http://devicetree.org/schemas/leds/ti,lp8860.yaml#
|
||||
$schema: http://devicetree.org/meta-schemas/core.yaml#
|
||||
|
||||
title: Texas Instruments - lp8860 4-Channel LED Driver
|
||||
|
||||
maintainers:
|
||||
- Andrew Davis <afd@ti.com>
|
||||
|
||||
description: |
|
||||
The LP8860-Q1 is an high-efficiency LED driver with boost controller.
|
||||
It has 4 high-precision current sinks that can be controlled by a PWM input
|
||||
signal, a SPI/I2C master, or both.
|
||||
|
||||
For more product information please see the link below:
|
||||
https://www.ti.com/product/lp8860-q1
|
||||
|
||||
properties:
|
||||
compatible:
|
||||
const: ti,lp8860
|
||||
|
||||
reg:
|
||||
maxItems: 1
|
||||
description: I2C slave address
|
||||
|
||||
"#address-cells":
|
||||
const: 1
|
||||
|
||||
"#size-cells":
|
||||
const: 0
|
||||
|
||||
enable-gpios:
|
||||
maxItems: 1
|
||||
description: GPIO pin to enable (active high) / disable the device
|
||||
|
||||
vled-supply:
|
||||
description: LED supply
|
||||
|
||||
patternProperties:
|
||||
"^led(@[0-3])?$":
|
||||
type: object
|
||||
$ref: common.yaml#
|
||||
unevaluatedProperties: false
|
||||
|
||||
properties:
|
||||
reg:
|
||||
description:
|
||||
Index of the LED.
|
||||
maxItems: 1
|
||||
|
||||
function: true
|
||||
color: true
|
||||
label: true
|
||||
linux,default-trigger: true
|
||||
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
|
||||
additionalProperties: false
|
||||
|
||||
examples:
|
||||
- |
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
#include <dt-bindings/leds/common.h>
|
||||
|
||||
i2c {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
led-controller@2d {
|
||||
compatible = "ti,lp8860";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
reg = <0x2d>;
|
||||
enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>;
|
||||
vled-supply = <&vbatt>;
|
||||
|
||||
led@0 {
|
||||
reg = <0>;
|
||||
function = LED_FUNCTION_BACKLIGHT;
|
||||
color = <LED_COLOR_ID_WHITE>;
|
||||
linux,default-trigger = "backlight";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
...
|
||||
15
MAINTAINERS
15
MAINTAINERS
@@ -185,6 +185,14 @@ W: http://www.adaptec.com/
|
||||
F: Documentation/scsi/aacraid.rst
|
||||
F: drivers/scsi/aacraid/
|
||||
|
||||
AAEON UPBOARD FPGA MFD DRIVER
|
||||
M: Thomas Richard <thomas.richard@bootlin.com>
|
||||
S: Maintained
|
||||
F: drivers/leds/leds-upboard.c
|
||||
F: drivers/mfd/upboard-fpga.c
|
||||
F: drivers/pinctrl/pinctrl-upboard.c
|
||||
F: include/linux/mfd/upboard-fpga.h
|
||||
|
||||
AB8500 BATTERY AND CHARGER DRIVERS
|
||||
M: Linus Walleij <linus.walleij@linaro.org>
|
||||
F: Documentation/devicetree/bindings/power/supply/*ab8500*
|
||||
@@ -23293,6 +23301,13 @@ S: Supported
|
||||
F: Documentation/devicetree/bindings/iio/dac/ti,dac7612.yaml
|
||||
F: drivers/iio/dac/ti-dac7612.c
|
||||
|
||||
TEXAS INSTRUMENTS' LB8864 LED BACKLIGHT DRIVER
|
||||
M: Alexander Sverdlin <alexander.sverdlin@siemens.com>
|
||||
L: linux-leds@vger.kernel.org
|
||||
S: Maintained
|
||||
F: Documentation/devicetree/bindings/leds/backlight/ti,lp8864.yaml
|
||||
F: drivers/leds/leds-lp8864.c
|
||||
|
||||
TEXAS INSTRUMENTS' SYSTEM CONTROL INTERFACE (TISCI) PROTOCOL DRIVER
|
||||
M: Nishanth Menon <nm@ti.com>
|
||||
M: Tero Kristo <kristo@kernel.org>
|
||||
|
||||
@@ -217,6 +217,8 @@ config LEDS_TURRIS_OMNIA
|
||||
depends on I2C
|
||||
depends on MACH_ARMADA_38X || COMPILE_TEST
|
||||
depends on OF
|
||||
depends on TURRIS_OMNIA_MCU
|
||||
depends on TURRIS_OMNIA_MCU_GPIO
|
||||
select LEDS_TRIGGERS
|
||||
help
|
||||
This option enables basic support for the LEDs found on the front
|
||||
@@ -511,6 +513,18 @@ config LEDS_LP8860
|
||||
on the LP8860 4 channel LED driver using the I2C communication
|
||||
bus.
|
||||
|
||||
config LEDS_LP8864
|
||||
tristate "LED support for the TI LP8864/LP8866 4/6 channel LED drivers"
|
||||
depends on LEDS_CLASS && I2C && OF
|
||||
select REGMAP_I2C
|
||||
help
|
||||
If you say yes here you get support for the TI LP8864-Q1,
|
||||
LP8864S-Q1, LP8866-Q1, LP8866S-Q1 4/6 channel LED backlight
|
||||
drivers with I2C interface.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called leds-lp8864.
|
||||
|
||||
config LEDS_CLEVO_MAIL
|
||||
tristate "Mail LED on Clevo notebook"
|
||||
depends on LEDS_CLASS && BROKEN
|
||||
@@ -826,6 +840,15 @@ config LEDS_SC27XX_BLTC
|
||||
This driver can also be built as a module. If so the module will be
|
||||
called leds-sc27xx-bltc.
|
||||
|
||||
config LEDS_UPBOARD
|
||||
tristate "LED support for the UP board"
|
||||
depends on LEDS_CLASS && MFD_UPBOARD_FPGA
|
||||
help
|
||||
This option enables support for the UP board LEDs.
|
||||
|
||||
This driver can also be built as a module. If so the module will be
|
||||
called leds-upboard.
|
||||
|
||||
comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
|
||||
|
||||
config LEDS_BLINKM
|
||||
|
||||
@@ -57,6 +57,7 @@ obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o
|
||||
obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o
|
||||
obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o
|
||||
obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o
|
||||
obj-$(CONFIG_LEDS_LP8864) += leds-lp8864.o
|
||||
obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o
|
||||
obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o
|
||||
obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o
|
||||
@@ -82,6 +83,7 @@ obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
|
||||
obj-$(CONFIG_LEDS_QNAP_MCU) += leds-qnap-mcu.o
|
||||
obj-$(CONFIG_LEDS_REGULATOR) += leds-regulator.o
|
||||
obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o
|
||||
obj-$(CONFIG_LEDS_ST1202) += leds-st1202.o
|
||||
obj-$(CONFIG_LEDS_SUN50I_A100) += leds-sun50i-a100.o
|
||||
obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o
|
||||
obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o
|
||||
@@ -90,6 +92,7 @@ obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o
|
||||
obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o
|
||||
obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o
|
||||
obj-$(CONFIG_LEDS_TURRIS_OMNIA) += leds-turris-omnia.o
|
||||
obj-$(CONFIG_LEDS_UPBOARD) += leds-upboard.o
|
||||
obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
|
||||
obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
|
||||
obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
|
||||
|
||||
@@ -85,13 +85,13 @@ static ssize_t max_brightness_show(struct device *dev,
|
||||
static DEVICE_ATTR_RO(max_brightness);
|
||||
|
||||
#ifdef CONFIG_LEDS_TRIGGERS
|
||||
static BIN_ATTR(trigger, 0644, led_trigger_read, led_trigger_write, 0);
|
||||
static struct bin_attribute *led_trigger_bin_attrs[] = {
|
||||
static const BIN_ATTR(trigger, 0644, led_trigger_read, led_trigger_write, 0);
|
||||
static const struct bin_attribute *const led_trigger_bin_attrs[] = {
|
||||
&bin_attr_trigger,
|
||||
NULL,
|
||||
};
|
||||
static const struct attribute_group led_trigger_group = {
|
||||
.bin_attrs = led_trigger_bin_attrs,
|
||||
.bin_attrs_new = led_trigger_bin_attrs,
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig)
|
||||
}
|
||||
|
||||
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
|
||||
struct bin_attribute *bin_attr, char *buf,
|
||||
const struct bin_attribute *bin_attr, char *buf,
|
||||
loff_t pos, size_t count)
|
||||
{
|
||||
struct device *dev = kobj_to_dev(kobj);
|
||||
@@ -123,7 +123,7 @@ static int led_trigger_format(char *buf, size_t size,
|
||||
* copy it.
|
||||
*/
|
||||
ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
|
||||
struct bin_attribute *attr, char *buf,
|
||||
const struct bin_attribute *attr, char *buf,
|
||||
loff_t pos, size_t count)
|
||||
{
|
||||
struct device *dev = kobj_to_dev(kobj);
|
||||
|
||||
@@ -394,7 +394,7 @@ static int cht_wc_leds_probe(struct platform_device *pdev)
|
||||
led->cdev.pattern_clear = cht_wc_leds_pattern_clear;
|
||||
led->cdev.max_brightness = 255;
|
||||
|
||||
ret = led_classdev_register(&pdev->dev, &led->cdev);
|
||||
ret = devm_led_classdev_register(&pdev->dev, &led->cdev);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
@@ -406,10 +406,6 @@ static int cht_wc_leds_probe(struct platform_device *pdev)
|
||||
static void cht_wc_leds_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct cht_wc_leds *leds = platform_get_drvdata(pdev);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CHT_WC_LED_COUNT; i++)
|
||||
led_classdev_unregister(&leds->leds[i].cdev);
|
||||
|
||||
/* Restore LED1 regs if hw-control was active else leave LED1 off */
|
||||
if (!(leds->led1_initial_regs.ctrl & CHT_WC_LED1_SWCTL))
|
||||
|
||||
@@ -265,7 +265,7 @@ static int lp8860_init(struct lp8860_led *led)
|
||||
goto out;
|
||||
}
|
||||
|
||||
reg_count = ARRAY_SIZE(lp8860_eeprom_disp_regs) / sizeof(lp8860_eeprom_disp_regs[0]);
|
||||
reg_count = ARRAY_SIZE(lp8860_eeprom_disp_regs);
|
||||
for (i = 0; i < reg_count; i++) {
|
||||
ret = regmap_write(led->eeprom_regmap,
|
||||
lp8860_eeprom_disp_regs[i].reg,
|
||||
|
||||
296
drivers/leds/leds-lp8864.c
Normal file
296
drivers/leds/leds-lp8864.c
Normal file
@@ -0,0 +1,296 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* TI LP8864/LP8866 4/6 Channel LED Driver
|
||||
*
|
||||
* Copyright (C) 2024 Siemens AG
|
||||
*
|
||||
* Based on LP8860 driver by Dan Murphy <dmurphy@ti.com>
|
||||
*/
|
||||
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#define LP8864_BRT_CONTROL 0x00
|
||||
#define LP8864_USER_CONFIG1 0x04
|
||||
#define LP8864_BRT_MODE_MASK GENMASK(9, 8)
|
||||
#define LP8864_BRT_MODE_REG BIT(9) /* Brightness control by DISPLAY_BRT reg */
|
||||
#define LP8864_SUPPLY_STATUS 0x0e
|
||||
#define LP8864_BOOST_STATUS 0x10
|
||||
#define LP8864_LED_STATUS 0x12
|
||||
#define LP8864_LED_STATUS_WR_MASK GENMASK(14, 9) /* Writeable bits in the LED_STATUS reg */
|
||||
|
||||
/* Textual meaning for status bits, starting from bit 1 */
|
||||
static const char *const lp8864_supply_status_msg[] = {
|
||||
"Vin under-voltage fault",
|
||||
"Vin over-voltage fault",
|
||||
"Vdd under-voltage fault",
|
||||
"Vin over-current fault",
|
||||
"Missing charge pump fault",
|
||||
"Charge pump fault",
|
||||
"Missing boost sync fault",
|
||||
"CRC error fault ",
|
||||
};
|
||||
|
||||
/* Textual meaning for status bits, starting from bit 1 */
|
||||
static const char *const lp8864_boost_status_msg[] = {
|
||||
"Boost OVP low fault",
|
||||
"Boost OVP high fault",
|
||||
"Boost over-current fault",
|
||||
"Missing boost FSET resistor fault",
|
||||
"Missing MODE SEL resistor fault",
|
||||
"Missing LED resistor fault",
|
||||
"ISET resistor short to ground fault",
|
||||
"Thermal shutdown fault",
|
||||
};
|
||||
|
||||
/* Textual meaning for every register bit */
|
||||
static const char *const lp8864_led_status_msg[] = {
|
||||
"LED 1 fault",
|
||||
"LED 2 fault",
|
||||
"LED 3 fault",
|
||||
"LED 4 fault",
|
||||
"LED 5 fault",
|
||||
"LED 6 fault",
|
||||
"LED open fault",
|
||||
"LED internal short fault",
|
||||
"LED short to GND fault",
|
||||
NULL, NULL, NULL,
|
||||
"Invalid string configuration fault",
|
||||
NULL,
|
||||
"I2C time out fault",
|
||||
};
|
||||
|
||||
/**
|
||||
* struct lp8864_led
|
||||
* @client: Pointer to the I2C client
|
||||
* @led_dev: led class device pointer
|
||||
* @regmap: Devices register map
|
||||
* @led_status_mask: Helps to report LED fault only once
|
||||
*/
|
||||
struct lp8864_led {
|
||||
struct i2c_client *client;
|
||||
struct led_classdev led_dev;
|
||||
struct regmap *regmap;
|
||||
u16 led_status_mask;
|
||||
};
|
||||
|
||||
static int lp8864_fault_check(struct lp8864_led *led)
|
||||
{
|
||||
int ret, i;
|
||||
unsigned int val;
|
||||
|
||||
ret = regmap_read(led->regmap, LP8864_SUPPLY_STATUS, &val);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
/* Odd bits are status bits, even bits are clear bits */
|
||||
for (i = 0; i < ARRAY_SIZE(lp8864_supply_status_msg); i++)
|
||||
if (val & BIT(i * 2 + 1))
|
||||
dev_warn(&led->client->dev, "%s\n", lp8864_supply_status_msg[i]);
|
||||
|
||||
/*
|
||||
* Clear bits have an index preceding the corresponding Status bits;
|
||||
* both have to be written "1" simultaneously to clear the corresponding
|
||||
* Status bit.
|
||||
*/
|
||||
if (val)
|
||||
ret = regmap_write(led->regmap, LP8864_SUPPLY_STATUS, val >> 1 | val);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = regmap_read(led->regmap, LP8864_BOOST_STATUS, &val);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
/* Odd bits are status bits, even bits are clear bits */
|
||||
for (i = 0; i < ARRAY_SIZE(lp8864_boost_status_msg); i++)
|
||||
if (val & BIT(i * 2 + 1))
|
||||
dev_warn(&led->client->dev, "%s\n", lp8864_boost_status_msg[i]);
|
||||
|
||||
if (val)
|
||||
ret = regmap_write(led->regmap, LP8864_BOOST_STATUS, val >> 1 | val);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = regmap_read(led->regmap, LP8864_LED_STATUS, &val);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Clear already reported faults that maintain their value until device
|
||||
* power-down
|
||||
*/
|
||||
val &= ~led->led_status_mask;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(lp8864_led_status_msg); i++)
|
||||
if (lp8864_led_status_msg[i] && val & BIT(i))
|
||||
dev_warn(&led->client->dev, "%s\n", lp8864_led_status_msg[i]);
|
||||
|
||||
/*
|
||||
* Mark those which maintain their value until device power-down as
|
||||
* "already reported"
|
||||
*/
|
||||
led->led_status_mask |= val & ~LP8864_LED_STATUS_WR_MASK;
|
||||
|
||||
/*
|
||||
* Only bits 14, 12, 10 have to be cleared here, but others are RO,
|
||||
* we don't care what we write to them.
|
||||
*/
|
||||
if (val & LP8864_LED_STATUS_WR_MASK)
|
||||
ret = regmap_write(led->regmap, LP8864_LED_STATUS, val >> 1 | val);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
dev_err(&led->client->dev, "Failed to read/clear faults (%pe)\n", ERR_PTR(ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lp8864_brightness_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness brt_val)
|
||||
{
|
||||
struct lp8864_led *led = container_of(led_cdev, struct lp8864_led, led_dev);
|
||||
/* Scale 0..LED_FULL into 16-bit HW brightness */
|
||||
unsigned int val = brt_val * 0xffff / LED_FULL;
|
||||
int ret;
|
||||
|
||||
ret = lp8864_fault_check(led);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = regmap_write(led->regmap, LP8864_BRT_CONTROL, val);
|
||||
if (ret)
|
||||
dev_err(&led->client->dev, "Failed to write brightness value\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum led_brightness lp8864_brightness_get(struct led_classdev *led_cdev)
|
||||
{
|
||||
struct lp8864_led *led = container_of(led_cdev, struct lp8864_led, led_dev);
|
||||
unsigned int val;
|
||||
int ret;
|
||||
|
||||
ret = regmap_read(led->regmap, LP8864_BRT_CONTROL, &val);
|
||||
if (ret) {
|
||||
dev_err(&led->client->dev, "Failed to read brightness value\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Scale 16-bit HW brightness into 0..LED_FULL */
|
||||
return val * LED_FULL / 0xffff;
|
||||
}
|
||||
|
||||
static const struct regmap_config lp8864_regmap_config = {
|
||||
.reg_bits = 8,
|
||||
.val_bits = 16,
|
||||
.val_format_endian = REGMAP_ENDIAN_LITTLE,
|
||||
};
|
||||
|
||||
static void lp8864_disable_gpio(void *data)
|
||||
{
|
||||
struct gpio_desc *gpio = data;
|
||||
|
||||
gpiod_set_value(gpio, 0);
|
||||
}
|
||||
|
||||
static int lp8864_probe(struct i2c_client *client)
|
||||
{
|
||||
int ret;
|
||||
struct lp8864_led *led;
|
||||
struct device_node *np = dev_of_node(&client->dev);
|
||||
struct device_node *child_node;
|
||||
struct led_init_data init_data = {};
|
||||
struct gpio_desc *enable_gpio;
|
||||
|
||||
led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL);
|
||||
if (!led)
|
||||
return -ENOMEM;
|
||||
|
||||
child_node = of_get_next_available_child(np, NULL);
|
||||
if (!child_node) {
|
||||
dev_err(&client->dev, "No LED function defined\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = devm_regulator_get_enable_optional(&client->dev, "vled");
|
||||
if (ret && ret != -ENODEV)
|
||||
return dev_err_probe(&client->dev, ret, "Failed to enable vled regulator\n");
|
||||
|
||||
enable_gpio = devm_gpiod_get_optional(&client->dev, "enable", GPIOD_OUT_HIGH);
|
||||
if (IS_ERR(enable_gpio))
|
||||
return dev_err_probe(&client->dev, PTR_ERR(enable_gpio),
|
||||
"Failed to get enable GPIO\n");
|
||||
|
||||
ret = devm_add_action_or_reset(&client->dev, lp8864_disable_gpio, enable_gpio);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
led->client = client;
|
||||
led->led_dev.brightness_set_blocking = lp8864_brightness_set;
|
||||
led->led_dev.brightness_get = lp8864_brightness_get;
|
||||
|
||||
led->regmap = devm_regmap_init_i2c(client, &lp8864_regmap_config);
|
||||
if (IS_ERR(led->regmap))
|
||||
return dev_err_probe(&client->dev, PTR_ERR(led->regmap),
|
||||
"Failed to allocate regmap\n");
|
||||
|
||||
/* Control brightness by DISPLAY_BRT register */
|
||||
ret = regmap_update_bits(led->regmap, LP8864_USER_CONFIG1, LP8864_BRT_MODE_MASK,
|
||||
LP8864_BRT_MODE_REG);
|
||||
if (ret) {
|
||||
dev_err(&led->client->dev, "Failed to set brightness control mode\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = lp8864_fault_check(led);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
init_data.fwnode = of_fwnode_handle(child_node);
|
||||
init_data.devicename = "lp8864";
|
||||
init_data.default_label = ":display_cluster";
|
||||
|
||||
ret = devm_led_classdev_register_ext(&client->dev, &led->led_dev, &init_data);
|
||||
if (ret)
|
||||
dev_err(&client->dev, "Failed to register LED device (%pe)\n", ERR_PTR(ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id lp8864_id[] = {
|
||||
{ "lp8864" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, lp8864_id);
|
||||
|
||||
static const struct of_device_id of_lp8864_leds_match[] = {
|
||||
{ .compatible = "ti,lp8864" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, of_lp8864_leds_match);
|
||||
|
||||
static struct i2c_driver lp8864_driver = {
|
||||
.driver = {
|
||||
.name = "lp8864",
|
||||
.of_match_table = of_lp8864_leds_match,
|
||||
},
|
||||
.probe = lp8864_probe,
|
||||
.id_table = lp8864_id,
|
||||
};
|
||||
module_i2c_driver(lp8864_driver);
|
||||
|
||||
MODULE_DESCRIPTION("Texas Instruments LP8864/LP8866 LED driver");
|
||||
MODULE_AUTHOR("Alexander Sverdlin <alexander.sverdlin@siemens.com>");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -439,6 +439,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
|
||||
}
|
||||
gpio_ext_pdev = of_find_device_by_node(gpio_ext_np);
|
||||
if (!gpio_ext_pdev) {
|
||||
of_node_put(gpio_ext_np);
|
||||
dev_err(dev, "Failed to find platform device for gpio-ext\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* CZ.NIC's Turris Omnia LEDs driver
|
||||
*
|
||||
* 2020, 2023 by Marek Behún <kabel@kernel.org>
|
||||
* 2020, 2023, 2024 by Marek Behún <kabel@kernel.org>
|
||||
*/
|
||||
|
||||
#include <linux/i2c.h>
|
||||
@@ -10,35 +10,23 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/turris-omnia-mcu-interface.h>
|
||||
|
||||
#define OMNIA_BOARD_LEDS 12
|
||||
#define OMNIA_LED_NUM_CHANNELS 3
|
||||
|
||||
/* MCU controller commands at I2C address 0x2a */
|
||||
#define OMNIA_MCU_I2C_ADDR 0x2a
|
||||
|
||||
#define CMD_GET_STATUS_WORD 0x01
|
||||
#define STS_FEATURES_SUPPORTED BIT(2)
|
||||
|
||||
#define CMD_GET_FEATURES 0x10
|
||||
#define FEAT_LED_GAMMA_CORRECTION BIT(5)
|
||||
|
||||
/* LED controller commands at I2C address 0x2b */
|
||||
#define CMD_LED_MODE 0x03
|
||||
#define CMD_LED_MODE_LED(l) ((l) & 0x0f)
|
||||
#define CMD_LED_MODE_USER 0x10
|
||||
|
||||
#define CMD_LED_STATE 0x04
|
||||
#define CMD_LED_STATE_LED(l) ((l) & 0x0f)
|
||||
#define CMD_LED_STATE_ON 0x10
|
||||
|
||||
#define CMD_LED_COLOR 0x05
|
||||
#define CMD_LED_SET_BRIGHTNESS 0x07
|
||||
#define CMD_LED_GET_BRIGHTNESS 0x08
|
||||
|
||||
#define CMD_SET_GAMMA_CORRECTION 0x30
|
||||
#define CMD_GET_GAMMA_CORRECTION 0x31
|
||||
/* MCU controller I2C address 0x2a, needed for detecting MCU features */
|
||||
#define OMNIA_MCU_I2C_ADDR 0x2a
|
||||
|
||||
/**
|
||||
* struct omnia_led - per-LED part of driver private data structure
|
||||
* @mc_cdev: multi-color LED class device
|
||||
* @subled_info: per-channel information
|
||||
* @cached_channels: cached values of per-channel brightness that was sent to the MCU
|
||||
* @on: whether the LED was set on
|
||||
* @hwtrig: whether the LED blinking was offloaded to the MCU
|
||||
* @reg: LED identifier to the MCU
|
||||
*/
|
||||
struct omnia_led {
|
||||
struct led_classdev_mc mc_cdev;
|
||||
struct mc_subled subled_info[OMNIA_LED_NUM_CHANNELS];
|
||||
@@ -49,73 +37,38 @@ struct omnia_led {
|
||||
|
||||
#define to_omnia_led(l) container_of(l, struct omnia_led, mc_cdev)
|
||||
|
||||
/**
|
||||
* struct omnia_leds - driver private data structure
|
||||
* @client: I2C client device
|
||||
* @lock: mutex to protect cached state
|
||||
* @has_gamma_correction: whether the MCU firmware supports gamma correction
|
||||
* @brightness_knode: kernel node of the "brightness" device sysfs attribute (this is the
|
||||
* driver specific global brightness, not the LED classdev brightness)
|
||||
* @leds: flexible array of per-LED data
|
||||
*/
|
||||
struct omnia_leds {
|
||||
struct i2c_client *client;
|
||||
struct mutex lock;
|
||||
bool has_gamma_correction;
|
||||
struct kernfs_node *brightness_knode;
|
||||
struct omnia_led leds[];
|
||||
};
|
||||
|
||||
static int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, u8 val)
|
||||
static int omnia_cmd_set_color(const struct i2c_client *client, u8 led, u8 r, u8 g, u8 b)
|
||||
{
|
||||
u8 buf[2] = { cmd, val };
|
||||
int ret;
|
||||
u8 buf[5] = { OMNIA_CMD_LED_COLOR, led, r, g, b };
|
||||
|
||||
ret = i2c_master_send(client, buf, sizeof(buf));
|
||||
|
||||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd,
|
||||
void *reply, size_t len)
|
||||
{
|
||||
struct i2c_msg msgs[2];
|
||||
int ret;
|
||||
|
||||
msgs[0].addr = addr;
|
||||
msgs[0].flags = 0;
|
||||
msgs[0].len = 1;
|
||||
msgs[0].buf = &cmd;
|
||||
msgs[1].addr = addr;
|
||||
msgs[1].flags = I2C_M_RD;
|
||||
msgs[1].len = len;
|
||||
msgs[1].buf = reply;
|
||||
|
||||
ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
|
||||
if (likely(ret == ARRAY_SIZE(msgs)))
|
||||
return 0;
|
||||
else if (ret < 0)
|
||||
return ret;
|
||||
else
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int omnia_cmd_read_u8(const struct i2c_client *client, u8 cmd)
|
||||
{
|
||||
u8 reply;
|
||||
int err;
|
||||
|
||||
err = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return reply;
|
||||
return omnia_cmd_write(client, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
static int omnia_led_send_color_cmd(const struct i2c_client *client,
|
||||
struct omnia_led *led)
|
||||
{
|
||||
char cmd[5];
|
||||
int ret;
|
||||
|
||||
cmd[0] = CMD_LED_COLOR;
|
||||
cmd[1] = led->reg;
|
||||
cmd[2] = led->subled_info[0].brightness;
|
||||
cmd[3] = led->subled_info[1].brightness;
|
||||
cmd[4] = led->subled_info[2].brightness;
|
||||
|
||||
/* Send the color change command */
|
||||
ret = i2c_master_send(client, cmd, 5);
|
||||
ret = omnia_cmd_set_color(client, led->reg, led->subled_info[0].brightness,
|
||||
led->subled_info[1].brightness, led->subled_info[2].brightness);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -170,12 +123,12 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev,
|
||||
* is not being blinked by HW.
|
||||
*/
|
||||
if (!err && !led->hwtrig && !brightness != !led->on) {
|
||||
u8 state = CMD_LED_STATE_LED(led->reg);
|
||||
u8 state = OMNIA_CMD_LED_STATE_LED(led->reg);
|
||||
|
||||
if (brightness)
|
||||
state |= CMD_LED_STATE_ON;
|
||||
state |= OMNIA_CMD_LED_STATE_ON;
|
||||
|
||||
err = omnia_cmd_write_u8(leds->client, CMD_LED_STATE, state);
|
||||
err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_STATE, state);
|
||||
if (!err)
|
||||
led->on = !!brightness;
|
||||
}
|
||||
@@ -210,8 +163,8 @@ static int omnia_hwtrig_activate(struct led_classdev *cdev)
|
||||
|
||||
if (!err) {
|
||||
/* Put the LED into MCU controlled mode */
|
||||
err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE,
|
||||
CMD_LED_MODE_LED(led->reg));
|
||||
err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_MODE,
|
||||
OMNIA_CMD_LED_MODE_LED(led->reg));
|
||||
if (!err)
|
||||
led->hwtrig = true;
|
||||
}
|
||||
@@ -232,9 +185,8 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev)
|
||||
led->hwtrig = false;
|
||||
|
||||
/* Put the LED into software mode */
|
||||
err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE,
|
||||
CMD_LED_MODE_LED(led->reg) |
|
||||
CMD_LED_MODE_USER);
|
||||
err = omnia_cmd_write_u8(leds->client, OMNIA_CMD_LED_MODE,
|
||||
OMNIA_CMD_LED_MODE_LED(led->reg) | OMNIA_CMD_LED_MODE_USER);
|
||||
|
||||
mutex_unlock(&leds->lock);
|
||||
|
||||
@@ -300,38 +252,26 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
|
||||
*/
|
||||
cdev->default_trigger = omnia_hw_trigger.name;
|
||||
|
||||
/* put the LED into software mode */
|
||||
ret = omnia_cmd_write_u8(client, CMD_LED_MODE,
|
||||
CMD_LED_MODE_LED(led->reg) |
|
||||
CMD_LED_MODE_USER);
|
||||
if (ret) {
|
||||
dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np,
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
/* Put the LED into software mode */
|
||||
ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(led->reg) |
|
||||
OMNIA_CMD_LED_MODE_USER);
|
||||
if (ret)
|
||||
return dev_err_probe(dev, ret, "Cannot set LED %pOF to software mode\n", np);
|
||||
|
||||
/* disable the LED */
|
||||
ret = omnia_cmd_write_u8(client, CMD_LED_STATE,
|
||||
CMD_LED_STATE_LED(led->reg));
|
||||
if (ret) {
|
||||
dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret);
|
||||
return ret;
|
||||
}
|
||||
/* Disable the LED */
|
||||
ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_STATE, OMNIA_CMD_LED_STATE_LED(led->reg));
|
||||
if (ret)
|
||||
return dev_err_probe(dev, ret, "Cannot set LED %pOF brightness\n", np);
|
||||
|
||||
/* Set initial color and cache it */
|
||||
ret = omnia_led_send_color_cmd(client, led);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Cannot set LED %pOF initial color: %i\n", np,
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
if (ret < 0)
|
||||
return dev_err_probe(dev, ret, "Cannot set LED %pOF initial color\n", np);
|
||||
|
||||
ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev,
|
||||
&init_data);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Cannot register LED %pOF: %i\n", np, ret);
|
||||
return ret;
|
||||
}
|
||||
if (ret < 0)
|
||||
return dev_err_probe(dev, ret, "Cannot register LED %pOF\n", np);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -351,14 +291,14 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a,
|
||||
char *buf)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
int ret;
|
||||
u8 reply;
|
||||
int err;
|
||||
|
||||
ret = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS);
|
||||
err = omnia_cmd_read_u8(client, OMNIA_CMD_GET_BRIGHTNESS, &reply);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return sysfs_emit(buf, "%d\n", ret);
|
||||
return sysfs_emit(buf, "%d\n", reply);
|
||||
}
|
||||
|
||||
static ssize_t brightness_store(struct device *dev, struct device_attribute *a,
|
||||
@@ -374,7 +314,7 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a,
|
||||
if (brightness > 100)
|
||||
return -EINVAL;
|
||||
|
||||
err = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness);
|
||||
err = omnia_cmd_write_u8(client, OMNIA_CMD_SET_BRIGHTNESS, brightness);
|
||||
|
||||
return err ?: count;
|
||||
}
|
||||
@@ -385,17 +325,16 @@ static ssize_t gamma_correction_show(struct device *dev,
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct omnia_leds *leds = i2c_get_clientdata(client);
|
||||
int ret;
|
||||
u8 reply = 0;
|
||||
int err;
|
||||
|
||||
if (leds->has_gamma_correction) {
|
||||
ret = omnia_cmd_read_u8(client, CMD_GET_GAMMA_CORRECTION);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} else {
|
||||
ret = 0;
|
||||
err = omnia_cmd_read_u8(client, OMNIA_CMD_GET_GAMMA_CORRECTION, &reply);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
||||
return sysfs_emit(buf, "%d\n", !!ret);
|
||||
return sysfs_emit(buf, "%d\n", !!reply);
|
||||
}
|
||||
|
||||
static ssize_t gamma_correction_store(struct device *dev,
|
||||
@@ -413,7 +352,7 @@ static ssize_t gamma_correction_store(struct device *dev,
|
||||
if (kstrtobool(buf, &val) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
err = omnia_cmd_write_u8(client, CMD_SET_GAMMA_CORRECTION, val);
|
||||
err = omnia_cmd_write_u8(client, OMNIA_CMD_SET_GAMMA_CORRECTION, val);
|
||||
|
||||
return err ?: count;
|
||||
}
|
||||
@@ -426,26 +365,104 @@ static struct attribute *omnia_led_controller_attrs[] = {
|
||||
};
|
||||
ATTRIBUTE_GROUPS(omnia_led_controller);
|
||||
|
||||
static int omnia_mcu_get_features(const struct i2c_client *client)
|
||||
static irqreturn_t omnia_brightness_changed_threaded_fn(int irq, void *data)
|
||||
{
|
||||
struct omnia_leds *leds = data;
|
||||
|
||||
if (unlikely(!leds->brightness_knode)) {
|
||||
/*
|
||||
* Note that sysfs_get_dirent() may sleep. This is okay, because we are in threaded
|
||||
* context.
|
||||
*/
|
||||
leds->brightness_knode = sysfs_get_dirent(leds->client->dev.kobj.sd, "brightness");
|
||||
if (!leds->brightness_knode)
|
||||
return IRQ_NONE;
|
||||
}
|
||||
|
||||
sysfs_notify_dirent(leds->brightness_knode);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void omnia_brightness_knode_put(void *data)
|
||||
{
|
||||
struct omnia_leds *leds = data;
|
||||
|
||||
if (leds->brightness_knode)
|
||||
sysfs_put(leds->brightness_knode);
|
||||
}
|
||||
|
||||
static int omnia_request_brightness_irq(struct omnia_leds *leds)
|
||||
{
|
||||
struct device *dev = &leds->client->dev;
|
||||
int ret;
|
||||
|
||||
if (!leds->client->irq) {
|
||||
dev_info(dev,
|
||||
"Brightness change interrupt supported by MCU firmware but not described in device-tree\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Registering the brightness_knode destructor before requesting the IRQ ensures that on
|
||||
* removal the brightness_knode sysfs node is put only after the IRQ is freed.
|
||||
* This is needed because the interrupt handler uses the knode.
|
||||
*/
|
||||
ret = devm_add_action(dev, omnia_brightness_knode_put, leds);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return devm_request_threaded_irq(dev, leds->client->irq, NULL,
|
||||
omnia_brightness_changed_threaded_fn, IRQF_ONESHOT,
|
||||
"leds-turris-omnia", leds);
|
||||
}
|
||||
|
||||
static int omnia_mcu_get_features(const struct i2c_client *mcu_client)
|
||||
{
|
||||
u16 reply;
|
||||
int err;
|
||||
|
||||
err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR,
|
||||
CMD_GET_STATUS_WORD, &reply, sizeof(reply));
|
||||
err = omnia_cmd_read_u16(mcu_client, OMNIA_CMD_GET_STATUS_WORD, &reply);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */
|
||||
if (!(le16_to_cpu(reply) & STS_FEATURES_SUPPORTED))
|
||||
/* Check whether MCU firmware supports the OMNIA_CMD_GET_FEAUTRES command */
|
||||
if (!(reply & OMNIA_STS_FEATURES_SUPPORTED))
|
||||
return 0;
|
||||
|
||||
err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR,
|
||||
CMD_GET_FEATURES, &reply, sizeof(reply));
|
||||
err = omnia_cmd_read_u16(mcu_client, OMNIA_CMD_GET_FEATURES, &reply);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return le16_to_cpu(reply);
|
||||
return reply;
|
||||
}
|
||||
|
||||
static int omnia_match_mcu_client(struct device *dev, void *data)
|
||||
{
|
||||
struct i2c_client *client;
|
||||
|
||||
client = i2c_verify_client(dev);
|
||||
if (!client)
|
||||
return 0;
|
||||
|
||||
return client->addr == OMNIA_MCU_I2C_ADDR;
|
||||
}
|
||||
|
||||
static int omnia_find_mcu_and_get_features(struct device *dev)
|
||||
{
|
||||
struct device *mcu_dev;
|
||||
int ret;
|
||||
|
||||
mcu_dev = device_find_child(dev->parent, NULL, omnia_match_mcu_client);
|
||||
if (!mcu_dev)
|
||||
return -ENODEV;
|
||||
|
||||
ret = omnia_mcu_get_features(i2c_verify_client(mcu_dev));
|
||||
|
||||
put_device(mcu_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int omnia_leds_probe(struct i2c_client *client)
|
||||
@@ -457,13 +474,10 @@ static int omnia_leds_probe(struct i2c_client *client)
|
||||
int ret, count;
|
||||
|
||||
count = of_get_available_child_count(np);
|
||||
if (!count) {
|
||||
dev_err(dev, "LEDs are not defined in device tree!\n");
|
||||
return -ENODEV;
|
||||
} else if (count > OMNIA_BOARD_LEDS) {
|
||||
dev_err(dev, "Too many LEDs defined in device tree!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (count == 0)
|
||||
return dev_err_probe(dev, -ENODEV, "LEDs are not defined in device tree!\n");
|
||||
if (count > OMNIA_BOARD_LEDS)
|
||||
return dev_err_probe(dev, -EINVAL, "Too many LEDs defined in device tree!\n");
|
||||
|
||||
leds = devm_kzalloc(dev, struct_size(leds, leds, count), GFP_KERNEL);
|
||||
if (!leds)
|
||||
@@ -472,28 +486,23 @@ static int omnia_leds_probe(struct i2c_client *client)
|
||||
leds->client = client;
|
||||
i2c_set_clientdata(client, leds);
|
||||
|
||||
ret = omnia_mcu_get_features(client);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Cannot determine MCU supported features: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
ret = omnia_find_mcu_and_get_features(dev);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(dev, ret, "Cannot determine MCU supported features\n");
|
||||
|
||||
leds->has_gamma_correction = ret & FEAT_LED_GAMMA_CORRECTION;
|
||||
if (!leds->has_gamma_correction) {
|
||||
dev_info(dev,
|
||||
"Your board's MCU firmware does not support the LED gamma correction feature.\n");
|
||||
dev_info(dev,
|
||||
"Consider upgrading MCU firmware with the omnia-mcutool utility.\n");
|
||||
leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION;
|
||||
|
||||
if (ret & OMNIA_FEAT_BRIGHTNESS_INT) {
|
||||
ret = omnia_request_brightness_irq(leds);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(dev, ret, "Cannot request brightness IRQ\n");
|
||||
}
|
||||
|
||||
mutex_init(&leds->lock);
|
||||
|
||||
ret = devm_led_trigger_register(dev, &omnia_hw_trigger);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Cannot register private LED trigger: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
if (ret < 0)
|
||||
return dev_err_probe(dev, ret, "Cannot register private LED trigger\n");
|
||||
|
||||
led = &leds->leds[0];
|
||||
for_each_available_child_of_node_scoped(np, child) {
|
||||
@@ -509,20 +518,11 @@ static int omnia_leds_probe(struct i2c_client *client)
|
||||
|
||||
static void omnia_leds_remove(struct i2c_client *client)
|
||||
{
|
||||
u8 buf[5];
|
||||
/* Put all LEDs into default (HW triggered) mode */
|
||||
omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(OMNIA_BOARD_LEDS));
|
||||
|
||||
/* put all LEDs into default (HW triggered) mode */
|
||||
omnia_cmd_write_u8(client, CMD_LED_MODE,
|
||||
CMD_LED_MODE_LED(OMNIA_BOARD_LEDS));
|
||||
|
||||
/* set all LEDs color to [255, 255, 255] */
|
||||
buf[0] = CMD_LED_COLOR;
|
||||
buf[1] = OMNIA_BOARD_LEDS;
|
||||
buf[2] = 255;
|
||||
buf[3] = 255;
|
||||
buf[4] = 255;
|
||||
|
||||
i2c_master_send(client, buf, 5);
|
||||
/* Set all LEDs color to [255, 255, 255] */
|
||||
omnia_cmd_set_color(client, OMNIA_BOARD_LEDS, 255, 255, 255);
|
||||
}
|
||||
|
||||
static const struct of_device_id of_omnia_leds_match[] = {
|
||||
|
||||
126
drivers/leds/leds-upboard.c
Normal file
126
drivers/leds/leds-upboard.c
Normal file
@@ -0,0 +1,126 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* UP board LED driver.
|
||||
*
|
||||
* Copyright (c) AAEON. All rights reserved.
|
||||
* Copyright (C) 2024 Bootlin
|
||||
*
|
||||
* Author: Gary Wang <garywang@aaeon.com.tw>
|
||||
* Author: Thomas Richard <thomas.richard@bootlin.com>
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/container_of.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/mfd/upboard-fpga.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regmap.h>
|
||||
|
||||
#define led_cdev_to_led_upboard(c) container_of(c, struct upboard_led, cdev)
|
||||
|
||||
struct upboard_led {
|
||||
struct regmap_field *field;
|
||||
struct led_classdev cdev;
|
||||
};
|
||||
|
||||
struct upboard_led_profile {
|
||||
const char *name;
|
||||
unsigned int bit;
|
||||
};
|
||||
|
||||
static struct upboard_led_profile upboard_up_led_profile[] = {
|
||||
{ "upboard:yellow:" LED_FUNCTION_STATUS, 0 },
|
||||
{ "upboard:green:" LED_FUNCTION_STATUS, 1 },
|
||||
{ "upboard:red:" LED_FUNCTION_STATUS, 2 },
|
||||
};
|
||||
|
||||
static struct upboard_led_profile upboard_up2_led_profile[] = {
|
||||
{ "upboard:blue:" LED_FUNCTION_STATUS, 0 },
|
||||
{ "upboard:yellow:" LED_FUNCTION_STATUS, 1 },
|
||||
{ "upboard:green:" LED_FUNCTION_STATUS, 2 },
|
||||
{ "upboard:red:" LED_FUNCTION_STATUS, 3 },
|
||||
};
|
||||
|
||||
static enum led_brightness upboard_led_brightness_get(struct led_classdev *cdev)
|
||||
{
|
||||
struct upboard_led *led = led_cdev_to_led_upboard(cdev);
|
||||
int brightness, ret;
|
||||
|
||||
ret = regmap_field_read(led->field, &brightness);
|
||||
|
||||
return ret ? LED_OFF : brightness;
|
||||
};
|
||||
|
||||
static int upboard_led_brightness_set(struct led_classdev *cdev, enum led_brightness brightness)
|
||||
{
|
||||
struct upboard_led *led = led_cdev_to_led_upboard(cdev);
|
||||
|
||||
return regmap_field_write(led->field, brightness != LED_OFF);
|
||||
};
|
||||
|
||||
static int upboard_led_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct upboard_fpga *fpga = dev_get_drvdata(dev->parent);
|
||||
struct upboard_led_profile *led_profile;
|
||||
struct upboard_led *led;
|
||||
int led_instances, ret, i;
|
||||
|
||||
switch (fpga->fpga_data->type) {
|
||||
case UPBOARD_UP_FPGA:
|
||||
led_profile = upboard_up_led_profile;
|
||||
led_instances = ARRAY_SIZE(upboard_up_led_profile);
|
||||
break;
|
||||
case UPBOARD_UP2_FPGA:
|
||||
led_profile = upboard_up2_led_profile;
|
||||
led_instances = ARRAY_SIZE(upboard_up2_led_profile);
|
||||
break;
|
||||
default:
|
||||
return dev_err_probe(dev, -EINVAL, "Unknown device type %d\n",
|
||||
fpga->fpga_data->type);
|
||||
}
|
||||
|
||||
for (i = 0; i < led_instances; i++) {
|
||||
const struct reg_field fldconf = {
|
||||
.reg = UPBOARD_REG_FUNC_EN0,
|
||||
.lsb = led_profile[i].bit,
|
||||
.msb = led_profile[i].bit,
|
||||
};
|
||||
|
||||
led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
|
||||
if (!led)
|
||||
return -ENOMEM;
|
||||
|
||||
led->field = devm_regmap_field_alloc(&pdev->dev, fpga->regmap, fldconf);
|
||||
if (IS_ERR(led->field))
|
||||
return PTR_ERR(led->field);
|
||||
|
||||
led->cdev.brightness_get = upboard_led_brightness_get;
|
||||
led->cdev.brightness_set_blocking = upboard_led_brightness_set;
|
||||
led->cdev.max_brightness = LED_ON;
|
||||
|
||||
led->cdev.name = led_profile[i].name;
|
||||
|
||||
ret = devm_led_classdev_register(dev, &led->cdev);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver upboard_led_driver = {
|
||||
.driver = {
|
||||
.name = "upboard-leds",
|
||||
},
|
||||
.probe = upboard_led_probe,
|
||||
};
|
||||
|
||||
module_platform_driver(upboard_led_driver);
|
||||
|
||||
MODULE_AUTHOR("Gary Wang <garywang@aaeon.com.tw>");
|
||||
MODULE_AUTHOR("Thomas Richard <thomas.richard@bootlin.com>");
|
||||
MODULE_DESCRIPTION("UP Board LED driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("platform:upboard-led");
|
||||
@@ -22,10 +22,10 @@ void led_stop_software_blink(struct led_classdev *led_cdev);
|
||||
void led_set_brightness_nopm(struct led_classdev *led_cdev, unsigned int value);
|
||||
void led_set_brightness_nosleep(struct led_classdev *led_cdev, unsigned int value);
|
||||
ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
|
||||
struct bin_attribute *attr, char *buf,
|
||||
const struct bin_attribute *attr, char *buf,
|
||||
loff_t pos, size_t count);
|
||||
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
|
||||
struct bin_attribute *bin_attr, char *buf,
|
||||
const struct bin_attribute *bin_attr, char *buf,
|
||||
loff_t pos, size_t count);
|
||||
|
||||
extern struct rw_semaphore leds_list_lock;
|
||||
|
||||
@@ -50,7 +50,13 @@ static int led_pwm_mc_set(struct led_classdev *cdev,
|
||||
duty = priv->leds[i].state.period - duty;
|
||||
|
||||
priv->leds[i].state.duty_cycle = duty;
|
||||
priv->leds[i].state.enabled = duty > 0;
|
||||
/*
|
||||
* Disabling a PWM doesn't guarantee that it emits the inactive level.
|
||||
* So keep it on. Only for suspending the PWM should be disabled because
|
||||
* otherwise it refuses to suspend. The possible downside is that the
|
||||
* LED might stay (or even go) on.
|
||||
*/
|
||||
priv->leds[i].state.enabled = !(cdev->flags & LED_SUSPENDED);
|
||||
ret = pwm_apply_might_sleep(priv->leds[i].pwm,
|
||||
&priv->leds[i].state);
|
||||
if (ret)
|
||||
|
||||
@@ -156,7 +156,7 @@ static ssize_t led_invert_show(struct device *dev,
|
||||
{
|
||||
struct activity_data *activity_data = led_trigger_get_drvdata(dev);
|
||||
|
||||
return sprintf(buf, "%u\n", activity_data->invert);
|
||||
return sprintf(buf, "%d\n", activity_data->invert);
|
||||
}
|
||||
|
||||
static ssize_t led_invert_store(struct device *dev,
|
||||
|
||||
@@ -605,6 +605,8 @@ static int netdev_trig_notify(struct notifier_block *nb,
|
||||
trigger_data->net_dev = NULL;
|
||||
break;
|
||||
case NETDEV_UP:
|
||||
trigger_data->hw_control = can_hw_control(trigger_data);
|
||||
fallthrough;
|
||||
case NETDEV_CHANGE:
|
||||
get_device_state(trigger_data);
|
||||
/* Refresh link_speed visibility */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user