aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/fsl/eukrea-tlv320.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/fsl/eukrea-tlv320.c')
-rw-r--r--sound/soc/fsl/eukrea-tlv320.c108
1 files changed, 96 insertions, 12 deletions
diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index 5983740be123..eb093d5b85c4 100644
--- a/sound/soc/fsl/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -15,8 +15,11 @@
15 * 15 *
16 */ 16 */
17 17
18#include <linux/errno.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
21#include <linux/of.h>
22#include <linux/of_platform.h>
20#include <linux/device.h> 23#include <linux/device.h>
21#include <linux/i2c.h> 24#include <linux/i2c.h>
22#include <sound/core.h> 25#include <sound/core.h>
@@ -26,6 +29,7 @@
26 29
27#include "../codecs/tlv320aic23.h" 30#include "../codecs/tlv320aic23.h"
28#include "imx-ssi.h" 31#include "imx-ssi.h"
32#include "fsl_ssi.h"
29#include "imx-audmux.h" 33#include "imx-audmux.h"
30 34
31#define CODEC_CLOCK 12000000 35#define CODEC_CLOCK 12000000
@@ -41,7 +45,8 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
41 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | 45 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
42 SND_SOC_DAIFMT_NB_NF | 46 SND_SOC_DAIFMT_NB_NF |
43 SND_SOC_DAIFMT_CBM_CFM); 47 SND_SOC_DAIFMT_CBM_CFM);
44 if (ret) { 48 /* fsl_ssi lacks the set_fmt ops. */
49 if (ret && ret != -ENOTSUPP) {
45 dev_err(cpu_dai->dev, 50 dev_err(cpu_dai->dev,
46 "Failed to set the cpu dai format.\n"); 51 "Failed to set the cpu dai format.\n");
47 return ret; 52 return ret;
@@ -63,11 +68,13 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
63 "Failed to set the codec sysclk.\n"); 68 "Failed to set the codec sysclk.\n");
64 return ret; 69 return ret;
65 } 70 }
71
66 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0); 72 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
67 73
68 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, 74 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
69 SND_SOC_CLOCK_IN); 75 SND_SOC_CLOCK_IN);
70 if (ret) { 76 /* fsl_ssi lacks the set_sysclk ops */
77 if (ret && ret != -EINVAL) {
71 dev_err(cpu_dai->dev, 78 dev_err(cpu_dai->dev,
72 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n"); 79 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
73 return ret; 80 return ret;
@@ -84,14 +91,10 @@ static struct snd_soc_dai_link eukrea_tlv320_dai = {
84 .name = "tlv320aic23", 91 .name = "tlv320aic23",
85 .stream_name = "TLV320AIC23", 92 .stream_name = "TLV320AIC23",
86 .codec_dai_name = "tlv320aic23-hifi", 93 .codec_dai_name = "tlv320aic23-hifi",
87 .platform_name = "imx-ssi.0",
88 .codec_name = "tlv320aic23-codec.0-001a",
89 .cpu_dai_name = "imx-ssi.0",
90 .ops = &eukrea_tlv320_snd_ops, 94 .ops = &eukrea_tlv320_snd_ops,
91}; 95};
92 96
93static struct snd_soc_card eukrea_tlv320 = { 97static struct snd_soc_card eukrea_tlv320 = {
94 .name = "cpuimx-audio",
95 .owner = THIS_MODULE, 98 .owner = THIS_MODULE,
96 .dai_link = &eukrea_tlv320_dai, 99 .dai_link = &eukrea_tlv320_dai,
97 .num_links = 1, 100 .num_links = 1,
@@ -101,8 +104,65 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
101{ 104{
102 int ret; 105 int ret;
103 int int_port = 0, ext_port; 106 int int_port = 0, ext_port;
107 struct device_node *np = pdev->dev.of_node;
108 struct device_node *ssi_np, *codec_np;
104 109
105 if (machine_is_eukrea_cpuimx27()) { 110 eukrea_tlv320.dev = &pdev->dev;
111 if (np) {
112 ret = snd_soc_of_parse_card_name(&eukrea_tlv320,
113 "eukrea,model");
114 if (ret) {
115 dev_err(&pdev->dev,
116 "eukrea,model node missing or invalid.\n");
117 goto err;
118 }
119
120 ssi_np = of_parse_phandle(pdev->dev.of_node,
121 "ssi-controller", 0);
122 if (!ssi_np) {
123 dev_err(&pdev->dev,
124 "ssi-controller missing or invalid.\n");
125 ret = -ENODEV;
126 goto err;
127 }
128
129 codec_np = of_parse_phandle(ssi_np, "codec-handle", 0);
130 if (codec_np)
131 eukrea_tlv320_dai.codec_of_node = codec_np;
132 else
133 dev_err(&pdev->dev, "codec-handle node missing or invalid.\n");
134
135 ret = of_property_read_u32(np, "fsl,mux-int-port", &int_port);
136 if (ret) {
137 dev_err(&pdev->dev,
138 "fsl,mux-int-port node missing or invalid.\n");
139 return ret;
140 }
141 ret = of_property_read_u32(np, "fsl,mux-ext-port", &ext_port);
142 if (ret) {
143 dev_err(&pdev->dev,
144 "fsl,mux-ext-port node missing or invalid.\n");
145 return ret;
146 }
147
148 /*
149 * The port numbering in the hardware manual starts at 1, while
150 * the audmux API expects it starts at 0.
151 */
152 int_port--;
153 ext_port--;
154
155 eukrea_tlv320_dai.cpu_of_node = ssi_np;
156 eukrea_tlv320_dai.platform_of_node = ssi_np;
157 } else {
158 eukrea_tlv320_dai.cpu_dai_name = "imx-ssi.0";
159 eukrea_tlv320_dai.platform_name = "imx-ssi.0";
160 eukrea_tlv320_dai.codec_name = "tlv320aic23-codec.0-001a";
161 eukrea_tlv320.name = "cpuimx-audio";
162 }
163
164 if (machine_is_eukrea_cpuimx27() ||
165 of_find_compatible_node(NULL, NULL, "fsl,imx21-audmux")) {
106 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, 166 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
107 IMX_AUDMUX_V1_PCR_SYN | 167 IMX_AUDMUX_V1_PCR_SYN |
108 IMX_AUDMUX_V1_PCR_TFSDIR | 168 IMX_AUDMUX_V1_PCR_TFSDIR |
@@ -119,8 +179,12 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
119 ); 179 );
120 } else if (machine_is_eukrea_cpuimx25sd() || 180 } else if (machine_is_eukrea_cpuimx25sd() ||
121 machine_is_eukrea_cpuimx35sd() || 181 machine_is_eukrea_cpuimx35sd() ||
122 machine_is_eukrea_cpuimx51sd()) { 182 machine_is_eukrea_cpuimx51sd() ||
123 ext_port = machine_is_eukrea_cpuimx25sd() ? 4 : 3; 183 of_find_compatible_node(NULL, NULL, "fsl,imx31-audmux")) {
184 if (!np)
185 ext_port = machine_is_eukrea_cpuimx25sd() ?
186 4 : 3;
187
124 imx_audmux_v2_configure_port(int_port, 188 imx_audmux_v2_configure_port(int_port,
125 IMX_AUDMUX_V2_PTCR_SYN | 189 IMX_AUDMUX_V2_PTCR_SYN |
126 IMX_AUDMUX_V2_PTCR_TFSDIR | 190 IMX_AUDMUX_V2_PTCR_TFSDIR |
@@ -134,14 +198,27 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
134 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port) 198 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)
135 ); 199 );
136 } else { 200 } else {
137 /* return happy. We might run on a totally different machine */ 201 if (np) {
138 return 0; 202 /* The eukrea,asoc-tlv320 driver was explicitely
203 * requested (through the device tree).
204 */
205 dev_err(&pdev->dev,
206 "Missing or invalid audmux DT node.\n");
207 return -ENODEV;
208 } else {
209 /* Return happy.
210 * We might run on a totally different machine.
211 */
212 return 0;
213 }
139 } 214 }
140 215
141 eukrea_tlv320.dev = &pdev->dev;
142 ret = snd_soc_register_card(&eukrea_tlv320); 216 ret = snd_soc_register_card(&eukrea_tlv320);
217err:
143 if (ret) 218 if (ret)
144 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); 219 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
220 if (np)
221 of_node_put(ssi_np);
145 222
146 return ret; 223 return ret;
147} 224}
@@ -153,10 +230,17 @@ static int eukrea_tlv320_remove(struct platform_device *pdev)
153 return 0; 230 return 0;
154} 231}
155 232
233static const struct of_device_id imx_tlv320_dt_ids[] = {
234 { .compatible = "eukrea,asoc-tlv320"},
235 { /* sentinel */ }
236};
237MODULE_DEVICE_TABLE(of, imx_tlv320_dt_ids);
238
156static struct platform_driver eukrea_tlv320_driver = { 239static struct platform_driver eukrea_tlv320_driver = {
157 .driver = { 240 .driver = {
158 .name = "eukrea_tlv320", 241 .name = "eukrea_tlv320",
159 .owner = THIS_MODULE, 242 .owner = THIS_MODULE,
243 .of_match_table = imx_tlv320_dt_ids,
160 }, 244 },
161 .probe = eukrea_tlv320_probe, 245 .probe = eukrea_tlv320_probe,
162 .remove = eukrea_tlv320_remove, 246 .remove = eukrea_tlv320_remove,