dmasound.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _dmasound_h_
  3. /*
  4. * linux/sound/oss/dmasound/dmasound.h
  5. *
  6. *
  7. * Minor numbers for the sound driver.
  8. *
  9. * Unfortunately Creative called the codec chip of SB as a DSP. For this
  10. * reason the /dev/dsp is reserved for digitized audio use. There is a
  11. * device for true DSP processors but it will be called something else.
  12. * In v3.0 it's /dev/sndproc but this could be a temporary solution.
  13. */
  14. #define _dmasound_h_
  15. #include <linux/types.h>
  16. #define SND_NDEVS 256 /* Number of supported devices */
  17. #define SND_DEV_CTL 0 /* Control port /dev/mixer */
  18. #define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM
  19. synthesizer and MIDI output) */
  20. #define SND_DEV_MIDIN 2 /* Raw midi access */
  21. #define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */
  22. #define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */
  23. #define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */
  24. #define SND_DEV_STATUS 6 /* /dev/sndstat */
  25. /* #7 not in use now. Was in 2.4. Free for use after v3.0. */
  26. #define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */
  27. #define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */
  28. #define SND_DEV_PSS SND_DEV_SNDPROC
  29. /* switch on various prinks */
  30. #define DEBUG_DMASOUND 1
  31. #define MAX_AUDIO_DEV 5
  32. #define MAX_MIXER_DEV 4
  33. #define MAX_SYNTH_DEV 3
  34. #define MAX_MIDI_DEV 6
  35. #define MAX_TIMER_DEV 3
  36. #define MAX_CATCH_RADIUS 10
  37. #define le2be16(x) (((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
  38. #define le2be16dbl(x) (((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
  39. #define IOCTL_IN(arg, ret) \
  40. do { int error = get_user(ret, (int __user *)(arg)); \
  41. if (error) return error; \
  42. } while (0)
  43. #define IOCTL_OUT(arg, ret) ioctl_return((int __user *)(arg), ret)
  44. static inline int ioctl_return(int __user *addr, int value)
  45. {
  46. return value < 0 ? value : put_user(value, addr);
  47. }
  48. /*
  49. * Configuration
  50. */
  51. #undef HAS_8BIT_TABLES
  52. #if defined(CONFIG_DMASOUND_ATARI) || defined(CONFIG_DMASOUND_ATARI_MODULE) ||\
  53. defined(CONFIG_DMASOUND_PAULA) || defined(CONFIG_DMASOUND_PAULA_MODULE) ||\
  54. defined(CONFIG_DMASOUND_Q40) || defined(CONFIG_DMASOUND_Q40_MODULE)
  55. #define HAS_8BIT_TABLES
  56. #define MIN_BUFFERS 4
  57. #define MIN_BUFSIZE (1<<12) /* in bytes (- where does this come from ?) */
  58. #define MIN_FRAG_SIZE 8 /* not 100% sure about this */
  59. #define MAX_BUFSIZE (1<<17) /* Limit for Amiga is 128 kb */
  60. #define MAX_FRAG_SIZE 15 /* allow *4 for mono-8 => stereo-16 (for multi) */
  61. #else /* is pmac and multi is off */
  62. #define MIN_BUFFERS 2
  63. #define MIN_BUFSIZE (1<<8) /* in bytes */
  64. #define MIN_FRAG_SIZE 8
  65. #define MAX_BUFSIZE (1<<18) /* this is somewhat arbitrary for pmac */
  66. #define MAX_FRAG_SIZE 16 /* need to allow *4 for mono-8 => stereo-16 */
  67. #endif
  68. #define DEFAULT_N_BUFFERS 4
  69. #define DEFAULT_BUFF_SIZE (1<<15)
  70. /*
  71. * Initialization
  72. */
  73. extern int dmasound_init(void);
  74. extern void dmasound_deinit(void);
  75. /* description of the set-up applies to either hard or soft settings */
  76. typedef struct {
  77. int format; /* AFMT_* */
  78. int stereo; /* 0 = mono, 1 = stereo */
  79. int size; /* 8/16 bit*/
  80. int speed; /* speed */
  81. } SETTINGS;
  82. /*
  83. * Machine definitions
  84. */
  85. typedef struct {
  86. const char *name;
  87. const char *name2;
  88. struct module *owner;
  89. void *(*dma_alloc)(unsigned int, gfp_t);
  90. void (*dma_free)(void *, unsigned int);
  91. int (*irqinit)(void);
  92. void (*irqcleanup)(void);
  93. void (*init)(void);
  94. void (*silence)(void);
  95. int (*setFormat)(int);
  96. int (*setVolume)(int);
  97. int (*setBass)(int);
  98. int (*setTreble)(int);
  99. int (*setGain)(int);
  100. void (*play)(void);
  101. void (*record)(void); /* optional */
  102. void (*mixer_init)(void); /* optional */
  103. int (*mixer_ioctl)(u_int, u_long); /* optional */
  104. int (*write_sq_setup)(void); /* optional */
  105. int (*read_sq_setup)(void); /* optional */
  106. int (*sq_open)(fmode_t); /* optional */
  107. int (*state_info)(char *, size_t); /* optional */
  108. void (*abort_read)(void); /* optional */
  109. int min_dsp_speed;
  110. int max_dsp_speed;
  111. int version ;
  112. int hardware_afmts ; /* OSS says we only return h'ware info */
  113. /* when queried via SNDCTL_DSP_GETFMTS */
  114. int capabilities ; /* low-level reply to SNDCTL_DSP_GETCAPS */
  115. SETTINGS default_hard ; /* open() or init() should set something valid */
  116. SETTINGS default_soft ; /* you can make it look like old OSS, if you want to */
  117. } MACHINE;
  118. /*
  119. * Low level stuff
  120. */
  121. typedef struct {
  122. ssize_t (*ct_ulaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  123. ssize_t (*ct_alaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  124. ssize_t (*ct_s8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  125. ssize_t (*ct_u8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  126. ssize_t (*ct_s16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  127. ssize_t (*ct_u16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  128. ssize_t (*ct_s16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  129. ssize_t (*ct_u16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  130. } TRANS;
  131. struct sound_settings {
  132. MACHINE mach; /* machine dependent things */
  133. SETTINGS hard; /* hardware settings */
  134. SETTINGS soft; /* software settings */
  135. SETTINGS dsp; /* /dev/dsp default settings */
  136. TRANS *trans_write; /* supported translations */
  137. int volume_left; /* volume (range is machine dependent) */
  138. int volume_right;
  139. int bass; /* tone (range is machine dependent) */
  140. int treble;
  141. int gain;
  142. int minDev; /* minor device number currently open */
  143. spinlock_t lock;
  144. };
  145. extern struct sound_settings dmasound;
  146. #ifdef HAS_8BIT_TABLES
  147. extern char dmasound_ulaw2dma8[];
  148. extern char dmasound_alaw2dma8[];
  149. #endif
  150. /*
  151. * Mid level stuff
  152. */
  153. static inline int dmasound_set_volume(int volume)
  154. {
  155. return dmasound.mach.setVolume(volume);
  156. }
  157. static inline int dmasound_set_bass(int bass)
  158. {
  159. return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
  160. }
  161. static inline int dmasound_set_treble(int treble)
  162. {
  163. return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
  164. }
  165. static inline int dmasound_set_gain(int gain)
  166. {
  167. return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
  168. }
  169. /*
  170. * Sound queue stuff, the heart of the driver
  171. */
  172. struct sound_queue {
  173. /* buffers allocated for this queue */
  174. int numBufs; /* real limits on what the user can have */
  175. int bufSize; /* in bytes */
  176. char **buffers;
  177. /* current parameters */
  178. int locked ; /* params cannot be modified when != 0 */
  179. int user_frags ; /* user requests this many */
  180. int user_frag_size ; /* of this size */
  181. int max_count; /* actual # fragments <= numBufs */
  182. int block_size; /* internal block size in bytes */
  183. int max_active; /* in-use fragments <= max_count */
  184. /* it shouldn't be necessary to declare any of these volatile */
  185. int front, rear, count;
  186. int rear_size;
  187. /*
  188. * The use of the playing field depends on the hardware
  189. *
  190. * Atari, PMac: The number of frames that are loaded/playing
  191. *
  192. * Amiga: Bit 0 is set: a frame is loaded
  193. * Bit 1 is set: a frame is playing
  194. */
  195. int active;
  196. wait_queue_head_t action_queue, open_queue, sync_queue;
  197. int non_blocking;
  198. int busy, syncing, xruns, died;
  199. };
  200. #define WAKE_UP(queue) (wake_up_interruptible(&queue))
  201. extern struct sound_queue dmasound_write_sq;
  202. #define write_sq dmasound_write_sq
  203. extern int dmasound_catchRadius;
  204. #define catchRadius dmasound_catchRadius
  205. /* define the value to be put in the byte-swap reg in mac-io
  206. when we want it to swap for us.
  207. */
  208. #define BS_VAL 1
  209. #define SW_INPUT_VOLUME_SCALE 4
  210. #define SW_INPUT_VOLUME_DEFAULT (128 / SW_INPUT_VOLUME_SCALE)
  211. #endif /* _dmasound_h_ */