ab8500-debugfs.c 54 KB

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