Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 61699
Collapse All | Expand All

(-)ppc/tumbler.c (-1 / +1182 lines)
Lines 1-2 Link Here
1
#define __NO_VERSION__
1
#define __NO_VERSION__
2
#include "../alsa-kernel/ppc/tumbler.c"
2
/*
3
 * PMac Tumbler/Snapper lowlevel functions
4
 *
5
 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
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
 *   Rene Rebe <rene.rebe@gmx.net>:
22
 *     * update from shadow registers on wakeup and headphone plug
23
 *     * automatically toggle DRC on headphone plug
24
 *	
25
 */
26
27
28
#include <sound/driver.h>
29
#include <linux/init.h>
30
#include <linux/delay.h>
31
#include <linux/i2c.h>
32
#include <linux/i2c-dev.h>
33
#include <linux/kmod.h>
34
#include <linux/slab.h>
35
#include <linux/interrupt.h>
36
#include <sound/core.h>
37
#include <asm/io.h>
38
#include <asm/irq.h>
39
#ifdef CONFIG_PPC_HAS_FEATURE_CALLS
40
#include <asm/pmac_feature.h>
41
#endif
42
#include "pmac.h"
43
#include "tumbler_volume.h"
44
45
/* i2c address for tumbler */
46
#define TAS_I2C_ADDR	0x34
47
48
/* registers */
49
#define TAS_REG_MCS	0x01	/* main control */
50
#define TAS_REG_DRC	0x02
51
#define TAS_REG_VOL	0x04
52
#define TAS_REG_TREBLE	0x05
53
#define TAS_REG_BASS	0x06
54
#define TAS_REG_INPUT1	0x07
55
#define TAS_REG_INPUT2	0x08
56
57
/* tas3001c */
58
#define TAS_REG_PCM	TAS_REG_INPUT1
59
 
60
/* tas3004 */
61
#define TAS_REG_LMIX	TAS_REG_INPUT1
62
#define TAS_REG_RMIX	TAS_REG_INPUT2
63
#define TAS_REG_MCS2	0x43		/* main control 2 */
64
#define TAS_REG_ACS	0x40		/* analog control */
65
66
/* mono volumes for tas3001c/tas3004 */
67
enum {
68
	VOL_IDX_PCM_MONO, /* tas3001c only */
69
	VOL_IDX_BASS, VOL_IDX_TREBLE,
70
	VOL_IDX_LAST_MONO
71
};
72
73
/* stereo volumes for tas3004 */
74
enum {
75
	VOL_IDX_PCM, VOL_IDX_PCM2, VOL_IDX_ADC,
76
	VOL_IDX_LAST_MIX
77
};
78
79
typedef struct pmac_gpio {
80
#ifdef CONFIG_PPC_HAS_FEATURE_CALLS
81
	unsigned int addr;
82
#else
83
	void *addr;
84
#endif
85
	int active_state;
86
} pmac_gpio_t;
87
88
typedef struct pmac_tumbler_t {
89
	pmac_keywest_t i2c;
90
	pmac_gpio_t audio_reset;
91
	pmac_gpio_t amp_mute;
92
	pmac_gpio_t hp_mute;
93
	pmac_gpio_t hp_detect;
94
	int headphone_irq;
95
	unsigned int master_vol[2];
96
	unsigned int master_switch[2];
97
	unsigned int mono_vol[VOL_IDX_LAST_MONO];
98
	unsigned int mix_vol[VOL_IDX_LAST_MIX][2]; /* stereo volumes for tas3004 */
99
	int drc_range;
100
	int drc_enable;
101
	int capture_source;
102
} pmac_tumbler_t;
103
104
105
/*
106
 */
107
108
static int send_init_client(pmac_keywest_t *i2c, unsigned int *regs)
109
{
110
	while (*regs > 0) {
111
		int err, count = 10;
112
		do {
113
			err =  snd_pmac_keywest_write_byte(i2c, regs[0], regs[1]);
114
			if (err >= 0)
115
				break;
116
			mdelay(10);
117
		} while (count--);
118
		if (err < 0)
119
			return -ENXIO;
120
		regs += 2;
121
	}
122
	return 0;
123
}
124
125
126
static int tumbler_init_client(pmac_keywest_t *i2c)
127
{
128
	static unsigned int regs[] = {
129
		/* normal operation, SCLK=64fps, i2s output, i2s input, 16bit width */
130
		TAS_REG_MCS, (1<<6)|(2<<4)|(2<<2)|0,
131
		0, /* terminator */
132
	};
133
	return send_init_client(i2c, regs);
134
}
135
136
static int snapper_init_client(pmac_keywest_t *i2c)
137
{
138
	static unsigned int regs[] = {
139
		/* normal operation, SCLK=64fps, i2s output, 16bit width */
140
		TAS_REG_MCS, (1<<6)|(2<<4)|0,
141
		/* normal operation, all-pass mode */
142
		TAS_REG_MCS2, (1<<1),
143
		/* normal output, no deemphasis, A input, power-up, line-in */
144
		TAS_REG_ACS, 0,
145
		0, /* terminator */
146
	};
147
	return send_init_client(i2c, regs);
148
}
149
	
150
/*
151
 * gpio access
152
 */
153
#ifdef CONFIG_PPC_HAS_FEATURE_CALLS
154
#define do_gpio_write(gp, val) \
155
	pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, (gp)->addr, val)
156
#define do_gpio_read(gp) \
157
	pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, (gp)->addr, 0)
158
#define tumbler_gpio_free(gp) /* NOP */
159
#else
160
#define do_gpio_write(gp, val)	writeb(val, (gp)->addr)
161
#define do_gpio_read(gp)	readb((gp)->addr)
162
static inline void tumbler_gpio_free(pmac_gpio_t *gp)
163
{
164
	if (gp->addr) {
165
		iounmap(gp->addr);
166
		gp->addr = 0;
167
	}
168
}
169
#endif /* CONFIG_PPC_HAS_FEATURE_CALLS */
170
171
static void write_audio_gpio(pmac_gpio_t *gp, int active)
172
{
173
	if (! gp->addr)
174
		return;
175
	active = active ? gp->active_state : !gp->active_state;
176
	do_gpio_write(gp, active ? 0x05 : 0x04);
177
}
178
179
static int read_audio_gpio(pmac_gpio_t *gp)
180
{
181
	int ret;
182
	if (! gp->addr)
183
		return 0;
184
	ret = ((do_gpio_read(gp) & 0x02) !=0);
185
	return ret == gp->active_state;
186
}
187
188
/*
189
 * update master volume
190
 */
