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
28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/slab.h>
32 #include <linux/platform_device.h>
33 #include <linux/interrupt.h>
34 #include <linux/sched.h>
35 #include <sound/control.h>
37 #include <sound/pcm.h>
39 #include <sound/pcm_params.h>
40 #include <sound/initval.h>
41 #include "intel_sst.h"
42 #include "intel_sst_ioctl.h"
43 #include "intelmid_snd_control.h"
46 MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
47 MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
48 MODULE_AUTHOR("Dharageswari R <dharageswari.r@intel.com>");
49 MODULE_AUTHOR("KP Jeeja <jeeja.kp@intel.com>");
50 MODULE_DESCRIPTION("Intel MAD Sound card driver");
51 MODULE_LICENSE("GPL v2");
52 MODULE_SUPPORTED_DEVICE("{Intel,Intel_MAD}");
55 static int card_index = SNDRV_DEFAULT_IDX1;/* Index 0-MAX */
56 static char *card_id = SNDRV_DEFAULT_STR1; /* ID for this card */
58 module_param(card_index, int, 0444);
59 MODULE_PARM_DESC(card_index, "Index value for INTELMAD soundcard.");
60 module_param(card_id, charp, 0444);
61 MODULE_PARM_DESC(card_id, "ID string for INTELMAD soundcard.");
63 int sst_card_vendor_id;
64 int intelmid_audio_interrupt_enable;/*checkpatch fix*/
66 /* Data path functionalities */
67 static struct snd_pcm_hardware snd_intelmad_stream = {
68 .info = (SNDRV_PCM_INFO_INTERLEAVED |
69 SNDRV_PCM_INFO_DOUBLE |
70 SNDRV_PCM_INFO_PAUSE |
71 SNDRV_PCM_INFO_RESUME |
73 SNDRV_PCM_INFO_MMAP_VALID |
74 SNDRV_PCM_INFO_BLOCK_TRANSFER |
75 SNDRV_PCM_INFO_SYNC_START),
76 .formats = (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 |
77 SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 |
78 SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32),
79 .rates = (SNDRV_PCM_RATE_8000|
80 SNDRV_PCM_RATE_44100 |
81 SNDRV_PCM_RATE_48000),
85 .channels_min = MIN_CHANNEL,
86 .channels_max = MAX_CHANNEL_AMIC,
87 .buffer_bytes_max = MAX_BUFFER,
88 .period_bytes_min = MIN_PERIOD_BYTES,
89 .period_bytes_max = MAX_PERIOD_BYTES,
90 .periods_min = MIN_PERIODS,
91 .periods_max = MAX_PERIODS,
92 .fifo_size = FIFO_SIZE,
97 * snd_intelmad_pcm_trigger - stream activities are handled here
99 * @substream:substream for which the stream function is called
100 * @cmd:the stream commamd that requested from upper layer
102 * This function is called whenever an a stream activity is invoked
104 static int snd_intelmad_pcm_trigger(struct snd_pcm_substream *substream,
108 struct snd_intelmad *intelmaddata;
109 struct mad_stream_pvt *stream;
110 /*struct stream_buffer buffer_to_sst;*/
116 intelmaddata = snd_pcm_substream_chip(substream);
117 stream = substream->runtime->private_data;
119 WARN_ON(!intelmaddata->sstdrv_ops);
120 WARN_ON(!intelmaddata->sstdrv_ops->scard_ops);
123 case SNDRV_PCM_TRIGGER_START:
124 pr_debug("Trigger Start\n");
125 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_START,
126 &stream->stream_info.str_id);
129 stream->stream_status = RUNNING;
130 stream->substream = substream;
131 stream->stream_status = RUNNING;
133 case SNDRV_PCM_TRIGGER_STOP:
134 pr_debug("in stop\n");
135 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_DROP,
136 &stream->stream_info.str_id);
139 stream->stream_status = DROPPED;
141 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
142 pr_debug("in pause\n");
143 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_PAUSE,
144 &stream->stream_info.str_id);
147 stream->stream_status = PAUSED;
149 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
150 pr_debug("in pause release\n");
151 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_RESUME,
152 &stream->stream_info.str_id);
155 stream->stream_status = RUNNING;
164 * snd_intelmad_pcm_prepare- internal preparation before starting a stream
166 * @substream: substream for which the function is called
168 * This function is called when a stream is started for internal preparation.
170 static int snd_intelmad_pcm_prepare(struct snd_pcm_substream *substream)
172 struct mad_stream_pvt *stream;
174 struct snd_intelmad *intelmaddata;
176 pr_debug("pcm_prepare called\n");
179 stream = substream->runtime->private_data;
180 intelmaddata = snd_pcm_substream_chip(substream);
181 pr_debug("pb cnt = %d cap cnt = %d\n",\
182 intelmaddata->playback_cnt,
183 intelmaddata->capture_cnt);
185 if (stream->stream_info.str_id) {
186 pr_debug("Prepare called for already set stream\n");
187 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_DROP,
188 &stream->stream_info.str_id);
192 ret_val = snd_intelmad_alloc_stream(substream);
195 stream->dbg_cum_bytes = 0;
196 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
197 intelmaddata->playback_cnt++;
199 intelmaddata->capture_cnt++;
200 /* return back the stream id */
201 snprintf(substream->pcm->id, sizeof(substream->pcm->id),
202 "%d", stream->stream_info.str_id);
203 pr_debug("stream id to user = %s\n",
206 ret_val = snd_intelmad_init_stream(substream);
209 substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
213 static int snd_intelmad_hw_params(struct snd_pcm_substream *substream,
214 struct snd_pcm_hw_params *hw_params)
218 pr_debug("snd_intelmad_hw_params called\n");
219 ret_val = snd_pcm_lib_malloc_pages(substream,
220 params_buffer_bytes(hw_params));
221 memset(substream->runtime->dma_area, 0,
222 params_buffer_bytes(hw_params));
227 static int snd_intelmad_hw_free(struct snd_pcm_substream *substream)
229 pr_debug("snd_intelmad_hw_free called\n");
230 return snd_pcm_lib_free_pages(substream);
234 * snd_intelmad_pcm_pointer- to send the current buffer pointer processed by hw
236 * @substream: substream for which the function is called
238 * This function is called by ALSA framework to get the current hw buffer ptr
239 * when a period is elapsed
241 static snd_pcm_uframes_t snd_intelmad_pcm_pointer
242 (struct snd_pcm_substream *substream)
244 /* struct snd_pcm_runtime *runtime = substream->runtime; */
245 struct mad_stream_pvt *stream;
246 struct snd_intelmad *intelmaddata;
251 intelmaddata = snd_pcm_substream_chip(substream);
252 stream = substream->runtime->private_data;
253 if (stream->stream_status == INIT)
256 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_BUFFER_POINTER,
257 &stream->stream_info);
259 pr_err("error code = 0x%x\n", ret_val);
262 pr_debug("samples reported out 0x%llx\n",
263 stream->stream_info.buffer_ptr);
264 pr_debug("Frame bits:: %d period_count :: %d\n",
265 (int)substream->runtime->frame_bits,
266 (int)substream->runtime->period_size);
268 return stream->stream_info.buffer_ptr;
273 * snd_intelmad_close- to free parameteres when stream is stopped
275 * @substream: substream for which the function is called
277 * This function is called by ALSA framework when stream is stopped
279 static int snd_intelmad_close(struct snd_pcm_substream *substream)
281 struct snd_intelmad *intelmaddata;
282 struct mad_stream_pvt *stream;
287 stream = substream->runtime->private_data;
289 pr_debug("snd_intelmad_close called\n");
290 intelmaddata = snd_pcm_substream_chip(substream);
292 pr_debug("str id = %d\n", stream->stream_info.str_id);
293 if (stream->stream_info.str_id) {
294 /* SST API to actually stop/free the stream */
295 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_FREE,
296 &stream->stream_info.str_id);
297 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
298 intelmaddata->playback_cnt--;
300 intelmaddata->capture_cnt--;
302 pr_debug("snd_intelmad_close : pb cnt = %d cap cnt = %d\n",
303 intelmaddata->playback_cnt, intelmaddata->capture_cnt);
304 kfree(substream->runtime->private_data);
309 * snd_intelmad_open- to set runtime parameters during stream start
311 * @substream: substream for which the function is called
312 * @type: audio device type
314 * This function is called by ALSA framework when stream is started
316 static int snd_intelmad_open(struct snd_pcm_substream *substream,
317 enum snd_sst_audio_device_type type)
319 struct snd_intelmad *intelmaddata;
320 struct snd_pcm_runtime *runtime;
321 struct mad_stream_pvt *stream;
325 pr_debug("snd_intelmad_open called\n");
327 intelmaddata = snd_pcm_substream_chip(substream);
328 runtime = substream->runtime;
329 /* set the runtime hw parameter with local snd_pcm_hardware struct */
330 runtime->hw = snd_intelmad_stream;
331 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
332 runtime->hw = snd_intelmad_stream;
333 runtime->hw.rates = SNDRV_PCM_RATE_48000;
334 runtime->hw.rate_min = MAX_RATE;
335 runtime->hw.formats = (SNDRV_PCM_FMTBIT_S24 |
336 SNDRV_PCM_FMTBIT_U24);
337 if (intelmaddata->sstdrv_ops->scard_ops->input_dev_id == AMIC)
338 runtime->hw.channels_max = MAX_CHANNEL_AMIC;
340 runtime->hw.channels_max = MAX_CHANNEL_DMIC;
343 /* setup the internal datastruture stream pointers based on it being
344 playback or capture stream */
345 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
348 stream->stream_info.str_id = 0;
349 stream->device = type;
350 stream->stream_status = INIT;
351 runtime->private_data = stream;
352 return snd_pcm_hw_constraint_integer(runtime,
353 SNDRV_PCM_HW_PARAM_PERIODS);
356 static int snd_intelmad_headset_open(struct snd_pcm_substream *substream)
358 return snd_intelmad_open(substream, SND_SST_DEVICE_HEADSET);
361 static int snd_intelmad_ihf_open(struct snd_pcm_substream *substream)
363 return snd_intelmad_open(substream, SND_SST_DEVICE_IHF);
366 static int snd_intelmad_vibra_open(struct snd_pcm_substream *substream)
368 return snd_intelmad_open(substream, SND_SST_DEVICE_VIBRA);
371 static int snd_intelmad_haptic_open(struct snd_pcm_substream *substream)
373 return snd_intelmad_open(substream, SND_SST_DEVICE_HAPTIC);
376 static struct snd_pcm_ops snd_intelmad_headset_ops = {
377 .open = snd_intelmad_headset_open,
378 .close = snd_intelmad_close,
379 .ioctl = snd_pcm_lib_ioctl,
380 .hw_params = snd_intelmad_hw_params,
381 .hw_free = snd_intelmad_hw_free,
382 .prepare = snd_intelmad_pcm_prepare,
383 .trigger = snd_intelmad_pcm_trigger,
384 .pointer = snd_intelmad_pcm_pointer,
387 static struct snd_pcm_ops snd_intelmad_ihf_ops = {
388 .open = snd_intelmad_ihf_open,
389 .close = snd_intelmad_close,
390 .ioctl = snd_pcm_lib_ioctl,
391 .hw_params = snd_intelmad_hw_params,
392 .hw_free = snd_intelmad_hw_free,
393 .prepare = snd_intelmad_pcm_prepare,
394 .trigger = snd_intelmad_pcm_trigger,
395 .pointer = snd_intelmad_pcm_pointer,
398 static struct snd_pcm_ops snd_intelmad_vibra_ops = {
399 .open = snd_intelmad_vibra_open,
400 .close = snd_intelmad_close,
401 .ioctl = snd_pcm_lib_ioctl,
402 .hw_params = snd_intelmad_hw_params,
403 .hw_free = snd_intelmad_hw_free,
404 .prepare = snd_intelmad_pcm_prepare,
405 .trigger = snd_intelmad_pcm_trigger,
406 .pointer = snd_intelmad_pcm_pointer,
409 static struct snd_pcm_ops snd_intelmad_haptic_ops = {
410 .open = snd_intelmad_haptic_open,
411 .close = snd_intelmad_close,
412 .ioctl = snd_pcm_lib_ioctl,
413 .hw_params = snd_intelmad_hw_params,
414 .hw_free = snd_intelmad_hw_free,
415 .prepare = snd_intelmad_pcm_prepare,
416 .trigger = snd_intelmad_pcm_trigger,
417 .pointer = snd_intelmad_pcm_pointer,
420 static struct snd_pcm_ops snd_intelmad_capture_ops = {
421 .open = snd_intelmad_headset_open,
422 .close = snd_intelmad_close,
423 .ioctl = snd_pcm_lib_ioctl,
424 .hw_params = snd_intelmad_hw_params,
425 .hw_free = snd_intelmad_hw_free,
426 .prepare = snd_intelmad_pcm_prepare,
427 .trigger = snd_intelmad_pcm_trigger,
428 .pointer = snd_intelmad_pcm_pointer,
433 * snd_intelmad_intr_handler- interrupt handler
435 * @irq : irq number of the interrupt received
436 * @dev: device context
438 * This function is called when an interrupt is raised at the sound card
440 static irqreturn_t snd_intelmad_intr_handler(int irq, void *dev)
442 struct snd_intelmad *intelmaddata =
443 (struct snd_intelmad *)dev;
446 memcpy_fromio(&intsts,
447 ((void *)(intelmaddata->int_base)),
449 intelmaddata->mad_jack_msg.intsts = intsts;
450 intelmaddata->mad_jack_msg.intelmaddata = intelmaddata;
452 queue_work(intelmaddata->mad_jack_wq, &intelmaddata->mad_jack_msg.wq);
457 void sst_mad_send_jack_report(struct snd_jack *jack,
458 int buttonpressevent , int status)
462 pr_debug("MAD error jack empty\n");
465 pr_debug("MAD send jack report for = %d!!!\n", status);
466 pr_debug("MAD send jack report %d\n", jack->type);
467 snd_jack_report(jack, status);
469 /*button pressed and released */
470 if (buttonpressevent)
471 snd_jack_report(jack, 0);
472 pr_debug("MAD sending jack report Done !!!\n");
479 void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
481 struct snd_jack *jack = NULL;
482 unsigned int present = 0, jack_event_flag = 0, buttonpressflag = 0;
483 struct sc_reg_access sc_access[] = {
484 {0x187, 0x00, MASK7},
485 {0x188, 0x10, MASK4},
486 {0x18b, 0x10, MASK4},
489 struct sc_reg_access sc_access_write[] = {
495 if (!(intelmid_audio_interrupt_enable)) {
496 pr_debug("Audio interrupt enable\n");
497 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3);
499 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1);
500 intelmid_audio_interrupt_enable = 1;
501 intelmaddata->jack[0].jack_status = 0;
502 intelmaddata->jack[1].jack_status = 0;
505 /* send headphone detect */
506 pr_debug("MAD headphone %d\n", intsts & 0x4);
507 jack = &intelmaddata->jack[0].jack;
508 present = !(intelmaddata->jack[0].jack_status);
509 intelmaddata->jack[0].jack_status = present;
515 /* send short push */
516 pr_debug("MAD short push %d\n", intsts & 0x2);
517 jack = &intelmaddata->jack[2].jack;
524 pr_debug("MAD long push %d\n", intsts & 0x1);
525 jack = &intelmaddata->jack[3].jack;
531 if (!(intelmid_audio_interrupt_enable)) {
532 pr_debug("Audio interrupt enable\n");
533 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3);
535 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1);
536 intelmid_audio_interrupt_enable = 1;
537 intelmaddata->jack[0].jack_status = 0;
538 intelmaddata->jack[1].jack_status = 0;
540 /* send headset detect */
541 pr_debug("MAD headset = %d\n", intsts & 0x8);
542 jack = &intelmaddata->jack[1].jack;
543 present = !(intelmaddata->jack[1].jack_status);
544 intelmaddata->jack[1].jack_status = present;
549 sst_mad_send_jack_report(jack, buttonpressflag, present);
553 void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
555 u8 value = 0, jack_prev_state = 0;
556 struct snd_jack *jack = NULL;
557 unsigned int present = 0, jack_event_flag = 0, buttonpressflag = 0;
559 struct sc_reg_access sc_access_read = {0,};
560 struct snd_pmic_ops *scard_ops;
562 scard_ops = intelmaddata->sstdrv_ops->scard_ops;
564 pr_debug("previous value: %x\n", intelmaddata->jack_prev_state);
566 if (!(intelmid_audio_interrupt_enable)) {
567 pr_debug("Audio interrupt enable\n");
568 intelmaddata->jack_prev_state = 0xC0;
569 intelmid_audio_interrupt_enable = 1;
573 jack_prev_state = intelmaddata->jack_prev_state;
574 if (intelmaddata->pmic_status == PMIC_INIT) {
575 sc_access_read.reg_addr = 0x201;
576 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1);
577 value = (sc_access_read.value);
578 pr_debug("value returned = 0x%x\n", value);
581 if (jack_prev_state == 0xc0 && value == 0x40) {
582 /*headset detected. */
583 pr_debug("MAD headset inserted\n");
584 jack = &intelmaddata->jack[1].jack;
587 intelmaddata->jack[1].jack_status = 1;
591 if (jack_prev_state == 0xc0 && value == 0x00) {
592 /* headphone detected. */
593 pr_debug("MAD headphone inserted\n");
594 jack = &intelmaddata->jack[0].jack;
600 if (jack_prev_state == 0x40 && value == 0xc0) {
602 pr_debug("Jack headset status %d\n",
603 intelmaddata->jack[1].jack_status);
604 pr_debug("MAD headset removed\n");
605 jack = &intelmaddata->jack[1].jack;
608 intelmaddata->jack[1].jack_status = 0;
611 if (jack_prev_state == 0x00 && value == 0xc0) {
612 /* headphone detected. */
613 pr_debug("Jack headphone status %d\n",
614 intelmaddata->jack[0].jack_status);
615 pr_debug("headphone removed\n");
616 jack = &intelmaddata->jack[0].jack;
621 if (jack_prev_state == 0x40 && value == 0x00) {
623 do_gettimeofday(&intelmaddata->jack[1].buttonpressed);
624 pr_debug("MAD button press detected\n");
628 if (jack_prev_state == 0x00 && value == 0x40) {
629 if (intelmaddata->jack[1].jack_status) {
632 &intelmaddata->jack[1].buttonreleased);
634 pr_debug("Button Released detected\n");
635 timediff = intelmaddata->jack[1].
636 buttonreleased.tv_sec - intelmaddata->
637 jack[1].buttonpressed.tv_sec;
640 pr_debug("long press detected\n");
641 /* send headphone detect/undetect */
642 jack = &intelmaddata->jack[3].jack;
646 pr_debug("short press detected\n");
647 /* send headphone detect/undetect */
648 jack = &intelmaddata->jack[2].jack;
655 intelmaddata->jack_prev_state = value;
658 sst_mad_send_jack_report(jack, buttonpressflag, present);
662 void sst_mad_jackdetection_nec(u8 intsts, struct snd_intelmad *intelmaddata)
665 struct snd_jack *jack = NULL;
666 unsigned int present = 0, jack_event_flag = 0, buttonpressflag = 0;
667 struct sc_reg_access sc_access_read = {0,};
669 if (intelmaddata->pmic_status == PMIC_INIT) {
670 sc_access_read.reg_addr = 0x132;
671 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1);
672 value = (sc_access_read.value);
673 pr_debug("value returned = 0x%x\n", value);
676 pr_debug("headset detected\n");
677 /* send headset detect/undetect */
678 jack = &intelmaddata->jack[1].jack;
679 present = (value == 0x1) ? 1 : 0;
683 pr_debug("headphone detected\n");
684 /* send headphone detect/undetect */
685 jack = &intelmaddata->jack[0].jack;
686 present = (value == 0x2) ? 1 : 0;
690 pr_debug("short push detected\n");
691 /* send short push */
692 jack = &intelmaddata->jack[2].jack;
698 pr_debug("long push detected\n");
700 jack = &intelmaddata->jack[3].jack;
707 sst_mad_send_jack_report(jack, buttonpressflag, present);
712 void sst_process_mad_jack_detection(struct work_struct *work)
715 struct mad_jack_msg_wq *mad_jack_detect =
716 container_of(work, struct mad_jack_msg_wq, wq);
718 struct snd_intelmad *intelmaddata =
719 mad_jack_detect->intelmaddata;
721 intsts = mad_jack_detect->intsts;
723 switch (intelmaddata->sstdrv_ops->vendor_id) {
725 sst_mad_jackdetection_fs(intsts , intelmaddata);
728 sst_mad_jackdetection_mx(intsts , intelmaddata);
731 sst_mad_jackdetection_nec(intsts , intelmaddata);
737 static int __devinit snd_intelmad_register_irq(
738 struct snd_intelmad *intelmaddata)
741 u32 regbase = AUDINT_BASE, regsize = 8;
744 pr_debug("irq reg done, regbase 0x%x, regsize 0x%x\n",
746 intelmaddata->int_base = ioremap_nocache(regbase, regsize);
747 if (!intelmaddata->int_base)
748 pr_err("Mapping of cache failed\n");
749 pr_debug("irq = 0x%x\n", intelmaddata->irq);
750 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL)
751 drv_name = DRIVER_NAME_MFLD;
753 drv_name = DRIVER_NAME_MRST;
754 ret_val = request_irq(intelmaddata->irq,
755 snd_intelmad_intr_handler,
756 IRQF_SHARED, drv_name,
759 pr_err("cannot register IRQ\n");
763 static int __devinit snd_intelmad_sst_register(
764 struct snd_intelmad *intelmaddata)
767 struct snd_pmic_ops *intelmad_vendor_ops[MAX_VENDORS] = {
774 struct sc_reg_access vendor_addr = {0x00, 0x00, 0x00};
776 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT) {
777 ret_val = sst_sc_reg_access(&vendor_addr, PMIC_READ, 1);
780 sst_card_vendor_id = (vendor_addr.value & (MASK2|MASK1|MASK0));
781 pr_debug("orginal n extrated vendor id = 0x%x %d\n",
782 vendor_addr.value, sst_card_vendor_id);
783 if (sst_card_vendor_id < 0 || sst_card_vendor_id > 2) {
784 pr_err("vendor card not supported!!\n");
788 sst_card_vendor_id = 0x3;
790 intelmaddata->sstdrv_ops->module_name = SST_CARD_NAMES;
791 intelmaddata->sstdrv_ops->vendor_id = sst_card_vendor_id;
792 BUG_ON(!intelmad_vendor_ops[sst_card_vendor_id]);
793 intelmaddata->sstdrv_ops->scard_ops =
794 intelmad_vendor_ops[sst_card_vendor_id];
796 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
797 intelmaddata->sstdrv_ops->scard_ops->pb_on = 0;
798 intelmaddata->sstdrv_ops->scard_ops->cap_on = 0;
799 intelmaddata->sstdrv_ops->scard_ops->input_dev_id = DMIC;
800 intelmaddata->sstdrv_ops->scard_ops->output_dev_id =
804 /* registering with SST driver to get access to SST APIs to use */
805 ret_val = register_sst_card(intelmaddata->sstdrv_ops);
807 pr_err("sst card registration failed\n");
811 sst_card_vendor_id = intelmaddata->sstdrv_ops->vendor_id;
812 intelmaddata->pmic_status = PMIC_UNINIT;
816 /* Driver Init/exit functionalities */
818 * snd_intelmad_pcm_new - to setup pcm for the card
820 * @card: pointer to the sound card structure
821 * @intelmaddata: pointer to internal context
822 * @pb: playback count for this card
823 * @cap: capture count for this card
824 * @index: device index
826 * This function is called from probe function to set up pcm params
829 static int __devinit snd_intelmad_pcm_new(struct snd_card *card,
830 struct snd_intelmad *intelmaddata,
831 unsigned int pb, unsigned int cap, unsigned int index)
835 char name[32] = INTEL_MAD;
836 struct snd_pcm_ops *pb_ops = NULL, *cap_ops = NULL;
838 pr_debug("called for pb %d, cp %d, idx %d\n", pb, cap, index);
839 ret_val = snd_pcm_new(card, name, index, pb, cap, &pcm);
842 /* setup the ops for playback and capture streams */
845 pb_ops = &snd_intelmad_headset_ops;
846 cap_ops = &snd_intelmad_capture_ops;
849 pb_ops = &snd_intelmad_ihf_ops;
850 cap_ops = &snd_intelmad_capture_ops;
853 pb_ops = &snd_intelmad_vibra_ops;
854 cap_ops = &snd_intelmad_capture_ops;
857 pb_ops = &snd_intelmad_haptic_ops;
858 cap_ops = &snd_intelmad_capture_ops;
862 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, pb_ops);
864 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, cap_ops);
865 /* setup private data which can be retrieved when required */
866 pcm->private_data = intelmaddata;
868 strncpy(pcm->name, card->shortname, strlen(card->shortname));
869 /* allocate dma pages for ALSA stream operations */
870 snd_pcm_lib_preallocate_pages_for_all(pcm,
871 SNDRV_DMA_TYPE_CONTINUOUS,
872 snd_dma_continuous_data(GFP_KERNEL),
873 MIN_BUFFER, MAX_BUFFER);
877 static int __devinit snd_intelmad_pcm(struct snd_card *card,
878 struct snd_intelmad *intelmaddata)
883 WARN_ON(!intelmaddata);
884 pr_debug("snd_intelmad_pcm called\n");
885 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 1, 0);
886 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT)
888 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 1);
891 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 2);
894 return snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 3);
898 * snd_intelmad_jack- to setup jack settings of the card
900 * @intelmaddata: pointer to internal context
902 * This function is called send jack events
904 static int snd_intelmad_jack(struct snd_intelmad *intelmaddata)
906 struct snd_jack *jack;
909 pr_debug("snd_intelmad_jack called\n");
910 jack = &intelmaddata->jack[0].jack;
911 retval = snd_jack_new(intelmaddata->card, "Headphone",
912 SND_JACK_HEADPHONE, &jack);
915 snd_jack_report(jack, 0);
917 jack->private_data = jack;
918 intelmaddata->jack[0].jack = *jack;
921 jack = &intelmaddata->jack[1].jack;
922 retval = snd_jack_new(intelmaddata->card, "Headset",
923 SND_JACK_HEADSET, &jack);
929 jack->private_data = jack;
930 intelmaddata->jack[1].jack = *jack;
933 jack = &intelmaddata->jack[2].jack;
934 retval = snd_jack_new(intelmaddata->card, "Short Press",
935 SND_JACK_HS_SHORT_PRESS, &jack);
940 jack->private_data = jack;
941 intelmaddata->jack[2].jack = *jack;
944 jack = &intelmaddata->jack[3].jack;
945 retval = snd_jack_new(intelmaddata->card, "Long Press",
946 SND_JACK_HS_LONG_PRESS, &jack);
951 jack->private_data = jack;
952 intelmaddata->jack[3].jack = *jack;
958 * snd_intelmad_mixer- to setup mixer settings of the card
960 * @intelmaddata: pointer to internal context
962 * This function is called from probe function to set up mixer controls
964 static int __devinit snd_intelmad_mixer(struct snd_intelmad *intelmaddata)
966 struct snd_card *card;
968 int ret_val = 0, max_controls = 0;
969 char *mixername = "IntelMAD Controls";
970 struct snd_kcontrol_new *controls;
972 WARN_ON(!intelmaddata);
974 card = intelmaddata->card;
975 strncpy(card->mixername, mixername, sizeof(card->mixername)-1);
976 /* add all widget controls and expose the same */
977 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
978 max_controls = MAX_CTRL_MFLD;
979 controls = snd_intelmad_controls_mfld;
981 max_controls = MAX_CTRL_MRST;
982 controls = snd_intelmad_controls_mrst;
984 for (idx = 0; idx < max_controls; idx++) {
985 ret_val = snd_ctl_add(card,
986 snd_ctl_new1(&controls[idx],
988 pr_debug("mixer[idx]=%d added\n", idx);
990 pr_err("in adding of control index = %d\n", idx);
997 static int snd_intelmad_dev_free(struct snd_device *device)
999 struct snd_intelmad *intelmaddata;
1003 intelmaddata = device->device_data;
1005 pr_debug("snd_intelmad_dev_free called\n");
1006 snd_card_free(intelmaddata->card);
1007 /*genl_unregister_family(&audio_event_genl_family);*/
1008 unregister_sst_card(intelmaddata->sstdrv_ops);
1010 /* free allocated memory for internal context */
1011 destroy_workqueue(intelmaddata->mad_jack_wq);
1012 kfree(intelmaddata->sstdrv_ops);
1013 kfree(intelmaddata);
1017 static int __devinit snd_intelmad_create(
1018 struct snd_intelmad *intelmaddata,
1019 struct snd_card *card)
1022 static struct snd_device_ops ops = {
1023 .dev_free = snd_intelmad_dev_free,
1026 WARN_ON(!intelmaddata);
1028 /* ALSA api to register for the device */
1029 ret_val = snd_device_new(card, SNDRV_DEV_LOWLEVEL, intelmaddata, &ops);
1034 * snd_intelmad_probe- function registred for init
1035 * @pdev : pointer to the device struture
1036 * This function is called when the device is initialized
1038 int __devinit snd_intelmad_probe(struct platform_device *pdev)
1040 struct snd_card *card;
1042 struct snd_intelmad *intelmaddata;
1043 const struct platform_device_id *id = platform_get_device_id(pdev);
1044 unsigned int cpu_id = (unsigned int)id->driver_data;
1046 pr_debug("probe for %s cpu_id %d\n", pdev->name, cpu_id);
1047 if (!strcmp(pdev->name, DRIVER_NAME_MRST))
1048 pr_debug("detected MRST\n");
1049 else if (!strcmp(pdev->name, DRIVER_NAME_MFLD))
1050 pr_debug("detected MFLD\n");
1052 pr_err("detected unknown device abort!!\n");
1055 if ((cpu_id < CPU_CHIP_LINCROFT) || (cpu_id > CPU_CHIP_PENWELL)) {
1056 pr_err("detected unknown cpu_id abort!!\n");
1059 /* allocate memory for saving internal context and working */
1060 intelmaddata = kzalloc(sizeof(*intelmaddata), GFP_KERNEL);
1061 if (!intelmaddata) {
1062 pr_debug("mem alloctn fail\n");
1066 /* allocate memory for LPE API set */
1067 intelmaddata->sstdrv_ops = kzalloc(sizeof(struct intel_sst_card_ops),
1069 if (!intelmaddata->sstdrv_ops) {
1070 pr_err("mem allocation for ops fail\n");
1071 kfree(intelmaddata);
1075 intelmaddata->cpu_id = cpu_id;
1076 /* create a card instance with ALSA framework */
1077 ret_val = snd_card_create(card_index, card_id, THIS_MODULE, 0, &card);
1079 pr_err("snd_card_create fail\n");
1083 intelmaddata->pdev = pdev;
1084 intelmaddata->irq = platform_get_irq(pdev, 0);
1085 platform_set_drvdata(pdev, intelmaddata);
1086 intelmaddata->card = card;
1087 intelmaddata->card_id = card_id;
1088 intelmaddata->card_index = card_index;
1089 intelmaddata->master_mute = UNMUTE;
1090 intelmaddata->playback_cnt = intelmaddata->capture_cnt = 0;
1091 strncpy(card->driver, INTEL_MAD, strlen(INTEL_MAD));
1092 strncpy(card->shortname, INTEL_MAD, strlen(INTEL_MAD));
1094 intelmaddata->sstdrv_ops->module_name = SST_CARD_NAMES;
1095 /* registering with LPE driver to get access to SST APIs to use */
1096 ret_val = snd_intelmad_sst_register(intelmaddata);
1098 pr_err("snd_intelmad_sst_register failed\n");
1102 intelmaddata->pmic_status = PMIC_INIT;
1104 ret_val = snd_intelmad_pcm(card, intelmaddata);
1106 pr_err("snd_intelmad_pcm failed\n");
1110 ret_val = snd_intelmad_mixer(intelmaddata);
1112 pr_err("snd_intelmad_mixer failed\n");
1116 ret_val = snd_intelmad_jack(intelmaddata);
1118 pr_err("snd_intelmad_jack failed\n");
1122 /*create work queue for jack interrupt*/
1123 INIT_WORK(&intelmaddata->mad_jack_msg.wq,
1124 sst_process_mad_jack_detection);
1126 intelmaddata->mad_jack_wq = create_workqueue("sst_mad_jack_wq");
1127 if (!intelmaddata->mad_jack_wq)
1128 goto free_mad_jack_wq;
1130 ret_val = snd_intelmad_register_irq(intelmaddata);
1132 pr_err("snd_intelmad_register_irq fail\n");
1136 /* internal function call to register device with ALSA */
1137 ret_val = snd_intelmad_create(intelmaddata, card);
1139 pr_err("snd_intelmad_create failed\n");
1142 card->private_data = &intelmaddata;
1143 snd_card_set_dev(card, &pdev->dev);
1144 ret_val = snd_card_register(card);
1146 pr_err("snd_card_register failed\n");
1150 pr_debug("snd_intelmad_probe complete\n");
1154 destroy_workqueue(intelmaddata->mad_jack_wq);
1156 pr_err("probe failed\n");
1157 snd_card_free(card);
1158 kfree(intelmaddata->sstdrv_ops);
1159 kfree(intelmaddata);
1164 static int snd_intelmad_remove(struct platform_device *pdev)
1166 struct snd_intelmad *intelmaddata = platform_get_drvdata(pdev);
1169 snd_card_free(intelmaddata->card);
1170 unregister_sst_card(intelmaddata->sstdrv_ops);
1171 /* free allocated memory for internal context */
1172 destroy_workqueue(intelmaddata->mad_jack_wq);
1173 kfree(intelmaddata->sstdrv_ops);
1174 kfree(intelmaddata);
1179 /*********************************************************************
1180 * Driver initialization and exit
1181 *********************************************************************/
1182 static const struct platform_device_id snd_intelmad_ids[] = {
1183 {DRIVER_NAME_MRST, CPU_CHIP_LINCROFT},
1184 {DRIVER_NAME_MFLD, CPU_CHIP_PENWELL},
1189 static struct platform_driver snd_intelmad_driver = {
1191 .owner = THIS_MODULE,
1192 .name = "intel_mid_sound_card",
1194 .id_table = snd_intelmad_ids,
1195 .probe = snd_intelmad_probe,
1196 .remove = __devexit_p(snd_intelmad_remove),
1200 * alsa_card_intelmad_init- driver init function
1202 * This function is called when driver module is inserted
1204 static int __init alsa_card_intelmad_init(void)
1206 pr_debug("mad_init called\n");
1207 return platform_driver_register(&snd_intelmad_driver);
1211 * alsa_card_intelmad_exit- driver exit function
1213 * This function is called when driver module is removed
1215 static void __exit alsa_card_intelmad_exit(void)
1217 pr_debug("mad_exit called\n");
1218 return platform_driver_unregister(&snd_intelmad_driver);
1221 module_init(alsa_card_intelmad_init)
1222 module_exit(alsa_card_intelmad_exit)