Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /* Copyright (C) by Paul Barton-Davis 1998-1999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Some portions of this file are taken from work that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * copyright (C) by Hannu Savolainen 1993-1996
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) /*  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * An ALSA lowlevel driver for Turtle Beach ICS2115 wavetable synth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *                                             (Maui, Tropez, Tropez Plus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * This driver supports the onboard wavetable synthesizer (an ICS2115),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * including patch, sample and program loading and unloading, conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * of GUS patches during loading, and full user-level access to all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * WaveFront commands. It tries to provide semi-intelligent patch and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * sample management as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <sound/snd_wavefront.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static int wf_raw = 0; /* we normally check for "raw state" to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 			  loading. if non-zero, then during driver loading, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 			  state of the board is ignored, and we reset the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 			  board and load the firmware anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 		       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 		   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) static int fx_raw = 1; /* if this is zero, we'll leave the FX processor in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 			  whatever state it is when the driver is loaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 			  The default is to download the microprogram and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 			  associated coefficients to set it up for "default"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 			  operation, whatever that means.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 		       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) static int debug_default = 0;  /* you can set this to control debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 				  during driver loading. it takes any combination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 				  of the WF_DEBUG_* flags defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 				  wavefront.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 			       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) /* XXX this needs to be made firmware and hardware version dependent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define DEFAULT_OSPATH	"wavefront.os"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) static char *ospath = DEFAULT_OSPATH; /* the firmware file name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static int wait_usecs = 150; /* This magic number seems to give pretty optimal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 				throughput based on my limited experimentation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 				If you want to play around with it and find a better
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 				value, be my guest. Remember, the idea is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 				get a number that causes us to just busy wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 				for as many WaveFront commands as possible, without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 				coming up with a number so large that we hog the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 				whole CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 				Specifically, with this number, out of about 134,000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 				status waits, only about 250 result in a sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 			    */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static int sleep_interval = 100;   /* HZ/sleep_interval seconds per sleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static int sleep_tries = 50;       /* number of times we'll try to sleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) static int reset_time = 2;        /* hundreths of a second we wait after a HW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 				     reset for the expected interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 				  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) static int ramcheck_time = 20;    /* time in seconds to wait while ROM code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 				     checks on-board RAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 				  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static int osrun_time = 10;       /* time in seconds we wait for the OS to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 				     start running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 				  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) module_param(wf_raw, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) MODULE_PARM_DESC(wf_raw, "if non-zero, assume that we need to boot the OS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) module_param(fx_raw, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) MODULE_PARM_DESC(fx_raw, "if non-zero, assume that the FX process needs help");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) module_param(debug_default, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) MODULE_PARM_DESC(debug_default, "debug parameters for card initialization");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) module_param(wait_usecs, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) MODULE_PARM_DESC(wait_usecs, "how long to wait without sleeping, usecs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) module_param(sleep_interval, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) MODULE_PARM_DESC(sleep_interval, "how long to sleep when waiting for reply");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) module_param(sleep_tries, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) MODULE_PARM_DESC(sleep_tries, "how many times to try sleeping during a wait");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) module_param(ospath, charp, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) MODULE_PARM_DESC(ospath, "pathname to processed ICS2115 OS firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) module_param(reset_time, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) MODULE_PARM_DESC(reset_time, "how long to wait for a reset to take effect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) module_param(ramcheck_time, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) MODULE_PARM_DESC(ramcheck_time, "how many seconds to wait for the RAM test");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) module_param(osrun_time, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) MODULE_PARM_DESC(osrun_time, "how many seconds to wait for the ICS2115 OS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) /* if WF_DEBUG not defined, no run-time debugging messages will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)    be available via the debug flag setting. Given the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)    beta state of the driver, this will remain set until a future 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)    version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) #define WF_DEBUG 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) #ifdef WF_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) #define DPRINT(cond, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)        if ((dev->debug & (cond)) == (cond)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	     snd_printk (__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)        }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) #define DPRINT(cond, args...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) #endif /* WF_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #define LOGNAME "WaveFront: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) /* bitmasks for WaveFront status port value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #define STAT_RINTR_ENABLED	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #define STAT_CAN_READ		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) #define STAT_INTR_READ		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) #define STAT_WINTR_ENABLED	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #define STAT_CAN_WRITE		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #define STAT_INTR_WRITE		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) static int wavefront_delete_sample (snd_wavefront_t *, int sampnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) static int wavefront_find_free_sample (snd_wavefront_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) struct wavefront_command {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	int cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	char *action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	unsigned int read_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	unsigned int write_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	int need_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	int errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	const char *errstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) } wavefront_errors[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	{ 0x01, "Bad sample number" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	{ 0x02, "Out of sample memory" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	{ 0x03, "Bad patch number" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	{ 0x04, "Error in number of voices" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	{ 0x06, "Sample load already in progress" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	{ 0x0B, "No sample load request pending" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	{ 0x0E, "Bad MIDI channel number" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	{ 0x10, "Download Record Error" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	{ 0x80, "Success" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	{ 0x0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #define NEEDS_ACK 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static struct wavefront_command wavefront_commands[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	{ WFC_SET_SYNTHVOL, "set synthesizer volume", 0, 1, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	{ WFC_GET_SYNTHVOL, "get synthesizer volume", 1, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	{ WFC_SET_NVOICES, "set number of voices", 0, 1, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	{ WFC_GET_NVOICES, "get number of voices", 1, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	{ WFC_SET_TUNING, "set synthesizer tuning", 0, 2, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	{ WFC_GET_TUNING, "get synthesizer tuning", 2, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	{ WFC_DISABLE_CHANNEL, "disable synth channel", 0, 1, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	{ WFC_ENABLE_CHANNEL, "enable synth channel", 0, 1, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	{ WFC_GET_CHANNEL_STATUS, "get synth channel status", 3, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	{ WFC_MISYNTH_OFF, "disable midi-in to synth", 0, 0, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	{ WFC_MISYNTH_ON, "enable midi-in to synth", 0, 0, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	{ WFC_VMIDI_ON, "enable virtual midi mode", 0, 0, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	{ WFC_VMIDI_OFF, "disable virtual midi mode", 0, 0, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	{ WFC_MIDI_STATUS, "report midi status", 1, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	{ WFC_FIRMWARE_VERSION, "report firmware version", 2, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	{ WFC_HARDWARE_VERSION, "report hardware version", 2, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	{ WFC_GET_NSAMPLES, "report number of samples", 2, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	{ WFC_INSTOUT_LEVELS, "report instantaneous output levels", 7, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	{ WFC_PEAKOUT_LEVELS, "report peak output levels", 7, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	{ WFC_DOWNLOAD_SAMPLE, "download sample",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	  0, WF_SAMPLE_BYTES, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	{ WFC_DOWNLOAD_BLOCK, "download block", 0, 0, NEEDS_ACK},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	{ WFC_DOWNLOAD_SAMPLE_HEADER, "download sample header",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	  0, WF_SAMPLE_HDR_BYTES, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	{ WFC_UPLOAD_SAMPLE_HEADER, "upload sample header", 13, 2, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	/* This command requires a variable number of bytes to be written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	   There is a hack in snd_wavefront_cmd() to support this. The actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	   count is passed in as the read buffer ptr, cast appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	   Ugh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	{ WFC_DOWNLOAD_MULTISAMPLE, "download multisample", 0, 0, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	/* This one is a hack as well. We just read the first byte of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	   response, don't fetch an ACK, and leave the rest to the 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	   calling function. Ugly, ugly, ugly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	{ WFC_UPLOAD_MULTISAMPLE, "upload multisample", 2, 1, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	{ WFC_DOWNLOAD_SAMPLE_ALIAS, "download sample alias",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	  0, WF_ALIAS_BYTES, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	{ WFC_UPLOAD_SAMPLE_ALIAS, "upload sample alias", WF_ALIAS_BYTES, 2, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	{ WFC_DELETE_SAMPLE, "delete sample", 0, 2, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	{ WFC_IDENTIFY_SAMPLE_TYPE, "identify sample type", 5, 2, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	{ WFC_UPLOAD_SAMPLE_PARAMS, "upload sample parameters" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	{ WFC_REPORT_FREE_MEMORY, "report free memory", 4, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	{ WFC_DOWNLOAD_PATCH, "download patch", 0, 134, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	{ WFC_UPLOAD_PATCH, "upload patch", 132, 2, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	{ WFC_DOWNLOAD_PROGRAM, "download program", 0, 33, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	{ WFC_UPLOAD_PROGRAM, "upload program", 32, 1, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	{ WFC_DOWNLOAD_EDRUM_PROGRAM, "download enhanced drum program", 0, 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	  NEEDS_ACK},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	{ WFC_UPLOAD_EDRUM_PROGRAM, "upload enhanced drum program", 8, 1, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	{ WFC_SET_EDRUM_CHANNEL, "set enhanced drum program channel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	  0, 1, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	{ WFC_DISABLE_DRUM_PROGRAM, "disable drum program", 0, 1, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	{ WFC_REPORT_CHANNEL_PROGRAMS, "report channel program numbers",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	  32, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	{ WFC_NOOP, "the no-op command", 0, 0, NEEDS_ACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	{ 0x00 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) static const char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) wavefront_errorstr (int errnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	for (i = 0; wavefront_errors[i].errstr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		if (wavefront_errors[i].errno == errnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 			return wavefront_errors[i].errstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	return "Unknown WaveFront error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) static struct wavefront_command *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) wavefront_get_command (int cmd) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	for (i = 0; wavefront_commands[i].cmd != 0; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		if (cmd == wavefront_commands[i].cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 			return &wavefront_commands[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) wavefront_status (snd_wavefront_t *dev) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	return inb (dev->status_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) wavefront_sleep (int limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	schedule_timeout_interruptible(limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	return signal_pending(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) wavefront_wait (snd_wavefront_t *dev, int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	int             i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	/* Spin for a short period of time, because >99% of all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	   requests to the WaveFront can be serviced inline like this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	for (i = 0; i < wait_usecs; i += 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		if (wavefront_status (dev) & mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		udelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	for (i = 0; i < sleep_tries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		if (wavefront_status (dev) & mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		if (wavefront_sleep (HZ/sleep_interval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) wavefront_read (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	if (wavefront_wait (dev, STAT_CAN_READ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		return inb (dev->data_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	DPRINT (WF_DEBUG_DATA, "read timeout.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) wavefront_write (snd_wavefront_t *dev, unsigned char data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	if (wavefront_wait (dev, STAT_CAN_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		outb (data, dev->data_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	DPRINT (WF_DEBUG_DATA, "write timeout.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) snd_wavefront_cmd (snd_wavefront_t *dev, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		   int cmd, unsigned char *rbuf, unsigned char *wbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	int ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	struct wavefront_command *wfcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	if ((wfcmd = wavefront_get_command (cmd)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		snd_printk ("command 0x%x not supported.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 			cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	/* Hack to handle the one variable-size write command. See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	   wavefront_send_multisample() for the other half of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	   gross and ugly strategy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	if (cmd == WFC_DOWNLOAD_MULTISAMPLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		wfcmd->write_cnt = (unsigned long) rbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		rbuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	DPRINT (WF_DEBUG_CMD, "0x%x [%s] (%d,%d,%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			       cmd, wfcmd->action, wfcmd->read_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			       wfcmd->write_cnt, wfcmd->need_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	if (wavefront_write (dev, cmd)) { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		DPRINT ((WF_DEBUG_IO|WF_DEBUG_CMD), "cannot request "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 						     "0x%x [%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 						     cmd, wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	} 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	if (wfcmd->write_cnt > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		DPRINT (WF_DEBUG_DATA, "writing %d bytes "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 					"for 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 					wfcmd->write_cnt, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		for (i = 0; i < wfcmd->write_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			if (wavefront_write (dev, wbuf[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 				DPRINT (WF_DEBUG_IO, "bad write for byte "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 						      "%d of 0x%x [%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 						      i, cmd, wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			DPRINT (WF_DEBUG_DATA, "write[%d] = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 						i, wbuf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	if (wfcmd->read_cnt > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		DPRINT (WF_DEBUG_DATA, "reading %d ints "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 					"for 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 					wfcmd->read_cnt, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		for (i = 0; i < wfcmd->read_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			if ((c = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 				DPRINT (WF_DEBUG_IO, "bad read for byte "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 						      "%d of 0x%x [%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 						      i, cmd, wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 			/* Now handle errors. Lots of special cases here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 			if (c == 0xff) { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 				if ((c = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 					DPRINT (WF_DEBUG_IO, "bad read for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 							      "error byte at "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 							      "read byte %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 							      "of 0x%x [%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 							      i, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 							      wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 					return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 				/* Can you believe this madness ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 				if (c == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 				    wfcmd->cmd == WFC_IDENTIFY_SAMPLE_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 					rbuf[0] = WF_ST_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 					return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 				} else if (c == 3 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 					   wfcmd->cmd == WFC_UPLOAD_PATCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 					return 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 				} else if (c == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 					   wfcmd->cmd == WFC_UPLOAD_PROGRAM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 					return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 					DPRINT (WF_DEBUG_IO, "error %d (%s) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 							      "during "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 							      "read for byte "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 							      "%d of 0x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 							      "[%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 							      c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 							      wavefront_errorstr (c),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 							      i, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 							      wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 					return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 				rbuf[i] = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 			DPRINT (WF_DEBUG_DATA, "read[%d] = 0x%x\n",i, rbuf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	if ((wfcmd->read_cnt == 0 && wfcmd->write_cnt == 0) || wfcmd->need_ack) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		DPRINT (WF_DEBUG_CMD, "reading ACK for 0x%x\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		/* Some commands need an ACK, but return zero instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		   of the standard value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		if ((ack = wavefront_read (dev)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 			ack = WF_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		if (ack != WF_ACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			if (ack == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 				DPRINT (WF_DEBUG_IO, "cannot read ack for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 						      "0x%x [%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 						      cmd, wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 				int err = -1; /* something unknown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 				if (ack == 0xff) { /* explicit error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 					if ((err = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 						DPRINT (WF_DEBUG_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 							"cannot read err "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 							"for 0x%x [%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 							cmd, wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 				
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 				DPRINT (WF_DEBUG_IO, "0x%x [%s] "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 					"failed (0x%x, 0x%x, %s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 					cmd, wfcmd->action, ack, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 					wavefront_errorstr (err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 				
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 				return -err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		DPRINT (WF_DEBUG_DATA, "ack received "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 					"for 0x%x [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 					cmd, wfcmd->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		DPRINT (WF_DEBUG_CMD, "0x%x [%s] does not need "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 				       "ACK (%d,%d,%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 				       cmd, wfcmd->action, wfcmd->read_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 				       wfcmd->write_cnt, wfcmd->need_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) WaveFront data munging   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) Things here are weird. All data written to the board cannot 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) have its most significant bit set. Any data item with values 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) potentially > 0x7F (127) must be split across multiple bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) Sometimes, we need to munge numeric values that are represented on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) the x86 side as 8-32 bit values. Sometimes, we need to munge data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) that is represented on the x86 side as an array of bytes. The most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) efficient approach to handling both cases seems to be to use 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) different functions for munging and 2 for de-munging. This avoids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) weird casting and worrying about bit-level offsets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) **********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) static unsigned char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) munge_int32 (unsigned int src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	     unsigned char *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	     unsigned int dst_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	for (i = 0; i < dst_size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		*dst = src & 0x7F;  /* Mask high bit of LSB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		src = src >> 7;     /* Rotate Right 7 bits  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	                            /* Note: we leave the upper bits in place */ 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		dst++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) static int 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) demunge_int32 (unsigned char* src, int src_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548)  	int outval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550)  	for (i = src_size - 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		outval=(outval<<7)+src[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	return outval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) static 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) unsigned char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) munge_buf (unsigned char *src, unsigned char *dst, unsigned int dst_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	unsigned int last = dst_size / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	for (i = 0; i < last; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		*dst++ = src[i] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		*dst++ = src[i] >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) static 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) unsigned char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) demunge_buf (unsigned char *src, unsigned char *dst, unsigned int src_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	unsigned char *end = src + src_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	end = src + src_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	/* NOTE: src and dst *CAN* point to the same address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	for (i = 0; src != end; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		dst[i] = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		dst[i] |= (*src++)<<7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) WaveFront: sample, patch and program management.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) wavefront_delete_sample (snd_wavefront_t *dev, int sample_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	unsigned char wbuf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	wbuf[0] = sample_num & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	wbuf[1] = sample_num >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	if ((x = snd_wavefront_cmd (dev, WFC_DELETE_SAMPLE, NULL, wbuf)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		dev->sample_status[sample_num] = WF_ST_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	return x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) wavefront_get_sample_status (snd_wavefront_t *dev, int assume_rom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	unsigned char rbuf[32], wbuf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	unsigned int    sc_real, sc_alias, sc_multi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	/* check sample status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	if (snd_wavefront_cmd (dev, WFC_GET_NSAMPLES, rbuf, wbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		snd_printk ("cannot request sample count.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	} 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	sc_real = sc_alias = sc_multi = dev->samples_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	for (i = 0; i < WF_MAX_SAMPLE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		wbuf[0] = i & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		wbuf[1] = i >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		if (snd_wavefront_cmd (dev, WFC_IDENTIFY_SAMPLE_TYPE, rbuf, wbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			snd_printk(KERN_WARNING "cannot identify sample "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 				   "type of slot %d\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 			dev->sample_status[i] = WF_ST_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		dev->sample_status[i] = (WF_SLOT_FILLED|rbuf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		if (assume_rom) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 			dev->sample_status[i] |= WF_SLOT_ROM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		switch (rbuf[0] & WF_ST_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		case WF_ST_SAMPLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			sc_real++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		case WF_ST_MULTISAMPLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 			sc_multi++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		case WF_ST_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 			sc_alias++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		case WF_ST_EMPTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			snd_printk ("unknown sample type for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 				    "slot %d (0x%x)\n", 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 				    i, rbuf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		if (rbuf[0] != WF_ST_EMPTY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			dev->samples_used++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		} 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	snd_printk ("%d samples used (%d real, %d aliases, %d multi), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		    "%d empty\n", dev->samples_used, sc_real, sc_alias, sc_multi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		    WF_MAX_SAMPLE - dev->samples_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) wavefront_get_patch_status (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	unsigned char patchbuf[WF_PATCH_BYTES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	unsigned char patchnum[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	wavefront_patch *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	int i, x, cnt, cnt2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	for (i = 0; i < WF_MAX_PATCH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		patchnum[0] = i & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		patchnum[1] = i >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		if ((x = snd_wavefront_cmd (dev, WFC_UPLOAD_PATCH, patchbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 					patchnum)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			dev->patch_status[i] |= WF_SLOT_FILLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 			p = (wavefront_patch *) patchbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			dev->sample_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 				[p->sample_number|(p->sample_msb<<7)] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 				WF_SLOT_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		} else if (x == 3) { /* Bad patch number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 			dev->patch_status[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 			snd_printk ("upload patch "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 				    "error 0x%x\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			dev->patch_status[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	/* program status has already filled in slot_used bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	for (i = 0, cnt = 0, cnt2 = 0; i < WF_MAX_PATCH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		if (dev->patch_status[i] & WF_SLOT_FILLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		if (dev->patch_status[i] & WF_SLOT_USED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			cnt2++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	snd_printk ("%d patch slots filled, %d in use\n", cnt, cnt2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) wavefront_get_program_status (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	unsigned char progbuf[WF_PROGRAM_BYTES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	wavefront_program prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	unsigned char prognum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	int i, x, l, cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	for (i = 0; i < WF_MAX_PROGRAM; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		prognum = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		if ((x = snd_wavefront_cmd (dev, WFC_UPLOAD_PROGRAM, progbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 					&prognum)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			dev->prog_status[i] |= WF_SLOT_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			demunge_buf (progbuf, (unsigned char *) &prog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 				     WF_PROGRAM_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			for (l = 0; l < WF_NUM_LAYERS; l++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 				if (prog.layer[l].mute) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 					dev->patch_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 						[prog.layer[l].patch_number] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 						WF_SLOT_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		} else if (x == 1) { /* Bad program number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			dev->prog_status[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 			snd_printk ("upload program "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 				    "error 0x%x\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 			dev->prog_status[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	for (i = 0, cnt = 0; i < WF_MAX_PROGRAM; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		if (dev->prog_status[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 			cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	snd_printk ("%d programs slots in use\n", cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) wavefront_send_patch (snd_wavefront_t *dev, wavefront_patch_info *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	unsigned char buf[WF_PATCH_BYTES+2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	unsigned char *bptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	DPRINT (WF_DEBUG_LOAD_PATCH, "downloading patch %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 				      header->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (header->number >= ARRAY_SIZE(dev->patch_status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	dev->patch_status[header->number] |= WF_SLOT_FILLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	bptr = munge_int32 (header->number, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	munge_buf ((unsigned char *)&header->hdr.p, bptr, WF_PATCH_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PATCH, NULL, buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		snd_printk ("download patch failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) wavefront_send_program (snd_wavefront_t *dev, wavefront_patch_info *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	unsigned char buf[WF_PROGRAM_BYTES+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	DPRINT (WF_DEBUG_LOAD_PATCH, "downloading program %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		header->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	if (header->number >= ARRAY_SIZE(dev->prog_status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	dev->prog_status[header->number] = WF_SLOT_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	/* XXX need to zero existing SLOT_USED bit for program_status[i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	   where `i' is the program that's being (potentially) overwritten.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	for (i = 0; i < WF_NUM_LAYERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		if (header->hdr.pr.layer[i].mute) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 			dev->patch_status[header->hdr.pr.layer[i].patch_number] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 				WF_SLOT_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			/* XXX need to mark SLOT_USED for sample used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			   patch_number, but this means we have to load it. Ick.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	buf[0] = header->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	munge_buf ((unsigned char *)&header->hdr.pr, &buf[1], WF_PROGRAM_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_PROGRAM, NULL, buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		snd_printk ("download patch failed\n");	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) wavefront_freemem (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	char rbuf[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (snd_wavefront_cmd (dev, WFC_REPORT_FREE_MEMORY, rbuf, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		snd_printk ("can't get memory stats.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		return demunge_int32 (rbuf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) wavefront_send_sample (snd_wavefront_t *dev, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		       wavefront_patch_info *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		       u16 __user *dataptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		       int data_is_unsigned)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	/* samples are downloaded via a 16-bit wide i/o port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	   (you could think of it as 2 adjacent 8-bit wide ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	   but its less efficient that way). therefore, all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	   the blocksizes and so forth listed in the documentation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	   and used conventionally to refer to sample sizes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	   which are given in 8-bit units (bytes), need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	   divided by 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)         */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	u16 sample_short = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	u16 __user *data_end = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	const unsigned int max_blksize = 4096/2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	unsigned int written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	unsigned int blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	int dma_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	int blocknum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	unsigned char sample_hdr[WF_SAMPLE_HDR_BYTES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	unsigned char *shptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	int skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	int initial_skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	DPRINT (WF_DEBUG_LOAD_PATCH, "sample %sdownload for slot %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 				      "type %d, %d bytes from 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 				      header->size ? "" : "header ", 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 				      header->number, header->subkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 				      header->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 				      (unsigned long) header->dataptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	if (header->number == WAVEFRONT_FIND_FREE_SAMPLE_SLOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		if ((x = wavefront_find_free_sample (dev)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		snd_printk ("unspecified sample => %d\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		header->number = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (header->number >= WF_MAX_SAMPLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	if (header->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		/* XXX it's a debatable point whether or not RDONLY semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		   on the ROM samples should cover just the sample data or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		   the sample header. For now, it only covers the sample data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		   so anyone is free at all times to rewrite sample headers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		   My reason for this is that we have the sample headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		   available in the WFB file for General MIDI, and so these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		   can always be reset if needed. The sample data, however,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		   cannot be recovered without a complete reset and firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		   reload of the ICS2115, which is a very expensive operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		   So, doing things this way allows us to honor the notion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		   "RESETSAMPLES" reasonably cheaply. Note however, that this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		   is done purely at user level: there is no WFB parser in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		   this driver, and so a complete reset (back to General MIDI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		   or theoretically some other configuration) is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		   responsibility of the user level library. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		   To try to do this in the kernel would be a little
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		   crazy: we'd need 158K of kernel space just to hold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		   a copy of the patch/program/sample header data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		if (dev->rom_samples_rdonly) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			if (dev->sample_status[header->number] & WF_SLOT_ROM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 				snd_printk ("sample slot %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 					    "write protected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 					    header->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 				return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		wavefront_delete_sample (dev, header->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	if (header->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		dev->freemem = wavefront_freemem (dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		if (dev->freemem < (int)header->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 			snd_printk ("insufficient memory to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 				    "load %d byte sample.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 				    header->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	skip = WF_GET_CHANNEL(&header->hdr.s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (skip > 0 && header->hdr.s.SampleResolution != LINEAR_16BIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		snd_printk ("channel selection only "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			    "possible on 16-bit samples");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	switch (skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		initial_skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		skip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		initial_skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		skip = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		initial_skip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		skip = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		initial_skip = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		skip = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		initial_skip = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		skip = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		initial_skip = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		skip = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		initial_skip = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		skip = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	DPRINT (WF_DEBUG_LOAD_PATCH, "channel selection: %d => "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 				      "initial skip = %d, skip = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 				      WF_GET_CHANNEL (&header->hdr.s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 				      initial_skip, skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	/* Be safe, and zero the "Unused" bits ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	WF_SET_CHANNEL(&header->hdr.s, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	/* adjust size for 16 bit samples by dividing by two.  We always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	   send 16 bits per write, even for 8 bit samples, so the length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	   is always half the size of the sample data in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	length = header->size / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	/* the data we're sent has not been munged, and in fact, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	   header we have to send isn't just a munged copy either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	   so, build the sample header right here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	shptr = &sample_hdr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	shptr = munge_int32 (header->number, shptr, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	if (header->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		shptr = munge_int32 (length, shptr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	/* Yes, a 4 byte result doesn't contain all of the offset bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	   but the offset only uses 24 bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	shptr = munge_int32 (*((u32 *) &header->hdr.s.sampleStartOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 			     shptr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	shptr = munge_int32 (*((u32 *) &header->hdr.s.loopStartOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			     shptr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	shptr = munge_int32 (*((u32 *) &header->hdr.s.loopEndOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			     shptr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	shptr = munge_int32 (*((u32 *) &header->hdr.s.sampleEndOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 			     shptr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	/* This one is truly weird. What kind of weirdo decided that in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	   a system dominated by 16 and 32 bit integers, they would use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	   a just 12 bits ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	shptr = munge_int32 (header->hdr.s.FrequencyBias, shptr, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	/* Why is this nybblified, when the MSB is *always* zero ? 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	   Anyway, we can't take address of bitfield, so make a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	   good-faith guess at where it starts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	shptr = munge_int32 (*(&header->hdr.s.FrequencyBias+1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			     shptr, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (snd_wavefront_cmd (dev, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 			   header->size ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 			   WFC_DOWNLOAD_SAMPLE : WFC_DOWNLOAD_SAMPLE_HEADER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 			   NULL, sample_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		snd_printk ("sample %sdownload refused.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 			    header->size ? "" : "header ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	if (header->size == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		goto sent; /* Sorry. Just had to have one somewhere */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	data_end = dataptr + length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	/* Do any initial skip over an unused channel's data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	dataptr += initial_skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	for (written = 0, blocknum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	     written < length; written += max_blksize, blocknum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		if ((length - written) > max_blksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 			blocksize = max_blksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 			/* round to nearest 16-byte value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			blocksize = ALIGN(length - written, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_BLOCK, NULL, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 			snd_printk ("download block "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 				    "request refused.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		for (i = 0; i < blocksize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			if (dataptr < data_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 				__get_user (sample_short, dataptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 				dataptr += skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 				if (data_is_unsigned) { /* GUS ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 					if (WF_SAMPLE_IS_8BIT(&header->hdr.s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 						/* 8 bit sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 						 resolution, sign
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 						 extend both bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 						*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 						((unsigned char*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 						 &sample_short)[0] += 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 						((unsigned char*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 						 &sample_short)[1] += 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 						/* 16 bit sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 						 resolution, sign
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 						 extend the MSB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 						*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 						sample_short += 0x7fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 				/* In padding section of final block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 				   Don't fetch unsupplied data from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 				   user space, just continue with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 				   whatever the final value was.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			if (i < blocksize - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 				outw (sample_short, dev->block_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 				outw (sample_short, dev->last_block_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		/* Get "DMA page acknowledge", even though its really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		   nothing to do with DMA at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		if ((dma_ack = wavefront_read (dev)) != WF_DMA_ACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 			if (dma_ack == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 				snd_printk ("upload sample "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 					    "DMA ack timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 				snd_printk ("upload sample "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 					    "DMA ack error 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 					    dma_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_SAMPLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	/* Note, label is here because sending the sample header shouldn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	   alter the sample_status info at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)  sent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) wavefront_send_alias (snd_wavefront_t *dev, wavefront_patch_info *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	unsigned char alias_hdr[WF_ALIAS_BYTES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	DPRINT (WF_DEBUG_LOAD_PATCH, "download alias, %d is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 				      "alias for %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 				      header->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 				      header->hdr.a.OriginalSample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	if (header->number >= WF_MAX_SAMPLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	munge_int32 (header->number, &alias_hdr[0], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	munge_int32 (header->hdr.a.OriginalSample, &alias_hdr[2], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	munge_int32 (*((unsigned int *)&header->hdr.a.sampleStartOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 		     &alias_hdr[4], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	munge_int32 (*((unsigned int *)&header->hdr.a.loopStartOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		     &alias_hdr[8], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	munge_int32 (*((unsigned int *)&header->hdr.a.loopEndOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		     &alias_hdr[12], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	munge_int32 (*((unsigned int *)&header->hdr.a.sampleEndOffset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		     &alias_hdr[16], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	munge_int32 (header->hdr.a.FrequencyBias, &alias_hdr[20], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	munge_int32 (*(&header->hdr.a.FrequencyBias+1), &alias_hdr[23], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		snd_printk ("download alias failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_ALIAS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) wavefront_send_multisample (snd_wavefront_t *dev, wavefront_patch_info *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	int num_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	unsigned char *msample_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	if (header->number >= WF_MAX_SAMPLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	msample_hdr = kmalloc(WF_MSAMPLE_BYTES, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	if (! msample_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	munge_int32 (header->number, &msample_hdr[0], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	/* You'll recall at this point that the "number of samples" value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	   in a wavefront_multisample struct is actually the log2 of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	   real number of samples.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	num_samples = (1<<(header->hdr.ms.NumberOfSamples&7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	msample_hdr[2] = (unsigned char) header->hdr.ms.NumberOfSamples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	DPRINT (WF_DEBUG_LOAD_PATCH, "multi %d with %d=%d samples\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 				      header->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 				      header->hdr.ms.NumberOfSamples,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 				      num_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	for (i = 0; i < num_samples; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 		DPRINT(WF_DEBUG_LOAD_PATCH|WF_DEBUG_DATA, "sample[%d] = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		       i, header->hdr.ms.SampleNumber[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		munge_int32 (header->hdr.ms.SampleNumber[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		     &msample_hdr[3+(i*2)], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	/* Need a hack here to pass in the number of bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	   to be written to the synth. This is ugly, and perhaps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	   one day, I'll fix it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_MULTISAMPLE, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			   (unsigned char *) (long) ((num_samples*2)+3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 			   msample_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		snd_printk ("download of multisample failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		kfree(msample_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	dev->sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_MULTISAMPLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	kfree(msample_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) wavefront_fetch_multisample (snd_wavefront_t *dev, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 			     wavefront_patch_info *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	unsigned char log_ns[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	unsigned char number[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	int num_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	munge_int32 (header->number, number, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	if (snd_wavefront_cmd (dev, WFC_UPLOAD_MULTISAMPLE, log_ns, number)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		snd_printk ("upload multisample failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	DPRINT (WF_DEBUG_DATA, "msample %d has %d samples\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 				header->number, log_ns[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	header->hdr.ms.NumberOfSamples = log_ns[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	/* get the number of samples ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	num_samples = (1 << log_ns[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	for (i = 0; i < num_samples; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		char d[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		if ((val = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 			snd_printk ("upload multisample failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 				    "during sample loop.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		d[0] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		if ((val = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 			snd_printk ("upload multisample failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 				    "during sample loop.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		d[1] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		header->hdr.ms.SampleNumber[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 			demunge_int32 ((unsigned char *) d, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		DPRINT (WF_DEBUG_DATA, "msample sample[%d] = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 					i, header->hdr.ms.SampleNumber[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) wavefront_send_drum (snd_wavefront_t *dev, wavefront_patch_info *header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	unsigned char drumbuf[WF_DRUM_BYTES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	wavefront_drum *drum = &header->hdr.d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	DPRINT (WF_DEBUG_LOAD_PATCH, "downloading edrum for MIDI "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		"note %d, patch = %d\n", 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		header->number, drum->PatchNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	drumbuf[0] = header->number & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		munge_int32 (((unsigned char *)drum)[i], &drumbuf[1+(i*2)], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	if (snd_wavefront_cmd (dev, WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		snd_printk ("download drum failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) static int 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) wavefront_find_free_sample (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	for (i = 0; i < WF_MAX_SAMPLE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		if (!(dev->sample_status[i] & WF_SLOT_FILLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	snd_printk ("no free sample slots!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) static int 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) wavefront_find_free_patch (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	for (i = 0; i < WF_MAX_PATCH; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		if (!(dev->patch_status[i] & WF_SLOT_FILLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	snd_printk ("no free patch slots!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) wavefront_load_patch (snd_wavefront_t *dev, const char __user *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	wavefront_patch_info *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	header = kmalloc(sizeof(*header), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	if (! header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	if (copy_from_user (header, addr, sizeof(wavefront_patch_info) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 			    sizeof(wavefront_any))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		snd_printk ("bad address for load patch.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		goto __error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	DPRINT (WF_DEBUG_LOAD_PATCH, "download "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 				      "Sample type: %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 				      "Sample number: %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 				      "Sample size: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 				      header->subkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 				      header->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 				      header->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	switch (header->subkey) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	case WF_ST_SAMPLE:  /* sample or sample_header, based on patch->size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		if (copy_from_user (&header->hdr.s, header->hdrptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 				    sizeof (wavefront_sample))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		err = wavefront_send_sample (dev, header, header->dataptr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	case WF_ST_MULTISAMPLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		if (copy_from_user (&header->hdr.s, header->hdrptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 				    sizeof (wavefront_multisample))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		err = wavefront_send_multisample (dev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	case WF_ST_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		if (copy_from_user (&header->hdr.a, header->hdrptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 				    sizeof (wavefront_alias))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		err = wavefront_send_alias (dev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	case WF_ST_DRUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		if (copy_from_user (&header->hdr.d, header->hdrptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 				    sizeof (wavefront_drum))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 		err = wavefront_send_drum (dev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	case WF_ST_PATCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		if (copy_from_user (&header->hdr.p, header->hdrptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 				    sizeof (wavefront_patch))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		err = wavefront_send_patch (dev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	case WF_ST_PROGRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		if (copy_from_user (&header->hdr.pr, header->hdrptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 				    sizeof (wavefront_program))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		err = wavefront_send_program (dev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		snd_printk ("unknown patch type %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			    header->subkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)  __error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	kfree(header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) WaveFront: hardware-dependent interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) process_sample_hdr (u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	wavefront_sample s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	u8 *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	ptr = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	/* The board doesn't send us an exact copy of a "wavefront_sample"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	   in response to an Upload Sample Header command. Instead, we 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	   have to convert the data format back into our data structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	   just as in the Download Sample command, where we have to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	   something very similar in the reverse direction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	*((u32 *) &s.sampleStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	*((u32 *) &s.loopStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	*((u32 *) &s.loopEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	*((u32 *) &s.sampleEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	*((u32 *) &s.FrequencyBias) = demunge_int32 (ptr, 3); ptr += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	s.SampleResolution = *ptr & 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	s.Loop = *ptr & 0x8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	s.Bidirectional = *ptr & 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	s.Reverse = *ptr & 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	/* Now copy it back to where it came from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	memcpy (buf, (unsigned char *) &s, sizeof (wavefront_sample));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) wavefront_synth_control (snd_wavefront_card_t *acard, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 			 wavefront_control *wc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	snd_wavefront_t *dev = &acard->wavefront;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	unsigned char patchnumbuf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	DPRINT (WF_DEBUG_CMD, "synth control with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		"cmd 0x%x\n", wc->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	/* Pre-handling of or for various commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	switch (wc->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	case WFC_DISABLE_INTERRUPTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 		snd_printk ("interrupts disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 		outb (0x80|0x20, dev->control_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 		dev->interrupts_are_midi = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	case WFC_ENABLE_INTERRUPTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		snd_printk ("interrupts enabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 		outb (0x80|0x40|0x20, dev->control_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		dev->interrupts_are_midi = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	case WFC_INTERRUPT_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 		wc->rbuf[0] = dev->interrupts_are_midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	case WFC_ROMSAMPLES_RDONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 		dev->rom_samples_rdonly = wc->wbuf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		wc->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	case WFC_IDENTIFY_SLOT_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		i = wc->wbuf[0] | (wc->wbuf[1] << 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		if (i <0 || i >= WF_MAX_SAMPLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 			snd_printk ("invalid slot ID %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 				i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 			wc->status = EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 		wc->rbuf[0] = dev->sample_status[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		wc->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	case WFC_DEBUG_DRIVER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		dev->debug = wc->wbuf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		snd_printk ("debug = 0x%x\n", dev->debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	case WFC_UPLOAD_PATCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		munge_int32 (*((u32 *) wc->wbuf), patchnumbuf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		memcpy (wc->wbuf, patchnumbuf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	case WFC_UPLOAD_MULTISAMPLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		/* multisamples have to be handled differently, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		   cannot be dealt with properly by snd_wavefront_cmd() alone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		wc->status = wavefront_fetch_multisample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 			(dev, (wavefront_patch_info *) wc->rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	case WFC_UPLOAD_SAMPLE_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		snd_printk ("support for sample alias upload "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 			"being considered.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		wc->status = EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	wc->status = snd_wavefront_cmd (dev, wc->cmd, wc->rbuf, wc->wbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	/* Post-handling of certain commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	   In particular, if the command was an upload, demunge the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	   so that the user-level doesn't have to think about it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	if (wc->status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 		switch (wc->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 			/* intercept any freemem requests so that we know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 			   we are always current with the user-level view
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 			   of things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		case WFC_REPORT_FREE_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 			dev->freemem = demunge_int32 (wc->rbuf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		case WFC_UPLOAD_PATCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 			demunge_buf (wc->rbuf, wc->rbuf, WF_PATCH_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		case WFC_UPLOAD_PROGRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 			demunge_buf (wc->rbuf, wc->rbuf, WF_PROGRAM_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		case WFC_UPLOAD_EDRUM_PROGRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 			demunge_buf (wc->rbuf, wc->rbuf, WF_DRUM_BYTES - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 		case WFC_UPLOAD_SAMPLE_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 			process_sample_hdr (wc->rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		case WFC_UPLOAD_SAMPLE_ALIAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 			snd_printk ("support for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 				    "sample aliases still "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 				    "being considered.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		case WFC_VMIDI_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			snd_wavefront_midi_disable_virtual (acard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 		case WFC_VMIDI_ON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 			snd_wavefront_midi_enable_virtual (acard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) int 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) snd_wavefront_synth_open (struct snd_hwdep *hw, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	if (!try_module_get(hw->card->module))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	file->private_data = hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) int 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) snd_wavefront_synth_release (struct snd_hwdep *hw, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	module_put(hw->card->module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) snd_wavefront_synth_ioctl (struct snd_hwdep *hw, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 			   unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	snd_wavefront_t *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	snd_wavefront_card_t *acard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	wavefront_control *wc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	card = (struct snd_card *) hw->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	if (snd_BUG_ON(!card))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	if (snd_BUG_ON(!card->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	acard = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	dev = &acard->wavefront;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	case WFCTL_LOAD_SPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		if (wavefront_load_patch (dev, argp) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	case WFCTL_WFCMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		wc = memdup_user(argp, sizeof(*wc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		if (IS_ERR(wc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 			return PTR_ERR(wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		if (wavefront_synth_control (acard, wc) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 			err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		else if (copy_to_user (argp, wc, sizeof (*wc)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 		kfree(wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) /***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) /*  WaveFront: interface for card-level wavefront module               */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) /***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) snd_wavefront_internal_interrupt (snd_wavefront_card_t *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	snd_wavefront_t *dev = &card->wavefront;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	   Some comments on interrupts. I attempted a version of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	   driver that used interrupts throughout the code instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	   doing busy and/or sleep-waiting. Alas, it appears that once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	   the Motorola firmware is downloaded, the card *never*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	   generates an RX interrupt. These are successfully generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	   during firmware loading, and after that wavefront_status()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	   reports that an interrupt is pending on the card from time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	   to time, but it never seems to be delivered to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	   driver. Note also that wavefront_status() continues to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	   report that RX interrupts are enabled, suggesting that I
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	   didn't goof up and disable them by mistake.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	   Thus, I stepped back to a prior version of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	   wavefront_wait(), the only place where this really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	   matters. Its sad, but I've looked through the code to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	   on things, and I really feel certain that the Motorola
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	   firmware prevents RX-ready interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	if ((wavefront_status(dev) & (STAT_INTR_READ|STAT_INTR_WRITE)) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	spin_lock(&dev->irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	dev->irq_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	dev->irq_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	spin_unlock(&dev->irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	wake_up(&dev->interrupt_sleeper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) /* STATUS REGISTER 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 0 Host Rx Interrupt Enable (1=Enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 1 Host Rx Register Full (1=Full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 2 Host Rx Interrupt Pending (1=Interrupt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 3 Unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 4 Host Tx Interrupt (1=Enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 5 Host Tx Register empty (1=Empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 6 Host Tx Interrupt Pending (1=Interrupt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 7 Unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) snd_wavefront_interrupt_bits (int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	int bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	switch (irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	case 9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		bits = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 		bits = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	case 12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		bits = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	case 15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		bits = 0x18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 		snd_printk ("invalid IRQ %d\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		bits = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	return bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) wavefront_should_cause_interrupt (snd_wavefront_t *dev, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 				  int val, int port, unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	wait_queue_entry_t wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	init_waitqueue_entry(&wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	spin_lock_irq(&dev->irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	add_wait_queue(&dev->interrupt_sleeper, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	dev->irq_ok = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	outb (val,port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	spin_unlock_irq(&dev->irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	while (!dev->irq_ok && time_before(jiffies, timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 		schedule_timeout_uninterruptible(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 		barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) wavefront_reset_to_cleanliness (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	int bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	int hwv[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	/* IRQ already checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	bits = snd_wavefront_interrupt_bits (dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	/* try reset of port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	outb (0x0, dev->control_port); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	/* At this point, the board is in reset, and the H/W initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	   register is accessed at the same address as the data port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)      
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	   Bit 7 - Enable IRQ Driver	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	   0 - Tri-state the Wave-Board drivers for the PC Bus IRQs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	   1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)      
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	   Bit 6 - MIDI Interface Select
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	   0 - Use the MIDI Input from the 26-pin WaveBlaster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	   compatible header as the serial MIDI source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	   1 - Use the MIDI Input from the 9-pin D connector as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	   serial MIDI source.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829)      
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	   Bits 5:3 - IRQ Selection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	   0 0 0 - IRQ 2/9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	   0 0 1 - IRQ 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	   0 1 0 - IRQ 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	   0 1 1 - IRQ 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	   1 0 0 - Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	   1 0 1 - Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	   1 1 0 - Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	   1 1 1 - Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)      
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	   Bits 2:1 - Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	   Bit 0 - Disable Boot ROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	   0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	   1 - memory accesses to 03FC30-03FFFFH are directed to external 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	   storage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)      
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	/* configure hardware: IRQ, enable interrupts, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	   plus external 9-pin MIDI interface selected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	outb (0x80 | 0x40 | bits, dev->data_port);	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	/* CONTROL REGISTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	   0 Host Rx Interrupt Enable (1=Enabled)      0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	   1 Unused                                    0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	   2 Unused                                    0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	   3 Unused                                    0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	   4 Host Tx Interrupt Enable                 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	   5 Mute (0=Mute; 1=Play)                    0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	   6 Master Interrupt Enable (1=Enabled)      0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	   7 Master Reset (0=Reset; 1=Run)            0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	   Take us out of reset, mute output, master + TX + RX interrupts on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	   We'll get an interrupt presumably to tell us that the TX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	   register is clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	wavefront_should_cause_interrupt(dev, 0x80|0x40|0x10|0x1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 					 dev->control_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 					 (reset_time*HZ)/100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	/* Note: data port is now the data port, not the h/w initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	   port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	if (!dev->irq_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 		snd_printk ("intr not received after h/w un-reset.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	} 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	/* Note: data port is now the data port, not the h/w initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	   port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	   At this point, only "HW VERSION" or "DOWNLOAD OS" commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	   will work. So, issue one of them, and wait for TX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	   interrupt. This can take a *long* time after a cold boot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	   while the ISC ROM does its RAM test. The SDK says up to 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	   seconds - with 12MB of RAM on a Tropez+, it takes a lot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	   longer than that (~16secs). Note that the card understands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	   the difference between a warm and a cold boot, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	   subsequent ISC2115 reboots (say, caused by module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	   reloading) will get through this much faster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	   XXX Interesting question: why is no RX interrupt received first ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	wavefront_should_cause_interrupt(dev, WFC_HARDWARE_VERSION, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 					 dev->data_port, ramcheck_time*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	if (!dev->irq_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 		snd_printk ("post-RAM-check interrupt not received.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	} 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	if (!wavefront_wait (dev, STAT_CAN_READ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 		snd_printk ("no response to HW version cmd.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	if ((hwv[0] = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		snd_printk ("board not responding correctly.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	if (hwv[0] == 0xFF) { /* NAK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 		/* Board's RAM test failed. Try to read error code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		   and tell us about it either way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		if ((hwv[0] = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 			snd_printk ("on-board RAM test failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 				    "(bad error code).\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 			snd_printk ("on-board RAM test failed "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 				    "(error code: 0x%x).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 				hwv[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	/* We're OK, just get the next byte of the HW version response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	if ((hwv[1] = wavefront_read (dev)) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		snd_printk ("incorrect h/w response.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	snd_printk ("hardware version %d.%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 		    hwv[0], hwv[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948)      gone_bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	return (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) wavefront_download_firmware (snd_wavefront_t *dev, char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	const unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	int len, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	int section_cnt_downloaded = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	const struct firmware *firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	err = request_firmware(&firmware, path, dev->card->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 		snd_printk(KERN_ERR "firmware (%s) download failed!!!\n", path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	buf = firmware->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 		int section_length = *(signed char *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 		if (section_length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 		if (section_length < 0 || section_length > WF_SECTION_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 			snd_printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 				   "invalid firmware section length %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 				   section_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 			goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 		len++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 		if (firmware->size < len + section_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 			snd_printk(KERN_ERR "firmware section read error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 			goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 		/* Send command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 		if (wavefront_write(dev, WFC_DOWNLOAD_OS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 			goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 		for (; section_length; section_length--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 			if (wavefront_write(dev, *buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 				goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 			buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 			len++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 		/* get ACK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 		if (!wavefront_wait(dev, STAT_CAN_READ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 			snd_printk(KERN_ERR "time out for firmware ACK.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 			goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 		err = inb(dev->data_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 		if (err != WF_ACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 			snd_printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 				   "download of section #%d not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 				   "acknowledged, ack = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 				   section_cnt_downloaded + 1, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 			goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		section_cnt_downloaded++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	release_firmware(firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)  failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	release_firmware(firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 	snd_printk(KERN_ERR "firmware download failed!!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) wavefront_do_reset (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	char voices[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	if (wavefront_reset_to_cleanliness (dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 		snd_printk ("hw reset failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	if (dev->israw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 		if (wavefront_download_firmware (dev, ospath)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 			goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 		dev->israw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 		/* Wait for the OS to get running. The protocol for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 		   this is non-obvious, and was determined by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		   using port-IO tracing in DOSemu and some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 		   experimentation here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		   Rather than using timed waits, use interrupts creatively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		wavefront_should_cause_interrupt (dev, WFC_NOOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 						  dev->data_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 						  (osrun_time*HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 		if (!dev->irq_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 			snd_printk ("no post-OS interrupt.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 			goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		/* Now, do it again ! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		wavefront_should_cause_interrupt (dev, WFC_NOOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 						  dev->data_port, (10*HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		if (!dev->irq_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 			snd_printk ("no post-OS interrupt(2).\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 			goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		/* OK, no (RX/TX) interrupts any more, but leave mute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 		   in effect. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 		outb (0x80|0x40, dev->control_port); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	/* SETUPSND.EXE asks for sample memory config here, but since i
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	   have no idea how to interpret the result, we'll forget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	   about it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	if ((dev->freemem = wavefront_freemem (dev)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	snd_printk ("available DRAM %dk\n", dev->freemem / 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	if (wavefront_write (dev, 0xf0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 	    wavefront_write (dev, 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	    (wavefront_read (dev) < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 		dev->debug = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 		snd_printk ("MPU emulation mode not set.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	voices[0] = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	if (snd_wavefront_cmd (dev, WFC_SET_NVOICES, NULL, voices)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		snd_printk ("cannot set number of voices to 32.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		goto gone_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)  gone_bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	/* reset that sucker so that it doesn't bother us. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	outb (0x0, dev->control_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 	dev->interrupts_are_midi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) snd_wavefront_start (snd_wavefront_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 	int samples_are_from_rom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	/* IMPORTANT: assumes that snd_wavefront_detect() and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 	   wavefront_reset_to_cleanliness() has already been called 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	if (dev->israw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 		samples_are_from_rom = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		/* XXX is this always true ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 		samples_are_from_rom = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	if (dev->israw || fx_raw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 		if (wavefront_do_reset (dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	/* Check for FX device, present only on Tropez+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	dev->has_fx = (snd_wavefront_fx_detect (dev) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	if (dev->has_fx && fx_raw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 		snd_wavefront_fx_start (dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	wavefront_get_sample_status (dev, samples_are_from_rom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	wavefront_get_program_status (dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	wavefront_get_patch_status (dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	/* Start normal operation: unreset, master interrupt enabled, no mute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	outb (0x80|0x40|0x20, dev->control_port); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) snd_wavefront_detect (snd_wavefront_card_t *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	unsigned char   rbuf[4], wbuf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 	snd_wavefront_t *dev = &card->wavefront;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 	/* returns zero if a WaveFront card is successfully detected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	   negative otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	dev->israw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	dev->has_fx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	dev->debug = debug_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	dev->interrupts_are_midi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	dev->irq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	dev->rom_samples_rdonly = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	if (snd_wavefront_cmd (dev, WFC_FIRMWARE_VERSION, rbuf, wbuf) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 		dev->fw_version[0] = rbuf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		dev->fw_version[1] = rbuf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		snd_printk ("firmware %d.%d already loaded.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 			    rbuf[0], rbuf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		/* check that a command actually works */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183)       
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		if (snd_wavefront_cmd (dev, WFC_HARDWARE_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 				       rbuf, wbuf) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 			dev->hw_version[0] = rbuf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 			dev->hw_version[1] = rbuf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 			snd_printk ("not raw, but no "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 				    "hardware version!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		if (!wf_raw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 			snd_printk ("reloading firmware as you requested.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 			dev->israw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 		dev->israw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		snd_printk ("no response to firmware probe, assume raw.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) MODULE_FIRMWARE(DEFAULT_OSPATH);