1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun //
3*4882a593Smuzhiyun // Freescale P1022DS ALSA SoC Machine driver
4*4882a593Smuzhiyun //
5*4882a593Smuzhiyun // Author: Timur Tabi <timur@freescale.com>
6*4882a593Smuzhiyun //
7*4882a593Smuzhiyun // Copyright 2010 Freescale Semiconductor, Inc.
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/module.h>
10*4882a593Smuzhiyun #include <linux/fsl/guts.h>
11*4882a593Smuzhiyun #include <linux/interrupt.h>
12*4882a593Smuzhiyun #include <linux/of_address.h>
13*4882a593Smuzhiyun #include <linux/of_device.h>
14*4882a593Smuzhiyun #include <linux/slab.h>
15*4882a593Smuzhiyun #include <sound/soc.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include "fsl_dma.h"
18*4882a593Smuzhiyun #include "fsl_ssi.h"
19*4882a593Smuzhiyun #include "fsl_utils.h"
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun /* P1022-specific PMUXCR and DMUXCR bit definitions */
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #define CCSR_GUTS_PMUXCR_UART0_I2C1_MASK 0x0001c000
24*4882a593Smuzhiyun #define CCSR_GUTS_PMUXCR_UART0_I2C1_UART0_SSI 0x00010000
25*4882a593Smuzhiyun #define CCSR_GUTS_PMUXCR_UART0_I2C1_SSI 0x00018000
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #define CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK 0x00000c00
28*4882a593Smuzhiyun #define CCSR_GUTS_PMUXCR_SSI_DMA_TDM_SSI 0x00000000
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #define CCSR_GUTS_DMUXCR_PAD 1 /* DMA controller/channel set to pad */
31*4882a593Smuzhiyun #define CCSR_GUTS_DMUXCR_SSI 2 /* DMA controller/channel set to SSI */
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun * Set the DMACR register in the GUTS
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * The DMACR register determines the source of initiated transfers for each
37*4882a593Smuzhiyun * channel on each DMA controller. Rather than have a bunch of repetitive
38*4882a593Smuzhiyun * macros for the bit patterns, we just have a function that calculates
39*4882a593Smuzhiyun * them.
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * guts: Pointer to GUTS structure
42*4882a593Smuzhiyun * co: The DMA controller (0 or 1)
43*4882a593Smuzhiyun * ch: The channel on the DMA controller (0, 1, 2, or 3)
44*4882a593Smuzhiyun * device: The device to set as the target (CCSR_GUTS_DMUXCR_xxx)
45*4882a593Smuzhiyun */
guts_set_dmuxcr(struct ccsr_guts __iomem * guts,unsigned int co,unsigned int ch,unsigned int device)46*4882a593Smuzhiyun static inline void guts_set_dmuxcr(struct ccsr_guts __iomem *guts,
47*4882a593Smuzhiyun unsigned int co, unsigned int ch, unsigned int device)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun unsigned int shift = 16 + (8 * (1 - co) + 2 * (3 - ch));
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun clrsetbits_be32(&guts->dmuxcr, 3 << shift, device << shift);
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /* There's only one global utilities register */
55*4882a593Smuzhiyun static phys_addr_t guts_phys;
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /**
58*4882a593Smuzhiyun * machine_data: machine-specific ASoC device data
59*4882a593Smuzhiyun *
60*4882a593Smuzhiyun * This structure contains data for a single sound platform device on an
61*4882a593Smuzhiyun * P1022 DS. Some of the data is taken from the device tree.
62*4882a593Smuzhiyun */
63*4882a593Smuzhiyun struct machine_data {
64*4882a593Smuzhiyun struct snd_soc_dai_link dai[2];
65*4882a593Smuzhiyun struct snd_soc_card card;
66*4882a593Smuzhiyun unsigned int dai_format;
67*4882a593Smuzhiyun unsigned int codec_clk_direction;
68*4882a593Smuzhiyun unsigned int cpu_clk_direction;
69*4882a593Smuzhiyun unsigned int clk_frequency;
70*4882a593Smuzhiyun unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */
71*4882a593Smuzhiyun unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */
72*4882a593Smuzhiyun unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
73*4882a593Smuzhiyun char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /**
77*4882a593Smuzhiyun * p1022_ds_machine_probe: initialize the board
78*4882a593Smuzhiyun *
79*4882a593Smuzhiyun * This function is used to initialize the board-specific hardware.
80*4882a593Smuzhiyun *
81*4882a593Smuzhiyun * Here we program the DMACR and PMUXCR registers.
82*4882a593Smuzhiyun */
p1022_ds_machine_probe(struct snd_soc_card * card)83*4882a593Smuzhiyun static int p1022_ds_machine_probe(struct snd_soc_card *card)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun struct machine_data *mdata =
86*4882a593Smuzhiyun container_of(card, struct machine_data, card);
87*4882a593Smuzhiyun struct ccsr_guts __iomem *guts;
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
90*4882a593Smuzhiyun if (!guts) {
91*4882a593Smuzhiyun dev_err(card->dev, "could not map global utilities\n");
92*4882a593Smuzhiyun return -ENOMEM;
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /* Enable SSI Tx signal */
96*4882a593Smuzhiyun clrsetbits_be32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_UART0_I2C1_MASK,
97*4882a593Smuzhiyun CCSR_GUTS_PMUXCR_UART0_I2C1_UART0_SSI);
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /* Enable SSI Rx signal */
100*4882a593Smuzhiyun clrsetbits_be32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK,
101*4882a593Smuzhiyun CCSR_GUTS_PMUXCR_SSI_DMA_TDM_SSI);
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /* Enable DMA Channel for SSI */
104*4882a593Smuzhiyun guts_set_dmuxcr(guts, mdata->dma_id[0], mdata->dma_channel_id[0],
105*4882a593Smuzhiyun CCSR_GUTS_DMUXCR_SSI);
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun guts_set_dmuxcr(guts, mdata->dma_id[1], mdata->dma_channel_id[1],
108*4882a593Smuzhiyun CCSR_GUTS_DMUXCR_SSI);
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun iounmap(guts);
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun return 0;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /**
116*4882a593Smuzhiyun * p1022_ds_startup: program the board with various hardware parameters
117*4882a593Smuzhiyun *
118*4882a593Smuzhiyun * This function takes board-specific information, like clock frequencies
119*4882a593Smuzhiyun * and serial data formats, and passes that information to the codec and
120*4882a593Smuzhiyun * transport drivers.
121*4882a593Smuzhiyun */
p1022_ds_startup(struct snd_pcm_substream * substream)122*4882a593Smuzhiyun static int p1022_ds_startup(struct snd_pcm_substream *substream)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
125*4882a593Smuzhiyun struct machine_data *mdata =
126*4882a593Smuzhiyun container_of(rtd->card, struct machine_data, card);
127*4882a593Smuzhiyun struct device *dev = rtd->card->dev;
128*4882a593Smuzhiyun int ret = 0;
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun /* Tell the codec driver what the serial protocol is. */
131*4882a593Smuzhiyun ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0), mdata->dai_format);
132*4882a593Smuzhiyun if (ret < 0) {
133*4882a593Smuzhiyun dev_err(dev, "could not set codec driver audio format\n");
134*4882a593Smuzhiyun return ret;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun /*
138*4882a593Smuzhiyun * Tell the codec driver what the MCLK frequency is, and whether it's
139*4882a593Smuzhiyun * a slave or master.
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, mdata->clk_frequency,
142*4882a593Smuzhiyun mdata->codec_clk_direction);
143*4882a593Smuzhiyun if (ret < 0) {
144*4882a593Smuzhiyun dev_err(dev, "could not set codec driver clock params\n");
145*4882a593Smuzhiyun return ret;
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun return 0;
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun /**
152*4882a593Smuzhiyun * p1022_ds_machine_remove: Remove the sound device
153*4882a593Smuzhiyun *
154*4882a593Smuzhiyun * This function is called to remove the sound device for one SSI. We
155*4882a593Smuzhiyun * de-program the DMACR and PMUXCR register.
156*4882a593Smuzhiyun */
p1022_ds_machine_remove(struct snd_soc_card * card)157*4882a593Smuzhiyun static int p1022_ds_machine_remove(struct snd_soc_card *card)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun struct machine_data *mdata =
160*4882a593Smuzhiyun container_of(card, struct machine_data, card);
161*4882a593Smuzhiyun struct ccsr_guts __iomem *guts;
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
164*4882a593Smuzhiyun if (!guts) {
165*4882a593Smuzhiyun dev_err(card->dev, "could not map global utilities\n");
166*4882a593Smuzhiyun return -ENOMEM;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun /* Restore the signal routing */
170*4882a593Smuzhiyun clrbits32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_UART0_I2C1_MASK);
171*4882a593Smuzhiyun clrbits32(&guts->pmuxcr, CCSR_GUTS_PMUXCR_SSI_DMA_TDM_MASK);
172*4882a593Smuzhiyun guts_set_dmuxcr(guts, mdata->dma_id[0], mdata->dma_channel_id[0], 0);
173*4882a593Smuzhiyun guts_set_dmuxcr(guts, mdata->dma_id[1], mdata->dma_channel_id[1], 0);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun iounmap(guts);
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun return 0;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun /**
181*4882a593Smuzhiyun * p1022_ds_ops: ASoC machine driver operations
182*4882a593Smuzhiyun */
183*4882a593Smuzhiyun static const struct snd_soc_ops p1022_ds_ops = {
184*4882a593Smuzhiyun .startup = p1022_ds_startup,
185*4882a593Smuzhiyun };
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /**
188*4882a593Smuzhiyun * p1022_ds_probe: platform probe function for the machine driver
189*4882a593Smuzhiyun *
190*4882a593Smuzhiyun * Although this is a machine driver, the SSI node is the "master" node with
191*4882a593Smuzhiyun * respect to audio hardware connections. Therefore, we create a new ASoC
192*4882a593Smuzhiyun * device for each new SSI node that has a codec attached.
193*4882a593Smuzhiyun */
p1022_ds_probe(struct platform_device * pdev)194*4882a593Smuzhiyun static int p1022_ds_probe(struct platform_device *pdev)
195*4882a593Smuzhiyun {
196*4882a593Smuzhiyun struct device *dev = pdev->dev.parent;
197*4882a593Smuzhiyun /* ssi_pdev is the platform device for the SSI node that probed us */
198*4882a593Smuzhiyun struct platform_device *ssi_pdev = to_platform_device(dev);
199*4882a593Smuzhiyun struct device_node *np = ssi_pdev->dev.of_node;
200*4882a593Smuzhiyun struct device_node *codec_np = NULL;
201*4882a593Smuzhiyun struct machine_data *mdata;
202*4882a593Smuzhiyun struct snd_soc_dai_link_component *comp;
203*4882a593Smuzhiyun int ret = -ENODEV;
204*4882a593Smuzhiyun const char *sprop;
205*4882a593Smuzhiyun const u32 *iprop;
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun /* Find the codec node for this SSI. */
208*4882a593Smuzhiyun codec_np = of_parse_phandle(np, "codec-handle", 0);
209*4882a593Smuzhiyun if (!codec_np) {
210*4882a593Smuzhiyun dev_err(dev, "could not find codec node\n");
211*4882a593Smuzhiyun return -EINVAL;
212*4882a593Smuzhiyun }
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun mdata = kzalloc(sizeof(struct machine_data), GFP_KERNEL);
215*4882a593Smuzhiyun if (!mdata) {
216*4882a593Smuzhiyun ret = -ENOMEM;
217*4882a593Smuzhiyun goto error_put;
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun comp = devm_kzalloc(&pdev->dev, 6 * sizeof(*comp), GFP_KERNEL);
221*4882a593Smuzhiyun if (!comp) {
222*4882a593Smuzhiyun ret = -ENOMEM;
223*4882a593Smuzhiyun goto error_put;
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun mdata->dai[0].cpus = &comp[0];
227*4882a593Smuzhiyun mdata->dai[0].codecs = &comp[1];
228*4882a593Smuzhiyun mdata->dai[0].platforms = &comp[2];
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun mdata->dai[0].num_cpus = 1;
231*4882a593Smuzhiyun mdata->dai[0].num_codecs = 1;
232*4882a593Smuzhiyun mdata->dai[0].num_platforms = 1;
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun mdata->dai[1].cpus = &comp[3];
235*4882a593Smuzhiyun mdata->dai[1].codecs = &comp[4];
236*4882a593Smuzhiyun mdata->dai[1].platforms = &comp[5];
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun mdata->dai[1].num_cpus = 1;
239*4882a593Smuzhiyun mdata->dai[1].num_codecs = 1;
240*4882a593Smuzhiyun mdata->dai[1].num_platforms = 1;
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun mdata->dai[0].cpus->dai_name = dev_name(&ssi_pdev->dev);
244*4882a593Smuzhiyun mdata->dai[0].ops = &p1022_ds_ops;
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun /* ASoC core can match codec with device node */
247*4882a593Smuzhiyun mdata->dai[0].codecs->of_node = codec_np;
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun /* We register two DAIs per SSI, one for playback and the other for
250*4882a593Smuzhiyun * capture. We support codecs that have separate DAIs for both playback
251*4882a593Smuzhiyun * and capture.
252*4882a593Smuzhiyun */
253*4882a593Smuzhiyun memcpy(&mdata->dai[1], &mdata->dai[0], sizeof(struct snd_soc_dai_link));
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun /* The DAI names from the codec (snd_soc_dai_driver.name) */
256*4882a593Smuzhiyun mdata->dai[0].codecs->dai_name = "wm8776-hifi-playback";
257*4882a593Smuzhiyun mdata->dai[1].codecs->dai_name = "wm8776-hifi-capture";
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun /* Get the device ID */
260*4882a593Smuzhiyun iprop = of_get_property(np, "cell-index", NULL);
261*4882a593Smuzhiyun if (!iprop) {
262*4882a593Smuzhiyun dev_err(&pdev->dev, "cell-index property not found\n");
263*4882a593Smuzhiyun ret = -EINVAL;
264*4882a593Smuzhiyun goto error;
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun mdata->ssi_id = be32_to_cpup(iprop);
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun /* Get the serial format and clock direction. */
269*4882a593Smuzhiyun sprop = of_get_property(np, "fsl,mode", NULL);
270*4882a593Smuzhiyun if (!sprop) {
271*4882a593Smuzhiyun dev_err(&pdev->dev, "fsl,mode property not found\n");
272*4882a593Smuzhiyun ret = -EINVAL;
273*4882a593Smuzhiyun goto error;
274*4882a593Smuzhiyun }
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun if (strcasecmp(sprop, "i2s-slave") == 0) {
277*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
278*4882a593Smuzhiyun SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM;
279*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
280*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun /* In i2s-slave mode, the codec has its own clock source, so we
283*4882a593Smuzhiyun * need to get the frequency from the device tree and pass it to
284*4882a593Smuzhiyun * the codec driver.
285*4882a593Smuzhiyun */
286*4882a593Smuzhiyun iprop = of_get_property(codec_np, "clock-frequency", NULL);
287*4882a593Smuzhiyun if (!iprop || !*iprop) {
288*4882a593Smuzhiyun dev_err(&pdev->dev, "codec bus-frequency "
289*4882a593Smuzhiyun "property is missing or invalid\n");
290*4882a593Smuzhiyun ret = -EINVAL;
291*4882a593Smuzhiyun goto error;
292*4882a593Smuzhiyun }
293*4882a593Smuzhiyun mdata->clk_frequency = be32_to_cpup(iprop);
294*4882a593Smuzhiyun } else if (strcasecmp(sprop, "i2s-master") == 0) {
295*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
296*4882a593Smuzhiyun SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
297*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
298*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
299*4882a593Smuzhiyun } else if (strcasecmp(sprop, "lj-slave") == 0) {
300*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
301*4882a593Smuzhiyun SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM;
302*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
303*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
304*4882a593Smuzhiyun } else if (strcasecmp(sprop, "lj-master") == 0) {
305*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
306*4882a593Smuzhiyun SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBS_CFS;
307*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
308*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
309*4882a593Smuzhiyun } else if (strcasecmp(sprop, "rj-slave") == 0) {
310*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
311*4882a593Smuzhiyun SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBM_CFM;
312*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
313*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
314*4882a593Smuzhiyun } else if (strcasecmp(sprop, "rj-master") == 0) {
315*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
316*4882a593Smuzhiyun SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBS_CFS;
317*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
318*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
319*4882a593Smuzhiyun } else if (strcasecmp(sprop, "ac97-slave") == 0) {
320*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
321*4882a593Smuzhiyun SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBM_CFM;
322*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_OUT;
323*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_IN;
324*4882a593Smuzhiyun } else if (strcasecmp(sprop, "ac97-master") == 0) {
325*4882a593Smuzhiyun mdata->dai_format = SND_SOC_DAIFMT_NB_NF |
326*4882a593Smuzhiyun SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBS_CFS;
327*4882a593Smuzhiyun mdata->codec_clk_direction = SND_SOC_CLOCK_IN;
328*4882a593Smuzhiyun mdata->cpu_clk_direction = SND_SOC_CLOCK_OUT;
329*4882a593Smuzhiyun } else {
330*4882a593Smuzhiyun dev_err(&pdev->dev,
331*4882a593Smuzhiyun "unrecognized fsl,mode property '%s'\n", sprop);
332*4882a593Smuzhiyun ret = -EINVAL;
333*4882a593Smuzhiyun goto error;
334*4882a593Smuzhiyun }
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun if (!mdata->clk_frequency) {
337*4882a593Smuzhiyun dev_err(&pdev->dev, "unknown clock frequency\n");
338*4882a593Smuzhiyun ret = -EINVAL;
339*4882a593Smuzhiyun goto error;
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun /* Find the playback DMA channel to use. */
343*4882a593Smuzhiyun mdata->dai[0].platforms->name = mdata->platform_name[0];
344*4882a593Smuzhiyun ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma", &mdata->dai[0],
345*4882a593Smuzhiyun &mdata->dma_channel_id[0],
346*4882a593Smuzhiyun &mdata->dma_id[0]);
347*4882a593Smuzhiyun if (ret) {
348*4882a593Smuzhiyun dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n");
349*4882a593Smuzhiyun goto error;
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun /* Find the capture DMA channel to use. */
353*4882a593Smuzhiyun mdata->dai[1].platforms->name = mdata->platform_name[1];
354*4882a593Smuzhiyun ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma", &mdata->dai[1],
355*4882a593Smuzhiyun &mdata->dma_channel_id[1],
356*4882a593Smuzhiyun &mdata->dma_id[1]);
357*4882a593Smuzhiyun if (ret) {
358*4882a593Smuzhiyun dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n");
359*4882a593Smuzhiyun goto error;
360*4882a593Smuzhiyun }
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun /* Initialize our DAI data structure. */
363*4882a593Smuzhiyun mdata->dai[0].stream_name = "playback";
364*4882a593Smuzhiyun mdata->dai[1].stream_name = "capture";
365*4882a593Smuzhiyun mdata->dai[0].name = mdata->dai[0].stream_name;
366*4882a593Smuzhiyun mdata->dai[1].name = mdata->dai[1].stream_name;
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun mdata->card.probe = p1022_ds_machine_probe;
369*4882a593Smuzhiyun mdata->card.remove = p1022_ds_machine_remove;
370*4882a593Smuzhiyun mdata->card.name = pdev->name; /* The platform driver name */
371*4882a593Smuzhiyun mdata->card.owner = THIS_MODULE;
372*4882a593Smuzhiyun mdata->card.dev = &pdev->dev;
373*4882a593Smuzhiyun mdata->card.num_links = 2;
374*4882a593Smuzhiyun mdata->card.dai_link = mdata->dai;
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun /* Register with ASoC */
377*4882a593Smuzhiyun ret = snd_soc_register_card(&mdata->card);
378*4882a593Smuzhiyun if (ret) {
379*4882a593Smuzhiyun dev_err(&pdev->dev, "could not register card\n");
380*4882a593Smuzhiyun goto error;
381*4882a593Smuzhiyun }
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun of_node_put(codec_np);
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun return 0;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun error:
388*4882a593Smuzhiyun kfree(mdata);
389*4882a593Smuzhiyun error_put:
390*4882a593Smuzhiyun of_node_put(codec_np);
391*4882a593Smuzhiyun return ret;
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun /**
395*4882a593Smuzhiyun * p1022_ds_remove: remove the platform device
396*4882a593Smuzhiyun *
397*4882a593Smuzhiyun * This function is called when the platform device is removed.
398*4882a593Smuzhiyun */
p1022_ds_remove(struct platform_device * pdev)399*4882a593Smuzhiyun static int p1022_ds_remove(struct platform_device *pdev)
400*4882a593Smuzhiyun {
401*4882a593Smuzhiyun struct snd_soc_card *card = platform_get_drvdata(pdev);
402*4882a593Smuzhiyun struct machine_data *mdata =
403*4882a593Smuzhiyun container_of(card, struct machine_data, card);
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun snd_soc_unregister_card(card);
406*4882a593Smuzhiyun kfree(mdata);
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun return 0;
409*4882a593Smuzhiyun }
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun static struct platform_driver p1022_ds_driver = {
412*4882a593Smuzhiyun .probe = p1022_ds_probe,
413*4882a593Smuzhiyun .remove = p1022_ds_remove,
414*4882a593Smuzhiyun .driver = {
415*4882a593Smuzhiyun /*
416*4882a593Smuzhiyun * The name must match 'compatible' property in the device tree,
417*4882a593Smuzhiyun * in lowercase letters.
418*4882a593Smuzhiyun */
419*4882a593Smuzhiyun .name = "snd-soc-p1022ds",
420*4882a593Smuzhiyun },
421*4882a593Smuzhiyun };
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun /**
424*4882a593Smuzhiyun * p1022_ds_init: machine driver initialization.
425*4882a593Smuzhiyun *
426*4882a593Smuzhiyun * This function is called when this module is loaded.
427*4882a593Smuzhiyun */
p1022_ds_init(void)428*4882a593Smuzhiyun static int __init p1022_ds_init(void)
429*4882a593Smuzhiyun {
430*4882a593Smuzhiyun struct device_node *guts_np;
431*4882a593Smuzhiyun struct resource res;
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun /* Get the physical address of the global utilities registers */
434*4882a593Smuzhiyun guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
435*4882a593Smuzhiyun if (of_address_to_resource(guts_np, 0, &res)) {
436*4882a593Smuzhiyun pr_err("snd-soc-p1022ds: missing/invalid global utils node\n");
437*4882a593Smuzhiyun of_node_put(guts_np);
438*4882a593Smuzhiyun return -EINVAL;
439*4882a593Smuzhiyun }
440*4882a593Smuzhiyun guts_phys = res.start;
441*4882a593Smuzhiyun of_node_put(guts_np);
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun return platform_driver_register(&p1022_ds_driver);
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun /**
447*4882a593Smuzhiyun * p1022_ds_exit: machine driver exit
448*4882a593Smuzhiyun *
449*4882a593Smuzhiyun * This function is called when this driver is unloaded.
450*4882a593Smuzhiyun */
p1022_ds_exit(void)451*4882a593Smuzhiyun static void __exit p1022_ds_exit(void)
452*4882a593Smuzhiyun {
453*4882a593Smuzhiyun platform_driver_unregister(&p1022_ds_driver);
454*4882a593Smuzhiyun }
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun module_init(p1022_ds_init);
457*4882a593Smuzhiyun module_exit(p1022_ds_exit);
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
460*4882a593Smuzhiyun MODULE_DESCRIPTION("Freescale P1022 DS ALSA SoC machine driver");
461*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
462