Commit 7cdc2b98cec4c9b5bd563adf9eec90e7a7e12234

Authored by Linus Walleij
Committed by Samuel Ortiz
1 parent 956f25a677

mfd: AB3100 propagate error

This makes ab3100_set_register_interruptible() propagate the error
code from suboperations properly so it can be handles properly.
(A special case comes from signal interruption.)

Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

drivers/mfd/ab3100-core.c
1 /* 1 /*
2 * Copyright (C) 2007-2009 ST-Ericsson 2 * Copyright (C) 2007-2009 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2 3 * License terms: GNU General Public License (GPL) version 2
4 * Low-level core for exclusive access to the AB3100 IC on the I2C bus 4 * Low-level core for exclusive access to the AB3100 IC on the I2C bus
5 * and some basic chip-configuration. 5 * and some basic chip-configuration.
6 * Author: Linus Walleij <linus.walleij@stericsson.com> 6 * Author: Linus Walleij <linus.walleij@stericsson.com>
7 */ 7 */
8 8
9 #include <linux/i2c.h> 9 #include <linux/i2c.h>
10 #include <linux/mutex.h> 10 #include <linux/mutex.h>
11 #include <linux/list.h> 11 #include <linux/list.h>
12 #include <linux/notifier.h> 12 #include <linux/notifier.h>
13 #include <linux/err.h> 13 #include <linux/err.h>
14 #include <linux/platform_device.h> 14 #include <linux/platform_device.h>
15 #include <linux/device.h> 15 #include <linux/device.h>
16 #include <linux/interrupt.h> 16 #include <linux/interrupt.h>
17 #include <linux/workqueue.h> 17 #include <linux/workqueue.h>
18 #include <linux/debugfs.h> 18 #include <linux/debugfs.h>
19 #include <linux/seq_file.h> 19 #include <linux/seq_file.h>
20 #include <linux/uaccess.h> 20 #include <linux/uaccess.h>
21 #include <linux/mfd/ab3100.h> 21 #include <linux/mfd/ab3100.h>
22 22
23 /* These are the only registers inside AB3100 used in this main file */ 23 /* These are the only registers inside AB3100 used in this main file */
24 24
25 /* Interrupt event registers */ 25 /* Interrupt event registers */
26 #define AB3100_EVENTA1 0x21 26 #define AB3100_EVENTA1 0x21
27 #define AB3100_EVENTA2 0x22 27 #define AB3100_EVENTA2 0x22
28 #define AB3100_EVENTA3 0x23 28 #define AB3100_EVENTA3 0x23
29 29
30 /* AB3100 DAC converter registers */ 30 /* AB3100 DAC converter registers */
31 #define AB3100_DIS 0x00 31 #define AB3100_DIS 0x00
32 #define AB3100_D0C 0x01 32 #define AB3100_D0C 0x01
33 #define AB3100_D1C 0x02 33 #define AB3100_D1C 0x02
34 #define AB3100_D2C 0x03 34 #define AB3100_D2C 0x03
35 #define AB3100_D3C 0x04 35 #define AB3100_D3C 0x04
36 36
37 /* Chip ID register */ 37 /* Chip ID register */
38 #define AB3100_CID 0x20 38 #define AB3100_CID 0x20
39 39
40 /* AB3100 interrupt registers */ 40 /* AB3100 interrupt registers */
41 #define AB3100_IMRA1 0x24 41 #define AB3100_IMRA1 0x24
42 #define AB3100_IMRA2 0x25 42 #define AB3100_IMRA2 0x25
43 #define AB3100_IMRA3 0x26 43 #define AB3100_IMRA3 0x26
44 #define AB3100_IMRB1 0x2B 44 #define AB3100_IMRB1 0x2B
45 #define AB3100_IMRB2 0x2C 45 #define AB3100_IMRB2 0x2C
46 #define AB3100_IMRB3 0x2D 46 #define AB3100_IMRB3 0x2D
47 47
48 /* System Power Monitoring and control registers */ 48 /* System Power Monitoring and control registers */
49 #define AB3100_MCA 0x2E 49 #define AB3100_MCA 0x2E
50 #define AB3100_MCB 0x2F 50 #define AB3100_MCB 0x2F
51 51
52 /* SIM power up */ 52 /* SIM power up */
53 #define AB3100_SUP 0x50 53 #define AB3100_SUP 0x50
54 54
55 /* 55 /*
56 * I2C communication 56 * I2C communication
57 * 57 *
58 * The AB3100 is usually assigned address 0x48 (7-bit) 58 * The AB3100 is usually assigned address 0x48 (7-bit)
59 * The chip is defined in the platform i2c_board_data section. 59 * The chip is defined in the platform i2c_board_data section.
60 */ 60 */
61 static unsigned short normal_i2c[] = { 0x48, I2C_CLIENT_END }; 61 static unsigned short normal_i2c[] = { 0x48, I2C_CLIENT_END };
62 I2C_CLIENT_INSMOD_1(ab3100); 62 I2C_CLIENT_INSMOD_1(ab3100);
63 63
64 u8 ab3100_get_chip_type(struct ab3100 *ab3100) 64 u8 ab3100_get_chip_type(struct ab3100 *ab3100)
65 { 65 {
66 u8 chip = ABUNKNOWN; 66 u8 chip = ABUNKNOWN;
67 67
68 switch (ab3100->chip_id & 0xf0) { 68 switch (ab3100->chip_id & 0xf0) {
69 case 0xa0: 69 case 0xa0:
70 chip = AB3000; 70 chip = AB3000;
71 break; 71 break;
72 case 0xc0: 72 case 0xc0:
73 chip = AB3100; 73 chip = AB3100;
74 break; 74 break;
75 } 75 }
76 return chip; 76 return chip;
77 } 77 }
78 EXPORT_SYMBOL(ab3100_get_chip_type); 78 EXPORT_SYMBOL(ab3100_get_chip_type);
79 79
80 int ab3100_set_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 regval) 80 int ab3100_set_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 regval)
81 { 81 {
82 u8 regandval[2] = {reg, regval}; 82 u8 regandval[2] = {reg, regval};
83 int err; 83 int err;
84 84
85 err = mutex_lock_interruptible(&ab3100->access_mutex); 85 err = mutex_lock_interruptible(&ab3100->access_mutex);
86 if (err) 86 if (err)
87 return err; 87 return err;
88 88
89 /* 89 /*
90 * A two-byte write message with the first byte containing the register 90 * A two-byte write message with the first byte containing the register
91 * number and the second byte containing the value to be written 91 * number and the second byte containing the value to be written
92 * effectively sets a register in the AB3100. 92 * effectively sets a register in the AB3100.
93 */ 93 */
94 err = i2c_master_send(ab3100->i2c_client, regandval, 2); 94 err = i2c_master_send(ab3100->i2c_client, regandval, 2);
95 if (err < 0) { 95 if (err < 0) {
96 dev_err(ab3100->dev, 96 dev_err(ab3100->dev,
97 "write error (write register): %d\n", 97 "write error (write register): %d\n",
98 err); 98 err);
99 } else if (err != 2) { 99 } else if (err != 2) {
100 dev_err(ab3100->dev, 100 dev_err(ab3100->dev,
101 "write error (write register) " 101 "write error (write register) "
102 "%d bytes transferred (expected 2)\n", 102 "%d bytes transferred (expected 2)\n",
103 err); 103 err);
104 err = -EIO; 104 err = -EIO;
105 } else { 105 } else {
106 /* All is well */ 106 /* All is well */
107 err = 0; 107 err = 0;
108 } 108 }
109 mutex_unlock(&ab3100->access_mutex); 109 mutex_unlock(&ab3100->access_mutex);
110 return 0; 110 return err;
111 } 111 }
112 EXPORT_SYMBOL(ab3100_set_register_interruptible); 112 EXPORT_SYMBOL(ab3100_set_register_interruptible);
113 113
114 114
115 /* 115 /*
116 * The test registers exist at an I2C bus address up one 116 * The test registers exist at an I2C bus address up one
117 * from the ordinary base. They are not supposed to be used 117 * from the ordinary base. They are not supposed to be used
118 * in production code, but sometimes you have to do that 118 * in production code, but sometimes you have to do that
119 * anyway. It's currently only used from this file so declare 119 * anyway. It's currently only used from this file so declare
120 * it static and do not export. 120 * it static and do not export.
121 */ 121 */
122 static int ab3100_set_test_register_interruptible(struct ab3100 *ab3100, 122 static int ab3100_set_test_register_interruptible(struct ab3100 *ab3100,
123 u8 reg, u8 regval) 123 u8 reg, u8 regval)
124 { 124 {
125 u8 regandval[2] = {reg, regval}; 125 u8 regandval[2] = {reg, regval};
126 int err; 126 int err;
127 127
128 err = mutex_lock_interruptible(&ab3100->access_mutex); 128 err = mutex_lock_interruptible(&ab3100->access_mutex);
129 if (err) 129 if (err)
130 return err; 130 return err;
131 131
132 err = i2c_master_send(ab3100->testreg_client, regandval, 2); 132 err = i2c_master_send(ab3100->testreg_client, regandval, 2);
133 if (err < 0) { 133 if (err < 0) {
134 dev_err(ab3100->dev, 134 dev_err(ab3100->dev,
135 "write error (write test register): %d\n", 135 "write error (write test register): %d\n",
136 err); 136 err);
137 } else if (err != 2) { 137 } else if (err != 2) {
138 dev_err(ab3100->dev, 138 dev_err(ab3100->dev,
139 "write error (write test register) " 139 "write error (write test register) "
140 "%d bytes transferred (expected 2)\n", 140 "%d bytes transferred (expected 2)\n",
141 err); 141 err);
142 err = -EIO; 142 err = -EIO;
143 } else { 143 } else {
144 /* All is well */ 144 /* All is well */
145 err = 0; 145 err = 0;
146 } 146 }
147 mutex_unlock(&ab3100->access_mutex); 147 mutex_unlock(&ab3100->access_mutex);
148 148
149 return err; 149 return err;
150 } 150 }
151 151
152 152
153 int ab3100_get_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 *regval) 153 int ab3100_get_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 *regval)
154 { 154 {
155 int err; 155 int err;
156 156
157 err = mutex_lock_interruptible(&ab3100->access_mutex); 157 err = mutex_lock_interruptible(&ab3100->access_mutex);
158 if (err) 158 if (err)
159 return err; 159 return err;
160 160
161 /* 161 /*
162 * AB3100 require an I2C "stop" command between each message, else 162 * AB3100 require an I2C "stop" command between each message, else
163 * it will not work. The only way of achieveing this with the 163 * it will not work. The only way of achieveing this with the
164 * message transport layer is to send the read and write messages 164 * message transport layer is to send the read and write messages
165 * separately. 165 * separately.
166 */ 166 */
167 err = i2c_master_send(ab3100->i2c_client, &reg, 1); 167 err = i2c_master_send(ab3100->i2c_client, &reg, 1);
168 if (err < 0) { 168 if (err < 0) {
169 dev_err(ab3100->dev, 169 dev_err(ab3100->dev,
170 "write error (send register address): %d\n", 170 "write error (send register address): %d\n",
171 err); 171 err);
172 goto get_reg_out_unlock; 172 goto get_reg_out_unlock;
173 } else if (err != 1) { 173 } else if (err != 1) {
174 dev_err(ab3100->dev, 174 dev_err(ab3100->dev,
175 "write error (send register address) " 175 "write error (send register address) "
176 "%d bytes transferred (expected 1)\n", 176 "%d bytes transferred (expected 1)\n",
177 err); 177 err);
178 err = -EIO; 178 err = -EIO;
179 goto get_reg_out_unlock; 179 goto get_reg_out_unlock;
180 } else { 180 } else {
181 /* All is well */ 181 /* All is well */
182 err = 0; 182 err = 0;
183 } 183 }
184 184
185 err = i2c_master_recv(ab3100->i2c_client, regval, 1); 185 err = i2c_master_recv(ab3100->i2c_client, regval, 1);
186 if (err < 0) { 186 if (err < 0) {
187 dev_err(ab3100->dev, 187 dev_err(ab3100->dev,
188 "write error (read register): %d\n", 188 "write error (read register): %d\n",
189 err); 189 err);
190 goto get_reg_out_unlock; 190 goto get_reg_out_unlock;
191 } else if (err != 1) { 191 } else if (err != 1) {
192 dev_err(ab3100->dev, 192 dev_err(ab3100->dev,
193 "write error (read register) " 193 "write error (read register) "
194 "%d bytes transferred (expected 1)\n", 194 "%d bytes transferred (expected 1)\n",
195 err); 195 err);
196 err = -EIO; 196 err = -EIO;
197 goto get_reg_out_unlock; 197 goto get_reg_out_unlock;
198 } else { 198 } else {
199 /* All is well */ 199 /* All is well */
200 err = 0; 200 err = 0;
201 } 201 }
202 202
203 get_reg_out_unlock: 203 get_reg_out_unlock:
204 mutex_unlock(&ab3100->access_mutex); 204 mutex_unlock(&ab3100->access_mutex);
205 return err; 205 return err;
206 } 206 }
207 EXPORT_SYMBOL(ab3100_get_register_interruptible); 207 EXPORT_SYMBOL(ab3100_get_register_interruptible);
208 208
209 209
210 int ab3100_get_register_page_interruptible(struct ab3100 *ab3100, 210 int ab3100_get_register_page_interruptible(struct ab3100 *ab3100,
211 u8 first_reg, u8 *regvals, u8 numregs) 211 u8 first_reg, u8 *regvals, u8 numregs)
212 { 212 {
213 int err; 213 int err;
214 214
215 if (ab3100->chip_id == 0xa0 || 215 if (ab3100->chip_id == 0xa0 ||
216 ab3100->chip_id == 0xa1) 216 ab3100->chip_id == 0xa1)
217 /* These don't support paged reads */ 217 /* These don't support paged reads */
218 return -EIO; 218 return -EIO;
219 219
220 err = mutex_lock_interruptible(&ab3100->access_mutex); 220 err = mutex_lock_interruptible(&ab3100->access_mutex);
221 if (err) 221 if (err)
222 return err; 222 return err;
223 223
224 /* 224 /*
225 * Paged read also require an I2C "stop" command. 225 * Paged read also require an I2C "stop" command.
226 */ 226 */
227 err = i2c_master_send(ab3100->i2c_client, &first_reg, 1); 227 err = i2c_master_send(ab3100->i2c_client, &first_reg, 1);
228 if (err < 0) { 228 if (err < 0) {
229 dev_err(ab3100->dev, 229 dev_err(ab3100->dev,
230 "write error (send first register address): %d\n", 230 "write error (send first register address): %d\n",
231 err); 231 err);
232 goto get_reg_page_out_unlock; 232 goto get_reg_page_out_unlock;
233 } else if (err != 1) { 233 } else if (err != 1) {
234 dev_err(ab3100->dev, 234 dev_err(ab3100->dev,
235 "write error (send first register address) " 235 "write error (send first register address) "
236 "%d bytes transferred (expected 1)\n", 236 "%d bytes transferred (expected 1)\n",
237 err); 237 err);
238 err = -EIO; 238 err = -EIO;
239 goto get_reg_page_out_unlock; 239 goto get_reg_page_out_unlock;
240 } 240 }
241 241
242 err = i2c_master_recv(ab3100->i2c_client, regvals, numregs); 242 err = i2c_master_recv(ab3100->i2c_client, regvals, numregs);
243 if (err < 0) { 243 if (err < 0) {
244 dev_err(ab3100->dev, 244 dev_err(ab3100->dev,
245 "write error (read register page): %d\n", 245 "write error (read register page): %d\n",
246 err); 246 err);
247 goto get_reg_page_out_unlock; 247 goto get_reg_page_out_unlock;
248 } else if (err != numregs) { 248 } else if (err != numregs) {
249 dev_err(ab3100->dev, 249 dev_err(ab3100->dev,
250 "write error (read register page) " 250 "write error (read register page) "
251 "%d bytes transferred (expected %d)\n", 251 "%d bytes transferred (expected %d)\n",
252 err, numregs); 252 err, numregs);
253 err = -EIO; 253 err = -EIO;
254 goto get_reg_page_out_unlock; 254 goto get_reg_page_out_unlock;
255 } 255 }
256 256
257 /* All is well */ 257 /* All is well */
258 err = 0; 258 err = 0;
259 259
260 get_reg_page_out_unlock: 260 get_reg_page_out_unlock:
261 mutex_unlock(&ab3100->access_mutex); 261 mutex_unlock(&ab3100->access_mutex);
262 return err; 262 return err;
263 } 263 }
264 EXPORT_SYMBOL(ab3100_get_register_page_interruptible); 264 EXPORT_SYMBOL(ab3100_get_register_page_interruptible);
265 265
266 266
267 int ab3100_mask_and_set_register_interruptible(struct ab3100 *ab3100, 267 int ab3100_mask_and_set_register_interruptible(struct ab3100 *ab3100,
268 u8 reg, u8 andmask, u8 ormask) 268 u8 reg, u8 andmask, u8 ormask)
269 { 269 {
270 u8 regandval[2] = {reg, 0}; 270 u8 regandval[2] = {reg, 0};
271 int err; 271 int err;
272 272
273 err = mutex_lock_interruptible(&ab3100->access_mutex); 273 err = mutex_lock_interruptible(&ab3100->access_mutex);
274 if (err) 274 if (err)
275 return err; 275 return err;
276 276
277 /* First read out the target register */ 277 /* First read out the target register */
278 err = i2c_master_send(ab3100->i2c_client, &reg, 1); 278 err = i2c_master_send(ab3100->i2c_client, &reg, 1);
279 if (err < 0) { 279 if (err < 0) {
280 dev_err(ab3100->dev, 280 dev_err(ab3100->dev,
281 "write error (maskset send address): %d\n", 281 "write error (maskset send address): %d\n",
282 err); 282 err);
283 goto get_maskset_unlock; 283 goto get_maskset_unlock;
284 } else if (err != 1) { 284 } else if (err != 1) {
285 dev_err(ab3100->dev, 285 dev_err(ab3100->dev,
286 "write error (maskset send address) " 286 "write error (maskset send address) "
287 "%d bytes transferred (expected 1)\n", 287 "%d bytes transferred (expected 1)\n",
288 err); 288 err);
289 err = -EIO; 289 err = -EIO;
290 goto get_maskset_unlock; 290 goto get_maskset_unlock;
291 } 291 }
292 292
293 err = i2c_master_recv(ab3100->i2c_client, &regandval[1], 1); 293 err = i2c_master_recv(ab3100->i2c_client, &regandval[1], 1);
294 if (err < 0) { 294 if (err < 0) {
295 dev_err(ab3100->dev, 295 dev_err(ab3100->dev,
296 "write error (maskset read register): %d\n", 296 "write error (maskset read register): %d\n",
297 err); 297 err);
298 goto get_maskset_unlock; 298 goto get_maskset_unlock;
299 } else if (err != 1) { 299 } else if (err != 1) {
300 dev_err(ab3100->dev, 300 dev_err(ab3100->dev,
301 "write error (maskset read register) " 301 "write error (maskset read register) "
302 "%d bytes transferred (expected 1)\n", 302 "%d bytes transferred (expected 1)\n",
303 err); 303 err);
304 err = -EIO; 304 err = -EIO;
305 goto get_maskset_unlock; 305 goto get_maskset_unlock;
306 } 306 }
307 307
308 /* Modify the register */ 308 /* Modify the register */
309 regandval[1] &= andmask; 309 regandval[1] &= andmask;
310 regandval[1] |= ormask; 310 regandval[1] |= ormask;
311 311
312 /* Write the register */ 312 /* Write the register */
313 err = i2c_master_send(ab3100->i2c_client, regandval, 2); 313 err = i2c_master_send(ab3100->i2c_client, regandval, 2);
314 if (err < 0) { 314 if (err < 0) {
315 dev_err(ab3100->dev, 315 dev_err(ab3100->dev,
316 "write error (write register): %d\n", 316 "write error (write register): %d\n",
317 err); 317 err);
318 goto get_maskset_unlock; 318 goto get_maskset_unlock;
319 } else if (err != 2) { 319 } else if (err != 2) {
320 dev_err(ab3100->dev, 320 dev_err(ab3100->dev,
321 "write error (write register) " 321 "write error (write register) "
322 "%d bytes transferred (expected 2)\n", 322 "%d bytes transferred (expected 2)\n",
323 err); 323 err);
324 err = -EIO; 324 err = -EIO;
325 goto get_maskset_unlock; 325 goto get_maskset_unlock;
326 } 326 }
327 327
328 /* All is well */ 328 /* All is well */
329 err = 0; 329 err = 0;
330 330
331 get_maskset_unlock: 331 get_maskset_unlock:
332 mutex_unlock(&ab3100->access_mutex); 332 mutex_unlock(&ab3100->access_mutex);
333 return err; 333 return err;
334 } 334 }
335 EXPORT_SYMBOL(ab3100_mask_and_set_register_interruptible); 335 EXPORT_SYMBOL(ab3100_mask_and_set_register_interruptible);
336 336
337 337
338 /* 338 /*
339 * Register a simple callback for handling any AB3100 events. 339 * Register a simple callback for handling any AB3100 events.
340 */ 340 */
341 int ab3100_event_register(struct ab3100 *ab3100, 341 int ab3100_event_register(struct ab3100 *ab3100,
342 struct notifier_block *nb) 342 struct notifier_block *nb)
343 { 343 {
344 return blocking_notifier_chain_register(&ab3100->event_subscribers, 344 return blocking_notifier_chain_register(&ab3100->event_subscribers,
345 nb); 345 nb);
346 } 346 }
347 EXPORT_SYMBOL(ab3100_event_register); 347 EXPORT_SYMBOL(ab3100_event_register);
348 348
349 /* 349 /*
350 * Remove a previously registered callback. 350 * Remove a previously registered callback.
351 */ 351 */
352 int ab3100_event_unregister(struct ab3100 *ab3100, 352 int ab3100_event_unregister(struct ab3100 *ab3100,
353 struct notifier_block *nb) 353 struct notifier_block *nb)
354 { 354 {
355 return blocking_notifier_chain_unregister(&ab3100->event_subscribers, 355 return blocking_notifier_chain_unregister(&ab3100->event_subscribers,
356 nb); 356 nb);
357 } 357 }
358 EXPORT_SYMBOL(ab3100_event_unregister); 358 EXPORT_SYMBOL(ab3100_event_unregister);
359 359
360 360
361 int ab3100_event_registers_startup_state_get(struct ab3100 *ab3100, 361 int ab3100_event_registers_startup_state_get(struct ab3100 *ab3100,
362 u32 *fatevent) 362 u32 *fatevent)
363 { 363 {
364 if (!ab3100->startup_events_read) 364 if (!ab3100->startup_events_read)
365 return -EAGAIN; /* Try again later */ 365 return -EAGAIN; /* Try again later */
366 *fatevent = ab3100->startup_events; 366 *fatevent = ab3100->startup_events;
367 return 0; 367 return 0;
368 } 368 }
369 EXPORT_SYMBOL(ab3100_event_registers_startup_state_get); 369 EXPORT_SYMBOL(ab3100_event_registers_startup_state_get);
370 370
371 /* Interrupt handling worker */ 371 /* Interrupt handling worker */
372 static void ab3100_work(struct work_struct *work) 372 static void ab3100_work(struct work_struct *work)
373 { 373 {
374 struct ab3100 *ab3100 = container_of(work, struct ab3100, work); 374 struct ab3100 *ab3100 = container_of(work, struct ab3100, work);
375 u8 event_regs[3]; 375 u8 event_regs[3];
376 u32 fatevent; 376 u32 fatevent;
377 int err; 377 int err;
378 378
379 err = ab3100_get_register_page_interruptible(ab3100, AB3100_EVENTA1, 379 err = ab3100_get_register_page_interruptible(ab3100, AB3100_EVENTA1,
380 event_regs, 3); 380 event_regs, 3);
381 if (err) 381 if (err)
382 goto err_event_wq; 382 goto err_event_wq;
383 383
384 fatevent = (event_regs[0] << 16) | 384 fatevent = (event_regs[0] << 16) |
385 (event_regs[1] << 8) | 385 (event_regs[1] << 8) |
386 event_regs[2]; 386 event_regs[2];
387 387
388 if (!ab3100->startup_events_read) { 388 if (!ab3100->startup_events_read) {
389 ab3100->startup_events = fatevent; 389 ab3100->startup_events = fatevent;
390 ab3100->startup_events_read = true; 390 ab3100->startup_events_read = true;
391 } 391 }
392 /* 392 /*
393 * The notified parties will have to mask out the events 393 * The notified parties will have to mask out the events
394 * they're interested in and react to them. They will be 394 * they're interested in and react to them. They will be
395 * notified on all events, then they use the fatevent value 395 * notified on all events, then they use the fatevent value
396 * to determine if they're interested. 396 * to determine if they're interested.
397 */ 397 */
398 blocking_notifier_call_chain(&ab3100->event_subscribers, 398 blocking_notifier_call_chain(&ab3100->event_subscribers,
399 fatevent, NULL); 399 fatevent, NULL);
400 400
401 dev_dbg(ab3100->dev, 401 dev_dbg(ab3100->dev,
402 "IRQ Event: 0x%08x\n", fatevent); 402 "IRQ Event: 0x%08x\n", fatevent);
403 403
404 /* By now the IRQ should be acked and deasserted so enable it again */ 404 /* By now the IRQ should be acked and deasserted so enable it again */
405 enable_irq(ab3100->i2c_client->irq); 405 enable_irq(ab3100->i2c_client->irq);
406 return; 406 return;
407 407
408 err_event_wq: 408 err_event_wq:
409 dev_dbg(ab3100->dev, 409 dev_dbg(ab3100->dev,
410 "error in event workqueue\n"); 410 "error in event workqueue\n");
411 /* Enable the IRQ anyway, what choice do we have? */ 411 /* Enable the IRQ anyway, what choice do we have? */
412 enable_irq(ab3100->i2c_client->irq); 412 enable_irq(ab3100->i2c_client->irq);
413 return; 413 return;
414 } 414 }
415 415
416 static irqreturn_t ab3100_irq_handler(int irq, void *data) 416 static irqreturn_t ab3100_irq_handler(int irq, void *data)
417 { 417 {
418 struct ab3100 *ab3100 = data; 418 struct ab3100 *ab3100 = data;
419 /* 419 /*
420 * Disable the IRQ and dispatch a worker to handle the 420 * Disable the IRQ and dispatch a worker to handle the
421 * event. Since the chip resides on I2C this is slow 421 * event. Since the chip resides on I2C this is slow
422 * stuff and we will re-enable the interrupts once th 422 * stuff and we will re-enable the interrupts once th
423 * worker has finished. 423 * worker has finished.
424 */ 424 */
425 disable_irq(ab3100->i2c_client->irq); 425 disable_irq(ab3100->i2c_client->irq);
426 schedule_work(&ab3100->work); 426 schedule_work(&ab3100->work);
427 return IRQ_HANDLED; 427 return IRQ_HANDLED;
428 } 428 }
429 429
430 #ifdef CONFIG_DEBUG_FS 430 #ifdef CONFIG_DEBUG_FS
431 /* 431 /*
432 * Some debugfs entries only exposed if we're using debug 432 * Some debugfs entries only exposed if we're using debug
433 */ 433 */
434 static int ab3100_registers_print(struct seq_file *s, void *p) 434 static int ab3100_registers_print(struct seq_file *s, void *p)
435 { 435 {
436 struct ab3100 *ab3100 = s->private; 436 struct ab3100 *ab3100 = s->private;
437 u8 value; 437 u8 value;
438 u8 reg; 438 u8 reg;
439 439
440 seq_printf(s, "AB3100 registers:\n"); 440 seq_printf(s, "AB3100 registers:\n");
441 441
442 for (reg = 0; reg < 0xff; reg++) { 442 for (reg = 0; reg < 0xff; reg++) {
443 ab3100_get_register_interruptible(ab3100, reg, &value); 443 ab3100_get_register_interruptible(ab3100, reg, &value);
444 seq_printf(s, "[0x%x]: 0x%x\n", reg, value); 444 seq_printf(s, "[0x%x]: 0x%x\n", reg, value);
445 } 445 }
446 return 0; 446 return 0;
447 } 447 }
448 448
449 static int ab3100_registers_open(struct inode *inode, struct file *file) 449 static int ab3100_registers_open(struct inode *inode, struct file *file)
450 { 450 {
451 return single_open(file, ab3100_registers_print, inode->i_private); 451 return single_open(file, ab3100_registers_print, inode->i_private);
452 } 452 }
453 453
454 static const struct file_operations ab3100_registers_fops = { 454 static const struct file_operations ab3100_registers_fops = {
455 .open = ab3100_registers_open, 455 .open = ab3100_registers_open,
456 .read = seq_read, 456 .read = seq_read,
457 .llseek = seq_lseek, 457 .llseek = seq_lseek,
458 .release = single_release, 458 .release = single_release,
459 .owner = THIS_MODULE, 459 .owner = THIS_MODULE,
460 }; 460 };
461 461
462 struct ab3100_get_set_reg_priv { 462 struct ab3100_get_set_reg_priv {
463 struct ab3100 *ab3100; 463 struct ab3100 *ab3100;
464 bool mode; 464 bool mode;
465 }; 465 };
466 466
467 static int ab3100_get_set_reg_open_file(struct inode *inode, struct file *file) 467 static int ab3100_get_set_reg_open_file(struct inode *inode, struct file *file)
468 { 468 {
469 file->private_data = inode->i_private; 469 file->private_data = inode->i_private;
470 return 0; 470 return 0;
471 } 471 }
472 472
473 static ssize_t ab3100_get_set_reg(struct file *file, 473 static ssize_t ab3100_get_set_reg(struct file *file,
474 const char __user *user_buf, 474 const char __user *user_buf,
475 size_t count, loff_t *ppos) 475 size_t count, loff_t *ppos)
476 { 476 {
477 struct ab3100_get_set_reg_priv *priv = file->private_data; 477 struct ab3100_get_set_reg_priv *priv = file->private_data;
478 struct ab3100 *ab3100 = priv->ab3100; 478 struct ab3100 *ab3100 = priv->ab3100;
479 char buf[32]; 479 char buf[32];
480 ssize_t buf_size; 480 ssize_t buf_size;
481 int regp; 481 int regp;
482 unsigned long user_reg; 482 unsigned long user_reg;
483 int err; 483 int err;
484 int i = 0; 484 int i = 0;
485 485
486 /* Get userspace string and assure termination */ 486 /* Get userspace string and assure termination */
487 buf_size = min(count, (sizeof(buf)-1)); 487 buf_size = min(count, (sizeof(buf)-1));
488 if (copy_from_user(buf, user_buf, buf_size)) 488 if (copy_from_user(buf, user_buf, buf_size))
489 return -EFAULT; 489 return -EFAULT;
490 buf[buf_size] = 0; 490 buf[buf_size] = 0;
491 491
492 /* 492 /*
493 * The idea is here to parse a string which is either 493 * The idea is here to parse a string which is either
494 * "0xnn" for reading a register, or "0xaa 0xbb" for 494 * "0xnn" for reading a register, or "0xaa 0xbb" for
495 * writing 0xbb to the register 0xaa. First move past 495 * writing 0xbb to the register 0xaa. First move past
496 * whitespace and then begin to parse the register. 496 * whitespace and then begin to parse the register.
497 */ 497 */
498 while ((i < buf_size) && (buf[i] == ' ')) 498 while ((i < buf_size) && (buf[i] == ' '))
499 i++; 499 i++;
500 regp = i; 500 regp = i;
501 501
502 /* 502 /*
503 * Advance pointer to end of string then terminate 503 * Advance pointer to end of string then terminate
504 * the register string. This is needed to satisfy 504 * the register string. This is needed to satisfy
505 * the strict_strtoul() function. 505 * the strict_strtoul() function.
506 */ 506 */
507 while ((i < buf_size) && (buf[i] != ' ')) 507 while ((i < buf_size) && (buf[i] != ' '))
508 i++; 508 i++;
509 buf[i] = '\0'; 509 buf[i] = '\0';
510 510
511 err = strict_strtoul(&buf[regp], 16, &user_reg); 511 err = strict_strtoul(&buf[regp], 16, &user_reg);
512 if (err) 512 if (err)
513 return err; 513 return err;
514 if (user_reg > 0xff) 514 if (user_reg > 0xff)
515 return -EINVAL; 515 return -EINVAL;
516 516
517 /* Either we read or we write a register here */ 517 /* Either we read or we write a register here */
518 if (!priv->mode) { 518 if (!priv->mode) {
519 /* Reading */ 519 /* Reading */
520 u8 reg = (u8) user_reg; 520 u8 reg = (u8) user_reg;
521 u8 regvalue; 521 u8 regvalue;
522 522
523 ab3100_get_register_interruptible(ab3100, reg, &regvalue); 523 ab3100_get_register_interruptible(ab3100, reg, &regvalue);
524 524
525 dev_info(ab3100->dev, 525 dev_info(ab3100->dev,
526 "debug read AB3100 reg[0x%02x]: 0x%02x\n", 526 "debug read AB3100 reg[0x%02x]: 0x%02x\n",
527 reg, regvalue); 527 reg, regvalue);
528 } else { 528 } else {
529 int valp; 529 int valp;
530 unsigned long user_value; 530 unsigned long user_value;
531 u8 reg = (u8) user_reg; 531 u8 reg = (u8) user_reg;
532 u8 value; 532 u8 value;
533 u8 regvalue; 533 u8 regvalue;
534 534
535 /* 535 /*
536 * Writing, we need some value to write to 536 * Writing, we need some value to write to
537 * the register so keep parsing the string 537 * the register so keep parsing the string
538 * from userspace. 538 * from userspace.
539 */ 539 */
540 i++; 540 i++;
541 while ((i < buf_size) && (buf[i] == ' ')) 541 while ((i < buf_size) && (buf[i] == ' '))
542 i++; 542 i++;
543 valp = i; 543 valp = i;
544 while ((i < buf_size) && (buf[i] != ' ')) 544 while ((i < buf_size) && (buf[i] != ' '))
545 i++; 545 i++;
546 buf[i] = '\0'; 546 buf[i] = '\0';
547 547
548 err = strict_strtoul(&buf[valp], 16, &user_value); 548 err = strict_strtoul(&buf[valp], 16, &user_value);
549 if (err) 549 if (err)
550 return err; 550 return err;
551 if (user_reg > 0xff) 551 if (user_reg > 0xff)
552 return -EINVAL; 552 return -EINVAL;
553 553
554 value = (u8) user_value; 554 value = (u8) user_value;
555 ab3100_set_register_interruptible(ab3100, reg, value); 555 ab3100_set_register_interruptible(ab3100, reg, value);
556 ab3100_get_register_interruptible(ab3100, reg, &regvalue); 556 ab3100_get_register_interruptible(ab3100, reg, &regvalue);
557 557
558 dev_info(ab3100->dev, 558 dev_info(ab3100->dev,
559 "debug write reg[0x%02x] with 0x%02x, " 559 "debug write reg[0x%02x] with 0x%02x, "
560 "after readback: 0x%02x\n", 560 "after readback: 0x%02x\n",
561 reg, value, regvalue); 561 reg, value, regvalue);
562 } 562 }
563 return buf_size; 563 return buf_size;
564 } 564 }
565 565
566 static const struct file_operations ab3100_get_set_reg_fops = { 566 static const struct file_operations ab3100_get_set_reg_fops = {
567 .open = ab3100_get_set_reg_open_file, 567 .open = ab3100_get_set_reg_open_file,
568 .write = ab3100_get_set_reg, 568 .write = ab3100_get_set_reg,
569 }; 569 };
570 570
571 static struct dentry *ab3100_dir; 571 static struct dentry *ab3100_dir;
572 static struct dentry *ab3100_reg_file; 572 static struct dentry *ab3100_reg_file;
573 static struct ab3100_get_set_reg_priv ab3100_get_priv; 573 static struct ab3100_get_set_reg_priv ab3100_get_priv;
574 static struct dentry *ab3100_get_reg_file; 574 static struct dentry *ab3100_get_reg_file;
575 static struct ab3100_get_set_reg_priv ab3100_set_priv; 575 static struct ab3100_get_set_reg_priv ab3100_set_priv;
576 static struct dentry *ab3100_set_reg_file; 576 static struct dentry *ab3100_set_reg_file;
577 577
578 static void ab3100_setup_debugfs(struct ab3100 *ab3100) 578 static void ab3100_setup_debugfs(struct ab3100 *ab3100)
579 { 579 {
580 int err; 580 int err;
581 581
582 ab3100_dir = debugfs_create_dir("ab3100", NULL); 582 ab3100_dir = debugfs_create_dir("ab3100", NULL);
583 if (!ab3100_dir) 583 if (!ab3100_dir)
584 goto exit_no_debugfs; 584 goto exit_no_debugfs;
585 585
586 ab3100_reg_file = debugfs_create_file("registers", 586 ab3100_reg_file = debugfs_create_file("registers",
587 S_IRUGO, ab3100_dir, ab3100, 587 S_IRUGO, ab3100_dir, ab3100,
588 &ab3100_registers_fops); 588 &ab3100_registers_fops);
589 if (!ab3100_reg_file) { 589 if (!ab3100_reg_file) {
590 err = -ENOMEM; 590 err = -ENOMEM;
591 goto exit_destroy_dir; 591 goto exit_destroy_dir;
592 } 592 }
593 593
594 ab3100_get_priv.ab3100 = ab3100; 594 ab3100_get_priv.ab3100 = ab3100;
595 ab3100_get_priv.mode = false; 595 ab3100_get_priv.mode = false;
596 ab3100_get_reg_file = debugfs_create_file("get_reg", 596 ab3100_get_reg_file = debugfs_create_file("get_reg",
597 S_IWUGO, ab3100_dir, &ab3100_get_priv, 597 S_IWUGO, ab3100_dir, &ab3100_get_priv,
598 &ab3100_get_set_reg_fops); 598 &ab3100_get_set_reg_fops);
599 if (!ab3100_get_reg_file) { 599 if (!ab3100_get_reg_file) {
600 err = -ENOMEM; 600 err = -ENOMEM;
601 goto exit_destroy_reg; 601 goto exit_destroy_reg;
602 } 602 }
603 603
604 ab3100_set_priv.ab3100 = ab3100; 604 ab3100_set_priv.ab3100 = ab3100;
605 ab3100_set_priv.mode = true; 605 ab3100_set_priv.mode = true;
606 ab3100_set_reg_file = debugfs_create_file("set_reg", 606 ab3100_set_reg_file = debugfs_create_file("set_reg",
607 S_IWUGO, ab3100_dir, &ab3100_set_priv, 607 S_IWUGO, ab3100_dir, &ab3100_set_priv,
608 &ab3100_get_set_reg_fops); 608 &ab3100_get_set_reg_fops);
609 if (!ab3100_set_reg_file) { 609 if (!ab3100_set_reg_file) {
610 err = -ENOMEM; 610 err = -ENOMEM;
611 goto exit_destroy_get_reg; 611 goto exit_destroy_get_reg;
612 } 612 }
613 return; 613 return;
614 614
615 exit_destroy_get_reg: 615 exit_destroy_get_reg:
616 debugfs_remove(ab3100_get_reg_file); 616 debugfs_remove(ab3100_get_reg_file);
617 exit_destroy_reg: 617 exit_destroy_reg:
618 debugfs_remove(ab3100_reg_file); 618 debugfs_remove(ab3100_reg_file);
619 exit_destroy_dir: 619 exit_destroy_dir:
620 debugfs_remove(ab3100_dir); 620 debugfs_remove(ab3100_dir);
621 exit_no_debugfs: 621 exit_no_debugfs:
622 return; 622 return;
623 } 623 }
624 static inline void ab3100_remove_debugfs(void) 624 static inline void ab3100_remove_debugfs(void)
625 { 625 {
626 debugfs_remove(ab3100_set_reg_file); 626 debugfs_remove(ab3100_set_reg_file);
627 debugfs_remove(ab3100_get_reg_file); 627 debugfs_remove(ab3100_get_reg_file);
628 debugfs_remove(ab3100_reg_file); 628 debugfs_remove(ab3100_reg_file);
629 debugfs_remove(ab3100_dir); 629 debugfs_remove(ab3100_dir);
630 } 630 }
631 #else 631 #else
632 static inline void ab3100_setup_debugfs(struct ab3100 *ab3100) 632 static inline void ab3100_setup_debugfs(struct ab3100 *ab3100)
633 { 633 {
634 } 634 }
635 static inline void ab3100_remove_debugfs(void) 635 static inline void ab3100_remove_debugfs(void)
636 { 636 {
637 } 637 }
638 #endif 638 #endif
639 639
640 /* 640 /*
641 * Basic set-up, datastructure creation/destruction and I2C interface. 641 * Basic set-up, datastructure creation/destruction and I2C interface.
642 * This sets up a default config in the AB3100 chip so that it 642 * This sets up a default config in the AB3100 chip so that it
643 * will work as expected. 643 * will work as expected.
644 */ 644 */
645 645
646 struct ab3100_init_setting { 646 struct ab3100_init_setting {
647 u8 abreg; 647 u8 abreg;
648 u8 setting; 648 u8 setting;
649 }; 649 };
650 650
651 static const struct ab3100_init_setting __initdata 651 static const struct ab3100_init_setting __initdata
652 ab3100_init_settings[] = { 652 ab3100_init_settings[] = {
653 { 653 {
654 .abreg = AB3100_MCA, 654 .abreg = AB3100_MCA,
655 .setting = 0x01 655 .setting = 0x01
656 }, { 656 }, {
657 .abreg = AB3100_MCB, 657 .abreg = AB3100_MCB,
658 .setting = 0x30 658 .setting = 0x30
659 }, { 659 }, {
660 .abreg = AB3100_IMRA1, 660 .abreg = AB3100_IMRA1,
661 .setting = 0x00 661 .setting = 0x00
662 }, { 662 }, {
663 .abreg = AB3100_IMRA2, 663 .abreg = AB3100_IMRA2,
664 .setting = 0xFF 664 .setting = 0xFF
665 }, { 665 }, {
666 .abreg = AB3100_IMRA3, 666 .abreg = AB3100_IMRA3,
667 .setting = 0x01 667 .setting = 0x01
668 }, { 668 }, {
669 .abreg = AB3100_IMRB1, 669 .abreg = AB3100_IMRB1,
670 .setting = 0xFF 670 .setting = 0xFF
671 }, { 671 }, {
672 .abreg = AB3100_IMRB2, 672 .abreg = AB3100_IMRB2,
673 .setting = 0xFF 673 .setting = 0xFF
674 }, { 674 }, {
675 .abreg = AB3100_IMRB3, 675 .abreg = AB3100_IMRB3,
676 .setting = 0xFF 676 .setting = 0xFF
677 }, { 677 }, {
678 .abreg = AB3100_SUP, 678 .abreg = AB3100_SUP,
679 .setting = 0x00 679 .setting = 0x00
680 }, { 680 }, {
681 .abreg = AB3100_DIS, 681 .abreg = AB3100_DIS,
682 .setting = 0xF0 682 .setting = 0xF0
683 }, { 683 }, {
684 .abreg = AB3100_D0C, 684 .abreg = AB3100_D0C,
685 .setting = 0x00 685 .setting = 0x00
686 }, { 686 }, {
687 .abreg = AB3100_D1C, 687 .abreg = AB3100_D1C,
688 .setting = 0x00 688 .setting = 0x00
689 }, { 689 }, {
690 .abreg = AB3100_D2C, 690 .abreg = AB3100_D2C,
691 .setting = 0x00 691 .setting = 0x00
692 }, { 692 }, {
693 .abreg = AB3100_D3C, 693 .abreg = AB3100_D3C,
694 .setting = 0x00 694 .setting = 0x00
695 }, 695 },
696 }; 696 };
697 697
698 static int __init ab3100_setup(struct ab3100 *ab3100) 698 static int __init ab3100_setup(struct ab3100 *ab3100)
699 { 699 {
700 int err = 0; 700 int err = 0;
701 int i; 701 int i;
702 702
703 for (i = 0; i < ARRAY_SIZE(ab3100_init_settings); i++) { 703 for (i = 0; i < ARRAY_SIZE(ab3100_init_settings); i++) {
704 err = ab3100_set_register_interruptible(ab3100, 704 err = ab3100_set_register_interruptible(ab3100,
705 ab3100_init_settings[i].abreg, 705 ab3100_init_settings[i].abreg,
706 ab3100_init_settings[i].setting); 706 ab3100_init_settings[i].setting);
707 if (err) 707 if (err)
708 goto exit_no_setup; 708 goto exit_no_setup;
709 } 709 }
710 710
711 /* 711 /*
712 * Special trick to make the AB3100 use the 32kHz clock (RTC) 712 * Special trick to make the AB3100 use the 32kHz clock (RTC)
713 * bit 3 in test register 0x02 is a special, undocumented test 713 * bit 3 in test register 0x02 is a special, undocumented test
714 * register bit that only exist in AB3100 P1E 714 * register bit that only exist in AB3100 P1E
715 */ 715 */
716 if (ab3100->chip_id == 0xc4) { 716 if (ab3100->chip_id == 0xc4) {
717 dev_warn(ab3100->dev, 717 dev_warn(ab3100->dev,
718 "AB3100 P1E variant detected, " 718 "AB3100 P1E variant detected, "
719 "forcing chip to 32KHz\n"); 719 "forcing chip to 32KHz\n");
720 err = ab3100_set_test_register_interruptible(ab3100, 0x02, 0x08); 720 err = ab3100_set_test_register_interruptible(ab3100, 0x02, 0x08);
721 } 721 }
722 722
723 exit_no_setup: 723 exit_no_setup:
724 return err; 724 return err;
725 } 725 }
726 726
727 /* 727 /*
728 * Here we define all the platform devices that appear 728 * Here we define all the platform devices that appear
729 * as children of the AB3100. These are regular platform 729 * as children of the AB3100. These are regular platform
730 * devices with the IORESOURCE_IO .start and .end set 730 * devices with the IORESOURCE_IO .start and .end set
731 * to correspond to the internal AB3100 register range 731 * to correspond to the internal AB3100 register range
732 * mapping to the corresponding subdevice. 732 * mapping to the corresponding subdevice.
733 */ 733 */
734 734
735 #define AB3100_DEVICE(devname, devid) \ 735 #define AB3100_DEVICE(devname, devid) \
736 static struct platform_device ab3100_##devname##_device = { \ 736 static struct platform_device ab3100_##devname##_device = { \
737 .name = devid, \ 737 .name = devid, \
738 .id = -1, \ 738 .id = -1, \
739 } 739 }
740 740
741 /* 741 /*
742 * This lists all the subdevices and corresponding register 742 * This lists all the subdevices and corresponding register
743 * ranges. 743 * ranges.
744 */ 744 */
745 AB3100_DEVICE(dac, "ab3100-dac"); 745 AB3100_DEVICE(dac, "ab3100-dac");
746 AB3100_DEVICE(leds, "ab3100-leds"); 746 AB3100_DEVICE(leds, "ab3100-leds");
747 AB3100_DEVICE(power, "ab3100-power"); 747 AB3100_DEVICE(power, "ab3100-power");
748 AB3100_DEVICE(regulators, "ab3100-regulators"); 748 AB3100_DEVICE(regulators, "ab3100-regulators");
749 AB3100_DEVICE(sim, "ab3100-sim"); 749 AB3100_DEVICE(sim, "ab3100-sim");
750 AB3100_DEVICE(uart, "ab3100-uart"); 750 AB3100_DEVICE(uart, "ab3100-uart");
751 AB3100_DEVICE(rtc, "ab3100-rtc"); 751 AB3100_DEVICE(rtc, "ab3100-rtc");
752 AB3100_DEVICE(charger, "ab3100-charger"); 752 AB3100_DEVICE(charger, "ab3100-charger");
753 AB3100_DEVICE(boost, "ab3100-boost"); 753 AB3100_DEVICE(boost, "ab3100-boost");
754 AB3100_DEVICE(adc, "ab3100-adc"); 754 AB3100_DEVICE(adc, "ab3100-adc");
755 AB3100_DEVICE(fuelgauge, "ab3100-fuelgauge"); 755 AB3100_DEVICE(fuelgauge, "ab3100-fuelgauge");
756 AB3100_DEVICE(vibrator, "ab3100-vibrator"); 756 AB3100_DEVICE(vibrator, "ab3100-vibrator");
757 AB3100_DEVICE(otp, "ab3100-otp"); 757 AB3100_DEVICE(otp, "ab3100-otp");
758 AB3100_DEVICE(codec, "ab3100-codec"); 758 AB3100_DEVICE(codec, "ab3100-codec");
759 759
760 static struct platform_device * 760 static struct platform_device *
761 ab3100_platform_devs[] = { 761 ab3100_platform_devs[] = {
762 &ab3100_dac_device, 762 &ab3100_dac_device,
763 &ab3100_leds_device, 763 &ab3100_leds_device,
764 &ab3100_power_device, 764 &ab3100_power_device,
765 &ab3100_regulators_device, 765 &ab3100_regulators_device,
766 &ab3100_sim_device, 766 &ab3100_sim_device,
767 &ab3100_uart_device, 767 &ab3100_uart_device,
768 &ab3100_rtc_device, 768 &ab3100_rtc_device,
769 &ab3100_charger_device, 769 &ab3100_charger_device,
770 &ab3100_boost_device, 770 &ab3100_boost_device,
771 &ab3100_adc_device, 771 &ab3100_adc_device,
772 &ab3100_fuelgauge_device, 772 &ab3100_fuelgauge_device,
773 &ab3100_vibrator_device, 773 &ab3100_vibrator_device,
774 &ab3100_otp_device, 774 &ab3100_otp_device,
775 &ab3100_codec_device, 775 &ab3100_codec_device,
776 }; 776 };
777 777
778 struct ab_family_id { 778 struct ab_family_id {
779 u8 id; 779 u8 id;
780 char *name; 780 char *name;
781 }; 781 };
782 782
783 static const struct ab_family_id ids[] __initdata = { 783 static const struct ab_family_id ids[] __initdata = {
784 /* AB3100 */ 784 /* AB3100 */
785 { 785 {
786 .id = 0xc0, 786 .id = 0xc0,
787 .name = "P1A" 787 .name = "P1A"
788 }, { 788 }, {
789 .id = 0xc1, 789 .id = 0xc1,
790 .name = "P1B" 790 .name = "P1B"
791 }, { 791 }, {
792 .id = 0xc2, 792 .id = 0xc2,
793 .name = "P1C" 793 .name = "P1C"
794 }, { 794 }, {
795 .id = 0xc3, 795 .id = 0xc3,
796 .name = "P1D" 796 .name = "P1D"
797 }, { 797 }, {
798 .id = 0xc4, 798 .id = 0xc4,
799 .name = "P1E" 799 .name = "P1E"
800 }, { 800 }, {
801 .id = 0xc5, 801 .id = 0xc5,
802 .name = "P1F/R1A" 802 .name = "P1F/R1A"
803 }, { 803 }, {
804 .id = 0xc6, 804 .id = 0xc6,
805 .name = "P1G/R1A" 805 .name = "P1G/R1A"
806 }, { 806 }, {
807 .id = 0xc7, 807 .id = 0xc7,
808 .name = "P2A/R2A" 808 .name = "P2A/R2A"
809 }, { 809 }, {
810 .id = 0xc8, 810 .id = 0xc8,
811 .name = "P2B/R2B" 811 .name = "P2B/R2B"
812 }, 812 },
813 /* AB3000 variants, not supported */ 813 /* AB3000 variants, not supported */
814 { 814 {
815 .id = 0xa0 815 .id = 0xa0
816 }, { 816 }, {
817 .id = 0xa1 817 .id = 0xa1
818 }, { 818 }, {
819 .id = 0xa2 819 .id = 0xa2
820 }, { 820 }, {
821 .id = 0xa3 821 .id = 0xa3
822 }, { 822 }, {
823 .id = 0xa4 823 .id = 0xa4
824 }, { 824 }, {
825 .id = 0xa5 825 .id = 0xa5
826 }, { 826 }, {
827 .id = 0xa6 827 .id = 0xa6
828 }, { 828 }, {
829 .id = 0xa7 829 .id = 0xa7
830 }, 830 },
831 /* Terminator */ 831 /* Terminator */
832 { 832 {
833 .id = 0x00, 833 .id = 0x00,
834 }, 834 },
835 }; 835 };
836 836
837 static int __init ab3100_probe(struct i2c_client *client, 837 static int __init ab3100_probe(struct i2c_client *client,
838 const struct i2c_device_id *id) 838 const struct i2c_device_id *id)
839 { 839 {
840 struct ab3100 *ab3100; 840 struct ab3100 *ab3100;
841 int err; 841 int err;
842 int i; 842 int i;
843 843
844 ab3100 = kzalloc(sizeof(struct ab3100), GFP_KERNEL); 844 ab3100 = kzalloc(sizeof(struct ab3100), GFP_KERNEL);
845 if (!ab3100) { 845 if (!ab3100) {
846 dev_err(&client->dev, "could not allocate AB3100 device\n"); 846 dev_err(&client->dev, "could not allocate AB3100 device\n");
847 return -ENOMEM; 847 return -ENOMEM;
848 } 848 }
849 849
850 /* Initialize data structure */ 850 /* Initialize data structure */
851 mutex_init(&ab3100->access_mutex); 851 mutex_init(&ab3100->access_mutex);
852 BLOCKING_INIT_NOTIFIER_HEAD(&ab3100->event_subscribers); 852 BLOCKING_INIT_NOTIFIER_HEAD(&ab3100->event_subscribers);
853 853
854 ab3100->i2c_client = client; 854 ab3100->i2c_client = client;
855 ab3100->dev = &ab3100->i2c_client->dev; 855 ab3100->dev = &ab3100->i2c_client->dev;
856 856
857 i2c_set_clientdata(client, ab3100); 857 i2c_set_clientdata(client, ab3100);
858 858
859 /* Read chip ID register */ 859 /* Read chip ID register */
860 err = ab3100_get_register_interruptible(ab3100, AB3100_CID, 860 err = ab3100_get_register_interruptible(ab3100, AB3100_CID,
861 &ab3100->chip_id); 861 &ab3100->chip_id);
862 if (err) { 862 if (err) {
863 dev_err(&client->dev, 863 dev_err(&client->dev,
864 "could not communicate with the AB3100 analog " 864 "could not communicate with the AB3100 analog "
865 "baseband chip\n"); 865 "baseband chip\n");
866 goto exit_no_detect; 866 goto exit_no_detect;
867 } 867 }
868 868
869 for (i = 0; ids[i].id != 0x0; i++) { 869 for (i = 0; ids[i].id != 0x0; i++) {
870 if (ids[i].id == ab3100->chip_id) { 870 if (ids[i].id == ab3100->chip_id) {
871 if (ids[i].name != NULL) { 871 if (ids[i].name != NULL) {
872 snprintf(&ab3100->chip_name[0], 872 snprintf(&ab3100->chip_name[0],
873 sizeof(ab3100->chip_name) - 1, 873 sizeof(ab3100->chip_name) - 1,
874 "AB3100 %s", 874 "AB3100 %s",
875 ids[i].name); 875 ids[i].name);
876 break; 876 break;
877 } else { 877 } else {
878 dev_err(&client->dev, 878 dev_err(&client->dev,
879 "AB3000 is not supported\n"); 879 "AB3000 is not supported\n");
880 goto exit_no_detect; 880 goto exit_no_detect;
881 } 881 }
882 } 882 }
883 } 883 }
884 884
885 if (ids[i].id == 0x0) { 885 if (ids[i].id == 0x0) {
886 dev_err(&client->dev, "unknown analog baseband chip id: 0x%x\n", 886 dev_err(&client->dev, "unknown analog baseband chip id: 0x%x\n",
887 ab3100->chip_id); 887 ab3100->chip_id);
888 dev_err(&client->dev, "accepting it anyway. Please update " 888 dev_err(&client->dev, "accepting it anyway. Please update "
889 "the driver.\n"); 889 "the driver.\n");
890 goto exit_no_detect; 890 goto exit_no_detect;
891 } 891 }
892 892
893 dev_info(&client->dev, "Detected chip: %s\n", 893 dev_info(&client->dev, "Detected chip: %s\n",
894 &ab3100->chip_name[0]); 894 &ab3100->chip_name[0]);
895 895
896 /* Attach a second dummy i2c_client to the test register address */ 896 /* Attach a second dummy i2c_client to the test register address */
897 ab3100->testreg_client = i2c_new_dummy(client->adapter, 897 ab3100->testreg_client = i2c_new_dummy(client->adapter,
898 client->addr + 1); 898 client->addr + 1);
899 if (!ab3100->testreg_client) { 899 if (!ab3100->testreg_client) {
900 err = -ENOMEM; 900 err = -ENOMEM;
901 goto exit_no_testreg_client; 901 goto exit_no_testreg_client;
902 } 902 }
903 903
904 strlcpy(ab3100->testreg_client->name, id->name, 904 strlcpy(ab3100->testreg_client->name, id->name,
905 sizeof(ab3100->testreg_client->name)); 905 sizeof(ab3100->testreg_client->name));
906 906
907 err = ab3100_setup(ab3100); 907 err = ab3100_setup(ab3100);
908 if (err) 908 if (err)
909 goto exit_no_setup; 909 goto exit_no_setup;
910 910
911 INIT_WORK(&ab3100->work, ab3100_work); 911 INIT_WORK(&ab3100->work, ab3100_work);
912 912
913 /* This real unpredictable IRQ is of course sampled for entropy */ 913 /* This real unpredictable IRQ is of course sampled for entropy */
914 err = request_irq(client->irq, ab3100_irq_handler, 914 err = request_irq(client->irq, ab3100_irq_handler,
915 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, 915 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
916 "AB3100 IRQ", ab3100); 916 "AB3100 IRQ", ab3100);
917 if (err) 917 if (err)
918 goto exit_no_irq; 918 goto exit_no_irq;
919 919
920 /* Set parent and a pointer back to the container in device data */ 920 /* Set parent and a pointer back to the container in device data */
921 for (i = 0; i < ARRAY_SIZE(ab3100_platform_devs); i++) { 921 for (i = 0; i < ARRAY_SIZE(ab3100_platform_devs); i++) {
922 ab3100_platform_devs[i]->dev.parent = 922 ab3100_platform_devs[i]->dev.parent =
923 &client->dev; 923 &client->dev;
924 platform_set_drvdata(ab3100_platform_devs[i], ab3100); 924 platform_set_drvdata(ab3100_platform_devs[i], ab3100);
925 } 925 }
926 926
927 /* Register the platform devices */ 927 /* Register the platform devices */
928 platform_add_devices(ab3100_platform_devs, 928 platform_add_devices(ab3100_platform_devs,
929 ARRAY_SIZE(ab3100_platform_devs)); 929 ARRAY_SIZE(ab3100_platform_devs));
930 930
931 ab3100_setup_debugfs(ab3100); 931 ab3100_setup_debugfs(ab3100);
932 932
933 return 0; 933 return 0;
934 934
935 exit_no_irq: 935 exit_no_irq:
936 exit_no_setup: 936 exit_no_setup:
937 i2c_unregister_device(ab3100->testreg_client); 937 i2c_unregister_device(ab3100->testreg_client);
938 exit_no_testreg_client: 938 exit_no_testreg_client:
939 exit_no_detect: 939 exit_no_detect:
940 kfree(ab3100); 940 kfree(ab3100);
941 return err; 941 return err;
942 } 942 }
943 943
944 static int __exit ab3100_remove(struct i2c_client *client) 944 static int __exit ab3100_remove(struct i2c_client *client)
945 { 945 {
946 struct ab3100 *ab3100 = i2c_get_clientdata(client); 946 struct ab3100 *ab3100 = i2c_get_clientdata(client);
947 int i; 947 int i;
948 948
949 /* Unregister subdevices */ 949 /* Unregister subdevices */
950 for (i = 0; i < ARRAY_SIZE(ab3100_platform_devs); i++) 950 for (i = 0; i < ARRAY_SIZE(ab3100_platform_devs); i++)
951 platform_device_unregister(ab3100_platform_devs[i]); 951 platform_device_unregister(ab3100_platform_devs[i]);
952 952
953 ab3100_remove_debugfs(); 953 ab3100_remove_debugfs();
954 i2c_unregister_device(ab3100->testreg_client); 954 i2c_unregister_device(ab3100->testreg_client);
955 955
956 /* 956 /*
957 * At this point, all subscribers should have unregistered 957 * At this point, all subscribers should have unregistered
958 * their notifiers so deactivate IRQ 958 * their notifiers so deactivate IRQ
959 */ 959 */
960 free_irq(client->irq, ab3100); 960 free_irq(client->irq, ab3100);
961 kfree(ab3100); 961 kfree(ab3100);
962 return 0; 962 return 0;
963 } 963 }
964 964
965 static const struct i2c_device_id ab3100_id[] = { 965 static const struct i2c_device_id ab3100_id[] = {
966 { "ab3100", ab3100 }, 966 { "ab3100", ab3100 },
967 { } 967 { }
968 }; 968 };
969 MODULE_DEVICE_TABLE(i2c, ab3100_id); 969 MODULE_DEVICE_TABLE(i2c, ab3100_id);
970 970
971 static struct i2c_driver ab3100_driver = { 971 static struct i2c_driver ab3100_driver = {
972 .driver = { 972 .driver = {
973 .name = "ab3100", 973 .name = "ab3100",
974 .owner = THIS_MODULE, 974 .owner = THIS_MODULE,
975 }, 975 },
976 .id_table = ab3100_id, 976 .id_table = ab3100_id,
977 .probe = ab3100_probe, 977 .probe = ab3100_probe,
978 .remove = __exit_p(ab3100_remove), 978 .remove = __exit_p(ab3100_remove),
979 }; 979 };
980 980
981 static int __init ab3100_i2c_init(void) 981 static int __init ab3100_i2c_init(void)
982 { 982 {
983 return i2c_add_driver(&ab3100_driver); 983 return i2c_add_driver(&ab3100_driver);
984 } 984 }
985 985
986 static void __exit ab3100_i2c_exit(void) 986 static void __exit ab3100_i2c_exit(void)
987 { 987 {
988 i2c_del_driver(&ab3100_driver); 988 i2c_del_driver(&ab3100_driver);
989 } 989 }
990 990
991 subsys_initcall(ab3100_i2c_init); 991 subsys_initcall(ab3100_i2c_init);
992 module_exit(ab3100_i2c_exit); 992 module_exit(ab3100_i2c_exit);
993 993
994 MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>"); 994 MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
995 MODULE_DESCRIPTION("AB3100 core driver"); 995 MODULE_DESCRIPTION("AB3100 core driver");
996 MODULE_LICENSE("GPL"); 996 MODULE_LICENSE("GPL");
997 997