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 | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 23 | * SPI 0 -> 1st AK4396 (front) |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 24 | * SPI 1 -> 2nd AK4396 (surround) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 25 | * SPI 2 -> 3rd AK4396 (center/LFE) |
| 26 | * SPI 3 -> WM8785 |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 27 | * SPI 4 -> 4th AK4396 (back) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 28 | * |
| 29 | * GPIO 0 -> DFS0 of AK5385 |
| 30 | * GPIO 1 -> DFS1 of AK5385 |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 31 | * GPIO 8 -> enable headphone amplifier on HT-Omega models |
Clemens Ladisch | dc0adf4 | 2009-09-28 11:17:36 +0200 | [diff] [blame] | 32 | * |
| 33 | * CM9780: |
| 34 | * |
| 35 | * 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] | 36 | */ |
| 37 | |
Clemens Ladisch | df91bc2 | 2008-08-29 13:08:34 +0200 | [diff] [blame] | 38 | #include <linux/delay.h> |
Clemens Ladisch | 902b05c | 2008-02-22 18:40:56 +0100 | [diff] [blame] | 39 | #include <linux/mutex.h> |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 40 | #include <linux/pci.h> |
Clemens Ladisch | 902b05c | 2008-02-22 18:40:56 +0100 | [diff] [blame] | 41 | #include <sound/ac97_codec.h> |
Clemens Ladisch | ccc80fb | 2008-01-16 08:32:08 +0100 | [diff] [blame] | 42 | #include <sound/control.h> |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 43 | #include <sound/core.h> |
| 44 | #include <sound/initval.h> |
| 45 | #include <sound/pcm.h> |
| 46 | #include <sound/pcm_params.h> |
| 47 | #include <sound/tlv.h> |
| 48 | #include "oxygen.h" |
Clemens Ladisch | c626026 | 2008-01-25 08:41:52 +0100 | [diff] [blame] | 49 | #include "ak4396.h" |
Clemens Ladisch | f5b2368 | 2008-03-19 08:14:01 +0100 | [diff] [blame] | 50 | #include "wm8785.h" |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 51 | |
| 52 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
| 53 | MODULE_DESCRIPTION("C-Media CMI8788 driver"); |
Clemens Ladisch | d023dc0 | 2008-05-13 09:18:27 +0200 | [diff] [blame] | 54 | MODULE_LICENSE("GPL v2"); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 55 | MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8788}}"); |
| 56 | |
| 57 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 58 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
| 59 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
| 60 | |
| 61 | module_param_array(index, int, NULL, 0444); |
| 62 | MODULE_PARM_DESC(index, "card index"); |
| 63 | module_param_array(id, charp, NULL, 0444); |
| 64 | MODULE_PARM_DESC(id, "ID string"); |
| 65 | module_param_array(enable, bool, NULL, 0444); |
| 66 | MODULE_PARM_DESC(enable, "enable card"); |
| 67 | |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 68 | enum { |
| 69 | MODEL_CMEDIA_REF, /* C-Media's reference design */ |
| 70 | MODEL_MERIDIAN, /* AuzenTech X-Meridian */ |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 71 | MODEL_CLARO, /* HT-Omega Claro */ |
| 72 | MODEL_CLARO_HALO, /* HT-Omega Claro halo */ |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 75 | static struct pci_device_id oxygen_ids[] __devinitdata = { |
Clemens Ladisch | 2f1b0ec | 2008-09-22 08:57:24 +0200 | [diff] [blame] | 76 | { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF }, |
| 77 | { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF }, |
| 78 | { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF }, |
| 79 | { OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF }, |
| 80 | { OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF }, |
| 81 | { OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF }, |
| 82 | { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF }, |
| 83 | { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, |
| 84 | { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN }, |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 85 | { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO }, |
| 86 | { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO }, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 87 | { } |
| 88 | }; |
| 89 | MODULE_DEVICE_TABLE(pci, oxygen_ids); |
| 90 | |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 91 | |
| 92 | #define GPIO_AK5385_DFS_MASK 0x0003 |
| 93 | #define GPIO_AK5385_DFS_NORMAL 0x0000 |
| 94 | #define GPIO_AK5385_DFS_DOUBLE 0x0001 |
| 95 | #define GPIO_AK5385_DFS_QUAD 0x0002 |
| 96 | |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 97 | #define GPIO_CLARO_HP 0x0100 |
| 98 | |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 99 | struct generic_data { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 100 | u8 ak4396_regs[4][5]; |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 101 | u16 wm8785_regs[3]; |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 104 | static void ak4396_write(struct oxygen *chip, unsigned int codec, |
| 105 | u8 reg, u8 value) |
| 106 | { |
| 107 | /* maps ALSA channel pair number to SPI output */ |
| 108 | static const u8 codec_spi_map[4] = { |
Clemens Ladisch | 7113e95 | 2008-01-14 08:55:03 +0100 | [diff] [blame] | 109 | 0, 1, 2, 4 |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 110 | }; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 111 | struct generic_data *data = chip->model_data; |
| 112 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 113 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 114 | OXYGEN_SPI_DATA_LENGTH_2 | |
Clemens Ladisch | 2ea8598 | 2008-01-30 08:38:30 +0100 | [diff] [blame] | 115 | OXYGEN_SPI_CLOCK_160 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 116 | (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 117 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 118 | AK4396_WRITE | (reg << 8) | value); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 119 | data->ak4396_regs[codec][reg] = value; |
| 120 | } |
| 121 | |
| 122 | static void ak4396_write_cached(struct oxygen *chip, unsigned int codec, |
| 123 | u8 reg, u8 value) |
| 124 | { |
| 125 | struct generic_data *data = chip->model_data; |
| 126 | |
| 127 | if (value != data->ak4396_regs[codec][reg]) |
| 128 | ak4396_write(chip, codec, reg, value); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) |
| 132 | { |
Clemens Ladisch | e58aee9 | 2008-05-13 09:20:51 +0200 | [diff] [blame] | 133 | struct generic_data *data = chip->model_data; |
| 134 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 135 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 136 | OXYGEN_SPI_DATA_LENGTH_2 | |
Clemens Ladisch | 2ea8598 | 2008-01-30 08:38:30 +0100 | [diff] [blame] | 137 | OXYGEN_SPI_CLOCK_160 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 138 | (3 << OXYGEN_SPI_CODEC_SHIFT) | |
| 139 | OXYGEN_SPI_CEN_LATCH_CLOCK_LO, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 140 | (reg << 9) | value); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 141 | if (reg < ARRAY_SIZE(data->wm8785_regs)) |
| 142 | data->wm8785_regs[reg] = value; |
Clemens Ladisch | bbbfb55 | 2008-05-13 09:21:48 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 145 | static void ak4396_registers_init(struct oxygen *chip) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 146 | { |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 147 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 148 | unsigned int i; |
| 149 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 150 | for (i = 0; i < 4; ++i) { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 151 | ak4396_write(chip, i, AK4396_CONTROL_1, |
| 152 | AK4396_DIF_24_MSB | AK4396_RSTN); |
| 153 | ak4396_write(chip, i, AK4396_CONTROL_2, |
| 154 | data->ak4396_regs[0][AK4396_CONTROL_2]); |
| 155 | ak4396_write(chip, i, AK4396_CONTROL_3, |
| 156 | AK4396_PCM); |
| 157 | ak4396_write(chip, i, AK4396_LCH_ATT, |
| 158 | chip->dac_volume[i * 2]); |
| 159 | ak4396_write(chip, i, AK4396_RCH_ATT, |
| 160 | chip->dac_volume[i * 2 + 1]); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 161 | } |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static void ak4396_init(struct oxygen *chip) |
| 165 | { |
| 166 | struct generic_data *data = chip->model_data; |
| 167 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 168 | data->ak4396_regs[0][AK4396_CONTROL_2] = |
| 169 | AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 170 | ak4396_registers_init(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 171 | snd_component_add(chip->card, "AK4396"); |
| 172 | } |
| 173 | |
| 174 | static void ak5385_init(struct oxygen *chip) |
| 175 | { |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 176 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_AK5385_DFS_MASK); |
| 177 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_AK5385_DFS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 178 | snd_component_add(chip->card, "AK5385"); |
| 179 | } |
| 180 | |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 181 | static void wm8785_registers_init(struct oxygen *chip) |
| 182 | { |
| 183 | struct generic_data *data = chip->model_data; |
| 184 | |
| 185 | wm8785_write(chip, WM8785_R7, 0); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 186 | wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]); |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 187 | wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]); |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 190 | static void wm8785_init(struct oxygen *chip) |
| 191 | { |
Clemens Ladisch | e58aee9 | 2008-05-13 09:20:51 +0200 | [diff] [blame] | 192 | struct generic_data *data = chip->model_data; |
| 193 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 194 | data->wm8785_regs[0] = |
| 195 | WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST; |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 196 | data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL; |
Clemens Ladisch | 75146fc | 2008-05-13 09:22:43 +0200 | [diff] [blame] | 197 | wm8785_registers_init(chip); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 198 | snd_component_add(chip->card, "WM8785"); |
| 199 | } |
| 200 | |
| 201 | static void generic_init(struct oxygen *chip) |
| 202 | { |
| 203 | ak4396_init(chip); |
| 204 | wm8785_init(chip); |
| 205 | } |
| 206 | |
| 207 | static void meridian_init(struct oxygen *chip) |
| 208 | { |
| 209 | ak4396_init(chip); |
| 210 | ak5385_init(chip); |
| 211 | } |
| 212 | |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 213 | static void claro_enable_hp(struct oxygen *chip) |
| 214 | { |
| 215 | msleep(300); |
| 216 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_HP); |
| 217 | oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP); |
| 218 | } |
| 219 | |
| 220 | static void claro_init(struct oxygen *chip) |
| 221 | { |
| 222 | ak4396_init(chip); |
| 223 | wm8785_init(chip); |
| 224 | claro_enable_hp(chip); |
| 225 | } |
| 226 | |
| 227 | static void claro_halo_init(struct oxygen *chip) |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 228 | { |
| 229 | ak4396_init(chip); |
| 230 | ak5385_init(chip); |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 231 | claro_enable_hp(chip); |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 234 | static void generic_cleanup(struct oxygen *chip) |
| 235 | { |
| 236 | } |
| 237 | |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 238 | static void claro_disable_hp(struct oxygen *chip) |
| 239 | { |
| 240 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP); |
| 241 | } |
| 242 | |
| 243 | static void claro_cleanup(struct oxygen *chip) |
| 244 | { |
| 245 | claro_disable_hp(chip); |
| 246 | } |
| 247 | |
| 248 | static void claro_suspend(struct oxygen *chip) |
| 249 | { |
| 250 | claro_disable_hp(chip); |
| 251 | } |
| 252 | |
Clemens Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 253 | static void generic_resume(struct oxygen *chip) |
| 254 | { |
| 255 | ak4396_registers_init(chip); |
| 256 | wm8785_registers_init(chip); |
| 257 | } |
| 258 | |
Clemens Ladisch | c2bc4ff | 2008-09-22 09:05:29 +0200 | [diff] [blame] | 259 | static void meridian_resume(struct oxygen *chip) |
| 260 | { |
| 261 | ak4396_registers_init(chip); |
| 262 | } |
| 263 | |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 264 | static void claro_resume(struct oxygen *chip) |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 265 | { |
| 266 | ak4396_registers_init(chip); |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 267 | claro_enable_hp(chip); |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 270 | static void set_ak4396_params(struct oxygen *chip, |
| 271 | struct snd_pcm_hw_params *params) |
| 272 | { |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 273 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 274 | unsigned int i; |
| 275 | u8 value; |
| 276 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 277 | value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 278 | if (params_rate(params) <= 54000) |
| 279 | value |= AK4396_DFS_NORMAL; |
Clemens Ladisch | 236c492 | 2008-01-28 08:32:58 +0100 | [diff] [blame] | 280 | else if (params_rate(params) <= 108000) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 281 | value |= AK4396_DFS_DOUBLE; |
| 282 | else |
| 283 | value |= AK4396_DFS_QUAD; |
Clemens Ladisch | df91bc2 | 2008-08-29 13:08:34 +0200 | [diff] [blame] | 284 | |
| 285 | msleep(1); /* wait for the new MCLK to become stable */ |
| 286 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 287 | if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) { |
| 288 | for (i = 0; i < 4; ++i) { |
| 289 | ak4396_write(chip, i, AK4396_CONTROL_1, |
| 290 | AK4396_DIF_24_MSB); |
| 291 | ak4396_write(chip, i, AK4396_CONTROL_2, value); |
| 292 | ak4396_write(chip, i, AK4396_CONTROL_1, |
| 293 | AK4396_DIF_24_MSB | AK4396_RSTN); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | static void update_ak4396_volume(struct oxygen *chip) |
| 299 | { |
| 300 | unsigned int i; |
| 301 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 302 | for (i = 0; i < 4; ++i) { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 303 | ak4396_write_cached(chip, i, AK4396_LCH_ATT, |
| 304 | chip->dac_volume[i * 2]); |
| 305 | ak4396_write_cached(chip, i, AK4396_RCH_ATT, |
| 306 | chip->dac_volume[i * 2 + 1]); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 310 | static void update_ak4396_mute(struct oxygen *chip) |
| 311 | { |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 312 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 313 | unsigned int i; |
| 314 | u8 value; |
| 315 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 316 | value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 317 | if (chip->dac_mute) |
| 318 | value |= AK4396_SMUTE; |
| 319 | for (i = 0; i < 4; ++i) |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 320 | ak4396_write_cached(chip, i, AK4396_CONTROL_2, value); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void set_wm8785_params(struct oxygen *chip, |
| 324 | struct snd_pcm_hw_params *params) |
| 325 | { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 326 | struct generic_data *data = chip->model_data; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 327 | unsigned int value; |
| 328 | |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 329 | value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST; |
Clemens Ladisch | 71e22a4 | 2008-01-21 08:50:51 +0100 | [diff] [blame] | 330 | if (params_rate(params) <= 48000) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 331 | value |= WM8785_OSR_SINGLE; |
Clemens Ladisch | 71e22a4 | 2008-01-21 08:50:51 +0100 | [diff] [blame] | 332 | else if (params_rate(params) <= 96000) |
| 333 | value |= WM8785_OSR_DOUBLE; |
| 334 | else |
| 335 | value |= WM8785_OSR_QUAD; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 336 | if (value != data->wm8785_regs[0]) { |
| 337 | wm8785_write(chip, WM8785_R7, 0); |
| 338 | wm8785_write(chip, WM8785_R0, value); |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 339 | wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 340 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static void set_ak5385_params(struct oxygen *chip, |
| 344 | struct snd_pcm_hw_params *params) |
| 345 | { |
| 346 | unsigned int value; |
| 347 | |
| 348 | if (params_rate(params) <= 54000) |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 349 | value = GPIO_AK5385_DFS_NORMAL; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 350 | else if (params_rate(params) <= 108000) |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 351 | value = GPIO_AK5385_DFS_DOUBLE; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 352 | else |
Clemens Ladisch | 878ac3e | 2008-01-21 08:50:19 +0100 | [diff] [blame] | 353 | value = GPIO_AK5385_DFS_QUAD; |
| 354 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, |
| 355 | value, GPIO_AK5385_DFS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 356 | } |
| 357 | |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 358 | static int rolloff_info(struct snd_kcontrol *ctl, |
| 359 | struct snd_ctl_elem_info *info) |
| 360 | { |
| 361 | static const char *const names[2] = { |
| 362 | "Sharp Roll-off", "Slow Roll-off" |
| 363 | }; |
| 364 | |
| 365 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 366 | info->count = 1; |
| 367 | info->value.enumerated.items = 2; |
| 368 | if (info->value.enumerated.item >= 2) |
| 369 | info->value.enumerated.item = 1; |
| 370 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static int rolloff_get(struct snd_kcontrol *ctl, |
| 375 | struct snd_ctl_elem_value *value) |
| 376 | { |
| 377 | struct oxygen *chip = ctl->private_data; |
| 378 | struct generic_data *data = chip->model_data; |
| 379 | |
| 380 | value->value.enumerated.item[0] = |
| 381 | (data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0; |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static int rolloff_put(struct snd_kcontrol *ctl, |
| 386 | struct snd_ctl_elem_value *value) |
| 387 | { |
| 388 | struct oxygen *chip = ctl->private_data; |
| 389 | struct generic_data *data = chip->model_data; |
| 390 | unsigned int i; |
| 391 | int changed; |
| 392 | u8 reg; |
| 393 | |
| 394 | mutex_lock(&chip->mutex); |
| 395 | reg = data->ak4396_regs[0][AK4396_CONTROL_2]; |
| 396 | if (value->value.enumerated.item[0]) |
| 397 | reg |= AK4396_SLOW; |
| 398 | else |
| 399 | reg &= ~AK4396_SLOW; |
| 400 | changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2]; |
| 401 | if (changed) { |
| 402 | for (i = 0; i < 4; ++i) |
| 403 | ak4396_write(chip, i, AK4396_CONTROL_2, reg); |
| 404 | } |
| 405 | mutex_unlock(&chip->mutex); |
| 406 | return changed; |
| 407 | } |
| 408 | |
| 409 | static const struct snd_kcontrol_new rolloff_control = { |
| 410 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 411 | .name = "DAC Filter Playback Enum", |
| 412 | .info = rolloff_info, |
| 413 | .get = rolloff_get, |
| 414 | .put = rolloff_put, |
| 415 | }; |
| 416 | |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 417 | static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) |
| 418 | { |
| 419 | static const char *const names[2] = { |
| 420 | "None", "High-pass Filter" |
| 421 | }; |
| 422 | |
| 423 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 424 | info->count = 1; |
| 425 | info->value.enumerated.items = 2; |
| 426 | if (info->value.enumerated.item >= 2) |
| 427 | info->value.enumerated.item = 1; |
| 428 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) |
| 433 | { |
| 434 | struct oxygen *chip = ctl->private_data; |
| 435 | struct generic_data *data = chip->model_data; |
| 436 | |
| 437 | value->value.enumerated.item[0] = |
| 438 | (data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0; |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) |
| 443 | { |
| 444 | struct oxygen *chip = ctl->private_data; |
| 445 | struct generic_data *data = chip->model_data; |
| 446 | unsigned int reg; |
| 447 | int changed; |
| 448 | |
| 449 | mutex_lock(&chip->mutex); |
| 450 | reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL); |
| 451 | if (value->value.enumerated.item[0]) |
| 452 | reg |= WM8785_HPFR | WM8785_HPFL; |
| 453 | changed = reg != data->wm8785_regs[WM8785_R2]; |
| 454 | if (changed) |
| 455 | wm8785_write(chip, WM8785_R2, reg); |
| 456 | mutex_unlock(&chip->mutex); |
| 457 | return changed; |
| 458 | } |
| 459 | |
| 460 | static const struct snd_kcontrol_new hpf_control = { |
| 461 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 462 | .name = "ADC Filter Capture Enum", |
| 463 | .info = hpf_info, |
| 464 | .get = hpf_get, |
| 465 | .put = hpf_put, |
| 466 | }; |
| 467 | |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 468 | static int generic_mixer_init(struct oxygen *chip) |
| 469 | { |
| 470 | return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); |
| 471 | } |
| 472 | |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 473 | static int generic_wm8785_mixer_init(struct oxygen *chip) |
| 474 | { |
| 475 | int err; |
| 476 | |
| 477 | err = generic_mixer_init(chip); |
| 478 | if (err < 0) |
| 479 | return err; |
| 480 | err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip)); |
| 481 | if (err < 0) |
| 482 | return err; |
| 483 | return 0; |
| 484 | } |
| 485 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 486 | static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); |
| 487 | |
| 488 | static const struct oxygen_model model_generic = { |
| 489 | .shortname = "C-Media CMI8788", |
| 490 | .longname = "C-Media Oxygen HD Audio", |
| 491 | .chip = "CMI8788", |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 492 | .init = generic_init, |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 493 | .mixer_init = generic_wm8785_mixer_init, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 494 | .cleanup = generic_cleanup, |
Clemens Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 495 | .resume = generic_resume, |
Clemens Ladisch | 76ffe1e | 2009-09-28 11:20:11 +0200 | [diff] [blame] | 496 | .get_i2s_mclk = oxygen_default_i2s_mclk, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 497 | .set_dac_params = set_ak4396_params, |
| 498 | .set_adc_params = set_wm8785_params, |
| 499 | .update_dac_volume = update_ak4396_volume, |
| 500 | .update_dac_mute = update_ak4396_mute, |
Clemens Ladisch | 4972a17 | 2008-04-16 09:15:45 +0200 | [diff] [blame] | 501 | .dac_tlv = ak4396_db_scale, |
Clemens Ladisch | 7ef37cd | 2008-01-21 08:51:55 +0100 | [diff] [blame] | 502 | .model_data_size = sizeof(struct generic_data), |
Clemens Ladisch | d76596b | 2008-09-22 09:02:08 +0200 | [diff] [blame] | 503 | .device_config = PLAYBACK_0_TO_I2S | |
| 504 | PLAYBACK_1_TO_SPDIF | |
| 505 | PLAYBACK_2_TO_AC97_1 | |
| 506 | CAPTURE_0_FROM_I2S_1 | |
| 507 | CAPTURE_1_FROM_SPDIF | |
| 508 | CAPTURE_2_FROM_AC97_1, |
Clemens Ladisch | 976cd62 | 2008-01-25 08:37:49 +0100 | [diff] [blame] | 509 | .dac_channels = 8, |
Clemens Ladisch | 193e813 | 2008-04-16 09:13:36 +0200 | [diff] [blame] | 510 | .dac_volume_min = 0, |
| 511 | .dac_volume_max = 255, |
Clemens Ladisch | 87eedd2 | 2008-03-19 08:20:13 +0100 | [diff] [blame] | 512 | .function_flags = OXYGEN_FUNCTION_SPI | |
| 513 | OXYGEN_FUNCTION_ENABLE_SPI_4_5, |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 514 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 515 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 516 | }; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 517 | |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 518 | static int __devinit get_oxygen_model(struct oxygen *chip, |
| 519 | const struct pci_device_id *id) |
| 520 | { |
| 521 | chip->model = model_generic; |
| 522 | switch (id->driver_data) { |
| 523 | case MODEL_MERIDIAN: |
| 524 | chip->model.init = meridian_init; |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 525 | chip->model.mixer_init = generic_mixer_init; |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 526 | chip->model.resume = meridian_resume; |
| 527 | chip->model.set_adc_params = set_ak5385_params; |
| 528 | chip->model.device_config = PLAYBACK_0_TO_I2S | |
| 529 | PLAYBACK_1_TO_SPDIF | |
| 530 | CAPTURE_0_FROM_I2S_2 | |
| 531 | CAPTURE_1_FROM_SPDIF; |
| 532 | break; |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 533 | case MODEL_CLARO: |
| 534 | chip->model.init = claro_init; |
| 535 | chip->model.cleanup = claro_cleanup; |
| 536 | chip->model.suspend = claro_suspend; |
| 537 | chip->model.resume = claro_resume; |
| 538 | break; |
| 539 | case MODEL_CLARO_HALO: |
| 540 | chip->model.init = claro_halo_init; |
Clemens Ladisch | 1ff0488 | 2009-09-28 11:21:51 +0200 | [diff] [blame] | 541 | chip->model.mixer_init = generic_mixer_init; |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 542 | chip->model.cleanup = claro_cleanup; |
| 543 | chip->model.suspend = claro_suspend; |
| 544 | chip->model.resume = claro_resume; |
Clemens Ladisch | d91b424 | 2009-02-20 09:31:14 +0100 | [diff] [blame] | 545 | chip->model.set_adc_params = set_ak5385_params; |
| 546 | break; |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 547 | } |
| 548 | if (id->driver_data == MODEL_MERIDIAN || |
Clemens Ladisch | 873591d | 2009-03-09 09:12:55 +0100 | [diff] [blame] | 549 | id->driver_data == MODEL_CLARO_HALO) { |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 550 | chip->model.misc_flags = OXYGEN_MISC_MIDI; |
| 551 | chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT; |
| 552 | } |
| 553 | return 0; |
| 554 | } |
| 555 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 556 | static int __devinit generic_oxygen_probe(struct pci_dev *pci, |
| 557 | const struct pci_device_id *pci_id) |
| 558 | { |
| 559 | static int dev; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 560 | int err; |
| 561 | |
| 562 | if (dev >= SNDRV_CARDS) |
| 563 | return -ENODEV; |
| 564 | if (!enable[dev]) { |
| 565 | ++dev; |
| 566 | return -ENOENT; |
| 567 | } |
Clemens Ladisch | bb71858 | 2009-02-19 08:37:13 +0100 | [diff] [blame] | 568 | err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE, |
Clemens Ladisch | 30459d7 | 2009-02-19 08:42:44 +0100 | [diff] [blame] | 569 | oxygen_ids, get_oxygen_model); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 570 | if (err >= 0) |
| 571 | ++dev; |
| 572 | return err; |
| 573 | } |
| 574 | |
| 575 | static struct pci_driver oxygen_driver = { |
| 576 | .name = "CMI8788", |
| 577 | .id_table = oxygen_ids, |
| 578 | .probe = generic_oxygen_probe, |
| 579 | .remove = __devexit_p(oxygen_pci_remove), |
Clemens Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 580 | #ifdef CONFIG_PM |
| 581 | .suspend = oxygen_pci_suspend, |
| 582 | .resume = oxygen_pci_resume, |
| 583 | #endif |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | static int __init alsa_card_oxygen_init(void) |
| 587 | { |
| 588 | return pci_register_driver(&oxygen_driver); |
| 589 | } |
| 590 | |
| 591 | static void __exit alsa_card_oxygen_exit(void) |
| 592 | { |
| 593 | pci_unregister_driver(&oxygen_driver); |
| 594 | } |
| 595 | |
| 596 | module_init(alsa_card_oxygen_init) |
| 597 | module_exit(alsa_card_oxygen_exit) |