1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _LEDS_LP55XX_COMMON_H
16#define _LEDS_LP55XX_COMMON_H
17
18enum lp55xx_engine_index {
19 LP55XX_ENGINE_INVALID,
20 LP55XX_ENGINE_1,
21 LP55XX_ENGINE_2,
22 LP55XX_ENGINE_3,
23 LP55XX_ENGINE_MAX = LP55XX_ENGINE_3,
24};
25
26enum lp55xx_engine_mode {
27 LP55XX_ENGINE_DISABLED,
28 LP55XX_ENGINE_LOAD,
29 LP55XX_ENGINE_RUN,
30};
31
32#define LP55XX_DEV_ATTR_RW(name, show, store) \
33 DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show, store)
34#define LP55XX_DEV_ATTR_RO(name, show) \
35 DEVICE_ATTR(name, S_IRUGO, show, NULL)
36#define LP55XX_DEV_ATTR_WO(name, store) \
37 DEVICE_ATTR(name, S_IWUSR, NULL, store)
38
39#define show_mode(nr) \
40static ssize_t show_engine##nr##_mode(struct device *dev, \
41 struct device_attribute *attr, \
42 char *buf) \
43{ \
44 return show_engine_mode(dev, attr, buf, nr); \
45}
46
47#define store_mode(nr) \
48static ssize_t store_engine##nr##_mode(struct device *dev, \
49 struct device_attribute *attr, \
50 const char *buf, size_t len) \
51{ \
52 return store_engine_mode(dev, attr, buf, len, nr); \
53}
54
55#define show_leds(nr) \
56static ssize_t show_engine##nr##_leds(struct device *dev, \
57 struct device_attribute *attr, \
58 char *buf) \
59{ \
60 return show_engine_leds(dev, attr, buf, nr); \
61}
62
63#define store_leds(nr) \
64static ssize_t store_engine##nr##_leds(struct device *dev, \
65 struct device_attribute *attr, \
66 const char *buf, size_t len) \
67{ \
68 return store_engine_leds(dev, attr, buf, len, nr); \
69}
70
71#define store_load(nr) \
72static ssize_t store_engine##nr##_load(struct device *dev, \
73 struct device_attribute *attr, \
74 const char *buf, size_t len) \
75{ \
76 return store_engine_load(dev, attr, buf, len, nr); \
77}
78
79struct lp55xx_led;
80struct lp55xx_chip;
81
82
83
84
85
86
87struct lp55xx_reg {
88 u8 addr;
89 u8 val;
90};
91
92
93
94
95
96
97
98
99
100
101
102
103
104struct lp55xx_device_config {
105 const struct lp55xx_reg reset;
106 const struct lp55xx_reg enable;
107 const int max_channel;
108
109
110 int (*post_init_device) (struct lp55xx_chip *chip);
111
112
113 int (*brightness_fn)(struct lp55xx_led *led);
114
115
116 void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
117
118
119 void (*firmware_cb)(struct lp55xx_chip *chip);
120
121
122 void (*run_engine) (struct lp55xx_chip *chip, bool start);
123
124
125 const struct attribute_group *dev_attr_group;
126};
127
128
129
130
131
132
133struct lp55xx_engine {
134 enum lp55xx_engine_mode mode;
135 u16 led_mux;
136};
137
138
139
140
141
142
143
144
145
146
147
148
149struct lp55xx_chip {
150 struct i2c_client *cl;
151 struct clk *clk;
152 struct lp55xx_platform_data *pdata;
153 struct mutex lock;
154 int num_leds;
155 struct lp55xx_device_config *cfg;
156 enum lp55xx_engine_index engine_idx;
157 struct lp55xx_engine engines[LP55XX_ENGINE_MAX];
158 const struct firmware *fw;
159};
160
161
162
163
164
165
166
167
168
169
170struct lp55xx_led {
171 int chan_nr;
172 struct led_classdev cdev;
173 u8 led_current;
174 u8 max_current;
175 u8 brightness;
176 struct lp55xx_chip *chip;
177};
178
179
180extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
181extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
182extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
183 u8 mask, u8 val);
184
185
186extern bool lp55xx_is_extclk_used(struct lp55xx_chip *chip);
187
188
189extern int lp55xx_init_device(struct lp55xx_chip *chip);
190extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
191
192
193extern int lp55xx_register_leds(struct lp55xx_led *led,
194 struct lp55xx_chip *chip);
195extern void lp55xx_unregister_leds(struct lp55xx_led *led,
196 struct lp55xx_chip *chip);
197
198
199extern int lp55xx_register_sysfs(struct lp55xx_chip *chip);
200extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip);
201
202
203extern struct lp55xx_platform_data
204*lp55xx_of_populate_pdata(struct device *dev, struct device_node *np);
205
206#endif
207