1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _dmasound_h_
31da177e4SLinus Torvalds /*
41da177e4SLinus Torvalds * linux/sound/oss/dmasound/dmasound.h
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds * Minor numbers for the sound driver.
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds * Unfortunately Creative called the codec chip of SB as a DSP. For this
101da177e4SLinus Torvalds * reason the /dev/dsp is reserved for digitized audio use. There is a
111da177e4SLinus Torvalds * device for true DSP processors but it will be called something else.
121da177e4SLinus Torvalds * In v3.0 it's /dev/sndproc but this could be a temporary solution.
131da177e4SLinus Torvalds */
141da177e4SLinus Torvalds #define _dmasound_h_
151da177e4SLinus Torvalds
161da177e4SLinus Torvalds #include <linux/types.h>
171da177e4SLinus Torvalds
181da177e4SLinus Torvalds #define SND_NDEVS 256 /* Number of supported devices */
191da177e4SLinus Torvalds #define SND_DEV_CTL 0 /* Control port /dev/mixer */
201da177e4SLinus Torvalds #define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM
211da177e4SLinus Torvalds synthesizer and MIDI output) */
221da177e4SLinus Torvalds #define SND_DEV_MIDIN 2 /* Raw midi access */
231da177e4SLinus Torvalds #define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */
241da177e4SLinus Torvalds #define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */
251da177e4SLinus Torvalds #define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */
261da177e4SLinus Torvalds #define SND_DEV_STATUS 6 /* /dev/sndstat */
271da177e4SLinus Torvalds /* #7 not in use now. Was in 2.4. Free for use after v3.0. */
281da177e4SLinus Torvalds #define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */
291da177e4SLinus Torvalds #define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */
301da177e4SLinus Torvalds #define SND_DEV_PSS SND_DEV_SNDPROC
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds /* switch on various prinks */
331da177e4SLinus Torvalds #define DEBUG_DMASOUND 1
341da177e4SLinus Torvalds
351da177e4SLinus Torvalds #define MAX_AUDIO_DEV 5
361da177e4SLinus Torvalds #define MAX_MIXER_DEV 4
371da177e4SLinus Torvalds #define MAX_SYNTH_DEV 3
381da177e4SLinus Torvalds #define MAX_MIDI_DEV 6
391da177e4SLinus Torvalds #define MAX_TIMER_DEV 3
401da177e4SLinus Torvalds
411da177e4SLinus Torvalds #define MAX_CATCH_RADIUS 10
421da177e4SLinus Torvalds
431da177e4SLinus Torvalds #define le2be16(x) (((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
441da177e4SLinus Torvalds #define le2be16dbl(x) (((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
451da177e4SLinus Torvalds
461da177e4SLinus Torvalds #define IOCTL_IN(arg, ret) \
471da177e4SLinus Torvalds do { int error = get_user(ret, (int __user *)(arg)); \
481da177e4SLinus Torvalds if (error) return error; \
491da177e4SLinus Torvalds } while (0)
501da177e4SLinus Torvalds #define IOCTL_OUT(arg, ret) ioctl_return((int __user *)(arg), ret)
511da177e4SLinus Torvalds
ioctl_return(int __user * addr,int value)521da177e4SLinus Torvalds static inline int ioctl_return(int __user *addr, int value)
531da177e4SLinus Torvalds {
541da177e4SLinus Torvalds return value < 0 ? value : put_user(value, addr);
551da177e4SLinus Torvalds }
561da177e4SLinus Torvalds
571da177e4SLinus Torvalds
581da177e4SLinus Torvalds /*
591da177e4SLinus Torvalds * Configuration
601da177e4SLinus Torvalds */
611da177e4SLinus Torvalds
621da177e4SLinus Torvalds #undef HAS_8BIT_TABLES
631da177e4SLinus Torvalds
641da177e4SLinus Torvalds #if defined(CONFIG_DMASOUND_ATARI) || defined(CONFIG_DMASOUND_ATARI_MODULE) ||\
651da177e4SLinus Torvalds defined(CONFIG_DMASOUND_PAULA) || defined(CONFIG_DMASOUND_PAULA_MODULE) ||\
661da177e4SLinus Torvalds defined(CONFIG_DMASOUND_Q40) || defined(CONFIG_DMASOUND_Q40_MODULE)
671da177e4SLinus Torvalds #define HAS_8BIT_TABLES
681da177e4SLinus Torvalds #define MIN_BUFFERS 4
691da177e4SLinus Torvalds #define MIN_BUFSIZE (1<<12) /* in bytes (- where does this come from ?) */
701da177e4SLinus Torvalds #define MIN_FRAG_SIZE 8 /* not 100% sure about this */
711da177e4SLinus Torvalds #define MAX_BUFSIZE (1<<17) /* Limit for Amiga is 128 kb */
721da177e4SLinus Torvalds #define MAX_FRAG_SIZE 15 /* allow *4 for mono-8 => stereo-16 (for multi) */
731da177e4SLinus Torvalds
741da177e4SLinus Torvalds #else /* is pmac and multi is off */
751da177e4SLinus Torvalds
761da177e4SLinus Torvalds #define MIN_BUFFERS 2
771da177e4SLinus Torvalds #define MIN_BUFSIZE (1<<8) /* in bytes */
781da177e4SLinus Torvalds #define MIN_FRAG_SIZE 8
791da177e4SLinus Torvalds #define MAX_BUFSIZE (1<<18) /* this is somewhat arbitrary for pmac */
801da177e4SLinus Torvalds #define MAX_FRAG_SIZE 16 /* need to allow *4 for mono-8 => stereo-16 */
811da177e4SLinus Torvalds #endif
821da177e4SLinus Torvalds
831da177e4SLinus Torvalds #define DEFAULT_N_BUFFERS 4
841da177e4SLinus Torvalds #define DEFAULT_BUFF_SIZE (1<<15)
851da177e4SLinus Torvalds
861da177e4SLinus Torvalds /*
871da177e4SLinus Torvalds * Initialization
881da177e4SLinus Torvalds */
891da177e4SLinus Torvalds
901da177e4SLinus Torvalds extern int dmasound_init(void);
911da177e4SLinus Torvalds extern void dmasound_deinit(void);
921da177e4SLinus Torvalds
931da177e4SLinus Torvalds /* description of the set-up applies to either hard or soft settings */
941da177e4SLinus Torvalds
951da177e4SLinus Torvalds typedef struct {
961da177e4SLinus Torvalds int format; /* AFMT_* */
971da177e4SLinus Torvalds int stereo; /* 0 = mono, 1 = stereo */
981da177e4SLinus Torvalds int size; /* 8/16 bit*/
991da177e4SLinus Torvalds int speed; /* speed */
1001da177e4SLinus Torvalds } SETTINGS;
1011da177e4SLinus Torvalds
1021da177e4SLinus Torvalds /*
1031da177e4SLinus Torvalds * Machine definitions
1041da177e4SLinus Torvalds */
1051da177e4SLinus Torvalds
1061da177e4SLinus Torvalds typedef struct {
1071da177e4SLinus Torvalds const char *name;
1081da177e4SLinus Torvalds const char *name2;
1091da177e4SLinus Torvalds struct module *owner;
1101ef64e67SAl Viro void *(*dma_alloc)(unsigned int, gfp_t);
1111da177e4SLinus Torvalds void (*dma_free)(void *, unsigned int);
1121da177e4SLinus Torvalds int (*irqinit)(void);
1131da177e4SLinus Torvalds void (*irqcleanup)(void);
1141da177e4SLinus Torvalds void (*init)(void);
1151da177e4SLinus Torvalds void (*silence)(void);
1161da177e4SLinus Torvalds int (*setFormat)(int);
1171da177e4SLinus Torvalds int (*setVolume)(int);
1181da177e4SLinus Torvalds int (*setBass)(int);
1191da177e4SLinus Torvalds int (*setTreble)(int);
1201da177e4SLinus Torvalds int (*setGain)(int);
1211da177e4SLinus Torvalds void (*play)(void);
1221da177e4SLinus Torvalds void (*record)(void); /* optional */
1231da177e4SLinus Torvalds void (*mixer_init)(void); /* optional */
1241da177e4SLinus Torvalds int (*mixer_ioctl)(u_int, u_long); /* optional */
1251da177e4SLinus Torvalds int (*write_sq_setup)(void); /* optional */
1261da177e4SLinus Torvalds int (*read_sq_setup)(void); /* optional */
127aeb5d727SAl Viro int (*sq_open)(fmode_t); /* optional */
1281da177e4SLinus Torvalds int (*state_info)(char *, size_t); /* optional */
1291da177e4SLinus Torvalds void (*abort_read)(void); /* optional */
1301da177e4SLinus Torvalds int min_dsp_speed;
1311da177e4SLinus Torvalds int max_dsp_speed;
1321da177e4SLinus Torvalds int version ;
1331da177e4SLinus Torvalds int hardware_afmts ; /* OSS says we only return h'ware info */
1341da177e4SLinus Torvalds /* when queried via SNDCTL_DSP_GETFMTS */
1351da177e4SLinus Torvalds int capabilities ; /* low-level reply to SNDCTL_DSP_GETCAPS */
1361da177e4SLinus Torvalds SETTINGS default_hard ; /* open() or init() should set something valid */
1371da177e4SLinus Torvalds SETTINGS default_soft ; /* you can make it look like old OSS, if you want to */
1381da177e4SLinus Torvalds } MACHINE;
1391da177e4SLinus Torvalds
1401da177e4SLinus Torvalds /*
1411da177e4SLinus Torvalds * Low level stuff
1421da177e4SLinus Torvalds */
1431da177e4SLinus Torvalds
1441da177e4SLinus Torvalds typedef struct {
1451da177e4SLinus Torvalds ssize_t (*ct_ulaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1461da177e4SLinus Torvalds ssize_t (*ct_alaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1471da177e4SLinus Torvalds ssize_t (*ct_s8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1481da177e4SLinus Torvalds ssize_t (*ct_u8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1491da177e4SLinus Torvalds ssize_t (*ct_s16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1501da177e4SLinus Torvalds ssize_t (*ct_u16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1511da177e4SLinus Torvalds ssize_t (*ct_s16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1521da177e4SLinus Torvalds ssize_t (*ct_u16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
1531da177e4SLinus Torvalds } TRANS;
1541da177e4SLinus Torvalds
1551da177e4SLinus Torvalds struct sound_settings {
1561da177e4SLinus Torvalds MACHINE mach; /* machine dependent things */
1571da177e4SLinus Torvalds SETTINGS hard; /* hardware settings */
1581da177e4SLinus Torvalds SETTINGS soft; /* software settings */
1591da177e4SLinus Torvalds SETTINGS dsp; /* /dev/dsp default settings */
1601da177e4SLinus Torvalds TRANS *trans_write; /* supported translations */
1611da177e4SLinus Torvalds int volume_left; /* volume (range is machine dependent) */
1621da177e4SLinus Torvalds int volume_right;
1631da177e4SLinus Torvalds int bass; /* tone (range is machine dependent) */
1641da177e4SLinus Torvalds int treble;
1651da177e4SLinus Torvalds int gain;
1661da177e4SLinus Torvalds int minDev; /* minor device number currently open */
1671da177e4SLinus Torvalds spinlock_t lock;
1681da177e4SLinus Torvalds };
1691da177e4SLinus Torvalds
1701da177e4SLinus Torvalds extern struct sound_settings dmasound;
1711da177e4SLinus Torvalds
1721da177e4SLinus Torvalds #ifdef HAS_8BIT_TABLES
1731da177e4SLinus Torvalds extern char dmasound_ulaw2dma8[];
1741da177e4SLinus Torvalds extern char dmasound_alaw2dma8[];
1751da177e4SLinus Torvalds #endif
1761da177e4SLinus Torvalds
1771da177e4SLinus Torvalds /*
1781da177e4SLinus Torvalds * Mid level stuff
1791da177e4SLinus Torvalds */
1801da177e4SLinus Torvalds
dmasound_set_volume(int volume)1811da177e4SLinus Torvalds static inline int dmasound_set_volume(int volume)
1821da177e4SLinus Torvalds {
1831da177e4SLinus Torvalds return dmasound.mach.setVolume(volume);
1841da177e4SLinus Torvalds }
1851da177e4SLinus Torvalds
dmasound_set_bass(int bass)1861da177e4SLinus Torvalds static inline int dmasound_set_bass(int bass)
1871da177e4SLinus Torvalds {
1881da177e4SLinus Torvalds return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
1891da177e4SLinus Torvalds }
1901da177e4SLinus Torvalds
dmasound_set_treble(int treble)1911da177e4SLinus Torvalds static inline int dmasound_set_treble(int treble)
1921da177e4SLinus Torvalds {
1931da177e4SLinus Torvalds return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
1941da177e4SLinus Torvalds }
1951da177e4SLinus Torvalds
dmasound_set_gain(int gain)1961da177e4SLinus Torvalds static inline int dmasound_set_gain(int gain)
1971da177e4SLinus Torvalds {
1981da177e4SLinus Torvalds return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
1991da177e4SLinus Torvalds }
2001da177e4SLinus Torvalds
2011da177e4SLinus Torvalds
2021da177e4SLinus Torvalds /*
2031da177e4SLinus Torvalds * Sound queue stuff, the heart of the driver
2041da177e4SLinus Torvalds */
2051da177e4SLinus Torvalds
2061da177e4SLinus Torvalds struct sound_queue {
2071da177e4SLinus Torvalds /* buffers allocated for this queue */
2081da177e4SLinus Torvalds int numBufs; /* real limits on what the user can have */
2091da177e4SLinus Torvalds int bufSize; /* in bytes */
2101da177e4SLinus Torvalds char **buffers;
2111da177e4SLinus Torvalds
2121da177e4SLinus Torvalds /* current parameters */
2131da177e4SLinus Torvalds int locked ; /* params cannot be modified when != 0 */
2141da177e4SLinus Torvalds int user_frags ; /* user requests this many */
2151da177e4SLinus Torvalds int user_frag_size ; /* of this size */
2161da177e4SLinus Torvalds int max_count; /* actual # fragments <= numBufs */
2171da177e4SLinus Torvalds int block_size; /* internal block size in bytes */
2181da177e4SLinus Torvalds int max_active; /* in-use fragments <= max_count */
2191da177e4SLinus Torvalds
2201da177e4SLinus Torvalds /* it shouldn't be necessary to declare any of these volatile */
2211da177e4SLinus Torvalds int front, rear, count;
2221da177e4SLinus Torvalds int rear_size;
2231da177e4SLinus Torvalds /*
2241da177e4SLinus Torvalds * The use of the playing field depends on the hardware
2251da177e4SLinus Torvalds *
2261da177e4SLinus Torvalds * Atari, PMac: The number of frames that are loaded/playing
2271da177e4SLinus Torvalds *
2281da177e4SLinus Torvalds * Amiga: Bit 0 is set: a frame is loaded
2291da177e4SLinus Torvalds * Bit 1 is set: a frame is playing
2301da177e4SLinus Torvalds */
2311da177e4SLinus Torvalds int active;
2321da177e4SLinus Torvalds wait_queue_head_t action_queue, open_queue, sync_queue;
2334b30fbdeSAl Viro int non_blocking;
2341da177e4SLinus Torvalds int busy, syncing, xruns, died;
2351da177e4SLinus Torvalds };
2361da177e4SLinus Torvalds
2371da177e4SLinus Torvalds #define WAKE_UP(queue) (wake_up_interruptible(&queue))
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvalds extern struct sound_queue dmasound_write_sq;
2401da177e4SLinus Torvalds #define write_sq dmasound_write_sq
2411da177e4SLinus Torvalds
2421da177e4SLinus Torvalds extern int dmasound_catchRadius;
2431da177e4SLinus Torvalds #define catchRadius dmasound_catchRadius
2441da177e4SLinus Torvalds
2451da177e4SLinus Torvalds /* define the value to be put in the byte-swap reg in mac-io
2461da177e4SLinus Torvalds when we want it to swap for us.
2471da177e4SLinus Torvalds */
2481da177e4SLinus Torvalds #define BS_VAL 1
2491da177e4SLinus Torvalds
2501da177e4SLinus Torvalds #define SW_INPUT_VOLUME_SCALE 4
2511da177e4SLinus Torvalds #define SW_INPUT_VOLUME_DEFAULT (128 / SW_INPUT_VOLUME_SCALE)
2521da177e4SLinus Torvalds
2531da177e4SLinus Torvalds #endif /* _dmasound_h_ */
254