pcsp.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * PC-Speaker driver for Linux
  4. *
  5. * Copyright (C) 1993-1997 Michael Beck
  6. * Copyright (C) 1997-2001 David Woodhouse
  7. * Copyright (C) 2001-2008 Stas Sergeev
  8. */
  9. #ifndef __PCSP_H__
  10. #define __PCSP_H__
  11. #include <linux/hrtimer.h>
  12. #include <linux/i8253.h>
  13. #include <linux/timex.h>
  14. #define PCSP_SOUND_VERSION 0x400 /* read 4.00 */
  15. #define PCSP_DEBUG 0
  16. /* default timer freq for PC-Speaker: 18643 Hz */
  17. #define DIV_18KHZ 64
  18. #define MAX_DIV DIV_18KHZ
  19. #define CALC_DIV(d) (MAX_DIV >> (d))
  20. #define CUR_DIV() CALC_DIV(chip->treble)
  21. #define PCSP_MAX_TREBLE 1
  22. /* unfortunately, with hrtimers 37KHz does not work very well :( */
  23. #define PCSP_DEFAULT_TREBLE 0
  24. #define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
  25. /* wild guess */
  26. #define PCSP_MIN_LPJ 1000000
  27. #define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
  28. #define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
  29. #define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
  30. #define PCSP_CALC_RATE(i) (PIT_TICK_RATE / CALC_DIV(i))
  31. #define PCSP_RATE() PCSP_CALC_RATE(chip->treble)
  32. #define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
  33. #define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
  34. #define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
  35. #define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
  36. #define PCSP_CALC_NS(div) ({ \
  37. u64 __val = 1000000000ULL * (div); \
  38. do_div(__val, PIT_TICK_RATE); \
  39. __val; \
  40. })
  41. #define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
  42. #define PCSP_MAX_PERIOD_SIZE (64*1024)
  43. #define PCSP_MAX_PERIODS 512
  44. #define PCSP_BUFFER_SIZE (128*1024)
  45. struct snd_pcsp {
  46. struct snd_card *card;
  47. struct snd_pcm *pcm;
  48. struct input_dev *input_dev;
  49. struct hrtimer timer;
  50. unsigned short port, irq, dma;
  51. spinlock_t substream_lock;
  52. struct snd_pcm_substream *playback_substream;
  53. unsigned int fmt_size;
  54. unsigned int is_signed;
  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 void pcsp_sync_stop(struct snd_pcsp *chip);
  69. extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
  70. extern int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm);
  71. #endif