wm8994-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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->spkmode_pu = of_property_read_bool(np, "wlf,spkmode-pu");
  260. pdata->csnaddr_pd = of_property_read_bool(np, "wlf,csnaddr-pd");
  261. pdata->ldo[0].enable = of_get_named_gpio(np, "wlf,ldo1ena", 0);
  262. if (pdata->ldo[0].enable < 0)
  263. pdata->ldo[0].enable = 0;
  264. pdata->ldo[1].enable = of_get_named_gpio(np, "wlf,ldo2ena", 0);
  265. if (pdata->ldo[1].enable < 0)
  266. pdata->ldo[1].enable = 0;
  267. return 0;
  268. }
  269. #else
  270. static int wm8994_set_pdata_from_of(struct wm8994 *wm8994)
  271. {
  272. return 0;
  273. }
  274. #endif
  275. /*
  276. * Instantiate the generic non-control parts of the device.
  277. */
  278. static int wm8994_device_init(struct wm8994 *wm8994, int irq)
  279. {
  280. struct wm8994_pdata *pdata;
  281. struct regmap_config *regmap_config;
  282. const struct reg_sequence *regmap_patch = NULL;
  283. const char *devname;
  284. int ret, i, patch_regs = 0;
  285. int pulls = 0;
  286. if (dev_get_platdata(wm8994->dev)) {
  287. pdata = dev_get_platdata(wm8994->dev);
  288. wm8994->pdata = *pdata;
  289. }
  290. pdata = &wm8994->pdata;
  291. ret = wm8994_set_pdata_from_of(wm8994);
  292. if (ret != 0)
  293. return ret;
  294. dev_set_drvdata(wm8994->dev, wm8994);
  295. /* Add the on-chip regulators first for bootstrapping */
  296. ret = mfd_add_devices(wm8994->dev, 0,
  297. wm8994_regulator_devs,
  298. ARRAY_SIZE(wm8994_regulator_devs),
  299. NULL, 0, NULL);
  300. if (ret != 0) {
  301. dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
  302. goto err;
  303. }
  304. switch (wm8994->type) {
  305. case WM1811:
  306. wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies);
  307. break;
  308. case WM8994:
  309. wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies);
  310. break;
  311. case WM8958:
  312. wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies);
  313. break;
  314. default:
  315. BUG();
  316. goto err;
  317. }
  318. wm8994->supplies = devm_kcalloc(wm8994->dev,
  319. wm8994->num_supplies,
  320. sizeof(struct regulator_bulk_data),
  321. GFP_KERNEL);
  322. if (!wm8994->supplies) {
  323. ret = -ENOMEM;
  324. goto err;
  325. }
  326. switch (wm8994->type) {
  327. case WM1811:
  328. for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++)
  329. wm8994->supplies[i].supply = wm1811_main_supplies[i];
  330. break;
  331. case WM8994:
  332. for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
  333. wm8994->supplies[i].supply = wm8994_main_supplies[i];
  334. break;
  335. case WM8958:
  336. for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++)
  337. wm8994->supplies[i].supply = wm8958_main_supplies[i];
  338. break;
  339. default:
  340. BUG();
  341. goto err;
  342. }
  343. /*
  344. * Can't use devres helper here as some of the supplies are provided by
  345. * wm8994->dev's children (regulators) and those regulators are
  346. * unregistered by the devres core before the supplies are freed.
  347. */
  348. ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
  349. wm8994->supplies);
  350. if (ret != 0) {
  351. dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
  352. goto err;
  353. }
  354. ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies);
  355. if (ret != 0) {
  356. dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret);
  357. goto err_regulator_free;
  358. }
  359. ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET);
  360. if (ret < 0) {
  361. dev_err(wm8994->dev, "Failed to read ID register\n");
  362. goto err_enable;
  363. }
  364. switch (ret) {
  365. case 0x1811:
  366. devname = "WM1811";
  367. if (wm8994->type != WM1811)
  368. dev_warn(wm8994->dev, "Device registered as type %d\n",
  369. wm8994->type);
  370. wm8994->type = WM1811;
  371. break;
  372. case 0x8994:
  373. devname = "WM8994";
  374. if (wm8994->type != WM8994)
  375. dev_warn(wm8994->dev, "Device registered as type %d\n",
  376. wm8994->type);
  377. wm8994->type = WM8994;
  378. break;
  379. case 0x8958:
  380. devname = "WM8958";
  381. if (wm8994->type != WM8958)
  382. dev_warn(wm8994->dev, "Device registered as type %d\n",
  383. wm8994->type);
  384. wm8994->type = WM8958;
  385. break;
  386. default:
  387. dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n",
  388. ret);
  389. ret = -EINVAL;
  390. goto err_enable;
  391. }
  392. ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION);
  393. if (ret < 0) {
  394. dev_err(wm8994->dev, "Failed to read revision register: %d\n",
  395. ret);
  396. goto err_enable;
  397. }
  398. wm8994->revision = ret & WM8994_CHIP_REV_MASK;
  399. wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT;
  400. switch (wm8994->type) {
  401. case WM8994:
  402. switch (wm8994->revision) {
  403. case 0:
  404. case 1:
  405. dev_warn(wm8994->dev,
  406. "revision %c not fully supported\n",
  407. 'A' + wm8994->revision);
  408. break;
  409. case 2:
  410. case 3:
  411. default:
  412. regmap_patch = wm8994_revc_patch;
  413. patch_regs = ARRAY_SIZE(wm8994_revc_patch);
  414. break;
  415. }
  416. break;
  417. case WM8958:
  418. switch (wm8994->revision) {
  419. case 0:
  420. regmap_patch = wm8958_reva_patch;
  421. patch_regs = ARRAY_SIZE(wm8958_reva_patch);
  422. break;
  423. default:
  424. break;
  425. }
  426. break;
  427. case WM1811:
  428. /* Revision C did not change the relevant layer */
  429. if (wm8994->revision > 1)
  430. wm8994->revision++;
  431. regmap_patch = wm1811_reva_patch;
  432. patch_regs = ARRAY_SIZE(wm1811_reva_patch);
  433. break;
  434. default:
  435. break;
  436. }
  437. dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname,
  438. 'A' + wm8994->revision, wm8994->cust_id);
  439. switch (wm8994->type) {
  440. case WM1811:
  441. regmap_config = &wm1811_regmap_config;
  442. break;
  443. case WM8994:
  444. regmap_config = &wm8994_regmap_config;
  445. break;
  446. case WM8958:
  447. regmap_config = &wm8958_regmap_config;
  448. break;
  449. default:
  450. dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type);
  451. ret = -EINVAL;
  452. goto err_enable;
  453. }
  454. ret = regmap_reinit_cache(wm8994->regmap, regmap_config);
  455. if (ret != 0) {
  456. dev_err(wm8994->dev, "Failed to reinit register cache: %d\n",
  457. ret);
  458. goto err_enable;
  459. }
  460. /* Explicitly put the device into reset in case regulators
  461. * don't get disabled in order to ensure we know the device
  462. * state.
  463. */
  464. ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
  465. wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
  466. if (ret != 0) {
  467. dev_err(wm8994->dev, "Failed to reset device: %d\n", ret);
  468. goto err_enable;
  469. }
  470. if (regmap_patch) {
  471. ret = regmap_register_patch(wm8994->regmap, regmap_patch,
  472. patch_regs);
  473. if (ret != 0) {
  474. dev_err(wm8994->dev, "Failed to register patch: %d\n",
  475. ret);
  476. goto err_enable;
  477. }
  478. }
  479. wm8994->irq_base = pdata->irq_base;
  480. wm8994->gpio_base = pdata->gpio_base;
  481. /* GPIO configuration is only applied if it's non-zero */
  482. for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
  483. if (pdata->gpio_defaults[i]) {
  484. wm8994_set_bits(wm8994, WM8994_GPIO_1 + i,
  485. 0xffff, pdata->gpio_defaults[i]);
  486. }
  487. }
  488. wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven;
  489. if (pdata->spkmode_pu)
  490. pulls |= WM8994_SPKMODE_PU;
  491. if (pdata->csnaddr_pd)
  492. pulls |= WM8994_CSNADDR_PD;
  493. /* Disable unneeded pulls */
  494. wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
  495. WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD |
  496. WM8994_SPKMODE_PU | WM8994_CSNADDR_PD,
  497. pulls);
  498. /* In some system designs where the regulators are not in use,
  499. * we can achieve a small reduction in leakage currents by
  500. * floating LDO outputs. This bit makes no difference if the
  501. * LDOs are enabled, it only affects cases where the LDOs were
  502. * in operation and are then disabled.
  503. */
  504. for (i = 0; i < WM8994_NUM_LDO_REGS; i++) {
  505. if (wm8994_ldo_in_use(pdata, i))
  506. wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
  507. WM8994_LDO1_DISCH, WM8994_LDO1_DISCH);
  508. else
  509. wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
  510. WM8994_LDO1_DISCH, 0);
  511. }
  512. wm8994_irq_init(wm8994);
  513. ret = mfd_add_devices(wm8994->dev, -1,
  514. wm8994_devs, ARRAY_SIZE(wm8994_devs),
  515. NULL, 0, NULL);
  516. if (ret != 0) {
  517. dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
  518. goto err_irq;
  519. }
  520. pm_runtime_enable(wm8994->dev);
  521. pm_runtime_idle(wm8994->dev);
  522. return 0;
  523. err_irq:
  524. wm8994_irq_exit(wm8994);
  525. err_enable:
  526. regulator_bulk_disable(wm8994->num_supplies,
  527. wm8994->supplies);
  528. err_regulator_free:
  529. regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
  530. err:
  531. mfd_remove_devices(wm8994->dev);
  532. return ret;
  533. }
  534. static void wm8994_device_exit(struct wm8994 *wm8994)
  535. {
  536. pm_runtime_disable(wm8994->dev);
  537. wm8994_irq_exit(wm8994);
  538. regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies);
  539. regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
  540. mfd_remove_devices(wm8994->dev);
  541. }
  542. static const struct of_device_id wm8994_of_match[] = {
  543. { .compatible = "wlf,wm1811", .data = (void *)WM1811 },
  544. { .compatible = "wlf,wm8994", .data = (void *)WM8994 },
  545. { .compatible = "wlf,wm8958", .data = (void *)WM8958 },
  546. { }
  547. };
  548. MODULE_DEVICE_TABLE(of, wm8994_of_match);
  549. static int wm8994_i2c_probe(struct i2c_client *i2c,
  550. const struct i2c_device_id *id)
  551. {
  552. const struct of_device_id *of_id;
  553. struct wm8994 *wm8994;
  554. int ret;
  555. wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL);
  556. if (wm8994 == NULL)
  557. return -ENOMEM;
  558. i2c_set_clientdata(i2c, wm8994);
  559. wm8994->dev = &i2c->dev;
  560. wm8994->irq = i2c->irq;
  561. if (i2c->dev.of_node) {
  562. of_id = of_match_device(wm8994_of_match, &i2c->dev);
  563. if (of_id)
  564. wm8994->type = (enum wm8994_type)of_id->data;
  565. } else {
  566. wm8994->type = id->driver_data;
  567. }
  568. wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config);
  569. if (IS_ERR(wm8994->regmap)) {
  570. ret = PTR_ERR(wm8994->regmap);
  571. dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
  572. ret);
  573. return ret;
  574. }
  575. return wm8994_device_init(wm8994, i2c->irq);
  576. }
  577. static int wm8994_i2c_remove(struct i2c_client *i2c)
  578. {
  579. struct wm8994 *wm8994 = i2c_get_clientdata(i2c);
  580. wm8994_device_exit(wm8994);
  581. return 0;
  582. }
  583. static const struct i2c_device_id wm8994_i2c_id[] = {
  584. { "wm1811", WM1811 },
  585. { "wm1811a", WM1811 },
  586. { "wm8994", WM8994 },
  587. { "wm8958", WM8958 },
  588. { }
  589. };
  590. MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id);
  591. static const struct dev_pm_ops wm8994_pm_ops = {
  592. SET_RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL)
  593. };
  594. static struct i2c_driver wm8994_i2c_driver = {
  595. .driver = {
  596. .name = "wm8994",
  597. .pm = &wm8994_pm_ops,
  598. .of_match_table = of_match_ptr(wm8994_of_match),
  599. },
  600. .probe = wm8994_i2c_probe,
  601. .remove = wm8994_i2c_remove,
  602. .id_table = wm8994_i2c_id,
  603. };
  604. module_i2c_driver(wm8994_i2c_driver);
  605. MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC");
  606. MODULE_LICENSE("GPL");
  607. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");