wm8994-core.c 16 KB

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