191
static int tumbler_set_master_volume(pmac_tumbler_t *mix)
192
{
193
	unsigned char block[6];
194
	unsigned int left_vol, right_vol;
195
  
196
	if (! mix->i2c.client)
197
		return -ENODEV;
198
  
199
	if (! mix->master_switch[0])
200
		left_vol = 0;
201
	else {
202
		left_vol = mix->master_vol[0];
203
		if (left_vol >= ARRAY_SIZE(master_volume_table))
204
			left_vol = ARRAY_SIZE(master_volume_table) - 1;
205
		left_vol = master_volume_table[left_vol];
206
	}
207
	if (! mix->master_switch[1])
208
		right_vol = 0;
209
	else {
210
		right_vol = mix->master_vol[1];
211
		if (right_vol >= ARRAY_SIZE(master_volume_table))
212
			right_vol = ARRAY_SIZE(master_volume_table) - 1;
213
		right_vol = master_volume_table[right_vol];
214
	}
215
216
	block[0] = (left_vol >> 16) & 0xff;
217
	block[1] = (left_vol >> 8)  & 0xff;
218
	block[2] = (left_vol >> 0)  & 0xff;
219
220
	block[3] = (right_vol >> 16) & 0xff;
221
	block[4] = (right_vol >> 8)  & 0xff;
222
	block[5] = (right_vol >> 0)  & 0xff;
223
  
224
	if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_VOL, 6, block) < 0) {
225
		snd_printk("failed to set volume \n");  
226
		return -EINVAL; 
227
	}
228
	return 0;
229
}
230
231
232
/* output volume */
233
static int tumbler_info_master_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
234
{
235
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
236
	uinfo->count = 2;
237
	uinfo->value.integer.min = 0;
238
	uinfo->value.integer.max = ARRAY_SIZE(master_volume_table) - 1;
239
	return 0;
240
}
241
242
static int tumbler_get_master_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
243
{
244
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
245
	pmac_tumbler_t *mix = chip->mixer_data;
246
	snd_assert(mix, return -ENODEV);
247
	ucontrol->value.integer.value[0] = mix->master_vol[0];
248
	ucontrol->value.integer.value[1] = mix->master_vol[1];
249
	return 0;
250
}
251
252
static int tumbler_put_master_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
253
{
254
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
255
	pmac_tumbler_t *mix = chip->mixer_data;
256
	int change;
257
258
	snd_assert(mix, return -ENODEV);
259
	change = mix->master_vol[0] != ucontrol->value.integer.value[0] ||
260
		mix->master_vol[1] != ucontrol->value.integer.value[1];
261
	if (change) {
262
		mix->master_vol[0] = ucontrol->value.integer.value[0];
263
		mix->master_vol[1] = ucontrol->value.integer.value[1];
264
		tumbler_set_master_volume(mix);
265
	}
266
	return change;
267
}
268
269
/* output switch */
270
static int tumbler_get_master_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
271
{
272
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
273
	pmac_tumbler_t *mix = chip->mixer_data;
274
	snd_assert(mix, return -ENODEV);
275
	ucontrol->value.integer.value[0] = mix->master_switch[0];
276
	ucontrol->value.integer.value[1] = mix->master_switch[1];
277
	return 0;
278
}
279
280
static int tumbler_put_master_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
281
{
282
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
283
	pmac_tumbler_t *mix = chip->mixer_data;
284
	int change;
285
286
	snd_assert(mix, return -ENODEV);
287
	change = mix->master_switch[0] != ucontrol->value.integer.value[0] ||
288
		mix->master_switch[1] != ucontrol->value.integer.value[1];
289
	if (change) {
290
		mix->master_switch[0] = !!ucontrol->value.integer.value[0];
291
		mix->master_switch[1] = !!ucontrol->value.integer.value[1];
292
		tumbler_set_master_volume(mix);
293
	}
294
	return change;
295
}
296
297
298
/*
299
 * TAS3001c dynamic range compression
300
 */
301
302
#define TAS3001_DRC_MAX		0x5f
303
304
static int tumbler_set_drc(pmac_tumbler_t *mix)
305
{
306
	unsigned char val[2];
307
308
	if (! mix->i2c.client)
309
		return -ENODEV;
310
  
311
	if (mix->drc_enable) {
312
		val[0] = 0xc1; /* enable, 3:1 compression */
313
		if (mix->drc_range > TAS3001_DRC_MAX)
314
			val[1] = 0xf0;
315
		else if (mix->drc_range < 0)
316
			val[1] = 0x91;
317
		else
318
			val[1] = mix->drc_range + 0x91;
319
	} else {
320
		val[0] = 0;
321
		val[1] = 0;
322
	}
323
324
	if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_DRC, 2, val) < 0) {
325
		snd_printk("failed to set DRC\n");  
326
		return -EINVAL; 
327
	}
328
	return 0;
329
}
330
331
/*
332
 * TAS3004
333
 */
334
335
#define TAS3004_DRC_MAX		0xef
336
337
static int snapper_set_drc(pmac_tumbler_t *mix)
338
{
339
	unsigned char val[6];
340
341
	if (! mix->i2c.client)
342
		return -ENODEV;
343
  
344
	if (mix->drc_enable)
345
		val[0] = 0x50; /* 3:1 above threshold */
346
	else
347
		val[0] = 0x51; /* disabled */
348
	val[1] = 0x02; /* 1:1 below threshold */
349
	if (mix->drc_range > 0xef)
350
		val[2] = 0xef;
351
	else if (mix->drc_range < 0)
352
		val[2] = 0x00;
353
	else
354
		val[2] = mix->drc_range;
355
	val[3] = 0xb0;
356
	val[4] = 0x60;
357
	val[5] = 0xa0;
358
359
	if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_DRC, 6, val) < 0) {
360
		snd_printk("failed to set DRC\n");  
361
		return -EINVAL; 
362
	}
363
	return 0;
