Lines Matching +full:pwm +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-only
17 #include <linux/pwm.h>
40 #define DEFAULT_BL_NAME "lcd-backlight"
73 struct pwm_device *pwm; member
76 struct regulator *enable; /* regulator for EN/VDDIO input */ member
81 return i2c_smbus_write_byte_data(lp->client, reg, data); in lp855x_write_byte()
89 ret = i2c_smbus_read_byte_data(lp->client, reg); in lp855x_update_bit()
91 dev_err(lp->dev, "failed to read 0x%.2x\n", reg); in lp855x_update_bit()
106 switch (lp->chip_id) { in lp855x_is_valid_rom_area()
173 struct lp855x_platform_data *pd = lp->pdata; in lp855x_configure()
175 if (lp->cfg->pre_init_device) { in lp855x_configure()
176 ret = lp->cfg->pre_init_device(lp); in lp855x_configure()
178 dev_err(lp->dev, "pre init device err: %d\n", ret); in lp855x_configure()
183 val = pd->initial_brightness; in lp855x_configure()
184 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_configure()
188 val = pd->device_control; in lp855x_configure()
189 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); in lp855x_configure()
193 if (pd->size_program > 0) { in lp855x_configure()
194 for (i = 0; i < pd->size_program; i++) { in lp855x_configure()
195 addr = pd->rom_data[i].addr; in lp855x_configure()
196 val = pd->rom_data[i].val; in lp855x_configure()
206 if (lp->cfg->post_init_device) { in lp855x_configure()
207 ret = lp->cfg->post_init_device(lp); in lp855x_configure()
209 dev_err(lp->dev, "post init device err: %d\n", ret); in lp855x_configure()
224 if (lp->needs_pwm_init) { in lp855x_pwm_ctrl()
225 pwm_init_state(lp->pwm, &state); in lp855x_pwm_ctrl()
227 if (lp->pdata->period_ns > 0) in lp855x_pwm_ctrl()
228 state.period = lp->pdata->period_ns; in lp855x_pwm_ctrl()
229 lp->needs_pwm_init = false; in lp855x_pwm_ctrl()
231 pwm_get_state(lp->pwm, &state); in lp855x_pwm_ctrl()
237 return pwm_apply_might_sleep(lp->pwm, &state); in lp855x_pwm_ctrl()
243 int brightness = bl->props.brightness; in lp855x_bl_update_status()
245 if (bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) in lp855x_bl_update_status()
248 if (lp->mode == PWM_BASED) in lp855x_bl_update_status()
250 bl->props.max_brightness); in lp855x_bl_update_status()
251 else if (lp->mode == REGISTER_BASED) in lp855x_bl_update_status()
252 return lp855x_write_byte(lp, lp->cfg->reg_brightness, in lp855x_bl_update_status()
254 return -EINVAL; in lp855x_bl_update_status()
266 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_backlight_register()
267 const char *name = pdata->name ? : DEFAULT_BL_NAME; in lp855x_backlight_register()
273 if (pdata->initial_brightness > props.max_brightness) in lp855x_backlight_register()
274 pdata->initial_brightness = props.max_brightness; in lp855x_backlight_register()
276 props.brightness = pdata->initial_brightness; in lp855x_backlight_register()
278 bl = devm_backlight_device_register(lp->dev, name, lp->dev, lp, in lp855x_backlight_register()
283 lp->bl = bl; in lp855x_backlight_register()
293 return scnprintf(buf, PAGE_SIZE, "%s\n", lp->chipname); in lp855x_get_chip_id()
302 if (lp->mode == PWM_BASED) in lp855x_get_bl_ctl_mode()
303 strmode = "pwm based"; in lp855x_get_bl_ctl_mode()
304 else if (lp->mode == REGISTER_BASED) in lp855x_get_bl_ctl_mode()
326 struct device *dev = lp->dev; in lp855x_parse_dt()
327 struct device_node *node = dev->of_node; in lp855x_parse_dt()
328 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_parse_dt()
333 return -EINVAL; in lp855x_parse_dt()
336 of_property_read_string(node, "bl-name", &pdata->name); in lp855x_parse_dt()
337 of_property_read_u8(node, "dev-ctrl", &pdata->device_control); in lp855x_parse_dt()
338 of_property_read_u8(node, "init-brt", &pdata->initial_brightness); in lp855x_parse_dt()
340 of_property_read_u32(node, "pwm-period", &pdata->period_ns); in lp855x_parse_dt()
351 return -ENOMEM; in lp855x_parse_dt()
354 of_property_read_u8(child, "rom-addr", &rom[i].addr); in lp855x_parse_dt()
355 of_property_read_u8(child, "rom-val", &rom[i].val); in lp855x_parse_dt()
359 pdata->size_program = rom_length; in lp855x_parse_dt()
360 pdata->rom_data = &rom[0]; in lp855x_parse_dt()
368 return -EINVAL; in lp855x_parse_dt()
381 ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_brightness); in lp855x_parse_acpi()
385 lp->pdata->initial_brightness = ret; in lp855x_parse_acpi()
387 ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_devicectrl); in lp855x_parse_acpi()
391 lp->pdata->device_control = ret; in lp855x_parse_acpi()
399 struct device *dev = &cl->dev; in lp855x_probe()
403 if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) in lp855x_probe()
404 return -EIO; in lp855x_probe()
408 return -ENOMEM; in lp855x_probe()
410 lp->client = cl; in lp855x_probe()
411 lp->dev = dev; in lp855x_probe()
412 lp->pdata = dev_get_platdata(dev); in lp855x_probe()
415 lp->chipname = id->name; in lp855x_probe()
416 lp->chip_id = id->driver_data; in lp855x_probe()
418 acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); in lp855x_probe()
420 return -ENODEV; in lp855x_probe()
422 lp->chipname = acpi_id->id; in lp855x_probe()
423 lp->chip_id = acpi_id->driver_data; in lp855x_probe()
426 switch (lp->chip_id) { in lp855x_probe()
432 lp->cfg = &lp855x_dev_cfg; in lp855x_probe()
436 lp->cfg = &lp8557_dev_cfg; in lp855x_probe()
439 return -EINVAL; in lp855x_probe()
442 if (!lp->pdata) { in lp855x_probe()
443 lp->pdata = devm_kzalloc(dev, sizeof(*lp->pdata), GFP_KERNEL); in lp855x_probe()
444 if (!lp->pdata) in lp855x_probe()
445 return -ENOMEM; in lp855x_probe()
458 lp->supply = devm_regulator_get(dev, "power"); in lp855x_probe()
459 if (IS_ERR(lp->supply)) { in lp855x_probe()
460 if (PTR_ERR(lp->supply) == -EPROBE_DEFER) in lp855x_probe()
461 return -EPROBE_DEFER; in lp855x_probe()
462 lp->supply = NULL; in lp855x_probe()
465 lp->enable = devm_regulator_get_optional(dev, "enable"); in lp855x_probe()
466 if (IS_ERR(lp->enable)) { in lp855x_probe()
467 ret = PTR_ERR(lp->enable); in lp855x_probe()
468 if (ret == -ENODEV) in lp855x_probe()
469 lp->enable = NULL; in lp855x_probe()
471 return dev_err_probe(dev, ret, "getting enable regulator\n"); in lp855x_probe()
474 lp->pwm = devm_pwm_get(lp->dev, lp->chipname); in lp855x_probe()
475 if (IS_ERR(lp->pwm)) { in lp855x_probe()
476 ret = PTR_ERR(lp->pwm); in lp855x_probe()
477 if (ret == -ENODEV || ret == -EINVAL) in lp855x_probe()
478 lp->pwm = NULL; in lp855x_probe()
480 return dev_err_probe(dev, ret, "getting PWM\n"); in lp855x_probe()
482 lp->needs_pwm_init = false; in lp855x_probe()
483 lp->mode = REGISTER_BASED; in lp855x_probe()
486 lp->needs_pwm_init = true; in lp855x_probe()
487 lp->mode = PWM_BASED; in lp855x_probe()
488 dev_dbg(dev, "mode: PWM based\n"); in lp855x_probe()
491 if (lp->supply) { in lp855x_probe()
492 ret = regulator_enable(lp->supply); in lp855x_probe()
494 dev_err(dev, "failed to enable supply: %d\n", ret); in lp855x_probe()
499 if (lp->enable) { in lp855x_probe()
500 ret = regulator_enable(lp->enable); in lp855x_probe()
502 dev_err(dev, "failed to enable vddio: %d\n", ret); in lp855x_probe()
527 ret = sysfs_create_group(&dev->kobj, &lp855x_attr_group); in lp855x_probe()
533 backlight_update_status(lp->bl); in lp855x_probe()
538 if (lp->enable) in lp855x_probe()
539 regulator_disable(lp->enable); in lp855x_probe()
541 if (lp->supply) in lp855x_probe()
542 regulator_disable(lp->supply); in lp855x_probe()
551 lp->bl->props.brightness = 0; in lp855x_remove()
552 backlight_update_status(lp->bl); in lp855x_remove()
553 if (lp->enable) in lp855x_remove()
554 regulator_disable(lp->enable); in lp855x_remove()
555 if (lp->supply) in lp855x_remove()
556 regulator_disable(lp->supply); in lp855x_remove()
557 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_remove()