Skip to content

Conversation

@edelweiseescala
Copy link

PR Description

  • Add LTC3220 driver and documentation.
  • Datasheet: LTC3220
  • Tested on RPI4 using the following eval boards: DC1265A-A, DC1265A-B

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have compiled my changes, including the documentation
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly
  • I have provided links for the relevant upstream lore

@UtsavAgarwalADI
Copy link

Could you format your commits so that there are spaces between labels? eg:

arm64:defconfig:xyz
arm64: defconfig: xyz

Additionally, could you add some more context regarding the commits?

You can see more examples here: https://lore.kernel.org/linux-arm-kernel/

Copy link

@vasbimpikasadi vasbimpikasadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shows great effort! It's a bit sparse on comments and I've noted some changes which I think have to be fixed before this gets approved.

Copy link
Collaborator

@nunojsa nunojsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round from me. This one will need some iterations before going upstream. I'm also not that familiar with the LED subsystem so I might give it a look at some point to be more helpful.

MODULE_AUTHOR("Edelweise Escala <edelweise.escala@analog.com>");
MODULE_DESCRIPTION("LED driver for LTC3220 controllers");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:leds-ltc3220");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically not used anymore

@edelweiseescala edelweiseescala marked this pull request as draft November 4, 2025 06:27
@edelweiseescala edelweiseescala force-pushed the main branch 2 times, most recently from d01ee06 to b251647 Compare November 4, 2025 08:46
@edelweiseescala
Copy link
Author

V2 Changelog:

dt-bindings: leds: ltc3220: Document LTC3220 18 channel LED Driver
-used adi
-dropped unnecessary descriptions
-dropped | formatting
-fixed led pattern

leds: ltc3220: add driver
-Fix naming which does not follow Linux convention, also fixed naming for defines with onw LTC3220 prefix. Follow kernel style
-Remove unnecessary headers, and fixed header arrangement
-Remove unnecessary functions (ltc3220_write)
-Used FIELD_PREP()
-Use firmware agnostic properties
-Use only GPL2
-Led brightness now uses ltc3220_set_led_data
Instead of 0-63 current level it is now 0-255 where in
0-63 - normal LED mode
64-127 - blink mode
127-191 - gradation mode
191-255 - GPO
this removes the need for another custom ABI for individual led mode.

Added leds: ltc3220: Documentation for Custom ABI
-documentation for the added custom ABI

@edelweiseescala edelweiseescala marked this pull request as ready for review November 4, 2025 10:48
@edelweiseescala
Copy link
Author

V3 Changelog:

fixed wrong files on commit

dt-bindings: leds: ltc3220: Document LTC3220 18 channel LED Driver
-fixed example format

leds: ltc3220: add driver
-used fsleep for reset
-fixed log message

leds: ltc3220: Documentation for Custom ABI
-add newline at EOF

Copy link
Contributor

@machschmitt machschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @edelweiseescala,

A few comments from my side.
Besides the code changes, I'd suggest to also update your SoB tag with better wording of your name.

required:
- compatible
- reg
- reset-gpios
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not common for chips to require a reset. Does the device really fail to work or not function without a hardware reset? It is often nice to do a reset before start managing a device. Though, if it can be operated without a reset, I'd drop the reset-gpios requirement.


What: /sys/class/leds/<led>/force_cpo_mode
Date: November 2025
Contact: Edelweise Escala <edelweise.escala@analog.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here and in the other doc entries.

#define LTC3220_ULED18 0x12
#define LTC3220_GRAD_BLINK 0x13

#define LTC3220_BIT0 BIT(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a reviewer, I don't think this define helped much in understanding the code.
I'd either drop it and use BIT(0) in place, or separate and give more meaningful names. e.g.

#define LTC3220_GRAD_COUNT_UP			BIT(0)

#define LTC3220_COMMAND_QUICK_WRITE			BIT(0)

Comment on lines 89 to 90
struct led_classdev led_cdev;
struct device *dev;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these led_cdev and *dev fields not used?

if (ret)
return ret;

device_for_each_child_node(&client->dev, child) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use device_for_each_child_node_scoped(), then no need for fwnode_handle_put().

