auxdisplay: lcd2s: make use of device property API
PATCH 1/4 auxdisplay: lcd2s: make use of device property API
Make use of device property API in this driver so that both OF based system and ACPI based system can use this driver.
--- drivers/auxdisplay/lcd2s.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/auxdisplay/lcd2s.c +3 -5
@@ -12,7 +12,9 @@* All rights reserved. */ #include <linux/kernel.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> +#include <linux/property.h> #include <linux/slab.h> #include <linux/i2c.h> #include <linux/delay.h>
@@ -355,20 +357,16 @@ static const struct i2c_device_id lcd2s_i2c_id[] = { };MODULE_DEVICE_TABLE (i2c, lcd2s_i2c_id); -#ifdef CONFIG_OF static const struct of_device_id lcd2s_of_table[] = { { .compatible ="modtronix,lcd2s" }, { } };MODULE_DEVICE_TABLE (of, lcd2s_of_table); -#endif static struct i2c_driver lcd2s_i2c_driver = { .driver = { .name ="lcd2s" , -#ifdef CONFIG_OF - .of_match_table =of_match_ptr (lcd2s_of_table), -#endif + .of_match_table = lcd2s_of_table, }, .probe = lcd2s_i2c_probe, .remove = lcd2s_i2c_remove,
Signature · 1 line
2.34.1
PATCH 2/4 auxdisplay: lcd2s: use module_i2c_driver to simplify the code
Use the module_i2c_driver() macro to make the code smaller and a bit simpler.
--- drivers/auxdisplay/lcd2s.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)
drivers/auxdisplay/lcd2s.c +1 -18
@@ -372,24 +372,7 @@ static struct i2c_driver lcd2s_i2c_driver = { .remove = lcd2s_i2c_remove, .id_table = lcd2s_i2c_id, }; - -static int __init lcd2s_modinit (void ) -{ -int ret =0 ; - - ret =i2c_add_driver (&lcd2s_i2c_driver); -if (ret !=0 ) -pr_err ("Failed to register lcd2s driver\n" ); - -return ret; -} -module_init (lcd2s_modinit) - -static void __exit lcd2s_exit(void) -{ -i2c_del_driver (&lcd2s_i2c_driver); -} -module_exit(lcd2s_exit) +module_i2c_driver (lcd2s_i2c_driver);MODULE_DESCRIPTION ("LCD2S character display driver" );MODULE_AUTHOR ("Lars Poeschel" );
Signature · 1 line
2.34.1
PATCH 3/4 auxdisplay: lcd2s: Switch to i2c ->probe_new()
In reply to Andy ShevchenkoThe deprecated i2c ->probe() functionality doesn't work with OF compatible strings, as it only checks for the i2c device id. While it's not a problem right now, it would still bring a better code. Switch to the new way of probing.
--- drivers/auxdisplay/lcd2s.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/auxdisplay/lcd2s.c +2 -3
@@ -288,8 +288,7 @@ static const struct charlcd_ops lcd2s_ops = { .redefine_char = lcd2s_redefine_char, }; -static int lcd2s_i2c_probe (struct i2c_client *i2c, -const struct i2c_device_id *id) +static int lcd2s_i2c_probe (struct i2c_client *i2c) {struct charlcd *lcd;struct lcd2s_data *lcd2s;
@@ -368,7 +367,7 @@ static struct i2c_driver lcd2s_i2c_driver = { .name = "lcd2s", .of_match_table = lcd2s_of_table, }, - .probe = lcd2s_i2c_probe, + .probe_new = lcd2s_i2c_probe, .remove = lcd2s_i2c_remove, .id_table = lcd2s_i2c_id, };
Signature · 1 line
2.34.1
PATCH 4/4 auxdisplay: lcd2s: Use array size explicitly in lcd2s_gotoxy()
In reply to Andy ShevchenkoCurrently the reading of the onstack array is confusing since two out of three members are of different types. Let it be more clear by explicitly set the array size, so everybody will understand that parameters are cast to the type of the array.
While at it, add a missed space.
--- drivers/auxdisplay/lcd2s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/lcd2s.c +1 -1
@@ -106,7 +106,7 @@ static int lcd2s_print(struct charlcd *lcd, int c)static int lcd2s_gotoxy (struct charlcd *lcd,unsigned int x,unsigned int y) {struct lcd2s_data *lcd2s = lcd->drvdata; -u8 buf[] = {LCD2S_CMD_CUR_POS , y +1 , x +1 }; +u8 buf[3 ] = {LCD2S_CMD_CUR_POS , y +1 , x +1 };lcd2s_i2c_master_send (lcd2s->i2c, buf,sizeof (buf));
Signature · 1 line
2.34.1
Re: [PATCH v1 4/4] auxdisplay: lcd2s: Use array size explicitly in lcd2s_gotoxy()
Hi Andy,
Quoted 5 lines · Andy Shevchenko
Currently the reading of the onstack array is confusing since two out of three members are of different types. Let it be more clear by explicitly set the array size, so everybody will understand that parameters are cast to the type of the array.
I am not sure what you mean by this, could you please elaborate why is it more clear if the size is given?
Cheers,
Miguel
Re: [PATCH v1 4/4] auxdisplay: lcd2s: Use array size explicitly in lcd2s_gotoxy()
Quoted 10 lines · Miguel Ojeda
Quoted 5 lines · Andy Shevchenko
Currently the reading of the onstack array is confusing since two out of three members are of different types. Let it be more clear by explicitly set the array size, so everybody will understand that parameters are cast to the type of the array.
I am not sure what you mean by this, could you please elaborate why is it more clear if the size is given?
With [] and parameters not being bytes by type one needs an additional processing step to figure that out. When I see u8 ...[3] I immediately understand that there are 3 _bytes_. Moreover, [] is error prone when one may add something to the buffer with the expectation that it will work somehow (for example, with an old device you need 3, with new device revision you need 4 bytes and passing 4 bytes breaks the old device). Of course most of that quite likely won't happen.
If you think this change is not worth it, please, drop.
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v1 4/4] auxdisplay: lcd2s: Use array size explicitly in lcd2s_gotoxy()
Hi Andy,
Quoted 8 lines · Andy Shevchenko
With [] and parameters not being bytes by type one needs an additional processing step to figure that out. When I see u8 ...[3] I immediately understand that there are 3 _bytes_. Moreover, [] is error prone when one may add something to the buffer with the expectation that it will work somehow (for example, with an old device you need 3, with new device revision you need 4 bytes and passing 4 bytes breaks the old device). Of course most of that quite likely won't happen.
I agree it is better to be explicit -- I just found the commit message very confusing, i.e. the type will always be u8, what is unclear is the total length, not so much the type change.
I think the best approach when one needs an array to stay a particular size due to some external constraint (like hardware) would be to use a static_assert with a comment mentioning where the requirement comes from. Or at least a comment above the array.
Either way, I applied this one too to -next a few days ago. Thanks!
Cheers,
Miguel
Re: [PATCH v1 4/4] auxdisplay: lcd2s: Use array size explicitly in lcd2s_gotoxy()
Quoted 15 lines · Miguel Ojeda
Quoted 8 lines · Andy Shevchenko
With [] and parameters not being bytes by type one needs an additional processing step to figure that out. When I see u8 ...[3] I immediately understand that there are 3 _bytes_. Moreover, [] is error prone when one may add something to the buffer with the expectation that it will work somehow (for example, with an old device you need 3, with new device revision you need 4 bytes and passing 4 bytes breaks the old device). Of course most of that quite likely won't happen.
I agree it is better to be explicit -- I just found the commit message very confusing, i.e. the type will always be
u8, what is unclear is the total length, not so much the type change.
Quoted 6 lines
I think the best approach when one needs an array to stay a particular size due to some external constraint (like hardware) would be to use a
static_assertwith a comment mentioning where the requirement comes from. Or at least a comment above the array.Either way, I applied this one too to -next a few days ago. Thanks!
Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
Quoted 3 lines · Andy Shevchenko
Make use of device property API in this driver so that both OF based system and ACPI based system can use this driver.
I applied the series to -next, but for my understanding: the device property API was already being used, even if non-OF platforms couldn't use the driver before this patch, right? i.e. the commit message seems like the patch modified the calls.
Cheers,
Miguel
Quoted 10 lines · Miguel Ojeda
Quoted 3 lines · Andy Shevchenko
Make use of device property API in this driver so that both OF based system and ACPI based system can use this driver.
I applied the series to -next, but for my understanding: the device property API was already being used, even if non-OF platforms couldn't use the driver before this patch, right? i.e. the commit message seems like the patch modified the calls.
Not really. The device property supports the PRP0001 special ACPI device that makes use of OF matching mechanism (via usage of OF match table). Without above change when CONFIG_OF=n, this may not work. I.o.w. device properties per se in use, but the mechanism of matching is not working.
Signature · 2 lines
With Best Regards, Andy Shevchenko