364
}
365
366
static int tumbler_info_drc_value(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
367
{
368
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
369
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
370
	uinfo->count = 1;
371
	uinfo->value.integer.min = 0;
372
	uinfo->value.integer.max =
373
		chip->model == PMAC_TUMBLER ? TAS3001_DRC_MAX : TAS3004_DRC_MAX;
374
	return 0;
375
}
376
377
static int tumbler_get_drc_value(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
378
{
379
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
380
	pmac_tumbler_t *mix;
381
	if (! (mix = chip->mixer_data))
382
		return -ENODEV;
383
	ucontrol->value.integer.value[0] = mix->drc_range;
384
	return 0;
385
}
386
387
static int tumbler_put_drc_value(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
388
{
389
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
390
	pmac_tumbler_t *mix;
391
	int change;
392
393
	if (! (mix = chip->mixer_data))
394
		return -ENODEV;
395
	change = mix->drc_range != ucontrol->value.integer.value[0];
396
	if (change) {
397
		mix->drc_range = ucontrol->value.integer.value[0];
398
		if (chip->model == PMAC_TUMBLER)
399
			tumbler_set_drc(mix);
400
		else
401
			snapper_set_drc(mix);
402
	}
403
	return change;
404
}
405
406
static int tumbler_get_drc_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
407
{
408
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
409
	pmac_tumbler_t *mix;
410
	if (! (mix = chip->mixer_data))
411
		return -ENODEV;
412
	ucontrol->value.integer.value[0] = mix->drc_enable;
413
	return 0;
414
}
415
416
static int tumbler_put_drc_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
417
{
418
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
419
	pmac_tumbler_t *mix;
420
	int change;
421
422
	if (! (mix = chip->mixer_data))
423
		return -ENODEV;
424
	change = mix->drc_enable != ucontrol->value.integer.value[0];
425
	if (change) {
426
		mix->drc_enable = !!ucontrol->value.integer.value[0];
427
		if (chip->model == PMAC_TUMBLER)
428
			tumbler_set_drc(mix);
429
		else
430
			snapper_set_drc(mix);
431
	}
432
	return change;
433
}
434
435
436
/*
437
 * mono volumes
438
 */
439
440
struct tumbler_mono_vol {
441
	int index;
442
	int reg;
443
	int bytes;
444
	unsigned int max;
445
	unsigned int *table;
446
};
447
448
static int tumbler_set_mono_volume(pmac_tumbler_t *mix, struct tumbler_mono_vol *info)
449
{
450
	unsigned char block[4];
451
	unsigned int vol;
452
	int i;
453
  
454
	if (! mix->i2c.client)
455
		return -ENODEV;
456
  
457
	vol = mix->mono_vol[info->index];
458
	if (vol >= info->max)
459
		vol = info->max - 1;
460
	vol = info->table[vol];
461
	for (i = 0; i < info->bytes; i++)
462
		block[i] = (vol >> ((info->bytes - i - 1) * 8)) & 0xff;
463
	if (snd_pmac_keywest_write(&mix->i2c, info->reg, info->bytes, block) < 0) {
464
		snd_printk("failed to set mono volume %d\n", info->index);  
465
		return -EINVAL; 
466
	}
467
	return 0;
468
}
469
470
static int tumbler_info_mono(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
471
{
472
	struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
473
474
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
475
	uinfo->count = 1;
476
	uinfo->value.integer.min = 0;
477
	uinfo->value.integer.max = info->max - 1;
478
	return 0;
479
}
480
481
static int tumbler_get_mono(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
482
{
483
	struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
484
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
485
	pmac_tumbler_t *mix;
486
	if (! (mix = chip->mixer_data))
487
		return -ENODEV;
488
	ucontrol->value.integer.value[0] = mix->mono_vol[info->index];
489
	return 0;
490
}
491
492
static int tumbler_put_mono(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
493
{
494
	struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
495
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
496
	pmac_tumbler_t *mix;
497
	int change;
498
499
	if (! (mix = chip->mixer_data))
500
		return -ENODEV;
501
	change = mix->mono_vol[info->index] != ucontrol->value.integer.value[0];
502
	if (change) {
503
		mix->mono_vol[info->index] = ucontrol->value.integer.value[0];
504
		tumbler_set_mono_volume(mix, info);
505
	}
506
	return change;
507
}
508
509
/* TAS3001c mono volumes */
510
static struct tumbler_mono_vol tumbler_pcm_vol_info = {
511
	.index = VOL_IDX_PCM_MONO,
512
	.reg = TAS_REG_PCM,
513
	.bytes = 3,
514
	.max = ARRAY_SIZE(mixer_volume_table),
515
	.table = mixer_volume_table,
516
};
517
518
static struct tumbler_mono_vol tumbler_bass_vol_info = {
519
	.index = VOL_IDX_BASS,
520
	.reg = TAS_REG_BASS,
521
	.bytes = 1,
522
	.max = ARRAY_SIZE(bass_volume_table),
523
	.table = bass_volume_table,
524
};
525
526
static struct tumbler_mono_vol tumbler_treble_vol_info = {
527
	.index = VOL_IDX_TREBLE,
528
	.reg = TAS_REG_TREBLE,
529
	.bytes = 1,
530
	.max = ARRAY_SIZE(treble_volume_table),
531
	.table = treble_volume_table,
532
};
533
534
/* TAS3004 mono volumes */
535
static struct tumbler_mono_vol snapper_bass_vol_info = {
536
	.index = VOL_IDX_BASS,
537
	.reg = TAS_REG_BASS,
538
	.bytes = 1,
539
	.max = ARRAY_SIZE(snapper_bass_volume_table),
540
	.table = snapper_bass_volume_table,
541
};
542
543
static struct tumbler_mono_vol snapper_treble_vol_info = {
544
	.index = VOL_IDX_TREBLE,
545
	.reg = TAS_REG_TREBLE,
546
	.bytes = 1,
547
	.max = ARRAY_SIZE(snapper_treble_volume_table),
548
	.table = snapper_treble_volume_table,
549
};
550
551
552
#define DEFINE_MONO(xname,type) { \
553
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
554
	.name = xname, \
555
	.info = tumbler_info_mono, \
556
	.get = tumbler_get_mono, \
557
	.put = tumbler_put_mono, \
558
	.private_value = (unsigned long)(&tumbler_##type##_vol_info), \
559
}
560
561
#define DEFINE_SNAPPER_MONO(xname,type) { \
562
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
563
	.name = xname, \
564
	.info = tumbler_info_mono, \
565
	.get = tumbler_get_mono, \
566
	.put = tumbler_put_mono, \
567
	.private_value = (unsigned long)(&snapper_##type##_vol_info), \
568
}
569
570
571
/*
572
 * snapper mixer volumes
573
 */
574
575
static int snapper_set_mix_vol1(pmac_tumbler_t *mix, int idx, int ch, int reg)
576
{
577
	int i, j, vol;
578
	unsigned char block[9];
579
580
	vol = mix->mix_vol[idx][ch];
581
	if (vol >= ARRAY_SIZE(mixer_volume_table)) {
582
		vol = ARRAY_SIZE(mixer_volume_table) - 1;
583
		mix->mix_vol[idx][ch] = vol;
584
	}
585
586
	for (i = 0; i < 3; i++) {
587
		vol = mix->mix_vol[i][ch];
588
		vol = mixer_volume_table[vol];
589
		for (j = 0; j < 3; j++)
590
			block[i * 3 + j] = (vol >> ((2 - j) * 8)) & 0xff;
591
	}
592
	if (snd_pmac_keywest_write(&mix->i2c, reg, 9, block) < 0) {
593
		snd_printk("failed to set mono volume %d\n", reg);  
594
		return -EINVAL; 
595
	}
596
	return 0;
597
}
598
599
static int snapper_set_mix_vol(pmac_tumbler_t *mix, int idx)
600
{
601
	if (! mix->i2c.client)
602
		return -ENODEV;
603
	if (snapper_set_mix_vol1(mix, idx, 0, TAS_REG_LMIX) < 0 ||
604
	    snapper_set_mix_vol1(mix, idx, 1, TAS_REG_RMIX) < 0)
605
		return -EINVAL;
606
	return 0;
607
}
608
609
static int snapper_info_mix(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
610
{
611
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
612
	uinfo->count = 2;
613
	uinfo->value.integer.min = 0;
614
	uinfo->value.integer.max = ARRAY_SIZE(mixer_volume_table) - 1;
615
	return 0;
616
}
617
618
static int snapper_get_mix(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
619
{
620
	int idx = (int)kcontrol->private_value;
621
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
622
	pmac_tumbler_t *mix;
623
	if (! (mix = chip->mixer_data))
624
		return -ENODEV;
625
	ucontrol->value.integer.value[0] = mix->mix_vol[idx][0];
626
	ucontrol->value.integer.value[1] = mix->mix_vol[idx][1];
627
	return 0;
628
}
629
630
static int snapper_put_mix(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
631
{
632
	int idx = (int)kcontrol->private_value;
633
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
634
	pmac_tumbler_t *mix;
635
	int change;
636
637
	if (! (mix = chip->mixer_data))
638
		return -ENODEV;
639
	change = mix->mix_vol[idx][0] != ucontrol->value.integer.value[0] ||
640
		mix->mix_vol[idx][1] != ucontrol->value.integer.value[1];
641
	if (change) {
642
		mix->mix_vol[idx][0] = ucontrol->value.integer.value[0];
643
		mix->mix_vol[idx][1] = ucontrol->value.integer.value[1];
644
		snapper_set_mix_vol(mix, idx);
645
	}
646
	return change;
647
}
648
649
650
/*
651
 * mute switches
652
 */
653
654
enum { TUMBLER_MUTE_HP, TUMBLER_MUTE_AMP };
655
656
static int tumbler_get_mute_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
657
{
658
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
659
	pmac_tumbler_t *mix;
660
	pmac_gpio_t *gp;
661
	if (! (mix = chip->mixer_data))
662
		return -ENODEV;
663
	gp = (kcontrol->private_value == TUMBLER_MUTE_HP) ? &mix->hp_mute : &mix->amp_mute;
664
	ucontrol->value.integer.value[0] = ! read_audio_gpio(gp);
665
	return 0;
666
}
667
668
static int tumbler_put_mute_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
669
{
670
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
671
	pmac_tumbler_t *mix;
672
	pmac_gpio_t *gp;
673
	int val;
674
#ifdef PMAC_SUPPORT_AUTOMUTE
675
	if (chip->update_automute && chip->auto_mute)
676
		return 0; /* don't touch in the auto-mute mode */
677
#endif	
678
	if (! (mix = chip->mixer_data))
679
		return -ENODEV;
680
	gp = (kcontrol->private_value == TUMBLER_MUTE_HP) ? &mix->hp_mute : &mix->amp_mute;
681
	val = ! read_audio_gpio(gp);
682
	if (val != ucontrol->value.integer.value[0]) {
683
		write_audio_gpio(gp, ! ucontrol->value.integer.value[0]);
684
		return 1;
685
	}
686
	return 0;
687
}
688
689
static int snapper_set_capture_source(pmac_tumbler_t *mix)
690
{
691
	if (! mix->i2c.client)
692
		return -ENODEV;
693
	return snd_pmac_keywest_write_byte(&mix->i2c, TAS_REG_ACS,
694
					   mix->capture_source ? 2 : 0);
695
}
696
697
static int snapper_info_capture_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
698
{
699
	static char *texts[2] = {
700
		"Line", "Mic"
701
	};
702
	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
703
	uinfo->count = 1;
704
	uinfo->value.enumerated.items = 2;
705
	if (uinfo->value.enumerated.item > 1)
706
		uinfo->value.enumerated.item = 1;
707
	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
708
	return 0;
709
}
710
711
static int snapper_get_capture_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
712
{
713
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
714
	pmac_tumbler_t *mix = chip->mixer_data;
715
716
	snd_assert(mix, return -ENODEV);
717
	ucontrol->value.integer.value[0] = mix->capture_source;
718
	return 0;
719
}
720
721
static int snapper_put_capture_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
722
{
723
	pmac_t *chip = snd_kcontrol_chip(kcontrol);
724
	pmac_tumbler_t *mix = chip->mixer_data;
725
	int change;
726
727
	snd_assert(mix, return -ENODEV);
728
	change = ucontrol->value.integer.value[0] != mix->capture_source;
729
	if (change) {
730
		mix->capture_source = !!ucontrol->value.integer.value[0];
731
		snapper_set_capture_source(mix);
732
	}
733
	return change;
734
}
735
736
#define DEFINE_SNAPPER_MIX(xname,idx,ofs) { \
737
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
738
	.name = xname, \
739
	.info = snapper_info_mix, \
740
	.get = snapper_get_mix, \
741
	.put = snapper_put_mix, \
742
	.index = idx,\
743
	.private_value = ofs, \
744
}
745
746
747
/*
748
 */
749
static snd_kcontrol_new_t tumbler_mixers[] __initdata = {
750
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
751
	  .name = "Master Playback Volume",
752
	  .info = tumbler_info_master_volume,
753
	  .get = tumbler_get_master_volume,
754
	  .put = tumbler_put_master_volume
755
	},
756
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
757
	  .name = "Master Playback Switch",
758
	  .info = snd_pmac_boolean_stereo_info,
759
	  .get = tumbler_get_master_switch,
760
	  .put = tumbler_put_master_switch
761
	},
762
	DEFINE_MONO("Tone Control - Bass", bass),
763
	DEFINE_MONO("Tone Control - Treble", treble),
764
	DEFINE_MONO("PCM Playback Volume", pcm),
765
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
766
	  .name = "DRC Range",
767
	  .info = tumbler_info_drc_value,
768
	  .get = tumbler_get_drc_value,
769
	  .put = tumbler_put_drc_value
770
	},
771
};
772
773
static snd_kcontrol_new_t snapper_mixers[] __initdata = {
774
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
775
	  .name = "Master Playback Volume",
776
	  .info = tumbler_info_master_volume,
777
	  .get = tumbler_get_master_volume,
778
	  .put = tumbler_put_master_volume
779
	},
780
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
781
	  .name = "Master Playback Switch",
782
	  .info = snd_pmac_boolean_stereo_info,
783
	  .get = tumbler_get_master_switch,
784
	  .put = tumbler_put_master_switch
785
	},
786
	DEFINE_SNAPPER_MIX("PCM Playback Volume", 0, VOL_IDX_PCM),
787
	DEFINE_SNAPPER_MIX("PCM Playback Volume", 1, VOL_IDX_PCM2),
788
	DEFINE_SNAPPER_MIX("Monitor Mix Volume", 0, VOL_IDX_ADC),
789
	DEFINE_SNAPPER_MONO("Tone Control - Bass", bass),
790
	DEFINE_SNAPPER_MONO("Tone Control - Treble", treble),
791
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
792
	  .name = "DRC Range",
793
	  .info = tumbler_info_drc_value,
794
	  .get = tumbler_get_drc_value,
795
	  .put = tumbler_put_drc_value
796
	},
797
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
798
	  .name = "Input Source", /* FIXME: "Capture Source" doesn't work properly */
799
	  .info = snapper_info_capture_source,
800
	  .get = snapper_get_capture_source,
801
	  .put = snapper_put_capture_source
802
	},
803
};
804
805
static snd_kcontrol_new_t tumbler_hp_sw __initdata = {
806
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
807
	.name = "Headphone Playback Switch",
808
	.info = snd_pmac_boolean_mono_info,
809
	.get = tumbler_get_mute_switch,
810
	.put = tumbler_put_mute_switch,
811
	.private_value = TUMBLER_MUTE_HP,
812
};
813
static snd_kcontrol_new_t tumbler_speaker_sw __initdata = {
814
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815
	.name = "PC Speaker Playback Switch",
816
	.info = snd_pmac_boolean_mono_info,
817
	.get = tumbler_get_mute_switch,
818
	.put = tumbler_put_mute_switch,
819
	.private_value = TUMBLER_MUTE_AMP,
820
};
821
static snd_kcontrol_new_t tumbler_drc_sw __initdata = {
822
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
823
	.name = "DRC Switch",
824
	.info = snd_pmac_boolean_mono_info,
825
	.get = tumbler_get_drc_switch,
826
	.put = tumbler_put_drc_switch
827
};
828
829
830
#ifdef PMAC_SUPPORT_AUTOMUTE
831
/*
832
 * auto-mute stuffs
833
 */
834
static int tumbler_detect_headphone(pmac_t *chip)
835
{
836
	pmac_tumbler_t *mix = chip->mixer_data;
837
	return read_audio_gpio(&mix->hp_detect);
838
}
839
840
static void check_mute(pmac_t *chip, pmac_gpio_t *gp, int val, int do_notify, snd_kcontrol_t *sw)
841
{
842
	//pmac_tumbler_t *mix = chip->mixer_data;
843
	if (val != read_audio_gpio(gp)) {
844
		write_audio_gpio(gp, val);
845
		if (do_notify)
846
			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &sw->id);
847
	}
848
}
849
850
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
851
static struct tq_struct device_change;
852
#else
853
static struct work_struct device_change;
854
#endif
855
856
static void
857
device_change_handler(void *self)
858
{
859
	pmac_t *chip = (pmac_t*) self;
860
	pmac_tumbler_t *mix;
861
862
	if (!chip)
863
		return;
864
865
	mix = chip->mixer_data;
866
867
	/* first set the DRC so the speaker do not explode -ReneR */
868
	if (chip->model == PMAC_TUMBLER)
869
		tumbler_set_drc(mix);
870
	else
871
		snapper_set_drc(mix);
872
873
	/* reset the master volume so the correct amplification is applied */
874
	tumbler_set_master_volume(mix);
875
}
876
877
static void tumbler_update_automute(pmac_t *chip, int do_notify)
878
{
879
	if (chip->auto_mute) {
880
		pmac_tumbler_t *mix = chip->mixer_data;
881
		snd_assert(mix, return);
882
		if (tumbler_detect_headphone(chip)) {
883
			/* mute speaker */
884
			check_mute(chip, &mix->amp_mute, 1, do_notify, chip->speaker_sw_ctl);
885
			check_mute(chip, &mix->hp_mute, 0, do_notify, chip->master_sw_ctl);
886
			mix->drc_enable = 0;
887
888
		} else {
889
			/* unmute speaker */
890
			check_mute(chip, &mix->amp_mute, 0, do_notify, chip->speaker_sw_ctl);
891
			check_mute(chip, &mix->hp_mute, 1, do_notify, chip->master_sw_ctl);
892
			mix->drc_enable = 1;
893
		}
894
		if (do_notify) {
895
			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
896
				       &chip->hp_detect_ctl->id);
897
			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
898
			               &chip->drc_sw_ctl->id);
899
		}
