ab8500-debugfs.c 48 KB

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