Skip to content

Commit

Permalink
leds: bd2802: Convert to use GPIO descriptors
Browse files Browse the repository at this point in the history
The Rohm BD2802 have no in-kernel users so we can drop the
GPIO number from the platform data and require users to
provide the GPIO line using machine descriptors.

As the descriptors come with inherent polarity inversion
semantics, we invert the calls to set the GPIO line such
that 0 means "unasserted" and 1 means "asserted".

Put a note in the driver that machine descriptor tables
will need to specify that the line is active low.

Cc: Kim Kyuwon <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
Signed-off-by: Pavel Machek <[email protected]>
  • Loading branch information
linusw authored and pavelmachek committed Dec 21, 2019
1 parent 6975290 commit 4c3718f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
27 changes: 18 additions & 9 deletions drivers/leds/leds-bd2802.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
#include <linux/leds.h>
#include <linux/leds-bd2802.h>
Expand Down Expand Up @@ -67,6 +67,7 @@ struct led_state {
struct bd2802_led {
struct bd2802_led_platform_data *pdata;
struct i2c_client *client;
struct gpio_desc *reset;
struct rw_semaphore rwsem;

struct led_state led[2];
Expand Down Expand Up @@ -200,7 +201,7 @@ static void bd2802_update_state(struct bd2802_led *led, enum led_ids id,
return;

if (bd2802_is_all_off(led) && !led->adf_on) {
gpio_set_value(led->pdata->reset_gpio, 0);
gpiod_set_value(led->reset, 1);
return;
}

Expand All @@ -226,7 +227,7 @@ static void bd2802_configure(struct bd2802_led *led)

static void bd2802_reset_cancel(struct bd2802_led *led)
{
gpio_set_value(led->pdata->reset_gpio, 1);
gpiod_set_value(led->reset, 0);
udelay(100);
bd2802_configure(led);
}
Expand Down Expand Up @@ -420,7 +421,7 @@ static void bd2802_disable_adv_conf(struct bd2802_led *led)
bd2802_addr_attributes[i]);

if (bd2802_is_all_off(led))
gpio_set_value(led->pdata->reset_gpio, 0);
gpiod_set_value(led->reset, 1);

led->adf_on = 0;
}
Expand Down Expand Up @@ -670,8 +671,16 @@ static int bd2802_probe(struct i2c_client *client,
pdata = led->pdata = dev_get_platdata(&client->dev);
i2c_set_clientdata(client, led);

/* Configure RESET GPIO (L: RESET, H: RESET cancel) */
gpio_request_one(pdata->reset_gpio, GPIOF_OUT_INIT_HIGH, "RGB_RESETB");
/*
* Configure RESET GPIO (L: RESET, H: RESET cancel)
*
* We request the reset GPIO as OUT_LOW which means de-asserted,
* board files specifying this GPIO line in a machine descriptor
* table should take care to specify GPIO_ACTIVE_LOW for this line.
*/
led->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(led->reset))
return PTR_ERR(led->reset);

/* Tacss = min 0.1ms */
udelay(100);
Expand All @@ -685,7 +694,7 @@ static int bd2802_probe(struct i2c_client *client,
dev_info(&client->dev, "return 0x%02x\n", ret);

/* To save the power, reset BD2802 after detecting */
gpio_set_value(led->pdata->reset_gpio, 0);
gpiod_set_value(led->reset, 1);

/* Default attributes */
led->wave_pattern = BD2802_PATTERN_HALF;
Expand Down Expand Up @@ -720,7 +729,7 @@ static int bd2802_remove(struct i2c_client *client)
struct bd2802_led *led = i2c_get_clientdata(client);
int i;

gpio_set_value(led->pdata->reset_gpio, 0);
gpiod_set_value(led->reset, 1);
bd2802_unregister_led_classdev(led);
if (led->adf_on)
bd2802_disable_adv_conf(led);
Expand Down Expand Up @@ -750,7 +759,7 @@ static int bd2802_suspend(struct device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct bd2802_led *led = i2c_get_clientdata(client);

gpio_set_value(led->pdata->reset_gpio, 0);
gpiod_set_value(led->reset, 1);

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion include/linux/leds-bd2802.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define _LEDS_BD2802_H_

struct bd2802_led_platform_data{
int reset_gpio;
u8 rgb_time;
};

Expand Down

0 comments on commit 4c3718f

Please sign in to comment.