900
901
		/* finally we need to schedule an update of the mixer values
902
		   (master and DRC are enough for now) -ReneR */
903
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
904
		schedule_task(&device_change);
905
#else
906
		schedule_work(&device_change);
907
#endif
908
909
	}
910
}
911
#endif /* PMAC_SUPPORT_AUTOMUTE */
912
913
914
/* interrupt - headphone plug changed */
915
static irqreturn_t headphone_intr(int irq, void *devid, struct pt_regs *regs)
916
{
917
	pmac_t *chip = devid;
918
	if (chip->update_automute && chip->initialized) {
919
		chip->update_automute(chip, 1);
920
		return IRQ_HANDLED;
921
	}
922
	return IRQ_NONE;
923
}
924
925
/* look for audio-gpio device */
926
static struct device_node *find_audio_device(const char *name)
927
{
928
	struct device_node *np;
929
  
930
	if (! (np = find_devices("gpio")))
931
		return NULL;
932
  
933
	for (np = np->child; np; np = np->sibling) {
934
		char *property = get_property(np, "audio-gpio", NULL);
935
		if (property && strcmp(property, name) == 0)
936
			return np;
937
	}  
938
	return NULL;
939
}
940
941
/* look for audio-gpio device */
942
static struct device_node *find_compatible_audio_device(const char *name)
943
{
944
	struct device_node *np;
945
  
946
	if (! (np = find_devices("gpio")))
947
		return NULL;
948
  
949
	for (np = np->child; np; np = np->sibling) {
950
		if (device_is_compatible(np, name))
951
			return np;
952
	}  
953
	return NULL;
954
}
955
956
/* find an audio device and get its address */
957
static unsigned long tumbler_find_device(const char *device, pmac_gpio_t *gp, int is_compatible)
958
{
959
	struct device_node *node;
960
	u32 *base;
961
962
	if (is_compatible)
963
		node = find_compatible_audio_device(device);
964
	else
965
		node = find_audio_device(device);
966
	if (! node) {
967
		snd_printdd("cannot find device %s\n", device);
968
		return -ENODEV;
969
	}
970
971
	base = (u32 *)get_property(node, "AAPL,address", NULL);
972
	if (! base) {
973
		snd_printd("cannot find address for device %s\n", device);
974
		return -ENODEV;
975
	}
976
977
#ifdef CONFIG_PPC_HAS_FEATURE_CALLS
978
	gp->addr = (*base) & 0x0000ffff;
979
#else
980
	gp->addr = (void*)ioremap((unsigned long)(*base), 1);
981
#endif
982
	base = (u32 *)get_property(node, "audio-gpio-active-state", NULL);
983
	if (base)
984
		gp->active_state = *base;
985
	else
986
		gp->active_state = 1;
987
988
989
	return (node->n_intrs > 0) ? node->intrs[0].line : 0;
990
}
991
992
/* reset audio */
993
static void tumbler_reset_audio(pmac_t *chip)
994
{
995
	pmac_tumbler_t *mix = chip->mixer_data;
996
997
	write_audio_gpio(&mix->audio_reset, 0);
998
	big_mdelay(200);
999
	write_audio_gpio(&mix->audio_reset, 1);
1000
	big_mdelay(100);
1001
	write_audio_gpio(&mix->audio_reset, 0);
1002
	big_mdelay(100);
1003
}
1004
1005
#ifdef CONFIG_PMAC_PBOOK
1006
/* resume mixer */
1007
static void tumbler_resume(pmac_t *chip)
1008
{
1009
	pmac_tumbler_t *mix = chip->mixer_data;
1010
1011
	snd_assert(mix, return);
1012
1013
	tumbler_reset_audio(chip);
1014
	if (mix->i2c.client && mix->i2c.init_client) {
1015
		if (mix->i2c.init_client(&mix->i2c) < 0)
1016
			printk(KERN_ERR "tumbler_init_client error\n");
1017
	} else
1018
		printk(KERN_ERR "tumbler: i2c is not initialized\n");
1019
	if (chip->model == PMAC_TUMBLER) {
1020
		tumbler_set_mono_volume(mix, &tumbler_pcm_vol_info);
1021
		tumbler_set_mono_volume(mix, &tumbler_bass_vol_info);
1022
		tumbler_set_mono_volume(mix, &tumbler_treble_vol_info);
1023
		tumbler_set_drc(mix);
1024
	} else {
1025
		snapper_set_mix_vol(mix, VOL_IDX_PCM);
1026
		snapper_set_mix_vol(mix, VOL_IDX_PCM2);
1027
		snapper_set_mix_vol(mix, VOL_IDX_ADC);
1028
		tumbler_set_mono_volume(mix, &snapper_bass_vol_info);
1029
		tumbler_set_mono_volume(mix, &snapper_treble_vol_info);
1030
		snapper_set_drc(mix);
1031
		snapper_set_capture_source(mix);
1032
	}
1033
	tumbler_set_master_volume(mix);
1034
	if (chip->update_automute)
1035
		chip->update_automute(chip, 0);
1036
}
1037
#endif
1038
1039
/* initialize tumbler */
1040
static int __init tumbler_init(pmac_t *chip)
1041
{
1042
	int irq, err;
1043
	pmac_tumbler_t *mix = chip->mixer_data;
1044
	snd_assert(mix, return -EINVAL);
1045
1046
	tumbler_find_device("audio-hw-reset", &mix->audio_reset, 0);
1047
	tumbler_find_device("amp-mute", &mix->amp_mute, 0);
1048
	tumbler_find_device("headphone-mute", &mix->hp_mute, 0);
1049
	irq = tumbler_find_device("headphone-detect", &mix->hp_detect, 0);
1050
	if (irq < 0)
1051
		irq = tumbler_find_device("keywest-gpio15", &mix->hp_detect, 1);
1052
1053
	tumbler_reset_audio(chip);
1054
1055
	/* activate headphone status interrupts */
1056
  	if (irq >= 0) {
1057
		unsigned char val;
1058
		if ((err = request_irq(irq, headphone_intr, 0,
1059
				       "Tumbler Headphone Detection", chip)) < 0)
1060
			return err;
1061
		/* activate headphone status interrupts */
1062
		val = do_gpio_read(&mix->hp_detect);
1063
		do_gpio_write(&mix->hp_detect, val | 0x80);
1064
	}
1065
	mix->headphone_irq = irq;
1066
  
1067
	return 0;
1068
}
1069
1070
static void tumbler_cleanup(pmac_t *chip)
1071
{
1072
	pmac_tumbler_t *mix = chip->mixer_data;
1073
	if (! mix)
1074
		return;
1075
1076
	if (mix->headphone_irq >= 0)
1077
		free_irq(mix->headphone_irq, chip);
1078
	tumbler_gpio_free(&mix->audio_reset);
1079
	tumbler_gpio_free(&mix->amp_mute);
1080
	tumbler_gpio_free(&mix->hp_mute);
1081
	tumbler_gpio_free(&mix->hp_detect);
1082
	snd_pmac_keywest_cleanup(&mix->i2c);
1083
	kfree(mix);
1084
	chip->mixer_data = NULL;
1085
}
1086
1087
/* exported */
1088
int __init snd_pmac_tumbler_init(pmac_t *chip)
1089
{
1090
	int i, err;
1091
	pmac_tumbler_t *mix;
1092
	u32 *paddr;
1093
	struct device_node *tas_node;
1094
	char *chipname;
1095
1096
#ifdef CONFIG_KMOD
1097
	if (current->fs->root)
1098
		request_module("i2c-keywest");
1099
#endif /* CONFIG_KMOD */	
1100
1101
	mix = kmalloc(sizeof(*mix), GFP_KERNEL);
1102
	if (! mix)
1103
		return -ENOMEM;
1104
	memset(mix, 0, sizeof(*mix));
1105
	mix->headphone_irq = -1;
1106
1107
	chip->mixer_data = mix;
1108
	chip->mixer_free = tumbler_cleanup;
1109
1110
	if ((err = tumbler_init(chip)) < 0)
1111
		return err;
1112
1113
	/* set up TAS */
1114
	tas_node = find_devices("deq");
1115
	if (tas_node == NULL)
1116
		return -ENODEV;
1117
1118
	paddr = (u32 *)get_property(tas_node, "i2c-address", NULL);
1119
	if (paddr)
1120
		mix->i2c.addr = (*paddr) >> 1;
1121
	else
1122
		mix->i2c.addr = TAS_I2C_ADDR;
1123
1124
	if (chip->model == PMAC_TUMBLER) {
1125
		mix->i2c.init_client = tumbler_init_client;
1126
		mix->i2c.name = "TAS3001c";
1127
		chipname = "Tumbler";
1128
	} else {
1129
		mix->i2c.init_client = snapper_init_client;
1130
		mix->i2c.name = "TAS3004";
1131
		chipname = "Snapper";
1132
	}
1133
1134
	if ((err = snd_pmac_keywest_init(&mix->i2c)) < 0)
1135
		return err;
1136
1137
	/*
1138
	 * build mixers
1139
	 */
1140
	sprintf(chip->card->mixername, "PowerMac %s", chipname);
1141
1142
	if (chip->model == PMAC_TUMBLER) {
1143
		for (i = 0; i < ARRAY_SIZE(tumbler_mixers); i++) {
1144
			if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&tumbler_mixers[i], chip))) < 0)
