wm8711.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * wm8711.c -- WM8711 ALSA SoC Audio driver
  3. *
  4. * Copyright 2006 Wolfson Microelectronics
  5. *
  6. * Author: Mike Arthur <linux@wolfsonmicro.com>
  7. *
  8. * Based on wm8731.c by Richard Purdie
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/pm.h>
  19. #include <linux/i2c.h>
  20. #include <linux/platform_device.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/soc.h>
  25. #include <sound/soc-dapm.h>
  26. #include <sound/initval.h>
  27. #include "wm8711.h"
  28. #define AUDIO_NAME "wm8711"
  29. #define WM8711_VERSION "0.3"
  30. /* codec private data */
  31. struct wm8711_priv {
  32. unsigned int sysclk;
  33. };
  34. /*
  35. * wm8711 register cache
  36. * We can't read the WM8711 register space when we are
  37. * using 2 wire for device control, so we cache them instead.
  38. * There is no point in caching the reset register
  39. */
  40. static const u16 wm8711_reg[WM8711_CACHEREGNUM] = {
  41. 0x0079, 0x0079, 0x000a, 0x0008,
  42. 0x009f, 0x000a, 0x0000, 0x0000
  43. };
  44. /*
  45. * read wm8711 register cache
  46. */
  47. static inline unsigned int wm8711_read_reg_cache(struct snd_soc_codec *codec,
  48. unsigned int reg)
  49. {
  50. u16 *cache = codec->reg_cache;
  51. if (reg == WM8711_RESET)
  52. return 0;
  53. if (reg >= WM8711_CACHEREGNUM)
  54. return -1;
  55. return cache[reg];
  56. }
  57. /*
  58. * write wm8711 register cache
  59. */
  60. static inline void wm8711_write_reg_cache(struct snd_soc_codec *codec,
  61. u16 reg, unsigned int value)
  62. {
  63. u16 *cache = codec->reg_cache;
  64. if (reg >= WM8711_CACHEREGNUM)
  65. return;
  66. cache[reg] = value;
  67. }
  68. /*
  69. * write to the WM8711 register space
  70. */
  71. static int wm8711_write(struct snd_soc_codec *codec, unsigned int reg,
  72. unsigned int value)
  73. {
  74. u8 data[2];
  75. /* data is
  76. * D15..D9 WM8753 register offset
  77. * D8...D0 register data
  78. */
  79. data[0] = (reg << 1) | ((value >> 8) & 0x0001);
  80. data[1] = value & 0x00ff;
  81. wm8711_write_reg_cache(codec, reg, value);
  82. if (codec->hw_write(codec->control_data, data, 2) == 2)
  83. return 0;
  84. else
  85. return -EIO;
  86. }
  87. #define wm8711_reset(c) wm8711_write(c, WM8711_RESET, 0)
  88. static const struct snd_kcontrol_new wm8711_snd_controls[] = {
  89. SOC_DOUBLE_R("Master Playback Volume", WM8711_LOUT1V, WM8711_ROUT1V,
  90. 0, 127, 0),
  91. SOC_DOUBLE_R("Master Playback ZC Switch", WM8711_LOUT1V, WM8711_ROUT1V,
  92. 7, 1, 0),
  93. };
  94. /* add non dapm controls */
  95. static int wm8711_add_controls(struct snd_soc_codec *codec)
  96. {
  97. int err, i;
  98. for (i = 0; i < ARRAY_SIZE(wm8711_snd_controls); i++) {
  99. err = snd_ctl_add(codec->card,
  100. snd_soc_cnew(&wm8711_snd_controls[i], codec,
  101. NULL));
  102. if (err < 0)
  103. return err;
  104. }
  105. return 0;
  106. }
  107. /* Output Mixer */
  108. static const struct snd_kcontrol_new wm8711_output_mixer_controls[] = {
  109. SOC_DAPM_SINGLE("Line Bypass Switch", WM8711_APANA, 3, 1, 0),
  110. SOC_DAPM_SINGLE("HiFi Playback Switch", WM8711_APANA, 4, 1, 0),
  111. };
  112. static const struct snd_soc_dapm_widget wm8711_dapm_widgets[] = {
  113. SND_SOC_DAPM_MIXER("Output Mixer", WM8711_PWR, 4, 1,
  114. &wm8711_output_mixer_controls[0],
  115. ARRAY_SIZE(wm8711_output_mixer_controls)),
  116. SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8711_PWR, 3, 1),
  117. SND_SOC_DAPM_OUTPUT("LOUT"),
  118. SND_SOC_DAPM_OUTPUT("LHPOUT"),
  119. SND_SOC_DAPM_OUTPUT("ROUT"),
  120. SND_SOC_DAPM_OUTPUT("RHPOUT"),
  121. };
  122. static const struct snd_soc_dapm_route intercon[] = {
  123. /* output mixer */
  124. {"Output Mixer", "Line Bypass Switch", "Line Input"},
  125. {"Output Mixer", "HiFi Playback Switch", "DAC"},
  126. /* outputs */
  127. {"RHPOUT", NULL, "Output Mixer"},
  128. {"ROUT", NULL, "Output Mixer"},
  129. {"LHPOUT", NULL, "Output Mixer"},
  130. {"LOUT", NULL, "Output Mixer"},
  131. };
  132. static int wm8711_add_widgets(struct snd_soc_codec *codec)
  133. {
  134. snd_soc_dapm_new_controls(codec, wm8711_dapm_widgets,
  135. ARRAY_SIZE(wm8711_dapm_widgets));
  136. snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
  137. snd_soc_dapm_new_widgets(codec);
  138. return 0;
  139. }
  140. struct _coeff_div {
  141. u32 mclk;
  142. u32 rate;
  143. u16 fs;
  144. u8 sr:4;
  145. u8 bosr:1;
  146. u8 usb:1;
  147. };
  148. /* codec mclk clock divider coefficients */
  149. static const struct _coeff_div coeff_div[] = {
  150. /* 48k */
  151. {12288000, 48000, 256, 0x0, 0x0, 0x0},
  152. {18432000, 48000, 384, 0x0, 0x1, 0x0},
  153. {12000000, 48000, 250, 0x0, 0x0, 0x1},
  154. /* 32k */
  155. {12288000, 32000, 384, 0x6, 0x0, 0x0},
  156. {18432000, 32000, 576, 0x6, 0x1, 0x0},
  157. {12000000, 32000, 375, 0x6, 0x0, 0x1},
  158. /* 8k */
  159. {12288000, 8000, 1536, 0x3, 0x0, 0x0},
  160. {18432000, 8000, 2304, 0x3, 0x1, 0x0},
  161. {11289600, 8000, 1408, 0xb, 0x0, 0x0},
  162. {16934400, 8000, 2112, 0xb, 0x1, 0x0},
  163. {12000000, 8000, 1500, 0x3, 0x0, 0x1},
  164. /* 96k */
  165. {12288000, 96000, 128, 0x7, 0x0, 0x0},
  166. {18432000, 96000, 192, 0x7, 0x1, 0x0},
  167. {12000000, 96000, 125, 0x7, 0x0, 0x1},
  168. /* 44.1k */
  169. {11289600, 44100, 256, 0x8, 0x0, 0x0},
  170. {16934400, 44100, 384, 0x8, 0x1, 0x0},
  171. {12000000, 44100, 272, 0x8, 0x1, 0x1},
  172. /* 88.2k */
  173. {11289600, 88200, 128, 0xf, 0x0, 0x0},
  174. {16934400, 88200, 192, 0xf, 0x1, 0x0},
  175. {12000000, 88200, 136, 0xf, 0x1, 0x1},
  176. };
  177. static inline int get_coeff(int mclk, int rate)
  178. {
  179. int i;
  180. for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
  181. if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
  182. return i;
  183. }
  184. return 0;
  185. }
  186. static int wm8711_hw_params(struct snd_pcm_substream *substream,
  187. struct snd_pcm_hw_params *params,
  188. struct snd_soc_dai *dai)
  189. {
  190. struct snd_soc_codec *codec = dai->codec;
  191. struct wm8711_priv *wm8711 = codec->private_data;
  192. u16 iface = wm8711_read_reg_cache(codec, WM8711_IFACE) & 0xfffc;
  193. int i = get_coeff(wm8711->sysclk, params_rate(params));
  194. u16 srate = (coeff_div[i].sr << 2) |
  195. (coeff_div[i].bosr << 1) | coeff_div[i].usb;
  196. wm8711_write(codec, WM8711_SRATE, srate);
  197. /* bit size */
  198. switch (params_format(params)) {
  199. case SNDRV_PCM_FORMAT_S16_LE:
  200. break;
  201. case SNDRV_PCM_FORMAT_S20_3LE:
  202. iface |= 0x0004;
  203. break;
  204. case SNDRV_PCM_FORMAT_S24_LE:
  205. iface |= 0x0008;
  206. break;
  207. }
  208. wm8711_write(codec, WM8711_IFACE, iface);
  209. return 0;
  210. }
  211. static int wm8711_pcm_prepare(struct snd_pcm_substream *substream,
  212. struct snd_soc_dai *dai)
  213. {
  214. struct snd_soc_codec *codec = dai->codec;
  215. /* set active */
  216. wm8711_write(codec, WM8711_ACTIVE, 0x0001);
  217. return 0;
  218. }
  219. static void wm8711_shutdown(struct snd_pcm_substream *substream,
  220. struct snd_soc_dai *dai)
  221. {
  222. struct snd_soc_codec *codec = dai->codec;
  223. /* deactivate */
  224. if (!codec->active) {
  225. udelay(50);
  226. wm8711_write(codec, WM8711_ACTIVE, 0x0);
  227. }
  228. }
  229. static int wm8711_mute(struct snd_soc_dai *dai, int mute)
  230. {
  231. struct snd_soc_codec *codec = dai->codec;
  232. u16 mute_reg = wm8711_read_reg_cache(codec, WM8711_APDIGI) & 0xfff7;
  233. if (mute)
  234. wm8711_write(codec, WM8711_APDIGI, mute_reg | 0x8);
  235. else
  236. wm8711_write(codec, WM8711_APDIGI, mute_reg);
  237. return 0;
  238. }
  239. static int wm8711_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  240. int clk_id, unsigned int freq, int dir)
  241. {
  242. struct snd_soc_codec *codec = codec_dai->codec;
  243. struct wm8711_priv *wm8711 = codec->private_data;
  244. switch (freq) {
  245. case 11289600:
  246. case 12000000:
  247. case 12288000:
  248. case 16934400:
  249. case 18432000:
  250. wm8711->sysclk = freq;
  251. return 0;
  252. }
  253. return -EINVAL;
  254. }
  255. static int wm8711_set_dai_fmt(struct snd_soc_dai *codec_dai,
  256. unsigned int fmt)
  257. {
  258. struct snd_soc_codec *codec = codec_dai->codec;
  259. u16 iface = 0;
  260. /* set master/slave audio interface */
  261. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  262. case SND_SOC_DAIFMT_CBM_CFM:
  263. iface |= 0x0040;
  264. break;
  265. case SND_SOC_DAIFMT_CBS_CFS:
  266. break;
  267. default:
  268. return -EINVAL;
  269. }
  270. /* interface format */
  271. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  272. case SND_SOC_DAIFMT_I2S:
  273. iface |= 0x0002;
  274. break;
  275. case SND_SOC_DAIFMT_RIGHT_J:
  276. break;
  277. case SND_SOC_DAIFMT_LEFT_J:
  278. iface |= 0x0001;
  279. break;
  280. case SND_SOC_DAIFMT_DSP_A:
  281. iface |= 0x0003;
  282. break;
  283. case SND_SOC_DAIFMT_DSP_B:
  284. iface |= 0x0013;
  285. break;
  286. default:
  287. return -EINVAL;
  288. }
  289. /* clock inversion */
  290. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  291. case SND_SOC_DAIFMT_NB_NF:
  292. break;
  293. case SND_SOC_DAIFMT_IB_IF:
  294. iface |= 0x0090;
  295. break;
  296. case SND_SOC_DAIFMT_IB_NF:
  297. iface |= 0x0080;
  298. break;
  299. case SND_SOC_DAIFMT_NB_IF:
  300. iface |= 0x0010;
  301. break;
  302. default:
  303. return -EINVAL;
  304. }
  305. /* set iface */
  306. wm8711_write(codec, WM8711_IFACE, iface);
  307. return 0;
  308. }
  309. static int wm8711_set_bias_level(struct snd_soc_codec *codec,
  310. enum snd_soc_bias_level level)
  311. {
  312. u16 reg = wm8711_read_reg_cache(codec, WM8711_PWR) & 0xff7f;
  313. switch (level) {
  314. case SND_SOC_BIAS_ON:
  315. wm8711_write(codec, WM8711_PWR, reg);
  316. break;
  317. case SND_SOC_BIAS_PREPARE:
  318. break;
  319. case SND_SOC_BIAS_STANDBY:
  320. wm8711_write(codec, WM8711_PWR, reg | 0x0040);
  321. break;
  322. case SND_SOC_BIAS_OFF:
  323. wm8711_write(codec, WM8711_ACTIVE, 0x0);
  324. wm8711_write(codec, WM8711_PWR, 0xffff);
  325. break;
  326. }
  327. codec->bias_level = level;
  328. return 0;
  329. }
  330. #define WM8711_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  331. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
  332. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  333. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
  334. SNDRV_PCM_RATE_96000)
  335. #define WM8711_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  336. SNDRV_PCM_FMTBIT_S24_LE)
  337. static struct snd_soc_dai_ops wm8711_ops = {
  338. .prepare = wm8711_pcm_prepare,
  339. .hw_params = wm8711_hw_params,
  340. .shutdown = wm8711_shutdown,
  341. .digital_mute = wm8711_mute,
  342. .set_sysclk = wm8711_set_dai_sysclk,
  343. .set_fmt = wm8711_set_dai_fmt,
  344. };
  345. struct snd_soc_dai wm8711_dai = {
  346. .name = "WM8711",
  347. .playback = {
  348. .stream_name = "Playback",
  349. .channels_min = 1,
  350. .channels_max = 2,
  351. .rates = WM8711_RATES,
  352. .formats = WM8711_FORMATS,},
  353. .ops = &wm8711_ops,
  354. };
  355. EXPORT_SYMBOL_GPL(wm8711_dai);
  356. static int wm8711_suspend(struct platform_device *pdev, pm_message_t state)
  357. {
  358. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  359. struct snd_soc_codec *codec = socdev->card->codec;
  360. wm8711_write(codec, WM8711_ACTIVE, 0x0);
  361. wm8711_set_bias_level(codec, SND_SOC_BIAS_OFF);
  362. return 0;
  363. }
  364. static int wm8711_resume(struct platform_device *pdev)
  365. {
  366. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  367. struct snd_soc_codec *codec = socdev->card->codec;
  368. int i;
  369. u8 data[2];
  370. u16 *cache = codec->reg_cache;
  371. /* Sync reg_cache with the hardware */
  372. for (i = 0; i < ARRAY_SIZE(wm8711_reg); i++) {
  373. data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
  374. data[1] = cache[i] & 0x00ff;
  375. codec->hw_write(codec->control_data, data, 2);
  376. }
  377. wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  378. wm8711_set_bias_level(codec, codec->suspend_bias_level);
  379. return 0;
  380. }
  381. /*
  382. * initialise the WM8711 driver
  383. * register the mixer and dsp interfaces with the kernel
  384. */
  385. static int wm8711_init(struct snd_soc_device *socdev)
  386. {
  387. struct snd_soc_codec *codec = socdev->card->codec;
  388. int reg, ret = 0;
  389. codec->name = "WM8711";
  390. codec->owner = THIS_MODULE;
  391. codec->read = wm8711_read_reg_cache;
  392. codec->write = wm8711_write;
  393. codec->set_bias_level = wm8711_set_bias_level;
  394. codec->dai = &wm8711_dai;
  395. codec->num_dai = 1;
  396. codec->reg_cache_size = ARRAY_SIZE(wm8711_reg);
  397. codec->reg_cache = kmemdup(wm8711_reg, sizeof(wm8711_reg), GFP_KERNEL);
  398. if (codec->reg_cache == NULL)
  399. return -ENOMEM;
  400. wm8711_reset(codec);
  401. /* register pcms */
  402. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  403. if (ret < 0) {
  404. printk(KERN_ERR "wm8711: failed to create pcms\n");
  405. goto pcm_err;
  406. }
  407. /* power on device */
  408. wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  409. /* set the update bits */
  410. reg = wm8711_read_reg_cache(codec, WM8711_LOUT1V);
  411. wm8711_write(codec, WM8711_LOUT1V, reg | 0x0100);
  412. reg = wm8711_read_reg_cache(codec, WM8711_ROUT1V);
  413. wm8711_write(codec, WM8711_ROUT1V, reg | 0x0100);
  414. wm8711_add_controls(codec);
  415. wm8711_add_widgets(codec);
  416. ret = snd_soc_init_card(socdev);
  417. if (ret < 0) {
  418. printk(KERN_ERR "wm8711: failed to register card\n");
  419. goto card_err;
  420. }
  421. return ret;
  422. card_err:
  423. snd_soc_free_pcms(socdev);
  424. snd_soc_dapm_free(socdev);
  425. pcm_err:
  426. kfree(codec->reg_cache);
  427. return ret;
  428. }
  429. static struct snd_soc_device *wm8711_socdev;
  430. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  431. /*
  432. * WM8711 2 wire address is determined by GPIO5
  433. * state during powerup.
  434. * low = 0x1a
  435. * high = 0x1b
  436. */
  437. #define I2C_DRIVERID_WM8711 0xfefe /* liam - need a proper id */
  438. static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
  439. /* Magic definition of all other variables and things */
  440. I2C_CLIENT_INSMOD;
  441. static struct i2c_driver wm8711_i2c_driver;
  442. static struct i2c_client client_template;
  443. /* If the i2c layer weren't so broken, we could pass this kind of data
  444. around */
  445. static int wm8711_codec_probe(struct i2c_adapter *adap, int addr, int kind)
  446. {
  447. struct snd_soc_device *socdev = wm8711_socdev;
  448. struct wm8711_setup_data *setup = socdev->codec_data;
  449. struct snd_soc_codec *codec = socdev->card->codec;
  450. struct i2c_client *i2c;
  451. int ret;
  452. if (addr != setup->i2c_address)
  453. return -ENODEV;
  454. client_template.adapter = adap;
  455. client_template.addr = addr;
  456. i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
  457. if (i2c == NULL) {
  458. kfree(codec);
  459. return -ENOMEM;
  460. }
  461. i2c_set_clientdata(i2c, codec);
  462. codec->control_data = i2c;
  463. ret = i2c_attach_client(i2c);
  464. if (ret < 0) {
  465. pr_err("failed to attach codec at addr %x\n", addr);
  466. goto err;
  467. }
  468. ret = wm8711_init(socdev);
  469. if (ret < 0) {
  470. pr_err("failed to initialise WM8711\n");
  471. goto err;
  472. }
  473. return ret;
  474. err:
  475. kfree(codec);
  476. kfree(i2c);
  477. return ret;
  478. }
  479. static int wm8711_i2c_detach(struct i2c_client *client)
  480. {
  481. struct snd_soc_codec *codec = i2c_get_clientdata(client);
  482. i2c_detach_client(client);
  483. kfree(codec->reg_cache);
  484. kfree(client);
  485. return 0;
  486. }
  487. static int wm8711_i2c_attach(struct i2c_adapter *adap)
  488. {
  489. return i2c_probe(adap, &addr_data, wm8711_codec_probe);
  490. }
  491. /* corgi i2c codec control layer */
  492. static struct i2c_driver wm8711_i2c_driver = {
  493. .driver = {
  494. .name = "WM8711 I2C Codec",
  495. .owner = THIS_MODULE,
  496. },
  497. .id = I2C_DRIVERID_WM8711,
  498. .attach_adapter = wm8711_i2c_attach,
  499. .detach_client = wm8711_i2c_detach,
  500. .command = NULL,
  501. };
  502. static struct i2c_client client_template = {
  503. .name = "WM8711",
  504. .driver = &wm8711_i2c_driver,
  505. };
  506. #endif
  507. static int wm8711_probe(struct platform_device *pdev)
  508. {
  509. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  510. struct wm8711_setup_data *setup;
  511. struct snd_soc_codec *codec;
  512. struct wm8711_priv *wm8711;
  513. int ret = 0;
  514. pr_info("WM8711 Audio Codec %s", WM8711_VERSION);
  515. setup = socdev->codec_data;
  516. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  517. if (codec == NULL)
  518. return -ENOMEM;
  519. wm8711 = kzalloc(sizeof(struct wm8711_priv), GFP_KERNEL);
  520. if (wm8711 == NULL) {
  521. kfree(codec);
  522. return -ENOMEM;
  523. }
  524. codec->private_data = wm8711;
  525. socdev->card->codec = codec;
  526. mutex_init(&codec->mutex);
  527. INIT_LIST_HEAD(&codec->dapm_widgets);
  528. INIT_LIST_HEAD(&codec->dapm_paths);
  529. wm8711_socdev = socdev;
  530. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  531. if (setup->i2c_address) {
  532. normal_i2c[0] = setup->i2c_address;
  533. codec->hw_write = (hw_write_t)i2c_master_send;
  534. ret = i2c_add_driver(&wm8711_i2c_driver);
  535. if (ret != 0)
  536. printk(KERN_ERR "can't add i2c driver");
  537. }
  538. #else
  539. /* Add other interfaces here */
  540. #endif
  541. return ret;
  542. }
  543. /* power down chip */
  544. static int wm8711_remove(struct platform_device *pdev)
  545. {
  546. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  547. struct snd_soc_codec *codec = socdev->card->codec;
  548. if (codec->control_data)
  549. wm8711_set_bias_level(codec, SND_SOC_BIAS_OFF);
  550. snd_soc_free_pcms(socdev);
  551. snd_soc_dapm_free(socdev);
  552. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  553. i2c_del_driver(&wm8711_i2c_driver);
  554. #endif
  555. kfree(codec->private_data);
  556. kfree(codec);
  557. return 0;
  558. }
  559. struct snd_soc_codec_device soc_codec_dev_wm8711 = {
  560. .probe = wm8711_probe,
  561. .remove = wm8711_remove,
  562. .suspend = wm8711_suspend,
  563. .resume = wm8711_resume,
  564. };
  565. EXPORT_SYMBOL_GPL(soc_codec_dev_wm8711);
  566. static int __init wm8711_modinit(void)
  567. {
  568. return snd_soc_register_dai(&wm8711_dai);
  569. }
  570. module_init(wm8711_modinit);
  571. static void __exit wm8711_exit(void)
  572. {
  573. snd_soc_unregister_dai(&wm8711_dai);
  574. }
  575. module_exit(wm8711_exit);
  576. MODULE_DESCRIPTION("ASoC WM8711 driver");
  577. MODULE_AUTHOR("Mike Arthur");
  578. MODULE_LICENSE("GPL");