oxygen.c 17.2 KB
Newer Older
C
Clemens Ladisch 已提交
1
/*
2
 * C-Media CMI8788 driver for C-Media's reference design and similar models
C
Clemens Ladisch 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
 *
 *
 *  This driver is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License, version 2.
 *
 *  This driver 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 driver; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

/*
21 22
 * CMI8788:
 *
C
Clemens Ladisch 已提交
23
 * SPI 0 -> 1st AK4396 (front)
24
 * SPI 1 -> 2nd AK4396 (surround)
C
Clemens Ladisch 已提交
25 26
 * SPI 2 -> 3rd AK4396 (center/LFE)
 * SPI 3 -> WM8785
27
 * SPI 4 -> 4th AK4396 (back)
C
Clemens Ladisch 已提交
28 29 30
 *
 * GPIO 0 -> DFS0 of AK5385
 * GPIO 1 -> DFS1 of AK5385
31
 * GPIO 8 -> enable headphone amplifier on HT-Omega models
32 33 34 35
 *
 * CM9780:
 *
 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input
C
Clemens Ladisch 已提交
36 37
 */

38
#include <linux/delay.h>
39
#include <linux/mutex.h>
C
Clemens Ladisch 已提交
40
#include <linux/pci.h>
41
#include <sound/ac97_codec.h>
42
#include <sound/control.h>
C
Clemens Ladisch 已提交
43 44 45 46 47 48
#include <sound/core.h>
#include <sound/initval.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/tlv.h>
#include "oxygen.h"
49
#include "ak4396.h"
50
#include "wm8785.h"
C
Clemens Ladisch 已提交
51 52 53

MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
MODULE_DESCRIPTION("C-Media CMI8788 driver");
54
MODULE_LICENSE("GPL v2");
C
Clemens Ladisch 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67
MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8788}}");

static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;

module_param_array(index, int, NULL, 0444);
MODULE_PARM_DESC(index, "card index");
module_param_array(id, charp, NULL, 0444);
MODULE_PARM_DESC(id, "ID string");
module_param_array(enable, bool, NULL, 0444);
MODULE_PARM_DESC(enable, "enable card");

68
enum {
C
Clemens Ladisch 已提交
69 70 71 72
	MODEL_CMEDIA_REF,
	MODEL_MERIDIAN,
	MODEL_CLARO,
	MODEL_CLARO_HALO,
73 74
	MODEL_FANTASIA,
	MODEL_2CH_OUTPUT,
75 76
};

77
static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
C
Clemens Ladisch 已提交
78
	/* C-Media's reference design */
79 80 81 82 83 84 85
	{ OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF },
	{ OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF },
	{ OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF },
	{ OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF },
	{ OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF },
	{ OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF },
	{ OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF },
C
Clemens Ladisch 已提交
86 87
	{ OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
	/* Kuroutoshikou CMI8787-HG2PCI */
88
	{ OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_2CH_OUTPUT },
C
Clemens Ladisch 已提交
89
	/* TempoTec HiFier Fantasia */
90 91 92
	{ OXYGEN_PCI_SUBID(0x14c3, 0x1710), .driver_data = MODEL_FANTASIA },
	/* TempoTec HiFier Serenade */
	{ OXYGEN_PCI_SUBID(0x14c3, 0x1711), .driver_data = MODEL_2CH_OUTPUT },
C
Clemens Ladisch 已提交
93
	/* AuzenTech X-Meridian */
94
	{ OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN },
C
Clemens Ladisch 已提交
95
	/* HT-Omega Claro */
96
	{ OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO },
C
Clemens Ladisch 已提交
97
	/* HT-Omega Claro halo */
98
	{ OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO },
C
Clemens Ladisch 已提交
99 100 101 102
	{ }
};
MODULE_DEVICE_TABLE(pci, oxygen_ids);

103 104 105 106 107 108

