ab8500-debugfs.c 17 KB

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