1145
				return err;
1146
		}
1147
	} else {
1148
		for (i = 0; i < ARRAY_SIZE(snapper_mixers); i++) {
1149
			if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snapper_mixers[i], chip))) < 0)
1150
				return err;
1151
		}
1152
	}
1153
	chip->master_sw_ctl = snd_ctl_new1(&tumbler_hp_sw, chip);
1154
	if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0)
1155
		return err;
1156
	chip->speaker_sw_ctl = snd_ctl_new1(&tumbler_speaker_sw, chip);
1157
	if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
1158
		return err;
1159
	chip->drc_sw_ctl = snd_ctl_new1(&tumbler_drc_sw, chip);
1160
	if ((err = snd_ctl_add(chip->card, chip->drc_sw_ctl)) < 0)
1161
		return err;
1162
1163
1164
#ifdef CONFIG_PMAC_PBOOK
1165
	chip->resume = tumbler_resume;
1166
#endif
1167
1168
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1169
	INIT_TQUEUE(&device_change, device_change_handler, (void *)chip);
1170
#else
1171
	INIT_WORK(&device_change, device_change_handler, (void *)chip);
1172
#endif
1173
1174
#ifdef PMAC_SUPPORT_AUTOMUTE
1175
	if (mix->headphone_irq >=0 && (err = snd_pmac_add_automute(chip)) < 0)
