wm831x-core.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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/mfd/wm831x/core.h>
  21. #include <linux/mfd/wm831x/pdata.h>
  22. #include <linux/mfd/wm831x/irq.h>
  23. #include <linux/mfd/wm831x/auxadc.h>
  24. #include <linux/mfd/wm831x/otp.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. 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_unlock: 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. void wm831x_reg_lock(struct wm831x *wm831x)
  112. {
  113. int ret;
  114. ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  115. if (ret == 0) {
  116. dev_vdbg(wm831x->dev, "Registers locked\n");
  117. mutex_lock(&wm831x->io_lock);
  118. WARN_ON(wm831x->locked);
  119. wm831x->locked = 1;
  120. mutex_unlock(&wm831x->io_lock);
  121. } else {
  122. dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret);
  123. }
  124. }
  125. EXPORT_SYMBOL_GPL(wm831x_reg_lock);
  126. /**
  127. * wm831x_reg_unlock: Unlock user keyed registers
  128. *
  129. * The WM831x has a user key preventing writes to particularly
  130. * critical registers. This function locks those registers,
  131. * preventing spurious writes.
  132. */
  133. int wm831x_reg_unlock(struct wm831x *wm831x)
  134. {
  135. int ret;
  136. /* 0x9716 is the value required to unlock the registers */
  137. ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716);
  138. if (ret == 0) {
  139. dev_vdbg(wm831x->dev, "Registers unlocked\n");
  140. mutex_lock(&wm831x->io_lock);
  141. WARN_ON(!wm831x->locked);
  142. wm831x->locked = 0;
  143. mutex_unlock(&wm831x->io_lock);
  144. }
  145. return ret;
  146. }
  147. EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
  148. static int wm831x_read(struct wm831x *wm831x, unsigned short reg,
  149. int bytes, void *dest)
  150. {
  151. int ret, i;
  152. u16 *buf = dest;
  153. BUG_ON(bytes % 2);
  154. BUG_ON(bytes <= 0);
  155. ret = wm831x->read_dev(wm831x, reg, bytes, dest);
  156. if (ret < 0)
  157. return ret;
  158. for (i = 0; i < bytes / 2; i++) {
  159. buf[i] = be16_to_cpu(buf[i]);
  160. dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n",
  161. buf[i], reg + i, reg + i);
  162. }
  163. return 0;
  164. }
  165. /**
  166. * wm831x_reg_read: Read a single WM831x register.
  167. *
  168. * @wm831x: Device to read from.
  169. * @reg: Register to read.
  170. */
  171. int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
  172. {
  173. unsigned short val;
  174. int ret;
  175. mutex_lock(&wm831x->io_lock);
  176. ret = wm831x_read(wm831x, reg, 2, &val);
  177. mutex_unlock(&wm831x->io_lock);
  178. if (ret < 0)
  179. return ret;
  180. else
  181. return val;
  182. }
  183. EXPORT_SYMBOL_GPL(wm831x_reg_read);
  184. /**
  185. * wm831x_bulk_read: Read multiple WM831x registers
  186. *
  187. * @wm831x: Device to read from
  188. * @reg: First register
  189. * @count: Number of registers
  190. * @buf: Buffer to fill.
  191. */
  192. int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
  193. int count, u16 *buf)
  194. {
  195. int ret;
  196. mutex_lock(&wm831x->io_lock);
  197. ret = wm831x_read(wm831x, reg, count * 2, buf);
  198. mutex_unlock(&wm831x->io_lock);
  199. return ret;
  200. }
  201. EXPORT_SYMBOL_GPL(wm831x_bulk_read);
  202. static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
  203. int bytes, void *src)
  204. {
  205. u16 *buf = src;
  206. int i;
  207. BUG_ON(bytes % 2);
  208. BUG_ON(bytes <= 0);
  209. for (i = 0; i < bytes / 2; i++) {
  210. if (wm831x_reg_locked(wm831x, reg))
  211. return -EPERM;
  212. dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n",
  213. buf[i], reg + i, reg + i);
  214. buf[i] = cpu_to_be16(buf[i]);
  215. }
  216. return wm831x->write_dev(wm831x, reg, bytes, src);
  217. }
  218. /**
  219. * wm831x_reg_write: Write a single WM831x register.
  220. *
  221. * @wm831x: Device to write to.
  222. * @reg: Register to write to.
  223. * @val: Value to write.
  224. */
  225. int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg,
  226. unsigned short val)
  227. {
  228. int ret;
  229. mutex_lock(&wm831x->io_lock);
  230. ret = wm831x_write(wm831x, reg, 2, &val);
  231. mutex_unlock(&wm831x->io_lock);
  232. return ret;
  233. }
  234. EXPORT_SYMBOL_GPL(wm831x_reg_write);
  235. /**
  236. * wm831x_set_bits: Set the value of a bitfield in a WM831x register
  237. *
  238. * @wm831x: Device to write to.
  239. * @reg: Register to write to.
  240. * @mask: Mask of bits to set.
  241. * @val: Value to set (unshifted)
  242. */
  243. int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
  244. unsigned short mask, unsigned short val)
  245. {
  246. int ret;
  247. u16 r;
  248. mutex_lock(&wm831x->io_lock);
  249. ret = wm831x_read(wm831x, reg, 2, &r);
  250. if (ret < 0)
  251. goto out;
  252. r &= ~mask;
  253. r |= val;
  254. ret = wm831x_write(wm831x, reg, 2, &r);
  255. out:
  256. mutex_unlock(&wm831x->io_lock);
  257. return ret;
  258. }
  259. EXPORT_SYMBOL_GPL(wm831x_set_bits);
  260. /**
  261. * wm831x_auxadc_read: Read a value from the WM831x AUXADC
  262. *
  263. * @wm831x: Device to read from.
  264. * @input: AUXADC input to read.
  265. */
  266. int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
  267. {
  268. int ret, src, irq_masked, timeout;
  269. /* Are we using the interrupt? */
  270. irq_masked = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_1_MASK);
  271. irq_masked &= WM831X_AUXADC_DATA_EINT;
  272. mutex_lock(&wm831x->auxadc_lock);
  273. ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
  274. WM831X_AUX_ENA, WM831X_AUX_ENA);
  275. if (ret < 0) {
  276. dev_err(wm831x->dev, "Failed to enable AUXADC: %d\n", ret);
  277. goto out;
  278. }
  279. /* We force a single source at present */
  280. src = input;
  281. ret = wm831x_reg_write(wm831x, WM831X_AUXADC_SOURCE,
  282. 1 << src);
  283. if (ret < 0) {
  284. dev_err(wm831x->dev, "Failed to set AUXADC source: %d\n", ret);
  285. goto out;
  286. }
  287. /* Clear any notification from a very late arriving interrupt */
  288. try_wait_for_completion(&wm831x->auxadc_done);
  289. ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
  290. WM831X_AUX_CVT_ENA, WM831X_AUX_CVT_ENA);
  291. if (ret < 0) {
  292. dev_err(wm831x->dev, "Failed to start AUXADC: %d\n", ret);
  293. goto disable;
  294. }
  295. if (irq_masked) {
  296. /* If we're not using interrupts then poll the
  297. * interrupt status register */
  298. timeout = 5;
  299. while (timeout) {
  300. msleep(1);
  301. ret = wm831x_reg_read(wm831x,
  302. WM831X_INTERRUPT_STATUS_1);
  303. if (ret < 0) {
  304. dev_err(wm831x->dev,
  305. "ISR 1 read failed: %d\n", ret);
  306. goto disable;
  307. }
  308. /* Did it complete? */
  309. if (ret & WM831X_AUXADC_DATA_EINT) {
  310. wm831x_reg_write(wm831x,
  311. WM831X_INTERRUPT_STATUS_1,
  312. WM831X_AUXADC_DATA_EINT);
  313. break;
  314. } else {
  315. dev_err(wm831x->dev,
  316. "AUXADC conversion timeout\n");
  317. ret = -EBUSY;
  318. goto disable;
  319. }
  320. }
  321. } else {
  322. /* If we are using interrupts then wait for the
  323. * interrupt to complete. Use an extremely long
  324. * timeout to handle situations with heavy load where
  325. * the notification of the interrupt may be delayed by
  326. * threaded IRQ handling. */
  327. if (!wait_for_completion_timeout(&wm831x->auxadc_done,
  328. msecs_to_jiffies(500))) {
  329. dev_err(wm831x->dev, "Timed out waiting for AUXADC\n");
  330. ret = -EBUSY;
  331. goto disable;
  332. }
  333. }
  334. ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
  335. if (ret < 0) {
  336. dev_err(wm831x->dev, "Failed to read AUXADC data: %d\n", ret);
  337. } else {
  338. src = ((ret & WM831X_AUX_DATA_SRC_MASK)
  339. >> WM831X_AUX_DATA_SRC_SHIFT) - 1;
  340. if (src == 14)
  341. src = WM831X_AUX_CAL;
  342. if (src != input) {
  343. dev_err(wm831x->dev, "Data from source %d not %d\n",
  344. src, input);
  345. ret = -EINVAL;
  346. } else {
  347. ret &= WM831X_AUX_DATA_MASK;
  348. }
  349. }
  350. disable:
  351. wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, WM831X_AUX_ENA, 0);
  352. out:
  353. mutex_unlock(&wm831x->auxadc_lock);
  354. return ret;
  355. }
  356. EXPORT_SYMBOL_GPL(wm831x_auxadc_read);
  357. static irqreturn_t wm831x_auxadc_irq(int irq, void *irq_data)
  358. {
  359. struct wm831x *wm831x = irq_data;
  360. complete(&wm831x->auxadc_done);
  361. return IRQ_HANDLED;
  362. }
  363. /**
  364. * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC
  365. *
  366. * @wm831x: Device to read from.
  367. * @input: AUXADC input to read.
  368. */
  369. int wm831x_auxadc_read_uv(struct wm831x *wm831x, enum wm831x_auxadc input)
  370. {
  371. int ret;
  372. ret = wm831x_auxadc_read(wm831x, input);
  373. if (ret < 0)
  374. return ret;
  375. ret *= 1465;
  376. return ret;
  377. }
  378. EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv);
  379. static struct resource wm831x_dcdc1_resources[] = {
  380. {
  381. .start = WM831X_DC1_CONTROL_1,
  382. .end = WM831X_DC1_DVS_CONTROL,
  383. .flags = IORESOURCE_IO,
  384. },
  385. {
  386. .name = "UV",
  387. .start = WM831X_IRQ_UV_DC1,
  388. .end = WM831X_IRQ_UV_DC1,
  389. .flags = IORESOURCE_IRQ,
  390. },
  391. {
  392. .name = "HC",
  393. .start = WM831X_IRQ_HC_DC1,
  394. .end = WM831X_IRQ_HC_DC1,
  395. .flags = IORESOURCE_IRQ,
  396. },
  397. };
  398. static struct resource wm831x_dcdc2_resources[] = {
  399. {
  400. .start = WM831X_DC2_CONTROL_1,
  401. .end = WM831X_DC2_DVS_CONTROL,
  402. .flags = IORESOURCE_IO,
  403. },
  404. {
  405. .name = "UV",
  406. .start = WM831X_IRQ_UV_DC2,
  407. .end = WM831X_IRQ_UV_DC2,
  408. .flags = IORESOURCE_IRQ,
  409. },
  410. {
  411. .name = "HC",
  412. .start = WM831X_IRQ_HC_DC2,
  413. .end = WM831X_IRQ_HC_DC2,
  414. .flags = IORESOURCE_IRQ,
  415. },
  416. };
  417. static struct resource wm831x_dcdc3_resources[] = {
  418. {
  419. .start = WM831X_DC3_CONTROL_1,
  420. .end = WM831X_DC3_SLEEP_CONTROL,
  421. .flags = IORESOURCE_IO,
  422. },
  423. {
  424. .name = "UV",
  425. .start = WM831X_IRQ_UV_DC3,
  426. .end = WM831X_IRQ_UV_DC3,
  427. .flags = IORESOURCE_IRQ,
  428. },
  429. };
  430. static struct resource wm831x_dcdc4_resources[] = {
  431. {
  432. .start = WM831X_DC4_CONTROL,
  433. .end = WM831X_DC4_SLEEP_CONTROL,
  434. .flags = IORESOURCE_IO,
  435. },
  436. {
  437. .name = "UV",
  438. .start = WM831X_IRQ_UV_DC4,
  439. .end = WM831X_IRQ_UV_DC4,
  440. .flags = IORESOURCE_IRQ,
  441. },
  442. };
  443. static struct resource wm8320_dcdc4_buck_resources[] = {
  444. {
  445. .start = WM831X_DC4_CONTROL,
  446. .end = WM832X_DC4_SLEEP_CONTROL,
  447. .flags = IORESOURCE_IO,
  448. },
  449. {
  450. .name = "UV",
  451. .start = WM831X_IRQ_UV_DC4,
  452. .end = WM831X_IRQ_UV_DC4,
  453. .flags = IORESOURCE_IRQ,
  454. },
  455. };
  456. static struct resource wm831x_gpio_resources[] = {
  457. {
  458. .start = WM831X_IRQ_GPIO_1,
  459. .end = WM831X_IRQ_GPIO_16,
  460. .flags = IORESOURCE_IRQ,
  461. },
  462. };
  463. static struct resource wm831x_isink1_resources[] = {
  464. {
  465. .start = WM831X_CURRENT_SINK_1,
  466. .end = WM831X_CURRENT_SINK_1,
  467. .flags = IORESOURCE_IO,
  468. },
  469. {
  470. .start = WM831X_IRQ_CS1,
  471. .end = WM831X_IRQ_CS1,
  472. .flags = IORESOURCE_IRQ,
  473. },
  474. };
  475. static struct resource wm831x_isink2_resources[] = {
  476. {
  477. .start = WM831X_CURRENT_SINK_2,
  478. .end = WM831X_CURRENT_SINK_2,
  479. .flags = IORESOURCE_IO,
  480. },
  481. {
  482. .start = WM831X_IRQ_CS2,
  483. .end = WM831X_IRQ_CS2,
  484. .flags = IORESOURCE_IRQ,
  485. },
  486. };
  487. static struct resource wm831x_ldo1_resources[] = {
  488. {
  489. .start = WM831X_LDO1_CONTROL,
  490. .end = WM831X_LDO1_SLEEP_CONTROL,
  491. .flags = IORESOURCE_IO,
  492. },
  493. {
  494. .name = "UV",
  495. .start = WM831X_IRQ_UV_LDO1,
  496. .end = WM831X_IRQ_UV_LDO1,
  497. .flags = IORESOURCE_IRQ,
  498. },
  499. };
  500. static struct resource wm831x_ldo2_resources[] = {
  501. {
  502. .start = WM831X_LDO2_CONTROL,
  503. .end = WM831X_LDO2_SLEEP_CONTROL,
  504. .flags = IORESOURCE_IO,
  505. },
  506. {
  507. .name = "UV",
  508. .start = WM831X_IRQ_UV_LDO2,
  509. .end = WM831X_IRQ_UV_LDO2,
  510. .flags = IORESOURCE_IRQ,
  511. },
  512. };
  513. static struct resource wm831x_ldo3_resources[] = {
  514. {
  515. .start = WM831X_LDO3_CONTROL,
  516. .end = WM831X_LDO3_SLEEP_CONTROL,
  517. .flags = IORESOURCE_IO,
  518. },
  519. {
  520. .name = "UV",
  521. .start = WM831X_IRQ_UV_LDO3,
  522. .end = WM831X_IRQ_UV_LDO3,
  523. .flags = IORESOURCE_IRQ,
  524. },
  525. };
  526. static struct resource wm831x_ldo4_resources[] = {
  527. {
  528. .start = WM831X_LDO4_CONTROL,
  529. .end = WM831X_LDO4_SLEEP_CONTROL,
  530. .flags = IORESOURCE_IO,
  531. },
  532. {
  533. .name = "UV",
  534. .start = WM831X_IRQ_UV_LDO4,
  535. .end = WM831X_IRQ_UV_LDO4,
  536. .flags = IORESOURCE_IRQ,
  537. },
  538. };
  539. static struct resource wm831x_ldo5_resources[] = {
  540. {
  541. .start = WM831X_LDO5_CONTROL,
  542. .end = WM831X_LDO5_SLEEP_CONTROL,
  543. .flags = IORESOURCE_IO,
  544. },
  545. {
  546. .name = "UV",
  547. .start = WM831X_IRQ_UV_LDO5,
  548. .end = WM831X_IRQ_UV_LDO5,
  549. .flags = IORESOURCE_IRQ,
  550. },
  551. };
  552. static struct resource wm831x_ldo6_resources[] = {
  553. {
  554. .start = WM831X_LDO6_CONTROL,
  555. .end = WM831X_LDO6_SLEEP_CONTROL,
  556. .flags = IORESOURCE_IO,
  557. },
  558. {
  559. .name = "UV",
  560. .start = WM831X_IRQ_UV_LDO6,
  561. .end = WM831X_IRQ_UV_LDO6,
  562. .flags = IORESOURCE_IRQ,
  563. },
  564. };
  565. static struct resource wm831x_ldo7_resources[] = {
  566. {
  567. .start = WM831X_LDO7_CONTROL,
  568. .end = WM831X_LDO7_SLEEP_CONTROL,
  569. .flags = IORESOURCE_IO,
  570. },
  571. {
  572. .name = "UV",
  573. .start = WM831X_IRQ_UV_LDO7,
  574. .end = WM831X_IRQ_UV_LDO7,
  575. .flags = IORESOURCE_IRQ,
  576. },
  577. };
  578. static struct resource wm831x_ldo8_resources[] = {
  579. {
  580. .start = WM831X_LDO8_CONTROL,
  581. .end = WM831X_LDO8_SLEEP_CONTROL,
  582. .flags = IORESOURCE_IO,
  583. },
  584. {
  585. .name = "UV",
  586. .start = WM831X_IRQ_UV_LDO8,
  587. .end = WM831X_IRQ_UV_LDO8,
  588. .flags = IORESOURCE_IRQ,
  589. },
  590. };
  591. static struct resource wm831x_ldo9_resources[] = {
  592. {
  593. .start = WM831X_LDO9_CONTROL,
  594. .end = WM831X_LDO9_SLEEP_CONTROL,
  595. .flags = IORESOURCE_IO,
  596. },
  597. {
  598. .name = "UV",
  599. .start = WM831X_IRQ_UV_LDO9,
  600. .end = WM831X_IRQ_UV_LDO9,
  601. .flags = IORESOURCE_IRQ,
  602. },
  603. };
  604. static struct resource wm831x_ldo10_resources[] = {
  605. {
  606. .start = WM831X_LDO10_CONTROL,
  607. .end = WM831X_LDO10_SLEEP_CONTROL,
  608. .flags = IORESOURCE_IO,
  609. },
  610. {
  611. .name = "UV",
  612. .start = WM831X_IRQ_UV_LDO10,
  613. .end = WM831X_IRQ_UV_LDO10,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. };
  617. static struct resource wm831x_ldo11_resources[] = {
  618. {
  619. .start = WM831X_LDO11_ON_CONTROL,
  620. .end = WM831X_LDO11_SLEEP_CONTROL,
  621. .flags = IORESOURCE_IO,
  622. },
  623. };
  624. static struct resource wm831x_on_resources[] = {
  625. {
  626. .start = WM831X_IRQ_ON,
  627. .end = WM831X_IRQ_ON,
  628. .flags = IORESOURCE_IRQ,
  629. },
  630. };
  631. static struct resource wm831x_power_resources[] = {
  632. {
  633. .name = "SYSLO",
  634. .start = WM831X_IRQ_PPM_SYSLO,
  635. .end = WM831X_IRQ_PPM_SYSLO,
  636. .flags = IORESOURCE_IRQ,
  637. },
  638. {
  639. .name = "PWR SRC",
  640. .start = WM831X_IRQ_PPM_PWR_SRC,
  641. .end = WM831X_IRQ_PPM_PWR_SRC,
  642. .flags = IORESOURCE_IRQ,
  643. },
  644. {
  645. .name = "USB CURR",
  646. .start = WM831X_IRQ_PPM_USB_CURR,
  647. .end = WM831X_IRQ_PPM_USB_CURR,
  648. .flags = IORESOURCE_IRQ,
  649. },
  650. {
  651. .name = "BATT HOT",
  652. .start = WM831X_IRQ_CHG_BATT_HOT,
  653. .end = WM831X_IRQ_CHG_BATT_HOT,
  654. .flags = IORESOURCE_IRQ,
  655. },
  656. {
  657. .name = "BATT COLD",
  658. .start = WM831X_IRQ_CHG_BATT_COLD,
  659. .end = WM831X_IRQ_CHG_BATT_COLD,
  660. .flags = IORESOURCE_IRQ,
  661. },
  662. {
  663. .name = "BATT FAIL",
  664. .start = WM831X_IRQ_CHG_BATT_FAIL,
  665. .end = WM831X_IRQ_CHG_BATT_FAIL,
  666. .flags = IORESOURCE_IRQ,
  667. },
  668. {
  669. .name = "OV",
  670. .start = WM831X_IRQ_CHG_OV,
  671. .end = WM831X_IRQ_CHG_OV,
  672. .flags = IORESOURCE_IRQ,
  673. },
  674. {
  675. .name = "END",
  676. .start = WM831X_IRQ_CHG_END,
  677. .end = WM831X_IRQ_CHG_END,
  678. .flags = IORESOURCE_IRQ,
  679. },
  680. {
  681. .name = "TO",
  682. .start = WM831X_IRQ_CHG_TO,
  683. .end = WM831X_IRQ_CHG_TO,
  684. .flags = IORESOURCE_IRQ,
  685. },
  686. {
  687. .name = "MODE",
  688. .start = WM831X_IRQ_CHG_MODE,
  689. .end = WM831X_IRQ_CHG_MODE,
  690. .flags = IORESOURCE_IRQ,
  691. },
  692. {
  693. .name = "START",
  694. .start = WM831X_IRQ_CHG_START,
  695. .end = WM831X_IRQ_CHG_START,
  696. .flags = IORESOURCE_IRQ,
  697. },
  698. };
  699. static struct resource wm831x_rtc_resources[] = {
  700. {
  701. .name = "PER",
  702. .start = WM831X_IRQ_RTC_PER,
  703. .end = WM831X_IRQ_RTC_PER,
  704. .flags = IORESOURCE_IRQ,
  705. },
  706. {
  707. .name = "ALM",
  708. .start = WM831X_IRQ_RTC_ALM,
  709. .end = WM831X_IRQ_RTC_ALM,
  710. .flags = IORESOURCE_IRQ,
  711. },
  712. };
  713. static struct resource wm831x_status1_resources[] = {
  714. {
  715. .start = WM831X_STATUS_LED_1,
  716. .end = WM831X_STATUS_LED_1,
  717. .flags = IORESOURCE_IO,
  718. },
  719. };
  720. static struct resource wm831x_status2_resources[] = {
  721. {
  722. .start = WM831X_STATUS_LED_2,
  723. .end = WM831X_STATUS_LED_2,
  724. .flags = IORESOURCE_IO,
  725. },
  726. };
  727. static struct resource wm831x_touch_resources[] = {
  728. {
  729. .name = "TCHPD",
  730. .start = WM831X_IRQ_TCHPD,
  731. .end = WM831X_IRQ_TCHPD,
  732. .flags = IORESOURCE_IRQ,
  733. },
  734. {
  735. .name = "TCHDATA",
  736. .start = WM831X_IRQ_TCHDATA,
  737. .end = WM831X_IRQ_TCHDATA,
  738. .flags = IORESOURCE_IRQ,
  739. },
  740. };
  741. static struct resource wm831x_wdt_resources[] = {
  742. {
  743. .start = WM831X_IRQ_WDOG_TO,
  744. .end = WM831X_IRQ_WDOG_TO,
  745. .flags = IORESOURCE_IRQ,
  746. },
  747. };
  748. static struct mfd_cell wm8310_devs[] = {
  749. {
  750. .name = "wm831x-backup",
  751. },
  752. {
  753. .name = "wm831x-buckv",
  754. .id = 1,
  755. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  756. .resources = wm831x_dcdc1_resources,
  757. },
  758. {
  759. .name = "wm831x-buckv",
  760. .id = 2,
  761. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  762. .resources = wm831x_dcdc2_resources,
  763. },
  764. {
  765. .name = "wm831x-buckp",
  766. .id = 3,
  767. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  768. .resources = wm831x_dcdc3_resources,
  769. },
  770. {
  771. .name = "wm831x-boostp",
  772. .id = 4,
  773. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  774. .resources = wm831x_dcdc4_resources,
  775. },
  776. {
  777. .name = "wm831x-epe",
  778. .id = 1,
  779. },
  780. {
  781. .name = "wm831x-epe",
  782. .id = 2,
  783. },
  784. {
  785. .name = "wm831x-gpio",
  786. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  787. .resources = wm831x_gpio_resources,
  788. },
  789. {
  790. .name = "wm831x-hwmon",
  791. },
  792. {
  793. .name = "wm831x-isink",
  794. .id = 1,
  795. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  796. .resources = wm831x_isink1_resources,
  797. },
  798. {
  799. .name = "wm831x-isink",
  800. .id = 2,
  801. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  802. .resources = wm831x_isink2_resources,
  803. },
  804. {
  805. .name = "wm831x-ldo",
  806. .id = 1,
  807. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  808. .resources = wm831x_ldo1_resources,
  809. },
  810. {
  811. .name = "wm831x-ldo",
  812. .id = 2,
  813. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  814. .resources = wm831x_ldo2_resources,
  815. },
  816. {
  817. .name = "wm831x-ldo",
  818. .id = 3,
  819. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  820. .resources = wm831x_ldo3_resources,
  821. },
  822. {
  823. .name = "wm831x-ldo",
  824. .id = 4,
  825. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  826. .resources = wm831x_ldo4_resources,
  827. },
  828. {
  829. .name = "wm831x-ldo",
  830. .id = 5,
  831. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  832. .resources = wm831x_ldo5_resources,
  833. },
  834. {
  835. .name = "wm831x-ldo",
  836. .id = 6,
  837. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  838. .resources = wm831x_ldo6_resources,
  839. },
  840. {
  841. .name = "wm831x-aldo",
  842. .id = 7,
  843. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  844. .resources = wm831x_ldo7_resources,
  845. },
  846. {
  847. .name = "wm831x-aldo",
  848. .id = 8,
  849. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  850. .resources = wm831x_ldo8_resources,
  851. },
  852. {
  853. .name = "wm831x-aldo",
  854. .id = 9,
  855. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  856. .resources = wm831x_ldo9_resources,
  857. },
  858. {
  859. .name = "wm831x-aldo",
  860. .id = 10,
  861. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  862. .resources = wm831x_ldo10_resources,
  863. },
  864. {
  865. .name = "wm831x-alive-ldo",
  866. .id = 11,
  867. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  868. .resources = wm831x_ldo11_resources,
  869. },
  870. {
  871. .name = "wm831x-on",
  872. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  873. .resources = wm831x_on_resources,
  874. },
  875. {
  876. .name = "wm831x-power",
  877. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  878. .resources = wm831x_power_resources,
  879. },
  880. {
  881. .name = "wm831x-rtc",
  882. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  883. .resources = wm831x_rtc_resources,
  884. },
  885. {
  886. .name = "wm831x-status",
  887. .id = 1,
  888. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  889. .resources = wm831x_status1_resources,
  890. },
  891. {
  892. .name = "wm831x-status",
  893. .id = 2,
  894. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  895. .resources = wm831x_status2_resources,
  896. },
  897. {
  898. .name = "wm831x-watchdog",
  899. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  900. .resources = wm831x_wdt_resources,
  901. },
  902. };
  903. static struct mfd_cell wm8311_devs[] = {
  904. {
  905. .name = "wm831x-backup",
  906. },
  907. {
  908. .name = "wm831x-buckv",
  909. .id = 1,
  910. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  911. .resources = wm831x_dcdc1_resources,
  912. },
  913. {
  914. .name = "wm831x-buckv",
  915. .id = 2,
  916. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  917. .resources = wm831x_dcdc2_resources,
  918. },
  919. {
  920. .name = "wm831x-buckp",
  921. .id = 3,
  922. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  923. .resources = wm831x_dcdc3_resources,
  924. },
  925. {
  926. .name = "wm831x-boostp",
  927. .id = 4,
  928. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  929. .resources = wm831x_dcdc4_resources,
  930. },
  931. {
  932. .name = "wm831x-epe",
  933. .id = 1,
  934. },
  935. {
  936. .name = "wm831x-epe",
  937. .id = 2,
  938. },
  939. {
  940. .name = "wm831x-gpio",
  941. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  942. .resources = wm831x_gpio_resources,
  943. },
  944. {
  945. .name = "wm831x-hwmon",
  946. },
  947. {
  948. .name = "wm831x-isink",
  949. .id = 1,
  950. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  951. .resources = wm831x_isink1_resources,
  952. },
  953. {
  954. .name = "wm831x-isink",
  955. .id = 2,
  956. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  957. .resources = wm831x_isink2_resources,
  958. },
  959. {
  960. .name = "wm831x-ldo",
  961. .id = 1,
  962. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  963. .resources = wm831x_ldo1_resources,
  964. },
  965. {
  966. .name = "wm831x-ldo",
  967. .id = 2,
  968. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  969. .resources = wm831x_ldo2_resources,
  970. },
  971. {
  972. .name = "wm831x-ldo",
  973. .id = 3,
  974. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  975. .resources = wm831x_ldo3_resources,
  976. },
  977. {
  978. .name = "wm831x-ldo",
  979. .id = 4,
  980. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  981. .resources = wm831x_ldo4_resources,
  982. },
  983. {
  984. .name = "wm831x-ldo",
  985. .id = 5,
  986. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  987. .resources = wm831x_ldo5_resources,
  988. },
  989. {
  990. .name = "wm831x-aldo",
  991. .id = 7,
  992. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  993. .resources = wm831x_ldo7_resources,
  994. },
  995. {
  996. .name = "wm831x-alive-ldo",
  997. .id = 11,
  998. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  999. .resources = wm831x_ldo11_resources,
  1000. },
  1001. {
  1002. .name = "wm831x-on",
  1003. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1004. .resources = wm831x_on_resources,
  1005. },
  1006. {
  1007. .name = "wm831x-power",
  1008. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1009. .resources = wm831x_power_resources,
  1010. },
  1011. {
  1012. .name = "wm831x-rtc",
  1013. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1014. .resources = wm831x_rtc_resources,
  1015. },
  1016. {
  1017. .name = "wm831x-status",
  1018. .id = 1,
  1019. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1020. .resources = wm831x_status1_resources,
  1021. },
  1022. {
  1023. .name = "wm831x-status",
  1024. .id = 2,
  1025. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1026. .resources = wm831x_status2_resources,
  1027. },
  1028. {
  1029. .name = "wm831x-touch",
  1030. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1031. .resources = wm831x_touch_resources,
  1032. },
  1033. {
  1034. .name = "wm831x-watchdog",
  1035. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1036. .resources = wm831x_wdt_resources,
  1037. },
  1038. };
  1039. static struct mfd_cell wm8312_devs[] = {
  1040. {
  1041. .name = "wm831x-backup",
  1042. },
  1043. {
  1044. .name = "wm831x-buckv",
  1045. .id = 1,
  1046. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1047. .resources = wm831x_dcdc1_resources,
  1048. },
  1049. {
  1050. .name = "wm831x-buckv",
  1051. .id = 2,
  1052. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1053. .resources = wm831x_dcdc2_resources,
  1054. },
  1055. {
  1056. .name = "wm831x-buckp",
  1057. .id = 3,
  1058. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1059. .resources = wm831x_dcdc3_resources,
  1060. },
  1061. {
  1062. .name = "wm831x-boostp",
  1063. .id = 4,
  1064. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  1065. .resources = wm831x_dcdc4_resources,
  1066. },
  1067. {
  1068. .name = "wm831x-epe",
  1069. .id = 1,
  1070. },
  1071. {
  1072. .name = "wm831x-epe",
  1073. .id = 2,
  1074. },
  1075. {
  1076. .name = "wm831x-gpio",
  1077. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1078. .resources = wm831x_gpio_resources,
  1079. },
  1080. {
  1081. .name = "wm831x-hwmon",
  1082. },
  1083. {
  1084. .name = "wm831x-isink",
  1085. .id = 1,
  1086. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1087. .resources = wm831x_isink1_resources,
  1088. },
  1089. {
  1090. .name = "wm831x-isink",
  1091. .id = 2,
  1092. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1093. .resources = wm831x_isink2_resources,
  1094. },
  1095. {
  1096. .name = "wm831x-ldo",
  1097. .id = 1,
  1098. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1099. .resources = wm831x_ldo1_resources,
  1100. },
  1101. {
  1102. .name = "wm831x-ldo",
  1103. .id = 2,
  1104. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1105. .resources = wm831x_ldo2_resources,
  1106. },
  1107. {
  1108. .name = "wm831x-ldo",
  1109. .id = 3,
  1110. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1111. .resources = wm831x_ldo3_resources,
  1112. },
  1113. {
  1114. .name = "wm831x-ldo",
  1115. .id = 4,
  1116. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1117. .resources = wm831x_ldo4_resources,
  1118. },
  1119. {
  1120. .name = "wm831x-ldo",
  1121. .id = 5,
  1122. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1123. .resources = wm831x_ldo5_resources,
  1124. },
  1125. {
  1126. .name = "wm831x-ldo",
  1127. .id = 6,
  1128. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1129. .resources = wm831x_ldo6_resources,
  1130. },
  1131. {
  1132. .name = "wm831x-aldo",
  1133. .id = 7,
  1134. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1135. .resources = wm831x_ldo7_resources,
  1136. },
  1137. {
  1138. .name = "wm831x-aldo",
  1139. .id = 8,
  1140. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1141. .resources = wm831x_ldo8_resources,
  1142. },
  1143. {
  1144. .name = "wm831x-aldo",
  1145. .id = 9,
  1146. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1147. .resources = wm831x_ldo9_resources,
  1148. },
  1149. {
  1150. .name = "wm831x-aldo",
  1151. .id = 10,
  1152. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1153. .resources = wm831x_ldo10_resources,
  1154. },
  1155. {
  1156. .name = "wm831x-alive-ldo",
  1157. .id = 11,
  1158. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1159. .resources = wm831x_ldo11_resources,
  1160. },
  1161. {
  1162. .name = "wm831x-on",
  1163. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1164. .resources = wm831x_on_resources,
  1165. },
  1166. {
  1167. .name = "wm831x-power",
  1168. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1169. .resources = wm831x_power_resources,
  1170. },
  1171. {
  1172. .name = "wm831x-rtc",
  1173. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1174. .resources = wm831x_rtc_resources,
  1175. },
  1176. {
  1177. .name = "wm831x-status",
  1178. .id = 1,
  1179. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1180. .resources = wm831x_status1_resources,
  1181. },
  1182. {
  1183. .name = "wm831x-status",
  1184. .id = 2,
  1185. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1186. .resources = wm831x_status2_resources,
  1187. },
  1188. {
  1189. .name = "wm831x-touch",
  1190. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1191. .resources = wm831x_touch_resources,
  1192. },
  1193. {
  1194. .name = "wm831x-watchdog",
  1195. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1196. .resources = wm831x_wdt_resources,
  1197. },
  1198. };
  1199. static struct mfd_cell wm8320_devs[] = {
  1200. {
  1201. .name = "wm831x-backup",
  1202. },
  1203. {
  1204. .name = "wm831x-buckv",
  1205. .id = 1,
  1206. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1207. .resources = wm831x_dcdc1_resources,
  1208. },
  1209. {
  1210. .name = "wm831x-buckv",
  1211. .id = 2,
  1212. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1213. .resources = wm831x_dcdc2_resources,
  1214. },
  1215. {
  1216. .name = "wm831x-buckp",
  1217. .id = 3,
  1218. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1219. .resources = wm831x_dcdc3_resources,
  1220. },
  1221. {
  1222. .name = "wm831x-buckp",
  1223. .id = 4,
  1224. .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
  1225. .resources = wm8320_dcdc4_buck_resources,
  1226. },
  1227. {
  1228. .name = "wm831x-gpio",
  1229. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1230. .resources = wm831x_gpio_resources,
  1231. },
  1232. {
  1233. .name = "wm831x-hwmon",
  1234. },
  1235. {
  1236. .name = "wm831x-ldo",
  1237. .id = 1,
  1238. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1239. .resources = wm831x_ldo1_resources,
  1240. },
  1241. {
  1242. .name = "wm831x-ldo",
  1243. .id = 2,
  1244. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1245. .resources = wm831x_ldo2_resources,
  1246. },
  1247. {
  1248. .name = "wm831x-ldo",
  1249. .id = 3,
  1250. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1251. .resources = wm831x_ldo3_resources,
  1252. },
  1253. {
  1254. .name = "wm831x-ldo",
  1255. .id = 4,
  1256. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1257. .resources = wm831x_ldo4_resources,
  1258. },
  1259. {
  1260. .name = "wm831x-ldo",
  1261. .id = 5,
  1262. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1263. .resources = wm831x_ldo5_resources,
  1264. },
  1265. {
  1266. .name = "wm831x-ldo",
  1267. .id = 6,
  1268. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1269. .resources = wm831x_ldo6_resources,
  1270. },
  1271. {
  1272. .name = "wm831x-aldo",
  1273. .id = 7,
  1274. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1275. .resources = wm831x_ldo7_resources,
  1276. },
  1277. {
  1278. .name = "wm831x-aldo",
  1279. .id = 8,
  1280. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1281. .resources = wm831x_ldo8_resources,
  1282. },
  1283. {
  1284. .name = "wm831x-aldo",
  1285. .id = 9,
  1286. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1287. .resources = wm831x_ldo9_resources,
  1288. },
  1289. {
  1290. .name = "wm831x-aldo",
  1291. .id = 10,
  1292. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1293. .resources = wm831x_ldo10_resources,
  1294. },
  1295. {
  1296. .name = "wm831x-alive-ldo",
  1297. .id = 11,
  1298. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1299. .resources = wm831x_ldo11_resources,
  1300. },
  1301. {
  1302. .name = "wm831x-on",
  1303. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1304. .resources = wm831x_on_resources,
  1305. },
  1306. {
  1307. .name = "wm831x-rtc",
  1308. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1309. .resources = wm831x_rtc_resources,
  1310. },
  1311. {
  1312. .name = "wm831x-status",
  1313. .id = 1,
  1314. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1315. .resources = wm831x_status1_resources,
  1316. },
  1317. {
  1318. .name = "wm831x-status",
  1319. .id = 2,
  1320. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1321. .resources = wm831x_status2_resources,
  1322. },
  1323. {
  1324. .name = "wm831x-watchdog",
  1325. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1326. .resources = wm831x_wdt_resources,
  1327. },
  1328. };
  1329. static struct mfd_cell backlight_devs[] = {
  1330. {
  1331. .name = "wm831x-backlight",
  1332. },
  1333. };
  1334. /*
  1335. * Instantiate the generic non-control parts of the device.
  1336. */
  1337. int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
  1338. {
  1339. struct wm831x_pdata *pdata = wm831x->dev->platform_data;
  1340. int rev;
  1341. enum wm831x_parent parent;
  1342. int ret, i;
  1343. mutex_init(&wm831x->io_lock);
  1344. mutex_init(&wm831x->key_lock);
  1345. mutex_init(&wm831x->auxadc_lock);
  1346. init_completion(&wm831x->auxadc_done);
  1347. dev_set_drvdata(wm831x->dev, wm831x);
  1348. ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
  1349. if (ret < 0) {
  1350. dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
  1351. goto err;
  1352. }
  1353. switch (ret) {
  1354. case 0x6204:
  1355. case 0x6246:
  1356. break;
  1357. default:
  1358. dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
  1359. ret = -EINVAL;
  1360. goto err;
  1361. }
  1362. ret = wm831x_reg_read(wm831x, WM831X_REVISION);
  1363. if (ret < 0) {
  1364. dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
  1365. goto err;
  1366. }
  1367. rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
  1368. ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
  1369. if (ret < 0) {
  1370. dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
  1371. goto err;
  1372. }
  1373. /* Some engineering samples do not have the ID set, rely on
  1374. * the device being registered correctly.
  1375. */
  1376. if (ret == 0) {
  1377. dev_info(wm831x->dev, "Device is an engineering sample\n");
  1378. ret = id;
  1379. }
  1380. switch (ret) {
  1381. case WM8310:
  1382. parent = WM8310;
  1383. wm831x->num_gpio = 16;
  1384. wm831x->charger_irq_wake = 1;
  1385. if (rev > 0) {
  1386. wm831x->has_gpio_ena = 1;
  1387. wm831x->has_cs_sts = 1;
  1388. }
  1389. dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
  1390. break;
  1391. case WM8311:
  1392. parent = WM8311;
  1393. wm831x->num_gpio = 16;
  1394. wm831x->charger_irq_wake = 1;
  1395. if (rev > 0) {
  1396. wm831x->has_gpio_ena = 1;
  1397. wm831x->has_cs_sts = 1;
  1398. }
  1399. dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
  1400. break;
  1401. case WM8312:
  1402. parent = WM8312;
  1403. wm831x->num_gpio = 16;
  1404. wm831x->charger_irq_wake = 1;
  1405. if (rev > 0) {
  1406. wm831x->has_gpio_ena = 1;
  1407. wm831x->has_cs_sts = 1;
  1408. }
  1409. dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
  1410. break;
  1411. case WM8320:
  1412. parent = WM8320;
  1413. wm831x->num_gpio = 12;
  1414. dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
  1415. break;
  1416. case WM8321:
  1417. parent = WM8321;
  1418. wm831x->num_gpio = 12;
  1419. dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
  1420. break;
  1421. case WM8325:
  1422. parent = WM8325;
  1423. wm831x->num_gpio = 12;
  1424. dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
  1425. break;
  1426. case WM8326:
  1427. parent = WM8326;
  1428. wm831x->num_gpio = 12;
  1429. dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev);
  1430. break;
  1431. default:
  1432. dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
  1433. ret = -EINVAL;
  1434. goto err;
  1435. }
  1436. /* This will need revisiting in future but is OK for all
  1437. * current parts.
  1438. */
  1439. if (parent != id)
  1440. dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
  1441. id);
  1442. /* Bootstrap the user key */
  1443. ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
  1444. if (ret < 0) {
  1445. dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
  1446. goto err;
  1447. }
  1448. if (ret != 0) {
  1449. dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
  1450. ret);
  1451. wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  1452. }
  1453. wm831x->locked = 1;
  1454. if (pdata && pdata->pre_init) {
  1455. ret = pdata->pre_init(wm831x);
  1456. if (ret != 0) {
  1457. dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
  1458. goto err;
  1459. }
  1460. }
  1461. if (pdata) {
  1462. for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
  1463. if (!pdata->gpio_defaults[i])
  1464. continue;
  1465. wm831x_reg_write(wm831x,
  1466. WM831X_GPIO1_CONTROL + i,
  1467. pdata->gpio_defaults[i] & 0xffff);
  1468. }
  1469. }
  1470. ret = wm831x_irq_init(wm831x, irq);
  1471. if (ret != 0)
  1472. goto err;
  1473. if (wm831x->irq_base) {
  1474. ret = request_threaded_irq(wm831x->irq_base +
  1475. WM831X_IRQ_AUXADC_DATA,
  1476. NULL, wm831x_auxadc_irq, 0,
  1477. "auxadc", wm831x);
  1478. if (ret < 0)
  1479. dev_err(wm831x->dev, "AUXADC IRQ request failed: %d\n",
  1480. ret);
  1481. }
  1482. /* The core device is up, instantiate the subdevices. */
  1483. switch (parent) {
  1484. case WM8310:
  1485. ret = mfd_add_devices(wm831x->dev, -1,
  1486. wm8310_devs, ARRAY_SIZE(wm8310_devs),
  1487. NULL, wm831x->irq_base);
  1488. break;
  1489. case WM8311:
  1490. ret = mfd_add_devices(wm831x->dev, -1,
  1491. wm8311_devs, ARRAY_SIZE(wm8311_devs),
  1492. NULL, wm831x->irq_base);
  1493. break;
  1494. case WM8312:
  1495. ret = mfd_add_devices(wm831x->dev, -1,
  1496. wm8312_devs, ARRAY_SIZE(wm8312_devs),
  1497. NULL, wm831x->irq_base);
  1498. break;
  1499. case WM8320:
  1500. case WM8321:
  1501. case WM8325:
  1502. case WM8326:
  1503. ret = mfd_add_devices(wm831x->dev, -1,
  1504. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1505. NULL, wm831x->irq_base);
  1506. break;
  1507. default:
  1508. /* If this happens the bus probe function is buggy */
  1509. BUG();
  1510. }
  1511. if (ret != 0) {
  1512. dev_err(wm831x->dev, "Failed to add children\n");
  1513. goto err_irq;
  1514. }
  1515. if (pdata && pdata->backlight) {
  1516. /* Treat errors as non-critical */
  1517. ret = mfd_add_devices(wm831x->dev, -1, backlight_devs,
  1518. ARRAY_SIZE(backlight_devs), NULL,
  1519. wm831x->irq_base);
  1520. if (ret < 0)
  1521. dev_err(wm831x->dev, "Failed to add backlight: %d\n",
  1522. ret);
  1523. }
  1524. wm831x_otp_init(wm831x);
  1525. if (pdata && pdata->post_init) {
  1526. ret = pdata->post_init(wm831x);
  1527. if (ret != 0) {
  1528. dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
  1529. goto err_irq;
  1530. }
  1531. }
  1532. return 0;
  1533. err_irq:
  1534. wm831x_irq_exit(wm831x);
  1535. err:
  1536. mfd_remove_devices(wm831x->dev);
  1537. kfree(wm831x);
  1538. return ret;
  1539. }
  1540. void wm831x_device_exit(struct wm831x *wm831x)
  1541. {
  1542. wm831x_otp_exit(wm831x);
  1543. mfd_remove_devices(wm831x->dev);
  1544. if (wm831x->irq_base)
  1545. free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
  1546. wm831x_irq_exit(wm831x);
  1547. kfree(wm831x);
  1548. }
  1549. int wm831x_device_suspend(struct wm831x *wm831x)
  1550. {
  1551. int reg, mask;
  1552. /* If the charger IRQs are a wake source then make sure we ack
  1553. * them even if they're not actively being used (eg, no power
  1554. * driver or no IRQ line wired up) then acknowledge the
  1555. * interrupts otherwise suspend won't last very long.
  1556. */
  1557. if (wm831x->charger_irq_wake) {
  1558. reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
  1559. mask = WM831X_CHG_BATT_HOT_EINT |
  1560. WM831X_CHG_BATT_COLD_EINT |
  1561. WM831X_CHG_BATT_FAIL_EINT |
  1562. WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
  1563. WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
  1564. WM831X_CHG_START_EINT;
  1565. /* If any of the interrupts are masked read the statuses */
  1566. if (reg & mask)
  1567. reg = wm831x_reg_read(wm831x,
  1568. WM831X_INTERRUPT_STATUS_2);
  1569. if (reg & mask) {
  1570. dev_info(wm831x->dev,
  1571. "Acknowledging masked charger IRQs: %x\n",
  1572. reg & mask);
  1573. wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
  1574. reg & mask);
  1575. }
  1576. }
  1577. return 0;
  1578. }
  1579. MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
  1580. MODULE_LICENSE("GPL");
  1581. MODULE_AUTHOR("Mark Brown");