#define GPIO_AK5385_DFS_MASK	0x0003
#define GPIO_AK5385_DFS_NORMAL	0x0000
#define GPIO_AK5385_DFS_DOUBLE	0x0001
#define GPIO_AK5385_DFS_QUAD	0x0002

109 110
#define GPIO_CLARO_HP		0x0100

111
struct generic_data {
112
	unsigned int dacs;
113
	u8 ak4396_regs[4][5];
114
	u16 wm8785_regs[3];
115 116
};

C
Clemens Ladisch 已提交
117 118 119 120 121
static void ak4396_write(struct oxygen *chip, unsigned int codec,
			 u8 reg, u8 value)
{
	/* maps ALSA channel pair number to SPI output */
	static const u8 codec_spi_map[4] = {
122
		0, 1, 2, 4
C
Clemens Ladisch 已提交
123
	};
124 125
	struct generic_data *data = chip->model_data;

126
	oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
C
Clemens Ladisch 已提交
127
			 OXYGEN_SPI_DATA_LENGTH_2 |
128
			 OXYGEN_SPI_CLOCK_160 |
C
Clemens Ladisch 已提交
129
			 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
130
			 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
C
Clemens Ladisch 已提交
131
			 AK4396_WRITE | (reg << 8) | value);
132 133 134 135 136 137 138 139 140 141
	data->ak4396_regs[codec][reg] = value;
}

static void ak4396_write_cached(struct oxygen *chip, unsigned int codec,
				u8 reg, u8 value)
{
	struct generic_data *data = chip->model_data;

	if (value != data->ak4396_regs[codec][reg])
		ak4396_write(chip, codec, reg, value);
C
Clemens Ladisch 已提交
142 143 144 145
}

static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
{
146 147
	struct generic_data *data = chip->model_data;

148
	oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
C
Clemens Ladisch 已提交
149
			 OXYGEN_SPI_DATA_LENGTH_2 |
150
			 OXYGEN_SPI_CLOCK_160 |
151 152
			 (3 << OXYGEN_SPI_CODEC_SHIFT) |
			 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
C
Clemens Ladisch 已提交
153
			 (reg << 9) | value);
154 155
	if (reg < ARRAY_SIZE(data->wm8785_regs))
		data->wm8785_regs[reg] = value;
156 157
}

158
static void ak4396_registers_init(struct oxygen *chip)
C
Clemens Ladisch 已提交
159
{
160
	struct generic_data *data = chip->model_data;
C
Clemens Ladisch 已提交
161 162
	unsigned int i;

163
	for (i = 0; i < data->dacs; ++i) {
164 165 166 167 168 169 170 171 172 173
		ak4396_write(chip, i, AK4396_CONTROL_1,
			     AK4396_DIF_24_MSB | AK4396_RSTN);
		ak4396_write(chip, i, AK4396_CONTROL_2,
			     data->ak4396_regs[0][AK4396_CONTROL_2]);
		ak4396_write(chip, i, AK4396_CONTROL_3,
			     AK4396_PCM);
		ak4396_write(chip, i, AK4396_LCH_ATT,
			     chip->dac_volume[i * 2]);
		ak4396_write(chip, i, AK4396_RCH_ATT,
			     chip->dac_volume[i * 2 + 1]);
C
Clemens Ladisch 已提交
174
	}
175 176 177 178 179 180
}

static void ak4396_init(struct oxygen *chip)
{
	struct generic_data *data = chip->model_data;

181
	data->dacs = chip->model.dac_channels / 2;
182 183
	data->ak4396_regs[0][AK4396_CONTROL_2] =
		AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
184
	ak4396_registers_init(chip);
C
Clemens Ladisch 已提交
185 186 187 188 189
	snd_component_add(chip->card, "AK4396");
}

static void ak5385_init(struct oxygen *chip)
{
190 191
	oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_AK5385_DFS_MASK);
	oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_AK5385_DFS_MASK);
C
Clemens Ladisch 已提交
192 193 194
	snd_component_add(chip->card, "AK5385");
}

