cs5535audio_olpc.c 2.5 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. /*
  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. static int olpc_dc_info(struct snd_kcontrol *kctl,
  30. struct snd_ctl_elem_info *uinfo)
  31. {
  32. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  33. uinfo->count = 1;
  34. uinfo->value.integer.min = 0;
  35. uinfo->value.integer.max = 1;
  36. return 0;
  37. }
  38. static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
  39. {
  40. struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
  41. u8 val;
  42. val = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2);
  43. val >>= AC97_AD_HPFD_SHIFT;
  44. v->value.integer.value[0] = val & 0x1;
  45. return 0;
  46. }
  47. static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
  48. {
  49. struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
  50. olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]);
  51. return 1;
  52. }
  53. static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
  54. {
  55. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  56. .name = "DC Mode Enable",
  57. .info = olpc_dc_info,
  58. .get = olpc_dc_get,
  59. .put = olpc_dc_put,
  60. .private_value = 0
  61. };
  62. void __devinit olpc_prequirks(struct snd_card *card,
  63. struct snd_ac97_template *ac97)
  64. {
  65. if (!machine_is_olpc())
  66. return;
  67. /* invert EAPD if on an OLPC B3 or higher */
  68. if (olpc_board_at_least(olpc_board_pre(0xb3)))
  69. ac97->scaps |= AC97_SCAP_INV_EAPD;
  70. }
  71. int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
  72. {
  73. struct snd_ctl_elem_id elem;
  74. if (!machine_is_olpc())
  75. return 0;
  76. /* drop the original AD1888 HPF control */
  77. memset(&elem, 0, sizeof(elem));
  78. elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  79. strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name));
  80. snd_ctl_remove_id(card, &elem);
  81. /* add the override for OLPC's HPF */
  82. return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
  83. ac97->private_data));
  84. }