USB: cp210x: allow more baud rates above 1Mbaud
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / mfd / ab8500-debugfs.c
blobdedb7f65cea600a205f83fc2e81e385649cf74ee
1 /*
2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2
6 */
8 #include <linux/seq_file.h>
9 #include <linux/uaccess.h>
10 #include <linux/fs.h>
11 #include <linux/module.h>
12 #include <linux/debugfs.h>
13 #include <linux/platform_device.h>
15 #include <linux/mfd/abx500.h>
16 #include <linux/mfd/ab8500.h>
18 static u32 debug_bank;
19 static u32 debug_address;
21 /**
22 * struct ab8500_reg_range
23 * @first: the first address of the range
24 * @last: the last address of the range
25 * @perm: access permissions for the range
27 struct ab8500_reg_range {
28 u8 first;
29 u8 last;
30 u8 perm;
33 /**
34 * struct ab8500_i2c_ranges
35 * @num_ranges: the number of ranges in the list
36 * @bankid: bank identifier
37 * @range: the list of register ranges
39 struct ab8500_i2c_ranges {
40 u8 num_ranges;
41 u8 bankid;
42 const struct ab8500_reg_range *range;
45 #define AB8500_NAME_STRING "ab8500"
46 #define AB8500_NUM_BANKS 22
48 #define AB8500_REV_REG 0x80
50 static struct ab8500_i2c_ranges debug_ranges[AB8500_NUM_BANKS] = {
51 [0x0] = {
52 .num_ranges = 0,
53 .range = 0,
55 [AB8500_SYS_CTRL1_BLOCK] = {
56 .num_ranges = 3,
57 .range = (struct ab8500_reg_range[]) {
59 .first = 0x00,
60 .last = 0x02,
63 .first = 0x42,
64 .last = 0x42,
67 .first = 0x80,
68 .last = 0x81,
72 [AB8500_SYS_CTRL2_BLOCK] = {
73 .num_ranges = 4,
74 .range = (struct ab8500_reg_range[]) {
76 .first = 0x00,
77 .last = 0x0D,
80 .first = 0x0F,
81 .last = 0x17,
84 .first = 0x30,
85 .last = 0x30,
88 .first = 0x32,
89 .last = 0x33,
93 [AB8500_REGU_CTRL1] = {
94 .num_ranges = 3,
95 .range = (struct ab8500_reg_range[]) {
97 .first = 0x00,
98 .last = 0x00,
101 .first = 0x03,
102 .last = 0x10,
105 .first = 0x80,
106 .last = 0x84,
110 [AB8500_REGU_CTRL2] = {
111 .num_ranges = 5,
112 .range = (struct ab8500_reg_range[]) {
114 .first = 0x00,
115 .last = 0x15,
118 .first = 0x17,
119 .last = 0x19,
122 .first = 0x1B,
123 .last = 0x1D,
126 .first = 0x1F,
127 .last = 0x22,
130 .first = 0x40,
131 .last = 0x44,
133 /* 0x80-0x8B is SIM registers and should
134 * not be accessed from here */
137 [AB8500_USB] = {
138 .num_ranges = 2,
139 .range = (struct ab8500_reg_range[]) {
141 .first = 0x80,
142 .last = 0x83,
145 .first = 0x87,
146 .last = 0x8A,
150 [AB8500_TVOUT] = {
151 .num_ranges = 9,
152 .range = (struct ab8500_reg_range[]) {
154 .first = 0x00,
155 .last = 0x12,
158 .first = 0x15,
159 .last = 0x17,
162 .first = 0x19,
163 .last = 0x21,
166 .first = 0x27,
167 .last = 0x2C,
170 .first = 0x41,
171 .last = 0x41,
174 .first = 0x45,
175 .last = 0x5B,
178 .first = 0x5D,
179 .last = 0x5D,
182 .first = 0x69,
183 .last = 0x69,
186 .first = 0x80,
187 .last = 0x81,
191 [AB8500_DBI] = {
192 .num_ranges = 0,
193 .range = NULL,
195 [AB8500_ECI_AV_ACC] = {
196 .num_ranges = 1,
197 .range = (struct ab8500_reg_range[]) {
199 .first = 0x80,
200 .last = 0x82,
204 [0x9] = {
205 .num_ranges = 0,
206 .range = NULL,
208 [AB8500_GPADC] = {
209 .num_ranges = 1,
210 .range = (struct ab8500_reg_range[]) {
212 .first = 0x00,
213 .last = 0x08,
217 [AB8500_CHARGER] = {
218 .num_ranges = 8,
219 .range = (struct ab8500_reg_range[]) {
221 .first = 0x00,
222 .last = 0x03,
225 .first = 0x05,
226 .last = 0x05,
229 .first = 0x40,
230 .last = 0x40,
233 .first = 0x42,
234 .last = 0x42,
237 .first = 0x44,
238 .last = 0x44,
241 .first = 0x50,
242 .last = 0x55,
245 .first = 0x80,
246 .last = 0x82,
249 .first = 0xC0,
250 .last = 0xC2,
254 [AB8500_GAS_GAUGE] = {
255 .num_ranges = 3,
256 .range = (struct ab8500_reg_range[]) {
258 .first = 0x00,
259 .last = 0x00,
262 .first = 0x07,
263 .last = 0x0A,
266 .first = 0x10,
267 .last = 0x14,
271 [AB8500_AUDIO] = {
272 .num_ranges = 1,
273 .range = (struct ab8500_reg_range[]) {
275 .first = 0x00,
276 .last = 0x6F,
280 [AB8500_INTERRUPT] = {
281 .num_ranges = 0,
282 .range = NULL,
284 [AB8500_RTC] = {
285 .num_ranges = 1,
286 .range = (struct ab8500_reg_range[]) {
288 .first = 0x00,
289 .last = 0x0F,
293 [AB8500_MISC] = {
294 .num_ranges = 8,
295 .range = (struct ab8500_reg_range[]) {
297 .first = 0x00,
298 .last = 0x05,
301 .first = 0x10,
302 .last = 0x15,
305 .first = 0x20,
306 .last = 0x25,
309 .first = 0x30,
310 .last = 0x35,
313 .first = 0x40,
314 .last = 0x45,
317 .first = 0x50,
318 .last = 0x50,
321 .first = 0x60,
322 .last = 0x67,
325 .first = 0x80,
326 .last = 0x80,
330 [0x11] = {
331 .num_ranges = 0,
332 .range = NULL,
334 [0x12] = {
335 .num_ranges = 0,
336 .range = NULL,
338 [0x13] = {
339 .num_ranges = 0,
340 .range = NULL,
342 [0x14] = {
343 .num_ranges = 0,
344 .range = NULL,
346 [AB8500_OTP_EMUL] = {
347 .num_ranges = 1,
348 .range = (struct ab8500_reg_range[]) {
350 .first = 0x01,
351 .last = 0x0F,
357 static int ab8500_registers_print(struct seq_file *s, void *p)
359 struct device *dev = s->private;
360 unsigned int i;
361 u32 bank = debug_bank;
363 seq_printf(s, AB8500_NAME_STRING " register values:\n");
365 seq_printf(s, " bank %u:\n", bank);
366 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
367 u32 reg;
369 for (reg = debug_ranges[bank].range[i].first;
370 reg <= debug_ranges[bank].range[i].last;
371 reg++) {
372 u8 value;
373 int err;
375 err = abx500_get_register_interruptible(dev,
376 (u8)bank, (u8)reg, &value);
377 if (err < 0) {
378 dev_err(dev, "ab->read fail %d\n", err);
379 return err;
382 err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank,
383 reg, value);
384 if (err < 0) {
385 dev_err(dev, "seq_printf overflow\n");
386 /* Error is not returned here since
387 * the output is wanted in any case */
388 return 0;
392 return 0;
395 static int ab8500_registers_open(struct inode *inode, struct file *file)
397 return single_open(file, ab8500_registers_print, inode->i_private);
400 static const struct file_operations ab8500_registers_fops = {
401 .open = ab8500_registers_open,
402 .read = seq_read,
403 .llseek = seq_lseek,
404 .release = single_release,
405 .owner = THIS_MODULE,
408 static int ab8500_bank_print(struct seq_file *s, void *p)
410 return seq_printf(s, "%d\n", debug_bank);
413 static int ab8500_bank_open(struct inode *inode, struct file *file)
415 return single_open(file, ab8500_bank_print, inode->i_private);
418 static ssize_t ab8500_bank_write(struct file *file,
419 const char __user *user_buf,
420 size_t count, loff_t *ppos)
422 struct device *dev = ((struct seq_file *)(file->private_data))->private;
423 unsigned long user_bank;
424 int err;
426 /* Get userspace string and assure termination */
427 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
428 if (err)
429 return err;
431 if (user_bank >= AB8500_NUM_BANKS) {
432 dev_err(dev, "debugfs error input > number of banks\n");
433 return -EINVAL;
436 debug_bank = user_bank;
438 return count;
441 static int ab8500_address_print(struct seq_file *s, void *p)
443 return seq_printf(s, "0x%02X\n", debug_address);
446 static int ab8500_address_open(struct inode *inode, struct file *file)
448 return single_open(file, ab8500_address_print, inode->i_private);
451 static ssize_t ab8500_address_write(struct file *file,
452 const char __user *user_buf,
453 size_t count, loff_t *ppos)
455 struct device *dev = ((struct seq_file *)(file->private_data))->private;
456 unsigned long user_address;
457 int err;
459 /* Get userspace string and assure termination */
460 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
461 if (err)
462 return err;
464 if (user_address > 0xff) {
465 dev_err(dev, "debugfs error input > 0xff\n");
466 return -EINVAL;
468 debug_address = user_address;
469 return count;
472 static int ab8500_val_print(struct seq_file *s, void *p)
474 struct device *dev = s->private;
475 int ret;
476 u8 regvalue;
478 ret = abx500_get_register_interruptible(dev,
479 (u8)debug_bank, (u8)debug_address, &regvalue);
480 if (ret < 0) {
481 dev_err(dev, "abx500_get_reg fail %d, %d\n",
482 ret, __LINE__);
483 return -EINVAL;
485 seq_printf(s, "0x%02X\n", regvalue);
487 return 0;
490 static int ab8500_val_open(struct inode *inode, struct file *file)
492 return single_open(file, ab8500_val_print, inode->i_private);
495 static ssize_t ab8500_val_write(struct file *file,
496 const char __user *user_buf,
497 size_t count, loff_t *ppos)
499 struct device *dev = ((struct seq_file *)(file->private_data))->private;
500 unsigned long user_val;
501 int err;
503 /* Get userspace string and assure termination */
504 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
505 if (err)
506 return err;
508 if (user_val > 0xff) {
509 dev_err(dev, "debugfs error input > 0xff\n");
510 return -EINVAL;
512 err = abx500_set_register_interruptible(dev,
513 (u8)debug_bank, debug_address, (u8)user_val);
514 if (err < 0) {
515 printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
516 return -EINVAL;
519 return count;
522 static const struct file_operations ab8500_bank_fops = {
523 .open = ab8500_bank_open,
524 .write = ab8500_bank_write,
525 .read = seq_read,
526 .llseek = seq_lseek,
527 .release = single_release,
528 .owner = THIS_MODULE,
531 static const struct file_operations ab8500_address_fops = {
532 .open = ab8500_address_open,
533 .write = ab8500_address_write,
534 .read = seq_read,
535 .llseek = seq_lseek,
536 .release = single_release,
537 .owner = THIS_MODULE,
540 static const struct file_operations ab8500_val_fops = {
541 .open = ab8500_val_open,
542 .write = ab8500_val_write,
543 .read = seq_read,
544 .llseek = seq_lseek,
545 .release = single_release,
546 .owner = THIS_MODULE,
549 static struct dentry *ab8500_dir;
550 static struct dentry *ab8500_reg_file;
551 static struct dentry *ab8500_bank_file;
552 static struct dentry *ab8500_address_file;
553 static struct dentry *ab8500_val_file;
555 static int __devinit ab8500_debug_probe(struct platform_device *plf)
557 debug_bank = AB8500_MISC;
558 debug_address = AB8500_REV_REG & 0x00FF;
560 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
561 if (!ab8500_dir)
562 goto exit_no_debugfs;
564 ab8500_reg_file = debugfs_create_file("all-bank-registers",
565 S_IRUGO, ab8500_dir, &plf->dev, &ab8500_registers_fops);
566 if (!ab8500_reg_file)
567 goto exit_destroy_dir;
569 ab8500_bank_file = debugfs_create_file("register-bank",
570 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops);
571 if (!ab8500_bank_file)
572 goto exit_destroy_reg;
574 ab8500_address_file = debugfs_create_file("register-address",
575 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev,
576 &ab8500_address_fops);
577 if (!ab8500_address_file)
578 goto exit_destroy_bank;
580 ab8500_val_file = debugfs_create_file("register-value",
581 (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops);
582 if (!ab8500_val_file)
583 goto exit_destroy_address;
585 return 0;
587 exit_destroy_address:
588 debugfs_remove(ab8500_address_file);
589 exit_destroy_bank:
590 debugfs_remove(ab8500_bank_file);
591 exit_destroy_reg:
592 debugfs_remove(ab8500_reg_file);
593 exit_destroy_dir:
594 debugfs_remove(ab8500_dir);
595 exit_no_debugfs:
596 dev_err(&plf->dev, "failed to create debugfs entries.\n");
597 return -ENOMEM;
600 static int __devexit ab8500_debug_remove(struct platform_device *plf)
602 debugfs_remove(ab8500_val_file);
603 debugfs_remove(ab8500_address_file);
604 debugfs_remove(ab8500_bank_file);
605 debugfs_remove(ab8500_reg_file);
606 debugfs_remove(ab8500_dir);
608 return 0;
611 static struct platform_driver ab8500_debug_driver = {
612 .driver = {
613 .name = "ab8500-debug",
614 .owner = THIS_MODULE,
616 .probe = ab8500_debug_probe,
617 .remove = __devexit_p(ab8500_debug_remove)
620 static int __init ab8500_debug_init(void)
622 return platform_driver_register(&ab8500_debug_driver);
625 static void __exit ab8500_debug_exit(void)
627 platform_driver_unregister(&ab8500_debug_driver);
629 subsys_initcall(ab8500_debug_init);
630 module_exit(ab8500_debug_exit);
632 MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
633 MODULE_DESCRIPTION("AB8500 DEBUG");
634 MODULE_LICENSE("GPL v2");