1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * LP55XX Common Driver Header
5 * Copyright (C) 2012 Texas Instruments
7 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
9 * Derived from leds-lp5521.c, leds-lp5523.c
12 #ifndef _LEDS_LP55XX_COMMON_H
13 #define _LEDS_LP55XX_COMMON_H
15 enum lp55xx_engine_index
{
16 LP55XX_ENGINE_INVALID
,
20 LP55XX_ENGINE_MAX
= LP55XX_ENGINE_3
,
23 enum lp55xx_engine_mode
{
24 LP55XX_ENGINE_DISABLED
,
29 #define LP55XX_DEV_ATTR_RW(name, show, store) \
30 DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show, store)
31 #define LP55XX_DEV_ATTR_RO(name, show) \
32 DEVICE_ATTR(name, S_IRUGO, show, NULL)
33 #define LP55XX_DEV_ATTR_WO(name, store) \
34 DEVICE_ATTR(name, S_IWUSR, NULL, store)
36 #define show_mode(nr) \
37 static ssize_t show_engine##nr##_mode(struct device *dev, \
38 struct device_attribute *attr, \
41 return show_engine_mode(dev, attr, buf, nr); \
44 #define store_mode(nr) \
45 static ssize_t store_engine##nr##_mode(struct device *dev, \
46 struct device_attribute *attr, \
47 const char *buf, size_t len) \
49 return store_engine_mode(dev, attr, buf, len, nr); \
52 #define show_leds(nr) \
53 static ssize_t show_engine##nr##_leds(struct device *dev, \
54 struct device_attribute *attr, \
57 return show_engine_leds(dev, attr, buf, nr); \
60 #define store_leds(nr) \
61 static ssize_t store_engine##nr##_leds(struct device *dev, \
62 struct device_attribute *attr, \
63 const char *buf, size_t len) \
65 return store_engine_leds(dev, attr, buf, len, nr); \
68 #define store_load(nr) \
69 static ssize_t store_engine##nr##_load(struct device *dev, \
70 struct device_attribute *attr, \
71 const char *buf, size_t len) \
73 return store_engine_load(dev, attr, buf, len, nr); \
81 * @addr : Register address
82 * @val : Register value
90 * struct lp55xx_device_config
91 * @reset : Chip specific reset command
92 * @enable : Chip specific enable command
93 * @max_channel : Maximum number of channels
94 * @post_init_device : Chip specific initialization code
95 * @brightness_fn : Brightness function
96 * @set_led_current : LED current set function
97 * @firmware_cb : Call function when the firmware is loaded
98 * @run_engine : Run internal engine for pattern
99 * @dev_attr_group : Device specific attributes
101 struct lp55xx_device_config
{
102 const struct lp55xx_reg reset
;
103 const struct lp55xx_reg enable
;
104 const int max_channel
;
106 /* define if the device has specific initialization process */
107 int (*post_init_device
) (struct lp55xx_chip
*chip
);
109 /* access brightness register */
110 int (*brightness_fn
)(struct lp55xx_led
*led
);
112 /* current setting function */
113 void (*set_led_current
) (struct lp55xx_led
*led
, u8 led_current
);
115 /* access program memory when the firmware is loaded */
116 void (*firmware_cb
)(struct lp55xx_chip
*chip
);
118 /* used for running firmware LED patterns */
119 void (*run_engine
) (struct lp55xx_chip
*chip
, bool start
);
121 /* additional device specific attributes */
122 const struct attribute_group
*dev_attr_group
;
126 * struct lp55xx_engine
127 * @mode : Engine mode
128 * @led_mux : Mux bits for LED selection. Only used in LP5523
130 struct lp55xx_engine
{
131 enum lp55xx_engine_mode mode
;
137 * @cl : I2C communication for access registers
138 * @pdata : Platform specific data
139 * @lock : Lock for user-space interface
140 * @num_leds : Number of registered LEDs
141 * @cfg : Device specific configuration data
142 * @engine_idx : Selected engine number
143 * @engines : Engine structure for the device attribute R/W interface
144 * @fw : Firmware data for running a LED pattern
147 struct i2c_client
*cl
;
149 struct lp55xx_platform_data
*pdata
;
150 struct mutex lock
; /* lock for user-space interface */
152 struct lp55xx_device_config
*cfg
;
153 enum lp55xx_engine_index engine_idx
;
154 struct lp55xx_engine engines
[LP55XX_ENGINE_MAX
];
155 const struct firmware
*fw
;
160 * @chan_nr : Channel number
161 * @cdev : LED class device
162 * @led_current : Current setting at each led channel
163 * @max_current : Maximun current at each led channel
164 * @brightness : Brightness value
165 * @chip : The lp55xx chip data
169 struct led_classdev cdev
;
173 struct lp55xx_chip
*chip
;
176 /* register access */
177 extern int lp55xx_write(struct lp55xx_chip
*chip
, u8 reg
, u8 val
);
178 extern int lp55xx_read(struct lp55xx_chip
*chip
, u8 reg
, u8
*val
);
179 extern int lp55xx_update_bits(struct lp55xx_chip
*chip
, u8 reg
,
182 /* external clock detection */
183 extern bool lp55xx_is_extclk_used(struct lp55xx_chip
*chip
);
185 /* common device init/deinit functions */
186 extern int lp55xx_init_device(struct lp55xx_chip
*chip
);
187 extern void lp55xx_deinit_device(struct lp55xx_chip
*chip
);
189 /* common LED class device functions */
190 extern int lp55xx_register_leds(struct lp55xx_led
*led
,
191 struct lp55xx_chip
*chip
);
192 extern void lp55xx_unregister_leds(struct lp55xx_led
*led
,
193 struct lp55xx_chip
*chip
);
195 /* common device attributes functions */
196 extern int lp55xx_register_sysfs(struct lp55xx_chip
*chip
);
197 extern void lp55xx_unregister_sysfs(struct lp55xx_chip
*chip
);
199 /* common device tree population function */
200 extern struct lp55xx_platform_data
201 *lp55xx_of_populate_pdata(struct device
*dev
, struct device_node
*np
);
203 #endif /* _LEDS_LP55XX_COMMON_H */