Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | /*
* intelmid_ctrl.c - Intel Sound card driver for MID
*
* Copyright (C) 2008-10 Intel Corp
* Authors: Harsha Priya <priya.harsha@intel.com>
* Vinod Koul <vinod.koul@intel.com>
* Dharageswari R <dharageswari.r@intel.com>
* KP Jeeja <jeeja.kp@intel.com>
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ALSA driver handling mixer controls for Intel MAD chipset
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <sound/core.h>
#include <sound/control.h>
#include "jack.h"
#include "intel_sst.h"
#include "intel_sst_ioctl.h"
#include "intelmid_snd_control.h"
#include "intelmid.h"
static char *out_names_mrst[] = {"Headphones",
"Internal speakers"};
static char *in_names_mrst[] = {"AMIC",
"DMIC",
"HS_MIC"};
static char *out_names_mfld[] = {"Headset ",
"EarPiece "};
static char *in_names_mfld[] = {"AMIC",
"DMIC"};
struct snd_control_val intelmad_ctrl_val[MAX_VENDORS] = {
{
.playback_vol_max = 63,
.playback_vol_min = 0,
.capture_vol_max = 63,
.capture_vol_min = 0,
},
{
.playback_vol_max = 0,
.playback_vol_min = -31,
.capture_vol_max = 0,
.capture_vol_min = -20,
},
{
.playback_vol_max = 0,
.playback_vol_min = -126,
.capture_vol_max = 0,
.capture_vol_min = -31,
},
};
/* control path functionalities */
static inline int snd_intelmad_volume_info(struct snd_ctl_elem_info *uinfo,
int control_type, int max, int min)
{
WARN_ON(!uinfo);
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = control_type;
uinfo->value.integer.min = min;
uinfo->value.integer.max = max;
return 0;
}
/**
* snd_intelmad_mute_info - provides information about the mute controls
*
* @kcontrol: pointer to the control
* @uinfo: pointer to the structure where the control's info need
* to be filled
*
* This function is called when a mixer application requests for control's info
*/
static int snd_intelmad_mute_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
WARN_ON(!uinfo);
WARN_ON(!kcontrol);
/* set up the mute as a boolean mono control with min-max values */
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
uinfo->count = MONO_CNTL;
uinfo->value.integer.min = MIN_MUTE;
uinfo->value.integer.max = MAX_MUTE;
return 0;
}
/**
* snd_intelmad_capture_volume_info - provides info about the volume control
*
* @kcontrol: pointer to the control
* @uinfo: pointer to the structure where the control's info need
* to be filled
*
* This function is called when a mixer application requests for control's info
*/
static int snd_intelmad_capture_volume_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
snd_intelmad_volume_info(uinfo, MONO_CNTL,
intelmad_ctrl_val[sst_card_vendor_id].capture_vol_max,
intelmad_ctrl_val[sst_card_vendor_id].capture_vol_min);
return 0;
}
/**
* snd_intelmad_playback_volume_info - provides info about the volume control
*
* @kcontrol: pointer to the control
* @uinfo: pointer to the structure where the control's info need
* to be filled
*
* This function is called when a mixer application requests for control's info
*/
static int snd_intelmad_playback_volume_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
snd_intelmad_volume_info(uinfo, STEREO_CNTL,
intelmad_ctrl_val[sst_card_vendor_id].playback_vol_max,
intelmad_ctrl_val[sst_card_vendor_id].playback_vol_min);
return 0;
}
/**
* snd_intelmad_device_info_mrst - provides information about the devices available
*
* @kcontrol: pointer to the control
* @uinfo: pointer to the structure where the devices's info need
* to be filled
*
* This function is called when a mixer application requests for device's info
*/
static int snd_intelmad_device_info_mrst(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
WARN_ON(!kcontrol);
WARN_ON(!uinfo);
/* setup device select as drop down controls with different values */
if (kcontrol->id.numid == OUTPUT_SEL)
uinfo->value.enumerated.items = ARRAY_SIZE(out_names_mrst);
else
uinfo->value.enumerated.items = ARRAY_SIZE(in_names_mrst);
uinfo->count = MONO_CNTL;
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
uinfo->value.enumerated.item = 1;
if (kcontrol->id.numid == OUTPUT_SEL)
strncpy(uinfo->value.enumerated.name,
out_names_mrst[uinfo->value.enumerated.item],
sizeof(uinfo->value.enumerated.name)-1);
else
strncpy(uinfo->value.enumerated.name,
in_names_mrst[uinfo->value.enumerated.item],
sizeof(uinfo->value.enumerated.name)-1);
return 0;
}
static int snd_intelmad_device_info_mfld(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
WARN_ON(!kcontrol);
WARN_ON(!uinfo);
/* setup device select as drop down controls with different values */
if (kcontrol->id.numid == OUTPUT_SEL)
uinfo->value.enumerated.items = ARRAY_SIZE(out_names_mfld);
else
uinfo->value.enumerated.items = ARRAY_SIZE(in_names_mfld);
uinfo->count = MONO_CNTL;
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
uinfo->value.enumerated.item = 1;
if (kcontrol->id.numid == OUTPUT_SEL)
strncpy(uinfo->value.enumerated.name,
out_names_mfld[uinfo->value.enumerated.item],
sizeof(uinfo->value.enumerated.name)-1);
else
strncpy(uinfo->value.enumerated.name,
in_names_mfld[uinfo->value.enumerated.item],
sizeof(uinfo->value.enumerated.name)-1);
return 0;
}
/**
* snd_intelmad_volume_get - gets the current volume for the control
*
* @kcontrol: pointer to the control
* @uval: pointer to the structure where the control's info need
* to be filled
*
* This function is called when .get function of a control is invoked from app
*/
static int snd_intelmad_volume_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *uval)
{
int ret_val = 0, cntl_list[2] = {0,};
int value = 0;
struct snd_intelmad *intelmaddata;
struct snd_pmic_ops *scard_ops;
pr_debug("snd_intelmad_volume_get called\n");
WARN_ON(!uval);
WARN_ON(!kcontrol);
intelmaddata = kcontrol->private_data;
WARN_ON(!intelmaddata->sstdrv_ops);
scard_ops = intelmaddata->sstdrv_ops->scard_ops;
WARN_ON(!scard_ops);
switch (kcontrol->id.numid) {
case PLAYBACK_VOL:
cntl_list[0] = PMIC_SND_RIGHT_PB_VOL;
cntl_list[1] = PMIC_SND_LEFT_PB_VOL;
break;
case CAPTURE_VOL:
cntl_list[0] = PMIC_SND_CAPTURE_VOL;
break;
default:
return -EINVAL;
}
ret_val = scard_ops->get_vol(cntl_list[0], &value);
uval->value.integer.value[0] = value;
if (ret_val)
return ret_val;
if (kcontrol->id.numid == PLAYBACK_VOL) {
ret_val = scard_ops->get_vol(cntl_list[1], &value);
uval->value.integer.value[1] = value;
}
return ret_val;
}
/**
* snd_intelmad_mute_get - gets the current mute status for the control
*
* @kcontrol: pointer to the control
* @uval: pointer to the structure where the control's info need
* to be filled
*
* This function is called when .get function of a control is invoked from app
*/
static int snd_intelmad_mute_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *uval)
{
int cntl_list = 0, ret_val = 0;
u8 value = 0;
struct snd_intelmad *intelmaddata;
struct snd_pmic_ops *scard_ops;
pr_debug("Mute_get called\n");
WARN_ON(!uval);
WARN_ON(!kcontrol);
intelmaddata = kcontrol->private_data;
WARN_ON(!intelmaddata->sstdrv_ops);
scard_ops = intelmaddata->sstdrv_ops->scard_ops;
WARN_ON(!scard_ops);
switch (kcontrol->id.numid) {
case PLAYBACK_MUTE:
if (intelmaddata->output_sel == STEREO_HEADPHONE)
cntl_list = PMIC_SND_LEFT_HP_MUTE;
else if ((intelmaddata->output_sel == INTERNAL_SPKR) ||
(intelmaddata->output_sel == MONO_EARPIECE))
cntl_list = PMIC_SND_LEFT_SPEAKER_MUTE;
break;
case CAPTURE_MUTE:
if (intelmaddata->input_sel == DMIC)
cntl_list = PMIC_SND_DMIC_MUTE;
else if (intelmaddata->input_sel == AMIC)
cntl_list = PMIC_SND_AMIC_MUTE;
else if (intelmaddata->input_sel == HS_MIC)
cntl_list = PMIC_SND_HP_MIC_MUTE;
break;
case MASTER_MUTE:
uval->value.integer.value[0] = intelmaddata->master_mute;
return 0;
default:
return -EINVAL;
}
ret_val = scard_ops->get_mute(cntl_list, &value);
uval->value.integer.value[0] = value;
return ret_val;
}
/**
* snd_intelmad_volume_set - sets the volume control's info
*
* @kcontrol: pointer to the control
* @uval: pointer to the structure where the control's info is
* available to be set
*
* This function is called when .set function of a control is invoked from app
*/
static int snd_intelmad_volume_set(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *uval)
{
int ret_val, cntl_list[2] = {0,};
struct snd_intelmad *intelmaddata;
struct snd_pmic_ops *scard_ops;
pr_debug("volume set called:%ld %ld\n",
uval->value.integer.value[0],
uval->value.integer.value[1]);
WARN_ON(!uval);
WARN_ON(!kcontrol);
intelmaddata = kcontrol->private_data;
WARN_ON(!intelmaddata->sstdrv_ops);
scard_ops = intelmaddata->sstdrv_ops->scard_ops;
WARN_ON(!scard_ops);
switch (kcontrol->id.numid) {
case PLAYBACK_VOL:
cntl_list[0] = PMIC_SND_LEFT_PB_VOL;
cntl_list[1] = PMIC_SND_RIGHT_PB_VOL;
break;
case CAPTURE_VOL:
cntl_list[0] = PMIC_SND_CAPTURE_VOL;
break;
default:
return -EINVAL;
}
ret_val = scard_ops->set_vol(cntl_list[0],
uval->value.integer.value[0]);
if (ret_val)
return ret_val;
if (kcontrol->id.numid == PLAYBACK_VOL)
ret_val = scard_ops->set_vol(cntl_list[1],
uval->value.integer.value[1]);
return ret_val;
}
/**
* snd_intelmad_mute_set - sets the mute control's info
*
* @kcontrol: pointer to the control
* @uval: pointer to the structure where the control's info is
* available to be set
*
* This function is called when .set function of a control is invoked from app
*/
static int snd_intelmad_mute_set(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *uval)
{
int cntl_list[2] = {0,}, ret_val;
struct snd_intelmad *intelmaddata;
struct snd_pmic_ops *scard_ops;
pr_debug("snd_intelmad_mute_set called\n");
WARN_ON(!uval);
WARN_ON(!kcontrol);
intelmaddata = kcontrol->private_data;
WARN_ON(!intelmaddata->sstdrv_ops);
scard_ops = intelmaddata->sstdrv_ops->scard_ops;
WARN_ON(!scard_ops);
kcontrol->private_value = uval->value.integer.value[0];
switch (kcontrol->id.numid) {
case PLAYBACK_MUTE:
if (intelmaddata->output_sel == STEREO_HEADPHONE) {
cntl_list[0] = PMIC_SND_LEFT_HP_MUTE;
cntl_list[1] = PMIC_SND_RIGHT_HP_MUTE;
} else if ((intelmaddata->output_sel == INTERNAL_SPKR) ||
(intelmaddata->output_sel == MONO_EARPIECE)) {
cntl_list[0] = PMIC_SND_LEFT_SPEAKER_MUTE;
cntl_list[1] = PMIC_SND_RIGHT_SPEAKER_MUTE;
}
break;
case CAPTURE_MUTE:/*based on sel device mute the i/p dev*/
if (intelmaddata->input_sel == DMIC)
cntl_list[0] = PMIC_SND_DMIC_MUTE;
else if (intelmaddata->input_sel == AMIC)
cntl_list[0] = PMIC_SND_AMIC_MUTE;
else if (intelmaddata->input_sel == HS_MIC)
cntl_list[0] = PMIC_SND_HP_MIC_MUTE;
break;
case MASTER_MUTE:
cntl_list[0] = PMIC_SND_MUTE_ALL;
intelmaddata->master_mute = uval->value.integer.value[0];
break;
default:
return -EINVAL;
}
ret_val = scard_ops->set_mute(cntl_list[0],
uval->value.integer.value[0]);
if (ret_val)
return ret_val;
if (kcontrol->id.numid == PLAYBACK_MUTE)
ret_val = scard_ops->set_mute(cntl_list[1],
uval->value.integer.value[0]);
return ret_val;
}
/**
* snd_intelmad_device_get - get the device select control's info
*
* @kcontrol: pointer to the control
* @uval: pointer to the structure where the control's info is
* to be filled
*
* This function is called when .get function of a control is invoked from app
*/
static int snd_intelmad_device_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *uval)
{
struct snd_intelmad *intelmaddata;
struct snd_pmic_ops *scard_ops;
pr_debug("device_get called\n");
WARN_ON(!uval);
WARN_ON(!kcontrol);
intelmaddata = kcontrol->private_data;
if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) {
scard_ops = intelmaddata->sstdrv_ops->scard_ops;
if (kcontrol->id.numid == OUTPUT_SEL)
uval->value.enumerated.item[0] =
scard_ops->output_dev_id;
else if (kcontrol->id.numid == INPUT_SEL)
uval->value.enumerated.item[0] =
scard_ops->input_dev_id;
else
return -EINVAL;
} else
uval->value.enumerated.item[0] = kcontrol->private_value;
return 0;
}
/**
* snd_intelmad_device_set - set the device select control's info
*
* @kcontrol: pointer to the control
* @uval: pointer to the structure where the control's info is
* available to be set
*
* This function is called when .set function of a control is invoked from app
*/
static int snd_intelmad_device_set(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *uval)
{
struct snd_intelmad *intelmaddata;
struct snd_pmic_ops *scard_ops;
int ret_val = 0, vendor, status;
struct intel_sst_pcm_control *pcm_control;
pr_debug("snd_intelmad_device_set called\n");
WARN_ON(!uval);
WARN_ON(!kcontrol);
status = -1;
intelmaddata = kcontrol->private_data;
WARN_ON(!intelmaddata->sstdrv_ops);
scard_ops = intelmaddata->sstdrv_ops->scard_ops;
WARN_ON(!scard_ops);
/* store value with driver */
kcontrol->private_value = uval->value.enumerated.item[0];
switch (kcontrol->id.numid) {
case OUTPUT_SEL:
ret_val = scard_ops->set_output_dev(
uval->value.enumerated.item[0]);
intelmaddata->output_sel = uval->value.enumerated.item[0];
break;
case INPUT_SEL:
vendor = intelmaddata->sstdrv_ops->vendor_id;
if ((vendor == SND_MX) || (vendor == SND_FS)) {
pcm_control = intelmaddata->sstdrv_ops->pcm_control;
if (uval->value.enumerated.item[0] == HS_MIC)
status = 1;
else
status = 0;
pcm_control->device_control(
SST_ENABLE_RX_TIME_SLOT, &status);
}
ret_val = scard_ops->set_input_dev(
uval->value.enumerated.item[0]);
intelmaddata->input_sel = uval->value.enumerated.item[0];
break;
default:
return -EINVAL;
}
kcontrol->private_value = uval->value.enumerated.item[0];
return ret_val;
}
struct snd_kcontrol_new snd_intelmad_controls_mrst[MAX_CTRL] __devinitdata = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Playback Source",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_device_info_mrst,
.get = snd_intelmad_device_get,
.put = snd_intelmad_device_set,
.private_value = 0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Capture Source",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_device_info_mrst,
.get = snd_intelmad_device_get,
.put = snd_intelmad_device_set,
.private_value = 0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Playback Volume",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_playback_volume_info,
.get = snd_intelmad_volume_get,
.put = snd_intelmad_volume_set,
.private_value = 0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Playback Switch",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_mute_info,
.get = snd_intelmad_mute_get,
.put = snd_intelmad_mute_set,
.private_value = 0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Capture Volume",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_capture_volume_info,
.get = snd_intelmad_volume_get,
.put = snd_intelmad_volume_set,
.private_value = 0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Capture Switch",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_mute_info,
.get = snd_intelmad_mute_get,
.put = snd_intelmad_mute_set,
.private_value = 0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "Master Playback Switch",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_mute_info,
.get = snd_intelmad_mute_get,
.put = snd_intelmad_mute_set,
.private_value = 0,
},
};
struct snd_kcontrol_new
snd_intelmad_controls_mfld[MAX_CTRL_MFLD] __devinitdata = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Playback Source",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_device_info_mfld,
.get = snd_intelmad_device_get,
.put = snd_intelmad_device_set,
.private_value = 0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Capture Source",
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.info = snd_intelmad_device_info_mfld,
.get = snd_intelmad_device_get,
.put = snd_intelmad_device_set,
.private_value = 0,
},
};
|