ab8500-debugfs.c 48 KB

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