1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI LP8501 9 channel LED Driver
5 * Copyright (C) 2013 Texas Instruments
7 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
10 #include <linux/delay.h>
11 #include <linux/firmware.h>
12 #include <linux/i2c.h>
13 #include <linux/init.h>
14 #include <linux/leds.h>
15 #include <linux/module.h>
16 #include <linux/mutex.h>
18 #include <linux/platform_data/leds-lp55xx.h>
19 #include <linux/slab.h>
21 #include "leds-lp55xx-common.h"
23 #define LP8501_PAGES_PER_ENGINE 1
24 #define LP8501_MAX_LEDS 9
27 #define LP8501_REG_ENABLE 0x00
28 #define LP8501_ENABLE BIT(6)
30 #define LP8501_REG_OP_MODE 0x01
32 #define LP8501_REG_PWR_CONFIG 0x05
33 #define LP8501_PWR_CONFIG_M 0x03
35 #define LP8501_REG_LED_PWM_BASE 0x16
37 #define LP8501_REG_LED_CURRENT_BASE 0x26
39 #define LP8501_REG_CONFIG 0x36
40 #define LP8501_PWM_PSAVE BIT(7)
41 #define LP8501_AUTO_INC BIT(6)
42 #define LP8501_PWR_SAVE BIT(5)
43 #define LP8501_CP_MODE_MASK 0x18
44 #define LP8501_CP_MODE_SHIFT 3
45 #define LP8501_INT_CLK BIT(0)
46 #define LP8501_DEFAULT_CFG (LP8501_PWM_PSAVE | LP8501_AUTO_INC | LP8501_PWR_SAVE)
48 #define LP8501_REG_STATUS 0x3A
49 #define LP8501_ENGINE_BUSY BIT(4)
51 #define LP8501_REG_RESET 0x3D
52 #define LP8501_RESET 0xFF
54 #define LP8501_REG_PROG_MEM 0x50
56 static int lp8501_post_init_device(struct lp55xx_chip
*chip
)
59 u8 val
= LP8501_DEFAULT_CFG
;
61 ret
= lp55xx_write(chip
, LP8501_REG_ENABLE
, LP8501_ENABLE
);
65 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */
66 usleep_range(1000, 2000);
68 if (chip
->pdata
->clock_mode
!= LP55XX_CLOCK_EXT
)
69 val
|= LP8501_INT_CLK
;
71 val
|= (chip
->pdata
->charge_pump_mode
<< LP8501_CP_MODE_SHIFT
) & LP8501_CP_MODE_MASK
;
73 ret
= lp55xx_write(chip
, LP8501_REG_CONFIG
, val
);
77 /* Power selection for each output */
78 return lp55xx_update_bits(chip
, LP8501_REG_PWR_CONFIG
,
79 LP8501_PWR_CONFIG_M
, chip
->pdata
->pwr_sel
);
82 static void lp8501_run_engine(struct lp55xx_chip
*chip
, bool start
)
86 lp55xx_stop_all_engine(chip
);
87 lp55xx_turn_off_channels(chip
);
91 lp55xx_run_engine_common(chip
);
94 /* Chip specific configurations */
95 static struct lp55xx_device_config lp8501_cfg
= {
97 .addr
= LP8501_REG_OP_MODE
,
100 .addr
= LP8501_REG_ENABLE
,
103 .addr
= LP8501_REG_STATUS
,
104 .mask
= LP8501_ENGINE_BUSY
,
107 .addr
= LP8501_REG_RESET
,
111 .addr
= LP8501_REG_ENABLE
,
112 .val
= LP8501_ENABLE
,
115 .addr
= LP8501_REG_PROG_MEM
,
117 .reg_led_pwm_base
= {
118 .addr
= LP8501_REG_LED_PWM_BASE
,
120 .reg_led_current_base
= {
121 .addr
= LP8501_REG_LED_CURRENT_BASE
,
123 .pages_per_engine
= LP8501_PAGES_PER_ENGINE
,
124 .max_channel
= LP8501_MAX_LEDS
,
125 .post_init_device
= lp8501_post_init_device
,
126 .brightness_fn
= lp55xx_led_brightness
,
127 .set_led_current
= lp55xx_set_led_current
,
128 .firmware_cb
= lp55xx_firmware_loaded_cb
,
129 .run_engine
= lp8501_run_engine
,
132 static const struct i2c_device_id lp8501_id
[] = {
133 { "lp8501", .driver_data
= (kernel_ulong_t
)&lp8501_cfg
, },
136 MODULE_DEVICE_TABLE(i2c
, lp8501_id
);
138 static const struct of_device_id of_lp8501_leds_match
[] = {
139 { .compatible
= "ti,lp8501", .data
= &lp8501_cfg
, },
143 MODULE_DEVICE_TABLE(of
, of_lp8501_leds_match
);
145 static struct i2c_driver lp8501_driver
= {
148 .of_match_table
= of_lp8501_leds_match
,
150 .probe
= lp55xx_probe
,
151 .remove
= lp55xx_remove
,
152 .id_table
= lp8501_id
,
155 module_i2c_driver(lp8501_driver
);
157 MODULE_DESCRIPTION("Texas Instruments LP8501 LED driver");
158 MODULE_AUTHOR("Milo Kim");
159 MODULE_LICENSE("GPL");