Lines Matching refs:lp
81 static int lp855x_write_byte(struct lp855x *lp, u8 reg, u8 data) in lp855x_write_byte() argument
83 return i2c_smbus_write_byte_data(lp->client, reg, data); in lp855x_write_byte()
86 static int lp855x_update_bit(struct lp855x *lp, u8 reg, u8 mask, u8 data) in lp855x_update_bit() argument
91 ret = i2c_smbus_read_byte_data(lp->client, reg); in lp855x_update_bit()
93 dev_err(lp->dev, "failed to read 0x%.2x\n", reg); in lp855x_update_bit()
101 return lp855x_write_byte(lp, reg, tmp); in lp855x_update_bit()
104 static bool lp855x_is_valid_rom_area(struct lp855x *lp, u8 addr) in lp855x_is_valid_rom_area() argument
108 switch (lp->chip_id) { in lp855x_is_valid_rom_area()
135 static int lp8557_bl_off(struct lp855x *lp) in lp8557_bl_off() argument
138 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_off()
142 static int lp8557_bl_on(struct lp855x *lp) in lp8557_bl_on() argument
145 return lp855x_update_bit(lp, LP8557_BL_CMD, LP8557_BL_MASK, in lp8557_bl_on()
171 static int lp855x_configure(struct lp855x *lp) in lp855x_configure() argument
175 struct lp855x_platform_data *pd = lp->pdata; in lp855x_configure()
177 switch (lp->chip_id) { in lp855x_configure()
183 lp->cfg = &lp855x_dev_cfg; in lp855x_configure()
187 lp->cfg = &lp8557_dev_cfg; in lp855x_configure()
193 if (lp->cfg->pre_init_device) { in lp855x_configure()
194 ret = lp->cfg->pre_init_device(lp); in lp855x_configure()
196 dev_err(lp->dev, "pre init device err: %d\n", ret); in lp855x_configure()
202 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_configure()
207 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); in lp855x_configure()
215 if (!lp855x_is_valid_rom_area(lp, addr)) in lp855x_configure()
218 ret = lp855x_write_byte(lp, addr, val); in lp855x_configure()
224 if (lp->cfg->post_init_device) { in lp855x_configure()
225 ret = lp->cfg->post_init_device(lp); in lp855x_configure()
227 dev_err(lp->dev, "post init device err: %d\n", ret); in lp855x_configure()
238 static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) in lp855x_pwm_ctrl() argument
240 unsigned int period = lp->pdata->period_ns; in lp855x_pwm_ctrl()
245 if (!lp->pwm) { in lp855x_pwm_ctrl()
246 pwm = devm_pwm_get(lp->dev, lp->chipname); in lp855x_pwm_ctrl()
250 lp->pwm = pwm; in lp855x_pwm_ctrl()
259 pwm_config(lp->pwm, duty, period); in lp855x_pwm_ctrl()
261 pwm_enable(lp->pwm); in lp855x_pwm_ctrl()
263 pwm_disable(lp->pwm); in lp855x_pwm_ctrl()
268 struct lp855x *lp = bl_get_data(bl); in lp855x_bl_update_status() local
274 if (lp->mode == PWM_BASED) in lp855x_bl_update_status()
275 lp855x_pwm_ctrl(lp, brightness, bl->props.max_brightness); in lp855x_bl_update_status()
276 else if (lp->mode == REGISTER_BASED) in lp855x_bl_update_status()
277 lp855x_write_byte(lp, lp->cfg->reg_brightness, (u8)brightness); in lp855x_bl_update_status()
287 static int lp855x_backlight_register(struct lp855x *lp) in lp855x_backlight_register() argument
291 struct lp855x_platform_data *pdata = lp->pdata; in lp855x_backlight_register()
303 bl = devm_backlight_device_register(lp->dev, name, lp->dev, lp, in lp855x_backlight_register()
308 lp->bl = bl; in lp855x_backlight_register()
316 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_chip_id() local
318 return scnprintf(buf, PAGE_SIZE, "%s\n", lp->chipname); in lp855x_get_chip_id()
324 struct lp855x *lp = dev_get_drvdata(dev); in lp855x_get_bl_ctl_mode() local
327 if (lp->mode == PWM_BASED) in lp855x_get_bl_ctl_mode()
329 else if (lp->mode == REGISTER_BASED) in lp855x_get_bl_ctl_mode()
349 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
351 struct device *dev = lp->dev; in lp855x_parse_dt()
391 lp->pdata = pdata; in lp855x_parse_dt()
396 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
404 struct lp855x *lp; in lp855x_probe() local
410 lp = devm_kzalloc(&cl->dev, sizeof(struct lp855x), GFP_KERNEL); in lp855x_probe()
411 if (!lp) in lp855x_probe()
414 lp->client = cl; in lp855x_probe()
415 lp->dev = &cl->dev; in lp855x_probe()
416 lp->chipname = id->name; in lp855x_probe()
417 lp->chip_id = id->driver_data; in lp855x_probe()
418 lp->pdata = dev_get_platdata(&cl->dev); in lp855x_probe()
420 if (!lp->pdata) { in lp855x_probe()
421 ret = lp855x_parse_dt(lp); in lp855x_probe()
426 if (lp->pdata->period_ns > 0) in lp855x_probe()
427 lp->mode = PWM_BASED; in lp855x_probe()
429 lp->mode = REGISTER_BASED; in lp855x_probe()
431 lp->supply = devm_regulator_get(lp->dev, "power"); in lp855x_probe()
432 if (IS_ERR(lp->supply)) { in lp855x_probe()
433 if (PTR_ERR(lp->supply) == -EPROBE_DEFER) in lp855x_probe()
435 lp->supply = NULL; in lp855x_probe()
438 lp->enable = devm_regulator_get_optional(lp->dev, "enable"); in lp855x_probe()
439 if (IS_ERR(lp->enable)) { in lp855x_probe()
440 ret = PTR_ERR(lp->enable); in lp855x_probe()
442 lp->enable = NULL; in lp855x_probe()
445 dev_err(lp->dev, "error getting enable regulator: %d\n", in lp855x_probe()
451 if (lp->supply) { in lp855x_probe()
452 ret = regulator_enable(lp->supply); in lp855x_probe()
459 if (lp->enable) { in lp855x_probe()
460 ret = regulator_enable(lp->enable); in lp855x_probe()
462 dev_err(lp->dev, "failed to enable vddio: %d\n", ret); in lp855x_probe()
473 i2c_set_clientdata(cl, lp); in lp855x_probe()
475 ret = lp855x_configure(lp); in lp855x_probe()
477 dev_err(lp->dev, "device config err: %d", ret); in lp855x_probe()
481 ret = lp855x_backlight_register(lp); in lp855x_probe()
483 dev_err(lp->dev, in lp855x_probe()
488 ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_probe()
490 dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret); in lp855x_probe()
494 backlight_update_status(lp->bl); in lp855x_probe()
500 struct lp855x *lp = i2c_get_clientdata(cl); in lp855x_remove() local
502 lp->bl->props.brightness = 0; in lp855x_remove()
503 backlight_update_status(lp->bl); in lp855x_remove()
504 if (lp->supply) in lp855x_remove()
505 regulator_disable(lp->supply); in lp855x_remove()
506 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_remove()