Commit bb982009 authored by Kim, Milo's avatar Kim, Milo Committed by Linus Torvalds

leds-lm3530: support pwm input mode

* add 'struct lm3530_pwm_data' in the platform data
  The pwm data is the platform specific functions which generate the pwm.
  The pwm data is only valid when brightness is pwm input mode.
  Functions should be implemented by the pwm driver.
  pwm_set_intensity() : set duty of pwm.
  pwm_get_intensity() : get current the brightness.

* brightness control by pwm
  If the control mode is pwm, then brightness is changed by the duty of
  pwm=.  So pwm platform function should be called in lm3530_brightness_set().

* do not update brightness register when pwm input mode
  In pwm input mode, brightness register is not used.
  If any value is updated in this register, then the led will be off.

* when input mode is changed, set duty of pwm to 0 if unnecessary.
Signed-off-by: default avatarMilo(Woogyom) Kim <milo.kim@ti.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e13d9786
...@@ -157,6 +157,7 @@ static int lm3530_init_registers(struct lm3530_data *drvdata) ...@@ -157,6 +157,7 @@ static int lm3530_init_registers(struct lm3530_data *drvdata)
u32 als_vmin, als_vmax, als_vstep; u32 als_vmin, als_vmax, als_vstep;
struct lm3530_platform_data *pltfm = drvdata->pdata; struct lm3530_platform_data *pltfm = drvdata->pdata;
struct i2c_client *client = drvdata->client; struct i2c_client *client = drvdata->client;
struct lm3530_pwm_data *pwm = &pltfm->pwm_data;
gen_config = (pltfm->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) | gen_config = (pltfm->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) |
((pltfm->max_current & 7) << LM3530_MAX_CURR_SHIFT); ((pltfm->max_current & 7) << LM3530_MAX_CURR_SHIFT);
...@@ -240,6 +241,15 @@ static int lm3530_init_registers(struct lm3530_data *drvdata) ...@@ -240,6 +241,15 @@ static int lm3530_init_registers(struct lm3530_data *drvdata)
} }
for (i = 0; i < LM3530_REG_MAX; i++) { for (i = 0; i < LM3530_REG_MAX; i++) {
/* do not update brightness register when pwm mode */
if (lm3530_reg[i] == LM3530_BRT_CTRL_REG &&
drvdata->mode == LM3530_BL_MODE_PWM) {
if (pwm->pwm_set_intensity)
pwm->pwm_set_intensity(reg_val[i],
drvdata->led_dev.max_brightness);
continue;
}
ret = i2c_smbus_write_byte_data(client, ret = i2c_smbus_write_byte_data(client,
lm3530_reg[i], reg_val[i]); lm3530_reg[i], reg_val[i]);
if (ret) if (ret)
...@@ -255,6 +265,9 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev, ...@@ -255,6 +265,9 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev,
int err; int err;
struct lm3530_data *drvdata = struct lm3530_data *drvdata =
container_of(led_cdev, struct lm3530_data, led_dev); container_of(led_cdev, struct lm3530_data, led_dev);
struct lm3530_platform_data *pdata = drvdata->pdata;
struct lm3530_pwm_data *pwm = &pdata->pwm_data;
u8 max_brightness = led_cdev->max_brightness;
switch (drvdata->mode) { switch (drvdata->mode) {
case LM3530_BL_MODE_MANUAL: case LM3530_BL_MODE_MANUAL:
...@@ -288,6 +301,8 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev, ...@@ -288,6 +301,8 @@ static void lm3530_brightness_set(struct led_classdev *led_cdev,
case LM3530_BL_MODE_ALS: case LM3530_BL_MODE_ALS:
break; break;
case LM3530_BL_MODE_PWM: case LM3530_BL_MODE_PWM:
if (pwm->pwm_set_intensity)
pwm->pwm_set_intensity(brt_val, max_brightness);
break; break;
default: default:
break; break;
...@@ -318,23 +333,24 @@ static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute ...@@ -318,23 +333,24 @@ static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute
{ {
struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct lm3530_data *drvdata; struct lm3530_data *drvdata;
struct lm3530_pwm_data *pwm;
u8 max_brightness;
int mode, err; int mode, err;
drvdata = container_of(led_cdev, struct lm3530_data, led_dev); drvdata = container_of(led_cdev, struct lm3530_data, led_dev);
pwm = &drvdata->pdata->pwm_data;
max_brightness = led_cdev->max_brightness;
mode = lm3530_get_mode_from_str(buf); mode = lm3530_get_mode_from_str(buf);
if (mode < 0) { if (mode < 0) {
dev_err(dev, "Invalid mode\n"); dev_err(dev, "Invalid mode\n");
return -EINVAL; return -EINVAL;
} }
if (mode == LM3530_BL_MODE_MANUAL) drvdata->mode = mode;
drvdata->mode = LM3530_BL_MODE_MANUAL;
else if (mode == LM3530_BL_MODE_ALS) /* set pwm to low if unnecessary */
drvdata->mode = LM3530_BL_MODE_ALS; if (mode != LM3530_BL_MODE_PWM && pwm->pwm_set_intensity)
else if (mode == LM3530_BL_MODE_PWM) { pwm->pwm_set_intensity(0, max_brightness);
dev_err(dev, "PWM mode not supported\n");
return -EINVAL;
}
err = lm3530_init_registers(drvdata); err = lm3530_init_registers(drvdata);
if (err) { if (err) {
......
...@@ -72,6 +72,12 @@ enum lm3530_als_mode { ...@@ -72,6 +72,12 @@ enum lm3530_als_mode {
LM3530_INPUT_CEIL, /* Max of ALS1 and ALS2 */ LM3530_INPUT_CEIL, /* Max of ALS1 and ALS2 */
}; };
/* PWM Platform Specific Data */
struct lm3530_pwm_data {
void (*pwm_set_intensity) (int brightness, int max_brightness);
int (*pwm_get_intensity) (int max_brightness);
};
/** /**
* struct lm3530_platform_data * struct lm3530_platform_data
* @mode: mode of operation i.e. Manual, ALS or PWM * @mode: mode of operation i.e. Manual, ALS or PWM
...@@ -87,6 +93,7 @@ enum lm3530_als_mode { ...@@ -87,6 +93,7 @@ enum lm3530_als_mode {
* @als_vmin: als input voltage calibrated for max brightness in mV * @als_vmin: als input voltage calibrated for max brightness in mV
* @als_vmax: als input voltage calibrated for min brightness in mV * @als_vmax: als input voltage calibrated for min brightness in mV
* @brt_val: brightness value (0-255) * @brt_val: brightness value (0-255)
* @pwm_data: PWM control functions (only valid when the mode is PWM)
*/ */
struct lm3530_platform_data { struct lm3530_platform_data {
enum lm3530_mode mode; enum lm3530_mode mode;
...@@ -107,6 +114,8 @@ struct lm3530_platform_data { ...@@ -107,6 +114,8 @@ struct lm3530_platform_data {
u32 als_vmax; u32 als_vmax;
u8 brt_val; u8 brt_val;
struct lm3530_pwm_data pwm_data;
}; };
#endif /* _LINUX_LED_LM3530_H__ */ #endif /* _LINUX_LED_LM3530_H__ */
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