Commit | Line | Data |
---|---|---|
86c33041 AS |
1 | /* |
2 | * SoC audio for EDB93xx | |
3 | * | |
4 | * Copyright (c) 2010 Alexander Sverdlin <subaparts@yandex.ru> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * This driver support CS4271 codec being master or slave, working | |
17 | * in control port mode, connected either via SPI or I2C. | |
18 | * The data format accepted is I2S or left-justified. | |
19 | * DAPM support not implemented. | |
20 | */ | |
21 | ||
22 | #include <linux/platform_device.h> | |
23 | #include <linux/gpio.h> | |
24 | #include <sound/core.h> | |
25 | #include <sound/pcm.h> | |
26 | #include <sound/soc.h> | |
27 | #include <asm/mach-types.h> | |
28 | #include <mach/hardware.h> | |
29 | #include "ep93xx-pcm.h" | |
30 | ||
86c33041 AS |
31 | static int edb93xx_hw_params(struct snd_pcm_substream *substream, |
32 | struct snd_pcm_hw_params *params) | |
33 | { | |
34 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
35 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
36 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
37 | int err; | |
6d33cd77 | 38 | unsigned int mclk_rate; |
86c33041 | 39 | unsigned int rate = params_rate(params); |
6d33cd77 | 40 | |
86c33041 | 41 | /* |
6d33cd77 AS |
42 | * According to CS4271 datasheet we use MCLK/LRCK=256 for |
43 | * rates below 50kHz and 128 for higher sample rates | |
86c33041 | 44 | */ |
6d33cd77 AS |
45 | if (rate < 50000) |
46 | mclk_rate = rate * 64 * 4; | |
47 | else | |
48 | mclk_rate = rate * 64 * 2; | |
86c33041 AS |
49 | |
50 | err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | |
51 | SND_SOC_DAIFMT_NB_IF | | |
52 | SND_SOC_DAIFMT_CBS_CFS); | |
53 | if (err) | |
54 | return err; | |
55 | ||
56 | err = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | | |
57 | SND_SOC_DAIFMT_NB_IF | | |
58 | SND_SOC_DAIFMT_CBS_CFS); | |
59 | if (err) | |
60 | return err; | |
61 | ||
62 | err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate, | |
63 | SND_SOC_CLOCK_IN); | |
64 | if (err) | |
65 | return err; | |
66 | ||
67 | return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate, | |
68 | SND_SOC_CLOCK_OUT); | |
69 | } | |
70 | ||
71 | static struct snd_soc_ops edb93xx_ops = { | |
72 | .hw_params = edb93xx_hw_params, | |
73 | }; | |
74 | ||
75 | static struct snd_soc_dai_link edb93xx_dai = { | |
76 | .name = "CS4271", | |
77 | .stream_name = "CS4271 HiFi", | |
78 | .platform_name = "ep93xx-pcm-audio", | |
79 | .cpu_dai_name = "ep93xx-i2s", | |
80 | .codec_name = "spi0.0", | |
81 | .codec_dai_name = "cs4271-hifi", | |
82 | .ops = &edb93xx_ops, | |
83 | }; | |
84 | ||
85 | static struct snd_soc_card snd_soc_edb93xx = { | |
86 | .name = "EDB93XX", | |
87 | .dai_link = &edb93xx_dai, | |
88 | .num_links = 1, | |
89 | }; | |
90 | ||
8a386ca2 | 91 | static int __devinit edb93xx_probe(struct platform_device *pdev) |
86c33041 | 92 | { |
8a386ca2 | 93 | struct snd_soc_card *card = &snd_soc_edb93xx; |
86c33041 AS |
94 | int ret; |
95 | ||
86c33041 AS |
96 | ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97, |
97 | EP93XX_SYSCON_I2SCLKDIV_ORIDE | | |
98 | EP93XX_SYSCON_I2SCLKDIV_SPOL); | |
99 | if (ret) | |
100 | return ret; | |
101 | ||
8a386ca2 MW |
102 | card->dev = &pdev->dev; |
103 | ||
104 | ret = snd_soc_register_card(card); | |
105 | if (ret) { | |
106 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", | |
107 | ret); | |
108 | ep93xx_i2s_release(); | |
86c33041 AS |
109 | } |
110 | ||
8a386ca2 MW |
111 | return ret; |
112 | } | |
86c33041 | 113 | |
8a386ca2 MW |
114 | static int __devexit edb93xx_remove(struct platform_device *pdev) |
115 | { | |
116 | struct snd_soc_card *card = platform_get_drvdata(pdev); | |
86c33041 | 117 | |
8a386ca2 | 118 | snd_soc_unregister_card(card); |
86c33041 | 119 | ep93xx_i2s_release(); |
8a386ca2 MW |
120 | |
121 | return 0; | |
122 | } | |
123 | ||
124 | static struct platform_driver edb93xx_driver = { | |
125 | .driver = { | |
126 | .name = "edb93xx-audio", | |
127 | .owner = THIS_MODULE, | |
128 | }, | |
129 | .probe = edb93xx_probe, | |
130 | .remove = __devexit_p(edb93xx_remove), | |
131 | }; | |
132 | ||
133 | static int __init edb93xx_init(void) | |
134 | { | |
135 | return platform_driver_register(&edb93xx_driver); | |
86c33041 AS |
136 | } |
137 | module_init(edb93xx_init); | |
138 | ||
139 | static void __exit edb93xx_exit(void) | |
140 | { | |
8a386ca2 | 141 | platform_driver_unregister(&edb93xx_driver); |
86c33041 AS |
142 | } |
143 | module_exit(edb93xx_exit); | |
144 | ||
145 | MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>"); | |
146 | MODULE_DESCRIPTION("ALSA SoC EDB93xx"); | |
147 | MODULE_LICENSE("GPL"); | |
8a386ca2 | 148 | MODULE_ALIAS("platform:edb93xx-audio"); |