uda134x.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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, 0xC0, 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. case UDA134X_DATA011:
  91. addr = UDA134X_DATA0_ADDR;
  92. break;
  93. case UDA134X_DATA1:
  94. addr = UDA134X_DATA1_ADDR;
  95. break;
  96. default:
  97. /* It's an extended address register */
  98. addr = (reg | UDA134X_EXTADDR_PREFIX);
  99. ret = l3_write(&pd->l3,
  100. UDA134X_DATA0_ADDR, &addr, 1);
  101. if (ret != 1)
  102. return -EIO;
  103. addr = UDA134X_DATA0_ADDR;
  104. data = (value | UDA134X_EXTDATA_PREFIX);
  105. break;
  106. }
  107. ret = l3_write(&pd->l3,
  108. addr, &data, 1);
  109. if (ret != 1)
  110. return -EIO;
  111. return 0;
  112. }
  113. static inline void uda134x_reset(struct snd_soc_codec *codec)
  114. {
  115. u8 reset_reg = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
  116. uda134x_write(codec, UDA134X_STATUS0, reset_reg | (1<<6));
  117. msleep(1);
  118. uda134x_write(codec, UDA134X_STATUS0, reset_reg & ~(1<<6));
  119. }
  120. static int uda134x_mute(struct snd_soc_dai *dai, int mute)
  121. {
  122. struct snd_soc_codec *codec = dai->codec;
  123. u8 mute_reg = uda134x_read_reg_cache(codec, UDA134X_DATA010);
  124. pr_debug("%s mute: %d\n", __func__, mute);
  125. if (mute)
  126. mute_reg |= (1<<2);
  127. else
  128. mute_reg &= ~(1<<2);
  129. uda134x_write(codec, UDA134X_DATA010, mute_reg);
  130. return 0;
  131. }
  132. static int uda134x_startup(struct snd_pcm_substream *substream,
  133. struct snd_soc_dai *dai)
  134. {
  135. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  136. struct snd_soc_codec *codec =rtd->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_codec *codec = rtd->codec;
  162. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  163. if (uda134x->master_substream == substream)
  164. uda134x->master_substream = uda134x->slave_substream;
  165. uda134x->slave_substream = NULL;
  166. }
  167. static int uda134x_hw_params(struct snd_pcm_substream *substream,
  168. struct snd_pcm_hw_params *params,
  169. struct snd_soc_dai *dai)
  170. {
  171. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  172. struct snd_soc_codec *codec = rtd->codec;
  173. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  174. u8 hw_params;
  175. if (substream == uda134x->slave_substream) {
  176. pr_debug("%s ignoring hw_params for slave substream\n",
  177. __func__);
  178. return 0;
  179. }
  180. hw_params = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
  181. hw_params &= STATUS0_SYSCLK_MASK;
  182. hw_params &= STATUS0_DAIFMT_MASK;
  183. pr_debug("%s sysclk: %d, rate:%d\n", __func__,
  184. uda134x->sysclk, params_rate(params));
  185. /* set SYSCLK / fs ratio */
  186. switch (uda134x->sysclk / params_rate(params)) {
  187. case 512:
  188. break;
  189. case 384:
  190. hw_params |= (1<<4);
  191. break;
  192. case 256:
  193. hw_params |= (1<<5);
  194. break;
  195. default:
  196. printk(KERN_ERR "%s unsupported fs\n", __func__);
  197. return -EINVAL;
  198. }
  199. pr_debug("%s dai_fmt: %d, params_format:%d\n", __func__,
  200. uda134x->dai_fmt, params_format(params));
  201. /* set DAI format and word length */
  202. switch (uda134x->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  203. case SND_SOC_DAIFMT_I2S:
  204. break;
  205. case SND_SOC_DAIFMT_RIGHT_J:
  206. switch (params_format(params)) {
  207. case SNDRV_PCM_FORMAT_S16_LE:
  208. hw_params |= (1<<1);
  209. break;
  210. case SNDRV_PCM_FORMAT_S18_3LE:
  211. hw_params |= (1<<2);
  212. break;
  213. case SNDRV_PCM_FORMAT_S20_3LE:
  214. hw_params |= ((1<<2) | (1<<1));
  215. break;
  216. default:
  217. printk(KERN_ERR "%s unsupported format (right)\n",
  218. __func__);
  219. return -EINVAL;
  220. }
  221. break;
  222. case SND_SOC_DAIFMT_LEFT_J:
  223. hw_params |= (1<<3);
  224. break;
  225. default:
  226. printk(KERN_ERR "%s unsupported format\n", __func__);
  227. return -EINVAL;
  228. }
  229. uda134x_write(codec, UDA134X_STATUS0, hw_params);
  230. return 0;
  231. }
  232. static int uda134x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  233. int clk_id, unsigned int freq, int dir)
  234. {
  235. struct snd_soc_codec *codec = codec_dai->codec;
  236. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  237. pr_debug("%s clk_id: %d, freq: %u, dir: %d\n", __func__,
  238. clk_id, freq, dir);
  239. /* Anything between 256fs*8Khz and 512fs*48Khz should be acceptable
  240. because the codec is slave. Of course limitations of the clock
  241. master (the IIS controller) apply.
  242. We'll error out on set_hw_params if it's not OK */
  243. if ((freq >= (256 * 8000)) && (freq <= (512 * 48000))) {
  244. uda134x->sysclk = freq;
  245. return 0;
  246. }
  247. printk(KERN_ERR "%s unsupported sysclk\n", __func__);
  248. return -EINVAL;
  249. }
  250. static int uda134x_set_dai_fmt(struct snd_soc_dai *codec_dai,
  251. unsigned int fmt)
  252. {
  253. struct snd_soc_codec *codec = codec_dai->codec;
  254. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  255. pr_debug("%s fmt: %08X\n", __func__, fmt);
  256. /* codec supports only full slave mode */
  257. if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
  258. printk(KERN_ERR "%s unsupported slave mode\n", __func__);
  259. return -EINVAL;
  260. }
  261. /* no support for clock inversion */
  262. if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) {
  263. printk(KERN_ERR "%s unsupported clock inversion\n", __func__);
  264. return -EINVAL;
  265. }
  266. /* We can't setup DAI format here as it depends on the word bit num */
  267. /* so let's just store the value for later */
  268. uda134x->dai_fmt = fmt;
  269. return 0;
  270. }
  271. static int uda134x_set_bias_level(struct snd_soc_codec *codec,
  272. enum snd_soc_bias_level level)
  273. {
  274. u8 reg;
  275. struct uda134x_platform_data *pd = codec->control_data;
  276. int i;
  277. u8 *cache = codec->reg_cache;
  278. pr_debug("%s bias level %d\n", __func__, level);
  279. switch (level) {
  280. case SND_SOC_BIAS_ON:
  281. /* ADC, DAC on */
  282. switch (pd->model) {
  283. case UDA134X_UDA1340:
  284. case UDA134X_UDA1344:
  285. case UDA134X_UDA1345:
  286. reg = uda134x_read_reg_cache(codec, UDA134X_DATA011);
  287. uda134x_write(codec, UDA134X_DATA011, reg | 0x03);
  288. break;
  289. case UDA134X_UDA1341:
  290. reg = uda134x_read_reg_cache(codec, UDA134X_STATUS1);
  291. uda134x_write(codec, UDA134X_STATUS1, reg | 0x03);
  292. break;
  293. default:
  294. printk(KERN_ERR "UDA134X SoC codec: "
  295. "unsupported model %d\n", pd->model);
  296. return -EINVAL;
  297. }
  298. break;
  299. case SND_SOC_BIAS_PREPARE:
  300. /* power on */
  301. if (pd->power) {
  302. pd->power(1);
  303. /* Sync reg_cache with the hardware */
  304. for (i = 0; i < ARRAY_SIZE(uda134x_reg); i++)
  305. codec->driver->write(codec, i, *cache++);
  306. }
  307. break;
  308. case SND_SOC_BIAS_STANDBY:
  309. /* ADC, DAC power off */
  310. switch (pd->model) {
  311. case UDA134X_UDA1340:
  312. case UDA134X_UDA1344:
  313. case UDA134X_UDA1345:
  314. reg = uda134x_read_reg_cache(codec, UDA134X_DATA011);
  315. uda134x_write(codec, UDA134X_DATA011, reg & ~(0x03));
  316. break;
  317. case UDA134X_UDA1341:
  318. reg = uda134x_read_reg_cache(codec, UDA134X_STATUS1);
  319. uda134x_write(codec, UDA134X_STATUS1, reg & ~(0x03));
  320. break;
  321. default:
  322. printk(KERN_ERR "UDA134X SoC codec: "
  323. "unsupported model %d\n", pd->model);
  324. return -EINVAL;
  325. }
  326. break;
  327. case SND_SOC_BIAS_OFF:
  328. /* power off */
  329. if (pd->power)
  330. pd->power(0);
  331. break;
  332. }
  333. codec->bias_level = level;
  334. return 0;
  335. }
  336. static const char *uda134x_dsp_setting[] = {"Flat", "Minimum1",
  337. "Minimum2", "Maximum"};
  338. static const char *uda134x_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
  339. static const char *uda134x_mixmode[] = {"Differential", "Analog1",
  340. "Analog2", "Both"};
  341. static const struct soc_enum uda134x_mixer_enum[] = {
  342. SOC_ENUM_SINGLE(UDA134X_DATA010, 0, 0x04, uda134x_dsp_setting),
  343. SOC_ENUM_SINGLE(UDA134X_DATA010, 3, 0x04, uda134x_deemph),
  344. SOC_ENUM_SINGLE(UDA134X_EA010, 0, 0x04, uda134x_mixmode),
  345. };
  346. static const struct snd_kcontrol_new uda1341_snd_controls[] = {
  347. SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),
  348. SOC_SINGLE("Capture Volume", UDA134X_EA010, 2, 0x07, 0),
  349. SOC_SINGLE("Analog1 Volume", UDA134X_EA000, 0, 0x1F, 1),
  350. SOC_SINGLE("Analog2 Volume", UDA134X_EA001, 0, 0x1F, 1),
  351. SOC_SINGLE("Mic Sensitivity", UDA134X_EA010, 2, 7, 0),
  352. SOC_SINGLE("Mic Volume", UDA134X_EA101, 0, 0x1F, 0),
  353. SOC_SINGLE("Tone Control - Bass", UDA134X_DATA001, 2, 0xF, 0),
  354. SOC_SINGLE("Tone Control - Treble", UDA134X_DATA001, 0, 3, 0),
  355. SOC_ENUM("Sound Processing Filter", uda134x_mixer_enum[0]),
  356. SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
  357. SOC_ENUM("Input Mux", uda134x_mixer_enum[2]),
  358. SOC_SINGLE("AGC Switch", UDA134X_EA100, 4, 1, 0),
  359. SOC_SINGLE("AGC Target Volume", UDA134X_EA110, 0, 0x03, 1),
  360. SOC_SINGLE("AGC Timing", UDA134X_EA110, 2, 0x07, 0),
  361. SOC_SINGLE("DAC +6dB Switch", UDA134X_STATUS1, 6, 1, 0),
  362. SOC_SINGLE("ADC +6dB Switch", UDA134X_STATUS1, 5, 1, 0),
  363. SOC_SINGLE("ADC Polarity Switch", UDA134X_STATUS1, 4, 1, 0),
  364. SOC_SINGLE("DAC Polarity Switch", UDA134X_STATUS1, 3, 1, 0),
  365. SOC_SINGLE("Double Speed Playback Switch", UDA134X_STATUS1, 2, 1, 0),
  366. SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
  367. };
  368. static const struct snd_kcontrol_new uda1340_snd_controls[] = {
  369. SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),
  370. SOC_SINGLE("Tone Control - Bass", UDA134X_DATA001, 2, 0xF, 0),
  371. SOC_SINGLE("Tone Control - Treble", UDA134X_DATA001, 0, 3, 0),
  372. SOC_ENUM("Sound Processing Filter", uda134x_mixer_enum[0]),
  373. SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
  374. SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
  375. };
  376. static const struct snd_kcontrol_new uda1345_snd_controls[] = {
  377. SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),
  378. SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
  379. SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
  380. };
  381. static struct snd_soc_dai_ops uda134x_dai_ops = {
  382. .startup = uda134x_startup,
  383. .shutdown = uda134x_shutdown,
  384. .hw_params = uda134x_hw_params,
  385. .digital_mute = uda134x_mute,
  386. .set_sysclk = uda134x_set_dai_sysclk,
  387. .set_fmt = uda134x_set_dai_fmt,
  388. };
  389. static struct snd_soc_dai_driver uda134x_dai = {
  390. .name = "uda134x-hifi",
  391. /* playback capabilities */
  392. .playback = {
  393. .stream_name = "Playback",
  394. .channels_min = 1,
  395. .channels_max = 2,
  396. .rates = UDA134X_RATES,
  397. .formats = UDA134X_FORMATS,
  398. },
  399. /* capture capabilities */
  400. .capture = {
  401. .stream_name = "Capture",
  402. .channels_min = 1,
  403. .channels_max = 2,
  404. .rates = UDA134X_RATES,
  405. .formats = UDA134X_FORMATS,
  406. },
  407. /* pcm operations */
  408. .ops = &uda134x_dai_ops,
  409. };
  410. static int uda134x_soc_probe(struct snd_soc_codec *codec)
  411. {
  412. struct uda134x_priv *uda134x;
  413. struct uda134x_platform_data *pd = dev_get_drvdata(codec->card->dev);
  414. int ret;
  415. printk(KERN_INFO "UDA134X SoC Audio Codec\n");
  416. if (!pd) {
  417. printk(KERN_ERR "UDA134X SoC codec: "
  418. "missing L3 bitbang function\n");
  419. return -ENODEV;
  420. }
  421. switch (pd->model) {
  422. case UDA134X_UDA1340:
  423. case UDA134X_UDA1341:
  424. case UDA134X_UDA1344:
  425. case UDA134X_UDA1345:
  426. break;
  427. default:
  428. printk(KERN_ERR "UDA134X SoC codec: "
  429. "unsupported model %d\n",
  430. pd->model);
  431. return -EINVAL;
  432. }
  433. uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL);
  434. if (uda134x == NULL)
  435. return -ENOMEM;
  436. snd_soc_codec_set_drvdata(codec, uda134x);
  437. codec->control_data = pd;
  438. if (pd->power)
  439. pd->power(1);
  440. uda134x_reset(codec);
  441. if (pd->is_powered_on_standby)
  442. uda134x_set_bias_level(codec, SND_SOC_BIAS_ON);
  443. else
  444. uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  445. switch (pd->model) {
  446. case UDA134X_UDA1340:
  447. case UDA134X_UDA1344:
  448. ret = snd_soc_add_controls(codec, uda1340_snd_controls,
  449. ARRAY_SIZE(uda1340_snd_controls));
  450. break;
  451. case UDA134X_UDA1341:
  452. ret = snd_soc_add_controls(codec, uda1341_snd_controls,
  453. ARRAY_SIZE(uda1341_snd_controls));
  454. break;
  455. case UDA134X_UDA1345:
  456. ret = snd_soc_add_controls(codec, uda1345_snd_controls,
  457. ARRAY_SIZE(uda1345_snd_controls));
  458. break;
  459. default:
  460. printk(KERN_ERR "%s unknown codec type: %d",
  461. __func__, pd->model);
  462. kfree(uda134x);
  463. return -EINVAL;
  464. }
  465. if (ret < 0) {
  466. printk(KERN_ERR "UDA134X: failed to register controls\n");
  467. kfree(uda134x);
  468. return ret;
  469. }
  470. return 0;
  471. }
  472. /* power down chip */
  473. static int uda134x_soc_remove(struct snd_soc_codec *codec)
  474. {
  475. struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
  476. uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  477. uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  478. kfree(uda134x);
  479. return 0;
  480. }
  481. #if defined(CONFIG_PM)
  482. static int uda134x_soc_suspend(struct snd_soc_codec *codec,
  483. pm_message_t state)
  484. {
  485. uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  486. uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  487. return 0;
  488. }
  489. static int uda134x_soc_resume(struct snd_soc_codec *codec)
  490. {
  491. uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
  492. uda134x_set_bias_level(codec, SND_SOC_BIAS_ON);
  493. return 0;
  494. }
  495. #else
  496. #define uda134x_soc_suspend NULL
  497. #define uda134x_soc_resume NULL
  498. #endif /* CONFIG_PM */
  499. static struct snd_soc_codec_driver soc_codec_dev_uda134x = {
  500. .probe = uda134x_soc_probe,
  501. .remove = uda134x_soc_remove,
  502. .suspend = uda134x_soc_suspend,
  503. .resume = uda134x_soc_resume,
  504. .reg_cache_size = sizeof(uda134x_reg),
  505. .reg_word_size = sizeof(u8),
  506. .reg_cache_default = uda134x_reg,
  507. .reg_cache_step = 1,
  508. .read = uda134x_read_reg_cache,
  509. .write = uda134x_write,
  510. #ifdef POWER_OFF_ON_STANDBY
  511. .set_bias_level = uda134x_set_bias_level,
  512. #endif
  513. };
  514. static int __devinit uda134x_codec_probe(struct platform_device *pdev)
  515. {
  516. return snd_soc_register_codec(&pdev->dev,
  517. &soc_codec_dev_uda134x, &uda134x_dai, 1);
  518. }
  519. static int __devexit uda134x_codec_remove(struct platform_device *pdev)
  520. {
  521. snd_soc_unregister_codec(&pdev->dev);
  522. return 0;
  523. }
  524. static struct platform_driver uda134x_codec_driver = {
  525. .driver = {
  526. .name = "uda134x-codec",
  527. .owner = THIS_MODULE,
  528. },
  529. .probe = uda134x_codec_probe,
  530. .remove = __devexit_p(uda134x_codec_remove),
  531. };
  532. static int __init uda134x_codec_init(void)
  533. {
  534. return platform_driver_register(&uda134x_codec_driver);
  535. }
  536. module_init(uda134x_codec_init);
  537. static void __exit uda134x_codec_exit(void)
  538. {
  539. platform_driver_unregister(&uda134x_codec_driver);
  540. }
  541. module_exit(uda134x_codec_exit);
  542. MODULE_DESCRIPTION("UDA134X ALSA soc codec driver");
  543. MODULE_AUTHOR("Zoltan Devai, Christian Pellegrin <chripell@evolware.org>");
  544. MODULE_LICENSE("GPL");