leds: aat1290: Add support for AAT1270
Subsystems (2)
v2 cover leds: aat1290: Add support for AAT1270
Document AAT1270 and FLINH pin, adjust driver to support AAT1270.
---
Changes in v2:
- added formulas for calculations
- adjusted mm_to_fl_ratio to be set according to chip info
- adjusted timeout configuration to be set according to chip info
---
Svyatoslav Ryhel (3):
dt-bindings: leds: skyworks,aat1290: Document AAT1270 Current
Regulator for Flash LEDs
dt-bindings: leds: skyworks,aat1290: Document FLINH pin
leds: aat1290: Add support for AAT1270 Current Regulator for Flash
LEDs
.../bindings/leds/skyworks,aat1290.yaml | 13 ++- drivers/leds/flash/leds-aat1290.c | 91 ++++++++++++++----- 2 files changed, 77 insertions(+), 27 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/3 dt-bindings: leds: skyworks,aat1290: Document AAT1270 Current Regulator for Flash LEDs
The AAT1270 Current Regulator for Flash LEDs has a similar configuration to the AAT1290, but it uses a different programming model and requires a separate compatible.
--- .../devicetree/bindings/leds/skyworks,aat1290.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/leds/skyworks,aat1290.yaml +6 -3
@@ -19,7 +19,9 @@ description: | properties: compatible: - const: skyworks,aat1290 + enum: + - skyworks,aat1290 + - skyworks,aat1270 enset-gpios: maxItems: 1
@@ -39,12 +41,13 @@ properties: flash-max-microamp: description: | Maximum flash LED supply current can be calculated using following - formula: I = 1A * 162 kOhm / Rset. + formula: I = 1A * 162 kOhm / Rset (for AAT1290) and + I = 1A * 81 kOhm / Rset (for AAT1270). flash-max-timeout-us: description: | Maximum flash timeout can be calculated using following formula: - T = 8.82 * 10^9 * Ct. + T = 8.82 * 10^9 * Ct (for AAT1290) and T = 21.5 * 10^9 * Ct (for AAT1270). required: - flash-max-microamp
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 1/3] dt-bindings: leds: skyworks,aat1290: Document AAT1270 Current Regulator for Flash LEDs
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
The AAT1270 Current Regulator for Flash LEDs has a similar configuration to the AAT1290, but it uses a different programming model and requires a separate compatible.
Signed-off-by Svyatoslav Ryhel <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/3] dt-bindings: leds: skyworks,aat1290: Document AAT1270 Current Regulator for Flash LEDs
In reply to Svyatoslav RyhelQuoted 30 lines · Svyatoslav Ryhel
The AAT1270 Current Regulator for Flash LEDs has a similar configuration to the AAT1290, but it uses a different programming model and requires a separate compatible.
Signed-off-by Svyatoslav Ryhel <[email protected]>--- .../devicetree/bindings/leds/skyworks,aat1290.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/leds/skyworks,aat1290.yaml +4
-2@@ -19,7 +19,9 @@ description: | properties: compatible: - const: skyworks,aat1290 + enum: + - skyworks,aat1290 + - skyworks,aat1270 enset-gpios: maxItems: 1@@ -39,12 +41,13 @@ properties: flash-max-microamp: description: | Maximum flash LED supply current can be calculated using following - formula: I = 1A * 162 kOhm / Rset. + formula: I = 1A * 162 kOhm / Rset (for AAT1290) and
Documentation/devicetree/bindings/leds/skyworks,aat1290.yaml properties: · line 53
Quoted 10 lines
Documentation/devicetree/bindings/leds/skyworks,aat1290.yaml +2
-1+ I = 1A * 81 kOhm / Rset (for AAT1270). flash-max-timeout-us: description: | Maximum flash timeout can be calculated using following formula: - T = 8.82 * 10^9 * Ct. + T = 8.82 * 10^9 * Ct (for AAT1290) and T = 21.5 * 10^9 * Ct (for AAT1270). required: - flash-max-microamp
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH v2 1/3] dt-bindings: leds: skyworks,aat1290: Document AAT1270 Current Regulator for Flash LEDs
In reply to Svyatoslav RyhelQuoted 9 lines · Svyatoslav Ryhel
The AAT1270 Current Regulator for Flash LEDs has a similar configuration to the AAT1290, but it uses a different programming model and requires a separate compatible.
Signed-off-by Svyatoslav Ryhel <[email protected]>--- .../devicetree/bindings/leds/skyworks,aat1290.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
PATCH v2 2/3 dt-bindings: leds: skyworks,aat1290: Document FLINH pin
In reply to Svyatoslav RyhelBoth the AAT1270 and AAT1290 feature a FLINH pin used for mandatory Flash inhibition.
--- Documentation/devicetree/bindings/leds/skyworks,aat1290.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/leds/skyworks,aat1290.yaml +4 -0
@@ -31,6 +31,10 @@ properties: maxItems: 1 description: FL_EN pin + flinh-gpios: + maxItems: 1 + description: FLINH pin + led: $ref: common.yaml# unevaluatedProperties: false
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 2/3] dt-bindings: leds: skyworks,aat1290: Document FLINH pin
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
Both the AAT1270 and AAT1290 feature a FLINH pin used for mandatory Flash inhibition.
Signed-off-by Svyatoslav Ryhel <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/3] dt-bindings: leds: skyworks,aat1290: Document FLINH pin
In reply to Svyatoslav RyhelQuoted 8 lines · Svyatoslav Ryhel
Both the AAT1270 and AAT1290 feature a FLINH pin used for mandatory Flash inhibition.
Signed-off-by Svyatoslav Ryhel <[email protected]>--- Documentation/devicetree/bindings/leds/skyworks,aat1290.yaml | 4 ++++ 1 file changed, 4 insertions(+)
PATCH v2 3/3 leds: aat1290: Add support for AAT1270 Current Regulator for Flash LEDs
In reply to Svyatoslav RyhelThe AAT1270 is quite similar to the AAT1290, but it does not support the Advanced Simple Serial Control (AS2C) used in the AAT1290. The AAT1270 uses an earlier version of AS2C, namely Simple Serial Control, which lacks address-sending capabilities.
Differentiate the chips by using a description structure with a flag to indicate if AS2C is supported, Maximum Movie to Flash Mode Current ratio and if flash timeout is fixed by the hardware.
--- drivers/leds/flash/leds-aat1290.c | 91 +++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 24 deletions(-)
drivers/leds/flash/leds-aat1290.c +67 -24
@@ -33,8 +33,8 @@#define AAT1290_MM_CURRENT_RATIO_ADDR 20#define AAT1290_MM_TO_FL_1_92 1 -#define AAT1290_MM_TO_FL_RATIO 1000 / 1920 -#define AAT1290_MAX_MM_CURRENT (fl_max) (fl_max * AAT1290_MM_TO_FL_RATIO) +#define AAT1270_MM_TO_FL_RATIO 7300 +#define AAT1290_MM_TO_FL_RATIO 1920#define AAT1290_LATCH_TIME_MIN_US 500#define AAT1290_LATCH_TIME_MAX_US 1000
@@ -43,9 +43,6 @@#define AAT1290_FLASH_TM_NUM_LEVELS 16#define AAT1290_MM_CURRENT_SCALE_SIZE 15 -#define AAT1290_NAME "aat1290" - -struct aat1290_led_config_data {/* maximum LED current in movie mode */ u32 max_mm_current;
@@ -59,6 +56,17 @@ struct aat1290_led_config_data {enum led_brightness max_brightness; }; +struct aat1290_led_chip_info { +/* led controller name */ +const char *name; +/* Maximum Movie to Flash Mode Current Ratio with 1000 presision */ +u32 mm_to_fl_ratio; +/* Advanced Simple Serial Control support */ +bool as2c; +/* Flash timeout is fixed by the hardware */ +bool fixed_timeout; +}; +struct aat1290_led {/* platform device data */ struct platform_device *pdev;
@@ -74,6 +82,10 @@ struct aat1290_led {struct gpio_desc *gpio_fl_en;/* EN|SET pin */ struct gpio_desc *gpio_en_set; + +/* led controller description */ +const struct aat1290_led_chip_info *info; +/* movie mode current scale */ int *mm_current_scale;/* device mode */
@@ -101,15 +113,17 @@ static void aat1290_as2cwire_write(struct aat1290_led *led, int addr, int value)udelay (AAT1290_FLEN_OFF_DELAY_TIME_US ); -/* write address */ -for (i =0 ; i < addr; ++i) { -udelay (AAT1290_EN_SET_TICK_TIME_US ); -gpiod_direction_output (led->gpio_en_set,0 ); -udelay (AAT1290_EN_SET_TICK_TIME_US ); -gpiod_direction_output (led->gpio_en_set,1 ); - } +if (led->info->as2c) { +/* write address */ +for (i =0 ; i < addr; ++i) { +udelay (AAT1290_EN_SET_TICK_TIME_US ); +gpiod_direction_output (led->gpio_en_set,0 ); +udelay (AAT1290_EN_SET_TICK_TIME_US ); +gpiod_direction_output (led->gpio_en_set,1 ); + } -usleep_range (AAT1290_LATCH_TIME_MIN_US ,AAT1290_LATCH_TIME_MAX_US ); +usleep_range (AAT1290_LATCH_TIME_MIN_US ,AAT1290_LATCH_TIME_MAX_US ); + }/* write data */ for (i =0 ; i < value; ++i) {
@@ -150,16 +164,18 @@ static int aat1290_led_brightness_set(struct led_classdev *led_cdev, led->movie_mode = false; }else {if (!led->movie_mode) { -aat1290_as2cwire_write (led, -AAT1290_MM_CURRENT_RATIO_ADDR , -AAT1290_MM_TO_FL_1_92 ); +if (led->info->as2c) +aat1290_as2cwire_write (led, +AAT1290_MM_CURRENT_RATIO_ADDR , +AAT1290_MM_TO_FL_1_92 ); led->movie_mode = true; }aat1290_as2cwire_write (led,AAT1290_MOVIE_MODE_CURRENT_ADDR ,AAT1290_MAX_MM_CURR_PERCENT_0 - brightness); -aat1290_as2cwire_write (led,AAT1290_MOVIE_MODE_CONFIG_ADDR , -AAT1290_MOVIE_MODE_ON ); +if (led->info->as2c) +aat1290_as2cwire_write (led,AAT1290_MOVIE_MODE_CONFIG_ADDR , +AAT1290_MOVIE_MODE_ON ); }mutex_unlock (&led->lock);
@@ -178,7 +194,8 @@ static int aat1290_led_flash_strobe_set(struct led_classdev_flash *fled_cdev,mutex_lock (&led->lock);if (state) { -aat1290_set_flash_safety_timer (led, timeout->val); +if (!led->info->fixed_timeout) +aat1290_set_flash_safety_timer (led, timeout->val);gpiod_direction_output (led->gpio_fl_en,1 ); }else {gpiod_direction_output (led->gpio_fl_en,0 );
@@ -308,8 +325,10 @@ static int init_mm_current_scale(struct aat1290_led *led,20 ,22 ,25 ,28 ,32 ,36 ,40 ,45 ,50 ,56 ,63 ,71 ,79 ,89 ,100 }; -int i, max_mm_current = -AAT1290_MAX_MM_CURRENT (cfg->max_flash_current); +int i, max_mm_current; + + max_mm_current =mult_frac (cfg->max_flash_current,1000 , + led->info->mm_to_fl_ratio); led->mm_current_scale = devm_kcalloc(&led->pdev->dev, ARRAY_SIZE(max_mm_current_percent),
@@ -360,7 +379,12 @@ static void aat1290_init_flash_timeout(struct aat1290_led *led,/* Init flash timeout setting */ setting = &fled_cdev->timeout; - setting->min = cfg->max_flash_tm /AAT1290_FLASH_TM_NUM_LEVELS ; + +if (!led->info->fixed_timeout) + setting->min = cfg->max_flash_tm /AAT1290_FLASH_TM_NUM_LEVELS ; +else + setting->min = cfg->max_flash_tm; + setting->max = cfg->max_flash_tm; setting->step = setting->min; setting->val = setting->max;
@@ -476,6 +500,10 @@ static int aat1290_led_probe(struct platform_device *pdev) fled_cdev->ops = &flash_ops; led_cdev = &fled_cdev->led_cdev; + led->info =device_get_match_data (dev); +if (!led->info) +return -ENODEV ; + ret =aat1290_led_get_configuration (led, &led_cfg, &sub_node);if (ret <0 )return ret;
@@ -490,7 +518,7 @@ static int aat1290_led_probe(struct platform_device *pdev)aat1290_init_flash_timeout (led, &led_cfg); init_data.fwnode =of_fwnode_handle (sub_node); - init_data.devicename =AAT1290_NAME ; + init_data.devicename = led->info->name;/* Register LED Flash class device */ ret = led_classdev_flash_register_ext(&pdev->dev, fled_cdev,
@@ -529,8 +557,23 @@ static void aat1290_led_remove(struct platform_device *pdev)mutex_destroy (&led->lock); } +static const struct aat1290_led_chip_info aat1290_info = { + .name ="aat1290" , + .mm_to_fl_ratio =AAT1290_MM_TO_FL_RATIO , + .as2c = true, + .fixed_timeout = false, +}; + +static const struct aat1290_led_chip_info aat1270_info = { + .name ="aat1270" , + .mm_to_fl_ratio =AAT1270_MM_TO_FL_RATIO , + .as2c = false, + .fixed_timeout = true, +}; +static const struct of_device_id aat1290_led_dt_match[] = { - { .compatible ="skyworks,aat1290" }, + { .compatible ="skyworks,aat1290" , .data = &aat1290_info }, + { .compatible ="skyworks,aat1270" , .data = &aat1270_info }, {}, };MODULE_DEVICE_TABLE (of, aat1290_led_dt_match);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 3/3] leds: aat1290: Add support for AAT1270 Current Regulator for Flash LEDs
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] leds: aat1290: division by zero due to unvalidated flash-max-timeout-us - [Medium] leds: aat1290…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] leds: aat1290: division by zero due to unvalidated flash-max-timeout-us
- [Medium] leds: aat1290: missing T_OFF reset pulse for AAT1270 SSC protocol --
commit edf7870e4592e0289f95e937e9de77118e50731c
Author: Svyatoslav Ryhel <[email protected]>
leds: aat1290: Add support for AAT1270 Current Regulator for Flash LEDs
The AAT1270 is quite similar to the AAT1290, but it does not support the Advanced Simple Serial Control (AS2C) used in the AAT1290. The AAT1270 uses an earlier version of AS2C, namely Simple Serial Control, which lacks address-sending capabilities.
drivers/leds/flash/leds-aat1290.c static void aat1290_as2cwire_write(struct aat1290_led *led, int addr, int value) · line 114
Quoted 6 lines
drivers/leds/flash/leds-aat1290.c +0
-0@@ -101,15 +113,17 @@ static void aat1290_as2cwire_write(struct aat1290_led *led, int addr, int value)udelay (AAT1290_FLEN_OFF_DELAY_TIME_US );
[Severity: Medium]
Is this delay sufficient to reset the AAT1270? The EN/SET pin is pulled low for only 10us (AAT1290_FLEN_OFF_DELAY_TIME_US) before sending pulses. For the AAT1270 SSC protocol, wouldn't a T_OFF duration of >500us be required to reset the internal counter to 0?
If a user changes the brightness of the AAT1270 LED via sysfs while it is already on, the driver directly calls aat1290_as2cwire_write() without fully turning the device off first. Will the Simple Serial Control counter fail to reset, causing new pulses to accumulate or be ignored?
Quoted 15 lines
drivers/leds/flash/leds-aat1290.c +8
-7-/* write address */ -for (i =0 ; i < addr; ++i) { -udelay (AAT1290_EN_SET_TICK_TIME_US ); -gpiod_direction_output (led->gpio_en_set,0 ); -udelay (AAT1290_EN_SET_TICK_TIME_US ); -gpiod_direction_output (led->gpio_en_set,1 ); - } +if (led->info->as2c) { +/* write address */ +for (i =0 ; i < addr; ++i) { +udelay (AAT1290_EN_SET_TICK_TIME_US ); +gpiod_direction_output (led->gpio_en_set,0 ); +udelay (AAT1290_EN_SET_TICK_TIME_US ); +gpiod_direction_output (led->gpio_en_set,1 ); + }
[ ... ]
drivers/leds/flash/leds-aat1290.c static void aat1290_init_flash_timeout(struct aat1290_led *led, · line 389
Quoted 13 lines
drivers/leds/flash/leds-aat1290.c +6
-1@@ -360,7 +379,12 @@ static void aat1290_init_flash_timeout(struct aat1290_led *led,/* Init flash timeout setting */ setting = &fled_cdev->timeout; - setting->min = cfg->max_flash_tm /AAT1290_FLASH_TM_NUM_LEVELS ; + +if (!led->info->fixed_timeout) + setting->min = cfg->max_flash_tm /AAT1290_FLASH_TM_NUM_LEVELS ; +else + setting->min = cfg->max_flash_tm; + setting->max = cfg->max_flash_tm; setting->step = setting->min;
[Severity: High]
Could this lead to a division by zero in led_clamp_align()?
If the device tree provides a flash-max-timeout-us less than 16 for the AAT1290, or 0 for the AAT1270, setting->min evaluates to 0. Since setting->step is assigned setting->min right below this, step also becomes 0.
When user-space writes to the flash_timeout sysfs attribute or triggers a strobe, will led_clamp_align() compute v % s->step and crash the kernel?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v2 3/3] leds: aat1290: Add support for AAT1270 Current Regulator for Flash LEDs
In reply to Svyatoslav RyhelHi Svyatoslav,
Thanks for the update.
Quoted 5 lines · Svyatoslav Ryhel
The AAT1270 is quite similar to the AAT1290, but it does not support the Advanced Simple Serial Control (AS2C) used in the AAT1290. The AAT1270 uses an earlier version of AS2C, namely Simple Serial Control, which lacks address-sending capabilities.
Quoted 8 lines
Differentiate the chips by using a description structure with a flag to indicate if AS2C is supported, Maximum Movie to Flash Mode Current ratio and if flash timeout is fixed by the hardware.
Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/leds/flash/leds-aat1290.c | 91 +++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 24 deletions(-)
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 1 line · Svyatoslav Ryhel
Document AAT1270 and FLINH pin, adjust driver to support AAT1270.
Applied, thanks!
[1/3] dt-bindings: leds: skyworks,aat1290: Document AAT1270 Current Regulator for Flash LEDs
commit: 9fe421537c14ed83d17edc8fcbd913833575ad67
[2/3] dt-bindings: leds: skyworks,aat1290: Document FLINH pin
commit: 8b81978dac2bb1cb260dd921b6b54d280f6c0557
[3/3] leds: aat1290: Add support for AAT1270 Current Regulator for Flash LEDs
commit: c4adf638e1663885e2b3b3cbdf7116c743150d4f--
Lee Jones [李琼斯]