wm831x-core.c 35 KB

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