1176
		return err;
1177
	chip->detect_headphone = tumbler_detect_headphone;
1178
	chip->update_automute = tumbler_update_automute;
1179
	tumbler_update_automute(chip, 0); /* update the status only */
1180
#endif
1181
1182
	return 0;
1183
}
(-)alsa-kernel/ppc/awacs.c (-2 / +2 lines)
Lines 829-838 Link Here
829
				snd_pmac_awacs_mixers)) < 0)
829
				snd_pmac_awacs_mixers)) < 0)
830
		return err;
830
		return err;
831
	if (chip->model == PMAC_SCREAMER)
831
	if (chip->model == PMAC_SCREAMER)
832
		err = build_mixers(chip, num_controls(snd_pmac_screamer_mixers2),
832
		err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
833
				   snd_pmac_screamer_mixers2);
833
				   snd_pmac_screamer_mixers2);
834
	else
834
	else
835
		err = build_mixers(chip, num_controls(snd_pmac_awacs_mixers2),
835
		err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
836
				   snd_pmac_awacs_mixers2);
836
				   snd_pmac_awacs_mixers2);
837
	if (err < 0)
837
	if (err < 0)
838
		return err;
838
		return err;
(-)alsa-kernel/ppc/Kconfig (-1 / +4 lines)
Lines 6-14 Link Here
6
comment "ALSA PowerMac requires I2C"
6
comment "ALSA PowerMac requires I2C"
7
	depends on SND && I2C=n
