cs5535audio_olpc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /* OLPC has an additional feature on top of regular AD1888 codec
  9. features. This is support for an analog input mode. This is a
  10. 2 step process. First, to turn off the AD1888 codec bias voltage
  11. and high pass filter. Second, to tell the embedded controller to
  12. reroute from a capacitive trace to a direct trace using an analog
  13. switch. The *_ec()s are what talk to that controller */
  14. static int snd_cs5535audio_ctl_info(struct snd_kcontrol *kcontrol,
  15. struct snd_ctl_elem_info *uinfo)
  16. {
  17. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  18. uinfo->count = 1;
  19. uinfo->value.integer.min = 0;
  20. uinfo->value.integer.max = 1;
  21. return 0;
  22. }
  23. #define AD1888_VREFOUT_EN_BIT (1 << 2)
  24. #define AD1888_HPF_EN_BIT (1 << 12)
  25. static int snd_cs5535audio_ctl_get(struct snd_kcontrol *kcontrol,
  26. struct snd_ctl_elem_value *ucontrol)
  27. {
  28. struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
  29. u8 val;
  30. val = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2);
  31. val >>= AC97_AD_HPFD_SHIFT;
  32. ucontrol->value.integer.value[0] = val & 0x1;
  33. return 0;
  34. }
  35. static int snd_cs5535audio_ctl_put(struct snd_kcontrol *kcontrol,
  36. struct snd_ctl_elem_value *ucontrol)
  37. {
  38. int err;
  39. struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
  40. u8 value;
  41. struct snd_ac97 *ac97 = cs5535au->ac97;
  42. /* value is 1 if analog input is desired */
  43. value = ucontrol->value.integer.value[0];
  44. /* turns off High Pass Filter if 1 */
  45. if (value)
  46. err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
  47. AD1888_HPF_EN_BIT, AD1888_HPF_EN_BIT);
  48. else
  49. err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
  50. AD1888_HPF_EN_BIT, 0);
  51. if (err < 0)
  52. snd_printk(KERN_ERR "Error updating AD_TEST2 %d\n", err);
  53. /* B2 and newer writes directly to a GPIO pin */
  54. if (value)
  55. geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
  56. else
  57. geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
  58. return 1;
  59. }
  60. static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
  61. {
  62. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  63. .name = "Analog Input Switch",
  64. .info = snd_cs5535audio_ctl_info,
  65. .get = snd_cs5535audio_ctl_get,
  66. .put = snd_cs5535audio_ctl_put,
  67. .private_value = 0
  68. };
  69. void __devinit olpc_prequirks(struct snd_card *card,
  70. struct snd_ac97_template *ac97)
  71. {
  72. if (!machine_is_olpc())
  73. return;
  74. /* invert EAPD if on an OLPC B3 or higher */
  75. if (olpc_board_at_least(olpc_board_pre(0xb3)))
  76. ac97->scaps |= AC97_SCAP_INV_EAPD;
  77. }
  78. int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
  79. {
  80. if (!machine_is_olpc())
  81. return 0;
  82. /* setup callback for mixer control that does analog input mode */
  83. return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
  84. ac97->private_data));
  85. }