blob: 41951820b50ecbca9c984cc26f632cf7cf2e0621 [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];
44 char codec_name[DAI_NAME_SIZE];
45 char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */
Timur Tabi17467f22008-01-11 18:15:26 +010046};
47
48/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000049 * mpc8610_hpcd_machine_probe: initialize the board
Timur Tabi17467f22008-01-11 18:15:26 +010050 *
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000051 * This function is used to initialize the board-specific hardware.
Timur Tabi17467f22008-01-11 18:15:26 +010052 *
53 * Here we program the DMACR and PMUXCR registers.
54 */
Mark Browne7361ec2011-01-26 14:17:20 +000055static int mpc8610_hpcd_machine_probe(struct snd_soc_card *card)
Timur Tabi17467f22008-01-11 18:15:26 +010056{
57 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000058 container_of(card, struct mpc8610_hpcd_data, card);
Timur Tabi6e6f6622010-07-22 11:33:30 -050059 struct ccsr_guts_86xx __iomem *guts;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000060
Timur Tabi6e6f6622010-07-22 11:33:30 -050061 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_86xx));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000062 if (!guts) {
63 dev_err(card->dev, "could not map global utilities\n");
64 return -ENOMEM;
65 }
Timur Tabi17467f22008-01-11 18:15:26 +010066
67 /* Program the signal routing between the SSI and the DMA */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000068 guts_set_dmacr(guts, machine_data->dma_id[0],
69 machine_data->dma_channel_id[0],
70 CCSR_GUTS_DMACR_DEV_SSI);
71 guts_set_dmacr(guts, machine_data->dma_id[1],
72 machine_data->dma_channel_id[1],
73 CCSR_GUTS_DMACR_DEV_SSI);
Timur Tabi17467f22008-01-11 18:15:26 +010074
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000075 guts_set_pmuxcr_dma(guts, machine_data->dma_id[0],
76 machine_data->dma_channel_id[0], 0);
77 guts_set_pmuxcr_dma(guts, machine_data->dma_id[1],
78 machine_data->dma_channel_id[1], 0);
Timur Tabi17467f22008-01-11 18:15:26 +010079
Timur Tabi17467f22008-01-11 18:15:26 +010080 switch (machine_data->ssi_id) {
81 case 0:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000082 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi17467f22008-01-11 18:15:26 +010083 CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_SSI);
84 break;
85 case 1:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000086 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi17467f22008-01-11 18:15:26 +010087 CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_SSI);
88 break;
89 }
90
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000091 iounmap(guts);
92
Timur Tabi17467f22008-01-11 18:15:26 +010093 return 0;
94}
95
96/**
97 * mpc8610_hpcd_startup: program the board with various hardware parameters
98 *
99 * This function takes board-specific information, like clock frequencies
100 * and serial data formats, and passes that information to the codec and
101 * transport drivers.
102 */
103static int mpc8610_hpcd_startup(struct snd_pcm_substream *substream)
104{
105 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Timur Tabi17467f22008-01-11 18:15:26 +0100106 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000107 container_of(rtd->card, struct mpc8610_hpcd_data, card);
108 struct device *dev = rtd->card->dev;
Timur Tabi17467f22008-01-11 18:15:26 +0100109 int ret = 0;
110
Timur Tabi17467f22008-01-11 18:15:26 +0100111 /* Tell the codec driver what the serial protocol is. */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000112 ret = snd_soc_dai_set_fmt(rtd->codec_dai, machine_data->dai_format);
Liam Girdwood64105cf2008-07-08 13:19:18 +0100113 if (ret < 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000114 dev_err(dev, "could not set codec driver audio format\n");
Liam Girdwood64105cf2008-07-08 13:19:18 +0100115 return ret;
Timur Tabi17467f22008-01-11 18:15:26 +0100116 }
117
118 /*
119 * Tell the codec driver what the MCLK frequency is, and whether it's
120 * a slave or master.
121 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000122 ret = snd_soc_dai_set_sysclk(rtd->codec_dai, 0,
123 machine_data->clk_frequency,
124 machine_data->codec_clk_direction);
Liam Girdwood64105cf2008-07-08 13:19:18 +0100125 if (ret < 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000126 dev_err(dev, "could not set codec driver clock params\n");
Liam Girdwood64105cf2008-07-08 13:19:18 +0100127 return ret;
Timur Tabi17467f22008-01-11 18:15:26 +0100128 }
129
130 return 0;
131}
132
133/**
134 * mpc8610_hpcd_machine_remove: Remove the sound device
135 *
136 * This function is called to remove the sound device for one SSI. We
137 * de-program the DMACR and PMUXCR register.
138 */
Mark Browne7361ec2011-01-26 14:17:20 +0000139static int mpc8610_hpcd_machine_remove(struct snd_soc_card *card)
Timur Tabi17467f22008-01-11 18:15:26 +0100140{
141 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000142 container_of(card, struct mpc8610_hpcd_data, card);
Timur Tabi6e6f6622010-07-22 11:33:30 -0500143 struct ccsr_guts_86xx __iomem *guts;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000144
Timur Tabi6e6f6622010-07-22 11:33:30 -0500145 guts = ioremap(guts_phys, sizeof(struct ccsr_guts_86xx));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000146 if (!guts) {
147 dev_err(card->dev, "could not map global utilities\n");
148 return -ENOMEM;
149 }
Timur Tabi17467f22008-01-11 18:15:26 +0100150
151 /* Restore the signal routing */
152
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000153 guts_set_dmacr(guts, machine_data->dma_id[0],
154 machine_data->dma_channel_id[0], 0);
155 guts_set_dmacr(guts, machine_data->dma_id[1],
156 machine_data->dma_channel_id[1], 0);
Timur Tabi17467f22008-01-11 18:15:26 +0100157
158 switch (machine_data->ssi_id) {
159 case 0:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000160 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi17467f22008-01-11 18:15:26 +0100161 CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_LA);
162 break;
163 case 1:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000164 clrsetbits_be32(&guts->pmuxcr,
Timur Tabi83544992008-06-13 14:02:31 -0500165 CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_LA);
Timur Tabi17467f22008-01-11 18:15:26 +0100166 break;
167 }
168
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000169 iounmap(guts);
170
Timur Tabi17467f22008-01-11 18:15:26 +0100171 return 0;
172}
173
174/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000175 * mpc8610_hpcd_ops: ASoC machine driver operations
Timur Tabi17467f22008-01-11 18:15:26 +0100176 */
177static struct snd_soc_ops mpc8610_hpcd_ops = {
178 .startup = mpc8610_hpcd_startup,
179};
180
181/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000182 * mpc8610_hpcd_probe: platform probe function for the machine driver
183 *
184 * Although this is a machine driver, the SSI node is the "master" node with
Timur Tabi17467f22008-01-11 18:15:26 +0100185 * respect to audio hardware connections. Therefore, we create a new ASoC
186 * device for each new SSI node that has a codec attached.
Timur Tabi17467f22008-01-11 18:15:26 +0100187 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000188static int mpc8610_hpcd_probe(struct platform_device *pdev)
Timur Tabi17467f22008-01-11 18:15:26 +0100189{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000190 struct device *dev = pdev->dev.parent;
Timur Tabi38fec722010-08-19 15:26:58 -0500191 /* ssi_pdev is the platform device for the SSI node that probed us */
192 struct platform_device *ssi_pdev =
193 container_of(dev, struct platform_device, dev);
194 struct device_node *np = ssi_pdev->dev.of_node;
Timur Tabi17467f22008-01-11 18:15:26 +0100195 struct device_node *codec_np = NULL;
Timur Tabi17467f22008-01-11 18:15:26 +0100196 struct platform_device *sound_device = NULL;
197 struct mpc8610_hpcd_data *machine_data;
Timur Tabi17467f22008-01-11 18:15:26 +0100198 int ret = -ENODEV;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000199 const char *sprop;
200 const u32 *iprop;
201
Shawn Guo7c59bc52012-02-24 22:09:37 +0800202 /* Find the codec node for this SSI. */
203 codec_np = of_parse_phandle(np, "codec-handle", 0);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000204 if (!codec_np) {
205 dev_err(dev, "invalid codec node\n");
206 return -EINVAL;
207 }
Timur Tabi17467f22008-01-11 18:15:26 +0100208
209 machine_data = kzalloc(sizeof(struct mpc8610_hpcd_data), GFP_KERNEL);
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200210 if (!machine_data) {
211 ret = -ENOMEM;
212 goto error_alloc;
213 }
Timur Tabi17467f22008-01-11 18:15:26 +0100214
Timur Tabi38fec722010-08-19 15:26:58 -0500215 machine_data->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000216 machine_data->dai[0].ops = &mpc8610_hpcd_ops;
Timur Tabi17467f22008-01-11 18:15:26 +0100217
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000218 /* Determine the codec name, it will be used as the codec DAI name */
Shawn Guo60aae8d2012-03-16 16:56:40 +0800219 ret = fsl_asoc_get_codec_dev_name(codec_np, machine_data->codec_name,
220 DAI_NAME_SIZE);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000221 if (ret) {
222 dev_err(&pdev->dev, "invalid codec node %s\n",
223 codec_np->full_name);
224 ret = -EINVAL;
225 goto error;
226 }
227 machine_data->dai[0].codec_name = machine_data->codec_name;
Timur Tabi17467f22008-01-11 18:15:26 +0100228
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000229 /* The DAI name from the codec (snd_soc_dai_driver.name) */
230 machine_data->dai[0].codec_dai_name = "cs4270-hifi";
231
232 /* We register two DAIs per SSI, one for playback and the other for
233 * capture. Currently, we only support codecs that have one DAI for
234 * both playback and capture.
Timur Tabi17467f22008-01-11 18:15:26 +0100235 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000236 memcpy(&machine_data->dai[1], &machine_data->dai[0],
237 sizeof(struct snd_soc_dai_link));
Timur Tabi17467f22008-01-11 18:15:26 +0100238
239 /* Get the device ID */
240 iprop = of_get_property(np, "cell-index", NULL);
241 if (!iprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000242 dev_err(&pdev->dev, "cell-index property not found\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100243 ret = -EINVAL;
244 goto error;
245 }
Timur Tabi147dfe92011-06-08 15:02:55 -0500246 machine_data->ssi_id = be32_to_cpup(iprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100247
248 /* Get the serial format and clock direction. */
249 sprop = of_get_property(np, "fsl,mode", NULL);
250 if (!sprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000251 dev_err(&pdev->dev, "fsl,mode property not found\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100252 ret = -EINVAL;
253 goto error;
254 }
255
256 if (strcasecmp(sprop, "i2s-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600257 machine_data->dai_format =
258 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100259 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
260 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
261
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000262 /* In i2s-slave mode, the codec has its own clock source, so we
Timur Tabi17467f22008-01-11 18:15:26 +0100263 * need to get the frequency from the device tree and pass it to
264 * the codec driver.
265 */
266 iprop = of_get_property(codec_np, "clock-frequency", NULL);
267 if (!iprop || !*iprop) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000268 dev_err(&pdev->dev, "codec bus-frequency "
269 "property is missing or invalid\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100270 ret = -EINVAL;
271 goto error;
272 }
Timur Tabi147dfe92011-06-08 15:02:55 -0500273 machine_data->clk_frequency = be32_to_cpup(iprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100274 } else if (strcasecmp(sprop, "i2s-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600275 machine_data->dai_format =
276 SND_SOC_DAIFMT_I2S | 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;
279 } else if (strcasecmp(sprop, "lj-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600280 machine_data->dai_format =
281 SND_SOC_DAIFMT_LEFT_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, "lj-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600285 machine_data->dai_format =
286 SND_SOC_DAIFMT_LEFT_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;
Roel Kluine5c21572008-02-22 18:41:41 +0100289 } else if (strcasecmp(sprop, "rj-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600290 machine_data->dai_format =
291 SND_SOC_DAIFMT_RIGHT_J | 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, "rj-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600295 machine_data->dai_format =
296 SND_SOC_DAIFMT_RIGHT_J | 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 if (strcasecmp(sprop, "ac97-slave") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600300 machine_data->dai_format =
301 SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBM_CFM;
Timur Tabi17467f22008-01-11 18:15:26 +0100302 machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT;
303 machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN;
304 } else if (strcasecmp(sprop, "ac97-master") == 0) {
Timur Tabi380c8832011-11-22 14:38:59 -0600305 machine_data->dai_format =
306 SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBS_CFS;
Timur Tabi17467f22008-01-11 18:15:26 +0100307 machine_data->codec_clk_direction = SND_SOC_CLOCK_IN;
308 machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT;
309 } else {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000310 dev_err(&pdev->dev,
311 "unrecognized fsl,mode property '%s'\n", sprop);
Timur Tabi17467f22008-01-11 18:15:26 +0100312 ret = -EINVAL;
313 goto error;
314 }
315
316 if (!machine_data->clk_frequency) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000317 dev_err(&pdev->dev, "unknown clock frequency\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100318 ret = -EINVAL;
319 goto error;
320 }
321
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000322 /* Find the playback DMA channel to use. */
323 machine_data->dai[0].platform_name = machine_data->platform_name[0];
Shawn Guo60aae8d2012-03-16 16:56:40 +0800324 ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma",
325 &machine_data->dai[0],
326 &machine_data->dma_channel_id[0],
327 &machine_data->dma_id[0]);
Timur Tabi17467f22008-01-11 18:15:26 +0100328 if (ret) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000329 dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100330 goto error;
331 }
332
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000333 /* Find the capture DMA channel to use. */
334 machine_data->dai[1].platform_name = machine_data->platform_name[1];
Shawn Guo60aae8d2012-03-16 16:56:40 +0800335 ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma",
336 &machine_data->dai[1],
337 &machine_data->dma_channel_id[1],
338 &machine_data->dma_id[1]);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000339 if (ret) {
340 dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100341 goto error;
342 }
343
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000344 /* Initialize our DAI data structure. */
345 machine_data->dai[0].stream_name = "playback";
346 machine_data->dai[1].stream_name = "capture";
347 machine_data->dai[0].name = machine_data->dai[0].stream_name;
348 machine_data->dai[1].name = machine_data->dai[1].stream_name;
Timur Tabi17467f22008-01-11 18:15:26 +0100349
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000350 machine_data->card.probe = mpc8610_hpcd_machine_probe;
351 machine_data->card.remove = mpc8610_hpcd_machine_remove;
352 machine_data->card.name = pdev->name; /* The platform driver name */
353 machine_data->card.num_links = 2;
354 machine_data->card.dai_link = machine_data->dai;
Timur Tabi17467f22008-01-11 18:15:26 +0100355
356 /* Allocate a new audio platform device structure */
357 sound_device = platform_device_alloc("soc-audio", -1);
358 if (!sound_device) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000359 dev_err(&pdev->dev, "platform device alloc failed\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100360 ret = -ENOMEM;
361 goto error;
362 }
363
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000364 /* Associate the card data with the sound device */
365 platform_set_drvdata(sound_device, &machine_data->card);
Timur Tabi17467f22008-01-11 18:15:26 +0100366
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000367 /* Register with ASoC */
Timur Tabi17467f22008-01-11 18:15:26 +0100368 ret = platform_device_add(sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100369 if (ret) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000370 dev_err(&pdev->dev, "platform device add failed\n");
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200371 goto error_sound;
Timur Tabi17467f22008-01-11 18:15:26 +0100372 }
Axel Lin67bd4892010-11-29 14:54:58 +0800373 dev_set_drvdata(&pdev->dev, sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100374
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000375 of_node_put(codec_np);
Timur Tabi17467f22008-01-11 18:15:26 +0100376
377 return 0;
378
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200379error_sound:
Axel Lind890a1a2011-09-20 15:09:00 +0800380 platform_device_put(sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100381error:
Timur Tabi17467f22008-01-11 18:15:26 +0100382 kfree(machine_data);
Julia Lawallc09f5ca2011-08-20 09:02:01 +0200383error_alloc:
384 of_node_put(codec_np);
Timur Tabi17467f22008-01-11 18:15:26 +0100385 return ret;
386}
387
388/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000389 * mpc8610_hpcd_remove: remove the platform device
Timur Tabi17467f22008-01-11 18:15:26 +0100390 *
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000391 * This function is called when the platform device is removed.
Timur Tabi17467f22008-01-11 18:15:26 +0100392 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000393static int __devexit mpc8610_hpcd_remove(struct platform_device *pdev)
Timur Tabi17467f22008-01-11 18:15:26 +0100394{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000395 struct platform_device *sound_device = dev_get_drvdata(&pdev->dev);
396 struct snd_soc_card *card = platform_get_drvdata(sound_device);
Timur Tabi17467f22008-01-11 18:15:26 +0100397 struct mpc8610_hpcd_data *machine_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000398 container_of(card, struct mpc8610_hpcd_data, card);
Timur Tabi17467f22008-01-11 18:15:26 +0100399
400 platform_device_unregister(sound_device);
401
Timur Tabi17467f22008-01-11 18:15:26 +0100402 kfree(machine_data);
403 sound_device->dev.platform_data = NULL;
404
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000405 dev_set_drvdata(&pdev->dev, NULL);
Timur Tabi17467f22008-01-11 18:15:26 +0100406
407 return 0;
408}
409
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000410static struct platform_driver mpc8610_hpcd_driver = {
411 .probe = mpc8610_hpcd_probe,
412 .remove = __devexit_p(mpc8610_hpcd_remove),
Grant Likely40182942010-04-13 16:13:02 -0700413 .driver = {
Shawn Guo2b81ec62012-03-09 00:59:46 +0800414 /* The name must match 'compatible' property in the device tree,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000415 * in lowercase letters.
416 */
417 .name = "snd-soc-mpc8610hpcd",
Grant Likely40182942010-04-13 16:13:02 -0700418 .owner = THIS_MODULE,
Grant Likely40182942010-04-13 16:13:02 -0700419 },
Timur Tabi17467f22008-01-11 18:15:26 +0100420};
421
422/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000423 * mpc8610_hpcd_init: machine driver initialization.
Timur Tabi17467f22008-01-11 18:15:26 +0100424 *
425 * This function is called when this module is loaded.
426 */
427static int __init mpc8610_hpcd_init(void)
428{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000429 struct device_node *guts_np;
430 struct resource res;
Timur Tabi17467f22008-01-11 18:15:26 +0100431
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000432 pr_info("Freescale MPC8610 HPCD ALSA SoC machine driver\n");
Timur Tabi17467f22008-01-11 18:15:26 +0100433
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000434 /* Get the physical address of the global utilities registers */
435 guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
436 if (of_address_to_resource(guts_np, 0, &res)) {
437 pr_err("mpc8610-hpcd: missing/invalid global utilities node\n");
438 return -EINVAL;
439 }
440 guts_phys = res.start;
Timur Tabi17467f22008-01-11 18:15:26 +0100441
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000442 return platform_driver_register(&mpc8610_hpcd_driver);
Timur Tabi17467f22008-01-11 18:15:26 +0100443}
444
445/**
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000446 * mpc8610_hpcd_exit: machine driver exit
Timur Tabi17467f22008-01-11 18:15:26 +0100447 *
448 * This function is called when this driver is unloaded.
449 */
450static void __exit mpc8610_hpcd_exit(void)
451{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000452 platform_driver_unregister(&mpc8610_hpcd_driver);
Timur Tabi17467f22008-01-11 18:15:26 +0100453}
454
455module_init(mpc8610_hpcd_init);
456module_exit(mpc8610_hpcd_exit);
457
458MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000459MODULE_DESCRIPTION("Freescale MPC8610 HPCD ALSA SoC machine driver");
460MODULE_LICENSE("GPL v2");