pcsp.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * PC-Speaker driver for Linux
  3. *
  4. * Copyright (C) 1993-1997 Michael Beck
  5. * Copyright (C) 1997-2001 David Woodhouse
  6. * Copyright (C) 2001-2008 Stas Sergeev
  7. */
  8. #ifndef __PCSP_H__
  9. #define __PCSP_H__
  10. #include <linux/hrtimer.h>
  11. #if defined(CONFIG_MIPS) || defined(CONFIG_X86)
  12. /* Use the global PIT lock ! */
  13. #include <asm/i8253.h>
  14. #else
  15. #include <asm/8253pit.h>
  16. static DEFINE_SPINLOCK(i8253_lock);
  17. #endif
  18. #define PCSP_SOUND_VERSION 0x400 /* read 4.00 */
  19. #define PCSP_DEBUG 0
  20. /* default timer freq for PC-Speaker: 18643 Hz */
  21. #define DIV_18KHZ 64
  22. #define MAX_DIV DIV_18KHZ
  23. #define CALC_DIV(d) (MAX_DIV >> (d))
  24. #define CUR_DIV() CALC_DIV(chip->treble)
  25. #define PCSP_MAX_TREBLE 1
  26. /* unfortunately, with hrtimers 37KHz does not work very well :( */
  27. #define PCSP_DEFAULT_TREBLE 0
  28. #define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
  29. /* wild guess */
  30. #define PCSP_MIN_LPJ 1000000
  31. #define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
  32. #define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
  33. #define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
  34. #define PCSP_CALC_RATE(i) (PIT_TICK_RATE / CALC_DIV(i))
  35. #define PCSP_RATE() PCSP_CALC_RATE(chip->treble)
  36. #define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
  37. #define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
  38. #define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
  39. #define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
  40. #define PCSP_CALC_NS(div) ({ \
  41. u64 __val = 1000000000ULL * (div); \
  42. do_div(__val, PIT_TICK_RATE); \
  43. __val; \
  44. })
  45. #define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
  46. #define PCSP_MAX_PERIOD_SIZE (64*1024)
  47. #define PCSP_MAX_PERIODS 512
  48. #define PCSP_BUFFER_SIZE (128*1024)
  49. struct snd_pcsp {
  50. struct snd_card *card;
  51. struct snd_pcm *pcm;
  52. struct input_dev *input_dev;
  53. struct hrtimer timer;
  54. unsigned short port, irq, dma;
  55. spinlock_t substream_lock;
  56. struct snd_pcm_substream *playback_substream;
  57. size_t playback_ptr;
  58. size_t period_ptr;
  59. atomic_t timer_active;
  60. int thalf;
  61. u64 ns_rem;
  62. unsigned char val61;
  63. int enable;
  64. int max_treble;
  65. int treble;
  66. int pcspkr;
  67. };
  68. extern struct snd_pcsp pcsp_chip;
  69. extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
  70. extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
  71. extern int snd_pcsp_new_mixer(struct snd_pcsp *chip);
  72. #endif