wm8994-core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. * wm8994-core.c -- Device access for Wolfson WM8994
  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/slab.h>
  17. #include <linux/i2c.h>
  18. #include <linux/err.h>
  19. #include <linux/delay.h>
  20. #include <linux/mfd/core.h>
  21. #include <linux/pm_runtime.h>
  22. #include <linux/regmap.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/regulator/machine.h>
  25. #include <linux/mfd/wm8994/core.h>
  26. #include <linux/mfd/wm8994/pdata.h>
  27. #include <linux/mfd/wm8994/registers.h>
  28. #include "wm8994.h"
  29. /**
  30. * wm8994_reg_read: Read a single WM8994 register.
  31. *
  32. * @wm8994: Device to read from.
  33. * @reg: Register to read.
  34. */
  35. int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg)
  36. {
  37. unsigned int val;
  38. int ret;
  39. ret = regmap_read(wm8994->regmap, reg, &val);
  40. if (ret < 0)
  41. return ret;
  42. else
  43. return val;
  44. }
  45. EXPORT_SYMBOL_GPL(wm8994_reg_read);
  46. /**
  47. * wm8994_bulk_read: Read multiple WM8994 registers
  48. *
  49. * @wm8994: Device to read from
  50. * @reg: First register
  51. * @count: Number of registers
  52. * @buf: Buffer to fill. The data will be returned big endian.
  53. */
  54. int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
  55. int count, u16 *buf)
  56. {
  57. return regmap_bulk_read(wm8994->regmap, reg, buf, count);
  58. }
  59. /**
  60. * wm8994_reg_write: Write a single WM8994 register.
  61. *
  62. * @wm8994: Device to write to.
  63. * @reg: Register to write to.
  64. * @val: Value to write.
  65. */
  66. int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
  67. unsigned short val)
  68. {
  69. return regmap_write(wm8994->regmap, reg, val);
  70. }
  71. EXPORT_SYMBOL_GPL(wm8994_reg_write);
  72. /**
  73. * wm8994_bulk_write: Write multiple WM8994 registers
  74. *
  75. * @wm8994: Device to write to
  76. * @reg: First register
  77. * @count: Number of registers
  78. * @buf: Buffer to write from. Data must be big-endian formatted.
  79. */
  80. int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
  81. int count, const u16 *buf)
  82. {
  83. return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16));
  84. }
  85. EXPORT_SYMBOL_GPL(wm8994_bulk_write);
  86. /**
  87. * wm8994_set_bits: Set the value of a bitfield in a WM8994 register
  88. *
  89. * @wm8994: Device to write to.
  90. * @reg: Register to write to.
  91. * @mask: Mask of bits to set.
  92. * @val: Value to set (unshifted)
  93. */
  94. int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
  95. unsigned short mask, unsigned short val)
  96. {
  97. return regmap_update_bits(wm8994->regmap, reg, mask, val);
  98. }
  99. EXPORT_SYMBOL_GPL(wm8994_set_bits);
  100. static struct mfd_cell wm8994_regulator_devs[] = {
  101. {
  102. .name = "wm8994-ldo",
  103. .id = 1,
  104. .pm_runtime_no_callbacks = true,
  105. },
  106. {
  107. .name = "wm8994-ldo",
  108. .id = 2,
  109. .pm_runtime_no_callbacks = true,
  110. },
  111. };
  112. static struct resource wm8994_codec_resources[] = {
  113. {
  114. .start = WM8994_IRQ_TEMP_SHUT,
  115. .end = WM8994_IRQ_TEMP_WARN,
  116. .flags = IORESOURCE_IRQ,
  117. },
  118. };
  119. static struct resource wm8994_gpio_resources[] = {
  120. {
  121. .start = WM8994_IRQ_GPIO(1),
  122. .end = WM8994_IRQ_GPIO(11),
  123. .flags = IORESOURCE_IRQ,
  124. },
  125. };
  126. static struct mfd_cell wm8994_devs[] = {
  127. {
  128. .name = "wm8994-codec",
  129. .num_resources = ARRAY_SIZE(wm8994_codec_resources),
  130. .resources = wm8994_codec_resources,
  131. },
  132. {
  133. .name = "wm8994-gpio",
  134. .num_resources = ARRAY_SIZE(wm8994_gpio_resources),
  135. .resources = wm8994_gpio_resources,
  136. .pm_runtime_no_callbacks = true,
  137. },
  138. };
  139. /*
  140. * Supplies for the main bulk of CODEC; the LDO supplies are ignored
  141. * and should be handled via the standard regulator API supply
  142. * management.
  143. */
  144. static const char *wm1811_main_supplies[] = {
  145. "DBVDD1",
  146. "DBVDD2",
  147. "DBVDD3",
  148. "DCVDD",
  149. "AVDD1",
  150. "AVDD2",
  151. "CPVDD",
  152. "SPKVDD1",
  153. "SPKVDD2",
  154. };
  155. static const char *wm8994_main_supplies[] = {
  156. "DBVDD",
  157. "DCVDD",
  158. "AVDD1",
  159. "AVDD2",
  160. "CPVDD",
  161. "SPKVDD1",
  162. "SPKVDD2",
  163. };
  164. static const char *wm8958_main_supplies[] = {
  165. "DBVDD1",
  166. "DBVDD2",
  167. "DBVDD3",
  168. "DCVDD",
  169. "AVDD1",
  170. "AVDD2",
  171. "CPVDD",
  172. "SPKVDD1",
  173. "SPKVDD2",
  174. };
  175. #ifdef CONFIG_PM
  176. static int wm8994_suspend(struct device *dev)
  177. {
  178. struct wm8994 *wm8994 = dev_get_drvdata(dev);
  179. int ret;
  180. /* Don't actually go through with the suspend if the CODEC is
  181. * still active (eg, for audio passthrough from CP. */
  182. ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1);
  183. if (ret < 0) {
  184. dev_err(dev, "Failed to read power status: %d\n", ret);
  185. } else if (ret & WM8994_VMID_SEL_MASK) {
  186. dev_dbg(dev, "CODEC still active, ignoring suspend\n");
  187. return 0;
  188. }
  189. ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_4);
  190. if (ret < 0) {
  191. dev_err(dev, "Failed to read power status: %d\n", ret);
  192. } else if (ret & (WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA |
  193. WM8994_AIF1ADC2L_ENA | WM8994_AIF1ADC2R_ENA |
  194. WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC1R_ENA)) {
  195. dev_dbg(dev, "CODEC still active, ignoring suspend\n");
  196. return 0;
  197. }
  198. ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_5);
  199. if (ret < 0) {
  200. dev_err(dev, "Failed to read power status: %d\n", ret);
  201. } else if (ret & (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA |
  202. WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA |
  203. WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA)) {
  204. dev_dbg(dev, "CODEC still active, ignoring suspend\n");
  205. return 0;
  206. }
  207. switch (wm8994->type) {
  208. case WM8958:
  209. case WM1811:
  210. ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1);
  211. if (ret < 0) {
  212. dev_err(dev, "Failed to read power status: %d\n", ret);
  213. } else if (ret & WM8958_MICD_ENA) {
  214. dev_dbg(dev, "CODEC still active, ignoring suspend\n");
  215. return 0;
  216. }
  217. break;
  218. default:
  219. break;
  220. }
  221. switch (wm8994->type) {
  222. case WM1811:
  223. ret = wm8994_reg_read(wm8994, WM8994_ANTIPOP_2);
  224. if (ret < 0) {
  225. dev_err(dev, "Failed to read jackdet: %d\n", ret);
  226. } else if (ret & WM1811_JACKDET_MODE_MASK) {
  227. dev_dbg(dev, "CODEC still active, ignoring suspend\n");
  228. return 0;
  229. }
  230. break;
  231. default:
  232. break;
  233. }
  234. switch (wm8994->type) {
  235. case WM1811:
  236. ret = wm8994_reg_read(wm8994, WM8994_ANTIPOP_2);
  237. if (ret < 0) {
  238. dev_err(dev, "Failed to read jackdet: %d\n", ret);
  239. } else if (ret & WM1811_JACKDET_MODE_MASK) {
  240. dev_dbg(dev, "CODEC still active, ignoring suspend\n");
  241. return 0;
  242. }
  243. break;
  244. default:
  245. break;
  246. }
  247. /* Disable LDO pulldowns while the device is suspended if we
  248. * don't know that something will be driving them. */
  249. if (!wm8994->ldo_ena_always_driven)
  250. wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
  251. WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
  252. WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD);
  253. /* Explicitly put the device into reset in case regulators
  254. * don't get disabled in order to ensure consistent restart.
  255. */
  256. wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
  257. wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
  258. regcache_mark_dirty(wm8994->regmap);
  259. /* Restore GPIO registers to prevent problems with mismatched
  260. * pin configurations.
  261. */
  262. ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1,
  263. WM8994_GPIO_11);
  264. if (ret != 0)
  265. dev_err(dev, "Failed to restore GPIO registers: %d\n", ret);
  266. /* In case one of the GPIOs is used as a wake input. */
  267. ret = regcache_sync_region(wm8994->regmap,
  268. WM8994_INTERRUPT_STATUS_1_MASK,
  269. WM8994_INTERRUPT_STATUS_1_MASK);
  270. if (ret != 0)
  271. dev_err(dev, "Failed to restore interrupt mask: %d\n", ret);
  272. regcache_cache_only(wm8994->regmap, true);
  273. wm8994->suspended = true;
  274. ret = regulator_bulk_disable(wm8994->num_supplies,
  275. wm8994->supplies);
  276. if (ret != 0) {
  277. dev_err(dev, "Failed to disable supplies: %d\n", ret);
  278. return ret;
  279. }
  280. return 0;
  281. }
  282. static int wm8994_resume(struct device *dev)
  283. {
  284. struct wm8994 *wm8994 = dev_get_drvdata(dev);
  285. int ret;
  286. /* We may have lied to the PM core about suspending */
  287. if (!wm8994->suspended)
  288. return 0;
  289. ret = regulator_bulk_enable(wm8994->num_supplies,
  290. wm8994->supplies);
  291. if (ret != 0) {
  292. dev_err(dev, "Failed to enable supplies: %d\n", ret);
  293. return ret;
  294. }
  295. regcache_cache_only(wm8994->regmap, false);
  296. ret = regcache_sync(wm8994->regmap);
  297. if (ret != 0) {
  298. dev_err(dev, "Failed to restore register map: %d\n", ret);
  299. goto err_enable;
  300. }
  301. /* Disable LDO pulldowns while the device is active */
  302. wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
  303. WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
  304. 0);
  305. wm8994->suspended = false;
  306. return 0;
  307. err_enable:
  308. regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies);
  309. return ret;
  310. }
  311. #endif
  312. #ifdef CONFIG_REGULATOR
  313. static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
  314. {
  315. struct wm8994_ldo_pdata *ldo_pdata;
  316. if (!pdata)
  317. return 0;
  318. ldo_pdata = &pdata->ldo[ldo];
  319. if (!ldo_pdata->init_data)
  320. return 0;
  321. return ldo_pdata->init_data->num_consumer_supplies != 0;
  322. }
  323. #else
  324. static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
  325. {
  326. return 0;
  327. }
  328. #endif
  329. static const __devinitdata struct reg_default wm8994_revc_patch[] = {
  330. { 0x102, 0x3 },
  331. { 0x56, 0x3 },
  332. { 0x817, 0x0 },
  333. { 0x102, 0x0 },
  334. };
  335. static const __devinitdata struct reg_default wm8958_reva_patch[] = {
  336. { 0x102, 0x3 },
  337. { 0xcb, 0x81 },
  338. { 0x817, 0x0 },
  339. { 0x102, 0x0 },
  340. };
  341. static const __devinitdata struct reg_default wm1811_reva_patch[] = {
  342. { 0x102, 0x3 },
  343. { 0x56, 0x7 },
  344. { 0x5d, 0x7e },
  345. { 0x5e, 0x0 },
  346. { 0x102, 0x0 },
  347. };
  348. /*
  349. * Instantiate the generic non-control parts of the device.
  350. */
  351. static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq)
  352. {
  353. struct wm8994_pdata *pdata = wm8994->dev->platform_data;
  354. struct regmap_config *regmap_config;
  355. const struct reg_default *regmap_patch = NULL;
  356. const char *devname;
  357. int ret, i, patch_regs;
  358. int pulls = 0;
  359. dev_set_drvdata(wm8994->dev, wm8994);
  360. /* Add the on-chip regulators first for bootstrapping */
  361. ret = mfd_add_devices(wm8994->dev, -1,
  362. wm8994_regulator_devs,
  363. ARRAY_SIZE(wm8994_regulator_devs),
  364. NULL, 0);
  365. if (ret != 0) {
  366. dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
  367. goto err;
  368. }
  369. switch (wm8994->type) {
  370. case WM1811:
  371. wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies);
  372. break;
  373. case WM8994:
  374. wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies);
  375. break;
  376. case WM8958:
  377. wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies);
  378. break;
  379. default:
  380. BUG();
  381. goto err;
  382. }
  383. wm8994->supplies = devm_kzalloc(wm8994->dev,
  384. sizeof(struct regulator_bulk_data) *
  385. wm8994->num_supplies, GFP_KERNEL);
  386. if (!wm8994->supplies) {
  387. ret = -ENOMEM;
  388. goto err;
  389. }
  390. switch (wm8994->type) {
  391. case WM1811:
  392. for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++)
  393. wm8994->supplies[i].supply = wm1811_main_supplies[i];
  394. break;
  395. case WM8994:
  396. for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
  397. wm8994->supplies[i].supply = wm8994_main_supplies[i];
  398. break;
  399. case WM8958:
  400. for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++)
  401. wm8994->supplies[i].supply = wm8958_main_supplies[i];
  402. break;
  403. default:
  404. BUG();
  405. goto err;
  406. }
  407. ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
  408. wm8994->supplies);
  409. if (ret != 0) {
  410. dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
  411. goto err;
  412. }
  413. ret = regulator_bulk_enable(wm8994->num_supplies,
  414. wm8994->supplies);
  415. if (ret != 0) {
  416. dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret);
  417. goto err_get;
  418. }
  419. ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET);
  420. if (ret < 0) {
  421. dev_err(wm8994->dev, "Failed to read ID register\n");
  422. goto err_enable;
  423. }
  424. switch (ret) {
  425. case 0x1811:
  426. devname = "WM1811";
  427. if (wm8994->type != WM1811)
  428. dev_warn(wm8994->dev, "Device registered as type %d\n",
  429. wm8994->type);
  430. wm8994->type = WM1811;
  431. break;
  432. case 0x8994:
  433. devname = "WM8994";
  434. if (wm8994->type != WM8994)
  435. dev_warn(wm8994->dev, "Device registered as type %d\n",
  436. wm8994->type);
  437. wm8994->type = WM8994;
  438. break;
  439. case 0x8958:
  440. devname = "WM8958";
  441. if (wm8994->type != WM8958)
  442. dev_warn(wm8994->dev, "Device registered as type %d\n",
  443. wm8994->type);
  444. wm8994->type = WM8958;
  445. break;
  446. default:
  447. dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n",
  448. ret);
  449. ret = -EINVAL;
  450. goto err_enable;
  451. }
  452. ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION);
  453. if (ret < 0) {
  454. dev_err(wm8994->dev, "Failed to read revision register: %d\n",
  455. ret);
  456. goto err_enable;
  457. }
  458. wm8994->revision = ret & WM8994_CHIP_REV_MASK;
  459. wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT;
  460. switch (wm8994->type) {
  461. case WM8994:
  462. switch (wm8994->revision) {
  463. case 0:
  464. case 1:
  465. dev_warn(wm8994->dev,
  466. "revision %c not fully supported\n",
  467. 'A' + wm8994->revision);
  468. break;
  469. case 2:
  470. case 3:
  471. regmap_patch = wm8994_revc_patch;
  472. patch_regs = ARRAY_SIZE(wm8994_revc_patch);
  473. break;
  474. default:
  475. break;
  476. }
  477. break;
  478. case WM8958:
  479. switch (wm8994->revision) {
  480. case 0:
  481. regmap_patch = wm8958_reva_patch;
  482. patch_regs = ARRAY_SIZE(wm8958_reva_patch);
  483. break;
  484. default:
  485. break;
  486. }
  487. break;
  488. case WM1811:
  489. /* Revision C did not change the relevant layer */
  490. if (wm8994->revision > 1)
  491. wm8994->revision++;
  492. switch (wm8994->revision) {
  493. case 0:
  494. case 1:
  495. case 2:
  496. case 3:
  497. regmap_patch = wm1811_reva_patch;
  498. patch_regs = ARRAY_SIZE(wm1811_reva_patch);
  499. break;
  500. default:
  501. break;
  502. }
  503. break;
  504. default:
  505. break;
  506. }
  507. dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname,
  508. 'A' + wm8994->revision, wm8994->cust_id);
  509. switch (wm8994->type) {
  510. case WM1811:
  511. regmap_config = &wm1811_regmap_config;
  512. break;
  513. case WM8994:
  514. regmap_config = &wm8994_regmap_config;
  515. break;
  516. case WM8958:
  517. regmap_config = &wm8958_regmap_config;
  518. break;
  519. default:
  520. dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type);
  521. return -EINVAL;
  522. }
  523. ret = regmap_reinit_cache(wm8994->regmap, regmap_config);
  524. if (ret != 0) {
  525. dev_err(wm8994->dev, "Failed to reinit register cache: %d\n",
  526. ret);
  527. return ret;
  528. }
  529. if (regmap_patch) {
  530. ret = regmap_register_patch(wm8994->regmap, regmap_patch,
  531. patch_regs);
  532. if (ret != 0) {
  533. dev_err(wm8994->dev, "Failed to register patch: %d\n",
  534. ret);
  535. goto err;
  536. }
  537. }
  538. if (pdata) {
  539. wm8994->irq_base = pdata->irq_base;
  540. wm8994->gpio_base = pdata->gpio_base;
  541. /* GPIO configuration is only applied if it's non-zero */
  542. for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
  543. if (pdata->gpio_defaults[i]) {
  544. wm8994_set_bits(wm8994, WM8994_GPIO_1 + i,
  545. 0xffff,
  546. pdata->gpio_defaults[i]);
  547. }
  548. }
  549. wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven;
  550. if (pdata->spkmode_pu)
  551. pulls |= WM8994_SPKMODE_PU;
  552. }
  553. /* Disable unneeded pulls */
  554. wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
  555. WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD |
  556. WM8994_SPKMODE_PU | WM8994_CSNADDR_PD,
  557. pulls);
  558. /* In some system designs where the regulators are not in use,
  559. * we can achieve a small reduction in leakage currents by
  560. * floating LDO outputs. This bit makes no difference if the
  561. * LDOs are enabled, it only affects cases where the LDOs were
  562. * in operation and are then disabled.
  563. */
  564. for (i = 0; i < WM8994_NUM_LDO_REGS; i++) {
  565. if (wm8994_ldo_in_use(pdata, i))
  566. wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
  567. WM8994_LDO1_DISCH, WM8994_LDO1_DISCH);
  568. else
  569. wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
  570. WM8994_LDO1_DISCH, 0);
  571. }
  572. wm8994_irq_init(wm8994);
  573. ret = mfd_add_devices(wm8994->dev, -1,
  574. wm8994_devs, ARRAY_SIZE(wm8994_devs),
  575. NULL, 0);
  576. if (ret != 0) {
  577. dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
  578. goto err_irq;
  579. }
  580. pm_runtime_enable(wm8994->dev);
  581. pm_runtime_idle(wm8994->dev);
  582. return 0;
  583. err_irq:
  584. wm8994_irq_exit(wm8994);
  585. err_enable:
  586. regulator_bulk_disable(wm8994->num_supplies,
  587. wm8994->supplies);
  588. err_get:
  589. regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
  590. err:
  591. mfd_remove_devices(wm8994->dev);
  592. return ret;
  593. }
  594. static __devexit void wm8994_device_exit(struct wm8994 *wm8994)
  595. {
  596. pm_runtime_disable(wm8994->dev);
  597. mfd_remove_devices(wm8994->dev);
  598. wm8994_irq_exit(wm8994);
  599. regulator_bulk_disable(wm8994->num_supplies,
  600. wm8994->supplies);
  601. regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
  602. }
  603. static const struct of_device_id wm8994_of_match[] = {
  604. { .compatible = "wlf,wm1811", },
  605. { .compatible = "wlf,wm8994", },
  606. { .compatible = "wlf,wm8958", },
  607. { }
  608. };
  609. MODULE_DEVICE_TABLE(of, wm8994_of_match);
  610. static __devinit int wm8994_i2c_probe(struct i2c_client *i2c,
  611. const struct i2c_device_id *id)
  612. {
  613. struct wm8994 *wm8994;
  614. int ret;
  615. wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL);
  616. if (wm8994 == NULL)
  617. return -ENOMEM;
  618. i2c_set_clientdata(i2c, wm8994);
  619. wm8994->dev = &i2c->dev;
  620. wm8994->irq = i2c->irq;
  621. wm8994->type = id->driver_data;
  622. wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config);
  623. if (IS_ERR(wm8994->regmap)) {
  624. ret = PTR_ERR(wm8994->regmap);
  625. dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
  626. ret);
  627. return ret;
  628. }
  629. return wm8994_device_init(wm8994, i2c->irq);
  630. }
  631. static __devexit int wm8994_i2c_remove(struct i2c_client *i2c)
  632. {
  633. struct wm8994 *wm8994 = i2c_get_clientdata(i2c);
  634. wm8994_device_exit(wm8994);
  635. return 0;
  636. }
  637. static const struct i2c_device_id wm8994_i2c_id[] = {
  638. { "wm1811", WM1811 },
  639. { "wm1811a", WM1811 },
  640. { "wm8994", WM8994 },
  641. { "wm8958", WM8958 },
  642. { }
  643. };
  644. MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id);
  645. static UNIVERSAL_DEV_PM_OPS(wm8994_pm_ops, wm8994_suspend, wm8994_resume,
  646. NULL);
  647. static struct i2c_driver wm8994_i2c_driver = {
  648. .driver = {
  649. .name = "wm8994",
  650. .owner = THIS_MODULE,
  651. .pm = &wm8994_pm_ops,
  652. .of_match_table = wm8994_of_match,
  653. },
  654. .probe = wm8994_i2c_probe,
  655. .remove = __devexit_p(wm8994_i2c_remove),
  656. .id_table = wm8994_i2c_id,
  657. };
  658. module_i2c_driver(wm8994_i2c_driver);
  659. MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC");
  660. MODULE_LICENSE("GPL");
  661. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");