wm831x-core.c 40 KB

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