blob: 2e40e12fc687db62b07e8bd7be7960a09d027715 [file] [log] [blame]
Mattias Wallin5814fc32010-09-13 16:05:04 +02001/*
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>
Paul Gortmaker4e36dd32011-07-03 15:13:27 -040011#include <linux/module.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020012#include <linux/debugfs.h>
13#include <linux/platform_device.h>
Lee Jones4b8ac082013-01-14 16:10:36 +000014#include <linux/interrupt.h>
15#include <linux/kobject.h>
16#include <linux/slab.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020017
18#include <linux/mfd/abx500.h>
Linus Walleijee66e652011-12-02 14:16:33 +010019#include <linux/mfd/abx500/ab8500.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020020
21static u32 debug_bank;
22static u32 debug_address;
23
Lee Jones4b8ac082013-01-14 16:10:36 +000024static int irq_first;
25static int irq_last;
26
Mattias Wallin5814fc32010-09-13 16:05:04 +020027/**
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 */
33struct ab8500_reg_range {
Mattias Wallind7b9f322010-11-26 13:06:39 +010034 u8 first;
35 u8 last;
36 u8 perm;
Mattias Wallin5814fc32010-09-13 16:05:04 +020037};
38
39/**
Lee Jones822672a2012-06-20 13:56:38 +010040 * struct ab8500_prcmu_ranges
Mattias Wallin5814fc32010-09-13 16:05:04 +020041 * @num_ranges: the number of ranges in the list
42 * @bankid: bank identifier
43 * @range: the list of register ranges
44 */
Lee Jones822672a2012-06-20 13:56:38 +010045struct ab8500_prcmu_ranges {
Mattias Wallind7b9f322010-11-26 13:06:39 +010046 u8 num_ranges;
47 u8 bankid;
48 const struct ab8500_reg_range *range;
Mattias Wallin5814fc32010-09-13 16:05:04 +020049};
50
51#define AB8500_NAME_STRING "ab8500"
52#define AB8500_NUM_BANKS 22
53
54#define AB8500_REV_REG 0x80
55
Lee Jones822672a2012-06-20 13:56:38 +010056static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
Mattias Wallind7b9f322010-11-26 13:06:39 +010057 [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,
Mark Brown87fff232010-12-13 14:06:47 +0000199 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100200 },
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,
Mark Brown87fff232010-12-13 14:06:47 +0000212 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100213 },
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,
Mark Brown87fff232010-12-13 14:06:47 +0000288 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100289 },
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,
Mark Brown87fff232010-12-13 14:06:47 +0000338 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100339 },
340 [0x12] = {
341 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000342 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100343 },
344 [0x13] = {
345 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000346 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100347 },
348 [0x14] = {
349 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000350 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100351 },
352 [AB8500_OTP_EMUL] = {
353 .num_ranges = 1,
354 .range = (struct ab8500_reg_range[]) {
355 {
356 .first = 0x01,
357 .last = 0x0F,
358 },
359 },
360 },
Mattias Wallin5814fc32010-09-13 16:05:04 +0200361};
362
Lee Jones4b8ac082013-01-14 16:10:36 +0000363static 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
Mattias Wallin5814fc32010-09-13 16:05:04 +0200378static int ab8500_registers_print(struct seq_file *s, void *p)
379{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100380 struct device *dev = s->private;
381 unsigned int i;
382 u32 bank = debug_bank;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200383
Mattias Wallind7b9f322010-11-26 13:06:39 +0100384 seq_printf(s, AB8500_NAME_STRING " register values:\n");
Mattias Wallin5814fc32010-09-13 16:05:04 +0200385
Mattias Wallind7b9f322010-11-26 13:06:39 +0100386 seq_printf(s, " bank %u:\n", bank);
387 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
388 u32 reg;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200389
Mattias Wallind7b9f322010-11-26 13:06:39 +0100390 for (reg = debug_ranges[bank].range[i].first;
391 reg <= debug_ranges[bank].range[i].last;
392 reg++) {
393 u8 value;
394 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200395
Mattias Wallind7b9f322010-11-26 13:06:39 +0100396 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 }
Mattias Wallin5814fc32010-09-13 16:05:04 +0200402
Mattias Wallind7b9f322010-11-26 13:06:39 +0100403 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;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200414}
415
416static int ab8500_registers_open(struct inode *inode, struct file *file)
417{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100418 return single_open(file, ab8500_registers_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200419}
420
421static const struct file_operations ab8500_registers_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100422 .open = ab8500_registers_open,
423 .read = seq_read,
424 .llseek = seq_lseek,
425 .release = single_release,
426 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200427};
428
429static int ab8500_bank_print(struct seq_file *s, void *p)
430{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100431 return seq_printf(s, "%d\n", debug_bank);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200432}
433
434static int ab8500_bank_open(struct inode *inode, struct file *file)
435{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100436 return single_open(file, ab8500_bank_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200437}
438
439static ssize_t ab8500_bank_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100440 const char __user *user_buf,
441 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200442{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100443 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +0100444 unsigned long user_bank;
445 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200446
Mattias Wallind7b9f322010-11-26 13:06:39 +0100447 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +0200448 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100449 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +0200450 return err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200451
Mattias Wallind7b9f322010-11-26 13:06:39 +0100452 if (user_bank >= AB8500_NUM_BANKS) {
453 dev_err(dev, "debugfs error input > number of banks\n");
454 return -EINVAL;
455 }
Mattias Wallin5814fc32010-09-13 16:05:04 +0200456
Mattias Wallind7b9f322010-11-26 13:06:39 +0100457 debug_bank = user_bank;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200458
Peter Huewe8504d632011-06-06 22:43:32 +0200459 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200460}
461
462static int ab8500_address_print(struct seq_file *s, void *p)
463{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100464 return seq_printf(s, "0x%02X\n", debug_address);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200465}
466
467static int ab8500_address_open(struct inode *inode, struct file *file)
468{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100469 return single_open(file, ab8500_address_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200470}
471
472static ssize_t ab8500_address_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100473 const char __user *user_buf,
474 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200475{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100476 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +0100477 unsigned long user_address;
478 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200479
Mattias Wallind7b9f322010-11-26 13:06:39 +0100480 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +0200481 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100482 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +0200483 return err;
484
Mattias Wallind7b9f322010-11-26 13:06:39 +0100485 if (user_address > 0xff) {
486 dev_err(dev, "debugfs error input > 0xff\n");
487 return -EINVAL;
488 }
489 debug_address = user_address;
Peter Huewe8504d632011-06-06 22:43:32 +0200490 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200491}
492
493static int ab8500_val_print(struct seq_file *s, void *p)
494{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100495 struct device *dev = s->private;
496 int ret;
497 u8 regvalue;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200498
Mattias Wallind7b9f322010-11-26 13:06:39 +0100499 ret = abx500_get_register_interruptible(dev,
500 (u8)debug_bank, (u8)debug_address, &regvalue);
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);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200507
Mattias Wallind7b9f322010-11-26 13:06:39 +0100508 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200509}
510
511static int ab8500_val_open(struct inode *inode, struct file *file)
512{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100513 return single_open(file, ab8500_val_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200514}
515
516static ssize_t ab8500_val_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100517 const char __user *user_buf,
518 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200519{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100520 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +0100521 unsigned long user_val;
522 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200523
Mattias Wallind7b9f322010-11-26 13:06:39 +0100524 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +0200525 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100526 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +0200527 return err;
528
Mattias Wallind7b9f322010-11-26 13:06:39 +0100529 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 }
Mattias Wallin5814fc32010-09-13 16:05:04 +0200539
Peter Huewe8504d632011-06-06 22:43:32 +0200540 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200541}
542
Lee Jones4b8ac082013-01-14 16:10:36 +0000543static 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
550static 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 */
563static ssize_t show_irq(struct device *dev,
564 struct device_attribute *attr, char *buf)
565{
566 return sprintf(buf, "irq\n");
567}
568
569static struct device_attribute *dev_attr[AB8500_NR_IRQS];
570static char *event_name[AB8500_NR_IRQS];
571
572static 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
630static 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
Mattias Wallin5814fc32010-09-13 16:05:04 +0200668static const struct file_operations ab8500_bank_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100669 .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,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200675};
676
677static const struct file_operations ab8500_address_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100678 .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,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200684};
685
686static const struct file_operations ab8500_val_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100687 .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,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200693};
694
Lee Jones4b8ac082013-01-14 16:10:36 +0000695static 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
704static 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
Mattias Wallin5814fc32010-09-13 16:05:04 +0200713static struct dentry *ab8500_dir;
714static struct dentry *ab8500_reg_file;
715static struct dentry *ab8500_bank_file;
716static struct dentry *ab8500_address_file;
717static struct dentry *ab8500_val_file;
Lee Jones4b8ac082013-01-14 16:10:36 +0000718static struct dentry *ab8500_subscribe_file;
719static struct dentry *ab8500_unsubscribe_file;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200720
Bill Pembertonf791be42012-11-19 13:23:04 -0500721static int ab8500_debug_probe(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200722{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100723 debug_bank = AB8500_MISC;
724 debug_address = AB8500_REV_REG & 0x00FF;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200725
Lee Jones4b8ac082013-01-14 16:10:36 +0000726 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
Mattias Wallind7b9f322010-11-26 13:06:39 +0100740 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
741 if (!ab8500_dir)
742 goto exit_no_debugfs;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200743
Mattias Wallind7b9f322010-11-26 13:06:39 +0100744 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;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200748
Mattias Wallind7b9f322010-11-26 13:06:39 +0100749 ab8500_bank_file = debugfs_create_file("register-bank",
Vasiliy Kulikov44bdcb52011-02-04 15:23:43 +0300750 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100751 if (!ab8500_bank_file)
752 goto exit_destroy_reg;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200753
Mattias Wallind7b9f322010-11-26 13:06:39 +0100754 ab8500_address_file = debugfs_create_file("register-address",
Vasiliy Kulikov44bdcb52011-02-04 15:23:43 +0300755 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100756 &ab8500_address_fops);
757 if (!ab8500_address_file)
758 goto exit_destroy_bank;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200759
Mattias Wallind7b9f322010-11-26 13:06:39 +0100760 ab8500_val_file = debugfs_create_file("register-value",
Vasiliy Kulikov44bdcb52011-02-04 15:23:43 +0300761 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops);
Mattias Wallind7b9f322010-11-26 13:06:39 +0100762 if (!ab8500_val_file)
763 goto exit_destroy_address;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200764
Lee Jones4b8ac082013-01-14 16:10:36 +0000765 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
Mattias Wallind7b9f322010-11-26 13:06:39 +0100779 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200780
Lee Jones4b8ac082013-01-14 16:10:36 +0000781exit_destroy_subscribe:
782 debugfs_remove(ab8500_subscribe_file);
783exit_destroy_val:
784 debugfs_remove(ab8500_val_file);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200785exit_destroy_address:
Mattias Wallind7b9f322010-11-26 13:06:39 +0100786 debugfs_remove(ab8500_address_file);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200787exit_destroy_bank:
Mattias Wallind7b9f322010-11-26 13:06:39 +0100788 debugfs_remove(ab8500_bank_file);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200789exit_destroy_reg:
Mattias Wallind7b9f322010-11-26 13:06:39 +0100790 debugfs_remove(ab8500_reg_file);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200791exit_destroy_dir:
Mattias Wallind7b9f322010-11-26 13:06:39 +0100792 debugfs_remove(ab8500_dir);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200793exit_no_debugfs:
Mattias Wallind7b9f322010-11-26 13:06:39 +0100794 dev_err(&plf->dev, "failed to create debugfs entries.\n");
795 return -ENOMEM;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200796}
797
Bill Pemberton4740f732012-11-19 13:26:01 -0500798static int ab8500_debug_remove(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +0200799{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100800 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);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200805
Mattias Wallind7b9f322010-11-26 13:06:39 +0100806 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200807}
808
809static struct platform_driver ab8500_debug_driver = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100810 .driver = {
811 .name = "ab8500-debug",
812 .owner = THIS_MODULE,
813 },
814 .probe = ab8500_debug_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500815 .remove = ab8500_debug_remove
Mattias Wallin5814fc32010-09-13 16:05:04 +0200816};
817
818static int __init ab8500_debug_init(void)
819{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100820 return platform_driver_register(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200821}
822
823static void __exit ab8500_debug_exit(void)
824{
Mattias Wallind7b9f322010-11-26 13:06:39 +0100825 platform_driver_unregister(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +0200826}
827subsys_initcall(ab8500_debug_init);
828module_exit(ab8500_debug_exit);
829
830MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
831MODULE_DESCRIPTION("AB8500 DEBUG");
832MODULE_LICENSE("GPL v2");