aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--Documentation/backlight/lp855x-driver.txt10
-rw-r--r--drivers/video/backlight/lp855x_bl.c37
-rw-r--r--include/linux/platform_data/lp855x.h9
3 files changed, 30 insertions, 26 deletions
diff --git a/Documentation/backlight/lp855x-driver.txt b/Documentation/backlight/lp855x-driver.txt
index f5e4caafab7d..1529394cfe8b 100644
--- a/Documentation/backlight/lp855x-driver.txt
+++ b/Documentation/backlight/lp855x-driver.txt
@@ -35,11 +35,8 @@ For supporting platform specific data, the lp855x platform data can be used.
35* mode : Brightness control mode. PWM or register based. 35* mode : Brightness control mode. PWM or register based.
36* device_control : Value of DEVICE CONTROL register. 36* device_control : Value of DEVICE CONTROL register.
37* initial_brightness : Initial value of backlight brightness. 37* initial_brightness : Initial value of backlight brightness.
38* pwm_data : Platform specific pwm generation functions. 38* period_ns : Platform specific PWM period value. unit is nano.
39 Only valid when brightness is pwm input mode. 39 Only valid when brightness is pwm input mode.
40 Functions should be implemented by PWM driver.
41 - pwm_set_intensity() : set duty of PWM
42 - pwm_get_intensity() : get current duty of PWM
43* load_new_rom_data : 40* load_new_rom_data :
44 0 : use default configuration data 41 0 : use default configuration data
45 1 : update values of eeprom or eprom registers on loading driver 42 1 : update values of eeprom or eprom registers on loading driver
@@ -71,8 +68,5 @@ static struct lp855x_platform_data lp8556_pdata = {
71 .mode = PWM_BASED, 68 .mode = PWM_BASED,
72 .device_control = PWM_CONFIG(LP8556), 69 .device_control = PWM_CONFIG(LP8556),
73 .initial_brightness = INITIAL_BRT, 70 .initial_brightness = INITIAL_BRT,
74 .pwm_data = { 71 .period_ns = 1000000,
75 .pwm_set_intensity = platform_pwm_set_intensity,
76 .pwm_get_intensity = platform_pwm_get_intensity,
77 },
78}; 72};
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);
diff --git a/include/linux/platform_data/lp855x.h b/include/linux/platform_data/lp855x.h
index 761f31752367..e81f62d24ee2 100644
--- a/include/linux/platform_data/lp855x.h
+++ b/include/linux/platform_data/lp855x.h
@@ -89,11 +89,6 @@ enum lp8556_brightness_source {
89 LP8556_COMBINED2, /* pwm + i2c after the shaper block */ 89 LP8556_COMBINED2, /* pwm + i2c after the shaper block */
90}; 90};
91 91
92struct lp855x_pwm_data {
93 void (*pwm_set_intensity) (int brightness, int max_brightness);
94 int (*pwm_get_intensity) (int max_brightness);
95};
96
97struct lp855x_rom_data { 92struct lp855x_rom_data {
98 u8 addr; 93 u8 addr;
99 u8 val; 94 u8 val;
@@ -105,7 +100,7 @@ struct lp855x_rom_data {
105 * @mode : brightness control by pwm or lp855x register 100 * @mode : brightness control by pwm or lp855x register
106 * @device_control : value of DEVICE CONTROL register 101 * @device_control : value of DEVICE CONTROL register
107 * @initial_brightness : initial value of backlight brightness 102 * @initial_brightness : initial value of backlight brightness
108 * @pwm_data : platform specific pwm generation functions. 103 * @period_ns : platform specific pwm period value. unit is nano.
109 Only valid when mode is PWM_BASED. 104 Only valid when mode is PWM_BASED.
110 * @load_new_rom_data : 105 * @load_new_rom_data :
111 0 : use default configuration data 106 0 : use default configuration data
@@ -118,7 +113,7 @@ struct lp855x_platform_data {
118 enum lp855x_brightness_ctrl_mode mode; 113 enum lp855x_brightness_ctrl_mode mode;
119 u8 device_control; 114 u8 device_control;
120 int initial_brightness; 115 int initial_brightness;
121 struct lp855x_pwm_data pwm_data; 116 unsigned int period_ns;
122 u8 load_new_rom_data; 117 u8 load_new_rom_data;
123 int size_program; 118 int size_program;
124 struct lp855x_rom_data *rom_data; 119 struct lp855x_rom_data *rom_data;