2 * Freescale MPC8610HPCD ALSA SoC Fabric driver
4 * Author: Timur Tabi <timur@freescale.com>
6 * Copyright 2007-2008 Freescale Semiconductor, Inc. This file is licensed
7 * under the terms of the GNU General Public License version 2. This
8 * program is licensed "as is" without any warranty of any kind, whether
12 #include <linux/module.h>
13 #include <linux/interrupt.h>
14 #include <linux/of_device.h>
15 #include <linux/of_platform.h>
16 #include <sound/soc.h>
17 #include <asm/immap_86xx.h>
19 #include "../codecs/cs4270.h"
24 * mpc8610_hpcd_data: fabric-specific ASoC device data
26 * This structure contains data for a single sound platform device on an
27 * MPC8610 HPCD. Some of the data is taken from the device tree.
29 struct mpc8610_hpcd_data
{
30 struct snd_soc_device sound_devdata
;
31 struct snd_soc_dai_link dai
;
32 struct snd_soc_machine machine
;
33 unsigned int dai_format
;
34 unsigned int codec_clk_direction
;
35 unsigned int cpu_clk_direction
;
36 unsigned int clk_frequency
;
37 struct ccsr_guts __iomem
*guts
;
38 struct ccsr_ssi __iomem
*ssi
;
39 unsigned int ssi_id
; /* 0 = SSI1, 1 = SSI2, etc */
41 unsigned int dma_id
; /* 0 = DMA1, 1 = DMA2, etc */
42 unsigned int dma_irq
[2];
43 struct ccsr_dma_channel __iomem
*dma
[2];
44 unsigned int dma_channel_id
[2]; /* 0 = ch 0, 1 = ch 1, etc*/
48 * mpc8610_hpcd_machine_probe: initalize the board
50 * This function is called when platform_device_add() is called. It is used
51 * to initialize the board-specific hardware.
53 * Here we program the DMACR and PMUXCR registers.
55 static int mpc8610_hpcd_machine_probe(struct platform_device
*sound_device
)
57 struct mpc8610_hpcd_data
*machine_data
=
58 sound_device
->dev
.platform_data
;
60 /* Program the signal routing between the SSI and the DMA */
61 guts_set_dmacr(machine_data
->guts
, machine_data
->dma_id
+ 1,
62 machine_data
->dma_channel_id
[0], CCSR_GUTS_DMACR_DEV_SSI
);
63 guts_set_dmacr(machine_data
->guts
, machine_data
->dma_id
+ 1,
64 machine_data
->dma_channel_id
[1], CCSR_GUTS_DMACR_DEV_SSI
);
66 guts_set_pmuxcr_dma(machine_data
->guts
, machine_data
->dma_id
,
67 machine_data
->dma_channel_id
[0], 0);
68 guts_set_pmuxcr_dma(machine_data
->guts
, machine_data
->dma_id
,
69 machine_data
->dma_channel_id
[1], 0);
71 guts_set_pmuxcr_dma(machine_data
->guts
, 1, 0, 0);
72 guts_set_pmuxcr_dma(machine_data
->guts
, 1, 3, 0);
73 guts_set_pmuxcr_dma(machine_data
->guts
, 0, 3, 0);
75 switch (machine_data
->ssi_id
) {
77 clrsetbits_be32(&machine_data
->guts
->pmuxcr
,
78 CCSR_GUTS_PMUXCR_SSI1_MASK
, CCSR_GUTS_PMUXCR_SSI1_SSI
);
81 clrsetbits_be32(&machine_data
->guts
->pmuxcr
,
82 CCSR_GUTS_PMUXCR_SSI2_MASK
, CCSR_GUTS_PMUXCR_SSI2_SSI
);
90 * mpc8610_hpcd_startup: program the board with various hardware parameters
92 * This function takes board-specific information, like clock frequencies
93 * and serial data formats, and passes that information to the codec and
96 static int mpc8610_hpcd_startup(struct snd_pcm_substream
*substream
)
98 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
99 struct snd_soc_codec_dai
*codec_dai
= rtd
->dai
->codec_dai
;
100 struct snd_soc_cpu_dai
*cpu_dai
= rtd
->dai
->cpu_dai
;
101 struct mpc8610_hpcd_data
*machine_data
=
102 rtd
->socdev
->dev
->platform_data
;
105 /* Tell the CPU driver what the serial protocol is. */
106 if (cpu_dai
->dai_ops
.set_fmt
) {
107 ret
= cpu_dai
->dai_ops
.set_fmt(cpu_dai
,
108 machine_data
->dai_format
);
110 dev_err(substream
->pcm
->card
->dev
,
111 "could not set CPU driver audio format\n");
116 /* Tell the codec driver what the serial protocol is. */
117 if (codec_dai
->dai_ops
.set_fmt
) {
118 ret
= codec_dai
->dai_ops
.set_fmt(codec_dai
,
119 machine_data
->dai_format
);
121 dev_err(substream
->pcm
->card
->dev
,
122 "could not set codec driver audio format\n");
128 * Tell the CPU driver what the clock frequency is, and whether it's a
131 if (cpu_dai
->dai_ops
.set_sysclk
) {
132 ret
= cpu_dai
->dai_ops
.set_sysclk(cpu_dai
, 0,
133 machine_data
->clk_frequency
,
134 machine_data
->cpu_clk_direction
);
136 dev_err(substream
->pcm
->card
->dev
,
137 "could not set CPU driver clock parameters\n");
143 * Tell the codec driver what the MCLK frequency is, and whether it's
146 if (codec_dai
->dai_ops
.set_sysclk
) {
147 ret
= codec_dai
->dai_ops
.set_sysclk(codec_dai
, 0,
148 machine_data
->clk_frequency
,
149 machine_data
->codec_clk_direction
);
151 dev_err(substream
->pcm
->card
->dev
,
152 "could not set codec driver clock params\n");
161 * mpc8610_hpcd_machine_remove: Remove the sound device
163 * This function is called to remove the sound device for one SSI. We
164 * de-program the DMACR and PMUXCR register.
166 int mpc8610_hpcd_machine_remove(struct platform_device
*sound_device
)
168 struct mpc8610_hpcd_data
*machine_data
=
169 sound_device
->dev
.platform_data
;
171 /* Restore the signal routing */
173 guts_set_dmacr(machine_data
->guts
, machine_data
->dma_id
+ 1,
174 machine_data
->dma_channel_id
[0], 0);
175 guts_set_dmacr(machine_data
->guts
, machine_data
->dma_id
+ 1,
176 machine_data
->dma_channel_id
[1], 0);
178 switch (machine_data
->ssi_id
) {
180 clrsetbits_be32(&machine_data
->guts
->pmuxcr
,
181 CCSR_GUTS_PMUXCR_SSI1_MASK
, CCSR_GUTS_PMUXCR_SSI1_LA
);
184 clrsetbits_be32(&machine_data
->guts
->pmuxcr
,
185 CCSR_GUTS_PMUXCR_SSI2_MASK
, CCSR_GUTS_PMUXCR_SSI1_LA
);
193 * mpc8610_hpcd_ops: ASoC fabric driver operations
195 static struct snd_soc_ops mpc8610_hpcd_ops
= {
196 .startup
= mpc8610_hpcd_startup
,
200 * mpc8610_hpcd_machine: ASoC machine data
202 static struct snd_soc_machine mpc8610_hpcd_machine
= {
203 .probe
= mpc8610_hpcd_machine_probe
,
204 .remove
= mpc8610_hpcd_machine_remove
,
205 .name
= "MPC8610 HPCD",
210 * mpc8610_hpcd_probe: OF probe function for the fabric driver
212 * This function gets called when an SSI node is found in the device tree.
214 * Although this is a fabric driver, the SSI node is the "master" node with
215 * respect to audio hardware connections. Therefore, we create a new ASoC
216 * device for each new SSI node that has a codec attached.
218 * FIXME: Currently, we only support one DMA controller, so if there are
219 * multiple SSI nodes with codecs, only the first will be supported.
221 * FIXME: Even if we did support multiple DMA controllers, we have no
222 * mechanism for assigning DMA controllers and channels to the individual
223 * SSI devices. We also probably aren't compatible with the generic Elo DMA
226 static int mpc8610_hpcd_probe(struct of_device
*ofdev
,
227 const struct of_device_id
*match
)
229 struct device_node
*np
= ofdev
->node
;
230 struct device_node
*codec_np
= NULL
;
231 struct device_node
*guts_np
= NULL
;
232 struct device_node
*dma_np
= NULL
;
233 struct device_node
*dma_channel_np
= NULL
;
234 const phandle
*codec_ph
;
238 struct platform_device
*sound_device
= NULL
;
239 struct mpc8610_hpcd_data
*machine_data
;
240 struct fsl_ssi_info ssi_info
;
241 struct fsl_dma_info dma_info
;
244 machine_data
= kzalloc(sizeof(struct mpc8610_hpcd_data
), GFP_KERNEL
);
248 memset(&ssi_info
, 0, sizeof(ssi_info
));
249 memset(&dma_info
, 0, sizeof(dma_info
));
251 ssi_info
.dev
= &ofdev
->dev
;
254 * We are only interested in SSIs with a codec phandle in them, so let's
255 * make sure this SSI has one.
257 codec_ph
= of_get_property(np
, "codec-handle", NULL
);
261 codec_np
= of_find_node_by_phandle(*codec_ph
);
265 /* The MPC8610 HPCD only knows about the CS4270 codec, so reject
267 if (!of_device_is_compatible(codec_np
, "cirrus,cs4270"))
270 /* Get the device ID */
271 iprop
= of_get_property(np
, "cell-index", NULL
);
273 dev_err(&ofdev
->dev
, "cell-index property not found\n");
277 machine_data
->ssi_id
= *iprop
;
278 ssi_info
.id
= *iprop
;
280 /* Get the serial format and clock direction. */
281 sprop
= of_get_property(np
, "fsl,mode", NULL
);
283 dev_err(&ofdev
->dev
, "fsl,mode property not found\n");
288 if (strcasecmp(sprop
, "i2s-slave") == 0) {
289 machine_data
->dai_format
= SND_SOC_DAIFMT_I2S
;
290 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_OUT
;
291 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_IN
;
294 * In i2s-slave mode, the codec has its own clock source, so we
295 * need to get the frequency from the device tree and pass it to
298 iprop
= of_get_property(codec_np
, "clock-frequency", NULL
);
299 if (!iprop
|| !*iprop
) {
300 dev_err(&ofdev
->dev
, "codec bus-frequency property "
301 "is missing or invalid\n");
305 machine_data
->clk_frequency
= *iprop
;
306 } else if (strcasecmp(sprop
, "i2s-master") == 0) {
307 machine_data
->dai_format
= SND_SOC_DAIFMT_I2S
;
308 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_IN
;
309 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_OUT
;
310 } else if (strcasecmp(sprop
, "lj-slave") == 0) {
311 machine_data
->dai_format
= SND_SOC_DAIFMT_LEFT_J
;
312 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_OUT
;
313 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_IN
;
314 } else if (strcasecmp(sprop
, "lj-master") == 0) {
315 machine_data
->dai_format
= SND_SOC_DAIFMT_LEFT_J
;
316 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_IN
;
317 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_OUT
;
318 <<<<<<< HEAD
:sound
/soc
/fsl
/mpc8610_hpcd
.c
319 } else if (strcasecmp(sprop
, "rj-master") == 0) {
321 } else if (strcasecmp(sprop
, "rj-slave") == 0) {
322 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:sound
/soc
/fsl
/mpc8610_hpcd
.c
323 machine_data
->dai_format
= SND_SOC_DAIFMT_RIGHT_J
;
324 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_OUT
;
325 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_IN
;
326 } else if (strcasecmp(sprop
, "rj-master") == 0) {
327 machine_data
->dai_format
= SND_SOC_DAIFMT_RIGHT_J
;
328 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_IN
;
329 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_OUT
;
330 } else if (strcasecmp(sprop
, "ac97-slave") == 0) {
331 machine_data
->dai_format
= SND_SOC_DAIFMT_AC97
;
332 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_OUT
;
333 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_IN
;
334 } else if (strcasecmp(sprop
, "ac97-master") == 0) {
335 machine_data
->dai_format
= SND_SOC_DAIFMT_AC97
;
336 machine_data
->codec_clk_direction
= SND_SOC_CLOCK_IN
;
337 machine_data
->cpu_clk_direction
= SND_SOC_CLOCK_OUT
;
340 "unrecognized fsl,mode property \"%s\"\n", sprop
);
345 if (!machine_data
->clk_frequency
) {
346 dev_err(&ofdev
->dev
, "unknown clock frequency\n");
351 /* Read the SSI information from the device tree */
352 ret
= of_address_to_resource(np
, 0, &res
);
354 dev_err(&ofdev
->dev
, "could not obtain SSI address\n");
358 dev_err(&ofdev
->dev
, "invalid SSI address\n");
361 ssi_info
.ssi_phys
= res
.start
;
363 machine_data
->ssi
= ioremap(ssi_info
.ssi_phys
, sizeof(struct ccsr_ssi
));
364 if (!machine_data
->ssi
) {
365 dev_err(&ofdev
->dev
, "could not map SSI address %x\n",
370 ssi_info
.ssi
= machine_data
->ssi
;
373 /* Get the IRQ of the SSI */
374 machine_data
->ssi_irq
= irq_of_parse_and_map(np
, 0);
375 if (!machine_data
->ssi_irq
) {
376 dev_err(&ofdev
->dev
, "could not get SSI IRQ\n");
380 ssi_info
.irq
= machine_data
->ssi_irq
;
383 /* Map the global utilities registers. */
384 guts_np
= of_find_compatible_node(NULL
, NULL
, "fsl,mpc8610-guts");
386 dev_err(&ofdev
->dev
, "could not obtain address of GUTS\n");
390 machine_data
->guts
= of_iomap(guts_np
, 0);
391 of_node_put(guts_np
);
392 if (!machine_data
->guts
) {
393 dev_err(&ofdev
->dev
, "could not map GUTS\n");
398 /* Find the DMA channels to use. For now, we always use the first DMA
400 for_each_compatible_node(dma_np
, NULL
, "fsl,mpc8610-dma") {
401 iprop
= of_get_property(dma_np
, "cell-index", NULL
);
402 if (iprop
&& (*iprop
== 0)) {
408 dev_err(&ofdev
->dev
, "could not find DMA node\n");
412 machine_data
->dma_id
= *iprop
;
415 * Find the DMA channels to use. For now, we always use DMA channel 0
416 * for playback, and DMA channel 1 for capture.
418 while ((dma_channel_np
= of_get_next_child(dma_np
, dma_channel_np
))) {
419 iprop
= of_get_property(dma_channel_np
, "cell-index", NULL
);
420 /* Is it DMA channel 0? */
421 if (iprop
&& (*iprop
== 0)) {
422 /* dma_channel[0] and dma_irq[0] are for playback */
423 dma_info
.dma_channel
[0] = of_iomap(dma_channel_np
, 0);
424 dma_info
.dma_irq
[0] =
425 irq_of_parse_and_map(dma_channel_np
, 0);
426 machine_data
->dma_channel_id
[0] = *iprop
;
429 if (iprop
&& (*iprop
== 1)) {
430 /* dma_channel[1] and dma_irq[1] are for capture */
431 dma_info
.dma_channel
[1] = of_iomap(dma_channel_np
, 0);
432 dma_info
.dma_irq
[1] =
433 irq_of_parse_and_map(dma_channel_np
, 0);
434 machine_data
->dma_channel_id
[1] = *iprop
;
438 if (!dma_info
.dma_channel
[0] || !dma_info
.dma_channel
[1] ||
439 !dma_info
.dma_irq
[0] || !dma_info
.dma_irq
[1]) {
440 dev_err(&ofdev
->dev
, "could not find DMA channels\n");
445 dma_info
.ssi_stx_phys
= ssi_info
.ssi_phys
+
446 offsetof(struct ccsr_ssi
, stx0
);
447 dma_info
.ssi_srx_phys
= ssi_info
.ssi_phys
+
448 offsetof(struct ccsr_ssi
, srx0
);
450 /* We have the DMA information, so tell the DMA driver what it is */
451 if (!fsl_dma_configure(&dma_info
)) {
452 dev_err(&ofdev
->dev
, "could not instantiate DMA device\n");
458 * Initialize our DAI data structure. We should probably get this
459 * information from the device tree.
461 machine_data
->dai
.name
= "CS4270";
462 machine_data
->dai
.stream_name
= "CS4270";
464 machine_data
->dai
.cpu_dai
= fsl_ssi_create_dai(&ssi_info
);
465 machine_data
->dai
.codec_dai
= &cs4270_dai
; /* The codec_dai we want */
466 machine_data
->dai
.ops
= &mpc8610_hpcd_ops
;
468 mpc8610_hpcd_machine
.dai_link
= &machine_data
->dai
;
470 /* Allocate a new audio platform device structure */
471 sound_device
= platform_device_alloc("soc-audio", -1);
473 dev_err(&ofdev
->dev
, "platform device allocation failed\n");
478 machine_data
->sound_devdata
.machine
= &mpc8610_hpcd_machine
;
479 machine_data
->sound_devdata
.codec_dev
= &soc_codec_device_cs4270
;
480 machine_data
->sound_devdata
.platform
= &fsl_soc_platform
;
482 sound_device
->dev
.platform_data
= machine_data
;
485 /* Set the platform device and ASoC device to point to each other */
486 platform_set_drvdata(sound_device
, &machine_data
->sound_devdata
);
488 machine_data
->sound_devdata
.dev
= &sound_device
->dev
;
491 /* Tell ASoC to probe us. This will call mpc8610_hpcd_machine.probe(),
493 ret
= platform_device_add(sound_device
);
496 dev_err(&ofdev
->dev
, "platform device add failed\n");
500 dev_set_drvdata(&ofdev
->dev
, sound_device
);
505 of_node_put(codec_np
);
506 of_node_put(guts_np
);
508 of_node_put(dma_channel_np
);
511 platform_device_unregister(sound_device
);
513 if (machine_data
->dai
.cpu_dai
)
514 fsl_ssi_destroy_dai(machine_data
->dai
.cpu_dai
);
517 iounmap(ssi_info
.ssi
);
520 irq_dispose_mapping(ssi_info
.irq
);
522 if (dma_info
.dma_channel
[0])
523 iounmap(dma_info
.dma_channel
[0]);
525 if (dma_info
.dma_channel
[1])
526 iounmap(dma_info
.dma_channel
[1]);
528 if (dma_info
.dma_irq
[0])
529 irq_dispose_mapping(dma_info
.dma_irq
[0]);
531 if (dma_info
.dma_irq
[1])
532 irq_dispose_mapping(dma_info
.dma_irq
[1]);
534 if (machine_data
->guts
)
535 iounmap(machine_data
->guts
);
543 * mpc8610_hpcd_remove: remove the OF device
545 * This function is called when the OF device is removed.
547 static int mpc8610_hpcd_remove(struct of_device
*ofdev
)
549 struct platform_device
*sound_device
= dev_get_drvdata(&ofdev
->dev
);
550 struct mpc8610_hpcd_data
*machine_data
=
551 sound_device
->dev
.platform_data
;
553 platform_device_unregister(sound_device
);
555 if (machine_data
->dai
.cpu_dai
)
556 fsl_ssi_destroy_dai(machine_data
->dai
.cpu_dai
);
558 if (machine_data
->ssi
)
559 iounmap(machine_data
->ssi
);
561 if (machine_data
->dma
[0])
562 iounmap(machine_data
->dma
[0]);
564 if (machine_data
->dma
[1])
565 iounmap(machine_data
->dma
[1]);
567 if (machine_data
->dma_irq
[0])
568 irq_dispose_mapping(machine_data
->dma_irq
[0]);
570 if (machine_data
->dma_irq
[1])
571 irq_dispose_mapping(machine_data
->dma_irq
[1]);
573 if (machine_data
->guts
)
574 iounmap(machine_data
->guts
);
577 sound_device
->dev
.platform_data
= NULL
;
579 dev_set_drvdata(&ofdev
->dev
, NULL
);
584 static struct of_device_id mpc8610_hpcd_match
[] = {
586 .compatible
= "fsl,mpc8610-ssi",
590 MODULE_DEVICE_TABLE(of
, mpc8610_hpcd_match
);
592 static struct of_platform_driver mpc8610_hpcd_of_driver
= {
593 .owner
= THIS_MODULE
,
594 .name
= "mpc8610_hpcd",
595 .match_table
= mpc8610_hpcd_match
,
596 .probe
= mpc8610_hpcd_probe
,
597 .remove
= mpc8610_hpcd_remove
,
601 * mpc8610_hpcd_init: fabric driver initialization.
603 * This function is called when this module is loaded.
605 static int __init
mpc8610_hpcd_init(void)
609 printk(KERN_INFO
"Freescale MPC8610 HPCD ALSA SoC fabric driver\n");
611 ret
= of_register_platform_driver(&mpc8610_hpcd_of_driver
);
615 "mpc8610-hpcd: failed to register platform driver\n");
621 * mpc8610_hpcd_exit: fabric driver exit
623 * This function is called when this driver is unloaded.
625 static void __exit
mpc8610_hpcd_exit(void)
627 of_unregister_platform_driver(&mpc8610_hpcd_of_driver
);
630 module_init(mpc8610_hpcd_init
);
631 module_exit(mpc8610_hpcd_exit
);
633 MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
634 MODULE_DESCRIPTION("Freescale MPC8610 HPCD ALSA SoC fabric driver");
635 MODULE_LICENSE("GPL");