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 switch (lp->chip_id) { in lp855x_configure()
181 lp->cfg = &lp855x_dev_cfg; in lp855x_configure()
185 lp->cfg = &lp8557_dev_cfg; in lp855x_configure()
191 if (lp->cfg->pre_init_device) { in lp855x_configure()
192 ret = lp->cfg->pre_init_device(lp); in lp855x_configure()
194 dev_err(lp->dev, "pre init device err: %d\n", ret); in lp855x_configure()
200 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_configure()
205 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); in lp855x_configure()
213 if (!lp855x_is_valid_rom_area(lp, addr)) in lp855x_configure()
216 ret = lp855x_write_byte(lp, addr, val); in lp855x_configure()
222 if (lp->cfg->post_init_device) { in lp855x_configure()
223 ret = lp->cfg->post_init_device(lp); in lp855x_configure()
225 dev_err(lp->dev, "post init device err: %d\n", ret); in lp855x_configure()
236 static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) in lp855x_pwm_ctrl() argument
238 unsigned int period = lp->pdata->period_ns; in lp855x_pwm_ctrl()
243 if (!lp->pwm) { in lp855x_pwm_ctrl()
244 pwm = devm_pwm_get(lp->dev, lp->chipname); in lp855x_pwm_ctrl()
248 lp->pwm = pwm; in lp855x_pwm_ctrl()
251 pwm_config(lp->pwm, duty, period); in lp855x_pwm_ctrl()
253 pwm_enable(lp->pwm); in lp855x_pwm_ctrl()
255 pwm_disable(lp->pwm); in lp855x_pwm_ctrl()
260 struct lp855x *lp = bl_get_data(bl); in lp855x_bl_update_status() local
266 if (lp->mode == PWM_BASED) in lp855x_bl_update_status()
267 lp855x_pwm_ctrl(lp, brightness, bl->props.max_brightness); in lp855x_bl_update_status()
268 else if (lp->mode == REGISTER_BASED) in lp855x_bl_update_status()
269 lp855x_write_byte(lp, lp->cfg->reg_brightness, (u8)brightness); in lp855x_bl_update_status()
279 static int lp855x_backlight_register(struct lp855x *lp) in lp855x_backlight_register() argument
283 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_backlight_register()
295 bl = devm_backlight_device_register(lp->dev, name, lp->dev, lp, in lp855x_backlight_register()
300 lp->bl = bl; in lp855x_backlight_register()
308 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_chip_id() local
310 return scnprintf(buf, PAGE_SIZE, "%s\n", lp->chipname); in lp855x_get_chip_id()
316 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_bl_ctl_mode() local
319 if (lp->mode == PWM_BASED) in lp855x_get_bl_ctl_mode()
321 else if (lp->mode == REGISTER_BASED) in lp855x_get_bl_ctl_mode()
341 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
343 struct device *dev = lp->dev; in lp855x_parse_dt()
383 lp->pdata = pdata; in lp855x_parse_dt()
388 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
396 struct lp855x *lp; in lp855x_probe() local
402 lp = devm_kzalloc(&cl->dev, sizeof(struct lp855x), GFP_KERNEL); in lp855x_probe()
403 if (!lp) in lp855x_probe()
406 lp->client = cl; in lp855x_probe()
407 lp->dev = &cl->dev; in lp855x_probe()
408 lp->chipname = id->name; in lp855x_probe()
409 lp->chip_id = id->driver_data; in lp855x_probe()
410 lp->pdata = dev_get_platdata(&cl->dev); in lp855x_probe()
412 if (!lp->pdata) { in lp855x_probe()
413 ret = lp855x_parse_dt(lp); in lp855x_probe()
418 if (lp->pdata->period_ns > 0) in lp855x_probe()
419 lp->mode = PWM_BASED; in lp855x_probe()
421 lp->mode = REGISTER_BASED; in lp855x_probe()
423 lp->supply = devm_regulator_get(lp->dev, "power"); in lp855x_probe()
424 if (IS_ERR(lp->supply)) { in lp855x_probe()
425 if (PTR_ERR(lp->supply) == -EPROBE_DEFER) in lp855x_probe()
427 lp->supply = NULL; in lp855x_probe()
430 if (lp->supply) { in lp855x_probe()
431 ret = regulator_enable(lp->supply); in lp855x_probe()
438 i2c_set_clientdata(cl, lp); in lp855x_probe()
440 ret = lp855x_configure(lp); in lp855x_probe()
442 dev_err(lp->dev, "device config err: %d", ret); in lp855x_probe()
446 ret = lp855x_backlight_register(lp); in lp855x_probe()
448 dev_err(lp->dev, in lp855x_probe()
453 ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_probe()
455 dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret); in lp855x_probe()
459 backlight_update_status(lp->bl); in lp855x_probe()
465 struct lp855x *lp = i2c_get_clientdata(cl); in lp855x_remove() local
467 lp->bl->props.brightness = 0; in lp855x_remove()
468 backlight_update_status(lp->bl); in lp855x_remove()
469 if (lp->supply) in lp855x_remove()
470 regulator_disable(lp->supply); in lp855x_remove()
471 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_remove()