2 * C-Media CMI8788 driver for the MediaTek/TempoTec HiFier Fantasia
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
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.
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.
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
26 #include <linux/delay.h>
27 #include <linux/pci.h>
28 #include <sound/control.h>
29 #include <sound/core.h>
30 #include <sound/initval.h>
31 #include <sound/pcm.h>
32 #include <sound/tlv.h>
36 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
37 MODULE_DESCRIPTION("TempoTec HiFier driver");
38 MODULE_LICENSE("GPL v2");
40 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
41 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
42 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
44 module_param_array(index, int, NULL, 0444);
45 MODULE_PARM_DESC(index, "card index");
46 module_param_array(id, charp, NULL, 0444);
47 MODULE_PARM_DESC(id, "ID string");
48 module_param_array(enable, bool, NULL, 0444);
49 MODULE_PARM_DESC(enable, "enable card");
51 static struct pci_device_id hifier_ids[] __devinitdata = {
52 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
53 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
54 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
57 MODULE_DEVICE_TABLE(pci, hifier_ids);
63 static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
65 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
66 OXYGEN_SPI_DATA_LENGTH_2 |
67 OXYGEN_SPI_CLOCK_160 |
68 (0 << OXYGEN_SPI_CODEC_SHIFT) |
69 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
70 AK4396_WRITE | (reg << 8) | value);
73 static void update_ak4396_volume(struct oxygen *chip)
75 ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
76 ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
79 static void hifier_registers_init(struct oxygen *chip)
81 struct hifier_data *data = chip->model_data;
83 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
84 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
85 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
86 update_ak4396_volume(chip);
89 static void hifier_init(struct oxygen *chip)
91 struct hifier_data *data = chip->model_data;
93 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
94 hifier_registers_init(chip);
96 snd_component_add(chip->card, "AK4396");
97 snd_component_add(chip->card, "CS5340");
100 static void hifier_cleanup(struct oxygen *chip)
104 static void hifier_resume(struct oxygen *chip)
106 hifier_registers_init(chip);
109 static void set_ak4396_params(struct oxygen *chip,
110 struct snd_pcm_hw_params *params)
112 struct hifier_data *data = chip->model_data;
115 value = data->ak4396_ctl2 & ~AK4396_DFS_MASK;
116 if (params_rate(params) <= 54000)
117 value |= AK4396_DFS_NORMAL;
118 else if (params_rate(params) <= 108000)
119 value |= AK4396_DFS_DOUBLE;
121 value |= AK4396_DFS_QUAD;
122 data->ak4396_ctl2 = value;
124 msleep(1); /* wait for the new MCLK to become stable */
126 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB);
127 ak4396_write(chip, AK4396_CONTROL_2, value);
128 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
131 static void update_ak4396_mute(struct oxygen *chip)
133 struct hifier_data *data = chip->model_data;
136 value = data->ak4396_ctl2 & ~AK4396_SMUTE;
138 value |= AK4396_SMUTE;
139 data->ak4396_ctl2 = value;
140 ak4396_write(chip, AK4396_CONTROL_2, value);
143 static void set_cs5340_params(struct oxygen *chip,
144 struct snd_pcm_hw_params *params)
148 static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
150 static const struct oxygen_model model_hifier = {
151 .shortname = "C-Media CMI8787",
152 .longname = "C-Media Oxygen HD Audio",
155 .cleanup = hifier_cleanup,
156 .resume = hifier_resume,
157 .set_dac_params = set_ak4396_params,
158 .set_adc_params = set_cs5340_params,
159 .update_dac_volume = update_ak4396_volume,
160 .update_dac_mute = update_ak4396_mute,
161 .dac_tlv = ak4396_db_scale,
162 .model_data_size = sizeof(struct hifier_data),
163 .device_config = PLAYBACK_0_TO_I2S |
164 PLAYBACK_1_TO_SPDIF |
165 CAPTURE_0_FROM_I2S_1,
168 .dac_volume_max = 255,
169 .function_flags = OXYGEN_FUNCTION_SPI,
170 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
171 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
174 static int __devinit get_hifier_model(struct oxygen *chip,
175 const struct pci_device_id *id)
177 chip->model = model_hifier;
181 static int __devinit hifier_probe(struct pci_dev *pci,
182 const struct pci_device_id *pci_id)
187 if (dev >= SNDRV_CARDS)
193 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
194 hifier_ids, get_hifier_model);
200 static struct pci_driver hifier_driver = {
201 .name = "CMI8787HiFier",
202 .id_table = hifier_ids,
203 .probe = hifier_probe,
204 .remove = __devexit_p(oxygen_pci_remove),
206 .suspend = oxygen_pci_suspend,
207 .resume = oxygen_pci_resume,
211 static int __init alsa_card_hifier_init(void)
213 return pci_register_driver(&hifier_driver);
216 static void __exit alsa_card_hifier_exit(void)
218 pci_unregister_driver(&hifier_driver);
221 module_init(alsa_card_hifier_init)
222 module_exit(alsa_card_hifier_exit)