Lines Matching refs:led
135 static int lm3601x_read_faults(struct lm3601x_led *led) in lm3601x_read_faults() argument
140 ret = regmap_read(led->regmap, LM3601X_FLAGS_REG, &flags_val); in lm3601x_read_faults()
144 led->last_flag = 0; in lm3601x_read_faults()
147 led->last_flag |= LED_FAULT_OVER_VOLTAGE; in lm3601x_read_faults()
150 led->last_flag |= LED_FAULT_OVER_TEMPERATURE; in lm3601x_read_faults()
153 led->last_flag |= LED_FAULT_SHORT_CIRCUIT; in lm3601x_read_faults()
156 led->last_flag |= LED_FAULT_OVER_CURRENT; in lm3601x_read_faults()
159 led->last_flag |= LED_FAULT_UNDER_VOLTAGE; in lm3601x_read_faults()
162 led->last_flag |= LED_FAULT_INPUT_VOLTAGE; in lm3601x_read_faults()
165 led->last_flag |= LED_FAULT_LED_OVER_TEMPERATURE; in lm3601x_read_faults()
167 return led->last_flag; in lm3601x_read_faults()
174 struct lm3601x_led *led = fled_cdev_to_led(fled_cdev); in lm3601x_brightness_set() local
177 mutex_lock(&led->lock); in lm3601x_brightness_set()
179 ret = lm3601x_read_faults(led); in lm3601x_brightness_set()
183 if (led->led_mode == LM3601X_LED_TORCH) in lm3601x_brightness_set()
189 ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG, in lm3601x_brightness_set()
194 ret = regmap_write(led->regmap, LM3601X_LED_TORCH_REG, brightness); in lm3601x_brightness_set()
198 ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG, in lm3601x_brightness_set()
202 mutex_unlock(&led->lock); in lm3601x_brightness_set()
209 struct lm3601x_led *led = fled_cdev_to_led(fled_cdev); in lm3601x_strobe_set() local
214 mutex_lock(&led->lock); in lm3601x_strobe_set()
216 ret = regmap_read(led->regmap, LM3601X_CFG_REG, ¤t_timeout); in lm3601x_strobe_set()
220 if (led->flash_timeout >= LM3601X_TIMEOUT_XOVER_US) in lm3601x_strobe_set()
221 timeout_reg_val = led->flash_timeout / LM3601X_UPPER_STEP_US + 0x07; in lm3601x_strobe_set()
223 timeout_reg_val = led->flash_timeout / LM3601X_LOWER_STEP_US - 0x01; in lm3601x_strobe_set()
225 if (led->flash_timeout != current_timeout) in lm3601x_strobe_set()
226 ret = regmap_update_bits(led->regmap, LM3601X_CFG_REG, in lm3601x_strobe_set()
230 ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG, in lm3601x_strobe_set()
234 ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG, in lm3601x_strobe_set()
237 ret = lm3601x_read_faults(led); in lm3601x_strobe_set()
239 mutex_unlock(&led->lock); in lm3601x_strobe_set()
246 struct lm3601x_led *led = fled_cdev_to_led(fled_cdev); in lm3601x_flash_brightness_set() local
250 mutex_lock(&led->lock); in lm3601x_flash_brightness_set()
251 ret = lm3601x_read_faults(led); in lm3601x_flash_brightness_set()
256 ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG, in lm3601x_flash_brightness_set()
263 ret = regmap_write(led->regmap, LM3601X_LED_FLASH_REG, brightness_val); in lm3601x_flash_brightness_set()
265 mutex_unlock(&led->lock); in lm3601x_flash_brightness_set()
272 struct lm3601x_led *led = fled_cdev_to_led(fled_cdev); in lm3601x_flash_timeout_set() local
274 mutex_lock(&led->lock); in lm3601x_flash_timeout_set()
276 led->flash_timeout = timeout; in lm3601x_flash_timeout_set()
278 mutex_unlock(&led->lock); in lm3601x_flash_timeout_set()
285 struct lm3601x_led *led = fled_cdev_to_led(fled_cdev); in lm3601x_strobe_get() local
289 mutex_lock(&led->lock); in lm3601x_strobe_get()
291 ret = regmap_read(led->regmap, LM3601X_ENABLE_REG, &strobe_state); in lm3601x_strobe_get()
298 mutex_unlock(&led->lock); in lm3601x_strobe_get()
305 struct lm3601x_led *led = fled_cdev_to_led(fled_cdev); in lm3601x_flash_fault_get() local
307 lm3601x_read_faults(led); in lm3601x_flash_fault_get()
309 *fault = led->last_flag; in lm3601x_flash_fault_get()
322 static int lm3601x_register_leds(struct lm3601x_led *led, in lm3601x_register_leds() argument
329 led->fled_cdev.ops = &flash_ops; in lm3601x_register_leds()
331 setting = &led->fled_cdev.timeout; in lm3601x_register_leds()
333 setting->max = led->max_flash_timeout; in lm3601x_register_leds()
335 setting->val = led->max_flash_timeout; in lm3601x_register_leds()
337 setting = &led->fled_cdev.brightness; in lm3601x_register_leds()
339 setting->max = led->flash_current_max; in lm3601x_register_leds()
341 setting->val = led->flash_current_max; in lm3601x_register_leds()
343 led_cdev = &led->fled_cdev.led_cdev; in lm3601x_register_leds()
345 led_cdev->max_brightness = DIV_ROUND_UP(led->torch_current_max, in lm3601x_register_leds()
350 init_data.devicename = led->client->name; in lm3601x_register_leds()
351 init_data.default_label = (led->led_mode == LM3601X_LED_TORCH) ? in lm3601x_register_leds()
353 return devm_led_classdev_flash_register_ext(&led->client->dev, in lm3601x_register_leds()
354 &led->fled_cdev, &init_data); in lm3601x_register_leds()
357 static int lm3601x_parse_node(struct lm3601x_led *led, in lm3601x_parse_node() argument
363 child = device_get_next_child_node(&led->client->dev, child); in lm3601x_parse_node()
365 dev_err(&led->client->dev, "No LED Child node\n"); in lm3601x_parse_node()
369 ret = fwnode_property_read_u32(child, "reg", &led->led_mode); in lm3601x_parse_node()
371 dev_err(&led->client->dev, "reg DT property missing\n"); in lm3601x_parse_node()
375 if (led->led_mode > LM3601X_LED_TORCH || in lm3601x_parse_node()
376 led->led_mode < LM3601X_LED_IR) { in lm3601x_parse_node()
377 dev_warn(&led->client->dev, "Invalid led mode requested\n"); in lm3601x_parse_node()
383 &led->torch_current_max); in lm3601x_parse_node()
385 dev_warn(&led->client->dev, in lm3601x_parse_node()
391 &led->flash_current_max); in lm3601x_parse_node()
393 dev_warn(&led->client->dev, in lm3601x_parse_node()
399 &led->max_flash_timeout); in lm3601x_parse_node()
401 dev_warn(&led->client->dev, in lm3601x_parse_node()
415 struct lm3601x_led *led; in lm3601x_probe() local
419 led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); in lm3601x_probe()
420 if (!led) in lm3601x_probe()
423 led->client = client; in lm3601x_probe()
424 i2c_set_clientdata(client, led); in lm3601x_probe()
426 ret = lm3601x_parse_node(led, &fwnode); in lm3601x_probe()
430 led->regmap = devm_regmap_init_i2c(client, &lm3601x_regmap); in lm3601x_probe()
431 if (IS_ERR(led->regmap)) { in lm3601x_probe()
432 ret = PTR_ERR(led->regmap); in lm3601x_probe()
438 mutex_init(&led->lock); in lm3601x_probe()
440 return lm3601x_register_leds(led, fwnode); in lm3601x_probe()
445 struct lm3601x_led *led = i2c_get_clientdata(client); in lm3601x_remove() local
447 return regmap_update_bits(led->regmap, LM3601X_ENABLE_REG, in lm3601x_remove()