blob: 090dd4354a2838fa2e818265270965c829460c34 [file] [log] [blame]
Clemens Ladischc6260262008-01-25 08:41:52 +01001/*
2 * C-Media CMI8788 driver for the MediaTek/TempoTec HiFier Fantasia
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#include <linux/pci.h>
21#include <sound/control.h>
22#include <sound/core.h>
23#include <sound/initval.h>
24#include <sound/pcm.h>
25#include <sound/tlv.h>
26#include "oxygen.h"
27#include "ak4396.h"
28
29MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
30MODULE_DESCRIPTION("TempoTec HiFier driver");
31MODULE_LICENSE("GPL");
32
33static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
34static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
35static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
36
37module_param_array(index, int, NULL, 0444);
38MODULE_PARM_DESC(index, "card index");
39module_param_array(id, charp, NULL, 0444);
40MODULE_PARM_DESC(id, "ID string");
41module_param_array(enable, bool, NULL, 0444);
42MODULE_PARM_DESC(enable, "enable card");
43
44static struct pci_device_id hifier_ids[] __devinitdata = {
45 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
46 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
47 { }
48};
49MODULE_DEVICE_TABLE(pci, hifier_ids);
50
51struct hifier_data {
52 u8 ak4396_ctl2;
53};
54
55static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
56{
57 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
58 OXYGEN_SPI_DATA_LENGTH_2 |
Clemens Ladisch2ea85982008-01-30 08:38:30 +010059 OXYGEN_SPI_CLOCK_160 |
Clemens Ladischc6260262008-01-25 08:41:52 +010060 (0 << OXYGEN_SPI_CODEC_SHIFT) |
61 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
62 AK4396_WRITE | (reg << 8) | value);
63}
64
65static void hifier_init(struct oxygen *chip)
66{
67 struct hifier_data *data = chip->model_data;
68
Clemens Ladische9835322008-04-16 09:14:30 +020069 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
Clemens Ladischc6260262008-01-25 08:41:52 +010070 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
71 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
72 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
Clemens Ladische9835322008-04-16 09:14:30 +020073 ak4396_write(chip, AK4396_LCH_ATT, 0);
74 ak4396_write(chip, AK4396_RCH_ATT, 0);
Clemens Ladischc6260262008-01-25 08:41:52 +010075
76 snd_component_add(chip->card, "AK4396");
77 snd_component_add(chip->card, "CS5340");
78}
79
80static void hifier_cleanup(struct oxygen *chip)
81{
82}
83
84static void set_ak4396_params(struct oxygen *chip,
85 struct snd_pcm_hw_params *params)
86{
87 struct hifier_data *data = chip->model_data;
88 u8 value;
89
90 value = data->ak4396_ctl2 & ~AK4396_DFS_MASK;
91 if (params_rate(params) <= 54000)
92 value |= AK4396_DFS_NORMAL;
Clemens Ladisch236c4922008-01-28 08:32:58 +010093 else if (params_rate(params) <= 108000)
Clemens Ladischc6260262008-01-25 08:41:52 +010094 value |= AK4396_DFS_DOUBLE;
95 else
96 value |= AK4396_DFS_QUAD;
97 data->ak4396_ctl2 = value;
98 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB);
99 ak4396_write(chip, AK4396_CONTROL_2, value);
100 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
101}
102
103static void update_ak4396_volume(struct oxygen *chip)
104{
105 ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
106 ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
107}
108
109static void update_ak4396_mute(struct oxygen *chip)
110{
111 struct hifier_data *data = chip->model_data;
112 u8 value;
113
114 value = data->ak4396_ctl2 & ~AK4396_SMUTE;
115 if (chip->dac_mute)
116 value |= AK4396_SMUTE;
117 data->ak4396_ctl2 = value;
118 ak4396_write(chip, AK4396_CONTROL_2, value);
119}
120
121static void set_cs5340_params(struct oxygen *chip,
122 struct snd_pcm_hw_params *params)
123{
124}
125
126static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
127
128static int hifier_control_filter(struct snd_kcontrol_new *template)
129{
Clemens Ladisch4972a172008-04-16 09:15:45 +0200130 if (!strcmp(template->name, "Stereo Upmixing"))
Clemens Ladischc6260262008-01-25 08:41:52 +0100131 return 1; /* stereo only - we don't need upmixing */
Clemens Ladischc6260262008-01-25 08:41:52 +0100132 return 0;
133}
134
Clemens Ladischc6260262008-01-25 08:41:52 +0100135static const struct oxygen_model model_hifier = {
136 .shortname = "C-Media CMI8787",
137 .longname = "C-Media Oxygen HD Audio",
138 .chip = "CMI8788",
Clemens Ladischb930b9f2008-02-26 08:40:57 +0100139 .owner = THIS_MODULE,
Clemens Ladischc6260262008-01-25 08:41:52 +0100140 .init = hifier_init,
141 .control_filter = hifier_control_filter,
Clemens Ladischc6260262008-01-25 08:41:52 +0100142 .cleanup = hifier_cleanup,
143 .set_dac_params = set_ak4396_params,
144 .set_adc_params = set_cs5340_params,
145 .update_dac_volume = update_ak4396_volume,
146 .update_dac_mute = update_ak4396_mute,
Clemens Ladisch4972a172008-04-16 09:15:45 +0200147 .dac_tlv = ak4396_db_scale,
Clemens Ladischc6260262008-01-25 08:41:52 +0100148 .model_data_size = sizeof(struct hifier_data),
Clemens Ladischf009ad92008-03-19 08:19:41 +0100149 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
150 PLAYBACK_1_TO_SPDIF |
151 CAPTURE_0_FROM_I2S_1,
Clemens Ladischc6260262008-01-25 08:41:52 +0100152 .dac_channels = 2,
Clemens Ladisch193e8132008-04-16 09:13:36 +0200153 .dac_volume_min = 0,
154 .dac_volume_max = 255,
Clemens Ladisch87eedd22008-03-19 08:20:13 +0100155 .function_flags = OXYGEN_FUNCTION_SPI,
Clemens Ladischc6260262008-01-25 08:41:52 +0100156 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
157 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
158};
159
160static int __devinit hifier_probe(struct pci_dev *pci,
161 const struct pci_device_id *pci_id)
162{
163 static int dev;
164 int err;
165
166 if (dev >= SNDRV_CARDS)
167 return -ENODEV;
168 if (!enable[dev]) {
169 ++dev;
170 return -ENOENT;
171 }
Clemens Ladischdb12b8e2008-03-19 08:20:59 +0100172 err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier);
Clemens Ladischc6260262008-01-25 08:41:52 +0100173 if (err >= 0)
174 ++dev;
175 return err;
176}
177
178static struct pci_driver hifier_driver = {
179 .name = "CMI8787HiFier",
180 .id_table = hifier_ids,
181 .probe = hifier_probe,
182 .remove = __devexit_p(oxygen_pci_remove),
183};
184
185static int __init alsa_card_hifier_init(void)
186{
187 return pci_register_driver(&hifier_driver);
188}
189
190static void __exit alsa_card_hifier_exit(void)
191{
192 pci_unregister_driver(&hifier_driver);
193}
194
195module_init(alsa_card_hifier_init)
196module_exit(alsa_card_hifier_exit)