/* * struct lp855x_device_config * @pre_init_device: init device function call before updating the brightness * @reg_brightness: register address for brigthenss control * @reg_devicectrl: register address for device control * @post_init_device: late init device function call
*/ struct lp855x_device_config { int (*pre_init_device)(struct lp855x *);
u8 reg_brightness;
u8 reg_devicectrl; int (*post_init_device)(struct lp855x *);
};
switch (lp->chip_id) { case LP8550: case LP8551: case LP8552: case LP8553:
start = LP855X_EEPROM_START;
end = LP855X_EEPROM_END; break; case LP8556:
start = LP8556_EPROM_START;
end = LP8556_EPROM_END; break; case LP8555:
start = LP8555_EPROM_START;
end = LP8555_EPROM_END; break; case LP8557:
start = LP8557_EPROM_START;
end = LP8557_EPROM_END; break; default: returnfalse;
}
/* * 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) *
*/ staticint lp855x_configure(struct lp855x *lp)
{
u8 val, addr; int i, ret; struct lp855x_platform_data *pd = lp->pdata;
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;
}
staticint lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
{ struct pwm_state state;
if (lp->needs_pwm_init) {
pwm_init_state(lp->pwm, &state); /* Legacy platform data compatibility */ if (lp->pdata->period_ns > 0)
state.period = lp->pdata->period_ns;
lp->needs_pwm_init = false;
} else {
pwm_get_state(lp->pwm, &state);
}
/* Fill ROM platform data if defined */
rom_length = of_get_child_count(node); if (rom_length > 0) { struct lp855x_rom_data *rom; struct device_node *child; int i = 0;
rom = devm_kcalloc(dev, rom_length, sizeof(*rom), GFP_KERNEL); if (!rom) return -ENOMEM;
staticint lp855x_parse_acpi(struct lp855x *lp)
{ int ret;
/* * On ACPI the device has already been initialized by the firmware * and is in register mode, so we can read back the settings from * the registers.
*/
ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_brightness); if (ret < 0) return ret;
lp->pdata->initial_brightness = ret;
ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_devicectrl); if (ret < 0) return ret;
switch (lp->chip_id) { case LP8550: case LP8551: case LP8552: case LP8553: case LP8556:
lp->cfg = &lp855x_dev_cfg; break; case LP8555: case LP8557:
lp->cfg = &lp8557_dev_cfg; break; default: return -EINVAL;
}
if (!lp->pdata) {
lp->pdata = devm_kzalloc(dev, sizeof(*lp->pdata), GFP_KERNEL); if (!lp->pdata) return -ENOMEM;
if (id) {
ret = lp855x_parse_dt(lp); if (ret < 0) return ret;
} else {
ret = lp855x_parse_acpi(lp); if (ret < 0) return ret;
}
}
lp->supply = devm_regulator_get(dev, "power"); if (IS_ERR(lp->supply)) { if (PTR_ERR(lp->supply) == -EPROBE_DEFER) return -EPROBE_DEFER;
lp->supply = NULL;
}
lp->enable = devm_regulator_get_optional(dev, "enable"); if (IS_ERR(lp->enable)) {
ret = PTR_ERR(lp->enable); if (ret == -ENODEV)
lp->enable = NULL; else return dev_err_probe(dev, ret, "getting enable regulator\n");
}
lp->pwm = devm_pwm_get(lp->dev, lp->chipname); if (IS_ERR(lp->pwm)) {
ret = PTR_ERR(lp->pwm); if (ret == -ENODEV || ret == -EINVAL)
lp->pwm = NULL; else return dev_err_probe(dev, ret, "getting PWM\n");
#ifdef CONFIG_ACPI staticconststruct acpi_device_id lp855x_acpi_match[] = { /* Xiaomi specific HID used for the LP8556 on the Mi Pad 2 */
{ "XMCC0001", LP8556 },
{ }
};
MODULE_DEVICE_TABLE(acpi, lp855x_acpi_match); #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.