uda134x.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * uda134x.c -- UDA134X ALSA SoC Codec driver
  3. *
  4. * Modifications by Christian Pellegrin <chripell@evolware.org>
  5. *
  6. * Copyright 2007 Dension Audio Systems Ltd.
  7. * Author: Zoltan Devai
  8. *
  9. * Based on the WM87xx drivers by Liam Girdwood and Richard Purdie
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <linux/slab.h>
  18. #include <sound/pcm.h>
  19. #include <sound/pcm_params.h>
  20. #include <sound/soc.h>
  21. #include <sound/soc-dapm.h>
  22. #include <sound/initval.h>
  23. #include <sound/uda134x.h>
  24. #include <sound/l3.h>
  25. #include "uda134x.h"
  26. #define UDA134X_RATES SNDRV_PCM_RATE_8000_48000
  27. #define UDA134X_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \
  28. SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_3LE)
  29. struct uda134x_priv {
  30. int sysclk;
  31. int dai_fmt;
  32. struct snd_pcm_substream *master_substream;
  33. struct snd_pcm_substream *slave_substream;
  34. };
  35. /* In-data addresses are hard-coded into the reg-cache values */
  36. static const char uda134x_reg[UDA134X_REGS_NUM] = {
  37. /* Extended address registers */
  38. 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
  39. /* Status, data regs */
  40. 0x00, 0x83, 0x00, 0x40, 0x80, 0x00,
  41. };
  42. /*
  43. * The codec has no support for reading its registers except for peak level...
  44. */
  45. static inline unsigned int uda134x_read_reg_cache(struct snd_soc_codec *codec,
  46. unsigned int reg)
  47. {
  48. u8 *cache = codec->reg_cache;
  49. if (reg >= UDA134X_REGS_NUM)
  50. return -1;
  51. return cache[reg];
  52. }
  53. /*
  54. * Write the register cache
  55. */
  56. static inline void uda134x_write_reg_cache(struct snd_soc_codec *codec,
  57. u8 reg, unsigned int value)
  58. {
  59. u8 *cache = codec->reg_cache;
  60. if (reg >= UDA134X_REGS_NUM)
  61. return;
  62. cache[reg] = value;
  63. }
  64. /*
  65. * Write to the uda134x registers
  66. *
  67. */
  68. static int uda134x_write(struct snd_soc_codec *codec, unsigned int reg,
  69. unsigned int value)
  70. {
  71. int ret;
  72. u8 addr;
  73. u8 data = value;
  74. struct uda134x_platform_data *pd = codec->control_data;
  75. pr_debug("%s reg: %02X, value:%02X\n", __func__, reg, value);
  76. if (reg >= UDA134X_REGS_NUM) {
  77. printk(KERN_ERR "%s unknown register: reg: %u",
  78. __func__, reg);
  79. return -EINVAL;
  80. }
  81. uda134x_write_reg_cache(codec, reg, value);
  82. switch (reg) {
  83. case UDA134X_STATUS0:
  84. case UDA134X_STATUS1:
  85. addr = UDA134X_STATUS_ADDR;
  86. break;
  87. case UDA134X_DATA000:
  88. case UDA134X_DATA001:
  89. case UDA134X_DATA010:
  90. addr = UDA134X_DATA0_ADDR;
  91. break;
  92. case UDA134X_DATA1:
  93. addr = UDA134X_DATA1_ADDR;
  94. break;
  95. default:
  96. /* It's an extended address register */
  97. addr = (reg | UDA134X_EXTADDR_PREFIX);
  98. ret = l3_write(&pd->l3,
  99. UDA134X_DATA0_ADDR, &addr, 1);
  100. if (ret != 1)
  101. return -EIO;
  102. addr = UDA134X_DATA0_ADDR;
  103. data = (value | UDA134X_EXTDATA_PREFIX);
  104. break;
  105. }
  106. ret = l3_write(&pd->l3,
  107. addr, &data, 1);
  108. if (ret != 1)
  109. return -EIO;
  110. return 0;
  111. }
  112. static inline void uda134x_reset(struct snd_soc_codec *codec)
  113. {
  114. u8 reset_reg = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
  115. uda134x_write(codec, UDA134X_STATUS0, reset_reg | (1<<6));
  116. msleep(1);
  117. uda134x_write(codec, UDA134X_STATUS0, reset_reg & ~(1<<6));
  118. }
  119. static int uda134x_mute(struct snd_soc_dai *dai, int mute)
  120. {
  121. struct snd_soc_codec *codec = dai->codec;
  122. u8 mute_reg = uda134x_read_reg_cache(codec, UDA134X_DATA010);
  123. pr_debug("%s mute: %d\n", __func__, mute);
  124. if (mute)
  125. mute_reg |= (1<<2);
  126. else
  127. mute_reg &= ~(1<<2);
  128. uda134x_write(codec, UDA134X_DATA010, mute_reg);
  129. return 0;
  130. }
  131. static int uda134x_startup(struct snd_pcm_substream *substream,
  132. struct snd_soc_dai *dai)
  133. {
  134. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  135. struct snd_soc_device *socdev = rtd->socdev;
  136. struct snd_soc_codec *codec = socdev->card->codec;
  137. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  138. struct snd_pcm_runtime *master_runtime;
  139. if (uda134x->master_substream) {
  140. master_runtime = uda134x->master_substream->runtime;
  141. pr_debug("%s constraining to %d bits at %d\n", __func__,
  142. master_runtime->sample_bits,
  143. master_runtime->rate);
  144. snd_pcm_hw_constraint_minmax(substream->runtime,
  145. SNDRV_PCM_HW_PARAM_RATE,
  146. master_runtime->rate,
  147. master_runtime->rate);
  148. snd_pcm_hw_constraint_minmax(substream->runtime,
  149. SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
  150. master_runtime->sample_bits,
  151. master_runtime->sample_bits);
  152. uda134x->slave_substream = substream;
  153. } else
  154. uda134x->master_substream = substream;
  155. return 0;
  156. }
  157. static void uda134x_shutdown(struct snd_pcm_substream *substream,
  158. struct snd_soc_dai *dai)
  159. {
  160. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  161. struct snd_soc_device *socdev = rtd->socdev;
  162. struct snd_soc_codec *codec = socdev->card->codec;
  163. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  164. if (uda134x->master_substream == substream)
  165. uda134x->master_substream = uda134x->slave_substream;
  166. uda134x->slave_substream = NULL;
  167. }
  168. static int uda134x_hw_params(struct snd_pcm_substream *substream,
  169. struct snd_pcm_hw_params *params,
  170. struct snd_soc_dai *dai)
  171. {
  172. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  173. struct snd_soc_device *socdev = rtd->socdev;
  174. struct snd_soc_codec *codec = socdev->card->codec;
  175. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  176. u8 hw_params;
  177. if (substream == uda134x->slave_substream) {
  178. pr_debug("%s ignoring hw_params for slave substream\n",
  179. __func__);
  180. return 0;
  181. }
  182. hw_params = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
  183. hw_params &= STATUS0_SYSCLK_MASK;
  184. hw_params &= STATUS0_DAIFMT_MASK;
  185. pr_debug("%s sysclk: %d, rate:%d\n", __func__,
  186. uda134x->sysclk, params_rate(params));
  187. /* set SYSCLK / fs ratio */
  188. switch (uda134x->sysclk / params_rate(params)) {
  189. case 512:
  190. break;
  191. case 384:
  192. hw_params |= (1<<4);
  193. break;
  194. case 256:
  195. hw_params |= (1<<5);
  196. break;
  197. default:
  198. printk(KERN_ERR "%s unsupported fs\n", __func__);
  199. return -EINVAL;
  200. }
  201. pr_debug("%s dai_fmt: %d, params_format:%d\n", __func__,
  202. uda134x->dai_fmt, params_format(params));
  203. /* set DAI format and word length */
  204. switch (uda134x->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  205. case SND_SOC_DAIFMT_I2S:
  206. break;
  207. case SND_SOC_DAIFMT_RIGHT_J:
  208. switch (params_format(params)) {
  209. case SNDRV_PCM_FORMAT_S16_LE:
  210. hw_params |= (1<<1);
  211. break;
  212. case SNDRV_PCM_FORMAT_S18_3LE:
  213. hw_params |= (1<<2);
  214. break;
  215. case SNDRV_PCM_FORMAT_S20_3LE:
  216. hw_params |= ((1<<2) | (1<<1));
  217. break;
  218. default:
  219. printk(KERN_ERR "%s unsupported format (right)\n",
  220. __func__);
  221. return -EINVAL;
  222. }
  223. break;
  224. case SND_SOC_DAIFMT_LEFT_J:
  225. hw_params |= (1<<3);
  226. break;
  227. default:
  228. printk(KERN_ERR "%s unsupported format\n", __func__);
  229. return -EINVAL;
  230. }
  231. uda134x_write(codec, UDA134X_STATUS0, hw_params);
  232. return 0;
  233. }
  234. static int uda134x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  235. int clk_id, unsigned int freq, int dir)
  236. {
  237. struct snd_soc_codec *codec = codec_dai->codec;
  238. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  239. pr_debug("%s clk_id: %d, freq: %u, dir: %d\n", __func__,
  240. clk_id, freq, dir);
  241. /* Anything between 256fs*8Khz and 512fs*48Khz should be acceptable
  242. because the codec is slave. Of course limitations of the clock
  243. master (the IIS controller) apply.
  244. We'll error out on set_hw_params if it's not OK */
  245. if ((freq >= (256 * 8000)) && (freq <= (512 * 48000))) {
  246. uda134x->sysclk = freq;
  247. return 0;
  248. }
  249. printk(KERN_ERR "%s unsupported sysclk\n", __func__);
  250. return -EINVAL;
  251. }
  252. static int uda134x_set_dai_fmt(struct snd_soc_dai *codec_dai,
  253. unsigned int fmt)
  254. {
  255. struct snd_soc_codec *codec = codec_dai->codec;
  256. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  257. pr_debug("%s fmt: %08X\n", __func__, fmt);
  258. /* codec supports only full slave mode */
  259. if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
  260. printk(KERN_ERR "%s unsupported slave mode\n", __func__);
  261. return -EINVAL;
  262. }
  263. /* no support for clock inversion */
  264. if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
  265. printk(KERN_ERR "%s unsupported clock inversion\n", __func__);
  266. return -EINVAL;
  267. }
  268. /* We can't setup DAI format here as it depends on the word bit num */
  269. /* so let's just store the value for later */
  270. uda134x->dai_fmt = fmt;
  271. return 0;
  272. }
  273. static int uda134x_set_bias_level(struct snd_soc_codec *codec,
  274. enum snd_soc_bias_level level)
  275. {
  276. u8 reg;
  277. struct uda134x_platform_data *pd = codec->control_data;
  278. int i;
  279. u8 *cache = codec->reg_cache;
  280. pr_debug("%s bias level %d\n", __func__, level);
  281. switch (level) {
  282. case SND_SOC_BIAS_ON:
  283. /* ADC, DAC on */
  284. reg = uda134x_read_reg_cache(codec, UDA134X_STATUS1);
  285. uda134x_write(codec, UDA134X_STATUS1, reg | 0x03);
  286. break;
  287. case SND_SOC_BIAS_PREPARE:
  288. /* power on */
  289. if (pd->power) {
  290. pd->power(1);
  291. /* Sync reg_cache with the hardware */
  292. for (i = 0; i < ARRAY_SIZE(uda134x_reg); i++)
  293. codec->write(codec, i, *cache++);
  294. }
  295. break;
  296. case SND_SOC_BIAS_STANDBY:
  297. /* ADC, DAC power off */
  298. reg = uda134x_read_reg_cache(codec, UDA134X_STATUS1);
  299. uda134x_write(codec, UDA134X_STATUS1, reg & ~(0x03));
  300. break;
  301. case SND_SOC_BIAS_OFF:
  302. /* power off */
  303. if (pd->power)
  304. pd->power(0);
  305. break;
  306. }
  307. codec->bias_level = level;
  308. return 0;
  309. }
  310. static const char *uda134x_dsp_setting[] = {"Flat", "Minimum1",
  311. "Minimum2", "Maximum"};
  312. static const char *uda134x_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
  313. static const char *uda134x_mixmode[] = {"Differential", "Analog1",
  314. "Analog2", "Both"};
  315. static const struct soc_enum uda134x_mixer_enum[] = {
  316. SOC_ENUM_SINGLE(UDA134X_DATA010, 0, 0x04, uda134x_dsp_setting),
  317. SOC_ENUM_SINGLE(UDA134X_DATA010, 3, 0x04, uda134x_deemph),
  318. SOC_ENUM_SINGLE(UDA134X_EA010, 0, 0x04, uda134x_mixmode),
  319. };
  320. static const struct snd_kcontrol_new uda1341_snd_controls[] = {
  321. SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),
  322. SOC_SINGLE("Capture Volume", UDA134X_EA010, 2, 0x07, 0),
  323. SOC_SINGLE("Analog1 Volume", UDA134X_EA000, 0, 0x1F, 1),
  324. SOC_SINGLE("Analog2 Volume", UDA134X_EA001, 0, 0x1F, 1),
  325. SOC_SINGLE("Mic Sensitivity", UDA134X_EA010, 2, 7, 0),
  326. SOC_SINGLE("Mic Volume", UDA134X_EA101, 0, 0x1F, 0),
  327. SOC_SINGLE("Tone Control - Bass", UDA134X_DATA001, 2, 0xF, 0),
  328. SOC_SINGLE("Tone Control - Treble", UDA134X_DATA001, 0, 3, 0),
  329. SOC_ENUM("Sound Processing Filter", uda134x_mixer_enum[0]),
  330. SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
  331. SOC_ENUM("Input Mux", uda134x_mixer_enum[2]),
  332. SOC_SINGLE("AGC Switch", UDA134X_EA100, 4, 1, 0),
  333. SOC_SINGLE("AGC Target Volume", UDA134X_EA110, 0, 0x03, 1),
  334. SOC_SINGLE("AGC Timing", UDA134X_EA110, 2, 0x07, 0),
  335. SOC_SINGLE("DAC +6dB Switch", UDA134X_STATUS1, 6, 1, 0),
  336. SOC_SINGLE("ADC +6dB Switch", UDA134X_STATUS1, 5, 1, 0),
  337. SOC_SINGLE("ADC Polarity Switch", UDA134X_STATUS1, 4, 1, 0),
  338. SOC_SINGLE("DAC Polarity Switch", UDA134X_STATUS1, 3, 1, 0),
  339. SOC_SINGLE("Double Speed Playback Switch", UDA134X_STATUS1, 2, 1, 0),
  340. SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
  341. };
  342. static const struct snd_kcontrol_new uda1340_snd_controls[] = {
  343. SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),
  344. SOC_SINGLE("Tone Control - Bass", UDA134X_DATA001, 2, 0xF, 0),
  345. SOC_SINGLE("Tone Control - Treble", UDA134X_DATA001, 0, 3, 0),
  346. SOC_ENUM("Sound Processing Filter", uda134x_mixer_enum[0]),
  347. SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
  348. SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
  349. };
  350. static const struct snd_kcontrol_new uda1345_snd_controls[] = {
  351. SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),
  352. SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
  353. SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
  354. };
  355. static struct snd_soc_dai_ops uda134x_dai_ops = {
  356. .startup = uda134x_startup,
  357. .shutdown = uda134x_shutdown,
  358. .hw_params = uda134x_hw_params,
  359. .digital_mute = uda134x_mute,
  360. .set_sysclk = uda134x_set_dai_sysclk,
  361. .set_fmt = uda134x_set_dai_fmt,
  362. };
  363. struct snd_soc_dai uda134x_dai = {
  364. .name = "UDA134X",
  365. /* playback capabilities */
  366. .playback = {
  367. .stream_name = "Playback",
  368. .channels_min = 1,
  369. .channels_max = 2,
  370. .rates = UDA134X_RATES,
  371. .formats = UDA134X_FORMATS,
  372. },
  373. /* capture capabilities */
  374. .capture = {
  375. .stream_name = "Capture",
  376. .channels_min = 1,
  377. .channels_max = 2,
  378. .rates = UDA134X_RATES,
  379. .formats = UDA134X_FORMATS,
  380. },
  381. /* pcm operations */
  382. .ops = &uda134x_dai_ops,
  383. };
  384. EXPORT_SYMBOL(uda134x_dai);
  385. static int uda134x_soc_probe(struct platform_device *pdev)
  386. {
  387. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  388. struct snd_soc_codec *codec;
  389. struct uda134x_priv *uda134x;
  390. void *codec_setup_data = socdev->codec_data;
  391. int ret = -ENOMEM;
  392. struct uda134x_platform_data *pd;
  393. printk(KERN_INFO "UDA134X SoC Audio Codec\n");
  394. if (!codec_setup_data) {
  395. printk(KERN_ERR "UDA134X SoC codec: "
  396. "missing L3 bitbang function\n");
  397. return -ENODEV;
  398. }
  399. pd = codec_setup_data;
  400. switch (pd->model) {
  401. case UDA134X_UDA1340:
  402. case UDA134X_UDA1341:
  403. case UDA134X_UDA1344:
  404. case UDA134X_UDA1345:
  405. break;
  406. default:
  407. printk(KERN_ERR "UDA134X SoC codec: "
  408. "unsupported model %d\n",
  409. pd->model);
  410. return -EINVAL;
  411. }
  412. socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  413. if (socdev->card->codec == NULL)
  414. return ret;
  415. codec = socdev->card->codec;
  416. uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL);
  417. if (uda134x == NULL)
  418. goto priv_err;
  419. snd_soc_codec_set_drvdata(codec, uda134x);
  420. codec->reg_cache = kmemdup(uda134x_reg, sizeof(uda134x_reg),
  421. GFP_KERNEL);
  422. if (codec->reg_cache == NULL)
  423. goto reg_err;
  424. mutex_init(&codec->mutex);
  425. codec->reg_cache_size = sizeof(uda134x_reg);
  426. codec->reg_cache_step = 1;
  427. codec->name = "UDA134X";
  428. codec->owner = THIS_MODULE;
  429. codec->dai = &uda134x_dai;
  430. codec->num_dai = 1;
  431. codec->read = uda134x_read_reg_cache;
  432. codec->write = uda134x_write;
  433. INIT_LIST_HEAD(&codec->dapm_widgets);
  434. INIT_LIST_HEAD(&codec->dapm_paths);
  435. codec->control_data = codec_setup_data;
  436. if (pd->power)
  437. pd->power(1);
  438. uda134x_reset(codec);
  439. if (pd->is_powered_on_standby) {
  440. codec->set_bias_level = NULL;
  441. uda134x_set_bias_level(codec, SND_SOC_BIAS_ON);
  442. } else {
  443. codec->set_bias_level = uda134x_set_bias_level;
  444. uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  445. }
  446. /* register pcms */
  447. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  448. if (ret < 0) {
  449. printk(KERN_ERR "UDA134X: failed to register pcms\n");
  450. goto pcm_err;
  451. }
  452. switch (pd->model) {
  453. case UDA134X_UDA1340:
  454. case UDA134X_UDA1344:
  455. ret = snd_soc_add_controls(codec, uda1340_snd_controls,
  456. ARRAY_SIZE(uda1340_snd_controls));
  457. break;
  458. case UDA134X_UDA1341:
  459. ret = snd_soc_add_controls(codec, uda1341_snd_controls,
  460. ARRAY_SIZE(uda1341_snd_controls));
  461. break;
  462. case UDA134X_UDA1345:
  463. ret = snd_soc_add_controls(codec, uda1345_snd_controls,
  464. ARRAY_SIZE(uda1345_snd_controls));
  465. break;
  466. default:
  467. printk(KERN_ERR "%s unknown codec type: %d",
  468. __func__, pd->model);
  469. return -EINVAL;
  470. }
  471. if (ret < 0) {
  472. printk(KERN_ERR "UDA134X: failed to register controls\n");
  473. goto pcm_err;
  474. }
  475. return 0;
  476. pcm_err:
  477. kfree(codec->reg_cache);
  478. reg_err:
  479. kfree(snd_soc_codec_get_drvdata(codec));
  480. priv_err:
  481. kfree(codec);
  482. return ret;
  483. }
  484. /* power down chip */
  485. static int uda134x_soc_remove(struct platform_device *pdev)
  486. {
  487. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  488. struct snd_soc_codec *codec = socdev->card->codec;
  489. uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  490. uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  491. snd_soc_free_pcms(socdev);
  492. snd_soc_dapm_free(socdev);
  493. kfree(snd_soc_codec_get_drvdata(codec));
  494. kfree(codec->reg_cache);
  495. kfree(codec);
  496. return 0;
  497. }
  498. #if defined(CONFIG_PM)
  499. static int uda134x_soc_suspend(struct platform_device *pdev,
  500. pm_message_t state)
  501. {
  502. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  503. struct snd_soc_codec *codec = socdev->card->codec;
  504. uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  505. uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  506. return 0;
  507. }
  508. static int uda134x_soc_resume(struct platform_device *pdev)
  509. {
  510. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  511. struct snd_soc_codec *codec = socdev->card->codec;
  512. uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
  513. uda134x_set_bias_level(codec, SND_SOC_BIAS_ON);
  514. return 0;
  515. }
  516. #else
  517. #define uda134x_soc_suspend NULL
  518. #define uda134x_soc_resume NULL
  519. #endif /* CONFIG_PM */
  520. struct snd_soc_codec_device soc_codec_dev_uda134x = {
  521. .probe = uda134x_soc_probe,
  522. .remove = uda134x_soc_remove,
  523. .suspend = uda134x_soc_suspend,
  524. .resume = uda134x_soc_resume,
  525. };
  526. EXPORT_SYMBOL_GPL(soc_codec_dev_uda134x);
  527. static int __init uda134x_init(void)
  528. {
  529. return snd_soc_register_dai(&uda134x_dai);
  530. }
  531. module_init(uda134x_init);
  532. static void __exit uda134x_exit(void)
  533. {
  534. snd_soc_unregister_dai(&uda134x_dai);
  535. }
  536. module_exit(uda134x_exit);
  537. MODULE_DESCRIPTION("UDA134X ALSA soc codec driver");
  538. MODULE_AUTHOR("Zoltan Devai, Christian Pellegrin <chripell@evolware.org>");
  539. MODULE_LICENSE("GPL");