uda134x.c 17 KB

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