wm8994-core.c 16 KB

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