Comment on lines 475 to 482
if (ret != 0 || !source || source > LTC3220_NUM_LEDS) {
dev_err(&client->dev, "Couldn't read LED address: %d\n",
ret);
fwnode_handle_put(child);
return -ENOMEM;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that all leds are required? Are all LEDs required? If not, I'd dev_war() and continue; instead of returning error.

@edelweiseescala edelweiseescala force-pushed the main branch 3 times, most recently from 80d038e to 03f6cf2 Compare November 13, 2025 08:20
@edelweiseescala
Copy link
Author

V4 Changelog:

fixed name on SoB

dt-bindings: leds: ltc3220: Document LTC3220 18 channel LED Driver
-removed reset on rquired
-made reset-gpio property clearer

leds: ltc3220: add driver
-use more meaningful bit name
-removed unused fields
-use device_for_each_child_node_scoped
-add some comments
-dropped i2c client on leds, used i2c leint on ltc3220_state struct

leds: ltc3220: Documentation for Custom ABI
-add kernel version

0 - Enables mode logic to control mode changes based on dropout signal
1 - Forces charge pump into 1.5x mode
2 - Forces charge pump into 2x mode
3 - Forces charge pump into 1x mode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this one seems something HW specific? Is this something that should change at runtime? If I'm right, consider a devicetree attr

Contact: Edelweise Escala <edelweise.escala@analog.com>
Description: LTC3220 shutdown command. If you write 1 it
shuts down part while preserving data in registers.
If you write 0 device is in normal operation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something you should implement under PM (Power management). Either runtime PM or normal suspend. Pick one :)

which allows parallel write on all 18 LED registers, when data is being written on
REG1. If you write 1 quick_write is enabled, 0 to disable.

What: /sys/class/leds/<led>/gradation_speed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this one could be better named gradation_period_ms. Then you would actually pass the period in milliseconds which is a better API for the user. This is possible because we have three distinct periods which match 3 distinct ramp times.

2 - Ramp time of 0.48s and Period of 0.625s
3 - Ramp time of 0.96s and Period of 1.25s

What: /sys/class/leds/<led>/gradation_is_increasing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one I would suggest gradation_mode and accept the strings "ramp_up" and "ramp_down". From the IIO world you could also add an additional gradation_mode_available which would be on RO and you would give the user the available possibilities. An example for debugfs:

https://elixir.bootlin.com/linux/v6.18-rc5/source/drivers/iio/adc/ad9467.c#L998

Here you need something different likely

(0..3) where:
0 - On Time of 0.625s and Period of 1.25s
1 - On Time of 0.156s and Period of 1.25s
2 - On Time of 0.625s and Period of 2.5s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow implement this with?

https://elixir.bootlin.com/linux/v6.18-rc5/source/include/linux/leds.h#L154

Make sure to look at other drivers and the subsystem to see what can be used.

ret = ltc3220_set_blink_and_gradation(ltc3220_state,
state,
ltc3220_state->grad_cfg.gradation_speed,
ltc3220_state->grad_cfg.is_increasing);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above looks very bad

&dev_attr_gradation_is_increasing.attr,
&dev_attr_blink_cfg.attr,
NULL
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be prepared to justify these attributes... I'm still not sure about it

ltc3220_gradation_is_increasing_store);

static ssize_t ltc3220_blink_cfg_show(struct device *dev,
struct device_attribute *attr, char *buf)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take care about the above


