Lines Matching full:lp
77 static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data) in lp855x_write_byte() argument
79 return i2c_smbus_write_byte_data(lp->client, reg, data); in lp855x_write_byte()
82 static int lp855x_update_bit(struct lp855x *lp, u8 reg, u8 mask, u8 data) in lp855x_update_bit() argument
87 ret = i2c_smbus_read_byte_data(lp->client, reg); in lp855x_update_bit()
89 dev_err(lp->dev, "failed to read 0x%.2x\n", reg); in lp855x_update_bit()
97 return lp855x_write_byte(lp, reg, tmp); in lp855x_update_bit()
100 static bool lp855x_is_valid_rom_area(struct lp855x *lp, u8 addr) in lp855x_is_valid_rom_area() argument
104 switch (lp->chip_id) { in lp855x_is_valid_rom_area()
131 static int lp8557_bl_off(struct lp855x *lp) in lp8557_bl_off() argument
134 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_off()
138 static int lp8557_bl_on(struct lp855x *lp) in lp8557_bl_on() argument
141 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_on()
167 static int lp855x_configure(struct lp855x *lp) in lp855x_configure() argument
171 struct lp855x_platform_data *pd = lp->pdata; in lp855x_configure()
173 switch (lp->chip_id) { in lp855x_configure()
179 lp->cfg = &lp855x_dev_cfg; in lp855x_configure()
183 lp->cfg = &lp8557_dev_cfg; in lp855x_configure()
189 if (lp->cfg->pre_init_device) { in lp855x_configure()
190 ret = lp->cfg->pre_init_device(lp); in lp855x_configure()
192 dev_err(lp->dev, "pre init device err: %d\n", ret); in lp855x_configure()
198 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_configure()
203 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); in lp855x_configure()
211 if (!lp855x_is_valid_rom_area(lp, addr)) in lp855x_configure()
214 ret = lp855x_write_byte(lp, addr, val); in lp855x_configure()
220 if (lp->cfg->post_init_device) { in lp855x_configure()
221 ret = lp->cfg->post_init_device(lp); in lp855x_configure()
223 dev_err(lp->dev, "post init device err: %d\n", ret); in lp855x_configure()
234 static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) in lp855x_pwm_ctrl() argument
236 unsigned int period = lp->pdata->period_ns; in lp855x_pwm_ctrl()
241 if (!lp->pwm) { in lp855x_pwm_ctrl()
242 pwm = devm_pwm_get(lp->dev, lp->chipname); in lp855x_pwm_ctrl()
246 lp->pwm = pwm; in lp855x_pwm_ctrl()
255 pwm_config(lp->pwm, duty, period); in lp855x_pwm_ctrl()
257 pwm_enable(lp->pwm); in lp855x_pwm_ctrl()
259 pwm_disable(lp->pwm); in lp855x_pwm_ctrl()
264 struct lp855x *lp = bl_get_data(bl); in lp855x_bl_update_status() local
270 if (lp->mode == PWM_BASED) in lp855x_bl_update_status()
271 lp855x_pwm_ctrl(lp, brightness, bl->props.max_brightness); in lp855x_bl_update_status()
272 else if (lp->mode == REGISTER_BASED) in lp855x_bl_update_status()
273 lp855x_write_byte(lp, lp->cfg->reg_brightness, (u8)brightness); in lp855x_bl_update_status()
283 static int lp855x_backlight_register(struct lp855x *lp) in lp855x_backlight_register() argument
287 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_backlight_register()
299 bl = devm_backlight_device_register(lp->dev, name, lp->dev, lp, in lp855x_backlight_register()
304 lp->bl = bl; in lp855x_backlight_register()
312 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_chip_id() local
314 return scnprintf(buf, PAGE_SIZE, "%s\n", lp->chipname); in lp855x_get_chip_id()
320 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_bl_ctl_mode() local
323 if (lp->mode == PWM_BASED) in lp855x_get_bl_ctl_mode()
325 else if (lp->mode == REGISTER_BASED) in lp855x_get_bl_ctl_mode()
345 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
347 struct device *dev = lp->dev; in lp855x_parse_dt()
387 lp->pdata = pdata; in lp855x_parse_dt()
392 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
400 struct lp855x *lp; in lp855x_probe() local
406 lp = devm_kzalloc(&cl->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 = &cl->dev; in lp855x_probe()
412 lp->chipname = id->name; in lp855x_probe()
413 lp->chip_id = id->driver_data; in lp855x_probe()
414 lp->pdata = dev_get_platdata(&cl->dev); in lp855x_probe()
416 if (!lp->pdata) { in lp855x_probe()
417 ret = lp855x_parse_dt(lp); in lp855x_probe()
422 if (lp->pdata->period_ns > 0) in lp855x_probe()
423 lp->mode = PWM_BASED; in lp855x_probe()
425 lp->mode = REGISTER_BASED; in lp855x_probe()
427 lp->supply = devm_regulator_get(lp->dev, "power"); in lp855x_probe()
428 if (IS_ERR(lp->supply)) { in lp855x_probe()
429 if (PTR_ERR(lp->supply) == -EPROBE_DEFER) in lp855x_probe()
431 lp->supply = NULL; in lp855x_probe()
434 lp->enable = devm_regulator_get_optional(lp->dev, "enable"); in lp855x_probe()
435 if (IS_ERR(lp->enable)) { in lp855x_probe()
436 ret = PTR_ERR(lp->enable); in lp855x_probe()
438 lp->enable = NULL; in lp855x_probe()
441 dev_err(lp->dev, "error getting enable regulator: %d\n", in lp855x_probe()
447 if (lp->supply) { in lp855x_probe()
448 ret = regulator_enable(lp->supply); in lp855x_probe()
455 if (lp->enable) { in lp855x_probe()
456 ret = regulator_enable(lp->enable); in lp855x_probe()
458 dev_err(lp->dev, "failed to enable vddio: %d\n", ret); in lp855x_probe()
469 i2c_set_clientdata(cl, lp); in lp855x_probe()
471 ret = lp855x_configure(lp); in lp855x_probe()
473 dev_err(lp->dev, "device config err: %d", ret); in lp855x_probe()
477 ret = lp855x_backlight_register(lp); in lp855x_probe()
479 dev_err(lp->dev, in lp855x_probe()
484 ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_probe()
486 dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret); in lp855x_probe()
490 backlight_update_status(lp->bl); in lp855x_probe()
495 if (lp->enable) in lp855x_probe()
496 regulator_disable(lp->enable); in lp855x_probe()
498 if (lp->supply) in lp855x_probe()
499 regulator_disable(lp->supply); in lp855x_probe()
506 struct lp855x *lp = i2c_get_clientdata(cl); in lp855x_remove() local
508 lp->bl->props.brightness = 0; in lp855x_remove()
509 backlight_update_status(lp->bl); in lp855x_remove()
510 if (lp->enable) in lp855x_remove()
511 regulator_disable(lp->enable); in lp855x_remove()
512 if (lp->supply) in lp855x_remove()
513 regulator_disable(lp->supply); in lp855x_remove()
514 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_remove()