wm8523.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * wm8523.c -- WM8523 ALSA SoC Audio driver
  3. *
  4. * Copyright 2009 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/i2c.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/regulator/consumer.h>
  21. #include <linux/slab.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/soc.h>
  26. #include <sound/soc-dapm.h>
  27. #include <sound/initval.h>
  28. #include <sound/tlv.h>
  29. #include "wm8523.h"
  30. static struct snd_soc_codec *wm8523_codec;
  31. struct snd_soc_codec_device soc_codec_dev_wm8523;
  32. #define WM8523_NUM_SUPPLIES 2
  33. static const char *wm8523_supply_names[WM8523_NUM_SUPPLIES] = {
  34. "AVDD",
  35. "LINEVDD",
  36. };
  37. #define WM8523_NUM_RATES 7
  38. /* codec private data */
  39. struct wm8523_priv {
  40. struct snd_soc_codec codec;
  41. u16 reg_cache[WM8523_REGISTER_COUNT];
  42. struct regulator_bulk_data supplies[WM8523_NUM_SUPPLIES];
  43. unsigned int sysclk;
  44. unsigned int rate_constraint_list[WM8523_NUM_RATES];
  45. struct snd_pcm_hw_constraint_list rate_constraint;
  46. };
  47. static const u16 wm8523_reg[WM8523_REGISTER_COUNT] = {
  48. 0x8523, /* R0 - DEVICE_ID */
  49. 0x0001, /* R1 - REVISION */
  50. 0x0000, /* R2 - PSCTRL1 */
  51. 0x1812, /* R3 - AIF_CTRL1 */
  52. 0x0000, /* R4 - AIF_CTRL2 */
  53. 0x0001, /* R5 - DAC_CTRL3 */
  54. 0x0190, /* R6 - DAC_GAINL */
  55. 0x0190, /* R7 - DAC_GAINR */
  56. 0x0000, /* R8 - ZERO_DETECT */
  57. };
  58. static int wm8523_volatile_register(unsigned int reg)
  59. {
  60. switch (reg) {
  61. case WM8523_DEVICE_ID:
  62. case WM8523_REVISION:
  63. return 1;
  64. default:
  65. return 0;
  66. }
  67. }
  68. static int wm8523_reset(struct snd_soc_codec *codec)
  69. {
  70. return snd_soc_write(codec, WM8523_DEVICE_ID, 0);
  71. }
  72. static const DECLARE_TLV_DB_SCALE(dac_tlv, -10000, 25, 0);
  73. static const char *wm8523_zd_count_text[] = {
  74. "1024",
  75. "2048",
  76. };
  77. static const struct soc_enum wm8523_zc_count =
  78. SOC_ENUM_SINGLE(WM8523_ZERO_DETECT, 0, 2, wm8523_zd_count_text);
  79. static const struct snd_kcontrol_new wm8523_snd_controls[] = {
  80. SOC_DOUBLE_R_TLV("Playback Volume", WM8523_DAC_GAINL, WM8523_DAC_GAINR,
  81. 0, 448, 0, dac_tlv),
  82. SOC_SINGLE("ZC Switch", WM8523_DAC_CTRL3, 4, 1, 0),
  83. SOC_SINGLE("Playback Deemphasis Switch", WM8523_AIF_CTRL1, 8, 1, 0),
  84. SOC_DOUBLE("Playback Switch", WM8523_DAC_CTRL3, 2, 3, 1, 1),
  85. SOC_SINGLE("Volume Ramp Up Switch", WM8523_DAC_CTRL3, 1, 1, 0),
  86. SOC_SINGLE("Volume Ramp Down Switch", WM8523_DAC_CTRL3, 0, 1, 0),
  87. SOC_ENUM("Zero Detect Count", wm8523_zc_count),
  88. };
  89. static const struct snd_soc_dapm_widget wm8523_dapm_widgets[] = {
  90. SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
  91. SND_SOC_DAPM_OUTPUT("LINEVOUTL"),
  92. SND_SOC_DAPM_OUTPUT("LINEVOUTR"),
  93. };
  94. static const struct snd_soc_dapm_route intercon[] = {
  95. { "LINEVOUTL", NULL, "DAC" },
  96. { "LINEVOUTR", NULL, "DAC" },
  97. };
  98. static int wm8523_add_widgets(struct snd_soc_codec *codec)
  99. {
  100. snd_soc_dapm_new_controls(codec, wm8523_dapm_widgets,
  101. ARRAY_SIZE(wm8523_dapm_widgets));
  102. snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
  103. return 0;
  104. }
  105. static struct {
  106. int value;
  107. int ratio;
  108. } lrclk_ratios[WM8523_NUM_RATES] = {
  109. { 1, 128 },
  110. { 2, 192 },
  111. { 3, 256 },
  112. { 4, 384 },
  113. { 5, 512 },
  114. { 6, 768 },
  115. { 7, 1152 },
  116. };
  117. static int wm8523_startup(struct snd_pcm_substream *substream,
  118. struct snd_soc_dai *dai)
  119. {
  120. struct snd_soc_codec *codec = dai->codec;
  121. struct wm8523_priv *wm8523 = codec->private_data;
  122. /* The set of sample rates that can be supported depends on the
  123. * MCLK supplied to the CODEC - enforce this.
  124. */
  125. if (!wm8523->sysclk) {
  126. dev_err(codec->dev,
  127. "No MCLK configured, call set_sysclk() on init\n");
  128. return -EINVAL;
  129. }
  130. return 0;
  131. snd_pcm_hw_constraint_list(substream->runtime, 0,
  132. SNDRV_PCM_HW_PARAM_RATE,
  133. &wm8523->rate_constraint);
  134. return 0;
  135. }
  136. static int wm8523_hw_params(struct snd_pcm_substream *substream,
  137. struct snd_pcm_hw_params *params,
  138. struct snd_soc_dai *dai)
  139. {
  140. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  141. struct snd_soc_device *socdev = rtd->socdev;
  142. struct snd_soc_codec *codec = socdev->card->codec;
  143. struct wm8523_priv *wm8523 = codec->private_data;
  144. int i;
  145. u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
  146. u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2);
  147. /* Find a supported LRCLK ratio */
  148. for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
  149. if (wm8523->sysclk / params_rate(params) ==
  150. lrclk_ratios[i].ratio)
  151. break;
  152. }
  153. /* Should never happen, should be handled by constraints */
  154. if (i == ARRAY_SIZE(lrclk_ratios)) {
  155. dev_err(codec->dev, "MCLK/fs ratio %d unsupported\n",
  156. wm8523->sysclk / params_rate(params));
  157. return -EINVAL;
  158. }
  159. aifctrl2 &= ~WM8523_SR_MASK;
  160. aifctrl2 |= lrclk_ratios[i].value;
  161. aifctrl1 &= ~WM8523_WL_MASK;
  162. switch (params_format(params)) {
  163. case SNDRV_PCM_FORMAT_S16_LE:
  164. break;
  165. case SNDRV_PCM_FORMAT_S20_3LE:
  166. aifctrl1 |= 0x8;
  167. break;
  168. case SNDRV_PCM_FORMAT_S24_LE:
  169. aifctrl1 |= 0x10;
  170. break;
  171. case SNDRV_PCM_FORMAT_S32_LE:
  172. aifctrl1 |= 0x18;
  173. break;
  174. }
  175. snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
  176. snd_soc_write(codec, WM8523_AIF_CTRL2, aifctrl2);
  177. return 0;
  178. }
  179. static int wm8523_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  180. int clk_id, unsigned int freq, int dir)
  181. {
  182. struct snd_soc_codec *codec = codec_dai->codec;
  183. struct wm8523_priv *wm8523 = codec->private_data;
  184. unsigned int val;
  185. int i;
  186. wm8523->sysclk = freq;
  187. wm8523->rate_constraint.count = 0;
  188. for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
  189. val = freq / lrclk_ratios[i].ratio;
  190. /* Check that it's a standard rate since core can't
  191. * cope with others and having the odd rates confuses
  192. * constraint matching.
  193. */
  194. switch (val) {
  195. case 8000:
  196. case 11025:
  197. case 16000:
  198. case 22050:
  199. case 32000:
  200. case 44100:
  201. case 48000:
  202. case 64000:
  203. case 88200:
  204. case 96000:
  205. case 176400:
  206. case 192000:
  207. dev_dbg(codec->dev, "Supported sample rate: %dHz\n",
  208. val);
  209. wm8523->rate_constraint_list[i] = val;
  210. wm8523->rate_constraint.count++;
  211. break;
  212. default:
  213. dev_dbg(codec->dev, "Skipping sample rate: %dHz\n",
  214. val);
  215. }
  216. }
  217. /* Need at least one supported rate... */
  218. if (wm8523->rate_constraint.count == 0)
  219. return -EINVAL;
  220. return 0;
  221. }
  222. static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai,
  223. unsigned int fmt)
  224. {
  225. struct snd_soc_codec *codec = codec_dai->codec;
  226. u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
  227. aifctrl1 &= ~(WM8523_BCLK_INV_MASK | WM8523_LRCLK_INV_MASK |
  228. WM8523_FMT_MASK | WM8523_AIF_MSTR_MASK);
  229. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  230. case SND_SOC_DAIFMT_CBM_CFM:
  231. aifctrl1 |= WM8523_AIF_MSTR;
  232. break;
  233. case SND_SOC_DAIFMT_CBS_CFS:
  234. break;
  235. default:
  236. return -EINVAL;
  237. }
  238. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  239. case SND_SOC_DAIFMT_I2S:
  240. aifctrl1 |= 0x0002;
  241. break;
  242. case SND_SOC_DAIFMT_RIGHT_J:
  243. break;
  244. case SND_SOC_DAIFMT_LEFT_J:
  245. aifctrl1 |= 0x0001;
  246. break;
  247. case SND_SOC_DAIFMT_DSP_A:
  248. aifctrl1 |= 0x0003;
  249. break;
  250. case SND_SOC_DAIFMT_DSP_B:
  251. aifctrl1 |= 0x0023;
  252. break;
  253. default:
  254. return -EINVAL;
  255. }
  256. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  257. case SND_SOC_DAIFMT_NB_NF:
  258. break;
  259. case SND_SOC_DAIFMT_IB_IF:
  260. aifctrl1 |= WM8523_BCLK_INV | WM8523_LRCLK_INV;
  261. break;
  262. case SND_SOC_DAIFMT_IB_NF:
  263. aifctrl1 |= WM8523_BCLK_INV;
  264. break;
  265. case SND_SOC_DAIFMT_NB_IF:
  266. aifctrl1 |= WM8523_LRCLK_INV;
  267. break;
  268. default:
  269. return -EINVAL;
  270. }
  271. snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
  272. return 0;
  273. }
  274. static int wm8523_set_bias_level(struct snd_soc_codec *codec,
  275. enum snd_soc_bias_level level)
  276. {
  277. struct wm8523_priv *wm8523 = codec->private_data;
  278. int ret, i;
  279. switch (level) {
  280. case SND_SOC_BIAS_ON:
  281. break;
  282. case SND_SOC_BIAS_PREPARE:
  283. /* Full power on */
  284. snd_soc_update_bits(codec, WM8523_PSCTRL1,
  285. WM8523_SYS_ENA_MASK, 3);
  286. break;
  287. case SND_SOC_BIAS_STANDBY:
  288. if (codec->bias_level == SND_SOC_BIAS_OFF) {
  289. ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
  290. wm8523->supplies);
  291. if (ret != 0) {
  292. dev_err(codec->dev,
  293. "Failed to enable supplies: %d\n",
  294. ret);
  295. return ret;
  296. }
  297. /* Initial power up */
  298. snd_soc_update_bits(codec, WM8523_PSCTRL1,
  299. WM8523_SYS_ENA_MASK, 1);
  300. /* Sync back default/cached values */
  301. for (i = WM8523_AIF_CTRL1;
  302. i < WM8523_MAX_REGISTER; i++)
  303. snd_soc_write(codec, i, wm8523->reg_cache[i]);
  304. msleep(100);
  305. }
  306. /* Power up to mute */
  307. snd_soc_update_bits(codec, WM8523_PSCTRL1,
  308. WM8523_SYS_ENA_MASK, 2);
  309. break;
  310. case SND_SOC_BIAS_OFF:
  311. /* The chip runs through the power down sequence for us. */
  312. snd_soc_update_bits(codec, WM8523_PSCTRL1,
  313. WM8523_SYS_ENA_MASK, 0);
  314. msleep(100);
  315. regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies),
  316. wm8523->supplies);
  317. break;
  318. }
  319. codec->bias_level = level;
  320. return 0;
  321. }
  322. #define WM8523_RATES SNDRV_PCM_RATE_8000_192000
  323. #define WM8523_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  324. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  325. static struct snd_soc_dai_ops wm8523_dai_ops = {
  326. .startup = wm8523_startup,
  327. .hw_params = wm8523_hw_params,
  328. .set_sysclk = wm8523_set_dai_sysclk,
  329. .set_fmt = wm8523_set_dai_fmt,
  330. };
  331. struct snd_soc_dai wm8523_dai = {
  332. .name = "WM8523",
  333. .playback = {
  334. .stream_name = "Playback",
  335. .channels_min = 2, /* Mono modes not yet supported */
  336. .channels_max = 2,
  337. .rates = WM8523_RATES,
  338. .formats = WM8523_FORMATS,
  339. },
  340. .ops = &wm8523_dai_ops,
  341. };
  342. EXPORT_SYMBOL_GPL(wm8523_dai);
  343. #ifdef CONFIG_PM
  344. static int wm8523_suspend(struct platform_device *pdev, pm_message_t state)
  345. {
  346. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  347. struct snd_soc_codec *codec = socdev->card->codec;
  348. wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
  349. return 0;
  350. }
  351. static int wm8523_resume(struct platform_device *pdev)
  352. {
  353. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  354. struct snd_soc_codec *codec = socdev->card->codec;
  355. wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  356. return 0;
  357. }
  358. #else
  359. #define wm8523_suspend NULL
  360. #define wm8523_resume NULL
  361. #endif
  362. static int wm8523_probe(struct platform_device *pdev)
  363. {
  364. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  365. struct snd_soc_codec *codec;
  366. int ret = 0;
  367. if (wm8523_codec == NULL) {
  368. dev_err(&pdev->dev, "Codec device not registered\n");
  369. return -ENODEV;
  370. }
  371. socdev->card->codec = wm8523_codec;
  372. codec = wm8523_codec;
  373. /* register pcms */
  374. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  375. if (ret < 0) {
  376. dev_err(codec->dev, "failed to create pcms: %d\n", ret);
  377. goto pcm_err;
  378. }
  379. snd_soc_add_controls(codec, wm8523_snd_controls,
  380. ARRAY_SIZE(wm8523_snd_controls));
  381. wm8523_add_widgets(codec);
  382. return ret;
  383. pcm_err:
  384. return ret;
  385. }
  386. static int wm8523_remove(struct platform_device *pdev)
  387. {
  388. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  389. snd_soc_free_pcms(socdev);
  390. snd_soc_dapm_free(socdev);
  391. return 0;
  392. }
  393. struct snd_soc_codec_device soc_codec_dev_wm8523 = {
  394. .probe = wm8523_probe,
  395. .remove = wm8523_remove,
  396. .suspend = wm8523_suspend,
  397. .resume = wm8523_resume,
  398. };
  399. EXPORT_SYMBOL_GPL(soc_codec_dev_wm8523);
  400. static int wm8523_register(struct wm8523_priv *wm8523,
  401. enum snd_soc_control_type control)
  402. {
  403. int ret;
  404. struct snd_soc_codec *codec = &wm8523->codec;
  405. int i;
  406. if (wm8523_codec) {
  407. dev_err(codec->dev, "Another WM8523 is registered\n");
  408. return -EINVAL;
  409. }
  410. mutex_init(&codec->mutex);
  411. INIT_LIST_HEAD(&codec->dapm_widgets);
  412. INIT_LIST_HEAD(&codec->dapm_paths);
  413. codec->private_data = wm8523;
  414. codec->name = "WM8523";
  415. codec->owner = THIS_MODULE;
  416. codec->bias_level = SND_SOC_BIAS_OFF;
  417. codec->set_bias_level = wm8523_set_bias_level;
  418. codec->dai = &wm8523_dai;
  419. codec->num_dai = 1;
  420. codec->reg_cache_size = WM8523_REGISTER_COUNT;
  421. codec->reg_cache = &wm8523->reg_cache;
  422. codec->volatile_register = wm8523_volatile_register;
  423. wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0];
  424. wm8523->rate_constraint.count =
  425. ARRAY_SIZE(wm8523->rate_constraint_list);
  426. memcpy(codec->reg_cache, wm8523_reg, sizeof(wm8523_reg));
  427. ret = snd_soc_codec_set_cache_io(codec, 8, 16, control);
  428. if (ret != 0) {
  429. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  430. goto err;
  431. }
  432. for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++)
  433. wm8523->supplies[i].supply = wm8523_supply_names[i];
  434. ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8523->supplies),
  435. wm8523->supplies);
  436. if (ret != 0) {
  437. dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
  438. goto err;
  439. }
  440. ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
  441. wm8523->supplies);
  442. if (ret != 0) {
  443. dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
  444. goto err_get;
  445. }
  446. ret = snd_soc_read(codec, WM8523_DEVICE_ID);
  447. if (ret < 0) {
  448. dev_err(codec->dev, "Failed to read ID register\n");
  449. goto err_enable;
  450. }
  451. if (ret != wm8523_reg[WM8523_DEVICE_ID]) {
  452. dev_err(codec->dev, "Device is not a WM8523, ID is %x\n", ret);
  453. ret = -EINVAL;
  454. goto err_enable;
  455. }
  456. ret = snd_soc_read(codec, WM8523_REVISION);
  457. if (ret < 0) {
  458. dev_err(codec->dev, "Failed to read revision register\n");
  459. goto err_enable;
  460. }
  461. dev_info(codec->dev, "revision %c\n",
  462. (ret & WM8523_CHIP_REV_MASK) + 'A');
  463. ret = wm8523_reset(codec);
  464. if (ret < 0) {
  465. dev_err(codec->dev, "Failed to issue reset\n");
  466. goto err_enable;
  467. }
  468. wm8523_dai.dev = codec->dev;
  469. /* Change some default settings - latch VU and enable ZC */
  470. wm8523->reg_cache[WM8523_DAC_GAINR] |= WM8523_DACR_VU;
  471. wm8523->reg_cache[WM8523_DAC_CTRL3] |= WM8523_ZC;
  472. wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  473. /* Bias level configuration will have done an extra enable */
  474. regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
  475. wm8523_codec = codec;
  476. ret = snd_soc_register_codec(codec);
  477. if (ret != 0) {
  478. dev_err(codec->dev, "Failed to register codec: %d\n", ret);
  479. return ret;
  480. }
  481. ret = snd_soc_register_dai(&wm8523_dai);
  482. if (ret != 0) {
  483. dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
  484. snd_soc_unregister_codec(codec);
  485. return ret;
  486. }
  487. return 0;
  488. err_enable:
  489. regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
  490. err_get:
  491. regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
  492. err:
  493. kfree(wm8523);
  494. return ret;
  495. }
  496. static void wm8523_unregister(struct wm8523_priv *wm8523)
  497. {
  498. wm8523_set_bias_level(&wm8523->codec, SND_SOC_BIAS_OFF);
  499. regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
  500. snd_soc_unregister_dai(&wm8523_dai);
  501. snd_soc_unregister_codec(&wm8523->codec);
  502. kfree(wm8523);
  503. wm8523_codec = NULL;
  504. }
  505. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  506. static __devinit int wm8523_i2c_probe(struct i2c_client *i2c,
  507. const struct i2c_device_id *id)
  508. {
  509. struct wm8523_priv *wm8523;
  510. struct snd_soc_codec *codec;
  511. wm8523 = kzalloc(sizeof(struct wm8523_priv), GFP_KERNEL);
  512. if (wm8523 == NULL)
  513. return -ENOMEM;
  514. codec = &wm8523->codec;
  515. codec->hw_write = (hw_write_t)i2c_master_send;
  516. i2c_set_clientdata(i2c, wm8523);
  517. codec->control_data = i2c;
  518. codec->dev = &i2c->dev;
  519. return wm8523_register(wm8523, SND_SOC_I2C);
  520. }
  521. static __devexit int wm8523_i2c_remove(struct i2c_client *client)
  522. {
  523. struct wm8523_priv *wm8523 = i2c_get_clientdata(client);
  524. wm8523_unregister(wm8523);
  525. return 0;
  526. }
  527. static const struct i2c_device_id wm8523_i2c_id[] = {
  528. { "wm8523", 0 },
  529. { }
  530. };
  531. MODULE_DEVICE_TABLE(i2c, wm8523_i2c_id);
  532. static struct i2c_driver wm8523_i2c_driver = {
  533. .driver = {
  534. .name = "WM8523",
  535. .owner = THIS_MODULE,
  536. },
  537. .probe = wm8523_i2c_probe,
  538. .remove = __devexit_p(wm8523_i2c_remove),
  539. .id_table = wm8523_i2c_id,
  540. };
  541. #endif
  542. static int __init wm8523_modinit(void)
  543. {
  544. int ret;
  545. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  546. ret = i2c_add_driver(&wm8523_i2c_driver);
  547. if (ret != 0) {
  548. printk(KERN_ERR "Failed to register WM8523 I2C driver: %d\n",
  549. ret);
  550. }
  551. #endif
  552. return 0;
  553. }
  554. module_init(wm8523_modinit);
  555. static void __exit wm8523_exit(void)
  556. {
  557. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  558. i2c_del_driver(&wm8523_i2c_driver);
  559. #endif
  560. }
  561. module_exit(wm8523_exit);
  562. MODULE_DESCRIPTION("ASoC WM8523 driver");
  563. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  564. MODULE_LICENSE("GPL");