195
static void wm8785_registers_init(struct oxygen *chip)
C
Clemens Ladisch 已提交
196
{
197 198
	struct generic_data *data = chip->model_data;

199
	wm8785_write(chip, WM8785_R7, 0);
200
	wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]);
201
	wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
202
}
203

204 205 206 207
static void wm8785_init(struct oxygen *chip)
{
	struct generic_data *data = chip->model_data;

208 209
	data->wm8785_regs[0] =
		WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST;
210
	data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL;
211
	wm8785_registers_init(chip);
C
Clemens Ladisch 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
	snd_component_add(chip->card, "WM8785");
}

static void generic_init(struct oxygen *chip)
{
	ak4396_init(chip);
	wm8785_init(chip);
}

static void meridian_init(struct oxygen *chip)
{
	ak4396_init(chip);
	ak5385_init(chip);
}

227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
static void claro_enable_hp(struct oxygen *chip)
{
	msleep(300);
	oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_HP);
	oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
}

static void claro_init(struct oxygen *chip)
{
	ak4396_init(chip);
	wm8785_init(chip);
	claro_enable_hp(chip);
}

static void claro_halo_init(struct oxygen *chip)
242 243 244
{
	ak4396_init(chip);
	ak5385_init(chip);
245
	claro_enable_hp(chip);
246 247
}

248
static void fantasia_init(struct oxygen *chip)
249 250 251 252 253
{
	ak4396_init(chip);
	snd_component_add(chip->card, "CS5340");
}

254
static void stereo_output_init(struct oxygen *chip)
255 256 257 258
{
	ak4396_init(chip);
}

C
Clemens Ladisch 已提交
259 260 261 262
static void generic_cleanup(struct oxygen *chip)
{
}

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
static void claro_disable_hp(struct oxygen *chip)
{
	oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
}

static void claro_cleanup(struct oxygen *chip)
{
	claro_disable_hp(chip);
}

static void claro_suspend(struct oxygen *chip)
{
	claro_disable_hp(chip);
}

C
Clemens Ladisch 已提交
278 279 280 281 282 283
static void generic_resume(struct oxygen *chip)
{
	ak4396_registers_init(chip);
	wm8785_registers_init(chip);
}

284 285 286 287 288
static void meridian_resume(struct oxygen *chip)
{
	ak4396_registers_init(chip);
}

289
static void claro_resume(struct oxygen *chip)
290 291
{
	ak4396_registers_init(chip);
292
	claro_enable_hp(chip);
293 294
}

295 296 297 298 299
static void stereo_resume(struct oxygen *chip)
{
	ak4396_registers_init(chip);
}

C
Clemens Ladisch 已提交
300 301 302
static void set_ak4396_params(struct oxygen *chip,
			      struct snd_pcm_hw_params *params)
{
303
	struct generic_data *data = chip->model_data;
C
Clemens Ladisch 已提交
304 305 306
	unsigned int i;
	u8 value;

307
	value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
C
Clemens Ladisch 已提交
308 309
	if (params_rate(params) <= 54000)
		value |= AK4396_DFS_NORMAL;
310
	else if (params_rate(params) <= 108000)
C
Clemens Ladisch 已提交
311 312 313
		value |= AK4396_DFS_DOUBLE;
	else
		value |= AK4396_DFS_QUAD;
314 315 316

	msleep(1); /* wait for the new MCLK to become stable */

317
	if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) {
318
		for (i = 0; i < data->dacs; ++i) {
319 320 321 322 323 324 325 326 327 328 329
			ak4396_write(chip, i, AK4396_CONTROL_1,
				     AK4396_DIF_24_MSB);
			ak4396_write(chip, i, AK4396_CONTROL_2, value);
			ak4396_write(chip, i, AK4396_CONTROL_1,
				     AK4396_DIF_24_MSB | AK4396_RSTN);
		}
	}
}

