2 * intelmid.c - Intel Sound card driver for MID
4 * Copyright (C) 2008-10 Intel Corp
5 * Authors: Harsha Priya <priya.harsha@intel.com>
6 * Vinod Koul <vinod.koul@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * ALSA driver for Intel MID sound card chipset
27 #include <linux/slab.h>
29 #include <linux/platform_device.h>
30 #include <linux/interrupt.h>
31 #include <linux/sched.h>
32 #include <sound/control.h>
34 #include <sound/pcm.h>
36 #include <sound/pcm_params.h>
37 #include <sound/initval.h>
38 #include "intel_sst.h"
39 #include "intel_sst_ioctl.h"
40 #include "intelmid_snd_control.h"
43 MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
44 MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
45 MODULE_AUTHOR("Dharageswari R <dharageswari.r@intel.com>");
46 MODULE_AUTHOR("KP Jeeja <jeeja.kp@intel.com>");
47 MODULE_DESCRIPTION("Intel MAD Sound card driver");
48 MODULE_LICENSE("GPL v2");
49 MODULE_SUPPORTED_DEVICE("{Intel,Intel_MAD}");
52 static int card_index = SNDRV_DEFAULT_IDX1;/* Index 0-MAX */
53 static char *card_id = SNDRV_DEFAULT_STR1; /* ID for this card */
55 module_param(card_index, int, 0444);
56 MODULE_PARM_DESC(card_index, "Index value for INTELMAD soundcard.");
57 module_param(card_id, charp, 0444);
58 MODULE_PARM_DESC(card_id, "ID string for INTELMAD soundcard.");
60 int sst_card_vendor_id;
61 int intelmid_audio_interrupt_enable;/*checkpatch fix*/
63 /* Data path functionalities */
64 static struct snd_pcm_hardware snd_intelmad_stream = {
65 .info = (SNDRV_PCM_INFO_INTERLEAVED |
66 SNDRV_PCM_INFO_DOUBLE |
67 SNDRV_PCM_INFO_PAUSE |
68 SNDRV_PCM_INFO_RESUME |
70 SNDRV_PCM_INFO_MMAP_VALID |
71 SNDRV_PCM_INFO_BLOCK_TRANSFER |
72 SNDRV_PCM_INFO_SYNC_START),
73 .formats = (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 |
74 SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 |
75 SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32),
76 .rates = (SNDRV_PCM_RATE_8000|
77 SNDRV_PCM_RATE_44100 |
78 SNDRV_PCM_RATE_48000),
82 .channels_min = MIN_CHANNEL,
83 .channels_max = MAX_CHANNEL_AMIC,
84 .buffer_bytes_max = MAX_BUFFER,
85 .period_bytes_min = MIN_PERIOD_BYTES,
86 .period_bytes_max = MAX_PERIOD_BYTES,
87 .periods_min = MIN_PERIODS,
88 .periods_max = MAX_PERIODS,
89 .fifo_size = FIFO_SIZE,
94 * snd_intelmad_pcm_trigger - stream activities are handled here
96 * @substream:substream for which the stream function is called
97 * @cmd:the stream commamd that requested from upper layer
99 * This function is called whenever an a stream activity is invoked
101 static int snd_intelmad_pcm_trigger(struct snd_pcm_substream *substream,
105 struct snd_intelmad *intelmaddata;
106 struct mad_stream_pvt *stream;
107 /*struct stream_buffer buffer_to_sst;*/
113 intelmaddata = snd_pcm_substream_chip(substream);
114 stream = substream->runtime->private_data;
116 WARN_ON(!intelmaddata->sstdrv_ops);
117 WARN_ON(!intelmaddata->sstdrv_ops->scard_ops);
120 case SNDRV_PCM_TRIGGER_START:
121 pr_debug("sst: Trigger Start\n");
122 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_START,
123 &stream->stream_info.str_id);
126 stream->stream_status = RUNNING;
127 stream->substream = substream;
128 stream->stream_status = RUNNING;
130 case SNDRV_PCM_TRIGGER_STOP:
131 pr_debug("sst: in stop\n");
132 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_DROP,
133 &stream->stream_info.str_id);
136 stream->stream_status = DROPPED;
138 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
139 pr_debug("sst: in pause\n");
140 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_PAUSE,
141 &stream->stream_info.str_id);
144 stream->stream_status = PAUSED;
146 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
147 pr_debug("sst: in pause release\n");
148 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_RESUME,
149 &stream->stream_info.str_id);
152 stream->stream_status = RUNNING;
161 * snd_intelmad_pcm_prepare- internal preparation before starting a stream
163 * @substream: substream for which the function is called
165 * This function is called when a stream is started for internal preparation.
167 static int snd_intelmad_pcm_prepare(struct snd_pcm_substream *substream)
169 struct mad_stream_pvt *stream;
171 struct snd_intelmad *intelmaddata;
173 pr_debug("sst: pcm_prepare called\n");
176 stream = substream->runtime->private_data;
177 intelmaddata = snd_pcm_substream_chip(substream);
178 pr_debug("sst: pb cnt = %d cap cnt = %d\n",\
179 intelmaddata->playback_cnt,
180 intelmaddata->capture_cnt);
182 if (stream->stream_info.str_id) {
183 pr_debug("sst: Prepare called for already set stream\n");
184 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_DROP,
185 &stream->stream_info.str_id);
189 ret_val = snd_intelmad_alloc_stream(substream);
192 stream->dbg_cum_bytes = 0;
193 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
194 intelmaddata->playback_cnt++;
196 intelmaddata->capture_cnt++;
197 /* return back the stream id */
198 snprintf(substream->pcm->id, sizeof(substream->pcm->id),
199 "%d", stream->stream_info.str_id);
200 pr_debug("sst: stream id to user = %s\n",
203 ret_val = snd_intelmad_init_stream(substream);
206 substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
210 static int snd_intelmad_hw_params(struct snd_pcm_substream *substream,
211 struct snd_pcm_hw_params *hw_params)
215 pr_debug("sst: snd_intelmad_hw_params called\n");
216 ret_val = snd_pcm_lib_malloc_pages(substream,
217 params_buffer_bytes(hw_params));
218 memset(substream->runtime->dma_area, 0,
219 params_buffer_bytes(hw_params));
224 static int snd_intelmad_hw_free(struct snd_pcm_substream *substream)
226 pr_debug("sst: snd_intelmad_hw_free called\n");
227 return snd_pcm_lib_free_pages(substream);
231 * snd_intelmad_pcm_pointer- to send the current buffer pointer processed by hw
233 * @substream: substream for which the function is called
235 * This function is called by ALSA framework to get the current hw buffer ptr
236 * when a period is elapsed
238 static snd_pcm_uframes_t snd_intelmad_pcm_pointer
239 (struct snd_pcm_substream *substream)
241 /* struct snd_pcm_runtime *runtime = substream->runtime; */
242 struct mad_stream_pvt *stream;
243 struct snd_intelmad *intelmaddata;
248 intelmaddata = snd_pcm_substream_chip(substream);
249 stream = substream->runtime->private_data;
250 if (stream->stream_status == INIT)
253 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_BUFFER_POINTER,
254 &stream->stream_info);
256 pr_err("sst: error code = 0x%x\n", ret_val);
259 pr_debug("sst: samples reported out 0x%llx\n",
260 stream->stream_info.buffer_ptr);
261 pr_debug("sst: Frame bits:: %d period_count :: %d\n",
262 (int)substream->runtime->frame_bits,
263 (int)substream->runtime->period_size);
265 return stream->stream_info.buffer_ptr;
270 * snd_intelmad_close- to free parameteres when stream is stopped
272 * @substream: substream for which the function is called
274 * This function is called by ALSA framework when stream is stopped
276 static int snd_intelmad_close(struct snd_pcm_substream *substream)
278 struct snd_intelmad *intelmaddata;
279 struct mad_stream_pvt *stream;
284 stream = substream->runtime->private_data;
286 pr_debug("sst: snd_intelmad_close called\n");
287 intelmaddata = snd_pcm_substream_chip(substream);
289 pr_debug("sst: str id = %d\n", stream->stream_info.str_id);
290 if (stream->stream_info.str_id) {
291 /* SST API to actually stop/free the stream */
292 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_FREE,
293 &stream->stream_info.str_id);
294 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
295 intelmaddata->playback_cnt--;
297 intelmaddata->capture_cnt--;
299 pr_debug("sst: snd_intelmad_close : pb cnt = %d cap cnt = %d\n",
300 intelmaddata->playback_cnt, intelmaddata->capture_cnt);
301 kfree(substream->runtime->private_data);
306 * snd_intelmad_open- to set runtime parameters during stream start
308 * @substream: substream for which the function is called
309 * @type: audio device type
311 * This function is called by ALSA framework when stream is started
313 static int snd_intelmad_open(struct snd_pcm_substream *substream,
314 enum snd_sst_audio_device_type type)
316 struct snd_intelmad *intelmaddata;
317 struct snd_pcm_runtime *runtime;
318 struct mad_stream_pvt *stream;
322 pr_debug("sst: snd_intelmad_open called\n");
324 intelmaddata = snd_pcm_substream_chip(substream);
325 runtime = substream->runtime;
326 /* set the runtime hw parameter with local snd_pcm_hardware struct */
327 runtime->hw = snd_intelmad_stream;
328 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
329 runtime->hw = snd_intelmad_stream;
330 runtime->hw.rates = SNDRV_PCM_RATE_48000;
331 runtime->hw.rate_min = MAX_RATE;
332 runtime->hw.formats = (SNDRV_PCM_FMTBIT_S24 |
333 SNDRV_PCM_FMTBIT_U24);
334 if (intelmaddata->sstdrv_ops->scard_ops->input_dev_id == AMIC)
335 runtime->hw.channels_max = MAX_CHANNEL_AMIC;
337 runtime->hw.channels_max = MAX_CHANNEL_DMIC;
340 /* setup the internal datastruture stream pointers based on it being
341 playback or capture stream */
342 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
345 stream->stream_info.str_id = 0;
346 stream->device = type;
347 stream->stream_status = INIT;
348 runtime->private_data = stream;
349 return snd_pcm_hw_constraint_integer(runtime,
350 SNDRV_PCM_HW_PARAM_PERIODS);
353 static int snd_intelmad_headset_open(struct snd_pcm_substream *substream)
355 return snd_intelmad_open(substream, SND_SST_DEVICE_HEADSET);
358 static int snd_intelmad_ihf_open(struct snd_pcm_substream *substream)
360 return snd_intelmad_open(substream, SND_SST_DEVICE_IHF);
363 static int snd_intelmad_vibra_open(struct snd_pcm_substream *substream)
365 return snd_intelmad_open(substream, SND_SST_DEVICE_VIBRA);
368 static int snd_intelmad_haptic_open(struct snd_pcm_substream *substream)
370 return snd_intelmad_open(substream, SND_SST_DEVICE_HAPTIC);
373 static struct snd_pcm_ops snd_intelmad_headset_ops = {
374 .open = snd_intelmad_headset_open,
375 .close = snd_intelmad_close,
376 .ioctl = snd_pcm_lib_ioctl,
377 .hw_params = snd_intelmad_hw_params,
378 .hw_free = snd_intelmad_hw_free,
379 .prepare = snd_intelmad_pcm_prepare,
380 .trigger = snd_intelmad_pcm_trigger,
381 .pointer = snd_intelmad_pcm_pointer,
384 static struct snd_pcm_ops snd_intelmad_ihf_ops = {
385 .open = snd_intelmad_ihf_open,
386 .close = snd_intelmad_close,
387 .ioctl = snd_pcm_lib_ioctl,
388 .hw_params = snd_intelmad_hw_params,
389 .hw_free = snd_intelmad_hw_free,
390 .prepare = snd_intelmad_pcm_prepare,
391 .trigger = snd_intelmad_pcm_trigger,
392 .pointer = snd_intelmad_pcm_pointer,
395 static struct snd_pcm_ops snd_intelmad_vibra_ops = {
396 .open = snd_intelmad_vibra_open,
397 .close = snd_intelmad_close,
398 .ioctl = snd_pcm_lib_ioctl,
399 .hw_params = snd_intelmad_hw_params,
400 .hw_free = snd_intelmad_hw_free,
401 .prepare = snd_intelmad_pcm_prepare,
402 .trigger = snd_intelmad_pcm_trigger,
403 .pointer = snd_intelmad_pcm_pointer,
406 static struct snd_pcm_ops snd_intelmad_haptic_ops = {
407 .open = snd_intelmad_haptic_open,
408 .close = snd_intelmad_close,
409 .ioctl = snd_pcm_lib_ioctl,
410 .hw_params = snd_intelmad_hw_params,
411 .hw_free = snd_intelmad_hw_free,
412 .prepare = snd_intelmad_pcm_prepare,
413 .trigger = snd_intelmad_pcm_trigger,
414 .pointer = snd_intelmad_pcm_pointer,
417 static struct snd_pcm_ops snd_intelmad_capture_ops = {
418 .open = snd_intelmad_headset_open,
419 .close = snd_intelmad_close,
420 .ioctl = snd_pcm_lib_ioctl,
421 .hw_params = snd_intelmad_hw_params,
422 .hw_free = snd_intelmad_hw_free,
423 .prepare = snd_intelmad_pcm_prepare,
424 .trigger = snd_intelmad_pcm_trigger,
425 .pointer = snd_intelmad_pcm_pointer,
430 * snd_intelmad_intr_handler- interrupt handler
432 * @irq : irq number of the interrupt received
433 * @dev: device context
435 * This function is called when an interrupt is raised at the sound card
437 static irqreturn_t snd_intelmad_intr_handler(int irq, void *dev)
439 struct snd_intelmad *intelmaddata =
440 (struct snd_intelmad *)dev;
443 memcpy_fromio(&intsts,
444 ((void *)(intelmaddata->int_base)),
446 intelmaddata->mad_jack_msg.intsts = intsts;
447 intelmaddata->mad_jack_msg.intelmaddata = intelmaddata;
449 queue_work(intelmaddata->mad_jack_wq, &intelmaddata->mad_jack_msg.wq);
454 void sst_mad_send_jack_report(struct snd_jack *jack,
455 int buttonpressevent , int status)
459 pr_debug("sst: MAD error jack empty\n");
462 pr_debug("sst: MAD send jack report for = %d!!!\n", status);
463 pr_debug("sst: MAD send jack report %d\n", jack->type);
464 snd_jack_report(jack, status);
466 /*button pressed and released */
467 if (buttonpressevent)
468 snd_jack_report(jack, 0);
469 pr_debug("sst: MAD sending jack report Done !!!\n");
476 void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
478 struct snd_jack *jack = NULL;
479 unsigned int present = 0, jack_event_flag = 0, buttonpressflag = 0;
480 struct sc_reg_access sc_access[] = {
481 {0x187, 0x00, MASK7},
482 {0x188, 0x10, MASK4},
483 {0x18b, 0x10, MASK4},
486 struct sc_reg_access sc_access_write[] = {
492 if (!(intelmid_audio_interrupt_enable)) {
493 pr_debug("sst: Audio interrupt enable\n");
494 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3);
496 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1);
497 intelmid_audio_interrupt_enable = 1;
498 intelmaddata->jack[0].jack_status = 0;
499 intelmaddata->jack[1].jack_status = 0;
502 /* send headphone detect */
503 pr_debug("sst: MAD headphone %d\n", intsts & 0x4);
504 jack = &intelmaddata->jack[0].jack;
505 present = !(intelmaddata->jack[0].jack_status);
506 intelmaddata->jack[0].jack_status = present;
512 /* send short push */
513 pr_debug("sst: MAD short push %d\n", intsts & 0x2);
514 jack = &intelmaddata->jack[2].jack;
521 pr_debug("sst: MAD long push %d\n", intsts & 0x1);
522 jack = &intelmaddata->jack[3].jack;
528 if (!(intelmid_audio_interrupt_enable)) {
529 pr_debug("sst: Audio interrupt enable\n");
530 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3);
532 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1);
533 intelmid_audio_interrupt_enable = 1;
534 intelmaddata->jack[0].jack_status = 0;
535 intelmaddata->jack[1].jack_status = 0;
537 /* send headset detect */
538 pr_debug("sst: MAD headset = %d\n", intsts & 0x8);
539 jack = &intelmaddata->jack[1].jack;
540 present = !(intelmaddata->jack[1].jack_status);
541 intelmaddata->jack[1].jack_status = present;
546 sst_mad_send_jack_report(jack, buttonpressflag, present);
550 void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
552 u8 value = 0, jack_prev_state = 0;
553 struct snd_jack *jack = NULL;
554 unsigned int present = 0, jack_event_flag = 0, buttonpressflag = 0;
556 struct sc_reg_access sc_access_read = {0,};
557 struct snd_pmic_ops *scard_ops;
559 scard_ops = intelmaddata->sstdrv_ops->scard_ops;
561 pr_debug("sst: previous value: %x\n", intelmaddata->jack_prev_state);
563 if (!(intelmid_audio_interrupt_enable)) {
564 pr_debug("sst: Audio interrupt enable\n");
565 intelmaddata->jack_prev_state = 0xC0;
566 intelmid_audio_interrupt_enable = 1;
570 jack_prev_state = intelmaddata->jack_prev_state;
571 if (intelmaddata->pmic_status == PMIC_INIT) {
572 sc_access_read.reg_addr = 0x201;
573 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1);
574 value = (sc_access_read.value);
575 pr_debug("sst: value returned = 0x%x\n", value);
578 if (jack_prev_state == 0xc0 && value == 0x40) {
579 /*headset detected. */
580 pr_debug("sst: MAD headset inserted\n");
581 jack = &intelmaddata->jack[1].jack;
584 intelmaddata->jack[1].jack_status = 1;
588 if (jack_prev_state == 0xc0 && value == 0x00) {
589 /* headphone detected. */
590 pr_debug("sst: MAD headphone inserted\n");
591 jack = &intelmaddata->jack[0].jack;
597 if (jack_prev_state == 0x40 && value == 0xc0) {
599 pr_debug("sst: Jack headset status %d\n",
600 intelmaddata->jack[1].jack_status);
601 pr_debug("sst: MAD headset removed\n");
602 jack = &intelmaddata->jack[1].jack;
605 intelmaddata->jack[1].jack_status = 0;
608 if (jack_prev_state == 0x00 && value == 0xc0) {
609 /* headphone detected. */
610 pr_debug("sst: Jack headphone status %d\n",
611 intelmaddata->jack[0].jack_status);
612 pr_debug("sst: headphone removed\n");
613 jack = &intelmaddata->jack[0].jack;
618 if (jack_prev_state == 0x40 && value == 0x00) {
620 do_gettimeofday(&intelmaddata->jack[1].buttonpressed);
621 pr_debug("sst: MAD button press detected n");
625 if (jack_prev_state == 0x00 && value == 0x40) {
626 if (intelmaddata->jack[1].jack_status) {
629 &intelmaddata->jack[1].buttonreleased);
631 pr_debug("sst: Button Released detected\n");
632 timediff = intelmaddata->jack[1].
633 buttonreleased.tv_sec - intelmaddata->
634 jack[1].buttonpressed.tv_sec;
637 pr_debug("sst: long press detected\n");
638 /* send headphone detect/undetect */
639 jack = &intelmaddata->jack[3].jack;
643 pr_debug("sst: short press detected\n");
644 /* send headphone detect/undetect */
645 jack = &intelmaddata->jack[2].jack;
652 intelmaddata->jack_prev_state = value;
655 sst_mad_send_jack_report(jack, buttonpressflag, present);
659 void sst_mad_jackdetection_nec(u8 intsts, struct snd_intelmad *intelmaddata)
662 struct snd_jack *jack = NULL;
663 unsigned int present = 0, jack_event_flag = 0, buttonpressflag = 0;
664 struct sc_reg_access sc_access_read = {0,};
666 if (intelmaddata->pmic_status == PMIC_INIT) {
667 sc_access_read.reg_addr = 0x132;
668 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1);
669 value = (sc_access_read.value);
670 pr_debug("sst: value returned = 0x%x\n", value);
673 pr_debug("sst: headset detected\n");
674 /* send headset detect/undetect */
675 jack = &intelmaddata->jack[1].jack;
676 present = (value == 0x1) ? 1 : 0;
680 pr_debug("sst: headphone detected\n");
681 /* send headphone detect/undetect */
682 jack = &intelmaddata->jack[0].jack;
683 present = (value == 0x2) ? 1 : 0;
687 pr_debug("sst: short push detected\n");
688 /* send short push */
689 jack = &intelmaddata->jack[2].jack;
695 pr_debug("sst: long push detected\n");
697 jack = &intelmaddata->jack[3].jack;
704 sst_mad_send_jack_report(jack, buttonpressflag, present);
709 void sst_process_mad_jack_detection(struct work_struct *work)
712 struct mad_jack_msg_wq *mad_jack_detect =
713 container_of(work, struct mad_jack_msg_wq, wq);
715 struct snd_intelmad *intelmaddata =
716 mad_jack_detect->intelmaddata;
718 intsts = mad_jack_detect->intsts;
720 switch (intelmaddata->sstdrv_ops->vendor_id) {
722 sst_mad_jackdetection_fs(intsts , intelmaddata);
725 sst_mad_jackdetection_mx(intsts , intelmaddata);
728 sst_mad_jackdetection_nec(intsts , intelmaddata);
734 static int __devinit snd_intelmad_register_irq(
735 struct snd_intelmad *intelmaddata)
738 u32 regbase = AUDINT_BASE, regsize = 8;
741 pr_debug("sst: irq reg done, regbase 0x%x, regsize 0x%x\n",
743 intelmaddata->int_base = ioremap_nocache(regbase, regsize);
744 if (!intelmaddata->int_base)
745 pr_err("sst: Mapping of cache failed\n");
746 pr_debug("sst: irq = 0x%x\n", intelmaddata->irq);
747 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL)
748 drv_name = DRIVER_NAME_MFLD;
750 drv_name = DRIVER_NAME_MRST;
751 ret_val = request_irq(intelmaddata->irq,
752 snd_intelmad_intr_handler,
753 IRQF_SHARED, drv_name,
756 pr_err("sst: cannot register IRQ\n");
760 static int __devinit snd_intelmad_sst_register(
761 struct snd_intelmad *intelmaddata)
764 struct snd_pmic_ops *intelmad_vendor_ops[MAX_VENDORS] = {
771 struct sc_reg_access vendor_addr = {0x00, 0x00, 0x00};
773 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT) {
774 ret_val = sst_sc_reg_access(&vendor_addr, PMIC_READ, 1);
777 sst_card_vendor_id = (vendor_addr.value & (MASK2|MASK1|MASK0));
778 pr_debug("sst: orginal n extrated vendor id = 0x%x %d\n",
779 vendor_addr.value, sst_card_vendor_id);
780 if (sst_card_vendor_id < 0 || sst_card_vendor_id > 2) {
781 pr_err("sst: vendor card not supported!!\n");
785 sst_card_vendor_id = 0x3;
787 intelmaddata->sstdrv_ops->module_name = SST_CARD_NAMES;
788 intelmaddata->sstdrv_ops->vendor_id = sst_card_vendor_id;
789 BUG_ON(!intelmad_vendor_ops[sst_card_vendor_id]);
790 intelmaddata->sstdrv_ops->scard_ops =
791 intelmad_vendor_ops[sst_card_vendor_id];
793 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
794 intelmaddata->sstdrv_ops->scard_ops->pb_on = 0;
795 intelmaddata->sstdrv_ops->scard_ops->cap_on = 0;
796 intelmaddata->sstdrv_ops->scard_ops->input_dev_id = DMIC;
797 intelmaddata->sstdrv_ops->scard_ops->output_dev_id =
801 /* registering with SST driver to get access to SST APIs to use */
802 ret_val = register_sst_card(intelmaddata->sstdrv_ops);
804 pr_err("sst: sst card registration failed\n");
808 sst_card_vendor_id = intelmaddata->sstdrv_ops->vendor_id;
809 intelmaddata->pmic_status = PMIC_UNINIT;
813 /* Driver Init/exit functionalities */
815 * snd_intelmad_pcm_new - to setup pcm for the card
817 * @card: pointer to the sound card structure
818 * @intelmaddata: pointer to internal context
819 * @pb: playback count for this card
820 * @cap: capture count for this card
821 * @index: device index
823 * This function is called from probe function to set up pcm params
826 static int __devinit snd_intelmad_pcm_new(struct snd_card *card,
827 struct snd_intelmad *intelmaddata,
828 unsigned int pb, unsigned int cap, unsigned int index)
832 char name[32] = INTEL_MAD;
833 struct snd_pcm_ops *pb_ops = NULL, *cap_ops = NULL;
835 pr_debug("sst: called for pb %d, cp %d, idx %d\n", pb, cap, index);
836 ret_val = snd_pcm_new(card, name, index, pb, cap, &pcm);
839 /* setup the ops for playback and capture streams */
842 pb_ops = &snd_intelmad_headset_ops;
843 cap_ops = &snd_intelmad_capture_ops;
846 pb_ops = &snd_intelmad_ihf_ops;
847 cap_ops = &snd_intelmad_capture_ops;
850 pb_ops = &snd_intelmad_vibra_ops;
851 cap_ops = &snd_intelmad_capture_ops;
854 pb_ops = &snd_intelmad_haptic_ops;
855 cap_ops = &snd_intelmad_capture_ops;
859 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, pb_ops);
861 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, cap_ops);
862 /* setup private data which can be retrieved when required */
863 pcm->private_data = intelmaddata;
865 strncpy(pcm->name, card->shortname, strlen(card->shortname));
866 /* allocate dma pages for ALSA stream operations */
867 snd_pcm_lib_preallocate_pages_for_all(pcm,
868 SNDRV_DMA_TYPE_CONTINUOUS,
869 snd_dma_continuous_data(GFP_KERNEL),
870 MIN_BUFFER, MAX_BUFFER);
874 static int __devinit snd_intelmad_pcm(struct snd_card *card,
875 struct snd_intelmad *intelmaddata)
880 WARN_ON(!intelmaddata);
881 pr_debug("sst: snd_intelmad_pcm called\n");
882 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 1, 0);
883 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT)
885 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 1);
888 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 2);
891 return snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 3);
895 * snd_intelmad_jack- to setup jack settings of the card
897 * @intelmaddata: pointer to internal context
899 * This function is called send jack events
901 static int snd_intelmad_jack(struct snd_intelmad *intelmaddata)
903 struct snd_jack *jack;
906 pr_debug("sst: snd_intelmad_jack called\n");
907 jack = &intelmaddata->jack[0].jack;
908 retval = snd_jack_new(intelmaddata->card, "Headphone",
909 SND_JACK_HEADPHONE, &jack);
912 snd_jack_report(jack, 0);
914 jack->private_data = jack;
915 intelmaddata->jack[0].jack = *jack;
918 jack = &intelmaddata->jack[1].jack;
919 retval = snd_jack_new(intelmaddata->card, "Headset",
920 SND_JACK_HEADSET, &jack);
926 jack->private_data = jack;
927 intelmaddata->jack[1].jack = *jack;
930 jack = &intelmaddata->jack[2].jack;
931 retval = snd_jack_new(intelmaddata->card, "Short Press",
932 SND_JACK_HS_SHORT_PRESS, &jack);
937 jack->private_data = jack;
938 intelmaddata->jack[2].jack = *jack;
941 jack = &intelmaddata->jack[3].jack;
942 retval = snd_jack_new(intelmaddata->card, "Long Press",
943 SND_JACK_HS_LONG_PRESS, &jack);
948 jack->private_data = jack;
949 intelmaddata->jack[3].jack = *jack;
955 * snd_intelmad_mixer- to setup mixer settings of the card
957 * @intelmaddata: pointer to internal context
959 * This function is called from probe function to set up mixer controls
961 static int __devinit snd_intelmad_mixer(struct snd_intelmad *intelmaddata)
963 struct snd_card *card;
965 int ret_val = 0, max_controls = 0;
966 char *mixername = "IntelMAD Controls";
967 struct snd_kcontrol_new *controls;
969 WARN_ON(!intelmaddata);
971 card = intelmaddata->card;
972 strncpy(card->mixername, mixername, sizeof(card->mixername)-1);
973 /* add all widget controls and expose the same */
974 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
975 max_controls = MAX_CTRL_MFLD;
976 controls = snd_intelmad_controls_mfld;
978 max_controls = MAX_CTRL_MRST;
979 controls = snd_intelmad_controls_mrst;
981 for (idx = 0; idx < max_controls; idx++) {
982 ret_val = snd_ctl_add(card,
983 snd_ctl_new1(&controls[idx],
985 pr_debug("sst: mixer[idx]=%d added\n", idx);
987 pr_err("sst: in adding of control index = %d\n", idx);
994 static int snd_intelmad_dev_free(struct snd_device *device)
996 struct snd_intelmad *intelmaddata;
1000 intelmaddata = device->device_data;
1002 pr_debug("sst: snd_intelmad_dev_free called\n");
1003 snd_card_free(intelmaddata->card);
1004 /*genl_unregister_family(&audio_event_genl_family);*/
1005 unregister_sst_card(intelmaddata->sstdrv_ops);
1007 /* free allocated memory for internal context */
1008 destroy_workqueue(intelmaddata->mad_jack_wq);
1009 kfree(intelmaddata->sstdrv_ops);
1010 kfree(intelmaddata);
1014 static int __devinit snd_intelmad_create(
1015 struct snd_intelmad *intelmaddata,
1016 struct snd_card *card)
1019 static struct snd_device_ops ops = {
1020 .dev_free = snd_intelmad_dev_free,
1023 WARN_ON(!intelmaddata);
1025 /* ALSA api to register for the device */
1026 ret_val = snd_device_new(card, SNDRV_DEV_LOWLEVEL, intelmaddata, &ops);
1031 * snd_intelmad_probe- function registred for init
1032 * @pdev : pointer to the device struture
1033 * This function is called when the device is initialized
1035 int __devinit snd_intelmad_probe(struct platform_device *pdev)
1037 struct snd_card *card;
1039 struct snd_intelmad *intelmaddata;
1040 const struct platform_device_id *id = platform_get_device_id(pdev);
1041 unsigned int cpu_id = (unsigned int)id->driver_data;
1043 pr_debug("sst: probe for %s cpu_id %d\n", pdev->name, cpu_id);
1044 if (!strcmp(pdev->name, DRIVER_NAME_MRST))
1045 pr_debug("sst: detected MRST\n");
1046 else if (!strcmp(pdev->name, DRIVER_NAME_MFLD))
1047 pr_debug("sst: detected MFLD\n");
1049 pr_err("sst: detected unknown device abort!!\n");
1052 if ((cpu_id < CPU_CHIP_LINCROFT) || (cpu_id > CPU_CHIP_PENWELL)) {
1053 pr_err("sst: detected unknown cpu_id abort!!\n");
1056 /* allocate memory for saving internal context and working */
1057 intelmaddata = kzalloc(sizeof(*intelmaddata), GFP_KERNEL);
1058 if (!intelmaddata) {
1059 pr_debug("sst: mem alloctn fail\n");
1063 /* allocate memory for LPE API set */
1064 intelmaddata->sstdrv_ops = kzalloc(sizeof(struct intel_sst_card_ops),
1066 if (!intelmaddata->sstdrv_ops) {
1067 pr_err("sst: mem allocation for ops fail\n");
1068 kfree(intelmaddata);
1072 intelmaddata->cpu_id = cpu_id;
1073 /* create a card instance with ALSA framework */
1074 ret_val = snd_card_create(card_index, card_id, THIS_MODULE, 0, &card);
1076 pr_err("sst: snd_card_create fail\n");
1080 intelmaddata->pdev = pdev;
1081 intelmaddata->irq = platform_get_irq(pdev, 0);
1082 platform_set_drvdata(pdev, intelmaddata);
1083 intelmaddata->card = card;
1084 intelmaddata->card_id = card_id;
1085 intelmaddata->card_index = card_index;
1086 intelmaddata->master_mute = UNMUTE;
1087 intelmaddata->playback_cnt = intelmaddata->capture_cnt = 0;
1088 strncpy(card->driver, INTEL_MAD, strlen(INTEL_MAD));
1089 strncpy(card->shortname, INTEL_MAD, strlen(INTEL_MAD));
1091 intelmaddata->sstdrv_ops->module_name = SST_CARD_NAMES;
1092 /* registering with LPE driver to get access to SST APIs to use */
1093 ret_val = snd_intelmad_sst_register(intelmaddata);
1095 pr_err("sst: snd_intelmad_sst_register failed\n");
1099 intelmaddata->pmic_status = PMIC_INIT;
1101 ret_val = snd_intelmad_pcm(card, intelmaddata);
1103 pr_err("sst: snd_intelmad_pcm failed\n");
1107 ret_val = snd_intelmad_mixer(intelmaddata);
1109 pr_err("sst: snd_intelmad_mixer failed\n");
1113 ret_val = snd_intelmad_jack(intelmaddata);
1115 pr_err("sst: snd_intelmad_jack failed\n");
1119 /*create work queue for jack interrupt*/
1120 INIT_WORK(&intelmaddata->mad_jack_msg.wq,
1121 sst_process_mad_jack_detection);
1123 intelmaddata->mad_jack_wq = create_workqueue("sst_mad_jack_wq");
1124 if (!intelmaddata->mad_jack_wq)
1125 goto free_mad_jack_wq;
1127 ret_val = snd_intelmad_register_irq(intelmaddata);
1129 pr_err("sst: snd_intelmad_register_irq fail\n");
1133 /* internal function call to register device with ALSA */
1134 ret_val = snd_intelmad_create(intelmaddata, card);
1136 pr_err("sst: snd_intelmad_create failed\n");
1139 card->private_data = &intelmaddata;
1140 snd_card_set_dev(card, &pdev->dev);
1141 ret_val = snd_card_register(card);
1143 pr_err("sst: snd_card_register failed\n");
1147 pr_debug("sst:snd_intelmad_probe complete\n");
1151 destroy_workqueue(intelmaddata->mad_jack_wq);
1153 pr_err("sst: probe failed\n");
1154 snd_card_free(card);
1155 kfree(intelmaddata->sstdrv_ops);
1156 kfree(intelmaddata);
1161 static int snd_intelmad_remove(struct platform_device *pdev)
1163 struct snd_intelmad *intelmaddata = platform_get_drvdata(pdev);
1166 snd_card_free(intelmaddata->card);
1167 unregister_sst_card(intelmaddata->sstdrv_ops);
1168 /* free allocated memory for internal context */
1169 destroy_workqueue(intelmaddata->mad_jack_wq);
1170 kfree(intelmaddata->sstdrv_ops);
1171 kfree(intelmaddata);
1176 /*********************************************************************
1177 * Driver initialization and exit
1178 *********************************************************************/
1179 static const struct platform_device_id snd_intelmad_ids[] = {
1180 {DRIVER_NAME_MRST, CPU_CHIP_LINCROFT},
1181 {DRIVER_NAME_MFLD, CPU_CHIP_PENWELL},
1186 static struct platform_driver snd_intelmad_driver = {
1188 .owner = THIS_MODULE,
1189 .name = "intel_mid_sound_card",
1191 .id_table = snd_intelmad_ids,
1192 .probe = snd_intelmad_probe,
1193 .remove = __devexit_p(snd_intelmad_remove),
1197 * alsa_card_intelmad_init- driver init function
1199 * This function is called when driver module is inserted
1201 static int __init alsa_card_intelmad_init(void)
1203 pr_debug("sst: mad_init called\n");
1204 return platform_driver_register(&snd_intelmad_driver);
1208 * alsa_card_intelmad_exit- driver exit function
1210 * This function is called when driver module is removed
1212 static void __exit alsa_card_intelmad_exit(void)
1214 pr_debug("sst:mad_exit called\n");
1215 return platform_driver_unregister(&snd_intelmad_driver);
1218 module_init(alsa_card_intelmad_init)
1219 module_exit(alsa_card_intelmad_exit)