blob: 8fdc430a4f68a60af485868867b03003c03a8ae2 [file] [log] [blame]
Timur Tabi17467f22008-01-11 18:15:26 +01001/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002 * Freescale MPC8610HPCD ALSA SoC Machine driver
Timur Tabi17467f22008-01-11 18:15:26 +01003 *
4 * Author: Timur Tabi <timur@freescale.com>
5 *
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00006 * Copyright 2007-2010 Freescale Semiconductor, Inc.
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
Timur Tabi17467f22008-01-11 18:15:26 +010011 */
12
13#include <linux/module.h>
14#include <linux/interrupt.h>
15#include <linux/of_device.h>
Timur Tabi38fec722010-08-19 15:26:58 -050016#include <linux/slab.h>
Timur Tabi17467f22008-01-11 18:15:26 +010017#include <sound/soc.h>
Timur Tabi6e6f6622010-07-22 11:33:30 -050018#include <asm/fsl_guts.h>
Timur Tabi17467f22008-01-11 18:15:26 +010019
Timur Tabi17467f22008-01-11 18:15:26 +010020#include "fsl_dma.h"
21#include "fsl_ssi.h"
Shawn Guo60aae8d2012-03-16 16:56:40 +080022#include "fsl_utils.h"
Timur Tabi17467f22008-01-11 18:15:26 +010023
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000024/* There's only one global utilities register */
25static phys_addr_t guts_phys;
26
Timur Tabi17467f22008-01-11 18:15:26 +010027/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000028 * mpc8610_hpcd_data: machine-specific ASoC device data
Timur Tabi17467f22008-01-11 18:15:26 +010029 *
30 * This structure contains data for a single sound platform device on an
31 * MPC8610 HPCD. Some of the data is taken from the device tree.
32 */
33struct mpc8610_hpcd_data {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000034 struct snd_soc_dai_link dai[2];
35 struct snd_soc_card card;
Timur Tabi17467f22008-01-11 18:15:26 +010036 unsigned int dai_format;
37 unsigned int codec_clk_direction;
38 unsigned int cpu_clk_direction;
39 unsigned int clk_frequency;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000040 unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */
41 unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */
Timur Tabi17467f22008-01-11 18:15:26 +010042 unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000043 char codec_dai_name[DAI_NAME_SIZE];
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000044 char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */
Timur Tabi17467f22008-01-11 18:15:26 +010045};
46
47/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000048 * mpc8610_hpcd_machine_probe: initialize the board
Timur Tabi17467f22008-01-11 18:15:26 +010049 *
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000050 * This function is used to initialize the board-specific hardware.
Timur Tabi17467f22008-01-11 18:15:26 +010051 *
52 * Here we program the DMACR and PMUXCR registers.
53 */
Mark Browne7361ec2011-01-26 14:17:20 +000054static int mpc8610_hpcd_machine_probe(struct snd_soc_card *card)
Timur Tabi17467f22008-01-11 18:15:26 +010055{
56 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000057 container_of(card, struct mpc8610_hpcd_data, card);
Timur Tabi6e6f6622010-07-22 11:33:30 -050058 struct ccsr_guts_86xx __iomem *guts;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000059
Timur Tabi6e6f6622010-07-22 11:33:30 -050060 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_86xx));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000061 if (!guts) {
62 dev_err(card->dev, "could not map global utilities\n");
63 return -ENOMEM;
64 }
Timur Tabi17467f22008-01-11 18:15:26 +010065
66 /* Program the signal routing between the SSI and the DMA */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000067 guts_set_dmacr(guts, machine_data->dma_id[0],
68 machine_data->dma_channel_id[0],
69 CCSR_GUTS_DMACR_DEV_SSI);
70 guts_set_dmacr(guts, machine_data->dma_id[1],
71 machine_data->dma_channel_id[1],
72 CCSR_GUTS_DMACR_DEV_SSI);
Timur Tabi17467f22008-01-11 18:15:26 +010073
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000074 guts_set_pmuxcr_dma(guts, machine_data->dma_id[0],
75 machine_data->dma_channel_id[0], 0);
76 guts_set_pmuxcr_dma(guts, machine_data->dma_id[1],
77 machine_data->dma_channel_id[1], 0);
Timur Tabi17467f22008-01-11 18:15:26 +010078
Timur Tabi17467f22008-01-11 18:15:26 +010079 switch (machine_data->ssi_id) {
80 case 0:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000081 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi17467f22008-01-11 18:15:26 +010082 CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_SSI);
83 break;
84 case 1:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000085 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi17467f22008-01-11 18:15:26 +010086 CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_SSI);
87 break;
88 }
89
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000090 iounmap(guts);
91
Timur Tabi17467f22008-01-11 18:15:26 +010092 return 0;
93}
94
95/**
96 * mpc8610_hpcd_startup: program the board with various hardware parameters
97 *
98 * This function takes board-specific information, like clock frequencies
99 * and serial data formats, and passes that information to the codec and
100 * transport drivers.
101 */
102static int mpc8610_hpcd_startup(struct snd_pcm_substream *substream)
103{
104 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Timur Tabi17467f22008-01-11 18:15:26 +0100105 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000106 container_of(rtd->card, struct mpc8610_hpcd_data, card);
107 struct device *dev = rtd->card->dev;
Timur Tabi17467f22008-01-11 18:15:26 +0100108 int ret = 0;
109
Timur Tabi17467f22008-01-11 18:15:26 +0100110 /* Tell the codec driver what the serial protocol is. */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000111 ret = snd_soc_dai_set_fmt(rtd->codec_dai, machine_data->dai_format);
Liam Girdwood64105cf2008-07-08 13:19:18 +0100112 if (ret < 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000113 dev_err(dev, "could not set codec driver audio format\n");
Liam Girdwood64105cf2008-07-08 13:19:18 +0100114 return ret;
Timur Tabi17467f22008-01-11 18:15:26 +0100115 }
116
117 /*
118 * Tell the codec driver what the MCLK frequency is, and whether it's
119 * a slave or master.
120 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000121 ret = snd_soc_dai_set_sysclk(rtd->codec_dai, 0,
122 machine_data->clk_frequency,
123 machine_data->codec_clk_direction);
Liam Girdwood64105cf2008-07-08 13:19:18 +0100124 if (ret < 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000125 dev_err(dev, "could not set codec driver clock params\n");
Liam Girdwood64105cf2008-07-08 13:19:18 +0100126 return ret;
Timur Tabi17467f22008-01-11 18:15:26 +0100127 }
128
129 return 0;
130}
131
132/**
133 * mpc8610_hpcd_machine_remove: Remove the sound device
134 *
135 * This function is called to remove the sound device for one SSI. We
136 * de-program the DMACR and PMUXCR register.
137 */
Mark Browne7361ec2011-01-26 14:17:20 +0000138static int mpc8610_hpcd_machine_remove(struct snd_soc_card *card)
Timur Tabi17467f22008-01-11 18:15:26 +0100139{
140 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000141 container_of(card, struct mpc8610_hpcd_data, card);
Timur Tabi6e6f6622010-07-22 11:33:30 -0500142 struct ccsr_guts_86xx __iomem *guts;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000143
Timur Tabi6e6f6622010-07-22 11:33:30 -0500144 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_86xx));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000145 if (!guts) {
146 dev_err(card->dev, "could not map global utilities\n");
147 return -ENOMEM;
148 }
Timur Tabi17467f22008-01-11 18:15:26 +0100149
150 /* Restore the signal routing */
151
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000152 guts_set_dmacr(guts, machine_data->dma_id[0],
153 machine_data->dma_channel_id[0], 0);
154 guts_set_dmacr(guts, machine_data->dma_id[1],
155 machine_data->dma_channel_id[1], 0);
Timur Tabi17467f22008-01-11 18:15:26 +0100156
157 switch (machine_data->ssi_id) {
158 case 0:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000159 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi17467f22008-01-11 18:15:26 +0100160 CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_LA);
161 break;
162 case 1:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000163 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi83544992008-06-13 14:02:31 -0500164 CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_LA);
Timur Tabi17467f22008-01-11 18:15:26 +0100165 break;
166 }
167
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000168 iounmap(guts);
169
Timur Tabi17467f22008-01-11 18:15:26 +0100170 return 0;
171}
172
173/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000174 * mpc8610_hpcd_ops: ASoC machine driver operations
Timur Tabi17467f22008-01-11 18:15:26 +0100175 */
176static struct snd_soc_ops mpc8610_hpcd_ops = {
177 .startup = mpc8610_hpcd_startup,
178};
179
180/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000181 * mpc8610_hpcd_probe: platform probe function for the machine driver
182 *
183 * Although this is a machine driver, the SSI node is the "master" node with
Timur Tabi17467f22008-01-11 18:15:26 +0100184 * respect to audio hardware connections. Therefore, we create a new ASoC
185 * device for each new SSI node that has a codec attached.
Timur Tabi17467f22008-01-11 18:15:26 +0100186 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000187static int mpc8610_hpcd_probe(struct platform_device *pdev)
Timur Tabi17467f22008-01-11 18:15:26 +0100188{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000189 struct device *dev = pdev->dev.parent;
Timur Tabi38fec722010-08-19 15:26:58 -0500190 /* ssi_pdev is the platform device for the SSI node that probed us */
191 struct platform_device *ssi_pdev =
192 container_of(dev, struct platform_device, dev);
193 struct device_node *np = ssi_pdev->dev.of_node;
Timur Tabi17467f22008-01-11 18:15:26 +0100194 struct device_node *codec_np = NULL;
Timur Tabi17467f22008-01-11 18:15:26 +0100195 struct platform_device *sound_device = NULL;
196 struct mpc8610_hpcd_data *machine_data;
Timur Tabi17467f22008-01-11 18:15:26 +0100197 int ret = -ENODEV;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000198 const char *sprop;
199 const u32 *iprop;
200
Shawn Guo7c59bc52012-02-24 22:09:37 +0800201 /* Find the codec node for this SSI. */
202 codec_np = of_parse_phandle(np, "codec-handle", 0);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000203 if (!codec_np) {
204 dev_err(dev, "invalid codec node\n");
205 return -EINVAL;
206 }
Timur Tabi17467f22008-01-11 18:15:26 +0100207
208 machine_data = kzalloc(sizeof(struct mpc8610_hpcd_data), GFP_KERNEL);
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200209 if (!machine_data) {
210 ret = -ENOMEM;
211 goto error_alloc;
212 }
Timur Tabi17467f22008-01-11 18:15:26 +0100213
Timur Tabi38fec722010-08-19 15:26:58 -0500214 machine_data->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000215 machine_data->dai[0].ops = &mpc8610_hpcd_ops;
Timur Tabi17467f22008-01-11 18:15:26 +0100216
Shawn Guo8f549d72012-03-16 16:56:41 +0800217 /* ASoC core can match codec with device node */
218 machine_data->dai[0].codec_of_node = codec_np;
Timur Tabi17467f22008-01-11 18:15:26 +0100219
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000220 /* The DAI name from the codec (snd_soc_dai_driver.name) */
221 machine_data->dai[0].codec_dai_name = "cs4270-hifi";
222
223 /* We register two DAIs per SSI, one for playback and the other for
224 * capture. Currently, we only support codecs that have one DAI for
225 * both playback and capture.
Timur Tabi17467f22008-01-11 18:15:26 +0100226 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000227 memcpy(&machine_data->dai[1], &machine_data->dai[0],
228 sizeof(struct snd_soc_dai_link));
Timur Tabi17467f22008-01-11 18:15:26 +0100229
230 /* Get the device ID */
231 iprop = of_get_property(np, "cell-index", NULL);
232 if (!iprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000233 dev_err(&pdev->dev, "cell-index property not found\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100234 ret = -EINVAL;
235 goto error;
236 }
Timur Tabi147dfe92011-06-08 15:02:55 -0500237 machine_data->ssi_id = be32_to_cpup(iprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100238
239 /* Get the serial format and clock direction. */
240 sprop = of_get_property(np, "fsl,mode", NULL);
241 if (!sprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000242 dev_err(&pdev->dev, "fsl,mode property not found\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100243 ret = -EINVAL;
244 goto error;
245 }
246
247 if (strcasecmp(sprop, "i2s-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600248 machine_data->dai_format =
249 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100250 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
251 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
252
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000253 /* In i2s-slave mode, the codec has its own clock source, so we
Timur Tabi17467f22008-01-11 18:15:26 +0100254 * need to get the frequency from the device tree and pass it to
255 * the codec driver.
256 */
257 iprop = of_get_property(codec_np, "clock-frequency", NULL);
258 if (!iprop || !*iprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000259 dev_err(&pdev->dev, "codec bus-frequency "
260 "property is missing or invalid\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100261 ret = -EINVAL;
262 goto error;
263 }
Timur Tabi147dfe92011-06-08 15:02:55 -0500264 machine_data->clk_frequency = be32_to_cpup(iprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100265 } else if (strcasecmp(sprop, "i2s-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600266 machine_data->dai_format =
267 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100268 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
269 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
270 } else if (strcasecmp(sprop, "lj-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600271 machine_data->dai_format =
272 SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100273 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
274 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
275 } else if (strcasecmp(sprop, "lj-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600276 machine_data->dai_format =
277 SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100278 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
279 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
Roel Kluine5c21572008-02-22 18:41:41 +0100280 } else if (strcasecmp(sprop, "rj-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600281 machine_data->dai_format =
282 SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100283 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
284 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
285 } else if (strcasecmp(sprop, "rj-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600286 machine_data->dai_format =
287 SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100288 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
289 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
290 } else if (strcasecmp(sprop, "ac97-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600291 machine_data->dai_format =
292 SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100293 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
294 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
295 } else if (strcasecmp(sprop, "ac97-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600296 machine_data->dai_format =
297 SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100298 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
299 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
300 } else {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000301 dev_err(&pdev->dev,
302 "unrecognized fsl,mode property '%s'\n", sprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100303 ret = -EINVAL;
304 goto error;
305 }
306
307 if (!machine_data->clk_frequency) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000308 dev_err(&pdev->dev, "unknown clock frequency\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100309 ret = -EINVAL;
310 goto error;
311 }
312
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000313 /* Find the playback DMA channel to use. */
314 machine_data->dai[0].platform_name = machine_data->platform_name[0];
Shawn Guo60aae8d2012-03-16 16:56:40 +0800315 ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma",
316 &machine_data->dai[0],
317 &machine_data->dma_channel_id[0],
318 &machine_data->dma_id[0]);
Timur Tabi17467f22008-01-11 18:15:26 +0100319 if (ret) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000320 dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100321 goto error;
322 }
323
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000324 /* Find the capture DMA channel to use. */
325 machine_data->dai[1].platform_name = machine_data->platform_name[1];
Shawn Guo60aae8d2012-03-16 16:56:40 +0800326 ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma",
327 &machine_data->dai[1],
328 &machine_data->dma_channel_id[1],
329 &machine_data->dma_id[1]);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000330 if (ret) {
331 dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100332 goto error;
333 }
334
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000335 /* Initialize our DAI data structure. */
336 machine_data->dai[0].stream_name = "playback";
337 machine_data->dai[1].stream_name = "capture";
338 machine_data->dai[0].name = machine_data->dai[0].stream_name;
339 machine_data->dai[1].name = machine_data->dai[1].stream_name;
Timur Tabi17467f22008-01-11 18:15:26 +0100340
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000341 machine_data->card.probe = mpc8610_hpcd_machine_probe;
342 machine_data->card.remove = mpc8610_hpcd_machine_remove;
343 machine_data->card.name = pdev->name; /* The platform driver name */
344 machine_data->card.num_links = 2;
345 machine_data->card.dai_link = machine_data->dai;
Timur Tabi17467f22008-01-11 18:15:26 +0100346
347 /* Allocate a new audio platform device structure */
348 sound_device = platform_device_alloc("soc-audio", -1);
349 if (!sound_device) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000350 dev_err(&pdev->dev, "platform device alloc failed\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100351 ret = -ENOMEM;
352 goto error;
353 }
354
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000355 /* Associate the card data with the sound device */
356 platform_set_drvdata(sound_device, &machine_data->card);
Timur Tabi17467f22008-01-11 18:15:26 +0100357
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000358 /* Register with ASoC */
Timur Tabi17467f22008-01-11 18:15:26 +0100359 ret = platform_device_add(sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100360 if (ret) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000361 dev_err(&pdev->dev, "platform device add failed\n");
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200362 goto error_sound;
Timur Tabi17467f22008-01-11 18:15:26 +0100363 }
Axel Lin67bd4892010-11-29 14:54:58 +0800364 dev_set_drvdata(&pdev->dev, sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100365
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000366 of_node_put(codec_np);
Timur Tabi17467f22008-01-11 18:15:26 +0100367
368 return 0;
369
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200370error_sound:
Axel Lind890a1a2011-09-20 15:09:00 +0800371 platform_device_put(sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100372error:
Timur Tabi17467f22008-01-11 18:15:26 +0100373 kfree(machine_data);
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200374error_alloc:
375 of_node_put(codec_np);
Timur Tabi17467f22008-01-11 18:15:26 +0100376 return ret;
377}
378
379/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000380 * mpc8610_hpcd_remove: remove the platform device
Timur Tabi17467f22008-01-11 18:15:26 +0100381 *
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000382 * This function is called when the platform device is removed.
Timur Tabi17467f22008-01-11 18:15:26 +0100383 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000384static int __devexit mpc8610_hpcd_remove(struct platform_device *pdev)
Timur Tabi17467f22008-01-11 18:15:26 +0100385{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000386 struct platform_device *sound_device = dev_get_drvdata(&pdev->dev);
387 struct snd_soc_card *card = platform_get_drvdata(sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100388 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000389 container_of(card, struct mpc8610_hpcd_data, card);
Timur Tabi17467f22008-01-11 18:15:26 +0100390
391 platform_device_unregister(sound_device);
392
Timur Tabi17467f22008-01-11 18:15:26 +0100393 kfree(machine_data);
394 sound_device->dev.platform_data = NULL;
395
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000396 dev_set_drvdata(&pdev->dev, NULL);
Timur Tabi17467f22008-01-11 18:15:26 +0100397
398 return 0;
399}
400
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000401static struct platform_driver mpc8610_hpcd_driver = {
402 .probe = mpc8610_hpcd_probe,
403 .remove = __devexit_p(mpc8610_hpcd_remove),
Grant Likely40182942010-04-13 16:13:02 -0700404 .driver = {
Shawn Guo2b81ec62012-03-09 00:59:46 +0800405 /* The name must match 'compatible' property in the device tree,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000406 * in lowercase letters.
407 */
408 .name = "snd-soc-mpc8610hpcd",
Grant Likely40182942010-04-13 16:13:02 -0700409 .owner = THIS_MODULE,
Grant Likely40182942010-04-13 16:13:02 -0700410 },
Timur Tabi17467f22008-01-11 18:15:26 +0100411};
412
413/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000414 * mpc8610_hpcd_init: machine driver initialization.
Timur Tabi17467f22008-01-11 18:15:26 +0100415 *
416 * This function is called when this module is loaded.
417 */
418static int __init mpc8610_hpcd_init(void)
419{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000420 struct device_node *guts_np;
421 struct resource res;
Timur Tabi17467f22008-01-11 18:15:26 +0100422
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000423 pr_info("Freescale MPC8610 HPCD ALSA SoC machine driver\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100424
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000425 /* Get the physical address of the global utilities registers */
426 guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
427 if (of_address_to_resource(guts_np, 0, &res)) {
428 pr_err("mpc8610-hpcd: missing/invalid global utilities node\n");
429 return -EINVAL;
430 }
431 guts_phys = res.start;
Timur Tabi17467f22008-01-11 18:15:26 +0100432
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000433 return platform_driver_register(&mpc8610_hpcd_driver);
Timur Tabi17467f22008-01-11 18:15:26 +0100434}
435
436/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000437 * mpc8610_hpcd_exit: machine driver exit
Timur Tabi17467f22008-01-11 18:15:26 +0100438 *
439 * This function is called when this driver is unloaded.
440 */
441static void __exit mpc8610_hpcd_exit(void)
442{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000443 platform_driver_unregister(&mpc8610_hpcd_driver);
Timur Tabi17467f22008-01-11 18:15:26 +0100444}
445
446module_init(mpc8610_hpcd_init);
447module_exit(mpc8610_hpcd_exit);
448
449MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000450MODULE_DESCRIPTION("Freescale MPC8610 HPCD ALSA SoC machine driver");
451MODULE_LICENSE("GPL v2");