static int lp855x_init_registers(struct lp855x *lp) { u8 val, addr; int i, ret; struct lp855x_platform_data *pd = lp->pdata; val = pd->initial_brightness; ret = lp855x_set_brightness(lp, val); if (ret) return ret; val = pd->device_control; ret = lp855x_write_byte(lp, DEVICE_CTRL, val); if (ret) return ret; if (pd->load_new_rom_data && pd->size_program) { for (i = 0; i < pd->size_program; i++) { addr = pd->rom_data[i].addr; val = pd->rom_data[i].val; if (!lp855x_is_valid_rom_area(lp, addr)) continue; ret = lp855x_write_byte(lp, addr, val); if (ret) return ret; } } return ret; }
static void lp855x_init_device(struct lp855x *lp) { u8 val, addr; int i, ret; struct lp855x_platform_data *pd = lp->pdata; val = pd->device_control; ret = lp855x_write_byte(lp, DEVICE_CTRL, val); if (pd->load_new_rom_data && pd->size_program) { for (i = 0; i < pd->size_program; i++) { addr = pd->rom_data[i].addr; val = pd->rom_data[i].val; if (!lp855x_is_valid_rom_area(lp, addr)) continue; if (addr == CFG98_CTRL) { u8 cfg98; lp855x_read_byte(lp, CFG98_CTRL, &cfg98); cfg98 &= ~IBOOST_LIM_2X_MASK; val = cfg98 | (val & IBOOST_LIM_2X_MASK); } ret |= lp855x_write_byte(lp, addr, val); } } ret |= lp855x_write_byte(lp, CFG3_CTRL, pd->cfg3); if (ret) dev_err(lp->dev, "i2c write err\n"); }
static int lp855x_resume_init(struct lp855x *lp) { u8 val, addr; int i, ret = 0; if (lp->cfg->pre_init_device) { ret = lp->cfg->pre_init_device(lp); if (ret) { dev_err(lp->dev, "pre init device err: %d\n", ret); goto exit; } } if (lp->pdata->size_program > 0) { for (i = 0; i < lp->pdata->size_program; i++) { addr = lp->pdata->rom_data[i].addr; val = lp->pdata->rom_data[i].val; if (!lp855x_is_valid_rom_area(lp, addr)) continue; if (addr == CFG98_CTRL) { u8 cfg98; lp855x_read_byte(lp, CFG98_CTRL, &cfg98); cfg98 &= ~IBOOST_LIM_2X_MASK; val = cfg98 | (val & IBOOST_LIM_2X_MASK); } ret = lp855x_write_byte(lp, addr, val); if (ret) { dev_err(lp->dev, "set register err: %d\n", ret); goto exit; } } } ret = lp855x_write_byte(lp, lp->cfg->reg_slope, lp->pdata->slope_reg); if (ret) { dev_err(lp->dev, "i2c write err\n"); goto exit; } if (lp->cfg->post_init_device) { ret = lp->cfg->post_init_device(lp); if (ret) { dev_err(lp->dev, "post init device err: %d\n", ret); goto exit; } } exit: return ret; }
/* * Device specific configuration flow * * a) pre_init_device(optional) * b) update the brightness register * c) update ROM area(optional) * d) post_init_device(optional) * */ static int lp855x_configure(struct lp855x *lp) { u8 val, addr; bool need_config; int i, ret, brightness; struct lp855x_platform_data *pd = lp->pdata; switch (lp->chipid->driver_data) { case LP8550 ... LP8556: lp->cfg = &lp855x_dev_cfg; break; case LP8557: lp->cfg = &lp8557_dev_cfg; break; default: ret = -EINVAL; dev_err(lp->dev, "device support err: %d\n", ret); goto exit; } ret = lp855x_check_need_config(lp, &need_config); if (ret || !need_config) goto exit; if (lp->cfg->pre_init_device) { ret = lp->cfg->pre_init_device(lp); if (ret) { dev_err(lp->dev, "pre init device err: %d\n", ret); goto exit; } } brightness = pd->initial_brightness; ret = lp855x_write_brightness(lp, lp->cfg->is_8bit_brightness, brightness); if (ret) { dev_err(lp->dev, "set initial brightness err: %d\n", ret); goto exit; } if (pd->size_program > 0) { for (i = 0; i < pd->size_program; i++) { addr = pd->rom_data[i].addr; val = pd->rom_data[i].val; if (!lp855x_is_valid_rom_area(lp, addr)) continue; if (addr == CFG98_CTRL) { u8 cfg98; lp855x_read_byte(lp, CFG98_CTRL, &cfg98); cfg98 &= ~IBOOST_LIM_2X_MASK; val = cfg98 | (val & IBOOST_LIM_2X_MASK); } ret = lp855x_write_byte(lp, addr, val); if (ret) { dev_err(lp->dev, "set register err: %d\n", ret); goto exit; } } } ret = lp855x_write_byte(lp, lp->cfg->reg_slope, pd->slope_reg); if (ret) { dev_err(lp->dev, "i2c write err\n"); goto exit; } if (lp->cfg->post_init_device) { ret = lp->cfg->post_init_device(lp); if (ret) { dev_err(lp->dev, "post init device err: %d\n", ret); goto exit; } } exit: return ret; }
/* * Device specific configuration flow * * a) pre_init_device(optional) * b) update the brightness register * c) update device control register * d) update ROM area(optional) * e) post_init_device(optional) * */ static int lp855x_configure(struct lp855x *lp) { u8 val, addr; int i, ret; struct lp855x_platform_data *pd = lp->pdata; switch (lp->chip_id) { case LP8550 ... LP8556: lp->cfg = &lp855x_dev_cfg; break; case LP8557: lp->cfg = &lp8557_dev_cfg; break; default: return -EINVAL; } if (lp->cfg->pre_init_device) { ret = lp->cfg->pre_init_device(lp); if (ret) { dev_err(lp->dev, "pre init device err: %d\n", ret); goto err; } } val = pd->initial_brightness; ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val); if (ret) goto err; val = pd->device_control; ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val); if (ret) goto err; if (pd->size_program > 0) { for (i = 0; i < pd->size_program; i++) { addr = pd->rom_data[i].addr; val = pd->rom_data[i].val; if (!lp855x_is_valid_rom_area(lp, addr)) continue; ret = lp855x_write_byte(lp, addr, val); if (ret) goto err; } } if (lp->cfg->post_init_device) { ret = lp->cfg->post_init_device(lp); if (ret) { dev_err(lp->dev, "post init device err: %d\n", ret); goto err; } } return 0; err: return ret; }