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