Lines Matching full:lp

78 static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)  in lp855x_write_byte()  argument
80 return i2c_smbus_write_byte_data(lp->client, reg, data); in lp855x_write_byte()
83 static int lp855x_update_bit(struct lp855x *lp, u8 reg, u8 mask, u8 data) in lp855x_update_bit() argument
88 ret = i2c_smbus_read_byte_data(lp->client, reg); in lp855x_update_bit()
90 dev_err(lp->dev, "failed to read 0x%.2x\n", reg); in lp855x_update_bit()
98 return lp855x_write_byte(lp, reg, tmp); in lp855x_update_bit()
101 static bool lp855x_is_valid_rom_area(struct lp855x *lp, u8 addr) in lp855x_is_valid_rom_area() argument
105 switch (lp->chip_id) { in lp855x_is_valid_rom_area()
132 static int lp8557_bl_off(struct lp855x *lp) in lp8557_bl_off() argument
135 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_off()
139 static int lp8557_bl_on(struct lp855x *lp) in lp8557_bl_on() argument
142 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_on()
168 static int lp855x_configure(struct lp855x *lp) in lp855x_configure() argument
172 struct lp855x_platform_data *pd = lp->pdata; in lp855x_configure()
174 if (lp->cfg->pre_init_device) { in lp855x_configure()
175 ret = lp->cfg->pre_init_device(lp); in lp855x_configure()
177 dev_err(lp->dev, "pre init device err: %d\n", ret); in lp855x_configure()
183 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_configure()
188 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); in lp855x_configure()
196 if (!lp855x_is_valid_rom_area(lp, addr)) in lp855x_configure()
199 ret = lp855x_write_byte(lp, addr, val); in lp855x_configure()
205 if (lp->cfg->post_init_device) { in lp855x_configure()
206 ret = lp->cfg->post_init_device(lp); in lp855x_configure()
208 dev_err(lp->dev, "post init device err: %d\n", ret); in lp855x_configure()
219 static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) in lp855x_pwm_ctrl() argument
225 if (!lp->pwm) { in lp855x_pwm_ctrl()
226 pwm = devm_pwm_get(lp->dev, lp->chipname); in lp855x_pwm_ctrl()
230 lp->pwm = pwm; in lp855x_pwm_ctrl()
232 pwm_init_state(lp->pwm, &state); in lp855x_pwm_ctrl()
234 pwm_get_state(lp->pwm, &state); in lp855x_pwm_ctrl()
237 state.period = lp->pdata->period_ns; in lp855x_pwm_ctrl()
241 pwm_apply_state(lp->pwm, &state); in lp855x_pwm_ctrl()
246 struct lp855x *lp = bl_get_data(bl); in lp855x_bl_update_status() local
252 if (lp->mode == PWM_BASED) in lp855x_bl_update_status()
253 lp855x_pwm_ctrl(lp, brightness, bl->props.max_brightness); in lp855x_bl_update_status()
254 else if (lp->mode == REGISTER_BASED) in lp855x_bl_update_status()
255 lp855x_write_byte(lp, lp->cfg->reg_brightness, (u8)brightness); in lp855x_bl_update_status()
265 static int lp855x_backlight_register(struct lp855x *lp) in lp855x_backlight_register() argument
269 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_backlight_register()
281 bl = devm_backlight_device_register(lp->dev, name, lp->dev, lp, in lp855x_backlight_register()
286 lp->bl = bl; in lp855x_backlight_register()
294 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_chip_id() local
296 return scnprintf(buf, PAGE_SIZE, "%s\n", lp->chipname); in lp855x_get_chip_id()
302 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_bl_ctl_mode() local
305 if (lp->mode == PWM_BASED) in lp855x_get_bl_ctl_mode()
307 else if (lp->mode == REGISTER_BASED) in lp855x_get_bl_ctl_mode()
327 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
329 struct device *dev = lp->dev; in lp855x_parse_dt()
331 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_parse_dt()
368 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
374 static int lp855x_parse_acpi(struct lp855x *lp) in lp855x_parse_acpi() argument
383 ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_brightness); in lp855x_parse_acpi()
387 lp->pdata->initial_brightness = ret; in lp855x_parse_acpi()
389 ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_devicectrl); in lp855x_parse_acpi()
393 lp->pdata->device_control = ret; in lp855x_parse_acpi()
401 struct lp855x *lp; in lp855x_probe() local
407 lp = devm_kzalloc(dev, sizeof(struct lp855x), GFP_KERNEL); in lp855x_probe()
408 if (!lp) in lp855x_probe()
411 lp->client = cl; in lp855x_probe()
412 lp->dev = dev; in lp855x_probe()
413 lp->pdata = dev_get_platdata(dev); in lp855x_probe()
416 lp->chipname = id->name; in lp855x_probe()
417 lp->chip_id = id->driver_data; in lp855x_probe()
423 lp->chipname = acpi_id->id; in lp855x_probe()
424 lp->chip_id = acpi_id->driver_data; in lp855x_probe()
427 switch (lp->chip_id) { in lp855x_probe()
433 lp->cfg = &lp855x_dev_cfg; in lp855x_probe()
437 lp->cfg = &lp8557_dev_cfg; in lp855x_probe()
443 if (!lp->pdata) { in lp855x_probe()
444 lp->pdata = devm_kzalloc(dev, sizeof(*lp->pdata), GFP_KERNEL); in lp855x_probe()
445 if (!lp->pdata) in lp855x_probe()
449 ret = lp855x_parse_dt(lp); in lp855x_probe()
453 ret = lp855x_parse_acpi(lp); in lp855x_probe()
459 if (lp->pdata->period_ns > 0) in lp855x_probe()
460 lp->mode = PWM_BASED; in lp855x_probe()
462 lp->mode = REGISTER_BASED; in lp855x_probe()
464 lp->supply = devm_regulator_get(dev, "power"); in lp855x_probe()
465 if (IS_ERR(lp->supply)) { in lp855x_probe()
466 if (PTR_ERR(lp->supply) == -EPROBE_DEFER) in lp855x_probe()
468 lp->supply = NULL; in lp855x_probe()
471 lp->enable = devm_regulator_get_optional(dev, "enable"); in lp855x_probe()
472 if (IS_ERR(lp->enable)) { in lp855x_probe()
473 ret = PTR_ERR(lp->enable); in lp855x_probe()
475 lp->enable = NULL; in lp855x_probe()
481 if (lp->supply) { in lp855x_probe()
482 ret = regulator_enable(lp->supply); in lp855x_probe()
489 if (lp->enable) { in lp855x_probe()
490 ret = regulator_enable(lp->enable); in lp855x_probe()
503 i2c_set_clientdata(cl, lp); in lp855x_probe()
505 ret = lp855x_configure(lp); in lp855x_probe()
511 ret = lp855x_backlight_register(lp); in lp855x_probe()
523 backlight_update_status(lp->bl); in lp855x_probe()
528 if (lp->enable) in lp855x_probe()
529 regulator_disable(lp->enable); in lp855x_probe()
531 if (lp->supply) in lp855x_probe()
532 regulator_disable(lp->supply); in lp855x_probe()
539 struct lp855x *lp = i2c_get_clientdata(cl); in lp855x_remove() local
541 lp->bl->props.brightness = 0; in lp855x_remove()
542 backlight_update_status(lp->bl); in lp855x_remove()
543 if (lp->enable) in lp855x_remove()
544 regulator_disable(lp->enable); in lp855x_remove()
545 if (lp->supply) in lp855x_remove()
546 regulator_disable(lp->supply); in lp855x_remove()
547 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_remove()