dmasound.h 8.2 KB

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