Lines Matching +full:brightness +full:- +full:levels

1 // SPDX-License-Identifier: GPL-2.0-or-later
63 unsigned int *levels; member
92 /* I2C register #0 - Device enable */ in mp3309c_enable_device()
93 ret = regmap_update_bits(chip->regmap, REG_I2C_0, REG_I2C_0_EN, in mp3309c_enable_device()
99 * I2C register #1 - Set working mode: in mp3309c_enable_device()
100 * - enable/disable synchronous mode in mp3309c_enable_device()
101 * - set overvoltage protection (OVP) in mp3309c_enable_device()
104 if (chip->pdata->sync_mode) in mp3309c_enable_device()
106 reg_val |= chip->pdata->over_voltage_protection; in mp3309c_enable_device()
107 ret = regmap_write(chip->regmap, REG_I2C_1, reg_val); in mp3309c_enable_device()
117 int brightness = backlight_get_brightness(bl); in mp3309c_bl_update_status() local
122 if (chip->pdata->dimming_mode == DIMMING_PWM) { in mp3309c_bl_update_status()
126 pwm_get_state(chip->pwmd, &pwmstate); in mp3309c_bl_update_status()
128 chip->pdata->levels[brightness], in mp3309c_bl_update_status()
129 chip->pdata->levels[chip->pdata->max_brightness]); in mp3309c_bl_update_status()
131 ret = pwm_apply_might_sleep(chip->pwmd, &pwmstate); in mp3309c_bl_update_status()
135 switch (chip->pdata->status) { in mp3309c_bl_update_status()
144 if (brightness > 0) { in mp3309c_bl_update_status()
147 chip->pdata->status = BACKLIGHT_ON; in mp3309c_bl_update_status()
149 chip->pdata->status = BACKLIGHT_OFF; in mp3309c_bl_update_status()
153 if (brightness == 0) in mp3309c_bl_update_status()
154 chip->pdata->status = BACKLIGHT_OFF; in mp3309c_bl_update_status()
161 * The first time, before setting brightness, we must enable the in mp3309c_bl_update_status()
164 if (chip->pdata->status == FIRST_POWER_ON) in mp3309c_bl_update_status()
173 * +--+--+--+--+--+--+--+--+ in mp3309c_bl_update_status()
175 * +--+--+--+--+--+--+--+--+ in mp3309c_bl_update_status()
177 analog_val = brightness; in mp3309c_bl_update_status()
180 bits_val += ((analog_val >> i) & 0x01) << (6 - i); in mp3309c_bl_update_status()
181 ret = regmap_update_bits(chip->regmap, REG_I2C_0, in mp3309c_bl_update_status()
186 if (brightness > 0) in mp3309c_bl_update_status()
187 chip->pdata->status = BACKLIGHT_ON; in mp3309c_bl_update_status()
189 chip->pdata->status = BACKLIGHT_OFF; in mp3309c_bl_update_status()
204 struct device *dev = chip->dev; in mp3309c_parse_fwnode()
208 return dev_err_probe(dev, -ENODEV, "failed to get firmware node\n"); in mp3309c_parse_fwnode()
213 * - PWM mode in mp3309c_parse_fwnode()
214 * - Analog by I2C control mode (default) in mp3309c_parse_fwnode()
219 pdata->dimming_mode = DIMMING_ANALOG_I2C; in mp3309c_parse_fwnode()
221 chip->pwmd = devm_pwm_get(dev, NULL); in mp3309c_parse_fwnode()
222 if (IS_ERR(chip->pwmd)) in mp3309c_parse_fwnode()
223 return dev_err_probe(dev, PTR_ERR(chip->pwmd), "error getting pwm data\n"); in mp3309c_parse_fwnode()
224 pdata->dimming_mode = DIMMING_PWM; in mp3309c_parse_fwnode()
225 pwm_apply_args(chip->pwmd); in mp3309c_parse_fwnode()
229 * In I2C control mode the dimming levels (0..31) are fixed by the in mp3309c_parse_fwnode()
233 if (pdata->dimming_mode == DIMMING_ANALOG_I2C) { in mp3309c_parse_fwnode()
235 * Analog (by I2C commands) control mode: fixed 0..31 brightness in mp3309c_parse_fwnode()
236 * levels in mp3309c_parse_fwnode()
241 chip->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH); in mp3309c_parse_fwnode()
242 if (IS_ERR(chip->enable_gpio)) in mp3309c_parse_fwnode()
243 return dev_err_probe(dev, PTR_ERR(chip->enable_gpio), in mp3309c_parse_fwnode()
247 * PWM control mode: check for brightness level in DT in mp3309c_parse_fwnode()
249 if (device_property_present(dev, "brightness-levels")) { in mp3309c_parse_fwnode()
250 /* Read brightness levels from DT */ in mp3309c_parse_fwnode()
251 num_levels = device_property_count_u32(dev, "brightness-levels"); in mp3309c_parse_fwnode()
253 return -EINVAL; in mp3309c_parse_fwnode()
255 /* Use default brightness levels */ in mp3309c_parse_fwnode()
260 /* Fill brightness levels array */ in mp3309c_parse_fwnode()
261 pdata->levels = devm_kcalloc(dev, num_levels, sizeof(*pdata->levels), GFP_KERNEL); in mp3309c_parse_fwnode()
262 if (!pdata->levels) in mp3309c_parse_fwnode()
263 return -ENOMEM; in mp3309c_parse_fwnode()
264 if (device_property_present(dev, "brightness-levels")) { in mp3309c_parse_fwnode()
265 ret = device_property_read_u32_array(dev, "brightness-levels", in mp3309c_parse_fwnode()
266 pdata->levels, num_levels); in mp3309c_parse_fwnode()
271 pdata->levels[i] = i; in mp3309c_parse_fwnode()
274 pdata->max_brightness = num_levels - 1; in mp3309c_parse_fwnode()
276 ret = device_property_read_u32(dev, "default-brightness", &pdata->default_brightness); in mp3309c_parse_fwnode()
278 pdata->default_brightness = pdata->max_brightness; in mp3309c_parse_fwnode()
279 if (pdata->default_brightness > pdata->max_brightness) { in mp3309c_parse_fwnode()
280 dev_err_probe(dev, -ERANGE, "default brightness exceeds max brightness\n"); in mp3309c_parse_fwnode()
281 pdata->default_brightness = pdata->max_brightness; in mp3309c_parse_fwnode()
285 * Over-voltage protection (OVP) in mp3309c_parse_fwnode()
289 * - 13.5V in mp3309c_parse_fwnode()
290 * - 24V in mp3309c_parse_fwnode()
291 * - 35.5V (hardware default setting) in mp3309c_parse_fwnode()
295 pdata->over_voltage_protection = REG_I2C_1_OVP1; in mp3309c_parse_fwnode()
296 ret = device_property_read_u32(dev, "mps,overvoltage-protection-microvolt", &tmp_value); in mp3309c_parse_fwnode()
300 pdata->over_voltage_protection = 0x00; in mp3309c_parse_fwnode()
303 pdata->over_voltage_protection = REG_I2C_1_OVP0; in mp3309c_parse_fwnode()
306 pdata->over_voltage_protection = REG_I2C_1_OVP1; in mp3309c_parse_fwnode()
309 return -EINVAL; in mp3309c_parse_fwnode()
313 /* Synchronous (default) and non-synchronous mode */ in mp3309c_parse_fwnode()
314 pdata->sync_mode = !device_property_read_bool(dev, "mps,no-sync-mode"); in mp3309c_parse_fwnode()
321 struct device *dev = &client->dev; in mp3309c_probe()
328 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in mp3309c_probe()
329 return dev_err_probe(dev, -EOPNOTSUPP, "failed to check i2c functionality\n"); in mp3309c_probe()
333 return -ENOMEM; in mp3309c_probe()
335 chip->dev = dev; in mp3309c_probe()
337 chip->regmap = devm_regmap_init_i2c(client, &mp3309c_regmap); in mp3309c_probe()
338 if (IS_ERR(chip->regmap)) in mp3309c_probe()
339 return dev_err_probe(dev, PTR_ERR(chip->regmap), in mp3309c_probe()
347 return -ENOMEM; in mp3309c_probe()
353 chip->pdata = pdata; in mp3309c_probe()
357 props.brightness = pdata->default_brightness; in mp3309c_probe()
358 props.max_brightness = pdata->max_brightness; in mp3309c_probe()
362 chip->bl = devm_backlight_device_register(dev, "mp3309c", dev, chip, in mp3309c_probe()
364 if (IS_ERR(chip->bl)) in mp3309c_probe()
365 return dev_err_probe(dev, PTR_ERR(chip->bl), in mp3309c_probe()
369 if (chip->pdata->dimming_mode == DIMMING_PWM) { in mp3309c_probe()
370 pwm_init_state(chip->pwmd, &pwmstate); in mp3309c_probe()
372 chip->pdata->default_brightness, in mp3309c_probe()
373 chip->pdata->max_brightness); in mp3309c_probe()
375 ret = pwm_apply_might_sleep(chip->pwmd, &pwmstate); in mp3309c_probe()
380 chip->pdata->status = FIRST_POWER_ON; in mp3309c_probe()
381 backlight_update_status(chip->bl); in mp3309c_probe()
389 struct backlight_device *bl = chip->bl; in mp3309c_remove()
391 bl->props.power = BACKLIGHT_POWER_OFF; in mp3309c_remove()
392 bl->props.brightness = 0; in mp3309c_remove()
393 backlight_update_status(chip->bl); in mp3309c_remove()