/*
* Copyright (c) 1999 by Uros Bizjak <uros@kss-loka.si>
* Takashi Iwai <tiwai@suse.de>
*
* SB16ASP/AWE32 CSP control
*
* CSP microcode loader:
* alsa-tools/sb16_csp/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <sound/driver.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <sound/core.h>
#include <sound/control.h>
#include <sound/info.h>
#include <sound/sb16_csp.h>
#include <sound/initval.h>
MODULE_AUTHOR("Uros Bizjak <uros@kss-loka.si>");
MODULE_DESCRIPTION("ALSA driver for SB16 Creative Signal Processor");
MODULE_LICENSE("GPL");
#ifdef SNDRV_LITTLE_ENDIAN
#define CSP_HDR_VALUE(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
#else
#define CSP_HDR_VALUE(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
#endif
#define LE_SHORT(v) le16_to_cpu(v)
#define LE_INT(v) le32_to_cpu(v)
#define RIFF_HEADER CSP_HDR_VALUE('R', 'I', 'F', 'F')
#define CSP__HEADER CSP_HDR_VALUE('C', 'S', 'P', ' ')
#define LIST_HEADER CSP_HDR_VALUE('L', 'I', 'S', 'T')
#define FUNC_HEADER CSP_HDR_VALUE('f', 'u', 'n', 'c')
#define CODE_HEADER CSP_HDR_VALUE('c', 'o', 'd', 'e')
#define INIT_HEADER CSP_HDR_VALUE('i', 'n', 'i', 't')
#define MAIN_HEADER CSP_HDR_VALUE('m', 'a', 'i', 'n')
/*
* RIFF data format
*/
typedef struct riff_header {
__u32 name;
__u32 len;
} riff_header_t;
typedef struct desc_header {
riff_header_t info;
__u16 func_nr;
__u16 VOC_type;
__u16 flags_play_rec;
__u16 flags_16bit_8bit;
__u16 flags_stereo_mono;
__u16 flags_rates;
} desc_header_t;
/*
* prototypes
*/
static void snd_sb_csp_free(snd_hwdep_t *hw);
static int snd_sb_csp_open(snd_hwdep_t * hw, struct file *file);
static int snd_sb_csp_ioctl(snd_hwdep_t * hw, struct file *file, unsigned int cmd, unsigned long arg);
static int snd_sb_csp_release(snd_hwdep_t * hw, struct file *file);
static int csp_detect(sb_t *chip, int *version);
static int set_codec_parameter(sb_t *chip, unsigned char par, unsigned char val);
static int set_register(sb_t *chip, unsigned char reg, unsigned char val);
static int read_register(sb_t *chip, unsigned char reg);
static int set_mode_register(sb_t *chip, unsigned char mode);
static int get_version(sb_t *chip);
static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t __user * code);
static int snd_sb_csp_unload(snd_sb_csp_t * p);
static int snd_sb_csp_load_user(snd_sb_csp_t * p, const unsigned char __user *buf, int size, int load_flags);
static int snd_sb_csp_autoload(snd_sb_csp_t * p, int pcm_sfmt, int play_rec_mode);
static int snd_sb_csp_check_version(snd_sb_csp_t * p);
static int snd_sb_csp_use(snd_sb_csp_t * p);
static int snd_sb_csp_unuse(snd_sb_csp_t * p);
static int snd_sb_csp_start(snd_sb_csp_t * p, int sample_width, int channels);
static int snd_sb_csp_stop(snd_sb_csp_t * p);
static int snd_sb_csp_pause(snd_sb_csp_t * p);
static int snd_sb_csp_restart(snd_sb_csp_t * p);
static int snd_sb_qsound_build(snd_sb_csp_t *