wm831x-core.c 38 KB

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