aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight/lp855x_bl.c
diff options
context:
space:
mode:
authorKim, Milo <Milo.Kim@ti.com>2012-12-17 19:00:43 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-17 20:15:16 -0500
commit8cc9764c9c7d01a6e2c3ddac8f0ac7716be01868 (patch)
tree29a1e895f720dcd8ee969df19ba089401e870f8b /drivers/video/backlight/lp855x_bl.c
parent05a5d4d2640dfe934ec78ba577dd21baccb11aa6 (diff)
drivers/video/backlight/lp855x_bl.c: use generic PWM functions
The LP855x family devices support the PWM input for the backlight control. Period of the PWM is configurable in the platform side. Platform specific functions are unnecessary anymore because generic PWM functions are used inside the driver. (PWM input mode) To set the brightness, new lp855x_pwm_ctrl() is used. If a PWM device is not allocated, devm_pwm_get() is called. The PWM consumer name is from the chip name such as 'lp8550' and 'lp8556'. To get the brightness value, no additional handling is required. Just the value of 'props.brightness' is returned. If the PWM driver is not ready while initializing the LP855x driver, it's OK. The PWM device can be retrieved later, when the brightness value is changed. Documentation is updated with an example. [akpm@linux-foundation.org: coding-style simplification, per Thierry] Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Cc: Thierry Reding <thierry.reding@avionic-design.de> Cc: Richard Purdie <rpurdie@rpsys.net> Cc: Bryan Wu <bryan.wu@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/video/backlight/lp855x_bl.c')
-rw-r--r--drivers/video/backlight/lp855x_bl.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index fd985e0681e9..b437541555ff 100644
--- a/drivers/video/backlight/lp855x_bl.c
+++ b/drivers/video/backlight/lp855x_bl.c
@@ -15,6 +15,7 @@
15#include <linux/backlight.h> 15#include <linux/backlight.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/platform_data/lp855x.h> 17#include <linux/platform_data/lp855x.h>
18#include <linux/pwm.h>
18 19
19/* Registers */ 20/* Registers */
20#define BRIGHTNESS_CTRL 0x00 21#define BRIGHTNESS_CTRL 0x00
@@ -36,6 +37,7 @@ struct lp855x {
36 struct device *dev; 37 struct device *dev;
37 struct mutex xfer_lock; 38 struct mutex xfer_lock;
38 struct lp855x_platform_data *pdata; 39 struct lp855x_platform_data *pdata;
40 struct pwm_device *pwm;
39}; 41};
40 42
41static int lp855x_read_byte(struct lp855x *lp, u8 reg, u8 *data) 43static int lp855x_read_byte(struct lp855x *lp, u8 reg, u8 *data)
@@ -121,6 +123,28 @@ static int lp855x_init_registers(struct lp855x *lp)
121 return ret; 123 return ret;
122} 124}
123 125
126static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
127{
128 unsigned int period = lp->pdata->period_ns;
129 unsigned int duty = br * period / max_br;
130 struct pwm_device *pwm;
131
132 /* request pwm device with the consumer name */
133 if (!lp->pwm) {
134 pwm = devm_pwm_get(lp->dev, lp->chipname);
135 if (IS_ERR(pwm))
136 return;
137
138 lp->pwm = pwm;
139 }
140
141 pwm_config(lp->pwm, duty, period);
142 if (duty)
143 pwm_enable(lp->pwm);
144 else
145 pwm_disable(lp->pwm);
146}
147
124static int lp855x_bl_update_status(struct backlight_device *bl) 148static int lp855x_bl_update_status(struct backlight_device *bl)
125{ 149{
126 struct lp855x *lp = bl_get_data(bl); 150 struct lp855x *lp = bl_get_data(bl);
@@ -130,12 +154,10 @@ static int lp855x_bl_update_status(struct backlight_device *bl)
130 bl->props.brightness = 0; 154 bl->props.brightness = 0;
131 155
132 if (mode == PWM_BASED) { 156 if (mode == PWM_BASED) {
133 struct lp855x_pwm_data *pd = &lp->pdata->pwm_data;
134 int br = bl->props.brightness; 157 int br = bl->props.brightness;
135 int max_br = bl->props.max_brightness; 158 int max_br = bl->props.max_brightness;
136 159
137 if (pd->pwm_set_intensity) 160 lp855x_pwm_ctrl(lp, br, max_br);
138 pd->pwm_set_intensity(br, max_br);
139 161
140 } else if (mode == REGISTER_BASED) { 162 } else if (mode == REGISTER_BASED) {
141 u8 val = bl->props.brightness; 163 u8 val = bl->props.brightness;
@@ -150,14 +172,7 @@ static int lp855x_bl_get_brightness(struct backlight_device *bl)
150 struct lp855x *lp = bl_get_data(bl); 172 struct lp855x *lp = bl_get_data(bl);
151 enum lp855x_brightness_ctrl_mode mode = lp->pdata->mode; 173 enum lp855x_brightness_ctrl_mode mode = lp->pdata->mode;
152 174
153 if (mode == PWM_BASED) { 175 if (mode == REGISTER_BASED) {
154 struct lp855x_pwm_data *pd = &lp->pdata->pwm_data;
155 int max_br = bl->props.max_brightness;
156
157 if (pd->pwm_get_intensity)
158 bl->props.brightness = pd->pwm_get_intensity(max_br);
159
160 } else if (mode == REGISTER_BASED) {
161 u8 val = 0; 176 u8 val = 0;
162 177
163 lp855x_read_byte(lp, BRIGHTNESS_CTRL, &val); 178 lp855x_read_byte(lp, BRIGHTNESS_CTRL, &val);