eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/backlight/pwm_bl.c |
| 3 | * |
| 4 | * simple PWM based backlight control, board code has to setup |
| 5 | * 1) pin configuration so PWM waveforms can output |
Eric Miao | b8cdd87 | 2009-02-10 13:30:37 +0800 | [diff] [blame] | 6 | * 2) platform_data being correctly configured |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
Enric Balletbo i Serra | 3157694 | 2018-03-28 19:03:25 +0200 | [diff] [blame] | 13 | #include <linux/delay.h> |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 14 | #include <linux/gpio/consumer.h> |
Thierry Reding | 8265b2e | 2013-08-30 12:32:18 +0200 | [diff] [blame] | 15 | #include <linux/gpio.h> |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/fb.h> |
| 21 | #include <linux/backlight.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/pwm.h> |
| 24 | #include <linux/pwm_backlight.h> |
Thierry Reding | 22ceeee | 2013-08-30 12:38:34 +0200 | [diff] [blame] | 25 | #include <linux/regulator/consumer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 27 | |
| 28 | struct pwm_bl_data { |
| 29 | struct pwm_device *pwm; |
Ben Dooks | cfc3899 | 2009-11-10 17:20:40 +0000 | [diff] [blame] | 30 | struct device *dev; |
Arun Murthy | fef7764 | 2010-11-11 14:05:28 -0800 | [diff] [blame] | 31 | unsigned int lth_brightness; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 32 | unsigned int *levels; |
Thierry Reding | 22ceeee | 2013-08-30 12:38:34 +0200 | [diff] [blame] | 33 | struct regulator *power_supply; |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 34 | struct gpio_desc *enable_gpio; |
Mike Dunn | 8f43e18 | 2013-09-22 09:59:56 -0700 | [diff] [blame] | 35 | unsigned int scale; |
Vladimir Zapolskiy | edf387b | 2014-10-11 16:46:26 +0300 | [diff] [blame] | 36 | bool legacy; |
Enric Balletbo i Serra | 3157694 | 2018-03-28 19:03:25 +0200 | [diff] [blame] | 37 | unsigned int post_pwm_on_delay; |
| 38 | unsigned int pwm_off_delay; |
Ben Dooks | cfc3899 | 2009-11-10 17:20:40 +0000 | [diff] [blame] | 39 | int (*notify)(struct device *, |
| 40 | int brightness); |
Dilan Lee | cc7993f | 2011-08-25 15:59:17 -0700 | [diff] [blame] | 41 | void (*notify_after)(struct device *, |
| 42 | int brightness); |
Robert Morell | ef0a5e8 | 2011-03-22 16:30:31 -0700 | [diff] [blame] | 43 | int (*check_fb)(struct device *, struct fb_info *); |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 44 | void (*exit)(struct device *); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 47 | static void pwm_backlight_power_on(struct pwm_bl_data *pb) |
Thierry Reding | 62b744a | 2013-10-07 11:32:02 +0200 | [diff] [blame] | 48 | { |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 49 | struct pwm_state state; |
Thierry Reding | 73d4e2b | 2013-10-22 09:37:05 +0200 | [diff] [blame] | 50 | int err; |
Thierry Reding | 62b744a | 2013-10-07 11:32:02 +0200 | [diff] [blame] | 51 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 52 | pwm_get_state(pb->pwm, &state); |
| 53 | if (state.enabled) |
Thierry Reding | 97c3843 | 2013-10-02 18:01:02 +0200 | [diff] [blame] | 54 | return; |
| 55 | |
Thierry Reding | 22ceeee | 2013-08-30 12:38:34 +0200 | [diff] [blame] | 56 | err = regulator_enable(pb->power_supply); |
| 57 | if (err < 0) |
| 58 | dev_err(pb->dev, "failed to enable power supply\n"); |
| 59 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 60 | state.enabled = true; |
| 61 | pwm_apply_state(pb->pwm, &state); |
Enric Balletbo i Serra | 5fb5cae | 2018-03-28 19:03:23 +0200 | [diff] [blame] | 62 | |
Enric Balletbo i Serra | 3157694 | 2018-03-28 19:03:25 +0200 | [diff] [blame] | 63 | if (pb->post_pwm_on_delay) |
| 64 | msleep(pb->post_pwm_on_delay); |
| 65 | |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 66 | if (pb->enable_gpio) |
Maxime Ripard | 0c9501f | 2016-08-31 10:18:12 +0200 | [diff] [blame] | 67 | gpiod_set_value_cansleep(pb->enable_gpio, 1); |
Thierry Reding | 62b744a | 2013-10-07 11:32:02 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static void pwm_backlight_power_off(struct pwm_bl_data *pb) |
| 71 | { |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 72 | struct pwm_state state; |
| 73 | |
| 74 | pwm_get_state(pb->pwm, &state); |
| 75 | if (!state.enabled) |
Thierry Reding | 97c3843 | 2013-10-02 18:01:02 +0200 | [diff] [blame] | 76 | return; |
| 77 | |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 78 | if (pb->enable_gpio) |
Maxime Ripard | 0c9501f | 2016-08-31 10:18:12 +0200 | [diff] [blame] | 79 | gpiod_set_value_cansleep(pb->enable_gpio, 0); |
Thierry Reding | 8265b2e | 2013-08-30 12:32:18 +0200 | [diff] [blame] | 80 | |
Enric Balletbo i Serra | 3157694 | 2018-03-28 19:03:25 +0200 | [diff] [blame] | 81 | if (pb->pwm_off_delay) |
| 82 | msleep(pb->pwm_off_delay); |
| 83 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 84 | state.enabled = false; |
| 85 | state.duty_cycle = 0; |
| 86 | pwm_apply_state(pb->pwm, &state); |
Enric Balletbo i Serra | 5fb5cae | 2018-03-28 19:03:23 +0200 | [diff] [blame] | 87 | |
Thierry Reding | 22ceeee | 2013-08-30 12:38:34 +0200 | [diff] [blame] | 88 | regulator_disable(pb->power_supply); |
Thierry Reding | 62b744a | 2013-10-07 11:32:02 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Thierry Reding | e4bfeda | 2013-10-18 10:46:24 +0200 | [diff] [blame] | 91 | static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) |
| 92 | { |
| 93 | unsigned int lth = pb->lth_brightness; |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 94 | struct pwm_state state; |
Derek Basehore | 5d0c49a | 2017-08-29 13:34:34 -0700 | [diff] [blame] | 95 | u64 duty_cycle; |
Thierry Reding | e4bfeda | 2013-10-18 10:46:24 +0200 | [diff] [blame] | 96 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 97 | pwm_get_state(pb->pwm, &state); |
| 98 | |
Thierry Reding | e4bfeda | 2013-10-18 10:46:24 +0200 | [diff] [blame] | 99 | if (pb->levels) |
| 100 | duty_cycle = pb->levels[brightness]; |
| 101 | else |
| 102 | duty_cycle = brightness; |
| 103 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 104 | duty_cycle *= state.period - lth; |
Derek Basehore | 5d0c49a | 2017-08-29 13:34:34 -0700 | [diff] [blame] | 105 | do_div(duty_cycle, pb->scale); |
| 106 | |
| 107 | return duty_cycle + lth; |
Thierry Reding | e4bfeda | 2013-10-18 10:46:24 +0200 | [diff] [blame] | 108 | } |
| 109 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 110 | static int pwm_backlight_update_status(struct backlight_device *bl) |
| 111 | { |
Jingoo Han | e6e3dbf | 2013-02-21 16:43:46 -0800 | [diff] [blame] | 112 | struct pwm_bl_data *pb = bl_get_data(bl); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 113 | int brightness = bl->props.brightness; |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 114 | struct pwm_state state; |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 115 | |
Alexandre Courbot | 0132267 | 2013-01-30 15:19:15 +0900 | [diff] [blame] | 116 | if (bl->props.power != FB_BLANK_UNBLANK || |
| 117 | bl->props.fb_blank != FB_BLANK_UNBLANK || |
| 118 | bl->props.state & BL_CORE_FBBLANK) |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 119 | brightness = 0; |
| 120 | |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 121 | if (pb->notify) |
Ben Dooks | cfc3899 | 2009-11-10 17:20:40 +0000 | [diff] [blame] | 122 | brightness = pb->notify(pb->dev, brightness); |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 123 | |
Thierry Reding | e4bfeda | 2013-10-18 10:46:24 +0200 | [diff] [blame] | 124 | if (brightness > 0) { |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 125 | pwm_get_state(pb->pwm, &state); |
| 126 | state.duty_cycle = compute_duty_cycle(pb, brightness); |
| 127 | pwm_apply_state(pb->pwm, &state); |
| 128 | pwm_backlight_power_on(pb); |
Thierry Reding | e4bfeda | 2013-10-18 10:46:24 +0200 | [diff] [blame] | 129 | } else |
Thierry Reding | 62b744a | 2013-10-07 11:32:02 +0200 | [diff] [blame] | 130 | pwm_backlight_power_off(pb); |
Dilan Lee | cc7993f | 2011-08-25 15:59:17 -0700 | [diff] [blame] | 131 | |
| 132 | if (pb->notify_after) |
| 133 | pb->notify_after(pb->dev, brightness); |
| 134 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
Robert Morell | ef0a5e8 | 2011-03-22 16:30:31 -0700 | [diff] [blame] | 138 | static int pwm_backlight_check_fb(struct backlight_device *bl, |
| 139 | struct fb_info *info) |
| 140 | { |
Jingoo Han | e6e3dbf | 2013-02-21 16:43:46 -0800 | [diff] [blame] | 141 | struct pwm_bl_data *pb = bl_get_data(bl); |
Robert Morell | ef0a5e8 | 2011-03-22 16:30:31 -0700 | [diff] [blame] | 142 | |
| 143 | return !pb->check_fb || pb->check_fb(pb->dev, info); |
| 144 | } |
| 145 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 146 | static const struct backlight_ops pwm_backlight_ops = { |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 147 | .update_status = pwm_backlight_update_status, |
Robert Morell | ef0a5e8 | 2011-03-22 16:30:31 -0700 | [diff] [blame] | 148 | .check_fb = pwm_backlight_check_fb, |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 149 | }; |
| 150 | |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 151 | #ifdef CONFIG_OF |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 152 | #define PWM_LUMINANCE_SCALE 10000 /* luminance scale */ |
| 153 | |
| 154 | /* An integer based power function */ |
| 155 | static u64 int_pow(u64 base, int exp) |
| 156 | { |
| 157 | u64 result = 1; |
| 158 | |
| 159 | while (exp) { |
| 160 | if (exp & 1) |
| 161 | result *= base; |
| 162 | exp >>= 1; |
| 163 | base *= base; |
| 164 | } |
| 165 | |
| 166 | return result; |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * CIE lightness to PWM conversion. |
| 171 | * |
| 172 | * The CIE 1931 lightness formula is what actually describes how we perceive |
| 173 | * light: |
| 174 | * Y = (L* / 902.3) if L* ≤ 0.08856 |
| 175 | * Y = ((L* + 16) / 116)^3 if L* > 0.08856 |
| 176 | * |
| 177 | * Where Y is the luminance, the amount of light coming out of the screen, and |
| 178 | * is a number between 0.0 and 1.0; and L* is the lightness, how bright a human |
| 179 | * perceives the screen to be, and is a number between 0 and 100. |
| 180 | * |
| 181 | * The following function does the fixed point maths needed to implement the |
| 182 | * above formula. |
| 183 | */ |
| 184 | static u64 cie1931(unsigned int lightness, unsigned int scale) |
| 185 | { |
| 186 | u64 retval; |
| 187 | |
| 188 | lightness *= 100; |
| 189 | if (lightness <= (8 * scale)) { |
| 190 | retval = DIV_ROUND_CLOSEST_ULL(lightness * 10, 9023); |
| 191 | } else { |
| 192 | retval = int_pow((lightness + (16 * scale)) / 116, 3); |
| 193 | retval = DIV_ROUND_CLOSEST_ULL(retval, (scale * scale)); |
| 194 | } |
| 195 | |
| 196 | return retval; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Create a default correction table for PWM values to create linear brightness |
| 201 | * for LED based backlights using the CIE1931 algorithm. |
| 202 | */ |
| 203 | static |
| 204 | int pwm_backlight_brightness_default(struct device *dev, |
| 205 | struct platform_pwm_backlight_data *data, |
| 206 | unsigned int period) |
| 207 | { |
| 208 | unsigned int counter = 0; |
| 209 | unsigned int i, n; |
| 210 | u64 retval; |
| 211 | |
| 212 | /* |
| 213 | * Count the number of bits needed to represent the period number. The |
| 214 | * number of bits is used to calculate the number of levels used for the |
| 215 | * brightness-levels table, the purpose of this calculation is have a |
| 216 | * pre-computed table with enough levels to get linear brightness |
| 217 | * perception. The period is divided by the number of bits so for a |
| 218 | * 8-bit PWM we have 255 / 8 = 32 brightness levels or for a 16-bit PWM |
| 219 | * we have 65535 / 16 = 4096 brightness levels. |
| 220 | * |
| 221 | * Note that this method is based on empirical testing on different |
| 222 | * devices with PWM of 8 and 16 bits of resolution. |
| 223 | */ |
| 224 | n = period; |
| 225 | while (n) { |
| 226 | counter += n % 2; |
| 227 | n >>= 1; |
| 228 | } |
| 229 | |
| 230 | data->max_brightness = DIV_ROUND_UP(period, counter); |
| 231 | data->levels = devm_kcalloc(dev, data->max_brightness, |
| 232 | sizeof(*data->levels), GFP_KERNEL); |
| 233 | if (!data->levels) |
| 234 | return -ENOMEM; |
| 235 | |
| 236 | /* Fill the table using the cie1931 algorithm */ |
| 237 | for (i = 0; i < data->max_brightness; i++) { |
| 238 | retval = cie1931((i * PWM_LUMINANCE_SCALE) / |
| 239 | data->max_brightness, PWM_LUMINANCE_SCALE) * |
| 240 | period; |
| 241 | retval = DIV_ROUND_CLOSEST_ULL(retval, PWM_LUMINANCE_SCALE); |
| 242 | if (retval > UINT_MAX) |
| 243 | return -EINVAL; |
| 244 | data->levels[i] = (unsigned int)retval; |
| 245 | } |
| 246 | |
| 247 | data->dft_brightness = data->max_brightness / 2; |
| 248 | data->max_brightness--; |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 253 | static int pwm_backlight_parse_dt(struct device *dev, |
| 254 | struct platform_pwm_backlight_data *data) |
| 255 | { |
| 256 | struct device_node *node = dev->of_node; |
Enric Balletbo i Serra | 573fe6d | 2018-04-09 10:33:30 +0200 | [diff] [blame] | 257 | unsigned int num_levels = 0; |
| 258 | unsigned int levels_count; |
Daniel Thompson | 6337867 | 2018-07-25 08:38:30 +0100 | [diff] [blame] | 259 | unsigned int num_steps = 0; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 260 | struct property *prop; |
Enric Balletbo i Serra | 573fe6d | 2018-04-09 10:33:30 +0200 | [diff] [blame] | 261 | unsigned int *table; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 262 | int length; |
| 263 | u32 value; |
| 264 | int ret; |
| 265 | |
| 266 | if (!node) |
| 267 | return -ENODEV; |
| 268 | |
| 269 | memset(data, 0, sizeof(*data)); |
| 270 | |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 271 | /* |
| 272 | * Determine the number of brightness levels, if this property is not |
| 273 | * set a default table of brightness levels will be used. |
| 274 | */ |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 275 | prop = of_find_property(node, "brightness-levels", &length); |
| 276 | if (!prop) |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 277 | return 0; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 278 | |
| 279 | data->max_brightness = length / sizeof(u32); |
| 280 | |
| 281 | /* read brightness levels from DT property */ |
| 282 | if (data->max_brightness > 0) { |
| 283 | size_t size = sizeof(*data->levels) * data->max_brightness; |
Enric Balletbo i Serra | 573fe6d | 2018-04-09 10:33:30 +0200 | [diff] [blame] | 284 | unsigned int i, j, n = 0; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 285 | |
| 286 | data->levels = devm_kzalloc(dev, size, GFP_KERNEL); |
| 287 | if (!data->levels) |
| 288 | return -ENOMEM; |
| 289 | |
| 290 | ret = of_property_read_u32_array(node, "brightness-levels", |
| 291 | data->levels, |
| 292 | data->max_brightness); |
| 293 | if (ret < 0) |
| 294 | return ret; |
| 295 | |
| 296 | ret = of_property_read_u32(node, "default-brightness-level", |
| 297 | &value); |
| 298 | if (ret < 0) |
| 299 | return ret; |
| 300 | |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 301 | data->dft_brightness = value; |
Enric Balletbo i Serra | 573fe6d | 2018-04-09 10:33:30 +0200 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * This property is optional, if is set enables linear |
| 305 | * interpolation between each of the values of brightness levels |
| 306 | * and creates a new pre-computed table. |
| 307 | */ |
| 308 | of_property_read_u32(node, "num-interpolated-steps", |
| 309 | &num_steps); |
| 310 | |
| 311 | /* |
| 312 | * Make sure that there is at least two entries in the |
| 313 | * brightness-levels table, otherwise we can't interpolate |
| 314 | * between two points. |
| 315 | */ |
| 316 | if (num_steps) { |
| 317 | if (data->max_brightness < 2) { |
| 318 | dev_err(dev, "can't interpolate\n"); |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Recalculate the number of brightness levels, now |
| 324 | * taking in consideration the number of interpolated |
| 325 | * steps between two levels. |
| 326 | */ |
| 327 | for (i = 0; i < data->max_brightness - 1; i++) { |
| 328 | if ((data->levels[i + 1] - data->levels[i]) / |
| 329 | num_steps) |
| 330 | num_levels += num_steps; |
| 331 | else |
| 332 | num_levels++; |
| 333 | } |
| 334 | num_levels++; |
| 335 | dev_dbg(dev, "new number of brightness levels: %d\n", |
| 336 | num_levels); |
| 337 | |
| 338 | /* |
| 339 | * Create a new table of brightness levels with all the |
| 340 | * interpolated steps. |
| 341 | */ |
| 342 | size = sizeof(*table) * num_levels; |
| 343 | table = devm_kzalloc(dev, size, GFP_KERNEL); |
| 344 | if (!table) |
| 345 | return -ENOMEM; |
| 346 | |
| 347 | /* Fill the interpolated table. */ |
| 348 | levels_count = 0; |
| 349 | for (i = 0; i < data->max_brightness - 1; i++) { |
| 350 | value = data->levels[i]; |
| 351 | n = (data->levels[i + 1] - value) / num_steps; |
| 352 | if (n > 0) { |
| 353 | for (j = 0; j < num_steps; j++) { |
| 354 | table[levels_count] = value; |
| 355 | value += n; |
| 356 | levels_count++; |
| 357 | } |
| 358 | } else { |
| 359 | table[levels_count] = data->levels[i]; |
| 360 | levels_count++; |
| 361 | } |
| 362 | } |
| 363 | table[levels_count] = data->levels[i]; |
| 364 | |
| 365 | /* |
| 366 | * As we use interpolation lets remove current |
| 367 | * brightness levels table and replace for the |
| 368 | * new interpolated table. |
| 369 | */ |
| 370 | devm_kfree(dev, data->levels); |
| 371 | data->levels = table; |
| 372 | |
| 373 | /* |
| 374 | * Reassign max_brightness value to the new total number |
| 375 | * of brightness levels. |
| 376 | */ |
| 377 | data->max_brightness = num_levels; |
| 378 | } |
| 379 | |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 380 | data->max_brightness--; |
| 381 | } |
| 382 | |
Enric Balletbo i Serra | 3157694 | 2018-03-28 19:03:25 +0200 | [diff] [blame] | 383 | /* |
| 384 | * These values are optional and set as 0 by default, the out values |
| 385 | * are modified only if a valid u32 value can be decoded. |
| 386 | */ |
| 387 | of_property_read_u32(node, "post-pwm-on-delay-ms", |
| 388 | &data->post_pwm_on_delay); |
| 389 | of_property_read_u32(node, "pwm-off-delay-ms", &data->pwm_off_delay); |
| 390 | |
Lothar Waßmann | 937222c | 2014-08-20 08:38:36 +0200 | [diff] [blame] | 391 | data->enable_gpio = -EINVAL; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
Arvind Yadav | 62cdfe6 | 2017-06-20 13:22:15 +0530 | [diff] [blame] | 395 | static const struct of_device_id pwm_backlight_of_match[] = { |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 396 | { .compatible = "pwm-backlight" }, |
| 397 | { } |
| 398 | }; |
| 399 | |
| 400 | MODULE_DEVICE_TABLE(of, pwm_backlight_of_match); |
| 401 | #else |
| 402 | static int pwm_backlight_parse_dt(struct device *dev, |
| 403 | struct platform_pwm_backlight_data *data) |
| 404 | { |
| 405 | return -ENODEV; |
| 406 | } |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 407 | |
| 408 | static |
| 409 | int pwm_backlight_brightness_default(struct device *dev, |
| 410 | struct platform_pwm_backlight_data *data, |
| 411 | unsigned int period) |
| 412 | { |
| 413 | return -ENODEV; |
| 414 | } |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 415 | #endif |
| 416 | |
Peter Ujfalusi | 7613c92 | 2016-11-22 15:41:22 +0200 | [diff] [blame] | 417 | static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) |
| 418 | { |
| 419 | struct device_node *node = pb->dev->of_node; |
| 420 | |
| 421 | /* Not booted with device tree or no phandle link to the node */ |
| 422 | if (!node || !node->phandle) |
| 423 | return FB_BLANK_UNBLANK; |
| 424 | |
| 425 | /* |
| 426 | * If the driver is probed from the device tree and there is a |
| 427 | * phandle link pointing to the backlight node, it is safe to |
| 428 | * assume that another driver will enable the backlight at the |
| 429 | * appropriate time. Therefore, if it is disabled, keep it so. |
| 430 | */ |
| 431 | |
| 432 | /* if the enable GPIO is disabled, do not enable the backlight */ |
| 433 | if (pb->enable_gpio && gpiod_get_value(pb->enable_gpio) == 0) |
| 434 | return FB_BLANK_POWERDOWN; |
| 435 | |
| 436 | /* The regulator is disabled, do not enable the backlight */ |
| 437 | if (!regulator_is_enabled(pb->power_supply)) |
| 438 | return FB_BLANK_POWERDOWN; |
| 439 | |
Peter Ujfalusi | d1b8129 | 2016-11-22 15:41:23 +0200 | [diff] [blame] | 440 | /* The PWM is disabled, keep it like this */ |
| 441 | if (!pwm_is_enabled(pb->pwm)) |
| 442 | return FB_BLANK_POWERDOWN; |
| 443 | |
Peter Ujfalusi | 7613c92 | 2016-11-22 15:41:22 +0200 | [diff] [blame] | 444 | return FB_BLANK_UNBLANK; |
| 445 | } |
| 446 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 447 | static int pwm_backlight_probe(struct platform_device *pdev) |
| 448 | { |
Jingoo Han | c512794c | 2013-11-12 15:09:04 -0800 | [diff] [blame] | 449 | struct platform_pwm_backlight_data *data = dev_get_platdata(&pdev->dev); |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 450 | struct platform_pwm_backlight_data defdata; |
| 451 | struct backlight_properties props; |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 452 | struct backlight_device *bl; |
Philipp Zabel | 8777078 | 2015-12-10 10:09:06 +0100 | [diff] [blame] | 453 | struct device_node *node = pdev->dev.of_node; |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 454 | struct pwm_bl_data *pb; |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 455 | struct pwm_state state; |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 456 | unsigned int i; |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 457 | int ret; |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 458 | |
Ben Dooks | 14563a4 | 2008-08-05 13:01:22 -0700 | [diff] [blame] | 459 | if (!data) { |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 460 | ret = pwm_backlight_parse_dt(&pdev->dev, &defdata); |
| 461 | if (ret < 0) { |
| 462 | dev_err(&pdev->dev, "failed to find platform data\n"); |
| 463 | return ret; |
| 464 | } |
| 465 | |
| 466 | data = &defdata; |
Ben Dooks | 14563a4 | 2008-08-05 13:01:22 -0700 | [diff] [blame] | 467 | } |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 468 | |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 469 | if (data->init) { |
| 470 | ret = data->init(&pdev->dev); |
| 471 | if (ret < 0) |
| 472 | return ret; |
| 473 | } |
| 474 | |
Julia Lawall | ce96922 | 2012-03-23 15:02:00 -0700 | [diff] [blame] | 475 | pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL); |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 476 | if (!pb) { |
| 477 | ret = -ENOMEM; |
| 478 | goto err_alloc; |
| 479 | } |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 480 | |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 481 | pb->notify = data->notify; |
Dilan Lee | cc7993f | 2011-08-25 15:59:17 -0700 | [diff] [blame] | 482 | pb->notify_after = data->notify_after; |
Robert Morell | ef0a5e8 | 2011-03-22 16:30:31 -0700 | [diff] [blame] | 483 | pb->check_fb = data->check_fb; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 484 | pb->exit = data->exit; |
Ben Dooks | cfc3899 | 2009-11-10 17:20:40 +0000 | [diff] [blame] | 485 | pb->dev = &pdev->dev; |
Enric Balletbo i Serra | 3157694 | 2018-03-28 19:03:25 +0200 | [diff] [blame] | 486 | pb->post_pwm_on_delay = data->post_pwm_on_delay; |
| 487 | pb->pwm_off_delay = data->pwm_off_delay; |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 488 | |
Axel Lin | cdaefcc | 2015-05-16 22:08:10 +0800 | [diff] [blame] | 489 | pb->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", |
Philipp Zabel | 3698d7e | 2015-11-18 18:12:25 +0100 | [diff] [blame] | 490 | GPIOD_ASIS); |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 491 | if (IS_ERR(pb->enable_gpio)) { |
| 492 | ret = PTR_ERR(pb->enable_gpio); |
Alexandre Courbot | ff9c542 | 2014-06-25 18:18:18 +0900 | [diff] [blame] | 493 | goto err_alloc; |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 494 | } |
Thierry Reding | 8265b2e | 2013-08-30 12:32:18 +0200 | [diff] [blame] | 495 | |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 496 | /* |
| 497 | * Compatibility fallback for drivers still using the integer GPIO |
| 498 | * platform data. Must go away soon. |
| 499 | */ |
| 500 | if (!pb->enable_gpio && gpio_is_valid(data->enable_gpio)) { |
| 501 | ret = devm_gpio_request_one(&pdev->dev, data->enable_gpio, |
| 502 | GPIOF_OUT_INIT_HIGH, "enable"); |
Thierry Reding | 8265b2e | 2013-08-30 12:32:18 +0200 | [diff] [blame] | 503 | if (ret < 0) { |
| 504 | dev_err(&pdev->dev, "failed to request GPIO#%d: %d\n", |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 505 | data->enable_gpio, ret); |
Thierry Reding | 8265b2e | 2013-08-30 12:32:18 +0200 | [diff] [blame] | 506 | goto err_alloc; |
| 507 | } |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 508 | |
| 509 | pb->enable_gpio = gpio_to_desc(data->enable_gpio); |
Thierry Reding | 8265b2e | 2013-08-30 12:32:18 +0200 | [diff] [blame] | 510 | } |
| 511 | |
Peter Ujfalusi | 7613c92 | 2016-11-22 15:41:22 +0200 | [diff] [blame] | 512 | /* |
Geert Uytterhoeven | 892c778 | 2017-04-04 12:54:35 +0200 | [diff] [blame] | 513 | * If the GPIO is not known to be already configured as output, that |
Wolfram Sang | bb084c0 | 2018-01-14 22:07:10 +0100 | [diff] [blame] | 514 | * is, if gpiod_get_direction returns either 1 or -EINVAL, change the |
| 515 | * direction to output and set the GPIO as active. |
Peter Ujfalusi | 7613c92 | 2016-11-22 15:41:22 +0200 | [diff] [blame] | 516 | * Do not force the GPIO to active when it was already output as it |
| 517 | * could cause backlight flickering or we would enable the backlight too |
| 518 | * early. Leave the decision of the initial backlight state for later. |
| 519 | */ |
| 520 | if (pb->enable_gpio && |
Wolfram Sang | bb084c0 | 2018-01-14 22:07:10 +0100 | [diff] [blame] | 521 | gpiod_get_direction(pb->enable_gpio) != 0) |
Peter Ujfalusi | 7613c92 | 2016-11-22 15:41:22 +0200 | [diff] [blame] | 522 | gpiod_direction_output(pb->enable_gpio, 1); |
Philipp Zabel | 3698d7e | 2015-11-18 18:12:25 +0100 | [diff] [blame] | 523 | |
Thierry Reding | 22ceeee | 2013-08-30 12:38:34 +0200 | [diff] [blame] | 524 | pb->power_supply = devm_regulator_get(&pdev->dev, "power"); |
| 525 | if (IS_ERR(pb->power_supply)) { |
| 526 | ret = PTR_ERR(pb->power_supply); |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 527 | goto err_alloc; |
Thierry Reding | 22ceeee | 2013-08-30 12:38:34 +0200 | [diff] [blame] | 528 | } |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 529 | |
Sachin Kamat | 60ce702 | 2012-09-17 11:50:47 +0530 | [diff] [blame] | 530 | pb->pwm = devm_pwm_get(&pdev->dev, NULL); |
Philipp Zabel | 8777078 | 2015-12-10 10:09:06 +0100 | [diff] [blame] | 531 | if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) { |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 532 | dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); |
Vladimir Zapolskiy | edf387b | 2014-10-11 16:46:26 +0300 | [diff] [blame] | 533 | pb->legacy = true; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 534 | pb->pwm = pwm_request(data->pwm_id, "pwm-backlight"); |
Vladimir Zapolskiy | dc88112 | 2015-10-12 15:29:03 +0300 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | if (IS_ERR(pb->pwm)) { |
| 538 | ret = PTR_ERR(pb->pwm); |
| 539 | if (ret != -EPROBE_DEFER) |
| 540 | dev_err(&pdev->dev, "unable to request PWM\n"); |
| 541 | goto err_alloc; |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | dev_dbg(&pdev->dev, "got pwm for backlight\n"); |
| 545 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 546 | /* Sync up PWM state. */ |
| 547 | pwm_init_state(pb->pwm, &state); |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 548 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 549 | /* |
| 550 | * The DT case will set the pwm_period_ns field to 0 and store the |
| 551 | * period, parsed from the DT, in the PWM device. For the non-DT case, |
| 552 | * set the period from platform data if it has not already been set |
| 553 | * via the PWM lookup table. |
| 554 | */ |
| 555 | if (!state.period && (data->pwm_period_ns > 0)) |
| 556 | state.period = data->pwm_period_ns; |
| 557 | |
| 558 | ret = pwm_apply_state(pb->pwm, &state); |
| 559 | if (ret) { |
| 560 | dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n", |
| 561 | ret); |
| 562 | goto err_alloc; |
| 563 | } |
| 564 | |
| 565 | if (!data->levels) { |
Enric Balletbo i Serra | 88ba95b | 2018-04-09 10:33:32 +0200 | [diff] [blame] | 566 | ret = pwm_backlight_brightness_default(&pdev->dev, data, |
| 567 | state.period); |
| 568 | if (ret < 0) { |
| 569 | dev_err(&pdev->dev, |
| 570 | "failed to setup default brightness table\n"); |
| 571 | goto err_alloc; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | for (i = 0; i <= data->max_brightness; i++) { |
| 576 | if (data->levels[i] > pb->scale) |
| 577 | pb->scale = data->levels[i]; |
| 578 | |
| 579 | pb->levels = data->levels; |
| 580 | } |
| 581 | |
Enric Balletbo i Serra | e6bcca0 | 2018-08-14 18:50:59 +0200 | [diff] [blame^] | 582 | pb->lth_brightness = data->lth_brightness * (state.period / pb->scale); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 583 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 584 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 585 | props.type = BACKLIGHT_RAW; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 586 | props.max_brightness = data->max_brightness; |
| 587 | bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb, |
| 588 | &pwm_backlight_ops, &props); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 589 | if (IS_ERR(bl)) { |
| 590 | dev_err(&pdev->dev, "failed to register backlight\n"); |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 591 | ret = PTR_ERR(bl); |
Vladimir Zapolskiy | 60d613d | 2015-06-14 17:32:14 +0300 | [diff] [blame] | 592 | if (pb->legacy) |
| 593 | pwm_free(pb->pwm); |
Alexandre Courbot | 257462d | 2014-02-27 14:53:34 +0900 | [diff] [blame] | 594 | goto err_alloc; |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 595 | } |
| 596 | |
Peter Ujfalusi | 83cfd72 | 2013-01-22 14:39:54 +0100 | [diff] [blame] | 597 | if (data->dft_brightness > data->max_brightness) { |
| 598 | dev_warn(&pdev->dev, |
| 599 | "invalid default brightness level: %u, using %u\n", |
| 600 | data->dft_brightness, data->max_brightness); |
| 601 | data->dft_brightness = data->max_brightness; |
| 602 | } |
| 603 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 604 | bl->props.brightness = data->dft_brightness; |
Peter Ujfalusi | 7613c92 | 2016-11-22 15:41:22 +0200 | [diff] [blame] | 605 | bl->props.power = pwm_backlight_initial_power_state(pb); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 606 | backlight_update_status(bl); |
| 607 | |
| 608 | platform_set_drvdata(pdev, bl); |
| 609 | return 0; |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 610 | |
Philipp Zabel | 3b73125 | 2008-05-22 14:18:40 +0100 | [diff] [blame] | 611 | err_alloc: |
| 612 | if (data->exit) |
| 613 | data->exit(&pdev->dev); |
| 614 | return ret; |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | static int pwm_backlight_remove(struct platform_device *pdev) |
| 618 | { |
| 619 | struct backlight_device *bl = platform_get_drvdata(pdev); |
Jingoo Han | e6e3dbf | 2013-02-21 16:43:46 -0800 | [diff] [blame] | 620 | struct pwm_bl_data *pb = bl_get_data(bl); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 621 | |
| 622 | backlight_device_unregister(bl); |
Thierry Reding | 62b744a | 2013-10-07 11:32:02 +0200 | [diff] [blame] | 623 | pwm_backlight_power_off(pb); |
Thierry Reding | 668e63c | 2013-10-07 11:30:50 +0200 | [diff] [blame] | 624 | |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 625 | if (pb->exit) |
| 626 | pb->exit(&pdev->dev); |
Vladimir Zapolskiy | edf387b | 2014-10-11 16:46:26 +0300 | [diff] [blame] | 627 | if (pb->legacy) |
| 628 | pwm_free(pb->pwm); |
Thierry Reding | 668e63c | 2013-10-07 11:30:50 +0200 | [diff] [blame] | 629 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | |
Thierry Reding | 5f33b89 | 2014-04-29 17:28:59 +0200 | [diff] [blame] | 633 | static void pwm_backlight_shutdown(struct platform_device *pdev) |
| 634 | { |
| 635 | struct backlight_device *bl = platform_get_drvdata(pdev); |
| 636 | struct pwm_bl_data *pb = bl_get_data(bl); |
| 637 | |
| 638 | pwm_backlight_power_off(pb); |
| 639 | } |
| 640 | |
Jingoo Han | c791126 | 2013-02-25 17:15:47 +0900 | [diff] [blame] | 641 | #ifdef CONFIG_PM_SLEEP |
Mark Brown | e2c17bc | 2012-01-10 15:09:22 -0800 | [diff] [blame] | 642 | static int pwm_backlight_suspend(struct device *dev) |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 643 | { |
Mark Brown | e2c17bc | 2012-01-10 15:09:22 -0800 | [diff] [blame] | 644 | struct backlight_device *bl = dev_get_drvdata(dev); |
Jingoo Han | e6e3dbf | 2013-02-21 16:43:46 -0800 | [diff] [blame] | 645 | struct pwm_bl_data *pb = bl_get_data(bl); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 646 | |
Marc Zyngier | 82e8b54 | 2009-06-19 10:50:54 +0200 | [diff] [blame] | 647 | if (pb->notify) |
Ben Dooks | cfc3899 | 2009-11-10 17:20:40 +0000 | [diff] [blame] | 648 | pb->notify(pb->dev, 0); |
Thierry Reding | 668e63c | 2013-10-07 11:30:50 +0200 | [diff] [blame] | 649 | |
Thierry Reding | 62b744a | 2013-10-07 11:32:02 +0200 | [diff] [blame] | 650 | pwm_backlight_power_off(pb); |
Thierry Reding | 668e63c | 2013-10-07 11:30:50 +0200 | [diff] [blame] | 651 | |
Dilan Lee | cc7993f | 2011-08-25 15:59:17 -0700 | [diff] [blame] | 652 | if (pb->notify_after) |
| 653 | pb->notify_after(pb->dev, 0); |
Thierry Reding | 668e63c | 2013-10-07 11:30:50 +0200 | [diff] [blame] | 654 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 655 | return 0; |
| 656 | } |
| 657 | |
Mark Brown | e2c17bc | 2012-01-10 15:09:22 -0800 | [diff] [blame] | 658 | static int pwm_backlight_resume(struct device *dev) |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 659 | { |
Mark Brown | e2c17bc | 2012-01-10 15:09:22 -0800 | [diff] [blame] | 660 | struct backlight_device *bl = dev_get_drvdata(dev); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 661 | |
| 662 | backlight_update_status(bl); |
Thierry Reding | 668e63c | 2013-10-07 11:30:50 +0200 | [diff] [blame] | 663 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 664 | return 0; |
| 665 | } |
Jingoo Han | c791126 | 2013-02-25 17:15:47 +0900 | [diff] [blame] | 666 | #endif |
Mark Brown | e2c17bc | 2012-01-10 15:09:22 -0800 | [diff] [blame] | 667 | |
Huayi Li | 1dea1fd | 2013-10-09 10:33:02 +0800 | [diff] [blame] | 668 | static const struct dev_pm_ops pwm_backlight_pm_ops = { |
| 669 | #ifdef CONFIG_PM_SLEEP |
| 670 | .suspend = pwm_backlight_suspend, |
| 671 | .resume = pwm_backlight_resume, |
| 672 | .poweroff = pwm_backlight_suspend, |
| 673 | .restore = pwm_backlight_resume, |
| 674 | #endif |
| 675 | }; |
Mark Brown | e2c17bc | 2012-01-10 15:09:22 -0800 | [diff] [blame] | 676 | |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 677 | static struct platform_driver pwm_backlight_driver = { |
| 678 | .driver = { |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 679 | .name = "pwm-backlight", |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 680 | .pm = &pwm_backlight_pm_ops, |
Thierry Reding | 3e3ed6c | 2011-12-16 21:25:29 +0100 | [diff] [blame] | 681 | .of_match_table = of_match_ptr(pwm_backlight_of_match), |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 682 | }, |
| 683 | .probe = pwm_backlight_probe, |
| 684 | .remove = pwm_backlight_remove, |
Thierry Reding | 5f33b89 | 2014-04-29 17:28:59 +0200 | [diff] [blame] | 685 | .shutdown = pwm_backlight_shutdown, |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 686 | }; |
| 687 | |
Axel Lin | 81178e0 | 2012-01-10 15:09:11 -0800 | [diff] [blame] | 688 | module_platform_driver(pwm_backlight_driver); |
eric miao | 42796d3 | 2008-04-14 09:35:08 +0100 | [diff] [blame] | 689 | |
| 690 | MODULE_DESCRIPTION("PWM based Backlight Driver"); |
| 691 | MODULE_LICENSE("GPL"); |
Ben Dooks | 8cd6819 | 2008-08-05 13:01:24 -0700 | [diff] [blame] | 692 | MODULE_ALIAS("platform:pwm-backlight"); |