ab8500-debugfs.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267
  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_ab8500;
  93. static int irq_first;
  94. static int irq_last;
  95. static u32 *irq_count;
  96. static int num_irqs;
  97. static struct device_attribute **dev_attr;
  98. static char **event_name;
  99. static u8 avg_sample = SAMPLE_16;
  100. static u8 trig_edge = RISING_EDGE;
  101. static u8 conv_type = ADC_SW;
  102. static u8 trig_timer;
  103. /**
  104. * struct ab8500_reg_range
  105. * @first: the first address of the range
  106. * @last: the last address of the range
  107. * @perm: access permissions for the range
  108. */
  109. struct ab8500_reg_range {
  110. u8 first;
  111. u8 last;
  112. u8 perm;
  113. };
  114. /**
  115. * struct ab8500_prcmu_ranges
  116. * @num_ranges: the number of ranges in the list
  117. * @bankid: bank identifier
  118. * @range: the list of register ranges
  119. */
  120. struct ab8500_prcmu_ranges {
  121. u8 num_ranges;
  122. u8 bankid;
  123. const struct ab8500_reg_range *range;
  124. };
  125. /* hwreg- "mask" and "shift" entries ressources */
  126. struct hwreg_cfg {
  127. u32 bank; /* target bank */
  128. unsigned long addr; /* target address */
  129. uint fmt; /* format */
  130. unsigned long mask; /* read/write mask, applied before any bit shift */
  131. long shift; /* bit shift (read:right shift, write:left shift */
  132. };
  133. /* fmt bit #0: 0=hexa, 1=dec */
  134. #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
  135. #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
  136. static struct hwreg_cfg hwreg_cfg = {
  137. .addr = 0, /* default: invalid phys addr */
  138. .fmt = 0, /* default: 32bit access, hex output */
  139. .mask = 0xFFFFFFFF, /* default: no mask */
  140. .shift = 0, /* default: no bit shift */
  141. };
  142. #define AB8500_NAME_STRING "ab8500"
  143. #define AB8500_ADC_NAME_STRING "gpadc"
  144. #define AB8500_NUM_BANKS AB8500_DEBUG_FIELD_LAST
  145. #define AB8500_REV_REG 0x80
  146. static struct ab8500_prcmu_ranges *debug_ranges;
  147. static struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
  148. [AB8500_M_FSM_RANK] = {
  149. .num_ranges = 0,
  150. .range = NULL,
  151. },
  152. [AB8500_SYS_CTRL1_BLOCK] = {
  153. .num_ranges = 3,
  154. .range = (struct ab8500_reg_range[]) {
  155. {
  156. .first = 0x00,
  157. .last = 0x02,
  158. },
  159. {
  160. .first = 0x42,
  161. .last = 0x42,
  162. },
  163. {
  164. .first = 0x80,
  165. .last = 0x81,
  166. },
  167. },
  168. },
  169. [AB8500_SYS_CTRL2_BLOCK] = {
  170. .num_ranges = 4,
  171. .range = (struct ab8500_reg_range[]) {
  172. {
  173. .first = 0x00,
  174. .last = 0x0D,
  175. },
  176. {
  177. .first = 0x0F,
  178. .last = 0x17,
  179. },
  180. {
  181. .first = 0x30,
  182. .last = 0x30,
  183. },
  184. {
  185. .first = 0x32,
  186. .last = 0x33,
  187. },
  188. },
  189. },
  190. [AB8500_REGU_CTRL1] = {
  191. .num_ranges = 3,
  192. .range = (struct ab8500_reg_range[]) {
  193. {
  194. .first = 0x00,
  195. .last = 0x00,
  196. },
  197. {
  198. .first = 0x03,
  199. .last = 0x10,
  200. },
  201. {
  202. .first = 0x80,
  203. .last = 0x84,
  204. },
  205. },
  206. },
  207. [AB8500_REGU_CTRL2] = {
  208. .num_ranges = 5,
  209. .range = (struct ab8500_reg_range[]) {
  210. {
  211. .first = 0x00,
  212. .last = 0x15,
  213. },
  214. {
  215. .first = 0x17,
  216. .last = 0x19,
  217. },
  218. {
  219. .first = 0x1B,
  220. .last = 0x1D,
  221. },
  222. {
  223. .first = 0x1F,
  224. .last = 0x22,
  225. },
  226. {
  227. .first = 0x40,
  228. .last = 0x44,
  229. },
  230. /*
  231. * 0x80-0x8B are SIM registers and should
  232. * not be accessed from here
  233. */
  234. },
  235. },
  236. [AB8500_USB] = {
  237. .num_ranges = 2,
  238. .range = (struct ab8500_reg_range[]) {
  239. {
  240. .first = 0x80,
  241. .last = 0x83,
  242. },
  243. {
  244. .first = 0x87,
  245. .last = 0x8A,
  246. },
  247. },
  248. },
  249. [AB8500_TVOUT] = {
  250. .num_ranges = 9,
  251. .range = (struct ab8500_reg_range[]) {
  252. {
  253. .first = 0x00,
  254. .last = 0x12,
  255. },
  256. {
  257. .first = 0x15,
  258. .last = 0x17,
  259. },
  260. {
  261. .first = 0x19,
  262. .last = 0x21,
  263. },
  264. {
  265. .first = 0x27,
  266. .last = 0x2C,
  267. },
  268. {
  269. .first = 0x41,
  270. .last = 0x41,
  271. },
  272. {
  273. .first = 0x45,
  274. .last = 0x5B,
  275. },
  276. {
  277. .first = 0x5D,
  278. .last = 0x5D,
  279. },
  280. {
  281. .first = 0x69,
  282. .last = 0x69,
  283. },
  284. {
  285. .first = 0x80,
  286. .last = 0x81,
  287. },
  288. },
  289. },
  290. [AB8500_DBI] = {
  291. .num_ranges = 0,
  292. .range = NULL,
  293. },
  294. [AB8500_ECI_AV_ACC] = {
  295. .num_ranges = 1,
  296. .range = (struct ab8500_reg_range[]) {
  297. {
  298. .first = 0x80,
  299. .last = 0x82,
  300. },
  301. },
  302. },
  303. [AB8500_RESERVED] = {
  304. .num_ranges = 0,
  305. .range = NULL,
  306. },
  307. [AB8500_GPADC] = {
  308. .num_ranges = 1,
  309. .range = (struct ab8500_reg_range[]) {
  310. {
  311. .first = 0x00,
  312. .last = 0x08,
  313. },
  314. },
  315. },
  316. [AB8500_CHARGER] = {
  317. .num_ranges = 9,
  318. .range = (struct ab8500_reg_range[]) {
  319. {
  320. .first = 0x00,
  321. .last = 0x03,
  322. },
  323. {
  324. .first = 0x05,
  325. .last = 0x05,
  326. },
  327. {
  328. .first = 0x40,
  329. .last = 0x40,
  330. },
  331. {
  332. .first = 0x42,
  333. .last = 0x42,
  334. },
  335. {
  336. .first = 0x44,
  337. .last = 0x44,
  338. },
  339. {
  340. .first = 0x50,
  341. .last = 0x55,
  342. },
  343. {
  344. .first = 0x80,
  345. .last = 0x82,
  346. },
  347. {
  348. .first = 0xC0,
  349. .last = 0xC2,
  350. },
  351. {
  352. .first = 0xf5,
  353. .last = 0xf6,
  354. },
  355. },
  356. },
  357. [AB8500_GAS_GAUGE] = {
  358. .num_ranges = 3,
  359. .range = (struct ab8500_reg_range[]) {
  360. {
  361. .first = 0x00,
  362. .last = 0x00,
  363. },
  364. {
  365. .first = 0x07,
  366. .last = 0x0A,
  367. },
  368. {
  369. .first = 0x10,
  370. .last = 0x14,
  371. },
  372. },
  373. },
  374. [AB8500_AUDIO] = {
  375. .num_ranges = 1,
  376. .range = (struct ab8500_reg_range[]) {
  377. {
  378. .first = 0x00,
  379. .last = 0x6F,
  380. },
  381. },
  382. },
  383. [AB8500_INTERRUPT] = {
  384. .num_ranges = 0,
  385. .range = NULL,
  386. },
  387. [AB8500_RTC] = {
  388. .num_ranges = 1,
  389. .range = (struct ab8500_reg_range[]) {
  390. {
  391. .first = 0x00,
  392. .last = 0x0F,
  393. },
  394. },
  395. },
  396. [AB8500_MISC] = {
  397. .num_ranges = 8,
  398. .range = (struct ab8500_reg_range[]) {
  399. {
  400. .first = 0x00,
  401. .last = 0x05,
  402. },
  403. {
  404. .first = 0x10,
  405. .last = 0x15,
  406. },
  407. {
  408. .first = 0x20,
  409. .last = 0x25,
  410. },
  411. {
  412. .first = 0x30,
  413. .last = 0x35,
  414. },
  415. {
  416. .first = 0x40,
  417. .last = 0x45,
  418. },
  419. {
  420. .first = 0x50,
  421. .last = 0x50,
  422. },
  423. {
  424. .first = 0x60,
  425. .last = 0x67,
  426. },
  427. {
  428. .first = 0x80,
  429. .last = 0x80,
  430. },
  431. },
  432. },
  433. [AB8500_DEVELOPMENT] = {
  434. .num_ranges = 1,
  435. .range = (struct ab8500_reg_range[]) {
  436. {
  437. .first = 0x00,
  438. .last = 0x00,
  439. },
  440. },
  441. },
  442. [AB8500_DEBUG] = {
  443. .num_ranges = 1,
  444. .range = (struct ab8500_reg_range[]) {
  445. {
  446. .first = 0x05,
  447. .last = 0x07,
  448. },
  449. },
  450. },
  451. [AB8500_PROD_TEST] = {
  452. .num_ranges = 0,
  453. .range = NULL,
  454. },
  455. [AB8500_STE_TEST] = {
  456. .num_ranges = 0,
  457. .range = NULL,
  458. },
  459. [AB8500_OTP_EMUL] = {
  460. .num_ranges = 1,
  461. .range = (struct ab8500_reg_range[]) {
  462. {
  463. .first = 0x01,
  464. .last = 0x0F,
  465. },
  466. },
  467. },
  468. };
  469. static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
  470. [0x0] = {
  471. .num_ranges = 0,
  472. .range = NULL,
  473. },
  474. [AB8500_SYS_CTRL1_BLOCK] = {
  475. .num_ranges = 5,
  476. .range = (struct ab8500_reg_range[]) {
  477. {
  478. .first = 0x00,
  479. .last = 0x04,
  480. },
  481. {
  482. .first = 0x42,
  483. .last = 0x42,
  484. },
  485. {
  486. .first = 0x52,
  487. .last = 0x52,
  488. },
  489. {
  490. .first = 0x54,
  491. .last = 0x57,
  492. },
  493. {
  494. .first = 0x80,
  495. .last = 0x83,
  496. },
  497. },
  498. },
  499. [AB8500_SYS_CTRL2_BLOCK] = {
  500. .num_ranges = 5,
  501. .range = (struct ab8500_reg_range[]) {
  502. {
  503. .first = 0x00,
  504. .last = 0x0D,
  505. },
  506. {
  507. .first = 0x0F,
  508. .last = 0x17,
  509. },
  510. {
  511. .first = 0x20,
  512. .last = 0x20,
  513. },
  514. {
  515. .first = 0x30,
  516. .last = 0x30,
  517. },
  518. {
  519. .first = 0x32,
  520. .last = 0x3A,
  521. },
  522. },
  523. },
  524. [AB8500_REGU_CTRL1] = {
  525. .num_ranges = 3,
  526. .range = (struct ab8500_reg_range[]) {
  527. {
  528. .first = 0x00,
  529. .last = 0x00,
  530. },
  531. {
  532. .first = 0x03,
  533. .last = 0x11,
  534. },
  535. {
  536. .first = 0x80,
  537. .last = 0x86,
  538. },
  539. },
  540. },
  541. [AB8500_REGU_CTRL2] = {
  542. .num_ranges = 6,
  543. .range = (struct ab8500_reg_range[]) {
  544. {
  545. .first = 0x00,
  546. .last = 0x06,
  547. },
  548. {
  549. .first = 0x08,
  550. .last = 0x15,
  551. },
  552. {
  553. .first = 0x17,
  554. .last = 0x19,
  555. },
  556. {
  557. .first = 0x1B,
  558. .last = 0x1D,
  559. },
  560. {
  561. .first = 0x1F,
  562. .last = 0x30,
  563. },
  564. {
  565. .first = 0x40,
  566. .last = 0x48,
  567. },
  568. /*
  569. * 0x80-0x8B are SIM registers and should
  570. * not be accessed from here
  571. */
  572. },
  573. },
  574. [AB8500_USB] = {
  575. .num_ranges = 3,
  576. .range = (struct ab8500_reg_range[]) {
  577. {
  578. .first = 0x80,
  579. .last = 0x83,
  580. },
  581. {
  582. .first = 0x87,
  583. .last = 0x8A,
  584. },
  585. {
  586. .first = 0x91,
  587. .last = 0x94,
  588. },
  589. },
  590. },
  591. [AB8500_TVOUT] = {
  592. .num_ranges = 0,
  593. .range = NULL,
  594. },
  595. [AB8500_DBI] = {
  596. .num_ranges = 0,
  597. .range = NULL,
  598. },
  599. [AB8500_ECI_AV_ACC] = {
  600. .num_ranges = 1,
  601. .range = (struct ab8500_reg_range[]) {
  602. {
  603. .first = 0x80,
  604. .last = 0x82,
  605. },
  606. },
  607. },
  608. [AB8500_RESERVED] = {
  609. .num_ranges = 0,
  610. .range = NULL,
  611. },
  612. [AB8500_GPADC] = {
  613. .num_ranges = 1,
  614. .range = (struct ab8500_reg_range[]) {
  615. {
  616. .first = 0x00,
  617. .last = 0x08,
  618. },
  619. },
  620. },
  621. [AB8500_CHARGER] = {
  622. .num_ranges = 9,
  623. .range = (struct ab8500_reg_range[]) {
  624. {
  625. .first = 0x02,
  626. .last = 0x03,
  627. },
  628. {
  629. .first = 0x05,
  630. .last = 0x05,
  631. },
  632. {
  633. .first = 0x40,
  634. .last = 0x44,
  635. },
  636. {
  637. .first = 0x50,
  638. .last = 0x57,
  639. },
  640. {
  641. .first = 0x60,
  642. .last = 0x60,
  643. },
  644. {
  645. .first = 0xA0,
  646. .last = 0xA7,
  647. },
  648. {
  649. .first = 0xAF,
  650. .last = 0xB2,
  651. },
  652. {
  653. .first = 0xC0,
  654. .last = 0xC2,
  655. },
  656. {
  657. .first = 0xF5,
  658. .last = 0xF5,
  659. },
  660. },
  661. },
  662. [AB8500_GAS_GAUGE] = {
  663. .num_ranges = 3,
  664. .range = (struct ab8500_reg_range[]) {
  665. {
  666. .first = 0x00,
  667. .last = 0x00,
  668. },
  669. {
  670. .first = 0x07,
  671. .last = 0x0A,
  672. },
  673. {
  674. .first = 0x10,
  675. .last = 0x14,
  676. },
  677. },
  678. },
  679. [AB8500_AUDIO] = {
  680. .num_ranges = 1,
  681. .range = (struct ab8500_reg_range[]) {
  682. {
  683. .first = 0x00,
  684. .last = 0x83,
  685. },
  686. },
  687. },
  688. [AB8500_INTERRUPT] = {
  689. .num_ranges = 11,
  690. .range = (struct ab8500_reg_range[]) {
  691. {
  692. .first = 0x00,
  693. .last = 0x04,
  694. },
  695. {
  696. .first = 0x06,
  697. .last = 0x07,
  698. },
  699. {
  700. .first = 0x09,
  701. .last = 0x09,
  702. },
  703. {
  704. .first = 0x0B,
  705. .last = 0x0C,
  706. },
  707. {
  708. .first = 0x12,
  709. .last = 0x15,
  710. },
  711. {
  712. .first = 0x18,
  713. .last = 0x18,
  714. },
  715. /* Latch registers should not be read here */
  716. {
  717. .first = 0x40,
  718. .last = 0x44,
  719. },
  720. {
  721. .first = 0x46,
  722. .last = 0x49,
  723. },
  724. {
  725. .first = 0x4B,
  726. .last = 0x4D,
  727. },
  728. {
  729. .first = 0x52,
  730. .last = 0x55,
  731. },
  732. {
  733. .first = 0x58,
  734. .last = 0x58,
  735. },
  736. /* LatchHier registers should not be read here */
  737. },
  738. },
  739. [AB8500_RTC] = {
  740. .num_ranges = 2,
  741. .range = (struct ab8500_reg_range[]) {
  742. {
  743. .first = 0x00,
  744. .last = 0x14,
  745. },
  746. {
  747. .first = 0x16,
  748. .last = 0x17,
  749. },
  750. },
  751. },
  752. [AB8500_MISC] = {
  753. .num_ranges = 8,
  754. .range = (struct ab8500_reg_range[]) {
  755. {
  756. .first = 0x00,
  757. .last = 0x06,
  758. },
  759. {
  760. .first = 0x10,
  761. .last = 0x16,
  762. },
  763. {
  764. .first = 0x20,
  765. .last = 0x26,
  766. },
  767. {
  768. .first = 0x30,
  769. .last = 0x36,
  770. },
  771. {
  772. .first = 0x40,
  773. .last = 0x46,
  774. },
  775. {
  776. .first = 0x50,
  777. .last = 0x50,
  778. },
  779. {
  780. .first = 0x60,
  781. .last = 0x6B,
  782. },
  783. {
  784. .first = 0x80,
  785. .last = 0x82,
  786. },
  787. },
  788. },
  789. [AB8500_DEVELOPMENT] = {
  790. .num_ranges = 2,
  791. .range = (struct ab8500_reg_range[]) {
  792. {
  793. .first = 0x00,
  794. .last = 0x00,
  795. },
  796. {
  797. .first = 0x05,
  798. .last = 0x05,
  799. },
  800. },
  801. },
  802. [AB8500_DEBUG] = {
  803. .num_ranges = 1,
  804. .range = (struct ab8500_reg_range[]) {
  805. {
  806. .first = 0x05,
  807. .last = 0x07,
  808. },
  809. },
  810. },
  811. [AB8500_PROD_TEST] = {
  812. .num_ranges = 0,
  813. .range = NULL,
  814. },
  815. [AB8500_STE_TEST] = {
  816. .num_ranges = 0,
  817. .range = NULL,
  818. },
  819. [AB8500_OTP_EMUL] = {
  820. .num_ranges = 1,
  821. .range = (struct ab8500_reg_range[]) {
  822. {
  823. .first = 0x01,
  824. .last = 0x15,
  825. },
  826. },
  827. },
  828. };
  829. static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
  830. [AB8500_M_FSM_RANK] = {
  831. .num_ranges = 1,
  832. .range = (struct ab8500_reg_range[]) {
  833. {
  834. .first = 0x00,
  835. .last = 0x0B,
  836. },
  837. },
  838. },
  839. [AB8500_SYS_CTRL1_BLOCK] = {
  840. .num_ranges = 6,
  841. .range = (struct ab8500_reg_range[]) {
  842. {
  843. .first = 0x00,
  844. .last = 0x04,
  845. },
  846. {
  847. .first = 0x42,
  848. .last = 0x42,
  849. },
  850. {
  851. .first = 0x50,
  852. .last = 0x54,
  853. },
  854. {
  855. .first = 0x57,
  856. .last = 0x57,
  857. },
  858. {
  859. .first = 0x80,
  860. .last = 0x83,
  861. },
  862. {
  863. .first = 0x90,
  864. .last = 0x90,
  865. },
  866. },
  867. },
  868. [AB8500_SYS_CTRL2_BLOCK] = {
  869. .num_ranges = 5,
  870. .range = (struct ab8500_reg_range[]) {
  871. {
  872. .first = 0x00,
  873. .last = 0x0D,
  874. },
  875. {
  876. .first = 0x0F,
  877. .last = 0x10,
  878. },
  879. {
  880. .first = 0x20,
  881. .last = 0x21,
  882. },
  883. {
  884. .first = 0x32,
  885. .last = 0x3C,
  886. },
  887. {
  888. .first = 0x40,
  889. .last = 0x42,
  890. },
  891. },
  892. },
  893. [AB8500_REGU_CTRL1] = {
  894. .num_ranges = 4,
  895. .range = (struct ab8500_reg_range[]) {
  896. {
  897. .first = 0x03,
  898. .last = 0x15,
  899. },
  900. {
  901. .first = 0x20,
  902. .last = 0x20,
  903. },
  904. {
  905. .first = 0x80,
  906. .last = 0x85,
  907. },
  908. {
  909. .first = 0x87,
  910. .last = 0x88,
  911. },
  912. },
  913. },
  914. [AB8500_REGU_CTRL2] = {
  915. .num_ranges = 8,
  916. .range = (struct ab8500_reg_range[]) {
  917. {
  918. .first = 0x00,
  919. .last = 0x06,
  920. },
  921. {
  922. .first = 0x08,
  923. .last = 0x15,
  924. },
  925. {
  926. .first = 0x17,
  927. .last = 0x19,
  928. },
  929. {
  930. .first = 0x1B,
  931. .last = 0x1D,
  932. },
  933. {
  934. .first = 0x1F,
  935. .last = 0x2F,
  936. },
  937. {
  938. .first = 0x31,
  939. .last = 0x3A,
  940. },
  941. {
  942. .first = 0x43,
  943. .last = 0x44,
  944. },
  945. {
  946. .first = 0x48,
  947. .last = 0x49,
  948. },
  949. },
  950. },
  951. [AB8500_USB] = {
  952. .num_ranges = 3,
  953. .range = (struct ab8500_reg_range[]) {
  954. {
  955. .first = 0x80,
  956. .last = 0x83,
  957. },
  958. {
  959. .first = 0x87,
  960. .last = 0x8A,
  961. },
  962. {
  963. .first = 0x91,
  964. .last = 0x94,
  965. },
  966. },
  967. },
  968. [AB8500_TVOUT] = {
  969. .num_ranges = 0,
  970. .range = NULL
  971. },
  972. [AB8500_DBI] = {
  973. .num_ranges = 4,
  974. .range = (struct ab8500_reg_range[]) {
  975. {
  976. .first = 0x00,
  977. .last = 0x07,
  978. },
  979. {
  980. .first = 0x10,
  981. .last = 0x11,
  982. },
  983. {
  984. .first = 0x20,
  985. .last = 0x21,
  986. },
  987. {
  988. .first = 0x30,
  989. .last = 0x43,
  990. },
  991. },
  992. },
  993. [AB8500_ECI_AV_ACC] = {
  994. .num_ranges = 2,
  995. .range = (struct ab8500_reg_range[]) {
  996. {
  997. .first = 0x00,
  998. .last = 0x03,
  999. },
  1000. {
  1001. .first = 0x80,
  1002. .last = 0x82,
  1003. },
  1004. },
  1005. },
  1006. [AB8500_RESERVED] = {
  1007. .num_ranges = 0,
  1008. .range = NULL,
  1009. },
  1010. [AB8500_GPADC] = {
  1011. .num_ranges = 4,
  1012. .range = (struct ab8500_reg_range[]) {
  1013. {
  1014. .first = 0x00,
  1015. .last = 0x01,
  1016. },
  1017. {
  1018. .first = 0x04,
  1019. .last = 0x06,
  1020. },
  1021. {
  1022. .first = 0x09,
  1023. .last = 0x0A,
  1024. },
  1025. {
  1026. .first = 0x10,
  1027. .last = 0x14,
  1028. },
  1029. },
  1030. },
  1031. [AB8500_CHARGER] = {
  1032. .num_ranges = 10,
  1033. .range = (struct ab8500_reg_range[]) {
  1034. {
  1035. .first = 0x00,
  1036. .last = 0x00,
  1037. },
  1038. {
  1039. .first = 0x02,
  1040. .last = 0x05,
  1041. },
  1042. {
  1043. .first = 0x40,
  1044. .last = 0x44,
  1045. },
  1046. {
  1047. .first = 0x50,
  1048. .last = 0x57,
  1049. },
  1050. {
  1051. .first = 0x60,
  1052. .last = 0x60,
  1053. },
  1054. {
  1055. .first = 0x70,
  1056. .last = 0x70,
  1057. },
  1058. {
  1059. .first = 0xA0,
  1060. .last = 0xA9,
  1061. },
  1062. {
  1063. .first = 0xAF,
  1064. .last = 0xB2,
  1065. },
  1066. {
  1067. .first = 0xC0,
  1068. .last = 0xC6,
  1069. },
  1070. {
  1071. .first = 0xF5,
  1072. .last = 0xF5,
  1073. },
  1074. },
  1075. },
  1076. [AB8500_GAS_GAUGE] = {
  1077. .num_ranges = 3,
  1078. .range = (struct ab8500_reg_range[]) {
  1079. {
  1080. .first = 0x00,
  1081. .last = 0x00,
  1082. },
  1083. {
  1084. .first = 0x07,
  1085. .last = 0x0A,
  1086. },
  1087. {
  1088. .first = 0x10,
  1089. .last = 0x14,
  1090. },
  1091. },
  1092. },
  1093. [AB8500_AUDIO] = {
  1094. .num_ranges = 1,
  1095. .range = (struct ab8500_reg_range[]) {
  1096. {
  1097. .first = 0x00,
  1098. .last = 0x9f,
  1099. },
  1100. },
  1101. },
  1102. [AB8500_INTERRUPT] = {
  1103. .num_ranges = 6,
  1104. .range = (struct ab8500_reg_range[]) {
  1105. {
  1106. .first = 0x00,
  1107. .last = 0x05,
  1108. },
  1109. {
  1110. .first = 0x0B,
  1111. .last = 0x0D,
  1112. },
  1113. {
  1114. .first = 0x12,
  1115. .last = 0x20,
  1116. },
  1117. /* Latch registers should not be read here */
  1118. {
  1119. .first = 0x40,
  1120. .last = 0x45,
  1121. },
  1122. {
  1123. .first = 0x4B,
  1124. .last = 0x4D,
  1125. },
  1126. {
  1127. .first = 0x52,
  1128. .last = 0x60,
  1129. },
  1130. /* LatchHier registers should not be read here */
  1131. },
  1132. },
  1133. [AB8500_RTC] = {
  1134. .num_ranges = 3,
  1135. .range = (struct ab8500_reg_range[]) {
  1136. {
  1137. .first = 0x00,
  1138. .last = 0x07,
  1139. },
  1140. {
  1141. .first = 0x0B,
  1142. .last = 0x18,
  1143. },
  1144. {
  1145. .first = 0x20,
  1146. .last = 0x25,
  1147. },
  1148. },
  1149. },
  1150. [AB8500_MISC] = {
  1151. .num_ranges = 9,
  1152. .range = (struct ab8500_reg_range[]) {
  1153. {
  1154. .first = 0x00,
  1155. .last = 0x06,
  1156. },
  1157. {
  1158. .first = 0x10,
  1159. .last = 0x16,
  1160. },
  1161. {
  1162. .first = 0x20,
  1163. .last = 0x26,
  1164. },
  1165. {
  1166. .first = 0x30,
  1167. .last = 0x36,
  1168. },
  1169. {
  1170. .first = 0x40,
  1171. .last = 0x49,
  1172. },
  1173. {
  1174. .first = 0x50,
  1175. .last = 0x50,
  1176. },
  1177. {
  1178. .first = 0x60,
  1179. .last = 0x6B,
  1180. },
  1181. {
  1182. .first = 0x70,
  1183. .last = 0x74,
  1184. },
  1185. {
  1186. .first = 0x80,
  1187. .last = 0x82,
  1188. },
  1189. },
  1190. },
  1191. [AB8500_DEVELOPMENT] = {
  1192. .num_ranges = 3,
  1193. .range = (struct ab8500_reg_range[]) {
  1194. {
  1195. .first = 0x00,
  1196. .last = 0x01,
  1197. },
  1198. {
  1199. .first = 0x06,
  1200. .last = 0x06,
  1201. },
  1202. {
  1203. .first = 0x10,
  1204. .last = 0x21,
  1205. },
  1206. },
  1207. },
  1208. [AB8500_DEBUG] = {
  1209. .num_ranges = 3,
  1210. .range = (struct ab8500_reg_range[]) {
  1211. {
  1212. .first = 0x01,
  1213. .last = 0x0C,
  1214. },
  1215. {
  1216. .first = 0x0E,
  1217. .last = 0x11,
  1218. },
  1219. {
  1220. .first = 0x80,
  1221. .last = 0x81,
  1222. },
  1223. },
  1224. },
  1225. [AB8500_PROD_TEST] = {
  1226. .num_ranges = 0,
  1227. .range = NULL,
  1228. },
  1229. [AB8500_STE_TEST] = {
  1230. .num_ranges = 0,
  1231. .range = NULL,
  1232. },
  1233. [AB8500_OTP_EMUL] = {
  1234. .num_ranges = 1,
  1235. .range = (struct ab8500_reg_range[]) {
  1236. {
  1237. .first = 0x00,
  1238. .last = 0x3F,
  1239. },
  1240. },
  1241. },
  1242. };
  1243. static irqreturn_t ab8500_debug_handler(int irq, void *data)
  1244. {
  1245. char buf[16];
  1246. struct kobject *kobj = (struct kobject *)data;
  1247. unsigned int irq_abb = irq - irq_first;
  1248. if (irq_abb < num_irqs)
  1249. irq_count[irq_abb]++;
  1250. /*
  1251. * This makes it possible to use poll for events (POLLPRI | POLLERR)
  1252. * from userspace on sysfs file named <irq-nr>
  1253. */
  1254. sprintf(buf, "%d", irq);
  1255. sysfs_notify(kobj, NULL, buf);
  1256. return IRQ_HANDLED;
  1257. }
  1258. /* Prints to seq_file or log_buf */
  1259. static int ab8500_registers_print(struct device *dev, u32 bank,
  1260. struct seq_file *s)
  1261. {
  1262. unsigned int i;
  1263. for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
  1264. u32 reg;
  1265. for (reg = debug_ranges[bank].range[i].first;
  1266. reg <= debug_ranges[bank].range[i].last;
  1267. reg++) {
  1268. u8 value;
  1269. int err;
  1270. err = abx500_get_register_interruptible(dev,
  1271. (u8)bank, (u8)reg, &value);
  1272. if (err < 0) {
  1273. dev_err(dev, "ab->read fail %d\n", err);
  1274. return err;
  1275. }
  1276. if (s) {
  1277. seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
  1278. bank, reg, value);
  1279. /*
  1280. * Error is not returned here since
  1281. * the output is wanted in any case
  1282. */
  1283. if (seq_has_overflowed(s))
  1284. return 0;
  1285. } else {
  1286. dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
  1287. bank, reg, value);
  1288. }
  1289. }
  1290. }
  1291. return 0;
  1292. }
  1293. static int ab8500_print_bank_registers(struct seq_file *s, void *p)
  1294. {
  1295. struct device *dev = s->private;
  1296. u32 bank = debug_bank;
  1297. seq_puts(s, AB8500_NAME_STRING " register values:\n");
  1298. seq_printf(s, " bank 0x%02X:\n", bank);
  1299. return ab8500_registers_print(dev, bank, s);
  1300. }
  1301. static int ab8500_registers_open(struct inode *inode, struct file *file)
  1302. {
  1303. return single_open(file, ab8500_print_bank_registers, inode->i_private);
  1304. }
  1305. static const struct file_operations ab8500_registers_fops = {
  1306. .open = ab8500_registers_open,
  1307. .read = seq_read,
  1308. .llseek = seq_lseek,
  1309. .release = single_release,
  1310. .owner = THIS_MODULE,
  1311. };
  1312. static int ab8500_print_all_banks(struct seq_file *s, void *p)
  1313. {
  1314. struct device *dev = s->private;
  1315. unsigned int i;
  1316. seq_puts(s, AB8500_NAME_STRING " register values:\n");
  1317. for (i = 0; i < AB8500_NUM_BANKS; i++) {
  1318. int err;
  1319. seq_printf(s, " bank 0x%02X:\n", i);
  1320. err = ab8500_registers_print(dev, i, s);
  1321. if (err)
  1322. return err;
  1323. }
  1324. return 0;
  1325. }
  1326. /* Dump registers to kernel log */
  1327. void ab8500_dump_all_banks(struct device *dev)
  1328. {
  1329. unsigned int i;
  1330. dev_info(dev, "ab8500 register values:\n");
  1331. for (i = 1; i < AB8500_NUM_BANKS; i++) {
  1332. dev_info(dev, " bank 0x%02X:\n", i);
  1333. ab8500_registers_print(dev, i, NULL);
  1334. }
  1335. }
  1336. static int ab8500_all_banks_open(struct inode *inode, struct file *file)
  1337. {
  1338. struct seq_file *s;
  1339. int err;
  1340. err = single_open(file, ab8500_print_all_banks, inode->i_private);
  1341. if (!err) {
  1342. /* Default buf size in seq_read is not enough */
  1343. s = (struct seq_file *)file->private_data;
  1344. s->size = (PAGE_SIZE * 2);
  1345. s->buf = kmalloc(s->size, GFP_KERNEL);
  1346. if (!s->buf) {
  1347. single_release(inode, file);
  1348. err = -ENOMEM;
  1349. }
  1350. }
  1351. return err;
  1352. }
  1353. static const struct file_operations ab8500_all_banks_fops = {
  1354. .open = ab8500_all_banks_open,
  1355. .read = seq_read,
  1356. .llseek = seq_lseek,
  1357. .release = single_release,
  1358. .owner = THIS_MODULE,
  1359. };
  1360. static int ab8500_bank_print(struct seq_file *s, void *p)
  1361. {
  1362. seq_printf(s, "0x%02X\n", debug_bank);
  1363. return 0;
  1364. }
  1365. static int ab8500_bank_open(struct inode *inode, struct file *file)
  1366. {
  1367. return single_open(file, ab8500_bank_print, inode->i_private);
  1368. }
  1369. static ssize_t ab8500_bank_write(struct file *file,
  1370. const char __user *user_buf,
  1371. size_t count, loff_t *ppos)
  1372. {
  1373. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1374. unsigned long user_bank;
  1375. int err;
  1376. err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
  1377. if (err)
  1378. return err;
  1379. if (user_bank >= AB8500_NUM_BANKS) {
  1380. dev_err(dev, "debugfs error input > number of banks\n");
  1381. return -EINVAL;
  1382. }
  1383. debug_bank = user_bank;
  1384. return count;
  1385. }
  1386. static int ab8500_address_print(struct seq_file *s, void *p)
  1387. {
  1388. seq_printf(s, "0x%02X\n", debug_address);
  1389. return 0;
  1390. }
  1391. static int ab8500_address_open(struct inode *inode, struct file *file)
  1392. {
  1393. return single_open(file, ab8500_address_print, inode->i_private);
  1394. }
  1395. static ssize_t ab8500_address_write(struct file *file,
  1396. const char __user *user_buf,
  1397. size_t count, loff_t *ppos)
  1398. {
  1399. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1400. unsigned long user_address;
  1401. int err;
  1402. err = kstrtoul_from_user(user_buf, count, 0, &user_address);
  1403. if (err)
  1404. return err;
  1405. if (user_address > 0xff) {
  1406. dev_err(dev, "debugfs error input > 0xff\n");
  1407. return -EINVAL;
  1408. }
  1409. debug_address = user_address;
  1410. return count;
  1411. }
  1412. static int ab8500_val_print(struct seq_file *s, void *p)
  1413. {
  1414. struct device *dev = s->private;
  1415. int ret;
  1416. u8 regvalue;
  1417. ret = abx500_get_register_interruptible(dev,
  1418. (u8)debug_bank, (u8)debug_address, &regvalue);
  1419. if (ret < 0) {
  1420. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  1421. ret, __LINE__);
  1422. return -EINVAL;
  1423. }
  1424. seq_printf(s, "0x%02X\n", regvalue);
  1425. return 0;
  1426. }
  1427. static int ab8500_val_open(struct inode *inode, struct file *file)
  1428. {
  1429. return single_open(file, ab8500_val_print, inode->i_private);
  1430. }
  1431. static ssize_t ab8500_val_write(struct file *file,
  1432. const char __user *user_buf,
  1433. size_t count, loff_t *ppos)
  1434. {
  1435. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  1436. unsigned long user_val;
  1437. int err;
  1438. err = kstrtoul_from_user(user_buf, count, 0, &user_val);
  1439. if (err)
  1440. return err;
  1441. if (user_val > 0xff) {
  1442. dev_err(dev, "debugfs error input > 0xff\n");
  1443. return -EINVAL;
  1444. }
  1445. err = abx500_set_register_interruptible(dev,
  1446. (u8)debug_bank, debug_address, (u8)user_val);
  1447. if (err < 0) {
  1448. pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
  1449. return -EINVAL;
  1450. }
  1451. return count;
  1452. }
  1453. /*
  1454. * Interrupt status
  1455. */
  1456. static u32 num_interrupts[AB8500_MAX_NR_IRQS];
  1457. static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
  1458. static int num_interrupt_lines;
  1459. void ab8500_debug_register_interrupt(int line)
  1460. {
  1461. if (line < num_interrupt_lines)
  1462. num_interrupts[line]++;
  1463. }
  1464. static int ab8500_interrupts_print(struct seq_file *s, void *p)
  1465. {
  1466. int line;
  1467. seq_puts(s, "name: number: number of: wake:\n");
  1468. for (line = 0; line < num_interrupt_lines; line++) {
  1469. struct irq_desc *desc = irq_to_desc(line + irq_first);
  1470. seq_printf(s, "%3i: %6i %4i",
  1471. line,
  1472. num_interrupts[line],
  1473. num_wake_interrupts[line]);
  1474. if (desc && desc->name)
  1475. seq_printf(s, "-%-8s", desc->name);
  1476. if (desc && desc->action) {
  1477. struct irqaction *action = desc->action;
  1478. seq_printf(s, " %s", action->name);
  1479. while ((action = action->next) != NULL)
  1480. seq_printf(s, ", %s", action->name);
  1481. }
  1482. seq_putc(s, '\n');
  1483. }
  1484. return 0;
  1485. }
  1486. static int ab8500_interrupts_open(struct inode *inode, struct file *file)
  1487. {
  1488. return single_open(file, ab8500_interrupts_print, inode->i_private);
  1489. }
  1490. /*
  1491. * - HWREG DB8500 formated routines
  1492. */
  1493. static int ab8500_hwreg_print(struct seq_file *s, void *d)
  1494. {
  1495. struct device *dev = s->private;
  1496. int ret;
  1497. u8 regvalue;
  1498. ret = abx500_get_register_interruptible(dev,
  1499. (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
  1500. if (ret < 0) {
  1501. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  1502. ret, __LINE__);
  1503. return -EINVAL;
  1504. }
  1505. if (hwreg_cfg.shift >= 0)
  1506. regvalue >>= hwreg_cfg.shift;
  1507. else
  1508. regvalue <<= -hwreg_cfg.shift;
  1509. regvalue &= hwreg_cfg.mask;
  1510. if (REG_FMT_DEC(&hwreg_cfg))
  1511. seq_printf(s, "%d\n", regvalue);
  1512. else
  1513. seq_printf(s, "0x%02X\n", regvalue);
  1514. return 0;
  1515. }
  1516. static int ab8500_hwreg_open(struct inode *inode, struct file *file)
  1517. {
  1518. return single_open(file, ab8500_hwreg_print, inode->i_private);
  1519. }
  1520. #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
  1521. #define AB8500_SUPPLY_CONTROL_REG 0x00
  1522. #define AB8500_FIRST_SIM_REG 0x80
  1523. #define AB8500_LAST_SIM_REG 0x8B
  1524. #define AB8505_LAST_SIM_REG 0x8C
  1525. static int ab8500_print_modem_registers(struct seq_file *s, void *p)
  1526. {
  1527. struct device *dev = s->private;
  1528. struct ab8500 *ab8500;
  1529. int err;
  1530. u8 value;
  1531. u8 orig_value;
  1532. u32 bank = AB8500_REGU_CTRL2;
  1533. u32 last_sim_reg = AB8500_LAST_SIM_REG;
  1534. u32 reg;
  1535. ab8500 = dev_get_drvdata(dev->parent);
  1536. dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
  1537. "and should only be done with care\n");
  1538. err = abx500_get_register_interruptible(dev,
  1539. AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
  1540. if (err < 0) {
  1541. dev_err(dev, "ab->read fail %d\n", err);
  1542. return err;
  1543. }
  1544. /* Config 1 will allow APE side to read SIM registers */
  1545. err = abx500_set_register_interruptible(dev,
  1546. AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
  1547. AB8500_SUPPLY_CONTROL_CONFIG_1);
  1548. if (err < 0) {
  1549. dev_err(dev, "ab->write fail %d\n", err);
  1550. return err;
  1551. }
  1552. seq_printf(s, " bank 0x%02X:\n", bank);
  1553. if (is_ab9540(ab8500) || is_ab8505(ab8500))
  1554. last_sim_reg = AB8505_LAST_SIM_REG;
  1555. for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
  1556. err = abx500_get_register_interruptible(dev,
  1557. bank, reg, &value);
  1558. if (err < 0) {
  1559. dev_err(dev, "ab->read fail %d\n", err);
  1560. return err;
  1561. }
  1562. seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
  1563. }
  1564. err = abx500_set_register_interruptible(dev,
  1565. AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
  1566. if (err < 0) {
  1567. dev_err(dev, "ab->write fail %d\n", err);
  1568. return err;
  1569. }
  1570. return 0;
  1571. }
  1572. static int ab8500_modem_open(struct inode *inode, struct file *file)
  1573. {
  1574. return single_open(file, ab8500_print_modem_registers,
  1575. inode->i_private);
  1576. }
  1577. static const struct file_operations ab8500_modem_fops = {
  1578. .open = ab8500_modem_open,
  1579. .read = seq_read,
  1580. .llseek = seq_lseek,
  1581. .release = single_release,
  1582. .owner = THIS_MODULE,
  1583. };
  1584. static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
  1585. {
  1586. int bat_ctrl_raw;
  1587. int bat_ctrl_convert;
  1588. struct ab8500_gpadc *gpadc;
  1589. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1590. bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
  1591. avg_sample, trig_edge, trig_timer, conv_type);
  1592. bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1593. BAT_CTRL, bat_ctrl_raw);
  1594. seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
  1595. return 0;
  1596. }
  1597. static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
  1598. {
  1599. return single_open(file, ab8500_gpadc_bat_ctrl_print,
  1600. inode->i_private);
  1601. }
  1602. static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
  1603. .open = ab8500_gpadc_bat_ctrl_open,
  1604. .read = seq_read,
  1605. .llseek = seq_lseek,
  1606. .release = single_release,
  1607. .owner = THIS_MODULE,
  1608. };
  1609. static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
  1610. {
  1611. int btemp_ball_raw;
  1612. int btemp_ball_convert;
  1613. struct ab8500_gpadc *gpadc;
  1614. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1615. btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
  1616. avg_sample, trig_edge, trig_timer, conv_type);
  1617. btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
  1618. btemp_ball_raw);
  1619. seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
  1620. return 0;
  1621. }
  1622. static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
  1623. struct file *file)
  1624. {
  1625. return single_open(file, ab8500_gpadc_btemp_ball_print,
  1626. inode->i_private);
  1627. }
  1628. static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
  1629. .open = ab8500_gpadc_btemp_ball_open,
  1630. .read = seq_read,
  1631. .llseek = seq_lseek,
  1632. .release = single_release,
  1633. .owner = THIS_MODULE,
  1634. };
  1635. static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
  1636. {
  1637. int main_charger_v_raw;
  1638. int main_charger_v_convert;
  1639. struct ab8500_gpadc *gpadc;
  1640. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1641. main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
  1642. avg_sample, trig_edge, trig_timer, conv_type);
  1643. main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1644. MAIN_CHARGER_V, main_charger_v_raw);
  1645. seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
  1646. return 0;
  1647. }
  1648. static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
  1649. struct file *file)
  1650. {
  1651. return single_open(file, ab8500_gpadc_main_charger_v_print,
  1652. inode->i_private);
  1653. }
  1654. static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
  1655. .open = ab8500_gpadc_main_charger_v_open,
  1656. .read = seq_read,
  1657. .llseek = seq_lseek,
  1658. .release = single_release,
  1659. .owner = THIS_MODULE,
  1660. };
  1661. static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
  1662. {
  1663. int acc_detect1_raw;
  1664. int acc_detect1_convert;
  1665. struct ab8500_gpadc *gpadc;
  1666. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1667. acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
  1668. avg_sample, trig_edge, trig_timer, conv_type);
  1669. acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
  1670. acc_detect1_raw);
  1671. seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
  1672. return 0;
  1673. }
  1674. static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
  1675. struct file *file)
  1676. {
  1677. return single_open(file, ab8500_gpadc_acc_detect1_print,
  1678. inode->i_private);
  1679. }
  1680. static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
  1681. .open = ab8500_gpadc_acc_detect1_open,
  1682. .read = seq_read,
  1683. .llseek = seq_lseek,
  1684. .release = single_release,
  1685. .owner = THIS_MODULE,
  1686. };
  1687. static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
  1688. {
  1689. int acc_detect2_raw;
  1690. int acc_detect2_convert;
  1691. struct ab8500_gpadc *gpadc;
  1692. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1693. acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
  1694. avg_sample, trig_edge, trig_timer, conv_type);
  1695. acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1696. ACC_DETECT2, acc_detect2_raw);
  1697. seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
  1698. return 0;
  1699. }
  1700. static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
  1701. struct file *file)
  1702. {
  1703. return single_open(file, ab8500_gpadc_acc_detect2_print,
  1704. inode->i_private);
  1705. }
  1706. static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
  1707. .open = ab8500_gpadc_acc_detect2_open,
  1708. .read = seq_read,
  1709. .llseek = seq_lseek,
  1710. .release = single_release,
  1711. .owner = THIS_MODULE,
  1712. };
  1713. static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
  1714. {
  1715. int aux1_raw;
  1716. int aux1_convert;
  1717. struct ab8500_gpadc *gpadc;
  1718. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1719. aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
  1720. avg_sample, trig_edge, trig_timer, conv_type);
  1721. aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
  1722. aux1_raw);
  1723. seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
  1724. return 0;
  1725. }
  1726. static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
  1727. {
  1728. return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
  1729. }
  1730. static const struct file_operations ab8500_gpadc_aux1_fops = {
  1731. .open = ab8500_gpadc_aux1_open,
  1732. .read = seq_read,
  1733. .llseek = seq_lseek,
  1734. .release = single_release,
  1735. .owner = THIS_MODULE,
  1736. };
  1737. static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
  1738. {
  1739. int aux2_raw;
  1740. int aux2_convert;
  1741. struct ab8500_gpadc *gpadc;
  1742. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1743. aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
  1744. avg_sample, trig_edge, trig_timer, conv_type);
  1745. aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
  1746. aux2_raw);
  1747. seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
  1748. return 0;
  1749. }
  1750. static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
  1751. {
  1752. return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
  1753. }
  1754. static const struct file_operations ab8500_gpadc_aux2_fops = {
  1755. .open = ab8500_gpadc_aux2_open,
  1756. .read = seq_read,
  1757. .llseek = seq_lseek,
  1758. .release = single_release,
  1759. .owner = THIS_MODULE,
  1760. };
  1761. static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
  1762. {
  1763. int main_bat_v_raw;
  1764. int main_bat_v_convert;
  1765. struct ab8500_gpadc *gpadc;
  1766. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1767. main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
  1768. avg_sample, trig_edge, trig_timer, conv_type);
  1769. main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
  1770. main_bat_v_raw);
  1771. seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
  1772. return 0;
  1773. }
  1774. static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
  1775. struct file *file)
  1776. {
  1777. return single_open(file, ab8500_gpadc_main_bat_v_print,
  1778. inode->i_private);
  1779. }
  1780. static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
  1781. .open = ab8500_gpadc_main_bat_v_open,
  1782. .read = seq_read,
  1783. .llseek = seq_lseek,
  1784. .release = single_release,
  1785. .owner = THIS_MODULE,
  1786. };
  1787. static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
  1788. {
  1789. int vbus_v_raw;
  1790. int vbus_v_convert;
  1791. struct ab8500_gpadc *gpadc;
  1792. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1793. vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
  1794. avg_sample, trig_edge, trig_timer, conv_type);
  1795. vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
  1796. vbus_v_raw);
  1797. seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
  1798. return 0;
  1799. }
  1800. static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
  1801. {
  1802. return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
  1803. }
  1804. static const struct file_operations ab8500_gpadc_vbus_v_fops = {
  1805. .open = ab8500_gpadc_vbus_v_open,
  1806. .read = seq_read,
  1807. .llseek = seq_lseek,
  1808. .release = single_release,
  1809. .owner = THIS_MODULE,
  1810. };
  1811. static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
  1812. {
  1813. int main_charger_c_raw;
  1814. int main_charger_c_convert;
  1815. struct ab8500_gpadc *gpadc;
  1816. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1817. main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
  1818. avg_sample, trig_edge, trig_timer, conv_type);
  1819. main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1820. MAIN_CHARGER_C, main_charger_c_raw);
  1821. seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
  1822. return 0;
  1823. }
  1824. static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
  1825. struct file *file)
  1826. {
  1827. return single_open(file, ab8500_gpadc_main_charger_c_print,
  1828. inode->i_private);
  1829. }
  1830. static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
  1831. .open = ab8500_gpadc_main_charger_c_open,
  1832. .read = seq_read,
  1833. .llseek = seq_lseek,
  1834. .release = single_release,
  1835. .owner = THIS_MODULE,
  1836. };
  1837. static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
  1838. {
  1839. int usb_charger_c_raw;
  1840. int usb_charger_c_convert;
  1841. struct ab8500_gpadc *gpadc;
  1842. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1843. usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
  1844. avg_sample, trig_edge, trig_timer, conv_type);
  1845. usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1846. USB_CHARGER_C, usb_charger_c_raw);
  1847. seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
  1848. return 0;
  1849. }
  1850. static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
  1851. struct file *file)
  1852. {
  1853. return single_open(file, ab8500_gpadc_usb_charger_c_print,
  1854. inode->i_private);
  1855. }
  1856. static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
  1857. .open = ab8500_gpadc_usb_charger_c_open,
  1858. .read = seq_read,
  1859. .llseek = seq_lseek,
  1860. .release = single_release,
  1861. .owner = THIS_MODULE,
  1862. };
  1863. static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
  1864. {
  1865. int bk_bat_v_raw;
  1866. int bk_bat_v_convert;
  1867. struct ab8500_gpadc *gpadc;
  1868. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1869. bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
  1870. avg_sample, trig_edge, trig_timer, conv_type);
  1871. bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  1872. BK_BAT_V, bk_bat_v_raw);
  1873. seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
  1874. return 0;
  1875. }
  1876. static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
  1877. {
  1878. return single_open(file, ab8500_gpadc_bk_bat_v_print,
  1879. inode->i_private);
  1880. }
  1881. static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
  1882. .open = ab8500_gpadc_bk_bat_v_open,
  1883. .read = seq_read,
  1884. .llseek = seq_lseek,
  1885. .release = single_release,
  1886. .owner = THIS_MODULE,
  1887. };
  1888. static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
  1889. {
  1890. int die_temp_raw;
  1891. int die_temp_convert;
  1892. struct ab8500_gpadc *gpadc;
  1893. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1894. die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
  1895. avg_sample, trig_edge, trig_timer, conv_type);
  1896. die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
  1897. die_temp_raw);
  1898. seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
  1899. return 0;
  1900. }
  1901. static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
  1902. {
  1903. return single_open(file, ab8500_gpadc_die_temp_print,
  1904. inode->i_private);
  1905. }
  1906. static const struct file_operations ab8500_gpadc_die_temp_fops = {
  1907. .open = ab8500_gpadc_die_temp_open,
  1908. .read = seq_read,
  1909. .llseek = seq_lseek,
  1910. .release = single_release,
  1911. .owner = THIS_MODULE,
  1912. };
  1913. static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
  1914. {
  1915. int usb_id_raw;
  1916. int usb_id_convert;
  1917. struct ab8500_gpadc *gpadc;
  1918. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1919. usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
  1920. avg_sample, trig_edge, trig_timer, conv_type);
  1921. usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
  1922. usb_id_raw);
  1923. seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
  1924. return 0;
  1925. }
  1926. static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
  1927. {
  1928. return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
  1929. }
  1930. static const struct file_operations ab8500_gpadc_usb_id_fops = {
  1931. .open = ab8500_gpadc_usb_id_open,
  1932. .read = seq_read,
  1933. .llseek = seq_lseek,
  1934. .release = single_release,
  1935. .owner = THIS_MODULE,
  1936. };
  1937. static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
  1938. {
  1939. int xtal_temp_raw;
  1940. int xtal_temp_convert;
  1941. struct ab8500_gpadc *gpadc;
  1942. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1943. xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
  1944. avg_sample, trig_edge, trig_timer, conv_type);
  1945. xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
  1946. xtal_temp_raw);
  1947. seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
  1948. return 0;
  1949. }
  1950. static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
  1951. {
  1952. return single_open(file, ab8540_gpadc_xtal_temp_print,
  1953. inode->i_private);
  1954. }
  1955. static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
  1956. .open = ab8540_gpadc_xtal_temp_open,
  1957. .read = seq_read,
  1958. .llseek = seq_lseek,
  1959. .release = single_release,
  1960. .owner = THIS_MODULE,
  1961. };
  1962. static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
  1963. {
  1964. int vbat_true_meas_raw;
  1965. int vbat_true_meas_convert;
  1966. struct ab8500_gpadc *gpadc;
  1967. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1968. vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
  1969. avg_sample, trig_edge, trig_timer, conv_type);
  1970. vbat_true_meas_convert =
  1971. ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
  1972. vbat_true_meas_raw);
  1973. seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
  1974. return 0;
  1975. }
  1976. static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
  1977. struct file *file)
  1978. {
  1979. return single_open(file, ab8540_gpadc_vbat_true_meas_print,
  1980. inode->i_private);
  1981. }
  1982. static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
  1983. .open = ab8540_gpadc_vbat_true_meas_open,
  1984. .read = seq_read,
  1985. .llseek = seq_lseek,
  1986. .release = single_release,
  1987. .owner = THIS_MODULE,
  1988. };
  1989. static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
  1990. {
  1991. int bat_ctrl_raw;
  1992. int bat_ctrl_convert;
  1993. int ibat_raw;
  1994. int ibat_convert;
  1995. struct ab8500_gpadc *gpadc;
  1996. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  1997. bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
  1998. avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
  1999. bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
  2000. bat_ctrl_raw);
  2001. ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
  2002. ibat_raw);
  2003. seq_printf(s,
  2004. "%d,0x%X\n"
  2005. "%d,0x%X\n",
  2006. bat_ctrl_convert, bat_ctrl_raw,
  2007. ibat_convert, ibat_raw);
  2008. return 0;
  2009. }
  2010. static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
  2011. struct file *file)
  2012. {
  2013. return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
  2014. inode->i_private);
  2015. }
  2016. static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
  2017. .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
  2018. .read = seq_read,
  2019. .llseek = seq_lseek,
  2020. .release = single_release,
  2021. .owner = THIS_MODULE,
  2022. };
  2023. static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
  2024. {
  2025. int vbat_meas_raw;
  2026. int vbat_meas_convert;
  2027. int ibat_raw;
  2028. int ibat_convert;
  2029. struct ab8500_gpadc *gpadc;
  2030. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  2031. vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
  2032. avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
  2033. vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
  2034. vbat_meas_raw);
  2035. ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
  2036. ibat_raw);
  2037. seq_printf(s,
  2038. "%d,0x%X\n"
  2039. "%d,0x%X\n",
  2040. vbat_meas_convert, vbat_meas_raw,
  2041. ibat_convert, ibat_raw);
  2042. return 0;
  2043. }
  2044. static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
  2045. struct file *file)
  2046. {
  2047. return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
  2048. inode->i_private);
  2049. }
  2050. static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
  2051. .open = ab8540_gpadc_vbat_meas_and_ibat_open,
  2052. .read = seq_read,
  2053. .llseek = seq_lseek,
  2054. .release = single_release,
  2055. .owner = THIS_MODULE,
  2056. };
  2057. static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s,
  2058. void *p)
  2059. {
  2060. int vbat_true_meas_raw;
  2061. int vbat_true_meas_convert;
  2062. int ibat_raw;
  2063. int ibat_convert;
  2064. struct ab8500_gpadc *gpadc;
  2065. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  2066. vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
  2067. VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
  2068. trig_timer, conv_type, &ibat_raw);
  2069. vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
  2070. VBAT_TRUE_MEAS, vbat_true_meas_raw);
  2071. ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
  2072. ibat_raw);
  2073. seq_printf(s,
  2074. "%d,0x%X\n"
  2075. "%d,0x%X\n",
  2076. vbat_true_meas_convert, vbat_true_meas_raw,
  2077. ibat_convert, ibat_raw);
  2078. return 0;
  2079. }
  2080. static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
  2081. struct file *file)
  2082. {
  2083. return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
  2084. inode->i_private);
  2085. }
  2086. static const struct file_operations
  2087. ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
  2088. .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
  2089. .read = seq_read,
  2090. .llseek = seq_lseek,
  2091. .release = single_release,
  2092. .owner = THIS_MODULE,
  2093. };
  2094. static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
  2095. {
  2096. int bat_temp_raw;
  2097. int bat_temp_convert;
  2098. int ibat_raw;
  2099. int ibat_convert;
  2100. struct ab8500_gpadc *gpadc;
  2101. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  2102. bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
  2103. avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
  2104. bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
  2105. bat_temp_raw);
  2106. ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
  2107. ibat_raw);
  2108. seq_printf(s,
  2109. "%d,0x%X\n"
  2110. "%d,0x%X\n",
  2111. bat_temp_convert, bat_temp_raw,
  2112. ibat_convert, ibat_raw);
  2113. return 0;
  2114. }
  2115. static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
  2116. struct file *file)
  2117. {
  2118. return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
  2119. inode->i_private);
  2120. }
  2121. static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
  2122. .open = ab8540_gpadc_bat_temp_and_ibat_open,
  2123. .read = seq_read,
  2124. .llseek = seq_lseek,
  2125. .release = single_release,
  2126. .owner = THIS_MODULE,
  2127. };
  2128. static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
  2129. {
  2130. struct ab8500_gpadc *gpadc;
  2131. u16 vmain_l, vmain_h, btemp_l, btemp_h;
  2132. u16 vbat_l, vbat_h, ibat_l, ibat_h;
  2133. gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  2134. ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
  2135. &vbat_l, &vbat_h, &ibat_l, &ibat_h);
  2136. seq_printf(s,
  2137. "VMAIN_L:0x%X\n"
  2138. "VMAIN_H:0x%X\n"
  2139. "BTEMP_L:0x%X\n"
  2140. "BTEMP_H:0x%X\n"
  2141. "VBAT_L:0x%X\n"
  2142. "VBAT_H:0x%X\n"
  2143. "IBAT_L:0x%X\n"
  2144. "IBAT_H:0x%X\n",
  2145. vmain_l, vmain_h, btemp_l, btemp_h,
  2146. vbat_l, vbat_h, ibat_l, ibat_h);
  2147. return 0;
  2148. }
  2149. static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
  2150. {
  2151. return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
  2152. }
  2153. static const struct file_operations ab8540_gpadc_otp_calib_fops = {
  2154. .open = ab8540_gpadc_otp_cal_open,
  2155. .read = seq_read,
  2156. .llseek = seq_lseek,
  2157. .release = single_release,
  2158. .owner = THIS_MODULE,
  2159. };
  2160. static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
  2161. {
  2162. seq_printf(s, "%d\n", avg_sample);
  2163. return 0;
  2164. }
  2165. static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
  2166. {
  2167. return single_open(file, ab8500_gpadc_avg_sample_print,
  2168. inode->i_private);
  2169. }
  2170. static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
  2171. const char __user *user_buf,
  2172. size_t count, loff_t *ppos)
  2173. {
  2174. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  2175. unsigned long user_avg_sample;
  2176. int err;
  2177. err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
  2178. if (err)
  2179. return err;
  2180. if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
  2181. || (user_avg_sample == SAMPLE_8)
  2182. || (user_avg_sample == SAMPLE_16)) {
  2183. avg_sample = (u8) user_avg_sample;
  2184. } else {
  2185. dev_err(dev,
  2186. "debugfs err input: should be egal to 1, 4, 8 or 16\n");
  2187. return -EINVAL;
  2188. }
  2189. return count;
  2190. }
  2191. static const struct file_operations ab8500_gpadc_avg_sample_fops = {
  2192. .open = ab8500_gpadc_avg_sample_open,
  2193. .read = seq_read,
  2194. .write = ab8500_gpadc_avg_sample_write,
  2195. .llseek = seq_lseek,
  2196. .release = single_release,
  2197. .owner = THIS_MODULE,
  2198. };
  2199. static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
  2200. {
  2201. seq_printf(s, "%d\n", trig_edge);
  2202. return 0;
  2203. }
  2204. static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
  2205. {
  2206. return single_open(file, ab8500_gpadc_trig_edge_print,
  2207. inode->i_private);
  2208. }
  2209. static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
  2210. const char __user *user_buf,
  2211. size_t count, loff_t *ppos)
  2212. {
  2213. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  2214. unsigned long user_trig_edge;
  2215. int err;
  2216. err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
  2217. if (err)
  2218. return err;
  2219. if ((user_trig_edge == RISING_EDGE)
  2220. || (user_trig_edge == FALLING_EDGE)) {
  2221. trig_edge = (u8) user_trig_edge;
  2222. } else {
  2223. dev_err(dev, "Wrong input:\n"
  2224. "Enter 0. Rising edge\n"
  2225. "Enter 1. Falling edge\n");
  2226. return -EINVAL;
  2227. }
  2228. return count;
  2229. }
  2230. static const struct file_operations ab8500_gpadc_trig_edge_fops = {
  2231. .open = ab8500_gpadc_trig_edge_open,
  2232. .read = seq_read,
  2233. .write = ab8500_gpadc_trig_edge_write,
  2234. .llseek = seq_lseek,
  2235. .release = single_release,
  2236. .owner = THIS_MODULE,
  2237. };
  2238. static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
  2239. {
  2240. seq_printf(s, "%d\n", trig_timer);
  2241. return 0;
  2242. }
  2243. static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
  2244. {
  2245. return single_open(file, ab8500_gpadc_trig_timer_print,
  2246. inode->i_private);
  2247. }
  2248. static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
  2249. const char __user *user_buf,
  2250. size_t count, loff_t *ppos)
  2251. {
  2252. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  2253. unsigned long user_trig_timer;
  2254. int err;
  2255. err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
  2256. if (err)
  2257. return err;
  2258. if (user_trig_timer & ~0xFF) {
  2259. dev_err(dev,
  2260. "debugfs error input: should be between 0 to 255\n");
  2261. return -EINVAL;
  2262. }
  2263. trig_timer = (u8) user_trig_timer;
  2264. return count;
  2265. }
  2266. static const struct file_operations ab8500_gpadc_trig_timer_fops = {
  2267. .open = ab8500_gpadc_trig_timer_open,
  2268. .read = seq_read,
  2269. .write = ab8500_gpadc_trig_timer_write,
  2270. .llseek = seq_lseek,
  2271. .release = single_release,
  2272. .owner = THIS_MODULE,
  2273. };
  2274. static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
  2275. {
  2276. seq_printf(s, "%d\n", conv_type);
  2277. return 0;
  2278. }
  2279. static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
  2280. {
  2281. return single_open(file, ab8500_gpadc_conv_type_print,
  2282. inode->i_private);
  2283. }
  2284. static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
  2285. const char __user *user_buf,
  2286. size_t count, loff_t *ppos)
  2287. {
  2288. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  2289. unsigned long user_conv_type;
  2290. int err;
  2291. err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
  2292. if (err)
  2293. return err;
  2294. if ((user_conv_type == ADC_SW)
  2295. || (user_conv_type == ADC_HW)) {
  2296. conv_type = (u8) user_conv_type;
  2297. } else {
  2298. dev_err(dev, "Wrong input:\n"
  2299. "Enter 0. ADC SW conversion\n"
  2300. "Enter 1. ADC HW conversion\n");
  2301. return -EINVAL;
  2302. }
  2303. return count;
  2304. }
  2305. static const struct file_operations ab8500_gpadc_conv_type_fops = {
  2306. .open = ab8500_gpadc_conv_type_open,
  2307. .read = seq_read,
  2308. .write = ab8500_gpadc_conv_type_write,
  2309. .llseek = seq_lseek,
  2310. .release = single_release,
  2311. .owner = THIS_MODULE,
  2312. };
  2313. /*
  2314. * return length of an ASCII numerical value, 0 is string is not a
  2315. * numerical value.
  2316. * string shall start at value 1st char.
  2317. * string can be tailed with \0 or space or newline chars only.
  2318. * value can be decimal or hexadecimal (prefixed 0x or 0X).
  2319. */
  2320. static int strval_len(char *b)
  2321. {
  2322. char *s = b;
  2323. if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
  2324. s += 2;
  2325. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  2326. if (!isxdigit(*s))
  2327. return 0;
  2328. }
  2329. } else {
  2330. if (*s == '-')
  2331. s++;
  2332. for (; *s && (*s != ' ') && (*s != '\n'); s++) {
  2333. if (!isdigit(*s))
  2334. return 0;
  2335. }
  2336. }
  2337. return (int) (s-b);
  2338. }
  2339. /*
  2340. * parse hwreg input data.
  2341. * update global hwreg_cfg only if input data syntax is ok.
  2342. */
  2343. static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
  2344. struct device *dev)
  2345. {
  2346. uint write, val = 0;
  2347. u8 regvalue;
  2348. int ret;
  2349. struct hwreg_cfg loc = {
  2350. .bank = 0, /* default: invalid phys addr */
  2351. .addr = 0, /* default: invalid phys addr */
  2352. .fmt = 0, /* default: 32bit access, hex output */
  2353. .mask = 0xFFFFFFFF, /* default: no mask */
  2354. .shift = 0, /* default: no bit shift */
  2355. };
  2356. /* read or write ? */
  2357. if (!strncmp(b, "read ", 5)) {
  2358. write = 0;
  2359. b += 5;
  2360. } else if (!strncmp(b, "write ", 6)) {
  2361. write = 1;
  2362. b += 6;
  2363. } else
  2364. return -EINVAL;
  2365. /* OPTIONS -l|-w|-b -s -m -o */
  2366. while ((*b == ' ') || (*b == '-')) {
  2367. if (*(b-1) != ' ') {
  2368. b++;
  2369. continue;
  2370. }
  2371. if ((!strncmp(b, "-d ", 3)) ||
  2372. (!strncmp(b, "-dec ", 5))) {
  2373. b += (*(b+2) == ' ') ? 3 : 5;
  2374. loc.fmt |= (1<<0);
  2375. } else if ((!strncmp(b, "-h ", 3)) ||
  2376. (!strncmp(b, "-hex ", 5))) {
  2377. b += (*(b+2) == ' ') ? 3 : 5;
  2378. loc.fmt &= ~(1<<0);
  2379. } else if ((!strncmp(b, "-m ", 3)) ||
  2380. (!strncmp(b, "-mask ", 6))) {
  2381. b += (*(b+2) == ' ') ? 3 : 6;
  2382. if (strval_len(b) == 0)
  2383. return -EINVAL;
  2384. ret = kstrtoul(b, 0, &loc.mask);
  2385. if (ret)
  2386. return ret;
  2387. } else if ((!strncmp(b, "-s ", 3)) ||
  2388. (!strncmp(b, "-shift ", 7))) {
  2389. b += (*(b+2) == ' ') ? 3 : 7;
  2390. if (strval_len(b) == 0)
  2391. return -EINVAL;
  2392. ret = kstrtol(b, 0, &loc.shift);
  2393. if (ret)
  2394. return ret;
  2395. } else {
  2396. return -EINVAL;
  2397. }
  2398. }
  2399. /* get arg BANK and ADDRESS */
  2400. if (strval_len(b) == 0)
  2401. return -EINVAL;
  2402. ret = kstrtouint(b, 0, &loc.bank);
  2403. if (ret)
  2404. return ret;
  2405. while (*b == ' ')
  2406. b++;
  2407. if (strval_len(b) == 0)
  2408. return -EINVAL;
  2409. ret = kstrtoul(b, 0, &loc.addr);
  2410. if (ret)
  2411. return ret;
  2412. if (write) {
  2413. while (*b == ' ')
  2414. b++;
  2415. if (strval_len(b) == 0)
  2416. return -EINVAL;
  2417. ret = kstrtouint(b, 0, &val);
  2418. if (ret)
  2419. return ret;
  2420. }
  2421. /* args are ok, update target cfg (mainly for read) */
  2422. *cfg = loc;
  2423. #ifdef ABB_HWREG_DEBUG
  2424. pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
  2425. REG_FMT_DEC(cfg) ? "decimal" : "hexa");
  2426. pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
  2427. cfg->addr, cfg->mask, cfg->shift, val);
  2428. #endif
  2429. if (!write)
  2430. return 0;
  2431. ret = abx500_get_register_interruptible(dev,
  2432. (u8)cfg->bank, (u8)cfg->addr, &regvalue);
  2433. if (ret < 0) {
  2434. dev_err(dev, "abx500_get_reg fail %d, %d\n",
  2435. ret, __LINE__);
  2436. return -EINVAL;
  2437. }
  2438. if (cfg->shift >= 0) {
  2439. regvalue &= ~(cfg->mask << (cfg->shift));
  2440. val = (val & cfg->mask) << (cfg->shift);
  2441. } else {
  2442. regvalue &= ~(cfg->mask >> (-cfg->shift));
  2443. val = (val & cfg->mask) >> (-cfg->shift);
  2444. }
  2445. val = val | regvalue;
  2446. ret = abx500_set_register_interruptible(dev,
  2447. (u8)cfg->bank, (u8)cfg->addr, (u8)val);
  2448. if (ret < 0) {
  2449. pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
  2450. return -EINVAL;
  2451. }
  2452. return 0;
  2453. }
  2454. static ssize_t ab8500_hwreg_write(struct file *file,
  2455. const char __user *user_buf, size_t count, loff_t *ppos)
  2456. {
  2457. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  2458. char buf[128];
  2459. int buf_size, ret;
  2460. /* Get userspace string and assure termination */
  2461. buf_size = min(count, (sizeof(buf)-1));
  2462. if (copy_from_user(buf, user_buf, buf_size))
  2463. return -EFAULT;
  2464. buf[buf_size] = 0;
  2465. /* get args and process */
  2466. ret = hwreg_common_write(buf, &hwreg_cfg, dev);
  2467. return (ret) ? ret : buf_size;
  2468. }
  2469. /*
  2470. * - irq subscribe/unsubscribe stuff
  2471. */
  2472. static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
  2473. {
  2474. seq_printf(s, "%d\n", irq_first);
  2475. return 0;
  2476. }
  2477. static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
  2478. struct file *file)
  2479. {
  2480. return single_open(file, ab8500_subscribe_unsubscribe_print,
  2481. inode->i_private);
  2482. }
  2483. /*
  2484. * Userspace should use poll() on this file. When an event occur
  2485. * the blocking poll will be released.
  2486. */
  2487. static ssize_t show_irq(struct device *dev,
  2488. struct device_attribute *attr, char *buf)
  2489. {
  2490. unsigned long name;
  2491. unsigned int irq_index;
  2492. int err;
  2493. err = kstrtoul(attr->attr.name, 0, &name);
  2494. if (err)
  2495. return err;
  2496. irq_index = name - irq_first;
  2497. if (irq_index >= num_irqs)
  2498. return -EINVAL;
  2499. return sprintf(buf, "%u\n", irq_count[irq_index]);
  2500. }
  2501. static ssize_t ab8500_subscribe_write(struct file *file,
  2502. const char __user *user_buf,
  2503. size_t count, loff_t *ppos)
  2504. {
  2505. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  2506. unsigned long user_val;
  2507. int err;
  2508. unsigned int irq_index;
  2509. err = kstrtoul_from_user(user_buf, count, 0, &user_val);
  2510. if (err)
  2511. return err;
  2512. if (user_val < irq_first) {
  2513. dev_err(dev, "debugfs error input < %d\n", irq_first);
  2514. return -EINVAL;
  2515. }
  2516. if (user_val > irq_last) {
  2517. dev_err(dev, "debugfs error input > %d\n", irq_last);
  2518. return -EINVAL;
  2519. }
  2520. irq_index = user_val - irq_first;
  2521. if (irq_index >= num_irqs)
  2522. return -EINVAL;
  2523. /*
  2524. * This will create a sysfs file named <irq-nr> which userspace can
  2525. * use to select or poll and get the AB8500 events
  2526. */
  2527. dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
  2528. GFP_KERNEL);
  2529. if (!dev_attr[irq_index])
  2530. return -ENOMEM;
  2531. event_name[irq_index] = kmalloc(count, GFP_KERNEL);
  2532. if (!event_name[irq_index])
  2533. return -ENOMEM;
  2534. sprintf(event_name[irq_index], "%lu", user_val);
  2535. dev_attr[irq_index]->show = show_irq;
  2536. dev_attr[irq_index]->store = NULL;
  2537. dev_attr[irq_index]->attr.name = event_name[irq_index];
  2538. dev_attr[irq_index]->attr.mode = S_IRUGO;
  2539. err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
  2540. if (err < 0) {
  2541. pr_info("sysfs_create_file failed %d\n", err);
  2542. return err;
  2543. }
  2544. err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
  2545. IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
  2546. "ab8500-debug", &dev->kobj);
  2547. if (err < 0) {
  2548. pr_info("request_threaded_irq failed %d, %lu\n",
  2549. err, user_val);
  2550. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  2551. return err;
  2552. }
  2553. return count;
  2554. }
  2555. static ssize_t ab8500_unsubscribe_write(struct file *file,
  2556. const char __user *user_buf,
  2557. size_t count, loff_t *ppos)
  2558. {
  2559. struct device *dev = ((struct seq_file *)(file->private_data))->private;
  2560. unsigned long user_val;
  2561. int err;
  2562. unsigned int irq_index;
  2563. err = kstrtoul_from_user(user_buf, count, 0, &user_val);
  2564. if (err)
  2565. return err;
  2566. if (user_val < irq_first) {
  2567. dev_err(dev, "debugfs error input < %d\n", irq_first);
  2568. return -EINVAL;
  2569. }
  2570. if (user_val > irq_last) {
  2571. dev_err(dev, "debugfs error input > %d\n", irq_last);
  2572. return -EINVAL;
  2573. }
  2574. irq_index = user_val - irq_first;
  2575. if (irq_index >= num_irqs)
  2576. return -EINVAL;
  2577. /* Set irq count to 0 when unsubscribe */
  2578. irq_count[irq_index] = 0;
  2579. if (dev_attr[irq_index])
  2580. sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
  2581. free_irq(user_val, &dev->kobj);
  2582. kfree(event_name[irq_index]);
  2583. kfree(dev_attr[irq_index]);
  2584. return count;
  2585. }
  2586. /*
  2587. * - several deubgfs nodes fops
  2588. */
  2589. static const struct file_operations ab8500_bank_fops = {
  2590. .open = ab8500_bank_open,
  2591. .write = ab8500_bank_write,
  2592. .read = seq_read,
  2593. .llseek = seq_lseek,
  2594. .release = single_release,
  2595. .owner = THIS_MODULE,
  2596. };
  2597. static const struct file_operations ab8500_address_fops = {
  2598. .open = ab8500_address_open,
  2599. .write = ab8500_address_write,
  2600. .read = seq_read,
  2601. .llseek = seq_lseek,
  2602. .release = single_release,
  2603. .owner = THIS_MODULE,
  2604. };
  2605. static const struct file_operations ab8500_val_fops = {
  2606. .open = ab8500_val_open,
  2607. .write = ab8500_val_write,
  2608. .read = seq_read,
  2609. .llseek = seq_lseek,
  2610. .release = single_release,
  2611. .owner = THIS_MODULE,
  2612. };
  2613. static const struct file_operations ab8500_interrupts_fops = {
  2614. .open = ab8500_interrupts_open,
  2615. .read = seq_read,
  2616. .llseek = seq_lseek,
  2617. .release = single_release,
  2618. .owner = THIS_MODULE,
  2619. };
  2620. static const struct file_operations ab8500_subscribe_fops = {
  2621. .open = ab8500_subscribe_unsubscribe_open,
  2622. .write = ab8500_subscribe_write,
  2623. .read = seq_read,
  2624. .llseek = seq_lseek,
  2625. .release = single_release,
  2626. .owner = THIS_MODULE,
  2627. };
  2628. static const struct file_operations ab8500_unsubscribe_fops = {
  2629. .open = ab8500_subscribe_unsubscribe_open,
  2630. .write = ab8500_unsubscribe_write,
  2631. .read = seq_read,
  2632. .llseek = seq_lseek,
  2633. .release = single_release,
  2634. .owner = THIS_MODULE,
  2635. };
  2636. static const struct file_operations ab8500_hwreg_fops = {
  2637. .open = ab8500_hwreg_open,
  2638. .write = ab8500_hwreg_write,
  2639. .read = seq_read,
  2640. .llseek = seq_lseek,
  2641. .release = single_release,
  2642. .owner = THIS_MODULE,
  2643. };
  2644. static struct dentry *ab8500_dir;
  2645. static struct dentry *ab8500_gpadc_dir;
  2646. static int ab8500_debug_probe(struct platform_device *plf)
  2647. {
  2648. struct dentry *file;
  2649. struct ab8500 *ab8500;
  2650. struct resource *res;
  2651. debug_bank = AB8500_MISC;
  2652. debug_address = AB8500_REV_REG & 0x00FF;
  2653. ab8500 = dev_get_drvdata(plf->dev.parent);
  2654. num_irqs = ab8500->mask_size;
  2655. irq_count = devm_kzalloc(&plf->dev,
  2656. sizeof(*irq_count)*num_irqs, GFP_KERNEL);
  2657. if (!irq_count)
  2658. return -ENOMEM;
  2659. dev_attr = devm_kzalloc(&plf->dev,
  2660. sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
  2661. if (!dev_attr)
  2662. return -ENOMEM;
  2663. event_name = devm_kzalloc(&plf->dev,
  2664. sizeof(*event_name)*num_irqs, GFP_KERNEL);
  2665. if (!event_name)
  2666. return -ENOMEM;
  2667. res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
  2668. if (!res) {
  2669. dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
  2670. return -ENXIO;
  2671. }
  2672. irq_ab8500 = res->start;
  2673. irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
  2674. if (irq_first < 0) {
  2675. dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
  2676. return irq_first;
  2677. }
  2678. irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
  2679. if (irq_last < 0) {
  2680. dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
  2681. return irq_last;
  2682. }
  2683. ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
  2684. if (!ab8500_dir)
  2685. goto err;
  2686. ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
  2687. ab8500_dir);
  2688. if (!ab8500_gpadc_dir)
  2689. goto err;
  2690. file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
  2691. &plf->dev, &ab8500_registers_fops);
  2692. if (!file)
  2693. goto err;
  2694. file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
  2695. &plf->dev, &ab8500_all_banks_fops);
  2696. if (!file)
  2697. goto err;
  2698. file = debugfs_create_file("register-bank",
  2699. (S_IRUGO | S_IWUSR | S_IWGRP),
  2700. ab8500_dir, &plf->dev, &ab8500_bank_fops);
  2701. if (!file)
  2702. goto err;
  2703. file = debugfs_create_file("register-address",
  2704. (S_IRUGO | S_IWUSR | S_IWGRP),
  2705. ab8500_dir, &plf->dev, &ab8500_address_fops);
  2706. if (!file)
  2707. goto err;
  2708. file = debugfs_create_file("register-value",
  2709. (S_IRUGO | S_IWUSR | S_IWGRP),
  2710. ab8500_dir, &plf->dev, &ab8500_val_fops);
  2711. if (!file)
  2712. goto err;
  2713. file = debugfs_create_file("irq-subscribe",
  2714. (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
  2715. &plf->dev, &ab8500_subscribe_fops);
  2716. if (!file)
  2717. goto err;
  2718. if (is_ab8500(ab8500)) {
  2719. debug_ranges = ab8500_debug_ranges;
  2720. num_interrupt_lines = AB8500_NR_IRQS;
  2721. } else if (is_ab8505(ab8500)) {
  2722. debug_ranges = ab8505_debug_ranges;
  2723. num_interrupt_lines = AB8505_NR_IRQS;
  2724. } else if (is_ab9540(ab8500)) {
  2725. debug_ranges = ab8505_debug_ranges;
  2726. num_interrupt_lines = AB9540_NR_IRQS;
  2727. } else if (is_ab8540(ab8500)) {
  2728. debug_ranges = ab8540_debug_ranges;
  2729. num_interrupt_lines = AB8540_NR_IRQS;
  2730. }
  2731. file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
  2732. &plf->dev, &ab8500_interrupts_fops);
  2733. if (!file)
  2734. goto err;
  2735. file = debugfs_create_file("irq-unsubscribe",
  2736. (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
  2737. &plf->dev, &ab8500_unsubscribe_fops);
  2738. if (!file)
  2739. goto err;
  2740. file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
  2741. ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
  2742. if (!file)
  2743. goto err;
  2744. file = debugfs_create_file("all-modem-registers",
  2745. (S_IRUGO | S_IWUSR | S_IWGRP),
  2746. ab8500_dir, &plf->dev, &ab8500_modem_fops);
  2747. if (!file)
  2748. goto err;
  2749. file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
  2750. ab8500_gpadc_dir, &plf->dev,
  2751. &ab8500_gpadc_bat_ctrl_fops);
  2752. if (!file)
  2753. goto err;
  2754. file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
  2755. ab8500_gpadc_dir,
  2756. &plf->dev, &ab8500_gpadc_btemp_ball_fops);
  2757. if (!file)
  2758. goto err;
  2759. file = debugfs_create_file("main_charger_v",
  2760. (S_IRUGO | S_IWUSR | S_IWGRP),
  2761. ab8500_gpadc_dir, &plf->dev,
  2762. &ab8500_gpadc_main_charger_v_fops);
  2763. if (!file)
  2764. goto err;
  2765. file = debugfs_create_file("acc_detect1",
  2766. (S_IRUGO | S_IWUSR | S_IWGRP),
  2767. ab8500_gpadc_dir, &plf->dev,
  2768. &ab8500_gpadc_acc_detect1_fops);
  2769. if (!file)
  2770. goto err;
  2771. file = debugfs_create_file("acc_detect2",
  2772. (S_IRUGO | S_IWUSR | S_IWGRP),
  2773. ab8500_gpadc_dir, &plf->dev,
  2774. &ab8500_gpadc_acc_detect2_fops);
  2775. if (!file)
  2776. goto err;
  2777. file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
  2778. ab8500_gpadc_dir, &plf->dev,
  2779. &ab8500_gpadc_aux1_fops);
  2780. if (!file)
  2781. goto err;
  2782. file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
  2783. ab8500_gpadc_dir, &plf->dev,
  2784. &ab8500_gpadc_aux2_fops);
  2785. if (!file)
  2786. goto err;
  2787. file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
  2788. ab8500_gpadc_dir, &plf->dev,
  2789. &ab8500_gpadc_main_bat_v_fops);
  2790. if (!file)
  2791. goto err;
  2792. file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
  2793. ab8500_gpadc_dir, &plf->dev,
  2794. &ab8500_gpadc_vbus_v_fops);
  2795. if (!file)
  2796. goto err;
  2797. file = debugfs_create_file("main_charger_c",
  2798. (S_IRUGO | S_IWUSR | S_IWGRP),
  2799. ab8500_gpadc_dir, &plf->dev,
  2800. &ab8500_gpadc_main_charger_c_fops);
  2801. if (!file)
  2802. goto err;
  2803. file = debugfs_create_file("usb_charger_c",
  2804. (S_IRUGO | S_IWUSR | S_IWGRP),
  2805. ab8500_gpadc_dir,
  2806. &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
  2807. if (!file)
  2808. goto err;
  2809. file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
  2810. ab8500_gpadc_dir, &plf->dev,
  2811. &ab8500_gpadc_bk_bat_v_fops);
  2812. if (!file)
  2813. goto err;
  2814. file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
  2815. ab8500_gpadc_dir, &plf->dev,
  2816. &ab8500_gpadc_die_temp_fops);
  2817. if (!file)
  2818. goto err;
  2819. file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
  2820. ab8500_gpadc_dir, &plf->dev,
  2821. &ab8500_gpadc_usb_id_fops);
  2822. if (!file)
  2823. goto err;
  2824. if (is_ab8540(ab8500)) {
  2825. file = debugfs_create_file("xtal_temp",
  2826. (S_IRUGO | S_IWUSR | S_IWGRP),
  2827. ab8500_gpadc_dir, &plf->dev,
  2828. &ab8540_gpadc_xtal_temp_fops);
  2829. if (!file)
  2830. goto err;
  2831. file = debugfs_create_file("vbattruemeas",
  2832. (S_IRUGO | S_IWUSR | S_IWGRP),
  2833. ab8500_gpadc_dir, &plf->dev,
  2834. &ab8540_gpadc_vbat_true_meas_fops);
  2835. if (!file)
  2836. goto err;
  2837. file = debugfs_create_file("batctrl_and_ibat",
  2838. (S_IRUGO | S_IWUGO),
  2839. ab8500_gpadc_dir,
  2840. &plf->dev,
  2841. &ab8540_gpadc_bat_ctrl_and_ibat_fops);
  2842. if (!file)
  2843. goto err;
  2844. file = debugfs_create_file("vbatmeas_and_ibat",
  2845. (S_IRUGO | S_IWUGO),
  2846. ab8500_gpadc_dir, &plf->dev,
  2847. &ab8540_gpadc_vbat_meas_and_ibat_fops);
  2848. if (!file)
  2849. goto err;
  2850. file = debugfs_create_file("vbattruemeas_and_ibat",
  2851. (S_IRUGO | S_IWUGO),
  2852. ab8500_gpadc_dir,
  2853. &plf->dev,
  2854. &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
  2855. if (!file)
  2856. goto err;
  2857. file = debugfs_create_file("battemp_and_ibat",
  2858. (S_IRUGO | S_IWUGO),
  2859. ab8500_gpadc_dir,
  2860. &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
  2861. if (!file)
  2862. goto err;
  2863. file = debugfs_create_file("otp_calib",
  2864. (S_IRUGO | S_IWUSR | S_IWGRP),
  2865. ab8500_gpadc_dir,
  2866. &plf->dev, &ab8540_gpadc_otp_calib_fops);
  2867. if (!file)
  2868. goto err;
  2869. }
  2870. file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
  2871. ab8500_gpadc_dir, &plf->dev,
  2872. &ab8500_gpadc_avg_sample_fops);
  2873. if (!file)
  2874. goto err;
  2875. file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
  2876. ab8500_gpadc_dir, &plf->dev,
  2877. &ab8500_gpadc_trig_edge_fops);
  2878. if (!file)
  2879. goto err;
  2880. file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
  2881. ab8500_gpadc_dir, &plf->dev,
  2882. &ab8500_gpadc_trig_timer_fops);
  2883. if (!file)
  2884. goto err;
  2885. file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
  2886. ab8500_gpadc_dir, &plf->dev,
  2887. &ab8500_gpadc_conv_type_fops);
  2888. if (!file)
  2889. goto err;
  2890. return 0;
  2891. err:
  2892. debugfs_remove_recursive(ab8500_dir);
  2893. dev_err(&plf->dev, "failed to create debugfs entries.\n");
  2894. return -ENOMEM;
  2895. }
  2896. static int ab8500_debug_remove(struct platform_device *plf)
  2897. {
  2898. debugfs_remove_recursive(ab8500_dir);
  2899. return 0;
  2900. }
  2901. static struct platform_driver ab8500_debug_driver = {
  2902. .driver = {
  2903. .name = "ab8500-debug",
  2904. },
  2905. .probe = ab8500_debug_probe,
  2906. .remove = ab8500_debug_remove
  2907. };
  2908. static int __init ab8500_debug_init(void)
  2909. {
  2910. return platform_driver_register(&ab8500_debug_driver);
  2911. }
  2912. static void __exit ab8500_debug_exit(void)
  2913. {
  2914. platform_driver_unregister(&ab8500_debug_driver);
  2915. }
  2916. subsys_initcall(ab8500_debug_init);
  2917. module_exit(ab8500_debug_exit);
  2918. MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
  2919. MODULE_DESCRIPTION("AB8500 DEBUG");
  2920. MODULE_LICENSE("GPL v2");