Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1 | /* |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 2 | * C-Media CMI8788 driver for C-Media's reference design and similar models |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 3 | * |
| 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 Ladisch | dc0adf4 | 2009-09-28 11:17:36 +0200 | [diff] [blame] | 21 | * CMI8788: |
| 22 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 23 | * 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 Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 28 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 29 | * GPIO 0 -> DFS0 of AK5385 |
| 30 | * GPIO 1 -> DFS1 of AK5385 |
Clemens Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 31 | * |
| 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 Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 37 | * GPIO 6 -> S/PDIF from optical (0) or coaxial (1) input |
Clemens Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 38 | * GPIO 8 -> enable headphone amplifier |
Clemens Ladisch | dc0adf4 | 2009-09-28 11:17:36 +0200 | [diff] [blame] | 39 | * |
| 40 | * CM9780: |
| 41 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 42 | * 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 Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 49 | */ |
| 50 | |
Clemens Ladisch | df91bc2 | 2008-08-29 13:08:34 +0200 | [diff] [blame] | 51 | #include <linux/delay.h> |
Clemens Ladisch | 902b05c | 2008-02-22 18:40:56 +0100 | [diff] [blame] | 52 | #include <linux/mutex.h> |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 53 | #include <linux/pci.h> |
Clemens Ladisch | 902b05c | 2008-02-22 18:40:56 +0100 | [diff] [blame] | 54 | #include <sound/ac97_codec.h> |
Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 55 | #include <sound/control.h> |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 56 | #include <sound/core.h> |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 57 | #include <sound/info.h> |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 58 | #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 Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 63 | #include "xonar_dg.h" |
Clemens Ladisch | c626026 | 2008-01-25 08:41:52 +0100 | [diff] [blame] | 64 | #include "ak4396.h" |
Clemens Ladisch | f5b2368 | 2008-03-19 08:14:01 +0100 | [diff] [blame] | 65 | #include "wm8785.h" |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 66 | |
| 67 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
| 68 | MODULE_DESCRIPTION("C-Media CMI8788 driver"); |
Clemens Ladisch | d023dc0 | 2008-05-13 09:18:27 +0200 | [diff] [blame] | 69 | MODULE_LICENSE("GPL v2"); |
Clemens Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 70 | MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8786}" |
| 71 | ",{C-Media,CMI8787}" |
| 72 | ",{C-Media,CMI8788}}"); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 73 | |
| 74 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 75 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
| 76 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
| 77 | |
| 78 | module_param_array(index, int, NULL, 0444); |
| 79 | MODULE_PARM_DESC(index, "card index"); |
| 80 | module_param_array(id, charp, NULL, 0444); |
| 81 | MODULE_PARM_DESC(id, "ID string"); |
| 82 | module_param_array(enable, bool, NULL, 0444); |
| 83 | MODULE_PARM_DESC(enable, "enable card"); |
| 84 | |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 85 | enum { |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 86 | MODEL_CMEDIA_REF, |
| 87 | MODEL_MERIDIAN, |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 88 | MODEL_MERIDIAN_2G, |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 89 | MODEL_CLARO, |
| 90 | MODEL_CLARO_HALO, |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 91 | MODEL_FANTASIA, |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 92 | MODEL_SERENADE, |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 93 | MODEL_2CH_OUTPUT, |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 94 | MODEL_HG2PCI, |
Clemens Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 95 | MODEL_XONAR_DG, |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Alexey Dobriyan | cebe41d | 2010-02-06 00:21:03 +0200 | [diff] [blame] | 98 | static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = { |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 99 | /* C-Media's reference design */ |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 100 | { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF }, |
Clemens Ladisch | 8c50b75 | 2011-01-10 16:16:32 +0100 | [diff] [blame] | 101 | { OXYGEN_PCI_SUBID(0x10b0, 0x0217), .driver_data = MODEL_CMEDIA_REF }, |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 102 | { 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 Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 108 | { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, |
Clemens Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 109 | /* Asus Xonar DG */ |
| 110 | { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG }, |
Clemens Ladisch | 8c50b75 | 2011-01-10 16:16:32 +0100 | [diff] [blame] | 111 | /* PCI 2.0 HD Audio */ |
| 112 | { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT }, |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 113 | /* Kuroutoshikou CMI8787-HG2PCI */ |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 114 | { OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_HG2PCI }, |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 115 | /* TempoTec HiFier Fantasia */ |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 116 | { OXYGEN_PCI_SUBID(0x14c3, 0x1710), .driver_data = MODEL_FANTASIA }, |
| 117 | /* TempoTec HiFier Serenade */ |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 118 | { OXYGEN_PCI_SUBID(0x14c3, 0x1711), .driver_data = MODEL_SERENADE }, |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 119 | /* AuzenTech X-Meridian */ |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 120 | { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN }, |
Clemens Ladisch | 8443d2e | 2011-01-10 16:17:26 +0100 | [diff] [blame] | 121 | /* AuzenTech X-Meridian 2G */ |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 122 | { OXYGEN_PCI_SUBID(0x5431, 0x017a), .driver_data = MODEL_MERIDIAN_2G }, |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 123 | /* HT-Omega Claro */ |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 124 | { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO }, |
Clemens Ladisch | 18f2483 | 2010-11-03 11:36:33 +0100 | [diff] [blame] | 125 | /* HT-Omega Claro halo */ |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 126 | { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO }, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 127 | { } |
| 128 | }; |
| 129 | MODULE_DEVICE_TABLE(pci, oxygen_ids); |
| 130 | |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 131 | |
| 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 Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 137 | #define GPIO_MERIDIAN_DIG_MASK 0x0050 |
| 138 | #define GPIO_MERIDIAN_DIG_EXT 0x0010 |
| 139 | #define GPIO_MERIDIAN_DIG_BOARD 0x0040 |
| 140 | |
Clemens Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 141 | #define GPIO_CLARO_DIG_COAX 0x0040 |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 142 | #define GPIO_CLARO_HP 0x0100 |
| 143 | |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 144 | struct generic_data { |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 145 | unsigned int dacs; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 146 | u8 ak4396_regs[4][5]; |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 147 | u16 wm8785_regs[3]; |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 150 | static 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 Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 155 | 0, 1, 2, 4 |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 156 | }; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 157 | struct generic_data *data = chip->model_data; |
| 158 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 159 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 160 | OXYGEN_SPI_DATA_LENGTH_2 | |
Clemens Ladisch | 2ea8598 | 2008-01-30 08:38:30 +0100 | [diff] [blame] | 161 | OXYGEN_SPI_CLOCK_160 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 162 | (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 163 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 164 | AK4396_WRITE | (reg << 8) | value); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 165 | data->ak4396_regs[codec][reg] = value; |
| 166 | } |
| 167 | |
| 168 | static 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 Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) |
| 178 | { |
Clemens Ladisch | e58aee9 | 2008-05-13 09:20:51 +0200 | [diff] [blame] | 179 | struct generic_data *data = chip->model_data; |
| 180 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 181 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 182 | OXYGEN_SPI_DATA_LENGTH_2 | |
Clemens Ladisch | 2ea8598 | 2008-01-30 08:38:30 +0100 | [diff] [blame] | 183 | OXYGEN_SPI_CLOCK_160 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 184 | (3 << OXYGEN_SPI_CODEC_SHIFT) | |
| 185 | OXYGEN_SPI_CEN_LATCH_CLOCK_LO, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 186 | (reg << 9) | value); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 187 | if (reg < ARRAY_SIZE(data->wm8785_regs)) |
| 188 | data->wm8785_regs[reg] = value; |
Clemens Ladisch | bbbfb55 | 2008-05-13 09:21:48 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 191 | static void ak4396_registers_init(struct oxygen *chip) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 192 | { |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 193 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 194 | unsigned int i; |
| 195 | |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 196 | for (i = 0; i < data->dacs; ++i) { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 197 | 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 Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 207 | } |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void ak4396_init(struct oxygen *chip) |
| 211 | { |
| 212 | struct generic_data *data = chip->model_data; |
| 213 | |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 214 | data->dacs = chip->model.dac_channels_pcm / 2; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 215 | data->ak4396_regs[0][AK4396_CONTROL_2] = |
| 216 | AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 217 | ak4396_registers_init(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 218 | snd_component_add(chip->card, "AK4396"); |
| 219 | } |
| 220 | |
| 221 | static void ak5385_init(struct oxygen *chip) |
| 222 | { |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 223 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_AK5385_DFS_MASK); |
| 224 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_AK5385_DFS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 225 | snd_component_add(chip->card, "AK5385"); |
| 226 | } |
| 227 | |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 228 | static 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 Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 233 | wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]); |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 234 | wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]); |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 235 | } |
| 236 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 237 | static void wm8785_init(struct oxygen *chip) |
| 238 | { |
Clemens Ladisch | e58aee9 | 2008-05-13 09:20:51 +0200 | [diff] [blame] | 239 | struct generic_data *data = chip->model_data; |
| 240 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 241 | data->wm8785_regs[0] = |
| 242 | WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST; |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 243 | data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL; |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 244 | wm8785_registers_init(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 245 | snd_component_add(chip->card, "WM8785"); |
| 246 | } |
| 247 | |
| 248 | static void generic_init(struct oxygen *chip) |
| 249 | { |
| 250 | ak4396_init(chip); |
| 251 | wm8785_init(chip); |
| 252 | } |
| 253 | |
| 254 | static void meridian_init(struct oxygen *chip) |
| 255 | { |
Clemens Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 256 | 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 Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 260 | ak4396_init(chip); |
| 261 | ak5385_init(chip); |
| 262 | } |
| 263 | |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 264 | static 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 | |
| 271 | static void claro_init(struct oxygen *chip) |
| 272 | { |
Clemens Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 273 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX); |
| 274 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX); |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 275 | ak4396_init(chip); |
| 276 | wm8785_init(chip); |
| 277 | claro_enable_hp(chip); |
| 278 | } |
| 279 | |
| 280 | static void claro_halo_init(struct oxygen *chip) |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 281 | { |
Clemens Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 282 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_DIG_COAX); |
| 283 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_DIG_COAX); |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 284 | ak4396_init(chip); |
| 285 | ak5385_init(chip); |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 286 | claro_enable_hp(chip); |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 289 | static void fantasia_init(struct oxygen *chip) |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 290 | { |
| 291 | ak4396_init(chip); |
| 292 | snd_component_add(chip->card, "CS5340"); |
| 293 | } |
| 294 | |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 295 | static void stereo_output_init(struct oxygen *chip) |
Clemens Ladisch | 31f86ba | 2010-11-02 17:18:23 +0100 | [diff] [blame] | 296 | { |
| 297 | ak4396_init(chip); |
| 298 | } |
| 299 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 300 | static void generic_cleanup(struct oxygen *chip) |
| 301 | { |
| 302 | } |
| 303 | |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 304 | static void claro_disable_hp(struct oxygen *chip) |
| 305 | { |
| 306 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP); |
| 307 | } |
| 308 | |
| 309 | static void claro_cleanup(struct oxygen *chip) |
| 310 | { |
| 311 | claro_disable_hp(chip); |
| 312 | } |
| 313 | |
| 314 | static void claro_suspend(struct oxygen *chip) |
| 315 | { |
| 316 | claro_disable_hp(chip); |
| 317 | } |
| 318 | |
Clemens Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 319 | static void generic_resume(struct oxygen *chip) |
| 320 | { |
| 321 | ak4396_registers_init(chip); |
| 322 | wm8785_registers_init(chip); |
| 323 | } |
| 324 | |
Clemens Ladisch | c2bc4ff | 2008-09-22 09:05:29 +0200 | [diff] [blame] | 325 | static void meridian_resume(struct oxygen *chip) |
| 326 | { |
| 327 | ak4396_registers_init(chip); |
| 328 | } |
| 329 | |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 330 | static void claro_resume(struct oxygen *chip) |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 331 | { |
| 332 | ak4396_registers_init(chip); |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 333 | claro_enable_hp(chip); |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 336 | static void stereo_resume(struct oxygen *chip) |
| 337 | { |
| 338 | ak4396_registers_init(chip); |
| 339 | } |
| 340 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 341 | static void set_ak4396_params(struct oxygen *chip, |
| 342 | struct snd_pcm_hw_params *params) |
| 343 | { |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 344 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 345 | unsigned int i; |
| 346 | u8 value; |
| 347 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 348 | value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 349 | if (params_rate(params) <= 54000) |
| 350 | value |= AK4396_DFS_NORMAL; |
Clemens Ladisch | 236c492 | 2008-01-28 08:32:58 +0100 | [diff] [blame] | 351 | else if (params_rate(params) <= 108000) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 352 | value |= AK4396_DFS_DOUBLE; |
| 353 | else |
| 354 | value |= AK4396_DFS_QUAD; |
Clemens Ladisch | df91bc2 | 2008-08-29 13:08:34 +0200 | [diff] [blame] | 355 | |
| 356 | msleep(1); /* wait for the new MCLK to become stable */ |
| 357 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 358 | if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) { |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 359 | for (i = 0; i < data->dacs; ++i) { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 360 | 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 | |
| 369 | static void update_ak4396_volume(struct oxygen *chip) |
| 370 | { |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 371 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 372 | unsigned int i; |
| 373 | |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 374 | for (i = 0; i < data->dacs; ++i) { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 375 | 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 Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 382 | static void update_ak4396_mute(struct oxygen *chip) |
| 383 | { |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 384 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 385 | unsigned int i; |
| 386 | u8 value; |
| 387 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 388 | value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 389 | if (chip->dac_mute) |
| 390 | value |= AK4396_SMUTE; |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 391 | for (i = 0; i < data->dacs; ++i) |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 392 | ak4396_write_cached(chip, i, AK4396_CONTROL_2, value); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static void set_wm8785_params(struct oxygen *chip, |
| 396 | struct snd_pcm_hw_params *params) |
| 397 | { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 398 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 399 | unsigned int value; |
| 400 | |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 401 | value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST; |
Clemens Ladisch | 71e22a4 | 2008-01-21 08:50:51 +0100 | [diff] [blame] | 402 | if (params_rate(params) <= 48000) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 403 | value |= WM8785_OSR_SINGLE; |
Clemens Ladisch | 71e22a4 | 2008-01-21 08:50:51 +0100 | [diff] [blame] | 404 | else if (params_rate(params) <= 96000) |
| 405 | value |= WM8785_OSR_DOUBLE; |
| 406 | else |
| 407 | value |= WM8785_OSR_QUAD; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 408 | if (value != data->wm8785_regs[0]) { |
| 409 | wm8785_write(chip, WM8785_R7, 0); |
| 410 | wm8785_write(chip, WM8785_R0, value); |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 411 | wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 412 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static 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 Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 421 | value = GPIO_AK5385_DFS_NORMAL; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 422 | else if (params_rate(params) <= 108000) |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 423 | value = GPIO_AK5385_DFS_DOUBLE; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 424 | else |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 425 | value = GPIO_AK5385_DFS_QUAD; |
| 426 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, |
| 427 | value, GPIO_AK5385_DFS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 428 | } |
| 429 | |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 430 | static void set_no_params(struct oxygen *chip, struct snd_pcm_hw_params *params) |
| 431 | { |
| 432 | } |
| 433 | |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 434 | static 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 Ladisch | 9600732 | 2011-01-10 16:25:44 +0100 | [diff] [blame] | 441 | return snd_ctl_enum_info(info, 1, 2, names); |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static 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 | |
| 455 | static 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 Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 472 | for (i = 0; i < data->dacs; ++i) |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 473 | ak4396_write(chip, i, AK4396_CONTROL_2, reg); |
| 474 | } |
| 475 | mutex_unlock(&chip->mutex); |
| 476 | return changed; |
| 477 | } |
| 478 | |
| 479 | static 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 Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 487 | static 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 Ladisch | 9600732 | 2011-01-10 16:25:44 +0100 | [diff] [blame] | 493 | return snd_ctl_enum_info(info, 1, 2, names); |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static 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 | |
| 506 | static 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 | |
| 524 | static 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 Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 532 | static int meridian_dig_source_info(struct snd_kcontrol *ctl, |
| 533 | struct snd_ctl_elem_info *info) |
Clemens Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 534 | { |
| 535 | static const char *const names[2] = { "On-board", "Extension" }; |
| 536 | |
| 537 | return snd_ctl_enum_info(info, 1, 2, names); |
| 538 | } |
| 539 | |
Clemens Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 540 | static 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 | |
| 548 | static int meridian_dig_source_get(struct snd_kcontrol *ctl, |
| 549 | struct snd_ctl_elem_value *value) |
Clemens Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 550 | { |
| 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 Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 559 | static 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 | |
| 570 | static int meridian_dig_source_put(struct snd_kcontrol *ctl, |
| 571 | struct snd_ctl_elem_value *value) |
Clemens Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 572 | { |
| 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 Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 591 | static 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 Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 610 | static 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 Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 618 | static 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 Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 626 | static int generic_mixer_init(struct oxygen *chip) |
| 627 | { |
| 628 | return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); |
| 629 | } |
| 630 | |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 631 | static 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 Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 644 | static 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 Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 658 | static 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 | |
| 672 | static 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 Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 686 | static 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 | |
| 700 | static 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 | |
| 712 | static 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 Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 719 | static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); |
| 720 | |
| 721 | static const struct oxygen_model model_generic = { |
| 722 | .shortname = "C-Media CMI8788", |
| 723 | .longname = "C-Media Oxygen HD Audio", |
| 724 | .chip = "CMI8788", |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 725 | .init = generic_init, |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 726 | .mixer_init = generic_wm8785_mixer_init, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 727 | .cleanup = generic_cleanup, |
Clemens Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 728 | .resume = generic_resume, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 729 | .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 Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 733 | .dump_registers = dump_oxygen_registers, |
Clemens Ladisch | 4972a17 | 2008-04-16 09:15:45 +0200 | [diff] [blame] | 734 | .dac_tlv = ak4396_db_scale, |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 735 | .model_data_size = sizeof(struct generic_data), |
Clemens Ladisch | d76596b | 2008-09-22 09:02:08 +0200 | [diff] [blame] | 736 | .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 Ladisch | b6ca8ab | 2010-10-04 13:21:52 +0200 | [diff] [blame] | 741 | CAPTURE_2_FROM_AC97_1 | |
| 742 | AC97_CD_INPUT, |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 743 | .dac_channels_pcm = 8, |
| 744 | .dac_channels_mixer = 8, |
Clemens Ladisch | 193e813 | 2008-04-16 09:13:36 +0200 | [diff] [blame] | 745 | .dac_volume_min = 0, |
| 746 | .dac_volume_max = 255, |
Clemens Ladisch | 87eedd2 | 2008-03-19 08:20:13 +0100 | [diff] [blame] | 747 | .function_flags = OXYGEN_FUNCTION_SPI | |
| 748 | OXYGEN_FUNCTION_ENABLE_SPI_4_5, |
Clemens Ladisch | ce2c492 | 2011-01-10 16:16:08 +0100 | [diff] [blame] | 749 | .dac_mclks = OXYGEN_MCLKS(256, 128, 128), |
Clemens Ladisch | 5b8bf2a | 2011-01-10 16:14:52 +0100 | [diff] [blame] | 750 | .adc_mclks = OXYGEN_MCLKS(256, 256, 128), |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 751 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 752 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 753 | }; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 754 | |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 755 | static int __devinit get_oxygen_model(struct oxygen *chip, |
| 756 | const struct pci_device_id *id) |
| 757 | { |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 758 | 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 Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 768 | chip->model = model_generic; |
| 769 | switch (id->driver_data) { |
| 770 | case MODEL_MERIDIAN: |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 771 | case MODEL_MERIDIAN_2G: |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 772 | chip->model.init = meridian_init; |
Clemens Ladisch | 64878df | 2011-01-10 16:35:38 +0100 | [diff] [blame] | 773 | chip->model.mixer_init = meridian_mixer_init; |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 774 | chip->model.resume = meridian_resume; |
| 775 | chip->model.set_adc_params = set_ak5385_params; |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 776 | chip->model.dump_registers = dump_ak4396_registers; |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 777 | 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 Ladisch | 5fc5152 | 2011-01-11 10:33:40 +0100 | [diff] [blame] | 781 | if (id->driver_data == MODEL_MERIDIAN) |
| 782 | chip->model.device_config |= AC97_CD_INPUT; |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 783 | break; |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 784 | case MODEL_CLARO: |
| 785 | chip->model.init = claro_init; |
Clemens Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 786 | chip->model.mixer_init = claro_mixer_init; |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 787 | 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 Ladisch | d1d7093 | 2011-01-11 10:35:29 +0100 | [diff] [blame] | 793 | chip->model.mixer_init = claro_halo_mixer_init; |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 794 | chip->model.cleanup = claro_cleanup; |
| 795 | chip->model.suspend = claro_suspend; |
| 796 | chip->model.resume = claro_resume; |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 797 | chip->model.set_adc_params = set_ak5385_params; |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 798 | chip->model.dump_registers = dump_ak4396_registers; |
Erik J. Staab | 0873a5a | 2010-09-22 11:07:41 +0200 | [diff] [blame] | 799 | 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 Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 803 | break; |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 804 | case MODEL_FANTASIA: |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 805 | case MODEL_SERENADE: |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 806 | case MODEL_2CH_OUTPUT: |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 807 | case MODEL_HG2PCI: |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 808 | chip->model.shortname = "C-Media CMI8787"; |
| 809 | chip->model.chip = "CMI8787"; |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 810 | if (id->driver_data == MODEL_FANTASIA) |
| 811 | chip->model.init = fantasia_init; |
Clemens Ladisch | 31f86ba | 2010-11-02 17:18:23 +0100 | [diff] [blame] | 812 | else |
Clemens Ladisch | 2146dcf | 2010-11-03 12:26:35 +0100 | [diff] [blame] | 813 | chip->model.init = stereo_output_init; |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 814 | chip->model.resume = stereo_resume; |
| 815 | chip->model.mixer_init = generic_mixer_init; |
| 816 | chip->model.set_adc_params = set_no_params; |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 817 | chip->model.dump_registers = dump_ak4396_registers; |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 818 | chip->model.device_config = PLAYBACK_0_TO_I2S | |
Clemens Ladisch | 31f86ba | 2010-11-02 17:18:23 +0100 | [diff] [blame] | 819 | PLAYBACK_1_TO_SPDIF; |
Clemens Ladisch | ce2c492 | 2011-01-10 16:16:08 +0100 | [diff] [blame] | 820 | if (id->driver_data == MODEL_FANTASIA) { |
Clemens Ladisch | 31f86ba | 2010-11-02 17:18:23 +0100 | [diff] [blame] | 821 | chip->model.device_config |= CAPTURE_0_FROM_I2S_1; |
Clemens Ladisch | ce2c492 | 2011-01-10 16:16:08 +0100 | [diff] [blame] | 822 | chip->model.adc_mclks = OXYGEN_MCLKS(256, 128, 128); |
| 823 | } |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame] | 824 | chip->model.dac_channels_pcm = 2; |
| 825 | chip->model.dac_channels_mixer = 2; |
Clemens Ladisch | 45c1de8 | 2010-11-02 17:08:37 +0100 | [diff] [blame] | 826 | break; |
Clemens Ladisch | 66410bf | 2011-01-10 16:20:29 +0100 | [diff] [blame] | 827 | case MODEL_XONAR_DG: |
| 828 | chip->model = model_xonar_dg; |
| 829 | break; |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 830 | } |
| 831 | if (id->driver_data == MODEL_MERIDIAN || |
Clemens Ladisch | 5fc5152 | 2011-01-11 10:33:40 +0100 | [diff] [blame] | 832 | id->driver_data == MODEL_MERIDIAN_2G || |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 833 | id->driver_data == MODEL_CLARO_HALO) { |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 834 | chip->model.misc_flags = OXYGEN_MISC_MIDI; |
| 835 | chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT; |
| 836 | } |
Clemens Ladisch | a4b1696 | 2011-01-10 16:37:19 +0100 | [diff] [blame] | 837 | if (id->driver_data < ARRAY_SIZE(names) && names[id->driver_data]) |
| 838 | chip->model.shortname = names[id->driver_data]; |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 839 | return 0; |
| 840 | } |
| 841 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 842 | static int __devinit generic_oxygen_probe(struct pci_dev *pci, |
| 843 | const struct pci_device_id *pci_id) |
| 844 | { |
| 845 | static int dev; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 846 | int err; |
| 847 | |
| 848 | if (dev >= SNDRV_CARDS) |
| 849 | return -ENODEV; |
| 850 | if (!enable[dev]) { |
| 851 | ++dev; |
| 852 | return -ENOENT; |
| 853 | } |
Clemens Ladisch | bb71858 | 2009-02-19 08:37:13 +0100 | [diff] [blame] | 854 | err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE, |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 855 | oxygen_ids, get_oxygen_model); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 856 | if (err >= 0) |
| 857 | ++dev; |
| 858 | return err; |
| 859 | } |
| 860 | |
| 861 | static 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 Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 866 | #ifdef CONFIG_PM |
| 867 | .suspend = oxygen_pci_suspend, |
| 868 | .resume = oxygen_pci_resume, |
| 869 | #endif |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 870 | }; |
| 871 | |
| 872 | static int __init alsa_card_oxygen_init(void) |
| 873 | { |
| 874 | return pci_register_driver(&oxygen_driver); |
| 875 | } |
| 876 | |
| 877 | static void __exit alsa_card_oxygen_exit(void) |
| 878 | { |
| 879 | pci_unregister_driver(&oxygen_driver); |
| 880 | } |
| 881 | |
| 882 | module_init(alsa_card_oxygen_init) |
| 883 | module_exit(alsa_card_oxygen_exit) |