cs5535audio_olpc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include <sound/driver.h>
  2. #include <sound/core.h>
  3. #include <sound/info.h>
  4. #include <sound/control.h>
  5. #include <sound/ac97_codec.h>
  6. #include <asm/olpc.h>
  7. #include "cs5535audio.h"
  8. /*
  9. * OLPC has an additional feature on top of the regular AD1888 codec features.
  10. * It has an Analog Input mode that is switched into (after disabling the
  11. * High Pass Filter) via GPIO. It is supported on B2 and later models.
  12. */
  13. void olpc_analog_input(struct snd_ac97 *ac97, int on)
  14. {
  15. int err;
  16. /* update the High Pass Filter (via AC97_AD_TEST2) */
  17. err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
  18. 1 << AC97_AD_HPFD_SHIFT, on << AC97_AD_HPFD_SHIFT);
  19. if (err < 0) {
  20. snd_printk(KERN_ERR "setting High Pass Filter - %d\n", err);
  21. return;
  22. }
  23. /* set Analog Input through GPIO */
  24. if (on)
  25. geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
  26. else
  27. geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
  28. }
  29. /*
  30. * OLPC XO-1's V_REFOUT is a mic bias enable.
  31. */
  32. void olpc_mic_bias(struct snd_ac97 *ac97, int on)
  33. {
  34. int err;
  35. on = on ? 0 : 1;
  36. err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
  37. 1 << AC97_AD_VREFD_SHIFT, on << AC97_AD_VREFD_SHIFT);
  38. if (err < 0)
  39. snd_printk(KERN_ERR "setting MIC Bias - %d\n", err);
  40. }
  41. static int olpc_dc_info(struct snd_kcontrol *kctl,
  42. struct snd_ctl_elem_info *uinfo)
  43. {
  44. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  45. uinfo->count = 1;
  46. uinfo->value.integer.min = 0;
  47. uinfo->value.integer.max = 1;
  48. return 0;
  49. }
  50. static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
  51. {
  52. v->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC,
  53. GPIO_OUTPUT_VAL);
  54. return 0;
  55. }
  56. static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
  57. {
  58. struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
  59. olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]);
  60. return 1;
  61. }
  62. static int olpc_mic_info(struct snd_kcontrol *kctl,
  63. struct snd_ctl_elem_info *uinfo)
  64. {
  65. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  66. uinfo->count = 1;
  67. uinfo->value.integer.min = 0;
  68. uinfo->value.integer.max = 1;
  69. return 0;
  70. }
  71. static int olpc_mic_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
  72. {
  73. struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
  74. struct snd_ac97 *ac97 = cs5535au->ac97;
  75. int i;
  76. i = (snd_ac97_read(ac97, AC97_AD_MISC) >> AC97_AD_VREFD_SHIFT) & 0x1;
  77. v->value.integer.value[0] = i ? 0 : 1;
  78. return 0;
  79. }
  80. static int olpc_mic_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
  81. {
  82. struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
  83. olpc_mic_bias(cs5535au->ac97, v->value.integer.value[0]);
  84. return 1;
  85. }
  86. static struct snd_kcontrol_new olpc_cs5535audio_ctls[] __devinitdata = {
  87. {
  88. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  89. .name = "DC Mode Enable",
  90. .info = olpc_dc_info,
  91. .get = olpc_dc_get,
  92. .put = olpc_dc_put,
  93. .private_value = 0
  94. },
  95. {
  96. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  97. .name = "MIC Bias Enable",
  98. .info = olpc_mic_info,
  99. .get = olpc_mic_get,
  100. .put = olpc_mic_put,
  101. .private_value = 0,
  102. },
  103. };
  104. void __devinit olpc_prequirks(struct snd_card *card,
  105. struct snd_ac97_template *ac97)
  106. {
  107. if (!machine_is_olpc())
  108. return;
  109. /* invert EAPD if on an OLPC B3 or higher */
  110. if (olpc_board_at_least(olpc_board_pre(0xb3)))
  111. ac97->scaps |= AC97_SCAP_INV_EAPD;
  112. }
  113. int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
  114. {
  115. struct snd_ctl_elem_id elem;
  116. int i, err;
  117. if (!machine_is_olpc())
  118. return 0;
  119. /* drop the original AD1888 HPF control */
  120. memset(&elem, 0, sizeof(elem));
  121. elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  122. strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name));
  123. snd_ctl_remove_id(card, &elem);
  124. /* drop the original V_REFOUT control */
  125. memset(&elem, 0, sizeof(elem));
  126. elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  127. strncpy(elem.name, "V_REFOUT Enable", sizeof(elem.name));
  128. snd_ctl_remove_id(card, &elem);
  129. /* add the OLPC-specific controls */
  130. for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) {
  131. err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i],
  132. ac97->private_data));
  133. if (err < 0)
  134. return err;
  135. }
  136. /* turn off the mic by default */
  137. olpc_mic_bias(ac97, 0);
  138. return 0;
  139. }