wm831x-core.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  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_io_parent = {
  579. .start = 0,
  580. .end = 0xffffffff,
  581. .flags = IORESOURCE_IO,
  582. };
  583. static struct resource wm831x_dcdc1_resources[] = {
  584. {
  585. .parent = &wm831x_io_parent,
  586. .start = WM831X_DC1_CONTROL_1,
  587. .end = WM831X_DC1_DVS_CONTROL,
  588. .flags = IORESOURCE_IO,
  589. },
  590. {
  591. .name = "UV",
  592. .start = WM831X_IRQ_UV_DC1,
  593. .end = WM831X_IRQ_UV_DC1,
  594. .flags = IORESOURCE_IRQ,
  595. },
  596. {
  597. .name = "HC",
  598. .start = WM831X_IRQ_HC_DC1,
  599. .end = WM831X_IRQ_HC_DC1,
  600. .flags = IORESOURCE_IRQ,
  601. },
  602. };
  603. static struct resource wm831x_dcdc2_resources[] = {
  604. {
  605. .parent = &wm831x_io_parent,
  606. .start = WM831X_DC2_CONTROL_1,
  607. .end = WM831X_DC2_DVS_CONTROL,
  608. .flags = IORESOURCE_IO,
  609. },
  610. {
  611. .name = "UV",
  612. .start = WM831X_IRQ_UV_DC2,
  613. .end = WM831X_IRQ_UV_DC2,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. {
  617. .name = "HC",
  618. .start = WM831X_IRQ_HC_DC2,
  619. .end = WM831X_IRQ_HC_DC2,
  620. .flags = IORESOURCE_IRQ,
  621. },
  622. };
  623. static struct resource wm831x_dcdc3_resources[] = {
  624. {
  625. .parent = &wm831x_io_parent,
  626. .start = WM831X_DC3_CONTROL_1,
  627. .end = WM831X_DC3_SLEEP_CONTROL,
  628. .flags = IORESOURCE_IO,
  629. },
  630. {
  631. .name = "UV",
  632. .start = WM831X_IRQ_UV_DC3,
  633. .end = WM831X_IRQ_UV_DC3,
  634. .flags = IORESOURCE_IRQ,
  635. },
  636. };
  637. static struct resource wm831x_dcdc4_resources[] = {
  638. {
  639. .parent = &wm831x_io_parent,
  640. .start = WM831X_DC4_CONTROL,
  641. .end = WM831X_DC4_SLEEP_CONTROL,
  642. .flags = IORESOURCE_IO,
  643. },
  644. {
  645. .name = "UV",
  646. .start = WM831X_IRQ_UV_DC4,
  647. .end = WM831X_IRQ_UV_DC4,
  648. .flags = IORESOURCE_IRQ,
  649. },
  650. };
  651. static struct resource wm8320_dcdc4_buck_resources[] = {
  652. {
  653. .parent = &wm831x_io_parent,
  654. .start = WM831X_DC4_CONTROL,
  655. .end = WM832X_DC4_SLEEP_CONTROL,
  656. .flags = IORESOURCE_IO,
  657. },
  658. {
  659. .name = "UV",
  660. .start = WM831X_IRQ_UV_DC4,
  661. .end = WM831X_IRQ_UV_DC4,
  662. .flags = IORESOURCE_IRQ,
  663. },
  664. };
  665. static struct resource wm831x_gpio_resources[] = {
  666. {
  667. .start = WM831X_IRQ_GPIO_1,
  668. .end = WM831X_IRQ_GPIO_16,
  669. .flags = IORESOURCE_IRQ,
  670. },
  671. };
  672. static struct resource wm831x_isink1_resources[] = {
  673. {
  674. .parent = &wm831x_io_parent,
  675. .start = WM831X_CURRENT_SINK_1,
  676. .end = WM831X_CURRENT_SINK_1,
  677. .flags = IORESOURCE_IO,
  678. },
  679. {
  680. .start = WM831X_IRQ_CS1,
  681. .end = WM831X_IRQ_CS1,
  682. .flags = IORESOURCE_IRQ,
  683. },
  684. };
  685. static struct resource wm831x_isink2_resources[] = {
  686. {
  687. .parent = &wm831x_io_parent,
  688. .start = WM831X_CURRENT_SINK_2,
  689. .end = WM831X_CURRENT_SINK_2,
  690. .flags = IORESOURCE_IO,
  691. },
  692. {
  693. .start = WM831X_IRQ_CS2,
  694. .end = WM831X_IRQ_CS2,
  695. .flags = IORESOURCE_IRQ,
  696. },
  697. };
  698. static struct resource wm831x_ldo1_resources[] = {
  699. {
  700. .parent = &wm831x_io_parent,
  701. .start = WM831X_LDO1_CONTROL,
  702. .end = WM831X_LDO1_SLEEP_CONTROL,
  703. .flags = IORESOURCE_IO,
  704. },
  705. {
  706. .name = "UV",
  707. .start = WM831X_IRQ_UV_LDO1,
  708. .end = WM831X_IRQ_UV_LDO1,
  709. .flags = IORESOURCE_IRQ,
  710. },
  711. };
  712. static struct resource wm831x_ldo2_resources[] = {
  713. {
  714. .parent = &wm831x_io_parent,
  715. .start = WM831X_LDO2_CONTROL,
  716. .end = WM831X_LDO2_SLEEP_CONTROL,
  717. .flags = IORESOURCE_IO,
  718. },
  719. {
  720. .name = "UV",
  721. .start = WM831X_IRQ_UV_LDO2,
  722. .end = WM831X_IRQ_UV_LDO2,
  723. .flags = IORESOURCE_IRQ,
  724. },
  725. };
  726. static struct resource wm831x_ldo3_resources[] = {
  727. {
  728. .parent = &wm831x_io_parent,
  729. .start = WM831X_LDO3_CONTROL,
  730. .end = WM831X_LDO3_SLEEP_CONTROL,
  731. .flags = IORESOURCE_IO,
  732. },
  733. {
  734. .name = "UV",
  735. .start = WM831X_IRQ_UV_LDO3,
  736. .end = WM831X_IRQ_UV_LDO3,
  737. .flags = IORESOURCE_IRQ,
  738. },
  739. };
  740. static struct resource wm831x_ldo4_resources[] = {
  741. {
  742. .parent = &wm831x_io_parent,
  743. .start = WM831X_LDO4_CONTROL,
  744. .end = WM831X_LDO4_SLEEP_CONTROL,
  745. .flags = IORESOURCE_IO,
  746. },
  747. {
  748. .name = "UV",
  749. .start = WM831X_IRQ_UV_LDO4,
  750. .end = WM831X_IRQ_UV_LDO4,
  751. .flags = IORESOURCE_IRQ,
  752. },
  753. };
  754. static struct resource wm831x_ldo5_resources[] = {
  755. {
  756. .parent = &wm831x_io_parent,
  757. .start = WM831X_LDO5_CONTROL,
  758. .end = WM831X_LDO5_SLEEP_CONTROL,
  759. .flags = IORESOURCE_IO,
  760. },
  761. {
  762. .name = "UV",
  763. .start = WM831X_IRQ_UV_LDO5,
  764. .end = WM831X_IRQ_UV_LDO5,
  765. .flags = IORESOURCE_IRQ,
  766. },
  767. };
  768. static struct resource wm831x_ldo6_resources[] = {
  769. {
  770. .parent = &wm831x_io_parent,
  771. .start = WM831X_LDO6_CONTROL,
  772. .end = WM831X_LDO6_SLEEP_CONTROL,
  773. .flags = IORESOURCE_IO,
  774. },
  775. {
  776. .name = "UV",
  777. .start = WM831X_IRQ_UV_LDO6,
  778. .end = WM831X_IRQ_UV_LDO6,
  779. .flags = IORESOURCE_IRQ,
  780. },
  781. };
  782. static struct resource wm831x_ldo7_resources[] = {
  783. {
  784. .parent = &wm831x_io_parent,
  785. .start = WM831X_LDO7_CONTROL,
  786. .end = WM831X_LDO7_SLEEP_CONTROL,
  787. .flags = IORESOURCE_IO,
  788. },
  789. {
  790. .name = "UV",
  791. .start = WM831X_IRQ_UV_LDO7,
  792. .end = WM831X_IRQ_UV_LDO7,
  793. .flags = IORESOURCE_IRQ,
  794. },
  795. };
  796. static struct resource wm831x_ldo8_resources[] = {
  797. {
  798. .parent = &wm831x_io_parent,
  799. .start = WM831X_LDO8_CONTROL,
  800. .end = WM831X_LDO8_SLEEP_CONTROL,
  801. .flags = IORESOURCE_IO,
  802. },
  803. {
  804. .name = "UV",
  805. .start = WM831X_IRQ_UV_LDO8,
  806. .end = WM831X_IRQ_UV_LDO8,
  807. .flags = IORESOURCE_IRQ,
  808. },
  809. };
  810. static struct resource wm831x_ldo9_resources[] = {
  811. {
  812. .parent = &wm831x_io_parent,
  813. .start = WM831X_LDO9_CONTROL,
  814. .end = WM831X_LDO9_SLEEP_CONTROL,
  815. .flags = IORESOURCE_IO,
  816. },
  817. {
  818. .name = "UV",
  819. .start = WM831X_IRQ_UV_LDO9,
  820. .end = WM831X_IRQ_UV_LDO9,
  821. .flags = IORESOURCE_IRQ,
  822. },
  823. };
  824. static struct resource wm831x_ldo10_resources[] = {
  825. {
  826. .parent = &wm831x_io_parent,
  827. .start = WM831X_LDO10_CONTROL,
  828. .end = WM831X_LDO10_SLEEP_CONTROL,
  829. .flags = IORESOURCE_IO,
  830. },
  831. {
  832. .name = "UV",
  833. .start = WM831X_IRQ_UV_LDO10,
  834. .end = WM831X_IRQ_UV_LDO10,
  835. .flags = IORESOURCE_IRQ,
  836. },
  837. };
  838. static struct resource wm831x_ldo11_resources[] = {
  839. {
  840. .parent = &wm831x_io_parent,
  841. .start = WM831X_LDO11_ON_CONTROL,
  842. .end = WM831X_LDO11_SLEEP_CONTROL,
  843. .flags = IORESOURCE_IO,
  844. },
  845. };
  846. static struct resource wm831x_on_resources[] = {
  847. {
  848. .start = WM831X_IRQ_ON,
  849. .end = WM831X_IRQ_ON,
  850. .flags = IORESOURCE_IRQ,
  851. },
  852. };
  853. static struct resource wm831x_power_resources[] = {
  854. {
  855. .name = "SYSLO",
  856. .start = WM831X_IRQ_PPM_SYSLO,
  857. .end = WM831X_IRQ_PPM_SYSLO,
  858. .flags = IORESOURCE_IRQ,
  859. },
  860. {
  861. .name = "PWR SRC",
  862. .start = WM831X_IRQ_PPM_PWR_SRC,
  863. .end = WM831X_IRQ_PPM_PWR_SRC,
  864. .flags = IORESOURCE_IRQ,
  865. },
  866. {
  867. .name = "USB CURR",
  868. .start = WM831X_IRQ_PPM_USB_CURR,
  869. .end = WM831X_IRQ_PPM_USB_CURR,
  870. .flags = IORESOURCE_IRQ,
  871. },
  872. {
  873. .name = "BATT HOT",
  874. .start = WM831X_IRQ_CHG_BATT_HOT,
  875. .end = WM831X_IRQ_CHG_BATT_HOT,
  876. .flags = IORESOURCE_IRQ,
  877. },
  878. {
  879. .name = "BATT COLD",
  880. .start = WM831X_IRQ_CHG_BATT_COLD,
  881. .end = WM831X_IRQ_CHG_BATT_COLD,
  882. .flags = IORESOURCE_IRQ,
  883. },
  884. {
  885. .name = "BATT FAIL",
  886. .start = WM831X_IRQ_CHG_BATT_FAIL,
  887. .end = WM831X_IRQ_CHG_BATT_FAIL,
  888. .flags = IORESOURCE_IRQ,
  889. },
  890. {
  891. .name = "OV",
  892. .start = WM831X_IRQ_CHG_OV,
  893. .end = WM831X_IRQ_CHG_OV,
  894. .flags = IORESOURCE_IRQ,
  895. },
  896. {
  897. .name = "END",
  898. .start = WM831X_IRQ_CHG_END,
  899. .end = WM831X_IRQ_CHG_END,
  900. .flags = IORESOURCE_IRQ,
  901. },
  902. {
  903. .name = "TO",
  904. .start = WM831X_IRQ_CHG_TO,
  905. .end = WM831X_IRQ_CHG_TO,
  906. .flags = IORESOURCE_IRQ,
  907. },
  908. {
  909. .name = "MODE",
  910. .start = WM831X_IRQ_CHG_MODE,
  911. .end = WM831X_IRQ_CHG_MODE,
  912. .flags = IORESOURCE_IRQ,
  913. },
  914. {
  915. .name = "START",
  916. .start = WM831X_IRQ_CHG_START,
  917. .end = WM831X_IRQ_CHG_START,
  918. .flags = IORESOURCE_IRQ,
  919. },
  920. };
  921. static struct resource wm831x_rtc_resources[] = {
  922. {
  923. .name = "PER",
  924. .start = WM831X_IRQ_RTC_PER,
  925. .end = WM831X_IRQ_RTC_PER,
  926. .flags = IORESOURCE_IRQ,
  927. },
  928. {
  929. .name = "ALM",
  930. .start = WM831X_IRQ_RTC_ALM,
  931. .end = WM831X_IRQ_RTC_ALM,
  932. .flags = IORESOURCE_IRQ,
  933. },
  934. };
  935. static struct resource wm831x_status1_resources[] = {
  936. {
  937. .parent = &wm831x_io_parent,
  938. .start = WM831X_STATUS_LED_1,
  939. .end = WM831X_STATUS_LED_1,
  940. .flags = IORESOURCE_IO,
  941. },
  942. };
  943. static struct resource wm831x_status2_resources[] = {
  944. {
  945. .parent = &wm831x_io_parent,
  946. .start = WM831X_STATUS_LED_2,
  947. .end = WM831X_STATUS_LED_2,
  948. .flags = IORESOURCE_IO,
  949. },
  950. };
  951. static struct resource wm831x_touch_resources[] = {
  952. {
  953. .name = "TCHPD",
  954. .start = WM831X_IRQ_TCHPD,
  955. .end = WM831X_IRQ_TCHPD,
  956. .flags = IORESOURCE_IRQ,
  957. },
  958. {
  959. .name = "TCHDATA",
  960. .start = WM831X_IRQ_TCHDATA,
  961. .end = WM831X_IRQ_TCHDATA,
  962. .flags = IORESOURCE_IRQ,
  963. },
  964. };
  965. static struct resource wm831x_wdt_resources[] = {
  966. {
  967. .start = WM831X_IRQ_WDOG_TO,
  968. .end = WM831X_IRQ_WDOG_TO,
  969. .flags = IORESOURCE_IRQ,
  970. },
  971. };
  972. static struct mfd_cell wm8310_devs[] = {
  973. {
  974. .name = "wm831x-backup",
  975. },
  976. {
  977. .name = "wm831x-buckv",
  978. .id = 1,
  979. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  980. .resources = wm831x_dcdc1_resources,
  981. },
  982. {
  983. .name = "wm831x-buckv",
  984. .id = 2,
  985. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  986. .resources = wm831x_dcdc2_resources,
  987. },
  988. {
  989. .name = "wm831x-buckp",
  990. .id = 3,
  991. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  992. .resources = wm831x_dcdc3_resources,
  993. },
  994. {
  995. .name = "wm831x-boostp",
  996. .id = 4,
  997. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  998. .resources = wm831x_dcdc4_resources,
  999. },
  1000. {
  1001. .name = "wm831x-clk",
  1002. },
  1003. {
  1004. .name = "wm831x-epe",
  1005. .id = 1,
  1006. },
  1007. {
  1008. .name = "wm831x-epe",
  1009. .id = 2,
  1010. },
  1011. {
  1012. .name = "wm831x-gpio",
  1013. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1014. .resources = wm831x_gpio_resources,
  1015. },
  1016. {
  1017. .name = "wm831x-hwmon",
  1018. },
  1019. {
  1020. .name = "wm831x-isink",
  1021. .id = 1,
  1022. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1023. .resources = wm831x_isink1_resources,
  1024. },
  1025. {
  1026. .name = "wm831x-isink",
  1027. .id = 2,
  1028. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1029. .resources = wm831x_isink2_resources,
  1030. },
  1031. {
  1032. .name = "wm831x-ldo",
  1033. .id = 1,
  1034. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1035. .resources = wm831x_ldo1_resources,
  1036. },
  1037. {
  1038. .name = "wm831x-ldo",
  1039. .id = 2,
  1040. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1041. .resources = wm831x_ldo2_resources,
  1042. },
  1043. {
  1044. .name = "wm831x-ldo",
  1045. .id = 3,
  1046. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1047. .resources = wm831x_ldo3_resources,
  1048. },
  1049. {
  1050. .name = "wm831x-ldo",
  1051. .id = 4,
  1052. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1053. .resources = wm831x_ldo4_resources,
  1054. },
  1055. {
  1056. .name = "wm831x-ldo",
  1057. .id = 5,
  1058. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1059. .resources = wm831x_ldo5_resources,
  1060. },
  1061. {
  1062. .name = "wm831x-ldo",
  1063. .id = 6,
  1064. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1065. .resources = wm831x_ldo6_resources,
  1066. },
  1067. {
  1068. .name = "wm831x-aldo",
  1069. .id = 7,
  1070. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1071. .resources = wm831x_ldo7_resources,
  1072. },
  1073. {
  1074. .name = "wm831x-aldo",
  1075. .id = 8,
  1076. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1077. .resources = wm831x_ldo8_resources,
  1078. },
  1079. {
  1080. .name = "wm831x-aldo",
  1081. .id = 9,
  1082. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1083. .resources = wm831x_ldo9_resources,
  1084. },
  1085. {
  1086. .name = "wm831x-aldo",
  1087. .id = 10,
  1088. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1089. .resources = wm831x_ldo10_resources,
  1090. },
  1091. {
  1092. .name = "wm831x-alive-ldo",
  1093. .id = 11,
  1094. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1095. .resources = wm831x_ldo11_resources,
  1096. },
  1097. {
  1098. .name = "wm831x-on",
  1099. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1100. .resources = wm831x_on_resources,
  1101. },
  1102. {
  1103. .name = "wm831x-power",
  1104. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1105. .resources = wm831x_power_resources,
  1106. },
  1107. {
  1108. .name = "wm831x-status",
  1109. .id = 1,
  1110. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1111. .resources = wm831x_status1_resources,
  1112. },
  1113. {
  1114. .name = "wm831x-status",
  1115. .id = 2,
  1116. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1117. .resources = wm831x_status2_resources,
  1118. },
  1119. {
  1120. .name = "wm831x-watchdog",
  1121. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1122. .resources = wm831x_wdt_resources,
  1123. },
  1124. };
  1125. static struct mfd_cell wm8311_devs[] = {
  1126. {
  1127. .name = "wm831x-backup",
  1128. },
  1129. {
  1130. .name = "wm831x-buckv",
  1131. .id = 1,
  1132. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1133. .resources = wm831x_dcdc1_resources,
  1134. },
  1135. {
  1136. .name = "wm831x-buckv",
  1137. .id = 2,
  1138. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1139. .resources = wm831x_dcdc2_resources,
  1140. },
  1141. {
  1142. .name = "wm831x-buckp",
  1143. .id = 3,
  1144. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1145. .resources = wm831x_dcdc3_resources,
  1146. },
  1147. {
  1148. .name = "wm831x-boostp",
  1149. .id = 4,
  1150. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  1151. .resources = wm831x_dcdc4_resources,
  1152. },
  1153. {
  1154. .name = "wm831x-clk",
  1155. },
  1156. {
  1157. .name = "wm831x-epe",
  1158. .id = 1,
  1159. },
  1160. {
  1161. .name = "wm831x-epe",
  1162. .id = 2,
  1163. },
  1164. {
  1165. .name = "wm831x-gpio",
  1166. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1167. .resources = wm831x_gpio_resources,
  1168. },
  1169. {
  1170. .name = "wm831x-hwmon",
  1171. },
  1172. {
  1173. .name = "wm831x-isink",
  1174. .id = 1,
  1175. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1176. .resources = wm831x_isink1_resources,
  1177. },
  1178. {
  1179. .name = "wm831x-isink",
  1180. .id = 2,
  1181. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1182. .resources = wm831x_isink2_resources,
  1183. },
  1184. {
  1185. .name = "wm831x-ldo",
  1186. .id = 1,
  1187. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1188. .resources = wm831x_ldo1_resources,
  1189. },
  1190. {
  1191. .name = "wm831x-ldo",
  1192. .id = 2,
  1193. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1194. .resources = wm831x_ldo2_resources,
  1195. },
  1196. {
  1197. .name = "wm831x-ldo",
  1198. .id = 3,
  1199. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1200. .resources = wm831x_ldo3_resources,
  1201. },
  1202. {
  1203. .name = "wm831x-ldo",
  1204. .id = 4,
  1205. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1206. .resources = wm831x_ldo4_resources,
  1207. },
  1208. {
  1209. .name = "wm831x-ldo",
  1210. .id = 5,
  1211. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1212. .resources = wm831x_ldo5_resources,
  1213. },
  1214. {
  1215. .name = "wm831x-aldo",
  1216. .id = 7,
  1217. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1218. .resources = wm831x_ldo7_resources,
  1219. },
  1220. {
  1221. .name = "wm831x-alive-ldo",
  1222. .id = 11,
  1223. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1224. .resources = wm831x_ldo11_resources,
  1225. },
  1226. {
  1227. .name = "wm831x-on",
  1228. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1229. .resources = wm831x_on_resources,
  1230. },
  1231. {
  1232. .name = "wm831x-power",
  1233. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1234. .resources = wm831x_power_resources,
  1235. },
  1236. {
  1237. .name = "wm831x-status",
  1238. .id = 1,
  1239. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1240. .resources = wm831x_status1_resources,
  1241. },
  1242. {
  1243. .name = "wm831x-status",
  1244. .id = 2,
  1245. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1246. .resources = wm831x_status2_resources,
  1247. },
  1248. {
  1249. .name = "wm831x-watchdog",
  1250. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1251. .resources = wm831x_wdt_resources,
  1252. },
  1253. };
  1254. static struct mfd_cell wm8312_devs[] = {
  1255. {
  1256. .name = "wm831x-backup",
  1257. },
  1258. {
  1259. .name = "wm831x-buckv",
  1260. .id = 1,
  1261. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1262. .resources = wm831x_dcdc1_resources,
  1263. },
  1264. {
  1265. .name = "wm831x-buckv",
  1266. .id = 2,
  1267. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1268. .resources = wm831x_dcdc2_resources,
  1269. },
  1270. {
  1271. .name = "wm831x-buckp",
  1272. .id = 3,
  1273. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1274. .resources = wm831x_dcdc3_resources,
  1275. },
  1276. {
  1277. .name = "wm831x-boostp",
  1278. .id = 4,
  1279. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  1280. .resources = wm831x_dcdc4_resources,
  1281. },
  1282. {
  1283. .name = "wm831x-clk",
  1284. },
  1285. {
  1286. .name = "wm831x-epe",
  1287. .id = 1,
  1288. },
  1289. {
  1290. .name = "wm831x-epe",
  1291. .id = 2,
  1292. },
  1293. {
  1294. .name = "wm831x-gpio",
  1295. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1296. .resources = wm831x_gpio_resources,
  1297. },
  1298. {
  1299. .name = "wm831x-hwmon",
  1300. },
  1301. {
  1302. .name = "wm831x-isink",
  1303. .id = 1,
  1304. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1305. .resources = wm831x_isink1_resources,
  1306. },
  1307. {
  1308. .name = "wm831x-isink",
  1309. .id = 2,
  1310. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1311. .resources = wm831x_isink2_resources,
  1312. },
  1313. {
  1314. .name = "wm831x-ldo",
  1315. .id = 1,
  1316. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1317. .resources = wm831x_ldo1_resources,
  1318. },
  1319. {
  1320. .name = "wm831x-ldo",
  1321. .id = 2,
  1322. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1323. .resources = wm831x_ldo2_resources,
  1324. },
  1325. {
  1326. .name = "wm831x-ldo",
  1327. .id = 3,
  1328. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1329. .resources = wm831x_ldo3_resources,
  1330. },
  1331. {
  1332. .name = "wm831x-ldo",
  1333. .id = 4,
  1334. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1335. .resources = wm831x_ldo4_resources,
  1336. },
  1337. {
  1338. .name = "wm831x-ldo",
  1339. .id = 5,
  1340. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1341. .resources = wm831x_ldo5_resources,
  1342. },
  1343. {
  1344. .name = "wm831x-ldo",
  1345. .id = 6,
  1346. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1347. .resources = wm831x_ldo6_resources,
  1348. },
  1349. {
  1350. .name = "wm831x-aldo",
  1351. .id = 7,
  1352. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1353. .resources = wm831x_ldo7_resources,
  1354. },
  1355. {
  1356. .name = "wm831x-aldo",
  1357. .id = 8,
  1358. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1359. .resources = wm831x_ldo8_resources,
  1360. },
  1361. {
  1362. .name = "wm831x-aldo",
  1363. .id = 9,
  1364. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1365. .resources = wm831x_ldo9_resources,
  1366. },
  1367. {
  1368. .name = "wm831x-aldo",
  1369. .id = 10,
  1370. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1371. .resources = wm831x_ldo10_resources,
  1372. },
  1373. {
  1374. .name = "wm831x-alive-ldo",
  1375. .id = 11,
  1376. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1377. .resources = wm831x_ldo11_resources,
  1378. },
  1379. {
  1380. .name = "wm831x-on",
  1381. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1382. .resources = wm831x_on_resources,
  1383. },
  1384. {
  1385. .name = "wm831x-power",
  1386. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1387. .resources = wm831x_power_resources,
  1388. },
  1389. {
  1390. .name = "wm831x-status",
  1391. .id = 1,
  1392. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1393. .resources = wm831x_status1_resources,
  1394. },
  1395. {
  1396. .name = "wm831x-status",
  1397. .id = 2,
  1398. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1399. .resources = wm831x_status2_resources,
  1400. },
  1401. {
  1402. .name = "wm831x-watchdog",
  1403. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1404. .resources = wm831x_wdt_resources,
  1405. },
  1406. };
  1407. static struct mfd_cell wm8320_devs[] = {
  1408. {
  1409. .name = "wm831x-backup",
  1410. },
  1411. {
  1412. .name = "wm831x-buckv",
  1413. .id = 1,
  1414. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1415. .resources = wm831x_dcdc1_resources,
  1416. },
  1417. {
  1418. .name = "wm831x-buckv",
  1419. .id = 2,
  1420. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1421. .resources = wm831x_dcdc2_resources,
  1422. },
  1423. {
  1424. .name = "wm831x-buckp",
  1425. .id = 3,
  1426. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1427. .resources = wm831x_dcdc3_resources,
  1428. },
  1429. {
  1430. .name = "wm831x-buckp",
  1431. .id = 4,
  1432. .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
  1433. .resources = wm8320_dcdc4_buck_resources,
  1434. },
  1435. {
  1436. .name = "wm831x-clk",
  1437. },
  1438. {
  1439. .name = "wm831x-gpio",
  1440. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1441. .resources = wm831x_gpio_resources,
  1442. },
  1443. {
  1444. .name = "wm831x-hwmon",
  1445. },
  1446. {
  1447. .name = "wm831x-ldo",
  1448. .id = 1,
  1449. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1450. .resources = wm831x_ldo1_resources,
  1451. },
  1452. {
  1453. .name = "wm831x-ldo",
  1454. .id = 2,
  1455. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1456. .resources = wm831x_ldo2_resources,
  1457. },
  1458. {
  1459. .name = "wm831x-ldo",
  1460. .id = 3,
  1461. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1462. .resources = wm831x_ldo3_resources,
  1463. },
  1464. {
  1465. .name = "wm831x-ldo",
  1466. .id = 4,
  1467. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1468. .resources = wm831x_ldo4_resources,
  1469. },
  1470. {
  1471. .name = "wm831x-ldo",
  1472. .id = 5,
  1473. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1474. .resources = wm831x_ldo5_resources,
  1475. },
  1476. {
  1477. .name = "wm831x-ldo",
  1478. .id = 6,
  1479. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1480. .resources = wm831x_ldo6_resources,
  1481. },
  1482. {
  1483. .name = "wm831x-aldo",
  1484. .id = 7,
  1485. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1486. .resources = wm831x_ldo7_resources,
  1487. },
  1488. {
  1489. .name = "wm831x-aldo",
  1490. .id = 8,
  1491. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1492. .resources = wm831x_ldo8_resources,
  1493. },
  1494. {
  1495. .name = "wm831x-aldo",
  1496. .id = 9,
  1497. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1498. .resources = wm831x_ldo9_resources,
  1499. },
  1500. {
  1501. .name = "wm831x-aldo",
  1502. .id = 10,
  1503. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1504. .resources = wm831x_ldo10_resources,
  1505. },
  1506. {
  1507. .name = "wm831x-alive-ldo",
  1508. .id = 11,
  1509. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1510. .resources = wm831x_ldo11_resources,
  1511. },
  1512. {
  1513. .name = "wm831x-on",
  1514. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1515. .resources = wm831x_on_resources,
  1516. },
  1517. {
  1518. .name = "wm831x-status",
  1519. .id = 1,
  1520. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1521. .resources = wm831x_status1_resources,
  1522. },
  1523. {
  1524. .name = "wm831x-status",
  1525. .id = 2,
  1526. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1527. .resources = wm831x_status2_resources,
  1528. },
  1529. {
  1530. .name = "wm831x-watchdog",
  1531. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1532. .resources = wm831x_wdt_resources,
  1533. },
  1534. };
  1535. static struct mfd_cell touch_devs[] = {
  1536. {
  1537. .name = "wm831x-touch",
  1538. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1539. .resources = wm831x_touch_resources,
  1540. },
  1541. };
  1542. static struct mfd_cell rtc_devs[] = {
  1543. {
  1544. .name = "wm831x-rtc",
  1545. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1546. .resources = wm831x_rtc_resources,
  1547. },
  1548. };
  1549. static struct mfd_cell backlight_devs[] = {
  1550. {
  1551. .name = "wm831x-backlight",
  1552. },
  1553. };
  1554. struct regmap_config wm831x_regmap_config = {
  1555. .reg_bits = 16,
  1556. .val_bits = 16,
  1557. .cache_type = REGCACHE_RBTREE,
  1558. .max_register = WM831X_DBE_CHECK_DATA,
  1559. .readable_reg = wm831x_reg_readable,
  1560. .writeable_reg = wm831x_reg_writeable,
  1561. .volatile_reg = wm831x_reg_volatile,
  1562. };
  1563. EXPORT_SYMBOL_GPL(wm831x_regmap_config);
  1564. /*
  1565. * Instantiate the generic non-control parts of the device.
  1566. */
  1567. int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
  1568. {
  1569. struct wm831x_pdata *pdata = wm831x->dev->platform_data;
  1570. int rev, wm831x_num;
  1571. enum wm831x_parent parent;
  1572. int ret, i;
  1573. mutex_init(&wm831x->io_lock);
  1574. mutex_init(&wm831x->key_lock);
  1575. dev_set_drvdata(wm831x->dev, wm831x);
  1576. wm831x->soft_shutdown = pdata->soft_shutdown;
  1577. ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
  1578. if (ret < 0) {
  1579. dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
  1580. goto err;
  1581. }
  1582. switch (ret) {
  1583. case 0x6204:
  1584. case 0x6246:
  1585. break;
  1586. default:
  1587. dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
  1588. ret = -EINVAL;
  1589. goto err;
  1590. }
  1591. ret = wm831x_reg_read(wm831x, WM831X_REVISION);
  1592. if (ret < 0) {
  1593. dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
  1594. goto err;
  1595. }
  1596. rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
  1597. ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
  1598. if (ret < 0) {
  1599. dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
  1600. goto err;
  1601. }
  1602. /* Some engineering samples do not have the ID set, rely on
  1603. * the device being registered correctly.
  1604. */
  1605. if (ret == 0) {
  1606. dev_info(wm831x->dev, "Device is an engineering sample\n");
  1607. ret = id;
  1608. }
  1609. switch (ret) {
  1610. case WM8310:
  1611. parent = WM8310;
  1612. wm831x->num_gpio = 16;
  1613. wm831x->charger_irq_wake = 1;
  1614. if (rev > 0) {
  1615. wm831x->has_gpio_ena = 1;
  1616. wm831x->has_cs_sts = 1;
  1617. }
  1618. dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
  1619. break;
  1620. case WM8311:
  1621. parent = WM8311;
  1622. wm831x->num_gpio = 16;
  1623. wm831x->charger_irq_wake = 1;
  1624. if (rev > 0) {
  1625. wm831x->has_gpio_ena = 1;
  1626. wm831x->has_cs_sts = 1;
  1627. }
  1628. dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
  1629. break;
  1630. case WM8312:
  1631. parent = WM8312;
  1632. wm831x->num_gpio = 16;
  1633. wm831x->charger_irq_wake = 1;
  1634. if (rev > 0) {
  1635. wm831x->has_gpio_ena = 1;
  1636. wm831x->has_cs_sts = 1;
  1637. }
  1638. dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
  1639. break;
  1640. case WM8320:
  1641. parent = WM8320;
  1642. wm831x->num_gpio = 12;
  1643. dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
  1644. break;
  1645. case WM8321:
  1646. parent = WM8321;
  1647. wm831x->num_gpio = 12;
  1648. dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
  1649. break;
  1650. case WM8325:
  1651. parent = WM8325;
  1652. wm831x->num_gpio = 12;
  1653. dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
  1654. break;
  1655. case WM8326:
  1656. parent = WM8326;
  1657. wm831x->num_gpio = 12;
  1658. dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev);
  1659. break;
  1660. default:
  1661. dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
  1662. ret = -EINVAL;
  1663. goto err;
  1664. }
  1665. /* This will need revisiting in future but is OK for all
  1666. * current parts.
  1667. */
  1668. if (parent != id)
  1669. dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
  1670. id);
  1671. /* Bootstrap the user key */
  1672. ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
  1673. if (ret < 0) {
  1674. dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
  1675. goto err;
  1676. }
  1677. if (ret != 0) {
  1678. dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
  1679. ret);
  1680. wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  1681. }
  1682. wm831x->locked = 1;
  1683. if (pdata && pdata->pre_init) {
  1684. ret = pdata->pre_init(wm831x);
  1685. if (ret != 0) {
  1686. dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
  1687. goto err;
  1688. }
  1689. }
  1690. if (pdata) {
  1691. for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
  1692. if (!pdata->gpio_defaults[i])
  1693. continue;
  1694. wm831x_reg_write(wm831x,
  1695. WM831X_GPIO1_CONTROL + i,
  1696. pdata->gpio_defaults[i] & 0xffff);
  1697. }
  1698. }
  1699. /* Multiply by 10 as we have many subdevices of the same type */
  1700. if (pdata && pdata->wm831x_num)
  1701. wm831x_num = pdata->wm831x_num * 10;
  1702. else
  1703. wm831x_num = -1;
  1704. ret = wm831x_irq_init(wm831x, irq);
  1705. if (ret != 0)
  1706. goto err;
  1707. wm831x_auxadc_init(wm831x);
  1708. /* The core device is up, instantiate the subdevices. */
  1709. switch (parent) {
  1710. case WM8310:
  1711. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1712. wm8310_devs, ARRAY_SIZE(wm8310_devs),
  1713. NULL, 0);
  1714. break;
  1715. case WM8311:
  1716. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1717. wm8311_devs, ARRAY_SIZE(wm8311_devs),
  1718. NULL, 0);
  1719. if (!pdata || !pdata->disable_touch)
  1720. mfd_add_devices(wm831x->dev, wm831x_num,
  1721. touch_devs, ARRAY_SIZE(touch_devs),
  1722. NULL, 0);
  1723. break;
  1724. case WM8312:
  1725. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1726. wm8312_devs, ARRAY_SIZE(wm8312_devs),
  1727. NULL, 0);
  1728. if (!pdata || !pdata->disable_touch)
  1729. mfd_add_devices(wm831x->dev, wm831x_num,
  1730. touch_devs, ARRAY_SIZE(touch_devs),
  1731. NULL, 0);
  1732. break;
  1733. case WM8320:
  1734. case WM8321:
  1735. case WM8325:
  1736. case WM8326:
  1737. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1738. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1739. NULL, 0);
  1740. break;
  1741. default:
  1742. /* If this happens the bus probe function is buggy */
  1743. BUG();
  1744. }
  1745. if (ret != 0) {
  1746. dev_err(wm831x->dev, "Failed to add children\n");
  1747. goto err_irq;
  1748. }
  1749. /* The RTC can only be used if the 32.768kHz crystal is
  1750. * enabled; this can't be controlled by software at runtime.
  1751. */
  1752. ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2);
  1753. if (ret < 0) {
  1754. dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret);
  1755. goto err_irq;
  1756. }
  1757. if (ret & WM831X_XTAL_ENA) {
  1758. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1759. rtc_devs, ARRAY_SIZE(rtc_devs),
  1760. NULL, 0);
  1761. if (ret != 0) {
  1762. dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret);
  1763. goto err_irq;
  1764. }
  1765. } else {
  1766. dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n");
  1767. }
  1768. if (pdata && pdata->backlight) {
  1769. /* Treat errors as non-critical */
  1770. ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs,
  1771. ARRAY_SIZE(backlight_devs), NULL,
  1772. 0);
  1773. if (ret < 0)
  1774. dev_err(wm831x->dev, "Failed to add backlight: %d\n",
  1775. ret);
  1776. }
  1777. wm831x_otp_init(wm831x);
  1778. if (pdata && pdata->post_init) {
  1779. ret = pdata->post_init(wm831x);
  1780. if (ret != 0) {
  1781. dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
  1782. goto err_irq;
  1783. }
  1784. }
  1785. return 0;
  1786. err_irq:
  1787. wm831x_irq_exit(wm831x);
  1788. err:
  1789. mfd_remove_devices(wm831x->dev);
  1790. return ret;
  1791. }
  1792. void wm831x_device_exit(struct wm831x *wm831x)
  1793. {
  1794. wm831x_otp_exit(wm831x);
  1795. mfd_remove_devices(wm831x->dev);
  1796. free_irq(wm831x_irq(wm831x, WM831X_IRQ_AUXADC_DATA), wm831x);
  1797. wm831x_irq_exit(wm831x);
  1798. }
  1799. int wm831x_device_suspend(struct wm831x *wm831x)
  1800. {
  1801. int reg, mask;
  1802. /* If the charger IRQs are a wake source then make sure we ack
  1803. * them even if they're not actively being used (eg, no power
  1804. * driver or no IRQ line wired up) then acknowledge the
  1805. * interrupts otherwise suspend won't last very long.
  1806. */
  1807. if (wm831x->charger_irq_wake) {
  1808. reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
  1809. mask = WM831X_CHG_BATT_HOT_EINT |
  1810. WM831X_CHG_BATT_COLD_EINT |
  1811. WM831X_CHG_BATT_FAIL_EINT |
  1812. WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
  1813. WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
  1814. WM831X_CHG_START_EINT;
  1815. /* If any of the interrupts are masked read the statuses */
  1816. if (reg & mask)
  1817. reg = wm831x_reg_read(wm831x,
  1818. WM831X_INTERRUPT_STATUS_2);
  1819. if (reg & mask) {
  1820. dev_info(wm831x->dev,
  1821. "Acknowledging masked charger IRQs: %x\n",
  1822. reg & mask);
  1823. wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
  1824. reg & mask);
  1825. }
  1826. }
  1827. return 0;
  1828. }
  1829. void wm831x_device_shutdown(struct wm831x *wm831x)
  1830. {
  1831. if (wm831x->soft_shutdown) {
  1832. dev_info(wm831x->dev, "Initiating shutdown...\n");
  1833. wm831x_set_bits(wm831x, WM831X_POWER_STATE, WM831X_CHIP_ON, 0);
  1834. }
  1835. }
  1836. EXPORT_SYMBOL_GPL(wm831x_device_shutdown);
  1837. MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
  1838. MODULE_LICENSE("GPL");
  1839. MODULE_AUTHOR("Mark Brown");