aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2008-01-25 02:41:52 -0500
committerJaroslav Kysela <perex@perex.cz>2008-01-31 11:30:15 -0500
commitc626026dd72ec8363aaa862178adeacfa7ac09c5 (patch)
tree676752343a5140acae3add27d9b20d98bbaaa403
parentb78e3dbb04ab4cbe3b94ef5426bcd5b167b6fc75 (diff)
[ALSA] add TempoTec HiFier driver
Add a driver for the MediaTek/TempoTec HiFier Fantasia sound card. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt9
-rw-r--r--sound/pci/Kconfig11
-rw-r--r--sound/pci/oxygen/Makefile2
-rw-r--r--sound/pci/oxygen/ak4396.h44
-rw-r--r--sound/pci/oxygen/hifier.c207
-rw-r--r--sound/pci/oxygen/oxygen.c43
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c2
7 files changed, 276 insertions, 42 deletions
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index 07317da87bd1..67256bd431d6 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -1092,6 +1092,15 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1092 1092
1093 See hdspm.txt for details. 1093 See hdspm.txt for details.
1094 1094
1095 Module snd-hifier
1096 -----------------
1097
1098 Module for the MediaTek/TempoTec HiFier Fantasia sound card.
1099
1100 This module supports autoprobe and multiple cards.
1101
1102 Power management is _not_ supported.
1103
1095 Module snd-ice1712 1104 Module snd-ice1712
1096 ------------------ 1105 ------------------
1097 1106
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 10c36947517e..812085d521f1 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -647,6 +647,17 @@ config SND_HDSPM
647 To compile this driver as a module, choose M here: the module 647 To compile this driver as a module, choose M here: the module
648 will be called snd-hdspm. 648 will be called snd-hdspm.
649 649
650config SND_HIFIER
651 tristate "TempoTec HiFier Fantasia"
652 depends on SND
653 select SND_OXYGEN_LIB
654 help
655 Say Y here to include support for the MediaTek/TempoTec HiFier
656 Fantasia sound card.
657
658 To compile this driver as a module, choose M here: the module
659 will be called snd-hifier.
660
650config SND_ICE1712 661config SND_ICE1712
651 tristate "ICEnsemble ICE1712 (Envy24)" 662 tristate "ICEnsemble ICE1712 (Envy24)"
652 depends on SND 663 depends on SND
diff --git a/sound/pci/oxygen/Makefile b/sound/pci/oxygen/Makefile
index 98d5bc039aa6..4ba07d42fd1d 100644
--- a/sound/pci/oxygen/Makefile
+++ b/sound/pci/oxygen/Makefile
@@ -1,7 +1,9 @@
1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o 1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o
2snd-hifier-objs := hifier.o
2snd-oxygen-objs := oxygen.o 3snd-oxygen-objs := oxygen.o
3snd-virtuoso-objs := virtuoso.o 4snd-virtuoso-objs := virtuoso.o
4 5
5obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o 6obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o
7obj-$(CONFIG_SND_HIFIER) += snd-hifier.o
6obj-$(CONFIG_SND_OXYGEN) += snd-oxygen.o 8obj-$(CONFIG_SND_OXYGEN) += snd-oxygen.o
7obj-$(CONFIG_SND_VIRTUOSO) += snd-virtuoso.o 9obj-$(CONFIG_SND_VIRTUOSO) += snd-virtuoso.o
diff --git a/sound/pci/oxygen/ak4396.h b/sound/pci/oxygen/ak4396.h
new file mode 100644
index 000000000000..551c1cf8e2e0
--- /dev/null
+++ b/sound/pci/oxygen/ak4396.h
@@ -0,0 +1,44 @@
1#ifndef AK4396_H_INCLUDED
2#define AK4396_H_INCLUDED
3
4#define AK4396_WRITE 0x2000
5
6#define AK4396_CONTROL_1 0
7#define AK4396_CONTROL_2 1
8#define AK4396_CONTROL_3 2
9#define AK4396_LCH_ATT 3
10#define AK4396_RCH_ATT 4
11
12/* control 1 */
13#define AK4396_RSTN 0x01
14#define AK4396_DIF_MASK 0x0e
15#define AK4396_DIF_16_LSB 0x00
16#define AK4396_DIF_20_LSB 0x02
17#define AK4396_DIF_24_MSB 0x04
18#define AK4396_DIF_24_I2S 0x06
19#define AK4396_DIF_24_LSB 0x08
20#define AK4396_ACKS 0x80
21/* control 2 */
22#define AK4396_SMUTE 0x01
23#define AK4396_DEM_MASK 0x06
24#define AK4396_DEM_441 0x00
25#define AK4396_DEM_OFF 0x02
26#define AK4396_DEM_48 0x04
27#define AK4396_DEM_32 0x06
28#define AK4396_DFS_MASK 0x18
29#define AK4396_DFS_NORMAL 0x00
30#define AK4396_DFS_DOUBLE 0x08
31#define AK4396_DFS_QUAD 0x10
32#define AK4396_SLOW 0x20
33#define AK4396_DZFM 0x40
34#define AK4396_DZFE 0x80
35/* control 3 */
36#define AK4396_DZFB 0x04
37#define AK4396_DCKB 0x10
38#define AK4396_DCKS 0x20
39#define AK4396_DSDM 0x40
40#define AK4396_D_P_MASK 0x80
41#define AK4396_PCM 0x00
42#define AK4396_DSD 0x80
43
44#endif
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
new file mode 100644
index 000000000000..05ea2b65843e
--- /dev/null
+++ b/sound/pci/oxygen/hifier.c
@@ -0,0 +1,207 @@
1/*
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 |
59 OXYGEN_SPI_CLOCK_320 |
60 (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
69 data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL;
70 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);
73 ak4396_write(chip, AK4396_LCH_ATT, 0xff);
74 ak4396_write(chip, AK4396_RCH_ATT, 0xff);
75
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;
93 else if (params_rate(params) < 120000)
94 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{
130 if (!strcmp(template->name, "Master Playback Volume")) {
131 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
132 template->tlv.p = ak4396_db_scale;
133 } else if (!strcmp(template->name, "Stereo Upmixing")) {
134 return 1; /* stereo only - we don't need upmixing */
135 } else if (!strcmp(template->name,
136 SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK)) ||
137 !strcmp(template->name,
138 SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) {
139 return 1; /* no digital input */
140 }
141 return 0;
142}
143
144static int hifier_mixer_init(struct oxygen *chip)
145{
146 return 0;
147}
148
149static const struct oxygen_model model_hifier = {
150 .shortname = "C-Media CMI8787",
151 .longname = "C-Media Oxygen HD Audio",
152 .chip = "CMI8788",
153 .init = hifier_init,
154 .control_filter = hifier_control_filter,
155 .mixer_init = hifier_mixer_init,
156 .cleanup = hifier_cleanup,
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 .model_data_size = sizeof(struct hifier_data),
162 .dac_channels = 2,
163 .used_channels = OXYGEN_CHANNEL_A |
164 OXYGEN_CHANNEL_SPDIF |
165 OXYGEN_CHANNEL_MULTICH,
166 .function_flags = 0,
167 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
168 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
169};
170
171static int __devinit hifier_probe(struct pci_dev *pci,
172 const struct pci_device_id *pci_id)
173{
174 static int dev;
175 int err;
176
177 if (dev >= SNDRV_CARDS)
178 return -ENODEV;
179 if (!enable[dev]) {
180 ++dev;
181 return -ENOENT;
182 }
183 err = oxygen_pci_probe(pci, index[dev], id[dev], 0, &model_hifier);
184 if (err >= 0)
185 ++dev;
186 return err;
187}
188
189static struct pci_driver hifier_driver = {
190 .name = "CMI8787HiFier",
191 .id_table = hifier_ids,
192 .probe = hifier_probe,
193 .remove = __devexit_p(oxygen_pci_remove),
194};
195
196static int __init alsa_card_hifier_init(void)
197{
198 return pci_register_driver(&hifier_driver);
199}
200
201static void __exit alsa_card_hifier_exit(void)
202{
203 pci_unregister_driver(&hifier_driver);
204}
205
206module_init(alsa_card_hifier_init)
207module_exit(alsa_card_hifier_exit)
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 60af3a7d9824..a0457a570946 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -36,6 +36,7 @@
36#include <sound/pcm_params.h> 36#include <sound/pcm_params.h>
37#include <sound/tlv.h> 37#include <sound/tlv.h>
38#include "oxygen.h" 38#include "oxygen.h"
39#include "ak4396.h"
39 40
40MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 41MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
41MODULE_DESCRIPTION("C-Media CMI8788 driver"); 42MODULE_DESCRIPTION("C-Media CMI8788 driver");
@@ -61,8 +62,6 @@ static struct pci_device_id oxygen_ids[] __devinitdata = {
61 { OXYGEN_PCI_SUBID(0x13f6, 0x0010) }, 62 { OXYGEN_PCI_SUBID(0x13f6, 0x0010) },
62 { OXYGEN_PCI_SUBID(0x13f6, 0x8788) }, 63 { OXYGEN_PCI_SUBID(0x13f6, 0x8788) },
63 { OXYGEN_PCI_SUBID(0x147a, 0xa017) }, 64 { OXYGEN_PCI_SUBID(0x147a, 0xa017) },
64 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
65 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
66 { OXYGEN_PCI_SUBID(0x1a58, 0x0910) }, 65 { OXYGEN_PCI_SUBID(0x1a58, 0x0910) },
67 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = 1 }, 66 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = 1 },
68 { OXYGEN_PCI_SUBID(0x7284, 0x9761) }, 67 { OXYGEN_PCI_SUBID(0x7284, 0x9761) },
@@ -76,46 +75,6 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
76#define GPIO_AK5385_DFS_DOUBLE 0x0001 75#define GPIO_AK5385_DFS_DOUBLE 0x0001
77#define GPIO_AK5385_DFS_QUAD 0x0002 76#define GPIO_AK5385_DFS_QUAD 0x0002
78 77
79#define AK4396_WRITE 0x2000
80
81#define AK4396_CONTROL_1 0
82#define AK4396_CONTROL_2 1
83#define AK4396_CONTROL_3 2
84#define AK4396_LCH_ATT 3
85#define AK4396_RCH_ATT 4
86
87/* control 1 */
88#define AK4396_RSTN 0x01
89#define AK4396_DIF_MASK 0x0e
90#define AK4396_DIF_16_LSB 0x00
91#define AK4396_DIF_20_LSB 0x02
92#define AK4396_DIF_24_MSB 0x04
93#define AK4396_DIF_24_I2S 0x06
94#define AK4396_DIF_24_LSB 0x08
95#define AK4396_ACKS 0x80
96/* control 2 */
97#define AK4396_SMUTE 0x01
98#define AK4396_DEM_MASK 0x06
99#define AK4396_DEM_441 0x00
100#define AK4396_DEM_OFF 0x02
101#define AK4396_DEM_48 0x04
102#define AK4396_DEM_32 0x06
103#define AK4396_DFS_MASK 0x18
104#define AK4396_DFS_NORMAL 0x00
105#define AK4396_DFS_DOUBLE 0x08
106#define AK4396_DFS_QUAD 0x10
107#define AK4396_SLOW 0x20
108#define AK4396_DZFM 0x40
109#define AK4396_DZFE 0x80
110/* control 3 */
111#define AK4396_DZFB 0x04
112#define AK4396_DCKB 0x10
113#define AK4396_DCKS 0x20
114#define AK4396_DSDM 0x40
115#define AK4396_D_P_MASK 0x80
116#define AK4396_PCM 0x00
117#define AK4396_DSD 0x80
118
119#define WM8785_R0 0 78#define WM8785_R0 0
120#define WM8785_R1 1 79#define WM8785_R1 1
121#define WM8785_R2 2 80#define WM8785_R2 2
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 21b227a94ace..fe53318e94e0 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -712,6 +712,8 @@ static int add_controls(struct oxygen *chip,
712 err = chip->model->control_filter(&template); 712 err = chip->model->control_filter(&template);
713 if (err < 0) 713 if (err < 0)
714 return err; 714 return err;
715 if (err == 1)
716 continue;
715 ctl = snd_ctl_new1(&template, chip); 717 ctl = snd_ctl_new1(&template, chip);
716 if (!ctl) 718 if (!ctl)
717 return -ENOMEM; 719 return -ENOMEM;