Commit | Line | Data |
---|---|---|
5814fc35 MW |
1 | /* |
2 | * Copyright (C) ST-Ericsson SA 2010 | |
3 | * | |
4 | * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson. | |
5 | * License Terms: GNU General Public License v2 | |
6 | */ | |
0fbce76e | 7 | /* |
8 | * AB8500 register access | |
9 | * ====================== | |
10 | * | |
11 | * read: | |
12 | * # echo BANK > <debugfs>/ab8500/register-bank | |
13 | * # echo ADDR > <debugfs>/ab8500/register-address | |
14 | * # cat <debugfs>/ab8500/register-value | |
15 | * | |
16 | * write: | |
17 | * # echo BANK > <debugfs>/ab8500/register-bank | |
18 | * # echo ADDR > <debugfs>/ab8500/register-address | |
19 | * # echo VALUE > <debugfs>/ab8500/register-value | |
20 | * | |
21 | * read all registers from a bank: | |
22 | * # echo BANK > <debugfs>/ab8500/register-bank | |
23 | * # cat <debugfs>/ab8500/all-bank-register | |
24 | * | |
25 | * BANK target AB8500 register bank | |
26 | * ADDR target AB8500 register address | |
27 | * VALUE decimal or 0x-prefixed hexadecimal | |
28 | * | |
29 | * | |
30 | * User Space notification on AB8500 IRQ | |
31 | * ===================================== | |
32 | * | |
33 | * Allows user space entity to be notified when target AB8500 IRQ occurs. | |
34 | * When subscribed, a sysfs entry is created in ab8500.i2c platform device. | |
35 | * One can pool this file to get target IRQ occurence information. | |
36 | * | |
37 | * subscribe to an AB8500 IRQ: | |
38 | * # echo IRQ > <debugfs>/ab8500/irq-subscribe | |
39 | * | |
40 | * unsubscribe from an AB8500 IRQ: | |
41 | * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe | |
42 | * | |
43 | * | |
44 | * AB8500 register formated read/write access | |
45 | * ========================================== | |
46 | * | |
47 | * Read: read data, data>>SHIFT, data&=MASK, output data | |
48 | * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE | |
49 | * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data | |
50 | * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98] | |
51 | * | |
52 | * Usage: | |
53 | * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg | |
54 | * | |
55 | * CMD read read access | |
56 | * write write access | |
57 | * | |
58 | * BANK target reg bank | |
59 | * ADDRESS target reg address | |
60 | * VALUE (write) value to be updated | |
61 | * | |
62 | * OPTIONS | |
63 | * -d|-dec (read) output in decimal | |
64 | * -h|-hexa (read) output in 0x-hexa (default) | |
65 | * -l|-w|-b 32bit (default), 16bit or 8bit reg access | |
66 | * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF) | |
67 | * -s|-shift SHIFT bit shift value (read:left, write:right) | |
68 | * -o|-offset OFFSET address offset to add to ADDRESS value | |
69 | * | |
70 | * Warning: bit shift operation is applied to bit-mask. | |
71 | * Warning: bit shift direction depends on read or right command. | |
72 | */ | |
5814fc35 MW |
73 | |
74 | #include <linux/seq_file.h> | |
75 | #include <linux/uaccess.h> | |
76 | #include <linux/fs.h> | |
4e36dd33 | 77 | #include <linux/module.h> |
5814fc35 MW |
78 | #include <linux/debugfs.h> |
79 | #include <linux/platform_device.h> | |
4b8ac082 LJ |
80 | #include <linux/interrupt.h> |
81 | #include <linux/kobject.h> | |
82 | #include <linux/slab.h> | |
2cf64e26 | 83 | #include <linux/irq.h> |
5814fc35 MW |
84 | |
85 | #include <linux/mfd/abx500.h> | |
0cd5b6d0 | 86 | #include <linux/mfd/abx500/ab8500.h> |
1478a316 | 87 | #include <linux/mfd/abx500/ab8500-gpadc.h> |
5814fc35 | 88 | |
0fbce76e | 89 | #ifdef CONFIG_DEBUG_FS |
90 | #include <linux/string.h> | |
91 | #include <linux/ctype.h> | |
92 | #endif | |
93 | ||
5814fc35 MW |
94 | static u32 debug_bank; |
95 | static u32 debug_address; | |
96 | ||
4b8ac082 LJ |
97 | static int irq_first; |
98 | static int irq_last; | |
ddba25f1 LW |
99 | static u32 *irq_count; |
100 | static int num_irqs; | |
0b337e70 | 101 | |
ddba25f1 LW |
102 | static struct device_attribute **dev_attr; |
103 | static char **event_name; | |
4b8ac082 | 104 | |
73482346 LJ |
105 | static u8 avg_sample = SAMPLE_16; |
106 | static u8 trig_edge = RISING_EDGE; | |
107 | static u8 conv_type = ADC_SW; | |
108 | static u8 trig_timer; | |
109 | ||
5814fc35 MW |
110 | /** |
111 | * struct ab8500_reg_range | |
112 | * @first: the first address of the range | |
113 | * @last: the last address of the range | |
114 | * @perm: access permissions for the range | |
115 | */ | |
116 | struct ab8500_reg_range { | |
d7b9f322 MW |
117 | u8 first; |
118 | u8 last; | |
119 | u8 perm; | |
5814fc35 MW |
120 | }; |
121 | ||
122 | /** | |
822672a7 | 123 | * struct ab8500_prcmu_ranges |
5814fc35 MW |
124 | * @num_ranges: the number of ranges in the list |
125 | * @bankid: bank identifier | |
126 | * @range: the list of register ranges | |
127 | */ | |
822672a7 | 128 | struct ab8500_prcmu_ranges { |
d7b9f322 MW |
129 | u8 num_ranges; |
130 | u8 bankid; | |
131 | const struct ab8500_reg_range *range; | |
5814fc35 MW |
132 | }; |
133 | ||
0fbce76e | 134 | /* hwreg- "mask" and "shift" entries ressources */ |
135 | struct hwreg_cfg { | |
136 | u32 bank; /* target bank */ | |
137 | u32 addr; /* target address */ | |
138 | uint fmt; /* format */ | |
139 | uint mask; /* read/write mask, applied before any bit shift */ | |
140 | int shift; /* bit shift (read:right shift, write:left shift */ | |
141 | }; | |
142 | /* fmt bit #0: 0=hexa, 1=dec */ | |
143 | #define REG_FMT_DEC(c) ((c)->fmt & 0x1) | |
144 | #define REG_FMT_HEX(c) (!REG_FMT_DEC(c)) | |
145 | ||
146 | static struct hwreg_cfg hwreg_cfg = { | |
147 | .addr = 0, /* default: invalid phys addr */ | |
148 | .fmt = 0, /* default: 32bit access, hex output */ | |
149 | .mask = 0xFFFFFFFF, /* default: no mask */ | |
150 | .shift = 0, /* default: no bit shift */ | |
151 | }; | |
152 | ||
5814fc35 | 153 | #define AB8500_NAME_STRING "ab8500" |
1478a316 | 154 | #define AB8500_ADC_NAME_STRING "gpadc" |
40c064e4 | 155 | #define AB8500_NUM_BANKS 24 |
5814fc35 MW |
156 | |
157 | #define AB8500_REV_REG 0x80 | |
158 | ||
9581ae39 LJ |
159 | static struct ab8500_prcmu_ranges *debug_ranges; |
160 | ||
161 | struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = { | |
d7b9f322 MW |
162 | [0x0] = { |
163 | .num_ranges = 0, | |
fad55a86 | 164 | .range = NULL, |
d7b9f322 MW |
165 | }, |
166 | [AB8500_SYS_CTRL1_BLOCK] = { | |
167 | .num_ranges = 3, | |
168 | .range = (struct ab8500_reg_range[]) { | |
169 | { | |
170 | .first = 0x00, | |
171 | .last = 0x02, | |
172 | }, | |
173 | { | |
174 | .first = 0x42, | |
175 | .last = 0x42, | |
176 | }, | |
177 | { | |
178 | .first = 0x80, | |
179 | .last = 0x81, | |
180 | }, | |
181 | }, | |
182 | }, | |
183 | [AB8500_SYS_CTRL2_BLOCK] = { | |
184 | .num_ranges = 4, | |
185 | .range = (struct ab8500_reg_range[]) { | |
186 | { | |
187 | .first = 0x00, | |
188 | .last = 0x0D, | |
189 | }, | |
190 | { | |
191 | .first = 0x0F, | |
192 | .last = 0x17, | |
193 | }, | |
194 | { | |
195 | .first = 0x30, | |
196 | .last = 0x30, | |
197 | }, | |
198 | { | |
199 | .first = 0x32, | |
200 | .last = 0x33, | |
201 | }, | |
202 | }, | |
203 | }, | |
204 | [AB8500_REGU_CTRL1] = { | |
205 | .num_ranges = 3, | |
206 | .range = (struct ab8500_reg_range[]) { | |
207 | { | |
208 | .first = 0x00, | |
209 | .last = 0x00, | |
210 | }, | |
211 | { | |
212 | .first = 0x03, | |
213 | .last = 0x10, | |
214 | }, | |
215 | { | |
216 | .first = 0x80, | |
217 | .last = 0x84, | |
218 | }, | |
219 | }, | |
220 | }, | |
221 | [AB8500_REGU_CTRL2] = { | |
222 | .num_ranges = 5, | |
223 | .range = (struct ab8500_reg_range[]) { | |
224 | { | |
225 | .first = 0x00, | |
226 | .last = 0x15, | |
227 | }, | |
228 | { | |
229 | .first = 0x17, | |
230 | .last = 0x19, | |
231 | }, | |
232 | { | |
233 | .first = 0x1B, | |
234 | .last = 0x1D, | |
235 | }, | |
236 | { | |
237 | .first = 0x1F, | |
238 | .last = 0x22, | |
239 | }, | |
240 | { | |
241 | .first = 0x40, | |
242 | .last = 0x44, | |
243 | }, | |
244 | /* 0x80-0x8B is SIM registers and should | |
245 | * not be accessed from here */ | |
246 | }, | |
247 | }, | |
248 | [AB8500_USB] = { | |
249 | .num_ranges = 2, | |
250 | .range = (struct ab8500_reg_range[]) { | |
251 | { | |
252 | .first = 0x80, | |
253 | .last = 0x83, | |
254 | }, | |
255 | { | |
256 | .first = 0x87, | |
257 | .last = 0x8A, | |
258 | }, | |
259 | }, | |
260 | }, | |
261 | [AB8500_TVOUT] = { | |
262 | .num_ranges = 9, | |
263 | .range = (struct ab8500_reg_range[]) { | |
264 | { | |
265 | .first = 0x00, | |
266 | .last = 0x12, | |
267 | }, | |
268 | { | |
269 | .first = 0x15, | |
270 | .last = 0x17, | |
271 | }, | |
272 | { | |
273 | .first = 0x19, | |
274 | .last = 0x21, | |
275 | }, | |
276 | { | |
277 | .first = 0x27, | |
278 | .last = 0x2C, | |
279 | }, | |
280 | { | |
281 | .first = 0x41, | |
282 | .last = 0x41, | |
283 | }, | |
284 | { | |
285 | .first = 0x45, | |
286 | .last = 0x5B, | |
287 | }, | |
288 | { | |
289 | .first = 0x5D, | |
290 | .last = 0x5D, | |
291 | }, | |
292 | { | |
293 | .first = 0x69, | |
294 | .last = 0x69, | |
295 | }, | |
296 | { | |
297 | .first = 0x80, | |
298 | .last = 0x81, | |
299 | }, | |
300 | }, | |
301 | }, | |
302 | [AB8500_DBI] = { | |
303 | .num_ranges = 0, | |
87fff232 | 304 | .range = NULL, |
d7b9f322 MW |
305 | }, |
306 | [AB8500_ECI_AV_ACC] = { | |
307 | .num_ranges = 1, | |
308 | .range = (struct ab8500_reg_range[]) { | |
309 | { | |
310 | .first = 0x80, | |
311 | .last = 0x82, | |
312 | }, | |
313 | }, | |
314 | }, | |
315 | [0x9] = { | |
316 | .num_ranges = 0, | |
87fff232 | 317 | .range = NULL, |
d7b9f322 MW |
318 | }, |
319 | [AB8500_GPADC] = { | |
320 | .num_ranges = 1, | |
321 | .range = (struct ab8500_reg_range[]) { | |
322 | { | |
323 | .first = 0x00, | |
324 | .last = 0x08, | |
325 | }, | |
326 | }, | |
327 | }, | |
328 | [AB8500_CHARGER] = { | |
40c064e4 | 329 | .num_ranges = 9, |
d7b9f322 MW |
330 | .range = (struct ab8500_reg_range[]) { |
331 | { | |
332 | .first = 0x00, | |
333 | .last = 0x03, | |
334 | }, | |
335 | { | |
336 | .first = 0x05, | |
337 | .last = 0x05, | |
338 | }, | |
339 | { | |
340 | .first = 0x40, | |
341 | .last = 0x40, | |
342 | }, | |
343 | { | |
344 | .first = 0x42, | |
345 | .last = 0x42, | |
346 | }, | |
347 | { | |
348 | .first = 0x44, | |
349 | .last = 0x44, | |
350 | }, | |
351 | { | |
352 | .first = 0x50, | |
353 | .last = 0x55, | |
354 | }, | |
355 | { | |
356 | .first = 0x80, | |
357 | .last = 0x82, | |
358 | }, | |
359 | { | |
360 | .first = 0xC0, | |
361 | .last = 0xC2, | |
362 | }, | |
40c064e4 PL |
363 | { |
364 | .first = 0xf5, | |
9581ae39 | 365 | .last = 0xf6, |
40c064e4 | 366 | }, |
d7b9f322 MW |
367 | }, |
368 | }, | |
369 | [AB8500_GAS_GAUGE] = { | |
370 | .num_ranges = 3, | |
371 | .range = (struct ab8500_reg_range[]) { | |
372 | { | |
373 | .first = 0x00, | |
374 | .last = 0x00, | |
375 | }, | |
376 | { | |
377 | .first = 0x07, | |
378 | .last = 0x0A, | |
379 | }, | |
380 | { | |
381 | .first = 0x10, | |
382 | .last = 0x14, | |
383 | }, | |
384 | }, | |
385 | }, | |
40c064e4 PL |
386 | [AB8500_DEVELOPMENT] = { |
387 | .num_ranges = 1, | |
388 | .range = (struct ab8500_reg_range[]) { | |
389 | { | |
390 | .first = 0x00, | |
391 | .last = 0x00, | |
392 | }, | |
393 | }, | |
394 | }, | |
395 | [AB8500_DEBUG] = { | |
396 | .num_ranges = 1, | |
397 | .range = (struct ab8500_reg_range[]) { | |
398 | { | |
399 | .first = 0x05, | |
400 | .last = 0x07, | |
401 | }, | |
402 | }, | |
403 | }, | |
d7b9f322 MW |
404 | [AB8500_AUDIO] = { |
405 | .num_ranges = 1, | |
406 | .range = (struct ab8500_reg_range[]) { | |
407 | { | |
408 | .first = 0x00, | |
409 | .last = 0x6F, | |
410 | }, | |
411 | }, | |
412 | }, | |
413 | [AB8500_INTERRUPT] = { | |
414 | .num_ranges = 0, | |
87fff232 | 415 | .range = NULL, |
d7b9f322 MW |
416 | }, |
417 | [AB8500_RTC] = { | |
418 | .num_ranges = 1, | |
419 | .range = (struct ab8500_reg_range[]) { | |
420 | { | |
421 | .first = 0x00, | |
422 | .last = 0x0F, | |
423 | }, | |
424 | }, | |
425 | }, | |
426 | [AB8500_MISC] = { | |
427 | .num_ranges = 8, | |
428 | .range = (struct ab8500_reg_range[]) { | |
429 | { | |
430 | .first = 0x00, | |
431 | .last = 0x05, | |
432 | }, | |
433 | { | |
434 | .first = 0x10, | |
435 | .last = 0x15, | |
436 | }, | |
437 | { | |
438 | .first = 0x20, | |
439 | .last = 0x25, | |
440 | }, | |
441 | { | |
442 | .first = 0x30, | |
443 | .last = 0x35, | |
444 | }, | |
445 | { | |
446 | .first = 0x40, | |
447 | .last = 0x45, | |
448 | }, | |
449 | { | |
450 | .first = 0x50, | |
451 | .last = 0x50, | |
452 | }, | |
453 | { | |
454 | .first = 0x60, | |
455 | .last = 0x67, | |
456 | }, | |
457 | { | |
458 | .first = 0x80, | |
459 | .last = 0x80, | |
460 | }, | |
461 | }, | |
462 | }, | |
463 | [0x11] = { | |
464 | .num_ranges = 0, | |
87fff232 | 465 | .range = NULL, |
d7b9f322 MW |
466 | }, |
467 | [0x12] = { | |
468 | .num_ranges = 0, | |
87fff232 | 469 | .range = NULL, |
d7b9f322 MW |
470 | }, |
471 | [0x13] = { | |
472 | .num_ranges = 0, | |
87fff232 | 473 | .range = NULL, |
d7b9f322 MW |
474 | }, |
475 | [0x14] = { | |
476 | .num_ranges = 0, | |
87fff232 | 477 | .range = NULL, |
d7b9f322 MW |
478 | }, |
479 | [AB8500_OTP_EMUL] = { | |
480 | .num_ranges = 1, | |
481 | .range = (struct ab8500_reg_range[]) { | |
482 | { | |
483 | .first = 0x01, | |
484 | .last = 0x0F, | |
485 | }, | |
486 | }, | |
487 | }, | |
5814fc35 MW |
488 | }; |
489 | ||
9581ae39 LJ |
490 | struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = { |
491 | [0x0] = { | |
492 | .num_ranges = 0, | |
493 | .range = NULL, | |
494 | }, | |
495 | [AB8500_SYS_CTRL1_BLOCK] = { | |
496 | .num_ranges = 5, | |
497 | .range = (struct ab8500_reg_range[]) { | |
498 | { | |
499 | .first = 0x00, | |
500 | .last = 0x04, | |
501 | }, | |
502 | { | |
503 | .first = 0x42, | |
504 | .last = 0x42, | |
505 | }, | |
506 | { | |
507 | .first = 0x52, | |
508 | .last = 0x52, | |
509 | }, | |
510 | { | |
511 | .first = 0x54, | |
512 | .last = 0x57, | |
513 | }, | |
514 | { | |
515 | .first = 0x80, | |
516 | .last = 0x83, | |
517 | }, | |
518 | }, | |
519 | }, | |
520 | [AB8500_SYS_CTRL2_BLOCK] = { | |
521 | .num_ranges = 5, | |
522 | .range = (struct ab8500_reg_range[]) { | |
523 | { | |
524 | .first = 0x00, | |
525 | .last = 0x0D, | |
526 | }, | |
527 | { | |
528 | .first = 0x0F, | |
529 | .last = 0x17, | |
530 | }, | |
531 | { | |
532 | .first = 0x20, | |
533 | .last = 0x20, | |
534 | }, | |
535 | { | |
536 | .first = 0x30, | |
537 | .last = 0x30, | |
538 | }, | |
539 | { | |
540 | .first = 0x32, | |
541 | .last = 0x3A, | |
542 | }, | |
543 | }, | |
544 | }, | |
545 | [AB8500_REGU_CTRL1] = { | |
546 | .num_ranges = 3, | |
547 | .range = (struct ab8500_reg_range[]) { | |
548 | { | |
549 | .first = 0x00, | |
550 | .last = 0x00, | |
551 | }, | |
552 | { | |
553 | .first = 0x03, | |
554 | .last = 0x11, | |
555 | }, | |
556 | { | |
557 | .first = 0x80, | |
558 | .last = 0x86, | |
559 | }, | |
560 | }, | |
561 | }, | |
562 | [AB8500_REGU_CTRL2] = { | |
563 | .num_ranges = 6, | |
564 | .range = (struct ab8500_reg_range[]) { | |
565 | { | |
566 | .first = 0x00, | |
567 | .last = 0x06, | |
568 | }, | |
569 | { | |
570 | .first = 0x08, | |
571 | .last = 0x15, | |
572 | }, | |
573 | { | |
574 | .first = 0x17, | |
575 | .last = 0x19, | |
576 | }, | |
577 | { | |
578 | .first = 0x1B, | |
579 | .last = 0x1D, | |
580 | }, | |
581 | { | |
582 | .first = 0x1F, | |
583 | .last = 0x30, | |
584 | }, | |
585 | { | |
586 | .first = 0x40, | |
587 | .last = 0x48, | |
588 | }, | |
589 | /* 0x80-0x8B is SIM registers and should | |
590 | * not be accessed from here */ | |
591 | }, | |
592 | }, | |
593 | [AB8500_USB] = { | |
594 | .num_ranges = 3, | |
595 | .range = (struct ab8500_reg_range[]) { | |
596 | { | |
597 | .first = 0x80, | |
598 | .last = 0x83, | |
599 | }, | |
600 | { | |
601 | .first = 0x87, | |
602 | .last = 0x8A, | |
603 | }, | |
604 | { | |
605 | .first = 0x91, | |
606 | .last = 0x94, | |
607 | }, | |
608 | }, | |
609 | }, | |
610 | [AB8500_TVOUT] = { | |
611 | .num_ranges = 0, | |
612 | .range = NULL, | |
613 | }, | |
614 | [AB8500_DBI] = { | |
615 | .num_ranges = 0, | |
616 | .range = NULL, | |
617 | }, | |
618 | [AB8500_ECI_AV_ACC] = { | |
619 | .num_ranges = 1, | |
620 | .range = (struct ab8500_reg_range[]) { | |
621 | { | |
622 | .first = 0x80, | |
623 | .last = 0x82, | |
624 | }, | |
625 | }, | |
626 | }, | |
627 | [AB8500_RESERVED] = { | |
628 | .num_ranges = 0, | |
629 | .range = NULL, | |
630 | }, | |
631 | [AB8500_GPADC] = { | |
632 | .num_ranges = 1, | |
633 | .range = (struct ab8500_reg_range[]) { | |
634 | { | |
635 | .first = 0x00, | |
636 | .last = 0x08, | |
637 | }, | |
638 | }, | |
639 | }, | |
640 | [AB8500_CHARGER] = { | |
641 | .num_ranges = 9, | |
642 | .range = (struct ab8500_reg_range[]) { | |
643 | { | |
644 | .first = 0x02, | |
645 | .last = 0x03, | |
646 | }, | |
647 | { | |
648 | .first = 0x05, | |
649 | .last = 0x05, | |
650 | }, | |
651 | { | |
652 | .first = 0x40, | |
653 | .last = 0x44, | |
654 | }, | |
655 | { | |
656 | .first = 0x50, | |
657 | .last = 0x57, | |
658 | }, | |
659 | { | |
660 | .first = 0x60, | |
661 | .last = 0x60, | |
662 | }, | |
663 | { | |
664 | .first = 0xA0, | |
665 | .last = 0xA7, | |
666 | }, | |
667 | { | |
668 | .first = 0xAF, | |
669 | .last = 0xB2, | |
670 | }, | |
671 | { | |
672 | .first = 0xC0, | |
673 | .last = 0xC2, | |
674 | }, | |
675 | { | |
676 | .first = 0xF5, | |
677 | .last = 0xF5, | |
678 | }, | |
679 | }, | |
680 | }, | |
681 | [AB8500_GAS_GAUGE] = { | |
682 | .num_ranges = 3, | |
683 | .range = (struct ab8500_reg_range[]) { | |
684 | { | |
685 | .first = 0x00, | |
686 | .last = 0x00, | |
687 | }, | |
688 | { | |
689 | .first = 0x07, | |
690 | .last = 0x0A, | |
691 | }, | |
692 | { | |
693 | .first = 0x10, | |
694 | .last = 0x14, | |
695 | }, | |
696 | }, | |
697 | }, | |
698 | [AB8500_AUDIO] = { | |
699 | .num_ranges = 1, | |
700 | .range = (struct ab8500_reg_range[]) { | |
701 | { | |
702 | .first = 0x00, | |
703 | .last = 0x83, | |
704 | }, | |
705 | }, | |
706 | }, | |
707 | [AB8500_INTERRUPT] = { | |
708 | .num_ranges = 11, | |
709 | .range = (struct ab8500_reg_range[]) { | |
710 | { | |
711 | .first = 0x00, | |
712 | .last = 0x04, | |
713 | }, | |
714 | { | |
715 | .first = 0x06, | |
716 | .last = 0x07, | |
717 | }, | |
718 | { | |
719 | .first = 0x09, | |
720 | .last = 0x09, | |
721 | }, | |
722 | { | |
723 | .first = 0x0B, | |
724 | .last = 0x0C, | |
725 | }, | |
726 | { | |
727 | .first = 0x12, | |
728 | .last = 0x15, | |
729 | }, | |
730 | { | |
731 | .first = 0x18, | |
732 | .last = 0x18, | |
733 | }, | |
734 | /* Latch registers should not be read here */ | |
735 | { | |
736 | .first = 0x40, | |
737 | .last = 0x44, | |
738 | }, | |
739 | { | |
740 | .first = 0x46, | |
741 | .last = 0x49, | |
742 | }, | |
743 | { | |
744 | .first = 0x4B, | |
745 | .last = 0x4D, | |
746 | }, | |
747 | { | |
748 | .first = 0x52, | |
749 | .last = 0x55, | |
750 | }, | |
751 | { | |
752 | .first = 0x58, | |
753 | .last = 0x58, | |
754 | }, | |
755 | /* LatchHier registers should not be read here */ | |
756 | }, | |
757 | }, | |
758 | [AB8500_RTC] = { | |
759 | .num_ranges = 2, | |
760 | .range = (struct ab8500_reg_range[]) { | |
761 | { | |
762 | .first = 0x00, | |
763 | .last = 0x14, | |
764 | }, | |
765 | { | |
766 | .first = 0x16, | |
767 | .last = 0x17, | |
768 | }, | |
769 | }, | |
770 | }, | |
771 | [AB8500_MISC] = { | |
772 | .num_ranges = 8, | |
773 | .range = (struct ab8500_reg_range[]) { | |
774 | { | |
775 | .first = 0x00, | |
776 | .last = 0x06, | |
777 | }, | |
778 | { | |
779 | .first = 0x10, | |
780 | .last = 0x16, | |
781 | }, | |
782 | { | |
783 | .first = 0x20, | |
784 | .last = 0x26, | |
785 | }, | |
786 | { | |
787 | .first = 0x30, | |
788 | .last = 0x36, | |
789 | }, | |
790 | { | |
791 | .first = 0x40, | |
792 | .last = 0x46, | |
793 | }, | |
794 | { | |
795 | .first = 0x50, | |
796 | .last = 0x50, | |
797 | }, | |
798 | { | |
799 | .first = 0x60, | |
800 | .last = 0x6B, | |
801 | }, | |
802 | { | |
803 | .first = 0x80, | |
804 | .last = 0x82, | |
805 | }, | |
806 | }, | |
807 | }, | |
808 | [AB8500_DEVELOPMENT] = { | |
809 | .num_ranges = 2, | |
810 | .range = (struct ab8500_reg_range[]) { | |
811 | { | |
812 | .first = 0x00, | |
813 | .last = 0x00, | |
814 | }, | |
815 | { | |
816 | .first = 0x05, | |
817 | .last = 0x05, | |
818 | }, | |
819 | }, | |
820 | }, | |
821 | [AB8500_DEBUG] = { | |
822 | .num_ranges = 1, | |
823 | .range = (struct ab8500_reg_range[]) { | |
824 | { | |
825 | .first = 0x05, | |
826 | .last = 0x07, | |
827 | }, | |
828 | }, | |
829 | }, | |
830 | [AB8500_PROD_TEST] = { | |
831 | .num_ranges = 0, | |
832 | .range = NULL, | |
833 | }, | |
834 | [AB8500_STE_TEST] = { | |
835 | .num_ranges = 0, | |
836 | .range = NULL, | |
837 | }, | |
838 | [AB8500_OTP_EMUL] = { | |
839 | .num_ranges = 1, | |
840 | .range = (struct ab8500_reg_range[]) { | |
841 | { | |
842 | .first = 0x01, | |
843 | .last = 0x15, | |
844 | }, | |
845 | }, | |
846 | }, | |
847 | }; | |
848 | ||
4b8ac082 LJ |
849 | static irqreturn_t ab8500_debug_handler(int irq, void *data) |
850 | { | |
851 | char buf[16]; | |
852 | struct kobject *kobj = (struct kobject *)data; | |
0b337e70 | 853 | unsigned int irq_abb = irq - irq_first; |
4b8ac082 | 854 | |
ddba25f1 | 855 | if (irq_abb < num_irqs) |
0b337e70 | 856 | irq_count[irq_abb]++; |
4b8ac082 LJ |
857 | /* |
858 | * This makes it possible to use poll for events (POLLPRI | POLLERR) | |
0b337e70 | 859 | * from userspace on sysfs file named <irq-nr> |
4b8ac082 | 860 | */ |
0b337e70 | 861 | sprintf(buf, "%d", irq); |
4b8ac082 LJ |
862 | sysfs_notify(kobj, NULL, buf); |
863 | ||
864 | return IRQ_HANDLED; | |
865 | } | |
866 | ||
42002c6d MYK |
867 | /* Prints to seq_file or log_buf */ |
868 | static int ab8500_registers_print(struct device *dev, u32 bank, | |
869 | struct seq_file *s) | |
5814fc35 | 870 | { |
d7b9f322 | 871 | unsigned int i; |
d7b9f322 | 872 | |
d7b9f322 MW |
873 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { |
874 | u32 reg; | |
875 | ||
876 | for (reg = debug_ranges[bank].range[i].first; | |
877 | reg <= debug_ranges[bank].range[i].last; | |
878 | reg++) { | |
879 | u8 value; | |
880 | int err; | |
881 | ||
882 | err = abx500_get_register_interruptible(dev, | |
883 | (u8)bank, (u8)reg, &value); | |
884 | if (err < 0) { | |
885 | dev_err(dev, "ab->read fail %d\n", err); | |
886 | return err; | |
887 | } | |
888 | ||
42002c6d | 889 | if (s) { |
cfc0849c | 890 | err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", |
42002c6d MYK |
891 | bank, reg, value); |
892 | if (err < 0) { | |
42002c6d MYK |
893 | /* Error is not returned here since |
894 | * the output is wanted in any case */ | |
895 | return 0; | |
896 | } | |
897 | } else { | |
cfc0849c MW |
898 | printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n", |
899 | bank, reg, value); | |
d7b9f322 MW |
900 | } |
901 | } | |
902 | } | |
903 | return 0; | |
5814fc35 MW |
904 | } |
905 | ||
42002c6d MYK |
906 | static int ab8500_print_bank_registers(struct seq_file *s, void *p) |
907 | { | |
908 | struct device *dev = s->private; | |
909 | u32 bank = debug_bank; | |
910 | ||
911 | seq_printf(s, AB8500_NAME_STRING " register values:\n"); | |
912 | ||
cfc0849c | 913 | seq_printf(s, " bank 0x%02X:\n", bank); |
42002c6d MYK |
914 | |
915 | ab8500_registers_print(dev, bank, s); | |
916 | return 0; | |
917 | } | |
918 | ||
5814fc35 MW |
919 | static int ab8500_registers_open(struct inode *inode, struct file *file) |
920 | { | |
42002c6d | 921 | return single_open(file, ab8500_print_bank_registers, inode->i_private); |
5814fc35 MW |
922 | } |
923 | ||
924 | static const struct file_operations ab8500_registers_fops = { | |
d7b9f322 MW |
925 | .open = ab8500_registers_open, |
926 | .read = seq_read, | |
927 | .llseek = seq_lseek, | |
928 | .release = single_release, | |
929 | .owner = THIS_MODULE, | |
5814fc35 MW |
930 | }; |
931 | ||
42002c6d MYK |
932 | static int ab8500_print_all_banks(struct seq_file *s, void *p) |
933 | { | |
934 | struct device *dev = s->private; | |
935 | unsigned int i; | |
936 | int err; | |
937 | ||
938 | seq_printf(s, AB8500_NAME_STRING " register values:\n"); | |
939 | ||
940 | for (i = 1; i < AB8500_NUM_BANKS; i++) { | |
cfc0849c | 941 | err = seq_printf(s, " bank 0x%02X:\n", i); |
42002c6d MYK |
942 | |
943 | ab8500_registers_print(dev, i, s); | |
944 | } | |
945 | return 0; | |
946 | } | |
947 | ||
1d843a6c MYK |
948 | /* Dump registers to kernel log */ |
949 | void ab8500_dump_all_banks(struct device *dev) | |
950 | { | |
951 | unsigned int i; | |
952 | ||
953 | printk(KERN_INFO"ab8500 register values:\n"); | |
954 | ||
955 | for (i = 1; i < AB8500_NUM_BANKS; i++) { | |
cfc0849c | 956 | printk(KERN_INFO" bank 0x%02X:\n", i); |
1d843a6c MYK |
957 | ab8500_registers_print(dev, i, NULL); |
958 | } | |
959 | } | |
960 | ||
5ff9090f LJ |
961 | /* Space for 500 registers. */ |
962 | #define DUMP_MAX_REGS 700 | |
963 | struct ab8500_register_dump | |
964 | { | |
965 | u8 bank; | |
966 | u8 reg; | |
967 | u8 value; | |
5ff9090f LJ |
968 | } ab8500_complete_register_dump[DUMP_MAX_REGS]; |
969 | ||
970 | extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size); | |
971 | ||
972 | /* This shall only be called upon kernel panic! */ | |
973 | void ab8500_dump_all_banks_to_mem(void) | |
974 | { | |
975 | int i, r = 0; | |
976 | u8 bank; | |
222460cb | 977 | int err = 0; |
5ff9090f LJ |
978 | |
979 | pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" " | |
980 | "for crash analyze.\n"); | |
981 | ||
982 | for (bank = 1; bank < AB8500_NUM_BANKS; bank++) { | |
983 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { | |
984 | u8 reg; | |
985 | ||
986 | for (reg = debug_ranges[bank].range[i].first; | |
987 | reg <= debug_ranges[bank].range[i].last; | |
988 | reg++) { | |
989 | u8 value; | |
5ff9090f LJ |
990 | |
991 | err = prcmu_abb_read(bank, reg, &value, 1); | |
992 | ||
222460cb JA |
993 | if (err < 0) |
994 | goto out; | |
995 | ||
5ff9090f LJ |
996 | ab8500_complete_register_dump[r].bank = bank; |
997 | ab8500_complete_register_dump[r].reg = reg; | |
998 | ab8500_complete_register_dump[r].value = value; | |
999 | ||
1000 | r++; | |
1001 | ||
1002 | if (r >= DUMP_MAX_REGS) { | |
1003 | pr_err("%s: too many register to dump!\n", | |
1004 | __func__); | |
222460cb JA |
1005 | err = -EINVAL; |
1006 | goto out; | |
5ff9090f LJ |
1007 | } |
1008 | } | |
1009 | } | |
1010 | } | |
222460cb JA |
1011 | out: |
1012 | if (err >= 0) | |
1013 | pr_info("Saved all ABB registers.\n"); | |
1014 | else | |
1015 | pr_info("Failed to save all ABB registers.\n"); | |
5ff9090f LJ |
1016 | } |
1017 | ||
42002c6d MYK |
1018 | static int ab8500_all_banks_open(struct inode *inode, struct file *file) |
1019 | { | |
1020 | struct seq_file *s; | |
1021 | int err; | |
1022 | ||
1023 | err = single_open(file, ab8500_print_all_banks, inode->i_private); | |
1024 | if (!err) { | |
1025 | /* Default buf size in seq_read is not enough */ | |
1026 | s = (struct seq_file *)file->private_data; | |
1027 | s->size = (PAGE_SIZE * 2); | |
1028 | s->buf = kmalloc(s->size, GFP_KERNEL); | |
1029 | if (!s->buf) { | |
1030 | single_release(inode, file); | |
1031 | err = -ENOMEM; | |
1032 | } | |
1033 | } | |
1034 | return err; | |
1035 | } | |
1036 | ||
1037 | static const struct file_operations ab8500_all_banks_fops = { | |
1038 | .open = ab8500_all_banks_open, | |
1039 | .read = seq_read, | |
1040 | .llseek = seq_lseek, | |
1041 | .release = single_release, | |
1042 | .owner = THIS_MODULE, | |
1043 | }; | |
1044 | ||
5814fc35 MW |
1045 | static int ab8500_bank_print(struct seq_file *s, void *p) |
1046 | { | |
cfc0849c | 1047 | return seq_printf(s, "0x%02X\n", debug_bank); |
5814fc35 MW |
1048 | } |
1049 | ||
1050 | static int ab8500_bank_open(struct inode *inode, struct file *file) | |
1051 | { | |
d7b9f322 | 1052 | return single_open(file, ab8500_bank_print, inode->i_private); |
5814fc35 MW |
1053 | } |
1054 | ||
1055 | static ssize_t ab8500_bank_write(struct file *file, | |
d7b9f322 MW |
1056 | const char __user *user_buf, |
1057 | size_t count, loff_t *ppos) | |
5814fc35 | 1058 | { |
d7b9f322 | 1059 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
d7b9f322 MW |
1060 | unsigned long user_bank; |
1061 | int err; | |
1062 | ||
1063 | /* Get userspace string and assure termination */ | |
8504d638 | 1064 | err = kstrtoul_from_user(user_buf, count, 0, &user_bank); |
d7b9f322 | 1065 | if (err) |
8504d638 | 1066 | return err; |
d7b9f322 MW |
1067 | |
1068 | if (user_bank >= AB8500_NUM_BANKS) { | |
1069 | dev_err(dev, "debugfs error input > number of banks\n"); | |
1070 | return -EINVAL; | |
1071 | } | |
1072 | ||
1073 | debug_bank = user_bank; | |
1074 | ||
8504d638 | 1075 | return count; |
5814fc35 MW |
1076 | } |
1077 | ||
1078 | static int ab8500_address_print(struct seq_file *s, void *p) | |
1079 | { | |
d7b9f322 | 1080 | return seq_printf(s, "0x%02X\n", debug_address); |
5814fc35 MW |
1081 | } |
1082 | ||
1083 | static int ab8500_address_open(struct inode *inode, struct file *file) | |
1084 | { | |
d7b9f322 | 1085 | return single_open(file, ab8500_address_print, inode->i_private); |
5814fc35 MW |
1086 | } |
1087 | ||
1088 | static ssize_t ab8500_address_write(struct file *file, | |
d7b9f322 MW |
1089 | const char __user *user_buf, |
1090 | size_t count, loff_t *ppos) | |
5814fc35 | 1091 | { |
d7b9f322 | 1092 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
d7b9f322 MW |
1093 | unsigned long user_address; |
1094 | int err; | |
1095 | ||
1096 | /* Get userspace string and assure termination */ | |
8504d638 | 1097 | err = kstrtoul_from_user(user_buf, count, 0, &user_address); |
d7b9f322 | 1098 | if (err) |
8504d638 PH |
1099 | return err; |
1100 | ||
d7b9f322 MW |
1101 | if (user_address > 0xff) { |
1102 | dev_err(dev, "debugfs error input > 0xff\n"); | |
1103 | return -EINVAL; | |
1104 | } | |
1105 | debug_address = user_address; | |
8504d638 | 1106 | return count; |
5814fc35 MW |
1107 | } |
1108 | ||
1109 | static int ab8500_val_print(struct seq_file *s, void *p) | |
1110 | { | |
d7b9f322 MW |
1111 | struct device *dev = s->private; |
1112 | int ret; | |
1113 | u8 regvalue; | |
1114 | ||
1115 | ret = abx500_get_register_interruptible(dev, | |
1116 | (u8)debug_bank, (u8)debug_address, ®value); | |
1117 | if (ret < 0) { | |
1118 | dev_err(dev, "abx500_get_reg fail %d, %d\n", | |
1119 | ret, __LINE__); | |
1120 | return -EINVAL; | |
1121 | } | |
1122 | seq_printf(s, "0x%02X\n", regvalue); | |
1123 | ||
1124 | return 0; | |
5814fc35 MW |
1125 | } |
1126 | ||
1127 | static int ab8500_val_open(struct inode *inode, struct file *file) | |
1128 | { | |
d7b9f322 | 1129 | return single_open(file, ab8500_val_print, inode->i_private); |
5814fc35 MW |
1130 | } |
1131 | ||
1132 | static ssize_t ab8500_val_write(struct file *file, | |
d7b9f322 MW |
1133 | const char __user *user_buf, |
1134 | size_t count, loff_t *ppos) | |
5814fc35 | 1135 | { |
d7b9f322 | 1136 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
d7b9f322 MW |
1137 | unsigned long user_val; |
1138 | int err; | |
1139 | ||
1140 | /* Get userspace string and assure termination */ | |
8504d638 | 1141 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
d7b9f322 | 1142 | if (err) |
8504d638 PH |
1143 | return err; |
1144 | ||
d7b9f322 MW |
1145 | if (user_val > 0xff) { |
1146 | dev_err(dev, "debugfs error input > 0xff\n"); | |
1147 | return -EINVAL; | |
1148 | } | |
1149 | err = abx500_set_register_interruptible(dev, | |
1150 | (u8)debug_bank, debug_address, (u8)user_val); | |
1151 | if (err < 0) { | |
1152 | printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__); | |
1153 | return -EINVAL; | |
1154 | } | |
1155 | ||
8504d638 | 1156 | return count; |
5814fc35 MW |
1157 | } |
1158 | ||
8f0eb43b BJ |
1159 | /* |
1160 | * Interrupt status | |
1161 | */ | |
1162 | static u32 num_interrupts[AB8500_MAX_NR_IRQS]; | |
2cf64e26 | 1163 | static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS]; |
8f0eb43b BJ |
1164 | static int num_interrupt_lines; |
1165 | ||
2cf64e26 JA |
1166 | bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int) |
1167 | { | |
1168 | return false; | |
1169 | } | |
1170 | ||
8f0eb43b BJ |
1171 | void ab8500_debug_register_interrupt(int line) |
1172 | { | |
2cf64e26 | 1173 | if (line < num_interrupt_lines) { |
8f0eb43b | 1174 | num_interrupts[line]++; |
2cf64e26 JA |
1175 | if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500)) |
1176 | num_wake_interrupts[line]++; | |
1177 | } | |
8f0eb43b BJ |
1178 | } |
1179 | ||
1180 | static int ab8500_interrupts_print(struct seq_file *s, void *p) | |
1181 | { | |
1182 | int line; | |
1183 | ||
2cf64e26 JA |
1184 | seq_printf(s, "name: number: number of: wake:\n"); |
1185 | ||
1186 | for (line = 0; line < num_interrupt_lines; line++) { | |
1187 | struct irq_desc *desc = irq_to_desc(line + irq_first); | |
1188 | struct irqaction *action = desc->action; | |
8f0eb43b | 1189 | |
2cf64e26 JA |
1190 | seq_printf(s, "%3i: %6i %4i", line, |
1191 | num_interrupts[line], | |
1192 | num_wake_interrupts[line]); | |
1193 | ||
1194 | if (desc && desc->name) | |
1195 | seq_printf(s, "-%-8s", desc->name); | |
1196 | if (action) { | |
1197 | seq_printf(s, " %s", action->name); | |
1198 | while ((action = action->next) != NULL) | |
1199 | seq_printf(s, ", %s", action->name); | |
1200 | } | |
1201 | seq_putc(s, '\n'); | |
1202 | } | |
8f0eb43b BJ |
1203 | |
1204 | return 0; | |
1205 | } | |
1206 | ||
1207 | static int ab8500_interrupts_open(struct inode *inode, struct file *file) | |
1208 | { | |
1209 | return single_open(file, ab8500_interrupts_print, inode->i_private); | |
1210 | } | |
1211 | ||
0fbce76e | 1212 | /* |
1213 | * - HWREG DB8500 formated routines | |
1214 | */ | |
1215 | static int ab8500_hwreg_print(struct seq_file *s, void *d) | |
1216 | { | |
1217 | struct device *dev = s->private; | |
1218 | int ret; | |
1219 | u8 regvalue; | |
1220 | ||
1221 | ret = abx500_get_register_interruptible(dev, | |
1222 | (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value); | |
1223 | if (ret < 0) { | |
1224 | dev_err(dev, "abx500_get_reg fail %d, %d\n", | |
1225 | ret, __LINE__); | |
1226 | return -EINVAL; | |
1227 | } | |
1228 | ||
1229 | if (hwreg_cfg.shift >= 0) | |
1230 | regvalue >>= hwreg_cfg.shift; | |
1231 | else | |
1232 | regvalue <<= -hwreg_cfg.shift; | |
1233 | regvalue &= hwreg_cfg.mask; | |
1234 | ||
1235 | if (REG_FMT_DEC(&hwreg_cfg)) | |
1236 | seq_printf(s, "%d\n", regvalue); | |
1237 | else | |
1238 | seq_printf(s, "0x%02X\n", regvalue); | |
1239 | return 0; | |
1240 | } | |
1241 | ||
1242 | static int ab8500_hwreg_open(struct inode *inode, struct file *file) | |
1243 | { | |
1244 | return single_open(file, ab8500_hwreg_print, inode->i_private); | |
1245 | } | |
1246 | ||
c7ebaee2 LJ |
1247 | #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01 |
1248 | #define AB8500_SUPPLY_CONTROL_REG 0x00 | |
1249 | #define AB8500_FIRST_SIM_REG 0x80 | |
1250 | #define AB8500_LAST_SIM_REG 0x8B | |
1251 | #define AB8505_LAST_SIM_REG 0x8C | |
1252 | ||
1253 | static int ab8500_print_modem_registers(struct seq_file *s, void *p) | |
1254 | { | |
1255 | struct device *dev = s->private; | |
1256 | struct ab8500 *ab8500; | |
1257 | int err; | |
1258 | u8 value; | |
1259 | u8 orig_value; | |
1260 | u32 bank = AB8500_REGU_CTRL2; | |
1261 | u32 last_sim_reg = AB8500_LAST_SIM_REG; | |
1262 | u32 reg; | |
1263 | ||
1264 | ab8500 = dev_get_drvdata(dev->parent); | |
1265 | dev_warn(dev, "WARNING! This operation can interfer with modem side\n" | |
1266 | "and should only be done with care\n"); | |
1267 | ||
1268 | err = abx500_get_register_interruptible(dev, | |
1269 | AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value); | |
1270 | if (err < 0) { | |
1271 | dev_err(dev, "ab->read fail %d\n", err); | |
1272 | return err; | |
1273 | } | |
1274 | /* Config 1 will allow APE side to read SIM registers */ | |
1275 | err = abx500_set_register_interruptible(dev, | |
1276 | AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, | |
1277 | AB8500_SUPPLY_CONTROL_CONFIG_1); | |
1278 | if (err < 0) { | |
1279 | dev_err(dev, "ab->write fail %d\n", err); | |
1280 | return err; | |
1281 | } | |
1282 | ||
1283 | seq_printf(s, " bank 0x%02X:\n", bank); | |
1284 | ||
1285 | if (is_ab9540(ab8500) || is_ab8505(ab8500)) | |
1286 | last_sim_reg = AB8505_LAST_SIM_REG; | |
1287 | ||
1288 | for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) { | |
1289 | err = abx500_get_register_interruptible(dev, | |
1290 | bank, reg, &value); | |
1291 | if (err < 0) { | |
1292 | dev_err(dev, "ab->read fail %d\n", err); | |
1293 | return err; | |
1294 | } | |
1295 | err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", | |
1296 | bank, reg, value); | |
1297 | } | |
1298 | err = abx500_set_register_interruptible(dev, | |
1299 | AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value); | |
1300 | if (err < 0) { | |
1301 | dev_err(dev, "ab->write fail %d\n", err); | |
1302 | return err; | |
1303 | } | |
1304 | return 0; | |
1305 | } | |
1306 | ||
1307 | static int ab8500_modem_open(struct inode *inode, struct file *file) | |
1308 | { | |
1309 | return single_open(file, ab8500_print_modem_registers, inode->i_private); | |
1310 | } | |
1311 | ||
1312 | static const struct file_operations ab8500_modem_fops = { | |
1313 | .open = ab8500_modem_open, | |
1314 | .read = seq_read, | |
1315 | .llseek = seq_lseek, | |
1316 | .release = single_release, | |
1317 | .owner = THIS_MODULE, | |
1318 | }; | |
1319 | ||
1478a316 JB |
1320 | static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p) |
1321 | { | |
1322 | int bat_ctrl_raw; | |
1323 | int bat_ctrl_convert; | |
1324 | struct ab8500_gpadc *gpadc; | |
1325 | ||
8908c049 | 1326 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1327 | bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL, |
1328 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1329 | bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
73482346 | 1330 | BAT_CTRL, bat_ctrl_raw); |
1478a316 JB |
1331 | |
1332 | return seq_printf(s, "%d,0x%X\n", | |
1333 | bat_ctrl_convert, bat_ctrl_raw); | |
1334 | } | |
1335 | ||
1336 | static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file) | |
1337 | { | |
1338 | return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private); | |
1339 | } | |
1340 | ||
1341 | static const struct file_operations ab8500_gpadc_bat_ctrl_fops = { | |
1342 | .open = ab8500_gpadc_bat_ctrl_open, | |
1343 | .read = seq_read, | |
1344 | .llseek = seq_lseek, | |
1345 | .release = single_release, | |
1346 | .owner = THIS_MODULE, | |
1347 | }; | |
1348 | ||
1349 | static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p) | |
1350 | { | |
1351 | int btemp_ball_raw; | |
1352 | int btemp_ball_convert; | |
1353 | struct ab8500_gpadc *gpadc; | |
1354 | ||
8908c049 | 1355 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1356 | btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL, |
1357 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1358 | btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, |
73482346 | 1359 | btemp_ball_raw); |
1478a316 JB |
1360 | |
1361 | return seq_printf(s, | |
1362 | "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw); | |
1363 | } | |
1364 | ||
1365 | static int ab8500_gpadc_btemp_ball_open(struct inode *inode, | |
1366 | struct file *file) | |
1367 | { | |
1368 | return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private); | |
1369 | } | |
1370 | ||
1371 | static const struct file_operations ab8500_gpadc_btemp_ball_fops = { | |
1372 | .open = ab8500_gpadc_btemp_ball_open, | |
1373 | .read = seq_read, | |
1374 | .llseek = seq_lseek, | |
1375 | .release = single_release, | |
1376 | .owner = THIS_MODULE, | |
1377 | }; | |
1378 | ||
1379 | static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p) | |
1380 | { | |
1381 | int main_charger_v_raw; | |
1382 | int main_charger_v_convert; | |
1383 | struct ab8500_gpadc *gpadc; | |
1384 | ||
8908c049 | 1385 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1386 | main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V, |
1387 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1388 | main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
73482346 | 1389 | MAIN_CHARGER_V, main_charger_v_raw); |
1478a316 JB |
1390 | |
1391 | return seq_printf(s, "%d,0x%X\n", | |
1392 | main_charger_v_convert, main_charger_v_raw); | |
1393 | } | |
1394 | ||
1395 | static int ab8500_gpadc_main_charger_v_open(struct inode *inode, | |
1396 | struct file *file) | |
1397 | { | |
1398 | return single_open(file, ab8500_gpadc_main_charger_v_print, | |
1399 | inode->i_private); | |
1400 | } | |
1401 | ||
1402 | static const struct file_operations ab8500_gpadc_main_charger_v_fops = { | |
1403 | .open = ab8500_gpadc_main_charger_v_open, | |
1404 | .read = seq_read, | |
1405 | .llseek = seq_lseek, | |
1406 | .release = single_release, | |
1407 | .owner = THIS_MODULE, | |
1408 | }; | |
1409 | ||
1410 | static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p) | |
1411 | { | |
1412 | int acc_detect1_raw; | |
1413 | int acc_detect1_convert; | |
1414 | struct ab8500_gpadc *gpadc; | |
1415 | ||
8908c049 | 1416 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1417 | acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1, |
1418 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1419 | acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1, |
73482346 | 1420 | acc_detect1_raw); |
1478a316 JB |
1421 | |
1422 | return seq_printf(s, "%d,0x%X\n", | |
1423 | acc_detect1_convert, acc_detect1_raw); | |
1424 | } | |
1425 | ||
1426 | static int ab8500_gpadc_acc_detect1_open(struct inode *inode, | |
1427 | struct file *file) | |
1428 | { | |
1429 | return single_open(file, ab8500_gpadc_acc_detect1_print, | |
1430 | inode->i_private); | |
1431 | } | |
1432 | ||
1433 | static const struct file_operations ab8500_gpadc_acc_detect1_fops = { | |
1434 | .open = ab8500_gpadc_acc_detect1_open, | |
1435 | .read = seq_read, | |
1436 | .llseek = seq_lseek, | |
1437 | .release = single_release, | |
1438 | .owner = THIS_MODULE, | |
1439 | }; | |
1440 | ||
1441 | static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p) | |
1442 | { | |
1443 | int acc_detect2_raw; | |
1444 | int acc_detect2_convert; | |
1445 | struct ab8500_gpadc *gpadc; | |
1446 | ||
8908c049 | 1447 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1448 | acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2, |
1449 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1450 | acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
73482346 | 1451 | ACC_DETECT2, acc_detect2_raw); |
1478a316 JB |
1452 | |
1453 | return seq_printf(s, "%d,0x%X\n", | |
1454 | acc_detect2_convert, acc_detect2_raw); | |
1455 | } | |
1456 | ||
1457 | static int ab8500_gpadc_acc_detect2_open(struct inode *inode, | |
1458 | struct file *file) | |
1459 | { | |
1460 | return single_open(file, ab8500_gpadc_acc_detect2_print, | |
1461 | inode->i_private); | |
1462 | } | |
1463 | ||
1464 | static const struct file_operations ab8500_gpadc_acc_detect2_fops = { | |
1465 | .open = ab8500_gpadc_acc_detect2_open, | |
1466 | .read = seq_read, | |
1467 | .llseek = seq_lseek, | |
1468 | .release = single_release, | |
1469 | .owner = THIS_MODULE, | |
1470 | }; | |
1471 | ||
1472 | static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p) | |
1473 | { | |
1474 | int aux1_raw; | |
1475 | int aux1_convert; | |
1476 | struct ab8500_gpadc *gpadc; | |
1477 | ||
8908c049 | 1478 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1479 | aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1, |
1480 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1481 | aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1, |
73482346 | 1482 | aux1_raw); |
1478a316 JB |
1483 | |
1484 | return seq_printf(s, "%d,0x%X\n", | |
1485 | aux1_convert, aux1_raw); | |
1486 | } | |
1487 | ||
1488 | static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file) | |
1489 | { | |
1490 | return single_open(file, ab8500_gpadc_aux1_print, inode->i_private); | |
1491 | } | |
1492 | ||
1493 | static const struct file_operations ab8500_gpadc_aux1_fops = { | |
1494 | .open = ab8500_gpadc_aux1_open, | |
1495 | .read = seq_read, | |
1496 | .llseek = seq_lseek, | |
1497 | .release = single_release, | |
1498 | .owner = THIS_MODULE, | |
1499 | }; | |
1500 | ||
1501 | static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p) | |
1502 | { | |
1503 | int aux2_raw; | |
1504 | int aux2_convert; | |
1505 | struct ab8500_gpadc *gpadc; | |
1506 | ||
8908c049 | 1507 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1508 | aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2, |
1509 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1510 | aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2, |
73482346 | 1511 | aux2_raw); |
1478a316 JB |
1512 | |
1513 | return seq_printf(s, "%d,0x%X\n", | |
1514 | aux2_convert, aux2_raw); | |
1515 | } | |
1516 | ||
1517 | static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file) | |
1518 | { | |
1519 | return single_open(file, ab8500_gpadc_aux2_print, inode->i_private); | |
1520 | } | |
1521 | ||
1522 | static const struct file_operations ab8500_gpadc_aux2_fops = { | |
1523 | .open = ab8500_gpadc_aux2_open, | |
1524 | .read = seq_read, | |
1525 | .llseek = seq_lseek, | |
1526 | .release = single_release, | |
1527 | .owner = THIS_MODULE, | |
1528 | }; | |
1529 | ||
1530 | static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p) | |
1531 | { | |
1532 | int main_bat_v_raw; | |
1533 | int main_bat_v_convert; | |
1534 | struct ab8500_gpadc *gpadc; | |
1535 | ||
8908c049 | 1536 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1537 | main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V, |
1538 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1539 | main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, |
73482346 | 1540 | main_bat_v_raw); |
1478a316 JB |
1541 | |
1542 | return seq_printf(s, "%d,0x%X\n", | |
1543 | main_bat_v_convert, main_bat_v_raw); | |
1544 | } | |
1545 | ||
1546 | static int ab8500_gpadc_main_bat_v_open(struct inode *inode, | |
1547 | struct file *file) | |
1548 | { | |
1549 | return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private); | |
1550 | } | |
1551 | ||
1552 | static const struct file_operations ab8500_gpadc_main_bat_v_fops = { | |
1553 | .open = ab8500_gpadc_main_bat_v_open, | |
1554 | .read = seq_read, | |
1555 | .llseek = seq_lseek, | |
1556 | .release = single_release, | |
1557 | .owner = THIS_MODULE, | |
1558 | }; | |
1559 | ||
1560 | static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p) | |
1561 | { | |
1562 | int vbus_v_raw; | |
1563 | int vbus_v_convert; | |
1564 | struct ab8500_gpadc *gpadc; | |
1565 | ||
8908c049 | 1566 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1567 | vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V, |
1568 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1569 | vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V, |
73482346 | 1570 | vbus_v_raw); |
1478a316 JB |
1571 | |
1572 | return seq_printf(s, "%d,0x%X\n", | |
1573 | vbus_v_convert, vbus_v_raw); | |
1574 | } | |
1575 | ||
1576 | static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file) | |
1577 | { | |
1578 | return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private); | |
1579 | } | |
1580 | ||
1581 | static const struct file_operations ab8500_gpadc_vbus_v_fops = { | |
1582 | .open = ab8500_gpadc_vbus_v_open, | |
1583 | .read = seq_read, | |
1584 | .llseek = seq_lseek, | |
1585 | .release = single_release, | |
1586 | .owner = THIS_MODULE, | |
1587 | }; | |
1588 | ||
1589 | static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p) | |
1590 | { | |
1591 | int main_charger_c_raw; | |
1592 | int main_charger_c_convert; | |
1593 | struct ab8500_gpadc *gpadc; | |
1594 | ||
8908c049 | 1595 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1596 | main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C, |
1597 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1598 | main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
73482346 | 1599 | MAIN_CHARGER_C, main_charger_c_raw); |
1478a316 JB |
1600 | |
1601 | return seq_printf(s, "%d,0x%X\n", | |
1602 | main_charger_c_convert, main_charger_c_raw); | |
1603 | } | |
1604 | ||
1605 | static int ab8500_gpadc_main_charger_c_open(struct inode *inode, | |
1606 | struct file *file) | |
1607 | { | |
1608 | return single_open(file, ab8500_gpadc_main_charger_c_print, | |
1609 | inode->i_private); | |
1610 | } | |
1611 | ||
1612 | static const struct file_operations ab8500_gpadc_main_charger_c_fops = { | |
1613 | .open = ab8500_gpadc_main_charger_c_open, | |
1614 | .read = seq_read, | |
1615 | .llseek = seq_lseek, | |
1616 | .release = single_release, | |
1617 | .owner = THIS_MODULE, | |
1618 | }; | |
1619 | ||
1620 | static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p) | |
1621 | { | |
1622 | int usb_charger_c_raw; | |
1623 | int usb_charger_c_convert; | |
1624 | struct ab8500_gpadc *gpadc; | |
1625 | ||
8908c049 | 1626 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1627 | usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C, |
1628 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1629 | usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
73482346 | 1630 | USB_CHARGER_C, usb_charger_c_raw); |
1478a316 JB |
1631 | |
1632 | return seq_printf(s, "%d,0x%X\n", | |
1633 | usb_charger_c_convert, usb_charger_c_raw); | |
1634 | } | |
1635 | ||
1636 | static int ab8500_gpadc_usb_charger_c_open(struct inode *inode, | |
1637 | struct file *file) | |
1638 | { | |
1639 | return single_open(file, ab8500_gpadc_usb_charger_c_print, | |
1640 | inode->i_private); | |
1641 | } | |
1642 | ||
1643 | static const struct file_operations ab8500_gpadc_usb_charger_c_fops = { | |
1644 | .open = ab8500_gpadc_usb_charger_c_open, | |
1645 | .read = seq_read, | |
1646 | .llseek = seq_lseek, | |
1647 | .release = single_release, | |
1648 | .owner = THIS_MODULE, | |
1649 | }; | |
1650 | ||
1651 | static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p) | |
1652 | { | |
1653 | int bk_bat_v_raw; | |
1654 | int bk_bat_v_convert; | |
1655 | struct ab8500_gpadc *gpadc; | |
1656 | ||
8908c049 | 1657 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1658 | bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V, |
1659 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1660 | bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
73482346 | 1661 | BK_BAT_V, bk_bat_v_raw); |
1478a316 JB |
1662 | |
1663 | return seq_printf(s, "%d,0x%X\n", | |
1664 | bk_bat_v_convert, bk_bat_v_raw); | |
1665 | } | |
1666 | ||
1667 | static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file) | |
1668 | { | |
1669 | return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private); | |
1670 | } | |
1671 | ||
1672 | static const struct file_operations ab8500_gpadc_bk_bat_v_fops = { | |
1673 | .open = ab8500_gpadc_bk_bat_v_open, | |
1674 | .read = seq_read, | |
1675 | .llseek = seq_lseek, | |
1676 | .release = single_release, | |
1677 | .owner = THIS_MODULE, | |
1678 | }; | |
1679 | ||
1680 | static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p) | |
1681 | { | |
1682 | int die_temp_raw; | |
1683 | int die_temp_convert; | |
1684 | struct ab8500_gpadc *gpadc; | |
1685 | ||
8908c049 | 1686 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
73482346 LJ |
1687 | die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP, |
1688 | avg_sample, trig_edge, trig_timer, conv_type); | |
1478a316 | 1689 | die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP, |
73482346 | 1690 | die_temp_raw); |
1478a316 JB |
1691 | |
1692 | return seq_printf(s, "%d,0x%X\n", | |
1693 | die_temp_convert, die_temp_raw); | |
1694 | } | |
1695 | ||
1696 | static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file) | |
1697 | { | |
1698 | return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private); | |
1699 | } | |
1700 | ||
1701 | static const struct file_operations ab8500_gpadc_die_temp_fops = { | |
1702 | .open = ab8500_gpadc_die_temp_open, | |
1703 | .read = seq_read, | |
1704 | .llseek = seq_lseek, | |
1705 | .release = single_release, | |
1706 | .owner = THIS_MODULE, | |
1707 | }; | |
1708 | ||
127629d7 LJ |
1709 | static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p) |
1710 | { | |
1711 | int usb_id_raw; | |
1712 | int usb_id_convert; | |
1713 | struct ab8500_gpadc *gpadc; | |
1714 | ||
1715 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1716 | usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID, | |
1717 | avg_sample, trig_edge, trig_timer, conv_type); | |
1718 | usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID, | |
1719 | usb_id_raw); | |
1720 | ||
1721 | return seq_printf(s, "%d,0x%X\n", | |
1722 | usb_id_convert, usb_id_raw); | |
1723 | } | |
1724 | ||
1725 | static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file) | |
1726 | { | |
1727 | return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private); | |
1728 | } | |
1729 | ||
1730 | static const struct file_operations ab8500_gpadc_usb_id_fops = { | |
1731 | .open = ab8500_gpadc_usb_id_open, | |
1732 | .read = seq_read, | |
1733 | .llseek = seq_lseek, | |
1734 | .release = single_release, | |
1735 | .owner = THIS_MODULE, | |
1736 | }; | |
1737 | ||
bc6b4132 LJ |
1738 | static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p) |
1739 | { | |
1740 | int xtal_temp_raw; | |
1741 | int xtal_temp_convert; | |
1742 | struct ab8500_gpadc *gpadc; | |
1743 | ||
1744 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1745 | xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP, | |
1746 | avg_sample, trig_edge, trig_timer, conv_type); | |
1747 | xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP, | |
1748 | xtal_temp_raw); | |
1749 | ||
1750 | return seq_printf(s, "%d,0x%X\n", | |
1751 | xtal_temp_convert, xtal_temp_raw); | |
1752 | } | |
1753 | ||
1754 | static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file) | |
1755 | { | |
1756 | return single_open(file, ab8540_gpadc_xtal_temp_print, | |
1757 | inode->i_private); | |
1758 | } | |
1759 | ||
1760 | static const struct file_operations ab8540_gpadc_xtal_temp_fops = { | |
1761 | .open = ab8540_gpadc_xtal_temp_open, | |
1762 | .read = seq_read, | |
1763 | .llseek = seq_lseek, | |
1764 | .release = single_release, | |
1765 | .owner = THIS_MODULE, | |
1766 | }; | |
1767 | ||
1768 | static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p) | |
1769 | { | |
1770 | int vbat_true_meas_raw; | |
1771 | int vbat_true_meas_convert; | |
1772 | struct ab8500_gpadc *gpadc; | |
1773 | ||
1774 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1775 | vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS, | |
1776 | avg_sample, trig_edge, trig_timer, conv_type); | |
1777 | vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS, | |
1778 | vbat_true_meas_raw); | |
1779 | ||
1780 | return seq_printf(s, "%d,0x%X\n", | |
1781 | vbat_true_meas_convert, vbat_true_meas_raw); | |
1782 | } | |
1783 | ||
1784 | static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode, | |
1785 | struct file *file) | |
1786 | { | |
1787 | return single_open(file, ab8540_gpadc_vbat_true_meas_print, | |
1788 | inode->i_private); | |
1789 | } | |
1790 | ||
1791 | static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = { | |
1792 | .open = ab8540_gpadc_vbat_true_meas_open, | |
1793 | .read = seq_read, | |
1794 | .llseek = seq_lseek, | |
1795 | .release = single_release, | |
1796 | .owner = THIS_MODULE, | |
1797 | }; | |
1798 | ||
1799 | static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p) | |
1800 | { | |
1801 | int bat_ctrl_raw; | |
1802 | int bat_ctrl_convert; | |
1803 | int ibat_raw; | |
1804 | int ibat_convert; | |
1805 | struct ab8500_gpadc *gpadc; | |
1806 | ||
1807 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1808 | bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT, | |
1809 | avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw); | |
1810 | ||
1811 | bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL, | |
1812 | bat_ctrl_raw); | |
1813 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, | |
1814 | ibat_raw); | |
1815 | ||
1816 | return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n", | |
1817 | bat_ctrl_convert, bat_ctrl_raw, | |
1818 | ibat_convert, ibat_raw); | |
1819 | } | |
1820 | ||
1821 | static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode, | |
1822 | struct file *file) | |
1823 | { | |
1824 | return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print, | |
1825 | inode->i_private); | |
1826 | } | |
1827 | ||
1828 | static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = { | |
1829 | .open = ab8540_gpadc_bat_ctrl_and_ibat_open, | |
1830 | .read = seq_read, | |
1831 | .llseek = seq_lseek, | |
1832 | .release = single_release, | |
1833 | .owner = THIS_MODULE, | |
1834 | }; | |
1835 | ||
1836 | static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p) | |
1837 | { | |
1838 | int vbat_meas_raw; | |
1839 | int vbat_meas_convert; | |
1840 | int ibat_raw; | |
1841 | int ibat_convert; | |
1842 | struct ab8500_gpadc *gpadc; | |
1843 | ||
1844 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1845 | vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT, | |
1846 | avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw); | |
1847 | vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, | |
1848 | vbat_meas_raw); | |
1849 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, | |
1850 | ibat_raw); | |
1851 | ||
1852 | return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n", | |
1853 | vbat_meas_convert, vbat_meas_raw, | |
1854 | ibat_convert, ibat_raw); | |
1855 | } | |
1856 | ||
1857 | static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode, | |
1858 | struct file *file) | |
1859 | { | |
1860 | return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print, | |
1861 | inode->i_private); | |
1862 | } | |
1863 | ||
1864 | static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = { | |
1865 | .open = ab8540_gpadc_vbat_meas_and_ibat_open, | |
1866 | .read = seq_read, | |
1867 | .llseek = seq_lseek, | |
1868 | .release = single_release, | |
1869 | .owner = THIS_MODULE, | |
1870 | }; | |
1871 | ||
1872 | static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, void *p) | |
1873 | { | |
1874 | int vbat_true_meas_raw; | |
1875 | int vbat_true_meas_convert; | |
1876 | int ibat_raw; | |
1877 | int ibat_convert; | |
1878 | struct ab8500_gpadc *gpadc; | |
1879 | ||
1880 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1881 | vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc, | |
1882 | VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge, | |
1883 | trig_timer, conv_type, &ibat_raw); | |
1884 | vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, | |
1885 | VBAT_TRUE_MEAS, vbat_true_meas_raw); | |
1886 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, | |
1887 | ibat_raw); | |
1888 | ||
1889 | return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n", | |
1890 | vbat_true_meas_convert, vbat_true_meas_raw, | |
1891 | ibat_convert, ibat_raw); | |
1892 | } | |
1893 | ||
1894 | static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode, | |
1895 | struct file *file) | |
1896 | { | |
1897 | return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print, | |
1898 | inode->i_private); | |
1899 | } | |
1900 | ||
1901 | static const struct file_operations ab8540_gpadc_vbat_true_meas_and_ibat_fops = { | |
1902 | .open = ab8540_gpadc_vbat_true_meas_and_ibat_open, | |
1903 | .read = seq_read, | |
1904 | .llseek = seq_lseek, | |
1905 | .release = single_release, | |
1906 | .owner = THIS_MODULE, | |
1907 | }; | |
1908 | ||
1909 | static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p) | |
1910 | { | |
1911 | int bat_temp_raw; | |
1912 | int bat_temp_convert; | |
1913 | int ibat_raw; | |
1914 | int ibat_convert; | |
1915 | struct ab8500_gpadc *gpadc; | |
1916 | ||
1917 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1918 | bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT, | |
1919 | avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw); | |
1920 | bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, | |
1921 | bat_temp_raw); | |
1922 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, | |
1923 | ibat_raw); | |
1924 | ||
1925 | return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n", | |
1926 | bat_temp_convert, bat_temp_raw, | |
1927 | ibat_convert, ibat_raw); | |
1928 | } | |
1929 | ||
1930 | static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode, | |
1931 | struct file *file) | |
1932 | { | |
1933 | return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print, | |
1934 | inode->i_private); | |
1935 | } | |
1936 | ||
1937 | static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = { | |
1938 | .open = ab8540_gpadc_bat_temp_and_ibat_open, | |
1939 | .read = seq_read, | |
1940 | .llseek = seq_lseek, | |
1941 | .release = single_release, | |
1942 | .owner = THIS_MODULE, | |
1943 | }; | |
1944 | ||
1945 | static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p) | |
1946 | { | |
1947 | struct ab8500_gpadc *gpadc; | |
1948 | u16 vmain_l, vmain_h, btemp_l, btemp_h; | |
1949 | u16 vbat_l, vbat_h, ibat_l, ibat_h; | |
1950 | ||
1951 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | |
1952 | ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h, | |
1953 | &vbat_l, &vbat_h, &ibat_l, &ibat_h); | |
1954 | return seq_printf(s, "VMAIN_L:0x%X\n" | |
1955 | "VMAIN_H:0x%X\n" | |
1956 | "BTEMP_L:0x%X\n" | |
1957 | "BTEMP_H:0x%X\n" | |
1958 | "VBAT_L:0x%X\n" | |
1959 | "VBAT_H:0x%X\n" | |
1960 | "IBAT_L:0x%X\n" | |
1961 | "IBAT_H:0x%X\n" | |
1962 | , | |
1963 | vmain_l, | |
1964 | vmain_h, | |
1965 | btemp_l, | |
1966 | btemp_h, | |
1967 | vbat_l, | |
1968 | vbat_h, | |
1969 | ibat_l, | |
1970 | ibat_h); | |
1971 | } | |
1972 | ||
1973 | static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file) | |
1974 | { | |
1975 | return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private); | |
1976 | } | |
1977 | ||
1978 | static const struct file_operations ab8540_gpadc_otp_calib_fops = { | |
1979 | .open = ab8540_gpadc_otp_cal_open, | |
1980 | .read = seq_read, | |
1981 | .llseek = seq_lseek, | |
1982 | .release = single_release, | |
1983 | .owner = THIS_MODULE, | |
1984 | }; | |
1985 | ||
73482346 LJ |
1986 | static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p) |
1987 | { | |
1988 | return seq_printf(s, "%d\n", avg_sample); | |
1989 | } | |
1990 | ||
1991 | static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file) | |
1992 | { | |
1993 | return single_open(file, ab8500_gpadc_avg_sample_print, | |
1994 | inode->i_private); | |
1995 | } | |
1996 | ||
1997 | static ssize_t ab8500_gpadc_avg_sample_write(struct file *file, | |
1998 | const char __user *user_buf, | |
1999 | size_t count, loff_t *ppos) | |
2000 | { | |
2001 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
2002 | char buf[32]; | |
2003 | int buf_size; | |
2004 | unsigned long user_avg_sample; | |
2005 | int err; | |
2006 | ||
2007 | /* Get userspace string and assure termination */ | |
2008 | buf_size = min(count, (sizeof(buf) - 1)); | |
2009 | if (copy_from_user(buf, user_buf, buf_size)) | |
2010 | return -EFAULT; | |
2011 | buf[buf_size] = 0; | |
2012 | ||
2013 | err = strict_strtoul(buf, 0, &user_avg_sample); | |
2014 | if (err) | |
2015 | return -EINVAL; | |
2016 | if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4) | |
2017 | || (user_avg_sample == SAMPLE_8) | |
2018 | || (user_avg_sample == SAMPLE_16)) { | |
2019 | avg_sample = (u8) user_avg_sample; | |
2020 | } else { | |
2021 | dev_err(dev, "debugfs error input: " | |
2022 | "should be egal to 1, 4, 8 or 16\n"); | |
2023 | return -EINVAL; | |
2024 | } | |
2025 | return buf_size; | |
2026 | } | |
2027 | ||
2028 | static const struct file_operations ab8500_gpadc_avg_sample_fops = { | |
2029 | .open = ab8500_gpadc_avg_sample_open, | |
2030 | .read = seq_read, | |
2031 | .write = ab8500_gpadc_avg_sample_write, | |
2032 | .llseek = seq_lseek, | |
2033 | .release = single_release, | |
2034 | .owner = THIS_MODULE, | |
2035 | }; | |
2036 | ||
2037 | static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p) | |
2038 | { | |
2039 | return seq_printf(s, "%d\n", trig_edge); | |
2040 | } | |
2041 | ||
2042 | static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file) | |
2043 | { | |
2044 | return single_open(file, ab8500_gpadc_trig_edge_print, | |
2045 | inode->i_private); | |
2046 | } | |
2047 | ||
2048 | static ssize_t ab8500_gpadc_trig_edge_write(struct file *file, | |
2049 | const char __user *user_buf, | |
2050 | size_t count, loff_t *ppos) | |
2051 | { | |
2052 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
2053 | char buf[32]; | |
2054 | int buf_size; | |
2055 | unsigned long user_trig_edge; | |
2056 | int err; | |
2057 | ||
2058 | /* Get userspace string and assure termination */ | |
2059 | buf_size = min(count, (sizeof(buf) - 1)); | |
2060 | if (copy_from_user(buf, user_buf, buf_size)) | |
2061 | return -EFAULT; | |
2062 | buf[buf_size] = 0; | |
2063 | ||
2064 | err = strict_strtoul(buf, 0, &user_trig_edge); | |
2065 | if (err) | |
2066 | return -EINVAL; | |
2067 | if ((user_trig_edge == RISING_EDGE) | |
2068 | || (user_trig_edge == FALLING_EDGE)) { | |
2069 | trig_edge = (u8) user_trig_edge; | |
2070 | } else { | |
2071 | dev_err(dev, "Wrong input:\n" | |
2072 | "Enter 0. Rising edge\n" | |
2073 | "Enter 1. Falling edge\n"); | |
2074 | return -EINVAL; | |
2075 | } | |
2076 | return buf_size; | |
2077 | } | |
2078 | ||
2079 | static const struct file_operations ab8500_gpadc_trig_edge_fops = { | |
2080 | .open = ab8500_gpadc_trig_edge_open, | |
2081 | .read = seq_read, | |
2082 | .write = ab8500_gpadc_trig_edge_write, | |
2083 | .llseek = seq_lseek, | |
2084 | .release = single_release, | |
2085 | .owner = THIS_MODULE, | |
2086 | }; | |
2087 | ||
2088 | static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p) | |
2089 | { | |
2090 | return seq_printf(s, "%d\n", trig_timer); | |
2091 | } | |
2092 | ||
2093 | static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file) | |
2094 | { | |
2095 | return single_open(file, ab8500_gpadc_trig_timer_print, | |
2096 | inode->i_private); | |
2097 | } | |
2098 | ||
2099 | static ssize_t ab8500_gpadc_trig_timer_write(struct file *file, | |
2100 | const char __user *user_buf, | |
2101 | size_t count, loff_t *ppos) | |
2102 | { | |
2103 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
2104 | char buf[32]; | |
2105 | int buf_size; | |
2106 | unsigned long user_trig_timer; | |
2107 | int err; | |
2108 | ||
2109 | /* Get userspace string and assure termination */ | |
2110 | buf_size = min(count, (sizeof(buf) - 1)); | |
2111 | if (copy_from_user(buf, user_buf, buf_size)) | |
2112 | return -EFAULT; | |
2113 | buf[buf_size] = 0; | |
2114 | ||
2115 | err = strict_strtoul(buf, 0, &user_trig_timer); | |
2116 | if (err) | |
2117 | return -EINVAL; | |
2118 | if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) { | |
2119 | trig_timer = (u8) user_trig_timer; | |
2120 | } else { | |
2121 | dev_err(dev, "debugfs error input: " | |
2122 | "should be beetween 0 to 255\n"); | |
2123 | return -EINVAL; | |
2124 | } | |
2125 | return buf_size; | |
2126 | } | |
2127 | ||
2128 | static const struct file_operations ab8500_gpadc_trig_timer_fops = { | |
2129 | .open = ab8500_gpadc_trig_timer_open, | |
2130 | .read = seq_read, | |
2131 | .write = ab8500_gpadc_trig_timer_write, | |
2132 | .llseek = seq_lseek, | |
2133 | .release = single_release, | |
2134 | .owner = THIS_MODULE, | |
2135 | }; | |
2136 | ||
2137 | static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p) | |
2138 | { | |
2139 | return seq_printf(s, "%d\n", conv_type); | |
2140 | } | |
2141 | ||
2142 | static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file) | |
2143 | { | |
2144 | return single_open(file, ab8500_gpadc_conv_type_print, | |
2145 | inode->i_private); | |
2146 | } | |
2147 | ||
2148 | static ssize_t ab8500_gpadc_conv_type_write(struct file *file, | |
2149 | const char __user *user_buf, | |
2150 | size_t count, loff_t *ppos) | |
2151 | { | |
2152 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
2153 | char buf[32]; | |
2154 | int buf_size; | |
2155 | unsigned long user_conv_type; | |
2156 | int err; | |
2157 | ||
2158 | /* Get userspace string and assure termination */ | |
2159 | buf_size = min(count, (sizeof(buf) - 1)); | |
2160 | if (copy_from_user(buf, user_buf, buf_size)) | |
2161 | return -EFAULT; | |
2162 | buf[buf_size] = 0; | |
2163 | ||
2164 | err = strict_strtoul(buf, 0, &user_conv_type); | |
2165 | if (err) | |
2166 | return -EINVAL; | |
2167 | if ((user_conv_type == ADC_SW) | |
2168 | || (user_conv_type == ADC_HW)) { | |
2169 | conv_type = (u8) user_conv_type; | |
2170 | } else { | |
2171 | dev_err(dev, "Wrong input:\n" | |
2172 | "Enter 0. ADC SW conversion\n" | |
2173 | "Enter 1. ADC HW conversion\n"); | |
2174 | return -EINVAL; | |
2175 | } | |
2176 | return buf_size; | |
2177 | } | |
2178 | ||
2179 | static const struct file_operations ab8500_gpadc_conv_type_fops = { | |
2180 | .open = ab8500_gpadc_conv_type_open, | |
2181 | .read = seq_read, | |
2182 | .write = ab8500_gpadc_conv_type_write, | |
2183 | .llseek = seq_lseek, | |
2184 | .release = single_release, | |
2185 | .owner = THIS_MODULE, | |
2186 | }; | |
2187 | ||
0fbce76e | 2188 | /* |
2189 | * return length of an ASCII numerical value, 0 is string is not a | |
2190 | * numerical value. | |
2191 | * string shall start at value 1st char. | |
2192 | * string can be tailed with \0 or space or newline chars only. | |
2193 | * value can be decimal or hexadecimal (prefixed 0x or 0X). | |
2194 | */ | |
2195 | static int strval_len(char *b) | |
2196 | { | |
2197 | char *s = b; | |
2198 | if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) { | |
2199 | s += 2; | |
2200 | for (; *s && (*s != ' ') && (*s != '\n'); s++) { | |
2201 | if (!isxdigit(*s)) | |
2202 | return 0; | |
2203 | } | |
2204 | } else { | |
2205 | if (*s == '-') | |
2206 | s++; | |
2207 | for (; *s && (*s != ' ') && (*s != '\n'); s++) { | |
2208 | if (!isdigit(*s)) | |
2209 | return 0; | |
2210 | } | |
2211 | } | |
2212 | return (int) (s-b); | |
2213 | } | |
2214 | ||
2215 | /* | |
2216 | * parse hwreg input data. | |
2217 | * update global hwreg_cfg only if input data syntax is ok. | |
2218 | */ | |
2219 | static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg, | |
2220 | struct device *dev) | |
2221 | { | |
2222 | uint write, val = 0; | |
2223 | u8 regvalue; | |
2224 | int ret; | |
2225 | struct hwreg_cfg loc = { | |
2226 | .bank = 0, /* default: invalid phys addr */ | |
2227 | .addr = 0, /* default: invalid phys addr */ | |
2228 | .fmt = 0, /* default: 32bit access, hex output */ | |
2229 | .mask = 0xFFFFFFFF, /* default: no mask */ | |
2230 | .shift = 0, /* default: no bit shift */ | |
2231 | }; | |
2232 | ||
2233 | /* read or write ? */ | |
2234 | if (!strncmp(b, "read ", 5)) { | |
2235 | write = 0; | |
2236 | b += 5; | |
2237 | } else if (!strncmp(b, "write ", 6)) { | |
2238 | write = 1; | |
2239 | b += 6; | |
2240 | } else | |
2241 | return -EINVAL; | |
2242 | ||
2243 | /* OPTIONS -l|-w|-b -s -m -o */ | |
2244 | while ((*b == ' ') || (*b == '-')) { | |
2245 | if (*(b-1) != ' ') { | |
2246 | b++; | |
2247 | continue; | |
2248 | } | |
2249 | if ((!strncmp(b, "-d ", 3)) || | |
2250 | (!strncmp(b, "-dec ", 5))) { | |
2251 | b += (*(b+2) == ' ') ? 3 : 5; | |
2252 | loc.fmt |= (1<<0); | |
2253 | } else if ((!strncmp(b, "-h ", 3)) || | |
2254 | (!strncmp(b, "-hex ", 5))) { | |
2255 | b += (*(b+2) == ' ') ? 3 : 5; | |
2256 | loc.fmt &= ~(1<<0); | |
2257 | } else if ((!strncmp(b, "-m ", 3)) || | |
2258 | (!strncmp(b, "-mask ", 6))) { | |
2259 | b += (*(b+2) == ' ') ? 3 : 6; | |
2260 | if (strval_len(b) == 0) | |
2261 | return -EINVAL; | |
2262 | loc.mask = simple_strtoul(b, &b, 0); | |
2263 | } else if ((!strncmp(b, "-s ", 3)) || | |
2264 | (!strncmp(b, "-shift ", 7))) { | |
2265 | b += (*(b+2) == ' ') ? 3 : 7; | |
2266 | if (strval_len(b) == 0) | |
2267 | return -EINVAL; | |
2268 | loc.shift = simple_strtol(b, &b, 0); | |
2269 | } else { | |
2270 | return -EINVAL; | |
2271 | } | |
2272 | } | |
2273 | /* get arg BANK and ADDRESS */ | |
2274 | if (strval_len(b) == 0) | |
2275 | return -EINVAL; | |
2276 | loc.bank = simple_strtoul(b, &b, 0); | |
2277 | while (*b == ' ') | |
2278 | b++; | |
2279 | if (strval_len(b) == 0) | |
2280 | return -EINVAL; | |
2281 | loc.addr = simple_strtoul(b, &b, 0); | |
2282 | ||
2283 | if (write) { | |
2284 | while (*b == ' ') | |
2285 | b++; | |
2286 | if (strval_len(b) == 0) | |
2287 | return -EINVAL; | |
2288 | val = simple_strtoul(b, &b, 0); | |
2289 | } | |
2290 | ||
2291 | /* args are ok, update target cfg (mainly for read) */ | |
2292 | *cfg = loc; | |
2293 | ||
2294 | #ifdef ABB_HWREG_DEBUG | |
2295 | pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d" | |
2296 | "value=0x%X\n", (write) ? "write" : "read", | |
2297 | REG_FMT_DEC(cfg) ? "decimal" : "hexa", | |
2298 | cfg->addr, cfg->mask, cfg->shift, val); | |
2299 | #endif | |
2300 | ||
2301 | if (!write) | |
2302 | return 0; | |
2303 | ||
2304 | ret = abx500_get_register_interruptible(dev, | |
2305 | (u8)cfg->bank, (u8)cfg->addr, ®value); | |
2306 | if (ret < 0) { | |
2307 | dev_err(dev, "abx500_get_reg fail %d, %d\n", | |
2308 | ret, __LINE__); | |
2309 | return -EINVAL; | |
2310 | } | |
2311 | ||
2312 | if (cfg->shift >= 0) { | |
2313 | regvalue &= ~(cfg->mask << (cfg->shift)); | |
2314 | val = (val & cfg->mask) << (cfg->shift); | |
2315 | } else { | |
2316 | regvalue &= ~(cfg->mask >> (-cfg->shift)); | |
2317 | val = (val & cfg->mask) >> (-cfg->shift); | |
2318 | } | |
2319 | val = val | regvalue; | |
2320 | ||
2321 | ret = abx500_set_register_interruptible(dev, | |
2322 | (u8)cfg->bank, (u8)cfg->addr, (u8)val); | |
2323 | if (ret < 0) { | |
2324 | pr_err("abx500_set_reg failed %d, %d", ret, __LINE__); | |
2325 | return -EINVAL; | |
2326 | } | |
2327 | ||
2328 | return 0; | |
2329 | } | |
2330 | ||
2331 | static ssize_t ab8500_hwreg_write(struct file *file, | |
2332 | const char __user *user_buf, size_t count, loff_t *ppos) | |
2333 | { | |
2334 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
2335 | char buf[128]; | |
2336 | int buf_size, ret; | |
2337 | ||
2338 | /* Get userspace string and assure termination */ | |
2339 | buf_size = min(count, (sizeof(buf)-1)); | |
2340 | if (copy_from_user(buf, user_buf, buf_size)) | |
2341 | return -EFAULT; | |
2342 | buf[buf_size] = 0; | |
2343 | ||
2344 | /* get args and process */ | |
2345 | ret = hwreg_common_write(buf, &hwreg_cfg, dev); | |
2346 | return (ret) ? ret : buf_size; | |
2347 | } | |
2348 | ||
2349 | /* | |
2350 | * - irq subscribe/unsubscribe stuff | |
2351 | */ | |
4b8ac082 LJ |
2352 | static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p) |
2353 | { | |
2354 | seq_printf(s, "%d\n", irq_first); | |
2355 | ||
2356 | return 0; | |
2357 | } | |
2358 | ||
2359 | static int ab8500_subscribe_unsubscribe_open(struct inode *inode, | |
2360 | struct file *file) | |
2361 | { | |
2362 | return single_open(file, ab8500_subscribe_unsubscribe_print, | |
2363 | inode->i_private); | |
2364 | } | |
2365 | ||
2366 | /* | |
0b337e70 | 2367 | * Userspace should use poll() on this file. When an event occur |
4b8ac082 LJ |
2368 | * the blocking poll will be released. |
2369 | */ | |
2370 | static ssize_t show_irq(struct device *dev, | |
2371 | struct device_attribute *attr, char *buf) | |
2372 | { | |
0b337e70 MW |
2373 | unsigned long name; |
2374 | unsigned int irq_index; | |
2375 | int err; | |
4b8ac082 | 2376 | |
0b337e70 MW |
2377 | err = strict_strtoul(attr->attr.name, 0, &name); |
2378 | if (err) | |
2379 | return err; | |
2380 | ||
2381 | irq_index = name - irq_first; | |
ddba25f1 | 2382 | if (irq_index >= num_irqs) |
0b337e70 MW |
2383 | return -EINVAL; |
2384 | else | |
2385 | return sprintf(buf, "%u\n", irq_count[irq_index]); | |
2386 | } | |
4b8ac082 LJ |
2387 | |
2388 | static ssize_t ab8500_subscribe_write(struct file *file, | |
2389 | const char __user *user_buf, | |
2390 | size_t count, loff_t *ppos) | |
2391 | { | |
2392 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
2393 | char buf[32]; | |
2394 | int buf_size; | |
2395 | unsigned long user_val; | |
2396 | int err; | |
0b337e70 | 2397 | unsigned int irq_index; |
4b8ac082 LJ |
2398 | |
2399 | /* Get userspace string and assure termination */ | |
2400 | buf_size = min(count, (sizeof(buf)-1)); | |
2401 | if (copy_from_user(buf, user_buf, buf_size)) | |
2402 | return -EFAULT; | |
2403 | buf[buf_size] = 0; | |
2404 | ||
2405 | err = strict_strtoul(buf, 0, &user_val); | |
2406 | if (err) | |
2407 | return -EINVAL; | |
2408 | if (user_val < irq_first) { | |
2409 | dev_err(dev, "debugfs error input < %d\n", irq_first); | |
2410 | return -EINVAL; | |
2411 | } | |
2412 | if (user_val > irq_last) { | |
2413 | dev_err(dev, "debugfs error input > %d\n", irq_last); | |
2414 | return -EINVAL; | |
2415 | } | |
2416 | ||
0b337e70 | 2417 | irq_index = user_val - irq_first; |
ddba25f1 | 2418 | if (irq_index >= num_irqs) |
0b337e70 MW |
2419 | return -EINVAL; |
2420 | ||
4b8ac082 | 2421 | /* |
0b337e70 | 2422 | * This will create a sysfs file named <irq-nr> which userspace can |
4b8ac082 LJ |
2423 | * use to select or poll and get the AB8500 events |
2424 | */ | |
0b337e70 MW |
2425 | dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), |
2426 | GFP_KERNEL); | |
2427 | event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); | |
2428 | sprintf(event_name[irq_index], "%lu", user_val); | |
2429 | dev_attr[irq_index]->show = show_irq; | |
2430 | dev_attr[irq_index]->store = NULL; | |
2431 | dev_attr[irq_index]->attr.name = event_name[irq_index]; | |
2432 | dev_attr[irq_index]->attr.mode = S_IRUGO; | |
2433 | err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr); | |
4b8ac082 LJ |
2434 | if (err < 0) { |
2435 | printk(KERN_ERR "sysfs_create_file failed %d\n", err); | |
2436 | return err; | |
2437 | } | |
2438 | ||
2439 | err = request_threaded_irq(user_val, NULL, ab8500_debug_handler, | |
2440 | IRQF_SHARED | IRQF_NO_SUSPEND, | |
2441 | "ab8500-debug", &dev->kobj); | |
2442 | if (err < 0) { | |
2443 | printk(KERN_ERR "request_threaded_irq failed %d, %lu\n", | |
2444 | err, user_val); | |
0b337e70 | 2445 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); |
4b8ac082 LJ |
2446 | return err; |
2447 | } | |
2448 | ||
2449 | return buf_size; | |
2450 | } | |
2451 | ||
2452 | static ssize_t ab8500_unsubscribe_write(struct file *file, | |
2453 | const char __user *user_buf, | |
2454 | size_t count, loff_t *ppos) | |
2455 | { | |
2456 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
2457 | char buf[32]; | |
2458 | int buf_size; | |
2459 | unsigned long user_val; | |
2460 | int err; | |
0b337e70 | 2461 | unsigned int irq_index; |
4b8ac082 LJ |
2462 | |
2463 | /* Get userspace string and assure termination */ | |
2464 | buf_size = min(count, (sizeof(buf)-1)); | |
2465 | if (copy_from_user(buf, user_buf, buf_size)) | |
2466 | return -EFAULT; | |
2467 | buf[buf_size] = 0; | |
2468 | ||
2469 | err = strict_strtoul(buf, 0, &user_val); | |
2470 | if (err) | |
2471 | return -EINVAL; | |
2472 | if (user_val < irq_first) { | |
2473 | dev_err(dev, "debugfs error input < %d\n", irq_first); | |
2474 | return -EINVAL; | |
2475 | } | |
2476 | if (user_val > irq_last) { | |
2477 | dev_err(dev, "debugfs error input > %d\n", irq_last); | |
2478 | return -EINVAL; | |
2479 | } | |
2480 | ||
0b337e70 | 2481 | irq_index = user_val - irq_first; |
ddba25f1 | 2482 | if (irq_index >= num_irqs) |
0b337e70 MW |
2483 | return -EINVAL; |
2484 | ||
2485 | /* Set irq count to 0 when unsubscribe */ | |
2486 | irq_count[irq_index] = 0; | |
2487 | ||
2488 | if (dev_attr[irq_index]) | |
2489 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); | |
4b8ac082 | 2490 | |
0b337e70 MW |
2491 | |
2492 | free_irq(user_val, &dev->kobj); | |
2493 | kfree(event_name[irq_index]); | |
2494 | kfree(dev_attr[irq_index]); | |
4b8ac082 LJ |
2495 | |
2496 | return buf_size; | |
2497 | } | |
2498 | ||
0fbce76e | 2499 | /* |
2500 | * - several deubgfs nodes fops | |
2501 | */ | |
2502 | ||
5814fc35 | 2503 | static const struct file_operations ab8500_bank_fops = { |
d7b9f322 MW |
2504 | .open = ab8500_bank_open, |
2505 | .write = ab8500_bank_write, | |
2506 | .read = seq_read, | |
2507 | .llseek = seq_lseek, | |
2508 | .release = single_release, | |
2509 | .owner = THIS_MODULE, | |
5814fc35 MW |
2510 | }; |
2511 | ||
2512 | static const struct file_operations ab8500_address_fops = { | |
d7b9f322 MW |
2513 | .open = ab8500_address_open, |
2514 | .write = ab8500_address_write, | |
2515 | .read = seq_read, | |
2516 | .llseek = seq_lseek, | |
2517 | .release = single_release, | |
2518 | .owner = THIS_MODULE, | |
5814fc35 MW |
2519 | }; |
2520 | ||
2521 | static const struct file_operations ab8500_val_fops = { | |
d7b9f322 MW |
2522 | .open = ab8500_val_open, |
2523 | .write = ab8500_val_write, | |
2524 | .read = seq_read, | |
2525 | .llseek = seq_lseek, | |
2526 | .release = single_release, | |
2527 | .owner = THIS_MODULE, | |
5814fc35 MW |
2528 | }; |
2529 | ||
8f0eb43b BJ |
2530 | static const struct file_operations ab8500_interrupts_fops = { |
2531 | .open = ab8500_interrupts_open, | |
2532 | .read = seq_read, | |
2533 | .llseek = seq_lseek, | |
2534 | .release = single_release, | |
2535 | .owner = THIS_MODULE, | |
2536 | }; | |
2537 | ||
4b8ac082 LJ |
2538 | static const struct file_operations ab8500_subscribe_fops = { |
2539 | .open = ab8500_subscribe_unsubscribe_open, | |
2540 | .write = ab8500_subscribe_write, | |
2541 | .read = seq_read, | |
2542 | .llseek = seq_lseek, | |
2543 | .release = single_release, | |
2544 | .owner = THIS_MODULE, | |
2545 | }; | |
2546 | ||
2547 | static const struct file_operations ab8500_unsubscribe_fops = { | |
2548 | .open = ab8500_subscribe_unsubscribe_open, | |
2549 | .write = ab8500_unsubscribe_write, | |
2550 | .read = seq_read, | |
2551 | .llseek = seq_lseek, | |
2552 | .release = single_release, | |
2553 | .owner = THIS_MODULE, | |
2554 | }; | |
2555 | ||
0fbce76e | 2556 | static const struct file_operations ab8500_hwreg_fops = { |
2557 | .open = ab8500_hwreg_open, | |
2558 | .write = ab8500_hwreg_write, | |
2559 | .read = seq_read, | |
2560 | .llseek = seq_lseek, | |
2561 | .release = single_release, | |
2562 | .owner = THIS_MODULE, | |
2563 | }; | |
2564 | ||
5814fc35 | 2565 | static struct dentry *ab8500_dir; |
1478a316 | 2566 | static struct dentry *ab8500_gpadc_dir; |
5814fc35 | 2567 | |
f791be49 | 2568 | static int ab8500_debug_probe(struct platform_device *plf) |
5814fc35 | 2569 | { |
0fbce76e | 2570 | struct dentry *file; |
ddba25f1 LW |
2571 | int ret = -ENOMEM; |
2572 | struct ab8500 *ab8500; | |
d7b9f322 MW |
2573 | debug_bank = AB8500_MISC; |
2574 | debug_address = AB8500_REV_REG & 0x00FF; | |
5814fc35 | 2575 | |
ddba25f1 LW |
2576 | ab8500 = dev_get_drvdata(plf->dev.parent); |
2577 | num_irqs = ab8500->mask_size; | |
2578 | ||
70bad04f | 2579 | irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL); |
ddba25f1 LW |
2580 | if (!irq_count) |
2581 | return -ENOMEM; | |
2582 | ||
2583 | dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL); | |
2584 | if (!dev_attr) | |
2585 | goto out_freeirq_count; | |
2586 | ||
2587 | event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL); | |
2588 | if (!event_name) | |
2589 | goto out_freedev_attr; | |
2590 | ||
4b8ac082 LJ |
2591 | irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); |
2592 | if (irq_first < 0) { | |
2593 | dev_err(&plf->dev, "First irq not found, err %d\n", | |
1478a316 | 2594 | irq_first); |
ddba25f1 LW |
2595 | ret = irq_first; |
2596 | goto out_freeevent_name; | |
4b8ac082 LJ |
2597 | } |
2598 | ||
2599 | irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); | |
2600 | if (irq_last < 0) { | |
2601 | dev_err(&plf->dev, "Last irq not found, err %d\n", | |
1478a316 | 2602 | irq_last); |
ddba25f1 | 2603 | ret = irq_last; |
2cf64e26 | 2604 | goto out_freeevent_name; |
4b8ac082 LJ |
2605 | } |
2606 | ||
d7b9f322 MW |
2607 | ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); |
2608 | if (!ab8500_dir) | |
0fbce76e | 2609 | goto err; |
5814fc35 | 2610 | |
1478a316 JB |
2611 | ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING, |
2612 | ab8500_dir); | |
2613 | if (!ab8500_gpadc_dir) | |
2614 | goto err; | |
2615 | ||
2616 | file = debugfs_create_file("all-bank-registers", S_IRUGO, | |
2617 | ab8500_dir, &plf->dev, &ab8500_registers_fops); | |
2618 | if (!file) | |
2619 | goto err; | |
2620 | ||
42002c6d MYK |
2621 | file = debugfs_create_file("all-banks", S_IRUGO, |
2622 | ab8500_dir, &plf->dev, &ab8500_all_banks_fops); | |
2623 | if (!file) | |
2624 | goto err; | |
2625 | ||
1478a316 JB |
2626 | file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR), |
2627 | ab8500_dir, &plf->dev, &ab8500_bank_fops); | |
2628 | if (!file) | |
2629 | goto err; | |
2630 | ||
2631 | file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR), | |
2632 | ab8500_dir, &plf->dev, &ab8500_address_fops); | |
2633 | if (!file) | |
2634 | goto err; | |
2635 | ||
2636 | file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR), | |
2637 | ab8500_dir, &plf->dev, &ab8500_val_fops); | |
2638 | if (!file) | |
2639 | goto err; | |
2640 | ||
2641 | file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR), | |
2642 | ab8500_dir, &plf->dev, &ab8500_subscribe_fops); | |
2643 | if (!file) | |
2644 | goto err; | |
2645 | ||
9581ae39 LJ |
2646 | if (is_ab8500(ab8500)) { |
2647 | debug_ranges = ab8500_debug_ranges; | |
8f0eb43b | 2648 | num_interrupt_lines = AB8500_NR_IRQS; |
9581ae39 LJ |
2649 | } else if (is_ab8505(ab8500)) { |
2650 | debug_ranges = ab8505_debug_ranges; | |
8f0eb43b | 2651 | num_interrupt_lines = AB8505_NR_IRQS; |
9581ae39 LJ |
2652 | } else if (is_ab9540(ab8500)) { |
2653 | debug_ranges = ab8505_debug_ranges; | |
8f0eb43b | 2654 | num_interrupt_lines = AB9540_NR_IRQS; |
9581ae39 LJ |
2655 | } else if (is_ab8540(ab8500)) { |
2656 | debug_ranges = ab8505_debug_ranges; | |
e436ddff | 2657 | num_interrupt_lines = AB8540_NR_IRQS; |
9581ae39 | 2658 | } |
8f0eb43b BJ |
2659 | |
2660 | file = debugfs_create_file("interrupts", (S_IRUGO), | |
2661 | ab8500_dir, &plf->dev, &ab8500_interrupts_fops); | |
2662 | if (!file) | |
2663 | goto err; | |
2664 | ||
1478a316 JB |
2665 | file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR), |
2666 | ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops); | |
2667 | if (!file) | |
2668 | goto err; | |
2669 | ||
2670 | file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR), | |
2671 | ab8500_dir, &plf->dev, &ab8500_hwreg_fops); | |
2672 | if (!file) | |
2673 | goto err; | |
2674 | ||
c7ebaee2 LJ |
2675 | file = debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUGO), |
2676 | ab8500_dir, &plf->dev, &ab8500_modem_fops); | |
2677 | if (!file) | |
2678 | goto err; | |
2679 | ||
1478a316 JB |
2680 | file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR), |
2681 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops); | |
2682 | if (!file) | |
2683 | goto err; | |
2684 | ||
2685 | file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR), | |
2686 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops); | |
2687 | if (!file) | |
2688 | goto err; | |
2689 | ||
2690 | file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR), | |
2691 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops); | |
2692 | if (!file) | |
2693 | goto err; | |
2694 | ||
2695 | file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR), | |
2696 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops); | |
2697 | if (!file) | |
2698 | goto err; | |
2699 | ||
2700 | file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR), | |
2701 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops); | |
2702 | if (!file) | |
2703 | goto err; | |
2704 | ||
2705 | file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR), | |
2706 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops); | |
2707 | if (!file) | |
2708 | goto err; | |
2709 | ||
2710 | file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR), | |
2711 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops); | |
0fbce76e | 2712 | if (!file) |
2713 | goto err; | |
5814fc35 | 2714 | |
1478a316 JB |
2715 | file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR), |
2716 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops); | |
0fbce76e | 2717 | if (!file) |
2718 | goto err; | |
5814fc35 | 2719 | |
1478a316 JB |
2720 | file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR), |
2721 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops); | |
0fbce76e | 2722 | if (!file) |
2723 | goto err; | |
5814fc35 | 2724 | |
1478a316 JB |
2725 | file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR), |
2726 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops); | |
0fbce76e | 2727 | if (!file) |
2728 | goto err; | |
2729 | ||
1478a316 JB |
2730 | file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR), |
2731 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops); | |
0fbce76e | 2732 | if (!file) |
2733 | goto err; | |
2734 | ||
1478a316 JB |
2735 | file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR), |
2736 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops); | |
0fbce76e | 2737 | if (!file) |
2738 | goto err; | |
2739 | ||
1478a316 JB |
2740 | file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR), |
2741 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops); | |
0fbce76e | 2742 | if (!file) |
2743 | goto err; | |
127629d7 LJ |
2744 | |
2745 | file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUGO), | |
2746 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_id_fops); | |
2747 | if (!file) | |
2748 | goto err; | |
2749 | ||
bc6b4132 LJ |
2750 | if (is_ab8540(ab8500)) { |
2751 | file = debugfs_create_file("xtal_temp", (S_IRUGO | S_IWUGO), | |
2752 | ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_xtal_temp_fops); | |
2753 | if (!file) | |
2754 | goto err; | |
2755 | file = debugfs_create_file("vbattruemeas", (S_IRUGO | S_IWUGO), | |
2756 | ab8500_gpadc_dir, &plf->dev, | |
2757 | &ab8540_gpadc_vbat_true_meas_fops); | |
2758 | if (!file) | |
2759 | goto err; | |
2760 | file = debugfs_create_file("batctrl_and_ibat", | |
2761 | (S_IRUGO | S_IWUGO), ab8500_gpadc_dir, | |
2762 | &plf->dev, &ab8540_gpadc_bat_ctrl_and_ibat_fops); | |
2763 | if (!file) | |
2764 | goto err; | |
2765 | file = debugfs_create_file("vbatmeas_and_ibat", | |
2766 | (S_IRUGO | S_IWUGO), ab8500_gpadc_dir, | |
2767 | &plf->dev, | |
2768 | &ab8540_gpadc_vbat_meas_and_ibat_fops); | |
2769 | if (!file) | |
2770 | goto err; | |
2771 | file = debugfs_create_file("vbattruemeas_and_ibat", | |
2772 | (S_IRUGO | S_IWUGO), ab8500_gpadc_dir, | |
2773 | &plf->dev, | |
2774 | &ab8540_gpadc_vbat_true_meas_and_ibat_fops); | |
2775 | if (!file) | |
2776 | goto err; | |
2777 | file = debugfs_create_file("battemp_and_ibat", | |
2778 | (S_IRUGO | S_IWUGO), ab8500_gpadc_dir, | |
2779 | &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops); | |
2780 | if (!file) | |
2781 | goto err; | |
2782 | file = debugfs_create_file("otp_calib", (S_IRUGO | S_IWUGO), | |
2783 | ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_otp_calib_fops); | |
2784 | if (!file) | |
2785 | goto err; | |
2786 | } | |
73482346 LJ |
2787 | file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUGO), |
2788 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops); | |
2789 | if (!file) | |
2790 | goto err; | |
2791 | ||
2792 | file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUGO), | |
2793 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops); | |
2794 | if (!file) | |
2795 | goto err; | |
2796 | ||
2797 | file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUGO), | |
2798 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops); | |
2799 | if (!file) | |
2800 | goto err; | |
2801 | ||
2802 | file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUGO), | |
2803 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops); | |
2804 | if (!file) | |
2805 | goto err; | |
4b8ac082 | 2806 | |
d7b9f322 | 2807 | return 0; |
5814fc35 | 2808 | |
0fbce76e | 2809 | err: |
2810 | if (ab8500_dir) | |
2811 | debugfs_remove_recursive(ab8500_dir); | |
d7b9f322 | 2812 | dev_err(&plf->dev, "failed to create debugfs entries.\n"); |
ddba25f1 LW |
2813 | out_freeevent_name: |
2814 | kfree(event_name); | |
2815 | out_freedev_attr: | |
2816 | kfree(dev_attr); | |
2817 | out_freeirq_count: | |
2818 | kfree(irq_count); | |
2819 | ||
2820 | return ret; | |
5814fc35 MW |
2821 | } |
2822 | ||
4740f73f | 2823 | static int ab8500_debug_remove(struct platform_device *plf) |
5814fc35 | 2824 | { |
0fbce76e | 2825 | debugfs_remove_recursive(ab8500_dir); |
ddba25f1 LW |
2826 | kfree(event_name); |
2827 | kfree(dev_attr); | |
2828 | kfree(irq_count); | |
2829 | ||
d7b9f322 | 2830 | return 0; |
5814fc35 MW |
2831 | } |
2832 | ||
2833 | static struct platform_driver ab8500_debug_driver = { | |
d7b9f322 MW |
2834 | .driver = { |
2835 | .name = "ab8500-debug", | |
2836 | .owner = THIS_MODULE, | |
2837 | }, | |
2838 | .probe = ab8500_debug_probe, | |
84449216 | 2839 | .remove = ab8500_debug_remove |
5814fc35 MW |
2840 | }; |
2841 | ||
2842 | static int __init ab8500_debug_init(void) | |
2843 | { | |
d7b9f322 | 2844 | return platform_driver_register(&ab8500_debug_driver); |
5814fc35 MW |
2845 | } |
2846 | ||
2847 | static void __exit ab8500_debug_exit(void) | |
2848 | { | |
d7b9f322 | 2849 | platform_driver_unregister(&ab8500_debug_driver); |
5814fc35 MW |
2850 | } |
2851 | subsys_initcall(ab8500_debug_init); | |
2852 | module_exit(ab8500_debug_exit); | |
2853 | ||
2854 | MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com"); | |
2855 | MODULE_DESCRIPTION("AB8500 DEBUG"); | |
2856 | MODULE_LICENSE("GPL v2"); |