ab8500-debugfs.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  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/irq.h>
  83. #include <linux/mfd/abx500.h>
  84. #include <linux/mfd/abx500/ab8500.h>
  85. #include <linux/mfd/abx500/ab8500-gpadc.h>
  86. #ifdef CONFIG_DEBUG_FS
  87. #include <linux/string.h>
  88. #include <linux/ctype.h>
  89. #endif
  90. static u32 debug_bank;
  91. static u32 debug_address;
  92. static int irq_first;
  93. static int irq_last;
  94. static u32 *irq_count;
  95. static int num_irqs;
  96. static struct device_attribute **dev_attr;
  97. static char **event_name;
  98. static u8 avg_sample = SAMPLE_16;
  99. static u8 trig_edge = RISING_EDGE;
  100. static u8 conv_type = ADC_SW;
  101. static u8 trig_timer;
  102. /**
  103. * struct ab8500_reg_range
  104. * @first: the first address of the range
  105. * @last: the last address of the range
  106. * @perm: access permissions for the range
  107. */
  108. struct ab8500_reg_range {
  109. u8 first;
  110. u8 last;
  111. u8 perm;
  112. };
  113. /**
  114. * struct ab8500_prcmu_ranges
  115. * @num_ranges: the number of ranges in the list
  116. * @bankid: bank identifier
  117. * @range: the list of register ranges
  118. */
  119. struct ab8500_prcmu_ranges {
  120. u8 num_ranges;
  121. u8 bankid;
  122. const struct ab8500_reg_range *range;
  123. };
  124. /* hwreg- "mask" and "shift" entries ressources */
  125. struct hwreg_cfg {
  126. u32 bank; /* target bank */
  127. u32 addr; /* target address */
  128. uint fmt; /* format */
  129. uint mask; /* read/write mask, applied before any bit shift */
  130. int shift; /* bit shift (read:right shift, write:left shift */
  131. };
  132. /* fmt bit #0: 0=hexa, 1=dec */
  133. #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
  134. #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
  135. static struct hwreg_cfg hwreg_cfg = {
  136. .addr = 0, /* default: invalid phys addr */
  137. .fmt = 0, /* default: 32bit access, hex output */
  138. .mask = 0xFFFFFFFF, /* default: no mask */
  139. .shift = 0, /* default: no bit shift */
  140. };
  141. #define AB8500_NAME_STRING "ab8500"
  142. #define AB8500_ADC_NAME_STRING "gpadc"
  143. #define AB8500_NUM_BANKS 24
  144. #define AB8500_REV_REG 0x80
  145. static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
  146. [0x0] = {
  147. .num_ranges = 0,
  148. .range = NULL,
  149. },
  150. [AB8500_SYS_CTRL1_BLOCK] = {
  151. .num_ranges = 3,
  152. .range = (struct ab8500_reg_range[]) {
  153. {
  154. .first = 0x00,
  155. .last = 0x02,
  156. },
  157. {
  158. .first = 0x42,
  159. .last = 0x42,
  160. },
  161. {
  162. .first = 0x80,
  163. .last = 0x81,
  164. },
  165. },
  166. },
  167. [AB8500_SYS_CTRL2_BLOCK] = {
  168. .num_ranges = 4,
  169. .range = (struct ab8500_reg_range[]) {
  170. {
  171. .first = 0x00,
  172. .last = 0x0D,
  173. },
  174. {
  175. .first = 0x0F,
  176. .last = 0x17,
  177. },
  178. {
  179. .first = 0x30,
  180. .last = 0x30,
  181. },
  182. {
  183. .first = 0x32,
  184. .last = 0x33,
  185. },
  186. },
  187. },
  188. [AB8500_REGU_CTRL1] = {
  189. .num_ranges = 3,
  190. .range = (struct ab8500_reg_range[]) {
  191. {
  192. .first = 0x00,
  193. .last = 0x00,
  194. },
  195. {
  196. .first = 0x03,
  197. .last = 0x10,
  198. },
  199. {
  200. .first = 0x80,
  201. .last = 0x84,
  202. },
  203. },
  204. },
  205. [AB8500_REGU_CTRL2] = {
  206. .num_ranges = 5,
  207. .range = (struct ab8500_reg_range[]) {
  208. {
  209. .first = 0x00,
  210. .last = 0x15,
  211. },
  212. {
  213. .first = 0x17,
  214. .last = 0x19,
  215. },
  216. {
  217. .first = 0x1B,
  218. .last = 0x1D,
  219. },
  220. {
  221. .first = 0x1F,
  222. .last = 0x22,
  223. },
  224. {
  225. .first = 0x40,
  226. .last = 0x44,
  227. },
  228. /* 0x80-0x8B is SIM registers and should
  229. * not be accessed from here */
  230. },
  231. },
  232. [AB8500_USB] = {
  233. .num_ranges = 2,
  234. .range = (struct ab8500_reg_range[]) {
  235. {
  236. .first = 0x80,
  237. .last = 0x83,
  238. },
  239. {
  240. .first = 0x87,
  241. .last = 0x8A,
  242. },
  243. },
  244. },
  245. [AB8500_TVOUT] = {
  246. .num_ranges = 9,
  247. .range = (struct ab8500_reg_range[]) {
  248. {
  249. .first = 0x00,
  250. .last = 0x12,
  251. },
  252. {
  253. .first = 0x15,
  254. .last = 0x17,
  255. },
  256. {
  257. .first = 0x19,
  258. .last = 0x21,
  259. },
  260. {
  261. .first = 0x27,
  262. .last = 0x2C,
  263. },
  264. {
  265. .first = 0x41,
  266. .last = 0x41,
  267. },
  268. {
  269. .first = 0x45,
  270. .last = 0x5B,
  271. },
  272. {
  273. .first = 0x5D,
  274. .last = 0x5D,
  275. },
  276. {
  277. .first = 0x69,
  278. .last = 0x69,
  279. },
  280. {
  281. .first = 0x80,
  282. .last = 0x81,
  283. },
  284. },
  285. },
  286. [AB8500_DBI] = {
  287. .num_ranges = 0,
  288. .range = NULL,
  289. },
  290. [AB8500_ECI_AV_ACC] = {
  291. .num_ranges = 1,
  292. .range = (struct ab8500_reg_range[]) {
  293. {
  294. .first = 0x80,
  295. .last = 0x82,
  296. },
  297. },
  298. },
  299. [0x9] = {
  300. .num_ranges = 0,
  301. .range = NULL,
  302. },
  303. [AB8500_GPADC] = {
  304. .num_ranges = 1,
  305. .range = (struct ab8500_reg_range[]) {
  306. {
  307. .first = 0x00,
  308. .last = 0x08,
  309. },
  310. },
  311. },
  312. [AB8500_CHARGER] = {
  313. .num_ranges = 9,
  314. .range = (struct ab8500_reg_range[]) {
  315. {
  316. .first = 0x00,
  317. .last = 0x03,
  318. },
  319. {
  320. .first = 0x05,
  321. .last = 0x05,
  322. },
  323. {
  324. .first = 0x40,
  325. .last = 0x40,
  326. },
  327. {
  328. .first = 0x42,
  329. .last = 0x42,
  330. },
  331. {
  332. .first = 0x44,
  333. .last = 0x44,
  334. },
  335. {
  336. .first = 0x50,
  337. .last = 0x55,
  338. },
  339. {
  340. .first = 0x80,
  341. .last = 0x82,
  342. },
  343. {
  344. .first = 0xC0,
  345. .last = 0xC2,
  346. },
  347. {
  348. .first = 0xf5,
  349. .last = 0xf6,
  350. },
  351. },
  352. },
  353. [AB8500_GAS_GAUGE] = {
  354. .num_ranges = 3,
  355. .range = (struct ab8500_reg_range[]) {
  356. {
  357. .first = 0x00,
  358. .last = 0x00,
  359. },
  360. {
  361. .first = 0x07,
  362. .last = 0x0A,
  363. },
  364. {
  365. .first = 0x10,
  366. .last = 0x14,
  367. },
  368. },
  369. },
  370. [AB8500_DEVELOPMENT] = {
  371. .num_ranges = 1,
  372. .range = (struct ab8500_reg_range[]) {
  373. {
  374. .first = 0x00,
  375. .last = 0x00,
  376. },
  377. },
  378. },
  379. [AB8500_DEBUG] = {
  380. .num_ranges = 1,
  381. .range = (struct ab8500_reg_range[]) {
  382. {
  383. .first = 0x05,
  384. .last = 0x07,
  385. },
  386. },
  387. },
  388. [AB8500_AUDIO] = {
  389. .num_ranges = 1,
  390. .range = (struct ab8500_reg_range[]) {
  391. {
  392. .first = 0x00,
  393. .last = 0x6F,
  394. },
  395. },
  396. },
  397. [AB8500_INTERRUPT] = {
  398. .num_ranges = 0,
  399. .range = NULL,
  400. },
  401. [AB8500_RTC] = {
  402. .num_ranges = 1,
  403. .range = (struct ab8500_reg_range[]) {
  404. {
  405. .first = 0x00,
  406. .last = 0x0F,
  407. },
  408. },
  409. },
  410. [AB8500_MISC] = {
  411. .num_ranges = 8,
  412. .range = (struct ab8500_reg_range[]) {
  413. {
  414. .first = 0x00,
  415. .last = 0x05,
  416. },
  417. {
  418. .first = 0x10,
  419. .last = 0x15,
  420. },
  421. {
  422. .first = 0x20,
  423. .last = 0x25,
  424. },
  425. {
  426. .first = 0x30,
  427. .last = 0x35,
  428. },
  429. {
  430. .first = 0x40,
  431. .last = 0x45,
  432. },
  433. {
  434. .first = 0x50,
  435. .last = 0x50,
  436. },
  437. {
  438. .first = 0x60,
  439. .last = 0x67,
  440. },
  441. {
  442. .first = 0x80,
  443. .last = 0x80,
  444. },
  445. },
  446. },
  447. [0x11] = {
  448. .num_ranges = 0,
  449. .range = NULL,
  450. },
  451. [0x12] = {
  452. .num_ranges = 0,
  453. .range = NULL,
  454. },
  455. [0x13] = {
  456. .num_ranges = 0,
  457. .range = NULL,
  458. },
  459. [0x14] = {
  460. .num_ranges = 0,
  461. .range = NULL,
  462. },
  463. [AB8500_OTP_EMUL] = {
  464. .num_ranges = 1,
  465. .range = (struct ab8500_reg_range[]) {
  466. {
  467. .first = 0x01,
  468. .last = 0x0F,
  469. },
  470. },
  471. },
  472. };
  473. static irqreturn_t ab8500_debug_handler(int irq, void *data)
  474. {
  475. char buf[16];
  476. struct kobject *kobj = (struct kobject *)data;
  477. unsigned int irq_abb = irq - irq_first;
  478. if (irq_abb < num_irqs)
  479. irq_count[irq_abb]++;
  480. /*
  481. * This makes it possible to use poll for events (POLLPRI | POLLERR)
  482. * from userspace on sysfs file named <irq-nr>
  483. */
  484. sprintf(buf, "%d", irq);
  485. sysfs_notify(kobj, NULL, buf);
  486. return IRQ_HANDLED;
  487. }
  488. /* Prints to seq_file or log_buf */
  489. static int ab8500_registers_print(struct device *dev, u32 bank,
  490. struct seq_file *s)
  491. {
  492. unsigned int i;
  493. for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
  494. u32 reg;
  495. for (reg = debug_ranges[bank].range[i].first;
  496. reg <= debug_ranges[bank].range[i].last;
  497. reg++) {
  498. u8 value;
  499. int err;
  500. err = abx500_get_register_interruptible(dev,
  501. (u8)bank, (u8)reg, &value);
  502. if (err < 0) {
  503. dev_err(dev, "ab->read fail %d\n", err);
  504. return err;
  505. }
  506. if (s) {
  507. err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
  508. bank, reg, value);
  509. if (err < 0) {
  510. dev_err(dev,
  511. "seq_printf overflow bank=0x%02X reg=0x%02X\n",
  512. bank, reg);
  513. /* Error is not returned here since
  514. * the output is wanted in any case */
  515. return 0;
  516. }
  517. } else {
  518. printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
  519. bank, reg, value);
  520. }
  521. }
  522. }
  523. return 0;
  524. }
  525. static int ab8500_print_bank_registers(struct seq_file *s, void *p)
  526. {
  527. struct device *dev = s->private;
  528. u32 bank = debug_bank;
  529. seq_printf(s, AB8500_NAME_STRING " register values:\n");
  530. seq_printf(s, " bank 0x%02X:\n", bank);
  531. ab8500_registers_print(dev, bank, s);
  532. return 0;
  533. }
  534. static int ab8500_registers_open(struct inode *inode, struct file *file)
  535. {
  536. return single_open(file, ab8500_print_bank_registers, inode->i_private);
  537. }
  538. static const struct file_operations ab8500_registers_fops = {
  539. .open = ab8500_registers_open,
  540. .read = seq_read,
  541. .llseek = seq_lseek,
  542. .release = single_release,
  543. .owner = THIS_MODULE,
  544. };
  545. static int ab8500_print_all_banks(struct seq_file *s, void *p)
  546. {
  547. struct device *dev = s->private;
  548. unsigned int i;
  549. int err;
  550. seq_printf(s, AB8500_NAME_STRING " register values:\n");
  551. for (i = 1; i < AB8500_NUM_BANKS; i++) {
  552. err = seq_printf(s, " bank 0x%02X:\n", i);
  553. if (err < 0)
  554. dev_err(dev, "seq_printf overflow, bank=0x%02X\n", i);
  555. ab8500_registers_print(dev, i, s);
  556. }
  557. return 0;
  558. }
  559. /* Dump registers to kernel log */
  560. void ab8500_dump_all_banks(struct device *dev)
  561. {
  562. unsigned int i;
  563. printk(KERN_INFO"ab8500 register values:\n");
  564. for (i = 1; i < AB8500_NUM_BANKS; i++) {
  565. printk(KERN_INFO" bank 0x%02X:\n", i);
  566. ab8500_registers_print(dev, i, NULL);
  567. }
  568. }
  569. /* Space for 500 registers. */
  570. #define DUMP_MAX_REGS 700
  571. struct ab8500_register_dump
  572. {
  573. u8 bank;
  574. u8 reg;
  575. u8 value;
  576. } ab8500_complete_register_dump[DUMP_MAX_REGS];
  577. extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
  578. /* This shall only be called upon kernel panic! */
  579. void ab8500_dump_all_banks_to_mem(void)
  580. {
  581. int i, r = 0;
  582. u8 bank;
  583. int err = 0;
  584. pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" "
  585. "for crash analyze.\n");
  586. for (bank = 1; bank < AB8500_NUM_BANKS; bank++) {
  587. for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
  588. u8 reg;
  589. for (reg = debug_ranges[bank].range[i].first;
  590. reg <= debug_ranges[bank].range[i].last;
  591. reg++) {
  592. u8 value;
  593. err = prcmu_abb_read(bank, reg, &value, 1);
  594. if (err < 0)
  595. goto out;
  596. ab8500_complete_register_dump[r].bank = bank;
  597. ab8500_complete_register_dump[r].reg = reg;
  598. ab8500_complete_register_dump[r].value = value;
  599. r++;
  600. if (r >= DUMP_MAX_REGS) {
  601. pr_err("%s: too many register to dump!\n",
  602. __func__);
  603. err = -EINVAL;
  604. goto out;
  605. }
  606. }
  607. }
  608. }
  609. out:
  610. if (err >= 0)
  611. pr_info("Saved all ABB registers.\n");
  612. else
  613. pr_info("Failed to save all ABB registers.\n");
  614. }
  615. static int ab8500_all_banks_open(struct inode *inode, struct file *file)
  616. {
  617. struct seq_file *s;
  618. int err;
  619. err = single_open(file, ab8500_print_all_banks, inode->i_private);
  620. if (!err) {
  621. /* Default buf size in seq_read is not enough */
  622. s = (struct seq_file *)file->private_data;
  623. s->size = (PAGE_SIZE * 2);
  624. s->buf = kmalloc(s->size, GFP_KERNEL);
  625. if (!s->buf) {
  626. single_release(inode, file);
  627. err = -ENOMEM;
  628. }
  629. }
  630. return err;
  631. }
  632. static const struct file_operations ab8500_all_banks_fops = {
  633. .open = ab8500_all_banks_open,
  634. .read = seq_read,
  635. .llseek = seq_lseek,
  636. .release = single_release,
  637. .owner = THIS_MODULE,
  638. };
  639. static int ab8500_bank_print(struct seq_file *s, void *p)
  640. {
  641. return seq_printf(s, "0x%02X\n", debug_bank);
  642. }
  643. static int ab8500_bank_open(struct inode *inode, struct file *file)
  644. {
  645. return single_open(file, ab8500_bank_print, inode->i_private);
  646. }
  647. static ssize_t ab8500_bank_write(struct file *file,
  648. const char __user *user_buf,
  649. size_t count, loff_t *ppos)
  650. {
  651. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  652. unsigned long user_bank;
  653. int err;
  654. /* Get userspace string and assure termination */
  655. err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
  656. if (err)
  657. return err;
  658. if (user_bank >= AB8500_NUM_BANKS) {
  659. dev_err(dev, "debugfs error input > number of banks\n");
  660. return -EINVAL;
  661. }
  662. debug_bank = user_bank;
  663. return count;
  664. }
  665. static int ab8500_address_print(struct seq_file *s, void *p)
  666. {
  667. return seq_printf(s, "0x%02X\n", debug_address);
  668. }
  669. static int ab8500_address_open(struct inode *inode, struct file *file)
  670. {
  671. return single_open(file, ab8500_address_print, inode->i_private);
  672. }
  673. static ssize_t ab8500_address_write(struct file *file,
  674. const char __user *user_buf,
  675. size_t count, loff_t *ppos)
  676. {
  677. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  678. unsigned long user_address;
  679. int err;
  680. /* Get userspace string and assure termination */
  681. err = kstrtoul_from_user(user_buf, count, 0, &user_address);
  682. if (err)
  683. return err;
  684. if (user_address > 0xff) {
  685. dev_err(dev, "debugfs error input > 0xff\n");
  686. return -EINVAL;
  687. }
  688. debug_address = user_address;
  689. return count;
  690. }
  691. static int ab8500_val_print(struct seq_file *s, void *p)
  692. {
  693. struct device *dev = s->private;
  694. int ret;
  695. u8 regvalue;
  696. ret = abx500_get_register_interruptible(dev,
  697. (u8)debug_bank, (u8)debug_address, &regvalue);
  698. if (ret < 0) {
  699. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  700. ret, __LINE__);
  701. return -EINVAL;
  702. }
  703. seq_printf(s, "0x%02X\n", regvalue);
  704. return 0;
  705. }
  706. static int ab8500_val_open(struct inode *inode, struct file *file)
  707. {
  708. return single_open(file, ab8500_val_print, inode->i_private);
  709. }
  710. static ssize_t ab8500_val_write(struct file *file,
  711. const char __user *user_buf,
  712. size_t count, loff_t *ppos)
  713. {
  714. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  715. unsigned long user_val;
  716. int err;
  717. /* Get userspace string and assure termination */
  718. err = kstrtoul_from_user(user_buf, count, 0, &user_val);
  719. if (err)
  720. return err;
  721. if (user_val > 0xff) {
  722. dev_err(dev, "debugfs error input > 0xff\n");
  723. return -EINVAL;
  724. }
  725. err = abx500_set_register_interruptible(dev,
  726. (u8)debug_bank, debug_address, (u8)user_val);
  727. if (err < 0) {
  728. printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
  729. return -EINVAL;
  730. }
  731. return count;
  732. }
  733. /*
  734. * Interrupt status
  735. */
  736. static u32 num_interrupts[AB8500_MAX_NR_IRQS];
  737. static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
  738. static int num_interrupt_lines;
  739. bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
  740. {
  741. return false;
  742. }
  743. void ab8500_debug_register_interrupt(int line)
  744. {
  745. if (line < num_interrupt_lines) {
  746. num_interrupts[line]++;
  747. if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500))
  748. num_wake_interrupts[line]++;
  749. }
  750. }
  751. static int ab8500_interrupts_print(struct seq_file *s, void *p)
  752. {
  753. int line;
  754. seq_printf(s, "name: number: number of: wake:\n");
  755. for (line = 0; line < num_interrupt_lines; line++) {
  756. struct irq_desc *desc = irq_to_desc(line + irq_first);
  757. struct irqaction *action = desc->action;
  758. seq_printf(s, "%3i: %6i %4i", line,
  759. num_interrupts[line],
  760. num_wake_interrupts[line]);
  761. if (desc && desc->name)
  762. seq_printf(s, "-%-8s", desc->name);
  763. if (action) {
  764. seq_printf(s, " %s", action->name);
  765. while ((action = action->next) != NULL)
  766. seq_printf(s, ", %s", action->name);
  767. }
  768. seq_putc(s, '\n');
  769. }
  770. return 0;
  771. }
  772. static int ab8500_interrupts_open(struct inode *inode, struct file *file)
  773. {
  774. return single_open(file, ab8500_interrupts_print, inode->i_private);
  775. }
  776. /*
  777. * - HWREG DB8500 formated routines
  778. */
  779. static int ab8500_hwreg_print(struct seq_file *s, void *d)
  780. {
  781. struct device *dev = s->private;
  782. int ret;
  783. u8 regvalue;
  784. ret = abx500_get_register_interruptible(dev,
  785. (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
  786. if (ret < 0) {
  787. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  788. ret, __LINE__);
  789. return -EINVAL;
  790. }
  791. if (hwreg_cfg.shift >= 0)
  792. regvalue >>= hwreg_cfg.shift;
  793. else
  794. regvalue <<= -hwreg_cfg.shift;
  795. regvalue &= hwreg_cfg.mask;
  796. if (REG_FMT_DEC(&hwreg_cfg))
  797. seq_printf(s, "%d\n", regvalue);
  798. else
  799. seq_printf(s, "0x%02X\n", regvalue);
  800. return 0;
  801. }
  802. static int ab8500_hwreg_open(struct inode *inode, struct file *file)
  803. {
  804. return single_open(file, ab8500_hwreg_print, inode->i_private);
  805. }
  806. static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
  807. {
  808. int bat_ctrl_raw;
  809. int bat_ctrl_convert;
  810. struct ab8500_gpadc *gpadc;
  811. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  812. bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
  813. avg_sample, trig_edge, trig_timer, conv_type);
  814. bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  815. BAT_CTRL, bat_ctrl_raw);
  816. return seq_printf(s, "%d,0x%X\n",
  817. bat_ctrl_convert, bat_ctrl_raw);
  818. }
  819. static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
  820. {
  821. return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
  822. }
  823. static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
  824. .open = ab8500_gpadc_bat_ctrl_open,
  825. .read = seq_read,
  826. .llseek = seq_lseek,
  827. .release = single_release,
  828. .owner = THIS_MODULE,
  829. };
  830. static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
  831. {
  832. int btemp_ball_raw;
  833. int btemp_ball_convert;
  834. struct ab8500_gpadc *gpadc;
  835. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  836. btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
  837. avg_sample, trig_edge, trig_timer, conv_type);
  838. btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
  839. btemp_ball_raw);
  840. return seq_printf(s,
  841. "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
  842. }
  843. static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
  844. struct file *file)
  845. {
  846. return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
  847. }
  848. static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
  849. .open = ab8500_gpadc_btemp_ball_open,
  850. .read = seq_read,
  851. .llseek = seq_lseek,
  852. .release = single_release,
  853. .owner = THIS_MODULE,
  854. };
  855. static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
  856. {
  857. int main_charger_v_raw;
  858. int main_charger_v_convert;
  859. struct ab8500_gpadc *gpadc;
  860. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  861. main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
  862. avg_sample, trig_edge, trig_timer, conv_type);
  863. main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  864. MAIN_CHARGER_V, main_charger_v_raw);
  865. return seq_printf(s, "%d,0x%X\n",
  866. main_charger_v_convert, main_charger_v_raw);
  867. }
  868. static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
  869. struct file *file)
  870. {
  871. return single_open(file, ab8500_gpadc_main_charger_v_print,
  872. inode->i_private);
  873. }
  874. static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
  875. .open = ab8500_gpadc_main_charger_v_open,
  876. .read = seq_read,
  877. .llseek = seq_lseek,
  878. .release = single_release,
  879. .owner = THIS_MODULE,
  880. };
  881. static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
  882. {
  883. int acc_detect1_raw;
  884. int acc_detect1_convert;
  885. struct ab8500_gpadc *gpadc;
  886. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  887. acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
  888. avg_sample, trig_edge, trig_timer, conv_type);
  889. acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
  890. acc_detect1_raw);
  891. return seq_printf(s, "%d,0x%X\n",
  892. acc_detect1_convert, acc_detect1_raw);
  893. }
  894. static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
  895. struct file *file)
  896. {
  897. return single_open(file, ab8500_gpadc_acc_detect1_print,
  898. inode->i_private);
  899. }
  900. static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
  901. .open = ab8500_gpadc_acc_detect1_open,
  902. .read = seq_read,
  903. .llseek = seq_lseek,
  904. .release = single_release,
  905. .owner = THIS_MODULE,
  906. };
  907. static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
  908. {
  909. int acc_detect2_raw;
  910. int acc_detect2_convert;
  911. struct ab8500_gpadc *gpadc;
  912. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  913. acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
  914. avg_sample, trig_edge, trig_timer, conv_type);
  915. acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  916. ACC_DETECT2, acc_detect2_raw);
  917. return seq_printf(s, "%d,0x%X\n",
  918. acc_detect2_convert, acc_detect2_raw);
  919. }
  920. static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
  921. struct file *file)
  922. {
  923. return single_open(file, ab8500_gpadc_acc_detect2_print,
  924. inode->i_private);
  925. }
  926. static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
  927. .open = ab8500_gpadc_acc_detect2_open,
  928. .read = seq_read,
  929. .llseek = seq_lseek,
  930. .release = single_release,
  931. .owner = THIS_MODULE,
  932. };
  933. static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
  934. {
  935. int aux1_raw;
  936. int aux1_convert;
  937. struct ab8500_gpadc *gpadc;
  938. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  939. aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
  940. avg_sample, trig_edge, trig_timer, conv_type);
  941. aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
  942. aux1_raw);
  943. return seq_printf(s, "%d,0x%X\n",
  944. aux1_convert, aux1_raw);
  945. }
  946. static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
  947. {
  948. return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
  949. }
  950. static const struct file_operations ab8500_gpadc_aux1_fops = {
  951. .open = ab8500_gpadc_aux1_open,
  952. .read = seq_read,
  953. .llseek = seq_lseek,
  954. .release = single_release,
  955. .owner = THIS_MODULE,
  956. };
  957. static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
  958. {
  959. int aux2_raw;
  960. int aux2_convert;
  961. struct ab8500_gpadc *gpadc;
  962. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  963. aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
  964. avg_sample, trig_edge, trig_timer, conv_type);
  965. aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
  966. aux2_raw);
  967. return seq_printf(s, "%d,0x%X\n",
  968. aux2_convert, aux2_raw);
  969. }
  970. static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
  971. {
  972. return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
  973. }
  974. static const struct file_operations ab8500_gpadc_aux2_fops = {
  975. .open = ab8500_gpadc_aux2_open,
  976. .read = seq_read,
  977. .llseek = seq_lseek,
  978. .release = single_release,
  979. .owner = THIS_MODULE,
  980. };
  981. static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
  982. {
  983. int main_bat_v_raw;
  984. int main_bat_v_convert;
  985. struct ab8500_gpadc *gpadc;
  986. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  987. main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
  988. avg_sample, trig_edge, trig_timer, conv_type);
  989. main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
  990. main_bat_v_raw);
  991. return seq_printf(s, "%d,0x%X\n",
  992. main_bat_v_convert, main_bat_v_raw);
  993. }
  994. static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
  995. struct file *file)
  996. {
  997. return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
  998. }
  999. static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
  1000. .open = ab8500_gpadc_main_bat_v_open,
  1001. .read = seq_read,
  1002. .llseek = seq_lseek,
  1003. .release = single_release,
  1004. .owner = THIS_MODULE,
  1005. };
  1006. static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
  1007. {
  1008. int vbus_v_raw;
  1009. int vbus_v_convert;
  1010. struct ab8500_gpadc *gpadc;
  1011. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1012. vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
  1013. avg_sample, trig_edge, trig_timer, conv_type);
  1014. vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
  1015. vbus_v_raw);
  1016. return seq_printf(s, "%d,0x%X\n",
  1017. vbus_v_convert, vbus_v_raw);
  1018. }
  1019. static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
  1020. {
  1021. return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
  1022. }
  1023. static const struct file_operations ab8500_gpadc_vbus_v_fops = {
  1024. .open = ab8500_gpadc_vbus_v_open,
  1025. .read = seq_read,
  1026. .llseek = seq_lseek,
  1027. .release = single_release,
  1028. .owner = THIS_MODULE,
  1029. };
  1030. static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
  1031. {
  1032. int main_charger_c_raw;
  1033. int main_charger_c_convert;
  1034. struct ab8500_gpadc *gpadc;
  1035. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1036. main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
  1037. avg_sample, trig_edge, trig_timer, conv_type);
  1038. main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1039. MAIN_CHARGER_C, main_charger_c_raw);
  1040. return seq_printf(s, "%d,0x%X\n",
  1041. main_charger_c_convert, main_charger_c_raw);
  1042. }
  1043. static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
  1044. struct file *file)
  1045. {
  1046. return single_open(file, ab8500_gpadc_main_charger_c_print,
  1047. inode->i_private);
  1048. }
  1049. static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
  1050. .open = ab8500_gpadc_main_charger_c_open,
  1051. .read = seq_read,
  1052. .llseek = seq_lseek,
  1053. .release = single_release,
  1054. .owner = THIS_MODULE,
  1055. };
  1056. static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
  1057. {
  1058. int usb_charger_c_raw;
  1059. int usb_charger_c_convert;
  1060. struct ab8500_gpadc *gpadc;
  1061. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1062. usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
  1063. avg_sample, trig_edge, trig_timer, conv_type);
  1064. usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1065. USB_CHARGER_C, usb_charger_c_raw);
  1066. return seq_printf(s, "%d,0x%X\n",
  1067. usb_charger_c_convert, usb_charger_c_raw);
  1068. }
  1069. static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
  1070. struct file *file)
  1071. {
  1072. return single_open(file, ab8500_gpadc_usb_charger_c_print,
  1073. inode->i_private);
  1074. }
  1075. static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
  1076. .open = ab8500_gpadc_usb_charger_c_open,
  1077. .read = seq_read,
  1078. .llseek = seq_lseek,
  1079. .release = single_release,
  1080. .owner = THIS_MODULE,
  1081. };
  1082. static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
  1083. {
  1084. int bk_bat_v_raw;
  1085. int bk_bat_v_convert;
  1086. struct ab8500_gpadc *gpadc;
  1087. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1088. bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
  1089. avg_sample, trig_edge, trig_timer, conv_type);
  1090. bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1091. BK_BAT_V, bk_bat_v_raw);
  1092. return seq_printf(s, "%d,0x%X\n",
  1093. bk_bat_v_convert, bk_bat_v_raw);
  1094. }
  1095. static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
  1096. {
  1097. return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
  1098. }
  1099. static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
  1100. .open = ab8500_gpadc_bk_bat_v_open,
  1101. .read = seq_read,
  1102. .llseek = seq_lseek,
  1103. .release = single_release,
  1104. .owner = THIS_MODULE,
  1105. };
  1106. static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
  1107. {
  1108. int die_temp_raw;
  1109. int die_temp_convert;
  1110. struct ab8500_gpadc *gpadc;
  1111. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1112. die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
  1113. avg_sample, trig_edge, trig_timer, conv_type);
  1114. die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
  1115. die_temp_raw);
  1116. return seq_printf(s, "%d,0x%X\n",
  1117. die_temp_convert, die_temp_raw);
  1118. }
  1119. static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
  1120. {
  1121. return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
  1122. }
  1123. static const struct file_operations ab8500_gpadc_die_temp_fops = {
  1124. .open = ab8500_gpadc_die_temp_open,
  1125. .read = seq_read,
  1126. .llseek = seq_lseek,
  1127. .release = single_release,
  1128. .owner = THIS_MODULE,
  1129. };
  1130. static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
  1131. {
  1132. return seq_printf(s, "%d\n", avg_sample);
  1133. }
  1134. static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
  1135. {
  1136. return single_open(file, ab8500_gpadc_avg_sample_print,
  1137. inode->i_private);
  1138. }
  1139. static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
  1140. const char __user *user_buf,
  1141. size_t count, loff_t *ppos)
  1142. {
  1143. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1144. char buf[32];
  1145. int buf_size;
  1146. unsigned long user_avg_sample;
  1147. int err;
  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_avg_sample);
  1154. if (err)
  1155. return -EINVAL;
  1156. if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
  1157. || (user_avg_sample == SAMPLE_8)
  1158. || (user_avg_sample == SAMPLE_16)) {
  1159. avg_sample = (u8) user_avg_sample;
  1160. } else {
  1161. dev_err(dev, "debugfs error input: "
  1162. "should be egal to 1, 4, 8 or 16\n");
  1163. return -EINVAL;
  1164. }
  1165. return buf_size;
  1166. }
  1167. static const struct file_operations ab8500_gpadc_avg_sample_fops = {
  1168. .open = ab8500_gpadc_avg_sample_open,
  1169. .read = seq_read,
  1170. .write = ab8500_gpadc_avg_sample_write,
  1171. .llseek = seq_lseek,
  1172. .release = single_release,
  1173. .owner = THIS_MODULE,
  1174. };
  1175. static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
  1176. {
  1177. return seq_printf(s, "%d\n", trig_edge);
  1178. }
  1179. static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
  1180. {
  1181. return single_open(file, ab8500_gpadc_trig_edge_print,
  1182. inode->i_private);
  1183. }
  1184. static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
  1185. const char __user *user_buf,
  1186. size_t count, loff_t *ppos)
  1187. {
  1188. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1189. char buf[32];
  1190. int buf_size;
  1191. unsigned long user_trig_edge;
  1192. int err;
  1193. /* Get userspace string and assure termination */
  1194. buf_size = min(count, (sizeof(buf) - 1));
  1195. if (copy_from_user(buf, user_buf, buf_size))
  1196. return -EFAULT;
  1197. buf[buf_size] = 0;
  1198. err = strict_strtoul(buf, 0, &user_trig_edge);
  1199. if (err)
  1200. return -EINVAL;
  1201. if ((user_trig_edge == RISING_EDGE)
  1202. || (user_trig_edge == FALLING_EDGE)) {
  1203. trig_edge = (u8) user_trig_edge;
  1204. } else {
  1205. dev_err(dev, "Wrong input:\n"
  1206. "Enter 0. Rising edge\n"
  1207. "Enter 1. Falling edge\n");
  1208. return -EINVAL;
  1209. }
  1210. return buf_size;
  1211. }
  1212. static const struct file_operations ab8500_gpadc_trig_edge_fops = {
  1213. .open = ab8500_gpadc_trig_edge_open,
  1214. .read = seq_read,
  1215. .write = ab8500_gpadc_trig_edge_write,
  1216. .llseek = seq_lseek,
  1217. .release = single_release,
  1218. .owner = THIS_MODULE,
  1219. };
  1220. static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
  1221. {
  1222. return seq_printf(s, "%d\n", trig_timer);
  1223. }
  1224. static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
  1225. {
  1226. return single_open(file, ab8500_gpadc_trig_timer_print,
  1227. inode->i_private);
  1228. }
  1229. static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
  1230. const char __user *user_buf,
  1231. size_t count, loff_t *ppos)
  1232. {
  1233. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1234. char buf[32];
  1235. int buf_size;
  1236. unsigned long user_trig_timer;
  1237. int err;
  1238. /* Get userspace string and assure termination */
  1239. buf_size = min(count, (sizeof(buf) - 1));
  1240. if (copy_from_user(buf, user_buf, buf_size))
  1241. return -EFAULT;
  1242. buf[buf_size] = 0;
  1243. err = strict_strtoul(buf, 0, &user_trig_timer);
  1244. if (err)
  1245. return -EINVAL;
  1246. if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
  1247. trig_timer = (u8) user_trig_timer;
  1248. } else {
  1249. dev_err(dev, "debugfs error input: "
  1250. "should be beetween 0 to 255\n");
  1251. return -EINVAL;
  1252. }
  1253. return buf_size;
  1254. }
  1255. static const struct file_operations ab8500_gpadc_trig_timer_fops = {
  1256. .open = ab8500_gpadc_trig_timer_open,
  1257. .read = seq_read,
  1258. .write = ab8500_gpadc_trig_timer_write,
  1259. .llseek = seq_lseek,
  1260. .release = single_release,
  1261. .owner = THIS_MODULE,
  1262. };
  1263. static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
  1264. {
  1265. return seq_printf(s, "%d\n", conv_type);
  1266. }
  1267. static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
  1268. {
  1269. return single_open(file, ab8500_gpadc_conv_type_print,
  1270. inode->i_private);
  1271. }
  1272. static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
  1273. const char __user *user_buf,
  1274. size_t count, loff_t *ppos)
  1275. {
  1276. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1277. char buf[32];
  1278. int buf_size;
  1279. unsigned long user_conv_type;
  1280. int err;
  1281. /* Get userspace string and assure termination */
  1282. buf_size = min(count, (sizeof(buf) - 1));
  1283. if (copy_from_user(buf, user_buf, buf_size))
  1284. return -EFAULT;
  1285. buf[buf_size] = 0;
  1286. err = strict_strtoul(buf, 0, &user_conv_type);
  1287. if (err)
  1288. return -EINVAL;
  1289. if ((user_conv_type == ADC_SW)
  1290. || (user_conv_type == ADC_HW)) {
  1291. conv_type = (u8) user_conv_type;
  1292. } else {
  1293. dev_err(dev, "Wrong input:\n"
  1294. "Enter 0. ADC SW conversion\n"
  1295. "Enter 1. ADC HW conversion\n");
  1296. return -EINVAL;
  1297. }
  1298. return buf_size;
  1299. }
  1300. static const struct file_operations ab8500_gpadc_conv_type_fops = {
  1301. .open = ab8500_gpadc_conv_type_open,
  1302. .read = seq_read,
  1303. .write = ab8500_gpadc_conv_type_write,
  1304. .llseek = seq_lseek,
  1305. .release = single_release,
  1306. .owner = THIS_MODULE,
  1307. };
  1308. /*
  1309. * return length of an ASCII numerical value, 0 is string is not a
  1310. * numerical value.
  1311. * string shall start at value 1st char.
  1312. * string can be tailed with \0 or space or newline chars only.
  1313. * value can be decimal or hexadecimal (prefixed 0x or 0X).
  1314. */
  1315. static int strval_len(char *b)
  1316. {
  1317. char *s = b;
  1318. if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
  1319. s += 2;
  1320. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  1321. if (!isxdigit(*s))
  1322. return 0;
  1323. }
  1324. } else {
  1325. if (*s == '-')
  1326. s++;
  1327. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  1328. if (!isdigit(*s))
  1329. return 0;
  1330. }
  1331. }
  1332. return (int) (s-b);
  1333. }
  1334. /*
  1335. * parse hwreg input data.
  1336. * update global hwreg_cfg only if input data syntax is ok.
  1337. */
  1338. static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
  1339. struct device *dev)
  1340. {
  1341. uint write, val = 0;
  1342. u8 regvalue;
  1343. int ret;
  1344. struct hwreg_cfg loc = {
  1345. .bank = 0, /* default: invalid phys addr */
  1346. .addr = 0, /* default: invalid phys addr */
  1347. .fmt = 0, /* default: 32bit access, hex output */
  1348. .mask = 0xFFFFFFFF, /* default: no mask */
  1349. .shift = 0, /* default: no bit shift */
  1350. };
  1351. /* read or write ? */
  1352. if (!strncmp(b, "read ", 5)) {
  1353. write = 0;
  1354. b += 5;
  1355. } else if (!strncmp(b, "write ", 6)) {
  1356. write = 1;
  1357. b += 6;
  1358. } else
  1359. return -EINVAL;
  1360. /* OPTIONS -l|-w|-b -s -m -o */
  1361. while ((*b == ' ') || (*b == '-')) {
  1362. if (*(b-1) != ' ') {
  1363. b++;
  1364. continue;
  1365. }
  1366. if ((!strncmp(b, "-d ", 3)) ||
  1367. (!strncmp(b, "-dec ", 5))) {
  1368. b += (*(b+2) == ' ') ? 3 : 5;
  1369. loc.fmt |= (1<<0);
  1370. } else if ((!strncmp(b, "-h ", 3)) ||
  1371. (!strncmp(b, "-hex ", 5))) {
  1372. b += (*(b+2) == ' ') ? 3 : 5;
  1373. loc.fmt &= ~(1<<0);
  1374. } else if ((!strncmp(b, "-m ", 3)) ||
  1375. (!strncmp(b, "-mask ", 6))) {
  1376. b += (*(b+2) == ' ') ? 3 : 6;
  1377. if (strval_len(b) == 0)
  1378. return -EINVAL;
  1379. loc.mask = simple_strtoul(b, &b, 0);
  1380. } else if ((!strncmp(b, "-s ", 3)) ||
  1381. (!strncmp(b, "-shift ", 7))) {
  1382. b += (*(b+2) == ' ') ? 3 : 7;
  1383. if (strval_len(b) == 0)
  1384. return -EINVAL;
  1385. loc.shift = simple_strtol(b, &b, 0);
  1386. } else {
  1387. return -EINVAL;
  1388. }
  1389. }
  1390. /* get arg BANK and ADDRESS */
  1391. if (strval_len(b) == 0)
  1392. return -EINVAL;
  1393. loc.bank = simple_strtoul(b, &b, 0);
  1394. while (*b == ' ')
  1395. b++;
  1396. if (strval_len(b) == 0)
  1397. return -EINVAL;
  1398. loc.addr = simple_strtoul(b, &b, 0);
  1399. if (write) {
  1400. while (*b == ' ')
  1401. b++;
  1402. if (strval_len(b) == 0)
  1403. return -EINVAL;
  1404. val = simple_strtoul(b, &b, 0);
  1405. }
  1406. /* args are ok, update target cfg (mainly for read) */
  1407. *cfg = loc;
  1408. #ifdef ABB_HWREG_DEBUG
  1409. pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
  1410. "value=0x%X\n", (write) ? "write" : "read",
  1411. REG_FMT_DEC(cfg) ? "decimal" : "hexa",
  1412. cfg->addr, cfg->mask, cfg->shift, val);
  1413. #endif
  1414. if (!write)
  1415. return 0;
  1416. ret = abx500_get_register_interruptible(dev,
  1417. (u8)cfg->bank, (u8)cfg->addr, &regvalue);
  1418. if (ret < 0) {
  1419. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  1420. ret, __LINE__);
  1421. return -EINVAL;
  1422. }
  1423. if (cfg->shift >= 0) {
  1424. regvalue &= ~(cfg->mask << (cfg->shift));
  1425. val = (val & cfg->mask) << (cfg->shift);
  1426. } else {
  1427. regvalue &= ~(cfg->mask >> (-cfg->shift));
  1428. val = (val & cfg->mask) >> (-cfg->shift);
  1429. }
  1430. val = val | regvalue;
  1431. ret = abx500_set_register_interruptible(dev,
  1432. (u8)cfg->bank, (u8)cfg->addr, (u8)val);
  1433. if (ret < 0) {
  1434. pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
  1435. return -EINVAL;
  1436. }
  1437. return 0;
  1438. }
  1439. static ssize_t ab8500_hwreg_write(struct file *file,
  1440. const char __user *user_buf, size_t count, loff_t *ppos)
  1441. {
  1442. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1443. char buf[128];
  1444. int buf_size, ret;
  1445. /* Get userspace string and assure termination */
  1446. buf_size = min(count, (sizeof(buf)-1));
  1447. if (copy_from_user(buf, user_buf, buf_size))
  1448. return -EFAULT;
  1449. buf[buf_size] = 0;
  1450. /* get args and process */
  1451. ret = hwreg_common_write(buf, &hwreg_cfg, dev);
  1452. return (ret) ? ret : buf_size;
  1453. }
  1454. /*
  1455. * - irq subscribe/unsubscribe stuff
  1456. */
  1457. static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
  1458. {
  1459. seq_printf(s, "%d\n", irq_first);
  1460. return 0;
  1461. }
  1462. static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
  1463. struct file *file)
  1464. {
  1465. return single_open(file, ab8500_subscribe_unsubscribe_print,
  1466. inode->i_private);
  1467. }
  1468. /*
  1469. * Userspace should use poll() on this file. When an event occur
  1470. * the blocking poll will be released.
  1471. */
  1472. static ssize_t show_irq(struct device *dev,
  1473. struct device_attribute *attr, char *buf)
  1474. {
  1475. unsigned long name;
  1476. unsigned int irq_index;
  1477. int err;
  1478. err = strict_strtoul(attr->attr.name, 0, &name);
  1479. if (err)
  1480. return err;
  1481. irq_index = name - irq_first;
  1482. if (irq_index >= num_irqs)
  1483. return -EINVAL;
  1484. else
  1485. return sprintf(buf, "%u\n", irq_count[irq_index]);
  1486. }
  1487. static ssize_t ab8500_subscribe_write(struct file *file,
  1488. const char __user *user_buf,
  1489. size_t count, loff_t *ppos)
  1490. {
  1491. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1492. char buf[32];
  1493. int buf_size;
  1494. unsigned long user_val;
  1495. int err;
  1496. unsigned int irq_index;
  1497. /* Get userspace string and assure termination */
  1498. buf_size = min(count, (sizeof(buf)-1));
  1499. if (copy_from_user(buf, user_buf, buf_size))
  1500. return -EFAULT;
  1501. buf[buf_size] = 0;
  1502. err = strict_strtoul(buf, 0, &user_val);
  1503. if (err)
  1504. return -EINVAL;
  1505. if (user_val < irq_first) {
  1506. dev_err(dev, "debugfs error input < %d\n", irq_first);
  1507. return -EINVAL;
  1508. }
  1509. if (user_val > irq_last) {
  1510. dev_err(dev, "debugfs error input > %d\n", irq_last);
  1511. return -EINVAL;
  1512. }
  1513. irq_index = user_val - irq_first;
  1514. if (irq_index >= num_irqs)
  1515. return -EINVAL;
  1516. /*
  1517. * This will create a sysfs file named <irq-nr> which userspace can
  1518. * use to select or poll and get the AB8500 events
  1519. */
  1520. dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
  1521. GFP_KERNEL);
  1522. event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL);
  1523. sprintf(event_name[irq_index], "%lu", user_val);
  1524. dev_attr[irq_index]->show = show_irq;
  1525. dev_attr[irq_index]->store = NULL;
  1526. dev_attr[irq_index]->attr.name = event_name[irq_index];
  1527. dev_attr[irq_index]->attr.mode = S_IRUGO;
  1528. err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1529. if (err < 0) {
  1530. printk(KERN_ERR "sysfs_create_file failed %d\n", err);
  1531. return err;
  1532. }
  1533. err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
  1534. IRQF_SHARED | IRQF_NO_SUSPEND,
  1535. "ab8500-debug", &dev->kobj);
  1536. if (err < 0) {
  1537. printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
  1538. err, user_val);
  1539. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1540. return err;
  1541. }
  1542. return buf_size;
  1543. }
  1544. static ssize_t ab8500_unsubscribe_write(struct file *file,
  1545. const char __user *user_buf,
  1546. size_t count, loff_t *ppos)
  1547. {
  1548. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1549. char buf[32];
  1550. int buf_size;
  1551. unsigned long user_val;
  1552. int err;
  1553. unsigned int irq_index;
  1554. /* Get userspace string and assure termination */
  1555. buf_size = min(count, (sizeof(buf)-1));
  1556. if (copy_from_user(buf, user_buf, buf_size))
  1557. return -EFAULT;
  1558. buf[buf_size] = 0;
  1559. err = strict_strtoul(buf, 0, &user_val);
  1560. if (err)
  1561. return -EINVAL;
  1562. if (user_val < irq_first) {
  1563. dev_err(dev, "debugfs error input < %d\n", irq_first);
  1564. return -EINVAL;
  1565. }
  1566. if (user_val > irq_last) {
  1567. dev_err(dev, "debugfs error input > %d\n", irq_last);
  1568. return -EINVAL;
  1569. }
  1570. irq_index = user_val - irq_first;
  1571. if (irq_index >= num_irqs)
  1572. return -EINVAL;
  1573. /* Set irq count to 0 when unsubscribe */
  1574. irq_count[irq_index] = 0;
  1575. if (dev_attr[irq_index])
  1576. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1577. free_irq(user_val, &dev->kobj);
  1578. kfree(event_name[irq_index]);
  1579. kfree(dev_attr[irq_index]);
  1580. return buf_size;
  1581. }
  1582. /*
  1583. * - several deubgfs nodes fops
  1584. */
  1585. static const struct file_operations ab8500_bank_fops = {
  1586. .open = ab8500_bank_open,
  1587. .write = ab8500_bank_write,
  1588. .read = seq_read,
  1589. .llseek = seq_lseek,
  1590. .release = single_release,
  1591. .owner = THIS_MODULE,
  1592. };
  1593. static const struct file_operations ab8500_address_fops = {
  1594. .open = ab8500_address_open,
  1595. .write = ab8500_address_write,
  1596. .read = seq_read,
  1597. .llseek = seq_lseek,
  1598. .release = single_release,
  1599. .owner = THIS_MODULE,
  1600. };
  1601. static const struct file_operations ab8500_val_fops = {
  1602. .open = ab8500_val_open,
  1603. .write = ab8500_val_write,
  1604. .read = seq_read,
  1605. .llseek = seq_lseek,
  1606. .release = single_release,
  1607. .owner = THIS_MODULE,
  1608. };
  1609. static const struct file_operations ab8500_interrupts_fops = {
  1610. .open = ab8500_interrupts_open,
  1611. .read = seq_read,
  1612. .llseek = seq_lseek,
  1613. .release = single_release,
  1614. .owner = THIS_MODULE,
  1615. };
  1616. static const struct file_operations ab8500_subscribe_fops = {
  1617. .open = ab8500_subscribe_unsubscribe_open,
  1618. .write = ab8500_subscribe_write,
  1619. .read = seq_read,
  1620. .llseek = seq_lseek,
  1621. .release = single_release,
  1622. .owner = THIS_MODULE,
  1623. };
  1624. static const struct file_operations ab8500_unsubscribe_fops = {
  1625. .open = ab8500_subscribe_unsubscribe_open,
  1626. .write = ab8500_unsubscribe_write,
  1627. .read = seq_read,
  1628. .llseek = seq_lseek,
  1629. .release = single_release,
  1630. .owner = THIS_MODULE,
  1631. };
  1632. static const struct file_operations ab8500_hwreg_fops = {
  1633. .open = ab8500_hwreg_open,
  1634. .write = ab8500_hwreg_write,
  1635. .read = seq_read,
  1636. .llseek = seq_lseek,
  1637. .release = single_release,
  1638. .owner = THIS_MODULE,
  1639. };
  1640. static struct dentry *ab8500_dir;
  1641. static struct dentry *ab8500_gpadc_dir;
  1642. static int ab8500_debug_probe(struct platform_device *plf)
  1643. {
  1644. struct dentry *file;
  1645. int ret = -ENOMEM;
  1646. struct ab8500 *ab8500;
  1647. debug_bank = AB8500_MISC;
  1648. debug_address = AB8500_REV_REG & 0x00FF;
  1649. ab8500 = dev_get_drvdata(plf->dev.parent);
  1650. num_irqs = ab8500->mask_size;
  1651. irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
  1652. if (!irq_count)
  1653. return -ENOMEM;
  1654. dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
  1655. if (!dev_attr)
  1656. goto out_freeirq_count;
  1657. event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
  1658. if (!event_name)
  1659. goto out_freedev_attr;
  1660. irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
  1661. if (irq_first < 0) {
  1662. dev_err(&plf->dev, "First irq not found, err %d\n",
  1663. irq_first);
  1664. ret = irq_first;
  1665. goto out_freeevent_name;
  1666. }
  1667. irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
  1668. if (irq_last < 0) {
  1669. dev_err(&plf->dev, "Last irq not found, err %d\n",
  1670. irq_last);
  1671. ret = irq_last;
  1672. goto out_freeevent_name;
  1673. }
  1674. ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
  1675. if (!ab8500_dir)
  1676. goto err;
  1677. ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
  1678. ab8500_dir);
  1679. if (!ab8500_gpadc_dir)
  1680. goto err;
  1681. file = debugfs_create_file("all-bank-registers", S_IRUGO,
  1682. ab8500_dir, &plf->dev, &ab8500_registers_fops);
  1683. if (!file)
  1684. goto err;
  1685. file = debugfs_create_file("all-banks", S_IRUGO,
  1686. ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
  1687. if (!file)
  1688. goto err;
  1689. file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
  1690. ab8500_dir, &plf->dev, &ab8500_bank_fops);
  1691. if (!file)
  1692. goto err;
  1693. file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR),
  1694. ab8500_dir, &plf->dev, &ab8500_address_fops);
  1695. if (!file)
  1696. goto err;
  1697. file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR),
  1698. ab8500_dir, &plf->dev, &ab8500_val_fops);
  1699. if (!file)
  1700. goto err;
  1701. file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR),
  1702. ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
  1703. if (!file)
  1704. goto err;
  1705. if (is_ab8500(ab8500))
  1706. num_interrupt_lines = AB8500_NR_IRQS;
  1707. else if (is_ab8505(ab8500))
  1708. num_interrupt_lines = AB8505_NR_IRQS;
  1709. else if (is_ab9540(ab8500))
  1710. num_interrupt_lines = AB9540_NR_IRQS;
  1711. file = debugfs_create_file("interrupts", (S_IRUGO),
  1712. ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
  1713. if (!file)
  1714. goto err;
  1715. file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR),
  1716. ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
  1717. if (!file)
  1718. goto err;
  1719. file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR),
  1720. ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
  1721. if (!file)
  1722. goto err;
  1723. file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR),
  1724. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
  1725. if (!file)
  1726. goto err;
  1727. file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR),
  1728. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
  1729. if (!file)
  1730. goto err;
  1731. file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR),
  1732. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
  1733. if (!file)
  1734. goto err;
  1735. file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR),
  1736. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
  1737. if (!file)
  1738. goto err;
  1739. file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR),
  1740. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
  1741. if (!file)
  1742. goto err;
  1743. file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR),
  1744. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
  1745. if (!file)
  1746. goto err;
  1747. file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR),
  1748. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
  1749. if (!file)
  1750. goto err;
  1751. file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR),
  1752. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
  1753. if (!file)
  1754. goto err;
  1755. file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR),
  1756. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
  1757. if (!file)
  1758. goto err;
  1759. file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR),
  1760. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
  1761. if (!file)
  1762. goto err;
  1763. file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR),
  1764. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
  1765. if (!file)
  1766. goto err;
  1767. file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR),
  1768. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
  1769. if (!file)
  1770. goto err;
  1771. file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR),
  1772. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
  1773. if (!file)
  1774. goto err;
  1775. file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUGO),
  1776. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
  1777. if (!file)
  1778. goto err;
  1779. file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUGO),
  1780. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
  1781. if (!file)
  1782. goto err;
  1783. file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUGO),
  1784. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
  1785. if (!file)
  1786. goto err;
  1787. file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUGO),
  1788. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
  1789. if (!file)
  1790. goto err;
  1791. return 0;
  1792. err:
  1793. if (ab8500_dir)
  1794. debugfs_remove_recursive(ab8500_dir);
  1795. dev_err(&plf->dev, "failed to create debugfs entries.\n");
  1796. out_freeevent_name:
  1797. kfree(event_name);
  1798. out_freedev_attr:
  1799. kfree(dev_attr);
  1800. out_freeirq_count:
  1801. kfree(irq_count);
  1802. return ret;
  1803. }
  1804. static int ab8500_debug_remove(struct platform_device *plf)
  1805. {
  1806. debugfs_remove_recursive(ab8500_dir);
  1807. kfree(event_name);
  1808. kfree(dev_attr);
  1809. kfree(irq_count);
  1810. return 0;
  1811. }
  1812. static struct platform_driver ab8500_debug_driver = {
  1813. .driver = {
  1814. .name = "ab8500-debug",
  1815. .owner = THIS_MODULE,
  1816. },
  1817. .probe = ab8500_debug_probe,
  1818. .remove = ab8500_debug_remove
  1819. };
  1820. static int __init ab8500_debug_init(void)
  1821. {
  1822. return platform_driver_register(&ab8500_debug_driver);
  1823. }
  1824. static void __exit ab8500_debug_exit(void)
  1825. {
  1826. platform_driver_unregister(&ab8500_debug_driver);
  1827. }
  1828. subsys_initcall(ab8500_debug_init);
  1829. module_exit(ab8500_debug_exit);
  1830. MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
  1831. MODULE_DESCRIPTION("AB8500 DEBUG");
  1832. MODULE_LICENSE("GPL v2");