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