ret = ltc3220_set_blink_and_gradation(ltc3220_state,
ltc3220_state->blink_cfg,
ltc3220_state->grad_cfg.gradation_speed,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

ret = ltc3220_set_blink_and_gradation(ltc3220_state,
ltc3220_state->blink_cfg,
state,
ltc3220_state->grad_cfg.is_increasing);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to fix things like the above (unless my github is rendering this in a very odd way)

@edelweiseescala
Copy link
Author

V5 Changelog:

dt-bindings: leds: ltc3220: Document LTC3220 18 channel LED Driver
-added quick write and force charge pump on device tree

leds: ltc3220: add driver
-styling fixes
-used led blink
-add missing headers
-dropped reset_gpio on struct and added it on reset function instead
-added missing error handling on reset
-modified gradation increasing to accept string ramp up or ramp down
-change gradation_speed to gradation_period_ms which takes period in ms as input

leds: ltc3220: Documentation for Custom ABI
-removed quick write and force charge pump
-renamed gradation speed
-added gradation_mode_available

@edelweiseescala edelweiseescala marked this pull request as ready for review November 14, 2025 10:03
Copy link

@vasbimpikasadi vasbimpikasadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting really better, loads of great feedback from everyone. This is shaping up quite nicely.


ltc3220_state = devm_kzalloc(&client->dev, sizeof(*ltc3220_state), GFP_KERNEL);
if (!ltc3220_state)
return -ENODEV;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory allocation failure should return -ENOMEM, not -ENODEV

&init_data);
if (ret) {
dev_err(&client->dev, "Fail LED class register\n");
return -ENOMEM;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ret should be propagated here to aid root causing issues should things go wrong?

NULL
};

static struct attribute_group device_cfg_group = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be const? It's never modified during runtime

@edelweiseescala
Copy link
Author

V6 Changelog:

leds: ltc3220: add driver
-fix returned error
-added const on device_cfg_group

led@6 {
reg = <6>;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have some of the properties coming from common.yaml that the device supports. Otherwise I wonder why we $ref it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added function and function-enumerator.

Contact: Edelweise Escala <edelweise.escala@analog.com>
Description: LTC3220 read only command to show possible gradiation mode such as:
"ramp_up"
"ramp_down"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure about the above ABI. Does it make sense to have these as runtime? I'm tempted to suggest DT but you might see what the maintainer has to say about it. Maybe there's already a way to handle it through the subsystem.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

ret = devm_device_add_group(&client->dev, &device_cfg_group);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just return devm_device_add_group()

&init_data);
if (ret) {
dev_err(&client->dev, "Fail LED class register\n");
return ret;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev_err_probe()

int ret;

if (!led_cdev->dev || !led_cdev->dev->parent)
return -ENODEV;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would double check the above can really happen. If it can, maybe it's a problem on subsystem itself

return -ENODEV;

if (!parent_dev || strcmp(parent_dev->bus->name, "i2c") != 0)
return -ENODEV;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, all of the above conditions look questionable to me


client = to_i2c_client(parent_dev);
uled_cfg = container_of(led_cdev, struct ltc3220_uled_cfg, led_cdev);
ltc3220_state = i2c_get_clientdata(client);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use container_of() to get ltc3220_state from uled_cfg assuming led_index is the position in the uled_cfg array. But still why not making easier and just have a pointer to the main ltc3220_state object from uled_cfg? Then you would just need two lines.

break;
}

return sysfs_emit(buf, "%u\n", period_ms);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not returning inline in each case statement? I would save some LOC

}

static ssize_t ltc3220_gradation_period_ms_show(struct device *dev,
struct device_attribute *attr, char *buf)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd indentation

Add dt-binding for ltc3220. LTC3220 18 Channel LED driver

Signed-off-by: Edelweise Escala <edelweise.escala@analog.com>
Add driver for ltc3220. LTC3220 18 Channel LED Driver

Signed-off-by: Edelweise Escala <edelweise.escala@analog.com>
Add entry for LTC3220 driver

Signed-off-by: Edelweise Escala <edelweise.escala@analog.com>
@edelweiseescala
Copy link
Author

V7 Changelog

Documentation/devicetree/bindings/leds/leds-ltc3220.yaml
-used Minimum:1 and Maximum:18 rathern than Enum
-added properties from common.yaml

Removed Custom ABI

drivers/leds/leds-ltc3220.c
-used dev_err_probe for errors in probe
-added struct ltc3220_state on uled_cfg
-removed default_label and just rely on device tree for the name
-fixed reset function
-remove gradation custom abi and used pattern_set to handle gradation

Copy link
Contributor

@machschmitt machschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, this is my second round of review.

