wm831x-core.c 42 KB

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