fsi-ak4642.c 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * FSI-AK464x sound support for ms7724se
 *
 * Copyright (C) 2009 Renesas Solutions Corp.
 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */

#include <linux/platform_device.h>
#include <sound/sh_fsi.h>

15 16
struct fsi_ak4642_data {
	const char *name;
17
	const char *card;
18 19 20
	const char *cpu_dai;
	const char *codec;
	const char *platform;
21
	int id;
22 23
};

24
static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
25
{
26 27
	struct snd_soc_dai *codec = rtd->codec_dai;
	struct snd_soc_dai *cpu = rtd->cpu_dai;
28 29
	int ret;

30 31
	ret = snd_soc_dai_set_fmt(codec, SND_SOC_DAIFMT_LEFT_J |
					 SND_SOC_DAIFMT_CBM_CFM);
32 33 34
	if (ret < 0)
		return ret;

35 36 37 38
	ret = snd_soc_dai_set_sysclk(codec, 0, 11289600, 0);
	if (ret < 0)
		return ret;

39 40
	ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_LEFT_J |
				       SND_SOC_DAIFMT_CBS_CFS);
41 42 43 44

	return ret;
}

45
static struct snd_soc_dai_link fsi_dai_link = {
46
	.codec_dai_name	= "ak4642-hifi",
47
	.init		= fsi_ak4642_dai_init,
48 49 50 51 52 53 54 55 56
};

static struct snd_soc_card fsi_soc_card  = {
	.dai_link	= &fsi_dai_link,
	.num_links	= 1,
};

static struct platform_device *fsi_snd_device;

57
static int fsi_ak4642_probe(struct platform_device *pdev)
58 59
{
	int ret = -ENOMEM;
60 61 62 63 64 65 66 67 68 69
	const struct platform_device_id	*id_entry;
	struct fsi_ak4642_data *pdata;

	id_entry = pdev->id_entry;
	if (!id_entry) {
		dev_err(&pdev->dev, "unknown fsi ak4642\n");
		return -ENODEV;
	}

	pdata = (struct fsi_ak4642_data *)id_entry->driver_data;
70

71
	fsi_snd_device = platform_device_alloc("soc-audio", pdata->id);
72 73 74
	if (!fsi_snd_device)
		goto out;

75 76 77 78 79
	fsi_dai_link.name		= pdata->name;
	fsi_dai_link.stream_name	= pdata->name;
	fsi_dai_link.cpu_dai_name	= pdata->cpu_dai;
	fsi_dai_link.platform_name	= pdata->platform;
	fsi_dai_link.codec_name		= pdata->codec;
80
	fsi_soc_card.name		= pdata->card;
81

82
	platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
83 84 85 86 87 88 89 90 91
	ret = platform_device_add(fsi_snd_device);

	if (ret)
		platform_device_put(fsi_snd_device);

out:
	return ret;
}

92
static int fsi_ak4642_remove(struct platform_device *pdev)
93 94
{
	platform_device_unregister(fsi_snd_device);
95 96 97 98 99
	return 0;
}

static struct fsi_ak4642_data fsi_a_ak4642 = {
	.name		= "AK4642",
100
	.card		= "FSIA-AK4642",
101 102 103
	.cpu_dai	= "fsia-dai",
	.codec		= "ak4642-codec.0-0012",
	.platform	= "sh_fsi.0",
104
	.id		= FSI_PORT_A,
105 106 107 108
};

static struct fsi_ak4642_data fsi_b_ak4642 = {
	.name		= "AK4642",
109
	.card		= "FSIB-AK4642",
110 111 112
	.cpu_dai	= "fsib-dai",
	.codec		= "ak4642-codec.0-0012",
	.platform	= "sh_fsi.0",
113
	.id		= FSI_PORT_B,
114 115 116 117
};

static struct fsi_ak4642_data fsi_a_ak4643 = {
	.name		= "AK4643",
118
	.card		= "FSIA-AK4643",
119 120 121
	.cpu_dai	= "fsia-dai",
	.codec		= "ak4642-codec.0-0013",
	.platform	= "sh_fsi.0",
122
	.id		= FSI_PORT_A,
123 124 125 126
};

static struct fsi_ak4642_data fsi_b_ak4643 = {
	.name		= "AK4643",
127
	.card		= "FSIB-AK4643",
128 129 130
	.cpu_dai	= "fsib-dai",
	.codec		= "ak4642-codec.0-0013",
	.platform	= "sh_fsi.0",
131
	.id		= FSI_PORT_B,
132 133 134 135
};

static struct fsi_ak4642_data fsi2_a_ak4642 = {
	.name		= "AK4642",
136
	.card		= "FSI2A-AK4642",
137 138 139
	.cpu_dai	= "fsia-dai",
	.codec		= "ak4642-codec.0-0012",
	.platform	= "sh_fsi2",
140
	.id		= FSI_PORT_A,
141 142 143 144
};

static struct fsi_ak4642_data fsi2_b_ak4642 = {
	.name		= "AK4642",
145
	.card		= "FSI2B-AK4642",
146 147 148
	.cpu_dai	= "fsib-dai",
	.codec		= "ak4642-codec.0-0012",
	.platform	= "sh_fsi2",
149
	.id		= FSI_PORT_B,
150 151 152 153
};

static struct fsi_ak4642_data fsi2_a_ak4643 = {
	.name		= "AK4643",
154
	.card		= "FSI2A-AK4643",
155 156 157
	.cpu_dai	= "fsia-dai",
	.codec		= "ak4642-codec.0-0013",
	.platform	= "sh_fsi2",
158
	.id		= FSI_PORT_A,
159 160 161 162
};

static struct fsi_ak4642_data fsi2_b_ak4643 = {
	.name		= "AK4643",
163
	.card		= "FSI2B-AK4643",
164 165 166
	.cpu_dai	= "fsib-dai",
	.codec		= "ak4642-codec.0-0013",
	.platform	= "sh_fsi2",
167
	.id		= FSI_PORT_B,
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
};

static struct platform_device_id fsi_id_table[] = {
	/* FSI */
	{ "sh_fsi_a_ak4642",	(kernel_ulong_t)&fsi_a_ak4642 },
	{ "sh_fsi_b_ak4642",	(kernel_ulong_t)&fsi_b_ak4642 },
	{ "sh_fsi_a_ak4643",	(kernel_ulong_t)&fsi_a_ak4643 },
	{ "sh_fsi_b_ak4643",	(kernel_ulong_t)&fsi_b_ak4643 },

	/* FSI 2 */
	{ "sh_fsi2_a_ak4642",	(kernel_ulong_t)&fsi2_a_ak4642 },
	{ "sh_fsi2_b_ak4642",	(kernel_ulong_t)&fsi2_b_ak4642 },
	{ "sh_fsi2_a_ak4643",	(kernel_ulong_t)&fsi2_a_ak4643 },
	{ "sh_fsi2_b_ak4643",	(kernel_ulong_t)&fsi2_b_ak4643 },
	{},
};

static struct platform_driver fsi_ak4642 = {
	.driver = {
		.name	= "fsi-ak4642-audio",
	},
	.probe		= fsi_ak4642_probe,
	.remove		= fsi_ak4642_remove,
	.id_table	= fsi_id_table,
};

static int __init fsi_ak4642_init(void)
{
	return platform_driver_register(&fsi_ak4642);
}

static void __exit fsi_ak4642_exit(void)
{
	platform_driver_unregister(&fsi_ak4642);
202 203 204 205 206 207 208 209
}

module_init(fsi_ak4642_init);
module_exit(fsi_ak4642_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Generic SH4 FSI-AK4642 sound card");
MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");