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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/pci.h>
30 #include <linux/file.h>
31 #include "intel_sst.h"
32 #include "intel_sst_ioctl.h"
33 #include "intelmid_snd_control.h"
35 static int msic_init_card(void)
37 struct sc_reg_access sc_access[] = {
38 /* dmic configuration */
41 /* audio paths config */
44 /* PCM2 interface slots */
45 /* preconfigured slots for 0-5 both tx, rx */
54 /*TI vibra w/a settings*/
62 /* pcm port setting */
66 /* Set vol HSLRVOLCTRL, IHFVOL */
71 /* HSEPRXCTRL Enable the headset left and right FIR filters */
75 /* amic configuration */
78 /* unmask ocaudio/accdet interrupts */
82 snd_msic_ops.card_status = SND_CARD_INIT_DONE;
83 sst_sc_reg_access(sc_access, PMIC_WRITE, 30);
84 snd_msic_ops.pb_on = 0;
85 snd_msic_ops.cap_on = 0;
86 snd_msic_ops.input_dev_id = DMIC; /*def dev*/
87 snd_msic_ops.output_dev_id = STEREO_HEADPHONE;
88 pr_debug("msic init complete!!\n");
92 static int msic_power_up_pb(unsigned int device)
94 struct sc_reg_access sc_access1[] = {
95 /* turn on the audio power supplies */
104 struct sc_reg_access sc_access2[] = {
107 /* DAC CONFIG ; both HP, LP on */
110 struct sc_reg_access sc_access3[] = {
111 /* HSEPRXCTRL Enable the headset left and right FIR filters */
116 struct sc_reg_access sc_access4[] = {
119 /* unmute the headset */
120 { 0x259, 0x80, 0x80},
121 { 0x25A, 0x80, 0x80},
123 struct sc_reg_access sc_access_vihf[] = {
127 struct sc_reg_access sc_access22[] = {
134 struct sc_reg_access sc_access32[] = {
138 struct sc_reg_access sc_access42[] = {
143 struct sc_reg_access sc_access23[] = {
146 /* DAC CONFIG ; both HP, LP on */
149 struct sc_reg_access sc_access43[] = {
152 /* unmute the headset */
153 { 0x259, 0x80, 0x80},
154 { 0x25A, 0x80, 0x80},
156 struct sc_reg_access sc_access_vib[] = {
157 /* enable driver, ADC */
161 struct sc_reg_access sc_access_hap[] = {
162 /* enable driver, ADC */
166 struct sc_reg_access sc_access_pcm2[] = {
172 if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
173 retval = msic_init_card();
178 pr_debug("powering up pb.... Device %d\n", device);
179 sst_sc_reg_access(sc_access1, PMIC_WRITE, 4);
181 case SND_SST_DEVICE_HEADSET:
182 if (snd_msic_ops.output_dev_id == STEREO_HEADPHONE) {
183 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 2);
184 sst_sc_reg_access(sc_access3, PMIC_WRITE, 2);
185 sst_sc_reg_access(sc_access4, PMIC_READ_MODIFY, 3);
187 sst_sc_reg_access(sc_access23, PMIC_READ_MODIFY, 2);
188 sst_sc_reg_access(sc_access3, PMIC_WRITE, 2);
189 sst_sc_reg_access(sc_access43, PMIC_READ_MODIFY, 3);
191 snd_msic_ops.pb_on = 1;
194 case SND_SST_DEVICE_IHF:
195 sst_sc_reg_access(sc_access_vihf, PMIC_WRITE, 1);
196 sst_sc_reg_access(sc_access22, PMIC_READ_MODIFY, 3);
197 sst_sc_reg_access(sc_access32, PMIC_READ_MODIFY, 1);
198 sst_sc_reg_access(sc_access42, PMIC_READ_MODIFY, 2);
201 case SND_SST_DEVICE_VIBRA:
202 sst_sc_reg_access(sc_access_vib, PMIC_READ_MODIFY, 2);
205 case SND_SST_DEVICE_HAPTIC:
206 sst_sc_reg_access(sc_access_hap, PMIC_READ_MODIFY, 2);
210 pr_warn("Wrong Device %d, selected %d\n",
211 device, snd_msic_ops.output_dev_id);
213 return sst_sc_reg_access(sc_access_pcm2, PMIC_READ_MODIFY, 1);
216 static int msic_power_up_cp(unsigned int device)
218 struct sc_reg_access sc_access[] = {
219 /* turn on the audio power supplies */
228 /* Turn on DMIC supply */
233 /* mic demux enable */
238 struct sc_reg_access sc_access_amic[] = {
239 /* turn on the audio power supplies */
253 /* Turn on AMIC supply */
257 struct sc_reg_access sc_access2[] = {
261 struct sc_reg_access sc_access3[] = {
262 /*wait for mic to stabalize before turning on audio channels*/
267 if (snd_msic_ops.card_status == SND_CARD_UN_INIT) {
268 retval = msic_init_card();
273 pr_debug("powering up cp....%d\n", snd_msic_ops.input_dev_id);
274 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 1);
275 snd_msic_ops.cap_on = 1;
276 if (snd_msic_ops.input_dev_id == AMIC)
277 sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 9);
279 sst_sc_reg_access(sc_access, PMIC_WRITE, 9);
280 return sst_sc_reg_access(sc_access3, PMIC_WRITE, 1);
284 static int msic_power_down(void)
288 pr_debug("powering dn msic\n");
289 snd_msic_ops.pb_on = 0;
290 snd_msic_ops.cap_on = 0;
294 static int msic_power_down_pb(void)
298 pr_debug("powering dn pb....\n");
299 snd_msic_ops.pb_on = 0;
303 static int msic_power_down_cp(void)
307 pr_debug("powering dn cp....\n");
308 snd_msic_ops.cap_on = 0;
312 static int msic_set_selected_output_dev(u8 value)
316 pr_debug("msic set selected output:%d\n", value);
317 snd_msic_ops.output_dev_id = value;
318 if (snd_msic_ops.pb_on)
319 msic_power_up_pb(SND_SST_DEVICE_HEADSET);
323 static int msic_set_selected_input_dev(u8 value)
326 struct sc_reg_access sc_access_dmic[] = {
329 struct sc_reg_access sc_access_amic[] = {
335 pr_debug("msic_set_selected_input_dev:%d\n", value);
336 snd_msic_ops.input_dev_id = value;
339 pr_debug("Selecting AMIC1\n");
340 retval = sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 1);
343 pr_debug("Selecting DMIC1\n");
344 retval = sst_sc_reg_access(sc_access_dmic, PMIC_WRITE, 1);
350 if (snd_msic_ops.cap_on)
351 retval = msic_power_up_cp(SND_SST_DEVICE_CAPTURE);
355 static int msic_set_pcm_voice_params(void)
360 static int msic_set_pcm_audio_params(int sfreq, int word_size, int num_channel)
365 static int msic_set_audio_port(int status)
370 static int msic_set_voice_port(int status)
375 static int msic_set_mute(int dev_id, u8 value)
380 static int msic_set_vol(int dev_id, int value)
385 static int msic_get_mute(int dev_id, u8 *value)
390 static int msic_get_vol(int dev_id, int *value)
395 struct snd_pmic_ops snd_msic_ops = {
396 .set_input_dev = msic_set_selected_input_dev,
397 .set_output_dev = msic_set_selected_output_dev,
398 .set_mute = msic_set_mute,
399 .get_mute = msic_get_mute,
400 .set_vol = msic_set_vol,
401 .get_vol = msic_get_vol,
402 .init_card = msic_init_card,
403 .set_pcm_audio_params = msic_set_pcm_audio_params,
404 .set_pcm_voice_params = msic_set_pcm_voice_params,
405 .set_voice_port = msic_set_voice_port,
406 .set_audio_port = msic_set_audio_port,
407 .power_up_pmic_pb = msic_power_up_pb,
408 .power_up_pmic_cp = msic_power_up_cp,
409 .power_down_pmic_pb = msic_power_down_pb,
410 .power_down_pmic_cp = msic_power_down_cp,
411 .power_down_pmic = msic_power_down,