timer.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) by Lee Revell <rlrevell@joe-job.com>
  3. * Clemens Ladisch <clemens@ladisch.de>
  4. * Routines for control of EMU10K1 chips
  5. *
  6. * BUGS:
  7. * --
  8. *
  9. * TODO:
  10. * --
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #include <linux/time.h>
  28. #include <sound/core.h>
  29. #include <sound/emu10k1.h>
  30. static int snd_emu10k1_timer_start(struct snd_timer *timer)
  31. {
  32. struct snd_emu10k1 *emu;
  33. unsigned long flags;
  34. unsigned int delay;
  35. emu = snd_timer_chip(timer);
  36. delay = timer->sticks - 1;
  37. if (delay < 5 ) /* minimum time is 5 ticks */
  38. delay = 5;
  39. spin_lock_irqsave(&emu->reg_lock, flags);
  40. snd_emu10k1_intr_enable(emu, INTE_INTERVALTIMERENB);
  41. outw(delay & TIMER_RATE_MASK, emu->port + TIMER);
  42. spin_unlock_irqrestore(&emu->reg_lock, flags);
  43. return 0;
  44. }
  45. static int snd_emu10k1_timer_stop(struct snd_timer *timer)
  46. {
  47. struct snd_emu10k1 *emu;
  48. unsigned long flags;
  49. emu = snd_timer_chip(timer);
  50. spin_lock_irqsave(&emu->reg_lock, flags);
  51. snd_emu10k1_intr_disable(emu, INTE_INTERVALTIMERENB);
  52. spin_unlock_irqrestore(&emu->reg_lock, flags);
  53. return 0;
  54. }
  55. static int snd_emu10k1_timer_precise_resolution(struct snd_timer *timer,
  56. unsigned long *num, unsigned long *den)
  57. {
  58. *num = 1;
  59. *den = 48000;
  60. return 0;
  61. }
  62. static struct snd_timer_hardware snd_emu10k1_timer_hw = {
  63. .flags = SNDRV_TIMER_HW_AUTO,
  64. .resolution = 20833, /* 1 sample @ 48KHZ = 20.833...us */
  65. .ticks = 1024,
  66. .start = snd_emu10k1_timer_start,
  67. .stop = snd_emu10k1_timer_stop,
  68. .precise_resolution = snd_emu10k1_timer_precise_resolution,
  69. };
  70. int __devinit snd_emu10k1_timer(struct snd_emu10k1 *emu, int device)
  71. {
  72. struct snd_timer *timer = NULL;
  73. struct snd_timer_id tid;
  74. int err;
  75. tid.dev_class = SNDRV_TIMER_CLASS_CARD;
  76. tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
  77. tid.card = emu->card->number;
  78. tid.device = device;
  79. tid.subdevice = 0;
  80. if ((err = snd_timer_new(emu->card, "EMU10K1", &tid, &timer)) >= 0) {
  81. strcpy(timer->name, "EMU10K1 timer");
  82. timer->private_data = emu;
  83. timer->hw = snd_emu10k1_timer_hw;
  84. }
  85. emu->timer = timer;
  86. return err;
  87. }