aboutsummaryrefslogtreecommitdiff
path: root/sound/soc/au1x/sample-ac97.c
blob: 27683eb7905e305f800211dcfa21718e73a4c5c9 (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
138
139
140
141
142
143
144
/*
 * Sample Au12x0/Au1550 PSC AC97 sound machine.
 *
 * Copyright (c) 2007-2008 Manuel Lauss <mano@roarinelk.homelinux.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms outlined in the file COPYING at the root of this
 *  source archive.
 *
 * This is a very generic AC97 sound machine driver for boards which
 * have (AC97) audio at PSC1 (e.g. DB1200 demoboards).
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <asm/mach-au1x00/au1000.h>
#include <asm/mach-au1x00/au1xxx_psc.h>
#include <asm/mach-au1x00/au1xxx_dbdma.h>

#include "../codecs/ac97.h"
#include "psc.h"

static int au1xpsc_sample_ac97_init(struct snd_soc_codec *codec)
{
	snd_soc_dapm_sync(codec);
	return 0;
}

static struct snd_soc_dai_link au1xpsc_sample_ac97_dai = {
	.name		= "AC97",
	.stream_name	= "AC97 HiFi",
	.cpu_dai	= &au1xpsc_ac97_dai,	/* see psc-ac97.c */
	.codec_dai	= &ac97_dai,		/* see codecs/ac97.c */
	.init		= au1xpsc_sample_ac97_init,
	.ops		= NULL,
};

static struct snd_soc_card au1xpsc_sample_ac97_machine = {
	.name		= "Au1xxx PSC AC97 Audio",
	.dai_link	= &au1xpsc_sample_ac97_dai,
	.num_links	= 1,
};

static struct snd_soc_device au1xpsc_sample_ac97_devdata = {
	.card		= &au1xpsc_sample_ac97_machine,
	.platform	= &au1xpsc_soc_platform, /* see dbdma2.c */
	.codec_dev	= &soc_codec_dev_ac97,
};

static struct resource au1xpsc_psc1_res[] = {
	[0] = {
		.start	= CPHYSADDR(PSC1_BASE_ADDR),
		.end	= CPHYSADDR(PSC1_BASE_ADDR) + 0x000fffff,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
#ifdef CONFIG_SOC_AU1200
		.start	= AU1200_PSC1_INT,
		.end	= AU1200_PSC1_INT,
#elif defined(CONFIG_SOC_AU1550)
		.start	= AU1550_PSC1_INT,
		.end	= AU1550_PSC1_INT,
#endif
		.flags	= IORESOURCE_IRQ,
	},
	[2] = {
		.start	= DSCR_CMD0_PSC1_TX,
		.end	= DSCR_CMD0_PSC1_TX,
		.flags	= IORESOURCE_DMA,
	},
	[3] = {
		.start	= DSCR_CMD0_PSC1_RX,
		.end	= DSCR_CMD0_PSC1_RX,
		.flags	= IORESOURCE_DMA,
	},
};

static struct platform_device *au1xpsc_sample_ac97_dev;

static int __init au1xpsc_sample_ac97_load(void)
{
	int ret;

#ifdef CONFIG_SOC_AU1200
	unsigned long io;

	/* modify sys_pinfunc for AC97 on PSC1 */
	io = au_readl(SYS_PINFUNC);
	io |= SYS_PINFUNC_P1C;
	io &= ~(SYS_PINFUNC_P1A | SYS_PINFUNC_P1B);
	au_writel(io, SYS_PINFUNC);
	au_sync();
#endif

	ret = -ENOMEM;

	/* setup PSC clock source for AC97 part: external clock provided
	 * by codec.  The psc-ac97.c driver depends on this setting!
	 */
	au_writel(PSC_SEL_CLK_SERCLK, PSC1_BASE_ADDR + PSC_SEL_OFFSET);
	au_sync();

	au1xpsc_sample_ac97_dev = platform_device_alloc("soc-audio", -1);
	if (!au1xpsc_sample_ac97_dev)
		goto out;

	au1xpsc_sample_ac97_dev->resource =
		kmemdup(au1xpsc_psc1_res, sizeof(struct resource) *
			ARRAY_SIZE(au1xpsc_psc1_res), GFP_KERNEL);
	au1xpsc_sample_ac97_dev->num_resources = ARRAY_SIZE(au1xpsc_psc1_res);
	au1xpsc_sample_ac97_dev->id = 1;

	platform_set_drvdata(au1xpsc_sample_ac97_dev,
			     &au1xpsc_sample_ac97_devdata);
	au1xpsc_sample_ac97_devdata.dev = &au1xpsc_sample_ac97_dev->dev;
	ret = platform_device_add(au1xpsc_sample_ac97_dev);

	if (ret) {
		platform_device_put(au1xpsc_sample_ac97_dev);
		au1xpsc_sample_ac97_dev = NULL;
	}

out:
	return ret;
}

static void __exit au1xpsc_sample_ac97_exit(void)
{
	platform_device_unregister(au1xpsc_sample_ac97_dev);
}

module_init(au1xpsc_sample_ac97_load);
module_exit(au1xpsc_sample_ac97_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Au1xxx PSC sample AC97 machine");
MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>");