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/module.h>
31 #include <linux/slab.h>
33 #include <linux/platform_device.h>
34 #include <linux/interrupt.h>
35 #include <linux/sched.h>
36 #include <linux/firmware.h>
37 #include <linux/input.h>
38 #include <sound/control.h>
40 #include <sound/pcm.h>
41 #include <sound/jack.h>
42 #include <sound/pcm_params.h>
43 #include <sound/initval.h>
44 #include <linux/gpio.h>
45 #include "intel_sst.h"
46 #include "intel_sst_ioctl.h"
47 #include "intel_sst_fw_ipc.h"
48 #include "intel_sst_common.h"
49 #include "intelmid_snd_control.h"
50 #include "intelmid_adc_control.h"
53 MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
54 MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
55 MODULE_AUTHOR("Dharageswari R <dharageswari.r@intel.com>");
56 MODULE_AUTHOR("KP Jeeja <jeeja.kp@intel.com>");
57 MODULE_DESCRIPTION("Intel MAD Sound card driver");
58 MODULE_LICENSE("GPL v2");
59 MODULE_SUPPORTED_DEVICE("{Intel,Intel_MAD}");
62 static int card_index = SNDRV_DEFAULT_IDX1;/* Index 0-MAX */
63 static char *card_id = SNDRV_DEFAULT_STR1; /* ID for this card */
65 module_param(card_index, int, 0444);
66 MODULE_PARM_DESC(card_index, "Index value for INTELMAD soundcard.");
67 module_param(card_id, charp, 0444);
68 MODULE_PARM_DESC(card_id, "ID string for INTELMAD soundcard.");
70 int sst_card_vendor_id;
71 int intelmid_audio_interrupt_enable;/*checkpatch fix*/
72 struct snd_intelmad *intelmad_drv;
74 #define INFO(_cpu_id, _irq_cache, _size) \
75 ((kernel_ulong_t)&(struct snd_intelmad_probe_info) { \
76 .cpu_id = (_cpu_id), \
77 .irq_cache = (_irq_cache), \
80 /* Data path functionalities */
81 static struct snd_pcm_hardware snd_intelmad_stream = {
82 .info = (SNDRV_PCM_INFO_INTERLEAVED |
83 SNDRV_PCM_INFO_DOUBLE |
84 SNDRV_PCM_INFO_PAUSE |
85 SNDRV_PCM_INFO_RESUME |
87 SNDRV_PCM_INFO_MMAP_VALID |
88 SNDRV_PCM_INFO_BLOCK_TRANSFER |
89 SNDRV_PCM_INFO_SYNC_START),
90 .formats = (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 |
91 SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 |
92 SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32),
93 .rates = (SNDRV_PCM_RATE_8000|
94 SNDRV_PCM_RATE_44100 |
95 SNDRV_PCM_RATE_48000),
99 .channels_min = MIN_CHANNEL,
100 .channels_max = MAX_CHANNEL_AMIC,
101 .buffer_bytes_max = MAX_BUFFER,
102 .period_bytes_min = MIN_PERIOD_BYTES,
103 .period_bytes_max = MAX_PERIOD_BYTES,
104 .periods_min = MIN_PERIODS,
105 .periods_max = MAX_PERIODS,
106 .fifo_size = FIFO_SIZE,
111 * snd_intelmad_pcm_trigger - stream activities are handled here
113 * @substream:substream for which the stream function is called
114 * @cmd:the stream commamd that requested from upper layer
116 * This function is called whenever an a stream activity is invoked
118 static int snd_intelmad_pcm_trigger(struct snd_pcm_substream *substream,
121 int ret_val = 0, str_id;
122 struct snd_intelmad *intelmaddata;
123 struct mad_stream_pvt *stream;
124 struct intel_sst_pcm_control *sst_ops;
128 intelmaddata = snd_pcm_substream_chip(substream);
129 stream = substream->runtime->private_data;
131 WARN_ON(!intelmaddata->sstdrv_ops);
132 WARN_ON(!intelmaddata->sstdrv_ops->scard_ops);
133 sst_ops = intelmaddata->sstdrv_ops->pcm_control;
134 str_id = stream->stream_info.str_id;
137 case SNDRV_PCM_TRIGGER_START:
138 pr_debug("Trigger Start\n");
139 ret_val = sst_ops->device_control(SST_SND_START, &str_id);
142 stream->stream_status = RUNNING;
143 stream->substream = substream;
145 case SNDRV_PCM_TRIGGER_STOP:
146 pr_debug("in stop\n");
147 ret_val = sst_ops->device_control(SST_SND_DROP, &str_id);
150 stream->stream_status = DROPPED;
152 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
153 pr_debug("in pause\n");
154 ret_val = sst_ops->device_control(SST_SND_PAUSE, &str_id);
157 stream->stream_status = PAUSED;
159 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
160 pr_debug("in pause release\n");
161 ret_val = sst_ops->device_control(SST_SND_RESUME, &str_id);
164 stream->stream_status = RUNNING;
173 * snd_intelmad_pcm_prepare- internal preparation before starting a stream
175 * @substream: substream for which the function is called
177 * This function is called when a stream is started for internal preparation.
179 static int snd_intelmad_pcm_prepare(struct snd_pcm_substream *substream)
181 struct mad_stream_pvt *stream;
183 struct snd_intelmad *intelmaddata;
185 pr_debug("pcm_prepare called\n");
188 stream = substream->runtime->private_data;
189 intelmaddata = snd_pcm_substream_chip(substream);
190 pr_debug("pb cnt = %d cap cnt = %d\n",\
191 intelmaddata->playback_cnt,
192 intelmaddata->capture_cnt);
194 if (stream->stream_info.str_id) {
195 pr_debug("Prepare called for already set stream\n");
196 ret_val = intelmaddata->sstdrv_ops->pcm_control->device_control(
197 SST_SND_DROP, &stream->stream_info.str_id);
201 ret_val = snd_intelmad_alloc_stream(substream);
204 stream->dbg_cum_bytes = 0;
205 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
206 intelmaddata->playback_cnt++;
208 intelmaddata->capture_cnt++;
209 /* return back the stream id */
210 snprintf(substream->pcm->id, sizeof(substream->pcm->id),
211 "%d", stream->stream_info.str_id);
212 pr_debug("stream id to user = %s\n",
215 ret_val = snd_intelmad_init_stream(substream);
218 substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
222 static int snd_intelmad_hw_params(struct snd_pcm_substream *substream,
223 struct snd_pcm_hw_params *hw_params)
227 pr_debug("snd_intelmad_hw_params called\n");
228 ret_val = snd_pcm_lib_malloc_pages(substream,
229 params_buffer_bytes(hw_params));
230 memset(substream->runtime->dma_area, 0,
231 params_buffer_bytes(hw_params));
236 static int snd_intelmad_hw_free(struct snd_pcm_substream *substream)
238 pr_debug("snd_intelmad_hw_free called\n");
239 return snd_pcm_lib_free_pages(substream);
243 * snd_intelmad_pcm_pointer- to send the current buffer pointer processed by hw
245 * @substream: substream for which the function is called
247 * This function is called by ALSA framework to get the current hw buffer ptr
248 * when a period is elapsed
250 static snd_pcm_uframes_t snd_intelmad_pcm_pointer
251 (struct snd_pcm_substream *substream)
253 /* struct snd_pcm_runtime *runtime = substream->runtime; */
254 struct mad_stream_pvt *stream;
255 struct snd_intelmad *intelmaddata;
260 intelmaddata = snd_pcm_substream_chip(substream);
261 stream = substream->runtime->private_data;
262 if (stream->stream_status == INIT)
265 ret_val = intelmaddata->sstdrv_ops->pcm_control->device_control(
266 SST_SND_BUFFER_POINTER, &stream->stream_info);
268 pr_err("error code = 0x%x\n", ret_val);
271 pr_debug("samples reported out 0x%llx\n",
272 stream->stream_info.buffer_ptr);
273 pr_debug("Frame bits:: %d period_count :: %d\n",
274 (int)substream->runtime->frame_bits,
275 (int)substream->runtime->period_size);
277 return stream->stream_info.buffer_ptr;
282 * snd_intelmad_close- to free parameteres when stream is stopped
284 * @substream: substream for which the function is called
286 * This function is called by ALSA framework when stream is stopped
288 static int snd_intelmad_close(struct snd_pcm_substream *substream)
290 struct snd_intelmad *intelmaddata;
291 struct mad_stream_pvt *stream;
292 int ret_val = 0, str_id;
296 stream = substream->runtime->private_data;
297 str_id = stream->stream_info.str_id;
299 pr_debug("sst: snd_intelmad_close called for %d\n", str_id);
300 intelmaddata = snd_pcm_substream_chip(substream);
302 pr_debug("str id = %d\n", stream->stream_info.str_id);
303 if (stream->stream_info.str_id) {
304 /* SST API to actually stop/free the stream */
305 ret_val = intelmaddata->sstdrv_ops->pcm_control->close(str_id);
306 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
307 intelmaddata->playback_cnt--;
309 intelmaddata->capture_cnt--;
311 pr_debug("snd_intelmad_close : pb cnt = %d cap cnt = %d\n",
312 intelmaddata->playback_cnt, intelmaddata->capture_cnt);
313 kfree(substream->runtime->private_data);
318 * snd_intelmad_open- to set runtime parameters during stream start
320 * @substream: substream for which the function is called
321 * @type: audio device type
323 * This function is called by ALSA framework when stream is started
325 static int snd_intelmad_open(struct snd_pcm_substream *substream,
326 enum snd_sst_audio_device_type type)
328 struct snd_intelmad *intelmaddata;
329 struct snd_pcm_runtime *runtime;
330 struct mad_stream_pvt *stream;
334 pr_debug("snd_intelmad_open called\n");
336 intelmaddata = snd_pcm_substream_chip(substream);
337 runtime = substream->runtime;
338 /* set the runtime hw parameter with local snd_pcm_hardware struct */
339 runtime->hw = snd_intelmad_stream;
340 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT) {
342 * MRST firmware currently denies stereo recording requests.
344 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
345 runtime->hw.formats = (SNDRV_PCM_FMTBIT_S16 |
346 SNDRV_PCM_FMTBIT_U16);
347 runtime->hw.channels_max = 1;
350 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
351 runtime->hw = snd_intelmad_stream;
352 runtime->hw.rates = SNDRV_PCM_RATE_48000;
353 runtime->hw.rate_min = MAX_RATE;
354 runtime->hw.formats = (SNDRV_PCM_FMTBIT_S24 |
355 SNDRV_PCM_FMTBIT_U24);
356 if (intelmaddata->sstdrv_ops->scard_ops->input_dev_id == AMIC)
357 runtime->hw.channels_max = MAX_CHANNEL_AMIC;
359 runtime->hw.channels_max = MAX_CHANNEL_DMIC;
362 /* setup the internal datastruture stream pointers based on it being
363 playback or capture stream */
364 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
367 stream->stream_info.str_id = 0;
368 stream->device = type;
369 stream->stream_status = INIT;
370 runtime->private_data = stream;
371 return snd_pcm_hw_constraint_integer(runtime,
372 SNDRV_PCM_HW_PARAM_PERIODS);
375 static int snd_intelmad_headset_open(struct snd_pcm_substream *substream)
377 return snd_intelmad_open(substream, SND_SST_DEVICE_HEADSET);
380 static int snd_intelmad_ihf_open(struct snd_pcm_substream *substream)
382 return snd_intelmad_open(substream, SND_SST_DEVICE_IHF);
385 static int snd_intelmad_vibra_open(struct snd_pcm_substream *substream)
387 return snd_intelmad_open(substream, SND_SST_DEVICE_VIBRA);
390 static int snd_intelmad_haptic_open(struct snd_pcm_substream *substream)
392 return snd_intelmad_open(substream, SND_SST_DEVICE_HAPTIC);
395 static struct snd_pcm_ops snd_intelmad_headset_ops = {
396 .open = snd_intelmad_headset_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_ihf_ops = {
407 .open = snd_intelmad_ihf_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_vibra_ops = {
418 .open = snd_intelmad_vibra_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,
428 static struct snd_pcm_ops snd_intelmad_haptic_ops = {
429 .open = snd_intelmad_haptic_open,
430 .close = snd_intelmad_close,
431 .ioctl = snd_pcm_lib_ioctl,
432 .hw_params = snd_intelmad_hw_params,
433 .hw_free = snd_intelmad_hw_free,
434 .prepare = snd_intelmad_pcm_prepare,
435 .trigger = snd_intelmad_pcm_trigger,
436 .pointer = snd_intelmad_pcm_pointer,
439 static struct snd_pcm_ops snd_intelmad_capture_ops = {
440 .open = snd_intelmad_headset_open,
441 .close = snd_intelmad_close,
442 .ioctl = snd_pcm_lib_ioctl,
443 .hw_params = snd_intelmad_hw_params,
444 .hw_free = snd_intelmad_hw_free,
445 .prepare = snd_intelmad_pcm_prepare,
446 .trigger = snd_intelmad_pcm_trigger,
447 .pointer = snd_intelmad_pcm_pointer,
450 int intelmad_get_mic_bias(void)
452 struct snd_pmic_ops *pmic_ops;
454 if (!intelmad_drv || !intelmad_drv->sstdrv_ops)
456 pmic_ops = intelmad_drv->sstdrv_ops->scard_ops;
457 if (pmic_ops && pmic_ops->pmic_get_mic_bias)
458 return pmic_ops->pmic_get_mic_bias(intelmad_drv);
462 EXPORT_SYMBOL_GPL(intelmad_get_mic_bias);
464 int intelmad_set_headset_state(int state)
466 struct snd_pmic_ops *pmic_ops;
468 if (!intelmad_drv || !intelmad_drv->sstdrv_ops)
470 pmic_ops = intelmad_drv->sstdrv_ops->scard_ops;
471 if (pmic_ops && pmic_ops->pmic_set_headset_state)
472 return pmic_ops->pmic_set_headset_state(state);
476 EXPORT_SYMBOL_GPL(intelmad_set_headset_state);
478 void sst_process_mad_jack_detection(struct work_struct *work)
481 struct mad_jack_msg_wq *mad_jack_detect =
482 container_of(work, struct mad_jack_msg_wq, wq);
484 struct snd_intelmad *intelmaddata =
485 mad_jack_detect->intelmaddata;
490 interrupt_status = mad_jack_detect->intsts;
491 if (intelmaddata->sstdrv_ops && intelmaddata->sstdrv_ops->scard_ops
492 && intelmaddata->sstdrv_ops->scard_ops->pmic_irq_cb) {
493 intelmaddata->sstdrv_ops->scard_ops->pmic_irq_cb(
494 (void *)intelmaddata, interrupt_status);
495 intelmaddata->sstdrv_ops->scard_ops->pmic_jack_enable();
497 kfree(mad_jack_detect);
500 * snd_intelmad_intr_handler- interrupt handler
502 * @irq : irq number of the interrupt received
503 * @dev: device context
505 * This function is called when an interrupt is raised at the sound card
507 static irqreturn_t snd_intelmad_intr_handler(int irq, void *dev)
509 struct snd_intelmad *intelmaddata =
510 (struct snd_intelmad *)dev;
512 struct mad_jack_msg_wq *mad_jack_msg;
513 memcpy_fromio(&interrupt_status,
514 ((void *)(intelmaddata->int_base)),
517 mad_jack_msg = kzalloc(sizeof(*mad_jack_msg), GFP_ATOMIC);
518 mad_jack_msg->intsts = interrupt_status;
519 mad_jack_msg->intelmaddata = intelmaddata;
520 INIT_WORK(&mad_jack_msg->wq, sst_process_mad_jack_detection);
521 queue_work(intelmaddata->mad_jack_wq, &mad_jack_msg->wq);
526 void sst_mad_send_jack_report(struct snd_jack *jack,
527 int buttonpressevent , int status)
531 pr_debug("MAD error jack empty\n");
534 snd_jack_report(jack, status);
535 /* button pressed and released */
536 if (buttonpressevent)
537 snd_jack_report(jack, 0);
538 pr_debug("MAD sending jack report Done !!!\n");
542 static int __devinit snd_intelmad_register_irq(
543 struct snd_intelmad *intelmaddata, unsigned int regbase,
544 unsigned int regsize)
549 pr_debug("irq reg regbase 0x%x, regsize 0x%x\n",
551 intelmaddata->int_base = ioremap_nocache(regbase, regsize);
552 if (!intelmaddata->int_base)
553 pr_err("Mapping of cache failed\n");
554 pr_debug("irq = 0x%x\n", intelmaddata->irq);
555 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL)
556 drv_name = DRIVER_NAME_MFLD;
558 drv_name = DRIVER_NAME_MRST;
559 ret_val = request_irq(intelmaddata->irq,
560 snd_intelmad_intr_handler,
561 IRQF_SHARED, drv_name,
564 pr_err("cannot register IRQ\n");
568 static int __devinit snd_intelmad_sst_register(
569 struct snd_intelmad *intelmaddata)
572 struct snd_pmic_ops *intelmad_vendor_ops[MAX_VENDORS] = {
579 struct sc_reg_access vendor_addr = {0x00, 0x00, 0x00};
581 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT) {
582 ret_val = sst_sc_reg_access(&vendor_addr, PMIC_READ, 1);
585 sst_card_vendor_id = (vendor_addr.value & (MASK2|MASK1|MASK0));
586 pr_debug("original n extrated vendor id = 0x%x %d\n",
587 vendor_addr.value, sst_card_vendor_id);
588 if (sst_card_vendor_id < 0 || sst_card_vendor_id > 2) {
589 pr_err("vendor card not supported!!\n");
593 sst_card_vendor_id = 0x3;
595 intelmaddata->sstdrv_ops->module_name = SST_CARD_NAMES;
596 intelmaddata->sstdrv_ops->vendor_id = sst_card_vendor_id;
597 BUG_ON(!intelmad_vendor_ops[sst_card_vendor_id]);
598 intelmaddata->sstdrv_ops->scard_ops =
599 intelmad_vendor_ops[sst_card_vendor_id];
601 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
602 intelmaddata->sstdrv_ops->scard_ops->pb_on = 0;
603 intelmaddata->sstdrv_ops->scard_ops->cap_on = 0;
604 intelmaddata->sstdrv_ops->scard_ops->input_dev_id = DMIC;
605 intelmaddata->sstdrv_ops->scard_ops->output_dev_id =
607 intelmaddata->sstdrv_ops->scard_ops->lineout_dev_id = NONE;
610 /* registering with SST driver to get access to SST APIs to use */
611 ret_val = register_sst_card(intelmaddata->sstdrv_ops);
613 pr_err("sst card registration failed\n");
616 sst_card_vendor_id = intelmaddata->sstdrv_ops->vendor_id;
617 intelmaddata->pmic_status = PMIC_UNINIT;
621 static void snd_intelmad_page_free(struct snd_pcm *pcm)
623 snd_pcm_lib_preallocate_free_for_all(pcm);
625 /* Driver Init/exit functionalities */
627 * snd_intelmad_pcm_new - to setup pcm for the card
629 * @card: pointer to the sound card structure
630 * @intelmaddata: pointer to internal context
631 * @pb: playback count for this card
632 * @cap: capture count for this card
633 * @index: device index
635 * This function is called from probe function to set up pcm params
638 static int __devinit snd_intelmad_pcm_new(struct snd_card *card,
639 struct snd_intelmad *intelmaddata,
640 unsigned int pb, unsigned int cap, unsigned int index)
644 char name[32] = INTEL_MAD;
645 struct snd_pcm_ops *pb_ops = NULL, *cap_ops = NULL;
647 pr_debug("called for pb %d, cp %d, idx %d\n", pb, cap, index);
648 ret_val = snd_pcm_new(card, name, index, pb, cap, &pcm);
651 /* setup the ops for playback and capture streams */
654 pb_ops = &snd_intelmad_headset_ops;
655 cap_ops = &snd_intelmad_capture_ops;
658 pb_ops = &snd_intelmad_ihf_ops;
659 cap_ops = &snd_intelmad_capture_ops;
662 pb_ops = &snd_intelmad_vibra_ops;
663 cap_ops = &snd_intelmad_capture_ops;
666 pb_ops = &snd_intelmad_haptic_ops;
667 cap_ops = &snd_intelmad_capture_ops;
671 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, pb_ops);
673 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, cap_ops);
674 /* setup private data which can be retrieved when required */
675 pcm->private_data = intelmaddata;
676 pcm->private_free = snd_intelmad_page_free;
678 strncpy(pcm->name, card->shortname, strlen(card->shortname));
679 /* allocate dma pages for ALSA stream operations */
680 snd_pcm_lib_preallocate_pages_for_all(pcm,
681 SNDRV_DMA_TYPE_CONTINUOUS,
682 snd_dma_continuous_data(GFP_KERNEL),
683 MIN_BUFFER, MAX_BUFFER);
687 static int __devinit snd_intelmad_pcm(struct snd_card *card,
688 struct snd_intelmad *intelmaddata)
693 WARN_ON(!intelmaddata);
694 pr_debug("snd_intelmad_pcm called\n");
695 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 1, 0);
696 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT)
698 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 1);
701 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 2);
704 return snd_intelmad_pcm_new(card, intelmaddata, 1, 0, 3);
708 * snd_intelmad_jack- to setup jack settings of the card
710 * @intelmaddata: pointer to internal context
712 * This function is called send jack events
714 static int snd_intelmad_jack(struct snd_intelmad *intelmaddata)
716 struct snd_jack *jack;
719 pr_debug("snd_intelmad_jack called\n");
720 jack = &intelmaddata->jack[0].jack;
721 snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PHONE);
722 retval = snd_jack_new(intelmaddata->card, "Intel(R) MID Audio Jack",
723 SND_JACK_HEADPHONE | SND_JACK_HEADSET |
724 SW_JACK_PHYSICAL_INSERT | SND_JACK_BTN_0
725 | SND_JACK_BTN_1, &jack);
726 pr_debug("snd_intelmad_jack called\n");
729 snd_jack_report(jack, 0);
731 jack->private_data = jack;
732 intelmaddata->jack[0].jack = *jack;
738 * snd_intelmad_mixer- to setup mixer settings of the card
740 * @intelmaddata: pointer to internal context
742 * This function is called from probe function to set up mixer controls
744 static int __devinit snd_intelmad_mixer(struct snd_intelmad *intelmaddata)
746 struct snd_card *card;
748 int ret_val = 0, max_controls = 0;
749 char *mixername = "IntelMAD Controls";
750 struct snd_kcontrol_new *controls;
752 WARN_ON(!intelmaddata);
754 card = intelmaddata->card;
755 strncpy(card->mixername, mixername, sizeof(card->mixername)-1);
756 /* add all widget controls and expose the same */
757 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
758 max_controls = MAX_CTRL_MFLD;
759 controls = snd_intelmad_controls_mfld;
761 max_controls = MAX_CTRL_MRST;
762 controls = snd_intelmad_controls_mrst;
764 for (idx = 0; idx < max_controls; idx++) {
765 ret_val = snd_ctl_add(card,
766 snd_ctl_new1(&controls[idx],
768 pr_debug("mixer[idx]=%d added\n", idx);
770 pr_err("in adding of control index = %d\n", idx);
777 static int snd_intelmad_dev_free(struct snd_device *device)
779 struct snd_intelmad *intelmaddata;
783 intelmaddata = device->device_data;
785 pr_debug("snd_intelmad_dev_free called\n");
786 unregister_sst_card(intelmaddata->sstdrv_ops);
788 /* free allocated memory for internal context */
789 destroy_workqueue(intelmaddata->mad_jack_wq);
790 device->device_data = NULL;
791 kfree(intelmaddata->sstdrv_ops);
797 static int __devinit snd_intelmad_create(
798 struct snd_intelmad *intelmaddata,
799 struct snd_card *card)
802 static struct snd_device_ops ops = {
803 .dev_free = snd_intelmad_dev_free,
806 WARN_ON(!intelmaddata);
808 /* ALSA api to register for the device */
809 ret_val = snd_device_new(card, SNDRV_DEV_LOWLEVEL, intelmaddata, &ops);
814 * snd_intelmad_probe- function registred for init
815 * @pdev : pointer to the device struture
816 * This function is called when the device is initialized
818 int __devinit snd_intelmad_probe(struct platform_device *pdev)
820 struct snd_card *card;
822 struct snd_intelmad *intelmaddata;
823 const struct platform_device_id *id = platform_get_device_id(pdev);
824 struct snd_intelmad_probe_info *info = (void *)id->driver_data;
826 pr_debug("probe for %s cpu_id %d\n", pdev->name, info->cpu_id);
827 pr_debug("rq_chache %x of size %x\n", info->irq_cache, info->size);
828 if (!strcmp(pdev->name, DRIVER_NAME_MRST))
829 pr_debug("detected MRST\n");
830 else if (!strcmp(pdev->name, DRIVER_NAME_MFLD))
831 pr_debug("detected MFLD\n");
833 pr_err("detected unknown device abort!!\n");
836 if ((info->cpu_id < CPU_CHIP_LINCROFT) ||
837 (info->cpu_id > CPU_CHIP_PENWELL)) {
838 pr_err("detected unknown cpu_id abort!!\n");
841 /* allocate memory for saving internal context and working */
842 intelmaddata = kzalloc(sizeof(*intelmaddata), GFP_KERNEL);
844 pr_debug("mem alloctn fail\n");
847 intelmad_drv = intelmaddata;
849 /* allocate memory for LPE API set */
850 intelmaddata->sstdrv_ops = kzalloc(sizeof(struct intel_sst_card_ops),
852 if (!intelmaddata->sstdrv_ops) {
853 pr_err("mem allocation for ops fail\n");
858 intelmaddata->cpu_id = info->cpu_id;
859 /* create a card instance with ALSA framework */
860 ret_val = snd_card_create(card_index, card_id, THIS_MODULE, 0, &card);
862 pr_err("snd_card_create fail\n");
866 intelmaddata->pdev = pdev;
867 intelmaddata->irq = platform_get_irq(pdev, 0);
868 platform_set_drvdata(pdev, intelmaddata);
869 intelmaddata->card = card;
870 intelmaddata->card_id = card_id;
871 intelmaddata->card_index = card_index;
872 intelmaddata->master_mute = UNMUTE;
873 intelmaddata->playback_cnt = intelmaddata->capture_cnt = 0;
874 strncpy(card->driver, INTEL_MAD, strlen(INTEL_MAD));
875 strncpy(card->shortname, INTEL_MAD, strlen(INTEL_MAD));
877 intelmaddata->sstdrv_ops->module_name = SST_CARD_NAMES;
878 /* registering with LPE driver to get access to SST APIs to use */
879 ret_val = snd_intelmad_sst_register(intelmaddata);
881 pr_err("snd_intelmad_sst_register failed\n");
885 intelmaddata->pmic_status = PMIC_INIT;
887 ret_val = snd_intelmad_pcm(card, intelmaddata);
889 pr_err("snd_intelmad_pcm failed\n");
893 ret_val = snd_intelmad_mixer(intelmaddata);
895 pr_err("snd_intelmad_mixer failed\n");
899 ret_val = snd_intelmad_jack(intelmaddata);
901 pr_err("snd_intelmad_jack failed\n");
904 intelmaddata->adc_address = mid_initialize_adc();
906 /*create work queue for jack interrupt*/
907 INIT_WORK(&intelmaddata->mad_jack_msg.wq,
908 sst_process_mad_jack_detection);
910 intelmaddata->mad_jack_wq = create_workqueue("sst_mad_jack_wq");
911 if (!intelmaddata->mad_jack_wq)
914 ret_val = snd_intelmad_register_irq(intelmaddata,
915 info->irq_cache, info->size);
917 pr_err("snd_intelmad_register_irq fail\n");
918 goto free_mad_jack_wq;
921 /* internal function call to register device with ALSA */
922 ret_val = snd_intelmad_create(intelmaddata, card);
924 pr_err("snd_intelmad_create failed\n");
927 card->private_data = &intelmaddata;
928 snd_card_set_dev(card, &pdev->dev);
929 ret_val = snd_card_register(card);
931 pr_err("snd_card_register failed\n");
934 if (pdev->dev.platform_data) {
935 int gpio_amp = *(int *)pdev->dev.platform_data;
936 if (gpio_request_one(gpio_amp, GPIOF_OUT_INIT_LOW, "amp power"))
938 intelmaddata->sstdrv_ops->scard_ops->gpio_amp = gpio_amp;
941 pr_debug("snd_intelmad_probe complete\n");
945 card->private_data = NULL;
947 destroy_workqueue(intelmaddata->mad_jack_wq);
949 snd_card_free(intelmaddata->card);
951 unregister_sst_card(intelmaddata->sstdrv_ops);
953 platform_set_drvdata(pdev, NULL);
955 pr_err("probe failed\n");
957 kfree(intelmaddata->sstdrv_ops);
963 static int snd_intelmad_remove(struct platform_device *pdev)
965 struct snd_intelmad *intelmaddata = platform_get_drvdata(pdev);
968 if (intelmaddata->sstdrv_ops->scard_ops->gpio_amp)
969 gpio_free(intelmaddata->sstdrv_ops->scard_ops->gpio_amp);
970 free_irq(intelmaddata->irq, intelmaddata);
971 snd_card_free(intelmaddata->card);
974 platform_set_drvdata(pdev, NULL);
978 /*********************************************************************
979 * Driver initialization and exit
980 *********************************************************************/
981 static const struct platform_device_id snd_intelmad_ids[] = {
982 {DRIVER_NAME_MRST, INFO(CPU_CHIP_LINCROFT, AUDINT_BASE, 1)},
983 {DRIVER_NAME_MFLD, INFO(CPU_CHIP_PENWELL, 0xFFFF7FCD, 1)},
988 static struct platform_driver snd_intelmad_driver = {
990 .owner = THIS_MODULE,
991 .name = "intel_mid_sound_card",
993 .id_table = snd_intelmad_ids,
994 .probe = snd_intelmad_probe,
995 .remove = __devexit_p(snd_intelmad_remove),
999 * alsa_card_intelmad_init- driver init function
1001 * This function is called when driver module is inserted
1003 static int __init alsa_card_intelmad_init(void)
1005 pr_debug("mad_init called\n");
1006 return platform_driver_register(&snd_intelmad_driver);
1010 * alsa_card_intelmad_exit- driver exit function
1012 * This function is called when driver module is removed
1014 static void __exit alsa_card_intelmad_exit(void)
1016 pr_debug("mad_exit called\n");
1017 return platform_driver_unregister(&snd_intelmad_driver);
1020 module_init(alsa_card_intelmad_init)
1021 module_exit(alsa_card_intelmad_exit)