auxdisplay: ht16k33: Make use of device properties
Subsystems (2)
Geert Uytterhoeven
reviewerPATCH 1/1 auxdisplay: ht16k33: Make use of device properties
The device property API allows drivers to gather device resources from different sources, such as ACPI, and lift the dependency on Device Tree. Convert the driver to unleash the power of the device property API.
---
Compile-tested only for the !OF case.
This depends on "[PATCH v6 00/19] auxdisplay: ht16k33: Add character display support"
(https://lore.kernel.org/r/[email protected])
drivers/auxdisplay/Kconfig | 2 +- drivers/auxdisplay/ht16k33.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-)
drivers/auxdisplay/Kconfig +1 -1
@@ -169,7 +169,7 @@ config IMG_ASCII_LCD config HT16K33 tristate "Holtek Ht16K33 LED controller with keyscan" - depends on FB && OF && I2C && INPUT + depends on FB && I2C && INPUT select FB_SYS_FOPS select FB_SYS_FILLRECT select FB_SYS_COPYAREA
drivers/auxdisplay/ht16k33.c +11 -14
@@ -12,7 +12,7 @@#include <linux/module.h> #include <linux/interrupt.h> #include <linux/i2c.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/fb.h> #include <linux/slab.h> #include <linux/backlight.h>
@@ -481,15 +481,13 @@ static int ht16k33_led_probe(struct device *dev, struct led_classdev *led, unsigned int brightness) {struct led_init_data init_data = {}; -struct device_node *node;int err;/* The LED is optional */ - node =of_get_child_by_name (dev->of_node,"led" ); -if (!node) + init_data.fwnode =device_get_named_child_node (dev,"led" ); +if (!init_data.fwnode)return 0 ; - init_data.fwnode =of_fwnode_handle (node); init_data.devicename ="auxdisplay" ; init_data.devname_mandatory = true;
@@ -510,7 +508,6 @@ static int ht16k33_keypad_probe(struct i2c_client *client, struct ht16k33_keypad *keypad) {struct device *dev = &client->dev; -struct device_node *node = dev->of_node;u32 rows =HT16K33_MATRIX_KEYPAD_MAX_ROWS ;u32 cols =HT16K33_MATRIX_KEYPAD_MAX_COLS ;int err;
@@ -529,11 +526,11 @@ static int ht16k33_keypad_probe(struct i2c_client *client, keypad->dev->open = ht16k33_keypad_start; keypad->dev->close = ht16k33_keypad_stop; -if (!of_get_property (node,"linux,no-autorepeat" ,NULL )) +if (!device_property_present (dev,"linux,no-autorepeat" ))__set_bit (EV_REP , keypad->dev->evbit); - err =of_property_read_u32 (node,"debounce-delay-ms" , - &keypad->debounce_ms); + err =device_property_read_u32 (dev,"debounce-delay-ms" , + &keypad->debounce_ms);if (err) {dev_err (dev,"key debounce delay not specified\n" );return err;
@@ -620,8 +617,8 @@ static int ht16k33_fbdev_probe(struct device *dev, struct ht16k33_priv *priv, goto err_fbdev_buffer; } - err =of_property_read_u32 (dev->of_node,"refresh-rate-hz" , - &fbdev->refresh_rate); + err =device_property_read_u32 (dev,"refresh-rate-hz" , + &fbdev->refresh_rate);if (err) {dev_err (dev,"refresh rate not specified\n" ); goto err_fbdev_info;
@@ -727,8 +724,8 @@ static int ht16k33_probe(struct i2c_client *client)if (err)return err; - err =of_property_read_u32 (dev->of_node,"default-brightness-level" , - &dft_brightness); + err =device_property_read_u32 (dev,"default-brightness-level" , + &dft_brightness);if (err) { dft_brightness =MAX_BRIGHTNESS ; }else if (dft_brightness >MAX_BRIGHTNESS ) {
@@ -816,7 +813,7 @@ static struct i2c_driver ht16k33_driver = { .remove = ht16k33_remove, .driver = { .name = DRIVER_NAME, - .of_match_table = of_match_ptr(ht16k33_of_match), + .of_match_table = ht16k33_of_match, }, .id_table = ht16k33_i2c_match, };
Signature · 1 line
2.25.1
Quoted 4 lines · Geert Uytterhoeven
The device property API allows drivers to gather device resources from different sources, such as ACPI, and lift the dependency on Device Tree. Convert the driver to unleash the power of the device property API.
With or without the nit-pick below
Quoted 66 lines
Suggested-by Marek Behún <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>---
Compile-tested only for the !OF case.This depends on "[PATCH v6 00/19] auxdisplay: ht16k33: Add character display support"
(https://lore.kernel.org/r/[email protected])drivers/auxdisplay/Kconfig | 2 +- drivers/auxdisplay/ht16k33.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-)drivers/auxdisplay/Kconfig +1
-1@@ -169,7 +169,7 @@ config IMG_ASCII_LCD config HT16K33 tristate "Holtek Ht16K33 LED controller with keyscan" - depends on FB && OF && I2C && INPUT + depends on FB && I2C && INPUT select FB_SYS_FOPS select FB_SYS_FILLRECT select FB_SYS_COPYAREAdrivers/auxdisplay/ht16k33.c +3
-6@@ -12,7 +12,7 @@#include <linux/module.h> #include <linux/interrupt.h> #include <linux/i2c.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/fb.h> #include <linux/slab.h> #include <linux/backlight.h> @@ -481,15 +481,13 @@ static int ht16k33_led_probe(struct device *dev, struct led_classdev *led, unsigned int brightness) {struct led_init_data init_data = {}; -struct device_node *node;int err;/* The LED is optional */ - node =of_get_child_by_name (dev->of_node,"led" ); -if (!node) + init_data.fwnode =device_get_named_child_node (dev,"led" ); +if (!init_data.fwnode)return 0 ; - init_data.fwnode =of_fwnode_handle (node); init_data.devicename ="auxdisplay" ; init_data.devname_mandatory = true;@@ -510,7 +508,6 @@ static int ht16k33_keypad_probe(struct i2c_client *client, struct ht16k33_keypad *keypad) {struct device *dev = &client->dev; -struct device_node *node = dev->of_node;u32 rows =HT16K33_MATRIX_KEYPAD_MAX_ROWS ;u32 cols =HT16K33_MATRIX_KEYPAD_MAX_COLS ;int err;
drivers/auxdisplay/ht16k33.c static int ht16k33_keypad_probe(struct i2c_client *client, · line 529
Quoted 5 lines
drivers/auxdisplay/ht16k33.c +1
-1@@ -529,11 +526,11 @@ static int ht16k33_keypad_probe(struct i2c_client *client, keypad->dev->open = ht16k33_keypad_start; keypad->dev->close = ht16k33_keypad_stop; -if (!of_get_property (node,"linux,no-autorepeat" ,NULL )) +if (!device_property_present (dev,"linux,no-autorepeat" ))
If it's boolean property one may use device_property_read_bool()...
drivers/auxdisplay/ht16k33.c static int ht16k33_keypad_probe(struct i2c_client *client, · line 530
Quoted 1 line
drivers/auxdisplay/ht16k33.c +0
-0__set_bit (EV_REP , keypad->dev->evbit);
...or put it as a parameter to __assign_bit(), for example.
Quoted 42 lines
drivers/auxdisplay/ht16k33.c +7
-8- err =of_property_read_u32 (node,"debounce-delay-ms" , - &keypad->debounce_ms); + err =device_property_read_u32 (dev,"debounce-delay-ms" , + &keypad->debounce_ms);if (err) {dev_err (dev,"key debounce delay not specified\n" );return err;@@ -620,8 +617,8 @@ static int ht16k33_fbdev_probe(struct device *dev, struct ht16k33_priv *priv, goto err_fbdev_buffer; } - err =of_property_read_u32 (dev->of_node,"refresh-rate-hz" , - &fbdev->refresh_rate); + err =device_property_read_u32 (dev,"refresh-rate-hz" , + &fbdev->refresh_rate);if (err) {dev_err (dev,"refresh rate not specified\n" ); goto err_fbdev_info;@@ -727,8 +724,8 @@ static int ht16k33_probe(struct i2c_client *client)if (err)return err; - err =of_property_read_u32 (dev->of_node,"default-brightness-level" , - &dft_brightness); + err =device_property_read_u32 (dev,"default-brightness-level" , + &dft_brightness);if (err) { dft_brightness =MAX_BRIGHTNESS ; }else if (dft_brightness >MAX_BRIGHTNESS ) {@@ -816,7 +813,7 @@ static struct i2c_driver ht16k33_driver = { .remove = ht16k33_remove, .driver = { .name = DRIVER_NAME, - .of_match_table = of_match_ptr(ht16k33_of_match), + .of_match_table = ht16k33_of_match, }, .id_table = ht16k33_i2c_match, }; --2.25.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Robin van der Gracht
maintainerHi Geert,
As part of this change let's rename matrix_keypad_parse_of_params() to matrix_keypad_parse_properties() as well.
- Robin
Quoted 121 lines · Geert Uytterhoeven
The device property API allows drivers to gather device resources from different sources, such as ACPI, and lift the dependency on Device Tree. Convert the driver to unleash the power of the device property API.
Suggested-by Marek Behún <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>---
Compile-tested only for the !OF case.This depends on "[PATCH v6 00/19] auxdisplay: ht16k33: Add character display support"
(https://lore.kernel.org/r/[email protected])drivers/auxdisplay/Kconfig | 2 +- drivers/auxdisplay/ht16k33.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-)drivers/auxdisplay/Kconfig +1
-1@@ -169,7 +169,7 @@ config IMG_ASCII_LCD config HT16K33 tristate "Holtek Ht16K33 LED controller with keyscan" - depends on FB && OF && I2C && INPUT + depends on FB && I2C && INPUT select FB_SYS_FOPS select FB_SYS_FILLRECT select FB_SYS_COPYAREAdrivers/auxdisplay/ht16k33.c +1
-1@@ -12,7 +12,7 @@#include <linux/module.h> #include <linux/interrupt.h> #include <linux/i2c.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/fb.h> #include <linux/slab.h> #include <linux/backlight.h> @@ -481,15 +481,13 @@ static int ht16k33_led_probe(struct device *dev,struct
led_classdev*led,drivers/auxdisplay/ht16k33.c +2
-5unsigned int brightness) {struct led_init_data init_data = {}; -struct device_node *node;int err;/* The LED is optional */ - node =of_get_child_by_name (dev->of_node,"led" ); -if (!node) + init_data.fwnode =device_get_named_child_node (dev,"led" ); +if (!init_data.fwnode)return 0 ; - init_data.fwnode =of_fwnode_handle (node); init_data.devicename ="auxdisplay" ; init_data.devname_mandatory = true;@@ -510,7 +508,6 @@ static int ht16k33_keypad_probe(struct i2c_client *client, struct ht16k33_keypad *keypad) {struct device *dev = &client->dev; -struct device_node *node = dev->of_node;u32 rows =HT16K33_MATRIX_KEYPAD_MAX_ROWS ;u32 cols =HT16K33_MATRIX_KEYPAD_MAX_COLS ;drivers/auxdisplay/ht16k33.c +3
-3int err;@@ -529,11 +526,11 @@ static int ht16k33_keypad_probe(struct i2c_client *client, keypad->dev->open = ht16k33_keypad_start; keypad->dev->close = ht16k33_keypad_stop; -if (!of_get_property (node,"linux,no-autorepeat" ,NULL )) +if (!device_property_present (dev,"linux,no-autorepeat" ))__set_bit (EV_REP , keypad->dev->evbit); - err =of_property_read_u32 (node,"debounce-delay-ms" , - &keypad->debounce_ms); + err =device_property_read_u32 (dev,"debounce-delay-ms" , + &keypad->debounce_ms);if (err) {dev_err (dev,"key debounce delay not specified\n" );drivers/auxdisplay/ht16k33.c +0
-0return err;@@ -620,8 +617,8 @@ static int ht16k33_fbdev_probe(struct device *dev,struct
ht16k33_priv*priv,drivers/auxdisplay/ht16k33.c +5
-5goto err_fbdev_buffer; } - err =of_property_read_u32 (dev->of_node,"refresh-rate-hz" , - &fbdev->refresh_rate); + err =device_property_read_u32 (dev,"refresh-rate-hz" , + &fbdev->refresh_rate);if (err) {dev_err (dev,"refresh rate not specified\n" ); goto err_fbdev_info;@@ -727,8 +724,8 @@ static int ht16k33_probe(struct i2c_client *client)if (err)return err; - err =of_property_read_u32 (dev->of_node,"default-brightness-level" , - &dft_brightness); + err =device_property_read_u32 (dev,"default-brightness-level" , + &dft_brightness);if (err) { dft_brightness =MAX_BRIGHTNESS ; }else if (dft_brightness >MAX_BRIGHTNESS ) {@@ -816,7 +813,7 @@ static struct i2c_driver ht16k33_driver = { .remove = ht16k33_remove, .driver = { .name = DRIVER_NAME, - .of_match_table = of_match_ptr(ht16k33_of_match), + .of_match_table = ht16k33_of_match, }, .id_table = ht16k33_i2c_match, };