wm831x-core.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939
  1. /*
  2. * wm831x-core.c -- Device access for Wolfson WM831x PMICs
  3. *
  4. * Copyright 2009 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/bcd.h>
  17. #include <linux/delay.h>
  18. #include <linux/mfd/core.h>
  19. #include <linux/slab.h>
  20. #include <linux/err.h>
  21. #include <linux/mfd/wm831x/core.h>
  22. #include <linux/mfd/wm831x/pdata.h>
  23. #include <linux/mfd/wm831x/irq.h>
  24. #include <linux/mfd/wm831x/auxadc.h>
  25. #include <linux/mfd/wm831x/otp.h>
  26. #include <linux/mfd/wm831x/pmu.h>
  27. #include <linux/mfd/wm831x/regulator.h>
  28. /* Current settings - values are 2*2^(reg_val/4) microamps. These are
  29. * exported since they are used by multiple drivers.
  30. */
  31. int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
  32. 2,
  33. 2,
  34. 3,
  35. 3,
  36. 4,
  37. 5,
  38. 6,
  39. 7,
  40. 8,
  41. 10,
  42. 11,
  43. 13,
  44. 16,
  45. 19,
  46. 23,
  47. 27,
  48. 32,
  49. 38,
  50. 45,
  51. 54,
  52. 64,
  53. 76,
  54. 91,
  55. 108,
  56. 128,
  57. 152,
  58. 181,
  59. 215,
  60. 256,
  61. 304,
  62. 362,
  63. 431,
  64. 512,
  65. 609,
  66. 724,
  67. 861,
  68. 1024,
  69. 1218,
  70. 1448,
  71. 1722,
  72. 2048,
  73. 2435,
  74. 2896,
  75. 3444,
  76. 4096,
  77. 4871,
  78. 5793,
  79. 6889,
  80. 8192,
  81. 9742,
  82. 11585,
  83. 13777,
  84. 16384,
  85. 19484,
  86. 23170,
  87. 27554,
  88. };
  89. EXPORT_SYMBOL_GPL(wm831x_isinkv_values);
  90. static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
  91. {
  92. if (!wm831x->locked)
  93. return 0;
  94. switch (reg) {
  95. case WM831X_WATCHDOG:
  96. case WM831X_DC4_CONTROL:
  97. case WM831X_ON_PIN_CONTROL:
  98. case WM831X_BACKUP_CHARGER_CONTROL:
  99. case WM831X_CHARGER_CONTROL_1:
  100. case WM831X_CHARGER_CONTROL_2:
  101. return 1;
  102. default:
  103. return 0;
  104. }
  105. }
  106. /**
  107. * wm831x_reg_unlock: Unlock user keyed registers
  108. *
  109. * The WM831x has a user key preventing writes to particularly
  110. * critical registers. This function locks those registers,
  111. * allowing writes to them.
  112. */
  113. void wm831x_reg_lock(struct wm831x *wm831x)
  114. {
  115. int ret;
  116. ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  117. if (ret == 0) {
  118. dev_vdbg(wm831x->dev, "Registers locked\n");
  119. mutex_lock(&wm831x->io_lock);
  120. WARN_ON(wm831x->locked);
  121. wm831x->locked = 1;
  122. mutex_unlock(&wm831x->io_lock);
  123. } else {
  124. dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret);
  125. }
  126. }
  127. EXPORT_SYMBOL_GPL(wm831x_reg_lock);
  128. /**
  129. * wm831x_reg_unlock: Unlock user keyed registers
  130. *
  131. * The WM831x has a user key preventing writes to particularly
  132. * critical registers. This function locks those registers,
  133. * preventing spurious writes.
  134. */
  135. int wm831x_reg_unlock(struct wm831x *wm831x)
  136. {
  137. int ret;
  138. /* 0x9716 is the value required to unlock the registers */
  139. ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716);
  140. if (ret == 0) {
  141. dev_vdbg(wm831x->dev, "Registers unlocked\n");
  142. mutex_lock(&wm831x->io_lock);
  143. WARN_ON(!wm831x->locked);
  144. wm831x->locked = 0;
  145. mutex_unlock(&wm831x->io_lock);
  146. }
  147. return ret;
  148. }
  149. EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
  150. static bool wm831x_reg_readable(struct device *dev, unsigned int reg)
  151. {
  152. switch (reg) {
  153. case WM831X_RESET_ID:
  154. case WM831X_REVISION:
  155. case WM831X_PARENT_ID:
  156. case WM831X_SYSVDD_CONTROL:
  157. case WM831X_THERMAL_MONITORING:
  158. case WM831X_POWER_STATE:
  159. case WM831X_WATCHDOG:
  160. case WM831X_ON_PIN_CONTROL:
  161. case WM831X_RESET_CONTROL:
  162. case WM831X_CONTROL_INTERFACE:
  163. case WM831X_SECURITY_KEY:
  164. case WM831X_SOFTWARE_SCRATCH:
  165. case WM831X_OTP_CONTROL:
  166. case WM831X_GPIO_LEVEL:
  167. case WM831X_SYSTEM_STATUS:
  168. case WM831X_ON_SOURCE:
  169. case WM831X_OFF_SOURCE:
  170. case WM831X_SYSTEM_INTERRUPTS:
  171. case WM831X_INTERRUPT_STATUS_1:
  172. case WM831X_INTERRUPT_STATUS_2:
  173. case WM831X_INTERRUPT_STATUS_3:
  174. case WM831X_INTERRUPT_STATUS_4:
  175. case WM831X_INTERRUPT_STATUS_5:
  176. case WM831X_IRQ_CONFIG:
  177. case WM831X_SYSTEM_INTERRUPTS_MASK:
  178. case WM831X_INTERRUPT_STATUS_1_MASK:
  179. case WM831X_INTERRUPT_STATUS_2_MASK:
  180. case WM831X_INTERRUPT_STATUS_3_MASK:
  181. case WM831X_INTERRUPT_STATUS_4_MASK:
  182. case WM831X_INTERRUPT_STATUS_5_MASK:
  183. case WM831X_RTC_WRITE_COUNTER:
  184. case WM831X_RTC_TIME_1:
  185. case WM831X_RTC_TIME_2:
  186. case WM831X_RTC_ALARM_1:
  187. case WM831X_RTC_ALARM_2:
  188. case WM831X_RTC_CONTROL:
  189. case WM831X_RTC_TRIM:
  190. case WM831X_TOUCH_CONTROL_1:
  191. case WM831X_TOUCH_CONTROL_2:
  192. case WM831X_TOUCH_DATA_X:
  193. case WM831X_TOUCH_DATA_Y:
  194. case WM831X_TOUCH_DATA_Z:
  195. case WM831X_AUXADC_DATA:
  196. case WM831X_AUXADC_CONTROL:
  197. case WM831X_AUXADC_SOURCE:
  198. case WM831X_COMPARATOR_CONTROL:
  199. case WM831X_COMPARATOR_1:
  200. case WM831X_COMPARATOR_2:
  201. case WM831X_COMPARATOR_3:
  202. case WM831X_COMPARATOR_4:
  203. case WM831X_GPIO1_CONTROL:
  204. case WM831X_GPIO2_CONTROL:
  205. case WM831X_GPIO3_CONTROL:
  206. case WM831X_GPIO4_CONTROL:
  207. case WM831X_GPIO5_CONTROL:
  208. case WM831X_GPIO6_CONTROL:
  209. case WM831X_GPIO7_CONTROL:
  210. case WM831X_GPIO8_CONTROL:
  211. case WM831X_GPIO9_CONTROL:
  212. case WM831X_GPIO10_CONTROL:
  213. case WM831X_GPIO11_CONTROL:
  214. case WM831X_GPIO12_CONTROL:
  215. case WM831X_GPIO13_CONTROL:
  216. case WM831X_GPIO14_CONTROL:
  217. case WM831X_GPIO15_CONTROL:
  218. case WM831X_GPIO16_CONTROL:
  219. case WM831X_CHARGER_CONTROL_1:
  220. case WM831X_CHARGER_CONTROL_2:
  221. case WM831X_CHARGER_STATUS:
  222. case WM831X_BACKUP_CHARGER_CONTROL:
  223. case WM831X_STATUS_LED_1:
  224. case WM831X_STATUS_LED_2:
  225. case WM831X_CURRENT_SINK_1:
  226. case WM831X_CURRENT_SINK_2:
  227. case WM831X_DCDC_ENABLE:
  228. case WM831X_LDO_ENABLE:
  229. case WM831X_DCDC_STATUS:
  230. case WM831X_LDO_STATUS:
  231. case WM831X_DCDC_UV_STATUS:
  232. case WM831X_LDO_UV_STATUS:
  233. case WM831X_DC1_CONTROL_1:
  234. case WM831X_DC1_CONTROL_2:
  235. case WM831X_DC1_ON_CONFIG:
  236. case WM831X_DC1_SLEEP_CONTROL:
  237. case WM831X_DC1_DVS_CONTROL:
  238. case WM831X_DC2_CONTROL_1:
  239. case WM831X_DC2_CONTROL_2:
  240. case WM831X_DC2_ON_CONFIG:
  241. case WM831X_DC2_SLEEP_CONTROL:
  242. case WM831X_DC2_DVS_CONTROL:
  243. case WM831X_DC3_CONTROL_1:
  244. case WM831X_DC3_CONTROL_2:
  245. case WM831X_DC3_ON_CONFIG:
  246. case WM831X_DC3_SLEEP_CONTROL:
  247. case WM831X_DC4_CONTROL:
  248. case WM831X_DC4_SLEEP_CONTROL:
  249. case WM831X_EPE1_CONTROL:
  250. case WM831X_EPE2_CONTROL:
  251. case WM831X_LDO1_CONTROL:
  252. case WM831X_LDO1_ON_CONTROL:
  253. case WM831X_LDO1_SLEEP_CONTROL:
  254. case WM831X_LDO2_CONTROL:
  255. case WM831X_LDO2_ON_CONTROL:
  256. case WM831X_LDO2_SLEEP_CONTROL:
  257. case WM831X_LDO3_CONTROL:
  258. case WM831X_LDO3_ON_CONTROL:
  259. case WM831X_LDO3_SLEEP_CONTROL:
  260. case WM831X_LDO4_CONTROL:
  261. case WM831X_LDO4_ON_CONTROL:
  262. case WM831X_LDO4_SLEEP_CONTROL:
  263. case WM831X_LDO5_CONTROL:
  264. case WM831X_LDO5_ON_CONTROL:
  265. case WM831X_LDO5_SLEEP_CONTROL:
  266. case WM831X_LDO6_CONTROL:
  267. case WM831X_LDO6_ON_CONTROL:
  268. case WM831X_LDO6_SLEEP_CONTROL:
  269. case WM831X_LDO7_CONTROL:
  270. case WM831X_LDO7_ON_CONTROL:
  271. case WM831X_LDO7_SLEEP_CONTROL:
  272. case WM831X_LDO8_CONTROL:
  273. case WM831X_LDO8_ON_CONTROL:
  274. case WM831X_LDO8_SLEEP_CONTROL:
  275. case WM831X_LDO9_CONTROL:
  276. case WM831X_LDO9_ON_CONTROL:
  277. case WM831X_LDO9_SLEEP_CONTROL:
  278. case WM831X_LDO10_CONTROL:
  279. case WM831X_LDO10_ON_CONTROL:
  280. case WM831X_LDO10_SLEEP_CONTROL:
  281. case WM831X_LDO11_ON_CONTROL:
  282. case WM831X_LDO11_SLEEP_CONTROL:
  283. case WM831X_POWER_GOOD_SOURCE_1:
  284. case WM831X_POWER_GOOD_SOURCE_2:
  285. case WM831X_CLOCK_CONTROL_1:
  286. case WM831X_CLOCK_CONTROL_2:
  287. case WM831X_FLL_CONTROL_1:
  288. case WM831X_FLL_CONTROL_2:
  289. case WM831X_FLL_CONTROL_3:
  290. case WM831X_FLL_CONTROL_4:
  291. case WM831X_FLL_CONTROL_5:
  292. case WM831X_UNIQUE_ID_1:
  293. case WM831X_UNIQUE_ID_2:
  294. case WM831X_UNIQUE_ID_3:
  295. case WM831X_UNIQUE_ID_4:
  296. case WM831X_UNIQUE_ID_5:
  297. case WM831X_UNIQUE_ID_6:
  298. case WM831X_UNIQUE_ID_7:
  299. case WM831X_UNIQUE_ID_8:
  300. case WM831X_FACTORY_OTP_ID:
  301. case WM831X_FACTORY_OTP_1:
  302. case WM831X_FACTORY_OTP_2:
  303. case WM831X_FACTORY_OTP_3:
  304. case WM831X_FACTORY_OTP_4:
  305. case WM831X_FACTORY_OTP_5:
  306. case WM831X_CUSTOMER_OTP_ID:
  307. case WM831X_DC1_OTP_CONTROL:
  308. case WM831X_DC2_OTP_CONTROL:
  309. case WM831X_DC3_OTP_CONTROL:
  310. case WM831X_LDO1_2_OTP_CONTROL:
  311. case WM831X_LDO3_4_OTP_CONTROL:
  312. case WM831X_LDO5_6_OTP_CONTROL:
  313. case WM831X_LDO7_8_OTP_CONTROL:
  314. case WM831X_LDO9_10_OTP_CONTROL:
  315. case WM831X_LDO11_EPE_CONTROL:
  316. case WM831X_GPIO1_OTP_CONTROL:
  317. case WM831X_GPIO2_OTP_CONTROL:
  318. case WM831X_GPIO3_OTP_CONTROL:
  319. case WM831X_GPIO4_OTP_CONTROL:
  320. case WM831X_GPIO5_OTP_CONTROL:
  321. case WM831X_GPIO6_OTP_CONTROL:
  322. case WM831X_DBE_CHECK_DATA:
  323. return true;
  324. default:
  325. return false;
  326. }
  327. }
  328. static bool wm831x_reg_writeable(struct device *dev, unsigned int reg)
  329. {
  330. struct wm831x *wm831x = dev_get_drvdata(dev);
  331. if (wm831x_reg_locked(wm831x, reg))
  332. return false;
  333. switch (reg) {
  334. case WM831X_SYSVDD_CONTROL:
  335. case WM831X_THERMAL_MONITORING:
  336. case WM831X_POWER_STATE:
  337. case WM831X_WATCHDOG:
  338. case WM831X_ON_PIN_CONTROL:
  339. case WM831X_RESET_CONTROL:
  340. case WM831X_CONTROL_INTERFACE:
  341. case WM831X_SECURITY_KEY:
  342. case WM831X_SOFTWARE_SCRATCH:
  343. case WM831X_OTP_CONTROL:
  344. case WM831X_GPIO_LEVEL:
  345. case WM831X_INTERRUPT_STATUS_1:
  346. case WM831X_INTERRUPT_STATUS_2:
  347. case WM831X_INTERRUPT_STATUS_3:
  348. case WM831X_INTERRUPT_STATUS_4:
  349. case WM831X_INTERRUPT_STATUS_5:
  350. case WM831X_IRQ_CONFIG:
  351. case WM831X_SYSTEM_INTERRUPTS_MASK:
  352. case WM831X_INTERRUPT_STATUS_1_MASK:
  353. case WM831X_INTERRUPT_STATUS_2_MASK:
  354. case WM831X_INTERRUPT_STATUS_3_MASK:
  355. case WM831X_INTERRUPT_STATUS_4_MASK:
  356. case WM831X_INTERRUPT_STATUS_5_MASK:
  357. case WM831X_RTC_TIME_1:
  358. case WM831X_RTC_TIME_2:
  359. case WM831X_RTC_ALARM_1:
  360. case WM831X_RTC_ALARM_2:
  361. case WM831X_RTC_CONTROL:
  362. case WM831X_RTC_TRIM:
  363. case WM831X_TOUCH_CONTROL_1:
  364. case WM831X_TOUCH_CONTROL_2:
  365. case WM831X_AUXADC_CONTROL:
  366. case WM831X_AUXADC_SOURCE:
  367. case WM831X_COMPARATOR_CONTROL:
  368. case WM831X_COMPARATOR_1:
  369. case WM831X_COMPARATOR_2:
  370. case WM831X_COMPARATOR_3:
  371. case WM831X_COMPARATOR_4:
  372. case WM831X_GPIO1_CONTROL:
  373. case WM831X_GPIO2_CONTROL:
  374. case WM831X_GPIO3_CONTROL:
  375. case WM831X_GPIO4_CONTROL:
  376. case WM831X_GPIO5_CONTROL:
  377. case WM831X_GPIO6_CONTROL:
  378. case WM831X_GPIO7_CONTROL:
  379. case WM831X_GPIO8_CONTROL:
  380. case WM831X_GPIO9_CONTROL:
  381. case WM831X_GPIO10_CONTROL:
  382. case WM831X_GPIO11_CONTROL:
  383. case WM831X_GPIO12_CONTROL:
  384. case WM831X_GPIO13_CONTROL:
  385. case WM831X_GPIO14_CONTROL:
  386. case WM831X_GPIO15_CONTROL:
  387. case WM831X_GPIO16_CONTROL:
  388. case WM831X_CHARGER_CONTROL_1:
  389. case WM831X_CHARGER_CONTROL_2:
  390. case WM831X_CHARGER_STATUS:
  391. case WM831X_BACKUP_CHARGER_CONTROL:
  392. case WM831X_STATUS_LED_1:
  393. case WM831X_STATUS_LED_2:
  394. case WM831X_CURRENT_SINK_1:
  395. case WM831X_CURRENT_SINK_2:
  396. case WM831X_DCDC_ENABLE:
  397. case WM831X_LDO_ENABLE:
  398. case WM831X_DC1_CONTROL_1:
  399. case WM831X_DC1_CONTROL_2:
  400. case WM831X_DC1_ON_CONFIG:
  401. case WM831X_DC1_SLEEP_CONTROL:
  402. case WM831X_DC1_DVS_CONTROL:
  403. case WM831X_DC2_CONTROL_1:
  404. case WM831X_DC2_CONTROL_2:
  405. case WM831X_DC2_ON_CONFIG:
  406. case WM831X_DC2_SLEEP_CONTROL:
  407. case WM831X_DC2_DVS_CONTROL:
  408. case WM831X_DC3_CONTROL_1:
  409. case WM831X_DC3_CONTROL_2:
  410. case WM831X_DC3_ON_CONFIG:
  411. case WM831X_DC3_SLEEP_CONTROL:
  412. case WM831X_DC4_CONTROL:
  413. case WM831X_DC4_SLEEP_CONTROL:
  414. case WM831X_EPE1_CONTROL:
  415. case WM831X_EPE2_CONTROL:
  416. case WM831X_LDO1_CONTROL:
  417. case WM831X_LDO1_ON_CONTROL:
  418. case WM831X_LDO1_SLEEP_CONTROL:
  419. case WM831X_LDO2_CONTROL:
  420. case WM831X_LDO2_ON_CONTROL:
  421. case WM831X_LDO2_SLEEP_CONTROL:
  422. case WM831X_LDO3_CONTROL:
  423. case WM831X_LDO3_ON_CONTROL:
  424. case WM831X_LDO3_SLEEP_CONTROL:
  425. case WM831X_LDO4_CONTROL:
  426. case WM831X_LDO4_ON_CONTROL:
  427. case WM831X_LDO4_SLEEP_CONTROL:
  428. case WM831X_LDO5_CONTROL:
  429. case WM831X_LDO5_ON_CONTROL:
  430. case WM831X_LDO5_SLEEP_CONTROL:
  431. case WM831X_LDO6_CONTROL:
  432. case WM831X_LDO6_ON_CONTROL:
  433. case WM831X_LDO6_SLEEP_CONTROL:
  434. case WM831X_LDO7_CONTROL:
  435. case WM831X_LDO7_ON_CONTROL:
  436. case WM831X_LDO7_SLEEP_CONTROL:
  437. case WM831X_LDO8_CONTROL:
  438. case WM831X_LDO8_ON_CONTROL:
  439. case WM831X_LDO8_SLEEP_CONTROL:
  440. case WM831X_LDO9_CONTROL:
  441. case WM831X_LDO9_ON_CONTROL:
  442. case WM831X_LDO9_SLEEP_CONTROL:
  443. case WM831X_LDO10_CONTROL:
  444. case WM831X_LDO10_ON_CONTROL:
  445. case WM831X_LDO10_SLEEP_CONTROL:
  446. case WM831X_LDO11_ON_CONTROL:
  447. case WM831X_LDO11_SLEEP_CONTROL:
  448. case WM831X_POWER_GOOD_SOURCE_1:
  449. case WM831X_POWER_GOOD_SOURCE_2:
  450. case WM831X_CLOCK_CONTROL_1:
  451. case WM831X_CLOCK_CONTROL_2:
  452. case WM831X_FLL_CONTROL_1:
  453. case WM831X_FLL_CONTROL_2:
  454. case WM831X_FLL_CONTROL_3:
  455. case WM831X_FLL_CONTROL_4:
  456. case WM831X_FLL_CONTROL_5:
  457. return true;
  458. default:
  459. return false;
  460. }
  461. }
  462. static bool wm831x_reg_volatile(struct device *dev, unsigned int reg)
  463. {
  464. switch (reg) {
  465. case WM831X_SYSTEM_STATUS:
  466. case WM831X_ON_SOURCE:
  467. case WM831X_OFF_SOURCE:
  468. case WM831X_GPIO_LEVEL:
  469. case WM831X_SYSTEM_INTERRUPTS:
  470. case WM831X_INTERRUPT_STATUS_1:
  471. case WM831X_INTERRUPT_STATUS_2:
  472. case WM831X_INTERRUPT_STATUS_3:
  473. case WM831X_INTERRUPT_STATUS_4:
  474. case WM831X_INTERRUPT_STATUS_5:
  475. case WM831X_RTC_TIME_1:
  476. case WM831X_RTC_TIME_2:
  477. case WM831X_TOUCH_DATA_X:
  478. case WM831X_TOUCH_DATA_Y:
  479. case WM831X_TOUCH_DATA_Z:
  480. case WM831X_AUXADC_DATA:
  481. case WM831X_CHARGER_STATUS:
  482. case WM831X_DCDC_STATUS:
  483. case WM831X_LDO_STATUS:
  484. case WM831X_DCDC_UV_STATUS:
  485. case WM831X_LDO_UV_STATUS:
  486. return true;
  487. default:
  488. return false;
  489. }
  490. }
  491. /**
  492. * wm831x_reg_read: Read a single WM831x register.
  493. *
  494. * @wm831x: Device to read from.
  495. * @reg: Register to read.
  496. */
  497. int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
  498. {
  499. unsigned int val;
  500. int ret;
  501. ret = regmap_read(wm831x->regmap, reg, &val);
  502. if (ret < 0)
  503. return ret;
  504. else
  505. return val;
  506. }
  507. EXPORT_SYMBOL_GPL(wm831x_reg_read);
  508. /**
  509. * wm831x_bulk_read: Read multiple WM831x registers
  510. *
  511. * @wm831x: Device to read from
  512. * @reg: First register
  513. * @count: Number of registers
  514. * @buf: Buffer to fill.
  515. */
  516. int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
  517. int count, u16 *buf)
  518. {
  519. return regmap_bulk_read(wm831x->regmap, reg, buf, count);
  520. }
  521. EXPORT_SYMBOL_GPL(wm831x_bulk_read);
  522. static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
  523. int bytes, void *src)
  524. {
  525. u16 *buf = src;
  526. int i, ret;
  527. BUG_ON(bytes % 2);
  528. BUG_ON(bytes <= 0);
  529. for (i = 0; i < bytes / 2; i++) {
  530. if (wm831x_reg_locked(wm831x, reg))
  531. return -EPERM;
  532. dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n",
  533. buf[i], reg + i, reg + i);
  534. ret = regmap_write(wm831x->regmap, reg + i, buf[i]);
  535. if (ret != 0)
  536. return ret;
  537. }
  538. return 0;
  539. }
  540. /**
  541. * wm831x_reg_write: Write a single WM831x register.
  542. *
  543. * @wm831x: Device to write to.
  544. * @reg: Register to write to.
  545. * @val: Value to write.
  546. */
  547. int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg,
  548. unsigned short val)
  549. {
  550. int ret;
  551. mutex_lock(&wm831x->io_lock);
  552. ret = wm831x_write(wm831x, reg, 2, &val);
  553. mutex_unlock(&wm831x->io_lock);
  554. return ret;
  555. }
  556. EXPORT_SYMBOL_GPL(wm831x_reg_write);
  557. /**
  558. * wm831x_set_bits: Set the value of a bitfield in a WM831x register
  559. *
  560. * @wm831x: Device to write to.
  561. * @reg: Register to write to.
  562. * @mask: Mask of bits to set.
  563. * @val: Value to set (unshifted)
  564. */
  565. int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
  566. unsigned short mask, unsigned short val)
  567. {
  568. int ret;
  569. mutex_lock(&wm831x->io_lock);
  570. if (!wm831x_reg_locked(wm831x, reg))
  571. ret = regmap_update_bits(wm831x->regmap, reg, mask, val);
  572. else
  573. ret = -EPERM;
  574. mutex_unlock(&wm831x->io_lock);
  575. return ret;
  576. }
  577. EXPORT_SYMBOL_GPL(wm831x_set_bits);
  578. static struct resource wm831x_dcdc1_resources[] = {
  579. {
  580. .start = WM831X_DC1_CONTROL_1,
  581. .end = WM831X_DC1_DVS_CONTROL,
  582. .flags = IORESOURCE_REG,
  583. },
  584. {
  585. .name = "UV",
  586. .start = WM831X_IRQ_UV_DC1,
  587. .end = WM831X_IRQ_UV_DC1,
  588. .flags = IORESOURCE_IRQ,
  589. },
  590. {
  591. .name = "HC",
  592. .start = WM831X_IRQ_HC_DC1,
  593. .end = WM831X_IRQ_HC_DC1,
  594. .flags = IORESOURCE_IRQ,
  595. },
  596. };
  597. static struct resource wm831x_dcdc2_resources[] = {
  598. {
  599. .start = WM831X_DC2_CONTROL_1,
  600. .end = WM831X_DC2_DVS_CONTROL,
  601. .flags = IORESOURCE_REG,
  602. },
  603. {
  604. .name = "UV",
  605. .start = WM831X_IRQ_UV_DC2,
  606. .end = WM831X_IRQ_UV_DC2,
  607. .flags = IORESOURCE_IRQ,
  608. },
  609. {
  610. .name = "HC",
  611. .start = WM831X_IRQ_HC_DC2,
  612. .end = WM831X_IRQ_HC_DC2,
  613. .flags = IORESOURCE_IRQ,
  614. },
  615. };
  616. static struct resource wm831x_dcdc3_resources[] = {
  617. {
  618. .start = WM831X_DC3_CONTROL_1,
  619. .end = WM831X_DC3_SLEEP_CONTROL,
  620. .flags = IORESOURCE_REG,
  621. },
  622. {
  623. .name = "UV",
  624. .start = WM831X_IRQ_UV_DC3,
  625. .end = WM831X_IRQ_UV_DC3,
  626. .flags = IORESOURCE_IRQ,
  627. },
  628. };
  629. static struct resource wm831x_dcdc4_resources[] = {
  630. {
  631. .start = WM831X_DC4_CONTROL,
  632. .end = WM831X_DC4_SLEEP_CONTROL,
  633. .flags = IORESOURCE_REG,
  634. },
  635. {
  636. .name = "UV",
  637. .start = WM831X_IRQ_UV_DC4,
  638. .end = WM831X_IRQ_UV_DC4,
  639. .flags = IORESOURCE_IRQ,
  640. },
  641. };
  642. static struct resource wm8320_dcdc4_buck_resources[] = {
  643. {
  644. .start = WM831X_DC4_CONTROL,
  645. .end = WM832X_DC4_SLEEP_CONTROL,
  646. .flags = IORESOURCE_REG,
  647. },
  648. {
  649. .name = "UV",
  650. .start = WM831X_IRQ_UV_DC4,
  651. .end = WM831X_IRQ_UV_DC4,
  652. .flags = IORESOURCE_IRQ,
  653. },
  654. };
  655. static struct resource wm831x_gpio_resources[] = {
  656. {
  657. .start = WM831X_IRQ_GPIO_1,
  658. .end = WM831X_IRQ_GPIO_16,
  659. .flags = IORESOURCE_IRQ,
  660. },
  661. };
  662. static struct resource wm831x_isink1_resources[] = {
  663. {
  664. .start = WM831X_CURRENT_SINK_1,
  665. .end = WM831X_CURRENT_SINK_1,
  666. .flags = IORESOURCE_REG,
  667. },
  668. {
  669. .start = WM831X_IRQ_CS1,
  670. .end = WM831X_IRQ_CS1,
  671. .flags = IORESOURCE_IRQ,
  672. },
  673. };
  674. static struct resource wm831x_isink2_resources[] = {
  675. {
  676. .start = WM831X_CURRENT_SINK_2,
  677. .end = WM831X_CURRENT_SINK_2,
  678. .flags = IORESOURCE_REG,
  679. },
  680. {
  681. .start = WM831X_IRQ_CS2,
  682. .end = WM831X_IRQ_CS2,
  683. .flags = IORESOURCE_IRQ,
  684. },
  685. };
  686. static struct resource wm831x_ldo1_resources[] = {
  687. {
  688. .start = WM831X_LDO1_CONTROL,
  689. .end = WM831X_LDO1_SLEEP_CONTROL,
  690. .flags = IORESOURCE_REG,
  691. },
  692. {
  693. .name = "UV",
  694. .start = WM831X_IRQ_UV_LDO1,
  695. .end = WM831X_IRQ_UV_LDO1,
  696. .flags = IORESOURCE_IRQ,
  697. },
  698. };
  699. static struct resource wm831x_ldo2_resources[] = {
  700. {
  701. .start = WM831X_LDO2_CONTROL,
  702. .end = WM831X_LDO2_SLEEP_CONTROL,
  703. .flags = IORESOURCE_REG,
  704. },
  705. {
  706. .name = "UV",
  707. .start = WM831X_IRQ_UV_LDO2,
  708. .end = WM831X_IRQ_UV_LDO2,
  709. .flags = IORESOURCE_IRQ,
  710. },
  711. };
  712. static struct resource wm831x_ldo3_resources[] = {
  713. {
  714. .start = WM831X_LDO3_CONTROL,
  715. .end = WM831X_LDO3_SLEEP_CONTROL,
  716. .flags = IORESOURCE_REG,
  717. },
  718. {
  719. .name = "UV",
  720. .start = WM831X_IRQ_UV_LDO3,
  721. .end = WM831X_IRQ_UV_LDO3,
  722. .flags = IORESOURCE_IRQ,
  723. },
  724. };
  725. static struct resource wm831x_ldo4_resources[] = {
  726. {
  727. .start = WM831X_LDO4_CONTROL,
  728. .end = WM831X_LDO4_SLEEP_CONTROL,
  729. .flags = IORESOURCE_REG,
  730. },
  731. {
  732. .name = "UV",
  733. .start = WM831X_IRQ_UV_LDO4,
  734. .end = WM831X_IRQ_UV_LDO4,
  735. .flags = IORESOURCE_IRQ,
  736. },
  737. };
  738. static struct resource wm831x_ldo5_resources[] = {
  739. {
  740. .start = WM831X_LDO5_CONTROL,
  741. .end = WM831X_LDO5_SLEEP_CONTROL,
  742. .flags = IORESOURCE_REG,
  743. },
  744. {
  745. .name = "UV",
  746. .start = WM831X_IRQ_UV_LDO5,
  747. .end = WM831X_IRQ_UV_LDO5,
  748. .flags = IORESOURCE_IRQ,
  749. },
  750. };
  751. static struct resource wm831x_ldo6_resources[] = {
  752. {
  753. .start = WM831X_LDO6_CONTROL,
  754. .end = WM831X_LDO6_SLEEP_CONTROL,
  755. .flags = IORESOURCE_REG,
  756. },
  757. {
  758. .name = "UV",
  759. .start = WM831X_IRQ_UV_LDO6,
  760. .end = WM831X_IRQ_UV_LDO6,
  761. .flags = IORESOURCE_IRQ,
  762. },
  763. };
  764. static struct resource wm831x_ldo7_resources[] = {
  765. {
  766. .start = WM831X_LDO7_CONTROL,
  767. .end = WM831X_LDO7_SLEEP_CONTROL,
  768. .flags = IORESOURCE_REG,
  769. },
  770. {
  771. .name = "UV",
  772. .start = WM831X_IRQ_UV_LDO7,
  773. .end = WM831X_IRQ_UV_LDO7,
  774. .flags = IORESOURCE_IRQ,
  775. },
  776. };
  777. static struct resource wm831x_ldo8_resources[] = {
  778. {
  779. .start = WM831X_LDO8_CONTROL,
  780. .end = WM831X_LDO8_SLEEP_CONTROL,
  781. .flags = IORESOURCE_REG,
  782. },
  783. {
  784. .name = "UV",
  785. .start = WM831X_IRQ_UV_LDO8,
  786. .end = WM831X_IRQ_UV_LDO8,
  787. .flags = IORESOURCE_IRQ,
  788. },
  789. };
  790. static struct resource wm831x_ldo9_resources[] = {
  791. {
  792. .start = WM831X_LDO9_CONTROL,
  793. .end = WM831X_LDO9_SLEEP_CONTROL,
  794. .flags = IORESOURCE_REG,
  795. },
  796. {
  797. .name = "UV",
  798. .start = WM831X_IRQ_UV_LDO9,
  799. .end = WM831X_IRQ_UV_LDO9,
  800. .flags = IORESOURCE_IRQ,
  801. },
  802. };
  803. static struct resource wm831x_ldo10_resources[] = {
  804. {
  805. .start = WM831X_LDO10_CONTROL,
  806. .end = WM831X_LDO10_SLEEP_CONTROL,
  807. .flags = IORESOURCE_REG,
  808. },
  809. {
  810. .name = "UV",
  811. .start = WM831X_IRQ_UV_LDO10,
  812. .end = WM831X_IRQ_UV_LDO10,
  813. .flags = IORESOURCE_IRQ,
  814. },
  815. };
  816. static struct resource wm831x_ldo11_resources[] = {
  817. {
  818. .start = WM831X_LDO11_ON_CONTROL,
  819. .end = WM831X_LDO11_SLEEP_CONTROL,
  820. .flags = IORESOURCE_REG,
  821. },
  822. };
  823. static struct resource wm831x_on_resources[] = {
  824. {
  825. .start = WM831X_IRQ_ON,
  826. .end = WM831X_IRQ_ON,
  827. .flags = IORESOURCE_IRQ,
  828. },
  829. };
  830. static struct resource wm831x_power_resources[] = {
  831. {
  832. .name = "SYSLO",
  833. .start = WM831X_IRQ_PPM_SYSLO,
  834. .end = WM831X_IRQ_PPM_SYSLO,
  835. .flags = IORESOURCE_IRQ,
  836. },
  837. {
  838. .name = "PWR SRC",
  839. .start = WM831X_IRQ_PPM_PWR_SRC,
  840. .end = WM831X_IRQ_PPM_PWR_SRC,
  841. .flags = IORESOURCE_IRQ,
  842. },
  843. {
  844. .name = "USB CURR",
  845. .start = WM831X_IRQ_PPM_USB_CURR,
  846. .end = WM831X_IRQ_PPM_USB_CURR,
  847. .flags = IORESOURCE_IRQ,
  848. },
  849. {
  850. .name = "BATT HOT",
  851. .start = WM831X_IRQ_CHG_BATT_HOT,
  852. .end = WM831X_IRQ_CHG_BATT_HOT,
  853. .flags = IORESOURCE_IRQ,
  854. },
  855. {
  856. .name = "BATT COLD",
  857. .start = WM831X_IRQ_CHG_BATT_COLD,
  858. .end = WM831X_IRQ_CHG_BATT_COLD,
  859. .flags = IORESOURCE_IRQ,
  860. },
  861. {
  862. .name = "BATT FAIL",
  863. .start = WM831X_IRQ_CHG_BATT_FAIL,
  864. .end = WM831X_IRQ_CHG_BATT_FAIL,
  865. .flags = IORESOURCE_IRQ,
  866. },
  867. {
  868. .name = "OV",
  869. .start = WM831X_IRQ_CHG_OV,
  870. .end = WM831X_IRQ_CHG_OV,
  871. .flags = IORESOURCE_IRQ,
  872. },
  873. {
  874. .name = "END",
  875. .start = WM831X_IRQ_CHG_END,
  876. .end = WM831X_IRQ_CHG_END,
  877. .flags = IORESOURCE_IRQ,
  878. },
  879. {
  880. .name = "TO",
  881. .start = WM831X_IRQ_CHG_TO,
  882. .end = WM831X_IRQ_CHG_TO,
  883. .flags = IORESOURCE_IRQ,
  884. },
  885. {
  886. .name = "MODE",
  887. .start = WM831X_IRQ_CHG_MODE,
  888. .end = WM831X_IRQ_CHG_MODE,
  889. .flags = IORESOURCE_IRQ,
  890. },
  891. {
  892. .name = "START",
  893. .start = WM831X_IRQ_CHG_START,
  894. .end = WM831X_IRQ_CHG_START,
  895. .flags = IORESOURCE_IRQ,
  896. },
  897. };
  898. static struct resource wm831x_rtc_resources[] = {
  899. {
  900. .name = "PER",
  901. .start = WM831X_IRQ_RTC_PER,
  902. .end = WM831X_IRQ_RTC_PER,
  903. .flags = IORESOURCE_IRQ,
  904. },
  905. {
  906. .name = "ALM",
  907. .start = WM831X_IRQ_RTC_ALM,
  908. .end = WM831X_IRQ_RTC_ALM,
  909. .flags = IORESOURCE_IRQ,
  910. },
  911. };
  912. static struct resource wm831x_status1_resources[] = {
  913. {
  914. .start = WM831X_STATUS_LED_1,
  915. .end = WM831X_STATUS_LED_1,
  916. .flags = IORESOURCE_REG,
  917. },
  918. };
  919. static struct resource wm831x_status2_resources[] = {
  920. {
  921. .start = WM831X_STATUS_LED_2,
  922. .end = WM831X_STATUS_LED_2,
  923. .flags = IORESOURCE_REG,
  924. },
  925. };
  926. static struct resource wm831x_touch_resources[] = {
  927. {
  928. .name = "TCHPD",
  929. .start = WM831X_IRQ_TCHPD,
  930. .end = WM831X_IRQ_TCHPD,
  931. .flags = IORESOURCE_IRQ,
  932. },
  933. {
  934. .name = "TCHDATA",
  935. .start = WM831X_IRQ_TCHDATA,
  936. .end = WM831X_IRQ_TCHDATA,
  937. .flags = IORESOURCE_IRQ,
  938. },
  939. };
  940. static struct resource wm831x_wdt_resources[] = {
  941. {
  942. .start = WM831X_IRQ_WDOG_TO,
  943. .end = WM831X_IRQ_WDOG_TO,
  944. .flags = IORESOURCE_IRQ,
  945. },
  946. };
  947. static const struct mfd_cell wm8310_devs[] = {
  948. {
  949. .name = "wm831x-backup",
  950. },
  951. {
  952. .name = "wm831x-buckv",
  953. .id = 1,
  954. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  955. .resources = wm831x_dcdc1_resources,
  956. },
  957. {
  958. .name = "wm831x-buckv",
  959. .id = 2,
  960. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  961. .resources = wm831x_dcdc2_resources,
  962. },
  963. {
  964. .name = "wm831x-buckp",
  965. .id = 3,
  966. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  967. .resources = wm831x_dcdc3_resources,
  968. },
  969. {
  970. .name = "wm831x-boostp",
  971. .id = 4,
  972. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  973. .resources = wm831x_dcdc4_resources,
  974. },
  975. {
  976. .name = "wm831x-clk",
  977. },
  978. {
  979. .name = "wm831x-epe",
  980. .id = 1,
  981. },
  982. {
  983. .name = "wm831x-epe",
  984. .id = 2,
  985. },
  986. {
  987. .name = "wm831x-gpio",
  988. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  989. .resources = wm831x_gpio_resources,
  990. },
  991. {
  992. .name = "wm831x-hwmon",
  993. },
  994. {
  995. .name = "wm831x-isink",
  996. .id = 1,
  997. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  998. .resources = wm831x_isink1_resources,
  999. },
  1000. {
  1001. .name = "wm831x-isink",
  1002. .id = 2,
  1003. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1004. .resources = wm831x_isink2_resources,
  1005. },
  1006. {
  1007. .name = "wm831x-ldo",
  1008. .id = 1,
  1009. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1010. .resources = wm831x_ldo1_resources,
  1011. },
  1012. {
  1013. .name = "wm831x-ldo",
  1014. .id = 2,
  1015. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1016. .resources = wm831x_ldo2_resources,
  1017. },
  1018. {
  1019. .name = "wm831x-ldo",
  1020. .id = 3,
  1021. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1022. .resources = wm831x_ldo3_resources,
  1023. },
  1024. {
  1025. .name = "wm831x-ldo",
  1026. .id = 4,
  1027. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1028. .resources = wm831x_ldo4_resources,
  1029. },
  1030. {
  1031. .name = "wm831x-ldo",
  1032. .id = 5,
  1033. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1034. .resources = wm831x_ldo5_resources,
  1035. },
  1036. {
  1037. .name = "wm831x-ldo",
  1038. .id = 6,
  1039. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1040. .resources = wm831x_ldo6_resources,
  1041. },
  1042. {
  1043. .name = "wm831x-aldo",
  1044. .id = 7,
  1045. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1046. .resources = wm831x_ldo7_resources,
  1047. },
  1048. {
  1049. .name = "wm831x-aldo",
  1050. .id = 8,
  1051. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1052. .resources = wm831x_ldo8_resources,
  1053. },
  1054. {
  1055. .name = "wm831x-aldo",
  1056. .id = 9,
  1057. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1058. .resources = wm831x_ldo9_resources,
  1059. },
  1060. {
  1061. .name = "wm831x-aldo",
  1062. .id = 10,
  1063. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1064. .resources = wm831x_ldo10_resources,
  1065. },
  1066. {
  1067. .name = "wm831x-alive-ldo",
  1068. .id = 11,
  1069. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1070. .resources = wm831x_ldo11_resources,
  1071. },
  1072. {
  1073. .name = "wm831x-on",
  1074. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1075. .resources = wm831x_on_resources,
  1076. },
  1077. {
  1078. .name = "wm831x-power",
  1079. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1080. .resources = wm831x_power_resources,
  1081. },
  1082. {
  1083. .name = "wm831x-status",
  1084. .id = 1,
  1085. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1086. .resources = wm831x_status1_resources,
  1087. },
  1088. {
  1089. .name = "wm831x-status",
  1090. .id = 2,
  1091. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1092. .resources = wm831x_status2_resources,
  1093. },
  1094. {
  1095. .name = "wm831x-watchdog",
  1096. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1097. .resources = wm831x_wdt_resources,
  1098. },
  1099. };
  1100. static const struct mfd_cell wm8311_devs[] = {
  1101. {
  1102. .name = "wm831x-backup",
  1103. },
  1104. {
  1105. .name = "wm831x-buckv",
  1106. .id = 1,
  1107. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1108. .resources = wm831x_dcdc1_resources,
  1109. },
  1110. {
  1111. .name = "wm831x-buckv",
  1112. .id = 2,
  1113. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1114. .resources = wm831x_dcdc2_resources,
  1115. },
  1116. {
  1117. .name = "wm831x-buckp",
  1118. .id = 3,
  1119. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1120. .resources = wm831x_dcdc3_resources,
  1121. },
  1122. {
  1123. .name = "wm831x-boostp",
  1124. .id = 4,
  1125. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  1126. .resources = wm831x_dcdc4_resources,
  1127. },
  1128. {
  1129. .name = "wm831x-clk",
  1130. },
  1131. {
  1132. .name = "wm831x-epe",
  1133. .id = 1,
  1134. },
  1135. {
  1136. .name = "wm831x-epe",
  1137. .id = 2,
  1138. },
  1139. {
  1140. .name = "wm831x-gpio",
  1141. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1142. .resources = wm831x_gpio_resources,
  1143. },
  1144. {
  1145. .name = "wm831x-hwmon",
  1146. },
  1147. {
  1148. .name = "wm831x-isink",
  1149. .id = 1,
  1150. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1151. .resources = wm831x_isink1_resources,
  1152. },
  1153. {
  1154. .name = "wm831x-isink",
  1155. .id = 2,
  1156. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1157. .resources = wm831x_isink2_resources,
  1158. },
  1159. {
  1160. .name = "wm831x-ldo",
  1161. .id = 1,
  1162. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1163. .resources = wm831x_ldo1_resources,
  1164. },
  1165. {
  1166. .name = "wm831x-ldo",
  1167. .id = 2,
  1168. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1169. .resources = wm831x_ldo2_resources,
  1170. },
  1171. {
  1172. .name = "wm831x-ldo",
  1173. .id = 3,
  1174. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1175. .resources = wm831x_ldo3_resources,
  1176. },
  1177. {
  1178. .name = "wm831x-ldo",
  1179. .id = 4,
  1180. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1181. .resources = wm831x_ldo4_resources,
  1182. },
  1183. {
  1184. .name = "wm831x-ldo",
  1185. .id = 5,
  1186. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1187. .resources = wm831x_ldo5_resources,
  1188. },
  1189. {
  1190. .name = "wm831x-aldo",
  1191. .id = 7,
  1192. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1193. .resources = wm831x_ldo7_resources,
  1194. },
  1195. {
  1196. .name = "wm831x-alive-ldo",
  1197. .id = 11,
  1198. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1199. .resources = wm831x_ldo11_resources,
  1200. },
  1201. {
  1202. .name = "wm831x-on",
  1203. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1204. .resources = wm831x_on_resources,
  1205. },
  1206. {
  1207. .name = "wm831x-power",
  1208. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1209. .resources = wm831x_power_resources,
  1210. },
  1211. {
  1212. .name = "wm831x-status",
  1213. .id = 1,
  1214. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1215. .resources = wm831x_status1_resources,
  1216. },
  1217. {
  1218. .name = "wm831x-status",
  1219. .id = 2,
  1220. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1221. .resources = wm831x_status2_resources,
  1222. },
  1223. {
  1224. .name = "wm831x-watchdog",
  1225. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1226. .resources = wm831x_wdt_resources,
  1227. },
  1228. };
  1229. static const struct mfd_cell wm8312_devs[] = {
  1230. {
  1231. .name = "wm831x-backup",
  1232. },
  1233. {
  1234. .name = "wm831x-buckv",
  1235. .id = 1,
  1236. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1237. .resources = wm831x_dcdc1_resources,
  1238. },
  1239. {
  1240. .name = "wm831x-buckv",
  1241. .id = 2,
  1242. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1243. .resources = wm831x_dcdc2_resources,
  1244. },
  1245. {
  1246. .name = "wm831x-buckp",
  1247. .id = 3,
  1248. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1249. .resources = wm831x_dcdc3_resources,
  1250. },
  1251. {
  1252. .name = "wm831x-boostp",
  1253. .id = 4,
  1254. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  1255. .resources = wm831x_dcdc4_resources,
  1256. },
  1257. {
  1258. .name = "wm831x-clk",
  1259. },
  1260. {
  1261. .name = "wm831x-epe",
  1262. .id = 1,
  1263. },
  1264. {
  1265. .name = "wm831x-epe",
  1266. .id = 2,
  1267. },
  1268. {
  1269. .name = "wm831x-gpio",
  1270. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1271. .resources = wm831x_gpio_resources,
  1272. },
  1273. {
  1274. .name = "wm831x-hwmon",
  1275. },
  1276. {
  1277. .name = "wm831x-isink",
  1278. .id = 1,
  1279. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1280. .resources = wm831x_isink1_resources,
  1281. },
  1282. {
  1283. .name = "wm831x-isink",
  1284. .id = 2,
  1285. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1286. .resources = wm831x_isink2_resources,
  1287. },
  1288. {
  1289. .name = "wm831x-ldo",
  1290. .id = 1,
  1291. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1292. .resources = wm831x_ldo1_resources,
  1293. },
  1294. {
  1295. .name = "wm831x-ldo",
  1296. .id = 2,
  1297. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1298. .resources = wm831x_ldo2_resources,
  1299. },
  1300. {
  1301. .name = "wm831x-ldo",
  1302. .id = 3,
  1303. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1304. .resources = wm831x_ldo3_resources,
  1305. },
  1306. {
  1307. .name = "wm831x-ldo",
  1308. .id = 4,
  1309. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1310. .resources = wm831x_ldo4_resources,
  1311. },
  1312. {
  1313. .name = "wm831x-ldo",
  1314. .id = 5,
  1315. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1316. .resources = wm831x_ldo5_resources,
  1317. },
  1318. {
  1319. .name = "wm831x-ldo",
  1320. .id = 6,
  1321. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1322. .resources = wm831x_ldo6_resources,
  1323. },
  1324. {
  1325. .name = "wm831x-aldo",
  1326. .id = 7,
  1327. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1328. .resources = wm831x_ldo7_resources,
  1329. },
  1330. {
  1331. .name = "wm831x-aldo",
  1332. .id = 8,
  1333. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1334. .resources = wm831x_ldo8_resources,
  1335. },
  1336. {
  1337. .name = "wm831x-aldo",
  1338. .id = 9,
  1339. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1340. .resources = wm831x_ldo9_resources,
  1341. },
  1342. {
  1343. .name = "wm831x-aldo",
  1344. .id = 10,
  1345. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1346. .resources = wm831x_ldo10_resources,
  1347. },
  1348. {
  1349. .name = "wm831x-alive-ldo",
  1350. .id = 11,
  1351. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1352. .resources = wm831x_ldo11_resources,
  1353. },
  1354. {
  1355. .name = "wm831x-on",
  1356. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1357. .resources = wm831x_on_resources,
  1358. },
  1359. {
  1360. .name = "wm831x-power",
  1361. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1362. .resources = wm831x_power_resources,
  1363. },
  1364. {
  1365. .name = "wm831x-status",
  1366. .id = 1,
  1367. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1368. .resources = wm831x_status1_resources,
  1369. },
  1370. {
  1371. .name = "wm831x-status",
  1372. .id = 2,
  1373. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1374. .resources = wm831x_status2_resources,
  1375. },
  1376. {
  1377. .name = "wm831x-watchdog",
  1378. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1379. .resources = wm831x_wdt_resources,
  1380. },
  1381. };
  1382. static const struct mfd_cell wm8320_devs[] = {
  1383. {
  1384. .name = "wm831x-backup",
  1385. },
  1386. {
  1387. .name = "wm831x-buckv",
  1388. .id = 1,
  1389. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1390. .resources = wm831x_dcdc1_resources,
  1391. },
  1392. {
  1393. .name = "wm831x-buckv",
  1394. .id = 2,
  1395. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1396. .resources = wm831x_dcdc2_resources,
  1397. },
  1398. {
  1399. .name = "wm831x-buckp",
  1400. .id = 3,
  1401. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1402. .resources = wm831x_dcdc3_resources,
  1403. },
  1404. {
  1405. .name = "wm831x-buckp",
  1406. .id = 4,
  1407. .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
  1408. .resources = wm8320_dcdc4_buck_resources,
  1409. },
  1410. {
  1411. .name = "wm831x-clk",
  1412. },
  1413. {
  1414. .name = "wm831x-gpio",
  1415. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1416. .resources = wm831x_gpio_resources,
  1417. },
  1418. {
  1419. .name = "wm831x-hwmon",
  1420. },
  1421. {
  1422. .name = "wm831x-ldo",
  1423. .id = 1,
  1424. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1425. .resources = wm831x_ldo1_resources,
  1426. },
  1427. {
  1428. .name = "wm831x-ldo",
  1429. .id = 2,
  1430. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1431. .resources = wm831x_ldo2_resources,
  1432. },
  1433. {
  1434. .name = "wm831x-ldo",
  1435. .id = 3,
  1436. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1437. .resources = wm831x_ldo3_resources,
  1438. },
  1439. {
  1440. .name = "wm831x-ldo",
  1441. .id = 4,
  1442. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1443. .resources = wm831x_ldo4_resources,
  1444. },
  1445. {
  1446. .name = "wm831x-ldo",
  1447. .id = 5,
  1448. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1449. .resources = wm831x_ldo5_resources,
  1450. },
  1451. {
  1452. .name = "wm831x-ldo",
  1453. .id = 6,
  1454. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1455. .resources = wm831x_ldo6_resources,
  1456. },
  1457. {
  1458. .name = "wm831x-aldo",
  1459. .id = 7,
  1460. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1461. .resources = wm831x_ldo7_resources,
  1462. },
  1463. {
  1464. .name = "wm831x-aldo",
  1465. .id = 8,
  1466. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1467. .resources = wm831x_ldo8_resources,
  1468. },
  1469. {
  1470. .name = "wm831x-aldo",
  1471. .id = 9,
  1472. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1473. .resources = wm831x_ldo9_resources,
  1474. },
  1475. {
  1476. .name = "wm831x-aldo",
  1477. .id = 10,
  1478. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1479. .resources = wm831x_ldo10_resources,
  1480. },
  1481. {
  1482. .name = "wm831x-alive-ldo",
  1483. .id = 11,
  1484. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1485. .resources = wm831x_ldo11_resources,
  1486. },
  1487. {
  1488. .name = "wm831x-on",
  1489. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1490. .resources = wm831x_on_resources,
  1491. },
  1492. {
  1493. .name = "wm831x-status",
  1494. .id = 1,
  1495. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1496. .resources = wm831x_status1_resources,
  1497. },
  1498. {
  1499. .name = "wm831x-status",
  1500. .id = 2,
  1501. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1502. .resources = wm831x_status2_resources,
  1503. },
  1504. {
  1505. .name = "wm831x-watchdog",
  1506. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1507. .resources = wm831x_wdt_resources,
  1508. },
  1509. };
  1510. static const struct mfd_cell touch_devs[] = {
  1511. {
  1512. .name = "wm831x-touch",
  1513. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1514. .resources = wm831x_touch_resources,
  1515. },
  1516. };
  1517. static const struct mfd_cell rtc_devs[] = {
  1518. {
  1519. .name = "wm831x-rtc",
  1520. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1521. .resources = wm831x_rtc_resources,
  1522. },
  1523. };
  1524. static const struct mfd_cell backlight_devs[] = {
  1525. {
  1526. .name = "wm831x-backlight",
  1527. },
  1528. };
  1529. struct regmap_config wm831x_regmap_config = {
  1530. .reg_bits = 16,
  1531. .val_bits = 16,
  1532. .cache_type = REGCACHE_RBTREE,
  1533. .max_register = WM831X_DBE_CHECK_DATA,
  1534. .readable_reg = wm831x_reg_readable,
  1535. .writeable_reg = wm831x_reg_writeable,
  1536. .volatile_reg = wm831x_reg_volatile,
  1537. };
  1538. EXPORT_SYMBOL_GPL(wm831x_regmap_config);
  1539. /*
  1540. * Instantiate the generic non-control parts of the device.
  1541. */
  1542. int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
  1543. {
  1544. struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
  1545. int rev, wm831x_num;
  1546. enum wm831x_parent parent;
  1547. int ret, i;
  1548. mutex_init(&wm831x->io_lock);
  1549. mutex_init(&wm831x->key_lock);
  1550. dev_set_drvdata(wm831x->dev, wm831x);
  1551. if (pdata)
  1552. wm831x->soft_shutdown = pdata->soft_shutdown;
  1553. ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
  1554. if (ret < 0) {
  1555. dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
  1556. goto err;
  1557. }
  1558. switch (ret) {
  1559. case 0x6204:
  1560. case 0x6246:
  1561. break;
  1562. default:
  1563. dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
  1564. ret = -EINVAL;
  1565. goto err;
  1566. }
  1567. ret = wm831x_reg_read(wm831x, WM831X_REVISION);
  1568. if (ret < 0) {
  1569. dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
  1570. goto err;
  1571. }
  1572. rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
  1573. ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
  1574. if (ret < 0) {
  1575. dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
  1576. goto err;
  1577. }
  1578. /* Some engineering samples do not have the ID set, rely on
  1579. * the device being registered correctly.
  1580. */
  1581. if (ret == 0) {
  1582. dev_info(wm831x->dev, "Device is an engineering sample\n");
  1583. ret = id;
  1584. }
  1585. switch (ret) {
  1586. case WM8310:
  1587. parent = WM8310;
  1588. wm831x->num_gpio = 16;
  1589. wm831x->charger_irq_wake = 1;
  1590. if (rev > 0) {
  1591. wm831x->has_gpio_ena = 1;
  1592. wm831x->has_cs_sts = 1;
  1593. }
  1594. dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
  1595. break;
  1596. case WM8311:
  1597. parent = WM8311;
  1598. wm831x->num_gpio = 16;
  1599. wm831x->charger_irq_wake = 1;
  1600. if (rev > 0) {
  1601. wm831x->has_gpio_ena = 1;
  1602. wm831x->has_cs_sts = 1;
  1603. }
  1604. dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
  1605. break;
  1606. case WM8312:
  1607. parent = WM8312;
  1608. wm831x->num_gpio = 16;
  1609. wm831x->charger_irq_wake = 1;
  1610. if (rev > 0) {
  1611. wm831x->has_gpio_ena = 1;
  1612. wm831x->has_cs_sts = 1;
  1613. }
  1614. dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
  1615. break;
  1616. case WM8320:
  1617. parent = WM8320;
  1618. wm831x->num_gpio = 12;
  1619. dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
  1620. break;
  1621. case WM8321:
  1622. parent = WM8321;
  1623. wm831x->num_gpio = 12;
  1624. dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
  1625. break;
  1626. case WM8325:
  1627. parent = WM8325;
  1628. wm831x->num_gpio = 12;
  1629. dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
  1630. break;
  1631. case WM8326:
  1632. parent = WM8326;
  1633. wm831x->num_gpio = 12;
  1634. dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev);
  1635. break;
  1636. default:
  1637. dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
  1638. ret = -EINVAL;
  1639. goto err;
  1640. }
  1641. /* This will need revisiting in future but is OK for all
  1642. * current parts.
  1643. */
  1644. if (parent != id)
  1645. dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
  1646. id);
  1647. /* Bootstrap the user key */
  1648. ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
  1649. if (ret < 0) {
  1650. dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
  1651. goto err;
  1652. }
  1653. if (ret != 0) {
  1654. dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
  1655. ret);
  1656. wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  1657. }
  1658. wm831x->locked = 1;
  1659. if (pdata && pdata->pre_init) {
  1660. ret = pdata->pre_init(wm831x);
  1661. if (ret != 0) {
  1662. dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
  1663. goto err;
  1664. }
  1665. }
  1666. if (pdata) {
  1667. for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
  1668. if (!pdata->gpio_defaults[i])
  1669. continue;
  1670. wm831x_reg_write(wm831x,
  1671. WM831X_GPIO1_CONTROL + i,
  1672. pdata->gpio_defaults[i] & 0xffff);
  1673. }
  1674. }
  1675. /* Multiply by 10 as we have many subdevices of the same type */
  1676. if (pdata && pdata->wm831x_num)
  1677. wm831x_num = pdata->wm831x_num * 10;
  1678. else
  1679. wm831x_num = -1;
  1680. ret = wm831x_irq_init(wm831x, irq);
  1681. if (ret != 0)
  1682. goto err;
  1683. wm831x_auxadc_init(wm831x);
  1684. /* The core device is up, instantiate the subdevices. */
  1685. switch (parent) {
  1686. case WM8310:
  1687. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1688. wm8310_devs, ARRAY_SIZE(wm8310_devs),
  1689. NULL, 0, NULL);
  1690. break;
  1691. case WM8311:
  1692. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1693. wm8311_devs, ARRAY_SIZE(wm8311_devs),
  1694. NULL, 0, NULL);
  1695. if (!pdata || !pdata->disable_touch)
  1696. mfd_add_devices(wm831x->dev, wm831x_num,
  1697. touch_devs, ARRAY_SIZE(touch_devs),
  1698. NULL, 0, NULL);
  1699. break;
  1700. case WM8312:
  1701. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1702. wm8312_devs, ARRAY_SIZE(wm8312_devs),
  1703. NULL, 0, NULL);
  1704. if (!pdata || !pdata->disable_touch)
  1705. mfd_add_devices(wm831x->dev, wm831x_num,
  1706. touch_devs, ARRAY_SIZE(touch_devs),
  1707. NULL, 0, NULL);
  1708. break;
  1709. case WM8320:
  1710. case WM8321:
  1711. case WM8325:
  1712. case WM8326:
  1713. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1714. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1715. NULL, 0, NULL);
  1716. break;
  1717. default:
  1718. /* If this happens the bus probe function is buggy */
  1719. BUG();
  1720. }
  1721. if (ret != 0) {
  1722. dev_err(wm831x->dev, "Failed to add children\n");
  1723. goto err_irq;
  1724. }
  1725. /* The RTC can only be used if the 32.768kHz crystal is
  1726. * enabled; this can't be controlled by software at runtime.
  1727. */
  1728. ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2);
  1729. if (ret < 0) {
  1730. dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret);
  1731. goto err_irq;
  1732. }
  1733. if (ret & WM831X_XTAL_ENA) {
  1734. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1735. rtc_devs, ARRAY_SIZE(rtc_devs),
  1736. NULL, 0, NULL);
  1737. if (ret != 0) {
  1738. dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret);
  1739. goto err_irq;
  1740. }
  1741. } else {
  1742. dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n");
  1743. }
  1744. if (pdata && pdata->backlight) {
  1745. /* Treat errors as non-critical */
  1746. ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs,
  1747. ARRAY_SIZE(backlight_devs), NULL,
  1748. 0, NULL);
  1749. if (ret < 0)
  1750. dev_err(wm831x->dev, "Failed to add backlight: %d\n",
  1751. ret);
  1752. }
  1753. wm831x_otp_init(wm831x);
  1754. if (pdata && pdata->post_init) {
  1755. ret = pdata->post_init(wm831x);
  1756. if (ret != 0) {
  1757. dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
  1758. goto err_irq;
  1759. }
  1760. }
  1761. return 0;
  1762. err_irq:
  1763. wm831x_irq_exit(wm831x);
  1764. err:
  1765. mfd_remove_devices(wm831x->dev);
  1766. return ret;
  1767. }
  1768. void wm831x_device_exit(struct wm831x *wm831x)
  1769. {
  1770. wm831x_otp_exit(wm831x);
  1771. mfd_remove_devices(wm831x->dev);
  1772. free_irq(wm831x_irq(wm831x, WM831X_IRQ_AUXADC_DATA), wm831x);
  1773. wm831x_irq_exit(wm831x);
  1774. }
  1775. int wm831x_device_suspend(struct wm831x *wm831x)
  1776. {
  1777. int reg, mask;
  1778. /* If the charger IRQs are a wake source then make sure we ack
  1779. * them even if they're not actively being used (eg, no power
  1780. * driver or no IRQ line wired up) then acknowledge the
  1781. * interrupts otherwise suspend won't last very long.
  1782. */
  1783. if (wm831x->charger_irq_wake) {
  1784. reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
  1785. mask = WM831X_CHG_BATT_HOT_EINT |
  1786. WM831X_CHG_BATT_COLD_EINT |
  1787. WM831X_CHG_BATT_FAIL_EINT |
  1788. WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
  1789. WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
  1790. WM831X_CHG_START_EINT;
  1791. /* If any of the interrupts are masked read the statuses */
  1792. if (reg & mask)
  1793. reg = wm831x_reg_read(wm831x,
  1794. WM831X_INTERRUPT_STATUS_2);
  1795. if (reg & mask) {
  1796. dev_info(wm831x->dev,
  1797. "Acknowledging masked charger IRQs: %x\n",
  1798. reg & mask);
  1799. wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
  1800. reg & mask);
  1801. }
  1802. }
  1803. return 0;
  1804. }
  1805. void wm831x_device_shutdown(struct wm831x *wm831x)
  1806. {
  1807. if (wm831x->soft_shutdown) {
  1808. dev_info(wm831x->dev, "Initiating shutdown...\n");
  1809. wm831x_set_bits(wm831x, WM831X_POWER_STATE, WM831X_CHIP_ON, 0);
  1810. }
  1811. }
  1812. EXPORT_SYMBOL_GPL(wm831x_device_shutdown);
  1813. MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
  1814. MODULE_LICENSE("GPL");
  1815. MODULE_AUTHOR("Mark Brown");