wm8994-core.c 17 KB

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