cs4231.c 5.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/*
 *  Generic driver for CS4231 chips
3
 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
L
Linus Torvalds 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *  Originally the CS4232/CS4232A driver, modified for use on CS4231 by
 *  Tugrul Galatali <galatalt@stuy.edu>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

#include <linux/init.h>
24
#include <linux/err.h>
R
Rene Herman 已提交
25
#include <linux/isa.h>
L
Linus Torvalds 已提交
26 27
#include <linux/time.h>
#include <linux/wait.h>
28
#include <linux/module.h>
L
Linus Torvalds 已提交
29
#include <sound/core.h>
30
#include <sound/wss.h>
L
Linus Torvalds 已提交
31 32 33
#include <sound/mpu401.h>
#include <sound/initval.h>

R
Rene Herman 已提交
34 35 36 37
#define CRD_NAME "Generic CS4231"
#define DEV_NAME "cs4231"

MODULE_DESCRIPTION(CRD_NAME);
38
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
L
Linus Torvalds 已提交
39 40 41 42 43
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4231}}");

static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
44
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;	/* Enable this card */
L
Linus Torvalds 已提交
45 46 47 48 49 50 51 52
static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 5,7,9,11,12,15 */
static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 9,11,12,15 */
static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */

module_param_array(index, int, NULL, 0444);
R
Rene Herman 已提交
53
MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
L
Linus Torvalds 已提交
54
module_param_array(id, charp, NULL, 0444);
R
Rene Herman 已提交
55
MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
L
Linus Torvalds 已提交
56
module_param_array(enable, bool, NULL, 0444);
R
Rene Herman 已提交
57
MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
58
module_param_hw_array(port, long, ioport, NULL, 0444);
R
Rene Herman 已提交
59
MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
60
module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
R
Rene Herman 已提交
61
MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
62
module_param_hw_array(irq, int, irq, NULL, 0444);
R
Rene Herman 已提交
63
MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
64
module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
R
Rene Herman 已提交
65
MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
66
module_param_hw_array(dma1, int, dma, NULL, 0444);
R
Rene Herman 已提交
67
MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
68
module_param_hw_array(dma2, int, dma, NULL, 0444);
R
Rene Herman 已提交
69
MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
L
Linus Torvalds 已提交
70

71
static int snd_cs4231_match(struct device *dev, unsigned int n)
R
Rene Herman 已提交
72 73 74
{
	if (!enable[n])
		return 0;
75

R
Rene Herman 已提交
76
	if (port[n] == SNDRV_AUTO_PORT) {
77
		dev_err(dev, "please specify port\n");
R
Rene Herman 已提交
78 79 80
		return 0;
	}
	if (irq[n] == SNDRV_AUTO_IRQ) {
81
		dev_err(dev, "please specify irq\n");
R
Rene Herman 已提交
82 83 84
		return 0;
	}
	if (dma1[n] == SNDRV_AUTO_DMA) {
85
		dev_err(dev, "please specify dma1\n");
R
Rene Herman 已提交
86 87 88 89
		return 0;
	}
	return 1;
}
L
Linus Torvalds 已提交
90

91
static int snd_cs4231_probe(struct device *dev, unsigned int n)
L
Linus Torvalds 已提交
92
{
93
	struct snd_card *card;
94
	struct snd_wss *chip;
R
Rene Herman 已提交
95
	int error;
L
Linus Torvalds 已提交
96

97
	error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
98 99
	if (error < 0)
		return error;
R
Rene Herman 已提交
100

101 102
	error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n],
			WSS_HW_DETECT, 0, &chip);
R
Rene Herman 已提交
103 104 105
	if (error < 0)
		goto out;

106
	card->private_data = chip;
L
Linus Torvalds 已提交
107

108
	error = snd_wss_pcm(chip, 0);
R
Rene Herman 已提交
109 110
	if (error < 0)
		goto out;
L
Linus Torvalds 已提交
111 112

	strcpy(card->driver, "CS4231");
113
	strcpy(card->shortname, chip->pcm->name);
R
Rene Herman 已提交
114

L
Linus Torvalds 已提交
115
	sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
116
		chip->pcm->name, chip->port, irq[n], dma1[n]);
R
Rene Herman 已提交
117 118 119
	if (dma2[n] >= 0)
		sprintf(card->longname + strlen(card->longname), "&%d", dma2[n]);

120
	error = snd_wss_mixer(chip);
R
Rene Herman 已提交
121 122 123
	if (error < 0)
		goto out;

124
	error = snd_wss_timer(chip, 0);
R
Rene Herman 已提交
125 126 127 128 129 130
	if (error < 0)
		goto out;

	if (mpu_port[n] > 0 && mpu_port[n] != SNDRV_AUTO_PORT) {
		if (mpu_irq[n] == SNDRV_AUTO_IRQ)
			mpu_irq[n] = -1;
L
Linus Torvalds 已提交
131
		if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
R
Rene Herman 已提交
132
					mpu_port[n], 0, mpu_irq[n],
L
Linus Torvalds 已提交
133
					NULL) < 0)
134
			dev_warn(dev, "MPU401 not detected\n");
L
Linus Torvalds 已提交
135
	}
136

R
Rene Herman 已提交
137 138 139
	error = snd_card_register(card);
	if (error < 0)
		goto out;
140

R
Rene Herman 已提交
141
	dev_set_drvdata(dev, card);
L
Linus Torvalds 已提交
142
	return 0;
143

R
Rene Herman 已提交
144 145
out:	snd_card_free(card);
	return error;
L
Linus Torvalds 已提交
146 147
}

148
static int snd_cs4231_remove(struct device *dev, unsigned int n)
149
{
R
Rene Herman 已提交
150
	snd_card_free(dev_get_drvdata(dev));
151 152 153 154
	return 0;
}

#ifdef CONFIG_PM
R
Rene Herman 已提交
155
static int snd_cs4231_suspend(struct device *dev, unsigned int n, pm_message_t state)
L
Linus Torvalds 已提交
156
{
R
Rene Herman 已提交
157
	struct snd_card *card = dev_get_drvdata(dev);
158
	struct snd_wss *chip = card->private_data;
R
Rene Herman 已提交
159

160 161 162 163
	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
	chip->suspend(chip);
	return 0;
}
L
Linus Torvalds 已提交
164

R
Rene Herman 已提交
165
static int snd_cs4231_resume(struct device *dev, unsigned int n)
166
{
R
Rene Herman 已提交
167
	struct snd_card *card = dev_get_drvdata(dev);
168
	struct snd_wss *chip = card->private_data;
R
Rene Herman 已提交
169

170 171 172 173 174 175
	chip->resume(chip);
	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
	return 0;
}
#endif

R
Rene Herman 已提交
176 177
static struct isa_driver snd_cs4231_driver = {
	.match		= snd_cs4231_match,
178
	.probe		= snd_cs4231_probe,
179
	.remove		= snd_cs4231_remove,
180 181 182 183 184
#ifdef CONFIG_PM
	.suspend	= snd_cs4231_suspend,
	.resume		= snd_cs4231_resume,
#endif
	.driver		= {
R
Rene Herman 已提交
185 186
		.name	= DEV_NAME
	}
187 188
};

189
module_isa_driver(snd_cs4231_driver, SNDRV_CARDS);