blob: 5f3a13d4369d6cbad47dbf33b52f668061a810a1 [file] [log] [blame]
Clemens Ladischd0ce9942007-12-23 19:50:57 +01001/*
Clemens Ladisch873591d2009-03-09 09:12:55 +01002 * C-Media CMI8788 driver for C-Media's reference design and similar models
Clemens Ladischd0ce9942007-12-23 19:50:57 +01003 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
Clemens Ladischdc0adf42009-09-28 11:17:36 +020021 * CMI8788:
22 *
Clemens Ladischde664932010-12-02 11:42:48 +010023 * SPI 0 -> 1st AK4396 (front)
24 * SPI 1 -> 2nd AK4396 (surround)
25 * SPI 2 -> 3rd AK4396 (center/LFE)
26 * SPI 3 -> WM8785
27 * SPI 4 -> 4th AK4396 (back)
Clemens Ladischd0ce9942007-12-23 19:50:57 +010028 *
Clemens Ladischde664932010-12-02 11:42:48 +010029 * GPIO 0 -> DFS0 of AK5385
30 * GPIO 1 -> DFS1 of AK5385
Clemens Ladisch64878df2011-01-10 16:35:38 +010031 *
32 * X-Meridian models:
33 * GPIO 4 -> enable extension S/PDIF input
34 * GPIO 6 -> enable on-board S/PDIF input
35 *
36 * Claro models:
Clemens Ladischd1d70932011-01-11 10:35:29 +010037 * GPIO 6 -> S/PDIF from optical (0) or coaxial (1) input
Clemens Ladisch64878df2011-01-10 16:35:38 +010038 * GPIO 8 -> enable headphone amplifier
Clemens Ladischdc0adf42009-09-28 11:17:36 +020039 *
40 * CM9780:
41 *
Clemens Ladischde664932010-12-02 11:42:48 +010042 * LINE_OUT -> input of ADC
43 *
44 * AUX_IN <- aux
45 * CD_IN <- CD
46 * MIC_IN <- mic
47 *
48 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input
Clemens Ladischd0ce9942007-12-23 19:50:57 +010049 */
50
Clemens Ladischdf91bc22008-08-29 13:08:34 +020051#include <linux/delay.h>
Clemens Ladisch902b05c2008-02-22 18:40:56 +010052#include <linux/mutex.h>
Clemens Ladischd0ce9942007-12-23 19:50:57 +010053#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040054#include <linux/module.h>
Clemens Ladisch902b05c2008-02-22 18:40:56 +010055#include <sound/ac97_codec.h>
Clemens Ladischccc80fb2008-01-16 08:32:08 +010056#include <sound/control.h>
Clemens Ladischd0ce9942007-12-23 19:50:57 +010057#include <sound/core.h>
Clemens Ladisch9719fca2010-12-02 11:41:10 +010058#include <sound/info.h>
Clemens Ladischd0ce9942007-12-23 19:50:57 +010059#include <sound/initval.h>
60#include <sound/pcm.h>
61#include <sound/pcm_params.h>
62#include <sound/tlv.h>
63#include "oxygen.h"
Clemens Ladisch66410bf2011-01-10 16:20:29 +010064#include "xonar_dg.h"
Clemens Ladischc6260262008-01-25 08:41:52 +010065#include "ak4396.h"
Clemens Ladischf5b23682008-03-19 08:14:01 +010066#include "wm8785.h"
Clemens Ladischd0ce9942007-12-23 19:50:57 +010067
68MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
69MODULE_DESCRIPTION("C-Media CMI8788 driver");
Clemens Ladischd023dc02008-05-13 09:18:27 +020070MODULE_LICENSE("GPL v2");
Clemens Ladisch66410bf2011-01-10 16:20:29 +010071MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8786}"
72 ",{C-Media,CMI8787}"
73 ",{C-Media,CMI8788}}");
Clemens Ladischd0ce9942007-12-23 19:50:57 +010074
75static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
76static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
77static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
78
79module_param_array(index, int, NULL, 0444);
80MODULE_PARM_DESC(index, "card index");
81module_param_array(id, charp, NULL, 0444);
82MODULE_PARM_DESC(id, "ID string");
83module_param_array(enable, bool, NULL, 0444);
84MODULE_PARM_DESC(enable, "enable card");
85
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +020086enum {
Clemens Ladisch18f24832010-11-03 11:36:33 +010087 MODEL_CMEDIA_REF,
88 MODEL_MERIDIAN,
Clemens Ladischa4b16962011-01-10 16:37:19 +010089 MODEL_MERIDIAN_2G,
Clemens Ladisch18f24832010-11-03 11:36:33 +010090 MODEL_CLARO,
91 MODEL_CLARO_HALO,
Clemens Ladisch2146dcf2010-11-03 12:26:35 +010092 MODEL_FANTASIA,
Clemens Ladischa4b16962011-01-10 16:37:19 +010093 MODEL_SERENADE,
Clemens Ladisch2146dcf2010-11-03 12:26:35 +010094 MODEL_2CH_OUTPUT,
Clemens Ladischa4b16962011-01-10 16:37:19 +010095 MODEL_HG2PCI,
Clemens Ladisch66410bf2011-01-10 16:20:29 +010096 MODEL_XONAR_DG,
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +020097};
98
Alexey Dobriyancebe41d2010-02-06 00:21:03 +020099static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
Clemens Ladisch18f24832010-11-03 11:36:33 +0100100 /* C-Media's reference design */
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +0200101 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch8c50b752011-01-10 16:16:32 +0100102 { OXYGEN_PCI_SUBID(0x10b0, 0x0217), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +0200103 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF },
104 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF },
105 { OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF },
106 { OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF },
107 { OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF },
108 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100109 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch66410bf2011-01-10 16:20:29 +0100110 /* Asus Xonar DG */
111 { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG },
Clemens Ladisch8c50b752011-01-10 16:16:32 +0100112 /* PCI 2.0 HD Audio */
113 { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100114 /* Kuroutoshikou CMI8787-HG2PCI */
Clemens Ladischa4b16962011-01-10 16:37:19 +0100115 { OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_HG2PCI },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100116 /* TempoTec HiFier Fantasia */
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100117 { OXYGEN_PCI_SUBID(0x14c3, 0x1710), .driver_data = MODEL_FANTASIA },
118 /* TempoTec HiFier Serenade */
Clemens Ladischa4b16962011-01-10 16:37:19 +0100119 { OXYGEN_PCI_SUBID(0x14c3, 0x1711), .driver_data = MODEL_SERENADE },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100120 /* AuzenTech X-Meridian */
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +0200121 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN },
Clemens Ladisch8443d2e2011-01-10 16:17:26 +0100122 /* AuzenTech X-Meridian 2G */
Clemens Ladischa4b16962011-01-10 16:37:19 +0100123 { OXYGEN_PCI_SUBID(0x5431, 0x017a), .driver_data = MODEL_MERIDIAN_2G },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100124 /* HT-Omega Claro */
Clemens Ladisch873591d2009-03-09 09:12:55 +0100125 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100126 /* HT-Omega Claro halo */
Clemens Ladisch873591d2009-03-09 09:12:55 +0100127 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO },
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100128 { }
129};
130MODULE_DEVICE_TABLE(pci, oxygen_ids);
131
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100132
133#define GPIO_AK5385_DFS_MASK 0x0003
134#define GPIO_AK5385_DFS_NORMAL 0x0000
135#define GPIO_AK5385_DFS_DOUBLE 0x0001
136#define GPIO_AK5385_DFS_QUAD 0x0002
137
Clemens Ladisch64878df2011-01-10 16:35:38 +0100138#define GPIO_MERIDIAN_DIG_MASK 0x0050
139#define GPIO_MERIDIAN_DIG_EXT 0x0010
140#define GPIO_MERIDIAN_DIG_BOARD 0x0040
141
Clemens Ladischd1d70932011-01-11 10:35:29 +0100142#define GPIO_CLARO_DIG_COAX 0x0040
Clemens Ladisch873591d2009-03-09 09:12:55 +0100143#define GPIO_CLARO_HP 0x0100
144
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100145struct generic_data {
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100146 unsigned int dacs;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200147 u8 ak4396_regs[4][5];
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200148 u16 wm8785_regs[3];
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100149};
150
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100151static void ak4396_write(struct oxygen *chip, unsigned int codec,
152 u8 reg, u8 value)
153{
154 /* maps ALSA channel pair number to SPI output */
155 static const u8 codec_spi_map[4] = {
Clemens Ladisch7113e952008-01-14 08:55:03 +0100156 0, 1, 2, 4
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100157 };
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200158 struct generic_data *data = chip->model_data;
159
Clemens Ladischc2353a02008-01-18 09:17:53 +0100160 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100161 OXYGEN_SPI_DATA_LENGTH_2 |
Clemens Ladisch2ea85982008-01-30 08:38:30 +0100162 OXYGEN_SPI_CLOCK_160 |
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100163 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
Clemens Ladischc2353a02008-01-18 09:17:53 +0100164 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100165 AK4396_WRITE | (reg << 8) | value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200166 data->ak4396_regs[codec][reg] = value;
167}
168
169static void ak4396_write_cached(struct oxygen *chip, unsigned int codec,
170 u8 reg, u8 value)
171{
172 struct generic_data *data = chip->model_data;
173
174 if (value != data->ak4396_regs[codec][reg])
175 ak4396_write(chip, codec, reg, value);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100176}
177
178static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
179{
Clemens Ladische58aee92008-05-13 09:20:51 +0200180 struct generic_data *data = chip->model_data;
181
Clemens Ladischc2353a02008-01-18 09:17:53 +0100182 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100183 OXYGEN_SPI_DATA_LENGTH_2 |
Clemens Ladisch2ea85982008-01-30 08:38:30 +0100184 OXYGEN_SPI_CLOCK_160 |
Clemens Ladischc2353a02008-01-18 09:17:53 +0100185 (3 << OXYGEN_SPI_CODEC_SHIFT) |
186 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100187 (reg << 9) | value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200188 if (reg < ARRAY_SIZE(data->wm8785_regs))
189 data->wm8785_regs[reg] = value;
Clemens Ladischbbbfb552008-05-13 09:21:48 +0200190}
191
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200192static void ak4396_registers_init(struct oxygen *chip)
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100193{
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100194 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100195 unsigned int i;
196
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100197 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200198 ak4396_write(chip, i, AK4396_CONTROL_1,
199 AK4396_DIF_24_MSB | AK4396_RSTN);
200 ak4396_write(chip, i, AK4396_CONTROL_2,
201 data->ak4396_regs[0][AK4396_CONTROL_2]);
202 ak4396_write(chip, i, AK4396_CONTROL_3,
203 AK4396_PCM);
204 ak4396_write(chip, i, AK4396_LCH_ATT,
205 chip->dac_volume[i * 2]);
206 ak4396_write(chip, i, AK4396_RCH_ATT,
207 chip->dac_volume[i * 2 + 1]);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100208 }
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200209}
210
211static void ak4396_init(struct oxygen *chip)
212{
213 struct generic_data *data = chip->model_data;
214
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +0100215 data->dacs = chip->model.dac_channels_pcm / 2;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200216 data->ak4396_regs[0][AK4396_CONTROL_2] =
217 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200218 ak4396_registers_init(chip);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100219 snd_component_add(chip->card, "AK4396");
220}
221
222static void ak5385_init(struct oxygen *chip)
223{
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100224 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_AK5385_DFS_MASK);
225 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_AK5385_DFS_MASK);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100226 snd_component_add(chip->card, "AK5385");
227}
228
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200229static void wm8785_registers_init(struct oxygen *chip)
230{
231 struct generic_data *data = chip->model_data;
232
233 wm8785_write(chip, WM8785_R7, 0);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200234 wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]);
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200235 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200236}
237
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100238static void wm8785_init(struct oxygen *chip)
239{
Clemens Ladische58aee92008-05-13 09:20:51 +0200240 struct generic_data *data = chip->model_data;
241
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200242 data->wm8785_regs[0] =
243 WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST;
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200244 data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL;
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200245 wm8785_registers_init(chip);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100246 snd_component_add(chip->card, "WM8785");
247}
248
249static void generic_init(struct oxygen *chip)
250{
251 ak4396_init(chip);
252 wm8785_init(chip);
253}
254
255static void meridian_init(struct oxygen *chip)
256{
Clemens Ladisch64878df2011-01-10 16:35:38 +0100257 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
258 GPIO_MERIDIAN_DIG_MASK);
259 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
260 GPIO_MERIDIAN_DIG_BOARD, GPIO_MERIDIAN_DIG_MASK);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100261 ak4396_init(chip);
262 ak5385_init(chip);
263}
264
Clemens Ladisch873591d2009-03-09 09:12:55 +0100265static void claro_enable_hp(struct oxygen *chip)
266{
267 msleep(300);
268 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_HP);
269 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
270}
271
272static void claro_init(struct oxygen *chip)
273{
Clemens Ladischd1d70932011-01-11 10:35:29 +0100274 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX);
275 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX);
Clemens Ladisch873591d2009-03-09 09:12:55 +0100276 ak4396_init(chip);
277 wm8785_init(chip);
278 claro_enable_hp(chip);
279}
280
281static void claro_halo_init(struct oxygen *chip)
Clemens Ladischd91b4242009-02-20 09:31:14 +0100282{
Clemens Ladischd1d70932011-01-11 10:35:29 +0100283 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX);
284 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX);
Clemens Ladischd91b4242009-02-20 09:31:14 +0100285 ak4396_init(chip);
286 ak5385_init(chip);
Clemens Ladisch873591d2009-03-09 09:12:55 +0100287 claro_enable_hp(chip);
Clemens Ladischd91b4242009-02-20 09:31:14 +0100288}
289
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100290static void fantasia_init(struct oxygen *chip)
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100291{
292 ak4396_init(chip);
293 snd_component_add(chip->card, "CS5340");
294}
295
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100296static void stereo_output_init(struct oxygen *chip)
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100297{
298 ak4396_init(chip);
299}
300
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100301static void generic_cleanup(struct oxygen *chip)
302{
303}
304
Clemens Ladisch873591d2009-03-09 09:12:55 +0100305static void claro_disable_hp(struct oxygen *chip)
306{
307 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
308}
309
310static void claro_cleanup(struct oxygen *chip)
311{
312 claro_disable_hp(chip);
313}
314
315static void claro_suspend(struct oxygen *chip)
316{
317 claro_disable_hp(chip);
318}
319
Clemens Ladisch4a4bc532008-05-13 09:24:39 +0200320static void generic_resume(struct oxygen *chip)
321{
322 ak4396_registers_init(chip);
323 wm8785_registers_init(chip);
324}
325
Clemens Ladischc2bc4ff2008-09-22 09:05:29 +0200326static void meridian_resume(struct oxygen *chip)
327{
328 ak4396_registers_init(chip);
329}
330
Clemens Ladisch873591d2009-03-09 09:12:55 +0100331static void claro_resume(struct oxygen *chip)
Clemens Ladischd91b4242009-02-20 09:31:14 +0100332{
333 ak4396_registers_init(chip);
Clemens Ladisch873591d2009-03-09 09:12:55 +0100334 claro_enable_hp(chip);
Clemens Ladischd91b4242009-02-20 09:31:14 +0100335}
336
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100337static void stereo_resume(struct oxygen *chip)
338{
339 ak4396_registers_init(chip);
340}
341
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100342static void set_ak4396_params(struct oxygen *chip,
343 struct snd_pcm_hw_params *params)
344{
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100345 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100346 unsigned int i;
347 u8 value;
348
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200349 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100350 if (params_rate(params) <= 54000)
351 value |= AK4396_DFS_NORMAL;
Clemens Ladisch236c4922008-01-28 08:32:58 +0100352 else if (params_rate(params) <= 108000)
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100353 value |= AK4396_DFS_DOUBLE;
354 else
355 value |= AK4396_DFS_QUAD;
Clemens Ladischdf91bc22008-08-29 13:08:34 +0200356
357 msleep(1); /* wait for the new MCLK to become stable */
358
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200359 if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) {
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100360 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200361 ak4396_write(chip, i, AK4396_CONTROL_1,
362 AK4396_DIF_24_MSB);
363 ak4396_write(chip, i, AK4396_CONTROL_2, value);
364 ak4396_write(chip, i, AK4396_CONTROL_1,
365 AK4396_DIF_24_MSB | AK4396_RSTN);
366 }
367 }
368}
369
370static void update_ak4396_volume(struct oxygen *chip)
371{
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100372 struct generic_data *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200373 unsigned int i;
374
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100375 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200376 ak4396_write_cached(chip, i, AK4396_LCH_ATT,
377 chip->dac_volume[i * 2]);
378 ak4396_write_cached(chip, i, AK4396_RCH_ATT,
379 chip->dac_volume[i * 2 + 1]);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100380 }
381}
382
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100383static void update_ak4396_mute(struct oxygen *chip)
384{
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100385 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100386 unsigned int i;
387 u8 value;
388
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200389 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100390 if (chip->dac_mute)
391 value |= AK4396_SMUTE;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100392 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200393 ak4396_write_cached(chip, i, AK4396_CONTROL_2, value);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100394}
395
396static void set_wm8785_params(struct oxygen *chip,
397 struct snd_pcm_hw_params *params)
398{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200399 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100400 unsigned int value;
401
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100402 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST;
Clemens Ladisch71e22a42008-01-21 08:50:51 +0100403 if (params_rate(params) <= 48000)
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100404 value |= WM8785_OSR_SINGLE;
Clemens Ladisch71e22a42008-01-21 08:50:51 +0100405 else if (params_rate(params) <= 96000)
406 value |= WM8785_OSR_DOUBLE;
407 else
408 value |= WM8785_OSR_QUAD;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200409 if (value != data->wm8785_regs[0]) {
410 wm8785_write(chip, WM8785_R7, 0);
411 wm8785_write(chip, WM8785_R0, value);
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200412 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200413 }
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100414}
415
416static void set_ak5385_params(struct oxygen *chip,
417 struct snd_pcm_hw_params *params)
418{
419 unsigned int value;
420
421 if (params_rate(params) <= 54000)
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100422 value = GPIO_AK5385_DFS_NORMAL;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100423 else if (params_rate(params) <= 108000)
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100424 value = GPIO_AK5385_DFS_DOUBLE;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100425 else
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100426 value = GPIO_AK5385_DFS_QUAD;
427 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
428 value, GPIO_AK5385_DFS_MASK);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100429}
430
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100431static void set_no_params(struct oxygen *chip, struct snd_pcm_hw_params *params)
432{
433}
434
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200435static int rolloff_info(struct snd_kcontrol *ctl,
436 struct snd_ctl_elem_info *info)
437{
438 static const char *const names[2] = {
439 "Sharp Roll-off", "Slow Roll-off"
440 };
441
Clemens Ladisch96007322011-01-10 16:25:44 +0100442 return snd_ctl_enum_info(info, 1, 2, names);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200443}
444
445static int rolloff_get(struct snd_kcontrol *ctl,
446 struct snd_ctl_elem_value *value)
447{
448 struct oxygen *chip = ctl->private_data;
449 struct generic_data *data = chip->model_data;
450
451 value->value.enumerated.item[0] =
452 (data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0;
453 return 0;
454}
455
456static int rolloff_put(struct snd_kcontrol *ctl,
457 struct snd_ctl_elem_value *value)
458{
459 struct oxygen *chip = ctl->private_data;
460 struct generic_data *data = chip->model_data;
461 unsigned int i;
462 int changed;
463 u8 reg;
464
465 mutex_lock(&chip->mutex);
466 reg = data->ak4396_regs[0][AK4396_CONTROL_2];
467 if (value->value.enumerated.item[0])
468 reg |= AK4396_SLOW;
469 else
470 reg &= ~AK4396_SLOW;
471 changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2];
472 if (changed) {
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100473 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200474 ak4396_write(chip, i, AK4396_CONTROL_2, reg);
475 }
476 mutex_unlock(&chip->mutex);
477 return changed;
478}
479
480static const struct snd_kcontrol_new rolloff_control = {
481 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "DAC Filter Playback Enum",
483 .info = rolloff_info,
484 .get = rolloff_get,
485 .put = rolloff_put,
486};
487
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200488static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
489{
490 static const char *const names[2] = {
491 "None", "High-pass Filter"
492 };
493
Clemens Ladisch96007322011-01-10 16:25:44 +0100494 return snd_ctl_enum_info(info, 1, 2, names);
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200495}
496
497static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
498{
499 struct oxygen *chip = ctl->private_data;
500 struct generic_data *data = chip->model_data;
501
502 value->value.enumerated.item[0] =
503 (data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0;
504 return 0;
505}
506
507static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
508{
509 struct oxygen *chip = ctl->private_data;
510 struct generic_data *data = chip->model_data;
511 unsigned int reg;
512 int changed;
513
514 mutex_lock(&chip->mutex);
515 reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL);
516 if (value->value.enumerated.item[0])
517 reg |= WM8785_HPFR | WM8785_HPFL;
518 changed = reg != data->wm8785_regs[WM8785_R2];
519 if (changed)
520 wm8785_write(chip, WM8785_R2, reg);
521 mutex_unlock(&chip->mutex);
522 return changed;
523}
524
525static const struct snd_kcontrol_new hpf_control = {
526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
527 .name = "ADC Filter Capture Enum",
528 .info = hpf_info,
529 .get = hpf_get,
530 .put = hpf_put,
531};
532
Clemens Ladischd1d70932011-01-11 10:35:29 +0100533static int meridian_dig_source_info(struct snd_kcontrol *ctl,
534 struct snd_ctl_elem_info *info)
Clemens Ladisch64878df2011-01-10 16:35:38 +0100535{
536 static const char *const names[2] = { "On-board", "Extension" };
537
538 return snd_ctl_enum_info(info, 1, 2, names);
539}
540
Clemens Ladischd1d70932011-01-11 10:35:29 +0100541static int claro_dig_source_info(struct snd_kcontrol *ctl,
542 struct snd_ctl_elem_info *info)
543{
544 static const char *const names[2] = { "Optical", "Coaxial" };
545
546 return snd_ctl_enum_info(info, 1, 2, names);
547}
548
549static int meridian_dig_source_get(struct snd_kcontrol *ctl,
550 struct snd_ctl_elem_value *value)
Clemens Ladisch64878df2011-01-10 16:35:38 +0100551{
552 struct oxygen *chip = ctl->private_data;
553
554 value->value.enumerated.item[0] =
555 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) &
556 GPIO_MERIDIAN_DIG_EXT);
557 return 0;
558}
559
Clemens Ladischd1d70932011-01-11 10:35:29 +0100560static int claro_dig_source_get(struct snd_kcontrol *ctl,
561 struct snd_ctl_elem_value *value)
562{
563 struct oxygen *chip = ctl->private_data;
564
565 value->value.enumerated.item[0] =
566 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) &
567 GPIO_CLARO_DIG_COAX);
568 return 0;
569}
570
571static int meridian_dig_source_put(struct snd_kcontrol *ctl,
572 struct snd_ctl_elem_value *value)
Clemens Ladisch64878df2011-01-10 16:35:38 +0100573{
574 struct oxygen *chip = ctl->private_data;
575 u16 old_reg, new_reg;
576 int changed;
577
578 mutex_lock(&chip->mutex);
579 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
580 new_reg = old_reg & ~GPIO_MERIDIAN_DIG_MASK;
581 if (value->value.enumerated.item[0] == 0)
582 new_reg |= GPIO_MERIDIAN_DIG_BOARD;
583 else
584 new_reg |= GPIO_MERIDIAN_DIG_EXT;
585 changed = new_reg != old_reg;
586 if (changed)
587 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
588 mutex_unlock(&chip->mutex);
589 return changed;
590}
591
Clemens Ladischd1d70932011-01-11 10:35:29 +0100592static int claro_dig_source_put(struct snd_kcontrol *ctl,
593 struct snd_ctl_elem_value *value)
594{
595 struct oxygen *chip = ctl->private_data;
596 u16 old_reg, new_reg;
597 int changed;
598
599 mutex_lock(&chip->mutex);
600 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
601 new_reg = old_reg & ~GPIO_CLARO_DIG_COAX;
602 if (value->value.enumerated.item[0])
603 new_reg |= GPIO_CLARO_DIG_COAX;
604 changed = new_reg != old_reg;
605 if (changed)
606 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
607 mutex_unlock(&chip->mutex);
608 return changed;
609}
610
Clemens Ladisch64878df2011-01-10 16:35:38 +0100611static const struct snd_kcontrol_new meridian_dig_source_control = {
612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
613 .name = "IEC958 Source Capture Enum",
614 .info = meridian_dig_source_info,
615 .get = meridian_dig_source_get,
616 .put = meridian_dig_source_put,
617};
618
Clemens Ladischd1d70932011-01-11 10:35:29 +0100619static const struct snd_kcontrol_new claro_dig_source_control = {
620 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
621 .name = "IEC958 Source Capture Enum",
622 .info = claro_dig_source_info,
623 .get = claro_dig_source_get,
624 .put = claro_dig_source_put,
625};
626
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200627static int generic_mixer_init(struct oxygen *chip)
628{
629 return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
630}
631
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200632static int generic_wm8785_mixer_init(struct oxygen *chip)
633{
634 int err;
635
636 err = generic_mixer_init(chip);
637 if (err < 0)
638 return err;
639 err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip));
640 if (err < 0)
641 return err;
642 return 0;
643}
644
Clemens Ladisch64878df2011-01-10 16:35:38 +0100645static int meridian_mixer_init(struct oxygen *chip)
646{
647 int err;
648
649 err = generic_mixer_init(chip);
650 if (err < 0)
651 return err;
652 err = snd_ctl_add(chip->card,
653 snd_ctl_new1(&meridian_dig_source_control, chip));
654 if (err < 0)
655 return err;
656 return 0;
657}
658
Clemens Ladischd1d70932011-01-11 10:35:29 +0100659static int claro_mixer_init(struct oxygen *chip)
660{
661 int err;
662
663 err = generic_wm8785_mixer_init(chip);
664 if (err < 0)
665 return err;
666 err = snd_ctl_add(chip->card,
667 snd_ctl_new1(&claro_dig_source_control, chip));
668 if (err < 0)
669 return err;
670 return 0;
671}
672
673static int claro_halo_mixer_init(struct oxygen *chip)
674{
675 int err;
676
677 err = generic_mixer_init(chip);
678 if (err < 0)
679 return err;
680 err = snd_ctl_add(chip->card,
681 snd_ctl_new1(&claro_dig_source_control, chip));
682 if (err < 0)
683 return err;
684 return 0;
685}
686
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100687static void dump_ak4396_registers(struct oxygen *chip,
688 struct snd_info_buffer *buffer)
689{
690 struct generic_data *data = chip->model_data;
691 unsigned int dac, i;
692
693 for (dac = 0; dac < data->dacs; ++dac) {
694 snd_iprintf(buffer, "\nAK4396 %u:", dac + 1);
695 for (i = 0; i < 5; ++i)
696 snd_iprintf(buffer, " %02x", data->ak4396_regs[dac][i]);
697 }
698 snd_iprintf(buffer, "\n");
699}
700
701static void dump_wm8785_registers(struct oxygen *chip,
702 struct snd_info_buffer *buffer)
703{
704 struct generic_data *data = chip->model_data;
705 unsigned int i;
706
707 snd_iprintf(buffer, "\nWM8785:");
708 for (i = 0; i < 3; ++i)
709 snd_iprintf(buffer, " %03x", data->wm8785_regs[i]);
710 snd_iprintf(buffer, "\n");
711}
712
713static void dump_oxygen_registers(struct oxygen *chip,
714 struct snd_info_buffer *buffer)
715{
716 dump_ak4396_registers(chip, buffer);
717 dump_wm8785_registers(chip, buffer);
718}
719
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100720static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
721
722static const struct oxygen_model model_generic = {
723 .shortname = "C-Media CMI8788",
724 .longname = "C-Media Oxygen HD Audio",
725 .chip = "CMI8788",
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100726 .init = generic_init,
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200727 .mixer_init = generic_wm8785_mixer_init,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100728 .cleanup = generic_cleanup,
Clemens Ladisch4a4bc532008-05-13 09:24:39 +0200729 .resume = generic_resume,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100730 .set_dac_params = set_ak4396_params,
731 .set_adc_params = set_wm8785_params,
732 .update_dac_volume = update_ak4396_volume,
733 .update_dac_mute = update_ak4396_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100734 .dump_registers = dump_oxygen_registers,
Clemens Ladisch4972a172008-04-16 09:15:45 +0200735 .dac_tlv = ak4396_db_scale,
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100736 .model_data_size = sizeof(struct generic_data),
Clemens Ladischd76596b2008-09-22 09:02:08 +0200737 .device_config = PLAYBACK_0_TO_I2S |
738 PLAYBACK_1_TO_SPDIF |
739 PLAYBACK_2_TO_AC97_1 |
740 CAPTURE_0_FROM_I2S_1 |
741 CAPTURE_1_FROM_SPDIF |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +0200742 CAPTURE_2_FROM_AC97_1 |
743 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +0100744 .dac_channels_pcm = 8,
745 .dac_channels_mixer = 8,
Clemens Ladisch193e8132008-04-16 09:13:36 +0200746 .dac_volume_min = 0,
747 .dac_volume_max = 255,
Clemens Ladisch87eedd22008-03-19 08:20:13 +0100748 .function_flags = OXYGEN_FUNCTION_SPI |
749 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
Clemens Ladischce2c4922011-01-10 16:16:08 +0100750 .dac_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100751 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
Clemens Ladisch05855ba2008-01-17 09:05:09 +0100752 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
753 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100754};
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100755
Clemens Ladisch30459d72009-02-19 08:42:44 +0100756static int __devinit get_oxygen_model(struct oxygen *chip,
757 const struct pci_device_id *id)
758{
Clemens Ladischa4b16962011-01-10 16:37:19 +0100759 static const char *const names[] = {
760 [MODEL_MERIDIAN] = "AuzenTech X-Meridian",
761 [MODEL_MERIDIAN_2G] = "AuzenTech X-Meridian 2G",
762 [MODEL_CLARO] = "HT-Omega Claro",
763 [MODEL_CLARO_HALO] = "HT-Omega Claro halo",
764 [MODEL_FANTASIA] = "TempoTec HiFier Fantasia",
765 [MODEL_SERENADE] = "TempoTec HiFier Serenade",
766 [MODEL_HG2PCI] = "CMI8787-HG2PCI",
767 };
768
Clemens Ladisch30459d72009-02-19 08:42:44 +0100769 chip->model = model_generic;
770 switch (id->driver_data) {
771 case MODEL_MERIDIAN:
Clemens Ladischa4b16962011-01-10 16:37:19 +0100772 case MODEL_MERIDIAN_2G:
Clemens Ladisch30459d72009-02-19 08:42:44 +0100773 chip->model.init = meridian_init;
Clemens Ladisch64878df2011-01-10 16:35:38 +0100774 chip->model.mixer_init = meridian_mixer_init;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100775 chip->model.resume = meridian_resume;
776 chip->model.set_adc_params = set_ak5385_params;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100777 chip->model.dump_registers = dump_ak4396_registers;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100778 chip->model.device_config = PLAYBACK_0_TO_I2S |
779 PLAYBACK_1_TO_SPDIF |
780 CAPTURE_0_FROM_I2S_2 |
781 CAPTURE_1_FROM_SPDIF;
Clemens Ladisch5fc51522011-01-11 10:33:40 +0100782 if (id->driver_data == MODEL_MERIDIAN)
783 chip->model.device_config |= AC97_CD_INPUT;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100784 break;
Clemens Ladisch873591d2009-03-09 09:12:55 +0100785 case MODEL_CLARO:
786 chip->model.init = claro_init;
Clemens Ladischd1d70932011-01-11 10:35:29 +0100787 chip->model.mixer_init = claro_mixer_init;
Clemens Ladisch873591d2009-03-09 09:12:55 +0100788 chip->model.cleanup = claro_cleanup;
789 chip->model.suspend = claro_suspend;
790 chip->model.resume = claro_resume;
791 break;
792 case MODEL_CLARO_HALO:
793 chip->model.init = claro_halo_init;
Clemens Ladischd1d70932011-01-11 10:35:29 +0100794 chip->model.mixer_init = claro_halo_mixer_init;
Clemens Ladisch873591d2009-03-09 09:12:55 +0100795 chip->model.cleanup = claro_cleanup;
796 chip->model.suspend = claro_suspend;
797 chip->model.resume = claro_resume;
Clemens Ladischd91b4242009-02-20 09:31:14 +0100798 chip->model.set_adc_params = set_ak5385_params;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100799 chip->model.dump_registers = dump_ak4396_registers;
Erik J. Staab0873a5a2010-09-22 11:07:41 +0200800 chip->model.device_config = PLAYBACK_0_TO_I2S |
801 PLAYBACK_1_TO_SPDIF |
802 CAPTURE_0_FROM_I2S_2 |
803 CAPTURE_1_FROM_SPDIF;
Clemens Ladischd91b4242009-02-20 09:31:14 +0100804 break;
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100805 case MODEL_FANTASIA:
Clemens Ladischa4b16962011-01-10 16:37:19 +0100806 case MODEL_SERENADE:
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100807 case MODEL_2CH_OUTPUT:
Clemens Ladischa4b16962011-01-10 16:37:19 +0100808 case MODEL_HG2PCI:
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100809 chip->model.shortname = "C-Media CMI8787";
810 chip->model.chip = "CMI8787";
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100811 if (id->driver_data == MODEL_FANTASIA)
812 chip->model.init = fantasia_init;
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100813 else
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100814 chip->model.init = stereo_output_init;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100815 chip->model.resume = stereo_resume;
816 chip->model.mixer_init = generic_mixer_init;
817 chip->model.set_adc_params = set_no_params;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100818 chip->model.dump_registers = dump_ak4396_registers;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100819 chip->model.device_config = PLAYBACK_0_TO_I2S |
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100820 PLAYBACK_1_TO_SPDIF;
Clemens Ladischce2c4922011-01-10 16:16:08 +0100821 if (id->driver_data == MODEL_FANTASIA) {
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100822 chip->model.device_config |= CAPTURE_0_FROM_I2S_1;
Clemens Ladischce2c4922011-01-10 16:16:08 +0100823 chip->model.adc_mclks = OXYGEN_MCLKS(256, 128, 128);
824 }
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +0100825 chip->model.dac_channels_pcm = 2;
826 chip->model.dac_channels_mixer = 2;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100827 break;
Clemens Ladisch66410bf2011-01-10 16:20:29 +0100828 case MODEL_XONAR_DG:
829 chip->model = model_xonar_dg;
830 break;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100831 }
832 if (id->driver_data == MODEL_MERIDIAN ||
Clemens Ladisch5fc51522011-01-11 10:33:40 +0100833 id->driver_data == MODEL_MERIDIAN_2G ||
Clemens Ladisch873591d2009-03-09 09:12:55 +0100834 id->driver_data == MODEL_CLARO_HALO) {
Clemens Ladisch30459d72009-02-19 08:42:44 +0100835 chip->model.misc_flags = OXYGEN_MISC_MIDI;
836 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
837 }
Clemens Ladischa4b16962011-01-10 16:37:19 +0100838 if (id->driver_data < ARRAY_SIZE(names) && names[id->driver_data])
839 chip->model.shortname = names[id->driver_data];
Clemens Ladisch30459d72009-02-19 08:42:44 +0100840 return 0;
841}
842
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100843static int __devinit generic_oxygen_probe(struct pci_dev *pci,
844 const struct pci_device_id *pci_id)
845{
846 static int dev;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100847 int err;
848
849 if (dev >= SNDRV_CARDS)
850 return -ENODEV;
851 if (!enable[dev]) {
852 ++dev;
853 return -ENOENT;
854 }
Clemens Ladischbb718582009-02-19 08:37:13 +0100855 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
Clemens Ladisch30459d72009-02-19 08:42:44 +0100856 oxygen_ids, get_oxygen_model);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100857 if (err >= 0)
858 ++dev;
859 return err;
860}
861
862static struct pci_driver oxygen_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +0200863 .name = KBUILD_MODNAME,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100864 .id_table = oxygen_ids,
865 .probe = generic_oxygen_probe,
866 .remove = __devexit_p(oxygen_pci_remove),
Clemens Ladisch4a4bc532008-05-13 09:24:39 +0200867#ifdef CONFIG_PM
868 .suspend = oxygen_pci_suspend,
869 .resume = oxygen_pci_resume,
870#endif
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100871};
872
873static int __init alsa_card_oxygen_init(void)
874{
875 return pci_register_driver(&oxygen_driver);
876}
877
878static void __exit alsa_card_oxygen_exit(void)
879{
880 pci_unregister_driver(&oxygen_driver);
881}
882
883module_init(alsa_card_oxygen_init)
884module_exit(alsa_card_oxygen_exit)