Commit 30dae2f9 authored by Sebastian Reichel's avatar Sebastian Reichel Committed by Bryan Wu

leds: lp55xx: handle enable pin in driver

This patch moves the handling of the chip's enable pin from the board
code into the driver. It also updates all board-code files using the
driver to incorporate this change.

This is needed for device tree support of the enable pin.
Signed-off-by: default avatarSebastian Reichel <sre@debian.org>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarTony Lindgren <tony@atomide.com>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent b0bb83df
...@@ -10,6 +10,7 @@ Each child has own specific current settings ...@@ -10,6 +10,7 @@ Each child has own specific current settings
- max-cur: Maximun current at each led channel. - max-cur: Maximun current at each led channel.
Optional properties: Optional properties:
- enable-gpio: GPIO attached to the chip's enable pin
- label: Used for naming LEDs - label: Used for naming LEDs
- pwr-sel: LP8501 specific property. Power selection for output channels. - pwr-sel: LP8501 specific property. Power selection for output channels.
0: D1~9 are connected to VDD 0: D1~9 are connected to VDD
......
...@@ -211,29 +211,11 @@ static struct lp55xx_led_config rx51_lp5523_led_config[] = { ...@@ -211,29 +211,11 @@ static struct lp55xx_led_config rx51_lp5523_led_config[] = {
} }
}; };
static int rx51_lp5523_setup(void)
{
return gpio_request_one(RX51_LP5523_CHIP_EN_GPIO, GPIOF_DIR_OUT,
"lp5523_enable");
}
static void rx51_lp5523_release(void)
{
gpio_free(RX51_LP5523_CHIP_EN_GPIO);
}
static void rx51_lp5523_enable(bool state)
{
gpio_set_value(RX51_LP5523_CHIP_EN_GPIO, !!state);
}
static struct lp55xx_platform_data rx51_lp5523_platform_data = { static struct lp55xx_platform_data rx51_lp5523_platform_data = {
.led_config = rx51_lp5523_led_config, .led_config = rx51_lp5523_led_config,
.num_channels = ARRAY_SIZE(rx51_lp5523_led_config), .num_channels = ARRAY_SIZE(rx51_lp5523_led_config),
.clock_mode = LP55XX_CLOCK_AUTO, .clock_mode = LP55XX_CLOCK_AUTO,
.setup_resources = rx51_lp5523_setup, .enable_gpio = RX51_LP5523_CHIP_EN_GPIO,
.release_resources = rx51_lp5523_release,
.enable = rx51_lp5523_enable,
}; };
#endif #endif
......
...@@ -297,6 +297,7 @@ static struct lp55xx_platform_data __initdata lp5521_pri_data = { ...@@ -297,6 +297,7 @@ static struct lp55xx_platform_data __initdata lp5521_pri_data = {
.led_config = &lp5521_pri_led[0], .led_config = &lp5521_pri_led[0],
.num_channels = 3, .num_channels = 3,
.clock_mode = LP55XX_CLOCK_EXT, .clock_mode = LP55XX_CLOCK_EXT,
.enable_gpio = -1,
}; };
static struct lp55xx_led_config lp5521_sec_led[] = { static struct lp55xx_led_config lp5521_sec_led[] = {
...@@ -322,6 +323,7 @@ static struct lp55xx_platform_data __initdata lp5521_sec_data = { ...@@ -322,6 +323,7 @@ static struct lp55xx_platform_data __initdata lp5521_sec_data = {
.led_config = &lp5521_sec_led[0], .led_config = &lp5521_sec_led[0],
.num_channels = 3, .num_channels = 3,
.clock_mode = LP55XX_CLOCK_EXT, .clock_mode = LP55XX_CLOCK_EXT,
.enable_gpio = -1,
}; };
/* I2C0 devices only available on the first HREF/MOP500 */ /* I2C0 devices only available on the first HREF/MOP500 */
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_data/leds-lp55xx.h> #include <linux/platform_data/leds-lp55xx.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include "leds-lp55xx-common.h" #include "leds-lp55xx-common.h"
...@@ -407,18 +409,18 @@ int lp55xx_init_device(struct lp55xx_chip *chip) ...@@ -407,18 +409,18 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
if (!pdata || !cfg) if (!pdata || !cfg)
return -EINVAL; return -EINVAL;
if (pdata->setup_resources) { if (gpio_is_valid(pdata->enable_gpio)) {
ret = pdata->setup_resources(); ret = devm_gpio_request_one(dev, pdata->enable_gpio,
GPIOF_DIR_OUT, "lp5523_enable");
if (ret < 0) { if (ret < 0) {
dev_err(dev, "setup resoure err: %d\n", ret); dev_err(dev, "could not acquire enable gpio (err=%d)\n",
ret);
goto err; goto err;
} }
}
if (pdata->enable) { gpio_set_value(pdata->enable_gpio, 0);
pdata->enable(0);
usleep_range(1000, 2000); /* Keep enable down at least 1ms */ usleep_range(1000, 2000); /* Keep enable down at least 1ms */
pdata->enable(1); gpio_set_value(pdata->enable_gpio, 1);
usleep_range(1000, 2000); /* 500us abs min. */ usleep_range(1000, 2000); /* 500us abs min. */
} }
...@@ -459,11 +461,8 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip) ...@@ -459,11 +461,8 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip)
if (chip->clk) if (chip->clk)
clk_disable_unprepare(chip->clk); clk_disable_unprepare(chip->clk);
if (pdata->enable) if (gpio_is_valid(pdata->enable_gpio))
pdata->enable(0); gpio_set_value(pdata->enable_gpio, 0);
if (pdata->release_resources)
pdata->release_resources();
} }
EXPORT_SYMBOL_GPL(lp55xx_deinit_device); EXPORT_SYMBOL_GPL(lp55xx_deinit_device);
...@@ -596,6 +595,8 @@ int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np) ...@@ -596,6 +595,8 @@ int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np)
of_property_read_string(np, "label", &pdata->label); of_property_read_string(np, "label", &pdata->label);
of_property_read_u8(np, "clock-mode", &pdata->clock_mode); of_property_read_u8(np, "clock-mode", &pdata->clock_mode);
pdata->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);
/* LP8501 specific */ /* LP8501 specific */
of_property_read_u8(np, "pwr-sel", (u8 *)&pdata->pwr_sel); of_property_read_u8(np, "pwr-sel", (u8 *)&pdata->pwr_sel);
......
...@@ -67,10 +67,8 @@ struct lp55xx_platform_data { ...@@ -67,10 +67,8 @@ struct lp55xx_platform_data {
/* Clock configuration */ /* Clock configuration */
u8 clock_mode; u8 clock_mode;
/* Platform specific functions */ /* optional enable GPIO */
int (*setup_resources)(void); int enable_gpio;
void (*release_resources)(void);
void (*enable)(bool state);
/* Predefined pattern data */ /* Predefined pattern data */
struct lp55xx_predef_pattern *patterns; struct lp55xx_predef_pattern *patterns;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment