1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*
* Copyright (C) 2008-2013 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
#include <linux/module.h>
#include <linux/of_platform.h>
#include <sound/soc.h>
#include "imx-audmux.h"
static int imx_audmux_config(int slave, int master)
{
unsigned int ptcr, pdcr;
slave = slave - 1;
master = master - 1;
ptcr = IMX_AUDMUX_V2_PTCR_SYN |
IMX_AUDMUX_V2_PTCR_TFSDIR |
IMX_AUDMUX_V2_PTCR_TFSEL(slave) |
IMX_AUDMUX_V2_PTCR_TCLKDIR |
IMX_AUDMUX_V2_PTCR_TCSEL(slave);
pdcr = IMX_AUDMUX_V2_PDCR_RXDSEL(slave);
imx_audmux_v2_configure_port(master, ptcr, pdcr);
ptcr = IMX_AUDMUX_V2_PTCR_SYN;
pdcr = IMX_AUDMUX_V2_PDCR_RXDSEL(master);
imx_audmux_v2_configure_port(slave, ptcr, pdcr);
return 0;
}
static int imx_si476x_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
u32 channels = params_channels(params);
u32 rate = params_rate(params);
u32 bclk = rate * channels * 32;
int ret = 0;
/* set cpu DAI configuration */
ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
if (ret) {
dev_err(cpu_dai->dev, "failed to set dai fmt\n");
return ret;
}
ret = snd_soc_dai_set_tdm_slot(cpu_dai,
channels == 1 ? 0xfffffffe : 0xfffffffc,
channels == 1 ? 0xfffffffe : 0xfffffffc,
2, 32);
if (ret) {
dev_err(cpu_dai->dev, "failed to set dai tdm slot\n");
return ret;
}
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, bclk, SND_SOC_CLOCK_OUT);
if (ret)
dev_err(cpu_dai->dev, "failed to set sysclk\n");
return ret;
}
static struct snd_soc_ops imx_si476x_ops = {
.hw_params = imx_si476x_hw_params,
};
static struct snd_soc_dai_link imx_dai = {
.name = "imx-si476x",
.stream_name = "imx-si476x",
.codec_dai_name = "si476x-codec",
.codec_name = "si476x-codec.99",
.ops = &imx_si476x_ops,
};
static struct snd_soc_card snd_soc_card_imx_3stack = {
.name = "imx-audio-si476x",
.dai_link = &imx_dai,
.num_links = 1,
};
static int imx_si476x_probe(struct platform_device *pdev)
{
struct snd_soc_card *card = &snd_soc_card_imx_3stack;
struct device_node *ssi_np, *np = pdev->dev.of_node;
struct platform_device *ssi_pdev;
int int_port, ext_port, ret;
ret = of_property_read_u32(np, "mux-int-port", &int_port);
if (ret) {
dev_err(&pdev->dev, "mux-int-port missing or invalid\n");
return ret;
}
ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
if (ret) {
dev_err(&pdev->dev, "mux-ext-port missing or invalid\n");
return ret;
}
imx_audmux_config(int_port, ext_port);
ssi_np = of_parse_phandle(pdev->dev.of_node, "ssi-controller", 0);
if (!ssi_np) {
dev_err(&pdev->dev, "phandle missing or invalid\n");
return -EINVAL;
}
ssi_pdev = of_find_device_by_node(ssi_np);
if (!ssi_pdev) {
dev_err(&pdev->dev, "failed to find SSI platform device\n");
ret = -EINVAL;
goto end;
}
card->dev = &pdev->dev;
card->dai_link->cpu_dai_name = dev_name(&ssi_pdev->dev);
card->dai_link->platform_of_node = ssi_np;
platform_set_drvdata(pdev, card);
ret = snd_soc_register_card(card);
if (ret)
dev_err(&pdev->dev, "Failed to register card: %d\n", ret);
end:
if (ssi_np)
of_node_put(ssi_np);
return ret;
}
static int imx_si476x_remove(struct platform_device *pdev)
{
struct snd_soc_card *card = &snd_soc_card_imx_3stack;
snd_soc_unregister_card(card);
return 0;
}
static const struct of_device_id imx_si476x_dt_ids[] = {
{ .compatible = "fsl,imx-audio-si476x", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, imx_si476x_dt_ids);
static struct platform_driver imx_si476x_driver = {
.driver = {
.name = "imx-tuner-si476x",
.owner = THIS_MODULE,
.pm = &snd_soc_pm_ops,
.of_match_table = imx_si476x_dt_ids,
},
.probe = imx_si476x_probe,
.remove = imx_si476x_remove,
};
module_platform_driver(imx_si476x_driver);
/* Module information */
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("ALSA SoC i.MX si476x");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:imx-tuner-si476x");
|