dmasound.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. #ifdef MODULE
  75. extern void dmasound_deinit(void);
  76. #else
  77. #define dmasound_deinit() do { } while (0)
  78. #endif
  79. /* description of the set-up applies to either hard or soft settings */
  80. typedef struct {
  81. int format; /* AFMT_* */
  82. int stereo; /* 0 = mono, 1 = stereo */
  83. int size; /* 8/16 bit*/
  84. int speed; /* speed */
  85. } SETTINGS;
  86. /*
  87. * Machine definitions
  88. */
  89. typedef struct {
  90. const char *name;
  91. const char *name2;
  92. struct module *owner;
  93. void *(*dma_alloc)(unsigned int, gfp_t);
  94. void (*dma_free)(void *, unsigned int);
  95. int (*irqinit)(void);
  96. #ifdef MODULE
  97. void (*irqcleanup)(void);
  98. #endif
  99. void (*init)(void);
  100. void (*silence)(void);
  101. int (*setFormat)(int);
  102. int (*setVolume)(int);
  103. int (*setBass)(int);
  104. int (*setTreble)(int);
  105. int (*setGain)(int);
  106. void (*play)(void);
  107. void (*record)(void); /* optional */
  108. void (*mixer_init)(void); /* optional */
  109. int (*mixer_ioctl)(u_int, u_long); /* optional */
  110. int (*write_sq_setup)(void); /* optional */
  111. int (*read_sq_setup)(void); /* optional */
  112. int (*sq_open)(fmode_t); /* optional */
  113. int (*state_info)(char *, size_t); /* optional */
  114. void (*abort_read)(void); /* optional */
  115. int min_dsp_speed;
  116. int max_dsp_speed;
  117. int version ;
  118. int hardware_afmts ; /* OSS says we only return h'ware info */
  119. /* when queried via SNDCTL_DSP_GETFMTS */
  120. int capabilities ; /* low-level reply to SNDCTL_DSP_GETCAPS */
  121. SETTINGS default_hard ; /* open() or init() should set something valid */
  122. SETTINGS default_soft ; /* you can make it look like old OSS, if you want to */
  123. } MACHINE;
  124. /*
  125. * Low level stuff
  126. */
  127. typedef struct {
  128. ssize_t (*ct_ulaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  129. ssize_t (*ct_alaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  130. ssize_t (*ct_s8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  131. ssize_t (*ct_u8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  132. ssize_t (*ct_s16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  133. ssize_t (*ct_u16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  134. ssize_t (*ct_s16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  135. ssize_t (*ct_u16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  136. } TRANS;
  137. struct sound_settings {
  138. MACHINE mach; /* machine dependent things */
  139. SETTINGS hard; /* hardware settings */
  140. SETTINGS soft; /* software settings */
  141. SETTINGS dsp; /* /dev/dsp default settings */
  142. TRANS *trans_write; /* supported translations */
  143. int volume_left; /* volume (range is machine dependent) */
  144. int volume_right;
  145. int bass; /* tone (range is machine dependent) */
  146. int treble;
  147. int gain;
  148. int minDev; /* minor device number currently open */
  149. spinlock_t lock;
  150. };
  151. extern struct sound_settings dmasound;
  152. #ifdef HAS_8BIT_TABLES
  153. extern char dmasound_ulaw2dma8[];
  154. extern char dmasound_alaw2dma8[];
  155. #endif
  156. /*
  157. * Mid level stuff
  158. */
  159. static inline int dmasound_set_volume(int volume)
  160. {
  161. return dmasound.mach.setVolume(volume);
  162. }
  163. static inline int dmasound_set_bass(int bass)
  164. {
  165. return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
  166. }
  167. static inline int dmasound_set_treble(int treble)
  168. {
  169. return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
  170. }
  171. static inline int dmasound_set_gain(int gain)
  172. {
  173. return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
  174. }
  175. /*
  176. * Sound queue stuff, the heart of the driver
  177. */
  178. struct sound_queue {
  179. /* buffers allocated for this queue */
  180. int numBufs; /* real limits on what the user can have */
  181. int bufSize; /* in bytes */
  182. char **buffers;
  183. /* current parameters */
  184. int locked ; /* params cannot be modified when != 0 */
  185. int user_frags ; /* user requests this many */
  186. int user_frag_size ; /* of this size */
  187. int max_count; /* actual # fragments <= numBufs */
  188. int block_size; /* internal block size in bytes */
  189. int max_active; /* in-use fragments <= max_count */
  190. /* it shouldn't be necessary to declare any of these volatile */
  191. int front, rear, count;
  192. int rear_size;
  193. /*
  194. * The use of the playing field depends on the hardware
  195. *
  196. * Atari, PMac: The number of frames that are loaded/playing
  197. *
  198. * Amiga: Bit 0 is set: a frame is loaded
  199. * Bit 1 is set: a frame is playing
  200. */
  201. int active;
  202. wait_queue_head_t action_queue, open_queue, sync_queue;
  203. int non_blocking;
  204. int busy, syncing, xruns, died;
  205. };
  206. #define WAKE_UP(queue) (wake_up_interruptible(&queue))
  207. extern struct sound_queue dmasound_write_sq;
  208. #define write_sq dmasound_write_sq
  209. extern int dmasound_catchRadius;
  210. #define catchRadius dmasound_catchRadius
  211. /* define the value to be put in the byte-swap reg in mac-io
  212. when we want it to swap for us.
  213. */
  214. #define BS_VAL 1
  215. #define SW_INPUT_VOLUME_SCALE 4
  216. #define SW_INPUT_VOLUME_DEFAULT (128 / SW_INPUT_VOLUME_SCALE)
  217. extern int expand_read_bal; /* Balance factor for reading */
  218. extern uint software_input_volume; /* software implemented recording volume! */
  219. #endif /* _dmasound_h_ */