7
	depends on SND && I2C=n
8
8
9
comment "ALSA PowerMac requires INPUT"
10
	depends on SND && INPUT=n
11
9
config SND_POWERMAC
12
config SND_POWERMAC
10
	tristate "PowerMac (AWACS, DACA, Burgundy, Tumbler, Keywest)"
13
	tristate "PowerMac (AWACS, DACA, Burgundy, Tumbler, Keywest)"
11
	depends on SND && I2C
14
	depends on SND && I2C && INPUT
12
	select SND_PCM
15
	select SND_PCM
13
16
14
endmenu
17
endmenu
(-)alsa-kernel/ppc/pmac.h (+1 lines)
Lines 155-160 Link Here
155
	void (*mixer_free)(pmac_t *);
155
	void (*mixer_free)(pmac_t *);
156
	snd_kcontrol_t *master_sw_ctl;
156
	snd_kcontrol_t *master_sw_ctl;
157
	snd_kcontrol_t *speaker_sw_ctl;
157
	snd_kcontrol_t *speaker_sw_ctl;
158
	snd_kcontrol_t *drc_sw_ctl;	/* only used for tumbler -ReneR */
158
	snd_kcontrol_t *hp_detect_ctl;
159
	snd_kcontrol_t *hp_detect_ctl;
159
160
160
	/* lowlevel callbacks */
161
	/* lowlevel callbacks */
(-)alsa-kernel/ppc/tumbler.c (-13 / +54 lines)
Lines 16-21 Link Here
16
 *   You should have received a copy of the GNU General Public License
16
 *   You should have received a copy of the GNU General Public License
17
 *   along with this program; if not, write to the Free Software
17
 *   along with this program; if not, write to the Free Software
18
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19
 *
20
 *   Rene Rebe <rene.rebe@gmx.net>:
21
 *     * update from shadow registers on wakeup and headphone plug
22
 *     * automatically toggle DRC on headphone plug
23
 *	
19
 */
24
 */
20
25
21
26
Lines 757-768 Link Here
757
	DEFINE_MONO("Tone Control - Treble", treble),
