diff options
Diffstat (limited to 'sound/i2c')
-rw-r--r-- | sound/i2c/Makefile | 18 | ||||
-rw-r--r-- | sound/i2c/cs8427.c | 572 | ||||
-rw-r--r-- | sound/i2c/i2c.c | 333 | ||||
-rw-r--r-- | sound/i2c/l3/Makefile | 8 | ||||
-rw-r--r-- | sound/i2c/l3/uda1341.c | 830 | ||||
-rw-r--r-- | sound/i2c/other/Makefile | 16 | ||||
-rw-r--r-- | sound/i2c/other/ak4114.c | 580 | ||||
-rw-r--r-- | sound/i2c/other/ak4117.c | 559 | ||||
-rw-r--r-- | sound/i2c/other/ak4xxx-adda.c | 501 | ||||
-rw-r--r-- | sound/i2c/other/tea575x-tuner.c | 233 | ||||
-rw-r--r-- | sound/i2c/tea6330t.c | 369 |
11 files changed, 4019 insertions, 0 deletions
diff --git a/sound/i2c/Makefile b/sound/i2c/Makefile new file mode 100644 index 000000000000..816a2e7c88ca --- /dev/null +++ b/sound/i2c/Makefile | |||
@@ -0,0 +1,18 @@ | |||
1 | # | ||
2 | # Makefile for ALSA | ||
3 | # Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz> | ||
4 | # | ||
5 | |||
6 | snd-i2c-objs := i2c.o | ||
7 | snd-cs8427-objs := cs8427.o | ||
8 | snd-tea6330t-objs := tea6330t.o | ||
9 | |||
10 | ifeq ($(subst m,y,$(CONFIG_L3)),y) | ||
11 | obj-$(CONFIG_L3) += l3/ | ||
12 | endif | ||
13 | |||
14 | obj-$(CONFIG_SND) += other/ | ||
15 | |||
16 | # Toplevel Module Dependency | ||
17 | obj-$(CONFIG_SND_INTERWAVE_STB) += snd-tea6330t.o snd-i2c.o | ||
18 | obj-$(CONFIG_SND_ICE1712) += snd-cs8427.o snd-i2c.o | ||
diff --git a/sound/i2c/cs8427.c b/sound/i2c/cs8427.c new file mode 100644 index 000000000000..a3fda859dd15 --- /dev/null +++ b/sound/i2c/cs8427.c | |||
@@ -0,0 +1,572 @@ | |||
1 | /* | ||
2 | * Routines for control of the CS8427 via i2c bus | ||
3 | * IEC958 (S/PDIF) receiver & transmitter by Cirrus Logic | ||
4 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <sound/driver.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <sound/core.h> | ||
28 | #include <sound/control.h> | ||
29 | #include <sound/pcm.h> | ||
30 | #include <sound/cs8427.h> | ||
31 | #include <sound/asoundef.h> | ||
32 | |||
33 | static void snd_cs8427_reset(snd_i2c_device_t *cs8427); | ||
34 | |||
35 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
36 | MODULE_DESCRIPTION("IEC958 (S/PDIF) receiver & transmitter by Cirrus Logic"); | ||
37 | MODULE_LICENSE("GPL"); | ||
38 | |||
39 | #define CS8427_ADDR (0x20>>1) /* fixed address */ | ||
40 | |||
41 | typedef struct { | ||
42 | snd_pcm_substream_t *substream; | ||
43 | char hw_status[24]; /* hardware status */ | ||
44 | char def_status[24]; /* default status */ | ||
45 | char pcm_status[24]; /* PCM private status */ | ||
46 | char hw_udata[32]; | ||
47 | snd_kcontrol_t *pcm_ctl; | ||
48 | } cs8427_stream_t; | ||
49 | |||
50 | typedef struct { | ||
51 | unsigned char regmap[0x14]; /* map of first 1 + 13 registers */ | ||
52 | unsigned int rate; | ||
53 | unsigned int reset_timeout; | ||
54 | cs8427_stream_t playback; | ||
55 | cs8427_stream_t capture; | ||
56 | } cs8427_t; | ||
57 | |||
58 | static unsigned char swapbits(unsigned char val) | ||
59 | { | ||
60 | int bit; | ||
61 | unsigned char res = 0; | ||
62 | for (bit = 0; bit < 8; bit++) { | ||
63 | res <<= 1; | ||
64 | res |= val & 1; | ||
65 | val >>= 1; | ||
66 | } | ||
67 | return res; | ||
68 | } | ||
69 | |||
70 | int snd_cs8427_reg_write(snd_i2c_device_t *device, unsigned char reg, unsigned char val) | ||
71 | { | ||
72 | int err; | ||
73 | unsigned char buf[2]; | ||
74 | |||
75 | buf[0] = reg & 0x7f; | ||
76 | buf[1] = val; | ||
77 | if ((err = snd_i2c_sendbytes(device, buf, 2)) != 2) { | ||
78 | snd_printk("unable to send bytes 0x%02x:0x%02x to CS8427 (%i)\n", buf[0], buf[1], err); | ||
79 | return err < 0 ? err : -EIO; | ||
80 | } | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static int snd_cs8427_reg_read(snd_i2c_device_t *device, unsigned char reg) | ||
85 | { | ||
86 | int err; | ||
87 | unsigned char buf; | ||
88 | |||
89 | if ((err = snd_i2c_sendbytes(device, ®, 1)) != 1) { | ||
90 | snd_printk("unable to send register 0x%x byte to CS8427\n", reg); | ||
91 | return err < 0 ? err : -EIO; | ||
92 | } | ||
93 | if ((err = snd_i2c_readbytes(device, &buf, 1)) != 1) { | ||
94 | snd_printk("unable to read register 0x%x byte from CS8427\n", reg); | ||
95 | return err < 0 ? err : -EIO; | ||
96 | } | ||
97 | return buf; | ||
98 | } | ||
99 | |||
100 | static int snd_cs8427_select_corudata(snd_i2c_device_t *device, int udata) | ||
101 | { | ||
102 | cs8427_t *chip = device->private_data; | ||
103 | int err; | ||
104 | |||
105 | udata = udata ? CS8427_BSEL : 0; | ||
106 | if (udata != (chip->regmap[CS8427_REG_CSDATABUF] & udata)) { | ||
107 | chip->regmap[CS8427_REG_CSDATABUF] &= ~CS8427_BSEL; | ||
108 | chip->regmap[CS8427_REG_CSDATABUF] |= udata; | ||
109 | err = snd_cs8427_reg_write(device, CS8427_REG_CSDATABUF, chip->regmap[CS8427_REG_CSDATABUF]); | ||
110 | if (err < 0) | ||
111 | return err; | ||
112 | } | ||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | static int snd_cs8427_send_corudata(snd_i2c_device_t *device, | ||
117 | int udata, | ||
118 | unsigned char *ndata, | ||
119 | int count) | ||
120 | { | ||
121 | cs8427_t *chip = device->private_data; | ||
122 | char *hw_data = udata ? chip->playback.hw_udata : chip->playback.hw_status; | ||
123 | char data[32]; | ||
124 | int err, idx; | ||
125 | |||
126 | if (!memcmp(hw_data, ndata, count)) | ||
127 | return 0; | ||
128 | if ((err = snd_cs8427_select_corudata(device, udata)) < 0) | ||
129 | return err; | ||
130 | memcpy(hw_data, ndata, count); | ||
131 | if (udata) { | ||
132 | memset(data, 0, sizeof(data)); | ||
133 | if (memcmp(hw_data, data, count) == 0) { | ||
134 | chip->regmap[CS8427_REG_UDATABUF] &= ~CS8427_UBMMASK; | ||
135 | chip->regmap[CS8427_REG_UDATABUF] |= CS8427_UBMZEROS | CS8427_EFTUI; | ||
136 | if ((err = snd_cs8427_reg_write(device, CS8427_REG_UDATABUF, chip->regmap[CS8427_REG_UDATABUF])) < 0) | ||
137 | return err; | ||
138 | return 0; | ||
139 | } | ||
140 | } | ||
141 | data[0] = CS8427_REG_AUTOINC | CS8427_REG_CORU_DATABUF; | ||
142 | for (idx = 0; idx < count; idx++) | ||
143 | data[idx + 1] = swapbits(ndata[idx]); | ||
144 | if (snd_i2c_sendbytes(device, data, count + 1) != count + 1) | ||
145 | return -EIO; | ||
146 | return 1; | ||
147 | } | ||
148 | |||
149 | static void snd_cs8427_free(snd_i2c_device_t *device) | ||
150 | { | ||
151 | kfree(device->private_data); | ||
152 | } | ||
153 | |||
154 | int snd_cs8427_create(snd_i2c_bus_t *bus, | ||
155 | unsigned char addr, | ||
156 | unsigned int reset_timeout, | ||
157 | snd_i2c_device_t **r_cs8427) | ||
158 | { | ||
159 | static unsigned char initvals1[] = { | ||
160 | CS8427_REG_CONTROL1 | CS8427_REG_AUTOINC, | ||
161 | /* CS8427_REG_CONTROL1: RMCK to OMCK, valid PCM audio, disable mutes, TCBL=output */ | ||
162 | CS8427_SWCLK | CS8427_TCBLDIR, | ||
163 | /* CS8427_REG_CONTROL2: hold last valid audio sample, RMCK=256*Fs, normal stereo operation */ | ||
164 | 0x00, | ||
165 | /* CS8427_REG_DATAFLOW: output drivers normal operation, Tx<=serial, Rx=>serial */ | ||
166 | CS8427_TXDSERIAL | CS8427_SPDAES3RECEIVER, | ||
167 | /* CS8427_REG_CLOCKSOURCE: Run off, CMCK=256*Fs, output time base = OMCK, input time base = | ||
168 | recovered input clock, recovered input clock source is ILRCK changed to AES3INPUT (workaround, see snd_cs8427_reset) */ | ||
169 | CS8427_RXDILRCK, | ||
170 | /* CS8427_REG_SERIALINPUT: Serial audio input port data format = I2S, 24-bit, 64*Fsi */ | ||
171 | CS8427_SIDEL | CS8427_SILRPOL, | ||
172 | /* CS8427_REG_SERIALOUTPUT: Serial audio output port data format = I2S, 24-bit, 64*Fsi */ | ||
173 | CS8427_SODEL | CS8427_SOLRPOL, | ||
174 | }; | ||
175 | static unsigned char initvals2[] = { | ||
176 | CS8427_REG_RECVERRMASK | CS8427_REG_AUTOINC, | ||
177 | /* CS8427_REG_RECVERRMASK: unmask the input PLL clock, V, confidence, biphase, parity status bits */ | ||
178 | /* CS8427_UNLOCK | CS8427_V | CS8427_CONF | CS8427_BIP | CS8427_PAR, */ | ||
179 | 0xff, /* set everything */ | ||
180 | /* CS8427_REG_CSDATABUF: | ||
181 | Registers 32-55 window to CS buffer | ||
182 | Inhibit D->E transfers from overwriting first 5 bytes of CS data. | ||
183 | Inhibit D->E transfers (all) of CS data. | ||
184 | Allow E->F transfer of CS data. | ||
185 | One byte mode; both A/B channels get same written CB data. | ||
186 | A channel info is output to chip's EMPH* pin. */ | ||
187 | CS8427_CBMR | CS8427_DETCI, | ||
188 | /* CS8427_REG_UDATABUF: | ||
189 | Use internal buffer to transmit User (U) data. | ||
190 | Chip's U pin is an output. | ||
191 | Transmit all O's for user data. | ||
192 | Inhibit D->E transfers. | ||
193 | Inhibit E->F transfers. */ | ||
194 | CS8427_UD | CS8427_EFTUI | CS8427_DETUI, | ||
195 | }; | ||
196 | int err; | ||
197 | cs8427_t *chip; | ||
198 | snd_i2c_device_t *device; | ||
199 | unsigned char buf[24]; | ||
200 | |||
201 | if ((err = snd_i2c_device_create(bus, "CS8427", CS8427_ADDR | (addr & 7), &device)) < 0) | ||
202 | return err; | ||
203 | chip = device->private_data = kcalloc(1, sizeof(*chip), GFP_KERNEL); | ||
204 | if (chip == NULL) { | ||
205 | snd_i2c_device_free(device); | ||
206 | return -ENOMEM; | ||
207 | } | ||
208 | device->private_free = snd_cs8427_free; | ||
209 | |||
210 | snd_i2c_lock(bus); | ||
211 | if ((err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER)) != CS8427_VER8427A) { | ||
212 | snd_i2c_unlock(bus); | ||
213 | snd_printk("unable to find CS8427 signature (expected 0x%x, read 0x%x), initialization is not completed\n", CS8427_VER8427A, err); | ||
214 | return -EFAULT; | ||
215 | } | ||
216 | /* turn off run bit while making changes to configuration */ | ||
217 | if ((err = snd_cs8427_reg_write(device, CS8427_REG_CLOCKSOURCE, 0x00)) < 0) | ||
218 | goto __fail; | ||
219 | /* send initial values */ | ||
220 | memcpy(chip->regmap + (initvals1[0] & 0x7f), initvals1 + 1, 6); | ||
221 | if ((err = snd_i2c_sendbytes(device, initvals1, 7)) != 7) { | ||
222 | err = err < 0 ? err : -EIO; | ||
223 | goto __fail; | ||
224 | } | ||
225 | /* Turn off CS8427 interrupt stuff that is not used in hardware */ | ||
226 | memset(buf, 0, 7); | ||
227 | /* from address 9 to 15 */ | ||
228 | buf[0] = 9; /* register */ | ||
229 | if ((err = snd_i2c_sendbytes(device, buf, 7)) != 7) | ||
230 | goto __fail; | ||
231 | /* send transfer initialization sequence */ | ||
232 | memcpy(chip->regmap + (initvals2[0] & 0x7f), initvals2 + 1, 3); | ||
233 | if ((err = snd_i2c_sendbytes(device, initvals2, 4)) != 4) { | ||
234 | err = err < 0 ? err : -EIO; | ||
235 | goto __fail; | ||
236 | } | ||
237 | /* write default channel status bytes */ | ||
238 | buf[0] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 0)); | ||
239 | buf[1] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 8)); | ||
240 | buf[2] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 16)); | ||
241 | buf[3] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 24)); | ||
242 | memset(buf + 4, 0, 24 - 4); | ||
243 | if (snd_cs8427_send_corudata(device, 0, buf, 24) < 0) | ||
244 | goto __fail; | ||
245 | memcpy(chip->playback.def_status, buf, 24); | ||
246 | memcpy(chip->playback.pcm_status, buf, 24); | ||
247 | snd_i2c_unlock(bus); | ||
248 | |||
249 | /* turn on run bit and rock'n'roll */ | ||
250 | if (reset_timeout < 1) | ||
251 | reset_timeout = 1; | ||
252 | chip->reset_timeout = reset_timeout; | ||
253 | snd_cs8427_reset(device); | ||
254 | |||
255 | #if 0 // it's nice for read tests | ||
256 | { | ||
257 | char buf[128]; | ||
258 | int xx; | ||
259 | buf[0] = 0x81; | ||
260 | snd_i2c_sendbytes(device, buf, 1); | ||
261 | snd_i2c_readbytes(device, buf, 127); | ||
262 | for (xx = 0; xx < 127; xx++) | ||
263 | printk("reg[0x%x] = 0x%x\n", xx+1, buf[xx]); | ||
264 | } | ||
265 | #endif | ||
266 | |||
267 | if (r_cs8427) | ||
268 | *r_cs8427 = device; | ||
269 | return 0; | ||
270 | |||
271 | __fail: | ||
272 | snd_i2c_unlock(bus); | ||
273 | snd_i2c_device_free(device); | ||
274 | return err < 0 ? err : -EIO; | ||
275 | } | ||
276 | |||
277 | /* | ||
278 | * Reset the chip using run bit, also lock PLL using ILRCK and | ||
279 | * put back AES3INPUT. This workaround is described in latest | ||
280 | * CS8427 datasheet, otherwise TXDSERIAL will not work. | ||
281 | */ | ||
282 | static void snd_cs8427_reset(snd_i2c_device_t *cs8427) | ||
283 | { | ||
284 | cs8427_t *chip; | ||
285 | unsigned long end_time; | ||
286 | int data; | ||
287 | |||
288 | snd_assert(cs8427, return); | ||
289 | chip = cs8427->private_data; | ||
290 | snd_i2c_lock(cs8427->bus); | ||
291 | chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~(CS8427_RUN | CS8427_RXDMASK); | ||
292 | snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]); | ||
293 | udelay(200); | ||
294 | chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RUN | CS8427_RXDILRCK; | ||
295 | snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]); | ||
296 | udelay(200); | ||
297 | snd_i2c_unlock(cs8427->bus); | ||
298 | end_time = jiffies + chip->reset_timeout; | ||
299 | while (time_after_eq(end_time, jiffies)) { | ||
300 | snd_i2c_lock(cs8427->bus); | ||
301 | data = snd_cs8427_reg_read(cs8427, CS8427_REG_RECVERRORS); | ||
302 | snd_i2c_unlock(cs8427->bus); | ||
303 | if (!(data & CS8427_UNLOCK)) | ||
304 | break; | ||
305 | set_current_state(TASK_UNINTERRUPTIBLE); | ||
306 | schedule_timeout(1); | ||
307 | } | ||
308 | snd_i2c_lock(cs8427->bus); | ||
309 | chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK; | ||
310 | chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RXDAES3INPUT; | ||
311 | snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]); | ||
312 | snd_i2c_unlock(cs8427->bus); | ||
313 | } | ||
314 | |||
315 | static int snd_cs8427_in_status_info(snd_kcontrol_t *kcontrol, | ||
316 | snd_ctl_elem_info_t *uinfo) | ||
317 | { | ||
318 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
319 | uinfo->count = 1; | ||
320 | uinfo->value.integer.min = 0; | ||
321 | uinfo->value.integer.max = 255; | ||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | static int snd_cs8427_in_status_get(snd_kcontrol_t *kcontrol, | ||
326 | snd_ctl_elem_value_t *ucontrol) | ||
327 | { | ||
328 | snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); | ||
329 | int data; | ||
330 | |||
331 | snd_i2c_lock(device->bus); | ||
332 | data = snd_cs8427_reg_read(device, kcontrol->private_value); | ||
333 | snd_i2c_unlock(device->bus); | ||
334 | if (data < 0) | ||
335 | return data; | ||
336 | ucontrol->value.integer.value[0] = data; | ||
337 | return 0; | ||
338 | } | ||
339 | |||
340 | static int snd_cs8427_qsubcode_info(snd_kcontrol_t *kcontrol, | ||
341 | snd_ctl_elem_info_t *uinfo) | ||
342 | { | ||
343 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; | ||
344 | uinfo->count = 10; | ||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | static int snd_cs8427_qsubcode_get(snd_kcontrol_t *kcontrol, | ||
349 | snd_ctl_elem_value_t *ucontrol) | ||
350 | { | ||
351 | snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); | ||
352 | unsigned char reg = CS8427_REG_QSUBCODE; | ||
353 | int err; | ||
354 | |||
355 | snd_i2c_lock(device->bus); | ||
356 | if ((err = snd_i2c_sendbytes(device, ®, 1)) != 1) { | ||
357 | snd_printk("unable to send register 0x%x byte to CS8427\n", reg); | ||
358 | snd_i2c_unlock(device->bus); | ||
359 | return err < 0 ? err : -EIO; | ||
360 | } | ||
361 | if ((err = snd_i2c_readbytes(device, ucontrol->value.bytes.data, 10)) != 10) { | ||
362 | snd_printk("unable to read Q-subcode bytes from CS8427\n"); | ||
363 | snd_i2c_unlock(device->bus); | ||
364 | return err < 0 ? err : -EIO; | ||
365 | } | ||
366 | snd_i2c_unlock(device->bus); | ||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static int snd_cs8427_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
371 | { | ||
372 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | ||
373 | uinfo->count = 1; | ||
374 | return 0; | ||
375 | } | ||
376 | |||
377 | static int snd_cs8427_spdif_get(snd_kcontrol_t * kcontrol, | ||
378 | snd_ctl_elem_value_t * ucontrol) | ||
379 | { | ||
380 | snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); | ||
381 | cs8427_t *chip = device->private_data; | ||
382 | |||
383 | snd_i2c_lock(device->bus); | ||
384 | memcpy(ucontrol->value.iec958.status, chip->playback.def_status, 24); | ||
385 | snd_i2c_unlock(device->bus); | ||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | static int snd_cs8427_spdif_put(snd_kcontrol_t * kcontrol, | ||
390 | snd_ctl_elem_value_t * ucontrol) | ||
391 | { | ||
392 | snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); | ||
393 | cs8427_t *chip = device->private_data; | ||
394 | unsigned char *status = kcontrol->private_value ? chip->playback.pcm_status : chip->playback.def_status; | ||
395 | snd_pcm_runtime_t *runtime = chip->playback.substream ? chip->playback.substream->runtime : NULL; | ||
396 | int err, change; | ||
397 | |||
398 | snd_i2c_lock(device->bus); | ||
399 | change = memcmp(ucontrol->value.iec958.status, status, 24) != 0; | ||
400 | memcpy(status, ucontrol->value.iec958.status, 24); | ||
401 | if (change && (kcontrol->private_value ? runtime != NULL : runtime == NULL)) { | ||
402 | err = snd_cs8427_send_corudata(device, 0, status, 24); | ||
403 | if (err < 0) | ||
404 | change = err; | ||
405 | } | ||
406 | snd_i2c_unlock(device->bus); | ||
407 | return change; | ||
408 | } | ||
409 | |||
410 | static int snd_cs8427_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
411 | { | ||
412 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | ||
413 | uinfo->count = 1; | ||
414 | return 0; | ||
415 | } | ||
416 | |||
417 | static int snd_cs8427_spdif_mask_get(snd_kcontrol_t * kcontrol, | ||
418 | snd_ctl_elem_value_t * ucontrol) | ||
419 | { | ||
420 | memset(ucontrol->value.iec958.status, 0xff, 24); | ||
421 | return 0; | ||
422 | } | ||
423 | |||
424 | static snd_kcontrol_new_t snd_cs8427_iec958_controls[] = { | ||
425 | { | ||
426 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
427 | .info = snd_cs8427_in_status_info, | ||
428 | .name = "IEC958 CS8427 Input Status", | ||
429 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
430 | .get = snd_cs8427_in_status_get, | ||
431 | .private_value = 15, | ||
432 | }, | ||
433 | { | ||
434 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
435 | .info = snd_cs8427_in_status_info, | ||
436 | .name = "IEC958 CS8427 Error Status", | ||
437 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
438 | .get = snd_cs8427_in_status_get, | ||
439 | .private_value = 16, | ||
440 | }, | ||
441 | { | ||
442 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
443 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
444 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), | ||
445 | .info = snd_cs8427_spdif_mask_info, | ||
446 | .get = snd_cs8427_spdif_mask_get, | ||
447 | }, | ||
448 | { | ||
449 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
450 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), | ||
451 | .info = snd_cs8427_spdif_info, | ||
452 | .get = snd_cs8427_spdif_get, | ||
453 | .put = snd_cs8427_spdif_put, | ||
454 | .private_value = 0 | ||
455 | }, | ||
456 | { | ||
457 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, | ||
458 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
459 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), | ||
460 | .info = snd_cs8427_spdif_info, | ||
461 | .get = snd_cs8427_spdif_get, | ||
462 | .put = snd_cs8427_spdif_put, | ||
463 | .private_value = 1 | ||
464 | }, | ||
465 | { | ||
466 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
467 | .info = snd_cs8427_qsubcode_info, | ||
468 | .name = "IEC958 Q-subcode Capture Default", | ||
469 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
470 | .get = snd_cs8427_qsubcode_get | ||
471 | }}; | ||
472 | |||
473 | int snd_cs8427_iec958_build(snd_i2c_device_t *cs8427, | ||
474 | snd_pcm_substream_t *play_substream, | ||
475 | snd_pcm_substream_t *cap_substream) | ||
476 | { | ||
477 | cs8427_t *chip = cs8427->private_data; | ||
478 | snd_kcontrol_t *kctl; | ||
479 | unsigned int idx; | ||
480 | int err; | ||
481 | |||
482 | snd_assert(play_substream && cap_substream, return -EINVAL); | ||
483 | for (idx = 0; idx < ARRAY_SIZE(snd_cs8427_iec958_controls); idx++) { | ||
484 | kctl = snd_ctl_new1(&snd_cs8427_iec958_controls[idx], cs8427); | ||
485 | if (kctl == NULL) | ||
486 | return -ENOMEM; | ||
487 | kctl->id.device = play_substream->pcm->device; | ||
488 | kctl->id.subdevice = play_substream->number; | ||
489 | err = snd_ctl_add(cs8427->bus->card, kctl); | ||
490 | if (err < 0) | ||
491 | return err; | ||
492 | if (!strcmp(kctl->id.name, SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM))) | ||
493 | chip->playback.pcm_ctl = kctl; | ||
494 | } | ||
495 | |||
496 | chip->playback.substream = play_substream; | ||
497 | chip->capture.substream = cap_substream; | ||
498 | snd_assert(chip->playback.pcm_ctl, return -EIO); | ||
499 | return 0; | ||
500 | } | ||
501 | |||
502 | int snd_cs8427_iec958_active(snd_i2c_device_t *cs8427, int active) | ||
503 | { | ||
504 | cs8427_t *chip; | ||
505 | |||
506 | snd_assert(cs8427, return -ENXIO); | ||
507 | chip = cs8427->private_data; | ||
508 | if (active) | ||
509 | memcpy(chip->playback.pcm_status, chip->playback.def_status, 24); | ||
510 | chip->playback.pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; | ||
511 | snd_ctl_notify(cs8427->bus->card, SNDRV_CTL_EVENT_MASK_VALUE | | ||
512 | SNDRV_CTL_EVENT_MASK_INFO, &chip->playback.pcm_ctl->id); | ||
513 | return 0; | ||
514 | } | ||
515 | |||
516 | int snd_cs8427_iec958_pcm(snd_i2c_device_t *cs8427, unsigned int rate) | ||
517 | { | ||
518 | cs8427_t *chip; | ||
519 | char *status; | ||
520 | int err, reset; | ||
521 | |||
522 | snd_assert(cs8427, return -ENXIO); | ||
523 | chip = cs8427->private_data; | ||
524 | status = chip->playback.pcm_status; | ||
525 | snd_i2c_lock(cs8427->bus); | ||
526 | if (status[0] & IEC958_AES0_PROFESSIONAL) { | ||
527 | status[0] &= ~IEC958_AES0_PRO_FS; | ||
528 | switch (rate) { | ||
529 | case 32000: status[0] |= IEC958_AES0_PRO_FS_32000; break; | ||
530 | case 44100: status[0] |= IEC958_AES0_PRO_FS_44100; break; | ||
531 | case 48000: status[0] |= IEC958_AES0_PRO_FS_48000; break; | ||
532 | default: status[0] |= IEC958_AES0_PRO_FS_NOTID; break; | ||
533 | } | ||
534 | } else { | ||
535 | status[3] &= ~IEC958_AES3_CON_FS; | ||
536 | switch (rate) { | ||
537 | case 32000: status[3] |= IEC958_AES3_CON_FS_32000; break; | ||
538 | case 44100: status[3] |= IEC958_AES3_CON_FS_44100; break; | ||
539 | case 48000: status[3] |= IEC958_AES3_CON_FS_48000; break; | ||
540 | } | ||
541 | } | ||
542 | err = snd_cs8427_send_corudata(cs8427, 0, status, 24); | ||
543 | if (err > 0) | ||
544 | snd_ctl_notify(cs8427->bus->card, | ||
545 | SNDRV_CTL_EVENT_MASK_VALUE, | ||
546 | &chip->playback.pcm_ctl->id); | ||
547 | reset = chip->rate != rate; | ||
548 | chip->rate = rate; | ||
549 | snd_i2c_unlock(cs8427->bus); | ||
550 | if (reset) | ||
551 | snd_cs8427_reset(cs8427); | ||
552 | return err < 0 ? err : 0; | ||
553 | } | ||
554 | |||
555 | static int __init alsa_cs8427_module_init(void) | ||
556 | { | ||
557 | return 0; | ||
558 | } | ||
559 | |||
560 | static void __exit alsa_cs8427_module_exit(void) | ||
561 | { | ||
562 | } | ||
563 | |||
564 | module_init(alsa_cs8427_module_init) | ||
565 | module_exit(alsa_cs8427_module_exit) | ||
566 | |||
567 | EXPORT_SYMBOL(snd_cs8427_create); | ||
568 | EXPORT_SYMBOL(snd_cs8427_reset); | ||
569 | EXPORT_SYMBOL(snd_cs8427_reg_write); | ||
570 | EXPORT_SYMBOL(snd_cs8427_iec958_build); | ||
571 | EXPORT_SYMBOL(snd_cs8427_iec958_active); | ||
572 | EXPORT_SYMBOL(snd_cs8427_iec958_pcm); | ||
diff --git a/sound/i2c/i2c.c b/sound/i2c/i2c.c new file mode 100644 index 000000000000..e8fa7e1a68e8 --- /dev/null +++ b/sound/i2c/i2c.c | |||
@@ -0,0 +1,333 @@ | |||
1 | /* | ||
2 | * Generic i2c interface for ALSA | ||
3 | * | ||
4 | * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> | ||
5 | * Modified for the ALSA driver by Jaroslav Kysela <perex@suse.cz> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <sound/driver.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/string.h> | ||
27 | #include <linux/errno.h> | ||
28 | #include <sound/core.h> | ||
29 | #include <sound/i2c.h> | ||
30 | |||
31 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
32 | MODULE_DESCRIPTION("Generic i2c interface for ALSA"); | ||
33 | MODULE_LICENSE("GPL"); | ||
34 | |||
35 | static int snd_i2c_bit_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count); | ||
36 | static int snd_i2c_bit_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count); | ||
37 | static int snd_i2c_bit_probeaddr(snd_i2c_bus_t *bus, unsigned short addr); | ||
38 | |||
39 | static snd_i2c_ops_t snd_i2c_bit_ops = { | ||
40 | .sendbytes = snd_i2c_bit_sendbytes, | ||
41 | .readbytes = snd_i2c_bit_readbytes, | ||
42 | .probeaddr = snd_i2c_bit_probeaddr, | ||
43 | }; | ||
44 | |||
45 | static int snd_i2c_bus_free(snd_i2c_bus_t *bus) | ||
46 | { | ||
47 | snd_i2c_bus_t *slave; | ||
48 | snd_i2c_device_t *device; | ||
49 | |||
50 | snd_assert(bus != NULL, return -EINVAL); | ||
51 | while (!list_empty(&bus->devices)) { | ||
52 | device = snd_i2c_device(bus->devices.next); | ||
53 | snd_i2c_device_free(device); | ||
54 | } | ||
55 | if (bus->master) | ||
56 | list_del(&bus->buses); | ||
57 | else { | ||
58 | while (!list_empty(&bus->buses)) { | ||
59 | slave = snd_i2c_slave_bus(bus->buses.next); | ||
60 | snd_device_free(bus->card, slave); | ||
61 | } | ||
62 | } | ||
63 | if (bus->private_free) | ||
64 | bus->private_free(bus); | ||
65 | kfree(bus); | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static int snd_i2c_bus_dev_free(snd_device_t *device) | ||
70 | { | ||
71 | snd_i2c_bus_t *bus = device->device_data; | ||
72 | return snd_i2c_bus_free(bus); | ||
73 | } | ||
74 | |||
75 | int snd_i2c_bus_create(snd_card_t *card, const char *name, snd_i2c_bus_t *master, snd_i2c_bus_t **ri2c) | ||
76 | { | ||
77 | snd_i2c_bus_t *bus; | ||
78 | int err; | ||
79 | static snd_device_ops_t ops = { | ||
80 | .dev_free = snd_i2c_bus_dev_free, | ||
81 | }; | ||
82 | |||
83 | *ri2c = NULL; | ||
84 | bus = kcalloc(1, sizeof(*bus), GFP_KERNEL); | ||
85 | if (bus == NULL) | ||
86 | return -ENOMEM; | ||
87 | init_MUTEX(&bus->lock_mutex); | ||
88 | INIT_LIST_HEAD(&bus->devices); | ||
89 | INIT_LIST_HEAD(&bus->buses); | ||
90 | bus->card = card; | ||
91 | bus->ops = &snd_i2c_bit_ops; | ||
92 | if (master) { | ||
93 | list_add_tail(&bus->buses, &master->buses); | ||
94 | bus->master = master; | ||
95 | } | ||
96 | strlcpy(bus->name, name, sizeof(bus->name)); | ||
97 | if ((err = snd_device_new(card, SNDRV_DEV_BUS, bus, &ops)) < 0) { | ||
98 | snd_i2c_bus_free(bus); | ||
99 | return err; | ||
100 | } | ||
101 | *ri2c = bus; | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | int snd_i2c_device_create(snd_i2c_bus_t *bus, const char *name, unsigned char addr, snd_i2c_device_t **rdevice) | ||
106 | { | ||
107 | snd_i2c_device_t *device; | ||
108 | |||
109 | *rdevice = NULL; | ||
110 | snd_assert(bus != NULL, return -EINVAL); | ||
111 | device = kcalloc(1, sizeof(*device), GFP_KERNEL); | ||
112 | if (device == NULL) | ||
113 | return -ENOMEM; | ||
114 | device->addr = addr; | ||
115 | strlcpy(device->name, name, sizeof(device->name)); | ||
116 | list_add_tail(&device->list, &bus->devices); | ||
117 | device->bus = bus; | ||
118 | *rdevice = device; | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | int snd_i2c_device_free(snd_i2c_device_t *device) | ||
123 | { | ||
124 | if (device->bus) | ||
125 | list_del(&device->list); | ||
126 | if (device->private_free) | ||
127 | device->private_free(device); | ||
128 | kfree(device); | ||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | int snd_i2c_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) | ||
133 | { | ||
134 | return device->bus->ops->sendbytes(device, bytes, count); | ||
135 | } | ||
136 | |||
137 | |||
138 | int snd_i2c_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) | ||
139 | { | ||
140 | return device->bus->ops->readbytes(device, bytes, count); | ||
141 | } | ||
142 | |||
143 | int snd_i2c_probeaddr(snd_i2c_bus_t *bus, unsigned short addr) | ||
144 | { | ||
145 | return bus->ops->probeaddr(bus, addr); | ||
146 | } | ||
147 | |||
148 | /* | ||
149 | * bit-operations | ||
150 | */ | ||
151 | |||
152 | static inline void snd_i2c_bit_hw_start(snd_i2c_bus_t *bus) | ||
153 | { | ||
154 | if (bus->hw_ops.bit->start) | ||
155 | bus->hw_ops.bit->start(bus); | ||
156 | } | ||
157 | |||
158 | static inline void snd_i2c_bit_hw_stop(snd_i2c_bus_t *bus) | ||
159 | { | ||
160 | if (bus->hw_ops.bit->stop) | ||
161 | bus->hw_ops.bit->stop(bus); | ||
162 | } | ||
163 | |||
164 | static void snd_i2c_bit_direction(snd_i2c_bus_t *bus, int clock, int data) | ||
165 | { | ||
166 | if (bus->hw_ops.bit->direction) | ||
167 | bus->hw_ops.bit->direction(bus, clock, data); | ||
168 | } | ||
169 | |||
170 | static void snd_i2c_bit_set(snd_i2c_bus_t *bus, int clock, int data) | ||
171 | { | ||
172 | bus->hw_ops.bit->setlines(bus, clock, data); | ||
173 | } | ||
174 | |||
175 | #if 0 | ||
176 | static int snd_i2c_bit_clock(snd_i2c_bus_t *bus) | ||
177 | { | ||
178 | if (bus->hw_ops.bit->getclock) | ||
179 | return bus->hw_ops.bit->getclock(bus); | ||
180 | return -ENXIO; | ||
181 | } | ||
182 | #endif | ||
183 | |||
184 | static int snd_i2c_bit_data(snd_i2c_bus_t *bus, int ack) | ||
185 | { | ||
186 | return bus->hw_ops.bit->getdata(bus, ack); | ||
187 | } | ||
188 | |||
189 | static void snd_i2c_bit_start(snd_i2c_bus_t *bus) | ||
190 | { | ||
191 | snd_i2c_bit_hw_start(bus); | ||
192 | snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */ | ||
193 | snd_i2c_bit_set(bus, 1, 1); | ||
194 | snd_i2c_bit_set(bus, 1, 0); | ||
195 | snd_i2c_bit_set(bus, 0, 0); | ||
196 | } | ||
197 | |||
198 | static void snd_i2c_bit_stop(snd_i2c_bus_t *bus) | ||
199 | { | ||
200 | snd_i2c_bit_set(bus, 0, 0); | ||
201 | snd_i2c_bit_set(bus, 1, 0); | ||
202 | snd_i2c_bit_set(bus, 1, 1); | ||
203 | snd_i2c_bit_hw_stop(bus); | ||
204 | } | ||
205 | |||
206 | static void snd_i2c_bit_send(snd_i2c_bus_t *bus, int data) | ||
207 | { | ||
208 | snd_i2c_bit_set(bus, 0, data); | ||
209 | snd_i2c_bit_set(bus, 1, data); | ||
210 | snd_i2c_bit_set(bus, 0, data); | ||
211 | } | ||
212 | |||
213 | static int snd_i2c_bit_ack(snd_i2c_bus_t *bus) | ||
214 | { | ||
215 | int ack; | ||
216 | |||
217 | snd_i2c_bit_set(bus, 0, 1); | ||
218 | snd_i2c_bit_set(bus, 1, 1); | ||
219 | snd_i2c_bit_direction(bus, 1, 0); /* SCL - wr, SDA - rd */ | ||
220 | ack = snd_i2c_bit_data(bus, 1); | ||
221 | snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */ | ||
222 | snd_i2c_bit_set(bus, 0, 1); | ||
223 | return ack ? -EIO : 0; | ||
224 | } | ||
225 | |||
226 | static int snd_i2c_bit_sendbyte(snd_i2c_bus_t *bus, unsigned char data) | ||
227 | { | ||
228 | int i, err; | ||
229 | |||
230 | for (i = 7; i >= 0; i--) | ||
231 | snd_i2c_bit_send(bus, !!(data & (1 << i))); | ||
232 | if ((err = snd_i2c_bit_ack(bus)) < 0) | ||
233 | return err; | ||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | static int snd_i2c_bit_readbyte(snd_i2c_bus_t *bus, int last) | ||
238 | { | ||
239 | int i; | ||
240 | unsigned char data = 0; | ||
241 | |||
242 | snd_i2c_bit_set(bus, 0, 1); | ||
243 | snd_i2c_bit_direction(bus, 1, 0); /* SCL - wr, SDA - rd */ | ||
244 | for (i = 7; i >= 0; i--) { | ||
245 | snd_i2c_bit_set(bus, 1, 1); | ||
246 | if (snd_i2c_bit_data(bus, 0)) | ||
247 | data |= (1 << i); | ||
248 | snd_i2c_bit_set(bus, 0, 1); | ||
249 | } | ||
250 | snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */ | ||
251 | snd_i2c_bit_send(bus, !!last); | ||
252 | return data; | ||
253 | } | ||
254 | |||
255 | static int snd_i2c_bit_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) | ||
256 | { | ||
257 | snd_i2c_bus_t *bus = device->bus; | ||
258 | int err, res = 0; | ||
259 | |||
260 | if (device->flags & SND_I2C_DEVICE_ADDRTEN) | ||
261 | return -EIO; /* not yet implemented */ | ||
262 | snd_i2c_bit_start(bus); | ||
263 | if ((err = snd_i2c_bit_sendbyte(bus, device->addr << 1)) < 0) { | ||
264 | snd_i2c_bit_hw_stop(bus); | ||
265 | return err; | ||
266 | } | ||
267 | while (count-- > 0) { | ||
268 | if ((err = snd_i2c_bit_sendbyte(bus, *bytes++)) < 0) { | ||
269 | snd_i2c_bit_hw_stop(bus); | ||
270 | return err; | ||
271 | } | ||
272 | res++; | ||
273 | } | ||
274 | snd_i2c_bit_stop(bus); | ||
275 | return res; | ||
276 | } | ||
277 | |||
278 | static int snd_i2c_bit_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) | ||
279 | { | ||
280 | snd_i2c_bus_t *bus = device->bus; | ||
281 | int err, res = 0; | ||
282 | |||
283 | if (device->flags & SND_I2C_DEVICE_ADDRTEN) | ||
284 | return -EIO; /* not yet implemented */ | ||
285 | snd_i2c_bit_start(bus); | ||
286 | if ((err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1)) < 0) { | ||
287 | snd_i2c_bit_hw_stop(bus); | ||
288 | return err; | ||
289 | } | ||
290 | while (count-- > 0) { | ||
291 | if ((err = snd_i2c_bit_readbyte(bus, count == 0)) < 0) { | ||
292 | snd_i2c_bit_hw_stop(bus); | ||
293 | return err; | ||
294 | } | ||
295 | *bytes++ = (unsigned char)err; | ||
296 | res++; | ||
297 | } | ||
298 | snd_i2c_bit_stop(bus); | ||
299 | return res; | ||
300 | } | ||
301 | |||
302 | static int snd_i2c_bit_probeaddr(snd_i2c_bus_t *bus, unsigned short addr) | ||
303 | { | ||
304 | int err; | ||
305 | |||
306 | if (addr & 0x8000) /* 10-bit address */ | ||
307 | return -EIO; /* not yet implemented */ | ||
308 | if (addr & 0x7f80) /* invalid address */ | ||
309 | return -EINVAL; | ||
310 | snd_i2c_bit_start(bus); | ||
311 | err = snd_i2c_bit_sendbyte(bus, addr << 1); | ||
312 | snd_i2c_bit_stop(bus); | ||
313 | return err; | ||
314 | } | ||
315 | |||
316 | EXPORT_SYMBOL(snd_i2c_bus_create); | ||
317 | EXPORT_SYMBOL(snd_i2c_device_create); | ||
318 | EXPORT_SYMBOL(snd_i2c_device_free); | ||
319 | EXPORT_SYMBOL(snd_i2c_sendbytes); | ||
320 | EXPORT_SYMBOL(snd_i2c_readbytes); | ||
321 | EXPORT_SYMBOL(snd_i2c_probeaddr); | ||
322 | |||
323 | static int __init alsa_i2c_init(void) | ||
324 | { | ||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static void __exit alsa_i2c_exit(void) | ||
329 | { | ||
330 | } | ||
331 | |||
332 | module_init(alsa_i2c_init) | ||
333 | module_exit(alsa_i2c_exit) | ||
diff --git a/sound/i2c/l3/Makefile b/sound/i2c/l3/Makefile new file mode 100644 index 000000000000..49455b8dcc04 --- /dev/null +++ b/sound/i2c/l3/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # | ||
2 | # Makefile for ALSA | ||
3 | # | ||
4 | |||
5 | snd-uda1341-objs := uda1341.o | ||
6 | |||
7 | # Module Dependency | ||
8 | obj-$(CONFIG_SND_SA11XX_UDA1341) += snd-uda1341.o | ||
diff --git a/sound/i2c/l3/uda1341.c b/sound/i2c/l3/uda1341.c new file mode 100644 index 000000000000..e13122f3fc50 --- /dev/null +++ b/sound/i2c/l3/uda1341.c | |||
@@ -0,0 +1,830 @@ | |||
1 | /* | ||
2 | * Philips UDA1341 mixer device driver | ||
3 | * Copyright (c) 2002 Tomas Kasparek <tomas.kasparek@seznam.cz> | ||
4 | * | ||
5 | * Portions are Copyright (C) 2000 Lernout & Hauspie Speech Products, N.V. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License. | ||
9 | * | ||
10 | * History: | ||
11 | * | ||
12 | * 2002-03-13 Tomas Kasparek initial release - based on uda1341.c from OSS | ||
13 | * 2002-03-28 Tomas Kasparek basic mixer is working (volume, bass, treble) | ||
14 | * 2002-03-30 Tomas Kasparek proc filesystem support, complete mixer and DSP | ||
15 | * features support | ||
16 | * 2002-04-12 Tomas Kasparek proc interface update, code cleanup | ||
17 | * 2002-05-12 Tomas Kasparek another code cleanup | ||
18 | */ | ||
19 | |||
20 | /* $Id: uda1341.c,v 1.15 2005/01/03 12:05:20 tiwai Exp $ */ | ||
21 | |||
22 | #include <sound/driver.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/types.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/errno.h> | ||
28 | #include <linux/ioctl.h> | ||
29 | |||
30 | #include <asm/uaccess.h> | ||
31 | |||
32 | #include <sound/core.h> | ||
33 | #include <sound/control.h> | ||
34 | #include <sound/initval.h> | ||
35 | #include <sound/info.h> | ||
36 | |||
37 | #include <linux/l3/l3.h> | ||
38 | |||
39 | #include <sound/uda1341.h> | ||
40 | |||
41 | /* {{{ HW regs definition */ | ||
42 | |||
43 | #define STAT0 0x00 | ||
44 | #define STAT1 0x80 | ||
45 | #define STAT_MASK 0x80 | ||
46 | |||
47 | #define DATA0_0 0x00 | ||
48 | #define DATA0_1 0x40 | ||
49 | #define DATA0_2 0x80 | ||
50 | #define DATA_MASK 0xc0 | ||
51 | |||
52 | #define IS_DATA0(x) ((x) >= data0_0 && (x) <= data0_2) | ||
53 | #define IS_DATA1(x) ((x) == data1) | ||
54 | #define IS_STATUS(x) ((x) == stat0 || (x) == stat1) | ||
55 | #define IS_EXTEND(x) ((x) >= ext0 && (x) <= ext6) | ||
56 | |||
57 | /* }}} */ | ||
58 | |||
59 | enum uda1341_regs_names { | ||
60 | stat0, | ||
61 | stat1, | ||
62 | data0_0, | ||
63 | data0_1, | ||
64 | data0_2, | ||
65 | data1, | ||
66 | ext0, | ||
67 | ext1, | ||
68 | ext2, | ||
69 | empty, | ||
70 | ext4, | ||
71 | ext5, | ||
72 | ext6, | ||
73 | uda1341_reg_last, | ||
74 | }; | ||
75 | |||
76 | const char *uda1341_reg_names[] = { | ||
77 | "stat 0 ", | ||
78 | "stat 1 ", | ||
79 | "data 00", | ||
80 | "data 01", | ||
81 | "data 02", | ||
82 | "data 1 ", | ||
83 | "ext 0", | ||
84 | "ext 1", | ||
85 | "ext 2", | ||
86 | "empty", | ||
87 | "ext 4", | ||
88 | "ext 5", | ||
89 | "ext 6", | ||
90 | }; | ||
91 | |||
92 | const int uda1341_enum_items[] = { | ||
93 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
94 | 2, //peak - before/after | ||
95 | 4, //deemp - none/32/44.1/48 | ||
96 | 0, | ||
97 | 4, //filter - flat/min/min/max | ||
98 | 0, 0, 0, | ||
99 | 4, //mixer - differ/line/mic/mixer | ||
100 | 0, 0, 0, 0, 0, | ||
101 | }; | ||
102 | |||
103 | const char ** uda1341_enum_names[] = { | ||
104 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | ||
105 | peak_names, //peak - before/after | ||
106 | deemp_names, //deemp - none/32/44.1/48 | ||
107 | NULL, | ||
108 | filter_names, //filter - flat/min/min/max | ||
109 | NULL, NULL, NULL, | ||
110 | mixer_names, //mixer - differ/line/mic/mixer | ||
111 | NULL, NULL, NULL, NULL, NULL, | ||
112 | }; | ||
113 | |||
114 | typedef int uda1341_cfg[CMD_LAST]; | ||
115 | |||
116 | typedef struct uda1341 uda1341_t; | ||
117 | |||
118 | struct uda1341 { | ||
119 | int (*write) (struct l3_client *uda1341, unsigned short reg, unsigned short val); | ||
120 | int (*read) (struct l3_client *uda1341, unsigned short reg); | ||
121 | unsigned char regs[uda1341_reg_last]; | ||
122 | int active; | ||
123 | spinlock_t reg_lock; | ||
124 | snd_card_t *card; | ||
125 | uda1341_cfg cfg; | ||
126 | #ifdef CONFIG_PM | ||
127 | unsigned char suspend_regs[uda1341_reg_last]; | ||
128 | uda1341_cfg suspend_cfg; | ||
129 | #endif | ||
130 | }; | ||
131 | |||
132 | //hack for ALSA magic casting | ||
133 | typedef struct l3_client l3_client_t; | ||
134 | |||
135 | /* transfer 8bit integer into string with binary representation */ | ||
136 | void int2str_bin8(uint8_t val, char *buf){ | ||
137 | const int size = sizeof(val) * 8; | ||
138 | int i; | ||
139 | |||
140 | for (i= 0; i < size; i++){ | ||
141 | *(buf++) = (val >> (size - 1)) ? '1' : '0'; | ||
142 | val <<= 1; | ||
143 | } | ||
144 | *buf = '\0'; //end the string with zero | ||
145 | } | ||
146 | |||
147 | /* {{{ HW manipulation routines */ | ||
148 | |||
149 | int snd_uda1341_codec_write(struct l3_client *clnt, unsigned short reg, unsigned short val) | ||
150 | { | ||
151 | struct uda1341 *uda = clnt->driver_data; | ||
152 | unsigned char buf[2] = { 0xc0, 0xe0 }; // for EXT addressing | ||
153 | int err = 0; | ||
154 | |||
155 | uda->regs[reg] = val; | ||
156 | |||
157 | if (uda->active) { | ||
158 | if (IS_DATA0(reg)) { | ||
159 | err = l3_write(clnt, UDA1341_DATA0, (const unsigned char *)&val, 1); | ||
160 | } else if (IS_DATA1(reg)) { | ||
161 | err = l3_write(clnt, UDA1341_DATA1, (const unsigned char *)&val, 1); | ||
162 | } else if (IS_STATUS(reg)) { | ||
163 | err = l3_write(clnt, UDA1341_STATUS, (const unsigned char *)&val, 1); | ||
164 | } else if (IS_EXTEND(reg)) { | ||
165 | buf[0] |= (reg - ext0) & 0x7; //EXT address | ||
166 | buf[1] |= val; //EXT data | ||
167 | err = l3_write(clnt, UDA1341_DATA0, (const unsigned char *)buf, 2); | ||
168 | } | ||
169 | } else | ||
170 | printk(KERN_ERR "UDA1341 codec not active!\n"); | ||
171 | return err; | ||
172 | } | ||
173 | |||
174 | int snd_uda1341_codec_read(struct l3_client *clnt, unsigned short reg) | ||
175 | { | ||
176 | unsigned char val; | ||
177 | int err; | ||
178 | |||
179 | err = l3_read(clnt, reg, &val, 1); | ||
180 | if (err == 1) | ||
181 | // use just 6bits - the rest is address of the reg | ||
182 | return val & 63; | ||
183 | return err < 0 ? err : -EIO; | ||
184 | } | ||
185 | |||
186 | static inline int snd_uda1341_valid_reg(struct l3_client *clnt, unsigned short reg) | ||
187 | { | ||
188 | return reg < uda1341_reg_last; | ||
189 | } | ||
190 | |||
191 | int snd_uda1341_update_bits(struct l3_client *clnt, unsigned short reg, unsigned short mask, | ||
192 | unsigned short shift, unsigned short value, int flush) | ||
193 | { | ||
194 | int change; | ||
195 | unsigned short old, new; | ||
196 | struct uda1341 *uda = clnt->driver_data; | ||
197 | |||
198 | #if 0 | ||
199 | printk(KERN_DEBUG "update_bits: reg: %s mask: %d shift: %d val: %d\n", | ||
200 | uda1341_reg_names[reg], mask, shift, value); | ||
201 | #endif | ||
202 | |||
203 | if (!snd_uda1341_valid_reg(clnt, reg)) | ||
204 | return -EINVAL; | ||
205 | spin_lock(&uda->reg_lock); | ||
206 | old = uda->regs[reg]; | ||
207 | new = (old & ~(mask << shift)) | (value << shift); | ||
208 | change = old != new; | ||
209 | if (change) { | ||
210 | if (flush) uda->write(clnt, reg, new); | ||
211 | uda->regs[reg] = new; | ||
212 | } | ||
213 | spin_unlock(&uda->reg_lock); | ||
214 | return change; | ||
215 | } | ||
216 | |||
217 | int snd_uda1341_cfg_write(struct l3_client *clnt, unsigned short what, | ||
218 | unsigned short value, int flush) | ||
219 | { | ||
220 | struct uda1341 *uda = clnt->driver_data; | ||
221 | int ret = 0; | ||
222 | #ifdef CONFIG_PM | ||
223 | int reg; | ||
224 | #endif | ||
225 | |||
226 | #if 0 | ||
227 | printk(KERN_DEBUG "cfg_write what: %d value: %d\n", what, value); | ||
228 | #endif | ||
229 | |||
230 | uda->cfg[what] = value; | ||
231 | |||
232 | switch(what) { | ||
233 | case CMD_RESET: | ||
234 | ret = snd_uda1341_update_bits(clnt, data0_2, 1, 2, 1, flush); // MUTE | ||
235 | ret = snd_uda1341_update_bits(clnt, stat0, 1, 6, 1, flush); // RESET | ||
236 | ret = snd_uda1341_update_bits(clnt, stat0, 1, 6, 0, flush); // RESTORE | ||
237 | uda->cfg[CMD_RESET]=0; | ||
238 | break; | ||
239 | case CMD_FS: | ||
240 | ret = snd_uda1341_update_bits(clnt, stat0, 3, 4, value, flush); | ||
241 | break; | ||
242 | case CMD_FORMAT: | ||
243 | ret = snd_uda1341_update_bits(clnt, stat0, 7, 1, value, flush); | ||
244 | break; | ||
245 | case CMD_OGAIN: | ||
246 | ret = snd_uda1341_update_bits(clnt, stat1, 1, 6, value, flush); | ||
247 | break; | ||
248 | case CMD_IGAIN: | ||
249 | ret = snd_uda1341_update_bits(clnt, stat1, 1, 5, value, flush); | ||
250 | break; | ||
251 | case CMD_DAC: | ||
252 | ret = snd_uda1341_update_bits(clnt, stat1, 1, 0, value, flush); | ||
253 | break; | ||
254 | case CMD_ADC: | ||
255 | ret = snd_uda1341_update_bits(clnt, stat1, 1, 1, value, flush); | ||
256 | break; | ||
257 | case CMD_VOLUME: | ||
258 | ret = snd_uda1341_update_bits(clnt, data0_0, 63, 0, value, flush); | ||
259 | break; | ||
260 | case CMD_BASS: | ||
261 | ret = snd_uda1341_update_bits(clnt, data0_1, 15, 2, value, flush); | ||
262 | break; | ||
263 | case CMD_TREBBLE: | ||
264 | ret = snd_uda1341_update_bits(clnt, data0_1, 3, 0, value, flush); | ||
265 | break; | ||
266 | case CMD_PEAK: | ||
267 | ret = snd_uda1341_update_bits(clnt, data0_2, 1, 5, value, flush); | ||
268 | break; | ||
269 | case CMD_DEEMP: | ||
270 | ret = snd_uda1341_update_bits(clnt, data0_2, 3, 3, value, flush); | ||
271 | break; | ||
272 | case CMD_MUTE: | ||
273 | ret = snd_uda1341_update_bits(clnt, data0_2, 1, 2, value, flush); | ||
274 | break; | ||
275 | case CMD_FILTER: | ||
276 | ret = snd_uda1341_update_bits(clnt, data0_2, 3, 0, value, flush); | ||
277 | break; | ||
278 | case CMD_CH1: | ||
279 | ret = snd_uda1341_update_bits(clnt, ext0, 31, 0, value, flush); | ||
280 | break; | ||
281 | case CMD_CH2: | ||
282 | ret = snd_uda1341_update_bits(clnt, ext1, 31, 0, value, flush); | ||
283 | break; | ||
284 | case CMD_MIC: | ||
285 | ret = snd_uda1341_update_bits(clnt, ext2, 7, 2, value, flush); | ||
286 | break; | ||
287 | case CMD_MIXER: | ||
288 | ret = snd_uda1341_update_bits(clnt, ext2, 3, 0, value, flush); | ||
289 | break; | ||
290 | case CMD_AGC: | ||
291 | ret = snd_uda1341_update_bits(clnt, ext4, 1, 4, value, flush); | ||
292 | break; | ||
293 | case CMD_IG: | ||
294 | ret = snd_uda1341_update_bits(clnt, ext4, 3, 0, value & 0x3, flush); | ||
295 | ret = snd_uda1341_update_bits(clnt, ext5, 31, 0, value >> 2, flush); | ||
296 | break; | ||
297 | case CMD_AGC_TIME: | ||
298 | ret = snd_uda1341_update_bits(clnt, ext6, 7, 2, value, flush); | ||
299 | break; | ||
300 | case CMD_AGC_LEVEL: | ||
301 | ret = snd_uda1341_update_bits(clnt, ext6, 3, 0, value, flush); | ||
302 | break; | ||
303 | #ifdef CONFIG_PM | ||
304 | case CMD_SUSPEND: | ||
305 | for (reg = stat0; reg < uda1341_reg_last; reg++) | ||
306 | uda->suspend_regs[reg] = uda->regs[reg]; | ||
307 | for (reg = 0; reg < CMD_LAST; reg++) | ||
308 | uda->suspend_cfg[reg] = uda->cfg[reg]; | ||
309 | break; | ||
310 | case CMD_RESUME: | ||
311 | for (reg = stat0; reg < uda1341_reg_last; reg++) | ||
312 | snd_uda1341_codec_write(clnt, reg, uda->suspend_regs[reg]); | ||
313 | for (reg = 0; reg < CMD_LAST; reg++) | ||
314 | uda->cfg[reg] = uda->suspend_cfg[reg]; | ||
315 | break; | ||
316 | #endif | ||
317 | default: | ||
318 | ret = -EINVAL; | ||
319 | break; | ||
320 | } | ||
321 | |||
322 | if (!uda->active) | ||
323 | printk(KERN_ERR "UDA1341 codec not active!\n"); | ||
324 | return ret; | ||
325 | } | ||
326 | |||
327 | /* }}} */ | ||
328 | |||
329 | /* {{{ Proc interface */ | ||
330 | |||
331 | static void snd_uda1341_proc_read(snd_info_entry_t *entry, | ||
332 | snd_info_buffer_t * buffer) | ||
333 | { | ||
334 | struct l3_client *clnt = entry->private_data; | ||
335 | struct uda1341 *uda = clnt->driver_data; | ||
336 | int peak; | ||
337 | |||
338 | peak = snd_uda1341_codec_read(clnt, UDA1341_DATA1); | ||
339 | if (peak < 0) | ||
340 | peak = 0; | ||
341 | |||
342 | snd_iprintf(buffer, "%s\n\n", uda->card->longname); | ||
343 | |||
344 | // for information about computed values see UDA1341TS datasheet pages 15 - 21 | ||
345 | snd_iprintf(buffer, "DAC power : %s\n", uda->cfg[CMD_DAC] ? "on" : "off"); | ||
346 | snd_iprintf(buffer, "ADC power : %s\n", uda->cfg[CMD_ADC] ? "on" : "off"); | ||
347 | snd_iprintf(buffer, "Clock frequency : %s\n", fs_names[uda->cfg[CMD_FS]]); | ||
348 | snd_iprintf(buffer, "Data format : %s\n\n", format_names[uda->cfg[CMD_FORMAT]]); | ||
349 | |||
350 | snd_iprintf(buffer, "Filter mode : %s\n", filter_names[uda->cfg[CMD_FILTER]]); | ||
351 | snd_iprintf(buffer, "Mixer mode : %s\n", mixer_names[uda->cfg[CMD_MIXER]]); | ||
352 | snd_iprintf(buffer, "De-emphasis : %s\n", deemp_names[uda->cfg[CMD_DEEMP]]); | ||
353 | snd_iprintf(buffer, "Peak detection pos. : %s\n", uda->cfg[CMD_PEAK] ? "after" : "before"); | ||
354 | snd_iprintf(buffer, "Peak value : %s\n\n", peak_value[peak]); | ||
355 | |||
356 | snd_iprintf(buffer, "Automatic Gain Ctrl : %s\n", uda->cfg[CMD_AGC] ? "on" : "off"); | ||
357 | snd_iprintf(buffer, "AGC attack time : %d ms\n", AGC_atime[uda->cfg[CMD_AGC_TIME]]); | ||
358 | snd_iprintf(buffer, "AGC decay time : %d ms\n", AGC_dtime[uda->cfg[CMD_AGC_TIME]]); | ||
359 | snd_iprintf(buffer, "AGC output level : %s dB\n\n", AGC_level[uda->cfg[CMD_AGC_LEVEL]]); | ||
360 | |||
361 | snd_iprintf(buffer, "Mute : %s\n", uda->cfg[CMD_MUTE] ? "on" : "off"); | ||
362 | |||
363 | if (uda->cfg[CMD_VOLUME] == 0) | ||
364 | snd_iprintf(buffer, "Volume : 0 dB\n"); | ||
365 | else if (uda->cfg[CMD_VOLUME] < 62) | ||
366 | snd_iprintf(buffer, "Volume : %d dB\n", -1*uda->cfg[CMD_VOLUME] +1); | ||
367 | else | ||
368 | snd_iprintf(buffer, "Volume : -INF dB\n"); | ||
369 | snd_iprintf(buffer, "Bass : %s\n", bass_values[uda->cfg[CMD_FILTER]][uda->cfg[CMD_BASS]]); | ||
370 | snd_iprintf(buffer, "Trebble : %d dB\n", uda->cfg[CMD_FILTER] ? 2*uda->cfg[CMD_TREBBLE] : 0); | ||
371 | snd_iprintf(buffer, "Input Gain (6dB) : %s\n", uda->cfg[CMD_IGAIN] ? "on" : "off"); | ||
372 | snd_iprintf(buffer, "Output Gain (6dB) : %s\n", uda->cfg[CMD_OGAIN] ? "on" : "off"); | ||
373 | snd_iprintf(buffer, "Mic sensitivity : %s\n", mic_sens_value[uda->cfg[CMD_MIC]]); | ||
374 | |||
375 | |||
376 | if(uda->cfg[CMD_CH1] < 31) | ||
377 | snd_iprintf(buffer, "Mixer gain channel 1: -%d.%c dB\n", | ||
378 | ((uda->cfg[CMD_CH1] >> 1) * 3) + (uda->cfg[CMD_CH1] & 1), | ||
379 | uda->cfg[CMD_CH1] & 1 ? '5' : '0'); | ||
380 | else | ||
381 | snd_iprintf(buffer, "Mixer gain channel 1: -INF dB\n"); | ||
382 | if(uda->cfg[CMD_CH2] < 31) | ||
383 | snd_iprintf(buffer, "Mixer gain channel 2: -%d.%c dB\n", | ||
384 | ((uda->cfg[CMD_CH2] >> 1) * 3) + (uda->cfg[CMD_CH2] & 1), | ||
385 | uda->cfg[CMD_CH2] & 1 ? '5' : '0'); | ||
386 | else | ||
387 | snd_iprintf(buffer, "Mixer gain channel 2: -INF dB\n"); | ||
388 | |||
389 | if(uda->cfg[CMD_IG] > 5) | ||
390 | snd_iprintf(buffer, "Input Amp. Gain ch 2: %d.%c dB\n", | ||
391 | (uda->cfg[CMD_IG] >> 1) -3, uda->cfg[CMD_IG] & 1 ? '5' : '0'); | ||
392 | else | ||
393 | snd_iprintf(buffer, "Input Amp. Gain ch 2: %s dB\n", ig_small_value[uda->cfg[CMD_IG]]); | ||
394 | } | ||
395 | |||
396 | static void snd_uda1341_proc_regs_read(snd_info_entry_t *entry, | ||
397 | snd_info_buffer_t * buffer) | ||
398 | { | ||
399 | struct l3_client *clnt = entry->private_data; | ||
400 | struct uda1341 *uda = clnt->driver_data; | ||
401 | int reg; | ||
402 | char buf[12]; | ||
403 | |||
404 | spin_lock(&uda->reg_lock); | ||
405 | for (reg = 0; reg < uda1341_reg_last; reg ++) { | ||
406 | if (reg == empty) | ||
407 | continue; | ||
408 | int2str_bin8(uda->regs[reg], buf); | ||
409 | snd_iprintf(buffer, "%s = %s\n", uda1341_reg_names[reg], buf); | ||
410 | } | ||
411 | |||
412 | int2str_bin8(snd_uda1341_codec_read(clnt, UDA1341_DATA1), buf); | ||
413 | snd_iprintf(buffer, "DATA1 = %s\n", buf); | ||
414 | |||
415 | spin_unlock(&uda->reg_lock); | ||
416 | } | ||
417 | |||
418 | static void __devinit snd_uda1341_proc_init(snd_card_t *card, struct l3_client *clnt) | ||
419 | { | ||
420 | snd_info_entry_t *entry; | ||
421 | |||
422 | if (! snd_card_proc_new(card, "uda1341", &entry)) | ||
423 | snd_info_set_text_ops(entry, clnt, 1024, snd_uda1341_proc_read); | ||
424 | if (! snd_card_proc_new(card, "uda1341-regs", &entry)) | ||
425 | snd_info_set_text_ops(entry, clnt, 1024, snd_uda1341_proc_regs_read); | ||
426 | } | ||
427 | |||
428 | /* }}} */ | ||
429 | |||
430 | /* {{{ Mixer controls setting */ | ||
431 | |||
432 | /* {{{ UDA1341 single functions */ | ||
433 | |||
434 | #define UDA1341_SINGLE(xname, where, reg, shift, mask, invert) \ | ||
435 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_uda1341_info_single, \ | ||
436 | .get = snd_uda1341_get_single, .put = snd_uda1341_put_single, \ | ||
437 | .private_value = where | (reg << 5) | (shift << 9) | (mask << 12) | (invert << 18) \ | ||
438 | } | ||
439 | |||
440 | static int snd_uda1341_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
441 | { | ||
442 | int mask = (kcontrol->private_value >> 12) & 63; | ||
443 | |||
444 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
445 | uinfo->count = 1; | ||
446 | uinfo->value.integer.min = 0; | ||
447 | uinfo->value.integer.max = mask; | ||
448 | return 0; | ||
449 | } | ||
450 | |||
451 | static int snd_uda1341_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
452 | { | ||
453 | struct l3_client *clnt = snd_kcontrol_chip(kcontrol); | ||
454 | uda1341_t *uda = clnt->driver_data; | ||
455 | int where = kcontrol->private_value & 31; | ||
456 | int mask = (kcontrol->private_value >> 12) & 63; | ||
457 | int invert = (kcontrol->private_value >> 18) & 1; | ||
458 | |||
459 | ucontrol->value.integer.value[0] = uda->cfg[where]; | ||
460 | if (invert) | ||
461 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; | ||
462 | |||
463 | return 0; | ||
464 | } | ||
465 | |||
466 | static int snd_uda1341_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
467 | { | ||
468 | struct l3_client *clnt = snd_kcontrol_chip(kcontrol); | ||
469 | uda1341_t *uda = clnt->driver_data; | ||
470 | int where = kcontrol->private_value & 31; | ||
471 | int reg = (kcontrol->private_value >> 5) & 15; | ||
472 | int shift = (kcontrol->private_value >> 9) & 7; | ||
473 | int mask = (kcontrol->private_value >> 12) & 63; | ||
474 | int invert = (kcontrol->private_value >> 18) & 1; | ||
475 | unsigned short val; | ||
476 | |||
477 | val = (ucontrol->value.integer.value[0] & mask); | ||
478 | if (invert) | ||
479 | val = mask - val; | ||
480 | |||
481 | uda->cfg[where] = val; | ||
482 | return snd_uda1341_update_bits(clnt, reg, mask, shift, val, FLUSH); | ||
483 | } | ||
484 | |||
485 | /* }}} */ | ||
486 | |||
487 | /* {{{ UDA1341 enum functions */ | ||
488 | |||
489 | #define UDA1341_ENUM(xname, where, reg, shift, mask, invert) \ | ||
490 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_uda1341_info_enum, \ | ||
491 | .get = snd_uda1341_get_enum, .put = snd_uda1341_put_enum, \ | ||
492 | .private_value = where | (reg << 5) | (shift << 9) | (mask << 12) | (invert << 18) \ | ||
493 | } | ||
494 | |||
495 | static int snd_uda1341_info_enum(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
496 | { | ||
497 | int where = kcontrol->private_value & 31; | ||
498 | const char **texts; | ||
499 | |||
500 | // this register we don't handle this way | ||
501 | if (!uda1341_enum_items[where]) | ||
502 | return -EINVAL; | ||
503 | |||
504 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
505 | uinfo->count = 1; | ||
506 | uinfo->value.enumerated.items = uda1341_enum_items[where]; | ||
507 | |||
508 | if (uinfo->value.enumerated.item >= uda1341_enum_items[where]) | ||
509 | uinfo->value.enumerated.item = uda1341_enum_items[where] - 1; | ||
510 | |||
511 | texts = uda1341_enum_names[where]; | ||
512 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | ||
513 | return 0; | ||
514 | } | ||
515 | |||
516 | static int snd_uda1341_get_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
517 | { | ||
518 | struct l3_client *clnt = snd_kcontrol_chip(kcontrol); | ||
519 | uda1341_t *uda = clnt->driver_data; | ||
520 | int where = kcontrol->private_value & 31; | ||
521 | |||
522 | ucontrol->value.enumerated.item[0] = uda->cfg[where]; | ||
523 | return 0; | ||
524 | } | ||
525 | |||
526 | static int snd_uda1341_put_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
527 | { | ||
528 | struct l3_client *clnt = snd_kcontrol_chip(kcontrol); | ||
529 | uda1341_t *uda = clnt->driver_data; | ||
530 | int where = kcontrol->private_value & 31; | ||
531 | int reg = (kcontrol->private_value >> 5) & 15; | ||
532 | int shift = (kcontrol->private_value >> 9) & 7; | ||
533 | int mask = (kcontrol->private_value >> 12) & 63; | ||
534 | |||
535 | uda->cfg[where] = (ucontrol->value.enumerated.item[0] & mask); | ||
536 | |||
537 | return snd_uda1341_update_bits(clnt, reg, mask, shift, uda->cfg[where], FLUSH); | ||
538 | } | ||
539 | |||
540 | /* }}} */ | ||
541 | |||
542 | /* {{{ UDA1341 2regs functions */ | ||
543 | |||
544 | #define UDA1341_2REGS(xname, where, reg_1, reg_2, shift_1, shift_2, mask_1, mask_2, invert) \ | ||
545 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .info = snd_uda1341_info_2regs, \ | ||
546 | .get = snd_uda1341_get_2regs, .put = snd_uda1341_put_2regs, \ | ||
547 | .private_value = where | (reg_1 << 5) | (reg_2 << 9) | (shift_1 << 13) | (shift_2 << 16) | \ | ||
548 | (mask_1 << 19) | (mask_2 << 25) | (invert << 31) \ | ||
549 | } | ||
550 | |||
551 | |||
552 | static int snd_uda1341_info_2regs(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
553 | { | ||
554 | int mask_1 = (kcontrol->private_value >> 19) & 63; | ||
555 | int mask_2 = (kcontrol->private_value >> 25) & 63; | ||
556 | int mask; | ||
557 | |||
558 | mask = (mask_2 + 1) * (mask_1 + 1) - 1; | ||
559 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
560 | uinfo->count = 1; | ||
561 | uinfo->value.integer.min = 0; | ||
562 | uinfo->value.integer.max = mask; | ||
563 | return 0; | ||
564 | } | ||
565 | |||
566 | static int snd_uda1341_get_2regs(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
567 | { | ||
568 | struct l3_client *clnt = snd_kcontrol_chip(kcontrol); | ||
569 | uda1341_t *uda = clnt->driver_data; | ||
570 | int where = kcontrol->private_value & 31; | ||
571 | int mask_1 = (kcontrol->private_value >> 19) & 63; | ||
572 | int mask_2 = (kcontrol->private_value >> 25) & 63; | ||
573 | int invert = (kcontrol->private_value >> 31) & 1; | ||
574 | int mask; | ||
575 | |||
576 | mask = (mask_2 + 1) * (mask_1 + 1) - 1; | ||
577 | |||
578 | ucontrol->value.integer.value[0] = uda->cfg[where]; | ||
579 | if (invert) | ||
580 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; | ||
581 | return 0; | ||
582 | } | ||
583 | |||
584 | static int snd_uda1341_put_2regs(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
585 | { | ||
586 | struct l3_client *clnt = snd_kcontrol_chip(kcontrol); | ||
587 | uda1341_t *uda = clnt->driver_data; | ||
588 | int where = kcontrol->private_value & 31; | ||
589 | int reg_1 = (kcontrol->private_value >> 5) & 15; | ||
590 | int reg_2 = (kcontrol->private_value >> 9) & 15; | ||
591 | int shift_1 = (kcontrol->private_value >> 13) & 7; | ||
592 | int shift_2 = (kcontrol->private_value >> 16) & 7; | ||
593 | int mask_1 = (kcontrol->private_value >> 19) & 63; | ||
594 | int mask_2 = (kcontrol->private_value >> 25) & 63; | ||
595 | int invert = (kcontrol->private_value >> 31) & 1; | ||
596 | int mask; | ||
597 | unsigned short val1, val2, val; | ||
598 | |||
599 | val = ucontrol->value.integer.value[0]; | ||
600 | |||
601 | mask = (mask_2 + 1) * (mask_1 + 1) - 1; | ||
602 | |||
603 | val1 = val & mask_1; | ||
604 | val2 = (val / (mask_1 + 1)) & mask_2; | ||
605 | |||
606 | if (invert) { | ||
607 | val1 = mask_1 - val1; | ||
608 | val2 = mask_2 - val2; | ||
609 | } | ||
610 | |||
611 | uda->cfg[where] = invert ? mask - val : val; | ||
612 | |||
613 | //FIXME - return value | ||
614 | snd_uda1341_update_bits(clnt, reg_1, mask_1, shift_1, val1, FLUSH); | ||
615 | return snd_uda1341_update_bits(clnt, reg_2, mask_2, shift_2, val2, FLUSH); | ||
616 | } | ||
617 | |||
618 | /* }}} */ | ||
619 | |||
620 | static snd_kcontrol_new_t snd_uda1341_controls[] = { | ||
621 | UDA1341_SINGLE("Master Playback Switch", CMD_MUTE, data0_2, 2, 1, 1), | ||
622 | UDA1341_SINGLE("Master Playback Volume", CMD_VOLUME, data0_0, 0, 63, 1), | ||
623 | |||
624 | UDA1341_SINGLE("Bass Playback Volume", CMD_BASS, data0_1, 2, 15, 0), | ||
625 | UDA1341_SINGLE("Treble Playback Volume", CMD_TREBBLE, data0_1, 0, 3, 0), | ||
626 | |||
627 | UDA1341_SINGLE("Input Gain Switch", CMD_IGAIN, stat1, 5, 1, 0), | ||
628 | UDA1341_SINGLE("Output Gain Switch", CMD_OGAIN, stat1, 6, 1, 0), | ||
629 | |||
630 | UDA1341_SINGLE("Mixer Gain Channel 1 Volume", CMD_CH1, ext0, 0, 31, 1), | ||
631 | UDA1341_SINGLE("Mixer Gain Channel 2 Volume", CMD_CH2, ext1, 0, 31, 1), | ||
632 | |||
633 | UDA1341_SINGLE("Mic Sensitivity Volume", CMD_MIC, ext2, 2, 7, 0), | ||
634 | |||
635 | UDA1341_SINGLE("AGC Output Level", CMD_AGC_LEVEL, ext6, 0, 3, 0), | ||
636 | UDA1341_SINGLE("AGC Time Constant", CMD_AGC_TIME, ext6, 2, 7, 0), | ||
637 | UDA1341_SINGLE("AGC Time Constant Switch", CMD_AGC, ext4, 4, 1, 0), | ||
638 | |||
639 | UDA1341_SINGLE("DAC Power", CMD_DAC, stat1, 0, 1, 0), | ||
640 | UDA1341_SINGLE("ADC Power", CMD_ADC, stat1, 1, 1, 0), | ||
641 | |||
642 | UDA1341_ENUM("Peak detection", CMD_PEAK, data0_2, 5, 1, 0), | ||
643 | UDA1341_ENUM("De-emphasis", CMD_DEEMP, data0_2, 3, 3, 0), | ||
644 | UDA1341_ENUM("Mixer mode", CMD_MIXER, ext2, 0, 3, 0), | ||
645 | UDA1341_ENUM("Filter mode", CMD_FILTER, data0_2, 0, 3, 0), | ||
646 | |||
647 | UDA1341_2REGS("Gain Input Amplifier Gain (channel 2)", CMD_IG, ext4, ext5, 0, 0, 3, 31, 0), | ||
648 | }; | ||
649 | |||
650 | static void uda1341_free(struct l3_client *uda1341) | ||
651 | { | ||
652 | l3_detach_client(uda1341); // calls kfree for driver_data (uda1341_t) | ||
653 | kfree(uda1341); | ||
654 | } | ||
655 | |||
656 | static int uda1341_dev_free(snd_device_t *device) | ||
657 | { | ||
658 | struct l3_client *clnt = device->device_data; | ||
659 | uda1341_free(clnt); | ||
660 | return 0; | ||
661 | } | ||
662 | |||
663 | int __init snd_chip_uda1341_mixer_new(snd_card_t *card, struct l3_client **clnt) | ||
664 | { | ||
665 | static snd_device_ops_t ops = { | ||
666 | .dev_free = uda1341_dev_free, | ||
667 | }; | ||
668 | struct l3_client *uda1341; | ||
669 | int idx, err; | ||
670 | |||
671 | snd_assert(card != NULL, return -EINVAL); | ||
672 | |||
673 | uda1341 = kcalloc(1, sizeof(*uda1341), GFP_KERNEL); | ||
674 | if (uda1341 == NULL) | ||
675 | return -ENOMEM; | ||
676 | |||
677 | if ((err = l3_attach_client(uda1341, "l3-bit-sa1100-gpio", "snd-uda1341"))) { | ||
678 | kfree(uda1341); | ||
679 | return err; | ||
680 | } | ||
681 | |||
682 | if ((err = snd_device_new(card, SNDRV_DEV_CODEC, uda1341, &ops)) < 0) { | ||
683 | l3_detach_client(uda1341); | ||
684 | kfree(uda1341); | ||
685 | return err; | ||
686 | } | ||
687 | |||
688 | for (idx = 0; idx < ARRAY_SIZE(snd_uda1341_controls); idx++) { | ||
689 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_uda1341_controls[idx], uda1341))) < 0) | ||
690 | return err; | ||
691 | } | ||
692 | |||
693 | *clnt = uda1341; | ||
694 | strcpy(card->mixername, "UDA1341TS Mixer"); | ||
695 | ((uda1341_t *)uda1341->driver_data)->card = card; | ||
696 | |||
697 | snd_uda1341_proc_init(card, uda1341); | ||
698 | |||
699 | return 0; | ||
700 | } | ||
701 | |||
702 | /* }}} */ | ||
703 | |||
704 | /* {{{ L3 operations */ | ||
705 | |||
706 | static int uda1341_attach(struct l3_client *clnt) | ||
707 | { | ||
708 | struct uda1341 *uda; | ||
709 | |||
710 | uda = kcalloc(1, sizeof(*uda), 0, GFP_KERNEL); | ||
711 | if (!uda) | ||
712 | return -ENOMEM; | ||
713 | |||
714 | /* init fixed parts of my copy of registers */ | ||
715 | uda->regs[stat0] = STAT0; | ||
716 | uda->regs[stat1] = STAT1; | ||
717 | |||
718 | uda->regs[data0_0] = DATA0_0; | ||
719 | uda->regs[data0_1] = DATA0_1; | ||
720 | uda->regs[data0_2] = DATA0_2; | ||
721 | |||
722 | uda->write = snd_uda1341_codec_write; | ||
723 | uda->read = snd_uda1341_codec_read; | ||
724 | |||
725 | spin_lock_init(&uda->reg_lock); | ||
726 | |||
727 | clnt->driver_data = uda; | ||
728 | return 0; | ||
729 | } | ||
730 | |||
731 | static void uda1341_detach(struct l3_client *clnt) | ||
732 | { | ||
733 | kfree(clnt->driver_data); | ||
734 | } | ||
735 | |||
736 | static int | ||
737 | uda1341_command(struct l3_client *clnt, int cmd, void *arg) | ||
738 | { | ||
739 | if (cmd != CMD_READ_REG) | ||
740 | return snd_uda1341_cfg_write(clnt, cmd, (int) arg, FLUSH); | ||
741 | |||
742 | return snd_uda1341_codec_read(clnt, (int) arg); | ||
743 | } | ||
744 | |||
745 | static int uda1341_open(struct l3_client *clnt) | ||
746 | { | ||
747 | struct uda1341 *uda = clnt->driver_data; | ||
748 | |||
749 | uda->active = 1; | ||
750 | |||
751 | /* init default configuration */ | ||
752 | snd_uda1341_cfg_write(clnt, CMD_RESET, 0, REGS_ONLY); | ||
753 | snd_uda1341_cfg_write(clnt, CMD_FS, F256, FLUSH); // unknown state after reset | ||
754 | snd_uda1341_cfg_write(clnt, CMD_FORMAT, LSB16, FLUSH); // unknown state after reset | ||
755 | snd_uda1341_cfg_write(clnt, CMD_OGAIN, ON, FLUSH); // default off after reset | ||
756 | snd_uda1341_cfg_write(clnt, CMD_IGAIN, ON, FLUSH); // default off after reset | ||
757 | snd_uda1341_cfg_write(clnt, CMD_DAC, ON, FLUSH); // ??? default value after reset | ||
758 | snd_uda1341_cfg_write(clnt, CMD_ADC, ON, FLUSH); // ??? default value after reset | ||
759 | snd_uda1341_cfg_write(clnt, CMD_VOLUME, 20, FLUSH); // default 0dB after reset | ||
760 | snd_uda1341_cfg_write(clnt, CMD_BASS, 0, REGS_ONLY); // default value after reset | ||
761 | snd_uda1341_cfg_write(clnt, CMD_TREBBLE, 0, REGS_ONLY); // default value after reset | ||
762 | snd_uda1341_cfg_write(clnt, CMD_PEAK, AFTER, REGS_ONLY);// default value after reset | ||
763 | snd_uda1341_cfg_write(clnt, CMD_DEEMP, NONE, REGS_ONLY);// default value after reset | ||
764 | //at this moment should be QMUTED by h3600_audio_init | ||
765 | snd_uda1341_cfg_write(clnt, CMD_MUTE, OFF, REGS_ONLY); // default value after reset | ||
766 | snd_uda1341_cfg_write(clnt, CMD_FILTER, MAX, FLUSH); // defaul flat after reset | ||
767 | snd_uda1341_cfg_write(clnt, CMD_CH1, 31, FLUSH); // default value after reset | ||
768 | snd_uda1341_cfg_write(clnt, CMD_CH2, 4, FLUSH); // default value after reset | ||
769 | snd_uda1341_cfg_write(clnt, CMD_MIC, 4, FLUSH); // default 0dB after reset | ||
770 | snd_uda1341_cfg_write(clnt, CMD_MIXER, MIXER, FLUSH); // default doub.dif.mode | ||
771 | snd_uda1341_cfg_write(clnt, CMD_AGC, OFF, FLUSH); // default value after reset | ||
772 | snd_uda1341_cfg_write(clnt, CMD_IG, 0, FLUSH); // unknown state after reset | ||
773 | snd_uda1341_cfg_write(clnt, CMD_AGC_TIME, 0, FLUSH); // default value after reset | ||
774 | snd_uda1341_cfg_write(clnt, CMD_AGC_LEVEL, 0, FLUSH); // default value after reset | ||
775 | |||
776 | return 0; | ||
777 | } | ||
778 | |||
779 | static void uda1341_close(struct l3_client *clnt) | ||
780 | { | ||
781 | struct uda1341 *uda = clnt->driver_data; | ||
782 | |||
783 | uda->active = 0; | ||
784 | } | ||
785 | |||
786 | /* }}} */ | ||
787 | |||
788 | /* {{{ Module and L3 initialization */ | ||
789 | |||
790 | static struct l3_ops uda1341_ops = { | ||
791 | .open = uda1341_open, | ||
792 | .command = uda1341_command, | ||
793 | .close = uda1341_close, | ||
794 | }; | ||
795 | |||
796 | static struct l3_driver uda1341_driver = { | ||
797 | .name = UDA1341_ALSA_NAME, | ||
798 | .attach_client = uda1341_attach, | ||
799 | .detach_client = uda1341_detach, | ||
800 | .ops = &uda1341_ops, | ||
801 | .owner = THIS_MODULE, | ||
802 | }; | ||
803 | |||
804 | static int __init uda1341_init(void) | ||
805 | { | ||
806 | return l3_add_driver(&uda1341_driver); | ||
807 | } | ||
808 | |||
809 | static void __exit uda1341_exit(void) | ||
810 | { | ||
811 | l3_del_driver(&uda1341_driver); | ||
812 | } | ||
813 | |||
814 | module_init(uda1341_init); | ||
815 | module_exit(uda1341_exit); | ||
816 | |||
817 | MODULE_AUTHOR("Tomas Kasparek <tomas.kasparek@seznam.cz>"); | ||
818 | MODULE_LICENSE("GPL"); | ||
819 | MODULE_DESCRIPTION("Philips UDA1341 CODEC driver for ALSA"); | ||
820 | MODULE_SUPPORTED_DEVICE("{{UDA1341,UDA1341TS}}"); | ||
821 | |||
822 | EXPORT_SYMBOL(snd_chip_uda1341_mixer_new); | ||
823 | |||
824 | /* }}} */ | ||
825 | |||
826 | /* | ||
827 | * Local variables: | ||
828 | * indent-tabs-mode: t | ||
829 | * End: | ||
830 | */ | ||
diff --git a/sound/i2c/other/Makefile b/sound/i2c/other/Makefile new file mode 100644 index 000000000000..2fe023ef00a7 --- /dev/null +++ b/sound/i2c/other/Makefile | |||
@@ -0,0 +1,16 @@ | |||
1 | # | ||
2 | # Makefile for ALSA | ||
3 | # Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz> | ||
4 | # | ||
5 | |||
6 | snd-ak4114-objs := ak4114.o | ||
7 | snd-ak4117-objs := ak4117.o | ||
8 | snd-ak4xxx-adda-objs := ak4xxx-adda.o | ||
9 | snd-tea575x-tuner-objs := tea575x-tuner.o | ||
10 | |||
11 | # Module Dependency | ||
12 | obj-$(CONFIG_SND_PDAUDIOCF) += snd-ak4117.o | ||
13 | obj-$(CONFIG_SND_ICE1712) += snd-ak4xxx-adda.o | ||
14 | obj-$(CONFIG_SND_ICE1724) += snd-ak4xxx-adda.o | ||
15 | obj-$(CONFIG_SND_ICE1724) += snd-ak4114.o | ||
16 | obj-$(CONFIG_SND_FM801_TEA575X) += snd-tea575x-tuner.o | ||
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c new file mode 100644 index 000000000000..f5e6018ea3f4 --- /dev/null +++ b/sound/i2c/other/ak4114.c | |||
@@ -0,0 +1,580 @@ | |||
1 | /* | ||
2 | * Routines for control of the AK4114 via I2C and 4-wire serial interface | ||
3 | * IEC958 (S/PDIF) receiver by Asahi Kasei | ||
4 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <sound/driver.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <sound/core.h> | ||
27 | #include <sound/control.h> | ||
28 | #include <sound/pcm.h> | ||
29 | #include <sound/ak4114.h> | ||
30 | #include <sound/asoundef.h> | ||
31 | |||
32 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
33 | MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei"); | ||
34 | MODULE_LICENSE("GPL"); | ||
35 | |||
36 | #define AK4114_ADDR 0x00 /* fixed address */ | ||
37 | |||
38 | static void ak4114_stats(void *); | ||
39 | |||
40 | static void reg_write(ak4114_t *ak4114, unsigned char reg, unsigned char val) | ||
41 | { | ||
42 | ak4114->write(ak4114->private_data, reg, val); | ||
43 | if (reg <= AK4114_REG_INT1_MASK) | ||
44 | ak4114->regmap[reg] = val; | ||
45 | else if (reg >= AK4114_REG_RXCSB0 && reg <= AK4114_REG_TXCSB4) | ||
46 | ak4114->txcsb[reg-AK4114_REG_RXCSB0] = val; | ||
47 | } | ||
48 | |||
49 | static inline unsigned char reg_read(ak4114_t *ak4114, unsigned char reg) | ||
50 | { | ||
51 | return ak4114->read(ak4114->private_data, reg); | ||
52 | } | ||
53 | |||
54 | #if 0 | ||
55 | static void reg_dump(ak4114_t *ak4114) | ||
56 | { | ||
57 | int i; | ||
58 | |||
59 | printk("AK4114 REG DUMP:\n"); | ||
60 | for (i = 0; i < 0x20; i++) | ||
61 | printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < sizeof(ak4114->regmap) ? ak4114->regmap[i] : 0); | ||
62 | } | ||
63 | #endif | ||
64 | |||
65 | static void snd_ak4114_free(ak4114_t *chip) | ||
66 | { | ||
67 | chip->init = 1; /* don't schedule new work */ | ||
68 | mb(); | ||
69 | if (chip->workqueue != NULL) { | ||
70 | flush_workqueue(chip->workqueue); | ||
71 | destroy_workqueue(chip->workqueue); | ||
72 | } | ||
73 | kfree(chip); | ||
74 | } | ||
75 | |||
76 | static int snd_ak4114_dev_free(snd_device_t *device) | ||
77 | { | ||
78 | ak4114_t *chip = device->device_data; | ||
79 | snd_ak4114_free(chip); | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | int snd_ak4114_create(snd_card_t *card, | ||
84 | ak4114_read_t *read, ak4114_write_t *write, | ||
85 | unsigned char pgm[7], unsigned char txcsb[5], | ||
86 | void *private_data, ak4114_t **r_ak4114) | ||
87 | { | ||
88 | ak4114_t *chip; | ||
89 | int err = 0; | ||
90 | unsigned char reg; | ||
91 | static snd_device_ops_t ops = { | ||
92 | .dev_free = snd_ak4114_dev_free, | ||
93 | }; | ||
94 | |||
95 | chip = kcalloc(1, sizeof(*chip), GFP_KERNEL); | ||
96 | if (chip == NULL) | ||
97 | return -ENOMEM; | ||
98 | spin_lock_init(&chip->lock); | ||
99 | chip->card = card; | ||
100 | chip->read = read; | ||
101 | chip->write = write; | ||
102 | chip->private_data = private_data; | ||
103 | |||
104 | for (reg = 0; reg < 7; reg++) | ||
105 | chip->regmap[reg] = pgm[reg]; | ||
106 | for (reg = 0; reg < 5; reg++) | ||
107 | chip->txcsb[reg] = txcsb[reg]; | ||
108 | |||
109 | chip->workqueue = create_workqueue("snd-ak4114"); | ||
110 | if (chip->workqueue == NULL) { | ||
111 | kfree(chip); | ||
112 | return -ENOMEM; | ||
113 | } | ||
114 | |||
115 | snd_ak4114_reinit(chip); | ||
116 | |||
117 | chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT); | ||
118 | chip->rcs1 = reg_read(chip, AK4114_REG_RCS1); | ||
119 | |||
120 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) | ||
121 | goto __fail; | ||
122 | |||
123 | if (r_ak4114) | ||
124 | *r_ak4114 = chip; | ||
125 | return 0; | ||
126 | |||
127 | __fail: | ||
128 | snd_ak4114_free(chip); | ||
129 | return err < 0 ? err : -EIO; | ||
130 | } | ||
131 | |||
132 | void snd_ak4114_reg_write(ak4114_t *chip, unsigned char reg, unsigned char mask, unsigned char val) | ||
133 | { | ||
134 | if (reg <= AK4114_REG_INT1_MASK) | ||
135 | reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val); | ||
136 | else if (reg >= AK4114_REG_TXCSB0 && reg <= AK4114_REG_TXCSB4) | ||
137 | reg_write(chip, reg, (chip->txcsb[reg] & ~mask) | val); | ||
138 | } | ||
139 | |||
140 | void snd_ak4114_reinit(ak4114_t *chip) | ||
141 | { | ||
142 | unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg; | ||
143 | |||
144 | chip->init = 1; | ||
145 | mb(); | ||
146 | flush_workqueue(chip->workqueue); | ||
147 | /* bring the chip to reset state and powerdown state */ | ||
148 | reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN)); | ||
149 | udelay(200); | ||
150 | /* release reset, but leave powerdown */ | ||
151 | reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN); | ||
152 | udelay(200); | ||
153 | for (reg = 1; reg < 7; reg++) | ||
154 | reg_write(chip, reg, chip->regmap[reg]); | ||
155 | for (reg = 0; reg < 5; reg++) | ||
156 | reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]); | ||
157 | /* release powerdown, everything is initialized now */ | ||
158 | reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN); | ||
159 | /* bring up statistics / event queing */ | ||
160 | chip->init = 0; | ||
161 | INIT_WORK(&chip->work, ak4114_stats, chip); | ||
162 | queue_delayed_work(chip->workqueue, &chip->work, HZ / 10); | ||
163 | } | ||
164 | |||
165 | static unsigned int external_rate(unsigned char rcs1) | ||
166 | { | ||
167 | switch (rcs1 & (AK4114_FS0|AK4114_FS1|AK4114_FS2|AK4114_FS3)) { | ||
168 | case AK4114_FS_32000HZ: return 32000; | ||
169 | case AK4114_FS_44100HZ: return 44100; | ||
170 | case AK4114_FS_48000HZ: return 48000; | ||
171 | case AK4114_FS_88200HZ: return 88200; | ||
172 | case AK4114_FS_96000HZ: return 96000; | ||
173 | case AK4114_FS_176400HZ: return 176400; | ||
174 | case AK4114_FS_192000HZ: return 192000; | ||
175 | default: return 0; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | static int snd_ak4114_in_error_info(snd_kcontrol_t *kcontrol, | ||
180 | snd_ctl_elem_info_t *uinfo) | ||
181 | { | ||
182 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
183 | uinfo->count = 1; | ||
184 | uinfo->value.integer.min = 0; | ||
185 | uinfo->value.integer.max = LONG_MAX; | ||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | static int snd_ak4114_in_error_get(snd_kcontrol_t *kcontrol, | ||
190 | snd_ctl_elem_value_t *ucontrol) | ||
191 | { | ||
192 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
193 | long *ptr; | ||
194 | |||
195 | spin_lock_irq(&chip->lock); | ||
196 | ptr = (long *)(((char *)chip) + kcontrol->private_value); | ||
197 | ucontrol->value.integer.value[0] = *ptr; | ||
198 | *ptr = 0; | ||
199 | spin_unlock_irq(&chip->lock); | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | static int snd_ak4114_in_bit_info(snd_kcontrol_t *kcontrol, | ||
204 | snd_ctl_elem_info_t *uinfo) | ||
205 | { | ||
206 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | ||
207 | uinfo->count = 1; | ||
208 | uinfo->value.integer.min = 0; | ||
209 | uinfo->value.integer.max = 1; | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | static int snd_ak4114_in_bit_get(snd_kcontrol_t *kcontrol, | ||
214 | snd_ctl_elem_value_t *ucontrol) | ||
215 | { | ||
216 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
217 | unsigned char reg = kcontrol->private_value & 0xff; | ||
218 | unsigned char bit = (kcontrol->private_value >> 8) & 0xff; | ||
219 | unsigned char inv = (kcontrol->private_value >> 31) & 1; | ||
220 | |||
221 | ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv; | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static int snd_ak4114_rate_info(snd_kcontrol_t *kcontrol, | ||
226 | snd_ctl_elem_info_t *uinfo) | ||
227 | { | ||
228 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
229 | uinfo->count = 1; | ||
230 | uinfo->value.integer.min = 0; | ||
231 | uinfo->value.integer.max = 192000; | ||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | static int snd_ak4114_rate_get(snd_kcontrol_t *kcontrol, | ||
236 | snd_ctl_elem_value_t *ucontrol) | ||
237 | { | ||
238 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
239 | |||
240 | ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4114_REG_RCS1)); | ||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int snd_ak4114_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
245 | { | ||
246 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | ||
247 | uinfo->count = 1; | ||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | static int snd_ak4114_spdif_get(snd_kcontrol_t * kcontrol, | ||
252 | snd_ctl_elem_value_t * ucontrol) | ||
253 | { | ||
254 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
255 | unsigned i; | ||
256 | |||
257 | for (i = 0; i < AK4114_REG_RXCSB_SIZE; i++) | ||
258 | ucontrol->value.iec958.status[i] = reg_read(chip, AK4114_REG_RXCSB0 + i); | ||
259 | return 0; | ||
260 | } | ||
261 | |||
262 | static int snd_ak4114_spdif_playback_get(snd_kcontrol_t * kcontrol, | ||
263 | snd_ctl_elem_value_t * ucontrol) | ||
264 | { | ||
265 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
266 | unsigned i; | ||
267 | |||
268 | for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++) | ||
269 | ucontrol->value.iec958.status[i] = chip->txcsb[i]; | ||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static int snd_ak4114_spdif_playback_put(snd_kcontrol_t * kcontrol, | ||
274 | snd_ctl_elem_value_t * ucontrol) | ||
275 | { | ||
276 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
277 | unsigned i; | ||
278 | |||
279 | for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++) | ||
280 | reg_write(chip, AK4114_REG_TXCSB0 + i, ucontrol->value.iec958.status[i]); | ||
281 | return 0; | ||
282 | } | ||
283 | |||
284 | static int snd_ak4114_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
285 | { | ||
286 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | ||
287 | uinfo->count = 1; | ||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | static int snd_ak4114_spdif_mask_get(snd_kcontrol_t * kcontrol, | ||
292 | snd_ctl_elem_value_t * ucontrol) | ||
293 | { | ||
294 | memset(ucontrol->value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE); | ||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | static int snd_ak4114_spdif_pinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
299 | { | ||
300 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
301 | uinfo->value.integer.min = 0; | ||
302 | uinfo->value.integer.max = 0xffff; | ||
303 | uinfo->count = 4; | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static int snd_ak4114_spdif_pget(snd_kcontrol_t * kcontrol, | ||
308 | snd_ctl_elem_value_t * ucontrol) | ||
309 | { | ||
310 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
311 | unsigned short tmp; | ||
312 | |||
313 | ucontrol->value.integer.value[0] = 0xf8f2; | ||
314 | ucontrol->value.integer.value[1] = 0x4e1f; | ||
315 | tmp = reg_read(chip, AK4114_REG_Pc0) | (reg_read(chip, AK4114_REG_Pc1) << 8); | ||
316 | ucontrol->value.integer.value[2] = tmp; | ||
317 | tmp = reg_read(chip, AK4114_REG_Pd0) | (reg_read(chip, AK4114_REG_Pd1) << 8); | ||
318 | ucontrol->value.integer.value[3] = tmp; | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | static int snd_ak4114_spdif_qinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
323 | { | ||
324 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; | ||
325 | uinfo->count = AK4114_REG_QSUB_SIZE; | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | static int snd_ak4114_spdif_qget(snd_kcontrol_t * kcontrol, | ||
330 | snd_ctl_elem_value_t * ucontrol) | ||
331 | { | ||
332 | ak4114_t *chip = snd_kcontrol_chip(kcontrol); | ||
333 | unsigned i; | ||
334 | |||
335 | for (i = 0; i < AK4114_REG_QSUB_SIZE; i++) | ||
336 | ucontrol->value.bytes.data[i] = reg_read(chip, AK4114_REG_QSUB_ADDR + i); | ||
337 | return 0; | ||
338 | } | ||
339 | |||
340 | /* Don't forget to change AK4114_CONTROLS define!!! */ | ||
341 | static snd_kcontrol_new_t snd_ak4114_iec958_controls[] = { | ||
342 | { | ||
343 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
344 | .name = "IEC958 Parity Errors", | ||
345 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
346 | .info = snd_ak4114_in_error_info, | ||
347 | .get = snd_ak4114_in_error_get, | ||
348 | .private_value = offsetof(ak4114_t, parity_errors), | ||
349 | }, | ||
350 | { | ||
351 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
352 | .name = "IEC958 V-Bit Errors", | ||
353 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
354 | .info = snd_ak4114_in_error_info, | ||
355 | .get = snd_ak4114_in_error_get, | ||
356 | .private_value = offsetof(ak4114_t, v_bit_errors), | ||
357 | }, | ||
358 | { | ||
359 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
360 | .name = "IEC958 C-CRC Errors", | ||
361 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
362 | .info = snd_ak4114_in_error_info, | ||
363 | .get = snd_ak4114_in_error_get, | ||
364 | .private_value = offsetof(ak4114_t, ccrc_errors), | ||
365 | }, | ||
366 | { | ||
367 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
368 | .name = "IEC958 Q-CRC Errors", | ||
369 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
370 | .info = snd_ak4114_in_error_info, | ||
371 | .get = snd_ak4114_in_error_get, | ||
372 | .private_value = offsetof(ak4114_t, qcrc_errors), | ||
373 | }, | ||
374 | { | ||
375 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
376 | .name = "IEC958 External Rate", | ||
377 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
378 | .info = snd_ak4114_rate_info, | ||
379 | .get = snd_ak4114_rate_get, | ||
380 | }, | ||
381 | { | ||
382 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
383 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), | ||
384 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
385 | .info = snd_ak4114_spdif_mask_info, | ||
386 | .get = snd_ak4114_spdif_mask_get, | ||
387 | }, | ||
388 | { | ||
389 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
390 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), | ||
391 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
392 | .info = snd_ak4114_spdif_info, | ||
393 | .get = snd_ak4114_spdif_playback_get, | ||
394 | .put = snd_ak4114_spdif_playback_put, | ||
395 | }, | ||
396 | { | ||
397 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
398 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK), | ||
399 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
400 | .info = snd_ak4114_spdif_mask_info, | ||
401 | .get = snd_ak4114_spdif_mask_get, | ||
402 | }, | ||
403 | { | ||
404 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
405 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), | ||
406 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
407 | .info = snd_ak4114_spdif_info, | ||
408 | .get = snd_ak4114_spdif_get, | ||
409 | }, | ||
410 | { | ||
411 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
412 | .name = "IEC958 Preample Capture Default", | ||
413 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
414 | .info = snd_ak4114_spdif_pinfo, | ||
415 | .get = snd_ak4114_spdif_pget, | ||
416 | }, | ||
417 | { | ||
418 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
419 | .name = "IEC958 Q-subcode Capture Default", | ||
420 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
421 | .info = snd_ak4114_spdif_qinfo, | ||
422 | .get = snd_ak4114_spdif_qget, | ||
423 | }, | ||
424 | { | ||
425 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
426 | .name = "IEC958 Audio", | ||
427 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
428 | .info = snd_ak4114_in_bit_info, | ||
429 | .get = snd_ak4114_in_bit_get, | ||
430 | .private_value = (1<<31) | (1<<8) | AK4114_REG_RCS0, | ||
431 | }, | ||
432 | { | ||
433 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
434 | .name = "IEC958 Non-PCM Bitstream", | ||
435 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
436 | .info = snd_ak4114_in_bit_info, | ||
437 | .get = snd_ak4114_in_bit_get, | ||
438 | .private_value = (6<<8) | AK4114_REG_RCS1, | ||
439 | }, | ||
440 | { | ||
441 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
442 | .name = "IEC958 DTS Bitstream", | ||
443 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
444 | .info = snd_ak4114_in_bit_info, | ||
445 | .get = snd_ak4114_in_bit_get, | ||
446 | .private_value = (3<<8) | AK4114_REG_RCS1, | ||
447 | } | ||
448 | }; | ||
449 | |||
450 | int snd_ak4114_build(ak4114_t *ak4114, | ||
451 | snd_pcm_substream_t *ply_substream, | ||
452 | snd_pcm_substream_t *cap_substream) | ||
453 | { | ||
454 | snd_kcontrol_t *kctl; | ||
455 | unsigned int idx; | ||
456 | int err; | ||
457 | |||
458 | snd_assert(cap_substream, return -EINVAL); | ||
459 | ak4114->playback_substream = ply_substream; | ||
460 | ak4114->capture_substream = cap_substream; | ||
461 | for (idx = 0; idx < AK4114_CONTROLS; idx++) { | ||
462 | kctl = snd_ctl_new1(&snd_ak4114_iec958_controls[idx], ak4114); | ||
463 | if (kctl == NULL) | ||
464 | return -ENOMEM; | ||
465 | if (!strstr(kctl->id.name, "Playback")) { | ||
466 | if (ply_substream == NULL) { | ||
467 | snd_ctl_free_one(kctl); | ||
468 | ak4114->kctls[idx] = NULL; | ||
469 | continue; | ||
470 | } | ||
471 | kctl->id.device = ply_substream->pcm->device; | ||
472 | kctl->id.subdevice = ply_substream->number; | ||
473 | } else { | ||
474 | kctl->id.device = cap_substream->pcm->device; | ||
475 | kctl->id.subdevice = cap_substream->number; | ||
476 | } | ||
477 | err = snd_ctl_add(ak4114->card, kctl); | ||
478 | if (err < 0) | ||
479 | return err; | ||
480 | ak4114->kctls[idx] = kctl; | ||
481 | } | ||
482 | return 0; | ||
483 | } | ||
484 | |||
485 | int snd_ak4114_external_rate(ak4114_t *ak4114) | ||
486 | { | ||
487 | unsigned char rcs1; | ||
488 | |||
489 | rcs1 = reg_read(ak4114, AK4114_REG_RCS1); | ||
490 | return external_rate(rcs1); | ||
491 | } | ||
492 | |||
493 | int snd_ak4114_check_rate_and_errors(ak4114_t *ak4114, unsigned int flags) | ||
494 | { | ||
495 | snd_pcm_runtime_t *runtime = ak4114->capture_substream ? ak4114->capture_substream->runtime : NULL; | ||
496 | unsigned long _flags; | ||
497 | int res = 0; | ||
498 | unsigned char rcs0, rcs1; | ||
499 | unsigned char c0, c1; | ||
500 | |||
501 | rcs1 = reg_read(ak4114, AK4114_REG_RCS1); | ||
502 | if (flags & AK4114_CHECK_NO_STAT) | ||
503 | goto __rate; | ||
504 | rcs0 = reg_read(ak4114, AK4114_REG_RCS0); | ||
505 | spin_lock_irqsave(&ak4114->lock, _flags); | ||
506 | if (rcs0 & AK4114_PAR) | ||
507 | ak4114->parity_errors++; | ||
508 | if (rcs1 & AK4114_V) | ||
509 | ak4114->v_bit_errors++; | ||
510 | if (rcs1 & AK4114_CCRC) | ||
511 | ak4114->ccrc_errors++; | ||
512 | if (rcs1 & AK4114_QCRC) | ||
513 | ak4114->qcrc_errors++; | ||
514 | c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)) ^ | ||
515 | (rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)); | ||
516 | c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0); | ||
517 | ak4114->rcs0 = rcs0 & ~(AK4114_QINT | AK4114_CINT); | ||
518 | ak4114->rcs1 = rcs1; | ||
519 | spin_unlock_irqrestore(&ak4114->lock, _flags); | ||
520 | |||
521 | if (rcs0 & AK4114_PAR) | ||
522 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[0]->id); | ||
523 | if (rcs0 & AK4114_V) | ||
524 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[1]->id); | ||
525 | if (rcs1 & AK4114_CCRC) | ||
526 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[2]->id); | ||
527 | if (rcs1 & AK4114_QCRC) | ||
528 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[3]->id); | ||
529 | |||
530 | /* rate change */ | ||
531 | if (c1 & 0xf0) | ||
532 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[4]->id); | ||
533 | |||
534 | if ((c0 & AK4114_PEM) | (c0 & AK4114_CINT)) | ||
535 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[9]->id); | ||
536 | if (c0 & AK4114_QINT) | ||
537 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[10]->id); | ||
538 | |||
539 | if (c0 & AK4114_AUDION) | ||
540 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[11]->id); | ||
541 | if (c0 & AK4114_AUTO) | ||
542 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[12]->id); | ||
543 | if (c0 & AK4114_DTSCD) | ||
544 | snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[13]->id); | ||
545 | |||
546 | if (ak4114->change_callback && (c0 | c1) != 0) | ||
547 | ak4114->change_callback(ak4114, c0, c1); | ||
548 | |||
549 | __rate: | ||
550 | /* compare rate */ | ||
551 | res = external_rate(rcs1); | ||
552 | if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) { | ||
553 | snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags); | ||
554 | if (snd_pcm_running(ak4114->capture_substream)) { | ||
555 | // printk("rate changed (%i <- %i)\n", runtime->rate, res); | ||
556 | snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING); | ||
557 | wake_up(&runtime->sleep); | ||
558 | res = 1; | ||
559 | } | ||
560 | snd_pcm_stream_unlock_irqrestore(ak4114->capture_substream, _flags); | ||
561 | } | ||
562 | return res; | ||
563 | } | ||
564 | |||
565 | static void ak4114_stats(void *data) | ||
566 | { | ||
567 | ak4114_t *chip = (ak4114_t *)data; | ||
568 | |||
569 | if (chip->init) | ||
570 | return; | ||
571 | snd_ak4114_check_rate_and_errors(chip, 0); | ||
572 | queue_delayed_work(chip->workqueue, &chip->work, HZ / 10); | ||
573 | } | ||
574 | |||
575 | EXPORT_SYMBOL(snd_ak4114_create); | ||
576 | EXPORT_SYMBOL(snd_ak4114_reg_write); | ||
577 | EXPORT_SYMBOL(snd_ak4114_reinit); | ||
578 | EXPORT_SYMBOL(snd_ak4114_build); | ||
579 | EXPORT_SYMBOL(snd_ak4114_external_rate); | ||
580 | EXPORT_SYMBOL(snd_ak4114_check_rate_and_errors); | ||
diff --git a/sound/i2c/other/ak4117.c b/sound/i2c/other/ak4117.c new file mode 100644 index 000000000000..0419c4336a55 --- /dev/null +++ b/sound/i2c/other/ak4117.c | |||
@@ -0,0 +1,559 @@ | |||
1 | /* | ||
2 | * Routines for control of the AK4117 via 4-wire serial interface | ||
3 | * IEC958 (S/PDIF) receiver by Asahi Kasei | ||
4 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <sound/driver.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <sound/core.h> | ||
27 | #include <sound/control.h> | ||
28 | #include <sound/pcm.h> | ||
29 | #include <sound/ak4117.h> | ||
30 | #include <sound/asoundef.h> | ||
31 | |||
32 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
33 | MODULE_DESCRIPTION("AK4117 IEC958 (S/PDIF) receiver by Asahi Kasei"); | ||
34 | MODULE_LICENSE("GPL"); | ||
35 | |||
36 | #define AK4117_ADDR 0x00 /* fixed address */ | ||
37 | |||
38 | static void snd_ak4117_timer(unsigned long data); | ||
39 | |||
40 | static void reg_write(ak4117_t *ak4117, unsigned char reg, unsigned char val) | ||
41 | { | ||
42 | ak4117->write(ak4117->private_data, reg, val); | ||
43 | if (reg < sizeof(ak4117->regmap)) | ||
44 | ak4117->regmap[reg] = val; | ||
45 | } | ||
46 | |||
47 | static inline unsigned char reg_read(ak4117_t *ak4117, unsigned char reg) | ||
48 | { | ||
49 | return ak4117->read(ak4117->private_data, reg); | ||
50 | } | ||
51 | |||
52 | #if 0 | ||
53 | static void reg_dump(ak4117_t *ak4117) | ||
54 | { | ||
55 | int i; | ||
56 | |||
57 | printk("AK4117 REG DUMP:\n"); | ||
58 | for (i = 0; i < 0x1b; i++) | ||
59 | printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4117, i), i < sizeof(ak4117->regmap) ? ak4117->regmap[i] : 0); | ||
60 | } | ||
61 | #endif | ||
62 | |||
63 | static void snd_ak4117_free(ak4117_t *chip) | ||
64 | { | ||
65 | del_timer(&chip->timer); | ||
66 | kfree(chip); | ||
67 | } | ||
68 | |||
69 | static int snd_ak4117_dev_free(snd_device_t *device) | ||
70 | { | ||
71 | ak4117_t *chip = device->device_data; | ||
72 | snd_ak4117_free(chip); | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | int snd_ak4117_create(snd_card_t *card, ak4117_read_t *read, ak4117_write_t *write, | ||
77 | unsigned char pgm[5], void *private_data, ak4117_t **r_ak4117) | ||
78 | { | ||
79 | ak4117_t *chip; | ||
80 | int err = 0; | ||
81 | unsigned char reg; | ||
82 | static snd_device_ops_t ops = { | ||
83 | .dev_free = snd_ak4117_dev_free, | ||
84 | }; | ||
85 | |||
86 | chip = kcalloc(1, sizeof(*chip), GFP_KERNEL); | ||
87 | if (chip == NULL) | ||
88 | return -ENOMEM; | ||
89 | spin_lock_init(&chip->lock); | ||
90 | chip->card = card; | ||
91 | chip->read = read; | ||
92 | chip->write = write; | ||
93 | chip->private_data = private_data; | ||
94 | init_timer(&chip->timer); | ||
95 | chip->timer.data = (unsigned long)chip; | ||
96 | chip->timer.function = snd_ak4117_timer; | ||
97 | |||
98 | for (reg = 0; reg < 5; reg++) | ||
99 | chip->regmap[reg] = pgm[reg]; | ||
100 | snd_ak4117_reinit(chip); | ||
101 | |||
102 | chip->rcs0 = reg_read(chip, AK4117_REG_RCS0) & ~(AK4117_QINT | AK4117_CINT | AK4117_STC); | ||
103 | chip->rcs1 = reg_read(chip, AK4117_REG_RCS1); | ||
104 | chip->rcs2 = reg_read(chip, AK4117_REG_RCS2); | ||
105 | |||
106 | if ((err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops)) < 0) | ||
107 | goto __fail; | ||
108 | |||
109 | if (r_ak4117) | ||
110 | *r_ak4117 = chip; | ||
111 | return 0; | ||
112 | |||
113 | __fail: | ||
114 | snd_ak4117_free(chip); | ||
115 | return err < 0 ? err : -EIO; | ||
116 | } | ||
117 | |||
118 | void snd_ak4117_reg_write(ak4117_t *chip, unsigned char reg, unsigned char mask, unsigned char val) | ||
119 | { | ||
120 | if (reg >= 5) | ||
121 | return; | ||
122 | reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val); | ||
123 | } | ||
124 | |||
125 | void snd_ak4117_reinit(ak4117_t *chip) | ||
126 | { | ||
127 | unsigned char old = chip->regmap[AK4117_REG_PWRDN], reg; | ||
128 | |||
129 | del_timer(&chip->timer); | ||
130 | chip->init = 1; | ||
131 | /* bring the chip to reset state and powerdown state */ | ||
132 | reg_write(chip, AK4117_REG_PWRDN, 0); | ||
133 | udelay(200); | ||
134 | /* release reset, but leave powerdown */ | ||
135 | reg_write(chip, AK4117_REG_PWRDN, (old | AK4117_RST) & ~AK4117_PWN); | ||
136 | udelay(200); | ||
137 | for (reg = 1; reg < 5; reg++) | ||
138 | reg_write(chip, reg, chip->regmap[reg]); | ||
139 | /* release powerdown, everything is initialized now */ | ||
140 | reg_write(chip, AK4117_REG_PWRDN, old | AK4117_RST | AK4117_PWN); | ||
141 | chip->init = 0; | ||
142 | chip->timer.expires = 1 + jiffies; | ||
143 | add_timer(&chip->timer); | ||
144 | } | ||
145 | |||
146 | static unsigned int external_rate(unsigned char rcs1) | ||
147 | { | ||
148 | switch (rcs1 & (AK4117_FS0|AK4117_FS1|AK4117_FS2|AK4117_FS3)) { | ||
149 | case AK4117_FS_32000HZ: return 32000; | ||
150 | case AK4117_FS_44100HZ: return 44100; | ||
151 | case AK4117_FS_48000HZ: return 48000; | ||
152 | case AK4117_FS_88200HZ: return 88200; | ||
153 | case AK4117_FS_96000HZ: return 96000; | ||
154 | case AK4117_FS_176400HZ: return 176400; | ||
155 | case AK4117_FS_192000HZ: return 192000; | ||
156 | default: return 0; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | static int snd_ak4117_in_error_info(snd_kcontrol_t *kcontrol, | ||
161 | snd_ctl_elem_info_t *uinfo) | ||
162 | { | ||
163 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
164 | uinfo->count = 1; | ||
165 | uinfo->value.integer.min = 0; | ||
166 | uinfo->value.integer.max = LONG_MAX; | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | static int snd_ak4117_in_error_get(snd_kcontrol_t *kcontrol, | ||
171 | snd_ctl_elem_value_t *ucontrol) | ||
172 | { | ||
173 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
174 | long *ptr; | ||
175 | |||
176 | spin_lock_irq(&chip->lock); | ||
177 | ptr = (long *)(((char *)chip) + kcontrol->private_value); | ||
178 | ucontrol->value.integer.value[0] = *ptr; | ||
179 | *ptr = 0; | ||
180 | spin_unlock_irq(&chip->lock); | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | static int snd_ak4117_in_bit_info(snd_kcontrol_t *kcontrol, | ||
185 | snd_ctl_elem_info_t *uinfo) | ||
186 | { | ||
187 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | ||
188 | uinfo->count = 1; | ||
189 | uinfo->value.integer.min = 0; | ||
190 | uinfo->value.integer.max = 1; | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int snd_ak4117_in_bit_get(snd_kcontrol_t *kcontrol, | ||
195 | snd_ctl_elem_value_t *ucontrol) | ||
196 | { | ||
197 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
198 | unsigned char reg = kcontrol->private_value & 0xff; | ||
199 | unsigned char bit = (kcontrol->private_value >> 8) & 0xff; | ||
200 | unsigned char inv = (kcontrol->private_value >> 31) & 1; | ||
201 | |||
202 | ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv; | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | static int snd_ak4117_rx_info(snd_kcontrol_t *kcontrol, | ||
207 | snd_ctl_elem_info_t *uinfo) | ||
208 | { | ||
209 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
210 | uinfo->count = 1; | ||
211 | uinfo->value.integer.min = 0; | ||
212 | uinfo->value.integer.max = 1; | ||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | static int snd_ak4117_rx_get(snd_kcontrol_t *kcontrol, | ||
217 | snd_ctl_elem_value_t *ucontrol) | ||
218 | { | ||
219 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
220 | |||
221 | ucontrol->value.integer.value[0] = (chip->regmap[AK4117_REG_IO] & AK4117_IPS) ? 1 : 0; | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static int snd_ak4117_rx_put(snd_kcontrol_t *kcontrol, | ||
226 | snd_ctl_elem_value_t *ucontrol) | ||
227 | { | ||
228 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
229 | int change; | ||
230 | u8 old_val; | ||
231 | |||
232 | spin_lock_irq(&chip->lock); | ||
233 | old_val = chip->regmap[AK4117_REG_IO]; | ||
234 | change = !!ucontrol->value.integer.value[0] != ((old_val & AK4117_IPS) ? 1 : 0); | ||
235 | if (change) | ||
236 | reg_write(chip, AK4117_REG_IO, (old_val & ~AK4117_IPS) | (ucontrol->value.integer.value[0] ? AK4117_IPS : 0)); | ||
237 | spin_unlock_irq(&chip->lock); | ||
238 | return change; | ||
239 | } | ||
240 | |||
241 | static int snd_ak4117_rate_info(snd_kcontrol_t *kcontrol, | ||
242 | snd_ctl_elem_info_t *uinfo) | ||
243 | { | ||
244 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
245 | uinfo->count = 1; | ||
246 | uinfo->value.integer.min = 0; | ||
247 | uinfo->value.integer.max = 192000; | ||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | static int snd_ak4117_rate_get(snd_kcontrol_t *kcontrol, | ||
252 | snd_ctl_elem_value_t *ucontrol) | ||
253 | { | ||
254 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
255 | |||
256 | ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4117_REG_RCS1)); | ||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | static int snd_ak4117_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
261 | { | ||
262 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | ||
263 | uinfo->count = 1; | ||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static int snd_ak4117_spdif_get(snd_kcontrol_t * kcontrol, | ||
268 | snd_ctl_elem_value_t * ucontrol) | ||
269 | { | ||
270 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
271 | unsigned i; | ||
272 | |||
273 | for (i = 0; i < AK4117_REG_RXCSB_SIZE; i++) | ||
274 | ucontrol->value.iec958.status[i] = reg_read(chip, AK4117_REG_RXCSB0 + i); | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int snd_ak4117_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
279 | { | ||
280 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; | ||
281 | uinfo->count = 1; | ||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | static int snd_ak4117_spdif_mask_get(snd_kcontrol_t * kcontrol, | ||
286 | snd_ctl_elem_value_t * ucontrol) | ||
287 | { | ||
288 | memset(ucontrol->value.iec958.status, 0xff, AK4117_REG_RXCSB_SIZE); | ||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | static int snd_ak4117_spdif_pinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
293 | { | ||
294 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
295 | uinfo->value.integer.min = 0; | ||
296 | uinfo->value.integer.max = 0xffff; | ||
297 | uinfo->count = 4; | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static int snd_ak4117_spdif_pget(snd_kcontrol_t * kcontrol, | ||
302 | snd_ctl_elem_value_t * ucontrol) | ||
303 | { | ||
304 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
305 | unsigned short tmp; | ||
306 | |||
307 | ucontrol->value.integer.value[0] = 0xf8f2; | ||
308 | ucontrol->value.integer.value[1] = 0x4e1f; | ||
309 | tmp = reg_read(chip, AK4117_REG_Pc0) | (reg_read(chip, AK4117_REG_Pc1) << 8); | ||
310 | ucontrol->value.integer.value[2] = tmp; | ||
311 | tmp = reg_read(chip, AK4117_REG_Pd0) | (reg_read(chip, AK4117_REG_Pd1) << 8); | ||
312 | ucontrol->value.integer.value[3] = tmp; | ||
313 | return 0; | ||
314 | } | ||
315 | |||
316 | static int snd_ak4117_spdif_qinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
317 | { | ||
318 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; | ||
319 | uinfo->count = AK4117_REG_QSUB_SIZE; | ||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | static int snd_ak4117_spdif_qget(snd_kcontrol_t * kcontrol, | ||
324 | snd_ctl_elem_value_t * ucontrol) | ||
325 | { | ||
326 | ak4117_t *chip = snd_kcontrol_chip(kcontrol); | ||
327 | unsigned i; | ||
328 | |||
329 | for (i = 0; i < AK4117_REG_QSUB_SIZE; i++) | ||
330 | ucontrol->value.bytes.data[i] = reg_read(chip, AK4117_REG_QSUB_ADDR + i); | ||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | /* Don't forget to change AK4117_CONTROLS define!!! */ | ||
335 | static snd_kcontrol_new_t snd_ak4117_iec958_controls[] = { | ||
336 | { | ||
337 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
338 | .name = "IEC958 Parity Errors", | ||
339 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
340 | .info = snd_ak4117_in_error_info, | ||
341 | .get = snd_ak4117_in_error_get, | ||
342 | .private_value = offsetof(ak4117_t, parity_errors), | ||
343 | }, | ||
344 | { | ||
345 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
346 | .name = "IEC958 V-Bit Errors", | ||
347 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
348 | .info = snd_ak4117_in_error_info, | ||
349 | .get = snd_ak4117_in_error_get, | ||
350 | .private_value = offsetof(ak4117_t, v_bit_errors), | ||
351 | }, | ||
352 | { | ||
353 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
354 | .name = "IEC958 C-CRC Errors", | ||
355 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
356 | .info = snd_ak4117_in_error_info, | ||
357 | .get = snd_ak4117_in_error_get, | ||
358 | .private_value = offsetof(ak4117_t, ccrc_errors), | ||
359 | }, | ||
360 | { | ||
361 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
362 | .name = "IEC958 Q-CRC Errors", | ||
363 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
364 | .info = snd_ak4117_in_error_info, | ||
365 | .get = snd_ak4117_in_error_get, | ||
366 | .private_value = offsetof(ak4117_t, qcrc_errors), | ||
367 | }, | ||
368 | { | ||
369 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
370 | .name = "IEC958 External Rate", | ||
371 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
372 | .info = snd_ak4117_rate_info, | ||
373 | .get = snd_ak4117_rate_get, | ||
374 | }, | ||
375 | { | ||
376 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
377 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK), | ||
378 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
379 | .info = snd_ak4117_spdif_mask_info, | ||
380 | .get = snd_ak4117_spdif_mask_get, | ||
381 | }, | ||
382 | { | ||
383 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
384 | .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), | ||
385 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
386 | .info = snd_ak4117_spdif_info, | ||
387 | .get = snd_ak4117_spdif_get, | ||
388 | }, | ||
389 | { | ||
390 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
391 | .name = "IEC958 Preample Capture Default", | ||
392 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
393 | .info = snd_ak4117_spdif_pinfo, | ||
394 | .get = snd_ak4117_spdif_pget, | ||
395 | }, | ||
396 | { | ||
397 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
398 | .name = "IEC958 Q-subcode Capture Default", | ||
399 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
400 | .info = snd_ak4117_spdif_qinfo, | ||
401 | .get = snd_ak4117_spdif_qget, | ||
402 | }, | ||
403 | { | ||
404 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
405 | .name = "IEC958 Audio", | ||
406 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
407 | .info = snd_ak4117_in_bit_info, | ||
408 | .get = snd_ak4117_in_bit_get, | ||
409 | .private_value = (1<<31) | (3<<8) | AK4117_REG_RCS0, | ||
410 | }, | ||
411 | { | ||
412 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
413 | .name = "IEC958 Non-PCM Bitstream", | ||
414 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
415 | .info = snd_ak4117_in_bit_info, | ||
416 | .get = snd_ak4117_in_bit_get, | ||
417 | .private_value = (5<<8) | AK4117_REG_RCS1, | ||
418 | }, | ||
419 | { | ||
420 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
421 | .name = "IEC958 DTS Bitstream", | ||
422 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, | ||
423 | .info = snd_ak4117_in_bit_info, | ||
424 | .get = snd_ak4117_in_bit_get, | ||
425 | .private_value = (6<<8) | AK4117_REG_RCS1, | ||
426 | }, | ||
427 | { | ||
428 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | ||
429 | .name = "AK4117 Input Select", | ||
430 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, | ||
431 | .info = snd_ak4117_rx_info, | ||
432 | .get = snd_ak4117_rx_get, | ||
433 | .put = snd_ak4117_rx_put, | ||
434 | } | ||
435 | }; | ||
436 | |||
437 | int snd_ak4117_build(ak4117_t *ak4117, snd_pcm_substream_t *cap_substream) | ||
438 | { | ||
439 | snd_kcontrol_t *kctl; | ||
440 | unsigned int idx; | ||
441 | int err; | ||
442 | |||
443 | snd_assert(cap_substream, return -EINVAL); | ||
444 | ak4117->substream = cap_substream; | ||
445 | for (idx = 0; idx < AK4117_CONTROLS; idx++) { | ||
446 | kctl = snd_ctl_new1(&snd_ak4117_iec958_controls[idx], ak4117); | ||
447 | if (kctl == NULL) | ||
448 | return -ENOMEM; | ||
449 | kctl->id.device = cap_substream->pcm->device; | ||
450 | kctl->id.subdevice = cap_substream->number; | ||
451 | err = snd_ctl_add(ak4117->card, kctl); | ||
452 | if (err < 0) | ||
453 | return err; | ||
454 | ak4117->kctls[idx] = kctl; | ||
455 | } | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | int snd_ak4117_external_rate(ak4117_t *ak4117) | ||
460 | { | ||
461 | unsigned char rcs1; | ||
462 | |||
463 | rcs1 = reg_read(ak4117, AK4117_REG_RCS1); | ||
464 | return external_rate(rcs1); | ||
465 | } | ||
466 | |||
467 | int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags) | ||
468 | { | ||
469 | snd_pcm_runtime_t *runtime = ak4117->substream ? ak4117->substream->runtime : NULL; | ||
470 | unsigned long _flags; | ||
471 | int res = 0; | ||
472 | unsigned char rcs0, rcs1, rcs2; | ||
473 | unsigned char c0, c1; | ||
474 | |||
475 | rcs1 = reg_read(ak4117, AK4117_REG_RCS1); | ||
476 | if (flags & AK4117_CHECK_NO_STAT) | ||
477 | goto __rate; | ||
478 | rcs0 = reg_read(ak4117, AK4117_REG_RCS0); | ||
479 | rcs2 = reg_read(ak4117, AK4117_REG_RCS2); | ||
480 | // printk("AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2); | ||
481 | spin_lock_irqsave(&ak4117->lock, _flags); | ||
482 | if (rcs0 & AK4117_PAR) | ||
483 | ak4117->parity_errors++; | ||
484 | if (rcs0 & AK4117_V) | ||
485 | ak4117->v_bit_errors++; | ||
486 | if (rcs2 & AK4117_CCRC) | ||
487 | ak4117->ccrc_errors++; | ||
488 | if (rcs2 & AK4117_QCRC) | ||
489 | ak4117->qcrc_errors++; | ||
490 | c0 = (ak4117->rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)) ^ | ||
491 | (rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)); | ||
492 | c1 = (ak4117->rcs1 & (AK4117_DTSCD | AK4117_NPCM | AK4117_PEM | 0x0f)) ^ | ||
493 | (rcs1 & (AK4117_DTSCD | AK4117_NPCM | AK4117_PEM | 0x0f)); | ||
494 | ak4117->rcs0 = rcs0 & ~(AK4117_QINT | AK4117_CINT | AK4117_STC); | ||
495 | ak4117->rcs1 = rcs1; | ||
496 | ak4117->rcs2 = rcs2; | ||
497 | spin_unlock_irqrestore(&ak4117->lock, _flags); | ||
498 | |||
499 | if (rcs0 & AK4117_PAR) | ||
500 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[0]->id); | ||
501 | if (rcs0 & AK4117_V) | ||
502 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[1]->id); | ||
503 | if (rcs2 & AK4117_CCRC) | ||
504 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[2]->id); | ||
505 | if (rcs2 & AK4117_QCRC) | ||
506 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[3]->id); | ||
507 | |||
508 | /* rate change */ | ||
509 | if (c1 & 0x0f) | ||
510 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[4]->id); | ||
511 | |||
512 | if ((c1 & AK4117_PEM) | (c0 & AK4117_CINT)) | ||
513 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[6]->id); | ||
514 | if (c0 & AK4117_QINT) | ||
515 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[8]->id); | ||
516 | |||
517 | if (c0 & AK4117_AUDION) | ||
518 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[9]->id); | ||
519 | if (c1 & AK4117_NPCM) | ||
520 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[10]->id); | ||
521 | if (c1 & AK4117_DTSCD) | ||
522 | snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[11]->id); | ||
523 | |||
524 | if (ak4117->change_callback && (c0 | c1) != 0) | ||
525 | ak4117->change_callback(ak4117, c0, c1); | ||
526 | |||
527 | __rate: | ||
528 | /* compare rate */ | ||
529 | res = external_rate(rcs1); | ||
530 | if (!(flags & AK4117_CHECK_NO_RATE) && runtime && runtime->rate != res) { | ||
531 | snd_pcm_stream_lock_irqsave(ak4117->substream, _flags); | ||
532 | if (snd_pcm_running(ak4117->substream)) { | ||
533 | // printk("rate changed (%i <- %i)\n", runtime->rate, res); | ||
534 | snd_pcm_stop(ak4117->substream, SNDRV_PCM_STATE_DRAINING); | ||
535 | wake_up(&runtime->sleep); | ||
536 | res = 1; | ||
537 | } | ||
538 | snd_pcm_stream_unlock_irqrestore(ak4117->substream, _flags); | ||
539 | } | ||
540 | return res; | ||
541 | } | ||
542 | |||
543 | static void snd_ak4117_timer(unsigned long data) | ||
544 | { | ||
545 | ak4117_t *chip = (ak4117_t *)data; | ||
546 | |||
547 | if (chip->init) | ||
548 | return; | ||
549 | snd_ak4117_check_rate_and_errors(chip, 0); | ||
550 | chip->timer.expires = 1 + jiffies; | ||
551 | add_timer(&chip->timer); | ||
552 | } | ||
553 | |||
554 | EXPORT_SYMBOL(snd_ak4117_create); | ||
555 | EXPORT_SYMBOL(snd_ak4117_reg_write); | ||
556 | EXPORT_SYMBOL(snd_ak4117_reinit); | ||
557 | EXPORT_SYMBOL(snd_ak4117_build); | ||
558 | EXPORT_SYMBOL(snd_ak4117_external_rate); | ||
559 | EXPORT_SYMBOL(snd_ak4117_check_rate_and_errors); | ||
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c new file mode 100644 index 000000000000..db2b7274a9d6 --- /dev/null +++ b/sound/i2c/other/ak4xxx-adda.c | |||
@@ -0,0 +1,501 @@ | |||
1 | /* | ||
2 | * ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4358 / AK4381 | ||
3 | * AD and DA converters | ||
4 | * | ||
5 | * Copyright (c) 2000-2004 Jaroslav Kysela <perex@suse.cz>, | ||
6 | * Takashi Iwai <tiwai@suse.de> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <sound/driver.h> | ||
25 | #include <asm/io.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <sound/core.h> | ||
30 | #include <sound/control.h> | ||
31 | #include <sound/ak4xxx-adda.h> | ||
32 | |||
33 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Takashi Iwai <tiwai@suse.de>"); | ||
34 | MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters"); | ||
35 | MODULE_LICENSE("GPL"); | ||
36 | |||
37 | void snd_akm4xxx_write(akm4xxx_t *ak, int chip, unsigned char reg, unsigned char val) | ||
38 | { | ||
39 | ak->ops.lock(ak, chip); | ||
40 | ak->ops.write(ak, chip, reg, val); | ||
41 | |||
42 | /* save the data */ | ||
43 | if (ak->type == SND_AK4524 || ak->type == SND_AK4528) { | ||
44 | if ((reg != 0x04 && reg != 0x05) || (val & 0x80) == 0) | ||
45 | snd_akm4xxx_set(ak, chip, reg, val); | ||
46 | else | ||
47 | snd_akm4xxx_set_ipga(ak, chip, reg, val); | ||
48 | } else { | ||
49 | /* AK4529, or else */ | ||
50 | snd_akm4xxx_set(ak, chip, reg, val); | ||
51 | } | ||
52 | ak->ops.unlock(ak, chip); | ||
53 | } | ||
54 | |||
55 | /* | ||
56 | * reset the AKM codecs | ||
57 | * @state: 1 = reset codec, 0 = restore the registers | ||
58 | * | ||
59 | * assert the reset operation and restores the register values to the chips. | ||
60 | */ | ||
61 | void snd_akm4xxx_reset(akm4xxx_t *ak, int state) | ||
62 | { | ||
63 | unsigned int chip; | ||
64 | unsigned char reg; | ||
65 | |||
66 | switch (ak->type) { | ||
67 | case SND_AK4524: | ||
68 | case SND_AK4528: | ||
69 | for (chip = 0; chip < ak->num_dacs/2; chip++) { | ||
70 | snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03); | ||
71 | if (state) | ||
72 | continue; | ||
73 | /* DAC volumes */ | ||
74 | for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++) | ||
75 | snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg)); | ||
76 | if (ak->type == SND_AK4528) | ||
77 | continue; | ||
78 | /* IPGA */ | ||
79 | for (reg = 0x04; reg < 0x06; reg++) | ||
80 | snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get_ipga(ak, chip, reg)); | ||
81 | } | ||
82 | break; | ||
83 | case SND_AK4529: | ||
84 | /* FIXME: needed for ak4529? */ | ||
85 | break; | ||
86 | case SND_AK4355: | ||
87 | case SND_AK4358: | ||
88 | if (state) { | ||
89 | snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ | ||
90 | return; | ||
91 | } | ||
92 | for (reg = 0x00; reg < 0x0b; reg++) | ||
93 | if (reg != 0x01) | ||
94 | snd_akm4xxx_write(ak, 0, reg, snd_akm4xxx_get(ak, 0, reg)); | ||
95 | snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */ | ||
96 | break; | ||
97 | case SND_AK4381: | ||
98 | for (chip = 0; chip < ak->num_dacs/2; chip++) { | ||
99 | snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f); | ||
100 | if (state) | ||
101 | continue; | ||
102 | for (reg = 0x01; reg < 0x05; reg++) | ||
103 | snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg)); | ||
104 | } | ||
105 | break; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | /* | ||
110 | * initialize all the ak4xxx chips | ||
111 | */ | ||
112 | void snd_akm4xxx_init(akm4xxx_t *ak) | ||
113 | { | ||
114 | static unsigned char inits_ak4524[] = { | ||
115 | 0x00, 0x07, /* 0: all power up */ | ||
116 | 0x01, 0x00, /* 1: ADC/DAC reset */ | ||
117 | 0x02, 0x60, /* 2: 24bit I2S */ | ||
118 | 0x03, 0x19, /* 3: deemphasis off */ | ||
119 | 0x01, 0x03, /* 1: ADC/DAC enable */ | ||
120 | 0x04, 0x00, /* 4: ADC left muted */ | ||
121 | 0x05, 0x00, /* 5: ADC right muted */ | ||
122 | 0x04, 0x80, /* 4: ADC IPGA gain 0dB */ | ||
123 | 0x05, 0x80, /* 5: ADC IPGA gain 0dB */ | ||
124 | 0x06, 0x00, /* 6: DAC left muted */ | ||
125 | 0x07, 0x00, /* 7: DAC right muted */ | ||
126 | 0xff, 0xff | ||
127 | }; | ||
128 | static unsigned char inits_ak4528[] = { | ||
129 | 0x00, 0x07, /* 0: all power up */ | ||
130 | 0x01, 0x00, /* 1: ADC/DAC reset */ | ||
131 | 0x02, 0x60, /* 2: 24bit I2S */ | ||
132 | 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */ | ||
133 | 0x01, 0x03, /* 1: ADC/DAC enable */ | ||
134 | 0x04, 0x00, /* 4: ADC left muted */ | ||
135 | 0x05, 0x00, /* 5: ADC right muted */ | ||
136 | 0xff, 0xff | ||
137 | }; | ||
138 | static unsigned char inits_ak4529[] = { | ||
139 | 0x09, 0x01, /* 9: ATS=0, RSTN=1 */ | ||
140 | 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */ | ||
141 | 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */ | ||
142 | 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */ | ||
143 | 0x02, 0xff, /* 2: LOUT1 muted */ | ||
144 | 0x03, 0xff, /* 3: ROUT1 muted */ | ||
145 | 0x04, 0xff, /* 4: LOUT2 muted */ | ||
146 | 0x05, 0xff, /* 5: ROUT2 muted */ | ||
147 | 0x06, 0xff, /* 6: LOUT3 muted */ | ||
148 | 0x07, 0xff, /* 7: ROUT3 muted */ | ||
149 | 0x0b, 0xff, /* B: LOUT4 muted */ | ||
150 | 0x0c, 0xff, /* C: ROUT4 muted */ | ||
151 | 0x08, 0x55, /* 8: deemphasis all off */ | ||
152 | 0xff, 0xff | ||
153 | }; | ||
154 | static unsigned char inits_ak4355[] = { | ||
155 | 0x01, 0x02, /* 1: reset and soft-mute */ | ||
156 | 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */ | ||
157 | 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */ | ||
158 | // 0x02, 0x2e, /* quad speed */ | ||
159 | 0x03, 0x01, /* 3: de-emphasis off */ | ||
160 | 0x04, 0x00, /* 4: LOUT1 volume muted */ | ||
161 | 0x05, 0x00, /* 5: ROUT1 volume muted */ | ||
162 | 0x06, 0x00, /* 6: LOUT2 volume muted */ | ||
163 | 0x07, 0x00, /* 7: ROUT2 volume muted */ | ||
164 | 0x08, 0x00, /* 8: LOUT3 volume muted */ | ||
165 | 0x09, 0x00, /* 9: ROUT3 volume muted */ | ||
166 | 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */ | ||
167 | 0x01, 0x01, /* 1: un-reset, unmute */ | ||
168 | 0xff, 0xff | ||
169 | }; | ||
170 | static unsigned char inits_ak4358[] = { | ||
171 | 0x01, 0x02, /* 1: reset and soft-mute */ | ||
172 | 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */ | ||
173 | 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */ | ||
174 | // 0x02, 0x2e, /* quad speed */ | ||
175 | 0x03, 0x01, /* 3: de-emphasis off */ | ||
176 | 0x04, 0x00, /* 4: LOUT1 volume muted */ | ||
177 | 0x05, 0x00, /* 5: ROUT1 volume muted */ | ||
178 | 0x06, 0x00, /* 6: LOUT2 volume muted */ | ||
179 | 0x07, 0x00, /* 7: ROUT2 volume muted */ | ||
180 | 0x08, 0x00, /* 8: LOUT3 volume muted */ | ||
181 | 0x09, 0x00, /* 9: ROUT3 volume muted */ | ||
182 | 0x0b, 0x00, /* b: LOUT4 volume muted */ | ||
183 | 0x0c, 0x00, /* c: ROUT4 volume muted */ | ||
184 | 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */ | ||
185 | 0x01, 0x01, /* 1: un-reset, unmute */ | ||
186 | 0xff, 0xff | ||
187 | }; | ||
188 | static unsigned char inits_ak4381[] = { | ||
189 | 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */ | ||
190 | 0x01, 0x02, /* 1: de-emphasis off, normal speed, sharp roll-off, DZF off */ | ||
191 | // 0x01, 0x12, /* quad speed */ | ||
192 | 0x02, 0x00, /* 2: DZF disabled */ | ||
193 | 0x03, 0x00, /* 3: LATT 0 */ | ||
194 | 0x04, 0x00, /* 4: RATT 0 */ | ||
195 | 0x00, 0x0f, /* 0: power-up, un-reset */ | ||
196 | 0xff, 0xff | ||
197 | }; | ||
198 | |||
199 | int chip, num_chips; | ||
200 | unsigned char *ptr, reg, data, *inits; | ||
201 | |||
202 | switch (ak->type) { | ||
203 | case SND_AK4524: | ||
204 | inits = inits_ak4524; | ||
205 | num_chips = ak->num_dacs / 2; | ||
206 | break; | ||
207 | case SND_AK4528: | ||
208 | inits = inits_ak4528; | ||
209 | num_chips = ak->num_dacs / 2; | ||
210 | break; | ||
211 | case SND_AK4529: | ||
212 | inits = inits_ak4529; | ||
213 | num_chips = 1; | ||
214 | break; | ||
215 | case SND_AK4355: | ||
216 | inits = inits_ak4355; | ||
217 | num_chips = 1; | ||
218 | break; | ||
219 | case SND_AK4358: | ||
220 | inits = inits_ak4358; | ||
221 | num_chips = 1; | ||
222 | break; | ||
223 | case SND_AK4381: | ||
224 | inits = inits_ak4381; | ||
225 | num_chips = ak->num_dacs / 2; | ||
226 | break; | ||
227 | default: | ||
228 | snd_BUG(); | ||
229 | return; | ||
230 | } | ||
231 | |||
232 | for (chip = 0; chip < num_chips; chip++) { | ||
233 | ptr = inits; | ||
234 | while (*ptr != 0xff) { | ||
235 | reg = *ptr++; | ||
236 | data = *ptr++; | ||
237 | snd_akm4xxx_write(ak, chip, reg, data); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | |||
242 | #define AK_GET_CHIP(val) (((val) >> 8) & 0xff) | ||
243 | #define AK_GET_ADDR(val) ((val) & 0xff) | ||
244 | #define AK_GET_SHIFT(val) (((val) >> 16) & 0x7f) | ||
245 | #define AK_GET_INVERT(val) (((val) >> 23) & 1) | ||
246 | #define AK_GET_MASK(val) (((val) >> 24) & 0xff) | ||
247 | #define AK_COMPOSE(chip,addr,shift,mask) (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24)) | ||
248 | #define AK_INVERT (1<<23) | ||
249 | |||
250 | static int snd_akm4xxx_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
251 | { | ||
252 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); | ||
253 | |||
254 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
255 | uinfo->count = 1; | ||
256 | uinfo->value.integer.min = 0; | ||
257 | uinfo->value.integer.max = mask; | ||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | static int snd_akm4xxx_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | ||
262 | { | ||
263 | akm4xxx_t *ak = snd_kcontrol_chip(kcontrol); | ||
264 | int chip = AK_GET_CHIP(kcontrol->private_value); | ||
265 | int addr = AK_GET_ADDR(kcontrol->private_value); | ||
266 | int invert = AK_GET_INVERT(kcontrol->private_value); | ||
267 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); | ||
268 | unsigned char val = snd_akm4xxx_get(ak, chip, addr); | ||
269 | |||
270 | ucontrol->value.integer.value[0] = invert ? mask - val : val; | ||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | static int snd_akm4xxx_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | ||
275 | { | ||
276 | akm4xxx_t *ak = snd_kcontrol_chip(kcontrol); | ||
277 | int chip = AK_GET_CHIP(kcontrol->private_value); | ||
278 | int addr = AK_GET_ADDR(kcontrol->private_value); | ||
279 | int invert = AK_GET_INVERT(kcontrol->private_value); | ||
280 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); | ||
281 | unsigned char nval = ucontrol->value.integer.value[0] % (mask+1); | ||
282 | int change; | ||
283 | |||
284 | if (invert) | ||
285 | nval = mask - nval; | ||
286 | change = snd_akm4xxx_get(ak, chip, addr) != nval; | ||
287 | if (change) | ||
288 | snd_akm4xxx_write(ak, chip, addr, nval); | ||
289 | return change; | ||
290 | } | ||
291 | |||
292 | static int snd_akm4xxx_ipga_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
293 | { | ||
294 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
295 | uinfo->count = 1; | ||
296 | uinfo->value.integer.min = 0; | ||
297 | uinfo->value.integer.max = 36; | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static int snd_akm4xxx_ipga_gain_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | ||
302 | { | ||
303 | akm4xxx_t *ak = snd_kcontrol_chip(kcontrol); | ||
304 | int chip = AK_GET_CHIP(kcontrol->private_value); | ||
305 | int addr = AK_GET_ADDR(kcontrol->private_value); | ||
306 | ucontrol->value.integer.value[0] = snd_akm4xxx_get_ipga(ak, chip, addr) & 0x7f; | ||
307 | return 0; | ||
308 | } | ||
309 | |||
310 | static int snd_akm4xxx_ipga_gain_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | ||
311 | { | ||
312 | akm4xxx_t *ak = snd_kcontrol_chip(kcontrol); | ||
313 | int chip = AK_GET_CHIP(kcontrol->private_value); | ||
314 | int addr = AK_GET_ADDR(kcontrol->private_value); | ||
315 | unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80; | ||
316 | int change = snd_akm4xxx_get_ipga(ak, chip, addr) != nval; | ||
317 | if (change) | ||
318 | snd_akm4xxx_write(ak, chip, addr, nval); | ||
319 | return change; | ||
320 | } | ||
321 | |||
322 | static int snd_akm4xxx_deemphasis_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) | ||
323 | { | ||
324 | static char *texts[4] = { | ||
325 | "44.1kHz", "Off", "48kHz", "32kHz", | ||
326 | }; | ||
327 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
328 | uinfo->count = 1; | ||
329 | uinfo->value.enumerated.items = 4; | ||
330 | if (uinfo->value.enumerated.item >= 4) | ||
331 | uinfo->value.enumerated.item = 3; | ||
332 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | ||
333 | return 0; | ||
334 | } | ||
335 | |||
336 | static int snd_akm4xxx_deemphasis_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol) | ||
337 | { | ||
338 | akm4xxx_t *ak = snd_kcontrol_chip(kcontrol); | ||
339 | int chip = AK_GET_CHIP(kcontrol->private_value); | ||
340 | int addr = AK_GET_ADDR(kcontrol->private_value); | ||
341 | int shift = AK_GET_SHIFT(kcontrol->private_value); | ||
342 | ucontrol->value.enumerated.item[0] = (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3; | ||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | static int snd_akm4xxx_deemphasis_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | ||
347 | { | ||
348 | akm4xxx_t *ak = snd_kcontrol_chip(kcontrol); | ||
349 | int chip = AK_GET_CHIP(kcontrol->private_value); | ||
350 | int addr = AK_GET_ADDR(kcontrol->private_value); | ||
351 | int shift = AK_GET_SHIFT(kcontrol->private_value); | ||
352 | unsigned char nval = ucontrol->value.enumerated.item[0] & 3; | ||
353 | int change; | ||
354 | |||
355 | nval = (nval << shift) | (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift)); | ||
356 | change = snd_akm4xxx_get(ak, chip, addr) != nval; | ||
357 | if (change) | ||
358 | snd_akm4xxx_write(ak, chip, addr, nval); | ||
359 | return change; | ||
360 | } | ||
361 | |||
362 | /* | ||
363 | * build AK4xxx controls | ||
364 | */ | ||
365 | |||
366 | int snd_akm4xxx_build_controls(akm4xxx_t *ak) | ||
367 | { | ||
368 | unsigned int idx, num_emphs; | ||
369 | snd_kcontrol_t *ctl; | ||
370 | int err; | ||
371 | |||
372 | ctl = kmalloc(sizeof(*ctl), GFP_KERNEL); | ||
373 | if (! ctl) | ||
374 | return -ENOMEM; | ||
375 | |||
376 | for (idx = 0; idx < ak->num_dacs; ++idx) { | ||
377 | memset(ctl, 0, sizeof(*ctl)); | ||
378 | strcpy(ctl->id.name, "DAC Volume"); | ||
379 | ctl->id.index = idx + ak->idx_offset * 2; | ||
380 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
381 | ctl->count = 1; | ||
382 | ctl->info = snd_akm4xxx_volume_info; | ||
383 | ctl->get = snd_akm4xxx_volume_get; | ||
384 | ctl->put = snd_akm4xxx_volume_put; | ||
385 | switch (ak->type) { | ||
386 | case SND_AK4524: | ||
387 | ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); /* register 6 & 7 */ | ||
388 | break; | ||
389 | case SND_AK4528: | ||
390 | ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */ | ||
391 | break; | ||
392 | case SND_AK4529: { | ||
393 | int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */ | ||
394 | ctl->private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT; | ||
395 | break; | ||
396 | } | ||
397 | case SND_AK4355: | ||
398 | ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */ | ||
399 | break; | ||
400 | case SND_AK4358: | ||
401 | if (idx >= 6) | ||
402 | ctl->private_value = AK_COMPOSE(0, idx + 5, 0, 255); /* register 4-9, chip #0 only */ | ||
403 | else | ||
404 | ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */ | ||
405 | break; | ||
406 | case SND_AK4381: | ||
407 | ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); /* register 3 & 4 */ | ||
408 | break; | ||
409 | default: | ||
410 | err = -EINVAL; | ||
411 | goto __error; | ||
412 | } | ||
413 | ctl->private_data = ak; | ||
414 | if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0) | ||
415 | goto __error; | ||
416 | } | ||
417 | for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) { | ||
418 | memset(ctl, 0, sizeof(*ctl)); | ||
419 | strcpy(ctl->id.name, "ADC Volume"); | ||
420 | ctl->id.index = idx + ak->idx_offset * 2; | ||
421 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
422 | ctl->count = 1; | ||
423 | ctl->info = snd_akm4xxx_volume_info; | ||
424 | ctl->get = snd_akm4xxx_volume_get; | ||
425 | ctl->put = snd_akm4xxx_volume_put; | ||
426 | ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */ | ||
427 | ctl->private_data = ak; | ||
428 | if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0) | ||
429 | goto __error; | ||
430 | |||
431 | memset(ctl, 0, sizeof(*ctl)); | ||
432 | strcpy(ctl->id.name, "IPGA Analog Capture Volume"); | ||
433 | ctl->id.index = idx + ak->idx_offset * 2; | ||
434 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
435 | ctl->count = 1; | ||
436 | ctl->info = snd_akm4xxx_ipga_gain_info; | ||
437 | ctl->get = snd_akm4xxx_ipga_gain_get; | ||
438 | ctl->put = snd_akm4xxx_ipga_gain_put; | ||
439 | ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); /* register 4 & 5 */ | ||
440 | ctl->private_data = ak; | ||
441 | if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0) | ||
442 | goto __error; | ||
443 | } | ||
444 | if (ak->type == SND_AK4355 || ak->type == SND_AK4358) | ||
445 | num_emphs = 1; | ||
446 | else | ||
447 | num_emphs = ak->num_dacs / 2; | ||
448 | for (idx = 0; idx < num_emphs; idx++) { | ||
449 | memset(ctl, 0, sizeof(*ctl)); | ||
450 | strcpy(ctl->id.name, "Deemphasis"); | ||
451 | ctl->id.index = idx + ak->idx_offset; | ||
452 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
453 | ctl->count = 1; | ||
454 | ctl->info = snd_akm4xxx_deemphasis_info; | ||
455 | ctl->get = snd_akm4xxx_deemphasis_get; | ||
456 | ctl->put = snd_akm4xxx_deemphasis_put; | ||
457 | switch (ak->type) { | ||
458 | case SND_AK4524: | ||
459 | case SND_AK4528: | ||
460 | ctl->private_value = AK_COMPOSE(idx, 3, 0, 0); /* register 3 */ | ||
461 | break; | ||
462 | case SND_AK4529: { | ||
463 | int shift = idx == 3 ? 6 : (2 - idx) * 2; | ||
464 | ctl->private_value = AK_COMPOSE(0, 8, shift, 0); /* register 8 with shift */ | ||
465 | break; | ||
466 | } | ||
467 | case SND_AK4355: | ||
468 | case SND_AK4358: | ||
469 | ctl->private_value = AK_COMPOSE(idx, 3, 0, 0); | ||
470 | break; | ||
471 | case SND_AK4381: | ||
472 | ctl->private_value = AK_COMPOSE(idx, 1, 1, 0); | ||
473 | break; | ||
474 | } | ||
475 | ctl->private_data = ak; | ||
476 | if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0) | ||
477 | goto __error; | ||
478 | } | ||
479 | err = 0; | ||
480 | |||
481 | __error: | ||
482 | kfree(ctl); | ||
483 | return err; | ||
484 | } | ||
485 | |||
486 | static int __init alsa_akm4xxx_module_init(void) | ||
487 | { | ||
488 | return 0; | ||
489 | } | ||
490 | |||
491 | static void __exit alsa_akm4xxx_module_exit(void) | ||
492 | { | ||
493 | } | ||
494 | |||
495 | module_init(alsa_akm4xxx_module_init) | ||
496 | module_exit(alsa_akm4xxx_module_exit) | ||
497 | |||
498 | EXPORT_SYMBOL(snd_akm4xxx_write); | ||
499 | EXPORT_SYMBOL(snd_akm4xxx_reset); | ||
500 | EXPORT_SYMBOL(snd_akm4xxx_init); | ||
501 | EXPORT_SYMBOL(snd_akm4xxx_build_controls); | ||
diff --git a/sound/i2c/other/tea575x-tuner.c b/sound/i2c/other/tea575x-tuner.c new file mode 100644 index 000000000000..0f05a2b9a370 --- /dev/null +++ b/sound/i2c/other/tea575x-tuner.c | |||
@@ -0,0 +1,233 @@ | |||
1 | /* | ||
2 | * ALSA driver for TEA5757/5759 Philips AM/FM radio tuner chips | ||
3 | * | ||
4 | * Copyright (c) 2004 Jaroslav Kysela <perex@suse.cz> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <sound/driver.h> | ||
24 | #include <asm/io.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <sound/core.h> | ||
29 | #include <sound/tea575x-tuner.h> | ||
30 | |||
31 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
32 | MODULE_DESCRIPTION("Routines for control of TEA5757/5759 Philips AM/FM radio tuner chips"); | ||
33 | MODULE_LICENSE("GPL"); | ||
34 | |||
35 | /* | ||
36 | * definitions | ||
37 | */ | ||
38 | |||
39 | #define TEA575X_BIT_SEARCH (1<<24) /* 1 = search action, 0 = tuned */ | ||
40 | #define TEA575X_BIT_UPDOWN (1<<23) /* 0 = search down, 1 = search up */ | ||
41 | #define TEA575X_BIT_MONO (1<<22) /* 0 = stereo, 1 = mono */ | ||
42 | #define TEA575X_BIT_BAND_MASK (3<<20) | ||
43 | #define TEA575X_BIT_BAND_FM (0<<20) | ||
44 | #define TEA575X_BIT_BAND_MW (1<<20) | ||
45 | #define TEA575X_BIT_BAND_LW (1<<21) | ||
46 | #define TEA575X_BIT_BAND_SW (1<<22) | ||
47 | #define TEA575X_BIT_PORT_0 (1<<19) /* user bit */ | ||
48 | #define TEA575X_BIT_PORT_1 (1<<18) /* user bit */ | ||
49 | #define TEA575X_BIT_SEARCH_MASK (3<<16) /* search level */ | ||
50 | #define TEA575X_BIT_SEARCH_5_28 (0<<16) /* FM >5uV, AM >28uV */ | ||
51 | #define TEA575X_BIT_SEARCH_10_40 (1<<16) /* FM >10uV, AM > 40uV */ | ||
52 | #define TEA575X_BIT_SEARCH_30_63 (2<<16) /* FM >30uV, AM > 63uV */ | ||
53 | #define TEA575X_BIT_SEARCH_150_1000 (3<<16) /* FM > 150uV, AM > 1000uV */ | ||
54 | #define TEA575X_BIT_DUMMY (1<<15) /* buffer */ | ||
55 | #define TEA575X_BIT_FREQ_MASK 0x7fff | ||
56 | |||
57 | /* | ||
58 | * lowlevel part | ||
59 | */ | ||
60 | |||
61 | static void snd_tea575x_set_freq(tea575x_t *tea) | ||
62 | { | ||
63 | unsigned long freq; | ||
64 | |||
65 | freq = tea->freq / 16; /* to kHz */ | ||
66 | if (freq > 108000) | ||
67 | freq = 108000; | ||
68 | if (freq < 87000) | ||
69 | freq = 87000; | ||
70 | /* crystal fixup */ | ||
71 | if (tea->tea5759) | ||
72 | freq -= tea->freq_fixup; | ||
73 | else | ||
74 | freq += tea->freq_fixup; | ||
75 | /* freq /= 12.5 */ | ||
76 | freq *= 10; | ||
77 | freq /= 125; | ||
78 | |||
79 | tea->val &= ~TEA575X_BIT_FREQ_MASK; | ||
80 | tea->val |= freq & TEA575X_BIT_FREQ_MASK; | ||
81 | tea->ops->write(tea, tea->val); | ||
82 | } | ||
83 | |||
84 | /* | ||
85 | * Linux Video interface | ||
86 | */ | ||
87 | |||
88 | static int snd_tea575x_ioctl(struct inode *inode, struct file *file, | ||
89 | unsigned int cmd, unsigned long data) | ||
90 | { | ||
91 | struct video_device *dev = video_devdata(file); | ||
92 | tea575x_t *tea = video_get_drvdata(dev); | ||
93 | void __user *arg = (void __user *)data; | ||
94 | |||
95 | switch(cmd) { | ||
96 | case VIDIOCGCAP: | ||
97 | { | ||
98 | struct video_capability v; | ||
99 | v.type = VID_TYPE_TUNER; | ||
100 | v.channels = 1; | ||
101 | v.audios = 1; | ||
102 | /* No we don't do pictures */ | ||
103 | v.maxwidth = 0; | ||
104 | v.maxheight = 0; | ||
105 | v.minwidth = 0; | ||
106 | v.minheight = 0; | ||
107 | strcpy(v.name, tea->tea5759 ? "TEA5759" : "TEA5757"); | ||
108 | if (copy_to_user(arg,&v,sizeof(v))) | ||
109 | return -EFAULT; | ||
110 | return 0; | ||
111 | } | ||
112 | case VIDIOCGTUNER: | ||
113 | { | ||
114 | struct video_tuner v; | ||
115 | if (copy_from_user(&v, arg,sizeof(v))!=0) | ||
116 | return -EFAULT; | ||
117 | if (v.tuner) /* Only 1 tuner */ | ||
118 | return -EINVAL; | ||
119 | v.rangelow = (87*16000); | ||
120 | v.rangehigh = (108*16000); | ||
121 | v.flags = VIDEO_TUNER_LOW; | ||
122 | v.mode = VIDEO_MODE_AUTO; | ||
123 | strcpy(v.name, "FM"); | ||
124 | v.signal = 0xFFFF; | ||
125 | if (copy_to_user(arg, &v, sizeof(v))) | ||
126 | return -EFAULT; | ||
127 | return 0; | ||
128 | } | ||
129 | case VIDIOCSTUNER: | ||
130 | { | ||
131 | struct video_tuner v; | ||
132 | if(copy_from_user(&v, arg, sizeof(v))) | ||
133 | return -EFAULT; | ||
134 | if(v.tuner!=0) | ||
135 | return -EINVAL; | ||
136 | /* Only 1 tuner so no setting needed ! */ | ||
137 | return 0; | ||
138 | } | ||
139 | case VIDIOCGFREQ: | ||
140 | if(copy_to_user(arg, &tea->freq, sizeof(tea->freq))) | ||
141 | return -EFAULT; | ||
142 | return 0; | ||
143 | case VIDIOCSFREQ: | ||
144 | if(copy_from_user(&tea->freq, arg, sizeof(tea->freq))) | ||
145 | return -EFAULT; | ||
146 | snd_tea575x_set_freq(tea); | ||
147 | return 0; | ||
148 | case VIDIOCGAUDIO: | ||
149 | { | ||
150 | struct video_audio v; | ||
151 | memset(&v, 0, sizeof(v)); | ||
152 | strcpy(v.name, "Radio"); | ||
153 | if(copy_to_user(arg,&v, sizeof(v))) | ||
154 | return -EFAULT; | ||
155 | return 0; | ||
156 | } | ||
157 | case VIDIOCSAUDIO: | ||
158 | { | ||
159 | struct video_audio v; | ||
160 | if(copy_from_user(&v, arg, sizeof(v))) | ||
161 | return -EFAULT; | ||
162 | if(v.audio) | ||
163 | return -EINVAL; | ||
164 | return 0; | ||
165 | } | ||
166 | default: | ||
167 | return -ENOIOCTLCMD; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | static void snd_tea575x_release(struct video_device *vfd) | ||
172 | { | ||
173 | } | ||
174 | |||
175 | /* | ||
176 | * initialize all the tea575x chips | ||
177 | */ | ||
178 | void snd_tea575x_init(tea575x_t *tea) | ||
179 | { | ||
180 | unsigned int val; | ||
181 | |||
182 | val = tea->ops->read(tea); | ||
183 | if (val == 0x1ffffff || val == 0) { | ||
184 | snd_printk(KERN_ERR "Cannot find TEA575x chip\n"); | ||
185 | return; | ||
186 | } | ||
187 | |||
188 | memset(&tea->vd, 0, sizeof(tea->vd)); | ||
189 | tea->vd.owner = tea->card->module; | ||
190 | strcpy(tea->vd.name, tea->tea5759 ? "TEA5759 radio" : "TEA5757 radio"); | ||
191 | tea->vd.type = VID_TYPE_TUNER; | ||
192 | tea->vd.hardware = VID_HARDWARE_RTRACK; /* FIXME: assign new number */ | ||
193 | tea->vd.release = snd_tea575x_release; | ||
194 | video_set_drvdata(&tea->vd, tea); | ||
195 | tea->vd.fops = &tea->fops; | ||
196 | tea->fops.owner = tea->card->module; | ||
197 | tea->fops.open = video_exclusive_open; | ||
198 | tea->fops.release = video_exclusive_release; | ||
199 | tea->fops.ioctl = snd_tea575x_ioctl; | ||
200 | if (video_register_device(&tea->vd, VFL_TYPE_RADIO, tea->dev_nr - 1) < 0) { | ||
201 | snd_printk(KERN_ERR "unable to register tea575x tuner\n"); | ||
202 | return; | ||
203 | } | ||
204 | tea->vd_registered = 1; | ||
205 | |||
206 | tea->val = TEA575X_BIT_BAND_FM | TEA575X_BIT_SEARCH_10_40; | ||
207 | tea->freq = 90500 * 16; /* 90.5Mhz default */ | ||
208 | |||
209 | snd_tea575x_set_freq(tea); | ||
210 | } | ||
211 | |||
212 | void snd_tea575x_exit(tea575x_t *tea) | ||
213 | { | ||
214 | if (tea->vd_registered) { | ||
215 | video_unregister_device(&tea->vd); | ||
216 | tea->vd_registered = 0; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | static int __init alsa_tea575x_module_init(void) | ||
221 | { | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static void __exit alsa_tea575x_module_exit(void) | ||
226 | { | ||
227 | } | ||
228 | |||
229 | module_init(alsa_tea575x_module_init) | ||
230 | module_exit(alsa_tea575x_module_exit) | ||
231 | |||
232 | EXPORT_SYMBOL(snd_tea575x_init); | ||
233 | EXPORT_SYMBOL(snd_tea575x_exit); | ||
diff --git a/sound/i2c/tea6330t.c b/sound/i2c/tea6330t.c new file mode 100644 index 000000000000..bb503e70b664 --- /dev/null +++ b/sound/i2c/tea6330t.c | |||
@@ -0,0 +1,369 @@ | |||
1 | /* | ||
2 | * Routines for control of the TEA6330T circuit via i2c bus | ||
3 | * Sound fader control circuit for car radios by Philips Semiconductors | ||
4 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <sound/driver.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <sound/core.h> | ||
27 | #include <sound/tea6330t.h> | ||
28 | |||
29 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
30 | MODULE_DESCRIPTION("Routines for control of the TEA6330T circuit via i2c bus"); | ||
31 | MODULE_LICENSE("GPL"); | ||
32 | |||
33 | #define TEA6330T_ADDR (0x80>>1) /* fixed address */ | ||
34 | |||
35 | #define TEA6330T_SADDR_VOLUME_LEFT 0x00 /* volume left */ | ||
36 | #define TEA6330T_SADDR_VOLUME_RIGHT 0x01 /* volume right */ | ||
37 | #define TEA6330T_SADDR_BASS 0x02 /* bass control */ | ||
38 | #define TEA6330T_SADDR_TREBLE 0x03 /* treble control */ | ||
39 | #define TEA6330T_SADDR_FADER 0x04 /* fader control */ | ||
40 | #define TEA6330T_MFN 0x20 /* mute control for selected channels */ | ||
41 | #define TEA6330T_FCH 0x10 /* select fader channels - front or rear */ | ||
42 | #define TEA6330T_SADDR_AUDIO_SWITCH 0x05 /* audio switch */ | ||
43 | #define TEA6330T_GMU 0x80 /* mute control, general mute */ | ||
44 | #define TEA6330T_EQN 0x40 /* equalizer switchover (0=equalizer-on) */ | ||
45 | |||
46 | int snd_tea6330t_detect(snd_i2c_bus_t *bus, int equalizer) | ||
47 | { | ||
48 | int res; | ||
49 | |||
50 | snd_i2c_lock(bus); | ||
51 | res = snd_i2c_probeaddr(bus, TEA6330T_ADDR); | ||
52 | snd_i2c_unlock(bus); | ||
53 | return res; | ||
54 | } | ||
55 | |||
56 | #if 0 | ||
57 | static void snd_tea6330t_set(tea6330t_t *tea, | ||
58 | unsigned char addr, unsigned char value) | ||
59 | { | ||
60 | #if 0 | ||
61 | printk("set - 0x%x/0x%x\n", addr, value); | ||
62 | #endif | ||
63 | snd_i2c_write(tea->bus, TEA6330T_ADDR, addr, value, 1); | ||
64 | } | ||
65 | #endif | ||
66 | |||
67 | #define TEA6330T_MASTER_VOLUME(xname, xindex) \ | ||
68 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | ||
69 | .info = snd_tea6330t_info_master_volume, \ | ||
70 | .get = snd_tea6330t_get_master_volume, .put = snd_tea6330t_put_master_volume } | ||
71 | |||
72 | static int snd_tea6330t_info_master_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
73 | { | ||
74 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
75 | uinfo->count = 2; | ||
76 | uinfo->value.integer.min = 0; | ||
77 | uinfo->value.integer.max = 43; | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | static int snd_tea6330t_get_master_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
82 | { | ||
83 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
84 | |||
85 | snd_i2c_lock(tea->bus); | ||
86 | ucontrol->value.integer.value[0] = tea->mleft - 0x14; | ||
87 | ucontrol->value.integer.value[1] = tea->mright - 0x14; | ||
88 | snd_i2c_unlock(tea->bus); | ||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static int snd_tea6330t_put_master_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
93 | { | ||
94 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
95 | int change, count, err; | ||
96 | unsigned char bytes[3]; | ||
97 | unsigned char val1, val2; | ||
98 | |||
99 | val1 = (ucontrol->value.integer.value[0] % 44) + 0x14; | ||
100 | val2 = (ucontrol->value.integer.value[1] % 44) + 0x14; | ||
101 | snd_i2c_lock(tea->bus); | ||
102 | change = val1 != tea->mleft || val2 != tea->mright; | ||
103 | tea->mleft = val1; | ||
104 | tea->mright = val2; | ||
105 | count = 0; | ||
106 | if (tea->regs[TEA6330T_SADDR_VOLUME_LEFT] != 0) { | ||
107 | bytes[count++] = TEA6330T_SADDR_VOLUME_LEFT; | ||
108 | bytes[count++] = tea->regs[TEA6330T_SADDR_VOLUME_LEFT] = tea->mleft; | ||
109 | } | ||
110 | if (tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] != 0) { | ||
111 | if (count == 0) | ||
112 | bytes[count++] = TEA6330T_SADDR_VOLUME_RIGHT; | ||
113 | bytes[count++] = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] = tea->mright; | ||
114 | } | ||
115 | if (count > 0) { | ||
116 | if ((err = snd_i2c_sendbytes(tea->device, bytes, count)) < 0) | ||
117 | change = err; | ||
118 | } | ||
119 | snd_i2c_unlock(tea->bus); | ||
120 | return change; | ||
121 | } | ||
122 | |||
123 | #define TEA6330T_MASTER_SWITCH(xname, xindex) \ | ||
124 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | ||
125 | .info = snd_tea6330t_info_master_switch, \ | ||
126 | .get = snd_tea6330t_get_master_switch, .put = snd_tea6330t_put_master_switch } | ||
127 | |||
128 | static int snd_tea6330t_info_master_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
129 | { | ||
130 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | ||
131 | uinfo->count = 2; | ||
132 | uinfo->value.integer.min = 0; | ||
133 | uinfo->value.integer.max = 1; | ||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | static int snd_tea6330t_get_master_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
138 | { | ||
139 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
140 | |||
141 | snd_i2c_lock(tea->bus); | ||
142 | ucontrol->value.integer.value[0] = tea->regs[TEA6330T_SADDR_VOLUME_LEFT] == 0 ? 0 : 1; | ||
143 | ucontrol->value.integer.value[1] = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] == 0 ? 0 : 1; | ||
144 | snd_i2c_unlock(tea->bus); | ||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static int snd_tea6330t_put_master_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
149 | { | ||
150 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
151 | int change, err; | ||
152 | unsigned char bytes[3]; | ||
153 | unsigned char oval1, oval2, val1, val2; | ||
154 | |||
155 | val1 = ucontrol->value.integer.value[0] & 1; | ||
156 | val2 = ucontrol->value.integer.value[1] & 1; | ||
157 | snd_i2c_lock(tea->bus); | ||
158 | oval1 = tea->regs[TEA6330T_SADDR_VOLUME_LEFT] == 0 ? 0 : 1; | ||
159 | oval2 = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] == 0 ? 0 : 1; | ||
160 | change = val1 != oval1 || val2 != oval2; | ||
161 | tea->regs[TEA6330T_SADDR_VOLUME_LEFT] = val1 ? tea->mleft : 0; | ||
162 | tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] = val2 ? tea->mright : 0; | ||
163 | bytes[0] = TEA6330T_SADDR_VOLUME_LEFT; | ||
164 | bytes[1] = tea->regs[TEA6330T_SADDR_VOLUME_LEFT]; | ||
165 | bytes[2] = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT]; | ||
166 | if ((err = snd_i2c_sendbytes(tea->device, bytes, 3)) < 0) | ||
167 | change = err; | ||
168 | snd_i2c_unlock(tea->bus); | ||
169 | return change; | ||
170 | } | ||
171 | |||
172 | #define TEA6330T_BASS(xname, xindex) \ | ||
173 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | ||
174 | .info = snd_tea6330t_info_bass, \ | ||
175 | .get = snd_tea6330t_get_bass, .put = snd_tea6330t_put_bass } | ||
176 | |||
177 | static int snd_tea6330t_info_bass(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
178 | { | ||
179 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
180 | |||
181 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
182 | uinfo->count = 1; | ||
183 | uinfo->value.integer.min = 0; | ||
184 | uinfo->value.integer.max = tea->max_bass; | ||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | static int snd_tea6330t_get_bass(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
189 | { | ||
190 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
191 | |||
192 | ucontrol->value.integer.value[0] = tea->bass; | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | static int snd_tea6330t_put_bass(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
197 | { | ||
198 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
199 | int change, err; | ||
200 | unsigned char bytes[2]; | ||
201 | unsigned char val1; | ||
202 | |||
203 | val1 = ucontrol->value.integer.value[0] % (tea->max_bass + 1); | ||
204 | snd_i2c_lock(tea->bus); | ||
205 | tea->bass = val1; | ||
206 | val1 += tea->equalizer ? 7 : 3; | ||
207 | change = tea->regs[TEA6330T_SADDR_BASS] != val1; | ||
208 | bytes[0] = TEA6330T_SADDR_BASS; | ||
209 | bytes[1] = tea->regs[TEA6330T_SADDR_BASS] = val1; | ||
210 | if ((err = snd_i2c_sendbytes(tea->device, bytes, 2)) < 0) | ||
211 | change = err; | ||
212 | snd_i2c_unlock(tea->bus); | ||
213 | return change; | ||
214 | } | ||
215 | |||
216 | #define TEA6330T_TREBLE(xname, xindex) \ | ||
217 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | ||
218 | .info = snd_tea6330t_info_treble, \ | ||
219 | .get = snd_tea6330t_get_treble, .put = snd_tea6330t_put_treble } | ||
220 | |||
221 | static int snd_tea6330t_info_treble(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) | ||
222 | { | ||
223 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
224 | |||
225 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
226 | uinfo->count = 1; | ||
227 | uinfo->value.integer.min = 0; | ||
228 | uinfo->value.integer.max = tea->max_treble; | ||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static int snd_tea6330t_get_treble(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
233 | { | ||
234 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
235 | |||
236 | ucontrol->value.integer.value[0] = tea->treble; | ||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | static int snd_tea6330t_put_treble(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) | ||
241 | { | ||
242 | tea6330t_t *tea = snd_kcontrol_chip(kcontrol); | ||
243 | int change, err; | ||
244 | unsigned char bytes[2]; | ||
245 | unsigned char val1; | ||
246 | |||
247 | val1 = ucontrol->value.integer.value[0] % (tea->max_treble + 1); | ||
248 | snd_i2c_lock(tea->bus); | ||
249 | tea->treble = val1; | ||
250 | val1 += 3; | ||
251 | change = tea->regs[TEA6330T_SADDR_TREBLE] != val1; | ||
252 | bytes[0] = TEA6330T_SADDR_TREBLE; | ||
253 | bytes[1] = tea->regs[TEA6330T_SADDR_TREBLE] = val1; | ||
254 | if ((err = snd_i2c_sendbytes(tea->device, bytes, 2)) < 0) | ||
255 | change = err; | ||
256 | snd_i2c_unlock(tea->bus); | ||
257 | return change; | ||
258 | } | ||
259 | |||
260 | static snd_kcontrol_new_t snd_tea6330t_controls[] = { | ||
261 | TEA6330T_MASTER_SWITCH("Master Playback Switch", 0), | ||
262 | TEA6330T_MASTER_VOLUME("Master Playback Volume", 0), | ||
263 | TEA6330T_BASS("Tone Control - Bass", 0), | ||
264 | TEA6330T_TREBLE("Tone Control - Treble", 0) | ||
265 | }; | ||
266 | |||
267 | static void snd_tea6330_free(snd_i2c_device_t *device) | ||
268 | { | ||
269 | tea6330t_t *tea = device->private_data; | ||
270 | kfree(tea); | ||
271 | } | ||
272 | |||
273 | int snd_tea6330t_update_mixer(snd_card_t * card, | ||
274 | snd_i2c_bus_t *bus, | ||
275 | int equalizer, int fader) | ||
276 | { | ||
277 | snd_i2c_device_t *device; | ||
278 | tea6330t_t *tea; | ||
279 | snd_kcontrol_new_t *knew; | ||
280 | unsigned int idx; | ||
281 | int err = -ENOMEM; | ||
282 | u8 default_treble, default_bass; | ||
283 | unsigned char bytes[7]; | ||
284 | |||
285 | tea = kcalloc(1, sizeof(*tea), GFP_KERNEL); | ||
286 | if (tea == NULL) | ||
287 | return -ENOMEM; | ||
288 | if ((err = snd_i2c_device_create(bus, "TEA6330T", TEA6330T_ADDR, &device)) < 0) { | ||
289 | kfree(tea); | ||
290 | return err; | ||
291 | } | ||
292 | tea->device = device; | ||
293 | tea->bus = bus; | ||
294 | tea->equalizer = equalizer; | ||
295 | tea->fader = fader; | ||
296 | device->private_data = tea; | ||
297 | device->private_free = snd_tea6330_free; | ||
298 | |||
299 | snd_i2c_lock(bus); | ||
300 | |||
301 | /* turn fader off and handle equalizer */ | ||
302 | tea->regs[TEA6330T_SADDR_FADER] = 0x3f; | ||
303 | tea->regs[TEA6330T_SADDR_AUDIO_SWITCH] = equalizer ? 0 : TEA6330T_EQN; | ||
304 | /* initialize mixer */ | ||
305 | if (!tea->equalizer) { | ||
306 | tea->max_bass = 9; | ||
307 | tea->max_treble = 8; | ||
308 | default_bass = 3 + 4; | ||
309 | tea->bass = 4; | ||
310 | default_treble = 3 + 4; | ||
311 | tea->treble = 4; | ||
312 | } else { | ||
313 | tea->max_bass = 5; | ||
314 | tea->max_treble = 0; | ||
315 | default_bass = 7 + 4; | ||
316 | tea->bass = 4; | ||
317 | default_treble = 3; | ||
318 | tea->treble = 0; | ||
319 | } | ||
320 | tea->mleft = tea->mright = 0x14; | ||
321 | tea->regs[TEA6330T_SADDR_BASS] = default_bass; | ||
322 | tea->regs[TEA6330T_SADDR_TREBLE] = default_treble; | ||
323 | |||
324 | /* compose I2C message and put the hardware to initial state */ | ||
325 | bytes[0] = TEA6330T_SADDR_VOLUME_LEFT; | ||
326 | for (idx = 0; idx < 6; idx++) | ||
327 | bytes[idx+1] = tea->regs[idx]; | ||
328 | if ((err = snd_i2c_sendbytes(device, bytes, 7)) < 0) | ||
329 | goto __error; | ||
330 | |||
331 | strcat(card->mixername, ",TEA6330T"); | ||
332 | if ((err = snd_component_add(card, "TEA6330T")) < 0) | ||
333 | goto __error; | ||
334 | |||
335 | for (idx = 0; idx < ARRAY_SIZE(snd_tea6330t_controls); idx++) { | ||
336 | knew = &snd_tea6330t_controls[idx]; | ||
337 | if (tea->treble == 0 && !strcmp(knew->name, "Tone Control - Treble")) | ||
338 | continue; | ||
339 | if ((err = snd_ctl_add(card, snd_ctl_new1(knew, tea))) < 0) | ||
340 | goto __error; | ||
341 | } | ||
342 | |||
343 | snd_i2c_unlock(bus); | ||
344 | return 0; | ||
345 | |||
346 | __error: | ||
347 | snd_i2c_unlock(bus); | ||
348 | snd_i2c_device_free(device); | ||
349 | return err; | ||
350 | } | ||
351 | |||
352 | EXPORT_SYMBOL(snd_tea6330t_detect); | ||
353 | EXPORT_SYMBOL(snd_tea6330t_update_mixer); | ||
354 | |||
355 | /* | ||
356 | * INIT part | ||
357 | */ | ||
358 | |||
359 | static int __init alsa_tea6330t_init(void) | ||
360 | { | ||
361 | return 0; | ||
362 | } | ||
363 | |||
364 | static void __exit alsa_tea6330t_exit(void) | ||
365 | { | ||
366 | } | ||
367 | |||
368 | module_init(alsa_tea6330t_init) | ||
369 | module_exit(alsa_tea6330t_exit) | ||