pcsp.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 CUR_DIV() (MAX_DIV >> chip->treble)
  24. #define PCSP_MAX_TREBLE 1
  25. /* unfortunately, with hrtimers 37KHz does not work very well :( */
  26. #define PCSP_DEFAULT_TREBLE 0
  27. #define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
  28. /* wild guess */
  29. #define PCSP_MIN_LPJ 1000000
  30. #define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
  31. #define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
  32. #define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
  33. #define PCSP_RATE() (PIT_TICK_RATE / CUR_DIV())
  34. #define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
  35. #define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
  36. #define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
  37. #define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
  38. #define PCSP_CALC_NS(div) ({ \
  39. u64 __val = 1000000000ULL * (div); \
  40. do_div(__val, PIT_TICK_RATE); \
  41. __val; \
  42. })
  43. #define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
  44. #define PCSP_MAX_PERIOD_SIZE (64*1024)
  45. #define PCSP_MAX_PERIODS 512
  46. #define PCSP_BUFFER_SIZE (128*1024)
  47. struct snd_pcsp {
  48. struct snd_card *card;
  49. struct snd_pcm *pcm;
  50. struct input_dev *input_dev;
  51. struct hrtimer timer;
  52. unsigned short port, irq, dma;
  53. spinlock_t substream_lock;
  54. struct snd_pcm_substream *playback_substream;
  55. size_t playback_ptr;
  56. size_t period_ptr;
  57. atomic_t timer_active;
  58. int thalf;
  59. u64 ns_rem;
  60. unsigned char val61;
  61. int enable;
  62. int max_treble;
  63. int treble;
  64. int pcspkr;
  65. };
  66. extern struct snd_pcsp pcsp_chip;
  67. extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
  68. extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
  69. extern int snd_pcsp_new_mixer(struct snd_pcsp *chip);
  70. #endif