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

}

static ssize_t ltc3220_shutdown_store(struct device *dev,
struct device_attribute *devAttr,

Choose a reason for hiding this comment

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

devAttr is in camel case can you fix to match Linux Kernel style

}

static ssize_t ltc3220_force_cpo_2x_store(struct device *dev,
struct device_attribute *devAttr,

Choose a reason for hiding this comment

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

same as above

}

static ssize_t ltc3220_force_cpo_1p5x_store(struct device *dev,
struct device_attribute *devAttr,

Choose a reason for hiding this comment

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

same as above

}

static ssize_t ltc3220_quick_write_store(struct device *dev,
struct device_attribute *devAttr,

Choose a reason for hiding this comment

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

same above

}

static int ltc3220_set_command(struct ltc3220_platform_data *platform_data,
bool is_shutdown, bool force2x, bool force1p5, bool quickWrite)

Choose a reason for hiding this comment

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

quickWrite is in camel case can you fix it according to Linux Kernel styling guide?

@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/

#define LTC3220_ULED18 0x12
#define LTC3220_GRAD_BLINK 0x13

static int ltc3220_write(struct i2c_client *client, u8 reg, u8 val)

Choose a reason for hiding this comment

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

Do we need another function call for this? I dont see any extra handling being done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. I don't see any real benefit in these wrappers. I would also see if regmap is a possibility

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.

{
int ret;
struct i2c_client *client = uled->client;
u8 reg_val = (mode << 6) | current_level;

Choose a reason for hiding this comment

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

This could overflow. Masking can prevent that. e.g. u8 reg_val = ((mode & 0x03) << 6) | (current_level & 0x3F);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, as I said in another comment I would just consider FIELD_PREP()


#define NUM_LEDS 18

#define MAX_CURRENT 64

Choose a reason for hiding this comment

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

Not sure about this one, but isn't it a 6-bit field? If so, it should be 0-63 so, #define MAX_CURRENT 63

struct ltc3220_uled_cfg *uled_cfg;

current_level = (int)brightness;
if (current_level > MAX_CURRENT)

Choose a reason for hiding this comment

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

You know the code way better than I do, but shouldn't that be an error? If it's fine to continue with current capped at max, at least a dev_info should be printed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure either, some subsystems (like hwmon) don't consider these stuff as hard errors and just tell you to do clamp()

Copy link
Author

Choose a reason for hiding this comment

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

I will be removing this, upon checking led subsystem already caps the value to the max if the user inputs a value exceeding the max. Thank you!

platform_data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(platform_data->reset_gpio)) {
dev_err(&client->dev, "Fail to set reset GPIO\n");
return -ENOMEM;

Choose a reason for hiding this comment

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

since IS_ERR() has returned an error, you should pass it on instead of hardcoding ENOMEM, ie PTR_ERR(platform_data->reset_gpio);

Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact, return dev_err_probe(dev, PTR_ERR(platform_data->reset_gpio), ...);

#ifndef __LINUX_I2C_LTC3220_H
#define __LINUX_I2C_LTC3220_H

#define NUM_LEDS 18
Copy link

@CalebEthridgeADI CalebEthridgeADI Oct 31, 2025

Choose a reason for hiding this comment

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

Can you add a LTC3220 prefix before these defines like you do in leds-ltc3220.c i.e LTC3220_NUM_LEDS ?

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.

compatible:
enum:
- lltc,ltc3220
- lltc,ltc3220-1
Copy link
Collaborator

Choose a reason for hiding this comment

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

adi, now 😉

description: |
I2C slave address
0x1c for ltc3220
0x1d for ltc3220-1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Drop the description here. It is already obvious

maintainers:
- Edelweise Escala <edelweise.escala@analog.com>

description: |
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for | formatting

reset-gpios:
maxItems: 1
description: |
GPIO attached to the chip's reset pin
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto about the description

$ref: common.yaml#
properties:
reg:
description: |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Drop |

platform_data->led_cdev.groups = ltc3220_config_groups;
ret = devm_led_classdev_register_ext(&client->dev,
&platform_data->led_cdev,
&init_data_config);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the above about? Is it like device level settings instead of individual LED settings?

Copy link
Author

Choose a reason for hiding this comment

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

It is like device level settings

return -ENOMEM;
}

ltc3220_reset(platform_data);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is typically done in the beginning. In fact, this is bogus... Note that you're doing this after calling devm_led_classdev_register_ext() which will expose the userspace interfaces. So, effectively you can now race against userspace in a way that userspace does some configuration and then a reset happens.

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

@@ -0,0 +1,64 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use only GPL2

struct gpio_desc *reset_gpio;
};

#endif /* __LINUX_I2C_LTC3220_H */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please drop the header file and move it to the source code. This is not supposed to be shared with any other source file AFAICT. Also, drop platform_data from the struct. Just name it struct ltc3220 or struct ltc3220_state. Platform data reference a very old way of doing things that is no longer used

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

Signed-off-by: edelweiseescala <edelweise.escala@analog.com>
Add documentation for different Custom ABI added for LTC3220.

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

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

Signed-off-by: edelweiseescala <edelweise.escala@analog.com>
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.

6 participants