ab8500-debugfs.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  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, " [%u/0x%02X]: 0x%02X\n",
  507. bank, reg, value);
  508. if (err < 0) {
  509. dev_err(dev,
  510. "seq_printf overflow bank=%d reg=%d\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" [%u/0x%02X]: 0x%02X\n", bank,
  518. 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 %u:\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 %u:\n", i);
  552. if (err < 0)
  553. dev_err(dev, "seq_printf overflow, bank=%d\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 %u:\n", i);
  565. ab8500_registers_print(dev, i, NULL);
  566. }
  567. }
  568. static int ab8500_all_banks_open(struct inode *inode, struct file *file)
  569. {
  570. struct seq_file *s;
  571. int err;
  572. err = single_open(file, ab8500_print_all_banks, inode->i_private);
  573. if (!err) {
  574. /* Default buf size in seq_read is not enough */
  575. s = (struct seq_file *)file->private_data;
  576. s->size = (PAGE_SIZE * 2);
  577. s->buf = kmalloc(s->size, GFP_KERNEL);
  578. if (!s->buf) {
  579. single_release(inode, file);
  580. err = -ENOMEM;
  581. }
  582. }
  583. return err;
  584. }
  585. static const struct file_operations ab8500_all_banks_fops = {
  586. .open = ab8500_all_banks_open,
  587. .read = seq_read,
  588. .llseek = seq_lseek,
  589. .release = single_release,
  590. .owner = THIS_MODULE,
  591. };
  592. static int ab8500_bank_print(struct seq_file *s, void *p)
  593. {
  594. return seq_printf(s, "%d\n", debug_bank);
  595. }
  596. static int ab8500_bank_open(struct inode *inode, struct file *file)
  597. {
  598. return single_open(file, ab8500_bank_print, inode->i_private);
  599. }
  600. static ssize_t ab8500_bank_write(struct file *file,
  601. const char __user *user_buf,
  602. size_t count, loff_t *ppos)
  603. {
  604. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  605. unsigned long user_bank;
  606. int err;
  607. /* Get userspace string and assure termination */
  608. err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
  609. if (err)
  610. return err;
  611. if (user_bank >= AB8500_NUM_BANKS) {
  612. dev_err(dev, "debugfs error input > number of banks\n");
  613. return -EINVAL;
  614. }
  615. debug_bank = user_bank;
  616. return count;
  617. }
  618. static int ab8500_address_print(struct seq_file *s, void *p)
  619. {
  620. return seq_printf(s, "0x%02X\n", debug_address);
  621. }
  622. static int ab8500_address_open(struct inode *inode, struct file *file)
  623. {
  624. return single_open(file, ab8500_address_print, inode->i_private);
  625. }
  626. static ssize_t ab8500_address_write(struct file *file,
  627. const char __user *user_buf,
  628. size_t count, loff_t *ppos)
  629. {
  630. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  631. unsigned long user_address;
  632. int err;
  633. /* Get userspace string and assure termination */
  634. err = kstrtoul_from_user(user_buf, count, 0, &user_address);
  635. if (err)
  636. return err;
  637. if (user_address > 0xff) {
  638. dev_err(dev, "debugfs error input > 0xff\n");
  639. return -EINVAL;
  640. }
  641. debug_address = user_address;
  642. return count;
  643. }
  644. static int ab8500_val_print(struct seq_file *s, void *p)
  645. {
  646. struct device *dev = s->private;
  647. int ret;
  648. u8 regvalue;
  649. ret = abx500_get_register_interruptible(dev,
  650. (u8)debug_bank, (u8)debug_address, &regvalue);
  651. if (ret < 0) {
  652. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  653. ret, __LINE__);
  654. return -EINVAL;
  655. }
  656. seq_printf(s, "0x%02X\n", regvalue);
  657. return 0;
  658. }
  659. static int ab8500_val_open(struct inode *inode, struct file *file)
  660. {
  661. return single_open(file, ab8500_val_print, inode->i_private);
  662. }
  663. static ssize_t ab8500_val_write(struct file *file,
  664. const char __user *user_buf,
  665. size_t count, loff_t *ppos)
  666. {
  667. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  668. unsigned long user_val;
  669. int err;
  670. /* Get userspace string and assure termination */
  671. err = kstrtoul_from_user(user_buf, count, 0, &user_val);
  672. if (err)
  673. return err;
  674. if (user_val > 0xff) {
  675. dev_err(dev, "debugfs error input > 0xff\n");
  676. return -EINVAL;
  677. }
  678. err = abx500_set_register_interruptible(dev,
  679. (u8)debug_bank, debug_address, (u8)user_val);
  680. if (err < 0) {
  681. printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
  682. return -EINVAL;
  683. }
  684. return count;
  685. }
  686. /*
  687. * Interrupt status
  688. */
  689. static u32 num_interrupts[AB8500_MAX_NR_IRQS];
  690. static int num_interrupt_lines;
  691. void ab8500_debug_register_interrupt(int line)
  692. {
  693. if (line < num_interrupt_lines)
  694. num_interrupts[line]++;
  695. }
  696. static int ab8500_interrupts_print(struct seq_file *s, void *p)
  697. {
  698. int line;
  699. seq_printf(s, "irq: number of\n");
  700. for (line = 0; line < num_interrupt_lines; line++)
  701. seq_printf(s, "%3i: %6i\n", line, num_interrupts[line]);
  702. return 0;
  703. }
  704. static int ab8500_interrupts_open(struct inode *inode, struct file *file)
  705. {
  706. return single_open(file, ab8500_interrupts_print, inode->i_private);
  707. }
  708. /*
  709. * - HWREG DB8500 formated routines
  710. */
  711. static int ab8500_hwreg_print(struct seq_file *s, void *d)
  712. {
  713. struct device *dev = s->private;
  714. int ret;
  715. u8 regvalue;
  716. ret = abx500_get_register_interruptible(dev,
  717. (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
  718. if (ret < 0) {
  719. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  720. ret, __LINE__);
  721. return -EINVAL;
  722. }
  723. if (hwreg_cfg.shift >= 0)
  724. regvalue >>= hwreg_cfg.shift;
  725. else
  726. regvalue <<= -hwreg_cfg.shift;
  727. regvalue &= hwreg_cfg.mask;
  728. if (REG_FMT_DEC(&hwreg_cfg))
  729. seq_printf(s, "%d\n", regvalue);
  730. else
  731. seq_printf(s, "0x%02X\n", regvalue);
  732. return 0;
  733. }
  734. static int ab8500_hwreg_open(struct inode *inode, struct file *file)
  735. {
  736. return single_open(file, ab8500_hwreg_print, inode->i_private);
  737. }
  738. static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
  739. {
  740. int bat_ctrl_raw;
  741. int bat_ctrl_convert;
  742. struct ab8500_gpadc *gpadc;
  743. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  744. bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
  745. avg_sample, trig_edge, trig_timer, conv_type);
  746. bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  747. BAT_CTRL, bat_ctrl_raw);
  748. return seq_printf(s, "%d,0x%X\n",
  749. bat_ctrl_convert, bat_ctrl_raw);
  750. }
  751. static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
  752. {
  753. return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
  754. }
  755. static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
  756. .open = ab8500_gpadc_bat_ctrl_open,
  757. .read = seq_read,
  758. .llseek = seq_lseek,
  759. .release = single_release,
  760. .owner = THIS_MODULE,
  761. };
  762. static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
  763. {
  764. int btemp_ball_raw;
  765. int btemp_ball_convert;
  766. struct ab8500_gpadc *gpadc;
  767. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  768. btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
  769. avg_sample, trig_edge, trig_timer, conv_type);
  770. btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
  771. btemp_ball_raw);
  772. return seq_printf(s,
  773. "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
  774. }
  775. static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
  776. struct file *file)
  777. {
  778. return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
  779. }
  780. static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
  781. .open = ab8500_gpadc_btemp_ball_open,
  782. .read = seq_read,
  783. .llseek = seq_lseek,
  784. .release = single_release,
  785. .owner = THIS_MODULE,
  786. };
  787. static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
  788. {
  789. int main_charger_v_raw;
  790. int main_charger_v_convert;
  791. struct ab8500_gpadc *gpadc;
  792. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  793. main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
  794. avg_sample, trig_edge, trig_timer, conv_type);
  795. main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  796. MAIN_CHARGER_V, main_charger_v_raw);
  797. return seq_printf(s, "%d,0x%X\n",
  798. main_charger_v_convert, main_charger_v_raw);
  799. }
  800. static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
  801. struct file *file)
  802. {
  803. return single_open(file, ab8500_gpadc_main_charger_v_print,
  804. inode->i_private);
  805. }
  806. static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
  807. .open = ab8500_gpadc_main_charger_v_open,
  808. .read = seq_read,
  809. .llseek = seq_lseek,
  810. .release = single_release,
  811. .owner = THIS_MODULE,
  812. };
  813. static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
  814. {
  815. int acc_detect1_raw;
  816. int acc_detect1_convert;
  817. struct ab8500_gpadc *gpadc;
  818. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  819. acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
  820. avg_sample, trig_edge, trig_timer, conv_type);
  821. acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
  822. acc_detect1_raw);
  823. return seq_printf(s, "%d,0x%X\n",
  824. acc_detect1_convert, acc_detect1_raw);
  825. }
  826. static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
  827. struct file *file)
  828. {
  829. return single_open(file, ab8500_gpadc_acc_detect1_print,
  830. inode->i_private);
  831. }
  832. static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
  833. .open = ab8500_gpadc_acc_detect1_open,
  834. .read = seq_read,
  835. .llseek = seq_lseek,
  836. .release = single_release,
  837. .owner = THIS_MODULE,
  838. };
  839. static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
  840. {
  841. int acc_detect2_raw;
  842. int acc_detect2_convert;
  843. struct ab8500_gpadc *gpadc;
  844. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  845. acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
  846. avg_sample, trig_edge, trig_timer, conv_type);
  847. acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  848. ACC_DETECT2, acc_detect2_raw);
  849. return seq_printf(s, "%d,0x%X\n",
  850. acc_detect2_convert, acc_detect2_raw);
  851. }
  852. static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
  853. struct file *file)
  854. {
  855. return single_open(file, ab8500_gpadc_acc_detect2_print,
  856. inode->i_private);
  857. }
  858. static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
  859. .open = ab8500_gpadc_acc_detect2_open,
  860. .read = seq_read,
  861. .llseek = seq_lseek,
  862. .release = single_release,
  863. .owner = THIS_MODULE,
  864. };
  865. static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
  866. {
  867. int aux1_raw;
  868. int aux1_convert;
  869. struct ab8500_gpadc *gpadc;
  870. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  871. aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
  872. avg_sample, trig_edge, trig_timer, conv_type);
  873. aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
  874. aux1_raw);
  875. return seq_printf(s, "%d,0x%X\n",
  876. aux1_convert, aux1_raw);
  877. }
  878. static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
  879. {
  880. return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
  881. }
  882. static const struct file_operations ab8500_gpadc_aux1_fops = {
  883. .open = ab8500_gpadc_aux1_open,
  884. .read = seq_read,
  885. .llseek = seq_lseek,
  886. .release = single_release,
  887. .owner = THIS_MODULE,
  888. };
  889. static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
  890. {
  891. int aux2_raw;
  892. int aux2_convert;
  893. struct ab8500_gpadc *gpadc;
  894. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  895. aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
  896. avg_sample, trig_edge, trig_timer, conv_type);
  897. aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
  898. aux2_raw);
  899. return seq_printf(s, "%d,0x%X\n",
  900. aux2_convert, aux2_raw);
  901. }
  902. static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
  903. {
  904. return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
  905. }
  906. static const struct file_operations ab8500_gpadc_aux2_fops = {
  907. .open = ab8500_gpadc_aux2_open,
  908. .read = seq_read,
  909. .llseek = seq_lseek,
  910. .release = single_release,
  911. .owner = THIS_MODULE,
  912. };
  913. static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
  914. {
  915. int main_bat_v_raw;
  916. int main_bat_v_convert;
  917. struct ab8500_gpadc *gpadc;
  918. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  919. main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
  920. avg_sample, trig_edge, trig_timer, conv_type);
  921. main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
  922. main_bat_v_raw);
  923. return seq_printf(s, "%d,0x%X\n",
  924. main_bat_v_convert, main_bat_v_raw);
  925. }
  926. static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
  927. struct file *file)
  928. {
  929. return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
  930. }
  931. static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
  932. .open = ab8500_gpadc_main_bat_v_open,
  933. .read = seq_read,
  934. .llseek = seq_lseek,
  935. .release = single_release,
  936. .owner = THIS_MODULE,
  937. };
  938. static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
  939. {
  940. int vbus_v_raw;
  941. int vbus_v_convert;
  942. struct ab8500_gpadc *gpadc;
  943. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  944. vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
  945. avg_sample, trig_edge, trig_timer, conv_type);
  946. vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
  947. vbus_v_raw);
  948. return seq_printf(s, "%d,0x%X\n",
  949. vbus_v_convert, vbus_v_raw);
  950. }
  951. static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
  952. {
  953. return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
  954. }
  955. static const struct file_operations ab8500_gpadc_vbus_v_fops = {
  956. .open = ab8500_gpadc_vbus_v_open,
  957. .read = seq_read,
  958. .llseek = seq_lseek,
  959. .release = single_release,
  960. .owner = THIS_MODULE,
  961. };
  962. static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
  963. {
  964. int main_charger_c_raw;
  965. int main_charger_c_convert;
  966. struct ab8500_gpadc *gpadc;
  967. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  968. main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
  969. avg_sample, trig_edge, trig_timer, conv_type);
  970. main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  971. MAIN_CHARGER_C, main_charger_c_raw);
  972. return seq_printf(s, "%d,0x%X\n",
  973. main_charger_c_convert, main_charger_c_raw);
  974. }
  975. static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
  976. struct file *file)
  977. {
  978. return single_open(file, ab8500_gpadc_main_charger_c_print,
  979. inode->i_private);
  980. }
  981. static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
  982. .open = ab8500_gpadc_main_charger_c_open,
  983. .read = seq_read,
  984. .llseek = seq_lseek,
  985. .release = single_release,
  986. .owner = THIS_MODULE,
  987. };
  988. static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
  989. {
  990. int usb_charger_c_raw;
  991. int usb_charger_c_convert;
  992. struct ab8500_gpadc *gpadc;
  993. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  994. usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
  995. avg_sample, trig_edge, trig_timer, conv_type);
  996. usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  997. USB_CHARGER_C, usb_charger_c_raw);
  998. return seq_printf(s, "%d,0x%X\n",
  999. usb_charger_c_convert, usb_charger_c_raw);
  1000. }
  1001. static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
  1002. struct file *file)
  1003. {
  1004. return single_open(file, ab8500_gpadc_usb_charger_c_print,
  1005. inode->i_private);
  1006. }
  1007. static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
  1008. .open = ab8500_gpadc_usb_charger_c_open,
  1009. .read = seq_read,
  1010. .llseek = seq_lseek,
  1011. .release = single_release,
  1012. .owner = THIS_MODULE,
  1013. };
  1014. static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
  1015. {
  1016. int bk_bat_v_raw;
  1017. int bk_bat_v_convert;
  1018. struct ab8500_gpadc *gpadc;
  1019. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1020. bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
  1021. avg_sample, trig_edge, trig_timer, conv_type);
  1022. bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1023. BK_BAT_V, bk_bat_v_raw);
  1024. return seq_printf(s, "%d,0x%X\n",
  1025. bk_bat_v_convert, bk_bat_v_raw);
  1026. }
  1027. static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
  1028. {
  1029. return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
  1030. }
  1031. static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
  1032. .open = ab8500_gpadc_bk_bat_v_open,
  1033. .read = seq_read,
  1034. .llseek = seq_lseek,
  1035. .release = single_release,
  1036. .owner = THIS_MODULE,
  1037. };
  1038. static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
  1039. {
  1040. int die_temp_raw;
  1041. int die_temp_convert;
  1042. struct ab8500_gpadc *gpadc;
  1043. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1044. die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
  1045. avg_sample, trig_edge, trig_timer, conv_type);
  1046. die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
  1047. die_temp_raw);
  1048. return seq_printf(s, "%d,0x%X\n",
  1049. die_temp_convert, die_temp_raw);
  1050. }
  1051. static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
  1052. {
  1053. return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
  1054. }
  1055. static const struct file_operations ab8500_gpadc_die_temp_fops = {
  1056. .open = ab8500_gpadc_die_temp_open,
  1057. .read = seq_read,
  1058. .llseek = seq_lseek,
  1059. .release = single_release,
  1060. .owner = THIS_MODULE,
  1061. };
  1062. static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
  1063. {
  1064. return seq_printf(s, "%d\n", avg_sample);
  1065. }
  1066. static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
  1067. {
  1068. return single_open(file, ab8500_gpadc_avg_sample_print,
  1069. inode->i_private);
  1070. }
  1071. static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
  1072. const char __user *user_buf,
  1073. size_t count, loff_t *ppos)
  1074. {
  1075. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1076. char buf[32];
  1077. int buf_size;
  1078. unsigned long user_avg_sample;
  1079. int err;
  1080. /* Get userspace string and assure termination */
  1081. buf_size = min(count, (sizeof(buf) - 1));
  1082. if (copy_from_user(buf, user_buf, buf_size))
  1083. return -EFAULT;
  1084. buf[buf_size] = 0;
  1085. err = strict_strtoul(buf, 0, &user_avg_sample);
  1086. if (err)
  1087. return -EINVAL;
  1088. if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
  1089. || (user_avg_sample == SAMPLE_8)
  1090. || (user_avg_sample == SAMPLE_16)) {
  1091. avg_sample = (u8) user_avg_sample;
  1092. } else {
  1093. dev_err(dev, "debugfs error input: "
  1094. "should be egal to 1, 4, 8 or 16\n");
  1095. return -EINVAL;
  1096. }
  1097. return buf_size;
  1098. }
  1099. static const struct file_operations ab8500_gpadc_avg_sample_fops = {
  1100. .open = ab8500_gpadc_avg_sample_open,
  1101. .read = seq_read,
  1102. .write = ab8500_gpadc_avg_sample_write,
  1103. .llseek = seq_lseek,
  1104. .release = single_release,
  1105. .owner = THIS_MODULE,
  1106. };
  1107. static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
  1108. {
  1109. return seq_printf(s, "%d\n", trig_edge);
  1110. }
  1111. static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
  1112. {
  1113. return single_open(file, ab8500_gpadc_trig_edge_print,
  1114. inode->i_private);
  1115. }
  1116. static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
  1117. const char __user *user_buf,
  1118. size_t count, loff_t *ppos)
  1119. {
  1120. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1121. char buf[32];
  1122. int buf_size;
  1123. unsigned long user_trig_edge;
  1124. int err;
  1125. /* Get userspace string and assure termination */
  1126. buf_size = min(count, (sizeof(buf) - 1));
  1127. if (copy_from_user(buf, user_buf, buf_size))
  1128. return -EFAULT;
  1129. buf[buf_size] = 0;
  1130. err = strict_strtoul(buf, 0, &user_trig_edge);
  1131. if (err)
  1132. return -EINVAL;
  1133. if ((user_trig_edge == RISING_EDGE)
  1134. || (user_trig_edge == FALLING_EDGE)) {
  1135. trig_edge = (u8) user_trig_edge;
  1136. } else {
  1137. dev_err(dev, "Wrong input:\n"
  1138. "Enter 0. Rising edge\n"
  1139. "Enter 1. Falling edge\n");
  1140. return -EINVAL;
  1141. }
  1142. return buf_size;
  1143. }
  1144. static const struct file_operations ab8500_gpadc_trig_edge_fops = {
  1145. .open = ab8500_gpadc_trig_edge_open,
  1146. .read = seq_read,
  1147. .write = ab8500_gpadc_trig_edge_write,
  1148. .llseek = seq_lseek,
  1149. .release = single_release,
  1150. .owner = THIS_MODULE,
  1151. };
  1152. static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
  1153. {
  1154. return seq_printf(s, "%d\n", trig_timer);
  1155. }
  1156. static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
  1157. {
  1158. return single_open(file, ab8500_gpadc_trig_timer_print,
  1159. inode->i_private);
  1160. }
  1161. static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
  1162. const char __user *user_buf,
  1163. size_t count, loff_t *ppos)
  1164. {
  1165. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1166. char buf[32];
  1167. int buf_size;
  1168. unsigned long user_trig_timer;
  1169. int err;
  1170. /* Get userspace string and assure termination */
  1171. buf_size = min(count, (sizeof(buf) - 1));
  1172. if (copy_from_user(buf, user_buf, buf_size))
  1173. return -EFAULT;
  1174. buf[buf_size] = 0;
  1175. err = strict_strtoul(buf, 0, &user_trig_timer);
  1176. if (err)
  1177. return -EINVAL;
  1178. if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
  1179. trig_timer = (u8) user_trig_timer;
  1180. } else {
  1181. dev_err(dev, "debugfs error input: "
  1182. "should be beetween 0 to 255\n");
  1183. return -EINVAL;
  1184. }
  1185. return buf_size;
  1186. }
  1187. static const struct file_operations ab8500_gpadc_trig_timer_fops = {
  1188. .open = ab8500_gpadc_trig_timer_open,
  1189. .read = seq_read,
  1190. .write = ab8500_gpadc_trig_timer_write,
  1191. .llseek = seq_lseek,
  1192. .release = single_release,
  1193. .owner = THIS_MODULE,
  1194. };
  1195. static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
  1196. {
  1197. return seq_printf(s, "%d\n", conv_type);
  1198. }
  1199. static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
  1200. {
  1201. return single_open(file, ab8500_gpadc_conv_type_print,
  1202. inode->i_private);
  1203. }
  1204. static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
  1205. const char __user *user_buf,
  1206. size_t count, loff_t *ppos)
  1207. {
  1208. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1209. char buf[32];
  1210. int buf_size;
  1211. unsigned long user_conv_type;
  1212. int err;
  1213. /* Get userspace string and assure termination */
  1214. buf_size = min(count, (sizeof(buf) - 1));
  1215. if (copy_from_user(buf, user_buf, buf_size))
  1216. return -EFAULT;
  1217. buf[buf_size] = 0;
  1218. err = strict_strtoul(buf, 0, &user_conv_type);
  1219. if (err)
  1220. return -EINVAL;
  1221. if ((user_conv_type == ADC_SW)
  1222. || (user_conv_type == ADC_HW)) {
  1223. conv_type = (u8) user_conv_type;
  1224. } else {
  1225. dev_err(dev, "Wrong input:\n"
  1226. "Enter 0. ADC SW conversion\n"
  1227. "Enter 1. ADC HW conversion\n");
  1228. return -EINVAL;
  1229. }
  1230. return buf_size;
  1231. }
  1232. static const struct file_operations ab8500_gpadc_conv_type_fops = {
  1233. .open = ab8500_gpadc_conv_type_open,
  1234. .read = seq_read,
  1235. .write = ab8500_gpadc_conv_type_write,
  1236. .llseek = seq_lseek,
  1237. .release = single_release,
  1238. .owner = THIS_MODULE,
  1239. };
  1240. /*
  1241. * return length of an ASCII numerical value, 0 is string is not a
  1242. * numerical value.
  1243. * string shall start at value 1st char.
  1244. * string can be tailed with \0 or space or newline chars only.
  1245. * value can be decimal or hexadecimal (prefixed 0x or 0X).
  1246. */
  1247. static int strval_len(char *b)
  1248. {
  1249. char *s = b;
  1250. if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
  1251. s += 2;
  1252. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  1253. if (!isxdigit(*s))
  1254. return 0;
  1255. }
  1256. } else {
  1257. if (*s == '-')
  1258. s++;
  1259. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  1260. if (!isdigit(*s))
  1261. return 0;
  1262. }
  1263. }
  1264. return (int) (s-b);
  1265. }
  1266. /*
  1267. * parse hwreg input data.
  1268. * update global hwreg_cfg only if input data syntax is ok.
  1269. */
  1270. static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
  1271. struct device *dev)
  1272. {
  1273. uint write, val = 0;
  1274. u8 regvalue;
  1275. int ret;
  1276. struct hwreg_cfg loc = {
  1277. .bank = 0, /* default: invalid phys addr */
  1278. .addr = 0, /* default: invalid phys addr */
  1279. .fmt = 0, /* default: 32bit access, hex output */
  1280. .mask = 0xFFFFFFFF, /* default: no mask */
  1281. .shift = 0, /* default: no bit shift */
  1282. };
  1283. /* read or write ? */
  1284. if (!strncmp(b, "read ", 5)) {
  1285. write = 0;
  1286. b += 5;
  1287. } else if (!strncmp(b, "write ", 6)) {
  1288. write = 1;
  1289. b += 6;
  1290. } else
  1291. return -EINVAL;
  1292. /* OPTIONS -l|-w|-b -s -m -o */
  1293. while ((*b == ' ') || (*b == '-')) {
  1294. if (*(b-1) != ' ') {
  1295. b++;
  1296. continue;
  1297. }
  1298. if ((!strncmp(b, "-d ", 3)) ||
  1299. (!strncmp(b, "-dec ", 5))) {
  1300. b += (*(b+2) == ' ') ? 3 : 5;
  1301. loc.fmt |= (1<<0);
  1302. } else if ((!strncmp(b, "-h ", 3)) ||
  1303. (!strncmp(b, "-hex ", 5))) {
  1304. b += (*(b+2) == ' ') ? 3 : 5;
  1305. loc.fmt &= ~(1<<0);
  1306. } else if ((!strncmp(b, "-m ", 3)) ||
  1307. (!strncmp(b, "-mask ", 6))) {
  1308. b += (*(b+2) == ' ') ? 3 : 6;
  1309. if (strval_len(b) == 0)
  1310. return -EINVAL;
  1311. loc.mask = simple_strtoul(b, &b, 0);
  1312. } else if ((!strncmp(b, "-s ", 3)) ||
  1313. (!strncmp(b, "-shift ", 7))) {
  1314. b += (*(b+2) == ' ') ? 3 : 7;
  1315. if (strval_len(b) == 0)
  1316. return -EINVAL;
  1317. loc.shift = simple_strtol(b, &b, 0);
  1318. } else {
  1319. return -EINVAL;
  1320. }
  1321. }
  1322. /* get arg BANK and ADDRESS */
  1323. if (strval_len(b) == 0)
  1324. return -EINVAL;
  1325. loc.bank = simple_strtoul(b, &b, 0);
  1326. while (*b == ' ')
  1327. b++;
  1328. if (strval_len(b) == 0)
  1329. return -EINVAL;
  1330. loc.addr = simple_strtoul(b, &b, 0);
  1331. if (write) {
  1332. while (*b == ' ')
  1333. b++;
  1334. if (strval_len(b) == 0)
  1335. return -EINVAL;
  1336. val = simple_strtoul(b, &b, 0);
  1337. }
  1338. /* args are ok, update target cfg (mainly for read) */
  1339. *cfg = loc;
  1340. #ifdef ABB_HWREG_DEBUG
  1341. pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
  1342. "value=0x%X\n", (write) ? "write" : "read",
  1343. REG_FMT_DEC(cfg) ? "decimal" : "hexa",
  1344. cfg->addr, cfg->mask, cfg->shift, val);
  1345. #endif
  1346. if (!write)
  1347. return 0;
  1348. ret = abx500_get_register_interruptible(dev,
  1349. (u8)cfg->bank, (u8)cfg->addr, &regvalue);
  1350. if (ret < 0) {
  1351. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  1352. ret, __LINE__);
  1353. return -EINVAL;
  1354. }
  1355. if (cfg->shift >= 0) {
  1356. regvalue &= ~(cfg->mask << (cfg->shift));
  1357. val = (val & cfg->mask) << (cfg->shift);
  1358. } else {
  1359. regvalue &= ~(cfg->mask >> (-cfg->shift));
  1360. val = (val & cfg->mask) >> (-cfg->shift);
  1361. }
  1362. val = val | regvalue;
  1363. ret = abx500_set_register_interruptible(dev,
  1364. (u8)cfg->bank, (u8)cfg->addr, (u8)val);
  1365. if (ret < 0) {
  1366. pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
  1367. return -EINVAL;
  1368. }
  1369. return 0;
  1370. }
  1371. static ssize_t ab8500_hwreg_write(struct file *file,
  1372. const char __user *user_buf, size_t count, loff_t *ppos)
  1373. {
  1374. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1375. char buf[128];
  1376. int buf_size, ret;
  1377. /* Get userspace string and assure termination */
  1378. buf_size = min(count, (sizeof(buf)-1));
  1379. if (copy_from_user(buf, user_buf, buf_size))
  1380. return -EFAULT;
  1381. buf[buf_size] = 0;
  1382. /* get args and process */
  1383. ret = hwreg_common_write(buf, &hwreg_cfg, dev);
  1384. return (ret) ? ret : buf_size;
  1385. }
  1386. /*
  1387. * - irq subscribe/unsubscribe stuff
  1388. */
  1389. static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
  1390. {
  1391. seq_printf(s, "%d\n", irq_first);
  1392. return 0;
  1393. }
  1394. static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
  1395. struct file *file)
  1396. {
  1397. return single_open(file, ab8500_subscribe_unsubscribe_print,
  1398. inode->i_private);
  1399. }
  1400. /*
  1401. * Userspace should use poll() on this file. When an event occur
  1402. * the blocking poll will be released.
  1403. */
  1404. static ssize_t show_irq(struct device *dev,
  1405. struct device_attribute *attr, char *buf)
  1406. {
  1407. unsigned long name;
  1408. unsigned int irq_index;
  1409. int err;
  1410. err = strict_strtoul(attr->attr.name, 0, &name);
  1411. if (err)
  1412. return err;
  1413. irq_index = name - irq_first;
  1414. if (irq_index >= num_irqs)
  1415. return -EINVAL;
  1416. else
  1417. return sprintf(buf, "%u\n", irq_count[irq_index]);
  1418. }
  1419. static ssize_t ab8500_subscribe_write(struct file *file,
  1420. const char __user *user_buf,
  1421. size_t count, loff_t *ppos)
  1422. {
  1423. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1424. char buf[32];
  1425. int buf_size;
  1426. unsigned long user_val;
  1427. int err;
  1428. unsigned int irq_index;
  1429. /* Get userspace string and assure termination */
  1430. buf_size = min(count, (sizeof(buf)-1));
  1431. if (copy_from_user(buf, user_buf, buf_size))
  1432. return -EFAULT;
  1433. buf[buf_size] = 0;
  1434. err = strict_strtoul(buf, 0, &user_val);
  1435. if (err)
  1436. return -EINVAL;
  1437. if (user_val < irq_first) {
  1438. dev_err(dev, "debugfs error input < %d\n", irq_first);
  1439. return -EINVAL;
  1440. }
  1441. if (user_val > irq_last) {
  1442. dev_err(dev, "debugfs error input > %d\n", irq_last);
  1443. return -EINVAL;
  1444. }
  1445. irq_index = user_val - irq_first;
  1446. if (irq_index >= num_irqs)
  1447. return -EINVAL;
  1448. /*
  1449. * This will create a sysfs file named <irq-nr> which userspace can
  1450. * use to select or poll and get the AB8500 events
  1451. */
  1452. dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
  1453. GFP_KERNEL);
  1454. event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL);
  1455. sprintf(event_name[irq_index], "%lu", user_val);
  1456. dev_attr[irq_index]->show = show_irq;
  1457. dev_attr[irq_index]->store = NULL;
  1458. dev_attr[irq_index]->attr.name = event_name[irq_index];
  1459. dev_attr[irq_index]->attr.mode = S_IRUGO;
  1460. err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1461. if (err < 0) {
  1462. printk(KERN_ERR "sysfs_create_file failed %d\n", err);
  1463. return err;
  1464. }
  1465. err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
  1466. IRQF_SHARED | IRQF_NO_SUSPEND,
  1467. "ab8500-debug", &dev->kobj);
  1468. if (err < 0) {
  1469. printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
  1470. err, user_val);
  1471. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1472. return err;
  1473. }
  1474. return buf_size;
  1475. }
  1476. static ssize_t ab8500_unsubscribe_write(struct file *file,
  1477. const char __user *user_buf,
  1478. size_t count, loff_t *ppos)
  1479. {
  1480. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1481. char buf[32];
  1482. int buf_size;
  1483. unsigned long user_val;
  1484. int err;
  1485. unsigned int irq_index;
  1486. /* Get userspace string and assure termination */
  1487. buf_size = min(count, (sizeof(buf)-1));
  1488. if (copy_from_user(buf, user_buf, buf_size))
  1489. return -EFAULT;
  1490. buf[buf_size] = 0;
  1491. err = strict_strtoul(buf, 0, &user_val);
  1492. if (err)
  1493. return -EINVAL;
  1494. if (user_val < irq_first) {
  1495. dev_err(dev, "debugfs error input < %d\n", irq_first);
  1496. return -EINVAL;
  1497. }
  1498. if (user_val > irq_last) {
  1499. dev_err(dev, "debugfs error input > %d\n", irq_last);
  1500. return -EINVAL;
  1501. }
  1502. irq_index = user_val - irq_first;
  1503. if (irq_index >= num_irqs)
  1504. return -EINVAL;
  1505. /* Set irq count to 0 when unsubscribe */
  1506. irq_count[irq_index] = 0;
  1507. if (dev_attr[irq_index])
  1508. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  1509. free_irq(user_val, &dev->kobj);
  1510. kfree(event_name[irq_index]);
  1511. kfree(dev_attr[irq_index]);
  1512. return buf_size;
  1513. }
  1514. /*
  1515. * - several deubgfs nodes fops
  1516. */
  1517. static const struct file_operations ab8500_bank_fops = {
  1518. .open = ab8500_bank_open,
  1519. .write = ab8500_bank_write,
  1520. .read = seq_read,
  1521. .llseek = seq_lseek,
  1522. .release = single_release,
  1523. .owner = THIS_MODULE,
  1524. };
  1525. static const struct file_operations ab8500_address_fops = {
  1526. .open = ab8500_address_open,
  1527. .write = ab8500_address_write,
  1528. .read = seq_read,
  1529. .llseek = seq_lseek,
  1530. .release = single_release,
  1531. .owner = THIS_MODULE,
  1532. };
  1533. static const struct file_operations ab8500_val_fops = {
  1534. .open = ab8500_val_open,
  1535. .write = ab8500_val_write,
  1536. .read = seq_read,
  1537. .llseek = seq_lseek,
  1538. .release = single_release,
  1539. .owner = THIS_MODULE,
  1540. };
  1541. static const struct file_operations ab8500_interrupts_fops = {
  1542. .open = ab8500_interrupts_open,
  1543. .read = seq_read,
  1544. .llseek = seq_lseek,
  1545. .release = single_release,
  1546. .owner = THIS_MODULE,
  1547. };
  1548. static const struct file_operations ab8500_subscribe_fops = {
  1549. .open = ab8500_subscribe_unsubscribe_open,
  1550. .write = ab8500_subscribe_write,
  1551. .read = seq_read,
  1552. .llseek = seq_lseek,
  1553. .release = single_release,
  1554. .owner = THIS_MODULE,
  1555. };
  1556. static const struct file_operations ab8500_unsubscribe_fops = {
  1557. .open = ab8500_subscribe_unsubscribe_open,
  1558. .write = ab8500_unsubscribe_write,
  1559. .read = seq_read,
  1560. .llseek = seq_lseek,
  1561. .release = single_release,
  1562. .owner = THIS_MODULE,
  1563. };
  1564. static const struct file_operations ab8500_hwreg_fops = {
  1565. .open = ab8500_hwreg_open,
  1566. .write = ab8500_hwreg_write,
  1567. .read = seq_read,
  1568. .llseek = seq_lseek,
  1569. .release = single_release,
  1570. .owner = THIS_MODULE,
  1571. };
  1572. static struct dentry *ab8500_dir;
  1573. static struct dentry *ab8500_gpadc_dir;
  1574. static int ab8500_debug_probe(struct platform_device *plf)
  1575. {
  1576. struct dentry *file;
  1577. int ret = -ENOMEM;
  1578. struct ab8500 *ab8500;
  1579. debug_bank = AB8500_MISC;
  1580. debug_address = AB8500_REV_REG & 0x00FF;
  1581. ab8500 = dev_get_drvdata(plf->dev.parent);
  1582. num_irqs = ab8500->mask_size;
  1583. irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
  1584. if (!irq_count)
  1585. return -ENOMEM;
  1586. dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
  1587. if (!dev_attr)
  1588. goto out_freeirq_count;
  1589. event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
  1590. if (!event_name)
  1591. goto out_freedev_attr;
  1592. irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
  1593. if (irq_first < 0) {
  1594. dev_err(&plf->dev, "First irq not found, err %d\n",
  1595. irq_first);
  1596. ret = irq_first;
  1597. goto out_freeevent_name;
  1598. }
  1599. irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
  1600. if (irq_last < 0) {
  1601. dev_err(&plf->dev, "Last irq not found, err %d\n",
  1602. irq_last);
  1603. ret = irq_last;
  1604. goto out_freeevent_name;
  1605. }
  1606. ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
  1607. if (!ab8500_dir)
  1608. goto err;
  1609. ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
  1610. ab8500_dir);
  1611. if (!ab8500_gpadc_dir)
  1612. goto err;
  1613. file = debugfs_create_file("all-bank-registers", S_IRUGO,
  1614. ab8500_dir, &plf->dev, &ab8500_registers_fops);
  1615. if (!file)
  1616. goto err;
  1617. file = debugfs_create_file("all-banks", S_IRUGO,
  1618. ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
  1619. if (!file)
  1620. goto err;
  1621. file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
  1622. ab8500_dir, &plf->dev, &ab8500_bank_fops);
  1623. if (!file)
  1624. goto err;
  1625. file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR),
  1626. ab8500_dir, &plf->dev, &ab8500_address_fops);
  1627. if (!file)
  1628. goto err;
  1629. file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR),
  1630. ab8500_dir, &plf->dev, &ab8500_val_fops);
  1631. if (!file)
  1632. goto err;
  1633. file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR),
  1634. ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
  1635. if (!file)
  1636. goto err;
  1637. if (is_ab8500(ab8500))
  1638. num_interrupt_lines = AB8500_NR_IRQS;
  1639. else if (is_ab8505(ab8500))
  1640. num_interrupt_lines = AB8505_NR_IRQS;
  1641. else if (is_ab9540(ab8500))
  1642. num_interrupt_lines = AB9540_NR_IRQS;
  1643. file = debugfs_create_file("interrupts", (S_IRUGO),
  1644. ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
  1645. if (!file)
  1646. goto err;
  1647. file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR),
  1648. ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
  1649. if (!file)
  1650. goto err;
  1651. file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR),
  1652. ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
  1653. if (!file)
  1654. goto err;
  1655. file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR),
  1656. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
  1657. if (!file)
  1658. goto err;
  1659. file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR),
  1660. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
  1661. if (!file)
  1662. goto err;
  1663. file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR),
  1664. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
  1665. if (!file)
  1666. goto err;
  1667. file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR),
  1668. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
  1669. if (!file)
  1670. goto err;
  1671. file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR),
  1672. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
  1673. if (!file)
  1674. goto err;
  1675. file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR),
  1676. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
  1677. if (!file)
  1678. goto err;
  1679. file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR),
  1680. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
  1681. if (!file)
  1682. goto err;
  1683. file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR),
  1684. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
  1685. if (!file)
  1686. goto err;
  1687. file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR),
  1688. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
  1689. if (!file)
  1690. goto err;
  1691. file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR),
  1692. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
  1693. if (!file)
  1694. goto err;
  1695. file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR),
  1696. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
  1697. if (!file)
  1698. goto err;
  1699. file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR),
  1700. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
  1701. if (!file)
  1702. goto err;
  1703. file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR),
  1704. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
  1705. if (!file)
  1706. goto err;
  1707. file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUGO),
  1708. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
  1709. if (!file)
  1710. goto err;
  1711. file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUGO),
  1712. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
  1713. if (!file)
  1714. goto err;
  1715. file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUGO),
  1716. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
  1717. if (!file)
  1718. goto err;
  1719. file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUGO),
  1720. ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
  1721. if (!file)
  1722. goto err;
  1723. return 0;
  1724. err:
  1725. if (ab8500_dir)
  1726. debugfs_remove_recursive(ab8500_dir);
  1727. dev_err(&plf->dev, "failed to create debugfs entries.\n");
  1728. out_freeevent_name:
  1729. kfree(event_name);
  1730. out_freedev_attr:
  1731. kfree(dev_attr);
  1732. out_freeirq_count:
  1733. kfree(irq_count);
  1734. return ret;
  1735. }
  1736. static int ab8500_debug_remove(struct platform_device *plf)
  1737. {
  1738. debugfs_remove_recursive(ab8500_dir);
  1739. kfree(event_name);
  1740. kfree(dev_attr);
  1741. kfree(irq_count);
  1742. return 0;
  1743. }
  1744. static struct platform_driver ab8500_debug_driver = {
  1745. .driver = {
  1746. .name = "ab8500-debug",
  1747. .owner = THIS_MODULE,
  1748. },
  1749. .probe = ab8500_debug_probe,
  1750. .remove = ab8500_debug_remove
  1751. };
  1752. static int __init ab8500_debug_init(void)
  1753. {
  1754. return platform_driver_register(&ab8500_debug_driver);
  1755. }
  1756. static void __exit ab8500_debug_exit(void)
  1757. {
  1758. platform_driver_unregister(&ab8500_debug_driver);
  1759. }
  1760. subsys_initcall(ab8500_debug_init);
  1761. module_exit(ab8500_debug_exit);
  1762. MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
  1763. MODULE_DESCRIPTION("AB8500 DEBUG");
  1764. MODULE_LICENSE("GPL v2");