static void update_ak4396_volume(struct oxygen *chip)
{
330
	struct generic_data *data = chip->model_data;
331 332
	unsigned int i;

333
	for (i = 0; i < data->dacs; ++i) {
334 335 336 337
		ak4396_write_cached(chip, i, AK4396_LCH_ATT,
				    chip->dac_volume[i * 2]);
		ak4396_write_cached(chip, i, AK4396_RCH_ATT,
				    chip->dac_volume[i * 2 + 1]);
C
Clemens Ladisch 已提交
338 339 340 341 342
	}
}

static void update_ak4396_mute(struct oxygen *chip)
{
343
	struct generic_data *data = chip->model_data;
C
Clemens Ladisch 已提交
344 345 346
	unsigned int i;
	u8 value;

347
	value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE;
C
Clemens Ladisch 已提交
348 349
	if (chip->dac_mute)
		value |= AK4396_SMUTE;
350
	for (i = 0; i < data->dacs; ++i)
351
		ak4396_write_cached(chip, i, AK4396_CONTROL_2, value);
C
Clemens Ladisch 已提交
352 353 354 355 356
}

static void set_wm8785_params(struct oxygen *chip,
			      struct snd_pcm_hw_params *params)
{
357
	struct generic_data *data = chip->model_data;
C
Clemens Ladisch 已提交
358 359
	unsigned int value;

360
	value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST;
361 362 363
	if (params_rate(params) <= 48000)
		value |= WM8785_OSR_SINGLE;
	else if (params_rate(params) <= 96000)
C
Clemens Ladisch 已提交
364 365
		value |= WM8785_OSR_DOUBLE;
	else
366
		value |= WM8785_OSR_QUAD;
367 368 369
	if (value != data->wm8785_regs[0]) {
		wm8785_write(chip, WM8785_R7, 0);
		wm8785_write(chip, WM8785_R0, value);
370
		wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
371
	}
C
Clemens Ladisch 已提交
372 373 374 375 376 377 378 379
}

static void set_ak5385_params(struct oxygen *chip,
			      struct snd_pcm_hw_params *params)
{
	unsigned int value;

	if (params_rate(params) <= 54000)
380
		value = GPIO_AK5385_DFS_NORMAL;
C
Clemens Ladisch 已提交
381
	else if (params_rate(params) <= 108000)
382
		value = GPIO_AK5385_DFS_DOUBLE;
C
Clemens Ladisch 已提交
383
	else
384 385 386
		value = GPIO_AK5385_DFS_QUAD;
	oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
			      value, GPIO_AK5385_DFS_MASK);
C
Clemens Ladisch 已提交
387 388
}

389 390 391 392
static void set_no_params(struct oxygen *chip, struct snd_pcm_hw_params *params)
{
}

393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
static int rolloff_info(struct snd_kcontrol *ctl,
			struct snd_ctl_elem_info *info)
{
	static const char *const names[2] = {
		"Sharp Roll-off", "Slow Roll-off"
	};

	info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	info->count = 1;
	info->value.enumerated.items = 2;
	if (info->value.enumerated.item >= 2)
		info->value.enumerated.item = 1;
	strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
	return 0;
}

static int rolloff_get(struct snd_kcontrol *ctl,
		       struct snd_ctl_elem_value *value)
{
	struct oxygen *chip = ctl->private_data;
	struct generic_data *data = chip->model_data;

	value->value.enumerated.item[0] =
		(data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0;
	return 0;
}

static int rolloff_put(struct snd_kcontrol *ctl,
		       struct snd_ctl_elem_value *value)
{
	struct oxygen *chip = ctl->private_data;
	struct generic_data *data = chip->model_data;
	unsigned int i;
	int changed;
	u8 reg;

	mutex_lock(&chip->mutex);
	reg = data->ak4396_regs[0][AK4396_CONTROL_2];
	if (value->value.enumerated.item[0])
		reg |= AK4396_SLOW;
	else
		reg &= ~AK4396_SLOW;
	changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2];
	if (changed) {
437
		for (i = 0; i < data->dacs; ++i)
438 439 440 441 442 443 444 445 446 447 448 449 450 451
			ak4396_write(chip, i, AK4396_CONTROL_2, reg);
	}
	mutex_unlock(&chip->mutex);
	return changed;
}

