Lines Matching +full:pwm +full:- +full:regulator
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2011 ST-Ericsson SA.
9 * based on leds-lm3530.c by Dan Murphy <D.Murphy@motorola.com>
17 #include <linux/led-lm3530.h>
19 #include <linux/regulator/consumer.h>
22 #define LM3530_LED_DEV "lcd-backlight"
23 #define LM3530_NAME "lm3530-led"
92 { "pwm", LM3530_BL_MODE_PWM },
100 * @mode: mode of operation - manual, ALS, PWM
101 * @regulator: regulator
103 * @enable: regulator is enabled
110 struct regulator *regulator; member
152 return -EINVAL; in lm3530_get_mode_from_str()
161 if (pdata->als_vmax == 0) { in lm3530_als_configure()
162 pdata->als_vmin = 0; in lm3530_als_configure()
163 pdata->als_vmax = LM3530_ALS_WINDOW_mV; in lm3530_als_configure()
166 als_vmin = pdata->als_vmin; in lm3530_als_configure()
167 als_vmax = pdata->als_vmax; in lm3530_als_configure()
169 if ((als_vmax - als_vmin) > LM3530_ALS_WINDOW_mV) in lm3530_als_configure()
170 pdata->als_vmax = als_vmax = als_vmin + LM3530_ALS_WINDOW_mV; in lm3530_als_configure()
173 als_vstep = (als_vmax - als_vmin) / (LM3530_ALS_ZB_MAX + 1); in lm3530_als_configure()
176 als->zones[i] = (((als_vmin + LM3530_ALS_OFFSET_mV) + in lm3530_als_configure()
179 als->config = in lm3530_als_configure()
180 (pdata->als_avrg_time << LM3530_ALS_AVG_TIME_SHIFT) | in lm3530_als_configure()
182 (pdata->als_input_mode << LM3530_ALS_SEL_SHIFT); in lm3530_als_configure()
184 als->imp_sel = in lm3530_als_configure()
185 (pdata->als1_resistor_sel << LM3530_ALS1_IMP_SHIFT) | in lm3530_als_configure()
186 (pdata->als2_resistor_sel << LM3530_ALS2_IMP_SHIFT); in lm3530_als_configure()
193 if (drvdata->enable) in lm3530_led_enable()
196 ret = regulator_enable(drvdata->regulator); in lm3530_led_enable()
198 dev_err(drvdata->led_dev.dev, "Failed to enable vin:%d\n", ret); in lm3530_led_enable()
202 drvdata->enable = true; in lm3530_led_enable()
210 if (!drvdata->enable) in lm3530_led_disable()
213 ret = regulator_disable(drvdata->regulator); in lm3530_led_disable()
215 dev_err(drvdata->led_dev.dev, "Failed to disable vin:%d\n", in lm3530_led_disable()
220 drvdata->enable = false; in lm3530_led_disable()
231 struct lm3530_platform_data *pdata = drvdata->pdata; in lm3530_init_registers()
232 struct i2c_client *client = drvdata->client; in lm3530_init_registers()
233 struct lm3530_pwm_data *pwm = &pdata->pwm_data; in lm3530_init_registers() local
238 gen_config = (pdata->brt_ramp_law << LM3530_RAMP_LAW_SHIFT) | in lm3530_init_registers()
239 ((pdata->max_current & 7) << LM3530_MAX_CURR_SHIFT); in lm3530_init_registers()
241 switch (drvdata->mode) { in lm3530_init_registers()
251 (pdata->pwm_pol_hi << LM3530_PWM_POL_SHIFT); in lm3530_init_registers()
255 brt_ramp = (pdata->brt_ramp_fall << LM3530_BRT_RAMP_FALL_SHIFT) | in lm3530_init_registers()
256 (pdata->brt_ramp_rise << LM3530_BRT_RAMP_RISE_SHIFT); in lm3530_init_registers()
258 if (drvdata->brightness) in lm3530_init_registers()
259 brightness = drvdata->brightness; in lm3530_init_registers()
261 brightness = drvdata->brightness = pdata->brt_val; in lm3530_init_registers()
263 if (brightness > drvdata->led_dev.max_brightness) in lm3530_init_registers()
264 brightness = drvdata->led_dev.max_brightness; in lm3530_init_registers()
286 /* do not update brightness register when pwm mode */ in lm3530_init_registers()
288 drvdata->mode == LM3530_BL_MODE_PWM) { in lm3530_init_registers()
289 if (pwm->pwm_set_intensity) in lm3530_init_registers()
290 pwm->pwm_set_intensity(reg_val[i], in lm3530_init_registers()
291 drvdata->led_dev.max_brightness); in lm3530_init_registers()
310 struct lm3530_platform_data *pdata = drvdata->pdata; in lm3530_brightness_set()
311 struct lm3530_pwm_data *pwm = &pdata->pwm_data; in lm3530_brightness_set() local
312 u8 max_brightness = led_cdev->max_brightness; in lm3530_brightness_set()
314 switch (drvdata->mode) { in lm3530_brightness_set()
317 if (!drvdata->enable) { in lm3530_brightness_set()
320 dev_err(&drvdata->client->dev, in lm3530_brightness_set()
327 err = i2c_smbus_write_byte_data(drvdata->client, in lm3530_brightness_set()
330 dev_err(&drvdata->client->dev, in lm3530_brightness_set()
333 drvdata->brightness = brt_val; in lm3530_brightness_set()
341 if (pwm->pwm_set_intensity) in lm3530_brightness_set()
342 pwm->pwm_set_intensity(brt_val, max_brightness); in lm3530_brightness_set()
358 if (drvdata->mode == mode_map[i].mode_val) in mode_show()
373 struct lm3530_pwm_data *pwm; in mode_store() local
378 pwm = &drvdata->pdata->pwm_data; in mode_store()
379 max_brightness = led_cdev->max_brightness; in mode_store()
386 drvdata->mode = mode; in mode_store()
388 /* set pwm to low if unnecessary */ in mode_store()
389 if (mode != LM3530_BL_MODE_PWM && pwm->pwm_set_intensity) in mode_store()
390 pwm->pwm_set_intensity(0, max_brightness); in mode_store()
398 return sizeof(drvdata->mode); in mode_store()
410 struct lm3530_platform_data *pdata = dev_get_platdata(&client->dev); in lm3530_probe()
415 dev_err(&client->dev, "platform data required\n"); in lm3530_probe()
416 return -ENODEV; in lm3530_probe()
420 if (pdata->mode > LM3530_BL_MODE_PWM) { in lm3530_probe()
421 dev_err(&client->dev, "Illegal Mode request\n"); in lm3530_probe()
422 return -EINVAL; in lm3530_probe()
425 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in lm3530_probe()
426 dev_err(&client->dev, "I2C_FUNC_I2C not supported\n"); in lm3530_probe()
427 return -EIO; in lm3530_probe()
430 drvdata = devm_kzalloc(&client->dev, sizeof(struct lm3530_data), in lm3530_probe()
433 return -ENOMEM; in lm3530_probe()
435 drvdata->mode = pdata->mode; in lm3530_probe()
436 drvdata->client = client; in lm3530_probe()
437 drvdata->pdata = pdata; in lm3530_probe()
438 drvdata->brightness = LED_OFF; in lm3530_probe()
439 drvdata->enable = false; in lm3530_probe()
440 drvdata->led_dev.name = LM3530_LED_DEV; in lm3530_probe()
441 drvdata->led_dev.brightness_set = lm3530_brightness_set; in lm3530_probe()
442 drvdata->led_dev.max_brightness = MAX_BRIGHTNESS; in lm3530_probe()
443 drvdata->led_dev.groups = lm3530_groups; in lm3530_probe()
447 drvdata->regulator = devm_regulator_get(&client->dev, "vin"); in lm3530_probe()
448 if (IS_ERR(drvdata->regulator)) { in lm3530_probe()
449 dev_err(&client->dev, "regulator get failed\n"); in lm3530_probe()
450 err = PTR_ERR(drvdata->regulator); in lm3530_probe()
451 drvdata->regulator = NULL; in lm3530_probe()
455 if (drvdata->pdata->brt_val) { in lm3530_probe()
458 dev_err(&client->dev, in lm3530_probe()
463 err = led_classdev_register(&client->dev, &drvdata->led_dev); in lm3530_probe()
465 dev_err(&client->dev, "Register led class failed: %d\n", err); in lm3530_probe()
477 led_classdev_unregister(&drvdata->led_dev); in lm3530_remove()