762
	DEFINE_MONO("Tone Control - Treble", treble),
758
	DEFINE_MONO("PCM Playback Volume", pcm),
763
	DEFINE_MONO("PCM Playback Volume", pcm),
759
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
760
	  .name = "DRC Switch",
761
	  .info = snd_pmac_boolean_mono_info,
762
	  .get = tumbler_get_drc_switch,
763
	  .put = tumbler_put_drc_switch
764
	},
765
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
766
	  .name = "DRC Range",
765
	  .name = "DRC Range",
767
	  .info = tumbler_info_drc_value,
766
	  .info = tumbler_info_drc_value,
768
	  .get = tumbler_get_drc_value,
767
	  .get = tumbler_get_drc_value,
Lines 789-800 Link Here
789
	DEFINE_SNAPPER_MONO("Tone Control - Bass", bass),
788
	DEFINE_SNAPPER_MONO("Tone Control - Bass", bass),
790
	DEFINE_SNAPPER_MONO("Tone Control - Treble", treble),
789
	DEFINE_SNAPPER_MONO("Tone Control - Treble", treble),
791
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
790
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
792
	  .name = "DRC Switch",
793
	  .info = snd_pmac_boolean_mono_info,
794
	  .get = tumbler_get_drc_switch,
795
	  .put = tumbler_put_drc_switch
796
	},
797
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
798
	  .name = "DRC Range",
791
	  .name = "DRC Range",
799
	  .info = tumbler_info_drc_value,
792
	  .info = tumbler_info_drc_value,
800
	  .get = tumbler_get_drc_value,
793
	  .get = tumbler_get_drc_value,
Lines 824-829 Link Here
824
	.put = tumbler_put_mute_switch,
817
	.put = tumbler_put_mute_switch,
825
	.private_value = TUMBLER_MUTE_AMP,
818
	.private_value = TUMBLER_MUTE_AMP,
826
};
819
};
820
static snd_kcontrol_new_t tumbler_drc_sw __initdata = {
821
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
822
	.name = "DRC Switch",
823
	.info = snd_pmac_boolean_mono_info,
824
	.get = tumbler_get_drc_switch,
825
	.put = tumbler_put_drc_switch
826
};
827
827
828
828
#ifdef PMAC_SUPPORT_AUTOMUTE
829
#ifdef PMAC_SUPPORT_AUTOMUTE
829
/*
830
/*
Lines 845-850 Link Here
845
	}
846
	}
846
}
847
}
847
848
849
static struct work_struct device_change;
850
851
static void
852
device_change_handler(void *self)
853
{
854
	pmac_t *chip = (pmac_t*) self;
855
	pmac_tumbler_t *mix;
856
857
	if (!chip)
858
		return;
859
860
	mix = chip->mixer_data;
861
862
	/* first set the DRC so the speaker do not explode -ReneR */
863
	if (chip->model == PMAC_TUMBLER)
864
		tumbler_set_drc(mix);
865
	else
866
		snapper_set_drc(mix);
867
868
	/* reset the master volume so the correct amplification is applied */
869
	tumbler_set_master_volume(mix);
870
}
871
848
static void tumbler_update_automute(pmac_t *chip, int do_notify)
872
static void tumbler_update_automute(pmac_t *chip, int do_notify)
849
{
873
{
850
	if (chip->auto_mute) {
874
	if (chip->auto_mute) {
Lines 854-867 Link Here
854
			/* mute speaker */
878
			/* mute speaker */
855
			check_mute(chip, &mix->amp_mute, 1, do_notify, chip->speaker_sw_ctl);
879
			check_mute(chip, &mix->amp_mute, 1, do_notify, chip->speaker_sw_ctl);
856
			check_mute(chip, &mix->hp_mute, 0, do_notify, chip->master_sw_ctl);
880
			check_mute(chip, &mix->hp_mute, 0, do_notify, chip->master_sw_ctl);
881
			mix->drc_enable = 0;
882
857
		} else {
883
		} else {
858
			/* unmute speaker */
884
			/* unmute speaker */
859
			check_mute(chip, &mix->amp_mute, 0, do_notify, chip->speaker_sw_ctl);
885
			check_mute(chip, &mix->amp_mute, 0, do_notify, chip->speaker_sw_ctl);
860
			check_mute(chip, &mix->hp_mute, 1, do_notify, chip->master_sw_ctl);
886
			check_mute(chip, &mix->hp_mute, 1, do_notify, chip->master_sw_ctl);
887
			mix->drc_enable = 1;
861
		}
888
		}
862
		if (do_notify)
889
		if (do_notify) {
863
			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
890
			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
864
				       &chip->hp_detect_ctl->id);
891
				       &chip->hp_detect_ctl->id);
892
			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
893
			               &chip->drc_sw_ctl->id);
894
		}
895
896
		/* finally we need to schedule an update of the mixer values
897
		   (master and DRC are enough for now) -ReneR */
898
		schedule_work(&device_change);
899
865
	}
900
	}
866
}
901
}
867
#endif /* PMAC_SUPPORT_AUTOMUTE */
902
#endif /* PMAC_SUPPORT_AUTOMUTE */
Lines 1112-1122 Link Here
1112
	chip->speaker_sw_ctl = snd_ctl_new1(&tumbler_speaker_sw, chip);
1147
	chip->speaker_sw_ctl = snd_ctl_new1(&tumbler_speaker_sw, chip);
1113
	if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
1148
	if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
1114
		return err;
1149
		return err;
1150
	chip->drc_sw_ctl = snd_ctl_new1(&tumbler_drc_sw, chip);
1151
	if ((err = snd_ctl_add(chip->card, chip->drc_sw_ctl)) < 0)
1152
		return err;
1153
1115
1154
1116
#ifdef CONFIG_PMAC_PBOOK
1155
#ifdef CONFIG_PMAC_PBOOK
1117
	chip->resume = tumbler_resume;
1156
	chip->resume = tumbler_resume;
1118
#endif
1157
#endif
1119
1158
1159
	INIT_WORK(&device_change, device_change_handler, (void *)chip);
1160
1120
#ifdef PMAC_SUPPORT_AUTOMUTE
1161
#ifdef PMAC_SUPPORT_AUTOMUTE
1121
	if (mix->headphone_irq >=0 && (err = snd_pmac_add_automute(chip)) < 0)
1162
	if (mix->headphone_irq >=0 && (err = snd_pmac_add_automute(chip)) < 0)
1122
		return err;
1163
		return err;

Return to bug 61699