This source file includes following definitions.
- psc724_wm8766_write
- psc724_wm8776_write
- psc724_set_master_switch
- psc724_get_master_switch
- psc724_set_jack_state
- psc724_update_hp_jack_state
- psc724_set_jack_detection
- psc724_get_jack_detection
- psc724_ctl_get
- psc724_ctl_put
- psc724_add_controls
- psc724_set_pro_rate
- psc724_resume
- psc724_init
- psc724_exit
1
2
3
4
5
6
7
8
9
10 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include <sound/core.h>
14
15 #include "ice1712.h"
16 #include "envy24ht.h"
17 #include "psc724.h"
18 #include "wm8766.h"
19 #include "wm8776.h"
20
21 struct psc724_spec {
22 struct snd_wm8766 wm8766;
23 struct snd_wm8776 wm8776;
24 bool mute_all, jack_detect;
25 struct snd_ice1712 *ice;
26 struct delayed_work hp_work;
27 bool hp_connected;
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 #define GPIO_HP_JACK (1 << 14)
92 #define GPIO_MUTE_SUR (1 << 20)
93 #define GPIO_MUTE_ALL (1 << 22)
94
95 #define JACK_INTERVAL 1000
96
97 #define PSC724_SPI_DELAY 1
98
99 #define PSC724_SPI_DATA (1 << 16)
100 #define PSC724_SPI_CLK (1 << 17)
101 #define PSC724_SPI_LOAD (1 << 18)
102 #define PSC724_SPI_MASK (PSC724_SPI_DATA | PSC724_SPI_CLK | PSC724_SPI_LOAD)
103
104 static void psc724_wm8766_write(struct snd_wm8766 *wm, u16 addr, u16 data)
105 {
106 struct psc724_spec *spec = container_of(wm, struct psc724_spec, wm8766);
107 struct snd_ice1712 *ice = spec->ice;
108 u32 st, bits;
109 int i;
110
111 snd_ice1712_save_gpio_status(ice);
112
113 st = ((addr & 0x7f) << 9) | (data & 0x1ff);
114 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction | PSC724_SPI_MASK);
115 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask & ~PSC724_SPI_MASK);
116 bits = snd_ice1712_gpio_read(ice) & ~PSC724_SPI_MASK;
117 snd_ice1712_gpio_write(ice, bits);
118
119 for (i = 0; i < 16; i++) {
120 udelay(PSC724_SPI_DELAY);
121 bits &= ~PSC724_SPI_CLK;
122
123 st <<= 1;
124 if (st & 0x10000)
125 bits |= PSC724_SPI_DATA;
126 else
127 bits &= ~PSC724_SPI_DATA;
128 snd_ice1712_gpio_write(ice, bits);
129
130 udelay(PSC724_SPI_DELAY);
131 bits |= PSC724_SPI_CLK;
132 snd_ice1712_gpio_write(ice, bits);
133 }
134
135 udelay(PSC724_SPI_DELAY);
136 bits |= PSC724_SPI_LOAD;
137 snd_ice1712_gpio_write(ice, bits);
138
139 udelay(PSC724_SPI_DELAY);
140 bits |= (PSC724_SPI_DATA | PSC724_SPI_CLK);
141 snd_ice1712_gpio_write(ice, bits);
142
143 snd_ice1712_restore_gpio_status(ice);
144 }
145
146 static void psc724_wm8776_write(struct snd_wm8776 *wm, u8 addr, u8 data)
147 {
148 struct psc724_spec *spec = container_of(wm, struct psc724_spec, wm8776);
149
150 snd_vt1724_write_i2c(spec->ice, 0x34, addr, data);
151 }
152
153
154
155 static void psc724_set_master_switch(struct snd_ice1712 *ice, bool on)
156 {
157 unsigned int bits = snd_ice1712_gpio_read(ice);
158 struct psc724_spec *spec = ice->spec;
159
160 spec->mute_all = !on;
161 if (on)
162 bits &= ~(GPIO_MUTE_ALL | GPIO_MUTE_SUR);
163 else
164 bits |= GPIO_MUTE_ALL | GPIO_MUTE_SUR;
165 snd_ice1712_gpio_write(ice, bits);
166 }
167
168 static bool psc724_get_master_switch(struct snd_ice1712 *ice)
169 {
170 struct psc724_spec *spec = ice->spec;
171
172 return !spec->mute_all;
173 }
174
175
176
177 static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected)
178 {
179 struct psc724_spec *spec = ice->spec;
180 struct snd_ctl_elem_id elem_id;
181 struct snd_kcontrol *kctl;
182 u16 power = spec->wm8776.regs[WM8776_REG_PWRDOWN] & ~WM8776_PWR_HPPD;
183
184 psc724_set_master_switch(ice, !hp_connected);
185 if (!hp_connected)
186 power |= WM8776_PWR_HPPD;
187 snd_wm8776_set_power(&spec->wm8776, power);
188 spec->hp_connected = hp_connected;
189
190 memset(&elem_id, 0, sizeof(elem_id));
191 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
192 strlcpy(elem_id.name, "Master Speakers Playback Switch",
193 sizeof(elem_id.name));
194 kctl = snd_ctl_find_id(ice->card, &elem_id);
195 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
196
197 strlcpy(elem_id.name, spec->wm8776.ctl[WM8776_CTL_HP_SW].name,
198 sizeof(elem_id.name));
199 kctl = snd_ctl_find_id(ice->card, &elem_id);
200 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
201 }
202
203 static void psc724_update_hp_jack_state(struct work_struct *work)
204 {
205 struct psc724_spec *spec = container_of(work, struct psc724_spec,
206 hp_work.work);
207 struct snd_ice1712 *ice = spec->ice;
208 bool hp_connected = snd_ice1712_gpio_read(ice) & GPIO_HP_JACK;
209
210 schedule_delayed_work(&spec->hp_work, msecs_to_jiffies(JACK_INTERVAL));
211 if (hp_connected == spec->hp_connected)
212 return;
213 psc724_set_jack_state(ice, hp_connected);
214 }
215
216 static void psc724_set_jack_detection(struct snd_ice1712 *ice, bool on)
217 {
218 struct psc724_spec *spec = ice->spec;
219
220 if (spec->jack_detect == on)
221 return;
222
223 spec->jack_detect = on;
224 if (on) {
225 bool hp_connected = snd_ice1712_gpio_read(ice) & GPIO_HP_JACK;
226 psc724_set_jack_state(ice, hp_connected);
227 schedule_delayed_work(&spec->hp_work,
228 msecs_to_jiffies(JACK_INTERVAL));
229 } else
230 cancel_delayed_work_sync(&spec->hp_work);
231 }
232
233 static bool psc724_get_jack_detection(struct snd_ice1712 *ice)
234 {
235 struct psc724_spec *spec = ice->spec;
236
237 return spec->jack_detect;
238 }
239
240
241
242 struct psc724_control {
243 const char *name;
244 void (*set)(struct snd_ice1712 *ice, bool on);
245 bool (*get)(struct snd_ice1712 *ice);
246 };
247
248 static const struct psc724_control psc724_cont[] = {
249 {
250 .name = "Master Speakers Playback Switch",
251 .set = psc724_set_master_switch,
252 .get = psc724_get_master_switch,
253 },
254 {
255 .name = "Headphone Jack Detection Playback Switch",
256 .set = psc724_set_jack_detection,
257 .get = psc724_get_jack_detection,
258 },
259 };
260
261 static int psc724_ctl_get(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol)
263 {
264 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
265 int n = kcontrol->private_value;
266
267 ucontrol->value.integer.value[0] = psc724_cont[n].get(ice);
268
269 return 0;
270 }
271
272 static int psc724_ctl_put(struct snd_kcontrol *kcontrol,
273 struct snd_ctl_elem_value *ucontrol)
274 {
275 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
276 int n = kcontrol->private_value;
277
278 psc724_cont[n].set(ice, ucontrol->value.integer.value[0]);
279
280 return 0;
281 }
282
283 static const char *front_volume = "Front Playback Volume";
284 static const char *front_switch = "Front Playback Switch";
285 static const char *front_zc = "Front Zero Cross Detect Playback Switch";
286 static const char *front_izd = "Front Infinite Zero Detect Playback Switch";
287 static const char *front_phase = "Front Phase Invert Playback Switch";
288 static const char *front_deemph = "Front Deemphasis Playback Switch";
289 static const char *ain1_switch = "Line Capture Switch";
290 static const char *ain2_switch = "CD Capture Switch";
291 static const char *ain3_switch = "AUX Capture Switch";
292 static const char *ain4_switch = "Front Mic Capture Switch";
293 static const char *ain5_switch = "Rear Mic Capture Switch";
294 static const char *rear_volume = "Surround Playback Volume";
295 static const char *clfe_volume = "CLFE Playback Volume";
296 static const char *rear_switch = "Surround Playback Switch";
297 static const char *clfe_switch = "CLFE Playback Switch";
298 static const char *rear_phase = "Surround Phase Invert Playback Switch";
299 static const char *clfe_phase = "CLFE Phase Invert Playback Switch";
300 static const char *rear_deemph = "Surround Deemphasis Playback Switch";
301 static const char *clfe_deemph = "CLFE Deemphasis Playback Switch";
302 static const char *rear_clfe_izd = "Rear Infinite Zero Detect Playback Switch";
303 static const char *rear_clfe_zc = "Rear Zero Cross Detect Playback Switch";
304
305 static int psc724_add_controls(struct snd_ice1712 *ice)
306 {
307 struct snd_kcontrol_new cont;
308 struct snd_kcontrol *ctl;
309 int err, i;
310 struct psc724_spec *spec = ice->spec;
311
312 spec->wm8776.ctl[WM8776_CTL_DAC_VOL].name = front_volume;
313 spec->wm8776.ctl[WM8776_CTL_DAC_SW].name = front_switch;
314 spec->wm8776.ctl[WM8776_CTL_DAC_ZC_SW].name = front_zc;
315 spec->wm8776.ctl[WM8776_CTL_AUX_SW].name = NULL;
316 spec->wm8776.ctl[WM8776_CTL_DAC_IZD_SW].name = front_izd;
317 spec->wm8776.ctl[WM8776_CTL_PHASE_SW].name = front_phase;
318 spec->wm8776.ctl[WM8776_CTL_DEEMPH_SW].name = front_deemph;
319 spec->wm8776.ctl[WM8776_CTL_INPUT1_SW].name = ain1_switch;
320 spec->wm8776.ctl[WM8776_CTL_INPUT2_SW].name = ain2_switch;
321 spec->wm8776.ctl[WM8776_CTL_INPUT3_SW].name = ain3_switch;
322 spec->wm8776.ctl[WM8776_CTL_INPUT4_SW].name = ain4_switch;
323 spec->wm8776.ctl[WM8776_CTL_INPUT5_SW].name = ain5_switch;
324 snd_wm8776_build_controls(&spec->wm8776);
325 spec->wm8766.ctl[WM8766_CTL_CH1_VOL].name = rear_volume;
326 spec->wm8766.ctl[WM8766_CTL_CH2_VOL].name = clfe_volume;
327 spec->wm8766.ctl[WM8766_CTL_CH3_VOL].name = NULL;
328 spec->wm8766.ctl[WM8766_CTL_CH1_SW].name = rear_switch;
329 spec->wm8766.ctl[WM8766_CTL_CH2_SW].name = clfe_switch;
330 spec->wm8766.ctl[WM8766_CTL_CH3_SW].name = NULL;
331 spec->wm8766.ctl[WM8766_CTL_PHASE1_SW].name = rear_phase;
332 spec->wm8766.ctl[WM8766_CTL_PHASE2_SW].name = clfe_phase;
333 spec->wm8766.ctl[WM8766_CTL_PHASE3_SW].name = NULL;
334 spec->wm8766.ctl[WM8766_CTL_DEEMPH1_SW].name = rear_deemph;
335 spec->wm8766.ctl[WM8766_CTL_DEEMPH2_SW].name = clfe_deemph;
336 spec->wm8766.ctl[WM8766_CTL_DEEMPH3_SW].name = NULL;
337 spec->wm8766.ctl[WM8766_CTL_IZD_SW].name = rear_clfe_izd;
338 spec->wm8766.ctl[WM8766_CTL_ZC_SW].name = rear_clfe_zc;
339 snd_wm8766_build_controls(&spec->wm8766);
340
341 memset(&cont, 0, sizeof(cont));
342 cont.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
343 for (i = 0; i < ARRAY_SIZE(psc724_cont); i++) {
344 cont.private_value = i;
345 cont.name = psc724_cont[i].name;
346 cont.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
347 cont.info = snd_ctl_boolean_mono_info;
348 cont.get = psc724_ctl_get;
349 cont.put = psc724_ctl_put;
350 ctl = snd_ctl_new1(&cont, ice);
351 if (!ctl)
352 return -ENOMEM;
353 err = snd_ctl_add(ice->card, ctl);
354 if (err < 0)
355 return err;
356 }
357
358 return 0;
359 }
360
361 static void psc724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate)
362 {
363 struct psc724_spec *spec = ice->spec;
364
365 snd_wm8776_volume_restore(&spec->wm8776);
366 snd_wm8766_volume_restore(&spec->wm8766);
367 }
368
369
370
371 #ifdef CONFIG_PM_SLEEP
372 static int psc724_resume(struct snd_ice1712 *ice)
373 {
374 struct psc724_spec *spec = ice->spec;
375
376 snd_wm8776_resume(&spec->wm8776);
377 snd_wm8766_resume(&spec->wm8766);
378
379 return 0;
380 }
381 #endif
382
383
384
385 static int psc724_init(struct snd_ice1712 *ice)
386 {
387 struct psc724_spec *spec;
388
389 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
390 if (!spec)
391 return -ENOMEM;
392 ice->spec = spec;
393 spec->ice = ice;
394
395 ice->num_total_dacs = 6;
396 ice->num_total_adcs = 2;
397 spec->wm8776.ops.write = psc724_wm8776_write;
398 spec->wm8776.card = ice->card;
399 snd_wm8776_init(&spec->wm8776);
400 spec->wm8766.ops.write = psc724_wm8766_write;
401 spec->wm8766.card = ice->card;
402 #ifdef CONFIG_PM_SLEEP
403 ice->pm_resume = psc724_resume;
404 ice->pm_suspend_enabled = 1;
405 #endif
406 snd_wm8766_init(&spec->wm8766);
407 snd_wm8766_set_if(&spec->wm8766,
408 WM8766_IF_FMT_I2S | WM8766_IF_IWL_24BIT);
409 ice->gpio.set_pro_rate = psc724_set_pro_rate;
410 INIT_DELAYED_WORK(&spec->hp_work, psc724_update_hp_jack_state);
411 psc724_set_jack_detection(ice, true);
412 return 0;
413 }
414
415 static void psc724_exit(struct snd_ice1712 *ice)
416 {
417 struct psc724_spec *spec = ice->spec;
418
419 cancel_delayed_work_sync(&spec->hp_work);
420 }
421
422
423 static unsigned char psc724_eeprom[] = {
424 [ICE_EEP2_SYSCONF] = 0x42,
425 [ICE_EEP2_ACLINK] = 0x80,
426 [ICE_EEP2_I2S] = 0xf0,
427 [ICE_EEP2_SPDIF] = 0xc1,
428
429 [ICE_EEP2_GPIO_DIR2] = 0x5f,
430
431 [ICE_EEP2_GPIO_MASK] = 0xff,
432 [ICE_EEP2_GPIO_MASK1] = 0xff,
433 [ICE_EEP2_GPIO_MASK2] = 0xa0,
434
435 [ICE_EEP2_GPIO_STATE2] = 0x20,
436 };
437
438 struct snd_ice1712_card_info snd_vt1724_psc724_cards[] = {
439 {
440 .subvendor = VT1724_SUBDEVICE_PSC724,
441 .name = "Philips PSC724 Ultimate Edge",
442 .model = "psc724",
443 .chip_init = psc724_init,
444 .chip_exit = psc724_exit,
445 .build_controls = psc724_add_controls,
446 .eeprom_size = sizeof(psc724_eeprom),
447 .eeprom_data = psc724_eeprom,
448 },
449 {}
450 };