summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/io/audio/ac97/ac97_alc.c
blob: 73ed9828af839cf0ea148167671076a785d18028 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * ALC (Realtek/Advance Logic) codec extensions.
 */

#include <sys/types.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/audio/audio_driver.h>
#include <sys/audio/ac97.h>
#include <sys/note.h>
#include "ac97_impl.h"

#define	ALC_DATA_FLOW_CTRL_REGISTER	0x6a
#define	ADFC_SPDIFIN_EN			0x8000
#define	ADFC_SPDIFIN_MON_EN		0x4000
#define	ADFC_SPDIF_OUT_MASK		0x3000
#define	ADFC_SPDIF_OUT_ACLINK		0x0000
#define	ADFC_SPDIF_OUT_ADC		0x1000
#define	ADFC_SPDIF_OUT_BYPASS		0x2000
#define	ADFC_PCM_SPDIFIN		0x0800
#define	ADFC_BACK_SURROUND		0x0400	/* ALC850 only */
#define	ADFC_CENTER_LFE			0x0400	/* ALC650 series */
#define	ADFC_MIC			0x0000
#define	ADFC_SURROUND			0x0200
#define	ADFC_LINEIN			0x0000
#define	ADFC_FRONT_MIC_MONO_OUT		0x0100	/* ALC850 */
#define	ADFC_ANALOG_INPUT_PASS_CLFE	0x0020
#define	ADFC_ANALOG_INPUT_PASS_SURROUND	0x0010
#define	ADFC_SURROUND_MIRROR		0x0001

#define	ALC_SURROUND_DAC_REGISTER	0x64
#define	ASD_SURROUND_MUTE		0x8000
#define	ASD_SURR_LEFT_VOL		0x1f00
#define	ASD_SURR_RIGHT_VOL		0x001f

#define	ALC_CEN_LFE_DAC_REGISTER	0x66
#define	ACLD_CEN_LFE_MUTE		0x8000
#define	ACLD_LFE_VOL			0x1f00
#define	ACLD_CEN_VOL			0x001f

#define	ALC_MISC_CTRL_REGISTER		0x7a
#define	AMC_XTLSEL			0x8000
#define	AMC_VREFOUT_DIS			0x1000
#define	AMC_INDEP_MUTE_CTRL		0x0800
#define	AMC_JD2_SURR_CEN_LFE		0x0008
#define	AMC_JD1_SURR_CEN_LFE		0x0004
#define	AMC_PIN47_SPDIF			0x0002
#define	AMC_PIN47_EAPD			0x0000
#define	AMC_JD0_SURR_CEN_LFE		0x0001

static void
alc650_set_linein_func(ac97_ctrl_t *actrl, uint64_t value)
{
	ac97_t		*ac = actrl->actrl_ac97;

	ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0);	/* select page 0 */
	if (value & 2) {
		ac_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_SURROUND);
	} else {
		ac_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_SURROUND);
	}
}

static void
alc650_set_mic_func(ac97_ctrl_t *actrl, uint64_t value)
{
	ac97_t		*ac = actrl->actrl_ac97;

	ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0);	/* select page 0 */
	if (value & 2) {
		ac_set(ac, ALC_MISC_CTRL_REGISTER, AMC_VREFOUT_DIS);
		ac_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_CENTER_LFE);
	} else {
		ac_clr(ac, ALC_MISC_CTRL_REGISTER, AMC_VREFOUT_DIS);
		ac_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_CENTER_LFE);
	}
}

#if 0
static void
alc850_set_auxin_func(ac97_ctrl_t *actrl, uint64_t value)
{
	ac97_t		*ac = actrl->actrl_ac97;

	ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0);	/* select page 0 */
	if (value & 2) {
		ac_set(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_BACK_SURROUND);
	} else {
		ac_clr(ac, ALC_DATA_FLOW_CTRL_REGISTER, ADFC_BACK_SURROUND);
	}
}
#endif

static void
alc650_set_pcm(ac97_ctrl_t *actrl, uint64_t value)
{
	ac97_t		*ac = actrl->actrl_ac97;
	uint16_t	adj_value;
	uint16_t	mute;
	uint8_t		vol;

	/* limit input values to 16 bits and split to right and left */
	vol = value & 0xff;

	/* If this control is mute-able than set as muted if needed */
	mute = vol ? 0 : ASD_SURROUND_MUTE;
	adj_value = ac_val_scale(vol, vol, 5) | mute;

	/* select page 0 */
	ac_wr(ac, AC97_INTERRUPT_PAGING_REGISTER, 0);
	/* adjust all three PCM volumes */
	ac_wr(ac, AC97_PCM_OUT_VOLUME_REGISTER, adj_value);
	ac_wr(ac, ALC_SURROUND_DAC_REGISTER, adj_value);
	ac_wr(ac, ALC_CEN_LFE_DAC_REGISTER, adj_value);
}

static const char *alc_linein_funcs[] = {
	AUDIO_PORT_LINEIN,
	AUDIO_PORT_SURROUND,
	NULL
};

static const char *alc_mic_funcs[] = {
	AUDIO_PORT_MIC,
	AUDIO_PORT_CENLFE,
	NULL
};

static ac97_ctrl_probe_t alc650_linein_func_cpt = {
	AUDIO_CTRL_ID_JACK1, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM, AC97_FLAGS,
	0, alc650_set_linein_func, NULL, 0, alc_linein_funcs
};
static ac97_ctrl_probe_t alc650_mic_func_cpt = {
	AUDIO_CTRL_ID_JACK2, 1, 3, 3, AUDIO_CTRL_TYPE_ENUM, AC97_FLAGS,
	0, alc650_set_mic_func, NULL, 0, alc_mic_funcs
};

static void
alc_pcm_override(ac97_t *ac)
{
	ac97_ctrl_t	*ctrl;

	/* override master PCM volume function */
	ctrl = ac97_control_find(ac, AUDIO_CTRL_ID_VOLUME);
	if (ctrl != NULL) {
		ctrl->actrl_write_fn = alc650_set_pcm;
	}
}

void
alc650_init(ac97_t *ac)
{
	ac97_ctrl_probe_t	cp;
	int			ival;

	bcopy(&alc650_linein_func_cpt, &cp, sizeof (cp));
	ival = ac_get_prop(ac, AC97_PROP_LINEIN_FUNC, 0);
	if ((ival >= 1) && (ival <= 2)) {
		cp.cp_initval = ival;
	}
	ac_add_control(ac, &cp);

	bcopy(&alc650_mic_func_cpt, &cp, sizeof (cp));
	ival = ac_get_prop(ac, AC97_PROP_MIC_FUNC, 0);
	if ((ival >= 1) && (ival <= 2)) {
		cp.cp_initval = ival;
	}
	ac_add_control(ac, &cp);

	alc_pcm_override(ac);
}

void
alc850_init(ac97_t *ac)
{
	/*
	 * NB: We could probably enable 7.1 here using the AUXIN source,
	 * but there are a few details still missing from the data sheet.
	 * (Such as, how is volume from the back-surround DAC managed?,
	 * and what SDATA slots are the back surround delivered on?)
	 *
	 * Also, the AC'97 controllers themselves don't necessarily support
	 * 7.1, so we'd have to figure out how to coordinate detection
	 * with the controller.  5.1 should be good enough for now.
	 *
	 * Unlike other products, ALC850 has separate pins for 5.1 data,
	 * so jack retasking isn't needed.  However, it can retask
	 * some jacks, but we don't have full details for that right
	 * now.  We've not seen it on any systems (yet) where this was
	 * necessary, though.
	 */

	alc_pcm_override(ac);
}