static const struct snd_kcontrol_new rolloff_control = {
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	.name = "DAC Filter Playback Enum",
	.info = rolloff_info,
	.get = rolloff_get,
	.put = rolloff_put,
};

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
{
	static const char *const names[2] = {
		"None", "High-pass Filter"
	};

	info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	info->count = 1;
	info->value.enumerated.items = 2;
	if (info->value.enumerated.item >= 2)
		info->value.enumerated.item = 1;
	strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
	return 0;
}

static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
{
	struct oxygen *chip = ctl->private_data;
	struct generic_data *data = chip->model_data;

	value->value.enumerated.item[0] =
		(data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0;
	return 0;
}

static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
{
	struct oxygen *chip = ctl->private_data;
	struct generic_data *data = chip->model_data;
	unsigned int reg;
	int changed;

	mutex_lock(&chip->mutex);
	reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL);
	if (value->value.enumerated.item[0])
		reg |= WM8785_HPFR | WM8785_HPFL;
	changed = reg != data->wm8785_regs[WM8785_R2];
	if (changed)
		wm8785_write(chip, WM8785_R2, reg);
	mutex_unlock(&chip->mutex);
	return changed;
}

static const struct snd_kcontrol_new hpf_control = {
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	.name = "ADC Filter Capture Enum",
	.info = hpf_info,
	.get = hpf_get,
	.put = hpf_put,
};

503 504 505 506 507
static int generic_mixer_init(struct oxygen *chip)
{
	return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
}

508 509 510 511 512 513 514 515 516 517 518 519 520
static int generic_wm8785_mixer_init(struct oxygen *chip)
{
	int err;

	err = generic_mixer_init(chip);
	if (err < 0)
		return err;
	err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip));
	if (err < 0)
		return err;
	return 0;
}

C
Clemens Ladisch 已提交
521 522 523 524 525 526 527
static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);

static const struct oxygen_model model_generic = {
	.shortname = "C-Media CMI8788",
	.longname = "C-Media Oxygen HD Audio",
	.chip = "CMI8788",
	.init = generic_init,
528
	.mixer_init = generic_wm8785_mixer_init,
C
Clemens Ladisch 已提交
529
	.cleanup = generic_cleanup,
C
Clemens Ladisch 已提交
530
	.resume = generic_resume,
531
	.get_i2s_mclk = oxygen_default_i2s_mclk,
C
Clemens Ladisch 已提交
532 533 534 535
	.set_dac_params = set_ak4396_params,
	.set_adc_params = set_wm8785_params,
	.update_dac_volume = update_ak4396_volume,
	.update_dac_mute = update_ak4396_mute,
536
	.dac_tlv = ak4396_db_scale,
537
	.model_data_size = sizeof(struct generic_data),
538 539 540 541 542
	.device_config = PLAYBACK_0_TO_I2S |
			 PLAYBACK_1_TO_SPDIF |
			 PLAYBACK_2_TO_AC97_1 |
			 CAPTURE_0_FROM_I2S_1 |
			 CAPTURE_1_FROM_SPDIF |
543 544
			 CAPTURE_2_FROM_AC97_1 |
			 AC97_CD_INPUT,
545
	.dac_channels = 8,
546 547
	.dac_volume_min = 0,
	.dac_volume_max = 255,
548 549
	.function_flags = OXYGEN_FUNCTION_SPI |
			  OXYGEN_FUNCTION_ENABLE_SPI_4_5,
550 551
	.dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
	.adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
C
Clemens Ladisch 已提交
552 553
};

