2 * Linux driver for TerraTec DMX 6Fire USB
6 * Author: Torsten Schenk <torsten.schenk@zoho.com>
7 * Created: Jan 01, 2011
9 * Copyright: (C) Torsten Schenk
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/interrupt.h>
18 #include <sound/control.h>
24 static char *opt_coax_texts
[2] = { "Optical", "Coax" };
25 static char *line_phono_texts
[2] = { "Line", "Phono" };
28 * calculated with $value\[i\] = 128 \cdot sqrt[3]{\frac{i}{128}}$
29 * this is done because the linear values cause rapid degredation
30 * of volume in the uppermost region.
32 static const u8 log_volume_table
[128] = {
33 0x00, 0x19, 0x20, 0x24, 0x28, 0x2b, 0x2e, 0x30, 0x32, 0x34,
34 0x36, 0x38, 0x3a, 0x3b, 0x3d, 0x3e, 0x40, 0x41, 0x42, 0x43,
35 0x44, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
36 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x53, 0x54, 0x55, 0x56,
37 0x56, 0x57, 0x58, 0x58, 0x59, 0x5a, 0x5b, 0x5b, 0x5c, 0x5c,
38 0x5d, 0x5e, 0x5e, 0x5f, 0x60, 0x60, 0x61, 0x61, 0x62, 0x62,
39 0x63, 0x63, 0x64, 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68,
40 0x68, 0x69, 0x69, 0x6a, 0x6a, 0x6b, 0x6b, 0x6c, 0x6c, 0x6c,
41 0x6d, 0x6d, 0x6e, 0x6e, 0x6f, 0x6f, 0x70, 0x70, 0x70, 0x71,
42 0x71, 0x72, 0x72, 0x73, 0x73, 0x73, 0x74, 0x74, 0x75, 0x75,
43 0x75, 0x76, 0x76, 0x77, 0x77, 0x77, 0x78, 0x78, 0x78, 0x79,
44 0x79, 0x7a, 0x7a, 0x7a, 0x7b, 0x7b, 0x7b, 0x7c, 0x7c, 0x7c,
45 0x7d, 0x7d, 0x7d, 0x7e, 0x7e, 0x7e, 0x7f, 0x7f };
48 * data that needs to be sent to device. sets up card internal stuff.
49 * values dumped from windows driver and filtered by trial'n'error.
57 { 0x22, 0x00, 0x00 }, { 0x20, 0x00, 0x08 }, { 0x22, 0x01, 0x01 },
58 { 0x20, 0x01, 0x08 }, { 0x22, 0x02, 0x00 }, { 0x20, 0x02, 0x08 },
59 { 0x22, 0x03, 0x00 }, { 0x20, 0x03, 0x08 }, { 0x22, 0x04, 0x00 },
60 { 0x20, 0x04, 0x08 }, { 0x22, 0x05, 0x01 }, { 0x20, 0x05, 0x08 },
61 { 0x22, 0x04, 0x01 }, { 0x12, 0x04, 0x00 }, { 0x12, 0x05, 0x00 },
62 { 0x12, 0x0d, 0x78 }, { 0x12, 0x21, 0x82 }, { 0x12, 0x22, 0x80 },
63 { 0x12, 0x23, 0x00 }, { 0x12, 0x06, 0x02 }, { 0x12, 0x03, 0x00 },
64 { 0x12, 0x02, 0x00 }, { 0x22, 0x03, 0x01 },
65 { 0 } /* TERMINATING ENTRY */
68 static void usb6fire_control_master_vol_update(struct control_runtime
*rt
)
70 struct comm_runtime
*comm_rt
= rt
->chip
->comm
;
73 comm_rt
->write8(comm_rt
, 0x12, 0x0f, 0x7f -
74 log_volume_table
[rt
->master_vol
]);
76 comm_rt
->write8(comm_rt
, 0x12, 0x0e, 0x00);
80 static void usb6fire_control_line_phono_update(struct control_runtime
*rt
)
82 struct comm_runtime
*comm_rt
= rt
->chip
->comm
;
84 comm_rt
->write8(comm_rt
, 0x22, 0x02, rt
->line_phono_switch
);
85 comm_rt
->write8(comm_rt
, 0x21, 0x02, rt
->line_phono_switch
);
89 static void usb6fire_control_opt_coax_update(struct control_runtime
*rt
)
91 struct comm_runtime
*comm_rt
= rt
->chip
->comm
;
93 comm_rt
->write8(comm_rt
, 0x22, 0x00, rt
->opt_coax_switch
);
94 comm_rt
->write8(comm_rt
, 0x21, 0x00, rt
->opt_coax_switch
);
98 static int usb6fire_control_master_vol_info(struct snd_kcontrol
*kcontrol
,
99 struct snd_ctl_elem_info
*uinfo
)
101 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
103 uinfo
->value
.integer
.min
= 0;
104 uinfo
->value
.integer
.max
= 127;
108 static int usb6fire_control_master_vol_put(struct snd_kcontrol
*kcontrol
,
109 struct snd_ctl_elem_value
*ucontrol
)
111 struct control_runtime
*rt
= snd_kcontrol_chip(kcontrol
);
113 if (rt
->master_vol
!= ucontrol
->value
.integer
.value
[0]) {
114 rt
->master_vol
= ucontrol
->value
.integer
.value
[0];
115 usb6fire_control_master_vol_update(rt
);
121 static int usb6fire_control_master_vol_get(struct snd_kcontrol
*kcontrol
,
122 struct snd_ctl_elem_value
*ucontrol
)
124 struct control_runtime
*rt
= snd_kcontrol_chip(kcontrol
);
125 ucontrol
->value
.integer
.value
[0] = rt
->master_vol
;
129 static int usb6fire_control_line_phono_info(struct snd_kcontrol
*kcontrol
,
130 struct snd_ctl_elem_info
*uinfo
)
132 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
134 uinfo
->value
.enumerated
.items
= 2;
135 if (uinfo
->value
.enumerated
.item
> 1)
136 uinfo
->value
.enumerated
.item
= 1;
137 strcpy(uinfo
->value
.enumerated
.name
,
138 line_phono_texts
[uinfo
->value
.enumerated
.item
]);
142 static int usb6fire_control_line_phono_put(struct snd_kcontrol
*kcontrol
,
143 struct snd_ctl_elem_value
*ucontrol
)
145 struct control_runtime
*rt
= snd_kcontrol_chip(kcontrol
);
147 if (rt
->line_phono_switch
!= ucontrol
->value
.integer
.value
[0]) {
148 rt
->line_phono_switch
= ucontrol
->value
.integer
.value
[0];
149 usb6fire_control_line_phono_update(rt
);
155 static int usb6fire_control_line_phono_get(struct snd_kcontrol
*kcontrol
,
156 struct snd_ctl_elem_value
*ucontrol
)
158 struct control_runtime
*rt
= snd_kcontrol_chip(kcontrol
);
159 ucontrol
->value
.integer
.value
[0] = rt
->line_phono_switch
;
163 static int usb6fire_control_opt_coax_info(struct snd_kcontrol
*kcontrol
,
164 struct snd_ctl_elem_info
*uinfo
)
166 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
168 uinfo
->value
.enumerated
.items
= 2;
169 if (uinfo
->value
.enumerated
.item
> 1)
170 uinfo
->value
.enumerated
.item
= 1;
171 strcpy(uinfo
->value
.enumerated
.name
,
172 opt_coax_texts
[uinfo
->value
.enumerated
.item
]);
176 static int usb6fire_control_opt_coax_put(struct snd_kcontrol
*kcontrol
,
177 struct snd_ctl_elem_value
*ucontrol
)
179 struct control_runtime
*rt
= snd_kcontrol_chip(kcontrol
);
182 if (rt
->opt_coax_switch
!= ucontrol
->value
.enumerated
.item
[0]) {
183 rt
->opt_coax_switch
= ucontrol
->value
.enumerated
.item
[0];
184 usb6fire_control_opt_coax_update(rt
);
190 static int usb6fire_control_opt_coax_get(struct snd_kcontrol
*kcontrol
,
191 struct snd_ctl_elem_value
*ucontrol
)
193 struct control_runtime
*rt
= snd_kcontrol_chip(kcontrol
);
194 ucontrol
->value
.enumerated
.item
[0] = rt
->opt_coax_switch
;
198 static struct __devinitdata snd_kcontrol_new elements
[] = {
200 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
201 .name
= "Master Playback Volume",
203 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
204 .info
= usb6fire_control_master_vol_info
,
205 .get
= usb6fire_control_master_vol_get
,
206 .put
= usb6fire_control_master_vol_put
209 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
210 .name
= "Line/Phono Capture Route",
212 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
213 .info
= usb6fire_control_line_phono_info
,
214 .get
= usb6fire_control_line_phono_get
,
215 .put
= usb6fire_control_line_phono_put
218 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
219 .name
= "Opt/Coax Capture Route",
221 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
222 .info
= usb6fire_control_opt_coax_info
,
223 .get
= usb6fire_control_opt_coax_get
,
224 .put
= usb6fire_control_opt_coax_put
229 int __devinit
usb6fire_control_init(struct sfire_chip
*chip
)
233 struct control_runtime
*rt
= kzalloc(sizeof(struct control_runtime
),
235 struct comm_runtime
*comm_rt
= chip
->comm
;
243 while (init_data
[i
].type
) {
244 comm_rt
->write8(comm_rt
, init_data
[i
].type
, init_data
[i
].reg
,
249 usb6fire_control_opt_coax_update(rt
);
250 usb6fire_control_line_phono_update(rt
);
251 usb6fire_control_master_vol_update(rt
);
254 while (elements
[i
].name
) {
255 ret
= snd_ctl_add(chip
->card
, snd_ctl_new1(&elements
[i
], rt
));
258 snd_printk(KERN_ERR PREFIX
"cannot add control.\n");
268 void usb6fire_control_abort(struct sfire_chip
*chip
)
271 void usb6fire_control_destroy(struct sfire_chip
*chip
)
273 kfree(chip
->control
);
274 chip
->control
= NULL
;