Besides the comments to the code, I'd also suggest to drop the "ltc3220:" part of
"dt-bindings: leds: ltc3220: Document LTC3220 18 channel LED Driver".
ltc3220 doesn't exist in the kernel, yet.

Comment on lines +36 to +46
adi,force-cpo-mode:
$ref: /schemas/types.yaml#/definitions/uint32
description:
Force charge pump operation mode.
0 = Auto mode (default) - Automatically selects optimal charge pump mode
1 = 1.5x mode - 1.5x voltage multiplication
2 = 2x mode - 2x voltage multiplication
3 = 1x mode - Charge pump bypass
minimum: 0
maximum: 3
default: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this similar to LTC3208 force-cpo-mode ?
b087967#diff-abf16a96d0bb11e1c9ed3b93a7bf72cbd73355ea1d4c95ae5c5bf4df79fcd49dR46
Looks like it is. My suggestion is to make LTC3220 and LTC3208 have the same documentation for their charge pump properties. Also, I'd suggest making it a string like in LTC3208 PR. Sometimes we might be tempted to use integers to simplify the property description and make the value writable to device registers. Though, frequently, new devices are released with a similar feature and different values and register configurations. Leading to different (but similar in semantics) properties with specific sets of allowed values that don't do any favor to dts writers. A string will allow describing any new charge pump configuration with adi,force-cpo-mode (or adi,force-cpo-level, whatever is more comprehensive) with a reasonable property value.

Comment on lines +48 to +52
adi,quick-write-enable:
type: boolean
description:
Enable quick write mode. When enabled, writing to LED D1 (register 0x01)
will update all 18 LED outputs with the same brightness value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see why this needs to be in device tree. To me, this sounds more like a device runtime configuration property. What about registering a 19th led? Set led_classdev name to "all". At some point during probe, do something like

		ltc3220_state->uled_cfg[<19 or last led index>].led_cdev.name = "all";
		ltc3220_state->uled_cfg[i].led_cdev.brightness_set_blocking = ltc3220_set_all_led_data;

with ltc3220_set_all_led_data doing the same thing as ltc3220_set_led_data, but with is_quick_write always true.

Comment on lines +383 to +384
return dev_err_probe(&client->dev, -ENOMEM,
"Failed to allocate memory\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the IIO subsystem people usually just return -ENOMEM in these cases. IIRC, trying to print a message would be of no use if the system is already lacking memory.

Comment on lines +394 to +397
ret = device_property_read_u8(&client->dev, "adi,force-cpo-mode",
&ltc3220_state->command_cfg.force_cpo_mode);
if (ret)
ltc3220_state->command_cfg.force_cpo_mode = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you follow my suggestion and make adi,force-cpo-mode a string, use device_property_match_property_string() to simplify the property parsing.

Comment on lines +404 to +405
if (device_property_read_bool(&client->dev, "adi,quick-write-enable"))
ltc3220_state->command_cfg.is_quick_write = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might hopefully be dropped (see comment in device tree doc).

Comment on lines +145 to +147
u8 reg_val;
int ret;
struct i2c_client *client = ltc3220_state->client;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally like arranging local variables in reverse xmas tree. Don't know how LED subsystem maintainer might prefer those, though.

Comment on lines +21 to +38
#define LTC3220_ULED01 0x01
#define LTC3220_ULED02 0x02
#define LTC3220_ULED03 0x03
#define LTC3220_ULED04 0x04
#define LTC3220_ULED05 0x05
#define LTC3220_ULED06 0x06
#define LTC3220_ULED07 0x07
#define LTC3220_ULED08 0x08
#define LTC3220_ULED09 0x09
#define LTC3220_ULED10 0x0A
#define LTC3220_ULED11 0x0B
#define LTC3220_ULED12 0x0C
#define LTC3220_ULED13 0x0D
#define LTC3220_ULED14 0x0E
#define LTC3220_ULED15 0x0F
#define LTC3220_ULED16 0x10
#define LTC3220_ULED17 0x11
#define LTC3220_ULED18 0x12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest
#define LTC3220_ULED(x) (x)
but these seem to have not been used?
If these are really not used, then I suggest to drop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants