blob: 9ff9318c52b9df42e7c8f61fb3aac2c3bba56983 [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 Tabi9cb6abc2012-03-19 11:06:39 -050058 struct ccsr_guts __iomem *guts;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000059
Timur Tabi9cb6abc2012-03-19 11:06:39 -050060 guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
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 Tabi9cb6abc2012-03-19 11:06:39 -0500142 struct ccsr_guts __iomem *guts;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000143
Timur Tabi9cb6abc2012-03-19 11:06:39 -0500144 guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
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 mpc8610_hpcd_data *machine_data;
Timur Tabi17467f22008-01-11 18:15:26 +0100196 int ret = -ENODEV;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000197 const char *sprop;
198 const u32 *iprop;
199
Shawn Guo7c59bc52012-02-24 22:09:37 +0800200 /* Find the codec node for this SSI. */
201 codec_np = of_parse_phandle(np, "codec-handle", 0);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000202 if (!codec_np) {
203 dev_err(dev, "invalid codec node\n");
204 return -EINVAL;
205 }
Timur Tabi17467f22008-01-11 18:15:26 +0100206
207 machine_data = kzalloc(sizeof(struct mpc8610_hpcd_data), GFP_KERNEL);
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200208 if (!machine_data) {
209 ret = -ENOMEM;
210 goto error_alloc;
211 }
Timur Tabi17467f22008-01-11 18:15:26 +0100212
Timur Tabi38fec722010-08-19 15:26:58 -0500213 machine_data->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000214 machine_data->dai[0].ops = &mpc8610_hpcd_ops;
Timur Tabi17467f22008-01-11 18:15:26 +0100215
Shawn Guo8f549d72012-03-16 16:56:41 +0800216 /* ASoC core can match codec with device node */
217 machine_data->dai[0].codec_of_node = codec_np;
Timur Tabi17467f22008-01-11 18:15:26 +0100218
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000219 /* The DAI name from the codec (snd_soc_dai_driver.name) */
220 machine_data->dai[0].codec_dai_name = "cs4270-hifi";
221
222 /* We register two DAIs per SSI, one for playback and the other for
223 * capture. Currently, we only support codecs that have one DAI for
224 * both playback and capture.
Timur Tabi17467f22008-01-11 18:15:26 +0100225 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000226 memcpy(&machine_data->dai[1], &machine_data->dai[0],
227 sizeof(struct snd_soc_dai_link));
Timur Tabi17467f22008-01-11 18:15:26 +0100228
229 /* Get the device ID */
230 iprop = of_get_property(np, "cell-index", NULL);
231 if (!iprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000232 dev_err(&pdev->dev, "cell-index property not found\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100233 ret = -EINVAL;
234 goto error;
235 }
Timur Tabi147dfe92011-06-08 15:02:55 -0500236 machine_data->ssi_id = be32_to_cpup(iprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100237
238 /* Get the serial format and clock direction. */
239 sprop = of_get_property(np, "fsl,mode", NULL);
240 if (!sprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000241 dev_err(&pdev->dev, "fsl,mode property not found\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100242 ret = -EINVAL;
243 goto error;
244 }
245
246 if (strcasecmp(sprop, "i2s-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600247 machine_data->dai_format =
248 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100249 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
250 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
251
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000252 /* In i2s-slave mode, the codec has its own clock source, so we
Timur Tabi17467f22008-01-11 18:15:26 +0100253 * need to get the frequency from the device tree and pass it to
254 * the codec driver.
255 */
256 iprop = of_get_property(codec_np, "clock-frequency", NULL);
257 if (!iprop || !*iprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000258 dev_err(&pdev->dev, "codec bus-frequency "
259 "property is missing or invalid\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100260 ret = -EINVAL;
261 goto error;
262 }
Timur Tabi147dfe92011-06-08 15:02:55 -0500263 machine_data->clk_frequency = be32_to_cpup(iprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100264 } else if (strcasecmp(sprop, "i2s-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600265 machine_data->dai_format =
266 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100267 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
268 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
269 } else if (strcasecmp(sprop, "lj-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600270 machine_data->dai_format =
271 SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100272 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
273 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
274 } else if (strcasecmp(sprop, "lj-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600275 machine_data->dai_format =
276 SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100277 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
278 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
Roel Kluine5c21572008-02-22 18:41:41 +0100279 } else if (strcasecmp(sprop, "rj-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600280 machine_data->dai_format =
281 SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100282 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
283 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
284 } else if (strcasecmp(sprop, "rj-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600285 machine_data->dai_format =
286 SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100287 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
288 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
289 } else if (strcasecmp(sprop, "ac97-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600290 machine_data->dai_format =
291 SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100292 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
293 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
294 } else if (strcasecmp(sprop, "ac97-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600295 machine_data->dai_format =
296 SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100297 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
298 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
299 } else {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000300 dev_err(&pdev->dev,
301 "unrecognized fsl,mode property '%s'\n", sprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100302 ret = -EINVAL;
303 goto error;
304 }
305
306 if (!machine_data->clk_frequency) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000307 dev_err(&pdev->dev, "unknown clock frequency\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100308 ret = -EINVAL;
309 goto error;
310 }
311
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000312 /* Find the playback DMA channel to use. */
313 machine_data->dai[0].platform_name = machine_data->platform_name[0];
Shawn Guo60aae8d2012-03-16 16:56:40 +0800314 ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma",
315 &machine_data->dai[0],
316 &machine_data->dma_channel_id[0],
317 &machine_data->dma_id[0]);
Timur Tabi17467f22008-01-11 18:15:26 +0100318 if (ret) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000319 dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100320 goto error;
321 }
322
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000323 /* Find the capture DMA channel to use. */
324 machine_data->dai[1].platform_name = machine_data->platform_name[1];
Shawn Guo60aae8d2012-03-16 16:56:40 +0800325 ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma",
326 &machine_data->dai[1],
327 &machine_data->dma_channel_id[1],
328 &machine_data->dma_id[1]);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000329 if (ret) {
330 dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100331 goto error;
332 }
333
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000334 /* Initialize our DAI data structure. */
335 machine_data->dai[0].stream_name = "playback";
336 machine_data->dai[1].stream_name = "capture";
337 machine_data->dai[0].name = machine_data->dai[0].stream_name;
338 machine_data->dai[1].name = machine_data->dai[1].stream_name;
Timur Tabi17467f22008-01-11 18:15:26 +0100339
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000340 machine_data->card.probe = mpc8610_hpcd_machine_probe;
341 machine_data->card.remove = mpc8610_hpcd_machine_remove;
342 machine_data->card.name = pdev->name; /* The platform driver name */
Timur Tabi13c57e52012-09-14 16:14:34 -0500343 machine_data->card.owner = THIS_MODULE;
344 machine_data->card.dev = &pdev->dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000345 machine_data->card.num_links = 2;
346 machine_data->card.dai_link = machine_data->dai;
Timur Tabi17467f22008-01-11 18:15:26 +0100347
Timur Tabi13c57e52012-09-14 16:14:34 -0500348 /* Register with ASoC */
349 ret = snd_soc_register_card(&machine_data->card);
350 if (ret) {
351 dev_err(&pdev->dev, "could not register card\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100352 goto error;
353 }
354
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000355 of_node_put(codec_np);
Timur Tabi17467f22008-01-11 18:15:26 +0100356
357 return 0;
358
359error:
Timur Tabi17467f22008-01-11 18:15:26 +0100360 kfree(machine_data);
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200361error_alloc:
362 of_node_put(codec_np);
Timur Tabi17467f22008-01-11 18:15:26 +0100363 return ret;
364}
365
366/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000367 * mpc8610_hpcd_remove: remove the platform device
Timur Tabi17467f22008-01-11 18:15:26 +0100368 *
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000369 * This function is called when the platform device is removed.
Timur Tabi17467f22008-01-11 18:15:26 +0100370 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000371static int __devexit mpc8610_hpcd_remove(struct platform_device *pdev)
Timur Tabi17467f22008-01-11 18:15:26 +0100372{
Timur Tabi13c57e52012-09-14 16:14:34 -0500373 struct snd_soc_card *card = platform_get_drvdata(pdev);
Timur Tabi17467f22008-01-11 18:15:26 +0100374 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000375 container_of(card, struct mpc8610_hpcd_data, card);
Timur Tabi17467f22008-01-11 18:15:26 +0100376
Timur Tabi13c57e52012-09-14 16:14:34 -0500377 snd_soc_unregister_card(card);
Timur Tabi17467f22008-01-11 18:15:26 +0100378 kfree(machine_data);
Timur Tabi17467f22008-01-11 18:15:26 +0100379
380 return 0;
381}
382
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000383static struct platform_driver mpc8610_hpcd_driver = {
384 .probe = mpc8610_hpcd_probe,
385 .remove = __devexit_p(mpc8610_hpcd_remove),
Grant Likely40182942010-04-13 16:13:02 -0700386 .driver = {
Shawn Guo2b81ec62012-03-09 00:59:46 +0800387 /* The name must match 'compatible' property in the device tree,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000388 * in lowercase letters.
389 */
390 .name = "snd-soc-mpc8610hpcd",
Grant Likely40182942010-04-13 16:13:02 -0700391 .owner = THIS_MODULE,
Grant Likely40182942010-04-13 16:13:02 -0700392 },
Timur Tabi17467f22008-01-11 18:15:26 +0100393};
394
395/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000396 * mpc8610_hpcd_init: machine driver initialization.
Timur Tabi17467f22008-01-11 18:15:26 +0100397 *
398 * This function is called when this module is loaded.
399 */
400static int __init mpc8610_hpcd_init(void)
401{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000402 struct device_node *guts_np;
403 struct resource res;
Timur Tabi17467f22008-01-11 18:15:26 +0100404
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000405 pr_info("Freescale MPC8610 HPCD ALSA SoC machine driver\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100406
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000407 /* Get the physical address of the global utilities registers */
408 guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
409 if (of_address_to_resource(guts_np, 0, &res)) {
410 pr_err("mpc8610-hpcd: missing/invalid global utilities node\n");
411 return -EINVAL;
412 }
413 guts_phys = res.start;
Timur Tabi17467f22008-01-11 18:15:26 +0100414
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000415 return platform_driver_register(&mpc8610_hpcd_driver);
Timur Tabi17467f22008-01-11 18:15:26 +0100416}
417
418/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000419 * mpc8610_hpcd_exit: machine driver exit
Timur Tabi17467f22008-01-11 18:15:26 +0100420 *
421 * This function is called when this driver is unloaded.
422 */
423static void __exit mpc8610_hpcd_exit(void)
424{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000425 platform_driver_unregister(&mpc8610_hpcd_driver);
Timur Tabi17467f22008-01-11 18:15:26 +0100426}
427
428module_init(mpc8610_hpcd_init);
429module_exit(mpc8610_hpcd_exit);
430
431MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000432MODULE_DESCRIPTION("Freescale MPC8610 HPCD ALSA SoC machine driver");
433MODULE_LICENSE("GPL v2");