blob: d7e8ddd9a67b3a28c0d22dbc9876c37b9ea2ecee [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>
Clemens Ladisch902b05c2008-02-22 18:40:56 +010054#include <sound/ac97_codec.h>
Clemens Ladischccc80fb2008-01-16 08:32:08 +010055#include <sound/control.h>
Clemens Ladischd0ce9942007-12-23 19:50:57 +010056#include <sound/core.h>
Clemens Ladisch9719fca2010-12-02 11:41:10 +010057#include <sound/info.h>
Clemens Ladischd0ce9942007-12-23 19:50:57 +010058#include <sound/initval.h>
59#include <sound/pcm.h>
60#include <sound/pcm_params.h>
61#include <sound/tlv.h>
62#include "oxygen.h"
Clemens Ladisch66410bf2011-01-10 16:20:29 +010063#include "xonar_dg.h"
Clemens Ladischc6260262008-01-25 08:41:52 +010064#include "ak4396.h"
Clemens Ladischf5b23682008-03-19 08:14:01 +010065#include "wm8785.h"
Clemens Ladischd0ce9942007-12-23 19:50:57 +010066
67MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
68MODULE_DESCRIPTION("C-Media CMI8788 driver");
Clemens Ladischd023dc02008-05-13 09:18:27 +020069MODULE_LICENSE("GPL v2");
Clemens Ladisch66410bf2011-01-10 16:20:29 +010070MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8786}"
71 ",{C-Media,CMI8787}"
72 ",{C-Media,CMI8788}}");
Clemens Ladischd0ce9942007-12-23 19:50:57 +010073
74static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
75static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
76static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
77
78module_param_array(index, int, NULL, 0444);
79MODULE_PARM_DESC(index, "card index");
80module_param_array(id, charp, NULL, 0444);
81MODULE_PARM_DESC(id, "ID string");
82module_param_array(enable, bool, NULL, 0444);
83MODULE_PARM_DESC(enable, "enable card");
84
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +020085enum {
Clemens Ladisch18f24832010-11-03 11:36:33 +010086 MODEL_CMEDIA_REF,
87 MODEL_MERIDIAN,
Clemens Ladischa4b16962011-01-10 16:37:19 +010088 MODEL_MERIDIAN_2G,
Clemens Ladisch18f24832010-11-03 11:36:33 +010089 MODEL_CLARO,
90 MODEL_CLARO_HALO,
Clemens Ladisch2146dcf2010-11-03 12:26:35 +010091 MODEL_FANTASIA,
Clemens Ladischa4b16962011-01-10 16:37:19 +010092 MODEL_SERENADE,
Clemens Ladisch2146dcf2010-11-03 12:26:35 +010093 MODEL_2CH_OUTPUT,
Clemens Ladischa4b16962011-01-10 16:37:19 +010094 MODEL_HG2PCI,
Clemens Ladisch66410bf2011-01-10 16:20:29 +010095 MODEL_XONAR_DG,
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +020096};
97
Alexey Dobriyancebe41d2010-02-06 00:21:03 +020098static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
Clemens Ladisch18f24832010-11-03 11:36:33 +010099 /* C-Media's reference design */
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +0200100 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch8c50b752011-01-10 16:16:32 +0100101 { OXYGEN_PCI_SUBID(0x10b0, 0x0217), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +0200102 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF },
103 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF },
104 { OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF },
105 { OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF },
106 { OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF },
107 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100108 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
Clemens Ladisch66410bf2011-01-10 16:20:29 +0100109 /* Asus Xonar DG */
110 { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG },
Clemens Ladisch8c50b752011-01-10 16:16:32 +0100111 /* PCI 2.0 HD Audio */
112 { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100113 /* Kuroutoshikou CMI8787-HG2PCI */
Clemens Ladischa4b16962011-01-10 16:37:19 +0100114 { OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_HG2PCI },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100115 /* TempoTec HiFier Fantasia */
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100116 { OXYGEN_PCI_SUBID(0x14c3, 0x1710), .driver_data = MODEL_FANTASIA },
117 /* TempoTec HiFier Serenade */
Clemens Ladischa4b16962011-01-10 16:37:19 +0100118 { OXYGEN_PCI_SUBID(0x14c3, 0x1711), .driver_data = MODEL_SERENADE },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100119 /* AuzenTech X-Meridian */
Clemens Ladisch2f1b0ec2008-09-22 08:57:24 +0200120 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN },
Clemens Ladisch8443d2e2011-01-10 16:17:26 +0100121 /* AuzenTech X-Meridian 2G */
Clemens Ladischa4b16962011-01-10 16:37:19 +0100122 { OXYGEN_PCI_SUBID(0x5431, 0x017a), .driver_data = MODEL_MERIDIAN_2G },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100123 /* HT-Omega Claro */
Clemens Ladisch873591d2009-03-09 09:12:55 +0100124 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO },
Clemens Ladisch18f24832010-11-03 11:36:33 +0100125 /* HT-Omega Claro halo */
Clemens Ladisch873591d2009-03-09 09:12:55 +0100126 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO },
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100127 { }
128};
129MODULE_DEVICE_TABLE(pci, oxygen_ids);
130
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100131
132#define GPIO_AK5385_DFS_MASK 0x0003
133#define GPIO_AK5385_DFS_NORMAL 0x0000
134#define GPIO_AK5385_DFS_DOUBLE 0x0001
135#define GPIO_AK5385_DFS_QUAD 0x0002
136
Clemens Ladisch64878df2011-01-10 16:35:38 +0100137#define GPIO_MERIDIAN_DIG_MASK 0x0050
138#define GPIO_MERIDIAN_DIG_EXT 0x0010
139#define GPIO_MERIDIAN_DIG_BOARD 0x0040
140
Clemens Ladischd1d70932011-01-11 10:35:29 +0100141#define GPIO_CLARO_DIG_COAX 0x0040
Clemens Ladisch873591d2009-03-09 09:12:55 +0100142#define GPIO_CLARO_HP 0x0100
143
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100144struct generic_data {
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100145 unsigned int dacs;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200146 u8 ak4396_regs[4][5];
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200147 u16 wm8785_regs[3];
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100148};
149
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100150static void ak4396_write(struct oxygen *chip, unsigned int codec,
151 u8 reg, u8 value)
152{
153 /* maps ALSA channel pair number to SPI output */
154 static const u8 codec_spi_map[4] = {
Clemens Ladisch7113e952008-01-14 08:55:03 +0100155 0, 1, 2, 4
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100156 };
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200157 struct generic_data *data = chip->model_data;
158
Clemens Ladischc2353a02008-01-18 09:17:53 +0100159 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100160 OXYGEN_SPI_DATA_LENGTH_2 |
Clemens Ladisch2ea85982008-01-30 08:38:30 +0100161 OXYGEN_SPI_CLOCK_160 |
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100162 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
Clemens Ladischc2353a02008-01-18 09:17:53 +0100163 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100164 AK4396_WRITE | (reg << 8) | value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200165 data->ak4396_regs[codec][reg] = value;
166}
167
168static void ak4396_write_cached(struct oxygen *chip, unsigned int codec,
169 u8 reg, u8 value)
170{
171 struct generic_data *data = chip->model_data;
172
173 if (value != data->ak4396_regs[codec][reg])
174 ak4396_write(chip, codec, reg, value);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100175}
176
177static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
178{
Clemens Ladische58aee92008-05-13 09:20:51 +0200179 struct generic_data *data = chip->model_data;
180
Clemens Ladischc2353a02008-01-18 09:17:53 +0100181 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100182 OXYGEN_SPI_DATA_LENGTH_2 |
Clemens Ladisch2ea85982008-01-30 08:38:30 +0100183 OXYGEN_SPI_CLOCK_160 |
Clemens Ladischc2353a02008-01-18 09:17:53 +0100184 (3 << OXYGEN_SPI_CODEC_SHIFT) |
185 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100186 (reg << 9) | value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200187 if (reg < ARRAY_SIZE(data->wm8785_regs))
188 data->wm8785_regs[reg] = value;
Clemens Ladischbbbfb552008-05-13 09:21:48 +0200189}
190
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200191static void ak4396_registers_init(struct oxygen *chip)
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100192{
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100193 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100194 unsigned int i;
195
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100196 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200197 ak4396_write(chip, i, AK4396_CONTROL_1,
198 AK4396_DIF_24_MSB | AK4396_RSTN);
199 ak4396_write(chip, i, AK4396_CONTROL_2,
200 data->ak4396_regs[0][AK4396_CONTROL_2]);
201 ak4396_write(chip, i, AK4396_CONTROL_3,
202 AK4396_PCM);
203 ak4396_write(chip, i, AK4396_LCH_ATT,
204 chip->dac_volume[i * 2]);
205 ak4396_write(chip, i, AK4396_RCH_ATT,
206 chip->dac_volume[i * 2 + 1]);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100207 }
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200208}
209
210static void ak4396_init(struct oxygen *chip)
211{
212 struct generic_data *data = chip->model_data;
213
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +0100214 data->dacs = chip->model.dac_channels_pcm / 2;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200215 data->ak4396_regs[0][AK4396_CONTROL_2] =
216 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200217 ak4396_registers_init(chip);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100218 snd_component_add(chip->card, "AK4396");
219}
220
221static void ak5385_init(struct oxygen *chip)
222{
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100223 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_AK5385_DFS_MASK);
224 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_AK5385_DFS_MASK);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100225 snd_component_add(chip->card, "AK5385");
226}
227
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200228static void wm8785_registers_init(struct oxygen *chip)
229{
230 struct generic_data *data = chip->model_data;
231
232 wm8785_write(chip, WM8785_R7, 0);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200233 wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]);
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200234 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200235}
236
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100237static void wm8785_init(struct oxygen *chip)
238{
Clemens Ladische58aee92008-05-13 09:20:51 +0200239 struct generic_data *data = chip->model_data;
240
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200241 data->wm8785_regs[0] =
242 WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST;
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200243 data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL;
Clemens Ladisch75146fc2008-05-13 09:22:43 +0200244 wm8785_registers_init(chip);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100245 snd_component_add(chip->card, "WM8785");
246}
247
248static void generic_init(struct oxygen *chip)
249{
250 ak4396_init(chip);
251 wm8785_init(chip);
252}
253
254static void meridian_init(struct oxygen *chip)
255{
Clemens Ladisch64878df2011-01-10 16:35:38 +0100256 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
257 GPIO_MERIDIAN_DIG_MASK);
258 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
259 GPIO_MERIDIAN_DIG_BOARD, GPIO_MERIDIAN_DIG_MASK);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100260 ak4396_init(chip);
261 ak5385_init(chip);
262}
263
Clemens Ladisch873591d2009-03-09 09:12:55 +0100264static void claro_enable_hp(struct oxygen *chip)
265{
266 msleep(300);
267 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_HP);
268 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
269}
270
271static void claro_init(struct oxygen *chip)
272{
Clemens Ladischd1d70932011-01-11 10:35:29 +0100273 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX);
274 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX);
Clemens Ladisch873591d2009-03-09 09:12:55 +0100275 ak4396_init(chip);
276 wm8785_init(chip);
277 claro_enable_hp(chip);
278}
279
280static void claro_halo_init(struct oxygen *chip)
Clemens Ladischd91b4242009-02-20 09:31:14 +0100281{
Clemens Ladischd1d70932011-01-11 10:35:29 +0100282 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX);
283 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX);
Clemens Ladischd91b4242009-02-20 09:31:14 +0100284 ak4396_init(chip);
285 ak5385_init(chip);
Clemens Ladisch873591d2009-03-09 09:12:55 +0100286 claro_enable_hp(chip);
Clemens Ladischd91b4242009-02-20 09:31:14 +0100287}
288
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100289static void fantasia_init(struct oxygen *chip)
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100290{
291 ak4396_init(chip);
292 snd_component_add(chip->card, "CS5340");
293}
294
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100295static void stereo_output_init(struct oxygen *chip)
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100296{
297 ak4396_init(chip);
298}
299
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100300static void generic_cleanup(struct oxygen *chip)
301{
302}
303
Clemens Ladisch873591d2009-03-09 09:12:55 +0100304static void claro_disable_hp(struct oxygen *chip)
305{
306 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
307}
308
309static void claro_cleanup(struct oxygen *chip)
310{
311 claro_disable_hp(chip);
312}
313
314static void claro_suspend(struct oxygen *chip)
315{
316 claro_disable_hp(chip);
317}
318
Clemens Ladisch4a4bc532008-05-13 09:24:39 +0200319static void generic_resume(struct oxygen *chip)
320{
321 ak4396_registers_init(chip);
322 wm8785_registers_init(chip);
323}
324
Clemens Ladischc2bc4ff2008-09-22 09:05:29 +0200325static void meridian_resume(struct oxygen *chip)
326{
327 ak4396_registers_init(chip);
328}
329
Clemens Ladisch873591d2009-03-09 09:12:55 +0100330static void claro_resume(struct oxygen *chip)
Clemens Ladischd91b4242009-02-20 09:31:14 +0100331{
332 ak4396_registers_init(chip);
Clemens Ladisch873591d2009-03-09 09:12:55 +0100333 claro_enable_hp(chip);
Clemens Ladischd91b4242009-02-20 09:31:14 +0100334}
335
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100336static void stereo_resume(struct oxygen *chip)
337{
338 ak4396_registers_init(chip);
339}
340
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100341static void set_ak4396_params(struct oxygen *chip,
342 struct snd_pcm_hw_params *params)
343{
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100344 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100345 unsigned int i;
346 u8 value;
347
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200348 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100349 if (params_rate(params) <= 54000)
350 value |= AK4396_DFS_NORMAL;
Clemens Ladisch236c4922008-01-28 08:32:58 +0100351 else if (params_rate(params) <= 108000)
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100352 value |= AK4396_DFS_DOUBLE;
353 else
354 value |= AK4396_DFS_QUAD;
Clemens Ladischdf91bc22008-08-29 13:08:34 +0200355
356 msleep(1); /* wait for the new MCLK to become stable */
357
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200358 if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) {
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100359 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200360 ak4396_write(chip, i, AK4396_CONTROL_1,
361 AK4396_DIF_24_MSB);
362 ak4396_write(chip, i, AK4396_CONTROL_2, value);
363 ak4396_write(chip, i, AK4396_CONTROL_1,
364 AK4396_DIF_24_MSB | AK4396_RSTN);
365 }
366 }
367}
368
369static void update_ak4396_volume(struct oxygen *chip)
370{
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100371 struct generic_data *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200372 unsigned int i;
373
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100374 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200375 ak4396_write_cached(chip, i, AK4396_LCH_ATT,
376 chip->dac_volume[i * 2]);
377 ak4396_write_cached(chip, i, AK4396_RCH_ATT,
378 chip->dac_volume[i * 2 + 1]);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100379 }
380}
381
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100382static void update_ak4396_mute(struct oxygen *chip)
383{
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100384 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100385 unsigned int i;
386 u8 value;
387
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200388 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100389 if (chip->dac_mute)
390 value |= AK4396_SMUTE;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100391 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200392 ak4396_write_cached(chip, i, AK4396_CONTROL_2, value);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100393}
394
395static void set_wm8785_params(struct oxygen *chip,
396 struct snd_pcm_hw_params *params)
397{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200398 struct generic_data *data = chip->model_data;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100399 unsigned int value;
400
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100401 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST;
Clemens Ladisch71e22a42008-01-21 08:50:51 +0100402 if (params_rate(params) <= 48000)
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100403 value |= WM8785_OSR_SINGLE;
Clemens Ladisch71e22a42008-01-21 08:50:51 +0100404 else if (params_rate(params) <= 96000)
405 value |= WM8785_OSR_DOUBLE;
406 else
407 value |= WM8785_OSR_QUAD;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200408 if (value != data->wm8785_regs[0]) {
409 wm8785_write(chip, WM8785_R7, 0);
410 wm8785_write(chip, WM8785_R0, value);
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200411 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200412 }
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100413}
414
415static void set_ak5385_params(struct oxygen *chip,
416 struct snd_pcm_hw_params *params)
417{
418 unsigned int value;
419
420 if (params_rate(params) <= 54000)
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100421 value = GPIO_AK5385_DFS_NORMAL;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100422 else if (params_rate(params) <= 108000)
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100423 value = GPIO_AK5385_DFS_DOUBLE;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100424 else
Clemens Ladisch878ac3e2008-01-21 08:50:19 +0100425 value = GPIO_AK5385_DFS_QUAD;
426 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
427 value, GPIO_AK5385_DFS_MASK);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100428}
429
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100430static void set_no_params(struct oxygen *chip, struct snd_pcm_hw_params *params)
431{
432}
433
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200434static int rolloff_info(struct snd_kcontrol *ctl,
435 struct snd_ctl_elem_info *info)
436{
437 static const char *const names[2] = {
438 "Sharp Roll-off", "Slow Roll-off"
439 };
440
Clemens Ladisch96007322011-01-10 16:25:44 +0100441 return snd_ctl_enum_info(info, 1, 2, names);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200442}
443
444static int rolloff_get(struct snd_kcontrol *ctl,
445 struct snd_ctl_elem_value *value)
446{
447 struct oxygen *chip = ctl->private_data;
448 struct generic_data *data = chip->model_data;
449
450 value->value.enumerated.item[0] =
451 (data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0;
452 return 0;
453}
454
455static int rolloff_put(struct snd_kcontrol *ctl,
456 struct snd_ctl_elem_value *value)
457{
458 struct oxygen *chip = ctl->private_data;
459 struct generic_data *data = chip->model_data;
460 unsigned int i;
461 int changed;
462 u8 reg;
463
464 mutex_lock(&chip->mutex);
465 reg = data->ak4396_regs[0][AK4396_CONTROL_2];
466 if (value->value.enumerated.item[0])
467 reg |= AK4396_SLOW;
468 else
469 reg &= ~AK4396_SLOW;
470 changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2];
471 if (changed) {
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100472 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200473 ak4396_write(chip, i, AK4396_CONTROL_2, reg);
474 }
475 mutex_unlock(&chip->mutex);
476 return changed;
477}
478
479static const struct snd_kcontrol_new rolloff_control = {
480 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
481 .name = "DAC Filter Playback Enum",
482 .info = rolloff_info,
483 .get = rolloff_get,
484 .put = rolloff_put,
485};
486
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200487static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
488{
489 static const char *const names[2] = {
490 "None", "High-pass Filter"
491 };
492
Clemens Ladisch96007322011-01-10 16:25:44 +0100493 return snd_ctl_enum_info(info, 1, 2, names);
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200494}
495
496static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
497{
498 struct oxygen *chip = ctl->private_data;
499 struct generic_data *data = chip->model_data;
500
501 value->value.enumerated.item[0] =
502 (data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0;
503 return 0;
504}
505
506static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
507{
508 struct oxygen *chip = ctl->private_data;
509 struct generic_data *data = chip->model_data;
510 unsigned int reg;
511 int changed;
512
513 mutex_lock(&chip->mutex);
514 reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL);
515 if (value->value.enumerated.item[0])
516 reg |= WM8785_HPFR | WM8785_HPFL;
517 changed = reg != data->wm8785_regs[WM8785_R2];
518 if (changed)
519 wm8785_write(chip, WM8785_R2, reg);
520 mutex_unlock(&chip->mutex);
521 return changed;
522}
523
524static const struct snd_kcontrol_new hpf_control = {
525 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
526 .name = "ADC Filter Capture Enum",
527 .info = hpf_info,
528 .get = hpf_get,
529 .put = hpf_put,
530};
531
Clemens Ladischd1d70932011-01-11 10:35:29 +0100532static int meridian_dig_source_info(struct snd_kcontrol *ctl,
533 struct snd_ctl_elem_info *info)
Clemens Ladisch64878df2011-01-10 16:35:38 +0100534{
535 static const char *const names[2] = { "On-board", "Extension" };
536
537 return snd_ctl_enum_info(info, 1, 2, names);
538}
539
Clemens Ladischd1d70932011-01-11 10:35:29 +0100540static int claro_dig_source_info(struct snd_kcontrol *ctl,
541 struct snd_ctl_elem_info *info)
542{
543 static const char *const names[2] = { "Optical", "Coaxial" };
544
545 return snd_ctl_enum_info(info, 1, 2, names);
546}
547
548static int meridian_dig_source_get(struct snd_kcontrol *ctl,
549 struct snd_ctl_elem_value *value)
Clemens Ladisch64878df2011-01-10 16:35:38 +0100550{
551 struct oxygen *chip = ctl->private_data;
552
553 value->value.enumerated.item[0] =
554 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) &
555 GPIO_MERIDIAN_DIG_EXT);
556 return 0;
557}
558
Clemens Ladischd1d70932011-01-11 10:35:29 +0100559static int claro_dig_source_get(struct snd_kcontrol *ctl,
560 struct snd_ctl_elem_value *value)
561{
562 struct oxygen *chip = ctl->private_data;
563
564 value->value.enumerated.item[0] =
565 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) &
566 GPIO_CLARO_DIG_COAX);
567 return 0;
568}
569
570static int meridian_dig_source_put(struct snd_kcontrol *ctl,
571 struct snd_ctl_elem_value *value)
Clemens Ladisch64878df2011-01-10 16:35:38 +0100572{
573 struct oxygen *chip = ctl->private_data;
574 u16 old_reg, new_reg;
575 int changed;
576
577 mutex_lock(&chip->mutex);
578 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
579 new_reg = old_reg & ~GPIO_MERIDIAN_DIG_MASK;
580 if (value->value.enumerated.item[0] == 0)
581 new_reg |= GPIO_MERIDIAN_DIG_BOARD;
582 else
583 new_reg |= GPIO_MERIDIAN_DIG_EXT;
584 changed = new_reg != old_reg;
585 if (changed)
586 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
587 mutex_unlock(&chip->mutex);
588 return changed;
589}
590
Clemens Ladischd1d70932011-01-11 10:35:29 +0100591static int claro_dig_source_put(struct snd_kcontrol *ctl,
592 struct snd_ctl_elem_value *value)
593{
594 struct oxygen *chip = ctl->private_data;
595 u16 old_reg, new_reg;
596 int changed;
597
598 mutex_lock(&chip->mutex);
599 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
600 new_reg = old_reg & ~GPIO_CLARO_DIG_COAX;
601 if (value->value.enumerated.item[0])
602 new_reg |= GPIO_CLARO_DIG_COAX;
603 changed = new_reg != old_reg;
604 if (changed)
605 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
606 mutex_unlock(&chip->mutex);
607 return changed;
608}
609
Clemens Ladisch64878df2011-01-10 16:35:38 +0100610static const struct snd_kcontrol_new meridian_dig_source_control = {
611 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
612 .name = "IEC958 Source Capture Enum",
613 .info = meridian_dig_source_info,
614 .get = meridian_dig_source_get,
615 .put = meridian_dig_source_put,
616};
617
Clemens Ladischd1d70932011-01-11 10:35:29 +0100618static const struct snd_kcontrol_new claro_dig_source_control = {
619 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
620 .name = "IEC958 Source Capture Enum",
621 .info = claro_dig_source_info,
622 .get = claro_dig_source_get,
623 .put = claro_dig_source_put,
624};
625
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200626static int generic_mixer_init(struct oxygen *chip)
627{
628 return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
629}
630
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200631static int generic_wm8785_mixer_init(struct oxygen *chip)
632{
633 int err;
634
635 err = generic_mixer_init(chip);
636 if (err < 0)
637 return err;
638 err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip));
639 if (err < 0)
640 return err;
641 return 0;
642}
643
Clemens Ladisch64878df2011-01-10 16:35:38 +0100644static int meridian_mixer_init(struct oxygen *chip)
645{
646 int err;
647
648 err = generic_mixer_init(chip);
649 if (err < 0)
650 return err;
651 err = snd_ctl_add(chip->card,
652 snd_ctl_new1(&meridian_dig_source_control, chip));
653 if (err < 0)
654 return err;
655 return 0;
656}
657
Clemens Ladischd1d70932011-01-11 10:35:29 +0100658static int claro_mixer_init(struct oxygen *chip)
659{
660 int err;
661
662 err = generic_wm8785_mixer_init(chip);
663 if (err < 0)
664 return err;
665 err = snd_ctl_add(chip->card,
666 snd_ctl_new1(&claro_dig_source_control, chip));
667 if (err < 0)
668 return err;
669 return 0;
670}
671
672static int claro_halo_mixer_init(struct oxygen *chip)
673{
674 int err;
675
676 err = generic_mixer_init(chip);
677 if (err < 0)
678 return err;
679 err = snd_ctl_add(chip->card,
680 snd_ctl_new1(&claro_dig_source_control, chip));
681 if (err < 0)
682 return err;
683 return 0;
684}
685
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100686static void dump_ak4396_registers(struct oxygen *chip,
687 struct snd_info_buffer *buffer)
688{
689 struct generic_data *data = chip->model_data;
690 unsigned int dac, i;
691
692 for (dac = 0; dac < data->dacs; ++dac) {
693 snd_iprintf(buffer, "\nAK4396 %u:", dac + 1);
694 for (i = 0; i < 5; ++i)
695 snd_iprintf(buffer, " %02x", data->ak4396_regs[dac][i]);
696 }
697 snd_iprintf(buffer, "\n");
698}
699
700static void dump_wm8785_registers(struct oxygen *chip,
701 struct snd_info_buffer *buffer)
702{
703 struct generic_data *data = chip->model_data;
704 unsigned int i;
705
706 snd_iprintf(buffer, "\nWM8785:");
707 for (i = 0; i < 3; ++i)
708 snd_iprintf(buffer, " %03x", data->wm8785_regs[i]);
709 snd_iprintf(buffer, "\n");
710}
711
712static void dump_oxygen_registers(struct oxygen *chip,
713 struct snd_info_buffer *buffer)
714{
715 dump_ak4396_registers(chip, buffer);
716 dump_wm8785_registers(chip, buffer);
717}
718
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100719static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
720
721static const struct oxygen_model model_generic = {
722 .shortname = "C-Media CMI8788",
723 .longname = "C-Media Oxygen HD Audio",
724 .chip = "CMI8788",
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100725 .init = generic_init,
Clemens Ladisch1ff04882009-09-28 11:21:51 +0200726 .mixer_init = generic_wm8785_mixer_init,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100727 .cleanup = generic_cleanup,
Clemens Ladisch4a4bc532008-05-13 09:24:39 +0200728 .resume = generic_resume,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100729 .set_dac_params = set_ak4396_params,
730 .set_adc_params = set_wm8785_params,
731 .update_dac_volume = update_ak4396_volume,
732 .update_dac_mute = update_ak4396_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100733 .dump_registers = dump_oxygen_registers,
Clemens Ladisch4972a172008-04-16 09:15:45 +0200734 .dac_tlv = ak4396_db_scale,
Clemens Ladisch7ef37cd2008-01-21 08:51:55 +0100735 .model_data_size = sizeof(struct generic_data),
Clemens Ladischd76596b2008-09-22 09:02:08 +0200736 .device_config = PLAYBACK_0_TO_I2S |
737 PLAYBACK_1_TO_SPDIF |
738 PLAYBACK_2_TO_AC97_1 |
739 CAPTURE_0_FROM_I2S_1 |
740 CAPTURE_1_FROM_SPDIF |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +0200741 CAPTURE_2_FROM_AC97_1 |
742 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +0100743 .dac_channels_pcm = 8,
744 .dac_channels_mixer = 8,
Clemens Ladisch193e8132008-04-16 09:13:36 +0200745 .dac_volume_min = 0,
746 .dac_volume_max = 255,
Clemens Ladisch87eedd22008-03-19 08:20:13 +0100747 .function_flags = OXYGEN_FUNCTION_SPI |
748 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
Clemens Ladischce2c4922011-01-10 16:16:08 +0100749 .dac_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100750 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
Clemens Ladisch05855ba2008-01-17 09:05:09 +0100751 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
752 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100753};
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100754
Clemens Ladisch30459d72009-02-19 08:42:44 +0100755static int __devinit get_oxygen_model(struct oxygen *chip,
756 const struct pci_device_id *id)
757{
Clemens Ladischa4b16962011-01-10 16:37:19 +0100758 static const char *const names[] = {
759 [MODEL_MERIDIAN] = "AuzenTech X-Meridian",
760 [MODEL_MERIDIAN_2G] = "AuzenTech X-Meridian 2G",
761 [MODEL_CLARO] = "HT-Omega Claro",
762 [MODEL_CLARO_HALO] = "HT-Omega Claro halo",
763 [MODEL_FANTASIA] = "TempoTec HiFier Fantasia",
764 [MODEL_SERENADE] = "TempoTec HiFier Serenade",
765 [MODEL_HG2PCI] = "CMI8787-HG2PCI",
766 };
767
Clemens Ladisch30459d72009-02-19 08:42:44 +0100768 chip->model = model_generic;
769 switch (id->driver_data) {
770 case MODEL_MERIDIAN:
Clemens Ladischa4b16962011-01-10 16:37:19 +0100771 case MODEL_MERIDIAN_2G:
Clemens Ladisch30459d72009-02-19 08:42:44 +0100772 chip->model.init = meridian_init;
Clemens Ladisch64878df2011-01-10 16:35:38 +0100773 chip->model.mixer_init = meridian_mixer_init;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100774 chip->model.resume = meridian_resume;
775 chip->model.set_adc_params = set_ak5385_params;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100776 chip->model.dump_registers = dump_ak4396_registers;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100777 chip->model.device_config = PLAYBACK_0_TO_I2S |
778 PLAYBACK_1_TO_SPDIF |
779 CAPTURE_0_FROM_I2S_2 |
780 CAPTURE_1_FROM_SPDIF;
Clemens Ladisch5fc51522011-01-11 10:33:40 +0100781 if (id->driver_data == MODEL_MERIDIAN)
782 chip->model.device_config |= AC97_CD_INPUT;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100783 break;
Clemens Ladisch873591d2009-03-09 09:12:55 +0100784 case MODEL_CLARO:
785 chip->model.init = claro_init;
Clemens Ladischd1d70932011-01-11 10:35:29 +0100786 chip->model.mixer_init = claro_mixer_init;
Clemens Ladisch873591d2009-03-09 09:12:55 +0100787 chip->model.cleanup = claro_cleanup;
788 chip->model.suspend = claro_suspend;
789 chip->model.resume = claro_resume;
790 break;
791 case MODEL_CLARO_HALO:
792 chip->model.init = claro_halo_init;
Clemens Ladischd1d70932011-01-11 10:35:29 +0100793 chip->model.mixer_init = claro_halo_mixer_init;
Clemens Ladisch873591d2009-03-09 09:12:55 +0100794 chip->model.cleanup = claro_cleanup;
795 chip->model.suspend = claro_suspend;
796 chip->model.resume = claro_resume;
Clemens Ladischd91b4242009-02-20 09:31:14 +0100797 chip->model.set_adc_params = set_ak5385_params;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100798 chip->model.dump_registers = dump_ak4396_registers;
Erik J. Staab0873a5a2010-09-22 11:07:41 +0200799 chip->model.device_config = PLAYBACK_0_TO_I2S |
800 PLAYBACK_1_TO_SPDIF |
801 CAPTURE_0_FROM_I2S_2 |
802 CAPTURE_1_FROM_SPDIF;
Clemens Ladischd91b4242009-02-20 09:31:14 +0100803 break;
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100804 case MODEL_FANTASIA:
Clemens Ladischa4b16962011-01-10 16:37:19 +0100805 case MODEL_SERENADE:
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100806 case MODEL_2CH_OUTPUT:
Clemens Ladischa4b16962011-01-10 16:37:19 +0100807 case MODEL_HG2PCI:
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100808 chip->model.shortname = "C-Media CMI8787";
809 chip->model.chip = "CMI8787";
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100810 if (id->driver_data == MODEL_FANTASIA)
811 chip->model.init = fantasia_init;
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100812 else
Clemens Ladisch2146dcf2010-11-03 12:26:35 +0100813 chip->model.init = stereo_output_init;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100814 chip->model.resume = stereo_resume;
815 chip->model.mixer_init = generic_mixer_init;
816 chip->model.set_adc_params = set_no_params;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100817 chip->model.dump_registers = dump_ak4396_registers;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100818 chip->model.device_config = PLAYBACK_0_TO_I2S |
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100819 PLAYBACK_1_TO_SPDIF;
Clemens Ladischce2c4922011-01-10 16:16:08 +0100820 if (id->driver_data == MODEL_FANTASIA) {
Clemens Ladisch31f86ba2010-11-02 17:18:23 +0100821 chip->model.device_config |= CAPTURE_0_FROM_I2S_1;
Clemens Ladischce2c4922011-01-10 16:16:08 +0100822 chip->model.adc_mclks = OXYGEN_MCLKS(256, 128, 128);
823 }
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +0100824 chip->model.dac_channels_pcm = 2;
825 chip->model.dac_channels_mixer = 2;
Clemens Ladisch45c1de82010-11-02 17:08:37 +0100826 break;
Clemens Ladisch66410bf2011-01-10 16:20:29 +0100827 case MODEL_XONAR_DG:
828 chip->model = model_xonar_dg;
829 break;
Clemens Ladisch30459d72009-02-19 08:42:44 +0100830 }
831 if (id->driver_data == MODEL_MERIDIAN ||
Clemens Ladisch5fc51522011-01-11 10:33:40 +0100832 id->driver_data == MODEL_MERIDIAN_2G ||
Clemens Ladisch873591d2009-03-09 09:12:55 +0100833 id->driver_data == MODEL_CLARO_HALO) {
Clemens Ladisch30459d72009-02-19 08:42:44 +0100834 chip->model.misc_flags = OXYGEN_MISC_MIDI;
835 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
836 }
Clemens Ladischa4b16962011-01-10 16:37:19 +0100837 if (id->driver_data < ARRAY_SIZE(names) && names[id->driver_data])
838 chip->model.shortname = names[id->driver_data];
Clemens Ladisch30459d72009-02-19 08:42:44 +0100839 return 0;
840}
841
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100842static int __devinit generic_oxygen_probe(struct pci_dev *pci,
843 const struct pci_device_id *pci_id)
844{
845 static int dev;
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100846 int err;
847
848 if (dev >= SNDRV_CARDS)
849 return -ENODEV;
850 if (!enable[dev]) {
851 ++dev;
852 return -ENOENT;
853 }
Clemens Ladischbb718582009-02-19 08:37:13 +0100854 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
Clemens Ladisch30459d72009-02-19 08:42:44 +0100855 oxygen_ids, get_oxygen_model);
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100856 if (err >= 0)
857 ++dev;
858 return err;
859}
860
861static struct pci_driver oxygen_driver = {
862 .name = "CMI8788",
863 .id_table = oxygen_ids,
864 .probe = generic_oxygen_probe,
865 .remove = __devexit_p(oxygen_pci_remove),
Clemens Ladisch4a4bc532008-05-13 09:24:39 +0200866#ifdef CONFIG_PM
867 .suspend = oxygen_pci_suspend,
868 .resume = oxygen_pci_resume,
869#endif
Clemens Ladischd0ce9942007-12-23 19:50:57 +0100870};
871
872static int __init alsa_card_oxygen_init(void)
873{
874 return pci_register_driver(&oxygen_driver);
875}
876
877static void __exit alsa_card_oxygen_exit(void)
878{
879 pci_unregister_driver(&oxygen_driver);
880}
881
882module_init(alsa_card_oxygen_init)
883module_exit(alsa_card_oxygen_exit)