Lines Matching refs:lp

79 static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data)  in lp855x_write_byte()  argument
81 return i2c_smbus_write_byte_data(lp->client, reg, data); in lp855x_write_byte()
84 static int lp855x_update_bit(struct lp855x *lp, u8 reg, u8 mask, u8 data) in lp855x_update_bit() argument
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()
99 return lp855x_write_byte(lp, reg, tmp); in lp855x_update_bit()
102 static bool lp855x_is_valid_rom_area(struct lp855x *lp, u8 addr) in lp855x_is_valid_rom_area() argument
106 switch (lp->chip_id) { in lp855x_is_valid_rom_area()
133 static int lp8557_bl_off(struct lp855x *lp) in lp8557_bl_off() argument
136 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_off()
140 static int lp8557_bl_on(struct lp855x *lp) in lp8557_bl_on() argument
143 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_on()
169 static int lp855x_configure(struct lp855x *lp) in lp855x_configure() argument
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()
184 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_configure()
189 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); in lp855x_configure()
197 if (!lp855x_is_valid_rom_area(lp, addr)) in lp855x_configure()
200 ret = lp855x_write_byte(lp, addr, 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()
220 static int lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) in lp855x_pwm_ctrl() argument
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_state(lp->pwm, &state); in lp855x_pwm_ctrl()
242 struct lp855x *lp = bl_get_data(bl); in lp855x_bl_update_status() local
248 if (lp->mode == PWM_BASED) in lp855x_bl_update_status()
249 return lp855x_pwm_ctrl(lp, 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()
262 static int lp855x_backlight_register(struct lp855x *lp) in lp855x_backlight_register() argument
266 struct lp855x_platform_data *pdata = lp->pdata; 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()
291 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_chip_id() local
293 return scnprintf(buf, PAGE_SIZE, "%s\n", lp->chipname); in lp855x_get_chip_id()
299 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_bl_ctl_mode() local
302 if (lp->mode == PWM_BASED) in lp855x_get_bl_ctl_mode()
304 else if (lp->mode == REGISTER_BASED) in lp855x_get_bl_ctl_mode()
324 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
326 struct device *dev = lp->dev; in lp855x_parse_dt()
328 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_parse_dt()
366 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
372 static int lp855x_parse_acpi(struct lp855x *lp) in lp855x_parse_acpi() argument
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()
400 struct lp855x *lp; in lp855x_probe() local
406 lp = devm_kzalloc(dev, sizeof(struct lp855x), GFP_KERNEL); in lp855x_probe()
407 if (!lp) 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()
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()
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()
448 ret = lp855x_parse_dt(lp); in lp855x_probe()
452 ret = lp855x_parse_acpi(lp); 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()
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()
469 lp->enable = NULL; 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()
478 lp->pwm = NULL; 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()
491 if (lp->supply) { in lp855x_probe()
492 ret = regulator_enable(lp->supply); in lp855x_probe()
499 if (lp->enable) { in lp855x_probe()
500 ret = regulator_enable(lp->enable); in lp855x_probe()
513 i2c_set_clientdata(cl, lp); in lp855x_probe()
515 ret = lp855x_configure(lp); in lp855x_probe()
521 ret = lp855x_backlight_register(lp); 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()
549 struct lp855x *lp = i2c_get_clientdata(cl); in lp855x_remove() local
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()