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 <linux/firmware.h>
36 #include <sound/control.h>
38 #include <sound/pcm.h>
40 #include <sound/pcm_params.h>
41 #include <sound/initval.h>
42 #include "intel_sst.h"
43 #include "intel_sst_ioctl.h"
44 #include "intel_sst_fw_ipc.h"
45 #include "intel_sst_common.h"
46 #include "intelmid_snd_control.h"
49 MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
50 MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
51 MODULE_AUTHOR("Dharageswari R <dharageswari.r@intel.com>");
52 MODULE_AUTHOR("KP Jeeja <jeeja.kp@intel.com>");
53 MODULE_DESCRIPTION("Intel MAD Sound card driver");
54 MODULE_LICENSE("GPL v2");
55 MODULE_SUPPORTED_DEVICE("{Intel,Intel_MAD}");
58 static int card_index
= SNDRV_DEFAULT_IDX1
;/* Index 0-MAX */
59 static char *card_id
= SNDRV_DEFAULT_STR1
; /* ID for this card */
61 module_param(card_index
, int, 0444);
62 MODULE_PARM_DESC(card_index
, "Index value for INTELMAD soundcard.");
63 module_param(card_id
, charp
, 0444);
64 MODULE_PARM_DESC(card_id
, "ID string for INTELMAD soundcard.");
66 int sst_card_vendor_id
;
67 int intelmid_audio_interrupt_enable
;/*checkpatch fix*/
69 /* Data path functionalities */
70 static struct snd_pcm_hardware snd_intelmad_stream
= {
71 .info
= (SNDRV_PCM_INFO_INTERLEAVED
|
72 SNDRV_PCM_INFO_DOUBLE
|
73 SNDRV_PCM_INFO_PAUSE
|
74 SNDRV_PCM_INFO_RESUME
|
76 SNDRV_PCM_INFO_MMAP_VALID
|
77 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
78 SNDRV_PCM_INFO_SYNC_START
),
79 .formats
= (SNDRV_PCM_FMTBIT_S16
| SNDRV_PCM_FMTBIT_U16
|
80 SNDRV_PCM_FMTBIT_S24
| SNDRV_PCM_FMTBIT_U24
|
81 SNDRV_PCM_FMTBIT_S32
| SNDRV_PCM_FMTBIT_U32
),
82 .rates
= (SNDRV_PCM_RATE_8000
|
83 SNDRV_PCM_RATE_44100
|
84 SNDRV_PCM_RATE_48000
),
88 .channels_min
= MIN_CHANNEL
,
89 .channels_max
= MAX_CHANNEL_AMIC
,
90 .buffer_bytes_max
= MAX_BUFFER
,
91 .period_bytes_min
= MIN_PERIOD_BYTES
,
92 .period_bytes_max
= MAX_PERIOD_BYTES
,
93 .periods_min
= MIN_PERIODS
,
94 .periods_max
= MAX_PERIODS
,
95 .fifo_size
= FIFO_SIZE
,
100 * snd_intelmad_pcm_trigger - stream activities are handled here
102 * @substream:substream for which the stream function is called
103 * @cmd:the stream commamd that requested from upper layer
105 * This function is called whenever an a stream activity is invoked
107 static int snd_intelmad_pcm_trigger(struct snd_pcm_substream
*substream
,
110 int ret_val
= 0, str_id
;
111 struct snd_intelmad
*intelmaddata
;
112 struct mad_stream_pvt
*stream
;
113 struct intel_sst_pcm_control
*sst_ops
;
117 intelmaddata
= snd_pcm_substream_chip(substream
);
118 stream
= substream
->runtime
->private_data
;
120 WARN_ON(!intelmaddata
->sstdrv_ops
);
121 WARN_ON(!intelmaddata
->sstdrv_ops
->scard_ops
);
122 sst_ops
= intelmaddata
->sstdrv_ops
->pcm_control
;
123 str_id
= stream
->stream_info
.str_id
;
126 case SNDRV_PCM_TRIGGER_START
:
127 pr_debug("Trigger Start\n");
128 ret_val
= sst_ops
->device_control(SST_SND_START
, &str_id
);
131 stream
->stream_status
= RUNNING
;
132 stream
->substream
= substream
;
134 case SNDRV_PCM_TRIGGER_STOP
:
135 pr_debug("in stop\n");
136 ret_val
= sst_ops
->device_control(SST_SND_DROP
, &str_id
);
139 stream
->stream_status
= DROPPED
;
141 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
142 pr_debug("in pause\n");
143 ret_val
= sst_ops
->device_control(SST_SND_PAUSE
, &str_id
);
146 stream
->stream_status
= PAUSED
;
148 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
149 pr_debug("in pause release\n");
150 ret_val
= sst_ops
->device_control(SST_SND_RESUME
, &str_id
);
153 stream
->stream_status
= RUNNING
;
162 * snd_intelmad_pcm_prepare- internal preparation before starting a stream
164 * @substream: substream for which the function is called
166 * This function is called when a stream is started for internal preparation.
168 static int snd_intelmad_pcm_prepare(struct snd_pcm_substream
*substream
)
170 struct mad_stream_pvt
*stream
;
172 struct snd_intelmad
*intelmaddata
;
174 pr_debug("pcm_prepare called\n");
177 stream
= substream
->runtime
->private_data
;
178 intelmaddata
= snd_pcm_substream_chip(substream
);
179 pr_debug("pb cnt = %d cap cnt = %d\n",\
180 intelmaddata
->playback_cnt
,
181 intelmaddata
->capture_cnt
);
183 if (stream
->stream_info
.str_id
) {
184 pr_debug("Prepare called for already set stream\n");
185 ret_val
= intelmaddata
->sstdrv_ops
->pcm_control
->device_control(
186 SST_SND_DROP
, &stream
->stream_info
.str_id
);
190 ret_val
= snd_intelmad_alloc_stream(substream
);
193 stream
->dbg_cum_bytes
= 0;
194 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
195 intelmaddata
->playback_cnt
++;
197 intelmaddata
->capture_cnt
++;
198 /* return back the stream id */
199 snprintf(substream
->pcm
->id
, sizeof(substream
->pcm
->id
),
200 "%d", stream
->stream_info
.str_id
);
201 pr_debug("stream id to user = %s\n",
204 ret_val
= snd_intelmad_init_stream(substream
);
207 substream
->runtime
->hw
.info
= SNDRV_PCM_INFO_BLOCK_TRANSFER
;
211 static int snd_intelmad_hw_params(struct snd_pcm_substream
*substream
,
212 struct snd_pcm_hw_params
*hw_params
)
216 pr_debug("snd_intelmad_hw_params called\n");
217 ret_val
= snd_pcm_lib_malloc_pages(substream
,
218 params_buffer_bytes(hw_params
));
219 memset(substream
->runtime
->dma_area
, 0,
220 params_buffer_bytes(hw_params
));
225 static int snd_intelmad_hw_free(struct snd_pcm_substream
*substream
)
227 pr_debug("snd_intelmad_hw_free called\n");
228 return snd_pcm_lib_free_pages(substream
);
232 * snd_intelmad_pcm_pointer- to send the current buffer pointer processed by hw
234 * @substream: substream for which the function is called
236 * This function is called by ALSA framework to get the current hw buffer ptr
237 * when a period is elapsed
239 static snd_pcm_uframes_t snd_intelmad_pcm_pointer
240 (struct snd_pcm_substream
*substream
)
242 /* struct snd_pcm_runtime *runtime = substream->runtime; */
243 struct mad_stream_pvt
*stream
;
244 struct snd_intelmad
*intelmaddata
;
249 intelmaddata
= snd_pcm_substream_chip(substream
);
250 stream
= substream
->runtime
->private_data
;
251 if (stream
->stream_status
== INIT
)
254 ret_val
= intelmaddata
->sstdrv_ops
->pcm_control
->device_control(
255 SST_SND_BUFFER_POINTER
, &stream
->stream_info
);
257 pr_err("error code = 0x%x\n", ret_val
);
260 pr_debug("samples reported out 0x%llx\n",
261 stream
->stream_info
.buffer_ptr
);
262 pr_debug("Frame bits:: %d period_count :: %d\n",
263 (int)substream
->runtime
->frame_bits
,
264 (int)substream
->runtime
->period_size
);
266 return stream
->stream_info
.buffer_ptr
;
271 * snd_intelmad_close- to free parameteres when stream is stopped
273 * @substream: substream for which the function is called
275 * This function is called by ALSA framework when stream is stopped
277 static int snd_intelmad_close(struct snd_pcm_substream
*substream
)
279 struct snd_intelmad
*intelmaddata
;
280 struct mad_stream_pvt
*stream
;
281 int ret_val
= 0, str_id
;
285 stream
= substream
->runtime
->private_data
;
286 str_id
= stream
->stream_info
.str_id
;
288 pr_debug("sst: snd_intelmad_close called for %d\n", str_id
);
289 intelmaddata
= snd_pcm_substream_chip(substream
);
291 pr_debug("str id = %d\n", stream
->stream_info
.str_id
);
292 if (stream
->stream_info
.str_id
) {
293 /* SST API to actually stop/free the stream */
294 ret_val
= intelmaddata
->sstdrv_ops
->pcm_control
->close(str_id
);
295 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
296 intelmaddata
->playback_cnt
--;
298 intelmaddata
->capture_cnt
--;
300 pr_debug("snd_intelmad_close : pb cnt = %d cap cnt = %d\n",
301 intelmaddata
->playback_cnt
, intelmaddata
->capture_cnt
);
302 kfree(substream
->runtime
->private_data
);
307 * snd_intelmad_open- to set runtime parameters during stream start
309 * @substream: substream for which the function is called
310 * @type: audio device type
312 * This function is called by ALSA framework when stream is started
314 static int snd_intelmad_open(struct snd_pcm_substream
*substream
,
315 enum snd_sst_audio_device_type type
)
317 struct snd_intelmad
*intelmaddata
;
318 struct snd_pcm_runtime
*runtime
;
319 struct mad_stream_pvt
*stream
;
323 pr_debug("snd_intelmad_open called\n");
325 intelmaddata
= snd_pcm_substream_chip(substream
);
326 runtime
= substream
->runtime
;
327 /* set the runtime hw parameter with local snd_pcm_hardware struct */
328 runtime
->hw
= snd_intelmad_stream
;
329 if (intelmaddata
->cpu_id
== CPU_CHIP_PENWELL
) {
330 runtime
->hw
= snd_intelmad_stream
;
331 runtime
->hw
.rates
= SNDRV_PCM_RATE_48000
;
332 runtime
->hw
.rate_min
= MAX_RATE
;
333 runtime
->hw
.formats
= (SNDRV_PCM_FMTBIT_S24
|
334 SNDRV_PCM_FMTBIT_U24
);
335 if (intelmaddata
->sstdrv_ops
->scard_ops
->input_dev_id
== AMIC
)
336 runtime
->hw
.channels_max
= MAX_CHANNEL_AMIC
;
338 runtime
->hw
.channels_max
= MAX_CHANNEL_DMIC
;
341 /* setup the internal datastruture stream pointers based on it being
342 playback or capture stream */
343 stream
= kzalloc(sizeof(*stream
), GFP_KERNEL
);
346 stream
->stream_info
.str_id
= 0;
347 stream
->device
= type
;
348 stream
->stream_status
= INIT
;
349 runtime
->private_data
= stream
;
350 return snd_pcm_hw_constraint_integer(runtime
,
351 SNDRV_PCM_HW_PARAM_PERIODS
);
354 static int snd_intelmad_headset_open(struct snd_pcm_substream
*substream
)
356 return snd_intelmad_open(substream
, SND_SST_DEVICE_HEADSET
);
359 static int snd_intelmad_ihf_open(struct snd_pcm_substream
*substream
)
361 return snd_intelmad_open(substream
, SND_SST_DEVICE_IHF
);
364 static int snd_intelmad_vibra_open(struct snd_pcm_substream
*substream
)
366 return snd_intelmad_open(substream
, SND_SST_DEVICE_VIBRA
);
369 static int snd_intelmad_haptic_open(struct snd_pcm_substream
*substream
)
371 return snd_intelmad_open(substream
, SND_SST_DEVICE_HAPTIC
);
374 static struct snd_pcm_ops snd_intelmad_headset_ops
= {
375 .open
= snd_intelmad_headset_open
,
376 .close
= snd_intelmad_close
,
377 .ioctl
= snd_pcm_lib_ioctl
,
378 .hw_params
= snd_intelmad_hw_params
,
379 .hw_free
= snd_intelmad_hw_free
,
380 .prepare
= snd_intelmad_pcm_prepare
,
381 .trigger
= snd_intelmad_pcm_trigger
,
382 .pointer
= snd_intelmad_pcm_pointer
,
385 static struct snd_pcm_ops snd_intelmad_ihf_ops
= {
386 .open
= snd_intelmad_ihf_open
,
387 .close
= snd_intelmad_close
,
388 .ioctl
= snd_pcm_lib_ioctl
,
389 .hw_params
= snd_intelmad_hw_params
,
390 .hw_free
= snd_intelmad_hw_free
,
391 .prepare
= snd_intelmad_pcm_prepare
,
392 .trigger
= snd_intelmad_pcm_trigger
,
393 .pointer
= snd_intelmad_pcm_pointer
,
396 static struct snd_pcm_ops snd_intelmad_vibra_ops
= {
397 .open
= snd_intelmad_vibra_open
,
398 .close
= snd_intelmad_close
,
399 .ioctl
= snd_pcm_lib_ioctl
,
400 .hw_params
= snd_intelmad_hw_params
,
401 .hw_free
= snd_intelmad_hw_free
,
402 .prepare
= snd_intelmad_pcm_prepare
,
403 .trigger
= snd_intelmad_pcm_trigger
,
404 .pointer
= snd_intelmad_pcm_pointer
,
407 static struct snd_pcm_ops snd_intelmad_haptic_ops
= {
408 .open
= snd_intelmad_haptic_open
,
409 .close
= snd_intelmad_close
,
410 .ioctl
= snd_pcm_lib_ioctl
,
411 .hw_params
= snd_intelmad_hw_params
,
412 .hw_free
= snd_intelmad_hw_free
,
413 .prepare
= snd_intelmad_pcm_prepare
,
414 .trigger
= snd_intelmad_pcm_trigger
,
415 .pointer
= snd_intelmad_pcm_pointer
,
418 static struct snd_pcm_ops snd_intelmad_capture_ops
= {
419 .open
= snd_intelmad_headset_open
,
420 .close
= snd_intelmad_close
,
421 .ioctl
= snd_pcm_lib_ioctl
,
422 .hw_params
= snd_intelmad_hw_params
,
423 .hw_free
= snd_intelmad_hw_free
,
424 .prepare
= snd_intelmad_pcm_prepare
,
425 .trigger
= snd_intelmad_pcm_trigger
,
426 .pointer
= snd_intelmad_pcm_pointer
,
431 * snd_intelmad_intr_handler- interrupt handler
433 * @irq : irq number of the interrupt received
434 * @dev: device context
436 * This function is called when an interrupt is raised at the sound card
438 static irqreturn_t
snd_intelmad_intr_handler(int irq
, void *dev
)
440 struct snd_intelmad
*intelmaddata
=
441 (struct snd_intelmad
*)dev
;
444 memcpy_fromio(&intsts
,
445 ((void *)(intelmaddata
->int_base
)),
447 intelmaddata
->mad_jack_msg
.intsts
= intsts
;
448 intelmaddata
->mad_jack_msg
.intelmaddata
= intelmaddata
;
450 queue_work(intelmaddata
->mad_jack_wq
, &intelmaddata
->mad_jack_msg
.wq
);
455 void sst_mad_send_jack_report(struct snd_jack
*jack
,
456 int buttonpressevent
, int status
)
460 pr_debug("MAD error jack empty\n");
463 pr_debug("MAD send jack report for = %d!!!\n", status
);
464 pr_debug("MAD send jack report %d\n", jack
->type
);
465 snd_jack_report(jack
, status
);
467 /*button pressed and released */
468 if (buttonpressevent
)
469 snd_jack_report(jack
, 0);
470 pr_debug("MAD sending jack report Done !!!\n");
477 void sst_mad_jackdetection_fs(u8 intsts
, struct snd_intelmad
*intelmaddata
)
479 struct snd_jack
*jack
= NULL
;
480 unsigned int present
= 0, jack_event_flag
= 0, buttonpressflag
= 0;
481 struct sc_reg_access sc_access
[] = {
482 {0x187, 0x00, MASK7
},
483 {0x188, 0x10, MASK4
},
484 {0x18b, 0x10, MASK4
},
487 struct sc_reg_access sc_access_write
[] = {
493 if (!(intelmid_audio_interrupt_enable
)) {
494 pr_debug("Audio interrupt enable\n");
495 sst_sc_reg_access(sc_access
, PMIC_READ_MODIFY
, 3);
497 sst_sc_reg_access(sc_access_write
, PMIC_WRITE
, 1);
498 intelmid_audio_interrupt_enable
= 1;
499 intelmaddata
->jack
[0].jack_status
= 0;
500 intelmaddata
->jack
[1].jack_status
= 0;
503 /* send headphone detect */
504 pr_debug("MAD headphone %d\n", intsts
& 0x4);
505 jack
= &intelmaddata
->jack
[0].jack
;
506 present
= !(intelmaddata
->jack
[0].jack_status
);
507 intelmaddata
->jack
[0].jack_status
= present
;
513 /* send short push */
514 pr_debug("MAD short push %d\n", intsts
& 0x2);
515 jack
= &intelmaddata
->jack
[2].jack
;
522 pr_debug("MAD long push %d\n", intsts
& 0x1);
523 jack
= &intelmaddata
->jack
[3].jack
;
529 if (!(intelmid_audio_interrupt_enable
)) {
530 pr_debug("Audio interrupt enable\n");
531 sst_sc_reg_access(sc_access
, PMIC_READ_MODIFY
, 3);
533 sst_sc_reg_access(sc_access_write
, PMIC_WRITE
, 1);
534 intelmid_audio_interrupt_enable
= 1;
535 intelmaddata
->jack
[0].jack_status
= 0;
536 intelmaddata
->jack
[1].jack_status
= 0;
538 /* send headset detect */
539 pr_debug("MAD headset = %d\n", intsts
& 0x8);
540 jack
= &intelmaddata
->jack
[1].jack
;
541 present
= !(intelmaddata
->jack
[1].jack_status
);
542 intelmaddata
->jack
[1].jack_status
= present
;
547 sst_mad_send_jack_report(jack
, buttonpressflag
, present
);
551 void sst_mad_jackdetection_mx(u8 intsts
, struct snd_intelmad
*intelmaddata
)
553 u8 value
= 0, jack_prev_state
= 0;
554 struct snd_jack
*jack
= NULL
;
555 unsigned int present
= 0, jack_event_flag
= 0, buttonpressflag
= 0;
557 struct sc_reg_access sc_access_read
= {0,};
558 struct snd_pmic_ops
*scard_ops
;
560 scard_ops
= intelmaddata
->sstdrv_ops
->scard_ops
;
562 pr_debug("previous value: %x\n", intelmaddata
->jack_prev_state
);
564 if (!(intelmid_audio_interrupt_enable
)) {
565 pr_debug("Audio interrupt enable\n");
566 intelmaddata
->jack_prev_state
= 0xC0;
567 intelmid_audio_interrupt_enable
= 1;
571 jack_prev_state
= intelmaddata
->jack_prev_state
;
572 if (intelmaddata
->pmic_status
== PMIC_INIT
) {
573 sc_access_read
.reg_addr
= 0x201;
574 sst_sc_reg_access(&sc_access_read
, PMIC_READ
, 1);
575 value
= (sc_access_read
.value
);
576 pr_debug("value returned = 0x%x\n", value
);
579 if (jack_prev_state
== 0xc0 && value
== 0x40) {
580 /*headset detected. */
581 pr_debug("MAD headset inserted\n");
582 jack
= &intelmaddata
->jack
[1].jack
;
585 intelmaddata
->jack
[1].jack_status
= 1;
589 if (jack_prev_state
== 0xc0 && value
== 0x00) {
590 /* headphone detected. */
591 pr_debug("MAD headphone inserted\n");
592 jack
= &intelmaddata
->jack
[0].jack
;
598 if (jack_prev_state
== 0x40 && value
== 0xc0) {
600 pr_debug("Jack headset status %d\n",
601 intelmaddata
->jack
[1].jack_status
);
602 pr_debug("MAD headset removed\n");
603 jack
= &intelmaddata
->jack
[1].jack
;
606 intelmaddata
->jack
[1].jack_status
= 0;
609 if (jack_prev_state
== 0x00 && value
== 0xc0) {
610 /* headphone detected. */
611 pr_debug("Jack headphone status %d\n",
612 intelmaddata
->jack
[0].jack_status
);
613 pr_debug("headphone removed\n");
614 jack
= &intelmaddata
->jack
[0].jack
;
619 if (jack_prev_state
== 0x40 && value
== 0x00) {
621 do_gettimeofday(&intelmaddata
->jack
[1].buttonpressed
);
622 pr_debug("MAD button press detected\n");
626 if (jack_prev_state
== 0x00 && value
== 0x40) {
627 if (intelmaddata
->jack
[1].jack_status
) {
630 &intelmaddata
->jack
[1].buttonreleased
);
632 pr_debug("Button Released detected\n");
633 timediff
= intelmaddata
->jack
[1].
634 buttonreleased
.tv_sec
- intelmaddata
->
635 jack
[1].buttonpressed
.tv_sec
;
638 pr_debug("long press detected\n");
639 /* send headphone detect/undetect */
640 jack
= &intelmaddata
->jack
[3].jack
;
644 pr_debug("short press detected\n");
645 /* send headphone detect/undetect */
646 jack
= &intelmaddata
->jack
[2].jack
;
653 intelmaddata
->jack_prev_state
= value
;
656 sst_mad_send_jack_report(jack
, buttonpressflag
, present
);
660 void sst_mad_jackdetection_nec(u8 intsts
, struct snd_intelmad
*intelmaddata
)
663 struct snd_jack
*jack
= NULL
;
664 unsigned int present
= 0, jack_event_flag
= 0, buttonpressflag
= 0;
665 struct sc_reg_access sc_access_read
= {0,};
667 if (intelmaddata
->pmic_status
== PMIC_INIT
) {
668 sc_access_read
.reg_addr
= 0x132;
669 sst_sc_reg_access(&sc_access_read
, PMIC_READ
, 1);
670 value
= (sc_access_read
.value
);
671 pr_debug("value returned = 0x%x\n", value
);
674 pr_debug("headset detected\n");
675 /* send headset detect/undetect */
676 jack
= &intelmaddata
->jack
[1].jack
;
677 present
= (value
== 0x1) ? 1 : 0;
681 pr_debug("headphone detected\n");
682 /* send headphone detect/undetect */
683 jack
= &intelmaddata
->jack
[0].jack
;
684 present
= (value
== 0x2) ? 1 : 0;
688 pr_debug("short push detected\n");
689 /* send short push */
690 jack
= &intelmaddata
->jack
[2].jack
;
696 pr_debug("long push detected\n");
698 jack
= &intelmaddata
->jack
[3].jack
;
705 sst_mad_send_jack_report(jack
, buttonpressflag
, present
);
710 void sst_process_mad_jack_detection(struct work_struct
*work
)
713 struct mad_jack_msg_wq
*mad_jack_detect
=
714 container_of(work
, struct mad_jack_msg_wq
, wq
);
716 struct snd_intelmad
*intelmaddata
=
717 mad_jack_detect
->intelmaddata
;
719 intsts
= mad_jack_detect
->intsts
;
721 switch (intelmaddata
->sstdrv_ops
->vendor_id
) {
723 sst_mad_jackdetection_fs(intsts
, intelmaddata
);
726 sst_mad_jackdetection_mx(intsts
, intelmaddata
);
729 sst_mad_jackdetection_nec(intsts
, intelmaddata
);
735 static int __devinit
snd_intelmad_register_irq(
736 struct snd_intelmad
*intelmaddata
)
739 u32 regbase
= AUDINT_BASE
, regsize
= 8;
742 pr_debug("irq reg done, regbase 0x%x, regsize 0x%x\n",
744 intelmaddata
->int_base
= ioremap_nocache(regbase
, regsize
);
745 if (!intelmaddata
->int_base
)
746 pr_err("Mapping of cache failed\n");
747 pr_debug("irq = 0x%x\n", intelmaddata
->irq
);
748 if (intelmaddata
->cpu_id
== CPU_CHIP_PENWELL
)
749 drv_name
= DRIVER_NAME_MFLD
;
751 drv_name
= DRIVER_NAME_MRST
;
752 ret_val
= request_irq(intelmaddata
->irq
,
753 snd_intelmad_intr_handler
,
754 IRQF_SHARED
, drv_name
,
757 pr_err("cannot register IRQ\n");
761 static int __devinit
snd_intelmad_sst_register(
762 struct snd_intelmad
*intelmaddata
)
765 struct snd_pmic_ops
*intelmad_vendor_ops
[MAX_VENDORS
] = {
772 struct sc_reg_access vendor_addr
= {0x00, 0x00, 0x00};
774 if (intelmaddata
->cpu_id
== CPU_CHIP_LINCROFT
) {
775 ret_val
= sst_sc_reg_access(&vendor_addr
, PMIC_READ
, 1);
778 sst_card_vendor_id
= (vendor_addr
.value
& (MASK2
|MASK1
|MASK0
));
779 pr_debug("original n extrated vendor id = 0x%x %d\n",
780 vendor_addr
.value
, sst_card_vendor_id
);
781 if (sst_card_vendor_id
< 0 || sst_card_vendor_id
> 2) {
782 pr_err("vendor card not supported!!\n");
786 sst_card_vendor_id
= 0x3;
788 intelmaddata
->sstdrv_ops
->module_name
= SST_CARD_NAMES
;
789 intelmaddata
->sstdrv_ops
->vendor_id
= sst_card_vendor_id
;
790 BUG_ON(!intelmad_vendor_ops
[sst_card_vendor_id
]);
791 intelmaddata
->sstdrv_ops
->scard_ops
=
792 intelmad_vendor_ops
[sst_card_vendor_id
];
794 if (intelmaddata
->cpu_id
== CPU_CHIP_PENWELL
) {
795 intelmaddata
->sstdrv_ops
->scard_ops
->pb_on
= 0;
796 intelmaddata
->sstdrv_ops
->scard_ops
->cap_on
= 0;
797 intelmaddata
->sstdrv_ops
->scard_ops
->input_dev_id
= DMIC
;
798 intelmaddata
->sstdrv_ops
->scard_ops
->output_dev_id
=
802 /* registering with SST driver to get access to SST APIs to use */
803 ret_val
= register_sst_card(intelmaddata
->sstdrv_ops
);
805 pr_err("sst card registration failed\n");
808 sst_drv_ctx
->scard_ops
->card_status
= SND_CARD_UN_INIT
;
810 sst_card_vendor_id
= intelmaddata
->sstdrv_ops
->vendor_id
;
811 intelmaddata
->pmic_status
= PMIC_UNINIT
;
815 /* Driver Init/exit functionalities */
817 * snd_intelmad_pcm_new - to setup pcm for the card
819 * @card: pointer to the sound card structure
820 * @intelmaddata: pointer to internal context
821 * @pb: playback count for this card
822 * @cap: capture count for this card
823 * @index: device index
825 * This function is called from probe function to set up pcm params
828 static int __devinit
snd_intelmad_pcm_new(struct snd_card
*card
,
829 struct snd_intelmad
*intelmaddata
,
830 unsigned int pb
, unsigned int cap
, unsigned int index
)
834 char name
[32] = INTEL_MAD
;
835 struct snd_pcm_ops
*pb_ops
= NULL
, *cap_ops
= NULL
;
837 pr_debug("called for pb %d, cp %d, idx %d\n", pb
, cap
, index
);
838 ret_val
= snd_pcm_new(card
, name
, index
, pb
, cap
, &pcm
);
841 /* setup the ops for playback and capture streams */
844 pb_ops
= &snd_intelmad_headset_ops
;
845 cap_ops
= &snd_intelmad_capture_ops
;
848 pb_ops
= &snd_intelmad_ihf_ops
;
849 cap_ops
= &snd_intelmad_capture_ops
;
852 pb_ops
= &snd_intelmad_vibra_ops
;
853 cap_ops
= &snd_intelmad_capture_ops
;
856 pb_ops
= &snd_intelmad_haptic_ops
;
857 cap_ops
= &snd_intelmad_capture_ops
;
861 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, pb_ops
);
863 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, cap_ops
);
864 /* setup private data which can be retrieved when required */
865 pcm
->private_data
= intelmaddata
;
867 strncpy(pcm
->name
, card
->shortname
, strlen(card
->shortname
));
868 /* allocate dma pages for ALSA stream operations */
869 snd_pcm_lib_preallocate_pages_for_all(pcm
,
870 SNDRV_DMA_TYPE_CONTINUOUS
,
871 snd_dma_continuous_data(GFP_KERNEL
),
872 MIN_BUFFER
, MAX_BUFFER
);
876 static int __devinit
snd_intelmad_pcm(struct snd_card
*card
,
877 struct snd_intelmad
*intelmaddata
)
882 WARN_ON(!intelmaddata
);
883 pr_debug("snd_intelmad_pcm called\n");
884 ret_val
= snd_intelmad_pcm_new(card
, intelmaddata
, 1, 1, 0);
885 if (intelmaddata
->cpu_id
== CPU_CHIP_LINCROFT
)
887 ret_val
= snd_intelmad_pcm_new(card
, intelmaddata
, 1, 0, 1);
890 ret_val
= snd_intelmad_pcm_new(card
, intelmaddata
, 1, 0, 2);
893 return snd_intelmad_pcm_new(card
, intelmaddata
, 1, 0, 3);
897 * snd_intelmad_jack- to setup jack settings of the card
899 * @intelmaddata: pointer to internal context
901 * This function is called send jack events
903 static int snd_intelmad_jack(struct snd_intelmad
*intelmaddata
)
905 struct snd_jack
*jack
;
908 pr_debug("snd_intelmad_jack called\n");
909 jack
= &intelmaddata
->jack
[0].jack
;
910 retval
= snd_jack_new(intelmaddata
->card
, "Headphone",
911 SND_JACK_HEADPHONE
, &jack
);
914 snd_jack_report(jack
, 0);
916 jack
->private_data
= jack
;
917 intelmaddata
->jack
[0].jack
= *jack
;
920 jack
= &intelmaddata
->jack
[1].jack
;
921 retval
= snd_jack_new(intelmaddata
->card
, "Headset",
922 SND_JACK_HEADSET
, &jack
);
928 jack
->private_data
= jack
;
929 intelmaddata
->jack
[1].jack
= *jack
;
932 jack
= &intelmaddata
->jack
[2].jack
;
933 retval
= snd_jack_new(intelmaddata
->card
, "Short Press",
934 SND_JACK_HS_SHORT_PRESS
, &jack
);
939 jack
->private_data
= jack
;
940 intelmaddata
->jack
[2].jack
= *jack
;
943 jack
= &intelmaddata
->jack
[3].jack
;
944 retval
= snd_jack_new(intelmaddata
->card
, "Long Press",
945 SND_JACK_HS_LONG_PRESS
, &jack
);
950 jack
->private_data
= jack
;
951 intelmaddata
->jack
[3].jack
= *jack
;
957 * snd_intelmad_mixer- to setup mixer settings of the card
959 * @intelmaddata: pointer to internal context
961 * This function is called from probe function to set up mixer controls
963 static int __devinit
snd_intelmad_mixer(struct snd_intelmad
*intelmaddata
)
965 struct snd_card
*card
;
967 int ret_val
= 0, max_controls
= 0;
968 char *mixername
= "IntelMAD Controls";
969 struct snd_kcontrol_new
*controls
;
971 WARN_ON(!intelmaddata
);
973 card
= intelmaddata
->card
;
974 strncpy(card
->mixername
, mixername
, sizeof(card
->mixername
)-1);
975 /* add all widget controls and expose the same */
976 if (intelmaddata
->cpu_id
== CPU_CHIP_PENWELL
) {
977 max_controls
= MAX_CTRL_MFLD
;
978 controls
= snd_intelmad_controls_mfld
;
980 max_controls
= MAX_CTRL_MRST
;
981 controls
= snd_intelmad_controls_mrst
;
983 for (idx
= 0; idx
< max_controls
; idx
++) {
984 ret_val
= snd_ctl_add(card
,
985 snd_ctl_new1(&controls
[idx
],
987 pr_debug("mixer[idx]=%d added\n", idx
);
989 pr_err("in adding of control index = %d\n", idx
);
996 static int snd_intelmad_dev_free(struct snd_device
*device
)
998 struct snd_intelmad
*intelmaddata
;
1002 intelmaddata
= device
->device_data
;
1004 pr_debug("snd_intelmad_dev_free called\n");
1005 snd_card_free(intelmaddata
->card
);
1006 /*genl_unregister_family(&audio_event_genl_family);*/
1007 unregister_sst_card(intelmaddata
->sstdrv_ops
);
1009 /* free allocated memory for internal context */
1010 destroy_workqueue(intelmaddata
->mad_jack_wq
);
1011 kfree(intelmaddata
->sstdrv_ops
);
1012 kfree(intelmaddata
);
1016 static int __devinit
snd_intelmad_create(
1017 struct snd_intelmad
*intelmaddata
,
1018 struct snd_card
*card
)
1021 static struct snd_device_ops ops
= {
1022 .dev_free
= snd_intelmad_dev_free
,
1025 WARN_ON(!intelmaddata
);
1027 /* ALSA api to register for the device */
1028 ret_val
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, intelmaddata
, &ops
);
1033 * snd_intelmad_probe- function registred for init
1034 * @pdev : pointer to the device struture
1035 * This function is called when the device is initialized
1037 int __devinit
snd_intelmad_probe(struct platform_device
*pdev
)
1039 struct snd_card
*card
;
1041 struct snd_intelmad
*intelmaddata
;
1042 const struct platform_device_id
*id
= platform_get_device_id(pdev
);
1043 unsigned int cpu_id
= (unsigned int)id
->driver_data
;
1045 pr_debug("probe for %s cpu_id %d\n", pdev
->name
, cpu_id
);
1046 if (!strcmp(pdev
->name
, DRIVER_NAME_MRST
))
1047 pr_debug("detected MRST\n");
1048 else if (!strcmp(pdev
->name
, DRIVER_NAME_MFLD
))
1049 pr_debug("detected MFLD\n");
1051 pr_err("detected unknown device abort!!\n");
1054 if ((cpu_id
< CPU_CHIP_LINCROFT
) || (cpu_id
> CPU_CHIP_PENWELL
)) {
1055 pr_err("detected unknown cpu_id abort!!\n");
1058 /* allocate memory for saving internal context and working */
1059 intelmaddata
= kzalloc(sizeof(*intelmaddata
), GFP_KERNEL
);
1060 if (!intelmaddata
) {
1061 pr_debug("mem alloctn fail\n");
1065 /* allocate memory for LPE API set */
1066 intelmaddata
->sstdrv_ops
= kzalloc(sizeof(struct intel_sst_card_ops
),
1068 if (!intelmaddata
->sstdrv_ops
) {
1069 pr_err("mem allocation for ops fail\n");
1070 kfree(intelmaddata
);
1074 intelmaddata
->cpu_id
= cpu_id
;
1075 /* create a card instance with ALSA framework */
1076 ret_val
= snd_card_create(card_index
, card_id
, THIS_MODULE
, 0, &card
);
1078 pr_err("snd_card_create fail\n");
1082 intelmaddata
->pdev
= pdev
;
1083 intelmaddata
->irq
= platform_get_irq(pdev
, 0);
1084 platform_set_drvdata(pdev
, intelmaddata
);
1085 intelmaddata
->card
= card
;
1086 intelmaddata
->card_id
= card_id
;
1087 intelmaddata
->card_index
= card_index
;
1088 intelmaddata
->master_mute
= UNMUTE
;
1089 intelmaddata
->playback_cnt
= intelmaddata
->capture_cnt
= 0;
1090 strncpy(card
->driver
, INTEL_MAD
, strlen(INTEL_MAD
));
1091 strncpy(card
->shortname
, INTEL_MAD
, strlen(INTEL_MAD
));
1093 intelmaddata
->sstdrv_ops
->module_name
= SST_CARD_NAMES
;
1094 /* registering with LPE driver to get access to SST APIs to use */
1095 ret_val
= snd_intelmad_sst_register(intelmaddata
);
1097 pr_err("snd_intelmad_sst_register failed\n");
1101 intelmaddata
->pmic_status
= PMIC_INIT
;
1103 ret_val
= snd_intelmad_pcm(card
, intelmaddata
);
1105 pr_err("snd_intelmad_pcm failed\n");
1109 ret_val
= snd_intelmad_mixer(intelmaddata
);
1111 pr_err("snd_intelmad_mixer failed\n");
1115 ret_val
= snd_intelmad_jack(intelmaddata
);
1117 pr_err("snd_intelmad_jack failed\n");
1121 /*create work queue for jack interrupt*/
1122 INIT_WORK(&intelmaddata
->mad_jack_msg
.wq
,
1123 sst_process_mad_jack_detection
);
1125 intelmaddata
->mad_jack_wq
= create_workqueue("sst_mad_jack_wq");
1126 if (!intelmaddata
->mad_jack_wq
)
1127 goto free_mad_jack_wq
;
1129 ret_val
= snd_intelmad_register_irq(intelmaddata
);
1131 pr_err("snd_intelmad_register_irq fail\n");
1135 /* internal function call to register device with ALSA */
1136 ret_val
= snd_intelmad_create(intelmaddata
, card
);
1138 pr_err("snd_intelmad_create failed\n");
1141 card
->private_data
= &intelmaddata
;
1142 snd_card_set_dev(card
, &pdev
->dev
);
1143 ret_val
= snd_card_register(card
);
1145 pr_err("snd_card_register failed\n");
1149 pr_debug("snd_intelmad_probe complete\n");
1153 destroy_workqueue(intelmaddata
->mad_jack_wq
);
1155 pr_err("probe failed\n");
1156 snd_card_free(card
);
1157 kfree(intelmaddata
->sstdrv_ops
);
1158 kfree(intelmaddata
);
1163 static int snd_intelmad_remove(struct platform_device
*pdev
)
1165 struct snd_intelmad
*intelmaddata
= platform_get_drvdata(pdev
);
1168 snd_card_free(intelmaddata
->card
);
1169 unregister_sst_card(intelmaddata
->sstdrv_ops
);
1170 /* free allocated memory for internal context */
1171 destroy_workqueue(intelmaddata
->mad_jack_wq
);
1172 kfree(intelmaddata
->sstdrv_ops
);
1173 kfree(intelmaddata
);
1178 /*********************************************************************
1179 * Driver initialization and exit
1180 *********************************************************************/
1181 static const struct platform_device_id snd_intelmad_ids
[] = {
1182 {DRIVER_NAME_MRST
, CPU_CHIP_LINCROFT
},
1183 {DRIVER_NAME_MFLD
, CPU_CHIP_PENWELL
},
1188 static struct platform_driver snd_intelmad_driver
= {
1190 .owner
= THIS_MODULE
,
1191 .name
= "intel_mid_sound_card",
1193 .id_table
= snd_intelmad_ids
,
1194 .probe
= snd_intelmad_probe
,
1195 .remove
= __devexit_p(snd_intelmad_remove
),
1199 * alsa_card_intelmad_init- driver init function
1201 * This function is called when driver module is inserted
1203 static int __init
alsa_card_intelmad_init(void)
1205 pr_debug("mad_init called\n");
1206 return platform_driver_register(&snd_intelmad_driver
);
1210 * alsa_card_intelmad_exit- driver exit function
1212 * This function is called when driver module is removed
1214 static void __exit
alsa_card_intelmad_exit(void)
1216 pr_debug("mad_exit called\n");
1217 return platform_driver_unregister(&snd_intelmad_driver
);
1220 module_init(alsa_card_intelmad_init
)
1221 module_exit(alsa_card_intelmad_exit
)