aboutsummaryrefslogtreecommitdiff
path: root/sound/soc/imx/imx-spdif-dai.c
blob: a3b38658c6f4237418357acf0260678d0a01ca78 (plain)
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
/*
 * ALSA SoC SPDIF Audio Layer for MXS
 *
 * Copyright (C) 2008-2011 Freescale Semiconductor, Inc.
 *
 * Based on stmp3xxx_spdif_dai.c
 * Vladimir Barinov <vbarinov@embeddedalley.com>
 * Copyright 2008 SigmaTel, Inc
 * Copyright 2008 Embedded Alley Solutions, Inc
 *
 * This file is licensed under the terms of the GNU General Public License
 * version 2.  This program  is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/dma-mapping.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#include <mach/dma.h>
#include <mach/hardware.h>

#include "../codecs/mxc_spdif.h"

#define MXC_SPDIF_TXFIFO_WML      0x8
#define MXC_SPDIF_RXFIFO_WML      0x8

struct imx_pcm_dma_params dma_params_tx;
struct imx_pcm_dma_params dma_params_rx;

static int imx_spdif_hw_params(struct snd_pcm_substream *substream,
			       struct snd_pcm_hw_params *params,
			       struct snd_soc_dai *cpu_dai)
{
	/* Tx/Rx config */
	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
		snd_soc_dai_set_dma_data(cpu_dai, substream, &dma_params_tx);
	else
		snd_soc_dai_set_dma_data(cpu_dai, substream, &dma_params_rx);

	return 0;
}

struct snd_soc_dai_ops imx_spdif_dai_ops = {
	.hw_params      = imx_spdif_hw_params,
};

struct snd_soc_dai_driver imx_spdif_dai = {
	.playback = {
		.channels_min = 2,
		.channels_max = 2,
		.rates = MXC_SPDIF_RATES_PLAYBACK,
		.formats = MXC_SPDIF_FORMATS_PLAYBACK,
	},
	.capture = {
		.channels_min = 2,
		.channels_max = 2,
		.rates = MXC_SPDIF_RATES_CAPTURE,
		.formats = MXC_SPDIF_FORMATS_CAPTURE,
	},
	.ops = &imx_spdif_dai_ops,
};

static int imx_spdif_dai_probe(struct platform_device *pdev)
{
	struct resource *res;
	int ret = 0;

	dma_params_tx.burstsize = MXC_SPDIF_TXFIFO_WML;
	dma_params_rx.burstsize = MXC_SPDIF_RXFIFO_WML;

	dma_params_tx.peripheral_type = IMX_DMATYPE_SPDIF;
	dma_params_rx.peripheral_type = IMX_DMATYPE_SPDIF;

	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
	if (res)
		dma_params_tx.dma = res->start;

	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
	if (res)
		dma_params_rx.dma = res->start;

	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx_reg");
	if (res)
		dma_params_tx.dma_addr = res->start;

	res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx_reg");
	if (res)
		dma_params_rx.dma_addr = res->start;

	ret = snd_soc_register_dai(&pdev->dev, &imx_spdif_dai);
	if (ret) {
		dev_err(&pdev->dev, "register DAI failed\n");
		goto failed_register;
	}

	return 0;

failed_register:
	return ret;
}

static int __devexit imx_spdif_dai_remove(struct platform_device *pdev)
{
	snd_soc_unregister_dai(&pdev->dev);
	return 0;
}

static struct platform_driver imx_ssi_driver = {
	.probe = imx_spdif_dai_probe,
	.remove = __devexit_p(imx_spdif_dai_remove),

	.driver = {
		.name = "imx-spdif-dai",
		.owner = THIS_MODULE,
	},
};

static int __init imx_spdif_dai_init(void)
{
	return platform_driver_register(&imx_ssi_driver);
}

static void __exit imx_spdif_dai_exit(void)
{
	platform_driver_unregister(&imx_ssi_driver);
}
module_init(imx_spdif_dai_init);
module_exit(imx_spdif_dai_exit);

MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("IMX SPDIF DAI");
MODULE_LICENSE("GPL");