2 * PMac DACA lowlevel functions
4 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/i2c.h>
25 #include <linux/kmod.h>
26 #include <linux/slab.h>
27 #include <sound/core.h>
31 #define DACA_I2C_ADDR 0x4d
34 #define DACA_REG_SR 0x01
35 #define DACA_REG_AVOL 0x02
36 #define DACA_REG_GCFG 0x03
38 /* maximum volume value */
39 #define DACA_VOL_MAX 0x38
43 struct pmac_keywest i2c
;
44 int left_vol
, right_vol
;
45 unsigned int deemphasis
: 1;
46 unsigned int amp_on
: 1;
51 * initialize / detect DACA
53 static int daca_init_client(struct pmac_keywest
*i2c
)
55 unsigned short wdata
= 0x00;
56 /* SR: no swap, 1bit delay, 32-48kHz */
57 /* GCFG: power amp inverted, DAC on */
58 if (i2c_smbus_write_byte_data(i2c
->client
, DACA_REG_SR
, 0x08) < 0 ||
59 i2c_smbus_write_byte_data(i2c
->client
, DACA_REG_GCFG
, 0x05) < 0)
61 return i2c_smbus_write_block_data(i2c
->client
, DACA_REG_AVOL
,
62 2, (unsigned char*)&wdata
);
68 static int daca_set_volume(struct pmac_daca
*mix
)
70 unsigned char data
[2];
72 if (! mix
->i2c
.client
)
75 if (mix
->left_vol
> DACA_VOL_MAX
)
76 data
[0] = DACA_VOL_MAX
;
78 data
[0] = mix
->left_vol
;
79 if (mix
->right_vol
> DACA_VOL_MAX
)
80 data
[1] = DACA_VOL_MAX
;
82 data
[1] = mix
->right_vol
;
83 data
[1] |= mix
->deemphasis
? 0x40 : 0;
84 if (i2c_smbus_write_block_data(mix
->i2c
.client
, DACA_REG_AVOL
,
86 snd_printk("failed to set volume \n");
93 /* deemphasis switch */
94 #define daca_info_deemphasis snd_ctl_boolean_mono_info
96 static int daca_get_deemphasis(struct snd_kcontrol
*kcontrol
,
97 struct snd_ctl_elem_value
*ucontrol
)
99 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
100 struct pmac_daca
*mix
;
101 if (! (mix
= chip
->mixer_data
))
103 ucontrol
->value
.integer
.value
[0] = mix
->deemphasis
? 1 : 0;
107 static int daca_put_deemphasis(struct snd_kcontrol
*kcontrol
,
108 struct snd_ctl_elem_value
*ucontrol
)
110 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
111 struct pmac_daca
*mix
;
114 if (! (mix
= chip
->mixer_data
))
116 change
= mix
->deemphasis
!= ucontrol
->value
.integer
.value
[0];
118 mix
->deemphasis
= ucontrol
->value
.integer
.value
[0];
119 daca_set_volume(mix
);
125 static int daca_info_volume(struct snd_kcontrol
*kcontrol
,
126 struct snd_ctl_elem_info
*uinfo
)
128 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
130 uinfo
->value
.integer
.min
= 0;
131 uinfo
->value
.integer
.max
= DACA_VOL_MAX
;
135 static int daca_get_volume(struct snd_kcontrol
*kcontrol
,
136 struct snd_ctl_elem_value
*ucontrol
)
138 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
139 struct pmac_daca
*mix
;
140 if (! (mix
= chip
->mixer_data
))
142 ucontrol
->value
.integer
.value
[0] = mix
->left_vol
;
143 ucontrol
->value
.integer
.value
[1] = mix
->right_vol
;
147 static int daca_put_volume(struct snd_kcontrol
*kcontrol
,
148 struct snd_ctl_elem_value
*ucontrol
)
150 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
151 struct pmac_daca
*mix
;
154 if (! (mix
= chip
->mixer_data
))
156 change
= mix
->left_vol
!= ucontrol
->value
.integer
.value
[0] ||
157 mix
->right_vol
!= ucontrol
->value
.integer
.value
[1];
159 mix
->left_vol
= ucontrol
->value
.integer
.value
[0];
160 mix
->right_vol
= ucontrol
->value
.integer
.value
[1];
161 daca_set_volume(mix
);
166 /* amplifier switch */
167 #define daca_info_amp daca_info_deemphasis
169 static int daca_get_amp(struct snd_kcontrol
*kcontrol
,
170 struct snd_ctl_elem_value
*ucontrol
)
172 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
173 struct pmac_daca
*mix
;
174 if (! (mix
= chip
->mixer_data
))
176 ucontrol
->value
.integer
.value
[0] = mix
->amp_on
? 1 : 0;
180 static int daca_put_amp(struct snd_kcontrol
*kcontrol
,
181 struct snd_ctl_elem_value
*ucontrol
)
183 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
184 struct pmac_daca
*mix
;
187 if (! (mix
= chip
->mixer_data
))
189 change
= mix
->amp_on
!= ucontrol
->value
.integer
.value
[0];
191 mix
->amp_on
= ucontrol
->value
.integer
.value
[0];
192 i2c_smbus_write_byte_data(mix
->i2c
.client
, DACA_REG_GCFG
,
193 mix
->amp_on
? 0x05 : 0x04);
198 static struct snd_kcontrol_new daca_mixers
[] = {
199 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
200 .name
= "Deemphasis Switch",
201 .info
= daca_info_deemphasis
,
202 .get
= daca_get_deemphasis
,
203 .put
= daca_put_deemphasis
205 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
206 .name
= "Master Playback Volume",
207 .info
= daca_info_volume
,
208 .get
= daca_get_volume
,
209 .put
= daca_put_volume
211 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
212 .name
= "Power Amplifier Switch",
213 .info
= daca_info_amp
,
221 static void daca_resume(struct snd_pmac
*chip
)
223 struct pmac_daca
*mix
= chip
->mixer_data
;
224 i2c_smbus_write_byte_data(mix
->i2c
.client
, DACA_REG_SR
, 0x08);
225 i2c_smbus_write_byte_data(mix
->i2c
.client
, DACA_REG_GCFG
,
226 mix
->amp_on
? 0x05 : 0x04);
227 daca_set_volume(mix
);
229 #endif /* CONFIG_PM */
232 static void daca_cleanup(struct snd_pmac
*chip
)
234 struct pmac_daca
*mix
= chip
->mixer_data
;
237 snd_pmac_keywest_cleanup(&mix
->i2c
);
239 chip
->mixer_data
= NULL
;
243 int __init
snd_pmac_daca_init(struct snd_pmac
*chip
)
246 struct pmac_daca
*mix
;
249 if (current
->fs
->root
)
250 request_module("i2c-powermac");
251 #endif /* CONFIG_KMOD */
253 mix
= kzalloc(sizeof(*mix
), GFP_KERNEL
);
256 chip
->mixer_data
= mix
;
257 chip
->mixer_free
= daca_cleanup
;
258 mix
->amp_on
= 1; /* default on */
260 mix
->i2c
.addr
= DACA_I2C_ADDR
;
261 mix
->i2c
.init_client
= daca_init_client
;
262 mix
->i2c
.name
= "DACA";
263 if ((err
= snd_pmac_keywest_init(&mix
->i2c
)) < 0)
269 strcpy(chip
->card
->mixername
, "PowerMac DACA");
271 for (i
= 0; i
< ARRAY_SIZE(daca_mixers
); i
++) {
272 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&daca_mixers
[i
], chip
))) < 0)
277 chip
->resume
= daca_resume
;