Lines Matching +full:pwm +full:- +full:backlight
1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI LP8788 MFD - backlight driver
10 #include <linux/backlight.h>
15 #include <linux/pwm.h>
32 #define DEFAULT_BL_NAME "lcd-backlight"
48 struct pwm_device *pwm; member
73 struct lp8788_backlight_platform_data *pdata = bl->pdata; in lp8788_backlight_configure()
83 cfg->bl_mode = pdata->bl_mode; in lp8788_backlight_configure()
84 cfg->dim_mode = pdata->dim_mode; in lp8788_backlight_configure()
85 cfg->full_scale = pdata->full_scale; in lp8788_backlight_configure()
86 cfg->rise_time = pdata->rise_time; in lp8788_backlight_configure()
87 cfg->fall_time = pdata->fall_time; in lp8788_backlight_configure()
88 cfg->pwm_pol = pdata->pwm_pol; in lp8788_backlight_configure()
92 val = (cfg->rise_time << LP8788_BL_RAMP_RISE_SHIFT) | cfg->fall_time; in lp8788_backlight_configure()
93 ret = lp8788_write_byte(bl->lp, LP8788_BL_RAMP, val); in lp8788_backlight_configure()
98 val = (cfg->full_scale << LP8788_BL_FULLSCALE_SHIFT) | in lp8788_backlight_configure()
99 (cfg->dim_mode << LP8788_BL_DIM_MODE_SHIFT); in lp8788_backlight_configure()
102 switch (cfg->bl_mode) { in lp8788_backlight_configure()
109 (cfg->pwm_pol << LP8788_BL_PWM_POLARITY_SHIFT); in lp8788_backlight_configure()
112 dev_err(bl->lp->dev, "invalid mode: %d\n", cfg->bl_mode); in lp8788_backlight_configure()
113 return -EINVAL; in lp8788_backlight_configure()
116 bl->mode = cfg->bl_mode; in lp8788_backlight_configure()
118 return lp8788_write_byte(bl->lp, LP8788_BL_CONFIG, val); in lp8788_backlight_configure()
126 struct pwm_device *pwm; in lp8788_pwm_ctrl() local
128 if (!bl->pdata) in lp8788_pwm_ctrl()
131 period = bl->pdata->period_ns; in lp8788_pwm_ctrl()
133 dev = bl->lp->dev; in lp8788_pwm_ctrl()
135 /* request PWM device with the consumer name */ in lp8788_pwm_ctrl()
136 if (!bl->pwm) { in lp8788_pwm_ctrl()
137 pwm = devm_pwm_get(dev, LP8788_DEV_BACKLIGHT); in lp8788_pwm_ctrl()
138 if (IS_ERR(pwm)) { in lp8788_pwm_ctrl()
139 dev_err(dev, "can not get PWM device\n"); in lp8788_pwm_ctrl()
143 bl->pwm = pwm; in lp8788_pwm_ctrl()
147 * the atomic PWM API. in lp8788_pwm_ctrl()
149 pwm_apply_args(pwm); in lp8788_pwm_ctrl()
152 pwm_config(bl->pwm, duty, period); in lp8788_pwm_ctrl()
154 pwm_enable(bl->pwm); in lp8788_pwm_ctrl()
156 pwm_disable(bl->pwm); in lp8788_pwm_ctrl()
162 enum lp8788_bl_ctrl_mode mode = bl->mode; in lp8788_bl_update_status()
164 if (bl_dev->props.state & BL_CORE_SUSPENDED) in lp8788_bl_update_status()
165 bl_dev->props.brightness = 0; in lp8788_bl_update_status()
168 int brt = bl_dev->props.brightness; in lp8788_bl_update_status()
169 int max = bl_dev->props.max_brightness; in lp8788_bl_update_status()
173 u8 brt = bl_dev->props.brightness; in lp8788_bl_update_status()
175 lp8788_write_byte(bl->lp, LP8788_BL_BRIGHTNESS, brt); in lp8788_bl_update_status()
190 struct lp8788_backlight_platform_data *pdata = bl->pdata; in lp8788_backlight_register()
199 init_brt = min_t(int, pdata->initial_brightness, in lp8788_backlight_register()
206 /* Backlight device name */ in lp8788_backlight_register()
207 if (!pdata || !pdata->name) in lp8788_backlight_register()
210 name = pdata->name; in lp8788_backlight_register()
212 bl_dev = backlight_device_register(name, bl->lp->dev, bl, in lp8788_backlight_register()
217 bl->bl_dev = bl_dev; in lp8788_backlight_register()
224 struct backlight_device *bl_dev = bl->bl_dev; in lp8788_backlight_unregister()
233 enum lp8788_bl_ctrl_mode mode = bl->mode; in lp8788_get_bl_ctl_mode()
237 strmode = "PWM based"; in lp8788_get_bl_ctl_mode()
259 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); in lp8788_backlight_probe()
263 bl = devm_kzalloc(lp->dev, sizeof(struct lp8788_bl), GFP_KERNEL); in lp8788_backlight_probe()
265 return -ENOMEM; in lp8788_backlight_probe()
267 bl->lp = lp; in lp8788_backlight_probe()
268 if (lp->pdata) in lp8788_backlight_probe()
269 bl->pdata = lp->pdata->bl_pdata; in lp8788_backlight_probe()
275 dev_err(lp->dev, "backlight config err: %d\n", ret); in lp8788_backlight_probe()
281 dev_err(lp->dev, "register backlight err: %d\n", ret); in lp8788_backlight_probe()
285 ret = sysfs_create_group(&pdev->dev.kobj, &lp8788_attr_group); in lp8788_backlight_probe()
287 dev_err(lp->dev, "register sysfs err: %d\n", ret); in lp8788_backlight_probe()
291 backlight_update_status(bl->bl_dev); in lp8788_backlight_probe()
304 struct backlight_device *bl_dev = bl->bl_dev; in lp8788_backlight_remove()
306 bl_dev->props.brightness = 0; in lp8788_backlight_remove()
308 sysfs_remove_group(&pdev->dev.kobj, &lp8788_attr_group); in lp8788_backlight_remove()
323 MODULE_DESCRIPTION("Texas Instruments LP8788 Backlight Driver");
326 MODULE_ALIAS("platform:lp8788-backlight");