Lines Matching refs: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 switch (lp->chip_id) { in lp855x_configure()
180 lp->cfg = &lp855x_dev_cfg; in lp855x_configure()
184 lp->cfg = &lp8557_dev_cfg; in lp855x_configure()
190 if (lp->cfg->pre_init_device) { in lp855x_configure()
191 ret = lp->cfg->pre_init_device(lp); in lp855x_configure()
193 dev_err(lp->dev, "pre init device err: %d\n", ret); in lp855x_configure()
199 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_configure()
204 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); in lp855x_configure()
212 if (!lp855x_is_valid_rom_area(lp, addr)) in lp855x_configure()
215 ret = lp855x_write_byte(lp, addr, val); in lp855x_configure()
221 if (lp->cfg->post_init_device) { in lp855x_configure()
222 ret = lp->cfg->post_init_device(lp); in lp855x_configure()
224 dev_err(lp->dev, "post init device err: %d\n", ret); in lp855x_configure()
235 static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) in lp855x_pwm_ctrl() argument
237 unsigned int period = lp->pdata->period_ns; in lp855x_pwm_ctrl()
242 if (!lp->pwm) { in lp855x_pwm_ctrl()
243 pwm = devm_pwm_get(lp->dev, lp->chipname); in lp855x_pwm_ctrl()
247 lp->pwm = pwm; in lp855x_pwm_ctrl()
250 pwm_config(lp->pwm, duty, period); in lp855x_pwm_ctrl()
252 pwm_enable(lp->pwm); in lp855x_pwm_ctrl()
254 pwm_disable(lp->pwm); in lp855x_pwm_ctrl()
259 struct lp855x *lp = bl_get_data(bl); in lp855x_bl_update_status() local
264 if (lp->mode == PWM_BASED) { in lp855x_bl_update_status()
268 lp855x_pwm_ctrl(lp, br, max_br); in lp855x_bl_update_status()
270 } else if (lp->mode == REGISTER_BASED) { in lp855x_bl_update_status()
273 lp855x_write_byte(lp, lp->cfg->reg_brightness, val); in lp855x_bl_update_status()
284 static int lp855x_backlight_register(struct lp855x *lp) in lp855x_backlight_register() argument
288 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()
394 lp->pdata = pdata; in lp855x_parse_dt()
399 static int lp855x_parse_dt(struct lp855x *lp) in lp855x_parse_dt() argument
407 struct lp855x *lp; in lp855x_probe() local
413 lp = devm_kzalloc(&cl->dev, sizeof(struct lp855x), GFP_KERNEL); in lp855x_probe()
414 if (!lp) in lp855x_probe()
417 lp->client = cl; in lp855x_probe()
418 lp->dev = &cl->dev; in lp855x_probe()
419 lp->chipname = id->name; in lp855x_probe()
420 lp->chip_id = id->driver_data; in lp855x_probe()
421 lp->pdata = dev_get_platdata(&cl->dev); in lp855x_probe()
423 if (!lp->pdata) { in lp855x_probe()
424 ret = lp855x_parse_dt(lp); in lp855x_probe()
429 if (lp->pdata->period_ns > 0) in lp855x_probe()
430 lp->mode = PWM_BASED; in lp855x_probe()
432 lp->mode = REGISTER_BASED; in lp855x_probe()
434 if (lp->pdata->supply) { in lp855x_probe()
435 ret = regulator_enable(lp->pdata->supply); in lp855x_probe()
442 i2c_set_clientdata(cl, lp); in lp855x_probe()
444 ret = lp855x_configure(lp); in lp855x_probe()
446 dev_err(lp->dev, "device config err: %d", ret); in lp855x_probe()
450 ret = lp855x_backlight_register(lp); in lp855x_probe()
452 dev_err(lp->dev, in lp855x_probe()
457 ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_probe()
459 dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret); in lp855x_probe()
463 backlight_update_status(lp->bl); in lp855x_probe()
469 struct lp855x *lp = i2c_get_clientdata(cl); in lp855x_remove() local
471 lp->bl->props.brightness = 0; in lp855x_remove()
472 backlight_update_status(lp->bl); in lp855x_remove()
473 if (lp->pdata->supply) in lp855x_remove()
474 regulator_disable(lp->pdata->supply); in lp855x_remove()
475 sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group); in lp855x_remove()