Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // Flash and torch driver for Texas Instruments LM3601X LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Flash driver chip family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/led-class-flash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define LM3601X_LED_IR		0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define LM3601X_LED_TORCH	0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /* Registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define LM3601X_ENABLE_REG	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define LM3601X_CFG_REG		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define LM3601X_LED_FLASH_REG	0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define LM3601X_LED_TORCH_REG	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define LM3601X_FLAGS_REG	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define LM3601X_DEV_ID_REG	0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define LM3601X_SW_RESET	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* Enable Mode bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define LM3601X_MODE_STANDBY	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define LM3601X_MODE_IR_DRV	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define LM3601X_MODE_TORCH	BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define LM3601X_MODE_STROBE	(BIT(0) | BIT(1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define LM3601X_STRB_EN		BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define LM3601X_STRB_EDGE_TRIG	BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define LM3601X_IVFM_EN		BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define LM36010_BOOST_LIMIT_28	BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define LM36010_BOOST_FREQ_4MHZ	BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define LM36010_BOOST_MODE_PASS	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /* Flag Mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define LM3601X_FLASH_TIME_OUT	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define LM3601X_UVLO_FAULT	BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define LM3601X_THERM_SHUTDOWN	BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define LM3601X_THERM_CURR	BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define LM36010_CURR_LIMIT	BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define LM3601X_SHORT_FAULT	BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define LM3601X_IVFM_TRIP	BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define LM36010_OVP_FAULT	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define LM3601X_MAX_TORCH_I_UA	376000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define LM3601X_MIN_TORCH_I_UA	2400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define LM3601X_TORCH_REG_DIV	2965
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define LM3601X_MAX_STROBE_I_UA	1500000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define LM3601X_MIN_STROBE_I_UA	11000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define LM3601X_STROBE_REG_DIV	11800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define LM3601X_TIMEOUT_MASK	0x1e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define LM3601X_ENABLE_MASK	(LM3601X_MODE_IR_DRV | LM3601X_MODE_TORCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define LM3601X_LOWER_STEP_US	40000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define LM3601X_UPPER_STEP_US	200000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define LM3601X_MIN_TIMEOUT_US	40000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define LM3601X_MAX_TIMEOUT_US	1600000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define LM3601X_TIMEOUT_XOVER_US 400000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) enum lm3601x_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	CHIP_LM36010 = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	CHIP_LM36011,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * struct lm3601x_led -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * @fled_cdev: flash LED class device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * @client: Pointer to the I2C client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @regmap: Devices register map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @lock: Lock for reading/writing the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * @led_name: LED label for the Torch or IR LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * @flash_timeout: the timeout for the flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * @last_flag: last known flags register value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * @torch_current_max: maximum current for the torch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * @flash_current_max: maximum current for the flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * @max_flash_timeout: maximum timeout for the flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * @led_mode: The mode to enable either IR or Torch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) struct lm3601x_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct led_classdev_flash fled_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned int flash_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned int last_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u32 torch_current_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	u32 flash_current_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	u32 max_flash_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	u32 led_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static const struct reg_default lm3601x_regmap_defs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	{ LM3601X_ENABLE_REG, 0x20 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	{ LM3601X_CFG_REG, 0x15 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	{ LM3601X_LED_FLASH_REG, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	{ LM3601X_LED_TORCH_REG, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static bool lm3601x_volatile_reg(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	case LM3601X_FLAGS_REG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static const struct regmap_config lm3601x_regmap = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	.val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.max_register = LM3601X_DEV_ID_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.reg_defaults = lm3601x_regmap_defs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.num_reg_defaults = ARRAY_SIZE(lm3601x_regmap_defs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.cache_type = REGCACHE_RBTREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.volatile_reg = lm3601x_volatile_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static struct lm3601x_led *fled_cdev_to_led(struct led_classdev_flash *fled_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return container_of(fled_cdev, struct lm3601x_led, fled_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int lm3601x_read_faults(struct lm3601x_led *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int flags_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	ret = regmap_read(led->regmap, LM3601X_FLAGS_REG, &flags_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	led->last_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (flags_val & LM36010_OVP_FAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		led->last_flag |= LED_FAULT_OVER_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (flags_val & (LM3601X_THERM_SHUTDOWN | LM3601X_THERM_CURR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		led->last_flag |= LED_FAULT_OVER_TEMPERATURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (flags_val & LM3601X_SHORT_FAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		led->last_flag |= LED_FAULT_SHORT_CIRCUIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (flags_val & LM36010_CURR_LIMIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		led->last_flag |= LED_FAULT_OVER_CURRENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (flags_val & LM3601X_UVLO_FAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		led->last_flag |= LED_FAULT_UNDER_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (flags_val & LM3601X_IVFM_TRIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		led->last_flag |= LED_FAULT_INPUT_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (flags_val & LM3601X_THERM_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		led->last_flag |= LED_FAULT_LED_OVER_TEMPERATURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return led->last_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static int lm3601x_brightness_set(struct led_classdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct lm3601x_led *led = fled_cdev_to_led(fled_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int ret, led_mode_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	mutex_lock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	ret = lm3601x_read_faults(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (led->led_mode == LM3601X_LED_TORCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		led_mode_val = LM3601X_MODE_TORCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		led_mode_val = LM3601X_MODE_IR_DRV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (brightness == LED_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 					led_mode_val, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	ret = regmap_write(led->regmap, LM3601X_LED_TORCH_REG, brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				LM3601X_MODE_TORCH | LM3601X_MODE_IR_DRV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				led_mode_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	mutex_unlock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static int lm3601x_strobe_set(struct led_classdev_flash *fled_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 				bool state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct lm3601x_led *led = fled_cdev_to_led(fled_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int timeout_reg_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	int current_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	mutex_lock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	ret = regmap_read(led->regmap, LM3601X_CFG_REG, &current_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (led->flash_timeout >= LM3601X_TIMEOUT_XOVER_US)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		timeout_reg_val = led->flash_timeout / LM3601X_UPPER_STEP_US + 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		timeout_reg_val = led->flash_timeout / LM3601X_LOWER_STEP_US - 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (led->flash_timeout != current_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		ret = regmap_update_bits(led->regmap, LM3601X_CFG_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 					LM3601X_TIMEOUT_MASK, timeout_reg_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					LM3601X_MODE_TORCH | LM3601X_MODE_IR_DRV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 					LM3601X_MODE_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 					LM3601X_MODE_STROBE, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	ret = lm3601x_read_faults(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	mutex_unlock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int lm3601x_flash_brightness_set(struct led_classdev_flash *fled_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 					u32 brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct lm3601x_led *led = fled_cdev_to_led(fled_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	u8 brightness_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	mutex_lock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ret = lm3601x_read_faults(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (brightness == LED_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		ret = regmap_update_bits(led->regmap, LM3601X_ENABLE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 					LM3601X_MODE_STROBE, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	brightness_val = brightness / LM3601X_STROBE_REG_DIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ret = regmap_write(led->regmap, LM3601X_LED_FLASH_REG, brightness_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	mutex_unlock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int lm3601x_flash_timeout_set(struct led_classdev_flash *fled_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				u32 timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	struct lm3601x_led *led = fled_cdev_to_led(fled_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	mutex_lock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	led->flash_timeout = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	mutex_unlock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int lm3601x_strobe_get(struct led_classdev_flash *fled_cdev, bool *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct lm3601x_led *led = fled_cdev_to_led(fled_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int strobe_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	mutex_lock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	ret = regmap_read(led->regmap, LM3601X_ENABLE_REG, &strobe_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	*state = strobe_state & LM3601X_MODE_STROBE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	mutex_unlock(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static int lm3601x_flash_fault_get(struct led_classdev_flash *fled_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 				u32 *fault)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct lm3601x_led *led = fled_cdev_to_led(fled_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	lm3601x_read_faults(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	*fault = led->last_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static const struct led_flash_ops flash_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	.flash_brightness_set	= lm3601x_flash_brightness_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.strobe_set		= lm3601x_strobe_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	.strobe_get		= lm3601x_strobe_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	.timeout_set		= lm3601x_flash_timeout_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	.fault_get		= lm3601x_flash_fault_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int lm3601x_register_leds(struct lm3601x_led *led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 				 struct fwnode_handle *fwnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct led_classdev *led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct led_flash_setting *setting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	struct led_init_data init_data = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	led->fled_cdev.ops = &flash_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	setting = &led->fled_cdev.timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	setting->min = LM3601X_MIN_TIMEOUT_US;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	setting->max = led->max_flash_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	setting->step = LM3601X_LOWER_STEP_US;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	setting->val = led->max_flash_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	setting = &led->fled_cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	setting->min = LM3601X_MIN_STROBE_I_UA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	setting->max = led->flash_current_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	setting->step = LM3601X_TORCH_REG_DIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	setting->val = led->flash_current_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	led_cdev = &led->fled_cdev.led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	led_cdev->brightness_set_blocking = lm3601x_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	led_cdev->max_brightness = DIV_ROUND_UP(led->torch_current_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 						LM3601X_TORCH_REG_DIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	led_cdev->flags |= LED_DEV_CAP_FLASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	init_data.fwnode = fwnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	init_data.devicename = led->client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	init_data.default_label = (led->led_mode == LM3601X_LED_TORCH) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 					"torch" : "infrared";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return devm_led_classdev_flash_register_ext(&led->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 						&led->fled_cdev, &init_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static int lm3601x_parse_node(struct lm3601x_led *led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			      struct fwnode_handle **fwnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	struct fwnode_handle *child = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	int ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	child = device_get_next_child_node(&led->client->dev, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (!child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		dev_err(&led->client->dev, "No LED Child node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	ret = fwnode_property_read_u32(child, "reg", &led->led_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		dev_err(&led->client->dev, "reg DT property missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (led->led_mode > LM3601X_LED_TORCH ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	    led->led_mode < LM3601X_LED_IR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		dev_warn(&led->client->dev, "Invalid led mode requested\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	ret = fwnode_property_read_u32(child, "led-max-microamp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 					&led->torch_current_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		dev_warn(&led->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			"led-max-microamp DT property missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	ret = fwnode_property_read_u32(child, "flash-max-microamp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				&led->flash_current_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		dev_warn(&led->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			 "flash-max-microamp DT property missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	ret = fwnode_property_read_u32(child, "flash-max-timeout-us",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 				&led->max_flash_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		dev_warn(&led->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			 "flash-max-timeout-us DT property missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	*fwnode = child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	fwnode_handle_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static int lm3601x_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	struct lm3601x_led *led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct fwnode_handle *fwnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (!led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	led->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	i2c_set_clientdata(client, led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	ret = lm3601x_parse_node(led, &fwnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	led->regmap = devm_regmap_init_i2c(client, &lm3601x_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (IS_ERR(led->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		ret = PTR_ERR(led->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			"Failed to allocate register map: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	mutex_init(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	return lm3601x_register_leds(led, fwnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static int lm3601x_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	struct lm3601x_led *led = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	mutex_destroy(&led->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return regmap_update_bits(led->regmap, LM3601X_ENABLE_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			   LM3601X_ENABLE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			   LM3601X_MODE_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static const struct i2c_device_id lm3601x_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	{ "LM36010", CHIP_LM36010 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	{ "LM36011", CHIP_LM36011 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) MODULE_DEVICE_TABLE(i2c, lm3601x_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static const struct of_device_id of_lm3601x_leds_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	{ .compatible = "ti,lm36010", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	{ .compatible = "ti,lm36011", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) MODULE_DEVICE_TABLE(of, of_lm3601x_leds_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static struct i2c_driver lm3601x_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		.name = "lm3601x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		.of_match_table = of_lm3601x_leds_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	.probe_new = lm3601x_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	.remove = lm3601x_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	.id_table = lm3601x_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) module_i2c_driver(lm3601x_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) MODULE_DESCRIPTION("Texas Instruments Flash Lighting driver for LM3601X");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) MODULE_LICENSE("GPL v2");