2 * intelmid_vm_control.c - Intel Sound card driver for MID
4 * Copyright (C) 2010 Intel Corp
5 * Authors: Vinod Koul <vinod.koul@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 * This file contains the control operations of msic vendors
27 #include <linux/pci.h>
28 #include <linux/file.h>
29 #include "intel_sst.h"
30 #include "intel_sst_ioctl.h"
31 #include "intelmid_snd_control.h"
33 static int msic_init_card(void)
35 struct sc_reg_access sc_access[] = {
36 /* dmic configuration */
39 /* audio paths config */
42 /* PCM2 interface slots */
43 /* preconfigured slots for 0-5 both tx, rx */
52 /*TI vibra w/a settings*/
60 /* pcm port setting */
64 /* Set vol HSLRVOLCTRL, IHFVOL */
69 /* HSEPRXCTRL Enable the headset left and right FIR filters */
73 /* amic configuration */
76 /* unmask ocaudio/accdet interrupts */
80 snd_msic_ops.card_status = SND_CARD_INIT_DONE;
81 sst_sc_reg_access(sc_access, PMIC_WRITE, 30);
82 snd_msic_ops.pb_on = 0;
83 snd_msic_ops.cap_on = 0;
84 snd_msic_ops.input_dev_id = DMIC; /*def dev*/
85 snd_msic_ops.output_dev_id = STEREO_HEADPHONE;
86 pr_debug("sst: msic init complete!!\n");
90 static int msic_power_up_pb(unsigned int device)
92 struct sc_reg_access sc_access1[] = {
93 /* turn on the audio power supplies */
102 struct sc_reg_access sc_access2[] = {
105 /* DAC CONFIG ; both HP, LP on */
108 struct sc_reg_access sc_access3[] = {
109 /* HSEPRXCTRL Enable the headset left and right FIR filters */
114 struct sc_reg_access sc_access4[] = {
117 /* unmute the headset */
118 { 0x259, 0x80, 0x80},
119 { 0x25A, 0x80, 0x80},
121 struct sc_reg_access sc_access_vihf[] = {
125 struct sc_reg_access sc_access22[] = {
132 struct sc_reg_access sc_access32[] = {
136 struct sc_reg_access sc_access42[] = {
141 struct sc_reg_access sc_access23[] = {
144 /* DAC CONFIG ; both HP, LP on */
147 struct sc_reg_access sc_access43[] = {
150 /* unmute the headset */
151 { 0x259, 0x80, 0x80},
152 { 0x25A, 0x80, 0x80},
154 struct sc_reg_access sc_access_vib[] = {
155 /* enable driver, ADC */
159 struct sc_reg_access sc_access_hap[] = {
160 /* enable driver, ADC */
164 struct sc_reg_access sc_access_pcm2[] = {
170 if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
171 retval = msic_init_card();
176 pr_debug("sst: powering up pb.... Device %d\n", device);
177 sst_sc_reg_access(sc_access1, PMIC_WRITE, 4);
179 case SND_SST_DEVICE_HEADSET:
180 if (snd_msic_ops.output_dev_id == STEREO_HEADPHONE) {
181 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 2);
182 sst_sc_reg_access(sc_access3, PMIC_WRITE, 2);
183 sst_sc_reg_access(sc_access4, PMIC_READ_MODIFY, 3);
185 sst_sc_reg_access(sc_access23, PMIC_READ_MODIFY, 2);
186 sst_sc_reg_access(sc_access3, PMIC_WRITE, 2);
187 sst_sc_reg_access(sc_access43, PMIC_READ_MODIFY, 3);
189 snd_msic_ops.pb_on = 1;
192 case SND_SST_DEVICE_IHF:
193 sst_sc_reg_access(sc_access_vihf, PMIC_WRITE, 1);
194 sst_sc_reg_access(sc_access22, PMIC_READ_MODIFY, 3);
195 sst_sc_reg_access(sc_access32, PMIC_READ_MODIFY, 1);
196 sst_sc_reg_access(sc_access42, PMIC_READ_MODIFY, 2);
199 case SND_SST_DEVICE_VIBRA:
200 sst_sc_reg_access(sc_access_vib, PMIC_READ_MODIFY, 2);
203 case SND_SST_DEVICE_HAPTIC:
204 sst_sc_reg_access(sc_access_hap, PMIC_READ_MODIFY, 2);
208 pr_warn("sst: Wrong Device %d, selected %d\n",
209 device, snd_msic_ops.output_dev_id);
211 return sst_sc_reg_access(sc_access_pcm2, PMIC_READ_MODIFY, 1);
214 static int msic_power_up_cp(unsigned int device)
216 struct sc_reg_access sc_access[] = {
217 /* turn on the audio power supplies */
226 /* Turn on DMIC supply */
231 /* mic demux enable */
236 struct sc_reg_access sc_access_amic[] = {
237 /* turn on the audio power supplies */
251 /* Turn on AMIC supply */
255 struct sc_reg_access sc_access2[] = {
259 struct sc_reg_access sc_access3[] = {
260 /*wait for mic to stabalize before turning on audio channels*/
265 if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
266 retval = msic_init_card();
271 pr_debug("sst: powering up cp....%d\n", snd_msic_ops.input_dev_id);
272 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 1);
273 snd_msic_ops.cap_on = 1;
274 if (snd_msic_ops.input_dev_id == AMIC)
275 sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 9);
277 sst_sc_reg_access(sc_access, PMIC_WRITE, 9);
278 return sst_sc_reg_access(sc_access3, PMIC_WRITE, 1);
282 static int msic_power_down(void)
286 pr_debug("sst: powering dn msic\n");
287 snd_msic_ops.pb_on = 0;
288 snd_msic_ops.cap_on = 0;
292 static int msic_power_down_pb(void)
296 pr_debug("sst: powering dn pb....\n");
297 snd_msic_ops.pb_on = 0;
301 static int msic_power_down_cp(void)
305 pr_debug("sst: powering dn cp....\n");
306 snd_msic_ops.cap_on = 0;
310 static int msic_set_selected_output_dev(u8 value)
314 pr_debug("sst: msic set selected output:%d\n", value);
315 snd_msic_ops.output_dev_id = value;
316 if (snd_msic_ops.pb_on)
317 msic_power_up_pb(SND_SST_DEVICE_HEADSET);
321 static int msic_set_selected_input_dev(u8 value)
324 struct sc_reg_access sc_access_dmic[] = {
327 struct sc_reg_access sc_access_amic[] = {
333 pr_debug("sst: msic_set_selected_input_dev:%d\n", value);
334 snd_msic_ops.input_dev_id = value;
337 pr_debug("sst: Selecting AMIC1\n");
338 retval = sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 1);
341 pr_debug("sst: Selecting DMIC1\n");
342 retval = sst_sc_reg_access(sc_access_dmic, PMIC_WRITE, 1);
348 if (snd_msic_ops.cap_on)
349 retval = msic_power_up_cp(SND_SST_DEVICE_CAPTURE);
353 static int msic_set_pcm_voice_params(void)
358 static int msic_set_pcm_audio_params(int sfreq, int word_size, int num_channel)
363 static int msic_set_audio_port(int status)
368 static int msic_set_voice_port(int status)
373 static int msic_set_mute(int dev_id, u8 value)
378 static int msic_set_vol(int dev_id, int value)
383 static int msic_get_mute(int dev_id, u8 *value)
388 static int msic_get_vol(int dev_id, int *value)
393 struct snd_pmic_ops snd_msic_ops = {
394 .set_input_dev = msic_set_selected_input_dev,
395 .set_output_dev = msic_set_selected_output_dev,
396 .set_mute = msic_set_mute,
397 .get_mute = msic_get_mute,
398 .set_vol = msic_set_vol,
399 .get_vol = msic_get_vol,
400 .init_card = msic_init_card,
401 .set_pcm_audio_params = msic_set_pcm_audio_params,
402 .set_pcm_voice_params = msic_set_pcm_voice_params,
403 .set_voice_port = msic_set_voice_port,
404 .set_audio_port = msic_set_audio_port,
405 .power_up_pmic_pb = msic_power_up_pb,
406 .power_up_pmic_cp = msic_power_up_cp,
407 .power_down_pmic_pb = msic_power_down_pb,
408 .power_down_pmic_cp = msic_power_down_cp,
409 .power_down_pmic = msic_power_down,