.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * sky81452-backlight.c SKY81452 backlight driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2014 Skyworks Solutions Inc. |
---|
5 | 6 | * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify it |
---|
8 | | - * under the terms of the GNU General Public License version 2 |
---|
9 | | - * as published by the Free Software Foundation. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, but |
---|
12 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | | - * General Public License for more details. |
---|
15 | | - * |
---|
16 | | - * You should have received a copy of the GNU General Public License along |
---|
17 | | - * with this program; if not, see <http://www.gnu.org/licenses/>. |
---|
18 | 7 | */ |
---|
19 | 8 | |
---|
20 | 9 | #include <linux/backlight.h> |
---|
21 | 10 | #include <linux/err.h> |
---|
22 | | -#include <linux/gpio.h> |
---|
| 11 | +#include <linux/gpio/consumer.h> |
---|
23 | 12 | #include <linux/init.h> |
---|
24 | 13 | #include <linux/kernel.h> |
---|
25 | 14 | #include <linux/module.h> |
---|
26 | 15 | #include <linux/of.h> |
---|
27 | | -#include <linux/of_gpio.h> |
---|
28 | 16 | #include <linux/platform_device.h> |
---|
29 | 17 | #include <linux/regmap.h> |
---|
30 | | -#include <linux/platform_data/sky81452-backlight.h> |
---|
31 | 18 | #include <linux/slab.h> |
---|
32 | 19 | |
---|
33 | 20 | /* registers */ |
---|
.. | .. |
---|
52 | 39 | |
---|
53 | 40 | #define SKY81452_DEFAULT_NAME "lcd-backlight" |
---|
54 | 41 | #define SKY81452_MAX_BRIGHTNESS (SKY81452_CS + 1) |
---|
| 42 | + |
---|
| 43 | +/** |
---|
| 44 | + * struct sky81452_platform_data |
---|
| 45 | + * @name: backlight driver name. |
---|
| 46 | + * If it is not defined, default name is lcd-backlight. |
---|
| 47 | + * @gpiod_enable:GPIO descriptor which control EN pin |
---|
| 48 | + * @enable: Enable mask for current sink channel 1, 2, 3, 4, 5 and 6. |
---|
| 49 | + * @ignore_pwm: true if DPWMI should be ignored. |
---|
| 50 | + * @dpwm_mode: true is DPWM dimming mode, otherwise Analog dimming mode. |
---|
| 51 | + * @phase_shift:true is phase shift mode. |
---|
| 52 | + * @short_detection_threshold: It should be one of 4, 5, 6 and 7V. |
---|
| 53 | + * @boost_current_limit: It should be one of 2300, 2750mA. |
---|
| 54 | + */ |
---|
| 55 | +struct sky81452_bl_platform_data { |
---|
| 56 | + const char *name; |
---|
| 57 | + struct gpio_desc *gpiod_enable; |
---|
| 58 | + unsigned int enable; |
---|
| 59 | + bool ignore_pwm; |
---|
| 60 | + bool dpwm_mode; |
---|
| 61 | + bool phase_shift; |
---|
| 62 | + unsigned int short_detection_threshold; |
---|
| 63 | + unsigned int boost_current_limit; |
---|
| 64 | +}; |
---|
55 | 65 | |
---|
56 | 66 | #define CTZ(b) __builtin_ctz(b) |
---|
57 | 67 | |
---|
.. | .. |
---|
193 | 203 | pdata->ignore_pwm = of_property_read_bool(np, "skyworks,ignore-pwm"); |
---|
194 | 204 | pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode"); |
---|
195 | 205 | pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift"); |
---|
196 | | - pdata->gpio_enable = of_get_gpio(np, 0); |
---|
| 206 | + pdata->gpiod_enable = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH); |
---|
197 | 207 | |
---|
198 | 208 | ret = of_property_count_u32_elems(np, "led-sources"); |
---|
199 | 209 | if (ret < 0) { |
---|
.. | .. |
---|
264 | 274 | { |
---|
265 | 275 | struct device *dev = &pdev->dev; |
---|
266 | 276 | struct regmap *regmap = dev_get_drvdata(dev->parent); |
---|
267 | | - struct sky81452_bl_platform_data *pdata = dev_get_platdata(dev); |
---|
| 277 | + struct sky81452_bl_platform_data *pdata; |
---|
268 | 278 | struct backlight_device *bd; |
---|
269 | 279 | struct backlight_properties props; |
---|
270 | 280 | const char *name; |
---|
271 | 281 | int ret; |
---|
272 | 282 | |
---|
273 | | - if (!pdata) { |
---|
274 | | - pdata = sky81452_bl_parse_dt(dev); |
---|
275 | | - if (IS_ERR(pdata)) |
---|
276 | | - return PTR_ERR(pdata); |
---|
277 | | - } |
---|
278 | | - |
---|
279 | | - if (gpio_is_valid(pdata->gpio_enable)) { |
---|
280 | | - ret = devm_gpio_request_one(dev, pdata->gpio_enable, |
---|
281 | | - GPIOF_OUT_INIT_HIGH, "sky81452-en"); |
---|
282 | | - if (ret < 0) { |
---|
283 | | - dev_err(dev, "failed to request GPIO. err=%d\n", ret); |
---|
284 | | - return ret; |
---|
285 | | - } |
---|
286 | | - } |
---|
| 283 | + pdata = sky81452_bl_parse_dt(dev); |
---|
| 284 | + if (IS_ERR(pdata)) |
---|
| 285 | + return PTR_ERR(pdata); |
---|
287 | 286 | |
---|
288 | 287 | ret = sky81452_bl_init_device(regmap, pdata); |
---|
289 | 288 | if (ret < 0) { |
---|
.. | .. |
---|
324 | 323 | bd->props.brightness = 0; |
---|
325 | 324 | backlight_update_status(bd); |
---|
326 | 325 | |
---|
327 | | - if (gpio_is_valid(pdata->gpio_enable)) |
---|
328 | | - gpio_set_value_cansleep(pdata->gpio_enable, 0); |
---|
| 326 | + if (pdata->gpiod_enable) |
---|
| 327 | + gpiod_set_value_cansleep(pdata->gpiod_enable, 0); |
---|
329 | 328 | |
---|
330 | 329 | return 0; |
---|
331 | 330 | } |
---|