cs5535audio_olpc.c 4.5 KB

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