ab8500-debugfs.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  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. * 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. */
  73. #include <linux/seq_file.h>
  74. #include <linux/uaccess.h>
  75. #include <linux/fs.h>
  76. #include <linux/module.h>
  77. #include <linux/debugfs.h>
  78. #include <linux/platform_device.h>
  79. #include <linux/interrupt.h>
  80. #include <linux/kobject.h>
  81. #include <linux/slab.h>
  82. #include <linux/mfd/abx500.h>
  83. #include <linux/mfd/abx500/ab8500-gpadc.h>
  84. #ifdef CONFIG_DEBUG_FS
  85. #include <linux/string.h>
  86. #include <linux/ctype.h>
  87. #endif
  88. static u32 debug_bank;
  89. static u32 debug_address;
  90. static int irq_first;
  91. static int irq_last;
  92. static u32 irq_count[AB8500_NR_IRQS];
  93. static struct device_attribute *dev_attr[AB8500_NR_IRQS];
  94. static char *event_name[AB8500_NR_IRQS];
  95. /**
  96. * struct ab8500_reg_range
  97. * @first: the first address of the range
  98. * @last: the last address of the range
  99. * @perm: access permissions for the range
  100. */
  101. struct ab8500_reg_range {
  102. u8 first;
  103. u8 last;
  104. u8 perm;
  105. };
  106. /**
  107. * struct ab8500_prcmu_ranges
  108. * @num_ranges: the number of ranges in the list
  109. * @bankid: bank identifier
  110. * @range: the list of register ranges
  111. */
  112. struct ab8500_prcmu_ranges {
  113. u8 num_ranges;
  114. u8 bankid;
  115. const struct ab8500_reg_range *range;
  116. };
  117. /* hwreg- "mask" and "shift" entries ressources */
  118. struct hwreg_cfg {
  119. u32 bank; /* target bank */
  120. u32 addr; /* target address */
  121. uint fmt; /* format */
  122. uint mask; /* read/write mask, applied before any bit shift */
  123. int shift; /* bit shift (read:right shift, write:left shift */
  124. };
  125. /* fmt bit #0: 0=hexa, 1=dec */
  126. #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
  127. #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
  128. static struct hwreg_cfg hwreg_cfg = {
  129. .addr = 0, /* default: invalid phys addr */
  130. .fmt = 0, /* default: 32bit access, hex output */
  131. .mask = 0xFFFFFFFF, /* default: no mask */
  132. .shift = 0, /* default: no bit shift */
  133. };
  134. #define AB8500_NAME_STRING "ab8500"
  135. #define AB8500_ADC_NAME_STRING "gpadc"
  136. #define AB8500_NUM_BANKS 24
  137. #define AB8500_REV_REG 0x80
  138. static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
  139. [0x0] = {
  140. .num_ranges = 0,
  141. .range = NULL,
  142. },
  143. [AB8500_SYS_CTRL1_BLOCK] = {
  144. .num_ranges = 3,
  145. .range = (struct ab8500_reg_range[]) {
  146. {
  147. .first = 0x00,
  148. .last = 0x02,
  149. },
  150. {
  151. .first = 0x42,
  152. .last = 0x42,
  153. },
  154. {
  155. .first = 0x80,
  156. .last = 0x81,
  157. },
  158. },
  159. },
  160. [AB8500_SYS_CTRL2_BLOCK] = {
  161. .num_ranges = 4,
  162. .range = (struct ab8500_reg_range[]) {
  163. {
  164. .first = 0x00,
  165. .last = 0x0D,
  166. },
  167. {
  168. .first = 0x0F,
  169. .last = 0x17,
  170. },
  171. {
  172. .first = 0x30,
  173. .last = 0x30,
  174. },
  175. {
  176. .first = 0x32,
  177. .last = 0x33,
  178. },
  179. },
  180. },
  181. [AB8500_REGU_CTRL1] = {
  182. .num_ranges = 3,
  183. .range = (struct ab8500_reg_range[]) {
  184. {
  185. .first = 0x00,
  186. .last = 0x00,
  187. },
  188. {
  189. .first = 0x03,
  190. .last = 0x10,
  191. },
  192. {
  193. .first = 0x80,
  194. .last = 0x84,
  195. },
  196. },
  197. },
  198. [AB8500_REGU_CTRL2] = {
  199. .num_ranges = 5,
  200. .range = (struct ab8500_reg_range[]) {
  201. {
  202. .first = 0x00,
  203. .last = 0x15,
  204. },
  205. {
  206. .first = 0x17,
  207. .last = 0x19,
  208. },
  209. {
  210. .first = 0x1B,
  211. .last = 0x1D,
  212. },
  213. {
  214. .first = 0x1F,
  215. .last = 0x22,
  216. },
  217. {
  218. .first = 0x40,
  219. .last = 0x44,
  220. },
  221. /* 0x80-0x8B is SIM registers and should
  222. * not be accessed from here */
  223. },
  224. },
  225. [AB8500_USB] = {
  226. .num_ranges = 2,
  227. .range = (struct ab8500_reg_range[]) {
  228. {
  229. .first = 0x80,
  230. .last = 0x83,
  231. },
  232. {
  233. .first = 0x87,
  234. .last = 0x8A,
  235. },
  236. },
  237. },
  238. [AB8500_TVOUT] = {
  239. .num_ranges = 9,
  240. .range = (struct ab8500_reg_range[]) {
  241. {
  242. .first = 0x00,
  243. .last = 0x12,
  244. },
  245. {
  246. .first = 0x15,
  247. .last = 0x17,
  248. },
  249. {
  250. .first = 0x19,
  251. .last = 0x21,
  252. },
  253. {
  254. .first = 0x27,
  255. .last = 0x2C,
  256. },
  257. {
  258. .first = 0x41,
  259. .last = 0x41,
  260. },
  261. {
  262. .first = 0x45,
  263. .last = 0x5B,
  264. },
  265. {
  266. .first = 0x5D,
  267. .last = 0x5D,
  268. },
  269. {
  270. .first = 0x69,
  271. .last = 0x69,
  272. },
  273. {
  274. .first = 0x80,
  275. .last = 0x81,
  276. },
  277. },
  278. },
  279. [AB8500_DBI] = {
  280. .num_ranges = 0,
  281. .range = NULL,
  282. },
  283. [AB8500_ECI_AV_ACC] = {
  284. .num_ranges = 1,
  285. .range = (struct ab8500_reg_range[]) {
  286. {
  287. .first = 0x80,
  288. .last = 0x82,
  289. },
  290. },
  291. },
  292. [0x9] = {
  293. .num_ranges = 0,
  294. .range = NULL,
  295. },
  296. [AB8500_GPADC] = {
  297. .num_ranges = 1,
  298. .range = (struct ab8500_reg_range[]) {
  299. {
  300. .first = 0x00,
  301. .last = 0x08,
  302. },
  303. },
  304. },
  305. [AB8500_CHARGER] = {
  306. .num_ranges = 9,
  307. .range = (struct ab8500_reg_range[]) {
  308. {
  309. .first = 0x00,
  310. .last = 0x03,
  311. },
  312. {
  313. .first = 0x05,
  314. .last = 0x05,
  315. },
  316. {
  317. .first = 0x40,
  318. .last = 0x40,
  319. },
  320. {
  321. .first = 0x42,
  322. .last = 0x42,
  323. },
  324. {
  325. .first = 0x44,
  326. .last = 0x44,
  327. },
  328. {
  329. .first = 0x50,
  330. .last = 0x55,
  331. },
  332. {
  333. .first = 0x80,
  334. .last = 0x82,
  335. },
  336. {
  337. .first = 0xC0,
  338. .last = 0xC2,
  339. },
  340. {
  341. .first = 0xf5,
  342. .last = 0xf6,
  343. },
  344. },
  345. },
  346. [AB8500_GAS_GAUGE] = {
  347. .num_ranges = 3,
  348. .range = (struct ab8500_reg_range[]) {
  349. {
  350. .first = 0x00,
  351. .last = 0x00,
  352. },
  353. {
  354. .first = 0x07,
  355. .last = 0x0A,
  356. },
  357. {
  358. .first = 0x10,
  359. .last = 0x14,
  360. },
  361. },
  362. },
  363. [AB8500_DEVELOPMENT] = {
  364. .num_ranges = 1,
  365. .range = (struct ab8500_reg_range[]) {
  366. {
  367. .first = 0x00,
  368. .last = 0x00,
  369. },
  370. },
  371. },
  372. [AB8500_DEBUG] = {
  373. .num_ranges = 1,
  374. .range = (struct ab8500_reg_range[]) {
  375. {
  376. .first = 0x05,
  377. .last = 0x07,
  378. },
  379. },
  380. },
  381. [AB8500_AUDIO] = {
  382. .num_ranges = 1,
  383. .range = (struct ab8500_reg_range[]) {
  384. {
  385. .first = 0x00,
  386. .last = 0x6F,
  387. },
  388. },
  389. },
  390. [AB8500_INTERRUPT] = {
  391. .num_ranges = 0,
  392. .range = NULL,
  393. },
  394. [AB8500_RTC] = {
  395. .num_ranges = 1,
  396. .range = (struct ab8500_reg_range[]) {
  397. {
  398. .first = 0x00,
  399. .last = 0x0F,
  400. },
  401. },
  402. },
  403. [AB8500_MISC] = {
  404. .num_ranges = 8,
  405. .range = (struct ab8500_reg_range[]) {
  406. {
  407. .first = 0x00,
  408. .last = 0x05,
  409. },
  410. {
  411. .first = 0x10,
  412. .last = 0x15,
  413. },
  414. {
  415. .first = 0x20,
  416. .last = 0x25,
  417. },
  418. {
  419. .first = 0x30,
  420. .last = 0x35,
  421. },
  422. {
  423. .first = 0x40,
  424. .last = 0x45,
  425. },
  426. {
  427. .first = 0x50,
  428. .last = 0x50,
  429. },
  430. {
  431. .first = 0x60,
  432. .last = 0x67,
  433. },
  434. {
  435. .first = 0x80,
  436. .last = 0x80,
  437. },
  438. },
  439. },
  440. [0x11] = {
  441. .num_ranges = 0,
  442. .range = NULL,
  443. },
  444. [0x12] = {
  445. .num_ranges = 0,
  446. .range = NULL,
  447. },
  448. [0x13] = {
  449. .num_ranges = 0,
  450. .range = NULL,
  451. },
  452. [0x14] = {
  453. .num_ranges = 0,
  454. .range = NULL,
  455. },
  456. [AB8500_OTP_EMUL] = {
  457. .num_ranges = 1,
  458. .range = (struct ab8500_reg_range[]) {
  459. {
  460. .first = 0x01,
  461. .last = 0x0F,
  462. },
  463. },
  464. },
  465. };
  466. static irqreturn_t ab8500_debug_handler(int irq, void *data)
  467. {
  468. char buf[16];
  469. struct kobject *kobj = (struct kobject *)data;
  470. unsigned int irq_abb = irq - irq_first;
  471. if (irq_abb < AB8500_NR_IRQS)
  472. irq_count[irq_abb]++;
  473. /*
  474. * This makes it possible to use poll for events (POLLPRI | POLLERR)
  475. * from userspace on sysfs file named <irq-nr>
  476. */
  477. sprintf(buf, "%d", irq);
  478. sysfs_notify(kobj, NULL, buf);
  479. return IRQ_HANDLED;
  480. }
  481. static int ab8500_registers_print(struct seq_file *s, void *p)
  482. {
  483. struct device *dev = s->private;
  484. unsigned int i;
  485. u32 bank = debug_bank;
  486. seq_printf(s, AB8500_NAME_STRING " register values:\n");
  487. seq_printf(s, " bank %u:\n", bank);
  488. for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
  489. u32 reg;
  490. for (reg = debug_ranges[bank].range[i].first;
  491. reg <= debug_ranges[bank].range[i].last;
  492. reg++) {
  493. u8 value;
  494. int err;
  495. err = abx500_get_register_interruptible(dev,
  496. (u8)bank, (u8)reg, &value);
  497. if (err < 0) {
  498. dev_err(dev, "ab->read fail %d\n", err);
  499. return err;
  500. }
  501. err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank,
  502. reg, value);
  503. if (err < 0) {
  504. dev_err(dev, "seq_printf overflow\n");
  505. /* Error is not returned here since
  506. * the output is wanted in any case */
  507. return 0;
  508. }
  509. }
  510. }
  511. return 0;
  512. }
  513. static int ab8500_registers_open(struct inode *inode, struct file *file)
  514. {
  515. return single_open(file, ab8500_registers_print, inode->i_private);
  516. }
  517. static const struct file_operations ab8500_registers_fops = {
  518. .open = ab8500_registers_open,
  519. .read = seq_read,
  520. .llseek = seq_lseek,
  521. .release = single_release,
  522. .owner = THIS_MODULE,
  523. };
  524. static int ab8500_bank_print(struct seq_file *s, void *p)
  525. {
  526. return seq_printf(s, "%d\n", debug_bank);
  527. }
  528. static int ab8500_bank_open(struct inode *inode, struct file *file)
  529. {
  530. return single_open(file, ab8500_bank_print, inode->i_private);
  531. }
  532. static ssize_t ab8500_bank_write(struct file *file,
  533. const char __user *user_buf,
  534. size_t count, loff_t *ppos)
  535. {
  536. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  537. unsigned long user_bank;
  538. int err;
  539. /* Get userspace string and assure termination */
  540. err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
  541. if (err)
  542. return err;
  543. if (user_bank >= AB8500_NUM_BANKS) {
  544. dev_err(dev, "debugfs error input > number of banks\n");
  545. return -EINVAL;
  546. }
  547. debug_bank = user_bank;
  548. return count;
  549. }
  550. static int ab8500_address_print(struct seq_file *s, void *p)
  551. {
  552. return seq_printf(s, "0x%02X\n", debug_address);
  553. }
  554. static int ab8500_address_open(struct inode *inode, struct file *file)
  555. {
  556. return single_open(file, ab8500_address_print, inode->i_private);
  557. }
  558. static ssize_t ab8500_address_write(struct file *file,
  559. const char __user *user_buf,
  560. size_t count, loff_t *ppos)
  561. {
  562. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  563. unsigned long user_address;
  564. int err;
  565. /* Get userspace string and assure termination */
  566. err = kstrtoul_from_user(user_buf, count, 0, &user_address);
  567. if (err)
  568. return err;
  569. if (user_address > 0xff) {
  570. dev_err(dev, "debugfs error input > 0xff\n");
  571. return -EINVAL;
  572. }
  573. debug_address = user_address;
  574. return count;
  575. }
  576. static int ab8500_val_print(struct seq_file *s, void *p)
  577. {
  578. struct device *dev = s->private;
  579. int ret;
  580. u8 regvalue;
  581. ret = abx500_get_register_interruptible(dev,
  582. (u8)debug_bank, (u8)debug_address, &regvalue);
  583. if (ret < 0) {
  584. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  585. ret, __LINE__);
  586. return -EINVAL;
  587. }
  588. seq_printf(s, "0x%02X\n", regvalue);
  589. return 0;
  590. }
  591. static int ab8500_val_open(struct inode *inode, struct file *file)
  592. {
  593. return single_open(file, ab8500_val_print, inode->i_private);
  594. }
  595. static ssize_t ab8500_val_write(struct file *file,
  596. const char __user *user_buf,
  597. size_t count, loff_t *ppos)
  598. {
  599. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  600. unsigned long user_val;
  601. int err;
  602. /* Get userspace string and assure termination */
  603. err = kstrtoul_from_user(user_buf, count, 0, &user_val);
  604. if (err)
  605. return err;
  606. if (user_val > 0xff) {
  607. dev_err(dev, "debugfs error input > 0xff\n");
  608. return -EINVAL;
  609. }
  610. err = abx500_set_register_interruptible(dev,
  611. (u8)debug_bank, debug_address, (u8)user_val);
  612. if (err < 0) {
  613. printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
  614. return -EINVAL;
  615. }
  616. return count;
  617. }
  618. /*
  619. * - HWREG DB8500 formated routines
  620. */
  621. static int ab8500_hwreg_print(struct seq_file *s, void *d)
  622. {
  623. struct device *dev = s->private;
  624. int ret;
  625. u8 regvalue;
  626. ret = abx500_get_register_interruptible(dev,
  627. (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
  628. if (ret < 0) {
  629. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  630. ret, __LINE__);
  631. return -EINVAL;
  632. }
  633. if (hwreg_cfg.shift >= 0)
  634. regvalue >>= hwreg_cfg.shift;
  635. else
  636. regvalue <<= -hwreg_cfg.shift;
  637. regvalue &= hwreg_cfg.mask;
  638. if (REG_FMT_DEC(&hwreg_cfg))
  639. seq_printf(s, "%d\n", regvalue);
  640. else
  641. seq_printf(s, "0x%02X\n", regvalue);
  642. return 0;
  643. }
  644. static int ab8500_hwreg_open(struct inode *inode, struct file *file)
  645. {
  646. return single_open(file, ab8500_hwreg_print, inode->i_private);
  647. }
  648. static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
  649. {
  650. int bat_ctrl_raw;
  651. int bat_ctrl_convert;
  652. struct ab8500_gpadc *gpadc;
  653. gpadc = ab8500_gpadc_get();
  654. bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL);
  655. bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  656. BAT_CTRL, bat_ctrl_raw);
  657. return seq_printf(s, "%d,0x%X\n",
  658. bat_ctrl_convert, bat_ctrl_raw);
  659. }
  660. static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
  661. {
  662. return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
  663. }
  664. static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
  665. .open = ab8500_gpadc_bat_ctrl_open,
  666. .read = seq_read,
  667. .llseek = seq_lseek,
  668. .release = single_release,
  669. .owner = THIS_MODULE,
  670. };
  671. static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
  672. {
  673. int btemp_ball_raw;
  674. int btemp_ball_convert;
  675. struct ab8500_gpadc *gpadc;
  676. gpadc = ab8500_gpadc_get();
  677. btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL);
  678. btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
  679. btemp_ball_raw);
  680. return seq_printf(s,
  681. "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
  682. }
  683. static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
  684. struct file *file)
  685. {
  686. return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
  687. }
  688. static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
  689. .open = ab8500_gpadc_btemp_ball_open,
  690. .read = seq_read,
  691. .llseek = seq_lseek,
  692. .release = single_release,
  693. .owner = THIS_MODULE,
  694. };
  695. static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
  696. {
  697. int main_charger_v_raw;
  698. int main_charger_v_convert;
  699. struct ab8500_gpadc *gpadc;
  700. gpadc = ab8500_gpadc_get();
  701. main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V);
  702. main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  703. MAIN_CHARGER_V, main_charger_v_raw);
  704. return seq_printf(s, "%d,0x%X\n",
  705. main_charger_v_convert, main_charger_v_raw);
  706. }
  707. static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
  708. struct file *file)
  709. {
  710. return single_open(file, ab8500_gpadc_main_charger_v_print,
  711. inode->i_private);
  712. }
  713. static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
  714. .open = ab8500_gpadc_main_charger_v_open,
  715. .read = seq_read,
  716. .llseek = seq_lseek,
  717. .release = single_release,
  718. .owner = THIS_MODULE,
  719. };
  720. static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
  721. {
  722. int acc_detect1_raw;
  723. int acc_detect1_convert;
  724. struct ab8500_gpadc *gpadc;
  725. gpadc = ab8500_gpadc_get();
  726. acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1);
  727. acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
  728. acc_detect1_raw);
  729. return seq_printf(s, "%d,0x%X\n",
  730. acc_detect1_convert, acc_detect1_raw);
  731. }
  732. static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
  733. struct file *file)
  734. {
  735. return single_open(file, ab8500_gpadc_acc_detect1_print,
  736. inode->i_private);
  737. }
  738. static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
  739. .open = ab8500_gpadc_acc_detect1_open,
  740. .read = seq_read,
  741. .llseek = seq_lseek,
  742. .release = single_release,
  743. .owner = THIS_MODULE,
  744. };
  745. static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
  746. {
  747. int acc_detect2_raw;
  748. int acc_detect2_convert;
  749. struct ab8500_gpadc *gpadc;
  750. gpadc = ab8500_gpadc_get();
  751. acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2);
  752. acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  753. ACC_DETECT2, acc_detect2_raw);
  754. return seq_printf(s, "%d,0x%X\n",
  755. acc_detect2_convert, acc_detect2_raw);
  756. }
  757. static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
  758. struct file *file)
  759. {
  760. return single_open(file, ab8500_gpadc_acc_detect2_print,
  761. inode->i_private);
  762. }
  763. static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
  764. .open = ab8500_gpadc_acc_detect2_open,
  765. .read = seq_read,
  766. .llseek = seq_lseek,
  767. .release = single_release,
  768. .owner = THIS_MODULE,
  769. };
  770. static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
  771. {
  772. int aux1_raw;
  773. int aux1_convert;
  774. struct ab8500_gpadc *gpadc;
  775. gpadc = ab8500_gpadc_get();
  776. aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1);
  777. aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
  778. aux1_raw);
  779. return seq_printf(s, "%d,0x%X\n",
  780. aux1_convert, aux1_raw);
  781. }
  782. static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
  783. {
  784. return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
  785. }
  786. static const struct file_operations ab8500_gpadc_aux1_fops = {
  787. .open = ab8500_gpadc_aux1_open,
  788. .read = seq_read,
  789. .llseek = seq_lseek,
  790. .release = single_release,
  791. .owner = THIS_MODULE,
  792. };
  793. static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
  794. {
  795. int aux2_raw;
  796. int aux2_convert;
  797. struct ab8500_gpadc *gpadc;
  798. gpadc = ab8500_gpadc_get();
  799. aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2);
  800. aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
  801. aux2_raw);
  802. return seq_printf(s, "%d,0x%X\n",
  803. aux2_convert, aux2_raw);
  804. }
  805. static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
  806. {
  807. return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
  808. }
  809. static const struct file_operations ab8500_gpadc_aux2_fops = {
  810. .open = ab8500_gpadc_aux2_open,
  811. .read = seq_read,
  812. .llseek = seq_lseek,
  813. .release = single_release,
  814. .owner = THIS_MODULE,
  815. };
  816. static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
  817. {
  818. int main_bat_v_raw;
  819. int main_bat_v_convert;
  820. struct ab8500_gpadc *gpadc;
  821. gpadc = ab8500_gpadc_get();
  822. main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V);
  823. main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
  824. main_bat_v_raw);
  825. return seq_printf(s, "%d,0x%X\n",
  826. main_bat_v_convert, main_bat_v_raw);
  827. }
  828. static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
  829. struct file *file)
  830. {
  831. return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
  832. }
  833. static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
  834. .open = ab8500_gpadc_main_bat_v_open,
  835. .read = seq_read,
  836. .llseek = seq_lseek,
  837. .release = single_release,
  838. .owner = THIS_MODULE,
  839. };
  840. static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
  841. {
  842. int vbus_v_raw;
  843. int vbus_v_convert;
  844. struct ab8500_gpadc *gpadc;
  845. gpadc = ab8500_gpadc_get();
  846. vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V);
  847. vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
  848. vbus_v_raw);
  849. return seq_printf(s, "%d,0x%X\n",
  850. vbus_v_convert, vbus_v_raw);
  851. }
  852. static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
  853. {
  854. return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
  855. }
  856. static const struct file_operations ab8500_gpadc_vbus_v_fops = {
  857. .open = ab8500_gpadc_vbus_v_open,
  858. .read = seq_read,
  859. .llseek = seq_lseek,
  860. .release = single_release,
  861. .owner = THIS_MODULE,
  862. };
  863. static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
  864. {
  865. int main_charger_c_raw;
  866. int main_charger_c_convert;
  867. struct ab8500_gpadc *gpadc;
  868. gpadc = ab8500_gpadc_get();
  869. main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C);
  870. main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  871. MAIN_CHARGER_C, main_charger_c_raw);
  872. return seq_printf(s, "%d,0x%X\n",
  873. main_charger_c_convert, main_charger_c_raw);
  874. }
  875. static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
  876. struct file *file)
  877. {
  878. return single_open(file, ab8500_gpadc_main_charger_c_print,
  879. inode->i_private);
  880. }
  881. static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
  882. .open = ab8500_gpadc_main_charger_c_open,
  883. .read = seq_read,
  884. .llseek = seq_lseek,
  885. .release = single_release,
  886. .owner = THIS_MODULE,
  887. };
  888. static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
  889. {
  890. int usb_charger_c_raw;
  891. int usb_charger_c_convert;
  892. struct ab8500_gpadc *gpadc;
  893. gpadc = ab8500_gpadc_get();
  894. usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C);
  895. usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  896. USB_CHARGER_C, usb_charger_c_raw);
  897. return seq_printf(s, "%d,0x%X\n",
  898. usb_charger_c_convert, usb_charger_c_raw);
  899. }
  900. static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
  901. struct file *file)
  902. {
  903. return single_open(file, ab8500_gpadc_usb_charger_c_print,
  904. inode->i_private);
  905. }
  906. static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
  907. .open = ab8500_gpadc_usb_charger_c_open,
  908. .read = seq_read,
  909. .llseek = seq_lseek,
  910. .release = single_release,
  911. .owner = THIS_MODULE,
  912. };
  913. static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
  914. {
  915. int bk_bat_v_raw;
  916. int bk_bat_v_convert;
  917. struct ab8500_gpadc *gpadc;
  918. gpadc = ab8500_gpadc_get();
  919. bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V);
  920. bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  921. BK_BAT_V, bk_bat_v_raw);
  922. return seq_printf(s, "%d,0x%X\n",
  923. bk_bat_v_convert, bk_bat_v_raw);
  924. }
  925. static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
  926. {
  927. return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
  928. }
  929. static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
  930. .open = ab8500_gpadc_bk_bat_v_open,
  931. .read = seq_read,
  932. .llseek = seq_lseek,
  933. .release = single_release,
  934. .owner = THIS_MODULE,
  935. };
  936. static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
  937. {
  938. int die_temp_raw;
  939. int die_temp_convert;
  940. struct ab8500_gpadc *gpadc;
  941. gpadc = ab8500_gpadc_get();
  942. die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP);
  943. die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
  944. die_temp_raw);
  945. return seq_printf(s, "%d,0x%X\n",
  946. die_temp_convert, die_temp_raw);
  947. }
  948. static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
  949. {
  950. return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
  951. }
  952. static const struct file_operations ab8500_gpadc_die_temp_fops = {
  953. .open = ab8500_gpadc_die_temp_open,
  954. .read = seq_read,
  955. .llseek = seq_lseek,
  956. .release = single_release,
  957. .owner = THIS_MODULE,
  958. };
  959. /*
  960. * return length of an ASCII numerical value, 0 is string is not a
  961. * numerical value.
  962. * string shall start at value 1st char.
  963. * string can be tailed with \0 or space or newline chars only.
  964. * value can be decimal or hexadecimal (prefixed 0x or 0X).
  965. */
  966. static int strval_len(char *b)
  967. {
  968. char *s = b;
  969. if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
  970. s += 2;
  971. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  972. if (!isxdigit(*s))
  973. return 0;
  974. }
  975. } else {
  976. if (*s == '-')
  977. s++;
  978. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  979. if (!isdigit(*s))
  980. return 0;
  981. }
  982. }
  983. return (int) (s-b);
  984. }
  985. /*
  986. * parse hwreg input data.
  987. * update global hwreg_cfg only if input data syntax is ok.
  988. */
  989. static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
  990. struct device *dev)
  991. {
  992. uint write, val = 0;
  993. u8 regvalue;
  994. int ret;
  995. struct hwreg_cfg loc = {
  996. .bank = 0, /* default: invalid phys addr */
  997. .addr = 0, /* default: invalid phys addr */
  998. .fmt = 0, /* default: 32bit access, hex output */
  999. .mask = 0xFFFFFFFF, /* default: no mask */
  1000. .shift = 0, /* default: no bit shift */
  1001. };
  1002. /* read or write ? */
  1003. if (!strncmp(b, "read ", 5)) {
  1004. write = 0;
  1005. b += 5;
  1006. } else if (!strncmp(b, "write ", 6)) {
  1007. write = 1;
  1008. b += 6;
  1009. } else
  1010. return -EINVAL;
  1011. /* OPTIONS -l|-w|-b -s -m -o */
  1012. while ((*b == ' ') || (*b == '-')) {
  1013. if (*(b-1) != ' ') {
  1014. b++;
  1015. continue;
  1016. }
  1017. if ((!strncmp(b, "-d ", 3)) ||
  1018. (!strncmp(b, "-dec ", 5))) {
  1019. b += (*(b+2) == ' ') ? 3 : 5;
  1020. loc.fmt |= (1<<0);
  1021. } else if ((!strncmp(b, "-h ", 3)) ||
  1022. (!strncmp(b, "-hex ", 5))) {
  1023. b += (*(b+2) == ' ') ? 3 : 5;
  1024. loc.fmt &= ~(1<<0);
  1025. } else if ((!strncmp(b, "-m ", 3)) ||
  1026. (!strncmp(b, "-mask ", 6))) {
  1027. b += (*(b+2) == ' ') ? 3 : 6;
  1028. if (strval_len(b) == 0)
  1029. return -EINVAL;
  1030. loc.mask = simple_strtoul(b, &b, 0);
  1031. } else if ((!strncmp(b, "-s ", 3)) ||
  1032. (!strncmp(b, "-shift ", 7))) {
  1033. b += (*(b+2) == ' ') ? 3 : 7;
  1034. if (strval_len(b) == 0)
  1035. return -EINVAL;
  1036. loc.shift = simple_strtol(b, &b, 0);
  1037. } else {
  1038. return -EINVAL;
  1039. }
  1040. }
  1041. /* get arg BANK and ADDRESS */
  1042. if (strval_len(b) == 0)
  1043. return -EINVAL;
  1044. loc.bank = simple_strtoul(b, &b, 0);
  1045. while (*b == ' ')
  1046. b++;
  1047. if (strval_len(b) == 0)
  1048. return -EINVAL;
  1049. loc.addr = simple_strtoul(b, &b, 0);
  1050. if (write) {
  1051. while (*b == ' ')
  1052. b++;
  1053. if (strval_len(b) == 0)
  1054. return -EINVAL;
  1055. val = simple_strtoul(b, &b, 0);
  1056. }
  1057. /* args are ok, update target cfg (mainly for read) */
  1058. *cfg = loc;
  1059. #ifdef ABB_HWREG_DEBUG
  1060. pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
  1061. "value=0x%X\n", (write) ? "write" : "read",
  1062. REG_FMT_DEC(cfg) ? "decimal" : "hexa",
  1063. cfg->addr, cfg->mask, cfg->shift, val);
  1064. #endif
  1065. if (!write)
  1066. return 0;
  1067. ret = abx500_get_register_interruptible(dev,
  1068. (u8)cfg->bank, (u8)cfg->addr, &regvalue);
  1069. if (ret < 0) {
  1070. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  1071. ret, __LINE__);
  1072. return -EINVAL;
  1073. }
  1074. if (cfg->shift >= 0) {
  1075. regvalue &= ~(cfg->mask << (cfg->shift));
  1076. val = (val & cfg->mask) << (cfg->shift);
  1077. } else {
  1078. regvalue &= ~(cfg->mask >> (-cfg->shift));
  1079. val = (val & cfg->mask) >> (-cfg->shift);
  1080. }
  1081. val = val | regvalue;
  1082. ret = abx500_set_register_interruptible(dev,
  1083. (u8)cfg->bank, (u8)cfg->addr, (u8)val);
  1084. if (ret < 0) {
  1085. pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
  1086. return -EINVAL;
  1087. }
  1088. return 0;
  1089. }
  1090. static ssize_t ab8500_hwreg_write(struct file *file,
  1091. const char __user *user_buf, size_t count, loff_t *ppos)
  1092. {
  1093. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1094. char buf[128];
  1095. int buf_size, ret;
  1096. /* Get userspace string and assure termination */
  1097. buf_size = min(count, (sizeof(buf)-1));
  1098. if (copy_from_user(buf, user_buf, buf_size))
  1099. return -EFAULT;
  1100. buf[buf_size] = 0;
  1101. /* get args and process */
  1102. ret = hwreg_common_write(buf, &hwreg_cfg, dev);
  1103. return (ret) ? ret : buf_size;
  1104. }
  1105. /*
  1106. * - irq subscribe/unsubscribe stuff
  1107. */
  1108. static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
  1109. {
  1110. seq_printf(s, "%d\n", irq_first);
  1111. return 0;
  1112. }
  1113. static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
  1114. struct file *file)
  1115. {
  1116. return single_open(file, ab8500_subscribe_unsubscribe_print,
  1117. inode->i_private);
  1118. }
  1119. /*
  1120. * Userspace should use poll() on this file. When an event occur
  1121. * the blocking poll will be released.
  1122. */
  1123. static ssize_t show_irq(struct device *dev,
  1124. struct device_attribute *attr, char *buf)
  1125. {
  1126. unsigned long name;
  1127. unsigned int irq_index;
  1128. int err;
  1129. err = strict_strtoul(attr->attr.name, 0, &name);
  1130. if (err)
  1131. return err;
  1132. irq_index = name - irq_first;
  1133. if (irq_index >= AB8500_NR_IRQS)
  1134. return -EINVAL;
  1135. else
  1136. return sprintf(buf, "%u\n", irq_count[irq_index]);
  1137. }
  1138. static ssize_t ab8500_subscribe_write(struct file *file,
  1139. const char __user *user_buf,
  1140. size_t count, loff_t *ppos)
  1141. {
  1142. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1143. char buf[32];
  1144. int buf_size;
  1145. unsigned long user_val;
  1146. int err;
  1147. unsigned int irq_index;
  1148. /* Get userspace string and assure termination */
  1149. buf_size = min(count, (sizeof(buf)-1));
  1150. if (copy_from_user(buf, user_buf, buf_size))
  1151. return -EFAULT;
  1152. buf[buf_size] = 0;
  1153. err = strict_strtoul(buf, 0, &user_val);
  1154. if (err)
  1155. return -EINVAL;
  1156. if (user_val < irq_first) {
  1157. dev_err(dev, "debugfs error input < %d\n", irq_first);
  1158. return -EINVAL;
  1159. }
  1160. if (user_val > irq_last) {
  1161. dev_err(dev, "debugfs error input > %d\n", irq_last);
  1162. return -EINVAL;
  1163. }
  1164. irq_index = user_val - irq_first;
  1165. if (irq_index >= AB8500_NR_IRQS)
  1166. return -EINVAL;
  1167. /*
  1168. * This will create a sysfs file named <irq-nr> which userspace can
  1169. * use to select or poll and get the AB8500 events
  1170. */
  1171. dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
  1172. GFP_KERNEL);
  1173. event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL);
  1174. sprintf(event_name[irq_index], "%lu", user_val);
  1175. dev_attr[irq_index]->show = show_irq;
  1176. dev_attr[irq_index]->store = NULL;
  1177. dev_attr[irq_index]->attr.name = event_name[irq_index];
  1178. dev_attr[irq_index]->attr.mode = S_IRUGO;
  1179. err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1180. if (err < 0) {
  1181. printk(KERN_ERR "sysfs_create_file failed %d\n", err);
  1182. return err;
  1183. }
  1184. err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
  1185. IRQF_SHARED | IRQF_NO_SUSPEND,
  1186. "ab8500-debug", &dev->kobj);
  1187. if (err < 0) {
  1188. printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
  1189. err, user_val);
  1190. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1191. return err;
  1192. }
  1193. return buf_size;
  1194. }
  1195. static ssize_t ab8500_unsubscribe_write(struct file *file,
  1196. const char __user *user_buf,
  1197. size_t count, loff_t *ppos)
  1198. {
  1199. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1200. char buf[32];
  1201. int buf_size;
  1202. unsigned long user_val;
  1203. int err;
  1204. unsigned int irq_index;
  1205. /* Get userspace string and assure termination */
  1206. buf_size = min(count, (sizeof(buf)-1));
  1207. if (copy_from_user(buf, user_buf, buf_size))
  1208. return -EFAULT;
  1209. buf[buf_size] = 0;
  1210. err = strict_strtoul(buf, 0, &user_val);
  1211. if (err)
  1212. return -EINVAL;
  1213. if (user_val < irq_first) {
  1214. dev_err(dev, "debugfs error input < %d\n", irq_first);
  1215. return -EINVAL;
  1216. }
  1217. if (user_val > irq_last) {
  1218. dev_err(dev, "debugfs error input > %d\n", irq_last);
  1219. return -EINVAL;
  1220. }
  1221. irq_index = user_val - irq_first;
  1222. if (irq_index >= AB8500_NR_IRQS)
  1223. return -EINVAL;
  1224. /* Set irq count to 0 when unsubscribe */
  1225. irq_count[irq_index] = 0;
  1226. if (dev_attr[irq_index])
  1227. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1228. free_irq(user_val, &dev->kobj);
  1229. kfree(event_name[irq_index]);
  1230. kfree(dev_attr[irq_index]);
  1231. return buf_size;
  1232. }
  1233. /*
  1234. * - several deubgfs nodes fops
  1235. */
  1236. static const struct file_operations ab8500_bank_fops = {
  1237. .open = ab8500_bank_open,
  1238. .write = ab8500_bank_write,
  1239. .read = seq_read,
  1240. .llseek = seq_lseek,
  1241. .release = single_release,
  1242. .owner = THIS_MODULE,
  1243. };
  1244. static const struct file_operations ab8500_address_fops = {
  1245. .open = ab8500_address_open,
  1246. .write = ab8500_address_write,
  1247. .read = seq_read,
  1248. .llseek = seq_lseek,
  1249. .release = single_release,
  1250. .owner = THIS_MODULE,
  1251. };
  1252. static const struct file_operations ab8500_val_fops = {
  1253. .open = ab8500_val_open,
  1254. .write = ab8500_val_write,
  1255. .read = seq_read,
  1256. .llseek = seq_lseek,
  1257. .release = single_release,
  1258. .owner = THIS_MODULE,
  1259. };
  1260. static const struct file_operations ab8500_subscribe_fops = {
  1261. .open = ab8500_subscribe_unsubscribe_open,
  1262. .write = ab8500_subscribe_write,
  1263. .read = seq_read,
  1264. .llseek = seq_lseek,
  1265. .release = single_release,
  1266. .owner = THIS_MODULE,
  1267. };
  1268. static const struct file_operations ab8500_unsubscribe_fops = {
  1269. .open = ab8500_subscribe_unsubscribe_open,
  1270. .write = ab8500_unsubscribe_write,
  1271. .read = seq_read,
  1272. .llseek = seq_lseek,
  1273. .release = single_release,
  1274. .owner = THIS_MODULE,
  1275. };
  1276. static const struct file_operations ab8500_hwreg_fops = {
  1277. .open = ab8500_hwreg_open,
  1278. .write = ab8500_hwreg_write,
  1279. .read = seq_read,
  1280. .llseek = seq_lseek,
  1281. .release = single_release,
  1282. .owner = THIS_MODULE,
  1283. };
  1284. static struct dentry *ab8500_dir;
  1285. static struct dentry *ab8500_gpadc_dir;
  1286. static int ab8500_debug_probe(struct platform_device *plf)
  1287. {
  1288. struct dentry *file;
  1289. debug_bank = AB8500_MISC;
  1290. debug_address = AB8500_REV_REG & 0x00FF;
  1291. irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
  1292. if (irq_first < 0) {
  1293. dev_err(&plf->dev, "First irq not found, err %d\n",
  1294. irq_first);
  1295. return irq_first;
  1296. }
  1297. irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
  1298. if (irq_last < 0) {
  1299. dev_err(&plf->dev, "Last irq not found, err %d\n",
  1300. irq_last);
  1301. return irq_last;
  1302. }
  1303. ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
  1304. if (!ab8500_dir)
  1305. goto err;
  1306. ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
  1307. ab8500_dir);
  1308. if (!ab8500_gpadc_dir)
  1309. goto err;
  1310. file = debugfs_create_file("all-bank-registers", S_IRUGO,
  1311. ab8500_dir, &plf->dev, &ab8500_registers_fops);
  1312. if (!file)
  1313. goto err;
  1314. file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
  1315. ab8500_dir, &plf->dev, &ab8500_bank_fops);
  1316. if (!file)
  1317. goto err;
  1318. file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR),
  1319. ab8500_dir, &plf->dev, &ab8500_address_fops);
  1320. if (!file)
  1321. goto err;
  1322. file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR),
  1323. ab8500_dir, &plf->dev, &ab8500_val_fops);
  1324. if (!file)
  1325. goto err;
  1326. file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR),
  1327. ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
  1328. if (!file)
  1329. goto err;
  1330. file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR),
  1331. ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
  1332. if (!file)
  1333. goto err;
  1334. file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR),
  1335. ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
  1336. if (!file)
  1337. goto err;
  1338. file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR),
  1339. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
  1340. if (!file)
  1341. goto err;
  1342. file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR),
  1343. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
  1344. if (!file)
  1345. goto err;
  1346. file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR),
  1347. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
  1348. if (!file)
  1349. goto err;
  1350. file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR),
  1351. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
  1352. if (!file)
  1353. goto err;
  1354. file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR),
  1355. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
  1356. if (!file)
  1357. goto err;
  1358. file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR),
  1359. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
  1360. if (!file)
  1361. goto err;
  1362. file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR),
  1363. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
  1364. if (!file)
  1365. goto err;
  1366. file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR),
  1367. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
  1368. if (!file)
  1369. goto err;
  1370. file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR),
  1371. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
  1372. if (!file)
  1373. goto err;
  1374. file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR),
  1375. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
  1376. if (!file)
  1377. goto err;
  1378. file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR),
  1379. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
  1380. if (!file)
  1381. goto err;
  1382. file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR),
  1383. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
  1384. if (!file)
  1385. goto err;
  1386. file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR),
  1387. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
  1388. if (!file)
  1389. goto err;
  1390. return 0;
  1391. err:
  1392. if (ab8500_dir)
  1393. debugfs_remove_recursive(ab8500_dir);
  1394. dev_err(&plf->dev, "failed to create debugfs entries.\n");
  1395. return -ENOMEM;
  1396. }
  1397. static int ab8500_debug_remove(struct platform_device *plf)
  1398. {
  1399. debugfs_remove_recursive(ab8500_dir);
  1400. return 0;
  1401. }
  1402. static struct platform_driver ab8500_debug_driver = {
  1403. .driver = {
  1404. .name = "ab8500-debug",
  1405. .owner = THIS_MODULE,
  1406. },
  1407. .probe = ab8500_debug_probe,
  1408. .remove = ab8500_debug_remove
  1409. };
  1410. static int __init ab8500_debug_init(void)
  1411. {
  1412. return platform_driver_register(&ab8500_debug_driver);
  1413. }
  1414. static void __exit ab8500_debug_exit(void)
  1415. {
  1416. platform_driver_unregister(&ab8500_debug_driver);
  1417. }
  1418. subsys_initcall(ab8500_debug_init);
  1419. module_exit(ab8500_debug_exit);
  1420. MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
  1421. MODULE_DESCRIPTION("AB8500 DEBUG");
  1422. MODULE_LICENSE("GPL v2");