554 555 556 557 558 559 560
static int __devinit get_oxygen_model(struct oxygen *chip,
				      const struct pci_device_id *id)
{
	chip->model = model_generic;
	switch (id->driver_data) {
	case MODEL_MERIDIAN:
		chip->model.init = meridian_init;
561
		chip->model.mixer_init = generic_mixer_init;
562 563 564 565 566 567 568
		chip->model.resume = meridian_resume;
		chip->model.set_adc_params = set_ak5385_params;
		chip->model.device_config = PLAYBACK_0_TO_I2S |
					    PLAYBACK_1_TO_SPDIF |
					    CAPTURE_0_FROM_I2S_2 |
					    CAPTURE_1_FROM_SPDIF;
		break;
569 570 571 572 573 574 575 576
	case MODEL_CLARO:
		chip->model.init = claro_init;
		chip->model.cleanup = claro_cleanup;
		chip->model.suspend = claro_suspend;
		chip->model.resume = claro_resume;
		break;
	case MODEL_CLARO_HALO:
		chip->model.init = claro_halo_init;
577
		chip->model.mixer_init = generic_mixer_init;
578 579 580
		chip->model.cleanup = claro_cleanup;
		chip->model.suspend = claro_suspend;
		chip->model.resume = claro_resume;
581
		chip->model.set_adc_params = set_ak5385_params;
582 583 584 585
		chip->model.device_config = PLAYBACK_0_TO_I2S |
					    PLAYBACK_1_TO_SPDIF |
					    CAPTURE_0_FROM_I2S_2 |
					    CAPTURE_1_FROM_SPDIF;
586
		break;
587 588
	case MODEL_FANTASIA:
	case MODEL_2CH_OUTPUT:
589 590
		chip->model.shortname = "C-Media CMI8787";
		chip->model.chip = "CMI8787";
591 592
		if (id->driver_data == MODEL_FANTASIA)
			chip->model.init = fantasia_init;
593
		else
594
			chip->model.init = stereo_output_init;
595 596 597 598
		chip->model.resume = stereo_resume;
		chip->model.mixer_init = generic_mixer_init;
		chip->model.set_adc_params = set_no_params;
		chip->model.device_config = PLAYBACK_0_TO_I2S |
599
					    PLAYBACK_1_TO_SPDIF;
600
		if (id->driver_data == MODEL_FANTASIA)
601
			chip->model.device_config |= CAPTURE_0_FROM_I2S_1;
602 603
		chip->model.dac_channels = 2;
		break;
604 605
	}
	if (id->driver_data == MODEL_MERIDIAN ||
606
	    id->driver_data == MODEL_CLARO_HALO) {
607 608 609 610 611 612
		chip->model.misc_flags = OXYGEN_MISC_MIDI;
		chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
	}
	return 0;
}

C
Clemens Ladisch 已提交
613 614 615 616 617 618 619 620 621 622 623 624
static int __devinit generic_oxygen_probe(struct pci_dev *pci,
					  const struct pci_device_id *pci_id)
{
	static int dev;
	int err;

	if (dev >= SNDRV_CARDS)
		return -ENODEV;
	if (!enable[dev]) {
		++dev;
		return -ENOENT;
	}
625
	err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
626
			       oxygen_ids, get_oxygen_model);
C
Clemens Ladisch 已提交
627 628 629 630 631 632 633 634 635 636
	if (err >= 0)
		++dev;
	return err;
}

static struct pci_driver oxygen_driver = {
	.name = "CMI8788",
	.id_table = oxygen_ids,
	.probe = generic_oxygen_probe,
	.remove = __devexit_p(oxygen_pci_remove),
C
Clemens Ladisch 已提交
637 638 639 640
#ifdef CONFIG_PM
	.suspend = oxygen_pci_suspend,
	.resume = oxygen_pci_resume,
#endif
C
Clemens Ladisch 已提交
641 642 643 644 645 646 647 648 649 650 651 652 653 654
};

static int __init alsa_card_oxygen_init(void)
{
	return pci_register_driver(&oxygen_driver);
}

static void __exit alsa_card_oxygen_exit(void)
{
	pci_unregister_driver(&oxygen_driver);
}

module_init(alsa_card_oxygen_init)
module_exit(alsa_card_oxygen_exit)