- 
                Notifications
    
You must be signed in to change notification settings  - Fork 908
 
Add LTC3220 driver #3005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add LTC3220 driver #3005
Conversation
6a5debb    to
    d57b64f      
    Compare
  
            
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | } | ||
| 
               | 
          ||
| static ssize_t ltc3220_shutdown_store(struct device *dev, | ||
| struct device_attribute *devAttr, | 
There was a problem hiding this comment.
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
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | } | ||
| 
               | 
          ||
| static ssize_t ltc3220_force_cpo_2x_store(struct device *dev, | ||
| struct device_attribute *devAttr, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | } | ||
| 
               | 
          ||
| static ssize_t ltc3220_force_cpo_1p5x_store(struct device *dev, | ||
| struct device_attribute *devAttr, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | } | ||
| 
               | 
          ||
| static ssize_t ltc3220_quick_write_store(struct device *dev, | ||
| struct device_attribute *devAttr, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same above
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | } | ||
| 
               | 
          ||
| static int ltc3220_set_command(struct ltc3220_platform_data *platform_data, | ||
| bool is_shutdown, bool force2x, bool force1p5, bool quickWrite) | 
There was a problem hiding this comment.
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?
| 
           Could you format your commits so that there are spaces between labels? eg: 
 Additionally, could you add some more context regarding the commits? You can see more examples here: https://lore.kernel.org/linux-arm-kernel/  | 
    
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | #define LTC3220_ULED18 0x12 | ||
| #define LTC3220_GRAD_BLINK 0x13 | ||
| 
               | 
          ||
| static int ltc3220_write(struct i2c_client *client, u8 reg, u8 val) | 
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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.
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | { | ||
| int ret; | ||
| struct i2c_client *client = uled->client; | ||
| u8 reg_val = (mode << 6) | current_level; | 
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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 | 
There was a problem hiding this comment.
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
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | struct ltc3220_uled_cfg *uled_cfg; | ||
| 
               | 
          ||
| current_level = (int)brightness; | ||
| if (current_level > MAX_CURRENT) | 
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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!
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | 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; | 
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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 | 
There was a problem hiding this comment.
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 ?
There was a problem hiding this 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 | 
There was a problem hiding this comment.
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 | 
There was a problem hiding this comment.
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: | | 
There was a problem hiding this comment.
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 | 
There was a problem hiding this comment.
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: | | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop |
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | platform_data->led_cdev.groups = ltc3220_config_groups; | ||
| ret = devm_led_classdev_register_ext(&client->dev, | ||
| &platform_data->led_cdev, | ||
| &init_data_config); | 
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | return -ENOMEM; | ||
| } | ||
| 
               | 
          ||
| ltc3220_reset(platform_data); | 
There was a problem hiding this comment.
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.
        
          
                drivers/leds/leds-ltc3220.c
              
                Outdated
          
        
      | MODULE_AUTHOR("Edelweise Escala <edelweise.escala@analog.com>"); | ||
| MODULE_DESCRIPTION("LED driver for LTC3220 controllers"); | ||
| MODULE_LICENSE("GPL"); | ||
| MODULE_ALIAS("platform:leds-ltc3220"); | 
There was a problem hiding this comment.
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 */ | |||
There was a problem hiding this comment.
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 */ | 
There was a problem hiding this comment.
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>
PR Description
PR Type
PR Checklist