Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _dmasound_h_
0003 /*
0004  *  linux/sound/oss/dmasound/dmasound.h
0005  *
0006  *
0007  *  Minor numbers for the sound driver.
0008  *
0009  *  Unfortunately Creative called the codec chip of SB as a DSP. For this
0010  *  reason the /dev/dsp is reserved for digitized audio use. There is a
0011  *  device for true DSP processors but it will be called something else.
0012  *  In v3.0 it's /dev/sndproc but this could be a temporary solution.
0013  */
0014 #define _dmasound_h_
0015 
0016 #include <linux/types.h>
0017 
0018 #define SND_NDEVS   256 /* Number of supported devices */
0019 #define SND_DEV_CTL 0   /* Control port /dev/mixer */
0020 #define SND_DEV_SEQ 1   /* Sequencer output /dev/sequencer (FM
0021                    synthesizer and MIDI output) */
0022 #define SND_DEV_MIDIN   2   /* Raw midi access */
0023 #define SND_DEV_DSP 3   /* Digitized voice /dev/dsp */
0024 #define SND_DEV_AUDIO   4   /* Sparc compatible /dev/audio */
0025 #define SND_DEV_DSP16   5   /* Like /dev/dsp but 16 bits/sample */
0026 #define SND_DEV_STATUS  6   /* /dev/sndstat */
0027 /* #7 not in use now. Was in 2.4. Free for use after v3.0. */
0028 #define SND_DEV_SEQ2    8   /* /dev/sequencer, level 2 interface */
0029 #define SND_DEV_SNDPROC 9   /* /dev/sndproc for programmable devices */
0030 #define SND_DEV_PSS SND_DEV_SNDPROC
0031 
0032 /* switch on various prinks */
0033 #define DEBUG_DMASOUND 1
0034 
0035 #define MAX_AUDIO_DEV   5
0036 #define MAX_MIXER_DEV   4
0037 #define MAX_SYNTH_DEV   3
0038 #define MAX_MIDI_DEV    6
0039 #define MAX_TIMER_DEV   3
0040 
0041 #define MAX_CATCH_RADIUS    10
0042 
0043 #define le2be16(x)  (((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
0044 #define le2be16dbl(x)   (((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
0045 
0046 #define IOCTL_IN(arg, ret) \
0047     do { int error = get_user(ret, (int __user *)(arg)); \
0048         if (error) return error; \
0049     } while (0)
0050 #define IOCTL_OUT(arg, ret) ioctl_return((int __user *)(arg), ret)
0051 
0052 static inline int ioctl_return(int __user *addr, int value)
0053 {
0054     return value < 0 ? value : put_user(value, addr);
0055 }
0056 
0057 
0058     /*
0059      *  Configuration
0060      */
0061 
0062 #undef HAS_8BIT_TABLES
0063 
0064 #if defined(CONFIG_DMASOUND_ATARI) || defined(CONFIG_DMASOUND_ATARI_MODULE) ||\
0065     defined(CONFIG_DMASOUND_PAULA) || defined(CONFIG_DMASOUND_PAULA_MODULE) ||\
0066     defined(CONFIG_DMASOUND_Q40) || defined(CONFIG_DMASOUND_Q40_MODULE)
0067 #define HAS_8BIT_TABLES
0068 #define MIN_BUFFERS 4
0069 #define MIN_BUFSIZE (1<<12) /* in bytes (- where does this come from ?) */
0070 #define MIN_FRAG_SIZE   8   /* not 100% sure about this */
0071 #define MAX_BUFSIZE (1<<17) /* Limit for Amiga is 128 kb */
0072 #define MAX_FRAG_SIZE   15  /* allow *4 for mono-8 => stereo-16 (for multi) */
0073 
0074 #else /* is pmac and multi is off */
0075 
0076 #define MIN_BUFFERS 2
0077 #define MIN_BUFSIZE (1<<8)  /* in bytes */
0078 #define MIN_FRAG_SIZE   8
0079 #define MAX_BUFSIZE (1<<18) /* this is somewhat arbitrary for pmac */
0080 #define MAX_FRAG_SIZE   16  /* need to allow *4 for mono-8 => stereo-16 */
0081 #endif
0082 
0083 #define DEFAULT_N_BUFFERS 4
0084 #define DEFAULT_BUFF_SIZE (1<<15)
0085 
0086     /*
0087      *  Initialization
0088      */
0089 
0090 extern int dmasound_init(void);
0091 extern void dmasound_deinit(void);
0092 
0093 /* description of the set-up applies to either hard or soft settings */
0094 
0095 typedef struct {
0096     int format;     /* AFMT_* */
0097     int stereo;     /* 0 = mono, 1 = stereo */
0098     int size;       /* 8/16 bit*/
0099     int speed;      /* speed */
0100 } SETTINGS;
0101 
0102     /*
0103      *  Machine definitions
0104      */
0105 
0106 typedef struct {
0107     const char *name;
0108     const char *name2;
0109     struct module *owner;
0110     void *(*dma_alloc)(unsigned int, gfp_t);
0111     void (*dma_free)(void *, unsigned int);
0112     int (*irqinit)(void);
0113     void (*irqcleanup)(void);
0114     void (*init)(void);
0115     void (*silence)(void);
0116     int (*setFormat)(int);
0117     int (*setVolume)(int);
0118     int (*setBass)(int);
0119     int (*setTreble)(int);
0120     int (*setGain)(int);
0121     void (*play)(void);
0122     void (*record)(void);       /* optional */
0123     void (*mixer_init)(void);       /* optional */
0124     int (*mixer_ioctl)(u_int, u_long);  /* optional */
0125     int (*write_sq_setup)(void);    /* optional */
0126     int (*read_sq_setup)(void);     /* optional */
0127     int (*sq_open)(fmode_t);        /* optional */
0128     int (*state_info)(char *, size_t);  /* optional */
0129     void (*abort_read)(void);       /* optional */
0130     int min_dsp_speed;
0131     int max_dsp_speed;
0132     int version ;
0133     int hardware_afmts ;        /* OSS says we only return h'ware info */
0134                     /* when queried via SNDCTL_DSP_GETFMTS */
0135     int capabilities ;      /* low-level reply to SNDCTL_DSP_GETCAPS */
0136     SETTINGS default_hard ; /* open() or init() should set something valid */
0137     SETTINGS default_soft ; /* you can make it look like old OSS, if you want to */
0138 } MACHINE;
0139 
0140     /*
0141      *  Low level stuff
0142      */
0143 
0144 typedef struct {
0145     ssize_t (*ct_ulaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0146     ssize_t (*ct_alaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0147     ssize_t (*ct_s8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0148     ssize_t (*ct_u8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0149     ssize_t (*ct_s16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0150     ssize_t (*ct_u16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0151     ssize_t (*ct_s16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0152     ssize_t (*ct_u16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
0153 } TRANS;
0154 
0155 struct sound_settings {
0156     MACHINE mach;   /* machine dependent things */
0157     SETTINGS hard;  /* hardware settings */
0158     SETTINGS soft;  /* software settings */
0159     SETTINGS dsp;   /* /dev/dsp default settings */
0160     TRANS *trans_write; /* supported translations */
0161     int volume_left;    /* volume (range is machine dependent) */
0162     int volume_right;
0163     int bass;       /* tone (range is machine dependent) */
0164     int treble;
0165     int gain;
0166     int minDev;     /* minor device number currently open */
0167     spinlock_t lock;
0168 };
0169 
0170 extern struct sound_settings dmasound;
0171 
0172 #ifdef HAS_8BIT_TABLES
0173 extern char dmasound_ulaw2dma8[];
0174 extern char dmasound_alaw2dma8[];
0175 #endif
0176 
0177     /*
0178      *  Mid level stuff
0179      */
0180 
0181 static inline int dmasound_set_volume(int volume)
0182 {
0183     return dmasound.mach.setVolume(volume);
0184 }
0185 
0186 static inline int dmasound_set_bass(int bass)
0187 {
0188     return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
0189 }
0190 
0191 static inline int dmasound_set_treble(int treble)
0192 {
0193     return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
0194 }
0195 
0196 static inline int dmasound_set_gain(int gain)
0197 {
0198     return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
0199 }
0200 
0201 
0202     /*
0203      * Sound queue stuff, the heart of the driver
0204      */
0205 
0206 struct sound_queue {
0207     /* buffers allocated for this queue */
0208     int numBufs;        /* real limits on what the user can have */
0209     int bufSize;        /* in bytes */
0210     char **buffers;
0211 
0212     /* current parameters */
0213     int locked ;        /* params cannot be modified when != 0 */
0214     int user_frags ;        /* user requests this many */
0215     int user_frag_size ;    /* of this size */
0216     int max_count;      /* actual # fragments <= numBufs */
0217     int block_size;     /* internal block size in bytes */
0218     int max_active;     /* in-use fragments <= max_count */
0219 
0220     /* it shouldn't be necessary to declare any of these volatile */
0221     int front, rear, count;
0222     int rear_size;
0223     /*
0224      *  The use of the playing field depends on the hardware
0225      *
0226      *  Atari, PMac: The number of frames that are loaded/playing
0227      *
0228      *  Amiga: Bit 0 is set: a frame is loaded
0229      *         Bit 1 is set: a frame is playing
0230      */
0231     int active;
0232     wait_queue_head_t action_queue, open_queue, sync_queue;
0233     int non_blocking;
0234     int busy, syncing, xruns, died;
0235 };
0236 
0237 #define WAKE_UP(queue)      (wake_up_interruptible(&queue))
0238 
0239 extern struct sound_queue dmasound_write_sq;
0240 #define write_sq    dmasound_write_sq
0241 
0242 extern int dmasound_catchRadius;
0243 #define catchRadius dmasound_catchRadius
0244 
0245 /* define the value to be put in the byte-swap reg in mac-io
0246    when we want it to swap for us.
0247 */
0248 #define BS_VAL 1
0249 
0250 #define SW_INPUT_VOLUME_SCALE   4
0251 #define SW_INPUT_VOLUME_DEFAULT (128 / SW_INPUT_VOLUME_SCALE)
0252 
0253 extern int expand_read_bal; /* Balance factor for reading */
0254 extern uint software_input_volume; /* software implemented recording volume! */
0255 
0256 #endif /* _dmasound_h_ */