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 | */ | |
7 | ||
8 | #include <linux/seq_file.h> | |
9 | #include <linux/uaccess.h> | |
10 | #include <linux/fs.h> | |
4e36dd33 | 11 | #include <linux/module.h> |
5814fc35 MW |
12 | #include <linux/debugfs.h> |
13 | #include <linux/platform_device.h> | |
4b8ac082 LJ |
14 | #include <linux/interrupt.h> |
15 | #include <linux/kobject.h> | |
16 | #include <linux/slab.h> | |
5814fc35 MW |
17 | |
18 | #include <linux/mfd/abx500.h> | |
ee66e653 | 19 | #include <linux/mfd/abx500/ab8500.h> |
5814fc35 MW |
20 | |
21 | static u32 debug_bank; | |
22 | static u32 debug_address; | |
23 | ||
4b8ac082 LJ |
24 | static int irq_first; |
25 | static int irq_last; | |
26 | ||
5814fc35 MW |
27 | /** |
28 | * struct ab8500_reg_range | |
29 | * @first: the first address of the range | |
30 | * @last: the last address of the range | |
31 | * @perm: access permissions for the range | |
32 | */ | |
33 | struct ab8500_reg_range { | |
d7b9f322 MW |
34 | u8 first; |
35 | u8 last; | |
36 | u8 perm; | |
5814fc35 MW |
37 | }; |
38 | ||
39 | /** | |
822672a7 | 40 | * struct ab8500_prcmu_ranges |
5814fc35 MW |
41 | * @num_ranges: the number of ranges in the list |
42 | * @bankid: bank identifier | |
43 | * @range: the list of register ranges | |
44 | */ | |
822672a7 | 45 | struct ab8500_prcmu_ranges { |
d7b9f322 MW |
46 | u8 num_ranges; |
47 | u8 bankid; | |
48 | const struct ab8500_reg_range *range; | |
5814fc35 MW |
49 | }; |
50 | ||
51 | #define AB8500_NAME_STRING "ab8500" | |
52 | #define AB8500_NUM_BANKS 22 | |
53 | ||
54 | #define AB8500_REV_REG 0x80 | |
55 | ||
822672a7 | 56 | static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = { |
d7b9f322 MW |
57 | [0x0] = { |
58 | .num_ranges = 0, | |
59 | .range = 0, | |
60 | }, | |
61 | [AB8500_SYS_CTRL1_BLOCK] = { | |
62 | .num_ranges = 3, | |
63 | .range = (struct ab8500_reg_range[]) { | |
64 | { | |
65 | .first = 0x00, | |
66 | .last = 0x02, | |
67 | }, | |
68 | { | |
69 | .first = 0x42, | |
70 | .last = 0x42, | |
71 | }, | |
72 | { | |
73 | .first = 0x80, | |
74 | .last = 0x81, | |
75 | }, | |
76 | }, | |
77 | }, | |
78 | [AB8500_SYS_CTRL2_BLOCK] = { | |
79 | .num_ranges = 4, | |
80 | .range = (struct ab8500_reg_range[]) { | |
81 | { | |
82 | .first = 0x00, | |
83 | .last = 0x0D, | |
84 | }, | |
85 | { | |
86 | .first = 0x0F, | |
87 | .last = 0x17, | |
88 | }, | |
89 | { | |
90 | .first = 0x30, | |
91 | .last = 0x30, | |
92 | }, | |
93 | { | |
94 | .first = 0x32, | |
95 | .last = 0x33, | |
96 | }, | |
97 | }, | |
98 | }, | |
99 | [AB8500_REGU_CTRL1] = { | |
100 | .num_ranges = 3, | |
101 | .range = (struct ab8500_reg_range[]) { | |
102 | { | |
103 | .first = 0x00, | |
104 | .last = 0x00, | |
105 | }, | |
106 | { | |
107 | .first = 0x03, | |
108 | .last = 0x10, | |
109 | }, | |
110 | { | |
111 | .first = 0x80, | |
112 | .last = 0x84, | |
113 | }, | |
114 | }, | |
115 | }, | |
116 | [AB8500_REGU_CTRL2] = { | |
117 | .num_ranges = 5, | |
118 | .range = (struct ab8500_reg_range[]) { | |
119 | { | |
120 | .first = 0x00, | |
121 | .last = 0x15, | |
122 | }, | |
123 | { | |
124 | .first = 0x17, | |
125 | .last = 0x19, | |
126 | }, | |
127 | { | |
128 | .first = 0x1B, | |
129 | .last = 0x1D, | |
130 | }, | |
131 | { | |
132 | .first = 0x1F, | |
133 | .last = 0x22, | |
134 | }, | |
135 | { | |
136 | .first = 0x40, | |
137 | .last = 0x44, | |
138 | }, | |
139 | /* 0x80-0x8B is SIM registers and should | |
140 | * not be accessed from here */ | |
141 | }, | |
142 | }, | |
143 | [AB8500_USB] = { | |
144 | .num_ranges = 2, | |
145 | .range = (struct ab8500_reg_range[]) { | |
146 | { | |
147 | .first = 0x80, | |
148 | .last = 0x83, | |
149 | }, | |
150 | { | |
151 | .first = 0x87, | |
152 | .last = 0x8A, | |
153 | }, | |
154 | }, | |
155 | }, | |
156 | [AB8500_TVOUT] = { | |
157 | .num_ranges = 9, | |
158 | .range = (struct ab8500_reg_range[]) { | |
159 | { | |
160 | .first = 0x00, | |
161 | .last = 0x12, | |
162 | }, | |
163 | { | |
164 | .first = 0x15, | |
165 | .last = 0x17, | |
166 | }, | |
167 | { | |
168 | .first = 0x19, | |
169 | .last = 0x21, | |
170 | }, | |
171 | { | |
172 | .first = 0x27, | |
173 | .last = 0x2C, | |
174 | }, | |
175 | { | |
176 | .first = 0x41, | |
177 | .last = 0x41, | |
178 | }, | |
179 | { | |
180 | .first = 0x45, | |
181 | .last = 0x5B, | |
182 | }, | |
183 | { | |
184 | .first = 0x5D, | |
185 | .last = 0x5D, | |
186 | }, | |
187 | { | |
188 | .first = 0x69, | |
189 | .last = 0x69, | |
190 | }, | |
191 | { | |
192 | .first = 0x80, | |
193 | .last = 0x81, | |
194 | }, | |
195 | }, | |
196 | }, | |
197 | [AB8500_DBI] = { | |
198 | .num_ranges = 0, | |
87fff232 | 199 | .range = NULL, |
d7b9f322 MW |
200 | }, |
201 | [AB8500_ECI_AV_ACC] = { | |
202 | .num_ranges = 1, | |
203 | .range = (struct ab8500_reg_range[]) { | |
204 | { | |
205 | .first = 0x80, | |
206 | .last = 0x82, | |
207 | }, | |
208 | }, | |
209 | }, | |
210 | [0x9] = { | |
211 | .num_ranges = 0, | |
87fff232 | 212 | .range = NULL, |
d7b9f322 MW |
213 | }, |
214 | [AB8500_GPADC] = { | |
215 | .num_ranges = 1, | |
216 | .range = (struct ab8500_reg_range[]) { | |
217 | { | |
218 | .first = 0x00, | |
219 | .last = 0x08, | |
220 | }, | |
221 | }, | |
222 | }, | |
223 | [AB8500_CHARGER] = { | |
224 | .num_ranges = 8, | |
225 | .range = (struct ab8500_reg_range[]) { | |
226 | { | |
227 | .first = 0x00, | |
228 | .last = 0x03, | |
229 | }, | |
230 | { | |
231 | .first = 0x05, | |
232 | .last = 0x05, | |
233 | }, | |
234 | { | |
235 | .first = 0x40, | |
236 | .last = 0x40, | |
237 | }, | |
238 | { | |
239 | .first = 0x42, | |
240 | .last = 0x42, | |
241 | }, | |
242 | { | |
243 | .first = 0x44, | |
244 | .last = 0x44, | |
245 | }, | |
246 | { | |
247 | .first = 0x50, | |
248 | .last = 0x55, | |
249 | }, | |
250 | { | |
251 | .first = 0x80, | |
252 | .last = 0x82, | |
253 | }, | |
254 | { | |
255 | .first = 0xC0, | |
256 | .last = 0xC2, | |
257 | }, | |
258 | }, | |
259 | }, | |
260 | [AB8500_GAS_GAUGE] = { | |
261 | .num_ranges = 3, | |
262 | .range = (struct ab8500_reg_range[]) { | |
263 | { | |
264 | .first = 0x00, | |
265 | .last = 0x00, | |
266 | }, | |
267 | { | |
268 | .first = 0x07, | |
269 | .last = 0x0A, | |
270 | }, | |
271 | { | |
272 | .first = 0x10, | |
273 | .last = 0x14, | |
274 | }, | |
275 | }, | |
276 | }, | |
277 | [AB8500_AUDIO] = { | |
278 | .num_ranges = 1, | |
279 | .range = (struct ab8500_reg_range[]) { | |
280 | { | |
281 | .first = 0x00, | |
282 | .last = 0x6F, | |
283 | }, | |
284 | }, | |
285 | }, | |
286 | [AB8500_INTERRUPT] = { | |
287 | .num_ranges = 0, | |
87fff232 | 288 | .range = NULL, |
d7b9f322 MW |
289 | }, |
290 | [AB8500_RTC] = { | |
291 | .num_ranges = 1, | |
292 | .range = (struct ab8500_reg_range[]) { | |
293 | { | |
294 | .first = 0x00, | |
295 | .last = 0x0F, | |
296 | }, | |
297 | }, | |
298 | }, | |
299 | [AB8500_MISC] = { | |
300 | .num_ranges = 8, | |
301 | .range = (struct ab8500_reg_range[]) { | |
302 | { | |
303 | .first = 0x00, | |
304 | .last = 0x05, | |
305 | }, | |
306 | { | |
307 | .first = 0x10, | |
308 | .last = 0x15, | |
309 | }, | |
310 | { | |
311 | .first = 0x20, | |
312 | .last = 0x25, | |
313 | }, | |
314 | { | |
315 | .first = 0x30, | |
316 | .last = 0x35, | |
317 | }, | |
318 | { | |
319 | .first = 0x40, | |
320 | .last = 0x45, | |
321 | }, | |
322 | { | |
323 | .first = 0x50, | |
324 | .last = 0x50, | |
325 | }, | |
326 | { | |
327 | .first = 0x60, | |
328 | .last = 0x67, | |
329 | }, | |
330 | { | |
331 | .first = 0x80, | |
332 | .last = 0x80, | |
333 | }, | |
334 | }, | |
335 | }, | |
336 | [0x11] = { | |
337 | .num_ranges = 0, | |
87fff232 | 338 | .range = NULL, |
d7b9f322 MW |
339 | }, |
340 | [0x12] = { | |
341 | .num_ranges = 0, | |
87fff232 | 342 | .range = NULL, |
d7b9f322 MW |
343 | }, |
344 | [0x13] = { | |
345 | .num_ranges = 0, | |
87fff232 | 346 | .range = NULL, |
d7b9f322 MW |
347 | }, |
348 | [0x14] = { | |
349 | .num_ranges = 0, | |
87fff232 | 350 | .range = NULL, |
d7b9f322 MW |
351 | }, |
352 | [AB8500_OTP_EMUL] = { | |
353 | .num_ranges = 1, | |
354 | .range = (struct ab8500_reg_range[]) { | |
355 | { | |
356 | .first = 0x01, | |
357 | .last = 0x0F, | |
358 | }, | |
359 | }, | |
360 | }, | |
5814fc35 MW |
361 | }; |
362 | ||
4b8ac082 LJ |
363 | static irqreturn_t ab8500_debug_handler(int irq, void *data) |
364 | { | |
365 | char buf[16]; | |
366 | struct kobject *kobj = (struct kobject *)data; | |
367 | ||
368 | /* | |
369 | * This makes it possible to use poll for events (POLLPRI | POLLERR) | |
370 | * from userspace on sysfs file named irq-<nr> | |
371 | */ | |
372 | sprintf(buf, "irq-%d", irq); | |
373 | sysfs_notify(kobj, NULL, buf); | |
374 | ||
375 | return IRQ_HANDLED; | |
376 | } | |
377 | ||
5814fc35 MW |
378 | static int ab8500_registers_print(struct seq_file *s, void *p) |
379 | { | |
d7b9f322 MW |
380 | struct device *dev = s->private; |
381 | unsigned int i; | |
382 | u32 bank = debug_bank; | |
383 | ||
384 | seq_printf(s, AB8500_NAME_STRING " register values:\n"); | |
385 | ||
386 | seq_printf(s, " bank %u:\n", bank); | |
387 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { | |
388 | u32 reg; | |
389 | ||
390 | for (reg = debug_ranges[bank].range[i].first; | |
391 | reg <= debug_ranges[bank].range[i].last; | |
392 | reg++) { | |
393 | u8 value; | |
394 | int err; | |
395 | ||
396 | err = abx500_get_register_interruptible(dev, | |
397 | (u8)bank, (u8)reg, &value); | |
398 | if (err < 0) { | |
399 | dev_err(dev, "ab->read fail %d\n", err); | |
400 | return err; | |
401 | } | |
402 | ||
403 | err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank, | |
404 | reg, value); | |
405 | if (err < 0) { | |
406 | dev_err(dev, "seq_printf overflow\n"); | |
407 | /* Error is not returned here since | |
408 | * the output is wanted in any case */ | |
409 | return 0; | |
410 | } | |
411 | } | |
412 | } | |
413 | return 0; | |
5814fc35 MW |
414 | } |
415 | ||
416 | static int ab8500_registers_open(struct inode *inode, struct file *file) | |
417 | { | |
d7b9f322 | 418 | return single_open(file, ab8500_registers_print, inode->i_private); |
5814fc35 MW |
419 | } |
420 | ||
421 | static const struct file_operations ab8500_registers_fops = { | |
d7b9f322 MW |
422 | .open = ab8500_registers_open, |
423 | .read = seq_read, | |
424 | .llseek = seq_lseek, | |
425 | .release = single_release, | |
426 | .owner = THIS_MODULE, | |
5814fc35 MW |
427 | }; |
428 | ||
429 | static int ab8500_bank_print(struct seq_file *s, void *p) | |
430 | { | |
d7b9f322 | 431 | return seq_printf(s, "%d\n", debug_bank); |
5814fc35 MW |
432 | } |
433 | ||
434 | static int ab8500_bank_open(struct inode *inode, struct file *file) | |
435 | { | |
d7b9f322 | 436 | return single_open(file, ab8500_bank_print, inode->i_private); |
5814fc35 MW |
437 | } |
438 | ||
439 | static ssize_t ab8500_bank_write(struct file *file, | |
d7b9f322 MW |
440 | const char __user *user_buf, |
441 | size_t count, loff_t *ppos) | |
5814fc35 | 442 | { |
d7b9f322 | 443 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
d7b9f322 MW |
444 | unsigned long user_bank; |
445 | int err; | |
446 | ||
447 | /* Get userspace string and assure termination */ | |
8504d638 | 448 | err = kstrtoul_from_user(user_buf, count, 0, &user_bank); |
d7b9f322 | 449 | if (err) |
8504d638 | 450 | return err; |
d7b9f322 MW |
451 | |
452 | if (user_bank >= AB8500_NUM_BANKS) { | |
453 | dev_err(dev, "debugfs error input > number of banks\n"); | |
454 | return -EINVAL; | |
455 | } | |
456 | ||
457 | debug_bank = user_bank; | |
458 | ||
8504d638 | 459 | return count; |
5814fc35 MW |
460 | } |
461 | ||
462 | static int ab8500_address_print(struct seq_file *s, void *p) | |
463 | { | |
d7b9f322 | 464 | return seq_printf(s, "0x%02X\n", debug_address); |
5814fc35 MW |
465 | } |
466 | ||
467 | static int ab8500_address_open(struct inode *inode, struct file *file) | |
468 | { | |
d7b9f322 | 469 | return single_open(file, ab8500_address_print, inode->i_private); |
5814fc35 MW |
470 | } |
471 | ||
472 | static ssize_t ab8500_address_write(struct file *file, | |
d7b9f322 MW |
473 | const char __user *user_buf, |
474 | size_t count, loff_t *ppos) | |
5814fc35 | 475 | { |
d7b9f322 | 476 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
d7b9f322 MW |
477 | unsigned long user_address; |
478 | int err; | |
479 | ||
480 | /* Get userspace string and assure termination */ | |
8504d638 | 481 | err = kstrtoul_from_user(user_buf, count, 0, &user_address); |
d7b9f322 | 482 | if (err) |
8504d638 PH |
483 | return err; |
484 | ||
d7b9f322 MW |
485 | if (user_address > 0xff) { |
486 | dev_err(dev, "debugfs error input > 0xff\n"); | |
487 | return -EINVAL; | |
488 | } | |
489 | debug_address = user_address; | |
8504d638 | 490 | return count; |
5814fc35 MW |
491 | } |
492 | ||
493 | static int ab8500_val_print(struct seq_file *s, void *p) | |
494 | { | |
d7b9f322 MW |
495 | struct device *dev = s->private; |
496 | int ret; | |
497 | u8 regvalue; | |
498 | ||
499 | ret = abx500_get_register_interruptible(dev, | |
500 | (u8)debug_bank, (u8)debug_address, ®value); | |
501 | if (ret < 0) { | |
502 | dev_err(dev, "abx500_get_reg fail %d, %d\n", | |
503 | ret, __LINE__); | |
504 | return -EINVAL; | |
505 | } | |
506 | seq_printf(s, "0x%02X\n", regvalue); | |
507 | ||
508 | return 0; | |
5814fc35 MW |
509 | } |
510 | ||
511 | static int ab8500_val_open(struct inode *inode, struct file *file) | |
512 | { | |
d7b9f322 | 513 | return single_open(file, ab8500_val_print, inode->i_private); |
5814fc35 MW |
514 | } |
515 | ||
516 | static ssize_t ab8500_val_write(struct file *file, | |
d7b9f322 MW |
517 | const char __user *user_buf, |
518 | size_t count, loff_t *ppos) | |
5814fc35 | 519 | { |
d7b9f322 | 520 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
d7b9f322 MW |
521 | unsigned long user_val; |
522 | int err; | |
523 | ||
524 | /* Get userspace string and assure termination */ | |
8504d638 | 525 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
d7b9f322 | 526 | if (err) |
8504d638 PH |
527 | return err; |
528 | ||
d7b9f322 MW |
529 | if (user_val > 0xff) { |
530 | dev_err(dev, "debugfs error input > 0xff\n"); | |
531 | return -EINVAL; | |
532 | } | |
533 | err = abx500_set_register_interruptible(dev, | |
534 | (u8)debug_bank, debug_address, (u8)user_val); | |
535 | if (err < 0) { | |
536 | printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__); | |
537 | return -EINVAL; | |
538 | } | |
539 | ||
8504d638 | 540 | return count; |
5814fc35 MW |
541 | } |
542 | ||
4b8ac082 LJ |
543 | static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p) |
544 | { | |
545 | seq_printf(s, "%d\n", irq_first); | |
546 | ||
547 | return 0; | |
548 | } | |
549 | ||
550 | static int ab8500_subscribe_unsubscribe_open(struct inode *inode, | |
551 | struct file *file) | |
552 | { | |
553 | return single_open(file, ab8500_subscribe_unsubscribe_print, | |
554 | inode->i_private); | |
555 | } | |
556 | ||
557 | /* | |
558 | * This function is used for all interrupts and will always print | |
559 | * the same string. It is however this file sysfs_notify called on. | |
560 | * Userspace should read this file and then poll. When an event occur | |
561 | * the blocking poll will be released. | |
562 | */ | |
563 | static ssize_t show_irq(struct device *dev, | |
564 | struct device_attribute *attr, char *buf) | |
565 | { | |
566 | return sprintf(buf, "irq\n"); | |
567 | } | |
568 | ||
569 | static struct device_attribute *dev_attr[AB8500_NR_IRQS]; | |
570 | static char *event_name[AB8500_NR_IRQS]; | |
571 | ||
572 | static ssize_t ab8500_subscribe_write(struct file *file, | |
573 | const char __user *user_buf, | |
574 | size_t count, loff_t *ppos) | |
575 | { | |
576 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
577 | char buf[32]; | |
578 | int buf_size; | |
579 | unsigned long user_val; | |
580 | int err; | |
581 | ||
582 | /* Get userspace string and assure termination */ | |
583 | buf_size = min(count, (sizeof(buf)-1)); | |
584 | if (copy_from_user(buf, user_buf, buf_size)) | |
585 | return -EFAULT; | |
586 | buf[buf_size] = 0; | |
587 | ||
588 | err = strict_strtoul(buf, 0, &user_val); | |
589 | if (err) | |
590 | return -EINVAL; | |
591 | if (user_val < irq_first) { | |
592 | dev_err(dev, "debugfs error input < %d\n", irq_first); | |
593 | return -EINVAL; | |
594 | } | |
595 | if (user_val > irq_last) { | |
596 | dev_err(dev, "debugfs error input > %d\n", irq_last); | |
597 | return -EINVAL; | |
598 | } | |
599 | ||
600 | /* | |
601 | * This will create a sysfs file named irq-<nr> which userspace can | |
602 | * use to select or poll and get the AB8500 events | |
603 | */ | |
604 | dev_attr[user_val] = kmalloc(sizeof(struct device_attribute), | |
605 | GFP_KERNEL); | |
606 | event_name[user_val] = kmalloc(buf_size, GFP_KERNEL); | |
607 | sprintf(event_name[user_val], "irq-%lu", user_val); | |
608 | dev_attr[user_val]->show = show_irq; | |
609 | dev_attr[user_val]->store = NULL; | |
610 | dev_attr[user_val]->attr.name = event_name[user_val]; | |
611 | dev_attr[user_val]->attr.mode = S_IRUGO; | |
612 | err = sysfs_create_file(&dev->kobj, &dev_attr[user_val]->attr); | |
613 | if (err < 0) { | |
614 | printk(KERN_ERR "sysfs_create_file failed %d\n", err); | |
615 | return err; | |
616 | } | |
617 | ||
618 | err = request_threaded_irq(user_val, NULL, ab8500_debug_handler, | |
619 | IRQF_SHARED | IRQF_NO_SUSPEND, | |
620 | "ab8500-debug", &dev->kobj); | |
621 | if (err < 0) { | |
622 | printk(KERN_ERR "request_threaded_irq failed %d, %lu\n", | |
623 | err, user_val); | |
624 | return err; | |
625 | } | |
626 | ||
627 | return buf_size; | |
628 | } | |
629 | ||
630 | static ssize_t ab8500_unsubscribe_write(struct file *file, | |
631 | const char __user *user_buf, | |
632 | size_t count, loff_t *ppos) | |
633 | { | |
634 | struct device *dev = ((struct seq_file *)(file->private_data))->private; | |
635 | char buf[32]; | |
636 | int buf_size; | |
637 | unsigned long user_val; | |
638 | int err; | |
639 | ||
640 | /* Get userspace string and assure termination */ | |
641 | buf_size = min(count, (sizeof(buf)-1)); | |
642 | if (copy_from_user(buf, user_buf, buf_size)) | |
643 | return -EFAULT; | |
644 | buf[buf_size] = 0; | |
645 | ||
646 | err = strict_strtoul(buf, 0, &user_val); | |
647 | if (err) | |
648 | return -EINVAL; | |
649 | if (user_val < irq_first) { | |
650 | dev_err(dev, "debugfs error input < %d\n", irq_first); | |
651 | return -EINVAL; | |
652 | } | |
653 | if (user_val > irq_last) { | |
654 | dev_err(dev, "debugfs error input > %d\n", irq_last); | |
655 | return -EINVAL; | |
656 | } | |
657 | ||
658 | free_irq(user_val, &dev->kobj); | |
659 | kfree(event_name[user_val]); | |
660 | kfree(dev_attr[user_val]); | |
661 | ||
662 | if (dev_attr[user_val]) | |
663 | sysfs_remove_file(&dev->kobj, &dev_attr[user_val]->attr); | |
664 | ||
665 | return buf_size; | |
666 | } | |
667 | ||
5814fc35 | 668 | static const struct file_operations ab8500_bank_fops = { |
d7b9f322 MW |
669 | .open = ab8500_bank_open, |
670 | .write = ab8500_bank_write, | |
671 | .read = seq_read, | |
672 | .llseek = seq_lseek, | |
673 | .release = single_release, | |
674 | .owner = THIS_MODULE, | |
5814fc35 MW |
675 | }; |
676 | ||
677 | static const struct file_operations ab8500_address_fops = { | |
d7b9f322 MW |
678 | .open = ab8500_address_open, |
679 | .write = ab8500_address_write, | |
680 | .read = seq_read, | |
681 | .llseek = seq_lseek, | |
682 | .release = single_release, | |
683 | .owner = THIS_MODULE, | |
5814fc35 MW |
684 | }; |
685 | ||
686 | static const struct file_operations ab8500_val_fops = { | |
d7b9f322 MW |
687 | .open = ab8500_val_open, |
688 | .write = ab8500_val_write, | |
689 | .read = seq_read, | |
690 | .llseek = seq_lseek, | |
691 | .release = single_release, | |
692 | .owner = THIS_MODULE, | |
5814fc35 MW |
693 | }; |
694 | ||
4b8ac082 LJ |
695 | static const struct file_operations ab8500_subscribe_fops = { |
696 | .open = ab8500_subscribe_unsubscribe_open, | |
697 | .write = ab8500_subscribe_write, | |
698 | .read = seq_read, | |
699 | .llseek = seq_lseek, | |
700 | .release = single_release, | |
701 | .owner = THIS_MODULE, | |
702 | }; | |
703 | ||
704 | static const struct file_operations ab8500_unsubscribe_fops = { | |
705 | .open = ab8500_subscribe_unsubscribe_open, | |
706 | .write = ab8500_unsubscribe_write, | |
707 | .read = seq_read, | |
708 | .llseek = seq_lseek, | |
709 | .release = single_release, | |
710 | .owner = THIS_MODULE, | |
711 | }; | |
712 | ||
5814fc35 MW |
713 | static struct dentry *ab8500_dir; |
714 | static struct dentry *ab8500_reg_file; | |
715 | static struct dentry *ab8500_bank_file; | |
716 | static struct dentry *ab8500_address_file; | |
717 | static struct dentry *ab8500_val_file; | |
4b8ac082 LJ |
718 | static struct dentry *ab8500_subscribe_file; |
719 | static struct dentry *ab8500_unsubscribe_file; | |
5814fc35 | 720 | |
f791be49 | 721 | static int ab8500_debug_probe(struct platform_device *plf) |
5814fc35 | 722 | { |
d7b9f322 MW |
723 | debug_bank = AB8500_MISC; |
724 | debug_address = AB8500_REV_REG & 0x00FF; | |
5814fc35 | 725 | |
4b8ac082 LJ |
726 | irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); |
727 | if (irq_first < 0) { | |
728 | dev_err(&plf->dev, "First irq not found, err %d\n", | |
729 | irq_first); | |
730 | return irq_first; | |
731 | } | |
732 | ||
733 | irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); | |
734 | if (irq_last < 0) { | |
735 | dev_err(&plf->dev, "Last irq not found, err %d\n", | |
736 | irq_last); | |
737 | return irq_last; | |
738 | } | |
739 | ||
d7b9f322 MW |
740 | ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); |
741 | if (!ab8500_dir) | |
742 | goto exit_no_debugfs; | |
5814fc35 | 743 | |
d7b9f322 MW |
744 | ab8500_reg_file = debugfs_create_file("all-bank-registers", |
745 | S_IRUGO, ab8500_dir, &plf->dev, &ab8500_registers_fops); | |
746 | if (!ab8500_reg_file) | |
747 | goto exit_destroy_dir; | |
5814fc35 | 748 | |
d7b9f322 | 749 | ab8500_bank_file = debugfs_create_file("register-bank", |
44bdcb54 | 750 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops); |
d7b9f322 MW |
751 | if (!ab8500_bank_file) |
752 | goto exit_destroy_reg; | |
5814fc35 | 753 | |
d7b9f322 | 754 | ab8500_address_file = debugfs_create_file("register-address", |
44bdcb54 | 755 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, |
d7b9f322 MW |
756 | &ab8500_address_fops); |
757 | if (!ab8500_address_file) | |
758 | goto exit_destroy_bank; | |
5814fc35 | 759 | |
d7b9f322 | 760 | ab8500_val_file = debugfs_create_file("register-value", |
44bdcb54 | 761 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops); |
d7b9f322 MW |
762 | if (!ab8500_val_file) |
763 | goto exit_destroy_address; | |
5814fc35 | 764 | |
4b8ac082 LJ |
765 | ab8500_subscribe_file = |
766 | debugfs_create_file("irq-subscribe", | |
767 | (S_IRUGO | S_IWUGO), ab8500_dir, &plf->dev, | |
768 | &ab8500_subscribe_fops); | |
769 | if (!ab8500_subscribe_file) | |
770 | goto exit_destroy_val; | |
771 | ||
772 | ab8500_unsubscribe_file = | |
773 | debugfs_create_file("irq-unsubscribe", | |
774 | (S_IRUGO | S_IWUGO), ab8500_dir, &plf->dev, | |
775 | &ab8500_unsubscribe_fops); | |
776 | if (!ab8500_unsubscribe_file) | |
777 | goto exit_destroy_subscribe; | |
778 | ||
d7b9f322 | 779 | return 0; |
5814fc35 | 780 | |
4b8ac082 LJ |
781 | exit_destroy_subscribe: |
782 | debugfs_remove(ab8500_subscribe_file); | |
783 | exit_destroy_val: | |
784 | debugfs_remove(ab8500_val_file); | |
5814fc35 | 785 | exit_destroy_address: |
d7b9f322 | 786 | debugfs_remove(ab8500_address_file); |
5814fc35 | 787 | exit_destroy_bank: |
d7b9f322 | 788 | debugfs_remove(ab8500_bank_file); |
5814fc35 | 789 | exit_destroy_reg: |
d7b9f322 | 790 | debugfs_remove(ab8500_reg_file); |
5814fc35 | 791 | exit_destroy_dir: |
d7b9f322 | 792 | debugfs_remove(ab8500_dir); |
5814fc35 | 793 | exit_no_debugfs: |
d7b9f322 MW |
794 | dev_err(&plf->dev, "failed to create debugfs entries.\n"); |
795 | return -ENOMEM; | |
5814fc35 MW |
796 | } |
797 | ||
4740f73f | 798 | static int ab8500_debug_remove(struct platform_device *plf) |
5814fc35 | 799 | { |
d7b9f322 MW |
800 | debugfs_remove(ab8500_val_file); |
801 | debugfs_remove(ab8500_address_file); | |
802 | debugfs_remove(ab8500_bank_file); | |
803 | debugfs_remove(ab8500_reg_file); | |
804 | debugfs_remove(ab8500_dir); | |
5814fc35 | 805 | |
d7b9f322 | 806 | return 0; |
5814fc35 MW |
807 | } |
808 | ||
809 | static struct platform_driver ab8500_debug_driver = { | |
d7b9f322 MW |
810 | .driver = { |
811 | .name = "ab8500-debug", | |
812 | .owner = THIS_MODULE, | |
813 | }, | |
814 | .probe = ab8500_debug_probe, | |
84449216 | 815 | .remove = ab8500_debug_remove |
5814fc35 MW |
816 | }; |
817 | ||
818 | static int __init ab8500_debug_init(void) | |
819 | { | |
d7b9f322 | 820 | return platform_driver_register(&ab8500_debug_driver); |
5814fc35 MW |
821 | } |
822 | ||
823 | static void __exit ab8500_debug_exit(void) | |
824 | { | |
d7b9f322 | 825 | platform_driver_unregister(&ab8500_debug_driver); |
5814fc35 MW |
826 | } |
827 | subsys_initcall(ab8500_debug_init); | |
828 | module_exit(ab8500_debug_exit); | |
829 | ||
830 | MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com"); | |
831 | MODULE_DESCRIPTION("AB8500 DEBUG"); | |
832 | MODULE_LICENSE("GPL v2"); |