wm831x-core.c 35 KB

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