diff options
Diffstat (limited to 'sound/pci/asihpi')
| -rw-r--r-- | sound/pci/asihpi/asihpi.c | 1430 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpi.h | 1288 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpi6000.c | 390 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpi6000.h | 2 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpi6205.c | 761 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpi6205.h | 28 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpi_internal.h | 1283 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpi_version.h | 32 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpicmn.c | 520 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpicmn.h | 39 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpidebug.c | 159 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpidebug.h | 325 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpidspcd.c | 160 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpidspcd.h | 70 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpifunc.c | 2607 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpimsginit.c | 24 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpimsginit.h | 14 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpimsgx.c | 227 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpimsgx.h | 2 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpioctl.c | 209 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpioctl.h | 8 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpios.c | 16 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpios.h | 28 | ||||
| -rw-r--r-- | sound/pci/asihpi/hpipcida.h | 2 | 
24 files changed, 3683 insertions, 5941 deletions
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c index c80b0b863c5..901c9490398 100644 --- a/sound/pci/asihpi/asihpi.c +++ b/sound/pci/asihpi/asihpi.c @@ -21,29 +21,13 @@   *  would appreciate it if you grant us the right to use those modifications   *  for any purpose including commercial applications.   */ -/* >0: print Hw params, timer vars. >1: print stream write/copy sizes  */ -#define REALLY_VERBOSE_LOGGING 0 - -#if REALLY_VERBOSE_LOGGING -#define VPRINTK1 snd_printd -#else -#define VPRINTK1(...) -#endif - -#if REALLY_VERBOSE_LOGGING > 1 -#define VPRINTK2 snd_printd -#else -#define VPRINTK2(...) -#endif - -#ifndef ASI_STYLE_NAMES -/* not sure how ALSA style name should look */ -#define ASI_STYLE_NAMES 1 -#endif  #include "hpi_internal.h" +#include "hpi_version.h"  #include "hpimsginit.h"  #include "hpioctl.h" +#include "hpicmn.h" +  #include <linux/pci.h>  #include <linux/init.h> @@ -51,6 +35,7 @@  #include <linux/slab.h>  #include <linux/time.h>  #include <linux/wait.h> +#include <linux/module.h>  #include <sound/core.h>  #include <sound/control.h>  #include <sound/pcm.h> @@ -60,15 +45,30 @@  #include <sound/tlv.h>  #include <sound/hwdep.h> -  MODULE_LICENSE("GPL");  MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>"); -MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx"); +MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx " +			HPI_VER_STRING); + +#if defined CONFIG_SND_DEBUG_VERBOSE +/** + * snd_printddd - very verbose debug printk + * @format: format string + * + * Works like snd_printk() for debugging purposes. + * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set. + * Must set snd module debug parameter to 3 to enable at runtime. + */ +#define snd_printddd(format, args...) \ +	__snd_printk(3, __FILE__, __LINE__, format, ##args) +#else +#define snd_printddd(format, args...) do { } while (0) +#endif  static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* index 0-MAX */  static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */ -static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; -static int enable_hpi_hwdep = 1; +static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; +static bool enable_hpi_hwdep = 1;  module_param_array(index, int, NULL, S_IRUGO);  MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard."); @@ -85,11 +85,11 @@ MODULE_PARM_DESC(enable_hpi_hwdep,  /* identify driver */  #ifdef KERNEL_ALSA_BUILD -static char *build_info = "built using headers from kernel source"; +static char *build_info = "Built using headers from kernel source";  module_param(build_info, charp, S_IRUGO);  MODULE_PARM_DESC(build_info, "built using headers from kernel source");  #else -static char *build_info = "built within ALSA source"; +static char *build_info = "Built within ALSA source";  module_param(build_info, charp, S_IRUGO);  MODULE_PARM_DESC(build_info, "built within ALSA source");  #endif @@ -100,17 +100,11 @@ static const int mixer_dump;  #define DEFAULT_SAMPLERATE 44100  static int adapter_fs = DEFAULT_SAMPLERATE; -static struct hpi_hsubsys *ss;	/* handle to HPI audio subsystem */ -  /* defaults */  #define PERIODS_MIN 2 -#define PERIOD_BYTES_MIN  2304 +#define PERIOD_BYTES_MIN  2048  #define BUFFER_BYTES_MAX (512 * 1024) -/*#define TIMER_MILLISECONDS 20 -#define FORCE_TIMER_JIFFIES ((TIMER_MILLISECONDS * HZ + 999)/1000) -*/ -  #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)  struct clk_source { @@ -129,22 +123,19 @@ struct clk_cache {  struct snd_card_asihpi {  	struct snd_card *card;  	struct pci_dev *pci; -	u16 adapter_index; -	u32 serial_number; -	u16 type; -	u16 version; -	u16 num_outstreams; -	u16 num_instreams; +	struct hpi_adapter *hpi;  	u32 h_mixer;  	struct clk_cache cc; -	u16 support_mmap; +	u16 can_dma;  	u16 support_grouping;  	u16 support_mrx;  	u16 update_interval_frames;  	u16 in_max_chans;  	u16 out_max_chans; +	u16 in_min_chans; +	u16 out_min_chans;  };  /* Per stream data */ @@ -152,11 +143,13 @@ struct snd_card_asihpi_pcm {  	struct timer_list timer;  	unsigned int respawn_timer;  	unsigned int hpi_buffer_attached; -	unsigned int pcm_size; -	unsigned int pcm_count; +	unsigned int buffer_bytes; +	unsigned int period_bytes;  	unsigned int bytes_per_sec; -	unsigned int pcm_irq_pos;	/* IRQ position */ -	unsigned int pcm_buf_pos;	/* position in buffer */ +	unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */ +	unsigned int pcm_buf_dma_ofs;	/* DMA R/W offset in buffer */ +	unsigned int pcm_buf_elapsed_dma_ofs;	/* DMA R/W offset in buffer */ +	unsigned int drained_count;  	struct snd_pcm_substream *substream;  	u32 h_stream;  	struct hpi_format format; @@ -167,7 +160,6 @@ struct snd_card_asihpi_pcm {  /* Functions to allow driver to give a buffer to HPI for busmastering */  static u16 hpi_stream_host_buffer_attach( -	struct hpi_hsubsys *hS,  	u32 h_stream,   /* handle to outstream. */  	u32 size_in_bytes, /* size in bytes of bus mastering buffer */  	u32 pci_address @@ -194,10 +186,7 @@ static u16 hpi_stream_host_buffer_attach(  	return hr.error;  } -static u16 hpi_stream_host_buffer_detach( -	struct hpi_hsubsys *hS, -	u32  h_stream -) +static u16 hpi_stream_host_buffer_detach(u32  h_stream)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -218,24 +207,23 @@ static u16 hpi_stream_host_buffer_detach(  	return hr.error;  } -static inline u16 hpi_stream_start(struct hpi_hsubsys *hS, u32 h_stream) +static inline u16 hpi_stream_start(u32 h_stream)  {  	if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM) -		return hpi_outstream_start(hS, h_stream); +		return hpi_outstream_start(h_stream);  	else -		return hpi_instream_start(hS, h_stream); +		return hpi_instream_start(h_stream);  } -static inline u16 hpi_stream_stop(struct hpi_hsubsys *hS, u32 h_stream) +static inline u16 hpi_stream_stop(u32 h_stream)  {  	if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM) -		return hpi_outstream_stop(hS, h_stream); +		return hpi_outstream_stop(h_stream);  	else -		return hpi_instream_stop(hS, h_stream); +		return hpi_instream_stop(h_stream);  }  static inline u16 hpi_stream_get_info_ex( -    struct hpi_hsubsys *hS,      u32 h_stream,      u16        *pw_state,      u32        *pbuffer_size, @@ -244,42 +232,43 @@ static inline u16 hpi_stream_get_info_ex(      u32        *pauxiliary_data  )  { +	u16 e;  	if (hpi_handle_object(h_stream)  ==  HPI_OBJ_OSTREAM) -		return hpi_outstream_get_info_ex(hS, h_stream, pw_state, +		e = hpi_outstream_get_info_ex(h_stream, pw_state,  					pbuffer_size, pdata_in_buffer,  					psample_count, pauxiliary_data);  	else -		return hpi_instream_get_info_ex(hS, h_stream, pw_state, +		e = hpi_instream_get_info_ex(h_stream, pw_state,  					pbuffer_size, pdata_in_buffer,  					psample_count, pauxiliary_data); +	return e;  } -static inline u16 hpi_stream_group_add(struct hpi_hsubsys *hS, +static inline u16 hpi_stream_group_add(  					u32 h_master,  					u32 h_stream)  {  	if (hpi_handle_object(h_master) ==  HPI_OBJ_OSTREAM) -		return hpi_outstream_group_add(hS, h_master, h_stream); +		return hpi_outstream_group_add(h_master, h_stream);  	else -		return hpi_instream_group_add(hS, h_master, h_stream); +		return hpi_instream_group_add(h_master, h_stream);  } -static inline u16 hpi_stream_group_reset(struct hpi_hsubsys *hS, -						u32 h_stream) +static inline u16 hpi_stream_group_reset(u32 h_stream)  {  	if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM) -		return hpi_outstream_group_reset(hS, h_stream); +		return hpi_outstream_group_reset(h_stream);  	else -		return hpi_instream_group_reset(hS, h_stream); +		return hpi_instream_group_reset(h_stream);  } -static inline u16 hpi_stream_group_get_map(struct hpi_hsubsys *hS, +static inline u16 hpi_stream_group_get_map(  				u32 h_stream, u32 *mo, u32 *mi)  {  	if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM) -		return hpi_outstream_group_get_map(hS, h_stream, mo, mi); +		return hpi_outstream_group_get_map(h_stream, mo, mi);  	else -		return hpi_instream_group_get_map(hS, h_stream, mo, mi); +		return hpi_instream_group_get_map(h_stream, mo, mi);  }  static u16 handle_error(u16 err, int line, char *filename) @@ -294,24 +283,28 @@ static u16 handle_error(u16 err, int line, char *filename)  #define hpi_handle_error(x)  handle_error(x, __LINE__, __FILE__)  /***************************** GENERAL PCM ****************/ -#if REALLY_VERBOSE_LOGGING -static void print_hwparams(struct snd_pcm_hw_params *p) -{ -	snd_printd("HWPARAMS \n"); -	snd_printd("samplerate %d \n", params_rate(p)); -	snd_printd("channels %d \n", params_channels(p)); -	snd_printd("format %d \n", params_format(p)); -	snd_printd("subformat %d \n", params_subformat(p)); -	snd_printd("buffer bytes %d \n", params_buffer_bytes(p)); -	snd_printd("period bytes %d \n", params_period_bytes(p)); -	snd_printd("access %d \n", params_access(p)); -	snd_printd("period_size %d \n", params_period_size(p)); -	snd_printd("periods %d \n", params_periods(p)); -	snd_printd("buffer_size %d \n", params_buffer_size(p)); + +static void print_hwparams(struct snd_pcm_substream *substream, +				struct snd_pcm_hw_params *p) +{ +	char name[16]; +	snd_pcm_debug_name(substream, name, sizeof(name)); +	snd_printd("%s HWPARAMS\n", name); +	snd_printd(" samplerate %d Hz\n", params_rate(p)); +	snd_printd(" channels %d\n", params_channels(p)); +	snd_printd(" format %d\n", params_format(p)); +	snd_printd(" subformat %d\n", params_subformat(p)); +	snd_printd(" buffer %d B\n", params_buffer_bytes(p)); +	snd_printd(" period %d B\n", params_period_bytes(p)); +	snd_printd(" access %d\n", params_access(p)); +	snd_printd(" period_size %d\n", params_period_size(p)); +	snd_printd(" periods %d\n", params_periods(p)); +	snd_printd(" buffer_size %d\n", params_buffer_size(p)); +	snd_printd(" %d B/s\n", params_rate(p) * +		params_channels(p) * +		snd_pcm_format_width(params_format(p)) / 8); +  } -#else -#define print_hwparams(x) -#endif  static snd_pcm_format_t hpi_to_alsa_formats[] = {  	-1,			/* INVALID */ @@ -335,7 +328,7 @@ static snd_pcm_format_t hpi_to_alsa_formats[] = {  	 */  	-1  #else -	/* SNDRV_PCM_FORMAT_S24_3LE */	/* { HPI_FORMAT_PCM24_SIGNED        15 */ +	/* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */  #endif  }; @@ -378,21 +371,21 @@ static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,  	} else {  		/* on cards without SRC,  		   valid rates are determined by sampleclock */ -		err = hpi_mixer_get_control(ss, asihpi->h_mixer, +		err = hpi_mixer_get_control(asihpi->h_mixer,  					  HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,  					  HPI_CONTROL_SAMPLECLOCK, &h_control);  		if (err) {  			snd_printk(KERN_ERR -				"no local sampleclock, err %d\n", err); +				"No local sampleclock, err %d\n", err);  		} -		for (idx = 0; idx < 100; idx++) { -			if (hpi_sample_clock_query_local_rate(ss, -				h_control, idx, &sample_rate)) { -				if (!idx) -					snd_printk(KERN_ERR -						"local rate query failed\n"); - +		for (idx = -1; idx < 100; idx++) { +			if (idx == -1) { +				if (hpi_sample_clock_get_sample_rate(h_control, +								&sample_rate)) +					continue; +			} else if (hpi_sample_clock_query_local_rate(h_control, +							idx, &sample_rate)) {  				break;  			} @@ -445,8 +438,6 @@ static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,  		}  	} -	/* printk(KERN_INFO "Supported rates %X %d %d\n", -	   rates, rate_min, rate_max); */  	pcmhw->rates = rates;  	pcmhw->rate_min = rate_min;  	pcmhw->rate_max = rate_max; @@ -463,7 +454,7 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,  	int width;  	unsigned int bytes_per_sec; -	print_hwparams(params); +	print_hwparams(substream, params);  	err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));  	if (err < 0)  		return err; @@ -471,46 +462,41 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,  	if (err)  		return err; -	VPRINTK1(KERN_INFO "format %d, %d chans, %d_hz\n", -				format, params_channels(params), -				params_rate(params)); -  	hpi_handle_error(hpi_format_create(&dpcm->format,  			params_channels(params),  			format, params_rate(params), 0, 0));  	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { -		if (hpi_instream_reset(ss, dpcm->h_stream) != 0) +		if (hpi_instream_reset(dpcm->h_stream) != 0)  			return -EINVAL; -		if (hpi_instream_set_format(ss, +		if (hpi_instream_set_format(  			dpcm->h_stream, &dpcm->format) != 0)  			return -EINVAL;  	}  	dpcm->hpi_buffer_attached = 0; -	if (card->support_mmap) { - -		err = hpi_stream_host_buffer_attach(ss, dpcm->h_stream, +	if (card->can_dma) { +		err = hpi_stream_host_buffer_attach(dpcm->h_stream,  			params_buffer_bytes(params),  runtime->dma_addr);  		if (err == 0) { -			snd_printd(KERN_INFO +			snd_printdd(  				"stream_host_buffer_attach succeeded %u %lu\n",  				params_buffer_bytes(params),  				(unsigned long)runtime->dma_addr);  		} else { -			snd_printd(KERN_INFO -					"stream_host_buffer_attach error %d\n", +			snd_printd("stream_host_buffer_attach error %d\n",  					err);  			return -ENOMEM;  		} -		err = hpi_stream_get_info_ex(ss, dpcm->h_stream, NULL, +		err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,  						&dpcm->hpi_buffer_attached,  						NULL, NULL, NULL); -		snd_printd(KERN_INFO "stream_host_buffer_attach status 0x%x\n", +		snd_printdd("stream_host_buffer_attach status 0x%x\n",  				dpcm->hpi_buffer_attached); +  	}  	bytes_per_sec = params_rate(params) * params_channels(params);  	width = snd_pcm_format_width(params_format(params)); @@ -520,16 +506,30 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,  		return -EINVAL;  	dpcm->bytes_per_sec = bytes_per_sec; -	dpcm->pcm_size = params_buffer_bytes(params); -	dpcm->pcm_count = params_period_bytes(params); -	snd_printd(KERN_INFO "pcm_size=%d, pcm_count=%d, bps=%d\n", -			dpcm->pcm_size, dpcm->pcm_count, bytes_per_sec); +	dpcm->buffer_bytes = params_buffer_bytes(params); +	dpcm->period_bytes = params_period_bytes(params); -	dpcm->pcm_irq_pos = 0; -	dpcm->pcm_buf_pos = 0;  	return 0;  } +static int +snd_card_asihpi_hw_free(struct snd_pcm_substream *substream) +{ +	struct snd_pcm_runtime *runtime = substream->runtime; +	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; +	if (dpcm->hpi_buffer_attached) +		hpi_stream_host_buffer_detach(dpcm->h_stream); + +	snd_pcm_lib_free_pages(substream); +	return 0; +} + +static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime) +{ +	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; +	kfree(dpcm); +} +  static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *  					    substream)  { @@ -537,9 +537,9 @@ static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *  	struct snd_card_asihpi_pcm *dpcm = runtime->private_data;  	int expiry; -	expiry = (dpcm->pcm_count * HZ / dpcm->bytes_per_sec); -	/* wait longer the first time, for samples to propagate */ -	expiry = max(expiry, 20); +	expiry = HZ / 200; +	/*? (dpcm->period_bytes * HZ / dpcm->bytes_per_sec); */ +	expiry = max(expiry, 1); /* don't let it be zero! */  	dpcm->timer.expires = jiffies + expiry;  	dpcm->respawn_timer = 1;  	add_timer(&dpcm->timer); @@ -561,38 +561,45 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,  	struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);  	struct snd_pcm_substream *s;  	u16 e; +	char name[16]; + +	snd_pcm_debug_name(substream, name, sizeof(name)); +	snd_printdd("%s trigger\n", name); -	snd_printd("trigger %dstream %d\n", -			substream->stream, substream->number);  	switch (cmd) {  	case SNDRV_PCM_TRIGGER_START:  		snd_pcm_group_for_each_entry(s, substream) { -			struct snd_card_asihpi_pcm *ds; -			ds = s->runtime->private_data; +			struct snd_pcm_runtime *runtime = s->runtime; +			struct snd_card_asihpi_pcm *ds = runtime->private_data;  			if (snd_pcm_substream_chip(s) != card)  				continue; -			if ((s->stream == SNDRV_PCM_STREAM_PLAYBACK) && -				(card->support_mmap)) { +			/* don't link Cap and Play */ +			if (substream->stream != s->stream) +				continue; + +			ds->drained_count = 0; +			if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {  				/* How do I know how much valid data is present -				* in buffer? Just guessing 2 periods, but if +				* in buffer? Must be at least one period! +				* Guessing 2 periods, but if  				* buffer is bigger it may contain even more  				* data??  				*/ -				unsigned int preload = ds->pcm_count * 2; -				VPRINTK2("preload %d\n", preload); +				unsigned int preload = ds->period_bytes * 1; +				snd_printddd("%d preload x%x\n", s->number, preload);  				hpi_handle_error(hpi_outstream_write_buf( -						ss, ds->h_stream, -						&s->runtime->dma_area[0], +						ds->h_stream, +						&runtime->dma_area[0],  						preload,  						&ds->format)); +				ds->pcm_buf_host_rw_ofs = preload;  			}  			if (card->support_grouping) { -				VPRINTK1("\t_group %dstream %d\n", s->stream, -						s->number); -				e = hpi_stream_group_add(ss, +				snd_printdd("%d group\n", s->number); +				e = hpi_stream_group_add(  					dpcm->h_stream,  					ds->h_stream);  				if (!e) { @@ -604,10 +611,12 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,  			} else  				break;  		} -		snd_printd("start\n"); +		snd_printdd("start\n");  		/* start the master stream */  		snd_card_asihpi_pcm_timer_start(substream); -		hpi_handle_error(hpi_stream_start(ss, dpcm->h_stream)); +		if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) || +			!card->can_dma) +			hpi_handle_error(hpi_stream_start(dpcm->h_stream));  		break;  	case SNDRV_PCM_TRIGGER_STOP: @@ -615,88 +624,71 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,  		snd_pcm_group_for_each_entry(s, substream) {  			if (snd_pcm_substream_chip(s) != card)  				continue; +			/* don't link Cap and Play */ +			if (substream->stream != s->stream) +				continue;  			/*? workaround linked streams don't  			transition to SETUP 20070706*/  			s->runtime->status->state = SNDRV_PCM_STATE_SETUP;  			if (card->support_grouping) { -				VPRINTK1("\t_group %dstream %d\n", s->stream, -					s->number); +				snd_printdd("%d group\n", s->number);  				snd_pcm_trigger_done(s, substream);  			} else  				break;  		} -		snd_printd("stop\n"); +		snd_printdd("stop\n");  		/* _prepare and _hwparams reset the stream */ -		hpi_handle_error(hpi_stream_stop(ss, dpcm->h_stream)); +		hpi_handle_error(hpi_stream_stop(dpcm->h_stream));  		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)  			hpi_handle_error( -				hpi_outstream_reset(ss, dpcm->h_stream)); +				hpi_outstream_reset(dpcm->h_stream));  		if (card->support_grouping) -			hpi_handle_error(hpi_stream_group_reset(ss, -						dpcm->h_stream)); +			hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));  		break;  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: -		snd_printd("pause release\n"); -		hpi_handle_error(hpi_stream_start(ss, dpcm->h_stream)); +		snd_printdd("pause release\n"); +		hpi_handle_error(hpi_stream_start(dpcm->h_stream));  		snd_card_asihpi_pcm_timer_start(substream);  		break;  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH: -		snd_printd("pause\n"); +		snd_printdd("pause\n");  		snd_card_asihpi_pcm_timer_stop(substream); -		hpi_handle_error(hpi_stream_stop(ss, dpcm->h_stream)); +		hpi_handle_error(hpi_stream_stop(dpcm->h_stream));  		break;  	default: -		snd_printd("\tINVALID\n"); +		snd_printd(KERN_ERR "\tINVALID\n");  		return -EINVAL;  	}  	return 0;  } -static int -snd_card_asihpi_hw_free(struct snd_pcm_substream *substream) -{ -	struct snd_pcm_runtime *runtime = substream->runtime; -	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	if (dpcm->hpi_buffer_attached) -		hpi_stream_host_buffer_detach(ss, dpcm->h_stream); - -	snd_pcm_lib_free_pages(substream); -	return 0; -} - -static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime) -{ -	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	kfree(dpcm); -} -  /*algorithm outline   Without linking degenerates to getting single stream pos etc   Without mmap 2nd loop degenerates to snd_pcm_period_elapsed  */  /* -buf_pos=get_buf_pos(s); +pcm_buf_dma_ofs=get_buf_pos(s);  for_each_linked_stream(s) { -	buf_pos=get_buf_pos(s); -	min_buf_pos = modulo_min(min_buf_pos, buf_pos, pcm_size) -	new_data = min(new_data, calc_new_data(buf_pos,irq_pos) +	pcm_buf_dma_ofs=get_buf_pos(s); +	min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes) +	new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)  }  timer.expires = jiffies + predict_next_period_ready(min_buf_pos);  for_each_linked_stream(s) { -	s->buf_pos = min_buf_pos; -	if (new_data > pcm_count) { +	s->pcm_buf_dma_ofs = min_buf_pos; +	if (new_data > period_bytes) {  		if (mmap) { -			irq_pos = (irq_pos + pcm_count) % pcm_size; +			irq_pos = (irq_pos + period_bytes) % buffer_bytes;  			if (playback) { -				write(pcm_count); +				write(period_bytes);  			} else { -				read(pcm_count); +				read(period_bytes);  			}  		}  		snd_pcm_period_elapsed(s); @@ -724,105 +716,184 @@ static inline unsigned int modulo_min(unsigned int a, unsigned int b,  static void snd_card_asihpi_timer_function(unsigned long data)  {  	struct snd_card_asihpi_pcm *dpcm = (struct snd_card_asihpi_pcm *)data; -	struct snd_card_asihpi *card = snd_pcm_substream_chip(dpcm->substream); +	struct snd_pcm_substream *substream = dpcm->substream; +	struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);  	struct snd_pcm_runtime *runtime;  	struct snd_pcm_substream *s;  	unsigned int newdata = 0; -	unsigned int buf_pos, min_buf_pos = 0; +	unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;  	unsigned int remdata, xfercount, next_jiffies;  	int first = 1; +	int loops = 0;  	u16 state; -	u32 buffer_size, data_avail, samples_played, aux; +	u32 buffer_size, bytes_avail, samples_played, on_card_bytes; +	char name[16]; + +	snd_pcm_debug_name(substream, name, sizeof(name)); + +	snd_printdd("%s snd_card_asihpi_timer_function\n", name);  	/* find minimum newdata and buffer pos in group */ -	snd_pcm_group_for_each_entry(s, dpcm->substream) { +	snd_pcm_group_for_each_entry(s, substream) {  		struct snd_card_asihpi_pcm *ds = s->runtime->private_data;  		runtime = s->runtime;  		if (snd_pcm_substream_chip(s) != card)  			continue; -		hpi_handle_error(hpi_stream_get_info_ex(ss, +		/* don't link Cap and Play */ +		if (substream->stream != s->stream) +			continue; + +		hpi_handle_error(hpi_stream_get_info_ex(  					ds->h_stream, &state, -					&buffer_size, &data_avail, -					&samples_played, &aux)); +					&buffer_size, &bytes_avail, +					&samples_played, &on_card_bytes));  		/* number of bytes in on-card buffer */ -		runtime->delay = aux; +		runtime->delay = on_card_bytes; -		if (state == HPI_STATE_DRAINED) { -			snd_printd(KERN_WARNING  "outstream %d drained\n", -					s->number); -			snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN); -			return; -		} +		if (!card->can_dma) +			on_card_bytes = bytes_avail;  		if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { -			buf_pos = frames_to_bytes(runtime, samples_played); -		} else { -			buf_pos = data_avail + ds->pcm_irq_pos; -		} +			pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail; +			if (state == HPI_STATE_STOPPED) { +				if (bytes_avail == 0) { +					hpi_handle_error(hpi_stream_start(ds->h_stream)); +					snd_printdd("P%d start\n", s->number); +					ds->drained_count = 0; +				} +			} else if (state == HPI_STATE_DRAINED) { +				snd_printd(KERN_WARNING "P%d drained\n", +						s->number); +				ds->drained_count++; +				if (ds->drained_count > 20) { +					unsigned long flags; +					snd_pcm_stream_lock_irqsave(s, flags); +					snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN); +					snd_pcm_stream_unlock_irqrestore(s, flags); +					continue; +				} +			} else { +				ds->drained_count = 0; +			} +		} else +			pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;  		if (first) {  			/* can't statically init min when wrap is involved */ -			min_buf_pos = buf_pos; -			newdata = (buf_pos - ds->pcm_irq_pos) % ds->pcm_size; +			min_buf_pos = pcm_buf_dma_ofs; +			newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;  			first = 0;  		} else {  			min_buf_pos = -				modulo_min(min_buf_pos, buf_pos, UINT_MAX+1L); +				modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);  			newdata = min( -				(buf_pos - ds->pcm_irq_pos) % ds->pcm_size, +				(pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,  				newdata);  		} -		VPRINTK1("PB timer hw_ptr x%04lX, appl_ptr x%04lX\n", +		snd_printdd("hw_ptr 0x%04lX, appl_ptr 0x%04lX\n",  			(unsigned long)frames_to_bytes(runtime,  						runtime->status->hw_ptr),  			(unsigned long)frames_to_bytes(runtime,  						runtime->control->appl_ptr)); -		VPRINTK1("%d S=%d, irq=%04X, pos=x%04X, left=x%04X," -			" aux=x%04X space=x%04X\n", s->number, -			state,	ds->pcm_irq_pos, buf_pos, (int)data_avail, -			(int)aux, buffer_size-data_avail); + +		snd_printdd("%d S=%d, " +			"rw=0x%04X, dma=0x%04X, left=0x%04X, " +			"aux=0x%04X space=0x%04X\n", +			s->number, state, +			ds->pcm_buf_host_rw_ofs, pcm_buf_dma_ofs, +			(int)bytes_avail, +			(int)on_card_bytes, buffer_size-bytes_avail); +		loops++;  	} +	pcm_buf_dma_ofs = min_buf_pos; -	remdata = newdata % dpcm->pcm_count; -	xfercount = newdata - remdata; /* a multiple of pcm_count */ -	next_jiffies = ((dpcm->pcm_count-remdata) * HZ / dpcm->bytes_per_sec)+1; -	next_jiffies = max(next_jiffies, 2U * HZ / 1000U); +	remdata = newdata % dpcm->period_bytes; +	xfercount = newdata - remdata; /* a multiple of period_bytes */ +	/* come back when on_card_bytes has decreased enough to allow +	   write to happen, or when data has been consumed to make another +	   period +	*/ +	if (xfercount && (on_card_bytes  > dpcm->period_bytes)) +		next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec); +	else +		next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec); + +	next_jiffies = max(next_jiffies, 1U);  	dpcm->timer.expires = jiffies + next_jiffies; -	VPRINTK1("jif %d buf pos x%04X newdata x%04X xc x%04X\n", -			next_jiffies, min_buf_pos, newdata, xfercount); +	snd_printdd("jif %d buf pos 0x%04X newdata 0x%04X xfer 0x%04X\n", +			next_jiffies, pcm_buf_dma_ofs, newdata, xfercount); -	snd_pcm_group_for_each_entry(s, dpcm->substream) { +	snd_pcm_group_for_each_entry(s, substream) {  		struct snd_card_asihpi_pcm *ds = s->runtime->private_data; -		ds->pcm_buf_pos = min_buf_pos; -		if (xfercount) { -			if (card->support_mmap) { -				ds->pcm_irq_pos = ds->pcm_irq_pos + xfercount; -				if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { -					VPRINTK2("write OS%d x%04x\n", +		/* don't link Cap and Play */ +		if (substream->stream != s->stream) +			continue; + +		ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs; + +		if (xfercount && +			/* Limit use of on card fifo for playback */ +			((on_card_bytes <= ds->period_bytes) || +			(s->stream == SNDRV_PCM_STREAM_CAPTURE))) + +		{ + +			unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes; +			unsigned int xfer1, xfer2; +			char *pd = &s->runtime->dma_area[buf_ofs]; + +			if (card->can_dma) { /* buffer wrap is handled at lower level */ +				xfer1 = xfercount; +				xfer2 = 0; +			} else { +				xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs); +				xfer2 = xfercount - xfer1; +			} + +			if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { +				snd_printddd("P%d write1 0x%04X 0x%04X\n", +					s->number, xfer1, buf_ofs); +				hpi_handle_error( +					hpi_outstream_write_buf( +						ds->h_stream, pd, xfer1, +						&ds->format)); + +				if (xfer2) { +					pd = s->runtime->dma_area; + +					snd_printddd("P%d write2 0x%04X 0x%04X\n",  							s->number, -							ds->pcm_count); +							xfercount - xfer1, buf_ofs);  					hpi_handle_error(  						hpi_outstream_write_buf( -							ss, ds->h_stream, -							&s->runtime-> -								dma_area[0], -							xfercount, +							ds->h_stream, pd, +							xfercount - xfer1,  							&ds->format)); -				} else { -					VPRINTK2("read IS%d x%04x\n", -						s->number, -						dpcm->pcm_count); +				} +			} else { +				snd_printddd("C%d read1 0x%04x\n", +					s->number, xfer1); +				hpi_handle_error( +					hpi_instream_read_buf( +						ds->h_stream, +						pd, xfer1)); +				if (xfer2) { +					pd = s->runtime->dma_area; +					snd_printddd("C%d read2 0x%04x\n", +						s->number, xfer2);  					hpi_handle_error(  						hpi_instream_read_buf( -							ss, ds->h_stream, -							NULL, xfercount)); +							ds->h_stream, +							pd, xfer2));  				} -			} /* else R/W will be handled by read/write callbacks */ +			} +			ds->pcm_buf_host_rw_ofs += xfercount; +			ds->pcm_buf_elapsed_dma_ofs += xfercount;  			snd_pcm_period_elapsed(s);  		}  	} @@ -835,7 +906,9 @@ static void snd_card_asihpi_timer_function(unsigned long data)  static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,  					  unsigned int cmd, void *arg)  { -	/* snd_printd(KERN_INFO "Playback ioctl %d\n", cmd); */ +	char name[16]; +	snd_pcm_debug_name(substream, name, sizeof(name)); +	snd_printddd(KERN_INFO "%s ioctl %d\n", name, cmd);  	return snd_pcm_lib_ioctl(substream, cmd, arg);  } @@ -845,12 +918,12 @@ static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *  	struct snd_pcm_runtime *runtime = substream->runtime;  	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	snd_printd(KERN_INFO "playback prepare %d\n", substream->number); - -	hpi_handle_error(hpi_outstream_reset(ss, dpcm->h_stream)); -	dpcm->pcm_irq_pos = 0; -	dpcm->pcm_buf_pos = 0; +	snd_printdd("P%d prepare\n", substream->number); +	hpi_handle_error(hpi_outstream_reset(dpcm->h_stream)); +	dpcm->pcm_buf_host_rw_ofs = 0; +	dpcm->pcm_buf_dma_ofs = 0; +	dpcm->pcm_buf_elapsed_dma_ofs = 0;  	return 0;  } @@ -860,89 +933,60 @@ snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)  	struct snd_pcm_runtime *runtime = substream->runtime;  	struct snd_card_asihpi_pcm *dpcm = runtime->private_data;  	snd_pcm_uframes_t ptr; +	char name[16]; +	snd_pcm_debug_name(substream, name, sizeof(name)); -	u32 samples_played; -	u16 err; - -	if (!snd_pcm_stream_linked(substream)) { -		/* NOTE, can use samples played for playback position here and -		* in timer fn because it LAGS the actual read pointer, and is a -		* better representation of actual playout position -		*/ -		err = hpi_outstream_get_info_ex(ss, dpcm->h_stream, NULL, -					NULL, NULL, -					&samples_played, NULL); -		hpi_handle_error(err); - -		dpcm->pcm_buf_pos = frames_to_bytes(runtime, samples_played); -	} -	/* else must return most conservative value found in timer func -	 * by looping over all streams -	 */ - -	ptr = bytes_to_frames(runtime, dpcm->pcm_buf_pos  % dpcm->pcm_size); -	VPRINTK2("playback_pointer=%04ld\n", (unsigned long)ptr); +	ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs  % dpcm->buffer_bytes); +	snd_printddd("%s pointer = 0x%04lx\n", name, (unsigned long)ptr);  	return ptr;  } -static void snd_card_asihpi_playback_format(struct snd_card_asihpi *asihpi, -						u32 h_stream, -						struct snd_pcm_hardware *pcmhw) +static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi, +						u32 h_stream)  {  	struct hpi_format hpi_format;  	u16 format;  	u16 err;  	u32 h_control;  	u32 sample_rate = 48000; +	u64 formats = 0;  	/* on cards without SRC, must query at valid rate,  	* maybe set by external sync  	*/ -	err = hpi_mixer_get_control(ss, asihpi->h_mixer, +	err = hpi_mixer_get_control(asihpi->h_mixer,  				  HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,  				  HPI_CONTROL_SAMPLECLOCK, &h_control);  	if (!err) -		err = hpi_sample_clock_get_sample_rate(ss, h_control, +		err = hpi_sample_clock_get_sample_rate(h_control,  				&sample_rate);  	for (format = HPI_FORMAT_PCM8_UNSIGNED;  	     format <= HPI_FORMAT_PCM24_SIGNED; format++) { -		err = hpi_format_create(&hpi_format, -					2, format, sample_rate, 128000, 0); +		err = hpi_format_create(&hpi_format, asihpi->out_max_chans, +					format, sample_rate, 128000, 0);  		if (!err) -			err = hpi_outstream_query_format(ss, h_stream, -							&hpi_format); +			err = hpi_outstream_query_format(h_stream, &hpi_format);  		if (!err && (hpi_to_alsa_formats[format] != -1)) -			pcmhw->formats |= -				(1ULL << hpi_to_alsa_formats[format]); +			formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);  	} +	return formats;  } -static struct snd_pcm_hardware snd_card_asihpi_playback = { -	.channels_min = 1, -	.channels_max = 2, -	.buffer_bytes_max = BUFFER_BYTES_MAX, -	.period_bytes_min = PERIOD_BYTES_MIN, -	.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN, -	.periods_min = PERIODS_MIN, -	.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN, -	.fifo_size = 0, -}; -  static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)  {  	struct snd_pcm_runtime *runtime = substream->runtime;  	struct snd_card_asihpi_pcm *dpcm;  	struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); +	struct snd_pcm_hardware snd_card_asihpi_playback;  	int err;  	dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);  	if (dpcm == NULL)  		return -ENOMEM; -	err = -	    hpi_outstream_open(ss, card->adapter_index, +	err = hpi_outstream_open(card->hpi->adapter->index,  			      substream->number, &dpcm->h_stream);  	hpi_handle_error(err);  	if (err) @@ -954,7 +998,7 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)  	/*? also check ASI5000 samplerate source  	    If external, only support external rate. -	    If internal and other stream playing, cant switch +	    If internal and other stream playing, can't switch  	*/  	init_timer(&dpcm->timer); @@ -964,12 +1008,19 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)  	runtime->private_data = dpcm;  	runtime->private_free = snd_card_asihpi_runtime_free; -	snd_card_asihpi_playback.channels_max = card->out_max_chans; +	memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback)); +	snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX; +	snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN;  	/*?snd_card_asihpi_playback.period_bytes_min =  	card->out_max_chans * 4096; */ - -	snd_card_asihpi_playback_format(card, dpcm->h_stream, -					&snd_card_asihpi_playback); +	snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; +	snd_card_asihpi_playback.periods_min = PERIODS_MIN; +	snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN; +	/* snd_card_asihpi_playback.fifo_size = 0; */ +	snd_card_asihpi_playback.channels_max = card->out_max_chans; +	snd_card_asihpi_playback.channels_min = card->out_min_chans; +	snd_card_asihpi_playback.formats = +			snd_card_asihpi_playback_formats(card, dpcm->h_stream);  	snd_card_asihpi_pcm_samplerates(card,  &snd_card_asihpi_playback); @@ -977,19 +1028,19 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)  					SNDRV_PCM_INFO_DOUBLE |  					SNDRV_PCM_INFO_BATCH |  					SNDRV_PCM_INFO_BLOCK_TRANSFER | -					SNDRV_PCM_INFO_PAUSE; - -	if (card->support_mmap) -		snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_MMAP | -						SNDRV_PCM_INFO_MMAP_VALID; +					SNDRV_PCM_INFO_PAUSE | +					SNDRV_PCM_INFO_MMAP | +					SNDRV_PCM_INFO_MMAP_VALID; -	if (card->support_grouping) +	if (card->support_grouping) {  		snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START; +		snd_pcm_set_sync(substream); +	}  	/* struct is copied, so can create initializer dynamically */  	runtime->hw = snd_card_asihpi_playback; -	if (card->support_mmap) +	if (card->can_dma)  		err = snd_pcm_hw_constraint_pow2(runtime, 0,  					SNDRV_PCM_HW_PARAM_BUFFER_BYTES);  	if (err < 0) @@ -997,12 +1048,11 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)  	snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,  		card->update_interval_frames); -	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -		card->update_interval_frames * 4, UINT_MAX); -	snd_pcm_set_sync(substream); +	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, +		card->update_interval_frames * 2, UINT_MAX); -	snd_printd(KERN_INFO "playback open\n"); +	snd_printdd("playback open\n");  	return 0;  } @@ -1012,67 +1062,12 @@ static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)  	struct snd_pcm_runtime *runtime = substream->runtime;  	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	hpi_handle_error(hpi_outstream_close(ss, dpcm->h_stream)); -	snd_printd(KERN_INFO "playback close\n"); - -	return 0; -} - -static int snd_card_asihpi_playback_copy(struct snd_pcm_substream *substream, -					int channel, -					snd_pcm_uframes_t pos, -					void __user *src, -					snd_pcm_uframes_t count) -{ -	struct snd_pcm_runtime *runtime = substream->runtime; -	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	unsigned int len; - -	len = frames_to_bytes(runtime, count); - -	if (copy_from_user(runtime->dma_area, src, len)) -		return -EFAULT; - -	VPRINTK2(KERN_DEBUG "playback copy%d %u bytes\n", -			substream->number, len); - -	hpi_handle_error(hpi_outstream_write_buf(ss, dpcm->h_stream, -				runtime->dma_area, len, &dpcm->format)); +	hpi_handle_error(hpi_outstream_close(dpcm->h_stream)); +	snd_printdd("playback close\n");  	return 0;  } -static int snd_card_asihpi_playback_silence(struct snd_pcm_substream * -					    substream, int channel, -					    snd_pcm_uframes_t pos, -					    snd_pcm_uframes_t count) -{ -	unsigned int len; -	struct snd_pcm_runtime *runtime = substream->runtime; -	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; - -	len = frames_to_bytes(runtime, count); -	snd_printd(KERN_INFO "playback silence  %u bytes\n", len); - -	memset(runtime->dma_area, 0, len); -	hpi_handle_error(hpi_outstream_write_buf(ss, dpcm->h_stream, -				runtime->dma_area, len, &dpcm->format)); -	return 0; -} - -static struct snd_pcm_ops snd_card_asihpi_playback_ops = { -	.open = snd_card_asihpi_playback_open, -	.close = snd_card_asihpi_playback_close, -	.ioctl = snd_card_asihpi_playback_ioctl, -	.hw_params = snd_card_asihpi_pcm_hw_params, -	.hw_free = snd_card_asihpi_hw_free, -	.prepare = snd_card_asihpi_playback_prepare, -	.trigger = snd_card_asihpi_trigger, -	.pointer = snd_card_asihpi_playback_pointer, -	.copy = snd_card_asihpi_playback_copy, -	.silence = snd_card_asihpi_playback_silence, -}; -  static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {  	.open = snd_card_asihpi_playback_open,  	.close = snd_card_asihpi_playback_close, @@ -1091,13 +1086,13 @@ snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)  	struct snd_pcm_runtime *runtime = substream->runtime;  	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	VPRINTK2("capture pointer %d=%d\n", -			substream->number, dpcm->pcm_buf_pos); -	/* NOTE Unlike playback can't use actual dwSamplesPlayed +	snd_printddd("capture pointer %d=%d\n", +			substream->number, dpcm->pcm_buf_dma_ofs); +	/* NOTE Unlike playback can't use actual samples_played  		for the capture position, because those samples aren't yet in  		the local buffer available for reading.  	*/ -	return bytes_to_frames(runtime, dpcm->pcm_buf_pos % dpcm->pcm_size); +	return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);  }  static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream, @@ -1111,78 +1106,67 @@ static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)  	struct snd_pcm_runtime *runtime = substream->runtime;  	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	hpi_handle_error(hpi_instream_reset(ss, dpcm->h_stream)); -	dpcm->pcm_irq_pos = 0; -	dpcm->pcm_buf_pos = 0; +	hpi_handle_error(hpi_instream_reset(dpcm->h_stream)); +	dpcm->pcm_buf_host_rw_ofs = 0; +	dpcm->pcm_buf_dma_ofs = 0; +	dpcm->pcm_buf_elapsed_dma_ofs = 0; -	snd_printd("capture prepare %d\n", substream->number); +	snd_printdd("Capture Prepare %d\n", substream->number);  	return 0;  } -static void snd_card_asihpi_capture_format(struct snd_card_asihpi *asihpi, -					u32 h_stream, -					 struct snd_pcm_hardware *pcmhw) +static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi, +					u32 h_stream)  {    struct hpi_format hpi_format;  	u16 format;  	u16 err;  	u32 h_control;  	u32 sample_rate = 48000; +	u64 formats = 0;  	/* on cards without SRC, must query at valid rate,  		maybe set by external sync */ -	err = hpi_mixer_get_control(ss, asihpi->h_mixer, +	err = hpi_mixer_get_control(asihpi->h_mixer,  				  HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,  				  HPI_CONTROL_SAMPLECLOCK, &h_control);  	if (!err) -		err = hpi_sample_clock_get_sample_rate(ss, h_control, +		err = hpi_sample_clock_get_sample_rate(h_control,  			&sample_rate);  	for (format = HPI_FORMAT_PCM8_UNSIGNED;  		format <= HPI_FORMAT_PCM24_SIGNED; format++) { -		err = hpi_format_create(&hpi_format, 2, format, -				sample_rate, 128000, 0); -		if (!err) -			err = hpi_instream_query_format(ss, h_stream, -					    &hpi_format); +		err = hpi_format_create(&hpi_format, asihpi->in_max_chans, +					format, sample_rate, 128000, 0);  		if (!err) -			pcmhw->formats |= -				(1ULL << hpi_to_alsa_formats[format]); +			err = hpi_instream_query_format(h_stream, &hpi_format); +		if (!err && (hpi_to_alsa_formats[format] != -1)) +			formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);  	} +	return formats;  } - -static struct snd_pcm_hardware snd_card_asihpi_capture = { -	.channels_min = 1, -	.channels_max = 2, -	.buffer_bytes_max = BUFFER_BYTES_MAX, -	.period_bytes_min = PERIOD_BYTES_MIN, -	.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN, -	.periods_min = PERIODS_MIN, -	.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN, -	.fifo_size = 0, -}; -  static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)  {  	struct snd_pcm_runtime *runtime = substream->runtime;  	struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);  	struct snd_card_asihpi_pcm *dpcm; +	struct snd_pcm_hardware snd_card_asihpi_capture;  	int err;  	dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);  	if (dpcm == NULL)  		return -ENOMEM; -	snd_printd("hpi_instream_open adapter %d stream %d\n", -		   card->adapter_index, substream->number); +	snd_printdd("capture open adapter %d stream %d\n", +			card->hpi->adapter->index, substream->number);  	err = hpi_handle_error( -	    hpi_instream_open(ss, card->adapter_index, +	    hpi_instream_open(card->hpi->adapter->index,  			     substream->number, &dpcm->h_stream));  	if (err)  		kfree(dpcm); @@ -1191,7 +1175,6 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)  	if (err)  		return -EIO; -  	init_timer(&dpcm->timer);  	dpcm->timer.data = (unsigned long) dpcm;  	dpcm->timer.function = snd_card_asihpi_timer_function; @@ -1199,19 +1182,28 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)  	runtime->private_data = dpcm;  	runtime->private_free = snd_card_asihpi_runtime_free; +	memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture)); +	snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX; +	snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN; +	snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; +	snd_card_asihpi_capture.periods_min = PERIODS_MIN; +	snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN; +	/* snd_card_asihpi_capture.fifo_size = 0; */  	snd_card_asihpi_capture.channels_max = card->in_max_chans; -	snd_card_asihpi_capture_format(card, dpcm->h_stream, -				       &snd_card_asihpi_capture); +	snd_card_asihpi_capture.channels_min = card->in_min_chans; +	snd_card_asihpi_capture.formats = +		snd_card_asihpi_capture_formats(card, dpcm->h_stream);  	snd_card_asihpi_pcm_samplerates(card,  &snd_card_asihpi_capture); -	snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED; +	snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED | +					SNDRV_PCM_INFO_MMAP | +					SNDRV_PCM_INFO_MMAP_VALID; -	if (card->support_mmap) -		snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_MMAP | -						SNDRV_PCM_INFO_MMAP_VALID; +	if (card->support_grouping) +		snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;  	runtime->hw = snd_card_asihpi_capture; -	if (card->support_mmap) +	if (card->can_dma)  		err = snd_pcm_hw_constraint_pow2(runtime, 0,  					SNDRV_PCM_HW_PARAM_BUFFER_BYTES);  	if (err < 0) @@ -1231,30 +1223,7 @@ static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)  {  	struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data; -	hpi_handle_error(hpi_instream_close(ss, dpcm->h_stream)); -	return 0; -} - -static int snd_card_asihpi_capture_copy(struct snd_pcm_substream *substream, -				int channel, snd_pcm_uframes_t pos, -				void __user *dst, snd_pcm_uframes_t count) -{ -	struct snd_pcm_runtime *runtime = substream->runtime; -	struct snd_card_asihpi_pcm *dpcm = runtime->private_data; -	u32 data_size; - -	data_size = frames_to_bytes(runtime, count); - -	VPRINTK2("capture copy%d %d bytes\n", substream->number, data_size); -	hpi_handle_error(hpi_instream_read_buf(ss, dpcm->h_stream, -				runtime->dma_area, data_size)); - -	/* Used by capture_pointer */ -	dpcm->pcm_irq_pos = dpcm->pcm_irq_pos + data_size; - -	if (copy_to_user(dst, runtime->dma_area, data_size)) -		return -EFAULT; - +	hpi_handle_error(hpi_instream_close(dpcm->h_stream));  	return 0;  } @@ -1269,45 +1238,31 @@ static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {  	.pointer = snd_card_asihpi_capture_pointer,  }; -static struct snd_pcm_ops snd_card_asihpi_capture_ops = { -	.open = snd_card_asihpi_capture_open, -	.close = snd_card_asihpi_capture_close, -	.ioctl = snd_card_asihpi_capture_ioctl, -	.hw_params = snd_card_asihpi_pcm_hw_params, -	.hw_free = snd_card_asihpi_hw_free, -	.prepare = snd_card_asihpi_capture_prepare, -	.trigger = snd_card_asihpi_trigger, -	.pointer = snd_card_asihpi_capture_pointer, -	.copy = snd_card_asihpi_capture_copy -}; - -static int __devinit snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, -				      int device, int substreams) +static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)  {  	struct snd_pcm *pcm;  	int err; +	u16 num_instreams, num_outstreams, x16; +	u32 x32; + +	err = hpi_adapter_get_info(asihpi->hpi->adapter->index, +			&num_outstreams, &num_instreams, +			&x16, &x32, &x16); -	err = snd_pcm_new(asihpi->card, "asihpi PCM", device, -			 asihpi->num_outstreams, asihpi->num_instreams, -			 &pcm); +	err = snd_pcm_new(asihpi->card, "Asihpi PCM", device, +			num_outstreams,	num_instreams, &pcm);  	if (err < 0)  		return err; +  	/* pointer to ops struct is stored, dont change ops afterwards! */ -	if (asihpi->support_mmap) { -		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, -				&snd_card_asihpi_playback_mmap_ops); -		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, -				&snd_card_asihpi_capture_mmap_ops); -	} else { -		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, -				&snd_card_asihpi_playback_ops); -		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, -				&snd_card_asihpi_capture_ops); -	} +	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, +			&snd_card_asihpi_playback_mmap_ops); +	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, +			&snd_card_asihpi_capture_mmap_ops);  	pcm->private_data = asihpi;  	pcm->info_flags = 0; -	strcpy(pcm->name, "asihpi PCM"); +	strcpy(pcm->name, "Asihpi PCM");  	/*? do we want to emulate MMAP for non-BBM cards?  	Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */ @@ -1327,11 +1282,10 @@ struct hpi_control {  	u16 dst_node_type;  	u16 dst_node_index;  	u16 band; -	char name[44]; /* copied to snd_ctl_elem_id.name[44]; */ +	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */  }; -static char *asihpi_tuner_band_names[] = -{ +static const char * const asihpi_tuner_band_names[] = {  	"invalid",  	"AM",  	"FM mono", @@ -1349,70 +1303,39 @@ compile_time_assert(  		(HPI_TUNER_BAND_LAST+1)),  	assert_tuner_band_names_size); -#if ASI_STYLE_NAMES -static char *asihpi_src_names[] = -{ +static const char * const asihpi_src_names[] = {  	"no source", -	"outstream", -	"line_in", -	"aes_in", -	"tuner", +	"PCM", +	"Line", +	"Digital", +	"Tuner",  	"RF", -	"clock", -	"bitstr", -	"mic", -	"cobranet", -	"analog_in", -	"adapter", +	"Clock", +	"Bitstream", +	"Mic", +	"Net", +	"Analog", +	"Adapter", +	"RTP", +	"Internal"  }; -#else -static char *asihpi_src_names[] = -{ -	"no source", -	"PCM playback", -	"line in", -	"digital in", -	"tuner", -	"RF", -	"clock", -	"bitstream", -	"mic", -	"cobranet in", -	"analog in", -	"adapter", -}; -#endif  compile_time_assert(  	(ARRAY_SIZE(asihpi_src_names) ==  		(HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),  	assert_src_names_size); -#if ASI_STYLE_NAMES -static char *asihpi_dst_names[] = -{ +static const char * const asihpi_dst_names[] = {  	"no destination", -	"instream", -	"line_out", -	"aes_out", +	"PCM", +	"Line", +	"Digital",  	"RF", -	"speaker" , -	"cobranet", -	"analog_out", +	"Speaker", +	"Net", +	"Analog", +	"RTP",  }; -#else -static char *asihpi_dst_names[] = -{ -	"no destination", -	"PCM capture", -	"line out", -	"digital out", -	"RF", -	"speaker", -	"cobranet out", -	"analog out" -}; -#endif  compile_time_assert(  	(ARRAY_SIZE(asihpi_dst_names) == @@ -1438,30 +1361,47 @@ static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,  				struct hpi_control *hpi_ctl,  				char *name)  { +	char *dir;  	memset(snd_control, 0, sizeof(*snd_control));  	snd_control->name = hpi_ctl->name;  	snd_control->private_value = hpi_ctl->h_control;  	snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;  	snd_control->index = 0; +	if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE) +		dir = ""; /* clock is neither capture nor playback */ +	else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM) +		dir = "Capture ";  /* On or towards a PCM capture destination*/ +	else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) && +		(!hpi_ctl->dst_node_type)) +		dir = "Capture "; /* On a source node that is not PCM playback */ +	else if (hpi_ctl->src_node_type && +		(hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) && +		(hpi_ctl->dst_node_type)) +		dir = "Monitor Playback "; /* Between an input and an output */ +	else +		dir = "Playback "; /* PCM Playback source, or  output node */ +  	if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type) -		sprintf(hpi_ctl->name, "%s%d to %s%d %s", +		sprintf(hpi_ctl->name, "%s %d %s %d %s%s",  			asihpi_src_names[hpi_ctl->src_node_type],  			hpi_ctl->src_node_index,  			asihpi_dst_names[hpi_ctl->dst_node_type],  			hpi_ctl->dst_node_index, -			name); +			dir, name);  	else if (hpi_ctl->dst_node_type) { -		sprintf(hpi_ctl->name, "%s%d %s", +		sprintf(hpi_ctl->name, "%s %d %s%s",  		asihpi_dst_names[hpi_ctl->dst_node_type],  		hpi_ctl->dst_node_index, -		name); +		dir, name);  	} else { -		sprintf(hpi_ctl->name, "%s%d %s", +		sprintf(hpi_ctl->name, "%s %d %s%s",  		asihpi_src_names[hpi_ctl->src_node_type],  		hpi_ctl->src_node_index, -		name); +		dir, name);  	} +	/* printk(KERN_INFO "Adding %s %d to %d ",  hpi_ctl->name, +		hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */  }  /*------------------------------------------------------------ @@ -1472,13 +1412,14 @@ static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,  				  struct snd_ctl_elem_info *uinfo)  {  	u32 h_control = kcontrol->private_value; +	u32 count;  	u16 err;  	/* native gains are in millibels */  	short min_gain_mB;  	short max_gain_mB;  	short step_gain_mB; -	err = hpi_volume_query_range(ss, h_control, +	err = hpi_volume_query_range(h_control,  			&min_gain_mB, &max_gain_mB, &step_gain_mB);  	if (err) {  		max_gain_mB = 0; @@ -1486,8 +1427,12 @@ static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,  		step_gain_mB = VOL_STEP_mB;  	} +	err = hpi_meter_query_channels(h_control, &count); +	if (err) +		count = HPI_MAX_CHANNELS; +  	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; -	uinfo->count = 2; +	uinfo->count = count;  	uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;  	uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;  	uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB; @@ -1500,7 +1445,7 @@ static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,  	u32 h_control = kcontrol->private_value;  	short an_gain_mB[HPI_MAX_CHANNELS]; -	hpi_handle_error(hpi_volume_get_gain(ss, h_control, an_gain_mB)); +	hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB));  	ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;  	ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB; @@ -1522,19 +1467,48 @@ static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,  	   asihpi->mixer_volume[addr][1] != right;  	 */  	change = 1; -	hpi_handle_error(hpi_volume_set_gain(ss, h_control, an_gain_mB)); +	hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));  	return change;  }  static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0); -static int __devinit snd_asihpi_volume_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +#define snd_asihpi_volume_mute_info	snd_ctl_boolean_mono_info + +static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol, +				 struct snd_ctl_elem_value *ucontrol) +{ +	u32 h_control = kcontrol->private_value; +	u32 mute; + +	hpi_handle_error(hpi_volume_get_mute(h_control, &mute)); +	ucontrol->value.integer.value[0] = mute ? 0 : 1; + +	return 0; +} + +static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol, +				 struct snd_ctl_elem_value *ucontrol) +{ +	u32 h_control = kcontrol->private_value; +	int change = 1; +	/* HPI currently only supports all or none muting of multichannel volume +	ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted +	*/ +	int mute =  ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS; +	hpi_handle_error(hpi_volume_set_mute(h_control, mute)); +	return change; +} + +static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi, +				 struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; +	int err; +	u32 mute; -	asihpi_ctl_init(&snd_control, hpi_ctl, "volume"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |  				SNDRV_CTL_ELEM_ACCESS_TLV_READ;  	snd_control.info = snd_asihpi_volume_info; @@ -1542,7 +1516,19 @@ static int __devinit snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,  	snd_control.put = snd_asihpi_volume_put;  	snd_control.tlv.p = db_scale_100; -	return ctl_add(card, &snd_control, asihpi); +	err = ctl_add(card, &snd_control, asihpi); +	if (err) +		return err; + +	if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) { +		asihpi_ctl_init(&snd_control, hpi_ctl, "Switch"); +		snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; +		snd_control.info = snd_asihpi_volume_mute_info; +		snd_control.get = snd_asihpi_volume_mute_get; +		snd_control.put = snd_asihpi_volume_mute_put; +		err = ctl_add(card, &snd_control, asihpi); +	} +	return err;  }  /*------------------------------------------------------------ @@ -1558,7 +1544,7 @@ static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,  	short step_gain_mB;  	err = -	    hpi_level_query_range(ss, h_control, &min_gain_mB, +	    hpi_level_query_range(h_control, &min_gain_mB,  			       &max_gain_mB, &step_gain_mB);  	if (err) {  		max_gain_mB = 2400; @@ -1580,7 +1566,7 @@ static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,  	u32 h_control = kcontrol->private_value;  	short an_gain_mB[HPI_MAX_CHANNELS]; -	hpi_handle_error(hpi_level_get_gain(ss, h_control, an_gain_mB)); +	hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));  	ucontrol->value.integer.value[0] =  	    an_gain_mB[0] / HPI_UNITS_PER_dB;  	ucontrol->value.integer.value[1] = @@ -1604,20 +1590,20 @@ static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,  	   asihpi->mixer_level[addr][1] != right;  	 */  	change = 1; -	hpi_handle_error(hpi_level_set_gain(ss, h_control, an_gain_mB)); +	hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));  	return change;  }  static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0); -static int __devinit snd_asihpi_level_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi, +				struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control;  	/* can't use 'volume' cos some nodes have volume as well */ -	asihpi_ctl_init(&snd_control, hpi_ctl, "level"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Level");  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |  				SNDRV_CTL_ELEM_ACCESS_TLV_READ;  	snd_control.info = snd_asihpi_level_info; @@ -1633,12 +1619,8 @@ static int __devinit snd_asihpi_level_add(struct snd_card_asihpi *asihpi,   ------------------------------------------------------------*/  /* AESEBU format */ -static char *asihpi_aesebu_format_names[] = -{ -	"N/A", -	"S/PDIF", -	"AES/EBU", -}; +static const char * const asihpi_aesebu_format_names[] = { +	"N/A", "S/PDIF", "AES/EBU" };  static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,  				  struct snd_ctl_elem_info *uinfo) @@ -1659,12 +1641,12 @@ static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,  static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,  			struct snd_ctl_elem_value *ucontrol, -			u16 (*func)(const struct hpi_hsubsys *, u32, u16 *)) +			u16 (*func)(u32, u16 *))  {  	u32 h_control = kcontrol->private_value;  	u16 source, err; -	err = func(ss, h_control, &source); +	err = func(h_control, &source);  	/* default to N/A */  	ucontrol->value.enumerated.item[0] = 0; @@ -1681,7 +1663,7 @@ static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,  static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,  			struct snd_ctl_elem_value *ucontrol, -			 u16 (*func)(const struct hpi_hsubsys *, u32, u16)) +			 u16 (*func)(u32, u16))  {  	u32 h_control = kcontrol->private_value; @@ -1693,7 +1675,7 @@ static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,  	if (ucontrol->value.enumerated.item[0] == 2)  		source = HPI_AESEBU_FORMAT_AESEBU; -	if (func(ss, h_control, source) != 0) +	if (func(h_control, source) != 0)  		return -EINVAL;  	return 1; @@ -1702,13 +1684,13 @@ static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,  static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,  				 struct snd_ctl_elem_value *ucontrol) {  	return snd_asihpi_aesebu_format_get(kcontrol, ucontrol, -					HPI_AESEBU__receiver_get_format); +					hpi_aesebu_receiver_get_format);  }  static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,  				 struct snd_ctl_elem_value *ucontrol) {  	return snd_asihpi_aesebu_format_put(kcontrol, ucontrol, -					HPI_AESEBU__receiver_set_format); +					hpi_aesebu_receiver_set_format);  }  static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol, @@ -1730,19 +1712,19 @@ static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,  	u32 h_control = kcontrol->private_value;  	u16 status; -	hpi_handle_error(HPI_AESEBU__receiver_get_error_status( -				ss, h_control, &status)); +	hpi_handle_error(hpi_aesebu_receiver_get_error_status( +					 h_control, &status));  	ucontrol->value.integer.value[0] = status;  	return 0;  } -static int __devinit snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +static int snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi, +				    struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; -	asihpi_ctl_init(&snd_control, hpi_ctl, "format"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Format");  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;  	snd_control.info = snd_asihpi_aesebu_format_info;  	snd_control.get = snd_asihpi_aesebu_rx_format_get; @@ -1752,7 +1734,7 @@ static int __devinit snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,  	if (ctl_add(card, &snd_control, asihpi) < 0)  		return -EINVAL; -	asihpi_ctl_init(&snd_control, hpi_ctl, "status"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Status");  	snd_control.access =  	    SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;  	snd_control.info = snd_asihpi_aesebu_rxstatus_info; @@ -1764,23 +1746,23 @@ static int __devinit snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,  static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,  				 struct snd_ctl_elem_value *ucontrol) {  	return snd_asihpi_aesebu_format_get(kcontrol, ucontrol, -					HPI_AESEBU__transmitter_get_format); +					hpi_aesebu_transmitter_get_format);  }  static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,  				 struct snd_ctl_elem_value *ucontrol) {  	return snd_asihpi_aesebu_format_put(kcontrol, ucontrol, -					HPI_AESEBU__transmitter_set_format); +					hpi_aesebu_transmitter_set_format);  } -static int __devinit snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +static int snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi, +				    struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; -	asihpi_ctl_init(&snd_control, hpi_ctl, "format"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Format");  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;  	snd_control.info = snd_asihpi_aesebu_format_info;  	snd_control.get = snd_asihpi_aesebu_tx_format_get; @@ -1804,7 +1786,7 @@ static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,  	u16 gain_range[3];  	for (idx = 0; idx < 3; idx++) { -		err = hpi_tuner_query_gain(ss, h_control, +		err = hpi_tuner_query_gain(h_control,  					  idx, &gain_range[idx]);  		if (err != 0)  			return err; @@ -1827,7 +1809,7 @@ static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,  	u32 h_control = kcontrol->private_value;  	short gain; -	hpi_handle_error(hpi_tuner_get_gain(ss, h_control, &gain)); +	hpi_handle_error(hpi_tuner_get_gain(h_control, &gain));  	ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;  	return 0; @@ -1843,7 +1825,7 @@ static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,  	short gain;  	gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB; -	hpi_handle_error(hpi_tuner_set_gain(ss, h_control, gain)); +	hpi_handle_error(hpi_tuner_set_gain(h_control, gain));  	return 1;  } @@ -1857,7 +1839,7 @@ static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,  	u32 i;  	for (i = 0; i < len; i++) { -		err = hpi_tuner_query_band(ss, +		err = hpi_tuner_query_band(  				h_control, i, &band_list[i]);  		if (err != 0)  			break; @@ -1913,7 +1895,7 @@ static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,  	num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,  				HPI_TUNER_BAND_LAST); -	hpi_handle_error(hpi_tuner_get_band(ss, h_control, &band)); +	hpi_handle_error(hpi_tuner_get_band(h_control, &band));  	ucontrol->value.enumerated.item[0] = -1;  	for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++) @@ -1932,6 +1914,7 @@ static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,  	struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);  	*/  	u32 h_control = kcontrol->private_value; +	unsigned int idx;  	u16 band;  	u16 tuner_bands[HPI_TUNER_BAND_LAST];  	u32 num_bands = 0; @@ -1939,8 +1922,11 @@ static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,  	num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,  			HPI_TUNER_BAND_LAST); -	band = tuner_bands[ucontrol->value.enumerated.item[0]]; -	hpi_handle_error(hpi_tuner_set_band(ss, h_control, band)); +	idx = ucontrol->value.enumerated.item[0]; +	if (idx >= ARRAY_SIZE(tuner_bands)) +		idx = ARRAY_SIZE(tuner_bands) - 1; +	band = tuner_bands[idx]; +	hpi_handle_error(hpi_tuner_set_band(h_control, band));  	return 1;  } @@ -1965,7 +1951,7 @@ static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,  	for (band_iter = 0; band_iter < num_bands; band_iter++) {  		for (idx = 0; idx < 3; idx++) { -			err = hpi_tuner_query_frequency(ss, h_control, +			err = hpi_tuner_query_frequency(h_control,  				idx, tuner_bands[band_iter],  				&temp_freq_range[idx]);  			if (err != 0) @@ -1998,7 +1984,7 @@ static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,  	u32 h_control = kcontrol->private_value;  	u32 freq; -	hpi_handle_error(hpi_tuner_get_frequency(ss, h_control, &freq)); +	hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));  	ucontrol->value.integer.value[0] = freq;  	return 0; @@ -2011,14 +1997,14 @@ static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,  	u32 freq;  	freq = ucontrol->value.integer.value[0]; -	hpi_handle_error(hpi_tuner_set_frequency(ss, h_control, freq)); +	hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));  	return 1;  }  /* Tuner control group initializer  */ -static int __devinit snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi, +				struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; @@ -2026,8 +2012,8 @@ static int __devinit snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,  	snd_control.private_value = hpi_ctl->h_control;  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; -	if (!hpi_tuner_get_gain(ss, hpi_ctl->h_control, NULL)) { -		asihpi_ctl_init(&snd_control, hpi_ctl, "gain"); +	if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) { +		asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");  		snd_control.info = snd_asihpi_tuner_gain_info;  		snd_control.get = snd_asihpi_tuner_gain_get;  		snd_control.put = snd_asihpi_tuner_gain_put; @@ -2036,7 +2022,7 @@ static int __devinit snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,  			return -EINVAL;  	} -	asihpi_ctl_init(&snd_control, hpi_ctl, "band"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Band");  	snd_control.info = snd_asihpi_tuner_band_info;  	snd_control.get = snd_asihpi_tuner_band_get;  	snd_control.put = snd_asihpi_tuner_band_put; @@ -2044,7 +2030,7 @@ static int __devinit snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,  	if (ctl_add(card, &snd_control, asihpi) < 0)  		return -EINVAL; -	asihpi_ctl_init(&snd_control, hpi_ctl, "freq"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");  	snd_control.info = snd_asihpi_tuner_freq_info;  	snd_control.get = snd_asihpi_tuner_freq_get;  	snd_control.put = snd_asihpi_tuner_freq_put; @@ -2058,8 +2044,15 @@ static int __devinit snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,  static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,  				 struct snd_ctl_elem_info *uinfo)  { +	u32 h_control = kcontrol->private_value; +	u32 count; +	u16 err; +	err = hpi_meter_query_channels(h_control, &count); +	if (err) +		count = HPI_MAX_CHANNELS; +  	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; -	uinfo->count = HPI_MAX_CHANNELS; +	uinfo->count = count;  	uinfo->value.integer.min = 0;  	uinfo->value.integer.max = 0x7FFFFFFF;  	return 0; @@ -2095,7 +2088,7 @@ static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,  	short an_gain_mB[HPI_MAX_CHANNELS], i;  	u16 err; -	err = hpi_meter_get_peak(ss, h_control, an_gain_mB); +	err = hpi_meter_get_peak(h_control, an_gain_mB);  	for (i = 0; i < HPI_MAX_CHANNELS; i++) {  		if (err) { @@ -2114,13 +2107,13 @@ static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,  	return 0;  } -static int __devinit snd_asihpi_meter_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl, int subidx) +static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi, +				struct hpi_control *hpi_ctl, int subidx)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; -	asihpi_ctl_init(&snd_control, hpi_ctl, "meter"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");  	snd_control.access =  	    SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;  	snd_control.info = snd_asihpi_meter_info; @@ -2140,7 +2133,7 @@ static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)  	struct hpi_control hpi_ctl;  	int s, err;  	for (s = 0; s < 32; s++) { -		err = hpi_multiplexer_query_source(ss, h_control, s, +		err = hpi_multiplexer_query_source(h_control, s,  						  &hpi_ctl.  						  src_node_type,  						  &hpi_ctl. @@ -2168,7 +2161,7 @@ static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,  		    uinfo->value.enumerated.items - 1;  	err = -	    hpi_multiplexer_query_source(ss, h_control, +	    hpi_multiplexer_query_source(h_control,  					uinfo->value.enumerated.item,  					&src_node_type, &src_node_index); @@ -2186,11 +2179,11 @@ static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,  	u16 src_node_type, src_node_index;  	int s; -	hpi_handle_error(hpi_multiplexer_get_source(ss, h_control, +	hpi_handle_error(hpi_multiplexer_get_source(h_control,  				&source_type, &source_index));  	/* Should cache this search result! */  	for (s = 0; s < 256; s++) { -		if (hpi_multiplexer_query_source(ss, h_control, s, +		if (hpi_multiplexer_query_source(h_control, s,  					    &src_node_type, &src_node_index))  			break; @@ -2201,7 +2194,7 @@ static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,  		}  	}  	snd_printd(KERN_WARNING -		"control %x failed to match mux source %hu %hu\n", +		"Control %x failed to match mux source %hu %hu\n",  		h_control, source_type, source_index);  	ucontrol->value.enumerated.item[0] = 0;  	return 0; @@ -2217,28 +2210,24 @@ static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,  	change = 1; -	e = hpi_multiplexer_query_source(ss, h_control, +	e = hpi_multiplexer_query_source(h_control,  				    ucontrol->value.enumerated.item[0],  				    &source_type, &source_index);  	if (!e)  		hpi_handle_error( -			hpi_multiplexer_set_source(ss, h_control, +			hpi_multiplexer_set_source(h_control,  						source_type, source_index));  	return change;  } -static int  __devinit snd_asihpi_mux_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +static int  snd_asihpi_mux_add(struct snd_card_asihpi *asihpi, +			       struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; -#if ASI_STYLE_NAMES -	asihpi_ctl_init(&snd_control, hpi_ctl, "multiplexer"); -#else -	asihpi_ctl_init(&snd_control, hpi_ctl, "route"); -#endif +	asihpi_ctl_init(&snd_control, hpi_ctl, "Route");  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;  	snd_control.info = snd_asihpi_mux_info;  	snd_control.get = snd_asihpi_mux_get; @@ -2254,33 +2243,41 @@ static int  __devinit snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,  static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,  				 struct snd_ctl_elem_info *uinfo)  { -	static char *mode_names[HPI_CHANNEL_MODE_LAST] = { -		"normal", "swap", -		"from_left", "from_right", -		"to_left", "to_right" +	static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = { +		"invalid", +		"Normal", "Swap", +		"From Left", "From Right", +		"To Left", "To Right"  	};  	u32 h_control = kcontrol->private_value;  	u16 mode;  	int i; +	u16 mode_map[6]; +	int valid_modes = 0;  	/* HPI channel mode values can be from 1 to 6  	Some adapters only support a contiguous subset  	*/  	for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++) -		if (hpi_channel_mode_query_mode( -			ss,  h_control, i, &mode)) -			break; +		if (!hpi_channel_mode_query_mode( +			h_control, i, &mode)) { +			mode_map[valid_modes] = mode; +			valid_modes++; +			} + +	if (!valid_modes) +		return -EINVAL;  	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;  	uinfo->count = 1; -	uinfo->value.enumerated.items = i; +	uinfo->value.enumerated.items = valid_modes; -	if (uinfo->value.enumerated.item >= i) -		uinfo->value.enumerated.item = i - 1; +	if (uinfo->value.enumerated.item >= valid_modes) +		uinfo->value.enumerated.item = valid_modes - 1;  	strcpy(uinfo->value.enumerated.name, -	       mode_names[uinfo->value.enumerated.item]); +	       mode_names[mode_map[uinfo->value.enumerated.item]]);  	return 0;  } @@ -2291,7 +2288,7 @@ static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,  	u32 h_control = kcontrol->private_value;  	u16 mode; -	if (hpi_channel_mode_get(ss, h_control, &mode)) +	if (hpi_channel_mode_get(h_control, &mode))  		mode = 1;  	ucontrol->value.enumerated.item[0] = mode - 1; @@ -2307,19 +2304,19 @@ static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,  	change = 1; -	hpi_handle_error(hpi_channel_mode_set(ss, h_control, +	hpi_handle_error(hpi_channel_mode_set(h_control,  			   ucontrol->value.enumerated.item[0] + 1));  	return change;  } -static int __devinit snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi, +				struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; -	asihpi_ctl_init(&snd_control, hpi_ctl, "channel mode"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Mode");  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;  	snd_control.info = snd_asihpi_cmode_info;  	snd_control.get = snd_asihpi_cmode_get; @@ -2331,15 +2328,12 @@ static int __devinit snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,  /*------------------------------------------------------------     Sampleclock source  controls   ------------------------------------------------------------*/ - -static char *sampleclock_sources[MAX_CLOCKSOURCES] = -    { "N/A", "local PLL", "AES/EBU sync", "word external", "word header", -	  "SMPTE", "AES/EBU in1", "auto", "network", "invalid", -	  "prev module", -	  "AES/EBU in2", "AES/EBU in3", "AES/EBU in4", "AES/EBU in5", -	  "AES/EBU in6", "AES/EBU in7", "AES/EBU in8"}; - - +static char *sampleclock_sources[MAX_CLOCKSOURCES] = { +	"N/A", "Local PLL", "Digital Sync", "Word External", "Word Header", +	"SMPTE", "Digital1", "Auto", "Network", "Invalid", +	"Prev Module", +	"Digital2", "Digital3", "Digital4", "Digital5", +	"Digital6", "Digital7", "Digital8"};  static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,  				  struct snd_ctl_elem_info *uinfo) @@ -2371,11 +2365,11 @@ static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,  	int i;  	ucontrol->value.enumerated.item[0] = 0; -	if (hpi_sample_clock_get_source(ss, h_control, &source)) +	if (hpi_sample_clock_get_source(h_control, &source))  		source = 0;  	if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT) -		if (hpi_sample_clock_get_source_index(ss, h_control, &srcindex)) +		if (hpi_sample_clock_get_source_index(h_control, &srcindex))  			srcindex = 0;  	for (i = 0; i < clkcache->count; i++) @@ -2394,7 +2388,8 @@ static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,  	struct snd_card_asihpi *asihpi =  			(struct snd_card_asihpi *)(kcontrol->private_data);  	struct clk_cache *clkcache = &asihpi->cc; -	int change, item; +	unsigned int item; +	int change;  	u32 h_control = kcontrol->private_value;  	change = 1; @@ -2402,11 +2397,11 @@ static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,  	if (item >= clkcache->count)  		item = clkcache->count-1; -	hpi_handle_error(hpi_sample_clock_set_source(ss, +	hpi_handle_error(hpi_sample_clock_set_source(  				h_control, clkcache->s[item].source));  	if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT) -		hpi_handle_error(hpi_sample_clock_set_source_index(ss, +		hpi_handle_error(hpi_sample_clock_set_source_index(  				h_control, clkcache->s[item].index));  	return change;  } @@ -2434,7 +2429,7 @@ static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,  	u32 rate;  	u16 e; -	e = hpi_sample_clock_get_local_rate(ss, h_control, &rate); +	e = hpi_sample_clock_get_local_rate(h_control, &rate);  	if (!e)  		ucontrol->value.integer.value[0] = rate;  	else @@ -2452,7 +2447,7 @@ static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,  	   asihpi->mixer_clkrate[addr][1] != right;  	 */  	change = 1; -	hpi_handle_error(hpi_sample_clock_set_local_rate(ss, h_control, +	hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,  				      ucontrol->value.integer.value[0]));  	return change;  } @@ -2476,7 +2471,7 @@ static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,  	u32 rate;  	u16 e; -	e = hpi_sample_clock_get_sample_rate(ss, h_control, &rate); +	e = hpi_sample_clock_get_sample_rate(h_control, &rate);  	if (!e)  		ucontrol->value.integer.value[0] = rate;  	else @@ -2484,8 +2479,8 @@ static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,  	return 0;  } -static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi, -					struct hpi_control *hpi_ctl) +static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi, +				      struct hpi_control *hpi_ctl)  {  	struct snd_card *card = asihpi->card;  	struct snd_kcontrol_new snd_control; @@ -2501,7 +2496,7 @@ static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,  	clkcache->has_local = 0;  	for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) { -		if  (hpi_sample_clock_query_source(ss, hSC, +		if  (hpi_sample_clock_query_source(hSC,  				i, &source))  			break;  		clkcache->s[i].source = source; @@ -2515,7 +2510,7 @@ static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,  	if (has_aes_in)  		/* already will have picked up index 0 above */  		for (j = 1; j < 8; j++) { -			if (hpi_sample_clock_query_source_index(ss, hSC, +			if (hpi_sample_clock_query_source_index(hSC,  				j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,  				&source))  				break; @@ -2528,7 +2523,7 @@ static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,  		}  	clkcache->count = i; -	asihpi_ctl_init(&snd_control, hpi_ctl, "source"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Source");  	snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;  	snd_control.info = snd_asihpi_clksrc_info;  	snd_control.get = snd_asihpi_clksrc_get; @@ -2538,7 +2533,7 @@ static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,  	if (clkcache->has_local) { -		asihpi_ctl_init(&snd_control, hpi_ctl, "local_rate"); +		asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");  		snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;  		snd_control.info = snd_asihpi_clklocal_info;  		snd_control.get = snd_asihpi_clklocal_get; @@ -2549,7 +2544,7 @@ static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,  			return -EINVAL;  	} -	asihpi_ctl_init(&snd_control, hpi_ctl, "rate"); +	asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");  	snd_control.access =  	    SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;  	snd_control.info = snd_asihpi_clkrate_info; @@ -2561,9 +2556,9 @@ static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,     Mixer   ------------------------------------------------------------*/ -static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi) +static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)  { -	struct snd_card *card = asihpi->card; +	struct snd_card *card;  	unsigned int idx = 0;  	unsigned int subindex = 0;  	int err; @@ -2571,10 +2566,11 @@ static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)  	if (snd_BUG_ON(!asihpi))  		return -EINVAL; -	strcpy(card->mixername, "asihpi mixer"); +	card = asihpi->card; +	strcpy(card->mixername, "Asihpi Mixer");  	err = -	    hpi_mixer_open(ss, asihpi->adapter_index, +	    hpi_mixer_open(asihpi->hpi->adapter->index,  			  &asihpi->h_mixer);  	hpi_handle_error(err);  	if (err) @@ -2585,7 +2581,7 @@ static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)  	for (idx = 0; idx < 2000; idx++) {  		err = hpi_mixer_get_control_by_index( -				ss, asihpi->h_mixer, +				asihpi->h_mixer,  				idx,  				&hpi_ctl.src_node_type,  				&hpi_ctl.src_node_index, @@ -2597,7 +2593,7 @@ static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)  			if (err == HPI_ERROR_CONTROL_DISABLED) {  				if (mixer_dump)  					snd_printk(KERN_INFO -						   "disabled HPI control(%d)\n", +						   "Disabled HPI Control(%d)\n",  						   idx);  				continue;  			} else @@ -2662,7 +2658,7 @@ static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)  		default:  			if (mixer_dump)  				snd_printk(KERN_INFO -					"untranslated HPI control" +					"Untranslated HPI Control"  					"(%d) %d %d %d %d %d\n",  					idx,  					hpi_ctl.control_type, @@ -2671,7 +2667,7 @@ static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)  					hpi_ctl.dst_node_type,  					hpi_ctl.dst_node_index);  			continue; -		}; +		}  		if (err < 0)  			return err;  	} @@ -2692,44 +2688,50 @@ snd_asihpi_proc_read(struct snd_info_entry *entry,  			struct snd_info_buffer *buffer)  {  	struct snd_card_asihpi *asihpi = entry->private_data; -	u16 version;  	u32 h_control;  	u32 rate = 0;  	u16 source = 0; + +	u16 num_outstreams; +	u16 num_instreams; +	u16 version; +	u32 serial_number; +	u16 type; +  	int err;  	snd_iprintf(buffer, "ASIHPI driver proc file\n"); + +	hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index, +			&num_outstreams, &num_instreams, +			&version, &serial_number, &type)); +  	snd_iprintf(buffer, -		"adapter ID=%4X\n_index=%d\n" -		"num_outstreams=%d\n_num_instreams=%d\n", -		asihpi->type, asihpi->adapter_index, -		asihpi->num_outstreams, asihpi->num_instreams); +			"Adapter type ASI%4X\nHardware Index %d\n" +			"%d outstreams\n%d instreams\n", +			type, asihpi->hpi->adapter->index, +			num_outstreams, num_instreams); -	version = asihpi->version;  	snd_iprintf(buffer, -		"serial#=%d\n_hw version %c%d\nDSP code version %03d\n", -		asihpi->serial_number, ((version >> 3) & 0xf) + 'A', -		version & 0x7, +		"Serial#%d\nHardware version %c%d\nDSP code version %03d\n", +		serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7,  		((version >> 13) * 100) + ((version >> 7) & 0x3f)); -	err = hpi_mixer_get_control(ss, asihpi->h_mixer, +	err = hpi_mixer_get_control(asihpi->h_mixer,  				  HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,  				  HPI_CONTROL_SAMPLECLOCK, &h_control);  	if (!err) { -		err = hpi_sample_clock_get_sample_rate(ss, -					h_control, &rate); -		err += hpi_sample_clock_get_source(ss, h_control, &source); +		err = hpi_sample_clock_get_sample_rate(h_control, &rate); +		err += hpi_sample_clock_get_source(h_control, &source);  		if (!err) -			snd_iprintf(buffer, "sample_clock=%d_hz, source %s\n", +			snd_iprintf(buffer, "Sample Clock %dHz, source %s\n",  			rate, sampleclock_sources[source]);  	} -  } - -static void __devinit snd_asihpi_proc_init(struct snd_card_asihpi *asihpi) +static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)  {  	struct snd_info_entry *entry; @@ -2771,8 +2773,8 @@ static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,  /* results in /dev/snd/hwC#D0 file for each card with index #     also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'  */ -static int __devinit snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi, -	int device, struct snd_hwdep **rhwdep) +static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi, +			      int device, struct snd_hwdep **rhwdep)  {  	struct snd_hwdep *hw;  	int err; @@ -2796,108 +2798,88 @@ static int __devinit snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi,  /*------------------------------------------------------------     CARD   ------------------------------------------------------------*/ -static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev, -				       const struct pci_device_id *pci_id) +static int snd_asihpi_probe(struct pci_dev *pci_dev, +			    const struct pci_device_id *pci_id)  {  	int err; - -	u16 version; -	int pcm_substreams; - -	struct hpi_adapter *hpi_card; +	struct hpi_adapter *hpi;  	struct snd_card *card;  	struct snd_card_asihpi *asihpi;  	u32 h_control;  	u32 h_stream; +	u32 adapter_index;  	static int dev;  	if (dev >= SNDRV_CARDS)  		return -ENODEV; -	/* Should this be enable[hpi_card->index] ? */ +	/* Should this be enable[hpi->index] ? */  	if (!enable[dev]) {  		dev++;  		return -ENOENT;  	} +	/* Initialise low-level HPI driver */  	err = asihpi_adapter_probe(pci_dev, pci_id);  	if (err < 0)  		return err; -	hpi_card = pci_get_drvdata(pci_dev); +	hpi = pci_get_drvdata(pci_dev); +	adapter_index = hpi->adapter->index;  	/* first try to give the card the same index as its hardware index */ -	err = snd_card_create(hpi_card->index, -			      id[hpi_card->index], THIS_MODULE, -			      sizeof(struct snd_card_asihpi), -			      &card); +	err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index], +			   THIS_MODULE, sizeof(struct snd_card_asihpi), &card);  	if (err < 0) {  		/* if that fails, try the default index==next available */ -		err = -		    snd_card_create(index[dev], id[dev], -				    THIS_MODULE, -				    sizeof(struct snd_card_asihpi), -				    &card); +		err = snd_card_new(&pci_dev->dev, index[dev], id[dev], +				   THIS_MODULE, sizeof(struct snd_card_asihpi), +				   &card);  		if (err < 0)  			return err;  		snd_printk(KERN_WARNING -			"**** WARNING **** adapter index %d->ALSA index %d\n", -			hpi_card->index, card->number); +			"**** WARNING **** Adapter index %d->ALSA index %d\n", +			adapter_index, card->number);  	} -	asihpi = (struct snd_card_asihpi *) card->private_data; +	asihpi = card->private_data;  	asihpi->card = card; -	asihpi->pci = hpi_card->pci; -	asihpi->adapter_index = hpi_card->index; -	hpi_handle_error(hpi_adapter_get_info(ss, -				 asihpi->adapter_index, -				 &asihpi->num_outstreams, -				 &asihpi->num_instreams, -				 &asihpi->version, -				 &asihpi->serial_number, &asihpi->type)); - -	version = asihpi->version; -	snd_printk(KERN_INFO "adapter ID=%4X index=%d num_outstreams=%d " -			"num_instreams=%d S/N=%d\n" -			"hw version %c%d DSP code version %03d\n", -			asihpi->type, asihpi->adapter_index, -			asihpi->num_outstreams, -			asihpi->num_instreams, asihpi->serial_number, -			((version >> 3) & 0xf) + 'A', -			version & 0x7, -			((version >> 13) * 100) + ((version >> 7) & 0x3f)); - -	pcm_substreams = asihpi->num_outstreams; -	if (pcm_substreams < asihpi->num_instreams) -		pcm_substreams = asihpi->num_instreams; - -	err = hpi_adapter_get_property(ss, asihpi->adapter_index, +	asihpi->pci = pci_dev; +	asihpi->hpi = hpi; + +	snd_printk(KERN_INFO "adapter ID=%4X index=%d\n", +			asihpi->hpi->adapter->type, adapter_index); + +	err = hpi_adapter_get_property(adapter_index,  		HPI_ADAPTER_PROPERTY_CAPS1,  		NULL, &asihpi->support_grouping);  	if (err)  		asihpi->support_grouping = 0; -	err = hpi_adapter_get_property(ss, asihpi->adapter_index, +	err = hpi_adapter_get_property(adapter_index,  		HPI_ADAPTER_PROPERTY_CAPS2,  		&asihpi->support_mrx, NULL);  	if (err)  		asihpi->support_mrx = 0; -	err = hpi_adapter_get_property(ss, asihpi->adapter_index, +	err = hpi_adapter_get_property(adapter_index,  		HPI_ADAPTER_PROPERTY_INTERVAL,  		NULL, &asihpi->update_interval_frames);  	if (err)  		asihpi->update_interval_frames = 512; -	hpi_handle_error(hpi_instream_open(ss, asihpi->adapter_index, +	if (!asihpi->can_dma) +		asihpi->update_interval_frames *= 2; + +	hpi_handle_error(hpi_instream_open(adapter_index,  			     0, &h_stream)); -	err = hpi_instream_host_buffer_free(ss, h_stream); -	asihpi->support_mmap = (!err); +	err = hpi_instream_host_buffer_free(h_stream); +	asihpi->can_dma = (!err); -	hpi_handle_error(hpi_instream_close(ss, h_stream)); +	hpi_handle_error(hpi_instream_close(h_stream)); -	err = hpi_adapter_get_property(ss, asihpi->adapter_index, +	err = hpi_adapter_get_property(adapter_index,  		HPI_ADAPTER_PROPERTY_CURCHANNELS,  		&asihpi->in_max_chans, &asihpi->out_max_chans);  	if (err) { @@ -2905,14 +2887,22 @@ static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev,  		asihpi->out_max_chans = 2;  	} -	snd_printk(KERN_INFO "supports mmap:%d grouping:%d mrx:%d\n", -			asihpi->support_mmap, +	if (asihpi->out_max_chans > 2) { /* assume LL mode */ +		asihpi->out_min_chans = asihpi->out_max_chans; +		asihpi->in_min_chans = asihpi->in_max_chans; +		asihpi->support_grouping = 0; +	} else { +		asihpi->out_min_chans = 1; +		asihpi->in_min_chans = 1; +	} + +	snd_printk(KERN_INFO "Has dma:%d, grouping:%d, mrx:%d\n", +			asihpi->can_dma,  			asihpi->support_grouping,  			asihpi->support_mrx  	      ); - -	err = snd_card_asihpi_pcm_new(asihpi, 0, pcm_substreams); +	err = snd_card_asihpi_pcm_new(asihpi, 0);  	if (err < 0) {  		snd_printk(KERN_ERR "pcm_new failed\n");  		goto __nodev; @@ -2923,13 +2913,13 @@ static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev,  		goto __nodev;  	} -	err = hpi_mixer_get_control(ss, asihpi->h_mixer, +	err = hpi_mixer_get_control(asihpi->h_mixer,  				  HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,  				  HPI_CONTROL_SAMPLECLOCK, &h_control);  	if (!err)  		err = hpi_sample_clock_set_local_rate( -			ss, h_control, adapter_fs); +			h_control, adapter_fs);  	snd_asihpi_proc_init(asihpi); @@ -2937,17 +2927,16 @@ static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev,  	    by enable_hwdep  module param*/  	snd_asihpi_hpi_new(asihpi, 0, NULL); -	if (asihpi->support_mmap) -		strcpy(card->driver, "ASIHPI-MMAP"); -	else -		strcpy(card->driver, "ASIHPI"); +	strcpy(card->driver, "ASIHPI"); -	sprintf(card->shortname, "AudioScience ASI%4X", asihpi->type); +	sprintf(card->shortname, "AudioScience ASI%4X", +			asihpi->hpi->adapter->type);  	sprintf(card->longname, "%s %i", -			card->shortname, asihpi->adapter_index); +			card->shortname, adapter_index);  	err = snd_card_register(card); +  	if (!err) { -		hpi_card->snd_card_asihpi = card; +		hpi->snd_card = card;  		dev++;  		return 0;  	} @@ -2958,12 +2947,11 @@ __nodev:  } -static void __devexit snd_asihpi_remove(struct pci_dev *pci_dev) +static void snd_asihpi_remove(struct pci_dev *pci_dev)  { -	struct hpi_adapter *hpi_card = pci_get_drvdata(pci_dev); - -	snd_card_free(hpi_card->snd_card_asihpi); -	hpi_card->snd_card_asihpi = NULL; +	struct hpi_adapter *hpi = pci_get_drvdata(pci_dev); +	snd_card_free(hpi->snd_card); +	hpi->snd_card = NULL;  	asihpi_adapter_remove(pci_dev);  } @@ -2979,11 +2967,11 @@ static DEFINE_PCI_DEVICE_TABLE(asihpi_pci_tbl) = {  MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);  static struct pci_driver driver = { -	.name = "asihpi", +	.name = KBUILD_MODNAME,  	.id_table = asihpi_pci_tbl,  	.probe = snd_asihpi_probe, -	.remove = __devexit_p(snd_asihpi_remove), -#ifdef CONFIG_PM +	.remove = snd_asihpi_remove, +#ifdef CONFIG_PM_SLEEP  /*	.suspend = snd_asihpi_suspend,  	.resume = snd_asihpi_resume, */  #endif diff --git a/sound/pci/asihpi/hpi.h b/sound/pci/asihpi/hpi.h index 23399d02f66..20887241a3a 100644 --- a/sound/pci/asihpi/hpi.h +++ b/sound/pci/asihpi/hpi.h @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -24,46 +24,20 @@   The HPI is a low-level hardware abstraction layer to all   AudioScience digital audio adapters -*/ -/* - You must define one operating system that the HPI is to be compiled under - HPI_OS_WIN32_USER   32bit Windows - HPI_OS_DSP_C6000    DSP TI C6000  (automatically set) - HPI_OS_WDM          Windows WDM kernel driver - HPI_OS_LINUX        Linux userspace - HPI_OS_LINUX_KERNEL Linux kernel (automatically set)  (C) Copyright AudioScience Inc. 1998-2010 -******************************************************************************/ -#ifndef _HPI_H_ -#define _HPI_H_ -/* HPI Version -If HPI_VER_MINOR is odd then its a development release not intended for the -public. If HPI_VER_MINOR is even then is a release version -i.e 3.05.02 is a development version  */ -#define HPI_VERSION_CONSTRUCTOR(maj, min, rel) \ -	((maj << 16) + (min << 8) + rel) - -#define HPI_VER_MAJOR(v) ((int)(v >> 16)) -#define HPI_VER_MINOR(v) ((int)((v >> 8) & 0xFF)) -#define HPI_VER_RELEASE(v) ((int)(v & 0xFF)) - -/* Use single digits for versions less that 10 to avoid octal. */ -#define HPI_VER HPI_VERSION_CONSTRUCTOR(4L, 4, 1) -#define HPI_VER_STRING "4.04.01" -/* Library version as documented in hpi-api-versions.txt */ -#define HPI_LIB_VER  HPI_VERSION_CONSTRUCTOR(9, 0, 0) +#ifndef _HPI_H_ +#define _HPI_H_  #include <linux/types.h> -#define HPI_EXCLUDE_DEPRECATED +#define HPI_BUILD_KERNEL_MODE  /******************************************************************************/ -/******************************************************************************/  /********       HPI API DEFINITIONS                                       *****/  /******************************************************************************/ -/******************************************************************************/ +  /*******************************************/  /**  Audio format types  \ingroup stream @@ -174,7 +148,6 @@ The range is +1.0 to -1.0, which corresponds to digital fullscale.  	HPI_FORMAT_UNDEFINED = 0xffff  }; -/******************************************* in/out Stream states */  /*******************************************/  /** Stream States  \ingroup stream @@ -194,7 +167,7 @@ enum HPI_STREAM_STATES {  		cards to be ready. */  	HPI_STATE_WAIT = 6  }; -/******************************************* mixer source node types */ +/*******************************************/  /** Source node types  \ingroup mixer  */ @@ -219,12 +192,16 @@ enum HPI_SOURCENODES {  	HPI_SOURCENODE_COBRANET = 109,  	HPI_SOURCENODE_ANALOG = 110,	     /**< analog input node. */  	HPI_SOURCENODE_ADAPTER = 111,	     /**< adapter node. */ +	/** RTP stream input node - This node is a destination for +	    packets of RTP audio samples from other devices. */ +	HPI_SOURCENODE_RTP_DESTINATION = 112, +	HPI_SOURCENODE_INTERNAL = 113,	     /**< node internal to the device. */  	/* !!!Update this  AND hpidebug.h if you add a new sourcenode type!!! */ -	HPI_SOURCENODE_LAST_INDEX = 111	     /**< largest ID */ +	HPI_SOURCENODE_LAST_INDEX = 113	     /**< largest ID */  		/* AX6 max sourcenode types = 15 */  }; -/******************************************* mixer dest node types */ +/*******************************************/  /** Destination node types  \ingroup mixer  */ @@ -236,7 +213,7 @@ enum HPI_DESTNODES {  	HPI_DESTNODE_NONE = 200,  	/** In Stream (Record) node. */  	HPI_DESTNODE_ISTREAM = 201, -	HPI_DESTNODE_LINEOUT = 202,	    /**< line out node. */ +	HPI_DESTNODE_LINEOUT = 202,	     /**< line out node. */  	HPI_DESTNODE_AESEBU_OUT = 203,	     /**< AES/EBU output node. */  	HPI_DESTNODE_RF = 204,		     /**< RF output node. */  	HPI_DESTNODE_SPEAKER = 205,	     /**< speaker output node. */ @@ -244,9 +221,11 @@ enum HPI_DESTNODES {  	    Audio samples from the device are sent out on the Cobranet network.*/  	HPI_DESTNODE_COBRANET = 206,  	HPI_DESTNODE_ANALOG = 207,	     /**< analog output node. */ - +	/** RTP stream output node - This node is a source for +	    packets of RTP audio samples that are sent to other devices. */ +	HPI_DESTNODE_RTP_SOURCE = 208,  	/* !!!Update this AND hpidebug.h if you add a new destnode type!!! */ -	HPI_DESTNODE_LAST_INDEX = 207	     /**< largest ID */ +	HPI_DESTNODE_LAST_INDEX = 208	     /**< largest ID */  		/* AX6 max destnode types = 15 */  }; @@ -262,11 +241,11 @@ enum HPI_CONTROLS {  	HPI_CONTROL_MUTE = 4,	/*mute control - not used at present. */  	HPI_CONTROL_MULTIPLEXER = 5,	/**< multiplexer control. */ -	HPI_CONTROL_AESEBU_TRANSMITTER = 6,	/**< AES/EBU transmitter control. */ -	HPI_CONTROL_AESEBUTX = HPI_CONTROL_AESEBU_TRANSMITTER, +	HPI_CONTROL_AESEBU_TRANSMITTER = 6, /**< AES/EBU transmitter control */ +	HPI_CONTROL_AESEBUTX = 6,	/* HPI_CONTROL_AESEBU_TRANSMITTER */  	HPI_CONTROL_AESEBU_RECEIVER = 7, /**< AES/EBU receiver control. */ -	HPI_CONTROL_AESEBURX = HPI_CONTROL_AESEBU_RECEIVER, +	HPI_CONTROL_AESEBURX = 7,	/* HPI_CONTROL_AESEBU_RECEIVER */  	HPI_CONTROL_LEVEL = 8, /**< level/trim control - works in d_bu. */  	HPI_CONTROL_TUNER = 9,	/**< tuner control. */ @@ -281,7 +260,7 @@ enum HPI_CONTROLS {  	HPI_CONTROL_SAMPLECLOCK = 17,	/**< sample clock control. */  	HPI_CONTROL_MICROPHONE = 18,	/**< microphone control. */  	HPI_CONTROL_PARAMETRIC_EQ = 19,	/**< parametric EQ control. */ -	HPI_CONTROL_EQUALIZER = HPI_CONTROL_PARAMETRIC_EQ, +	HPI_CONTROL_EQUALIZER = 19,	/*HPI_CONTROL_PARAMETRIC_EQ */  	HPI_CONTROL_COMPANDER = 20,	/**< compander control. */  	HPI_CONTROL_COBRANET = 21,	/**< cobranet control. */ @@ -296,10 +275,7 @@ enum HPI_CONTROLS {  /* WARNING types 256 or greater impact bit packing in all AX6 DSP code */  }; -/* Shorthand names that match attribute names */ - -/******************************************* ADAPTER ATTRIBUTES ****/ - +/*******************************************/  /** Adapter properties  These are used in HPI_AdapterSetProperty() and HPI_AdapterGetProperty()  \ingroup adapter @@ -330,12 +306,21 @@ by the driver and is not passed on to the DSP at all.  Indicates the state of the adapter's SSX2 setting. This setting is stored in  non-volatile memory on the adapter. A typical call sequence would be to use  HPI_ADAPTER_PROPERTY_SSX2_SETTING to set SSX2 on the adapter and then to reload -the driver. The driver would query HPI_ADAPTER_PROPERTY_SSX2_SETTING during startup -and if SSX2 is set, it would then call HPI_ADAPTER_PROPERTY_ENABLE_SSX2 to enable -SSX2 stream mapping within the kernel level of the driver. +the driver. The driver would query HPI_ADAPTER_PROPERTY_SSX2_SETTING during +startup and if SSX2 is set, it would then call HPI_ADAPTER_PROPERTY_ENABLE_SSX2 +to enable SSX2 stream mapping within the kernel level of the driver.  */  	HPI_ADAPTER_PROPERTY_SSX2_SETTING = 4, +/** Enables/disables PCI(e) IRQ. +A setting of 0 indicates that no interrupts are being generated. A DSP boot +this property is set to 0. Setting to a non-zero value specifies the number +of frames of audio that should be processed between interrupts. This property +should be set to multiple of the mixer interval as read back from the +HPI_ADAPTER_PROPERTY_INTERVAL property. +*/ +	HPI_ADAPTER_PROPERTY_IRQ_RATE = 5, +  /** Base number for readonly properties */  	HPI_ADAPTER_PROPERTY_READONLYBASE = 256, @@ -440,21 +425,42 @@ return value is true (1) or false (0). If the current adapter  mode is MONO SSX2 is disabled, even though this property will  return true.  */ -	HPI_ADAPTER_PROPERTY_SUPPORTS_SSX2 = 271 +	HPI_ADAPTER_PROPERTY_SUPPORTS_SSX2 = 271, +/** Readonly supports PCI(e) IRQ. +Indicates that the adapter in it's current mode supports interrupts +across the host bus. Note, this does not imply that interrupts are +enabled. Instead it indicates that they can be enabled. +*/ +	HPI_ADAPTER_PROPERTY_SUPPORTS_IRQ = 272, +/** Readonly supports firmware updating. +Indicates that the adapter implements an interface to update firmware +on the adapter. +*/ +	HPI_ADAPTER_PROPERTY_SUPPORTS_FW_UPDATE = 273, +/** Readonly Firmware IDs +Identifiy firmware independent of individual adapter type. +May be used as a filter for firmware update images. +Property 1 = Bootloader ID +Property 2 = Main program ID +*/ +	HPI_ADAPTER_PROPERTY_FIRMWARE_ID = 274  };  /** Adapter mode commands -Used in wQueryOrSet field of HPI_AdapterSetModeEx(). +Used in wQueryOrSet parameter of HPI_AdapterSetModeEx().  \ingroup adapter  */  enum HPI_ADAPTER_MODE_CMDS { +	/** Set the mode to the given parameter */  	HPI_ADAPTER_MODE_SET = 0, +	/** Return 0 or error depending whether mode is valid, +	but don't set the mode */  	HPI_ADAPTER_MODE_QUERY = 1  };  /** Adapter Modes -	These are used by HPI_AdapterSetModeEx() + These are used by HPI_AdapterSetModeEx()  \warning - more than 16 possible modes breaks  a bitmask in the Windows WAVE DLL @@ -625,14 +631,17 @@ enum HPI_MIXER_STORE_COMMAND {  	HPI_MIXER_STORE_ENABLE = 4,  /** Disable auto storage of some control settings. */  	HPI_MIXER_STORE_DISABLE = 5, -/** Save the attributes of a single control. */ +/** Unimplemented - save the attributes of a single control. */  	HPI_MIXER_STORE_SAVE_SINGLE = 6  }; -/************************************* CONTROL ATTRIBUTE VALUES ****/ +/****************************/ +/* CONTROL ATTRIBUTE VALUES */ +/****************************/ +  /** Used by mixer plugin enable functions -E.g. HPI_ParametricEQ_SetState() +E.g. HPI_ParametricEq_SetState()  \ingroup mixer  */  enum HPI_SWITCH_STATES { @@ -641,6 +650,7 @@ enum HPI_SWITCH_STATES {  };  /* Volume control special gain values */ +  /** volumes units are 100ths of a dB  \ingroup volume  */ @@ -650,6 +660,11 @@ enum HPI_SWITCH_STATES {  */  #define HPI_GAIN_OFF                    (-100 * HPI_UNITS_PER_dB) +/** channel mask specifying all channels +\ingroup volume +*/ +#define HPI_BITMASK_ALL_CHANNELS        (0xFFFFFFFF) +  /** value returned for no signal  \ingroup meter  */ @@ -667,7 +682,7 @@ enum HPI_VOLUME_AUTOFADES {  /** The physical encoding format of the AESEBU I/O. -Used in HPI_AESEBU_Transmitter_SetFormat(), HPI_AESEBU_Receiver_SetFormat() +Used in HPI_Aesebu_Transmitter_SetFormat(), HPI_Aesebu_Receiver_SetFormat()  along with related Get and Query functions  \ingroup aestx  */ @@ -680,7 +695,7 @@ enum HPI_AESEBU_FORMATS {  /** AES/EBU error status bits -Returned by HPI_AESEBU_Receiver_GetErrorStatus() +Returned by HPI_Aesebu_Receiver_GetErrorStatus()  \ingroup aesrx  */  enum HPI_AESEBU_ERRORS { @@ -709,7 +724,7 @@ enum HPI_AESEBU_ERRORS {  #define HPI_PAD_TITLE_LEN               64  /** The text string containing the comment. */  #define HPI_PAD_COMMENT_LEN             256 -/** The PTY when the tuner has not recieved any PTY. */ +/** The PTY when the tuner has not received any PTY. */  #define HPI_PAD_PROGRAM_TYPE_INVALID    0xffff  /** \} */ @@ -767,14 +782,6 @@ enum HPI_TUNER_MODE_VALUES {  	HPI_TUNER_MODE_RDS_RBDS = 2 /**<  RDS - RBDS mode */  }; -/** Tuner Level settings -\ingroup tuner -*/ -enum HPI_TUNER_LEVEL { -	HPI_TUNER_LEVEL_AVERAGE = 0, -	HPI_TUNER_LEVEL_RAW = 1 -}; -  /** Tuner Status Bits  These bitfield values are returned by a call to HPI_Tuner_GetStatus(). @@ -783,13 +790,13 @@ Multiple fields are returned from a single call.  */  enum HPI_TUNER_STATUS_BITS {  	HPI_TUNER_VIDEO_COLOR_PRESENT = 0x0001,	/**< video color is present. */ -	HPI_TUNER_VIDEO_IS_60HZ = 0x0020,	/**< 60 hz video detected. */ -	HPI_TUNER_VIDEO_HORZ_SYNC_MISSING = 0x0040,	/**< video HSYNC is missing. */ -	HPI_TUNER_VIDEO_STATUS_VALID = 0x0100,	/**< video status is valid. */ -	HPI_TUNER_PLL_LOCKED = 0x1000,		/**< the tuner's PLL is locked. */ -	HPI_TUNER_FM_STEREO = 0x2000,		/**< tuner reports back FM stereo. */ -	HPI_TUNER_DIGITAL = 0x0200,		/**< tuner reports digital programming. */ -	HPI_TUNER_MULTIPROGRAM = 0x0400		/**< tuner reports multiple programs. */ +	HPI_TUNER_VIDEO_IS_60HZ = 0x0020, /**< 60 hz video detected. */ +	HPI_TUNER_VIDEO_HORZ_SYNC_MISSING = 0x0040, /**< video HSYNC is missing. */ +	HPI_TUNER_VIDEO_STATUS_VALID = 0x0100, /**< video status is valid. */ +	HPI_TUNER_DIGITAL = 0x0200, /**< tuner reports digital programming. */ +	HPI_TUNER_MULTIPROGRAM = 0x0400, /**< tuner reports multiple programs. */ +	HPI_TUNER_PLL_LOCKED = 0x1000, /**< the tuner's PLL is locked. */ +	HPI_TUNER_FM_STEREO = 0x2000 /**< tuner reports back FM stereo. */  };  /** Channel Modes @@ -839,7 +846,7 @@ enum HPI_SAMPLECLOCK_SOURCES {  	HPI_SAMPLECLOCK_SOURCE_LAST = 10  }; -/** Equalizer filter types. Used by HPI_ParametricEQ_SetBand() +/** Equalizer filter types. Used by HPI_ParametricEq_SetBand()  \ingroup parmeq  */  enum HPI_FILTER_TYPE { @@ -882,7 +889,7 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_INVALID_OBJ = 101,  	/** Function does not exist. */  	HPI_ERROR_INVALID_FUNC = 102, -	/** The specified object (adapter/Stream) does not exist. */ +	/** The specified object does not exist. */  	HPI_ERROR_INVALID_OBJ_INDEX = 103,  	/** Trying to access an object that has not been opened yet. */  	HPI_ERROR_OBJ_NOT_OPEN = 104, @@ -890,8 +897,7 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_OBJ_ALREADY_OPEN = 105,  	/** PCI, ISA resource not valid. */  	HPI_ERROR_INVALID_RESOURCE = 106, -	/** GetInfo call from SubSysFindAdapters failed. */ -	HPI_ERROR_SUBSYSFINDADAPTERS_GETINFO = 107, +	/* HPI_ERROR_SUBSYSFINDADAPTERS_GETINFO= 107 */  	/** Default response was never updated with actual error code. */  	HPI_ERROR_INVALID_RESPONSE = 108,  	/** wSize field of response was not updated, @@ -899,38 +905,44 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_PROCESSING_MESSAGE = 109,  	/** The network did not respond in a timely manner. */  	HPI_ERROR_NETWORK_TIMEOUT = 110, -	/** An HPI handle is invalid (uninitialised?). */ +	/* An HPI handle is invalid (uninitialised?). */  	HPI_ERROR_INVALID_HANDLE = 111,  	/** A function or attribute has not been implemented yet. */  	HPI_ERROR_UNIMPLEMENTED = 112, -	/** There are too many clients attempting to access a network resource. */ +	/** There are too many clients attempting +	    to access a network resource. */  	HPI_ERROR_NETWORK_TOO_MANY_CLIENTS = 113, -	/** Response buffer passed to HPI_Message was smaller than returned response */ +	/** Response buffer passed to HPI_Message +	    was smaller than returned response. +	    wSpecificError field of hpi response contains the required size. +	*/  	HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL = 114,  	/** The returned response did not match the sent message */  	HPI_ERROR_RESPONSE_MISMATCH = 115, +	/** A control setting that should have been cached was not. */ +	HPI_ERROR_CONTROL_CACHING = 116, +	/** A message buffer in the path to the adapter was smaller +	    than the message size. +	    wSpecificError field of hpi response contains the actual size. +	*/ +	HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL = 117, -	/** Too many adapters.*/ -	HPI_ERROR_TOO_MANY_ADAPTERS = 200, +	/* HPI_ERROR_TOO_MANY_ADAPTERS= 200 */  	/** Bad adpater. */  	HPI_ERROR_BAD_ADAPTER = 201,  	/** Adapter number out of range or not set properly. */  	HPI_ERROR_BAD_ADAPTER_NUMBER = 202,  	/** 2 adapters with the same adapter number. */ -	HPI_DUPLICATE_ADAPTER_NUMBER = 203, -	/** DSP code failed to bootload. */ +	HPI_ERROR_DUPLICATE_ADAPTER_NUMBER = 203, +	/** DSP code failed to bootload. Usually a DSP memory test failure. */  	HPI_ERROR_DSP_BOOTLOAD = 204, -	/** Adapter failed DSP code self test. */ -	HPI_ERROR_DSP_SELFTEST = 205,  	/** Couldn't find or open the DSP code file. */  	HPI_ERROR_DSP_FILE_NOT_FOUND = 206,  	/** Internal DSP hardware error. */  	HPI_ERROR_DSP_HARDWARE = 207, -	/** Could not allocate memory in DOS. */ -	HPI_ERROR_DOS_MEMORY_ALLOC = 208,  	/** Could not allocate memory */  	HPI_ERROR_MEMORY_ALLOC = 208, -	/** Failed to correctly load/config PLD .*/ +	/** Failed to correctly load/config PLD. (unused) */  	HPI_ERROR_PLD_LOAD = 209,  	/** Unexpected end of file, block length too big etc. */  	HPI_ERROR_DSP_FILE_FORMAT = 210, @@ -939,8 +951,7 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_DSP_FILE_ACCESS_DENIED = 211,  	/** First DSP code section header not found in DSP file. */  	HPI_ERROR_DSP_FILE_NO_HEADER = 212, -	/** File read operation on DSP code file failed. */ -	HPI_ERROR_DSP_FILE_READ_ERROR = 213, +	/* HPI_ERROR_DSP_FILE_READ_ERROR= 213, */  	/** DSP code for adapter family not found. */  	HPI_ERROR_DSP_SECTION_NOT_FOUND = 214,  	/** Other OS specific error opening DSP file. */ @@ -950,23 +961,24 @@ enum HPI_ERROR_CODES {  	/** DSP code section header had size == 0. */  	HPI_ERROR_DSP_FILE_NULL_HEADER = 217, -	/** Base number for flash errors. */ -	HPI_ERROR_FLASH = 220, +	/* HPI_ERROR_FLASH = 220, */  	/** Flash has bad checksum */ -	HPI_ERROR_BAD_CHECKSUM = (HPI_ERROR_FLASH + 1), -	HPI_ERROR_BAD_SEQUENCE = (HPI_ERROR_FLASH + 2), -	HPI_ERROR_FLASH_ERASE = (HPI_ERROR_FLASH + 3), -	HPI_ERROR_FLASH_PROGRAM = (HPI_ERROR_FLASH + 4), -	HPI_ERROR_FLASH_VERIFY = (HPI_ERROR_FLASH + 5), -	HPI_ERROR_FLASH_TYPE = (HPI_ERROR_FLASH + 6), -	HPI_ERROR_FLASH_START = (HPI_ERROR_FLASH + 7), +	HPI_ERROR_BAD_CHECKSUM = 221, +	HPI_ERROR_BAD_SEQUENCE = 222, +	HPI_ERROR_FLASH_ERASE = 223, +	HPI_ERROR_FLASH_PROGRAM = 224, +	HPI_ERROR_FLASH_VERIFY = 225, +	HPI_ERROR_FLASH_TYPE = 226, +	HPI_ERROR_FLASH_START = 227, +	HPI_ERROR_FLASH_READ = 228, +	HPI_ERROR_FLASH_READ_NO_FILE = 229, +	HPI_ERROR_FLASH_SIZE = 230,  	/** Reserved for OEMs. */  	HPI_ERROR_RESERVED_1 = 290, -	/** Stream does not exist. */ -	HPI_ERROR_INVALID_STREAM = 300, +	/* HPI_ERROR_INVALID_STREAM = 300 use HPI_ERROR_INVALID_OBJ_INDEX */  	/** Invalid compression format. */  	HPI_ERROR_INVALID_FORMAT = 301,  	/** Invalid format samplerate */ @@ -977,21 +989,19 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_INVALID_BITRATE = 304,  	/** Invalid datasize used for stream read/write. */  	HPI_ERROR_INVALID_DATASIZE = 305, -	/** Stream buffer is full during stream write. */ -	HPI_ERROR_BUFFER_FULL = 306, -	/** Stream buffer is empty during stream read. */ -	HPI_ERROR_BUFFER_EMPTY = 307, -	/** Invalid datasize used for stream read/write. */ -	HPI_ERROR_INVALID_DATA_TRANSFER = 308, +	/* HPI_ERROR_BUFFER_FULL = 306 use HPI_ERROR_INVALID_DATASIZE */ +	/* HPI_ERROR_BUFFER_EMPTY = 307 use HPI_ERROR_INVALID_DATASIZE */ +	/** Null data pointer used for stream read/write. */ +	HPI_ERROR_INVALID_DATA_POINTER = 308,  	/** Packet ordering error for stream read/write. */  	HPI_ERROR_INVALID_PACKET_ORDER = 309,  	/** Object can't do requested operation in its current -	state, eg set format, change rec mux state while recording.*/ +	    state, eg set format, change rec mux state while recording.*/  	HPI_ERROR_INVALID_OPERATION = 310, -	/** Where an SRG is shared amongst streams, an incompatible samplerate is one -	that is different to any currently playing or recording stream. */ +	/** Where a SRG is shared amongst streams, an incompatible samplerate +	    is one that is different to any currently active stream. */  	HPI_ERROR_INCOMPATIBLE_SAMPLERATE = 311,  	/** Adapter mode is illegal.*/  	HPI_ERROR_BAD_ADAPTER_MODE = 312, @@ -1004,6 +1014,10 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_NO_INTERADAPTER_GROUPS = 314,  	/** Streams on different DSPs cannot be grouped. */  	HPI_ERROR_NO_INTERDSP_GROUPS = 315, +	/** Stream wait cancelled before threshold reached. */ +	HPI_ERROR_WAIT_CANCELLED = 316, +	/** A character string is invalid. */ +	HPI_ERROR_INVALID_STRING = 317,  	/** Invalid mixer node for this adapter. */  	HPI_ERROR_INVALID_NODE = 400, @@ -1017,6 +1031,7 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_CONTROL_DISABLED = 404,  	/** I2C transaction failed due to a missing ACK. */  	HPI_ERROR_CONTROL_I2C_MISSING_ACK = 405, +	HPI_ERROR_I2C_MISSING_ACK = 405,  	/** Control is busy, or coming out of  	reset and cannot be accessed at this time. */  	HPI_ERROR_CONTROL_NOT_READY = 407, @@ -1027,14 +1042,18 @@ enum HPI_ERROR_CODES {  	HPI_ERROR_NVMEM_FAIL = 452,  	/** I2C */ -	HPI_ERROR_I2C_MISSING_ACK = HPI_ERROR_CONTROL_I2C_MISSING_ACK,  	HPI_ERROR_I2C_BAD_ADR = 460, -	/** Entity errors */ +	/** Entity type did not match requested type */  	HPI_ERROR_ENTITY_TYPE_MISMATCH = 470, +	/** Entity item count did not match requested count */  	HPI_ERROR_ENTITY_ITEM_COUNT = 471, +	/** Entity type is not one of the valid types */  	HPI_ERROR_ENTITY_TYPE_INVALID = 472, +	/** Entity role is not one of the valid roles */  	HPI_ERROR_ENTITY_ROLE_INVALID = 473, +	/** Entity size doesn't match target size */ +	HPI_ERROR_ENTITY_SIZE_MISMATCH = 474,  	/* AES18 specific errors were 500..507 */ @@ -1044,18 +1063,24 @@ enum HPI_ERROR_CODES {  	/** hpioct32.c can't obtain mutex */  	HPI_ERROR_MUTEX_TIMEOUT = 700, -	/** errors from HPI backends have values >= this */ +	/** Backend errors used to be greater than this. +	    \deprecated Now, all backends return only errors defined here in hpi.h +	*/  	HPI_ERROR_BACKEND_BASE = 900, -	/** indicates a cached u16 value is invalid. */ -	HPI_ERROR_ILLEGAL_CACHE_VALUE = 0xffff +	/** Communication with DSP failed */ +	HPI_ERROR_DSP_COMMUNICATION = 900 +		/* Note that the dsp communication error is set to this value so that +		   it remains compatible with any software that expects such errors +		   to be backend errors i.e. >= 900. +		   Do not define any new error codes with values > 900. +		 */  };  /** \defgroup maximums HPI maximum values  \{  */ -/** Maximum number of adapters per HPI sub-system -   WARNING: modifying this value changes the response structure size.*/ +/** Maximum number of PCI HPI adapters */  #define HPI_MAX_ADAPTERS                20  /** Maximum number of in or out streams per adapter */  #define HPI_MAX_STREAMS                 16 @@ -1066,6 +1091,9 @@ enum HPI_ERROR_CODES {  #define HPI_MAX_ANC_BYTES_PER_FRAME     (64)  #define HPI_STRING_LEN                  16 +/** Networked adapters have index >= 100 */ +#define HPI_MIN_NETWORK_ADAPTER_IDX 100 +  /** Velocity units */  #define HPI_OSTREAM_VELOCITY_UNITS      4096  /** OutStream timescale units */ @@ -1075,7 +1103,7 @@ enum HPI_ERROR_CODES {  /**\}*/ -/* ////////////////////////////////////////////////////////////////////// */ +/**************/  /* STRUCTURES */  #ifndef DISABLE_PRAGMA_PACK1  #pragma pack(push, 1) @@ -1087,14 +1115,14 @@ enum HPI_ERROR_CODES {  struct hpi_format {  	u32 sample_rate;  				/**< 11025, 32000, 44100 ... */ -	u32 bit_rate;	      /**< for MPEG */ +	u32 bit_rate;		  /**< for MPEG */  	u32 attributes;  				/**< Stereo/JointStereo/Mono */  	u16 mode_legacy;  				/**< Legacy ancillary mode or idle bit  */ -	u16 unused;	      /**< unused */ -	u16 channels; /**< 1,2..., (or ancillary mode or idle bit */ -	u16 format;   /**< HPI_FORMAT_PCM16, _MPEG etc. see #HPI_FORMATS. */ +	u16 unused;		  /**< Unused */ +	u16 channels;	  /**< 1,2..., (or ancillary mode or idle bit */ +	u16 format;	  /**< HPI_FORMAT_PCM16, _MPEG etc. see #HPI_FORMATS. */  };  struct hpi_anc_frame { @@ -1106,930 +1134,594 @@ struct hpi_anc_frame {  */  struct hpi_async_event {  	u16 event_type;	/**< type of event. \sa async_event  */ -	u16 sequence;  /**< sequence number, allows lost event detection */ -	u32 state;    /**< new state */ -	u32 h_object;	 /**< handle to the object returning the event. */ +	u16 sequence; /**< Sequence number, allows lost event detection */ +	u32 state; /**< New state */ +	u32 h_object; /**< handle to the object returning the event. */  	union {  		struct {  			u16 index; /**< GPIO bit index. */  		} gpio;  		struct {  			u16 node_index;	/**< what node is the control on ? */ -			u16 node_type;	/**< what type of node is the control on ? */ +			u16 node_type; /**< what type of node is the control on ? */  		} control;  	} u;  }; -/*/////////////////////////////////////////////////////////////////////////// */ -/* Public HPI Entity related definitions                                     */ - -struct hpi_entity; - -enum e_entity_type { -	entity_type_null, -	entity_type_sequence,	/* sequence of potentially heterogeneous TLV entities */ - -	entity_type_reference,	/* refers to a TLV entity or NULL */ - -	entity_type_int,	/* 32 bit */ -	entity_type_float,	/* ieee754 binary 32 bit encoding */ -	entity_type_double, - -	entity_type_cstring, -	entity_type_octet, -	entity_type_ip4_address, -	entity_type_ip6_address, -	entity_type_mac_address, - -	LAST_ENTITY_TYPE -}; - -enum e_entity_role { -	entity_role_null, -	entity_role_value, -	entity_role_classname, - -	entity_role_units, -	entity_role_flags, -	entity_role_range, - -	entity_role_mapping, -	entity_role_enum, - -	entity_role_instance_of, -	entity_role_depends_on, -	entity_role_member_of_group, -	entity_role_value_constraint, -	entity_role_parameter_port, - -	entity_role_block, -	entity_role_node_group, -	entity_role_audio_port, -	entity_role_clock_port, -	LAST_ENTITY_ROLE -}; - -/* skip host side function declarations for -   DSP compile and documentation extraction */ - -struct hpi_hsubsys { -	int not_really_used; -}; -  #ifndef DISABLE_PRAGMA_PACK1  #pragma pack(pop)  #endif -/*////////////////////////////////////////////////////////////////////////// */ +/*****************/  /* HPI FUNCTIONS */ +/*****************/ -/*/////////////////////////// */ -/* DATA and FORMAT and STREAM */ - +/* Stream */  u16 hpi_stream_estimate_buffer_size(struct hpi_format *pF,  	u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size); -/*/////////// */ -/* SUB SYSTEM */ -struct hpi_hsubsys *hpi_subsys_create(void -	); - -void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys); - -u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, -	u32 *pversion); - -u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys, -	u32 *pversion_ex); - -u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion, -	u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length); - -u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys, -	u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length); +/*************/ +/* SubSystem */ +/*************/ -u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys, -	int *pn_num_adapters); +u16 hpi_subsys_get_version_ex(u32 *pversion_ex); -u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator, -	u32 *padapter_index, u16 *pw_adapter_type); +u16 hpi_subsys_get_num_adapters(int *pn_num_adapters); -u16 hpi_subsys_ssx2_bypass(const struct hpi_hsubsys *ph_subsys, u16 bypass); +u16 hpi_subsys_get_adapter(int iterator, u32 *padapter_index, +	u16 *pw_adapter_type); -u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys, -	const char *sz_interface); +/***********/ +/* Adapter */ +/***********/ -/*///////// */ -/* ADAPTER */ +u16 hpi_adapter_open(u16 adapter_index); -u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index); +u16 hpi_adapter_close(u16 adapter_index); -u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index); +u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams, +	u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number, +	u16 *pw_adapter_type); -u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 *pw_num_outstreams, u16 *pw_num_instreams, -	u16 *pw_version, u32 *pserial_number, u16 *pw_adapter_type); +u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index, +	u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version, +	u32 *pserial_number, u16 *pw_module_type, u32 *ph_module); -u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 module_index, u16 *pw_num_outputs, -	u16 *pw_num_inputs, u16 *pw_version, u32 *pserial_number, -	u16 *pw_module_type, u32 *ph_module); +u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode); -u16 hpi_adapter_set_mode(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 adapter_mode); +u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode, +	u16 query_or_set); -u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 adapter_mode, u16 query_or_set); +u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode); -u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 *padapter_mode); +u16 hpi_adapter_get_assert2(u16 adapter_index, u16 *p_assert_count, +	char *psz_assert, u32 *p_param1, u32 *p_param2, +	u32 *p_dsp_string_addr, u16 *p_processor_id); -u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 *assert_present, char *psz_assert, -	u16 *pw_line_number); +u16 hpi_adapter_test_assert(u16 adapter_index, u16 assert_id); -u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 *assert_present, char *psz_assert, -	u32 *pline_number, u16 *pw_assert_on_dsp); +u16 hpi_adapter_enable_capability(u16 adapter_index, u16 capability, u32 key); -u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 assert_id); +u16 hpi_adapter_self_test(u16 adapter_index); -u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 capability, u32 key); +u16 hpi_adapter_debug_read(u16 adapter_index, u32 dsp_address, char *p_bytes, +	int *count_bytes); -u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index); +u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 paramter1, +	u16 paramter2); -u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 dsp_address, char *p_bytes, int *count_bytes); +u16 hpi_adapter_get_property(u16 adapter_index, u16 property, +	u16 *pw_paramter1, u16 *pw_paramter2); -u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 property, u16 paramter1, u16 paramter2); +u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index, +	u16 what_to_enumerate, u16 property_index, u32 *psetting); +/*************/ +/* OutStream */ +/*************/ +u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index, +	u32 *ph_outstream); -u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 property, u16 *pw_paramter1, -	u16 *pw_paramter2); +u16 hpi_outstream_close(u32 h_outstream); -u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 index, u16 what_to_enumerate, -	u16 property_index, u32 *psetting); +u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state, +	u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played, +	u32 *pauxiliary_data_to_play); -/*////////////// */ -/* NonVol Memory */ -u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_nv_memory, u16 *pw_size_in_bytes); +u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_write_buf, +	u32 bytes_to_write, const struct hpi_format *p_format); -u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys, -	u32 h_nv_memory, u16 index, u16 *pw_data); +u16 hpi_outstream_start(u32 h_outstream); -u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys, -	u32 h_nv_memory, u16 index, u16 data); +u16 hpi_outstream_wait_start(u32 h_outstream); -/*////////////// */ -/* Digital I/O */ -u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits); +u16 hpi_outstream_stop(u32 h_outstream); -u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 bit_index, u16 *pw_bit_data); +u16 hpi_outstream_sinegen(u32 h_outstream); -u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 aw_all_bit_data[4] -	); - -u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 bit_index, u16 bit_data); - -u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 aw_all_bit_data[4] -	); - -/**********************/ -/* Async Event Object */ -/**********************/ -u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 *ph_async); - -u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async); - -u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async, -	u16 maximum_events, struct hpi_async_event *p_events, -	u16 *pw_number_returned); - -u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys, -	u32 h_async, u16 *pw_count); - -u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async, -	u16 maximum_events, struct hpi_async_event *p_events, -	u16 *pw_number_returned); +u16 hpi_outstream_reset(u32 h_outstream); -/*/////////// */ -/* WATCH-DOG  */ -u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_watchdog); - -u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog, -	u32 time_millisec); - -u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog); - -/**************/ -/* OUT STREAM */ -/**************/ -u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u16 outstream_index, u32 *ph_outstream); - -u16 hpi_outstream_close(const struct hpi_hsubsys *ph_subsys, u32 h_outstream); - -u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_to_play, -	u32 *psamples_played, u32 *pauxiliary_data_to_play); - -u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, const u8 *pb_write_buf, u32 bytes_to_write, -	const struct hpi_format *p_format); +u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format); -u16 hpi_outstream_start(const struct hpi_hsubsys *ph_subsys, u32 h_outstream); +u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format); -u16 hpi_outstream_wait_start(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream); +u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample, +	u32 punch_out_sample); -u16 hpi_outstream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_outstream); +u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity); -u16 hpi_outstream_sinegen(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream); +u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode); -u16 hpi_outstream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_outstream); +u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available); -u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, struct hpi_format *p_format); - -u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, struct hpi_format *p_format); - -u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 punch_in_sample, u32 punch_out_sample); - -u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, short velocity); - -u16 hpi_outstream_ancillary_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u16 mode); - -u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 *pframes_available); - -u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, struct hpi_anc_frame *p_anc_frame_buffer, +u16 hpi_outstream_ancillary_read(u32 h_outstream, +	struct hpi_anc_frame *p_anc_frame_buffer,  	u32 anc_frame_buffer_size_in_bytes,  	u32 number_of_ancillary_frames_to_read); -u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 time_scaleX10000); +u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scaleX10000); -u16 hpi_outstream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 size_in_bytes); +u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes); -u16 hpi_outstream_host_buffer_free(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream); +u16 hpi_outstream_host_buffer_free(u32 h_outstream); -u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 h_stream); +u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream); -u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 *poutstream_map, u32 *pinstream_map); +u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map, +	u32 *pinstream_map); -u16 hpi_outstream_group_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream); +u16 hpi_outstream_group_reset(u32 h_outstream); -/*////////// */ -/* IN_STREAM */ -u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u16 instream_index, u32 *ph_instream); +/************/ +/* InStream */ +/************/ +u16 hpi_instream_open(u16 adapter_index, u16 instream_index, +	u32 *ph_instream); -u16 hpi_instream_close(const struct hpi_hsubsys *ph_subsys, u32 h_instream); +u16 hpi_instream_close(u32 h_instream); -u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, const struct hpi_format *p_format); +u16 hpi_instream_query_format(u32 h_instream, +	const struct hpi_format *p_format); -u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, const struct hpi_format *p_format); +u16 hpi_instream_set_format(u32 h_instream, +	const struct hpi_format *p_format); -u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream, -	u8 *pb_read_buf, u32 bytes_to_read); +u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_read_buf, u32 bytes_to_read); -u16 hpi_instream_start(const struct hpi_hsubsys *ph_subsys, u32 h_instream); +u16 hpi_instream_start(u32 h_instream); -u16 hpi_instream_wait_start(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream); +u16 hpi_instream_wait_start(u32 h_instream); -u16 hpi_instream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_instream); +u16 hpi_instream_stop(u32 h_instream); -u16 hpi_instream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_instream); +u16 hpi_instream_reset(u32 h_instream); -u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_recorded, -	u32 *psamples_recorded, u32 *pauxiliary_data_recorded); +u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size, +	u32 *pdata_recorded, u32 *psamples_recorded, +	u32 *pauxiliary_data_recorded); -u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u16 bytes_per_frame, u16 mode, u16 alignment, -	u16 idle_bit); +u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame, +	u16 mode, u16 alignment, u16 idle_bit); -u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 *pframe_space); +u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space); -u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, const struct hpi_anc_frame *p_anc_frame_buffer, +u16 hpi_instream_ancillary_write(u32 h_instream, +	const struct hpi_anc_frame *p_anc_frame_buffer,  	u32 anc_frame_buffer_size_in_bytes,  	u32 number_of_ancillary_frames_to_write); -u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 size_in_bytes); +u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes); -u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream); +u16 hpi_instream_host_buffer_free(u32 h_instream); -u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 h_stream); +u16 hpi_instream_group_add(u32 h_instream, u32 h_stream); -u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 *poutstream_map, u32 *pinstream_map); +u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map, +	u32 *pinstream_map); -u16 hpi_instream_group_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream); +u16 hpi_instream_group_reset(u32 h_instream);  /*********/ -/* MIXER */ +/* Mixer */  /*********/ -u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_mixer); - -u16 hpi_mixer_close(const struct hpi_hsubsys *ph_subsys, u32 h_mixer); - -u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer, -	u16 src_node_type, u16 src_node_type_index, u16 dst_node_type, -	u16 dst_node_type_index, u16 control_type, u32 *ph_control); - -u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys, -	u32 h_mixer, u16 control_index, u16 *pw_src_node_type, -	u16 *pw_src_node_index, u16 *pw_dst_node_type, u16 *pw_dst_node_index, -	u16 *pw_control_type, u32 *ph_control); - -u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer, -	enum HPI_MIXER_STORE_COMMAND command, u16 index); -/*************************/ -/* mixer CONTROLS                */ -/*************************/ -/*************************/ -/* volume control                */ -/*************************/ -u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_gain0_01dB[HPI_MAX_CHANNELS] +u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer); + +u16 hpi_mixer_close(u32 h_mixer); + +u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type, +	u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index, +	u16 control_type, u32 *ph_control); + +u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index, +	u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type, +	u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control); + +u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command, +	u16 index); +/************/ +/* Controls */ +/************/ +/******************/ +/* Volume control */ +/******************/ +u16 hpi_volume_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]  	); -u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, +u16 hpi_volume_get_gain(u32 h_control,  	short an_gain0_01dB_out[HPI_MAX_CHANNELS]  	); +u16 hpi_volume_set_mute(u32 h_control, u32 mute); + +u16 hpi_volume_get_mute(u32 h_control, u32 *mute); +  #define hpi_volume_get_range hpi_volume_query_range -u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB); +u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB, +	short *max_gain_01dB, short *step_gain_01dB); -u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys, -	const u32 h_volume, u32 *p_channels); +u16 hpi_volume_query_channels(const u32 h_control, u32 *p_channels); -u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control, +u16 hpi_volume_auto_fade(u32 h_control,  	short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms); -u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS], -	u32 duration_ms, u16 profile); +u16 hpi_volume_auto_fade_profile(u32 h_control, +	short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms, +	u16 profile); -/*************************/ -/* level control         */ -/*************************/ -u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB); +u16 hpi_volume_query_auto_fade_profile(const u32 h_control, const u32 i, +	u16 *profile); + +/*****************/ +/* Level control */ +/*****************/ +u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB, +	short *max_gain_01dB, short *step_gain_01dB); -u16 hpi_level_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_gain0_01dB[HPI_MAX_CHANNELS] +u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]  	); -u16 hpi_level_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, +u16 hpi_level_get_gain(u32 h_control,  	short an_gain0_01dB_out[HPI_MAX_CHANNELS]  	); -/*************************/ -/* meter control                 */ -/*************************/ -u16 hpi_meter_query_channels(const struct hpi_hsubsys *ph_subsys, -	const u32 h_meter, u32 *p_channels); +/*****************/ +/* Meter control */ +/*****************/ +u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels); -u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control, +u16 hpi_meter_get_peak(u32 h_control,  	short an_peak0_01dB_out[HPI_MAX_CHANNELS]  	); -u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_peak0_01dB_out[HPI_MAX_CHANNELS] +u16 hpi_meter_get_rms(u32 h_control, short an_peak0_01dB_out[HPI_MAX_CHANNELS]  	); -u16 hpi_meter_set_peak_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 attack, u16 decay); +u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay); -u16 hpi_meter_set_rms_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 attack, u16 decay); +u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay); -u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *attack, u16 *decay); +u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *attack, u16 *decay); -u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *attack, u16 *decay); +u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *attack, u16 *decay); -/*************************/ -/* channel mode control  */ -/*************************/ -u16 hpi_channel_mode_query_mode(const struct hpi_hsubsys *ph_subsys, -	const u32 h_mode, const u32 index, u16 *pw_mode); +/************************/ +/* ChannelMode control */ +/************************/ +u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index, +	u16 *pw_mode); -u16 hpi_channel_mode_set(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 mode); +u16 hpi_channel_mode_set(u32 h_control, u16 mode); -u16 hpi_channel_mode_get(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 *mode); +u16 hpi_channel_mode_get(u32 h_control, u16 *mode); -/*************************/ -/* Tuner control                 */ -/*************************/ -u16 hpi_tuner_query_band(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, u16 *pw_band); +/*****************/ +/* Tuner control */ +/*****************/ +u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band); -u16 hpi_tuner_set_band(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 band); +u16 hpi_tuner_set_band(u32 h_control, u16 band); -u16 hpi_tuner_get_band(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 *pw_band); +u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band); -u16 hpi_tuner_query_frequency(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, const u16 band, u32 *pfreq); +u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index, +	const u16 band, u32 *pfreq); -u16 hpi_tuner_set_frequency(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 freq_ink_hz); +u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz); -u16 hpi_tuner_get_frequency(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pw_freq_ink_hz); +u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz); -u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *pw_level); +u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level); -u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short *pw_level); +u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level); -u16 hpi_tuner_query_gain(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, u16 *pw_gain); +u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain); -u16 hpi_tuner_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short gain); +u16 hpi_tuner_set_gain(u32 h_control, short gain); -u16 hpi_tuner_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *pn_gain); +u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain); -u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 *pw_status_mask, u16 *pw_status); +u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status); -u16 hpi_tuner_set_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 mode, u32 value); +u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value); -u16 hpi_tuner_get_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 mode, u32 *pn_value); +u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value); -u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *p_rds_data); +u16 hpi_tuner_get_rds(u32 h_control, char *p_rds_data); -u16 hpi_tuner_query_deemphasis(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, const u16 band, u32 *pdeemphasis); +u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index, +	const u16 band, u32 *pdeemphasis); -u16 hpi_tuner_set_deemphasis(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 deemphasis); -u16 hpi_tuner_get_deemphasis(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pdeemphasis); +u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis); +u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis); -u16 hpi_tuner_query_program(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, u32 *pbitmap_program); +u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program); -u16 hpi_tuner_set_program(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 program); +u16 hpi_tuner_set_program(u32 h_control, u32 program); -u16 hpi_tuner_get_program(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 *pprogram); +u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram); -u16 hpi_tuner_get_hd_radio_dsp_version(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, char *psz_dsp_version, const u32 string_size); +u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version, +	const u32 string_size); -u16 hpi_tuner_get_hd_radio_sdk_version(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, char *psz_sdk_version, const u32 string_size); +u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version, +	const u32 string_size); -u16 hpi_tuner_get_hd_radio_signal_quality(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pquality); +u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality); -u16 hpi_tuner_get_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pblend); +u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend); -u16 hpi_tuner_set_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, const u32 blend); +u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend); -/****************************/ -/* PADs control             */ -/****************************/ +/***************/ +/* PAD control */ +/***************/ -u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, char *psz_string, const u32 string_length); +u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string, +	const u32 string_length); -u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *psz_string, const u32 string_length); +u16 hpi_pad_get_artist(u32 h_control, char *psz_string, +	const u32 string_length); -u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *psz_string, const u32 string_length); +u16 hpi_pad_get_title(u32 h_control, char *psz_string, +	const u32 string_length); -u16 HPI_PAD__get_comment(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *psz_string, const u32 string_length); +u16 hpi_pad_get_comment(u32 h_control, char *psz_string, +	const u32 string_length); -u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *ppTY); +u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY); -u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 *ppI); +u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI); -u16 HPI_PAD__get_program_type_string(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, const u32 data_type, const u32 pTY, char *psz_string, -	const u32 string_length); +u16 hpi_pad_get_program_type_string(u32 h_control, const u32 data_type, +	const u32 pTY, char *psz_string, const u32 string_length);  /****************************/  /* AES/EBU Receiver control */  /****************************/ -u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys, -	const u32 h_aes_rx, const u32 index, u16 *pw_format); +u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index, +	u16 *pw_format); -u16 HPI_AESEBU__receiver_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 source); +u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 source); -u16 HPI_AESEBU__receiver_get_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_source); +u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_source); -u16 HPI_AESEBU__receiver_get_sample_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *psample_rate); +u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate); -u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 *pw_data); +u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data); -u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u16 index, u16 *pw_data); +u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index, +	u16 *pw_data); -u16 HPI_AESEBU__receiver_get_error_status(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_error_data); +u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data);  /*******************************/  /* AES/EBU Transmitter control */  /*******************************/ -u16 HPI_AESEBU__transmitter_set_sample_rate(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u32 sample_rate); +u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate); -u16 HPI_AESEBU__transmitter_set_user_data(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 data); +u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data); -u16 HPI_AESEBU__transmitter_set_channel_status(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u16 index, u16 data); +u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index, +	u16 data); -u16 HPI_AESEBU__transmitter_get_channel_status(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u16 index, u16 *pw_data); +u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index, +	u16 *pw_data); -u16 HPI_AESEBU__transmitter_query_format(const struct hpi_hsubsys *ph_subsys, -	const u32 h_aes_tx, const u32 index, u16 *pw_format); +u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index, +	u16 *pw_format); -u16 HPI_AESEBU__transmitter_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 output_format); +u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format); -u16 HPI_AESEBU__transmitter_get_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_output_format); +u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format);  /***********************/ -/* multiplexer control */ +/* Multiplexer control */  /***********************/ -u16 hpi_multiplexer_set_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 source_node_type, u16 source_node_index); - -u16 hpi_multiplexer_get_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *source_node_type, u16 *source_node_index); +u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type, +	u16 source_node_index); -u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 *source_node_type, +u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type,  	u16 *source_node_index); +u16 hpi_multiplexer_query_source(u32 h_control, u16 index, +	u16 *source_node_type, u16 *source_node_index); +  /***************/ -/* VOX control */ +/* Vox control */  /***************/ -u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_gain0_01dB); +u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB); -u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *an_gain0_01dB); +u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB);  /*********************/  /* Bitstream control */  /*********************/ -u16 hpi_bitstream_set_clock_edge(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 edge_type); +u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type); -u16 hpi_bitstream_set_data_polarity(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 polarity); +u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity); -u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_clk_activity, u16 *pw_data_activity); +u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity, +	u16 *pw_data_activity);  /***********************/  /* SampleClock control */  /***********************/ -u16 hpi_sample_clock_query_source(const struct hpi_hsubsys *ph_subsys, -	const u32 h_clock, const u32 index, u16 *pw_source); +u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index, +	u16 *pw_source); -u16 hpi_sample_clock_set_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 source); +u16 hpi_sample_clock_set_source(u32 h_control, u16 source); -u16 hpi_sample_clock_get_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_source); +u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source); -u16 hpi_sample_clock_query_source_index(const struct hpi_hsubsys *ph_subsys, -	const u32 h_clock, const u32 index, const u32 source, -	u16 *pw_source_index); +u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index, +	const u32 source, u16 *pw_source_index); -u16 hpi_sample_clock_set_source_index(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 source_index); +u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index); -u16 hpi_sample_clock_get_source_index(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_source_index); +u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index); -u16 hpi_sample_clock_get_sample_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *psample_rate); +u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate); -u16 hpi_sample_clock_query_local_rate(const struct hpi_hsubsys *ph_subsys, -	const u32 h_clock, const u32 index, u32 *psource); +u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index, +	u32 *psource); -u16 hpi_sample_clock_set_local_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 sample_rate); +u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate); -u16 hpi_sample_clock_get_local_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *psample_rate); +u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate); -u16 hpi_sample_clock_set_auto(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 enable); +u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable); -u16 hpi_sample_clock_get_auto(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *penable); +u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable); -u16 hpi_sample_clock_set_local_rate_lock(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 lock); +u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock); -u16 hpi_sample_clock_get_local_rate_lock(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *plock); +u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock);  /***********************/  /* Microphone control */  /***********************/ -u16 hpi_microphone_set_phantom_power(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 on_off); +u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off); -u16 hpi_microphone_get_phantom_power(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_on_off); +u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off); -/******************************* -  Parametric Equalizer control -*******************************/ -u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_number_of_bands, u16 *pw_enabled); +/********************************/ +/* Parametric Equalizer control */ +/********************************/ +u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands, +	u16 *pw_enabled); -u16 hpi_parametricEQ__set_state(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 on_off); +u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off); -u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 type, u32 frequency_hz, short q100, -	short gain0_01dB); +u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type, +	u32 frequency_hz, short q100, short gain0_01dB); -u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 *pn_type, u32 *pfrequency_hz, -	short *pnQ100, short *pn_gain0_01dB); +u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type, +	u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB); -u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, short coeffs[5] +u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]  	); -/******************************* -  Compressor Expander control -*******************************/ - -u16 hpi_compander_set_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 on); - -u16 hpi_compander_get_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pon); - -u16 hpi_compander_set_makeup_gain(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short makeup_gain0_01dB); - -u16 hpi_compander_get_makeup_gain(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short *pn_makeup_gain0_01dB); - -u16 hpi_compander_set_attack_time_constant(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u32 index, u32 attack); - -u16 hpi_compander_get_attack_time_constant(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u32 index, u32 *pw_attack); - -u16 hpi_compander_set_decay_time_constant(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, u32 decay); - -u16 hpi_compander_get_decay_time_constant(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, u32 *pw_decay); - -u16 hpi_compander_set_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, short threshold0_01dB); - -u16 hpi_compander_get_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, short *pn_threshold0_01dB); - -u16 hpi_compander_set_ratio(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, u32 ratio100); - -u16 hpi_compander_get_ratio(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, u32 *pw_ratio100); - -/******************************* -  Cobranet HMI control -*******************************/ -u16 hpi_cobranet_hmi_write(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 hmi_address, u32 byte_count, u8 *pb_data); - -u16 hpi_cobranet_hmi_read(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 hmi_address, u32 max_byte_count, u32 *pbyte_count, u8 *pb_data); - -u16 hpi_cobranet_hmi_get_status(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pstatus, u32 *preadable_size, -	u32 *pwriteable_size); - -/*Read the current IP address -*/ -u16 hpi_cobranet_getI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pi_paddress); - -/* Write the current IP address -*/ -u16 hpi_cobranet_setI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 i_paddress); - -/* Read the static IP address -*/ -u16 hpi_cobranet_get_staticI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pi_paddress); +/*******************************/ +/* Compressor Expander control */ +/*******************************/ -/* Write the static IP address -*/ -u16 hpi_cobranet_set_staticI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 i_paddress); +u16 hpi_compander_set_enable(u32 h_control, u32 on); -/* Read the MAC address -*/ -u16 hpi_cobranet_getMA_caddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pmAC_MS_bs, u32 *pmAC_LS_bs); +u16 hpi_compander_get_enable(u32 h_control, u32 *pon); -/******************************* -  Tone Detector control -*******************************/ -u16 hpi_tone_detector_get_state(const struct hpi_hsubsys *ph_subsys, u32 hC, -	u32 *state); +u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB); -u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys, u32 hC, -	u32 enable); +u16 hpi_compander_get_makeup_gain(u32 h_control, short *pn_makeup_gain0_01dB); -u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys, u32 hC, -	u32 *enable); +u16 hpi_compander_set_attack_time_constant(u32 h_control, u32 index, +	u32 attack); -u16 hpi_tone_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 event_enable); +u16 hpi_compander_get_attack_time_constant(u32 h_control, u32 index, +	u32 *pw_attack); -u16 hpi_tone_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 *event_enable); +u16 hpi_compander_set_decay_time_constant(u32 h_control, u32 index, +	u32 decay); -u16 hpi_tone_detector_set_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 hC, int threshold); +u16 hpi_compander_get_decay_time_constant(u32 h_control, u32 index, +	u32 *pw_decay); -u16 hpi_tone_detector_get_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 hC, int *threshold); +u16 hpi_compander_set_threshold(u32 h_control, u32 index, +	short threshold0_01dB); -u16 hpi_tone_detector_get_frequency(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 index, u32 *frequency); +u16 hpi_compander_get_threshold(u32 h_control, u32 index, +	short *pn_threshold0_01dB); -/******************************* -  Silence Detector control -*******************************/ -u16 hpi_silence_detector_get_state(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 *state); +u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100); -u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 enable); +u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *pw_ratio100); -u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 *enable); +/********************/ +/* Cobranet control */ +/********************/ +u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count, +	u8 *pb_data); -u16 hpi_silence_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 event_enable); +u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count, +	u32 *pbyte_count, u8 *pb_data); -u16 hpi_silence_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 *event_enable); +u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus, +	u32 *preadable_size, u32 *pwriteable_size); -u16 hpi_silence_detector_set_delay(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 delay); +u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address); -u16 hpi_silence_detector_get_delay(const struct hpi_hsubsys *ph_subsys, -	u32 hC, u32 *delay); +u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address); -u16 hpi_silence_detector_set_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 hC, int threshold); +u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address); -u16 hpi_silence_detector_get_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 hC, int *threshold); +u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address); -/******************************* -  Universal control -*******************************/ -u16 hpi_entity_find_next(struct hpi_entity *container_entity, -	enum e_entity_type type, enum e_entity_role role, int recursive_flag, -	struct hpi_entity **current_match); +u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *p_mac_msbs, +	u32 *p_mac_lsbs); -u16 hpi_entity_copy_value_from(struct hpi_entity *entity, -	enum e_entity_type type, size_t item_count, void *value_dst_p); +/*************************/ +/* Tone Detector control */ +/*************************/ +u16 hpi_tone_detector_get_state(u32 hC, u32 *state); -u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type, -	size_t *items, enum e_entity_role *role, void **value); +u16 hpi_tone_detector_set_enable(u32 hC, u32 enable); -u16 hpi_entity_alloc_and_pack(const enum e_entity_type type, -	const size_t item_count, const enum e_entity_role role, void *value, -	struct hpi_entity **entity); +u16 hpi_tone_detector_get_enable(u32 hC, u32 *enable); -void hpi_entity_free(struct hpi_entity *entity); +u16 hpi_tone_detector_set_event_enable(u32 hC, u32 event_enable); -u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC, -	struct hpi_entity **info); +u16 hpi_tone_detector_get_event_enable(u32 hC, u32 *event_enable); -u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC, -	struct hpi_entity **value); +u16 hpi_tone_detector_set_threshold(u32 hC, int threshold); -u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC, -	struct hpi_entity *value); +u16 hpi_tone_detector_get_threshold(u32 hC, int *threshold); -/*/////////// */ -/* DSP CLOCK  */ -/*/////////// */ -u16 hpi_clock_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_dsp_clock); +u16 hpi_tone_detector_get_frequency(u32 hC, u32 index, u32 *frequency); -u16 hpi_clock_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_clock, -	u16 hour, u16 minute, u16 second, u16 milli_second); +/****************************/ +/* Silence Detector control */ +/****************************/ +u16 hpi_silence_detector_get_state(u32 hC, u32 *state); -u16 hpi_clock_get_time(const struct hpi_hsubsys *ph_subsys, u32 h_clock, -	u16 *pw_hour, u16 *pw_minute, u16 *pw_second, u16 *pw_milli_second); +u16 hpi_silence_detector_set_enable(u32 hC, u32 enable); -/*/////////// */ -/* PROFILE        */ -/*/////////// */ -u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 profile_index, u32 *ph_profile, -	u16 *pw_max_profiles); +u16 hpi_silence_detector_get_enable(u32 hC, u32 *enable); -u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile, -	u16 index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count, -	u32 *pmax_micro_seconds, u32 *pmin_micro_seconds); +u16 hpi_silence_detector_set_event_enable(u32 hC, u32 event_enable); -u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile); +u16 hpi_silence_detector_get_event_enable(u32 hC, u32 *event_enable); -u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile); +u16 hpi_silence_detector_set_delay(u32 hC, u32 delay); -u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile, -	u16 index, char *sz_profile_name, u16 profile_name_length); +u16 hpi_silence_detector_get_delay(u32 hC, u32 *delay); -u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys, -	u32 h_profile, u32 *putilization); +u16 hpi_silence_detector_set_threshold(u32 hC, int threshold); -/*//////////////////// */ -/* UTILITY functions */ +u16 hpi_silence_detector_get_threshold(u32 hC, int *threshold); +/*********************/ +/* Utility functions */ +/*********************/  u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,  	u32 sample_rate, u32 bit_rate, u32 attributes); -/* Until it's verified, this function is for Windows OSs only */ - -#endif	 /*_H_HPI_ */ -/* -/////////////////////////////////////////////////////////////////////////////// -// See CVS for history.  Last complete set in rev 1.146 -//////////////////////////////////////////////////////////////////////////////// -*/ +#endif	 /*_HPI_H_ */ diff --git a/sound/pci/asihpi/hpi6000.c b/sound/pci/asihpi/hpi6000.c index 1b9bf9395cf..2414d7a2239 100644 --- a/sound/pci/asihpi/hpi6000.c +++ b/sound/pci/asihpi/hpi6000.c @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -43,16 +43,17 @@  #define HPI_HIF_ERROR_MASK      0x4000  /* HPI6000 specific error codes */ +#define HPI6000_ERROR_BASE 900	/* not actually used anywhere */ -#define HPI6000_ERROR_BASE                              900 +/* operational/messaging errors */  #define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT             901 -#define HPI6000_ERROR_MSG_RESP_SEND_MSG_ACK             902 +  #define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK             903  #define HPI6000_ERROR_MSG_GET_ADR                       904  #define HPI6000_ERROR_RESP_GET_ADR                      905  #define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32             906  #define HPI6000_ERROR_MSG_RESP_BLOCKREAD32              907 -#define HPI6000_ERROR_MSG_INVALID_DSP_INDEX             908 +  #define HPI6000_ERROR_CONTROL_CACHE_PARAMS              909  #define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT            911 @@ -62,7 +63,6 @@  #define HPI6000_ERROR_SEND_DATA_CMD                     915  #define HPI6000_ERROR_SEND_DATA_WRITE                   916  #define HPI6000_ERROR_SEND_DATA_IDLECMD                 917 -#define HPI6000_ERROR_SEND_DATA_VERIFY                  918  #define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT             921  #define HPI6000_ERROR_GET_DATA_ACK                      922 @@ -76,9 +76,8 @@  #define HPI6000_ERROR_MSG_RESP_GETRESPCMD               961  #define HPI6000_ERROR_MSG_RESP_IDLECMD                  962 -#define HPI6000_ERROR_MSG_RESP_BLOCKVERIFY32            963 -/* adapter init errors */ +/* Initialisation/bootload errors */  #define HPI6000_ERROR_UNHANDLED_SUBSYS_ID               930  /* can't access PCI2040 */ @@ -201,8 +200,8 @@ static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,  static void subsys_create_adapter(struct hpi_message *phm,  	struct hpi_response *phr); -static void subsys_delete_adapter(struct hpi_message *phm, -	struct hpi_response *phr); +static void adapter_delete(struct hpi_adapter_obj *pao, +	struct hpi_message *phm, struct hpi_response *phr);  static void adapter_get_asserts(struct hpi_adapter_obj *pao,  	struct hpi_message *phm, struct hpi_response *phr); @@ -210,6 +209,8 @@ static void adapter_get_asserts(struct hpi_adapter_obj *pao,  static short create_adapter_obj(struct hpi_adapter_obj *pao,  	u32 *pos_error_code); +static void delete_adapter_obj(struct hpi_adapter_obj *pao); +  /* local globals */  static u16 gw_pci_read_asserts;	/* used to count PCI2040 errors */ @@ -217,23 +218,10 @@ static u16 gw_pci_write_asserts;	/* used to count PCI2040 errors */  static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)  { -  	switch (phm->function) { -	case HPI_SUBSYS_OPEN: -	case HPI_SUBSYS_CLOSE: -	case HPI_SUBSYS_GET_INFO: -	case HPI_SUBSYS_DRIVER_UNLOAD: -	case HPI_SUBSYS_DRIVER_LOAD: -	case HPI_SUBSYS_FIND_ADAPTERS: -		/* messages that should not get here */ -		phr->error = HPI_ERROR_UNIMPLEMENTED; -		break;  	case HPI_SUBSYS_CREATE_ADAPTER:  		subsys_create_adapter(phm, phr);  		break; -	case HPI_SUBSYS_DELETE_ADAPTER: -		subsys_delete_adapter(phm, phr); -		break;  	default:  		phr->error = HPI_ERROR_INVALID_FUNC;  		break; @@ -243,6 +231,7 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)  static void control_message(struct hpi_adapter_obj *pao,  	struct hpi_message *phm, struct hpi_response *phr)  { +	struct hpi_hw_obj *phw = pao->priv;  	switch (phm->function) {  	case HPI_CONTROL_GET_STATE: @@ -251,27 +240,29 @@ static void control_message(struct hpi_adapter_obj *pao,  			err = hpi6000_update_control_cache(pao, phm);  			if (err) { -				phr->error = err; +				if (err >= HPI_ERROR_BACKEND_BASE) { +					phr->error = +						HPI_ERROR_CONTROL_CACHING; +					phr->specific_error = err; +				} else { +					phr->error = err; +				}  				break;  			} -			if (hpi_check_control_cache(((struct hpi_hw_obj *) -						pao->priv)->p_cache, phm, -					phr)) +			if (hpi_check_control_cache(phw->p_cache, phm, phr))  				break;  		}  		hw_message(pao, phm, phr);  		break; -	case HPI_CONTROL_GET_INFO: -		hw_message(pao, phm, phr); -		break;  	case HPI_CONTROL_SET_STATE:  		hw_message(pao, phm, phr); -		hpi_sync_control_cache(((struct hpi_hw_obj *)pao->priv)-> -			p_cache, phm, phr); +		hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm, phr);  		break; + +	case HPI_CONTROL_GET_INFO:  	default: -		phr->error = HPI_ERROR_INVALID_FUNC; +		hw_message(pao, phm, phr);  		break;  	}  } @@ -280,26 +271,16 @@ static void adapter_message(struct hpi_adapter_obj *pao,  	struct hpi_message *phm, struct hpi_response *phr)  {  	switch (phm->function) { -	case HPI_ADAPTER_GET_INFO: -		hw_message(pao, phm, phr); -		break;  	case HPI_ADAPTER_GET_ASSERT:  		adapter_get_asserts(pao, phm, phr);  		break; -	case HPI_ADAPTER_OPEN: -	case HPI_ADAPTER_CLOSE: -	case HPI_ADAPTER_TEST_ASSERT: -	case HPI_ADAPTER_SELFTEST: -	case HPI_ADAPTER_GET_MODE: -	case HPI_ADAPTER_SET_MODE: -	case HPI_ADAPTER_FIND_OBJECT: -	case HPI_ADAPTER_GET_PROPERTY: -	case HPI_ADAPTER_SET_PROPERTY: -	case HPI_ADAPTER_ENUM_PROPERTY: -		hw_message(pao, phm, phr); + +	case HPI_ADAPTER_DELETE: +		adapter_delete(pao, phm, phr);  		break; +  	default: -		phr->error = HPI_ERROR_INVALID_FUNC; +		hw_message(pao, phm, phr);  		break;  	}  } @@ -311,7 +292,7 @@ static void outstream_message(struct hpi_adapter_obj *pao,  	case HPI_OSTREAM_HOSTBUFFER_ALLOC:  	case HPI_OSTREAM_HOSTBUFFER_FREE:  		/* Don't let these messages go to the HW function because -		 * they're called without allocating the spinlock. +		 * they're called without locking the spinlock.  		 * For the HPI6000 adapters the HW would return  		 * HPI_ERROR_INVALID_FUNC anyway.  		 */ @@ -331,7 +312,7 @@ static void instream_message(struct hpi_adapter_obj *pao,  	case HPI_ISTREAM_HOSTBUFFER_ALLOC:  	case HPI_ISTREAM_HOSTBUFFER_FREE:  		/* Don't let these messages go to the HW function because -		 * they're called without allocating the spinlock. +		 * they're called without locking the spinlock.  		 * For the HPI6000 adapters the HW would return  		 * HPI_ERROR_INVALID_FUNC anyway.  		 */ @@ -352,26 +333,22 @@ void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)  {  	struct hpi_adapter_obj *pao = NULL; -	/* subsytem messages get executed by every HPI. */ -	/* All other messages are ignored unless the adapter index matches */ -	/* an adapter in the HPI */ -	HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->object, phm->function); - -	/* if Dsp has crashed then do not communicate with it any more */  	if (phm->object != HPI_OBJ_SUBSYSTEM) {  		pao = hpi_find_adapter(phm->adapter_index);  		if (!pao) { -			HPI_DEBUG_LOG(DEBUG, -				" %d,%d refused, for another HPI?\n", -				phm->object, phm->function); +			hpi_init_response(phr, phm->object, phm->function, +				HPI_ERROR_BAD_ADAPTER_NUMBER); +			HPI_DEBUG_LOG(DEBUG, "invalid adapter index: %d \n", +				phm->adapter_index);  			return;  		} +		/* Don't even try to communicate with crashed DSP */  		if (pao->dsp_crashed >= 10) {  			hpi_init_response(phr, phm->object, phm->function,  				HPI_ERROR_DSP_HARDWARE); -			HPI_DEBUG_LOG(DEBUG, " %d,%d dsp crashed.\n", -				phm->object, phm->function); +			HPI_DEBUG_LOG(DEBUG, "adapter %d dsp crashed\n", +				phm->adapter_index);  			return;  		}  	} @@ -381,7 +358,7 @@ void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)  			HPI_ERROR_PROCESSING_MESSAGE);  	switch (phm->type) { -	case HPI_TYPE_MESSAGE: +	case HPI_TYPE_REQUEST:  		switch (phm->object) {  		case HPI_OBJ_SUBSYSTEM:  			subsys_message(phm, phr); @@ -433,39 +410,34 @@ static void subsys_create_adapter(struct hpi_message *phm,  	struct hpi_adapter_obj ao;  	struct hpi_adapter_obj *pao;  	u32 os_error_code; -	short error = 0; +	u16 err = 0;  	u32 dsp_index = 0;  	HPI_DEBUG_LOG(VERBOSE, "subsys_create_adapter\n");  	memset(&ao, 0, sizeof(ao)); -	/* this HPI only creates adapters for TI/PCI2040 based devices */ -	if (phm->u.s.resource.bus_type != HPI_BUS_PCI) -		return; -	if (phm->u.s.resource.r.pci->vendor_id != HPI_PCI_VENDOR_ID_TI) -		return; -	if (phm->u.s.resource.r.pci->device_id != HPI_PCI_DEV_ID_PCI2040) -		return; -  	ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);  	if (!ao.priv) { -		HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n"); +		HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");  		phr->error = HPI_ERROR_MEMORY_ALLOC;  		return;  	}  	/* create the adapter object based on the resource information */ -	/*? memcpy(&ao.Pci,&phm->u.s.Resource.r.Pci,sizeof(ao.Pci)); */  	ao.pci = *phm->u.s.resource.r.pci; -	error = create_adapter_obj(&ao, &os_error_code); -	if (!error) -		error = hpi_add_adapter(&ao); -	if (error) { +	err = create_adapter_obj(&ao, &os_error_code); +	if (err) { +		delete_adapter_obj(&ao); +		if (err >= HPI_ERROR_BACKEND_BASE) { +			phr->error = HPI_ERROR_DSP_BOOTLOAD; +			phr->specific_error = err; +		} else { +			phr->error = err; +		} +  		phr->u.s.data = os_error_code; -		kfree(ao.priv); -		phr->error = error;  		return;  	}  	/* need to update paParentAdapter */ @@ -473,39 +445,25 @@ static void subsys_create_adapter(struct hpi_message *phm,  	if (!pao) {  		/* We just added this adapter, why can't we find it!? */  		HPI_DEBUG_LOG(ERROR, "lost adapter after boot\n"); -		phr->error = 950; +		phr->error = HPI_ERROR_BAD_ADAPTER;  		return;  	}  	for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) { -		struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv; +		struct hpi_hw_obj *phw = pao->priv;  		phw->ado[dsp_index].pa_parent_adapter = pao;  	} -	phr->u.s.aw_adapter_list[ao.index] = ao.adapter_type; +	phr->u.s.adapter_type = ao.type;  	phr->u.s.adapter_index = ao.index; -	phr->u.s.num_adapters++;  	phr->error = 0;  } -static void subsys_delete_adapter(struct hpi_message *phm, -	struct hpi_response *phr) +static void adapter_delete(struct hpi_adapter_obj *pao, +	struct hpi_message *phm, struct hpi_response *phr)  { -	struct hpi_adapter_obj *pao = NULL; -	struct hpi_hw_obj *phw; - -	pao = hpi_find_adapter(phm->adapter_index); -	if (!pao) -		return; - -	phw = (struct hpi_hw_obj *)pao->priv; - -	if (pao->has_control_cache) -		hpi_free_control_cache(phw->p_cache); - +	delete_adapter_obj(pao);  	hpi_delete_adapter(pao); -	kfree(phw); -  	phr->error = 0;  } @@ -517,10 +475,7 @@ static short create_adapter_obj(struct hpi_adapter_obj *pao,  	u32 dsp_index = 0;  	u32 control_cache_size = 0;  	u32 control_cache_count = 0; -	struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv; - -	/* init error reporting */ -	pao->dsp_crashed = 0; +	struct hpi_hw_obj *phw = pao->priv;  	/* The PCI2040 has the following address map */  	/* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */ @@ -575,36 +530,36 @@ static short create_adapter_obj(struct hpi_adapter_obj *pao,  	/* get info about the adapter by asking the adapter */  	/* send a HPI_ADAPTER_GET_INFO message */  	{ -		struct hpi_message hM; -		struct hpi_response hR0;	/* response from DSP 0 */ -		struct hpi_response hR1;	/* response from DSP 1 */ +		struct hpi_message hm; +		struct hpi_response hr0;	/* response from DSP 0 */ +		struct hpi_response hr1;	/* response from DSP 1 */  		u16 error = 0;  		HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n"); -		memset(&hM, 0, sizeof(hM)); -		hM.type = HPI_TYPE_MESSAGE; -		hM.size = sizeof(struct hpi_message); -		hM.object = HPI_OBJ_ADAPTER; -		hM.function = HPI_ADAPTER_GET_INFO; -		hM.adapter_index = 0; -		memset(&hR0, 0, sizeof(hR0)); -		memset(&hR1, 0, sizeof(hR1)); -		hR0.size = sizeof(hR0); -		hR1.size = sizeof(hR1); - -		error = hpi6000_message_response_sequence(pao, 0, &hM, &hR0); -		if (hR0.error) { -			HPI_DEBUG_LOG(DEBUG, "message error %d\n", hR0.error); -			return hR0.error; +		memset(&hm, 0, sizeof(hm)); +		hm.type = HPI_TYPE_REQUEST; +		hm.size = sizeof(struct hpi_message); +		hm.object = HPI_OBJ_ADAPTER; +		hm.function = HPI_ADAPTER_GET_INFO; +		hm.adapter_index = 0; +		memset(&hr0, 0, sizeof(hr0)); +		memset(&hr1, 0, sizeof(hr1)); +		hr0.size = sizeof(hr0); +		hr1.size = sizeof(hr1); + +		error = hpi6000_message_response_sequence(pao, 0, &hm, &hr0); +		if (hr0.error) { +			HPI_DEBUG_LOG(DEBUG, "message error %d\n", hr0.error); +			return hr0.error;  		}  		if (phw->num_dsp == 2) { -			error = hpi6000_message_response_sequence(pao, 1, &hM, -				&hR1); +			error = hpi6000_message_response_sequence(pao, 1, &hm, +				&hr1);  			if (error)  				return error;  		} -		pao->adapter_type = hR0.u.a.adapter_type; -		pao->index = hR0.u.a.adapter_index; +		pao->type = hr0.u.ax.info.adapter_type; +		pao->index = hr0.u.ax.info.adapter_index;  	}  	memset(&phw->control_cache[0], 0, @@ -618,22 +573,36 @@ static short create_adapter_obj(struct hpi_adapter_obj *pao,  		control_cache_count =  			hpi_read_word(&phw->ado[0],  			HPI_HIF_ADDR(control_cache_count)); -		pao->has_control_cache = 1;  		phw->p_cache =  			hpi_alloc_control_cache(control_cache_count, -			control_cache_size, (struct hpi_control_cache_info *) +			control_cache_size, (unsigned char *)  			&phw->control_cache[0]  			); -		if (!phw->p_cache) -			pao->has_control_cache = 0; -	} else -		pao->has_control_cache = 0; +		if (phw->p_cache) +			pao->has_control_cache = 1; +	} -	HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n", -		pao->adapter_type, pao->index); -	pao->open = 0;	/* upon creation the adapter is closed */ -	return 0; +	HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n", pao->type, +		pao->index); + +	if (phw->p_cache) +		phw->p_cache->adap_idx = pao->index; + +	return hpi_add_adapter(pao); +} + +static void delete_adapter_obj(struct hpi_adapter_obj *pao) +{ +	struct hpi_hw_obj *phw = pao->priv; + +	if (pao->has_control_cache) +		hpi_free_control_cache(phw->p_cache); + +	/* reset DSPs on adapter */ +	iowrite32(0x0003000F, phw->dw2040_HPICSR + HPI_RESET); + +	kfree(phw);  }  /************************************************************************/ @@ -645,11 +614,13 @@ static void adapter_get_asserts(struct hpi_adapter_obj *pao,  #ifndef HIDE_PCI_ASSERTS  	/* if we have PCI2040 asserts then collect them */  	if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) { -		phr->u.a.serial_number = +		phr->u.ax.assert.p1 =  			gw_pci_read_asserts * 100 + gw_pci_write_asserts; -		phr->u.a.adapter_index = 1;	/* assert count */ -		phr->u.a.adapter_type = -1;	/* "dsp index" */ -		strcpy(phr->u.a.sz_adapter_assert, "PCI2040 error"); +		phr->u.ax.assert.p2 = 0; +		phr->u.ax.assert.count = 1;	/* assert count */ +		phr->u.ax.assert.dsp_index = -1;	/* "dsp index" */ +		strcpy(phr->u.ax.assert.sz_message, "PCI2040 error"); +		phr->u.ax.assert.dsp_msg_addr = 0;  		gw_pci_read_asserts = 0;  		gw_pci_write_asserts = 0;  		phr->error = 0; @@ -666,7 +637,7 @@ static void adapter_get_asserts(struct hpi_adapter_obj *pao,  static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  	u32 *pos_error_code)  { -	struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv; +	struct hpi_hw_obj *phw = pao->priv;  	short error;  	u32 timeout;  	u32 read = 0; @@ -686,10 +657,10 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  	/* NOTE don't use wAdapterType in this routine. It is not setup yet */ -	switch (pao->pci.subsys_device_id) { +	switch (pao->pci.pci_dev->subsystem_device) {  	case 0x5100:  	case 0x5110:	/* ASI5100 revB or higher with C6711D */ -	case 0x5200:	/* ASI5200 PC_ie version of ASI5100 */ +	case 0x5200:	/* ASI5200 PCIe version of ASI5100 */  	case 0x6100:  	case 0x6200:  		boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200); @@ -709,8 +680,9 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  	 * note that bits 4..15 are read-only and so should always return zero,  	 * even though we wrote 1 to them  	 */ -	for (i = 0; i < 1000; i++) -		delay = ioread32(phw->dw2040_HPICSR + HPI_RESET); +	hpios_delay_micro_seconds(1000); +	delay = ioread32(phw->dw2040_HPICSR + HPI_RESET); +  	if (delay != dw2040_reset) {  		HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,  			delay); @@ -743,8 +715,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  	dw2040_reset = dw2040_reset & (~0x00000008);  	iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);  	/*delay to allow DSP to get going */ -	for (i = 0; i < 100; i++) -		delay = ioread32(phw->dw2040_HPICSR + HPI_RESET); +	hpios_delay_micro_seconds(100);  	/* loop through all DSPs, downloading DSP code */  	for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) { @@ -783,27 +754,27 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  			 */  			/* bypass PLL */  			hpi_write_word(pdo, 0x01B7C100, 0x0000); -			for (i = 0; i < 100; i++) -				delay = ioread32(phw->dw2040_HPICSR + -					HPI_RESET); +			hpios_delay_micro_seconds(100);  			/*  ** use default of PLL  x7 ** */  			/* EMIF = 225/3=75MHz */  			hpi_write_word(pdo, 0x01B7C120, 0x8002); +			hpios_delay_micro_seconds(100); +  			/* peri = 225/2 */  			hpi_write_word(pdo, 0x01B7C11C, 0x8001); +			hpios_delay_micro_seconds(100); +  			/* cpu  = 225/1 */  			hpi_write_word(pdo, 0x01B7C118, 0x8000); -			/* ~200us delay */ -			for (i = 0; i < 2000; i++) -				delay = ioread32(phw->dw2040_HPICSR + -					HPI_RESET); + +			/* ~2ms delay */ +			hpios_delay_micro_seconds(2000); +  			/* PLL not bypassed */  			hpi_write_word(pdo, 0x01B7C100, 0x0001); -			/* ~200us delay */ -			for (i = 0; i < 2000; i++) -				delay = ioread32(phw->dw2040_HPICSR + -					HPI_RESET); +			/* ~2ms delay */ +			hpios_delay_micro_seconds(2000);  		}  		/* test r/w to internal DSP memory @@ -927,9 +898,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  		}  		/* delay a little to allow SDRAM and DSP to "get going" */ - -		for (i = 0; i < 1000; i++) -			delay = ioread32(phw->dw2040_HPICSR + HPI_RESET); +		hpios_delay_micro_seconds(1000);  		/* test access to SDRAM */  		{ @@ -975,11 +944,8 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  		}  		/* write the DSP code down into the DSPs memory */ -		/*HpiDspCode_Open(nBootLoadFamily,&DspCode,pdwOsErrorCode); */ -		dsp_code.ps_dev = pao->pci.p_os_data; - -		error = hpi_dsp_code_open(boot_load_family, &dsp_code, -			pos_error_code); +		error = hpi_dsp_code_open(boot_load_family, pao->pci.pci_dev, +			&dsp_code, pos_error_code);  		if (error)  			return error; @@ -1073,8 +1039,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  		/* step 3. Start code by sending interrupt */  		iowrite32(0x00030003, pdo->prHPI_control); -		for (i = 0; i < 10000; i++) -			delay = ioread32(phw->dw2040_HPICSR + HPI_RESET); +		hpios_delay_micro_seconds(10000);  		/* wait for a non-zero value in hostcmd -  		 * indicating initialization is complete @@ -1101,7 +1066,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  			 * locks up with a bluescreen (NOT GPF or pagefault).  			 */  			else -				hpios_delay_micro_seconds(1000); +				hpios_delay_micro_seconds(10000);  		}  		if (timeout == 0)  			return HPI6000_ERROR_INIT_NOACK; @@ -1132,14 +1097,14 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  				mask = 0xFFFFFF00L;  				/* ASI5100 uses AX6 code, */  				/* but has no PLD r/w register to test */ -				if (HPI_ADAPTER_FAMILY_ASI(pao->pci. -						subsys_device_id) == +				if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev-> +						subsystem_device) ==  					HPI_ADAPTER_FAMILY_ASI(0x5100))  					mask = 0x00000000L;  				/* ASI5200 uses AX6 code, */  				/* but has no PLD r/w register to test */ -				if (HPI_ADAPTER_FAMILY_ASI(pao->pci. -						subsys_device_id) == +				if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev-> +						subsystem_device) ==  					HPI_ADAPTER_FAMILY_ASI(0x5200))  					mask = 0x00000000L;  				break; @@ -1204,7 +1169,7 @@ static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)  	u32 data = 0;  	if (hpi_set_address(pdo, address)) -		return 0;	/*? no way to return error */ +		return 0;	/*? No way to return error */  	/* take care of errata in revB DSP (2.0.1) */  	data = ioread32(pdo->prHPI_data); @@ -1253,8 +1218,8 @@ static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,  static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,  	u16 dsp_index, u32 hpi_address, u32 *source, u32 count)  { -	struct dsp_obj *pdo = -		&(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index]; +	struct hpi_hw_obj *phw = pao->priv; +	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 time_out = PCI_TIMEOUT;  	int c6711_burst_size = 128;  	u32 local_hpi_address = hpi_address; @@ -1291,8 +1256,8 @@ static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,  static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,  	u16 dsp_index, u32 hpi_address, u32 *dest, u32 count)  { -	struct dsp_obj *pdo = -		&(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index]; +	struct hpi_hw_obj *phw = pao->priv; +	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 time_out = PCI_TIMEOUT;  	int c6711_burst_size = 16;  	u32 local_hpi_address = hpi_address; @@ -1331,7 +1296,7 @@ static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,  static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,  	u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr)  { -	struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv; +	struct hpi_hw_obj *phw = pao->priv;  	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 timeout;  	u16 ack; @@ -1340,10 +1305,6 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,  	u32 *p_data;  	u16 error = 0; -	/* does the DSP we are referencing exist? */ -	if (dsp_index >= phw->num_dsp) -		return HPI6000_ERROR_MSG_INVALID_DSP_INDEX; -  	ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);  	if (ack & HPI_HIF_ERROR_MASK) {  		pao->dsp_crashed++; @@ -1351,9 +1312,7 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,  	}  	pao->dsp_crashed = 0; -	/* send the message */ - -	/* get the address and size */ +	/* get the message address and size */  	if (phw->message_buffer_address_on_dsp == 0) {  		timeout = TIMEOUT;  		do { @@ -1368,10 +1327,9 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,  	} else  		address = phw->message_buffer_address_on_dsp; -	/*        dwLength = sizeof(struct hpi_message); */  	length = phm->size; -	/* send it */ +	/* send the message */  	p_data = (u32 *)phm;  	if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,  			(u16)length / 4)) @@ -1385,7 +1343,7 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,  	if (ack & HPI_HIF_ERROR_MASK)  		return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK; -	/* get the address and size */ +	/* get the response address */  	if (phw->response_buffer_address_on_dsp == 0) {  		timeout = TIMEOUT;  		do { @@ -1409,7 +1367,7 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,  	if (!timeout)  		length = sizeof(struct hpi_response); -	/* get it */ +	/* get the response */  	p_data = (u32 *)phr;  	if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,  			(u16)length / 4)) @@ -1454,8 +1412,8 @@ static short hpi6000_send_data_check_adr(u32 address, u32 length_in_dwords)  static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,  	struct hpi_message *phm, struct hpi_response *phr)  { -	struct dsp_obj *pdo = -		&(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index]; +	struct hpi_hw_obj *phw = pao->priv; +	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 data_sent = 0;  	u16 ack;  	u32 length, address; @@ -1527,8 +1485,8 @@ static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,  static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,  	struct hpi_message *phm, struct hpi_response *phr)  { -	struct dsp_obj *pdo = -		&(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index]; +	struct hpi_hw_obj *phw = pao->priv; +	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 data_got = 0;  	u16 ack;  	u32 length, address; @@ -1591,8 +1549,8 @@ static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo)  static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,  	u16 dsp_index, u32 host_cmd)  { -	struct dsp_obj *pdo = -		&(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index]; +	struct hpi_hw_obj *phw = pao->priv; +	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 timeout = TIMEOUT;  	/* set command */ @@ -1617,7 +1575,7 @@ static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,  {  	u32 hPI_error; -	struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv; +	struct hpi_hw_obj *phw = pao->priv;  	/* read the error bits from the PCI2040 */  	hPI_error = ioread32(phw->dw2040_HPICSR + HPI_ERROR_REPORT); @@ -1637,8 +1595,8 @@ static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,  static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,  	u32 ack_value)  { -	struct dsp_obj *pdo = -		&(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index]; +	struct hpi_hw_obj *phw = pao->priv; +	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 ack = 0L;  	u32 timeout;  	u32 hPIC = 0L; @@ -1680,7 +1638,7 @@ static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,  	struct hpi_message *phm)  {  	const u16 dsp_index = 0; -	struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv; +	struct hpi_hw_obj *phw = pao->priv;  	struct dsp_obj *pdo = &phw->ado[dsp_index];  	u32 timeout;  	u32 cache_dirty_flag; @@ -1780,7 +1738,8 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,  {  	u16 error = 0;  	u16 dsp_index = 0; -	u16 num_dsp = ((struct hpi_hw_obj *)pao->priv)->num_dsp; +	struct hpi_hw_obj *phw = pao->priv; +	u16 num_dsp = phw->num_dsp;  	if (num_dsp < 2)  		dsp_index = 0; @@ -1805,17 +1764,11 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,  	hpios_dsplock_lock(pao);  	error = hpi6000_message_response_sequence(pao, dsp_index, phm, phr); -	/* maybe an error response */ -	if (error) { -		/* something failed in the HPI/DSP interface */ -		phr->error = error; -		/* just the header of the response is valid */ -		phr->size = sizeof(struct hpi_response_header); +	if (error)	/* something failed in the HPI/DSP interface */  		goto err; -	} -	if (phr->error != 0)	/* something failed in the DSP */ -		goto err; +	if (phr->error)	/* something failed in the DSP */ +		goto out;  	switch (phm->function) {  	case HPI_OSTREAM_WRITE: @@ -1827,21 +1780,30 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,  		error = hpi6000_get_data(pao, dsp_index, phm, phr);  		break;  	case HPI_ADAPTER_GET_ASSERT: -		phr->u.a.adapter_index = 0;	/* dsp 0 default */ +		phr->u.ax.assert.dsp_index = 0;	/* dsp 0 default */  		if (num_dsp == 2) { -			if (!phr->u.a.adapter_type) { +			if (!phr->u.ax.assert.count) {  				/* no assert from dsp 0, check dsp 1 */  				error = hpi6000_message_response_sequence(pao,  					1, phm, phr); -				phr->u.a.adapter_index = 1; +				phr->u.ax.assert.dsp_index = 1;  			}  		}  	} -	if (error) -		phr->error = error; -  err: +	if (error) { +		if (error >= HPI_ERROR_BACKEND_BASE) { +			phr->error = HPI_ERROR_DSP_COMMUNICATION; +			phr->specific_error = error; +		} else { +			phr->error = error; +		} + +		/* just the header of the response is valid */ +		phr->size = sizeof(struct hpi_response_header); +	} +out:  	hpios_dsplock_unlock(pao);  	return;  } diff --git a/sound/pci/asihpi/hpi6000.h b/sound/pci/asihpi/hpi6000.h index 4c7d507c0ec..7e0deeff5e7 100644 --- a/sound/pci/asihpi/hpi6000.h +++ b/sound/pci/asihpi/hpi6000.h @@ -1,7 +1,7 @@  /*****************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as diff --git a/sound/pci/asihpi/hpi6205.c b/sound/pci/asihpi/hpi6205.c index 2672f6591ce..4f2873880b1 100644 --- a/sound/pci/asihpi/hpi6205.c +++ b/sound/pci/asihpi/hpi6205.c @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -38,27 +38,29 @@  /*****************************************************************************/  /* HPI6205 specific error codes */ -#define HPI6205_ERROR_BASE                      1000 -/*#define HPI6205_ERROR_MEM_ALLOC 1001 */ -#define HPI6205_ERROR_6205_NO_IRQ               1002 -#define HPI6205_ERROR_6205_INIT_FAILED          1003 -/*#define HPI6205_ERROR_MISSING_DSPCODE 1004 */ -#define HPI6205_ERROR_UNKNOWN_PCI_DEVICE        1005 -#define HPI6205_ERROR_6205_REG                  1006 -#define HPI6205_ERROR_6205_DSPPAGE              1007 -#define HPI6205_ERROR_BAD_DSPINDEX              1008 -#define HPI6205_ERROR_C6713_HPIC                1009 -#define HPI6205_ERROR_C6713_HPIA                1010 -#define HPI6205_ERROR_C6713_PLL                 1011 -#define HPI6205_ERROR_DSP_INTMEM                1012 -#define HPI6205_ERROR_DSP_EXTMEM                1013 -#define HPI6205_ERROR_DSP_PLD                   1014 +#define HPI6205_ERROR_BASE 1000	/* not actually used anywhere */ + +/* operational/messaging errors */  #define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT     1015  #define HPI6205_ERROR_MSG_RESP_TIMEOUT          1016 -#define HPI6205_ERROR_6205_EEPROM               1017 -#define HPI6205_ERROR_DSP_EMIF                  1018 -#define hpi6205_error(dsp_index, err) (err) +/* initialization/bootload errors */ +#define HPI6205_ERROR_6205_NO_IRQ       1002 +#define HPI6205_ERROR_6205_INIT_FAILED  1003 +#define HPI6205_ERROR_6205_REG          1006 +#define HPI6205_ERROR_6205_DSPPAGE      1007 +#define HPI6205_ERROR_C6713_HPIC        1009 +#define HPI6205_ERROR_C6713_HPIA        1010 +#define HPI6205_ERROR_C6713_PLL         1011 +#define HPI6205_ERROR_DSP_INTMEM        1012 +#define HPI6205_ERROR_DSP_EXTMEM        1013 +#define HPI6205_ERROR_DSP_PLD           1014 +#define HPI6205_ERROR_6205_EEPROM       1017 +#define HPI6205_ERROR_DSP_EMIF1         1018 +#define HPI6205_ERROR_DSP_EMIF2         1019 +#define HPI6205_ERROR_DSP_EMIF3         1020 +#define HPI6205_ERROR_DSP_EMIF4         1021 +  /*****************************************************************************/  /* for C6205 PCI i/f */  /* Host Status Register (HSR) bitfields */ @@ -128,9 +130,6 @@ struct hpi_hw_obj {  	u32 outstream_host_buffer_size[HPI_MAX_STREAMS];  	struct consistent_dma_area h_control_cache; -	struct consistent_dma_area h_async_event_buffer; -/*      struct hpi_control_cache_single *pControlCache; */ -	struct hpi_async_event *p_async_event_buffer;  	struct hpi_control_cache *p_cache;  }; @@ -156,8 +155,8 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,  static void subsys_create_adapter(struct hpi_message *phm,  	struct hpi_response *phr); -static void subsys_delete_adapter(struct hpi_message *phm, -	struct hpi_response *phr); +static void adapter_delete(struct hpi_adapter_obj *pao, +	struct hpi_message *phm, struct hpi_response *phr);  static u16 create_adapter_obj(struct hpi_adapter_obj *pao,  	u32 *pos_error_code); @@ -208,8 +207,8 @@ static void instream_start(struct hpi_adapter_obj *pao,  static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,  	u32 address); -static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index, -	u32 address, u32 data); +static void boot_loader_write_mem32(struct hpi_adapter_obj *pao, +	int dsp_index, u32 address, u32 data);  static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao,  	int dsp_index); @@ -227,25 +226,13 @@ static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);  /*****************************************************************************/ -static void subsys_message(struct hpi_message *phm, struct hpi_response *phr) +static void subsys_message(struct hpi_adapter_obj *pao, +	struct hpi_message *phm, struct hpi_response *phr)  { -  	switch (phm->function) { -	case HPI_SUBSYS_OPEN: -	case HPI_SUBSYS_CLOSE: -	case HPI_SUBSYS_GET_INFO: -	case HPI_SUBSYS_DRIVER_UNLOAD: -	case HPI_SUBSYS_DRIVER_LOAD: -	case HPI_SUBSYS_FIND_ADAPTERS: -		/* messages that should not get here */ -		phr->error = HPI_ERROR_UNIMPLEMENTED; -		break;  	case HPI_SUBSYS_CREATE_ADAPTER:  		subsys_create_adapter(phm, phr);  		break; -	case HPI_SUBSYS_DELETE_ADAPTER: -		subsys_delete_adapter(phm, phr); -		break;  	default:  		phr->error = HPI_ERROR_INVALID_FUNC;  		break; @@ -257,15 +244,22 @@ static void control_message(struct hpi_adapter_obj *pao,  {  	struct hpi_hw_obj *phw = pao->priv; +	u16 pending_cache_error = 0;  	switch (phm->function) {  	case HPI_CONTROL_GET_STATE:  		if (pao->has_control_cache) { -			rmb();	/* make sure we see updates DM_aed from DSP */ -			if (hpi_check_control_cache(phw->p_cache, phm, phr)) +			rmb();	/* make sure we see updates DMAed from DSP */ +			if (hpi_check_control_cache(phw->p_cache, phm, phr)) {  				break; +			} else if (phm->u.c.attribute == HPI_METER_PEAK) { +				pending_cache_error = +					HPI_ERROR_CONTROL_CACHING; +			}  		}  		hw_message(pao, phm, phr); +		if (pending_cache_error && !phr->error) +			phr->error = pending_cache_error;  		break;  	case HPI_CONTROL_GET_INFO:  		hw_message(pao, phm, phr); @@ -273,7 +267,8 @@ static void control_message(struct hpi_adapter_obj *pao,  	case HPI_CONTROL_SET_STATE:  		hw_message(pao, phm, phr);  		if (pao->has_control_cache) -			hpi_sync_control_cache(phw->p_cache, phm, phr); +			hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm, +				phr);  		break;  	default:  		phr->error = HPI_ERROR_INVALID_FUNC; @@ -285,6 +280,10 @@ static void adapter_message(struct hpi_adapter_obj *pao,  	struct hpi_message *phm, struct hpi_response *phr)  {  	switch (phm->function) { +	case HPI_ADAPTER_DELETE: +		adapter_delete(pao, phm, phr); +		break; +  	default:  		hw_message(pao, phm, phr);  		break; @@ -296,9 +295,9 @@ static void outstream_message(struct hpi_adapter_obj *pao,  {  	if (phm->obj_index >= HPI_MAX_STREAMS) { -		phr->error = HPI_ERROR_INVALID_STREAM; +		phr->error = HPI_ERROR_INVALID_OBJ_INDEX;  		HPI_DEBUG_LOG(WARNING, -			"message referencing invalid stream %d " +			"Message referencing invalid stream %d "  			"on adapter index %d\n", phm->obj_index,  			phm->adapter_index);  		return; @@ -340,9 +339,9 @@ static void instream_message(struct hpi_adapter_obj *pao,  {  	if (phm->obj_index >= HPI_MAX_STREAMS) { -		phr->error = HPI_ERROR_INVALID_STREAM; +		phr->error = HPI_ERROR_INVALID_OBJ_INDEX;  		HPI_DEBUG_LOG(WARNING, -			"message referencing invalid stream %d " +			"Message referencing invalid stream %d "  			"on adapter index %d\n", phm->obj_index,  			phm->adapter_index);  		return; @@ -377,59 +376,36 @@ static void instream_message(struct hpi_adapter_obj *pao,  /** Entry point to this HPI backend   * All calls to the HPI start here   */ -void HPI_6205(struct hpi_message *phm, struct hpi_response *phr) +static +void _HPI_6205(struct hpi_adapter_obj *pao, struct hpi_message *phm, +	struct hpi_response *phr)  { -	struct hpi_adapter_obj *pao = NULL; - -	/* subsytem messages are processed by every HPI. -	 * All other messages are ignored unless the adapter index matches -	 * an adapter in the HPI -	 */ -	HPI_DEBUG_LOG(DEBUG, "HPI obj=%d, func=%d\n", phm->object, -		phm->function); - -	/* if Dsp has crashed then do not communicate with it any more */ -	if (phm->object != HPI_OBJ_SUBSYSTEM) { -		pao = hpi_find_adapter(phm->adapter_index); -		if (!pao) { -			HPI_DEBUG_LOG(DEBUG, -				" %d,%d refused, for another HPI?\n", -				phm->object, phm->function); -			return; -		} - -		if ((pao->dsp_crashed >= 10) -			&& (phm->function != HPI_ADAPTER_DEBUG_READ)) { -			/* allow last resort debug read even after crash */ -			hpi_init_response(phr, phm->object, phm->function, -				HPI_ERROR_DSP_HARDWARE); -			HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n", -				phm->object, phm->function); -			return; -		} +	if (pao && (pao->dsp_crashed >= 10) +		&& (phm->function != HPI_ADAPTER_DEBUG_READ)) { +		/* allow last resort debug read even after crash */ +		hpi_init_response(phr, phm->object, phm->function, +			HPI_ERROR_DSP_HARDWARE); +		HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n", phm->object, +			phm->function); +		return;  	}  	/* Init default response  */  	if (phm->function != HPI_SUBSYS_CREATE_ADAPTER) -		hpi_init_response(phr, phm->object, phm->function, -			HPI_ERROR_PROCESSING_MESSAGE); +		phr->error = HPI_ERROR_PROCESSING_MESSAGE;  	HPI_DEBUG_LOG(VERBOSE, "start of switch\n");  	switch (phm->type) { -	case HPI_TYPE_MESSAGE: +	case HPI_TYPE_REQUEST:  		switch (phm->object) {  		case HPI_OBJ_SUBSYSTEM: -			subsys_message(phm, phr); +			subsys_message(pao, phm, phr);  			break;  		case HPI_OBJ_ADAPTER: -			phr->size = -				sizeof(struct hpi_response_header) + -				sizeof(struct hpi_adapter_res);  			adapter_message(pao, phm, phr);  			break; -		case HPI_OBJ_CONTROLEX:  		case HPI_OBJ_CONTROL:  			control_message(pao, phm, phr);  			break; @@ -454,6 +430,26 @@ void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)  	}  } +void HPI_6205(struct hpi_message *phm, struct hpi_response *phr) +{ +	struct hpi_adapter_obj *pao = NULL; + +	if (phm->object != HPI_OBJ_SUBSYSTEM) { +		/* normal messages must have valid adapter index */ +		pao = hpi_find_adapter(phm->adapter_index); +	} else { +		/* subsys messages don't address an adapter */ +		_HPI_6205(NULL, phm, phr); +		return; +	} + +	if (pao) +		_HPI_6205(pao, phm, phr); +	else +		hpi_init_response(phr, phm->object, phm->function, +			HPI_ERROR_BAD_ADAPTER_NUMBER); +} +  /*****************************************************************************/  /* SUBSYSTEM */ @@ -474,51 +470,43 @@ static void subsys_create_adapter(struct hpi_message *phm,  	memset(&ao, 0, sizeof(ao)); -	/* this HPI only creates adapters for TI/PCI devices */ -	if (phm->u.s.resource.bus_type != HPI_BUS_PCI) -		return; -	if (phm->u.s.resource.r.pci->vendor_id != HPI_PCI_VENDOR_ID_TI) -		return; -	if (phm->u.s.resource.r.pci->device_id != HPI_PCI_DEV_ID_DSP6205) -		return; -  	ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);  	if (!ao.priv) { -		HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n"); +		HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");  		phr->error = HPI_ERROR_MEMORY_ALLOC;  		return;  	}  	ao.pci = *phm->u.s.resource.r.pci;  	err = create_adapter_obj(&ao, &os_error_code); -	if (!err) -		err = hpi_add_adapter(&ao);  	if (err) { -		phr->u.s.data = os_error_code;  		delete_adapter_obj(&ao); -		phr->error = err; +		if (err >= HPI_ERROR_BACKEND_BASE) { +			phr->error = HPI_ERROR_DSP_BOOTLOAD; +			phr->specific_error = err; +		} else { +			phr->error = err; +		} +		phr->u.s.data = os_error_code;  		return;  	} -	phr->u.s.aw_adapter_list[ao.index] = ao.adapter_type; +	phr->u.s.adapter_type = ao.type;  	phr->u.s.adapter_index = ao.index; -	phr->u.s.num_adapters++;  	phr->error = 0;  }  /** delete an adapter - required by WDM driver */ -static void subsys_delete_adapter(struct hpi_message *phm, -	struct hpi_response *phr) +static void adapter_delete(struct hpi_adapter_obj *pao, +	struct hpi_message *phm, struct hpi_response *phr)  { -	struct hpi_adapter_obj *pao;  	struct hpi_hw_obj *phw; -	pao = hpi_find_adapter(phm->adapter_index);  	if (!pao) {  		phr->error = HPI_ERROR_INVALID_OBJ_INDEX;  		return;  	} -	phw = (struct hpi_hw_obj *)pao->priv; +	phw = pao->priv;  	/* reset adapter h/w */  	/* Reset C6713 #1 */  	boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0); @@ -526,6 +514,7 @@ static void subsys_delete_adapter(struct hpi_message *phm,  	iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);  	delete_adapter_obj(pao); +	hpi_delete_adapter(pao);  	phr->error = 0;  } @@ -538,10 +527,6 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,  	struct hpi_hw_obj *phw = pao->priv;  	struct bus_master_interface *interface;  	u32 phys_addr; -#ifndef HPI6205_NO_HSR_POLL -	u32 time_out = HPI6205_TIMEOUT; -	u32 temp1; -#endif  	int i;  	u16 err; @@ -566,7 +551,7 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,  	if (hpios_locked_mem_alloc(&phw->h_locked_mem,  			sizeof(struct bus_master_interface), -			pao->pci.p_os_data)) +			pao->pci.pci_dev))  		phw->p_interface_buffer = NULL;  	else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,  			(void *)&phw->p_interface_buffer)) @@ -582,58 +567,39 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,  	}  	err = adapter_boot_load_dsp(pao, pos_error_code); -	if (err) +	if (err) { +		HPI_DEBUG_LOG(ERROR, "DSP code load failed\n");  		/* no need to clean up as SubSysCreateAdapter */  		/* calls DeleteAdapter on error. */  		return err; - +	}  	HPI_DEBUG_LOG(INFO, "load DSP code OK\n");  	/* allow boot load even if mem alloc wont work */  	if (!phw->p_interface_buffer) -		return hpi6205_error(0, HPI_ERROR_MEMORY_ALLOC); +		return HPI_ERROR_MEMORY_ALLOC;  	interface = phw->p_interface_buffer; -#ifndef HPI6205_NO_HSR_POLL -	/* wait for first interrupt indicating the DSP init is done */ -	time_out = HPI6205_TIMEOUT * 10; -	temp1 = 0; -	while (((temp1 & C6205_HSR_INTSRC) == 0) && --time_out) -		temp1 = ioread32(phw->prHSR); - -	if (temp1 & C6205_HSR_INTSRC) -		HPI_DEBUG_LOG(INFO, -			"interrupt confirming DSP code running OK\n"); -	else { -		HPI_DEBUG_LOG(ERROR, -			"timed out waiting for interrupt " -			"confirming DSP code running\n"); -		return hpi6205_error(0, HPI6205_ERROR_6205_NO_IRQ); -	} - -	/* reset the interrupt */ -	iowrite32(C6205_HSR_INTSRC, phw->prHSR); -#endif -  	/* make sure the DSP has started ok */  	if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {  		HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n"); -		return hpi6205_error(0, HPI6205_ERROR_6205_INIT_FAILED); +		return HPI6205_ERROR_6205_INIT_FAILED;  	}  	/* Note that *pao, *phw are zeroed after allocation,  	 * so pointers and flags are NULL by default.  	 * Allocate bus mastering control cache buffer and tell the DSP about it  	 */  	if (interface->control_cache.number_of_controls) { -		void *p_control_cache_virtual; +		u8 *p_control_cache_virtual;  		err = hpios_locked_mem_alloc(&phw->h_control_cache,  			interface->control_cache.size_in_bytes, -			pao->pci.p_os_data); +			pao->pci.pci_dev);  		if (!err)  			err = hpios_locked_mem_get_virt_addr(&phw-> -				h_control_cache, &p_control_cache_virtual); +				h_control_cache, +				(void *)&p_control_cache_virtual);  		if (!err) {  			memset(p_control_cache_virtual, 0,  				interface->control_cache.size_in_bytes); @@ -642,8 +608,8 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,  				hpi_alloc_control_cache(interface->  				control_cache.number_of_controls,  				interface->control_cache.size_in_bytes, -				(struct hpi_control_cache_info *)  				p_control_cache_virtual); +  			if (!phw->p_cache)  				err = HPI_ERROR_MEMORY_ALLOC;  		} @@ -662,96 +628,63 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,  			pao->has_control_cache = 0;  		}  	} -	/* allocate bus mastering async buffer and tell the DSP about it */ -	if (interface->async_buffer.b.size) { -		err = hpios_locked_mem_alloc(&phw->h_async_event_buffer, -			interface->async_buffer.b.size * -			sizeof(struct hpi_async_event), pao->pci.p_os_data); -		if (!err) -			err = hpios_locked_mem_get_virt_addr -				(&phw->h_async_event_buffer, (void *) -				&phw->p_async_event_buffer); -		if (!err) -			memset((void *)phw->p_async_event_buffer, 0, -				interface->async_buffer.b.size * -				sizeof(struct hpi_async_event)); -		if (!err) { -			err = hpios_locked_mem_get_phys_addr -				(&phw->h_async_event_buffer, &phys_addr); -			interface->async_buffer.physical_address32 = -				phys_addr; -		} -		if (err) { -			if (hpios_locked_mem_valid(&phw-> -					h_async_event_buffer)) { -				hpios_locked_mem_free -					(&phw->h_async_event_buffer); -				phw->p_async_event_buffer = NULL; -			} -		} -	}  	send_dsp_command(phw, H620_HIF_IDLE);  	{ -		struct hpi_message hM; -		struct hpi_response hR; +		struct hpi_message hm; +		struct hpi_response hr;  		u32 max_streams;  		HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n"); -		memset(&hM, 0, sizeof(hM)); -		hM.type = HPI_TYPE_MESSAGE; -		hM.size = sizeof(hM); -		hM.object = HPI_OBJ_ADAPTER; -		hM.function = HPI_ADAPTER_GET_INFO; -		hM.adapter_index = 0; -		memset(&hR, 0, sizeof(hR)); -		hR.size = sizeof(hR); - -		err = message_response_sequence(pao, &hM, &hR); +		memset(&hm, 0, sizeof(hm)); +		/* wAdapterIndex == version == 0 */ +		hm.type = HPI_TYPE_REQUEST; +		hm.size = sizeof(hm); +		hm.object = HPI_OBJ_ADAPTER; +		hm.function = HPI_ADAPTER_GET_INFO; + +		memset(&hr, 0, sizeof(hr)); +		hr.size = sizeof(hr); + +		err = message_response_sequence(pao, &hm, &hr);  		if (err) {  			HPI_DEBUG_LOG(ERROR, "message transport error %d\n",  				err);  			return err;  		} -		if (hR.error) -			return hR.error; - -		pao->adapter_type = hR.u.a.adapter_type; -		pao->index = hR.u.a.adapter_index; +		if (hr.error) +			return hr.error; -		max_streams = hR.u.a.num_outstreams + hR.u.a.num_instreams; +		pao->type = hr.u.ax.info.adapter_type; +		pao->index = hr.u.ax.info.adapter_index; -		hpios_locked_mem_prepare((max_streams * 6) / 10, max_streams, -			65536, pao->pci.p_os_data); +		max_streams = +			hr.u.ax.info.num_outstreams + +			hr.u.ax.info.num_instreams;  		HPI_DEBUG_LOG(VERBOSE,  			"got adapter info type %x index %d serial %d\n", -			hR.u.a.adapter_type, hR.u.a.adapter_index, -			hR.u.a.serial_number); +			hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index, +			hr.u.ax.info.serial_number);  	} -	pao->open = 0;	/* upon creation the adapter is closed */ +	if (phw->p_cache) +		phw->p_cache->adap_idx = pao->index;  	HPI_DEBUG_LOG(INFO, "bootload DSP OK\n"); -	return 0; + +	return hpi_add_adapter(pao);  }  /** Free memory areas allocated by adapter - * this routine is called from SubSysDeleteAdapter, + * this routine is called from AdapterDelete,    * and SubSysCreateAdapter if duplicate index  */  static void delete_adapter_obj(struct hpi_adapter_obj *pao)  { -	struct hpi_hw_obj *phw; +	struct hpi_hw_obj *phw = pao->priv;  	int i; -	phw = pao->priv; - -	if (hpios_locked_mem_valid(&phw->h_async_event_buffer)) { -		hpios_locked_mem_free(&phw->h_async_event_buffer); -		phw->p_async_event_buffer = NULL; -	} -  	if (hpios_locked_mem_valid(&phw->h_control_cache)) {  		hpios_locked_mem_free(&phw->h_control_cache);  		hpi_free_control_cache(phw->p_cache); @@ -775,14 +708,13 @@ static void delete_adapter_obj(struct hpi_adapter_obj *pao)  				[i]);  			phw->outstream_host_buffer_size[i] = 0;  		} - -	hpios_locked_mem_unprepare(pao->pci.p_os_data); - -	hpi_delete_adapter(pao);  	kfree(phw);  }  /*****************************************************************************/ +/* Adapter functions */ + +/*****************************************************************************/  /* OutStream Host buffer functions */  /** Allocate or attach buffer for busmastering @@ -824,7 +756,7 @@ static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,  		err = hpios_locked_mem_alloc(&phw->outstream_host_buffers  			[phm->obj_index], phm->u.d.u.buffer.buffer_size, -			pao->pci.p_os_data); +			pao->pci.pci_dev);  		if (err) {  			phr->error = HPI_ERROR_INVALID_DATASIZE; @@ -861,7 +793,7 @@ static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,  		if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.  				buffer_size - 1)) {  			HPI_DEBUG_LOG(ERROR, -				"buffer size must be 2^N not %d\n", +				"Buffer size must be 2^N not %d\n",  				phm->u.d.u.buffer.buffer_size);  			phr->error = HPI_ERROR_INVALID_DATASIZE;  			return; @@ -872,9 +804,10 @@ static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,  			obj_index];  		status->samples_processed = 0;  		status->stream_state = HPI_STATE_STOPPED; -		status->dSP_index = 0; -		status->host_index = status->dSP_index; +		status->dsp_index = 0; +		status->host_index = status->dsp_index;  		status->size_in_bytes = phm->u.d.u.buffer.buffer_size; +		status->auxiliary_data_available = 0;  		hw_message(pao, phm, phr); @@ -946,7 +879,7 @@ static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,  static u32 outstream_get_space_available(struct hpi_hostbuffer_status *status)  {  	return status->size_in_bytes - (status->host_index - -		status->dSP_index); +		status->dsp_index);  }  static void outstream_write(struct hpi_adapter_obj *pao, @@ -966,51 +899,6 @@ static void outstream_write(struct hpi_adapter_obj *pao,  	hpi_init_response(phr, phm->object, phm->function, 0);  	status = &interface->outstream_host_buffer_status[phm->obj_index]; -	if (phw->flag_outstream_just_reset[phm->obj_index]) { -		/* First OutStremWrite() call following reset will write data to the -		   adapter's buffers, reducing delay before stream can start. The DSP -		   takes care of setting the stream data format using format information -		   embedded in phm. -		 */ -		int partial_write = 0; -		unsigned int original_size = 0; - -		phw->flag_outstream_just_reset[phm->obj_index] = 0; - -		/* Send the first buffer to the DSP the old way. */ -		/* Limit size of first transfer - */ -		/* expect that this will not usually be triggered. */ -		if (phm->u.d.u.data.data_size > HPI6205_SIZEOF_DATA) { -			partial_write = 1; -			original_size = phm->u.d.u.data.data_size; -			phm->u.d.u.data.data_size = HPI6205_SIZEOF_DATA; -		} -		/* write it */ -		phm->function = HPI_OSTREAM_WRITE; -		hw_message(pao, phm, phr); - -		if (phr->error) -			return; - -		/* update status information that the DSP would typically -		 * update (and will update next time the DSP -		 * buffer update task reads data from the host BBM buffer) -		 */ -		status->auxiliary_data_available = phm->u.d.u.data.data_size; -		status->host_index += phm->u.d.u.data.data_size; -		status->dSP_index += phm->u.d.u.data.data_size; - -		/* if we did a full write, we can return from here. */ -		if (!partial_write) -			return; - -		/* tweak buffer parameters and let the rest of the */ -		/* buffer land in internal BBM buffer */ -		phm->u.d.u.data.data_size = -			original_size - HPI6205_SIZEOF_DATA; -		phm->u.d.u.data.pb_data += HPI6205_SIZEOF_DATA; -	} -  	space_available = outstream_get_space_available(status);  	if (space_available < phm->u.d.u.data.data_size) {  		phr->error = HPI_ERROR_INVALID_DATASIZE; @@ -1047,6 +935,24 @@ static void outstream_write(struct hpi_adapter_obj *pao,  		memcpy(p_bbm_data, p_app_data + l_first_write,  			phm->u.d.u.data.data_size - l_first_write);  	} + +	/* +	 * This version relies on the DSP code triggering an OStream buffer +	 * update immediately following a SET_FORMAT call. The host has +	 * already written data into the BBM buffer, but the DSP won't know +	 * about it until dwHostIndex is adjusted. +	 */ +	if (phw->flag_outstream_just_reset[phm->obj_index]) { +		/* Format can only change after reset. Must tell DSP. */ +		u16 function = phm->function; +		phw->flag_outstream_just_reset[phm->obj_index] = 0; +		phm->function = HPI_OSTREAM_SET_FORMAT; +		hw_message(pao, phm, phr);	/* send the format to the DSP */ +		phm->function = function; +		if (phr->error) +			return; +	} +  	status->host_index += phm->u.d.u.data.data_size;  } @@ -1132,7 +1038,7 @@ static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,  		err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->  				obj_index], phm->u.d.u.buffer.buffer_size, -			pao->pci.p_os_data); +			pao->pci.pci_dev);  		if (err) {  			phr->error = HPI_ERROR_INVALID_DATASIZE; @@ -1163,7 +1069,7 @@ static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,  		if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.  				buffer_size - 1)) {  			HPI_DEBUG_LOG(ERROR, -				"buffer size must be 2^N not %d\n", +				"Buffer size must be 2^N not %d\n",  				phm->u.d.u.buffer.buffer_size);  			phr->error = HPI_ERROR_INVALID_DATASIZE;  			return; @@ -1175,11 +1081,13 @@ static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,  			obj_index];  		status->samples_processed = 0;  		status->stream_state = HPI_STATE_STOPPED; -		status->dSP_index = 0; -		status->host_index = status->dSP_index; +		status->dsp_index = 0; +		status->host_index = status->dsp_index;  		status->size_in_bytes = phm->u.d.u.buffer.buffer_size; +		status->auxiliary_data_available = 0;  		hw_message(pao, phm, phr); +  		if (phr->error  			&& hpios_locked_mem_valid(&phw->  				instream_host_buffers[phm->obj_index])) { @@ -1255,7 +1163,7 @@ static void instream_start(struct hpi_adapter_obj *pao,  static u32 instream_get_bytes_available(struct hpi_hostbuffer_status *status)  { -	return status->dSP_index - status->host_index; +	return status->dsp_index - status->host_index;  }  static void instream_read(struct hpi_adapter_obj *pao, @@ -1344,33 +1252,37 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  	struct hpi_hw_obj *phw = pao->priv;  	struct dsp_code dsp_code;  	u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD]; -	u16 firmware_id = pao->pci.subsys_device_id;  	u32 temp;  	int dsp = 0, i = 0;  	u16 err = 0;  	boot_code_id[0] = HPI_ADAPTER_ASI(0x6205); -	/* special cases where firmware_id != subsys ID */ -	switch (firmware_id) { +	boot_code_id[1] = pao->pci.pci_dev->subsystem_device; +	boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(boot_code_id[1]); + +	/* fix up cases where bootcode id[1] != subsys id */ +	switch (boot_code_id[1]) {  	case HPI_ADAPTER_FAMILY_ASI(0x5000): -		boot_code_id[0] = firmware_id; -		firmware_id = 0; +		boot_code_id[0] = boot_code_id[1]; +		boot_code_id[1] = 0;  		break;  	case HPI_ADAPTER_FAMILY_ASI(0x5300):  	case HPI_ADAPTER_FAMILY_ASI(0x5400):  	case HPI_ADAPTER_FAMILY_ASI(0x6300): -		firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6400); +		boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);  		break; +	case HPI_ADAPTER_FAMILY_ASI(0x5500):  	case HPI_ADAPTER_FAMILY_ASI(0x5600):  	case HPI_ADAPTER_FAMILY_ASI(0x6500): -		firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6600); +		boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);  		break;  	case HPI_ADAPTER_FAMILY_ASI(0x8800): -		firmware_id = HPI_ADAPTER_FAMILY_ASI(0x8900); +		boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x8900); +		break; +	default:  		break;  	} -	boot_code_id[1] = firmware_id;  	/* reset DSP by writing a 1 to the WARMRESET bit */  	temp = C6205_HDCR_WARMRESET; @@ -1381,7 +1293,7 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  	temp = ioread32(phw->prHSR);  	if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=  		C6205_HSR_EEREAD) -		return hpi6205_error(0, HPI6205_ERROR_6205_EEPROM); +		return HPI6205_ERROR_6205_EEPROM;  	temp |= 0x04;  	/* disable PINTA interrupt */  	iowrite32(temp, phw->prHSR); @@ -1389,27 +1301,27 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  	/* check control register reports PCI boot mode */  	temp = ioread32(phw->prHDCR);  	if (!(temp & C6205_HDCR_PCIBOOT)) -		return hpi6205_error(0, HPI6205_ERROR_6205_REG); +		return HPI6205_ERROR_6205_REG; -	/* try writing a couple of numbers to the DSP page register */ +	/* try writing a few numbers to the DSP page register */  	/* and reading them back. */ -	temp = 1; +	temp = 3;  	iowrite32(temp, phw->prDSPP);  	if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP)) -		return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE); +		return HPI6205_ERROR_6205_DSPPAGE;  	temp = 2;  	iowrite32(temp, phw->prDSPP);  	if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP)) -		return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE); -	temp = 3; +		return HPI6205_ERROR_6205_DSPPAGE; +	temp = 1;  	iowrite32(temp, phw->prDSPP);  	if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP)) -		return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE); +		return HPI6205_ERROR_6205_DSPPAGE;  	/* reset DSP page to the correct number */  	temp = 0;  	iowrite32(temp, phw->prDSPP);  	if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP)) -		return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE); +		return HPI6205_ERROR_6205_DSPPAGE;  	phw->dsp_page = 0;  	/* release 6713 from reset before 6205 is bootloaded. @@ -1455,9 +1367,8 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  			return err;  		/* write the DSP code down into the DSPs memory */ -		dsp_code.ps_dev = pao->pci.p_os_data; -		err = hpi_dsp_code_open(boot_code_id[dsp], &dsp_code, -			pos_error_code); +		err = hpi_dsp_code_open(boot_code_id[dsp], pao->pci.pci_dev, +			&dsp_code, pos_error_code);  		if (err)  			return err; @@ -1484,10 +1395,8 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  			if (err)  				break;  			for (i = 0; i < (int)length; i++) { -				err = boot_loader_write_mem32(pao, dsp, -					address, *pcode); -				if (err) -					break; +				boot_loader_write_mem32(pao, dsp, address, +					*pcode);  				/* dummy read every 4 words */  				/* for 6205 advisory 1.4.4 */  				if (i % 4 == 0) @@ -1561,7 +1470,7 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,  		host_mailbox_address_on_dsp = 0x80000000;  		while ((physicalPC_iaddress != physicalPC_iaddress_verify)  			&& time_out--) { -			err = boot_loader_write_mem32(pao, 0, +			boot_loader_write_mem32(pao, 0,  				host_mailbox_address_on_dsp,  				physicalPC_iaddress);  			physicalPC_iaddress_verify = @@ -1631,11 +1540,10 @@ static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,  	return data;  } -static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index, -	u32 address, u32 data) +static void boot_loader_write_mem32(struct hpi_adapter_obj *pao, +	int dsp_index, u32 address, u32 data)  {  	struct hpi_hw_obj *phw = pao->priv; -	u16 err = 0;  	__iomem u32 *p_data;  	/*      u32 dwVerifyData=0; */ @@ -1675,15 +1583,11 @@ static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index,  		/* dummy read every 4 words for 6205 advisory 1.4.4 */  		boot_loader_read_mem32(pao, 0, 0); -	} else -		err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX); -	return err; +	}  }  static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  { -	u16 err = 0; -  	if (dsp_index == 0) {  		u32 setting; @@ -1711,8 +1615,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  		boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);  		if (setting != boot_loader_read_mem32(pao, dsp_index,  				0x01800008)) -			return hpi6205_error(dsp_index, -				HPI6205_ERROR_DSP_EMIF); +			return HPI6205_ERROR_DSP_EMIF1;  		/* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */  		/* which occupies D15..0. 6713 starts at 27MHz, so need */ @@ -1725,8 +1628,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  		boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);  		if (setting != boot_loader_read_mem32(pao, dsp_index,  				0x01800004)) -			return hpi6205_error(dsp_index, -				HPI6205_ERROR_DSP_EMIF); +			return HPI6205_ERROR_DSP_EMIF2;  		/* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */  		/* which occupies D15..0. 6713 starts at 27MHz, so need */ @@ -1738,8 +1640,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  		boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);  		if (setting != boot_loader_read_mem32(pao, dsp_index,  				0x01800010)) -			return hpi6205_error(dsp_index, -				HPI6205_ERROR_DSP_EMIF); +			return HPI6205_ERROR_DSP_EMIF3;  		/* EMIF CE3 setup - 32 bit async. */  		/* This is the PLD on the ASI5000 cards only */ @@ -1750,8 +1651,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  		boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);  		if (setting != boot_loader_read_mem32(pao, dsp_index,  				0x01800014)) -			return hpi6205_error(dsp_index, -				HPI6205_ERROR_DSP_EMIF); +			return HPI6205_ERROR_DSP_EMIF4;  		/* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */  		/*  need to use this else DSP code crashes? */ @@ -1775,12 +1675,9 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  		read_data =  			0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);  		if (write_data != read_data) { -			err = hpi6205_error(dsp_index, -				HPI6205_ERROR_C6713_HPIC);  			HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,  				read_data); - -			return err; +			return HPI6205_ERROR_C6713_HPIC;  		}  		/* HPIA - walking ones test */  		write_data = 1; @@ -1798,11 +1695,9 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  						HPIAH_ADDR))  				<< 16);  			if (read_data != write_data) { -				err = hpi6205_error(dsp_index, -					HPI6205_ERROR_C6713_HPIA);  				HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",  					write_data, read_data); -				return err; +				return HPI6205_ERROR_C6713_HPIA;  			}  			write_data = write_data << 1;  		} @@ -1847,30 +1742,81 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)  		/* PLL should not be bypassed! */  		if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)  			!= 0x0001) { -			err = hpi6205_error(dsp_index, -				HPI6205_ERROR_C6713_PLL); -			return err; +			return HPI6205_ERROR_C6713_PLL;  		}  		/* setup C67x EMIF  (note this is the only use of  		   BAR1 via BootLoader_WriteMem32) */  		boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,  			0x000034A8); + +		/* EMIF CE0 setup - 2Mx32 Sync DRAM +		   31..28       Wr setup +		   27..22       Wr strobe +		   21..20       Wr hold +		   19..16       Rd setup +		   15..14       - +		   13..8        Rd strobe +		   7..4         MTYPE   0011            Sync DRAM 32bits +		   3            Wr hold MSB +		   2..0         Rd hold +		 */  		boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,  			0x00000030); + +		/* EMIF SDRAM Extension +		   0x00 +		   31-21        0000b 0000b 000b +		   20           WR2RD = 2cycles-1  = 1b + +		   19-18        WR2DEAC = 3cycle-1 = 10b +		   17           WR2WR = 2cycle-1   = 1b +		   16-15        R2WDQM = 4cycle-1  = 11b +		   14-12        RD2WR = 6cycles-1  = 101b + +		   11-10        RD2DEAC = 4cycle-1 = 11b +		   9            RD2RD = 2cycle-1   = 1b +		   8-7          THZP = 3cycle-1    = 10b +		   6-5          TWR  = 2cycle-1    = 01b (tWR = 17ns) +		   4            TRRD = 2cycle      = 0b  (tRRD = 14ns) +		   3-1          TRAS = 5cycle-1    = 100b (Tras=42ns) +		   1            CAS latency = 3cyc = 1b +		   (for Micron 2M32-7 operating at 100MHz) +		 */  		boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,  			0x001BDF29); + +		/* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank) +		   31           -       0b       - +		   30           SDBSZ   1b              4 bank +		   29..28       SDRSZ   00b             11 row address pins + +		   27..26       SDCSZ   01b             8 column address pins +		   25           RFEN    1b              refersh enabled +		   24           INIT    1b              init SDRAM! + +		   23..20       TRCD    0001b                   (Trcd/Tcyc)-1 = (20/10)-1 = 1 + +		   19..16       TRP     0001b                   (Trp/Tcyc)-1 = (20/10)-1 = 1 + +		   15..12       TRC     0110b                   (Trc/Tcyc)-1 = (70/10)-1 = 6 + +		   11..0        -       0000b 0000b 0000b +		 */  		boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL, -			0x47117000); +			0x47116000); + +		/* SDRAM refresh timing +		   Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A +		 */  		boot_loader_write_mem32(pao, dsp_index,  			C6713_EMIF_SDRAMTIMING, 0x00000410);  		hpios_delay_micro_seconds(1000);  	} else if (dsp_index == 2) {  		/* DSP 2 is a C6713 */ +	} -	} else -		err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX); -	return err; +	return 0;  }  static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index, @@ -1896,7 +1842,7 @@ static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,  				test_addr);  			if (data != test_data) {  				HPI_DEBUG_LOG(VERBOSE, -					"memtest error details  " +					"Memtest error details  "  					"%08x %08x %08x %i\n", test_addr,  					test_data, data, dsp_index);  				return 1;	/* error */ @@ -1916,7 +1862,7 @@ static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,  		data = boot_loader_read_mem32(pao, dsp_index, test_addr);  		if (data != test_data) {  			HPI_DEBUG_LOG(VERBOSE, -				"memtest error details  " +				"Memtest error details  "  				"%08x %08x %08x %i\n", test_addr, test_data,  				data, dsp_index);  			return 1;	/* error */ @@ -1946,8 +1892,8 @@ static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,  			/* 64K data mem */  			err = boot_loader_test_memory(pao, dsp_index,  				0x80000000, 0x10000); -	} else if ((dsp_index == 1) || (dsp_index == 2)) { -		/* DSP 1&2 are a C6713 */ +	} else if (dsp_index == 1) { +		/* DSP 1 is a C6713 */  		/* 192K internal mem */  		err = boot_loader_test_memory(pao, dsp_index, 0x00000000,  			0x30000); @@ -1955,11 +1901,10 @@ static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,  			/* 64K internal mem / L2 cache */  			err = boot_loader_test_memory(pao, dsp_index,  				0x00030000, 0x10000); -	} else -		return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX); +	}  	if (err) -		return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_INTMEM); +		return HPI6205_ERROR_DSP_INTMEM;  	else  		return 0;  } @@ -1972,24 +1917,23 @@ static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,  	if (dsp_index == 0) {  		/* only test for SDRAM if an ASI5000 card */ -		if (pao->pci.subsys_device_id == 0x5000) { +		if (pao->pci.pci_dev->subsystem_device == 0x5000) {  			/* DSP 0 is always C6205 */  			dRAM_start_address = 0x00400000;  			dRAM_size = 0x200000;  			/*dwDRAMinc=1024; */  		} else  			return 0; -	} else if ((dsp_index == 1) || (dsp_index == 2)) { +	} else if (dsp_index == 1) {  		/* DSP 1 is a C6713 */  		dRAM_start_address = 0x80000000;  		dRAM_size = 0x200000;  		/*dwDRAMinc=1024; */ -	} else -		return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX); +	}  	if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,  			dRAM_size)) -		return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_EXTMEM); +		return HPI6205_ERROR_DSP_EXTMEM;  	return 0;  } @@ -1998,28 +1942,25 @@ static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)  	u32 data = 0;  	if (dsp_index == 0) {  		/* only test for DSP0 PLD on ASI5000 card */ -		if (pao->pci.subsys_device_id == 0x5000) { +		if (pao->pci.pci_dev->subsystem_device == 0x5000) {  			/* PLD is located at CE3=0x03000000 */  			data = boot_loader_read_mem32(pao, dsp_index,  				0x03000008);  			if ((data & 0xF) != 0x5) -				return hpi6205_error(dsp_index, -					HPI6205_ERROR_DSP_PLD); +				return HPI6205_ERROR_DSP_PLD;  			data = boot_loader_read_mem32(pao, dsp_index,  				0x0300000C);  			if ((data & 0xF) != 0xA) -				return hpi6205_error(dsp_index, -					HPI6205_ERROR_DSP_PLD); +				return HPI6205_ERROR_DSP_PLD;  		}  	} else if (dsp_index == 1) {  		/* DSP 1 is a C6713 */ -		if (pao->pci.subsys_device_id == 0x8700) { +		if (pao->pci.pci_dev->subsystem_device == 0x8700) {  			/* PLD is located at CE1=0x90000000 */  			data = boot_loader_read_mem32(pao, dsp_index,  				0x90000010);  			if ((data & 0xFF) != 0xAA) -				return hpi6205_error(dsp_index, -					HPI6205_ERROR_DSP_PLD); +				return HPI6205_ERROR_DSP_PLD;  			/* 8713 - LED on */  			boot_loader_write_mem32(pao, dsp_index, 0x90000000,  				0x02); @@ -2037,14 +1978,11 @@ static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,  	struct hpi_hw_obj *phw = pao->priv;  	u32 data_transferred = 0;  	u16 err = 0; -#ifndef HPI6205_NO_HSR_POLL -	u32 time_out; -#endif  	u32 temp2;  	struct bus_master_interface *interface = phw->p_interface_buffer;  	if (!p_data) -		return HPI_ERROR_INVALID_DATA_TRANSFER; +		return HPI_ERROR_INVALID_DATA_POINTER;  	data_size &= ~3L;	/* round data_size down to nearest 4 bytes */ @@ -2064,14 +2002,10 @@ static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,  		interface->transfer_size_in_bytes = this_copy; -#ifdef HPI6205_NO_HSR_POLL  		/* DSP must change this back to nOperation */  		interface->dsp_ack = H620_HIF_IDLE; -#endif -  		send_dsp_command(phw, operation); -#ifdef HPI6205_NO_HSR_POLL  		temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);  		HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",  			HPI6205_TIMEOUT - temp2, this_copy); @@ -2079,45 +2013,11 @@ static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,  		if (!temp2) {  			/* timed out */  			HPI_DEBUG_LOG(ERROR, -				"timed out waiting for " "state %d got %d\n", +				"Timed out waiting for " "state %d got %d\n",  				operation, interface->dsp_ack);  			break;  		} -#else -		/* spin waiting on the result */ -		time_out = HPI6205_TIMEOUT; -		temp2 = 0; -		while ((temp2 == 0) && time_out--) { -			/* give 16k bus mastering transfer time to happen */ -			/*(16k / 132Mbytes/s = 122usec) */ -			hpios_delay_micro_seconds(20); -			temp2 = ioread32(phw->prHSR); -			temp2 &= C6205_HSR_INTSRC; -		} -		HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n", -			HPI6205_TIMEOUT - time_out, this_copy); -		if (temp2 == C6205_HSR_INTSRC) { -			HPI_DEBUG_LOG(VERBOSE, -				"interrupt from HIF <data> OK\n"); -			/* -			   if(interface->dwDspAck != nOperation) { -			   HPI_DEBUG_LOG(DEBUG("interface->dwDspAck=%d, -			   expected %d \n", -			   interface->dwDspAck,nOperation); -			   } -			 */ -		} -/* need to handle this differently... */ -		else { -			HPI_DEBUG_LOG(ERROR, -				"interrupt from HIF <data> BAD\n"); -			err = HPI_ERROR_DSP_HARDWARE; -		} - -		/* reset the interrupt from the DSP */ -		iowrite32(C6205_HSR_INTSRC, phw->prHSR); -#endif  		if (operation == H620_HIF_GET_DATA)  			memcpy(&p_data[data_transferred],  				(void *)&interface->u.b_data[0], this_copy); @@ -2156,7 +2056,6 @@ static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)  static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)  {  	struct bus_master_interface *interface = phw->p_interface_buffer; -  	u32 r;  	interface->host_cmd = cmd; @@ -2174,31 +2073,39 @@ static unsigned int message_count;  static u16 message_response_sequence(struct hpi_adapter_obj *pao,  	struct hpi_message *phm, struct hpi_response *phr)  { -#ifndef HPI6205_NO_HSR_POLL -	u32 temp2; -#endif  	u32 time_out, time_out2;  	struct hpi_hw_obj *phw = pao->priv;  	struct bus_master_interface *interface = phw->p_interface_buffer;  	u16 err = 0;  	message_count++; +	if (phm->size > sizeof(interface->u.message_buffer)) { +		phr->error = HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL; +		phr->specific_error = sizeof(interface->u.message_buffer); +		phr->size = sizeof(struct hpi_response_header); +		HPI_DEBUG_LOG(ERROR, +			"message len %d too big for buffer %zd \n", phm->size, +			sizeof(interface->u.message_buffer)); +		return 0; +	} +  	/* Assume buffer of type struct bus_master_interface  	   is allocated "noncacheable" */  	if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {  		HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n"); -		return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT); +		return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;  	} -	interface->u.message_buffer = *phm; + +	memcpy(&interface->u.message_buffer, phm, phm->size);  	/* signal we want a response */  	send_dsp_command(phw, H620_HIF_GET_RESP);  	time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT); -	if (time_out2 == 0) { +	if (!time_out2) {  		HPI_DEBUG_LOG(ERROR, -			"(%u) timed out waiting for " "GET_RESP state [%x]\n", +			"(%u) Timed out waiting for " "GET_RESP state [%x]\n",  			message_count, interface->dsp_ack);  	} else {  		HPI_DEBUG_LOG(VERBOSE, @@ -2208,58 +2115,39 @@ static u16 message_response_sequence(struct hpi_adapter_obj *pao,  	/* spin waiting on HIF interrupt flag (end of msg process) */  	time_out = HPI6205_TIMEOUT; -#ifndef HPI6205_NO_HSR_POLL -	temp2 = 0; -	while ((temp2 == 0) && --time_out) { -		temp2 = ioread32(phw->prHSR); -		temp2 &= C6205_HSR_INTSRC; -		hpios_delay_micro_seconds(1); -	} -	if (temp2 == C6205_HSR_INTSRC) { -		rmb();	/* ensure we see latest value for dsp_ack */ -		if ((interface->dsp_ack != H620_HIF_GET_RESP)) { -			HPI_DEBUG_LOG(DEBUG, -				"(%u)interface->dsp_ack(0x%x) != " -				"H620_HIF_GET_RESP, t=%u\n", message_count, -				interface->dsp_ack, -				HPI6205_TIMEOUT - time_out); -		} else { -			HPI_DEBUG_LOG(VERBOSE, -				"(%u)int with GET_RESP after %u\n", -				message_count, HPI6205_TIMEOUT - time_out); +	/* read the result */ +	if (time_out) { +		if (interface->u.response_buffer.response.size <= phr->size) +			memcpy(phr, &interface->u.response_buffer, +				interface->u.response_buffer.response.size); +		else { +			HPI_DEBUG_LOG(ERROR, +				"response len %d too big for buffer %d\n", +				interface->u.response_buffer.response.size, +				phr->size); +			memcpy(phr, &interface->u.response_buffer, +				sizeof(struct hpi_response_header)); +			phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL; +			phr->specific_error = +				interface->u.response_buffer.response.size; +			phr->size = sizeof(struct hpi_response_header);  		} - -	} else { -		/* can we do anything else in response to the error ? */ -		HPI_DEBUG_LOG(ERROR, -			"interrupt from HIF module BAD (function %x)\n", -			phm->function);  	} - -	/* reset the interrupt from the DSP */ -	iowrite32(C6205_HSR_INTSRC, phw->prHSR); -#endif - -	/* read the result */ -	if (time_out != 0) -		*phr = interface->u.response_buffer; -  	/* set interface back to idle */  	send_dsp_command(phw, H620_HIF_IDLE); -	if ((time_out == 0) || (time_out2 == 0)) { +	if (!time_out || !time_out2) {  		HPI_DEBUG_LOG(DEBUG, "something timed out!\n"); -		return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_TIMEOUT); +		return HPI6205_ERROR_MSG_RESP_TIMEOUT;  	}  	/* special case for adapter close - */  	/* wait for the DSP to indicate it is idle */  	if (phm->function == HPI_ADAPTER_CLOSE) {  		if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {  			HPI_DEBUG_LOG(DEBUG, -				"timeout waiting for idle " +				"Timeout waiting for idle "  				"(on adapter_close)\n"); -			return hpi6205_error(0, -				HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT); +			return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;  		}  	}  	err = hpi_validate_response(phm, phr); @@ -2279,7 +2167,13 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,  	/* maybe an error response */  	if (err) {  		/* something failed in the HPI/DSP interface */ -		phr->error = err; +		if (err >= HPI_ERROR_BACKEND_BASE) { +			phr->error = HPI_ERROR_DSP_COMMUNICATION; +			phr->specific_error = err; +		} else { +			phr->error = err; +		} +  		pao->dsp_crashed++;  		/* just the header of the response is valid */ @@ -2304,23 +2198,6 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,  			phm->u.d.u.data.data_size, H620_HIF_GET_DATA);  		break; -	case HPI_CONTROL_SET_STATE: -		if (phm->object == HPI_OBJ_CONTROLEX -			&& phm->u.cx.attribute == HPI_COBRANET_SET_DATA) -			err = hpi6205_transfer_data(pao, -				phm->u.cx.u.cobranet_bigdata.pb_data, -				phm->u.cx.u.cobranet_bigdata.byte_count, -				H620_HIF_SEND_DATA); -		break; - -	case HPI_CONTROL_GET_STATE: -		if (phm->object == HPI_OBJ_CONTROLEX -			&& phm->u.cx.attribute == HPI_COBRANET_GET_DATA) -			err = hpi6205_transfer_data(pao, -				phm->u.cx.u.cobranet_bigdata.pb_data, -				phr->u.cx.u.cobranet_data.byte_count, -				H620_HIF_GET_DATA); -		break;  	}  	phr->error = err; diff --git a/sound/pci/asihpi/hpi6205.h b/sound/pci/asihpi/hpi6205.h index 1adae0857cd..ec0827b633a 100644 --- a/sound/pci/asihpi/hpi6205.h +++ b/sound/pci/asihpi/hpi6205.h @@ -1,7 +1,7 @@  /*****************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -25,9 +25,6 @@ Copyright AudioScience, Inc., 2003  #ifndef _HPI6205_H_  #define _HPI6205_H_ -/* transitional conditional compile shared between host and DSP */ -/* #define HPI6205_NO_HSR_POLL */ -  #include "hpi_internal.h"  /*********************************************************** @@ -73,15 +70,28 @@ The Host located memory buffer that the 6205 will bus master  in and out of.  ************************************************************/  #define HPI6205_SIZEOF_DATA (16*1024) + +struct message_buffer_6205 { +	struct hpi_message message; +	char data[256]; +}; + +struct response_buffer_6205 { +	struct hpi_response response; +	char data[256]; +}; + +union buffer_6205 { +	struct message_buffer_6205 message_buffer; +	struct response_buffer_6205 response_buffer; +	u8 b_data[HPI6205_SIZEOF_DATA]; +}; +  struct bus_master_interface {  	u32 host_cmd;  	u32 dsp_ack;  	u32 transfer_size_in_bytes; -	union { -		struct hpi_message message_buffer; -		struct hpi_response response_buffer; -		u8 b_data[HPI6205_SIZEOF_DATA]; -	} u; +	union buffer_6205 u;  	struct controlcache_6205 control_cache;  	struct async_event_buffer_6205 async_buffer;  	struct hpi_hostbuffer_status diff --git a/sound/pci/asihpi/hpi_internal.h b/sound/pci/asihpi/hpi_internal.h index 16f502d459d..bc86cb726d7 100644 --- a/sound/pci/asihpi/hpi_internal.h +++ b/sound/pci/asihpi/hpi_internal.h @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2012  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -25,19 +25,14 @@ HPI internal definitions  #define _HPI_INTERNAL_H_  #include "hpi.h" +  /** maximum number of memory regions mapped to an adapter */  #define HPI_MAX_ADAPTER_MEM_SPACES (2) -/* Each OS needs its own hpios.h, or specific define as above */ +/* Each OS needs its own hpios.h */  #include "hpios.h"  /* physical memory allocation */ -void hpios_locked_mem_init(void -	); -void hpios_locked_mem_free_all(void -	); -#define hpios_locked_mem_prepare(a, b, c, d); -#define hpios_locked_mem_unprepare(a)  /** Allocate and map an area of locked memory for bus master DMA operations. @@ -49,7 +44,7 @@ HpiOs_LockedMem_GetPyhsAddr() will always succed on the returned handle.  */  u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_locked_mem_handle,  							   /**< memory handle */ -	u32 size, /**< size in bytes to allocate */ +	u32 size, /**< Size in bytes to allocate */  	struct pci_dev *p_os_reference  	/**< OS specific data required for memory allocation */  	); @@ -96,41 +91,6 @@ typedef void hpi_handler_func(struct hpi_message *, struct hpi_response *);  #define compile_time_assert(cond, msg) \      typedef char ASSERT_##msg[(cond) ? 1 : -1] -/*/////////////////////////////////////////////////////////////////////////// */ -/* Private HPI Entity related definitions                                     */ - -#define STR_SIZE_FIELD_MAX 65535U -#define STR_TYPE_FIELD_MAX 255U -#define STR_ROLE_FIELD_MAX 255U - -struct hpi_entity_str { -	u16 size; -	u8 type; -	u8 role; -}; - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable : 4200) -#endif - -struct hpi_entity { -	struct hpi_entity_str header; -#if ! defined(HPI_OS_DSP_C6000) || (defined(HPI_OS_DSP_C6000) && (__TI_COMPILER_VERSION__ > 6000008)) -	/* DSP C6000 compiler v6.0.8 and lower -	   do not support  flexible array member */ -	u8 value[]; -#else -	/* NOTE! Using sizeof(struct hpi_entity) will give erroneous results */ -#define HPI_INTERNAL_WARN_ABOUT_ENTITY_VALUE -	u8 value[1]; -#endif -}; - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif -  /******************************************* bus types */  enum HPI_BUSES {  	HPI_BUS_ISAPNP = 1, @@ -139,206 +99,155 @@ enum HPI_BUSES {  	HPI_BUS_NET = 4  }; +enum HPI_SUBSYS_OPTIONS { +	/* 0, 256 are invalid, 1..255 reserved for global options */ +	HPI_SUBSYS_OPT_NET_ENABLE = 257, +	HPI_SUBSYS_OPT_NET_BROADCAST = 258, +	HPI_SUBSYS_OPT_NET_UNICAST = 259, +	HPI_SUBSYS_OPT_NET_ADDR = 260, +	HPI_SUBSYS_OPT_NET_MASK = 261, +	HPI_SUBSYS_OPT_NET_ADAPTER_ADDRESS_ADD = 262 +}; + +/** Volume flags +*/ +enum HPI_VOLUME_FLAGS { +	/** Set if the volume control is muted */ +	HPI_VOLUME_FLAG_MUTED = (1 << 0), +	/** Set if the volume control has a mute function */ +	HPI_VOLUME_FLAG_HAS_MUTE = (1 << 1), +	/** Set if volume control can do autofading */ +	HPI_VOLUME_FLAG_HAS_AUTOFADE = (1 << 2) +		/* Note Flags >= (1<<8) are for DSP internal use only */ +}; +  /******************************************* CONTROL ATTRIBUTES ****/  /* (in order of control type ID */  /* This allows for 255 control types, 256 unique attributes each */ -#define HPI_CTL_ATTR(ctl, ai) (HPI_CONTROL_##ctl * 0x100 + ai) +#define HPI_CTL_ATTR(ctl, ai) ((HPI_CONTROL_##ctl << 8) + ai)  /* Get the sub-index of the attribute for a control type */ -#define HPI_CTL_ATTR_INDEX(i) (i&0xff) +#define HPI_CTL_ATTR_INDEX(i) (i & 0xff)  /* Extract the control from the control attribute */ -#define HPI_CTL_ATTR_CONTROL(i) (i>>8) - -/* Generic control attributes.  */ - -/** Enable a control. -0=disable, 1=enable -\note generic to all mixer plugins? -*/ -#define HPI_GENERIC_ENABLE HPI_CTL_ATTR(GENERIC, 1) +#define HPI_CTL_ATTR_CONTROL(i) (i >> 8)  /** Enable event generation for a control.  0=disable, 1=enable  \note generic to all controls that can generate events  */ -#define HPI_GENERIC_EVENT_ENABLE HPI_CTL_ATTR(GENERIC, 2) - -/* Volume Control attributes */ -#define HPI_VOLUME_GAIN                 HPI_CTL_ATTR(VOLUME, 1) -#define HPI_VOLUME_AUTOFADE             HPI_CTL_ATTR(VOLUME, 2) - -/** For HPI_ControlQuery() to get the number of channels of a volume control*/ -#define HPI_VOLUME_NUM_CHANNELS         HPI_CTL_ATTR(VOLUME, 6) -#define HPI_VOLUME_RANGE                HPI_CTL_ATTR(VOLUME, 10) - -/** Level Control attributes */ -#define HPI_LEVEL_GAIN                  HPI_CTL_ATTR(LEVEL, 1) -#define HPI_LEVEL_RANGE                 HPI_CTL_ATTR(LEVEL, 10) - -/* Meter Control attributes */ -/** return RMS signal level */ -#define HPI_METER_RMS                   HPI_CTL_ATTR(METER, 1) -/** return peak signal level */ -#define HPI_METER_PEAK                  HPI_CTL_ATTR(METER, 2) -/** ballistics for ALL rms meters on adapter */ -#define HPI_METER_RMS_BALLISTICS        HPI_CTL_ATTR(METER, 3) -/** ballistics for ALL peak meters on adapter */ -#define HPI_METER_PEAK_BALLISTICS       HPI_CTL_ATTR(METER, 4) - -/** For HPI_ControlQuery() to get the number of channels of a meter control*/ -#define HPI_METER_NUM_CHANNELS          HPI_CTL_ATTR(METER, 5) - -/* Multiplexer control attributes */ -#define HPI_MULTIPLEXER_SOURCE          HPI_CTL_ATTR(MULTIPLEXER, 1) -#define HPI_MULTIPLEXER_QUERYSOURCE     HPI_CTL_ATTR(MULTIPLEXER, 2) - -/** AES/EBU transmitter control attributes */ -/** AESEBU or SPDIF */ -#define HPI_AESEBUTX_FORMAT             HPI_CTL_ATTR(AESEBUTX, 1) -#define HPI_AESEBUTX_SAMPLERATE         HPI_CTL_ATTR(AESEBUTX, 3) -#define HPI_AESEBUTX_CHANNELSTATUS      HPI_CTL_ATTR(AESEBUTX, 4) -#define HPI_AESEBUTX_USERDATA           HPI_CTL_ATTR(AESEBUTX, 5) - -/** AES/EBU receiver control attributes */ -#define HPI_AESEBURX_FORMAT             HPI_CTL_ATTR(AESEBURX, 1) -#define HPI_AESEBURX_ERRORSTATUS        HPI_CTL_ATTR(AESEBURX, 2) -#define HPI_AESEBURX_SAMPLERATE         HPI_CTL_ATTR(AESEBURX, 3) -#define HPI_AESEBURX_CHANNELSTATUS      HPI_CTL_ATTR(AESEBURX, 4) -#define HPI_AESEBURX_USERDATA           HPI_CTL_ATTR(AESEBURX, 5) - -/** \defgroup tuner_defs Tuners -\{ -*/ -/** \defgroup tuner_attrs Tuner control attributes -\{ -*/ -#define HPI_TUNER_BAND                  HPI_CTL_ATTR(TUNER, 1) -#define HPI_TUNER_FREQ                  HPI_CTL_ATTR(TUNER, 2) -#define HPI_TUNER_LEVEL                 HPI_CTL_ATTR(TUNER, 3) -#define HPI_TUNER_AUDIOMUTE             HPI_CTL_ATTR(TUNER, 4) -/* use TUNER_STATUS instead */ -#define HPI_TUNER_VIDEO_STATUS          HPI_CTL_ATTR(TUNER, 5) -#define HPI_TUNER_GAIN                  HPI_CTL_ATTR(TUNER, 6) -#define HPI_TUNER_STATUS                HPI_CTL_ATTR(TUNER, 7) -#define HPI_TUNER_MODE                  HPI_CTL_ATTR(TUNER, 8) -/** RDS data. */ -#define HPI_TUNER_RDS                   HPI_CTL_ATTR(TUNER, 9) -/** Audio pre-emphasis. */ -#define HPI_TUNER_DEEMPHASIS            HPI_CTL_ATTR(TUNER, 10) -/** HD Radio tuner program control. */ -#define HPI_TUNER_PROGRAM               HPI_CTL_ATTR(TUNER, 11) -/** HD Radio tuner digital signal quality. */ -#define HPI_TUNER_HDRADIO_SIGNAL_QUALITY        HPI_CTL_ATTR(TUNER, 12) -/** HD Radio SDK firmware version. */ -#define HPI_TUNER_HDRADIO_SDK_VERSION   HPI_CTL_ATTR(TUNER, 13) -/** HD Radio DSP firmware version. */ -#define HPI_TUNER_HDRADIO_DSP_VERSION   HPI_CTL_ATTR(TUNER, 14) -/** HD Radio signal blend (force analog, or automatic). */ -#define HPI_TUNER_HDRADIO_BLEND         HPI_CTL_ATTR(TUNER, 15) - -/** \} */ - -/** \defgroup pads_attrs Tuner PADs control attributes -\{ -*/ -/** The text string containing the station/channel combination. */ -#define HPI_PAD_CHANNEL_NAME            HPI_CTL_ATTR(PAD, 1) -/** The text string containing the artist. */ -#define HPI_PAD_ARTIST                  HPI_CTL_ATTR(PAD, 2) -/** The text string containing the title. */ -#define HPI_PAD_TITLE                   HPI_CTL_ATTR(PAD, 3) -/** The text string containing the comment. */ -#define HPI_PAD_COMMENT                 HPI_CTL_ATTR(PAD, 4) -/** The integer containing the PTY code. */ -#define HPI_PAD_PROGRAM_TYPE            HPI_CTL_ATTR(PAD, 5) -/** The integer containing the program identification. */ -#define HPI_PAD_PROGRAM_ID              HPI_CTL_ATTR(PAD, 6) -/** The integer containing whether traffic information is supported. -Contains either 1 or 0. */ -#define HPI_PAD_TA_SUPPORT              HPI_CTL_ATTR(PAD, 7) -/** The integer containing whether traffic announcement is in progress. -Contains either 1 or 0. */ -#define HPI_PAD_TA_ACTIVE               HPI_CTL_ATTR(PAD, 8) -/** \} */ -/** \} */ - -/* VOX control attributes */ -#define HPI_VOX_THRESHOLD               HPI_CTL_ATTR(VOX, 1) - -/*?? channel mode used hpi_multiplexer_source attribute == 1 */ -#define HPI_CHANNEL_MODE_MODE HPI_CTL_ATTR(CHANNEL_MODE, 1) - -/** \defgroup channel_modes Channel Modes -Used for HPI_ChannelModeSet/Get() -\{ + +/** Unique identifiers for every control attribute  */ -/** Left channel out = left channel in, Right channel out = right channel in. */ -#define HPI_CHANNEL_MODE_NORMAL                 1 -/** Left channel out = right channel in, Right channel out = left channel in. */ -#define HPI_CHANNEL_MODE_SWAP                   2 -/** Left channel out = left channel in, Right channel out = left channel in. */ -#define HPI_CHANNEL_MODE_LEFT_TO_STEREO         3 -/** Left channel out = right channel in, Right channel out = right channel in.*/ -#define HPI_CHANNEL_MODE_RIGHT_TO_STEREO        4 -/** Left channel out = (left channel in + right channel in)/2, -    Right channel out = mute. */ -#define HPI_CHANNEL_MODE_STEREO_TO_LEFT         5 -/** Left channel out = mute, -    Right channel out = (right channel in + left channel in)/2. */ -#define HPI_CHANNEL_MODE_STEREO_TO_RIGHT        6 -#define HPI_CHANNEL_MODE_LAST                   6 -/** \} */ - -/* Bitstream control set attributes */ -#define HPI_BITSTREAM_DATA_POLARITY     HPI_CTL_ATTR(BITSTREAM, 1) -#define HPI_BITSTREAM_CLOCK_EDGE        HPI_CTL_ATTR(BITSTREAM, 2) -#define HPI_BITSTREAM_CLOCK_SOURCE      HPI_CTL_ATTR(BITSTREAM, 3) +enum HPI_CONTROL_ATTRIBUTES { +	HPI_GENERIC_ENABLE = HPI_CTL_ATTR(GENERIC, 1), +	HPI_GENERIC_EVENT_ENABLE = HPI_CTL_ATTR(GENERIC, 2), + +	HPI_VOLUME_GAIN = HPI_CTL_ATTR(VOLUME, 1), +	HPI_VOLUME_AUTOFADE = HPI_CTL_ATTR(VOLUME, 2), +	HPI_VOLUME_MUTE = HPI_CTL_ATTR(VOLUME, 3), +	HPI_VOLUME_GAIN_AND_FLAGS = HPI_CTL_ATTR(VOLUME, 4), +	HPI_VOLUME_NUM_CHANNELS = HPI_CTL_ATTR(VOLUME, 6), +	HPI_VOLUME_RANGE = HPI_CTL_ATTR(VOLUME, 10), + +	HPI_METER_RMS = HPI_CTL_ATTR(METER, 1), +	HPI_METER_PEAK = HPI_CTL_ATTR(METER, 2), +	HPI_METER_RMS_BALLISTICS = HPI_CTL_ATTR(METER, 3), +	HPI_METER_PEAK_BALLISTICS = HPI_CTL_ATTR(METER, 4), +	HPI_METER_NUM_CHANNELS = HPI_CTL_ATTR(METER, 5), + +	HPI_MULTIPLEXER_SOURCE = HPI_CTL_ATTR(MULTIPLEXER, 1), +	HPI_MULTIPLEXER_QUERYSOURCE = HPI_CTL_ATTR(MULTIPLEXER, 2), + +	HPI_AESEBUTX_FORMAT = HPI_CTL_ATTR(AESEBUTX, 1), +	HPI_AESEBUTX_SAMPLERATE = HPI_CTL_ATTR(AESEBUTX, 3), +	HPI_AESEBUTX_CHANNELSTATUS = HPI_CTL_ATTR(AESEBUTX, 4), +	HPI_AESEBUTX_USERDATA = HPI_CTL_ATTR(AESEBUTX, 5), + +	HPI_AESEBURX_FORMAT = HPI_CTL_ATTR(AESEBURX, 1), +	HPI_AESEBURX_ERRORSTATUS = HPI_CTL_ATTR(AESEBURX, 2), +	HPI_AESEBURX_SAMPLERATE = HPI_CTL_ATTR(AESEBURX, 3), +	HPI_AESEBURX_CHANNELSTATUS = HPI_CTL_ATTR(AESEBURX, 4), +	HPI_AESEBURX_USERDATA = HPI_CTL_ATTR(AESEBURX, 5), + +	HPI_LEVEL_GAIN = HPI_CTL_ATTR(LEVEL, 1), +	HPI_LEVEL_RANGE = HPI_CTL_ATTR(LEVEL, 10), + +	HPI_TUNER_BAND = HPI_CTL_ATTR(TUNER, 1), +	HPI_TUNER_FREQ = HPI_CTL_ATTR(TUNER, 2), +	HPI_TUNER_LEVEL_AVG = HPI_CTL_ATTR(TUNER, 3), +	HPI_TUNER_LEVEL_RAW = HPI_CTL_ATTR(TUNER, 4), +	HPI_TUNER_SNR = HPI_CTL_ATTR(TUNER, 5), +	HPI_TUNER_GAIN = HPI_CTL_ATTR(TUNER, 6), +	HPI_TUNER_STATUS = HPI_CTL_ATTR(TUNER, 7), +	HPI_TUNER_MODE = HPI_CTL_ATTR(TUNER, 8), +	HPI_TUNER_RDS = HPI_CTL_ATTR(TUNER, 9), +	HPI_TUNER_DEEMPHASIS = HPI_CTL_ATTR(TUNER, 10), +	HPI_TUNER_PROGRAM = HPI_CTL_ATTR(TUNER, 11), +	HPI_TUNER_HDRADIO_SIGNAL_QUALITY = HPI_CTL_ATTR(TUNER, 12), +	HPI_TUNER_HDRADIO_SDK_VERSION = HPI_CTL_ATTR(TUNER, 13), +	HPI_TUNER_HDRADIO_DSP_VERSION = HPI_CTL_ATTR(TUNER, 14), +	HPI_TUNER_HDRADIO_BLEND = HPI_CTL_ATTR(TUNER, 15), + +	HPI_VOX_THRESHOLD = HPI_CTL_ATTR(VOX, 1), + +	HPI_CHANNEL_MODE_MODE = HPI_CTL_ATTR(CHANNEL_MODE, 1), + +	HPI_BITSTREAM_DATA_POLARITY = HPI_CTL_ATTR(BITSTREAM, 1), +	HPI_BITSTREAM_CLOCK_EDGE = HPI_CTL_ATTR(BITSTREAM, 2), +	HPI_BITSTREAM_CLOCK_SOURCE = HPI_CTL_ATTR(BITSTREAM, 3), +	HPI_BITSTREAM_ACTIVITY = HPI_CTL_ATTR(BITSTREAM, 4), + +	HPI_SAMPLECLOCK_SOURCE = HPI_CTL_ATTR(SAMPLECLOCK, 1), +	HPI_SAMPLECLOCK_SAMPLERATE = HPI_CTL_ATTR(SAMPLECLOCK, 2), +	HPI_SAMPLECLOCK_SOURCE_INDEX = HPI_CTL_ATTR(SAMPLECLOCK, 3), +	HPI_SAMPLECLOCK_LOCAL_SAMPLERATE = HPI_CTL_ATTR(SAMPLECLOCK, 4), +	HPI_SAMPLECLOCK_AUTO = HPI_CTL_ATTR(SAMPLECLOCK, 5), +	HPI_SAMPLECLOCK_LOCAL_LOCK = HPI_CTL_ATTR(SAMPLECLOCK, 6), + +	HPI_MICROPHONE_PHANTOM_POWER = HPI_CTL_ATTR(MICROPHONE, 1), + +	HPI_EQUALIZER_NUM_FILTERS = HPI_CTL_ATTR(EQUALIZER, 1), +	HPI_EQUALIZER_FILTER = HPI_CTL_ATTR(EQUALIZER, 2), +	HPI_EQUALIZER_COEFFICIENTS = HPI_CTL_ATTR(EQUALIZER, 3), + +	HPI_COMPANDER_PARAMS = HPI_CTL_ATTR(COMPANDER, 1), +	HPI_COMPANDER_MAKEUPGAIN = HPI_CTL_ATTR(COMPANDER, 2), +	HPI_COMPANDER_THRESHOLD = HPI_CTL_ATTR(COMPANDER, 3), +	HPI_COMPANDER_RATIO = HPI_CTL_ATTR(COMPANDER, 4), +	HPI_COMPANDER_ATTACK = HPI_CTL_ATTR(COMPANDER, 5), +	HPI_COMPANDER_DECAY = HPI_CTL_ATTR(COMPANDER, 6), + +	HPI_COBRANET_SET = HPI_CTL_ATTR(COBRANET, 1), +	HPI_COBRANET_GET = HPI_CTL_ATTR(COBRANET, 2), +	HPI_COBRANET_GET_STATUS = HPI_CTL_ATTR(COBRANET, 5), +	HPI_COBRANET_SEND_PACKET = HPI_CTL_ATTR(COBRANET, 6), +	HPI_COBRANET_GET_PACKET = HPI_CTL_ATTR(COBRANET, 7), + +	HPI_TONEDETECTOR_THRESHOLD = HPI_CTL_ATTR(TONEDETECTOR, 1), +	HPI_TONEDETECTOR_STATE = HPI_CTL_ATTR(TONEDETECTOR, 2), +	HPI_TONEDETECTOR_FREQUENCY = HPI_CTL_ATTR(TONEDETECTOR, 3), + +	HPI_SILENCEDETECTOR_THRESHOLD = HPI_CTL_ATTR(SILENCEDETECTOR, 1), +	HPI_SILENCEDETECTOR_STATE = HPI_CTL_ATTR(SILENCEDETECTOR, 2), +	HPI_SILENCEDETECTOR_DELAY = HPI_CTL_ATTR(SILENCEDETECTOR, 3), + +	HPI_PAD_CHANNEL_NAME = HPI_CTL_ATTR(PAD, 1), +	HPI_PAD_ARTIST = HPI_CTL_ATTR(PAD, 2), +	HPI_PAD_TITLE = HPI_CTL_ATTR(PAD, 3), +	HPI_PAD_COMMENT = HPI_CTL_ATTR(PAD, 4), +	HPI_PAD_PROGRAM_TYPE = HPI_CTL_ATTR(PAD, 5), +	HPI_PAD_PROGRAM_ID = HPI_CTL_ATTR(PAD, 6), +	HPI_PAD_TA_SUPPORT = HPI_CTL_ATTR(PAD, 7), +	HPI_PAD_TA_ACTIVE = HPI_CTL_ATTR(PAD, 8), + +	HPI_UNIVERSAL_ENTITY = HPI_CTL_ATTR(UNIVERSAL, 1) +};  #define HPI_POLARITY_POSITIVE           0  #define HPI_POLARITY_NEGATIVE           1 -/* Bitstream control get attributes */ -#define HPI_BITSTREAM_ACTIVITY          1 - -/* SampleClock control attributes */ -#define HPI_SAMPLECLOCK_SOURCE                  HPI_CTL_ATTR(SAMPLECLOCK, 1) -#define HPI_SAMPLECLOCK_SAMPLERATE              HPI_CTL_ATTR(SAMPLECLOCK, 2) -#define HPI_SAMPLECLOCK_SOURCE_INDEX            HPI_CTL_ATTR(SAMPLECLOCK, 3) -#define HPI_SAMPLECLOCK_LOCAL_SAMPLERATE\ -	HPI_CTL_ATTR(SAMPLECLOCK, 4) -#define HPI_SAMPLECLOCK_AUTO                    HPI_CTL_ATTR(SAMPLECLOCK, 5) -#define HPI_SAMPLECLOCK_LOCAL_LOCK                      HPI_CTL_ATTR(SAMPLECLOCK, 6) - -/* Microphone control attributes */ -#define HPI_MICROPHONE_PHANTOM_POWER HPI_CTL_ATTR(MICROPHONE, 1) - -/** Equalizer control attributes */ -/** Used to get number of filters in an EQ. (Can't set) */ -#define HPI_EQUALIZER_NUM_FILTERS HPI_CTL_ATTR(EQUALIZER, 1) -/** Set/get the filter by type, freq, Q, gain */ -#define HPI_EQUALIZER_FILTER HPI_CTL_ATTR(EQUALIZER, 2) -/** Get the biquad coefficients */ -#define HPI_EQUALIZER_COEFFICIENTS HPI_CTL_ATTR(EQUALIZER, 3) - -/* Note compander also uses HPI_GENERIC_ENABLE */ -#define HPI_COMPANDER_PARAMS     HPI_CTL_ATTR(COMPANDER, 1) -#define HPI_COMPANDER_MAKEUPGAIN HPI_CTL_ATTR(COMPANDER, 2) -#define HPI_COMPANDER_THRESHOLD  HPI_CTL_ATTR(COMPANDER, 3) -#define HPI_COMPANDER_RATIO      HPI_CTL_ATTR(COMPANDER, 4) -#define HPI_COMPANDER_ATTACK     HPI_CTL_ATTR(COMPANDER, 5) -#define HPI_COMPANDER_DECAY      HPI_CTL_ATTR(COMPANDER, 6) - -/* Cobranet control attributes. */ -#define HPI_COBRANET_SET         HPI_CTL_ATTR(COBRANET, 1) -#define HPI_COBRANET_GET         HPI_CTL_ATTR(COBRANET, 2) -#define HPI_COBRANET_SET_DATA    HPI_CTL_ATTR(COBRANET, 3) -#define HPI_COBRANET_GET_DATA    HPI_CTL_ATTR(COBRANET, 4) -#define HPI_COBRANET_GET_STATUS  HPI_CTL_ATTR(COBRANET, 5) -#define HPI_COBRANET_SEND_PACKET HPI_CTL_ATTR(COBRANET, 6) -#define HPI_COBRANET_GET_PACKET  HPI_CTL_ATTR(COBRANET, 7) -  /*------------------------------------------------------------   Cobranet Chip Bridge - copied from HMI.H  ------------------------------------------------------------*/ @@ -380,7 +289,7 @@ Used for HPI_ChannelModeSet/Get()  /* These defines are used to fill in protocol information for an Ethernet packet      sent using HMI on CS18102 */ -/** ID supplied by Cirrius for ASI packets. */ +/** ID supplied by Cirrus for ASI packets. */  #define HPI_ETHERNET_PACKET_ID                  0x85  /** Simple packet - no special routing required */  #define HPI_ETHERNET_PACKET_V1                  0x01 @@ -393,71 +302,24 @@ Used for HPI_ChannelModeSet/Get()  /** This packet must make its way to the host across the HPI interface */  #define HPI_ETHERNET_PACKET_HOSTED_VIA_HPI_V1   0x41 -#define HPI_ETHERNET_UDP_PORT (44600)	/*!< UDP messaging port */ - -/** Base network time out is set to 100 milli-seconds. */ -#define HPI_ETHERNET_TIMEOUT_MS      (100) - -/** \defgroup tonedet_attr Tonedetector attributes -\{ -Used by HPI_ToneDetector_Set() and HPI_ToneDetector_Get() -*/ - -/** Set the threshold level of a tonedetector, -Threshold is a -ve number in units of dB/100, -*/ -#define HPI_TONEDETECTOR_THRESHOLD HPI_CTL_ATTR(TONEDETECTOR, 1) - -/** Get the current state of tonedetection -The result is a bitmap of detected tones.  pairs of bits represent the left -and right channels, with left channel in LSB. -The lowest frequency detector state is in the LSB -*/ -#define HPI_TONEDETECTOR_STATE HPI_CTL_ATTR(TONEDETECTOR, 2) - -/** Get the frequency of a tonedetector band. -*/ -#define HPI_TONEDETECTOR_FREQUENCY HPI_CTL_ATTR(TONEDETECTOR, 3) - -/**\}*/ +#define HPI_ETHERNET_UDP_PORT 44600 /**< HPI UDP service */ -/** \defgroup silencedet_attr SilenceDetector attributes -\{ -*/ +/** Default network timeout in milli-seconds. */ +#define HPI_ETHERNET_TIMEOUT_MS 500 -/** Get the current state of tonedetection -The result is a bitmap with 1s for silent channels. Left channel is in LSB -*/ -#define HPI_SILENCEDETECTOR_STATE \ -  HPI_CTL_ATTR(SILENCEDETECTOR, 2) - -/** Set the threshold level of a SilenceDetector, -Threshold is a -ve number in units of dB/100, -*/ -#define HPI_SILENCEDETECTOR_THRESHOLD \ -  HPI_CTL_ATTR(SILENCEDETECTOR, 1) - -/** get/set the silence time before the detector triggers -*/ -#define HPI_SILENCEDETECTOR_DELAY \ -       HPI_CTL_ATTR(SILENCEDETECTOR, 3) - -/**\}*/ - -/* Locked memory buffer alloc/free phases */ -/** use one message to allocate or free physical memory */ -#define HPI_BUFFER_CMD_EXTERNAL                 0 -/** alloc physical memory */ -#define HPI_BUFFER_CMD_INTERNAL_ALLOC           1 -/** send physical memory address to adapter */ -#define HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER    2 -/** notify adapter to stop using physical buffer */ -#define HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER   3 -/** free physical buffer */ -#define HPI_BUFFER_CMD_INTERNAL_FREE            4 - -/******************************************* CONTROLX ATTRIBUTES ****/ -/* NOTE: All controlx attributes must be unique, unlike control attributes */ +/** Locked memory buffer alloc/free phases */ +enum HPI_BUFFER_CMDS { +	/** use one message to allocate or free physical memory */ +	HPI_BUFFER_CMD_EXTERNAL = 0, +	/** alloc physical memory */ +	HPI_BUFFER_CMD_INTERNAL_ALLOC = 1, +	/** send physical memory address to adapter */ +	HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER = 2, +	/** notify adapter to stop using physical buffer */ +	HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER = 3, +	/** free physical buffer */ +	HPI_BUFFER_CMD_INTERNAL_FREE = 4 +};  /*****************************************************************************/  /*****************************************************************************/ @@ -482,6 +344,12 @@ Threshold is a -ve number in units of dB/100,  #define HPI_USB_W2K_TAG                 0x57495341	/* "ASIW"       */  #define HPI_USB_LINUX_TAG               0x4C495341	/* "ASIL"       */ +/** Invalid Adapter index +Used in HPI messages that are not addressed to a specific adapter +Used in DLL to indicate device not present +*/ +#define HPI_ADAPTER_INDEX_INVALID 0xFFFF +  /** First 2 hex digits define the adapter family */  #define HPI_ADAPTER_FAMILY_MASK         0xff00  #define HPI_MODULE_FAMILY_MASK          0xfff0 @@ -490,178 +358,189 @@ Threshold is a -ve number in units of dB/100,  #define HPI_MODULE_FAMILY_ASI(f)   (f & HPI_MODULE_FAMILY_MASK)  #define HPI_ADAPTER_ASI(f)   (f) -/******************************************* message types */ -#define HPI_TYPE_MESSAGE                        1 -#define HPI_TYPE_RESPONSE                       2 -#define HPI_TYPE_DATA                           3 -#define HPI_TYPE_SSX2BYPASS_MESSAGE             4 - -/******************************************* object types */ -#define HPI_OBJ_SUBSYSTEM                       1 -#define HPI_OBJ_ADAPTER                         2 -#define HPI_OBJ_OSTREAM                         3 -#define HPI_OBJ_ISTREAM                         4 -#define HPI_OBJ_MIXER                           5 -#define HPI_OBJ_NODE                            6 -#define HPI_OBJ_CONTROL                         7 -#define HPI_OBJ_NVMEMORY                        8 -#define HPI_OBJ_GPIO                            9 -#define HPI_OBJ_WATCHDOG                        10 -#define HPI_OBJ_CLOCK                           11 -#define HPI_OBJ_PROFILE                         12 -#define HPI_OBJ_CONTROLEX                       13 -#define HPI_OBJ_ASYNCEVENT                      14 - -#define HPI_OBJ_MAXINDEX                        14 - -/******************************************* methods/functions */ - -#define HPI_OBJ_FUNCTION_SPACING        0x100 -#define HPI_MAKE_INDEX(obj, index) (obj * HPI_OBJ_FUNCTION_SPACING + index) +enum HPI_MESSAGE_TYPES { +	HPI_TYPE_REQUEST = 1, +	HPI_TYPE_RESPONSE = 2, +	HPI_TYPE_DATA = 3, +	HPI_TYPE_SSX2BYPASS_MESSAGE = 4, +	HPI_TYPE_COMMAND = 5, +	HPI_TYPE_NOTIFICATION = 6 +}; + +enum HPI_OBJECT_TYPES { +	HPI_OBJ_SUBSYSTEM = 1, +	HPI_OBJ_ADAPTER = 2, +	HPI_OBJ_OSTREAM = 3, +	HPI_OBJ_ISTREAM = 4, +	HPI_OBJ_MIXER = 5, +	HPI_OBJ_NODE = 6, +	HPI_OBJ_CONTROL = 7, +	HPI_OBJ_NVMEMORY = 8, +	HPI_OBJ_GPIO = 9, +	HPI_OBJ_WATCHDOG = 10, +	HPI_OBJ_CLOCK = 11, +	HPI_OBJ_PROFILE = 12, +	/* HPI_ OBJ_ CONTROLEX  = 13, */ +	HPI_OBJ_ASYNCEVENT = 14 +#define HPI_OBJ_MAXINDEX 14 +}; + +#define HPI_OBJ_FUNCTION_SPACING 0x100 +#define HPI_FUNC_ID(obj, i) (HPI_OBJ_##obj * HPI_OBJ_FUNCTION_SPACING + i) +  #define HPI_EXTRACT_INDEX(fn) (fn & 0xff) -/* SUB-SYSTEM */ -#define HPI_SUBSYS_OPEN                 HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 1) -#define HPI_SUBSYS_GET_VERSION          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 2) -#define HPI_SUBSYS_GET_INFO             HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 3) -#define HPI_SUBSYS_FIND_ADAPTERS        HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 4) -#define HPI_SUBSYS_CREATE_ADAPTER       HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 5) -#define HPI_SUBSYS_CLOSE                HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 6) -#define HPI_SUBSYS_DELETE_ADAPTER       HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 7) -#define HPI_SUBSYS_DRIVER_LOAD          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 8) -#define HPI_SUBSYS_DRIVER_UNLOAD        HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 9) -#define HPI_SUBSYS_READ_PORT_8          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 10) -#define HPI_SUBSYS_WRITE_PORT_8         HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 11) -#define HPI_SUBSYS_GET_NUM_ADAPTERS     HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 12) -#define HPI_SUBSYS_GET_ADAPTER          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 13) -#define HPI_SUBSYS_SET_NETWORK_INTERFACE HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 14) -#define HPI_SUBSYS_FUNCTION_COUNT 14 -/* ADAPTER */ -#define HPI_ADAPTER_OPEN                HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 1) -#define HPI_ADAPTER_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 2) -#define HPI_ADAPTER_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 3) -#define HPI_ADAPTER_GET_ASSERT          HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 4) -#define HPI_ADAPTER_TEST_ASSERT         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 5) -#define HPI_ADAPTER_SET_MODE            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 6) -#define HPI_ADAPTER_GET_MODE            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 7) -#define HPI_ADAPTER_ENABLE_CAPABILITY   HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 8) -#define HPI_ADAPTER_SELFTEST            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 9) -#define HPI_ADAPTER_FIND_OBJECT         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 10) -#define HPI_ADAPTER_QUERY_FLASH         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 11) -#define HPI_ADAPTER_START_FLASH         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 12) -#define HPI_ADAPTER_PROGRAM_FLASH       HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 13) -#define HPI_ADAPTER_SET_PROPERTY        HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 14) -#define HPI_ADAPTER_GET_PROPERTY        HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 15) -#define HPI_ADAPTER_ENUM_PROPERTY       HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 16) -#define HPI_ADAPTER_MODULE_INFO         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 17) -#define HPI_ADAPTER_DEBUG_READ          HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 18) -#define HPI_ADAPTER_FUNCTION_COUNT 18 -/* OUTPUT STREAM */ -#define HPI_OSTREAM_OPEN                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 1) -#define HPI_OSTREAM_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 2) -#define HPI_OSTREAM_WRITE               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 3) -#define HPI_OSTREAM_START               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 4) -#define HPI_OSTREAM_STOP                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 5) -#define HPI_OSTREAM_RESET               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 6) -#define HPI_OSTREAM_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 7) -#define HPI_OSTREAM_QUERY_FORMAT        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 8) -#define HPI_OSTREAM_DATA                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 9) -#define HPI_OSTREAM_SET_VELOCITY        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 10) -#define HPI_OSTREAM_SET_PUNCHINOUT      HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 11) -#define HPI_OSTREAM_SINEGEN             HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 12) -#define HPI_OSTREAM_ANC_RESET           HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 13) -#define HPI_OSTREAM_ANC_GET_INFO        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 14) -#define HPI_OSTREAM_ANC_READ            HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 15) -#define HPI_OSTREAM_SET_TIMESCALE       HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 16) -#define HPI_OSTREAM_SET_FORMAT          HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 17) -#define HPI_OSTREAM_HOSTBUFFER_ALLOC    HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 18) -#define HPI_OSTREAM_HOSTBUFFER_FREE     HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 19) -#define HPI_OSTREAM_GROUP_ADD           HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 20) -#define HPI_OSTREAM_GROUP_GETMAP        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 21) -#define HPI_OSTREAM_GROUP_RESET         HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 22) -#define HPI_OSTREAM_HOSTBUFFER_GET_INFO HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 23) -#define HPI_OSTREAM_WAIT_START          HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 24) -#define HPI_OSTREAM_FUNCTION_COUNT              24 -/* INPUT STREAM */ -#define HPI_ISTREAM_OPEN                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 1) -#define HPI_ISTREAM_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 2) -#define HPI_ISTREAM_SET_FORMAT          HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 3) -#define HPI_ISTREAM_READ                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 4) -#define HPI_ISTREAM_START               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 5) -#define HPI_ISTREAM_STOP                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 6) -#define HPI_ISTREAM_RESET               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 7) -#define HPI_ISTREAM_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 8) -#define HPI_ISTREAM_QUERY_FORMAT        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 9) -#define HPI_ISTREAM_ANC_RESET           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 10) -#define HPI_ISTREAM_ANC_GET_INFO        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 11) -#define HPI_ISTREAM_ANC_WRITE           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 12) -#define HPI_ISTREAM_HOSTBUFFER_ALLOC    HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 13) -#define HPI_ISTREAM_HOSTBUFFER_FREE     HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 14) -#define HPI_ISTREAM_GROUP_ADD           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 15) -#define HPI_ISTREAM_GROUP_GETMAP        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 16) -#define HPI_ISTREAM_GROUP_RESET         HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 17) -#define HPI_ISTREAM_HOSTBUFFER_GET_INFO HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 18) -#define HPI_ISTREAM_WAIT_START          HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 19) -#define HPI_ISTREAM_FUNCTION_COUNT              19 -/* MIXER */ +enum HPI_FUNCTION_IDS { +	HPI_SUBSYS_OPEN = HPI_FUNC_ID(SUBSYSTEM, 1), +	HPI_SUBSYS_GET_VERSION = HPI_FUNC_ID(SUBSYSTEM, 2), +	HPI_SUBSYS_GET_INFO = HPI_FUNC_ID(SUBSYSTEM, 3), +	HPI_SUBSYS_CREATE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 5), +	HPI_SUBSYS_CLOSE = HPI_FUNC_ID(SUBSYSTEM, 6), +	HPI_SUBSYS_DRIVER_LOAD = HPI_FUNC_ID(SUBSYSTEM, 8), +	HPI_SUBSYS_DRIVER_UNLOAD = HPI_FUNC_ID(SUBSYSTEM, 9), +	HPI_SUBSYS_GET_NUM_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 12), +	HPI_SUBSYS_GET_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 13), +	HPI_SUBSYS_SET_NETWORK_INTERFACE = HPI_FUNC_ID(SUBSYSTEM, 14), +	HPI_SUBSYS_OPTION_INFO = HPI_FUNC_ID(SUBSYSTEM, 15), +	HPI_SUBSYS_OPTION_GET = HPI_FUNC_ID(SUBSYSTEM, 16), +	HPI_SUBSYS_OPTION_SET = HPI_FUNC_ID(SUBSYSTEM, 17), +#define HPI_SUBSYS_FUNCTION_COUNT 17 + +	HPI_ADAPTER_OPEN = HPI_FUNC_ID(ADAPTER, 1), +	HPI_ADAPTER_CLOSE = HPI_FUNC_ID(ADAPTER, 2), +	HPI_ADAPTER_GET_INFO = HPI_FUNC_ID(ADAPTER, 3), +	HPI_ADAPTER_GET_ASSERT = HPI_FUNC_ID(ADAPTER, 4), +	HPI_ADAPTER_TEST_ASSERT = HPI_FUNC_ID(ADAPTER, 5), +	HPI_ADAPTER_SET_MODE = HPI_FUNC_ID(ADAPTER, 6), +	HPI_ADAPTER_GET_MODE = HPI_FUNC_ID(ADAPTER, 7), +	HPI_ADAPTER_ENABLE_CAPABILITY = HPI_FUNC_ID(ADAPTER, 8), +	HPI_ADAPTER_SELFTEST = HPI_FUNC_ID(ADAPTER, 9), +	HPI_ADAPTER_FIND_OBJECT = HPI_FUNC_ID(ADAPTER, 10), +	HPI_ADAPTER_QUERY_FLASH = HPI_FUNC_ID(ADAPTER, 11), +	HPI_ADAPTER_START_FLASH = HPI_FUNC_ID(ADAPTER, 12), +	HPI_ADAPTER_PROGRAM_FLASH = HPI_FUNC_ID(ADAPTER, 13), +	HPI_ADAPTER_SET_PROPERTY = HPI_FUNC_ID(ADAPTER, 14), +	HPI_ADAPTER_GET_PROPERTY = HPI_FUNC_ID(ADAPTER, 15), +	HPI_ADAPTER_ENUM_PROPERTY = HPI_FUNC_ID(ADAPTER, 16), +	HPI_ADAPTER_MODULE_INFO = HPI_FUNC_ID(ADAPTER, 17), +	HPI_ADAPTER_DEBUG_READ = HPI_FUNC_ID(ADAPTER, 18), +	HPI_ADAPTER_IRQ_QUERY_AND_CLEAR = HPI_FUNC_ID(ADAPTER, 19), +	HPI_ADAPTER_IRQ_CALLBACK = HPI_FUNC_ID(ADAPTER, 20), +	HPI_ADAPTER_DELETE = HPI_FUNC_ID(ADAPTER, 21), +	HPI_ADAPTER_READ_FLASH = HPI_FUNC_ID(ADAPTER, 22), +	HPI_ADAPTER_END_FLASH = HPI_FUNC_ID(ADAPTER, 23), +	HPI_ADAPTER_FILESTORE_DELETE_ALL = HPI_FUNC_ID(ADAPTER, 24), +#define HPI_ADAPTER_FUNCTION_COUNT 24 + +	HPI_OSTREAM_OPEN = HPI_FUNC_ID(OSTREAM, 1), +	HPI_OSTREAM_CLOSE = HPI_FUNC_ID(OSTREAM, 2), +	HPI_OSTREAM_WRITE = HPI_FUNC_ID(OSTREAM, 3), +	HPI_OSTREAM_START = HPI_FUNC_ID(OSTREAM, 4), +	HPI_OSTREAM_STOP = HPI_FUNC_ID(OSTREAM, 5), +	HPI_OSTREAM_RESET = HPI_FUNC_ID(OSTREAM, 6), +	HPI_OSTREAM_GET_INFO = HPI_FUNC_ID(OSTREAM, 7), +	HPI_OSTREAM_QUERY_FORMAT = HPI_FUNC_ID(OSTREAM, 8), +	HPI_OSTREAM_DATA = HPI_FUNC_ID(OSTREAM, 9), +	HPI_OSTREAM_SET_VELOCITY = HPI_FUNC_ID(OSTREAM, 10), +	HPI_OSTREAM_SET_PUNCHINOUT = HPI_FUNC_ID(OSTREAM, 11), +	HPI_OSTREAM_SINEGEN = HPI_FUNC_ID(OSTREAM, 12), +	HPI_OSTREAM_ANC_RESET = HPI_FUNC_ID(OSTREAM, 13), +	HPI_OSTREAM_ANC_GET_INFO = HPI_FUNC_ID(OSTREAM, 14), +	HPI_OSTREAM_ANC_READ = HPI_FUNC_ID(OSTREAM, 15), +	HPI_OSTREAM_SET_TIMESCALE = HPI_FUNC_ID(OSTREAM, 16), +	HPI_OSTREAM_SET_FORMAT = HPI_FUNC_ID(OSTREAM, 17), +	HPI_OSTREAM_HOSTBUFFER_ALLOC = HPI_FUNC_ID(OSTREAM, 18), +	HPI_OSTREAM_HOSTBUFFER_FREE = HPI_FUNC_ID(OSTREAM, 19), +	HPI_OSTREAM_GROUP_ADD = HPI_FUNC_ID(OSTREAM, 20), +	HPI_OSTREAM_GROUP_GETMAP = HPI_FUNC_ID(OSTREAM, 21), +	HPI_OSTREAM_GROUP_RESET = HPI_FUNC_ID(OSTREAM, 22), +	HPI_OSTREAM_HOSTBUFFER_GET_INFO = HPI_FUNC_ID(OSTREAM, 23), +	HPI_OSTREAM_WAIT_START = HPI_FUNC_ID(OSTREAM, 24), +	HPI_OSTREAM_WAIT = HPI_FUNC_ID(OSTREAM, 25), +#define HPI_OSTREAM_FUNCTION_COUNT 25 + +	HPI_ISTREAM_OPEN = HPI_FUNC_ID(ISTREAM, 1), +	HPI_ISTREAM_CLOSE = HPI_FUNC_ID(ISTREAM, 2), +	HPI_ISTREAM_SET_FORMAT = HPI_FUNC_ID(ISTREAM, 3), +	HPI_ISTREAM_READ = HPI_FUNC_ID(ISTREAM, 4), +	HPI_ISTREAM_START = HPI_FUNC_ID(ISTREAM, 5), +	HPI_ISTREAM_STOP = HPI_FUNC_ID(ISTREAM, 6), +	HPI_ISTREAM_RESET = HPI_FUNC_ID(ISTREAM, 7), +	HPI_ISTREAM_GET_INFO = HPI_FUNC_ID(ISTREAM, 8), +	HPI_ISTREAM_QUERY_FORMAT = HPI_FUNC_ID(ISTREAM, 9), +	HPI_ISTREAM_ANC_RESET = HPI_FUNC_ID(ISTREAM, 10), +	HPI_ISTREAM_ANC_GET_INFO = HPI_FUNC_ID(ISTREAM, 11), +	HPI_ISTREAM_ANC_WRITE = HPI_FUNC_ID(ISTREAM, 12), +	HPI_ISTREAM_HOSTBUFFER_ALLOC = HPI_FUNC_ID(ISTREAM, 13), +	HPI_ISTREAM_HOSTBUFFER_FREE = HPI_FUNC_ID(ISTREAM, 14), +	HPI_ISTREAM_GROUP_ADD = HPI_FUNC_ID(ISTREAM, 15), +	HPI_ISTREAM_GROUP_GETMAP = HPI_FUNC_ID(ISTREAM, 16), +	HPI_ISTREAM_GROUP_RESET = HPI_FUNC_ID(ISTREAM, 17), +	HPI_ISTREAM_HOSTBUFFER_GET_INFO = HPI_FUNC_ID(ISTREAM, 18), +	HPI_ISTREAM_WAIT_START = HPI_FUNC_ID(ISTREAM, 19), +	HPI_ISTREAM_WAIT = HPI_FUNC_ID(ISTREAM, 20), +#define HPI_ISTREAM_FUNCTION_COUNT 20 +  /* NOTE:     GET_NODE_INFO, SET_CONNECTION, GET_CONNECTIONS are not currently used */ -#define HPI_MIXER_OPEN                  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 1) -#define HPI_MIXER_CLOSE                 HPI_MAKE_INDEX(HPI_OBJ_MIXER, 2) -#define HPI_MIXER_GET_INFO              HPI_MAKE_INDEX(HPI_OBJ_MIXER, 3) -#define HPI_MIXER_GET_NODE_INFO         HPI_MAKE_INDEX(HPI_OBJ_MIXER, 4) -#define HPI_MIXER_GET_CONTROL           HPI_MAKE_INDEX(HPI_OBJ_MIXER, 5) -#define HPI_MIXER_SET_CONNECTION        HPI_MAKE_INDEX(HPI_OBJ_MIXER, 6) -#define HPI_MIXER_GET_CONNECTIONS       HPI_MAKE_INDEX(HPI_OBJ_MIXER, 7) -#define HPI_MIXER_GET_CONTROL_BY_INDEX  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 8) -#define HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 9) -#define HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES HPI_MAKE_INDEX(HPI_OBJ_MIXER, 10) -#define HPI_MIXER_STORE                 HPI_MAKE_INDEX(HPI_OBJ_MIXER, 11) -#define HPI_MIXER_FUNCTION_COUNT        11 -/* MIXER CONTROLS */ -#define HPI_CONTROL_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 1) -#define HPI_CONTROL_GET_STATE           HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 2) -#define HPI_CONTROL_SET_STATE           HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 3) +	HPI_MIXER_OPEN = HPI_FUNC_ID(MIXER, 1), +	HPI_MIXER_CLOSE = HPI_FUNC_ID(MIXER, 2), +	HPI_MIXER_GET_INFO = HPI_FUNC_ID(MIXER, 3), +	HPI_MIXER_GET_NODE_INFO = HPI_FUNC_ID(MIXER, 4), +	HPI_MIXER_GET_CONTROL = HPI_FUNC_ID(MIXER, 5), +	HPI_MIXER_SET_CONNECTION = HPI_FUNC_ID(MIXER, 6), +	HPI_MIXER_GET_CONNECTIONS = HPI_FUNC_ID(MIXER, 7), +	HPI_MIXER_GET_CONTROL_BY_INDEX = HPI_FUNC_ID(MIXER, 8), +	HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX = HPI_FUNC_ID(MIXER, 9), +	HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES = HPI_FUNC_ID(MIXER, 10), +	HPI_MIXER_STORE = HPI_FUNC_ID(MIXER, 11), +	HPI_MIXER_GET_CACHE_INFO = HPI_FUNC_ID(MIXER, 12), +	HPI_MIXER_GET_BLOCK_HANDLE = HPI_FUNC_ID(MIXER, 13), +	HPI_MIXER_GET_PARAMETER_HANDLE = HPI_FUNC_ID(MIXER, 14), +#define HPI_MIXER_FUNCTION_COUNT 14 + +	HPI_CONTROL_GET_INFO = HPI_FUNC_ID(CONTROL, 1), +	HPI_CONTROL_GET_STATE = HPI_FUNC_ID(CONTROL, 2), +	HPI_CONTROL_SET_STATE = HPI_FUNC_ID(CONTROL, 3),  #define HPI_CONTROL_FUNCTION_COUNT 3 -/* NONVOL MEMORY */ -#define HPI_NVMEMORY_OPEN               HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 1) -#define HPI_NVMEMORY_READ_BYTE          HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 2) -#define HPI_NVMEMORY_WRITE_BYTE         HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 3) + +	HPI_NVMEMORY_OPEN = HPI_FUNC_ID(NVMEMORY, 1), +	HPI_NVMEMORY_READ_BYTE = HPI_FUNC_ID(NVMEMORY, 2), +	HPI_NVMEMORY_WRITE_BYTE = HPI_FUNC_ID(NVMEMORY, 3),  #define HPI_NVMEMORY_FUNCTION_COUNT 3 -/* GPIO */ -#define HPI_GPIO_OPEN                   HPI_MAKE_INDEX(HPI_OBJ_GPIO, 1) -#define HPI_GPIO_READ_BIT               HPI_MAKE_INDEX(HPI_OBJ_GPIO, 2) -#define HPI_GPIO_WRITE_BIT              HPI_MAKE_INDEX(HPI_OBJ_GPIO, 3) -#define HPI_GPIO_READ_ALL               HPI_MAKE_INDEX(HPI_OBJ_GPIO, 4) -#define HPI_GPIO_WRITE_STATUS           HPI_MAKE_INDEX(HPI_OBJ_GPIO, 5) + +	HPI_GPIO_OPEN = HPI_FUNC_ID(GPIO, 1), +	HPI_GPIO_READ_BIT = HPI_FUNC_ID(GPIO, 2), +	HPI_GPIO_WRITE_BIT = HPI_FUNC_ID(GPIO, 3), +	HPI_GPIO_READ_ALL = HPI_FUNC_ID(GPIO, 4), +	HPI_GPIO_WRITE_STATUS = HPI_FUNC_ID(GPIO, 5),  #define HPI_GPIO_FUNCTION_COUNT 5 -/* ASYNC EVENT */ -#define HPI_ASYNCEVENT_OPEN             HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 1) -#define HPI_ASYNCEVENT_CLOSE            HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 2) -#define HPI_ASYNCEVENT_WAIT             HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 3) -#define HPI_ASYNCEVENT_GETCOUNT         HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 4) -#define HPI_ASYNCEVENT_GET              HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 5) -#define HPI_ASYNCEVENT_SENDEVENTS       HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 6) + +	HPI_ASYNCEVENT_OPEN = HPI_FUNC_ID(ASYNCEVENT, 1), +	HPI_ASYNCEVENT_CLOSE = HPI_FUNC_ID(ASYNCEVENT, 2), +	HPI_ASYNCEVENT_WAIT = HPI_FUNC_ID(ASYNCEVENT, 3), +	HPI_ASYNCEVENT_GETCOUNT = HPI_FUNC_ID(ASYNCEVENT, 4), +	HPI_ASYNCEVENT_GET = HPI_FUNC_ID(ASYNCEVENT, 5), +	HPI_ASYNCEVENT_SENDEVENTS = HPI_FUNC_ID(ASYNCEVENT, 6),  #define HPI_ASYNCEVENT_FUNCTION_COUNT 6 -/* WATCH-DOG */ -#define HPI_WATCHDOG_OPEN               HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 1) -#define HPI_WATCHDOG_SET_TIME           HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 2) -#define HPI_WATCHDOG_PING               HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 3) -/* CLOCK */ -#define HPI_CLOCK_OPEN                  HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 1) -#define HPI_CLOCK_SET_TIME              HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 2) -#define HPI_CLOCK_GET_TIME              HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 3) -/* PROFILE */ -#define HPI_PROFILE_OPEN_ALL            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 1) -#define HPI_PROFILE_START_ALL           HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 2) -#define HPI_PROFILE_STOP_ALL            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 3) -#define HPI_PROFILE_GET                 HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 4) -#define HPI_PROFILE_GET_IDLECOUNT       HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 5) -#define HPI_PROFILE_GET_NAME            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 6) -#define HPI_PROFILE_GET_UTILIZATION     HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 7) + +	HPI_WATCHDOG_OPEN = HPI_FUNC_ID(WATCHDOG, 1), +	HPI_WATCHDOG_SET_TIME = HPI_FUNC_ID(WATCHDOG, 2), +	HPI_WATCHDOG_PING = HPI_FUNC_ID(WATCHDOG, 3), + +	HPI_CLOCK_OPEN = HPI_FUNC_ID(CLOCK, 1), +	HPI_CLOCK_SET_TIME = HPI_FUNC_ID(CLOCK, 2), +	HPI_CLOCK_GET_TIME = HPI_FUNC_ID(CLOCK, 3), + +	HPI_PROFILE_OPEN_ALL = HPI_FUNC_ID(PROFILE, 1), +	HPI_PROFILE_START_ALL = HPI_FUNC_ID(PROFILE, 2), +	HPI_PROFILE_STOP_ALL = HPI_FUNC_ID(PROFILE, 3), +	HPI_PROFILE_GET = HPI_FUNC_ID(PROFILE, 4), +	HPI_PROFILE_GET_IDLECOUNT = HPI_FUNC_ID(PROFILE, 5), +	HPI_PROFILE_GET_NAME = HPI_FUNC_ID(PROFILE, 6), +	HPI_PROFILE_GET_UTILIZATION = HPI_FUNC_ID(PROFILE, 7)  #define HPI_PROFILE_FUNCTION_COUNT 7 -/* ////////////////////////////////////////////////////////////////////// */ -/* PRIVATE ATTRIBUTES */ +};  /* ////////////////////////////////////////////////////////////////////// */  /* STRUCTURES */ @@ -672,18 +551,7 @@ Threshold is a -ve number in units of dB/100,  /** PCI bus resource */  struct hpi_pci {  	u32 __iomem *ap_mem_base[HPI_MAX_ADAPTER_MEM_SPACES]; -	struct pci_dev *p_os_data; - -#ifndef HPI64BIT		/* keep structure size constant */ -	u32 padding[HPI_MAX_ADAPTER_MEM_SPACES + 1]; -#endif -	u16 vendor_id; -	u16 device_id; -	u16 subsys_vendor_id; -	u16 subsys_device_id; -	u16 bus_number; -	u16 device_number; -	u32 interrupt; +	struct pci_dev *pci_dev;  };  struct hpi_resource { @@ -702,12 +570,10 @@ struct hpi_resource {  /** Format info used inside struct hpi_message      Not the same as public API struct hpi_format */  struct hpi_msg_format { -	u32 sample_rate; -				/**< 11025, 32000, 44100 ... */ -	u32 bit_rate;	      /**< for MPEG */ -	u32 attributes; -				/**< Stereo/JointStereo/Mono */ -	u16 channels;	      /**< 1,2..., (or ancillary mode or idle bit */ +	u32 sample_rate; /**< 11025, 32000, 44100 etc. */ +	u32 bit_rate; /**< for MPEG */ +	u32 attributes;	/**< stereo/joint_stereo/mono */ +	u16 channels; /**< 1,2..., (or ancillary mode or idle bit */  	u16 format; /**< HPI_FORMAT_PCM16, _MPEG etc. see \ref HPI_FORMATS. */  }; @@ -740,9 +606,9 @@ struct hpi_data_compat32 {  #endif  struct hpi_buffer { -  /** placehoder for backward compatability (see dwBufferSize) */ +  /** placeholder for backward compatibility (see dwBufferSize) */  	struct hpi_msg_format reserved; -	u32 command;	/**< HPI_BUFFER_CMD_xxx*/ +	u32 command; /**< HPI_BUFFER_CMD_xxx*/  	u32 pci_address; /**< PCI physical address of buffer for DSP DMA */  	u32 buffer_size; /**< must line up with data_size of HPI_DATA*/  }; @@ -754,7 +620,7 @@ struct hpi_hostbuffer_status {  	u32 auxiliary_data_available;  	u32 stream_state;  	/* DSP index in to the host bus master buffer. */ -	u32 dSP_index; +	u32 dsp_index;  	/* Host index in to the host bus master buffer. */  	u32 host_index;  	u32 size_in_bytes; @@ -777,60 +643,54 @@ struct hpi_subsys_msg {  struct hpi_subsys_res {  	u32 version; -	u32 data;		/* used to return extended version */ -	u16 num_adapters;	/* number of adapters */ +	u32 data;		/* extended version */ +	u16 num_adapters;  	u16 adapter_index; -	u16 aw_adapter_list[HPI_MAX_ADAPTERS]; -}; - -struct hpi_adapter_msg { -	u32 adapter_mode;	/* adapter mode */ -	u16 assert_id;		/* assert number for "test assert" call -				   object_index for find object call -				   query_or_set for hpi_adapter_set_mode_ex() */ -	u16 object_type;	/* for adapter find object call */ +	u16 adapter_type; +	u16 pad16;  };  union hpi_adapterx_msg { -	struct hpi_adapter_msg adapter;  	struct { -		u32 offset; -	} query_flash; +		u32 dsp_address; +		u32 count_bytes; +	} debug_read;  	struct { -		u32 offset; -		u32 length; -		u32 key; -	} start_flash; +		u32 adapter_mode; +		u16 query_or_set; +	} mode;  	struct { -		u32 checksum; -		u16 sequence; -		u16 length; -		u16 offset; /**< offset from start of msg to data */ -		u16 unused; -	} program_flash; +		u16 index; +	} module_info; +	struct { +		u16 index; +		u16 what; +		u16 property_index; +	} property_enum;  	struct {  		u16 property;  		u16 parameter1;  		u16 parameter2;  	} property_set;  	struct { -		u16 index; -		u16 what; -		u16 property_index; -	} property_enum; +		u32 pad32; +		u16 key1; +		u16 key2; +	} restart;  	struct { -		u16 index; -	} module_info; +		u32 pad32; +		u16 value; +	} test_assert;  	struct { -		u32 dsp_address; -		u32 count_bytes; -	} debug_read; +		u32 yes; +	} irq_query; +	u32 pad[3];  };  struct hpi_adapter_res {  	u32 serial_number;  	u16 adapter_type; -	u16 adapter_index;	/* is this needed? also used for dsp_index */ +	u16 adapter_index;  	u16 num_instreams;  	u16 num_outstreams;  	u16 num_mixers; @@ -839,19 +699,25 @@ struct hpi_adapter_res {  };  union hpi_adapterx_res { -	struct hpi_adapter_res adapter; +	struct hpi_adapter_res info;  	struct { -		u32 checksum; -		u32 length; -		u32 version; -	} query_flash; +		u32 p1; +		u16 count; +		u16 dsp_index; +		u32 p2; +		u32 dsp_msg_addr; +		char sz_message[HPI_STRING_LEN]; +	} assert;  	struct { -		u16 sequence; -	} program_flash; +		u32 adapter_mode; +	} mode;  	struct {  		u16 parameter1;  		u16 parameter2;  	} property_get; +	struct { +		u32 yes; +	} irq_query;  };  struct hpi_stream_msg { @@ -863,6 +729,7 @@ struct hpi_stream_msg {  		u32 time_scale;  		struct hpi_buffer buffer;  		struct hpi_streamid stream; +		u32 threshold_bytes;  	} u;  }; @@ -911,7 +778,7 @@ struct hpi_stream_res {  struct hpi_mixer_msg {  	u16 control_index;  	u16 control_type;	/* = HPI_CONTROL_METER _VOLUME etc */ -	u16 padding1;		/* maintain alignment of subsequent fields */ +	u16 padding1;		/* Maintain alignment of subsequent fields */  	u16 node_type1;		/* = HPI_SOURCENODE_LINEIN etc */  	u16 node_index1;	/* = 0..N */  	u16 node_type2; @@ -949,6 +816,11 @@ union hpi_mixerx_res {  		u32 p_data;	/* pointer to data array */  		u16 more_to_do;	/* indicates if there is more to do */  	} gcabi; +	struct { +		u32 total_controls;	/* count of controls in the mixer */ +		u32 cache_controls;	/* count of controls in the cac */ +		u32 cache_bytes;	/* size of cache */ +	} cache_info;  };  struct hpi_control_msg { @@ -1000,107 +872,29 @@ union hpi_control_union_res {  		u32 band;  		u32 frequency;  		u32 gain; -		u32 level;  		u32 deemphasis;  		struct {  			u32 data[2];  			u32 bLER;  		} rds; +		short s_level; +		struct { +			u16 value; +			u16 mask; +		} status;  	} tuner;  	struct {  		char sz_data[8];  		u32 remaining_chars;  	} chars8;  	char c_data12[12]; -}; - -/* HPI_CONTROLX_STRUCTURES */ - -/* Message */ - -/** Used for all HMI variables where max length <= 8 bytes -*/ -struct hpi_controlx_msg_cobranet_data { -	u32 hmi_address; -	u32 byte_count; -	u32 data[2]; -}; - -/** Used for string data, and for packet bridge -*/ -struct hpi_controlx_msg_cobranet_bigdata { -	u32 hmi_address; -	u32 byte_count; -	u8 *pb_data; -#ifndef HPI64BIT -	u32 padding; -#endif -}; - -/** Used for PADS control reading of string fields. -*/ -struct hpi_controlx_msg_pad_data { -	u32 field; -	u32 byte_count; -	u8 *pb_data; -#ifndef HPI64BIT -	u32 padding; -#endif -}; - -/** Used for generic data -*/ - -struct hpi_controlx_msg_generic { -	u32 param1; -	u32 param2; -}; - -struct hpi_controlx_msg { -	u16 attribute;		/* control attribute or property */ -	u16 saved_index; -	union { -		struct hpi_controlx_msg_cobranet_data cobranet_data; -		struct hpi_controlx_msg_cobranet_bigdata cobranet_bigdata; -		struct hpi_controlx_msg_generic generic; -		struct hpi_controlx_msg_pad_data pad_data; -		/*struct param_value universal_value; */ -		/* nothing extra to send for status read */ -	} u; -}; - -/* Response */ -/** -*/ -struct hpi_controlx_res_cobranet_data { -	u32 byte_count; -	u32 data[2]; -}; - -struct hpi_controlx_res_cobranet_bigdata { -	u32 byte_count; -}; - -struct hpi_controlx_res_cobranet_status { -	u32 status; -	u32 readable_size; -	u32 writeable_size; -}; - -struct hpi_controlx_res_generic { -	u32 param1; -	u32 param2; -}; - -struct hpi_controlx_res {  	union { -		struct hpi_controlx_res_cobranet_bigdata cobranet_bigdata; -		struct hpi_controlx_res_cobranet_data cobranet_data; -		struct hpi_controlx_res_cobranet_status cobranet_status; -		struct hpi_controlx_res_generic generic; -		/*struct param_info universal_info; */ -		/*struct param_value universal_value; */ -	} u; +		struct { +			u32 status; +			u32 readable_size; +			u32 writeable_size; +		} status; +	} cobranet;  };  struct hpi_nvmemory_msg { @@ -1178,11 +972,11 @@ struct hpi_profile_res_open {  };  struct hpi_profile_res_time { -	u32 micro_seconds; +	u32 total_tick_count;  	u32 call_count; -	u32 max_micro_seconds; -	u32 min_micro_seconds; -	u16 seconds; +	u32 max_tick_count; +	u32 ticks_per_millisecond; +	u16 profile_interval;  };  struct hpi_profile_res_name { @@ -1218,7 +1012,6 @@ struct hpi_message {  	u16 obj_index;		/*  */  	union {  		struct hpi_subsys_msg s; -		struct hpi_adapter_msg a;  		union hpi_adapterx_msg ax;  		struct hpi_stream_msg d;  		struct hpi_mixer_msg m; @@ -1227,7 +1020,6 @@ struct hpi_message {  		/* identical to struct hpi_control_msg,  		   but field naming is improved */  		struct hpi_control_union_msg cu; -		struct hpi_controlx_msg cx;	/* extended mixer control; */  		struct hpi_nvmemory_msg n;  		struct hpi_gpio_msg l;	/* digital i/o */  		struct hpi_watchdog_msg w; @@ -1239,7 +1031,7 @@ struct hpi_message {  };  #define HPI_MESSAGE_SIZE_BY_OBJECT { \ -	sizeof(struct hpi_message_header) ,   /* default, no object type 0 */ \ +	sizeof(struct hpi_message_header) ,   /* Default, no object type 0 */ \  	sizeof(struct hpi_message_header) + sizeof(struct hpi_subsys_msg),\  	sizeof(struct hpi_message_header) + sizeof(union hpi_adapterx_msg),\  	sizeof(struct hpi_message_header) + sizeof(struct hpi_stream_msg),\ @@ -1252,10 +1044,15 @@ struct hpi_message {  	sizeof(struct hpi_message_header) + sizeof(struct hpi_watchdog_msg),\  	sizeof(struct hpi_message_header) + sizeof(struct hpi_clock_msg),\  	sizeof(struct hpi_message_header) + sizeof(struct hpi_profile_msg),\ -	sizeof(struct hpi_message_header) + sizeof(struct hpi_controlx_msg),\ +	sizeof(struct hpi_message_header), /* controlx obj removed */ \  	sizeof(struct hpi_message_header) + sizeof(struct hpi_async_msg) \  } +/* +Note that the wSpecificError error field should be inspected and potentially +reported whenever HPI_ERROR_DSP_COMMUNICATION or HPI_ERROR_DSP_BOOTLOAD is +returned in wError. +*/  struct hpi_response_header {  	u16 size;  	u8 type;		/* HPI_TYPE_RESPONSE  */ @@ -1277,7 +1074,6 @@ struct hpi_response {  	u16 specific_error;	/* adapter specific error */  	union {  		struct hpi_subsys_res s; -		struct hpi_adapter_res a;  		union hpi_adapterx_res ax;  		struct hpi_stream_res d;  		struct hpi_mixer_res m; @@ -1285,7 +1081,6 @@ struct hpi_response {  		struct hpi_control_res c;	/* mixer control; */  		/* identical to hpi_control_res, but field naming is improved */  		union hpi_control_union_res cu; -		struct hpi_controlx_res cx;	/* extended mixer control; */  		struct hpi_nvmemory_res n;  		struct hpi_gpio_res l;	/* digital i/o */  		struct hpi_watchdog_res w; @@ -1297,7 +1092,7 @@ struct hpi_response {  };  #define HPI_RESPONSE_SIZE_BY_OBJECT { \ -	sizeof(struct hpi_response_header) ,/* default, no object type 0 */ \ +	sizeof(struct hpi_response_header) ,/* Default, no object type 0 */ \  	sizeof(struct hpi_response_header) + sizeof(struct hpi_subsys_res),\  	sizeof(struct hpi_response_header) + sizeof(union  hpi_adapterx_res),\  	sizeof(struct hpi_response_header) + sizeof(struct hpi_stream_res),\ @@ -1310,11 +1105,11 @@ struct hpi_response {  	sizeof(struct hpi_response_header) + sizeof(struct hpi_watchdog_res),\  	sizeof(struct hpi_response_header) + sizeof(struct hpi_clock_res),\  	sizeof(struct hpi_response_header) + sizeof(struct hpi_profile_res),\ -	sizeof(struct hpi_response_header) + sizeof(struct hpi_controlx_res),\ +	sizeof(struct hpi_response_header), /* controlx obj removed */ \  	sizeof(struct hpi_response_header) + sizeof(struct hpi_async_res) \  } -/*********************** version 1 message/response *****************************/ +/*********************** version 1 message/response **************************/  #define HPINET_ETHERNET_DATA_SIZE (1500)  #define HPINET_IP_HDR_SIZE (20)  #define HPINET_IP_DATA_SIZE (HPINET_ETHERNET_DATA_SIZE - HPINET_IP_HDR_SIZE) @@ -1335,63 +1130,33 @@ struct hpi_res_adapter_get_info {  	struct hpi_adapter_res p;  }; -/* padding is so these are same size as v0 hpi_message */ -struct hpi_msg_adapter_query_flash { -	struct hpi_message_header h; -	u32 offset; -	u8 pad_to_version0_size[sizeof(struct hpi_message) -	/* V0 res */ -		sizeof(struct hpi_message_header) - 1 * sizeof(u32)]; -}; - -/* padding is so these are same size as v0 hpi_response */ -struct hpi_res_adapter_query_flash { +struct hpi_res_adapter_debug_read {  	struct hpi_response_header h; -	u32 checksum; -	u32 length; -	u32 version; -	u8 pad_to_version0_size[sizeof(struct hpi_response) -	/* V0 res */ -		sizeof(struct hpi_response_header) - 3 * sizeof(u32)]; +	u8 bytes[1024];  }; -struct hpi_msg_adapter_start_flash { -	struct hpi_message_header h; -	u32 offset; -	u32 length; -	u32 key; -	u8 pad_to_version0_size[sizeof(struct hpi_message) -	/* V0 res */ -		sizeof(struct hpi_message_header) - 3 * sizeof(u32)]; -}; - -struct hpi_res_adapter_start_flash { -	struct hpi_response_header h; -	u8 pad_to_version0_size[sizeof(struct hpi_response) -	/* V0 res */ -		sizeof(struct hpi_response_header)]; +struct hpi_msg_cobranet_hmi { +	u16 attribute; +	u16 padding; +	u32 hmi_address; +	u32 byte_count;  }; -struct hpi_msg_adapter_program_flash_payload { -	u32 checksum; -	u16 sequence; -	u16 length; -	u16 offset; /**< offset from start of msg to data */ -	u16 unused; -	/* ensure sizeof(header + payload) == sizeof(hpi_message_V0) -	   because old firmware expects data after message of this size */ -	u8 pad_to_version0_size[sizeof(struct hpi_message) -	/* V0 message */ -		sizeof(struct hpi_message_header) - sizeof(u32) - -		4 * sizeof(u16)]; +struct hpi_msg_cobranet_hmiwrite { +	struct hpi_message_header h; +	struct hpi_msg_cobranet_hmi p; +	u8 bytes[256];  }; -struct hpi_msg_adapter_program_flash { +struct hpi_msg_cobranet_hmiread {  	struct hpi_message_header h; -	struct hpi_msg_adapter_program_flash_payload p; -	u32 data[256]; +	struct hpi_msg_cobranet_hmi p;  }; -struct hpi_res_adapter_program_flash { +struct hpi_res_cobranet_hmiread {  	struct hpi_response_header h; -	u16 sequence; -	u8 pad_to_version0_size[sizeof(struct hpi_response) -	/* V0 res */ -		sizeof(struct hpi_response_header) - sizeof(u16)]; +	u32 byte_count; +	u8 bytes[256];  };  #if 1 @@ -1414,30 +1179,16 @@ struct hpi_response_header_v1 {  };  #endif -/* STRV HPI Packet */ -struct hpi_msg_strv { -	struct hpi_message_header h; -	struct hpi_entity strv; -}; - -struct hpi_res_strv { -	struct hpi_response_header h; -	struct hpi_entity strv; -}; -#define MIN_STRV_PACKET_SIZE sizeof(struct hpi_res_strv) -  struct hpi_msg_payload_v0 {  	struct hpi_message_header h;  	union {  		struct hpi_subsys_msg s; -		struct hpi_adapter_msg a;  		union hpi_adapterx_msg ax;  		struct hpi_stream_msg d;  		struct hpi_mixer_msg m;  		union hpi_mixerx_msg mx;  		struct hpi_control_msg c;  		struct hpi_control_union_msg cu; -		struct hpi_controlx_msg cx;  		struct hpi_nvmemory_msg n;  		struct hpi_gpio_msg l;  		struct hpi_watchdog_msg w; @@ -1451,14 +1202,12 @@ struct hpi_res_payload_v0 {  	struct hpi_response_header h;  	union {  		struct hpi_subsys_res s; -		struct hpi_adapter_res a;  		union hpi_adapterx_res ax;  		struct hpi_stream_res d;  		struct hpi_mixer_res m;  		union hpi_mixerx_res mx;  		struct hpi_control_res c;  		union hpi_control_union_res cu; -		struct hpi_controlx_res cx;  		struct hpi_nvmemory_res n;  		struct hpi_gpio_res l;  		struct hpi_watchdog_res w; @@ -1471,13 +1220,13 @@ struct hpi_res_payload_v0 {  union hpi_message_buffer_v1 {  	struct hpi_message m0;	/* version 0 */  	struct hpi_message_header_v1 h; -	unsigned char buf[HPI_MAX_PAYLOAD_SIZE]; +	u8 buf[HPI_MAX_PAYLOAD_SIZE];  };  union hpi_response_buffer_v1 {  	struct hpi_response r0;	/* version 0 */  	struct hpi_response_header_v1 h; -	unsigned char buf[HPI_MAX_PAYLOAD_SIZE]; +	u8 buf[HPI_MAX_PAYLOAD_SIZE];  };  compile_time_assert((sizeof(union hpi_message_buffer_v1) <= @@ -1499,6 +1248,11 @@ struct hpi_control_defn {  /*////////////////////////////////////////////////////////////////////////// */  /* declarations for control caching (internal to HPI<->DSP interaction)      */ +/** indicates a cached u16 value is invalid. */ +#define HPI_CACHE_INVALID_UINT16 0xFFFF +/** indicates a cached short value is invalid. */ +#define HPI_CACHE_INVALID_SHORT -32768 +  /** A compact representation of (part of) a controls state.  Used for efficient transfer of the control state  between DSP and host or across a network @@ -1512,58 +1266,97 @@ struct hpi_control_cache_info {  	u16 control_index;  }; -struct hpi_control_cache_single { +struct hpi_control_cache_vol { +	struct hpi_control_cache_info i; +	short an_log[2]; +	unsigned short flags; +	char padding[2]; +}; + +struct hpi_control_cache_meter { +	struct hpi_control_cache_info i; +	short an_log_peak[2]; +	short an_logRMS[2]; +}; + +struct hpi_control_cache_channelmode { +	struct hpi_control_cache_info i; +	u16 mode; +	char temp_padding[6]; +}; + +struct hpi_control_cache_mux { +	struct hpi_control_cache_info i; +	u16 source_node_type; +	u16 source_node_index; +	char temp_padding[4]; +}; + +struct hpi_control_cache_level { +	struct hpi_control_cache_info i; +	short an_log[2]; +	char temp_padding[4]; +}; + +struct hpi_control_cache_tuner { +	struct hpi_control_cache_info i; +	u32 freq_ink_hz; +	u16 band; +	short s_level_avg; +}; + +struct hpi_control_cache_aes3rx { +	struct hpi_control_cache_info i; +	u32 error_status; +	u32 format; +}; + +struct hpi_control_cache_aes3tx { +	struct hpi_control_cache_info i; +	u32 format; +	char temp_padding[4]; +}; + +struct hpi_control_cache_tonedetector { +	struct hpi_control_cache_info i; +	u16 state; +	char temp_padding[6]; +}; + +struct hpi_control_cache_silencedetector { +	struct hpi_control_cache_info i; +	u32 state; +	char temp_padding[4]; +}; + +struct hpi_control_cache_sampleclock {  	struct hpi_control_cache_info i; +	u16 source; +	u16 source_index; +	u32 sample_rate; +}; + +struct hpi_control_cache_microphone { +	struct hpi_control_cache_info i; +	u16 phantom_state; +	char temp_padding[6]; +}; + +struct hpi_control_cache_single {  	union { -		struct {	/* volume */ -			short an_log[2]; -		} v; -		struct {	/* peak meter */ -			short an_log_peak[2]; -			short an_logRMS[2]; -		} p; -		struct {	/* channel mode */ -			u16 mode; -		} m; -		struct {	/* multiplexer */ -			u16 source_node_type; -			u16 source_node_index; -		} x; -		struct {	/* level/trim */ -			short an_log[2]; -		} l; -		struct {	/* tuner - partial caching. -				   some attributes go to the DSP. */ -			u32 freq_ink_hz; -			u16 band; -			u16 level; -		} t; -		struct {	/* AESEBU rx status */ -			u32 error_status; -			u32 source; -		} aes3rx; -		struct {	/* AESEBU tx */ -			u32 format; -		} aes3tx; -		struct {	/* tone detector */ -			u16 state; -		} tone; -		struct {	/* silence detector */ -			u32 state; -			u32 count; -		} silence; -		struct {	/* sample clock */ -			u16 source; -			u16 source_index; -			u32 sample_rate; -		} clk; -		struct {	/* microphone control */ -			u16 state; -		} phantom_power; -		struct {	/* generic control */ -			u32 dw1; -			u32 dw2; -		} g; +		struct hpi_control_cache_info i; +		struct hpi_control_cache_vol vol; +		struct hpi_control_cache_meter meter; +		struct hpi_control_cache_channelmode mode; +		struct hpi_control_cache_mux mux; +		struct hpi_control_cache_level level; +		struct hpi_control_cache_tuner tuner; +		struct hpi_control_cache_aes3rx aes3rx; +		struct hpi_control_cache_aes3tx aes3tx; +		struct hpi_control_cache_tonedetector tone; +		struct hpi_control_cache_silencedetector silence; +		struct hpi_control_cache_sampleclock clk; +		struct hpi_control_cache_microphone microphone;  	} u;  }; @@ -1580,11 +1373,10 @@ struct hpi_control_cache_pad {  	u32 traffic_anouncement;  }; -/*/////////////////////////////////////////////////////////////////////////// */ -/* declarations for 2^N sized FIFO buffer (internal to HPI<->DSP interaction) */ +/* 2^N sized FIFO buffer (internal to HPI<->DSP interaction) */  struct hpi_fifo_buffer {  	u32 size; -	u32 dSP_index; +	u32 dsp_index;  	u32 host_index;  }; @@ -1606,25 +1398,16 @@ u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,  /*////////////////////////////////////////////////////////////////////////// */  /* main HPI entry point */ -hpi_handler_func hpi_send_recv; - -/* UDP message */ -void hpi_send_recvUDP(struct hpi_message *phm, struct hpi_response *phr, -	const unsigned int timeout); +void hpi_send_recv(struct hpi_message *phm, struct hpi_response *phr);  /* used in PnP OS/driver */ -u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys, -	const struct hpi_resource *p_resource, u16 *pw_adapter_index); - -u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index); +u16 hpi_subsys_create_adapter(const struct hpi_resource *p_resource, +	u16 *pw_adapter_index); -u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u8 **pp_buffer, +u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,  	struct hpi_hostbuffer_status **pp_status); -u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u8 **pp_buffer, +u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,  	struct hpi_hostbuffer_status **pp_status);  u16 hpi_adapter_restart(u16 adapter_index); @@ -1642,9 +1425,7 @@ void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR);  /*////////////////////////////////////////////////////////////////////////// */  /* declarations for individual HPI entry points */ -hpi_handler_func HPI_1000;  hpi_handler_func HPI_6000;  hpi_handler_func HPI_6205; -hpi_handler_func HPI_COMMON;  #endif				/* _HPI_INTERNAL_H_ */ diff --git a/sound/pci/asihpi/hpi_version.h b/sound/pci/asihpi/hpi_version.h new file mode 100644 index 00000000000..e9146e53bd5 --- /dev/null +++ b/sound/pci/asihpi/hpi_version.h @@ -0,0 +1,32 @@ +/** HPI Version Definitions +Development releases have odd minor version. +Production releases have even minor version. + +\file hpi_version.h +*/ + +#ifndef _HPI_VERSION_H +#define _HPI_VERSION_H + +/* Use single digits for versions less that 10 to avoid octal. */ +/* *** HPI_VER is the only edit required to update version *** */ +/** HPI version */ +#define HPI_VER HPI_VERSION_CONSTRUCTOR(4, 10, 1) + +/** HPI version string in dotted decimal format */ +#define HPI_VER_STRING "4.10.01" + +/** Library version as documented in hpi-api-versions.txt */ +#define HPI_LIB_VER  HPI_VERSION_CONSTRUCTOR(10, 2, 0) + +/** Construct hpi version number from major, minor, release numbers */ +#define HPI_VERSION_CONSTRUCTOR(maj, min, r) ((maj << 16) + (min << 8) + r) + +/** Extract major version from hpi version number */ +#define HPI_VER_MAJOR(v) ((int)(v >> 16)) +/** Extract minor version from hpi version number */ +#define HPI_VER_MINOR(v) ((int)((v >> 8) & 0xFF)) +/** Extract release from hpi version number */ +#define HPI_VER_RELEASE(v) ((int)(v & 0xFF)) + +#endif diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c index d67f4d3db91..7ed5c26c373 100644 --- a/sound/pci/asihpi/hpicmn.c +++ b/sound/pci/asihpi/hpicmn.c @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -26,6 +26,8 @@  #include "hpi_internal.h"  #include "hpidebug.h" +#include "hpimsginit.h" +  #include "hpicmn.h"  struct hpi_adapters_list { @@ -43,20 +45,30 @@ static struct hpi_adapters_list adapters;  **/  u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr)  { -	u16 error = 0; +	if (phr->type != HPI_TYPE_RESPONSE) { +		HPI_DEBUG_LOG(ERROR, "header type %d invalid\n", phr->type); +		return HPI_ERROR_INVALID_RESPONSE; +	} -	if ((phr->type != HPI_TYPE_RESPONSE) -		|| (phr->object != phm->object) -		|| (phr->function != phm->function)) -		error = HPI_ERROR_INVALID_RESPONSE; +	if (phr->object != phm->object) { +		HPI_DEBUG_LOG(ERROR, "header object %d invalid\n", +			phr->object); +		return HPI_ERROR_INVALID_RESPONSE; +	} + +	if (phr->function != phm->function) { +		HPI_DEBUG_LOG(ERROR, "header function %d invalid\n", +			phr->function); +		return HPI_ERROR_INVALID_RESPONSE; +	} -	return error; +	return 0;  }  u16 hpi_add_adapter(struct hpi_adapter_obj *pao)  {  	u16 retval = 0; -	/*HPI_ASSERT(pao->wAdapterType); */ +	/*HPI_ASSERT(pao->type); */  	hpios_alistlock_lock(&adapters); @@ -65,9 +77,19 @@ u16 hpi_add_adapter(struct hpi_adapter_obj *pao)  		goto unlock;  	} -	if (adapters.adapter[pao->index].adapter_type) { -		{ -			retval = HPI_DUPLICATE_ADAPTER_NUMBER; +	if (adapters.adapter[pao->index].type) { +		int a; +		for (a = HPI_MAX_ADAPTERS - 1; a >= 0; a--) { +			if (!adapters.adapter[a].type) { +				HPI_DEBUG_LOG(WARNING, +					"ASI%X duplicate index %d moved to %d\n", +					pao->type, pao->index, a); +				pao->index = a; +				break; +			} +		} +		if (a < 0) { +			retval = HPI_ERROR_DUPLICATE_ADAPTER_NUMBER;  			goto unlock;  		}  	} @@ -76,17 +98,22 @@ u16 hpi_add_adapter(struct hpi_adapter_obj *pao)  	adapters.gw_num_adapters++;  unlock: -	hpios_alistlock_un_lock(&adapters); +	hpios_alistlock_unlock(&adapters);  	return retval;  }  void hpi_delete_adapter(struct hpi_adapter_obj *pao)  { -	memset(pao, 0, sizeof(struct hpi_adapter_obj)); +	if (!pao->type) { +		HPI_DEBUG_LOG(ERROR, "removing null adapter?\n"); +		return; +	}  	hpios_alistlock_lock(&adapters); -	adapters.gw_num_adapters--;	/* dec the number of adapters */ -	hpios_alistlock_un_lock(&adapters); +	if (adapters.adapter[pao->index].type) +		adapters.gw_num_adapters--; +	memset(&adapters.adapter[pao->index], 0, sizeof(adapters.adapter[0])); +	hpios_alistlock_unlock(&adapters);  }  /** @@ -99,13 +126,13 @@ struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index)  	struct hpi_adapter_obj *pao = NULL;  	if (adapter_index >= HPI_MAX_ADAPTERS) { -		HPI_DEBUG_LOG(VERBOSE, "find_adapter invalid index %d ", +		HPI_DEBUG_LOG(VERBOSE, "find_adapter invalid index %d\n",  			adapter_index);  		return NULL;  	}  	pao = &adapters.adapter[adapter_index]; -	if (pao->adapter_type != 0) { +	if (pao->type != 0) {  		/*  		   HPI_DEBUG_LOG(VERBOSE, "Found adapter index %d\n",  		   wAdapterIndex); @@ -125,51 +152,34 @@ struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index)  * wipe an HPI_ADAPTERS_LIST structure.  *  **/ -static void wipe_adapter_list(void -	) +static void wipe_adapter_list(void)  {  	memset(&adapters, 0, sizeof(adapters));  } -/** -* SubSysGetAdapters fills awAdapterList in an struct hpi_response structure -* with all adapters in the given HPI_ADAPTERS_LIST. -* -*/ -static void subsys_get_adapters(struct hpi_response *phr) +static void subsys_get_adapter(struct hpi_message *phm, +	struct hpi_response *phr)  { -	/* fill in the response adapter array with the position */ -	/* identified by the adapter number/index of the adapters in */ -	/* this HPI */ -	/* i.e. if we have an A120 with it's jumper set to */ -	/* Adapter Number 2 then put an Adapter type A120 in the */ -	/* array in position 1 */ -	/* NOTE: AdapterNumber is 1..N, Index is 0..N-1 */ - -	/* input:  NONE */ -	/* output: wNumAdapters */ -	/*                 awAdapter[] */ -	/* */ - -	short i; -	struct hpi_adapter_obj *pao = NULL; +	int count = phm->obj_index; +	u16 index = 0; -	HPI_DEBUG_LOG(VERBOSE, "subsys_get_adapters\n"); - -	/* for each adapter, place it's type in the position of the array */ -	/* corresponding to it's adapter number */ -	for (i = 0; i < adapters.gw_num_adapters; i++) { -		pao = &adapters.adapter[i]; -		if (phr->u.s.aw_adapter_list[pao->index] != 0) { -			phr->error = HPI_DUPLICATE_ADAPTER_NUMBER; -			phr->specific_error = pao->index; -			return; +	/* find the nCount'th nonzero adapter in array */ +	for (index = 0; index < HPI_MAX_ADAPTERS; index++) { +		if (adapters.adapter[index].type) { +			if (!count) +				break; +			count--;  		} -		phr->u.s.aw_adapter_list[pao->index] = pao->adapter_type;  	} -	phr->u.s.num_adapters = adapters.gw_num_adapters; -	phr->error = 0;	/* the function completed OK; */ +	if (index < HPI_MAX_ADAPTERS) { +		phr->u.s.adapter_index = adapters.adapter[index].index; +		phr->u.s.adapter_type = adapters.adapter[index].type; +	} else { +		phr->u.s.adapter_index = 0; +		phr->u.s.adapter_type = 0; +		phr->error = HPI_ERROR_INVALID_OBJ_INDEX; +	}  }  static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC) @@ -178,67 +188,99 @@ static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)  	int cached = 0;  	if (!pC)  		return 0; -	if ((!pC->init) && (pC->p_cache != NULL) && (pC->control_count) -		&& (pC->cache_size_in_bytes) -		) { -		u32 *p_master_cache; -		pC->init = 1; - -		p_master_cache = (u32 *)pC->p_cache; -		HPI_DEBUG_LOG(VERBOSE, "check %d controls\n", + +	if (pC->init) +		return pC->init; + +	if (!pC->p_cache) +		return 0; + +	if (pC->control_count && pC->cache_size_in_bytes) { +		char *p_master_cache; +		unsigned int byte_count = 0; + +		p_master_cache = (char *)pC->p_cache; +		HPI_DEBUG_LOG(DEBUG, "check %d controls\n",  			pC->control_count);  		for (i = 0; i < pC->control_count; i++) {  			struct hpi_control_cache_info *info =  				(struct hpi_control_cache_info *) -				p_master_cache; +				&p_master_cache[byte_count]; + +			if (!info->size_in32bit_words) { +				if (!i) { +					HPI_DEBUG_LOG(INFO, +						"adap %d cache not ready?\n", +						pC->adap_idx); +					return 0; +				} +				/* The cache is invalid. +				 * Minimum valid entry size is +				 * sizeof(struct hpi_control_cache_info) +				 */ +				HPI_DEBUG_LOG(ERROR, +					"adap %d zero size cache entry %d\n", +					pC->adap_idx, i); +				break; +			}  			if (info->control_type) { -				pC->p_info[i] = info; +				pC->p_info[info->control_index] = info;  				cached++; -			} else -				pC->p_info[i] = NULL; +			} else {	/* dummy cache entry */ +				pC->p_info[info->control_index] = NULL; +			} -			if (info->size_in32bit_words) -				p_master_cache += info->size_in32bit_words; -			else -				p_master_cache += -					sizeof(struct -					hpi_control_cache_single) / -					sizeof(u32); +			byte_count += info->size_in32bit_words * 4;  			HPI_DEBUG_LOG(VERBOSE, -				"cached %d, pinfo %p index %d type %d\n", -				cached, pC->p_info[i], info->control_index, -				info->control_type); +				"cached %d, pinfo %p index %d type %d size %d\n", +				cached, pC->p_info[info->control_index], +				info->control_index, info->control_type, +				info->size_in32bit_words); + +			/* quit loop early if whole cache has been scanned. +			 * dwControlCount is the maximum possible entries +			 * but some may be absent from the cache +			 */ +			if (byte_count >= pC->cache_size_in_bytes) +				break; +			/* have seen last control index */ +			if (info->control_index == pC->control_count - 1) +				break;  		} -		/* -		   We didn't find anything to cache, so try again later ! -		 */ -		if (!cached) -			pC->init = 0; + +		if (byte_count != pC->cache_size_in_bytes) +			HPI_DEBUG_LOG(WARNING, +				"adap %d bytecount %d != cache size %d\n", +				pC->adap_idx, byte_count, +				pC->cache_size_in_bytes); +		else +			HPI_DEBUG_LOG(DEBUG, +				"adap %d cache good, bytecount == cache size = %d\n", +				pC->adap_idx, byte_count); + +		pC->init = (u16)cached;  	}  	return pC->init;  }  /** Find a control.  */ -static short find_control(struct hpi_message *phm, -	struct hpi_control_cache *p_cache, struct hpi_control_cache_info **pI, -	u16 *pw_control_index) +static short find_control(u16 control_index, +	struct hpi_control_cache *p_cache, struct hpi_control_cache_info **pI)  { -	*pw_control_index = phm->obj_index; -  	if (!control_cache_alloc_check(p_cache)) {  		HPI_DEBUG_LOG(VERBOSE, -			"control_cache_alloc_check() failed. adap%d ci%d\n", -			phm->adapter_index, *pw_control_index); +			"control_cache_alloc_check() failed %d\n", +			control_index);  		return 0;  	} -	*pI = p_cache->p_info[*pw_control_index]; +	*pI = p_cache->p_info[control_index];  	if (!*pI) { -		HPI_DEBUG_LOG(VERBOSE, "uncached adap %d, control %d\n", -			phm->adapter_index, *pw_control_index); +		HPI_DEBUG_LOG(VERBOSE, "Uncached Control %d\n", +			control_index);  		return 0;  	} else {  		HPI_DEBUG_LOG(VERBOSE, "find_control() type %d\n", @@ -247,25 +289,6 @@ static short find_control(struct hpi_message *phm,  	return 1;  } -/** Used by the kernel driver to figure out if a buffer needs mapping. - */ -short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache, -	struct hpi_message *phm, void **p, unsigned int *pN) -{ -	*pN = 0; -	*p = NULL; -	if ((phm->function == HPI_CONTROL_GET_STATE) -		&& (phm->object == HPI_OBJ_CONTROLEX) -		) { -		u16 control_index; -		struct hpi_control_cache_info *pI; - -		if (!find_control(phm, p_cache, &pI, &control_index)) -			return 0; -	} -	return 0; -} -  /* allow unified treatment of several string fields within struct */  #define HPICMN_PAD_OFS_AND_SIZE(m)  {\  	offsetof(struct hpi_control_cache_pad, m), \ @@ -276,7 +299,7 @@ struct pad_ofs_size {  	unsigned int field_size;  }; -static struct pad_ofs_size pad_desc[] = { +static const struct pad_ofs_size pad_desc[] = {  	HPICMN_PAD_OFS_AND_SIZE(c_channel),	/* HPI_PAD_CHANNEL_NAME */  	HPICMN_PAD_OFS_AND_SIZE(c_artist),	/* HPI_PAD_ARTIST */  	HPICMN_PAD_OFS_AND_SIZE(c_title),	/* HPI_PAD_TITLE */ @@ -290,75 +313,107 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,  	struct hpi_message *phm, struct hpi_response *phr)  {  	short found = 1; -	u16 control_index;  	struct hpi_control_cache_info *pI;  	struct hpi_control_cache_single *pC; -	struct hpi_control_cache_pad *p_pad; - -	if (!find_control(phm, p_cache, &pI, &control_index)) +	size_t response_size; +	if (!find_control(phm->obj_index, p_cache, &pI)) { +		HPI_DEBUG_LOG(VERBOSE, +			"HPICMN find_control() failed for adap %d\n", +			phm->adapter_index);  		return 0; +	}  	phr->error = 0; +	phr->specific_error = 0; +	phr->version = 0; + +	/* set the default response size */ +	response_size = +		sizeof(struct hpi_response_header) + +		sizeof(struct hpi_control_res);  	/* pC is the default cached control strucure. May be cast to  	   something else in the following switch statement.  	 */  	pC = (struct hpi_control_cache_single *)pI; -	p_pad = (struct hpi_control_cache_pad *)pI;  	switch (pI->control_type) {  	case HPI_CONTROL_METER:  		if (phm->u.c.attribute == HPI_METER_PEAK) { -			phr->u.c.an_log_value[0] = pC->u.p.an_log_peak[0]; -			phr->u.c.an_log_value[1] = pC->u.p.an_log_peak[1]; +			phr->u.c.an_log_value[0] = pC->u.meter.an_log_peak[0]; +			phr->u.c.an_log_value[1] = pC->u.meter.an_log_peak[1];  		} else if (phm->u.c.attribute == HPI_METER_RMS) { -			phr->u.c.an_log_value[0] = pC->u.p.an_logRMS[0]; -			phr->u.c.an_log_value[1] = pC->u.p.an_logRMS[1]; +			if (pC->u.meter.an_logRMS[0] == +				HPI_CACHE_INVALID_SHORT) { +				phr->error = +					HPI_ERROR_INVALID_CONTROL_ATTRIBUTE; +				phr->u.c.an_log_value[0] = HPI_METER_MINIMUM; +				phr->u.c.an_log_value[1] = HPI_METER_MINIMUM; +			} else { +				phr->u.c.an_log_value[0] = +					pC->u.meter.an_logRMS[0]; +				phr->u.c.an_log_value[1] = +					pC->u.meter.an_logRMS[1]; +			}  		} else  			found = 0;  		break;  	case HPI_CONTROL_VOLUME:  		if (phm->u.c.attribute == HPI_VOLUME_GAIN) { -			phr->u.c.an_log_value[0] = pC->u.v.an_log[0]; -			phr->u.c.an_log_value[1] = pC->u.v.an_log[1]; -		} else +			phr->u.c.an_log_value[0] = pC->u.vol.an_log[0]; +			phr->u.c.an_log_value[1] = pC->u.vol.an_log[1]; +		} else if (phm->u.c.attribute == HPI_VOLUME_MUTE) { +			if (pC->u.vol.flags & HPI_VOLUME_FLAG_HAS_MUTE) { +				if (pC->u.vol.flags & HPI_VOLUME_FLAG_MUTED) +					phr->u.c.param1 = +						HPI_BITMASK_ALL_CHANNELS; +				else +					phr->u.c.param1 = 0; +			} else { +				phr->error = +					HPI_ERROR_INVALID_CONTROL_ATTRIBUTE; +				phr->u.c.param1 = 0; +			} +		} else {  			found = 0; +		}  		break;  	case HPI_CONTROL_MULTIPLEXER:  		if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) { -			phr->u.c.param1 = pC->u.x.source_node_type; -			phr->u.c.param2 = pC->u.x.source_node_index; +			phr->u.c.param1 = pC->u.mux.source_node_type; +			phr->u.c.param2 = pC->u.mux.source_node_index;  		} else {  			found = 0;  		}  		break;  	case HPI_CONTROL_CHANNEL_MODE:  		if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE) -			phr->u.c.param1 = pC->u.m.mode; +			phr->u.c.param1 = pC->u.mode.mode;  		else  			found = 0;  		break;  	case HPI_CONTROL_LEVEL:  		if (phm->u.c.attribute == HPI_LEVEL_GAIN) { -			phr->u.c.an_log_value[0] = pC->u.l.an_log[0]; -			phr->u.c.an_log_value[1] = pC->u.l.an_log[1]; +			phr->u.c.an_log_value[0] = pC->u.level.an_log[0]; +			phr->u.c.an_log_value[1] = pC->u.level.an_log[1];  		} else  			found = 0;  		break;  	case HPI_CONTROL_TUNER:  		if (phm->u.c.attribute == HPI_TUNER_FREQ) -			phr->u.c.param1 = pC->u.t.freq_ink_hz; +			phr->u.c.param1 = pC->u.tuner.freq_ink_hz;  		else if (phm->u.c.attribute == HPI_TUNER_BAND) -			phr->u.c.param1 = pC->u.t.band; -		else if ((phm->u.c.attribute == HPI_TUNER_LEVEL) -			&& (phm->u.c.param1 == HPI_TUNER_LEVEL_AVERAGE)) -			if (pC->u.t.level == HPI_ERROR_ILLEGAL_CACHE_VALUE) { -				phr->u.c.param1 = 0; +			phr->u.c.param1 = pC->u.tuner.band; +		else if (phm->u.c.attribute == HPI_TUNER_LEVEL_AVG) +			if (pC->u.tuner.s_level_avg == +				HPI_CACHE_INVALID_SHORT) { +				phr->u.cu.tuner.s_level = 0;  				phr->error =  					HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;  			} else -				phr->u.c.param1 = pC->u.t.level; +				phr->u.cu.tuner.s_level = +					pC->u.tuner.s_level_avg;  		else  			found = 0;  		break; @@ -366,7 +421,7 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,  		if (phm->u.c.attribute == HPI_AESEBURX_ERRORSTATUS)  			phr->u.c.param1 = pC->u.aes3rx.error_status;  		else if (phm->u.c.attribute == HPI_AESEBURX_FORMAT) -			phr->u.c.param1 = pC->u.aes3rx.source; +			phr->u.c.param1 = pC->u.aes3rx.format;  		else  			found = 0;  		break; @@ -385,13 +440,12 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,  	case HPI_CONTROL_SILENCEDETECTOR:  		if (phm->u.c.attribute == HPI_SILENCEDETECTOR_STATE) {  			phr->u.c.param1 = pC->u.silence.state; -			phr->u.c.param2 = pC->u.silence.count;  		} else  			found = 0;  		break;  	case HPI_CONTROL_MICROPHONE:  		if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER) -			phr->u.c.param1 = pC->u.phantom_power.state; +			phr->u.c.param1 = pC->u.microphone.phantom_state;  		else  			found = 0;  		break; @@ -400,7 +454,7 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,  			phr->u.c.param1 = pC->u.clk.source;  		else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE_INDEX) {  			if (pC->u.clk.source_index == -				HPI_ERROR_ILLEGAL_CACHE_VALUE) { +				HPI_CACHE_INVALID_UINT16) {  				phr->u.c.param1 = 0;  				phr->error =  					HPI_ERROR_INVALID_CONTROL_ATTRIBUTE; @@ -411,60 +465,63 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,  		else  			found = 0;  		break; -	case HPI_CONTROL_PAD: - -		if (!(p_pad->field_valid_flags & (1 << -					HPI_CTL_ATTR_INDEX(phm->u.c. -						attribute)))) { -			phr->error = HPI_ERROR_INVALID_CONTROL_ATTRIBUTE; -			break; -		} +	case HPI_CONTROL_PAD:{ +			struct hpi_control_cache_pad *p_pad; +			p_pad = (struct hpi_control_cache_pad *)pI; -		if (phm->u.c.attribute == HPI_PAD_PROGRAM_ID) -			phr->u.c.param1 = p_pad->pI; -		else if (phm->u.c.attribute == HPI_PAD_PROGRAM_TYPE) -			phr->u.c.param1 = p_pad->pTY; -		else { -			unsigned int index = -				HPI_CTL_ATTR_INDEX(phm->u.c.attribute) - 1; -			unsigned int offset = phm->u.c.param1; -			unsigned int pad_string_len, field_size; -			char *pad_string; -			unsigned int tocopy; - -			HPI_DEBUG_LOG(VERBOSE, "PADS HPI_PADS_ %d\n", -				phm->u.c.attribute); - -			if (index > ARRAY_SIZE(pad_desc) - 1) { +			if (!(p_pad->field_valid_flags & (1 << +						HPI_CTL_ATTR_INDEX(phm->u.c. +							attribute)))) {  				phr->error =  					HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;  				break;  			} -			pad_string = ((char *)p_pad) + pad_desc[index].offset; -			field_size = pad_desc[index].field_size; -			/* Ensure null terminator */ -			pad_string[field_size - 1] = 0; - -			pad_string_len = strlen(pad_string) + 1; - -			if (offset > pad_string_len) { -				phr->error = HPI_ERROR_INVALID_CONTROL_VALUE; -				break; +			if (phm->u.c.attribute == HPI_PAD_PROGRAM_ID) +				phr->u.c.param1 = p_pad->pI; +			else if (phm->u.c.attribute == HPI_PAD_PROGRAM_TYPE) +				phr->u.c.param1 = p_pad->pTY; +			else { +				unsigned int index = +					HPI_CTL_ATTR_INDEX(phm->u.c. +					attribute) - 1; +				unsigned int offset = phm->u.c.param1; +				unsigned int pad_string_len, field_size; +				char *pad_string; +				unsigned int tocopy; + +				if (index > ARRAY_SIZE(pad_desc) - 1) { +					phr->error = +						HPI_ERROR_INVALID_CONTROL_ATTRIBUTE; +					break; +				} + +				pad_string = +					((char *)p_pad) + +					pad_desc[index].offset; +				field_size = pad_desc[index].field_size; +				/* Ensure null terminator */ +				pad_string[field_size - 1] = 0; + +				pad_string_len = strlen(pad_string) + 1; + +				if (offset > pad_string_len) { +					phr->error = +						HPI_ERROR_INVALID_CONTROL_VALUE; +					break; +				} + +				tocopy = pad_string_len - offset; +				if (tocopy > sizeof(phr->u.cu.chars8.sz_data)) +					tocopy = sizeof(phr->u.cu.chars8. +						sz_data); + +				memcpy(phr->u.cu.chars8.sz_data, +					&pad_string[offset], tocopy); + +				phr->u.cu.chars8.remaining_chars = +					pad_string_len - offset - tocopy;  			} - -			tocopy = pad_string_len - offset; -			if (tocopy > sizeof(phr->u.cu.chars8.sz_data)) -				tocopy = sizeof(phr->u.cu.chars8.sz_data); - -			HPI_DEBUG_LOG(VERBOSE, -				"PADS memcpy(%d), offset %d \n", tocopy, -				offset); -			memcpy(phr->u.cu.chars8.sz_data, &pad_string[offset], -				tocopy); - -			phr->u.cu.chars8.remaining_chars = -				pad_string_len - offset - tocopy;  		}  		break;  	default: @@ -472,21 +529,16 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,  		break;  	} -	if (found) -		HPI_DEBUG_LOG(VERBOSE, -			"cached adap %d, ctl %d, type %d, attr %d\n", -			phm->adapter_index, pI->control_index, -			pI->control_type, phm->u.c.attribute); -	else -		HPI_DEBUG_LOG(VERBOSE, -			"uncached adap %d, ctl %d, ctl type %d\n", -			phm->adapter_index, pI->control_index, -			pI->control_type); +	HPI_DEBUG_LOG(VERBOSE, "%s Adap %d, Ctl %d, Type %d, Attr %d\n", +		found ? "Cached" : "Uncached", phm->adapter_index, +		pI->control_index, pI->control_type, phm->u.c.attribute); -	if (found) -		phr->size = -			sizeof(struct hpi_response_header) + -			sizeof(struct hpi_control_res); +	if (found) { +		phr->size = (u16)response_size; +		phr->type = HPI_TYPE_RESPONSE; +		phr->object = phm->object; +		phr->function = phm->function; +	}  	return found;  } @@ -497,18 +549,21 @@ Only update if no error.  Volume and Level return the limited values in the response, so use these  Multiplexer does so use sent values  */ -void hpi_sync_control_cache(struct hpi_control_cache *p_cache, +void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,  	struct hpi_message *phm, struct hpi_response *phr)  { -	u16 control_index;  	struct hpi_control_cache_single *pC;  	struct hpi_control_cache_info *pI;  	if (phr->error)  		return; -	if (!find_control(phm, p_cache, &pI, &control_index)) +	if (!find_control(phm->obj_index, p_cache, &pI)) { +		HPI_DEBUG_LOG(VERBOSE, +			"HPICMN find_control() failed for adap %d\n", +			phm->adapter_index);  		return; +	}  	/* pC is the default cached control strucure.  	   May be cast to something else in the following switch statement. @@ -518,31 +573,36 @@ void hpi_sync_control_cache(struct hpi_control_cache *p_cache,  	switch (pI->control_type) {  	case HPI_CONTROL_VOLUME:  		if (phm->u.c.attribute == HPI_VOLUME_GAIN) { -			pC->u.v.an_log[0] = phr->u.c.an_log_value[0]; -			pC->u.v.an_log[1] = phr->u.c.an_log_value[1]; +			pC->u.vol.an_log[0] = phr->u.c.an_log_value[0]; +			pC->u.vol.an_log[1] = phr->u.c.an_log_value[1]; +		} else if (phm->u.c.attribute == HPI_VOLUME_MUTE) { +			if (phm->u.c.param1) +				pC->u.vol.flags |= HPI_VOLUME_FLAG_MUTED; +			else +				pC->u.vol.flags &= ~HPI_VOLUME_FLAG_MUTED;  		}  		break;  	case HPI_CONTROL_MULTIPLEXER:  		/* mux does not return its setting on Set command. */  		if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) { -			pC->u.x.source_node_type = (u16)phm->u.c.param1; -			pC->u.x.source_node_index = (u16)phm->u.c.param2; +			pC->u.mux.source_node_type = (u16)phm->u.c.param1; +			pC->u.mux.source_node_index = (u16)phm->u.c.param2;  		}  		break;  	case HPI_CONTROL_CHANNEL_MODE:  		/* mode does not return its setting on Set command. */  		if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE) -			pC->u.m.mode = (u16)phm->u.c.param1; +			pC->u.mode.mode = (u16)phm->u.c.param1;  		break;  	case HPI_CONTROL_LEVEL:  		if (phm->u.c.attribute == HPI_LEVEL_GAIN) { -			pC->u.v.an_log[0] = phr->u.c.an_log_value[0]; -			pC->u.v.an_log[1] = phr->u.c.an_log_value[1]; +			pC->u.vol.an_log[0] = phr->u.c.an_log_value[0]; +			pC->u.vol.an_log[1] = phr->u.c.an_log_value[1];  		}  		break;  	case HPI_CONTROL_MICROPHONE:  		if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER) -			pC->u.phantom_power.state = (u16)phm->u.c.param1; +			pC->u.microphone.phantom_state = (u16)phm->u.c.param1;  		break;  	case HPI_CONTROL_AESEBU_TRANSMITTER:  		if (phm->u.c.attribute == HPI_AESEBUTX_FORMAT) @@ -550,7 +610,7 @@ void hpi_sync_control_cache(struct hpi_control_cache *p_cache,  		break;  	case HPI_CONTROL_AESEBU_RECEIVER:  		if (phm->u.c.attribute == HPI_AESEBURX_FORMAT) -			pC->u.aes3rx.source = phm->u.c.param1; +			pC->u.aes3rx.format = phm->u.c.param1;  		break;  	case HPI_CONTROL_SAMPLECLOCK:  		if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE) @@ -565,59 +625,59 @@ void hpi_sync_control_cache(struct hpi_control_cache *p_cache,  	}  } -struct hpi_control_cache *hpi_alloc_control_cache(const u32 -	number_of_controls, const u32 size_in_bytes, -	struct hpi_control_cache_info *pDSP_control_buffer) +/** Allocate control cache. + +\return Cache pointer, or NULL if allocation fails. +*/ +struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count, +	const u32 size_in_bytes, u8 *p_dsp_control_buffer)  {  	struct hpi_control_cache *p_cache =  		kmalloc(sizeof(*p_cache), GFP_KERNEL);  	if (!p_cache)  		return NULL; -	p_cache->p_info = -		kmalloc(sizeof(*p_cache->p_info) * number_of_controls, -			GFP_KERNEL); + +	p_cache->p_info = kcalloc(control_count, sizeof(*p_cache->p_info), +				  GFP_KERNEL);  	if (!p_cache->p_info) {  		kfree(p_cache);  		return NULL;  	}  	p_cache->cache_size_in_bytes = size_in_bytes; -	p_cache->control_count = number_of_controls; -	p_cache->p_cache = -		(struct hpi_control_cache_single *)pDSP_control_buffer; +	p_cache->control_count = control_count; +	p_cache->p_cache = p_dsp_control_buffer;  	p_cache->init = 0;  	return p_cache;  }  void hpi_free_control_cache(struct hpi_control_cache *p_cache)  { -	if (p_cache->init) { +	if (p_cache) {  		kfree(p_cache->p_info); -		p_cache->p_info = NULL; -		p_cache->init = 0;  		kfree(p_cache);  	}  }  static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)  { +	hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function, 0);  	switch (phm->function) {  	case HPI_SUBSYS_OPEN:  	case HPI_SUBSYS_CLOSE:  	case HPI_SUBSYS_DRIVER_UNLOAD: -		phr->error = 0;  		break;  	case HPI_SUBSYS_DRIVER_LOAD:  		wipe_adapter_list();  		hpios_alistlock_init(&adapters); -		phr->error = 0;  		break; -	case HPI_SUBSYS_GET_INFO: -		subsys_get_adapters(phr); +	case HPI_SUBSYS_GET_ADAPTER: +		subsys_get_adapter(phm, phr); +		break; +	case HPI_SUBSYS_GET_NUM_ADAPTERS: +		phr->u.s.num_adapters = adapters.gw_num_adapters;  		break;  	case HPI_SUBSYS_CREATE_ADAPTER: -	case HPI_SUBSYS_DELETE_ADAPTER: -		phr->error = 0;  		break;  	default:  		phr->error = HPI_ERROR_INVALID_FUNC; @@ -628,7 +688,7 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)  void HPI_COMMON(struct hpi_message *phm, struct hpi_response *phr)  {  	switch (phm->type) { -	case HPI_TYPE_MESSAGE: +	case HPI_TYPE_REQUEST:  		switch (phm->object) {  		case HPI_OBJ_SUBSYSTEM:  			subsys_message(phm, phr); diff --git a/sound/pci/asihpi/hpicmn.h b/sound/pci/asihpi/hpicmn.h index 6229022f56c..e4412128304 100644 --- a/sound/pci/asihpi/hpicmn.h +++ b/sound/pci/asihpi/hpicmn.h @@ -1,7 +1,7 @@  /**      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -18,12 +18,15 @@  */ +struct hpi_adapter_obj; + +/* a function that takes an adapter obj and returns an int */ +typedef int adapter_int_func(struct hpi_adapter_obj *pao); +  struct hpi_adapter_obj {  	struct hpi_pci pci;	/* PCI info - bus#,dev#,address etc */ -	u16 adapter_type;	/* ASI6701 etc */ -	u16 index;		/* */ -	u16 open;		/* =1 when adapter open */ -	u16 mixer_open; +	u16 type;		/* 0x6644 == ASI6644 etc */ +	u16 index;  	struct hpios_spinlock dsp_lock; @@ -33,18 +36,19 @@ struct hpi_adapter_obj {  };  struct hpi_control_cache { -	u32 init;	     /**< indicates whether the -				structures are initialized */ +	/** indicates whether the structures are initialized */ +	u16 init; +	u16 adap_idx;  	u32 control_count;  	u32 cache_size_in_bytes; -	struct hpi_control_cache_info -	**p_info;		 /**< pointer to allocated memory of -				lookup pointers. */ -	struct hpi_control_cache_single -	*p_cache;		 /**< pointer to DSP's control cache. */ +	/** pointer to allocated memory of lookup pointers. */ +	struct hpi_control_cache_info **p_info; +	/** pointer to DSP's control cache. */ +	u8 *p_cache;  };  struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index); +  u16 hpi_add_adapter(struct hpi_adapter_obj *pao);  void hpi_delete_adapter(struct hpi_adapter_obj *pao); @@ -52,13 +56,12 @@ void hpi_delete_adapter(struct hpi_adapter_obj *pao);  short hpi_check_control_cache(struct hpi_control_cache *pC,  	struct hpi_message *phm, struct hpi_response *phr);  struct hpi_control_cache *hpi_alloc_control_cache(const u32 -	number_of_controls, const u32 size_in_bytes, -	struct hpi_control_cache_info -	*pDSP_control_buffer); +	number_of_controls, const u32 size_in_bytes, u8 *pDSP_control_buffer);  void hpi_free_control_cache(struct hpi_control_cache *p_cache); -void hpi_sync_control_cache(struct hpi_control_cache *pC, +void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *pC,  	struct hpi_message *phm, struct hpi_response *phr); +  u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr); -short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache, -	struct hpi_message *phm, void **p, unsigned int *pN); + +hpi_handler_func HPI_COMMON; diff --git a/sound/pci/asihpi/hpidebug.c b/sound/pci/asihpi/hpidebug.c index 949836ec913..ac86a1f1d3b 100644 --- a/sound/pci/asihpi/hpidebug.c +++ b/sound/pci/asihpi/hpidebug.c @@ -1,7 +1,7 @@  /************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -45,161 +45,14 @@ int hpi_debug_level_get(void)  	return hpi_debug_level;  } -#ifdef HPIOS_DEBUG_PRINT -/* implies OS has no printf-like function */ -#include <stdarg.h> - -void hpi_debug_printf(char *fmt, ...) -{ -	va_list arglist; -	char buffer[128]; - -	va_start(arglist, fmt); - -	if (buffer[0]) -		HPIOS_DEBUG_PRINT(buffer); -	va_end(arglist); -} -#endif - -struct treenode { -	void *array; -	unsigned int num_elements; -}; - -#define make_treenode_from_array(nodename, array) \ -static void *tmp_strarray_##nodename[] = array; \ -static struct treenode nodename = { \ -	&tmp_strarray_##nodename, \ -	ARRAY_SIZE(tmp_strarray_##nodename) \ -}; - -#define get_treenode_elem(node_ptr, idx, type)  \ -	(&(*((type *)(node_ptr)->array)[idx])) - -make_treenode_from_array(hpi_control_type_strings, HPI_CONTROL_TYPE_STRINGS) - -	make_treenode_from_array(hpi_subsys_strings, HPI_SUBSYS_STRINGS) -	make_treenode_from_array(hpi_adapter_strings, HPI_ADAPTER_STRINGS) -	make_treenode_from_array(hpi_istream_strings, HPI_ISTREAM_STRINGS) -	make_treenode_from_array(hpi_ostream_strings, HPI_OSTREAM_STRINGS) -	make_treenode_from_array(hpi_mixer_strings, HPI_MIXER_STRINGS) -	make_treenode_from_array(hpi_node_strings, -	{ -	"NODE is invalid object"}) - -	make_treenode_from_array(hpi_control_strings, HPI_CONTROL_STRINGS) -	make_treenode_from_array(hpi_nvmemory_strings, HPI_OBJ_STRINGS) -	make_treenode_from_array(hpi_digitalio_strings, HPI_DIGITALIO_STRINGS) -	make_treenode_from_array(hpi_watchdog_strings, HPI_WATCHDOG_STRINGS) -	make_treenode_from_array(hpi_clock_strings, HPI_CLOCK_STRINGS) -	make_treenode_from_array(hpi_profile_strings, HPI_PROFILE_STRINGS) -	make_treenode_from_array(hpi_asyncevent_strings, HPI_ASYNCEVENT_STRINGS) -#define HPI_FUNCTION_STRINGS \ -{ \ -  &hpi_subsys_strings,\ -  &hpi_adapter_strings,\ -  &hpi_ostream_strings,\ -  &hpi_istream_strings,\ -  &hpi_mixer_strings,\ -  &hpi_node_strings,\ -  &hpi_control_strings,\ -  &hpi_nvmemory_strings,\ -  &hpi_digitalio_strings,\ -  &hpi_watchdog_strings,\ -  &hpi_clock_strings,\ -  &hpi_profile_strings,\ -  &hpi_control_strings, \ -  &hpi_asyncevent_strings \ -} -	make_treenode_from_array(hpi_function_strings, HPI_FUNCTION_STRINGS) - -	compile_time_assert(HPI_OBJ_MAXINDEX == 14, obj_list_doesnt_match); - -static char *hpi_function_string(unsigned int function) -{ -	unsigned int object; -	struct treenode *tmp; - -	object = function / HPI_OBJ_FUNCTION_SPACING; -	function = function - object * HPI_OBJ_FUNCTION_SPACING; - -	if (object == 0 || object == HPI_OBJ_NODE -		|| object > hpi_function_strings.num_elements) -		return "invalid object"; - -	tmp = get_treenode_elem(&hpi_function_strings, object - 1, -		struct treenode *); - -	if (function == 0 || function > tmp->num_elements) -		return "invalid function"; - -	return get_treenode_elem(tmp, function - 1, char *); -} -  void hpi_debug_message(struct hpi_message *phm, char *sz_fileline)  {  	if (phm) { -		if ((phm->object <= HPI_OBJ_MAXINDEX) && phm->object) { -			u16 index = 0; -			u16 attrib = 0; -			int is_control = 0; - -			index = phm->obj_index; -			switch (phm->object) { -			case HPI_OBJ_ADAPTER: -			case HPI_OBJ_PROFILE: -				break; -			case HPI_OBJ_MIXER: -				if (phm->function == -					HPI_MIXER_GET_CONTROL_BY_INDEX) -					index = phm->u.m.control_index; -				break; -			case HPI_OBJ_OSTREAM: -			case HPI_OBJ_ISTREAM: -				break; - -			case HPI_OBJ_CONTROLEX: -			case HPI_OBJ_CONTROL: -				if (phm->version == 1) -					attrib = HPI_CTL_ATTR(UNIVERSAL, 1); -				else -					attrib = phm->u.c.attribute; -				is_control = 1; -				break; -			default: -				break; -			} - -			if (is_control && (attrib & 0xFF00)) { -				int control_type = (attrib & 0xFF00) >> 8; -				int attr_index = HPI_CTL_ATTR_INDEX(attrib); -				/* note the KERN facility level -				   is in szFileline already */ -				printk("%s adapter %d %s " -					"ctrl_index x%04x %s %d\n", -					sz_fileline, phm->adapter_index, -					hpi_function_string(phm->function), -					index, -					get_treenode_elem -					(&hpi_control_type_strings, -						control_type, char *), -					attr_index); - -			} else -				printk("%s adapter %d %s " -					"idx x%04x attr x%04x \n", -					sz_fileline, phm->adapter_index, -					hpi_function_string(phm->function), -					index, attrib); -		} else { -			printk("adap=%d, invalid obj=%d, func=0x%x\n", -				phm->adapter_index, phm->object, -				phm->function); -		} -	} else -		printk(KERN_ERR -			"NULL message pointer to hpi_debug_message!\n"); +		printk(KERN_DEBUG "HPI_MSG%d,%d,%d,%d,%d\n", phm->version, +			phm->adapter_index, phm->obj_index, phm->function, +			phm->u.c.attribute); +	} +  }  void hpi_debug_data(u16 *pdata, u32 len) diff --git a/sound/pci/asihpi/hpidebug.h b/sound/pci/asihpi/hpidebug.h index a2f0952a99f..2c9af2329d3 100644 --- a/sound/pci/asihpi/hpidebug.h +++ b/sound/pci/asihpi/hpidebug.h @@ -1,7 +1,7 @@  /*****************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -37,7 +37,7 @@ enum { HPI_DEBUG_LEVEL_ERROR = 0,	/* always log errors */  #define HPI_DEBUG_LEVEL_DEFAULT HPI_DEBUG_LEVEL_NOTICE  /* an OS can define an extra flag string that is appended to -   the start of each message, eg see hpios_linux.h */ +   the start of each message, eg see linux kernel hpios.h */  #ifdef SOURCEFILE_NAME  #define FILE_LINE  SOURCEFILE_NAME ":" __stringify(__LINE__) " " @@ -45,18 +45,11 @@ enum { HPI_DEBUG_LEVEL_ERROR = 0,	/* always log errors */  #define FILE_LINE  __FILE__ ":" __stringify(__LINE__) " "  #endif -#if defined(HPI_DEBUG) && defined(_WINDOWS) -#define HPI_DEBUGBREAK() debug_break() -#else -#define HPI_DEBUGBREAK() -#endif -  #define HPI_DEBUG_ASSERT(expression) \  	do { \ -		if (!(expression)) {\ -			printk(KERN_ERR  FILE_LINE\ -				"ASSERT " __stringify(expression));\ -			HPI_DEBUGBREAK();\ +		if (!(expression)) { \ +			printk(KERN_ERR  FILE_LINE \ +				"ASSERT " __stringify(expression)); \  		} \  	} while (0) @@ -78,28 +71,27 @@ void hpi_debug_message(struct hpi_message *phm, char *sz_fileline);  void hpi_debug_data(u16 *pdata, u32 len); -#define HPI_DEBUG_DATA(pdata, len)                                      \ -	do {                                                            \ +#define HPI_DEBUG_DATA(pdata, len) \ +	do { \  		if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \  			hpi_debug_data(pdata, len); \  	} while (0) -#define HPI_DEBUG_MESSAGE(level, phm)                                   \ -	do {                                                            \ -		if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) {         \ -			hpi_debug_message(phm,HPI_DEBUG_FLAG_##level    \ -				FILE_LINE __stringify(level));\ -		}                                                       \ +#define HPI_DEBUG_MESSAGE(level, phm) \ +	do { \ +		if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \ +			hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \ +				FILE_LINE __stringify(level)); \ +		} \  	} while (0) -#define HPI_DEBUG_RESPONSE(phr)                                         \ -	do {                                                            \ -		if ((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && (phr->error))\ -			HPI_DEBUG_LOG(ERROR, \ -				"HPI response - error# %d\n", \ -				phr->error); \ -		else if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \ -			HPI_DEBUG_LOG(VERBOSE, "HPI response OK\n");\ +#define HPI_DEBUG_RESPONSE(phr) \ +	do { \ +		if (((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && \ +			(phr->error)) ||\ +		(hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)) \ +			printk(KERN_DEBUG "HPI_RES%d,%d,%d\n", \ +				phr->version, phr->error, phr->specific_error); \  	} while (0)  #ifndef compile_time_assert @@ -107,279 +99,4 @@ void hpi_debug_data(u16 *pdata, u32 len);      typedef char msg[(cond) ? 1 : -1]  #endif -	  /* check that size is exactly some number */ -#define function_count_check(sym, size) \ -    compile_time_assert((sym##_FUNCTION_COUNT) == (size),\ -	    strings_match_defs_##sym) - -/* These strings should be generated using a macro which defines -   the corresponding symbol values.  */ -#define HPI_OBJ_STRINGS \ -{                               \ -  "HPI_OBJ_SUBSYSTEM",        \ -  "HPI_OBJ_ADAPTER",          \ -  "HPI_OBJ_OSTREAM",          \ -  "HPI_OBJ_ISTREAM",          \ -  "HPI_OBJ_MIXER",            \ -  "HPI_OBJ_NODE",             \ -  "HPI_OBJ_CONTROL",          \ -  "HPI_OBJ_NVMEMORY",         \ -  "HPI_OBJ_DIGITALIO",        \ -  "HPI_OBJ_WATCHDOG",         \ -  "HPI_OBJ_CLOCK",            \ -  "HPI_OBJ_PROFILE",          \ -  "HPI_OBJ_CONTROLEX"         \ -} - -#define HPI_SUBSYS_STRINGS      \ -{                               \ -  "HPI_SUBSYS_OPEN",          \ -  "HPI_SUBSYS_GET_VERSION",   \ -  "HPI_SUBSYS_GET_INFO",      \ -  "HPI_SUBSYS_FIND_ADAPTERS", \ -  "HPI_SUBSYS_CREATE_ADAPTER",\ -  "HPI_SUBSYS_CLOSE",         \ -  "HPI_SUBSYS_DELETE_ADAPTER", \ -  "HPI_SUBSYS_DRIVER_LOAD", \ -  "HPI_SUBSYS_DRIVER_UNLOAD", \ -  "HPI_SUBSYS_READ_PORT_8",   \ -  "HPI_SUBSYS_WRITE_PORT_8",  \ -  "HPI_SUBSYS_GET_NUM_ADAPTERS",\ -  "HPI_SUBSYS_GET_ADAPTER",   \ -  "HPI_SUBSYS_SET_NETWORK_INTERFACE"\ -} -function_count_check(HPI_SUBSYS, 14); - -#define HPI_ADAPTER_STRINGS     \ -{                               \ -  "HPI_ADAPTER_OPEN",         \ -  "HPI_ADAPTER_CLOSE",        \ -  "HPI_ADAPTER_GET_INFO",     \ -  "HPI_ADAPTER_GET_ASSERT",   \ -  "HPI_ADAPTER_TEST_ASSERT",    \ -  "HPI_ADAPTER_SET_MODE",       \ -  "HPI_ADAPTER_GET_MODE",       \ -  "HPI_ADAPTER_ENABLE_CAPABILITY",\ -  "HPI_ADAPTER_SELFTEST",        \ -  "HPI_ADAPTER_FIND_OBJECT",     \ -  "HPI_ADAPTER_QUERY_FLASH",     \ -  "HPI_ADAPTER_START_FLASH",     \ -  "HPI_ADAPTER_PROGRAM_FLASH",   \ -  "HPI_ADAPTER_SET_PROPERTY",    \ -  "HPI_ADAPTER_GET_PROPERTY",    \ -  "HPI_ADAPTER_ENUM_PROPERTY",    \ -  "HPI_ADAPTER_MODULE_INFO",    \ -  "HPI_ADAPTER_DEBUG_READ"    \ -} - -function_count_check(HPI_ADAPTER, 18); - -#define HPI_OSTREAM_STRINGS     \ -{                               \ -  "HPI_OSTREAM_OPEN",         \ -  "HPI_OSTREAM_CLOSE",        \ -  "HPI_OSTREAM_WRITE",        \ -  "HPI_OSTREAM_START",        \ -  "HPI_OSTREAM_STOP",         \ -  "HPI_OSTREAM_RESET",                \ -  "HPI_OSTREAM_GET_INFO",     \ -  "HPI_OSTREAM_QUERY_FORMAT", \ -  "HPI_OSTREAM_DATA",         \ -  "HPI_OSTREAM_SET_VELOCITY", \ -  "HPI_OSTREAM_SET_PUNCHINOUT", \ -  "HPI_OSTREAM_SINEGEN",        \ -  "HPI_OSTREAM_ANC_RESET",      \ -  "HPI_OSTREAM_ANC_GET_INFO",   \ -  "HPI_OSTREAM_ANC_READ",       \ -  "HPI_OSTREAM_SET_TIMESCALE",\ -  "HPI_OSTREAM_SET_FORMAT", \ -  "HPI_OSTREAM_HOSTBUFFER_ALLOC", \ -  "HPI_OSTREAM_HOSTBUFFER_FREE", \ -  "HPI_OSTREAM_GROUP_ADD",\ -  "HPI_OSTREAM_GROUP_GETMAP", \ -  "HPI_OSTREAM_GROUP_RESET", \ -  "HPI_OSTREAM_HOSTBUFFER_GET_INFO", \ -  "HPI_OSTREAM_WAIT_START", \ -} -function_count_check(HPI_OSTREAM, 24); - -#define HPI_ISTREAM_STRINGS     \ -{                               \ -  "HPI_ISTREAM_OPEN",         \ -  "HPI_ISTREAM_CLOSE",        \ -  "HPI_ISTREAM_SET_FORMAT",   \ -  "HPI_ISTREAM_READ",         \ -  "HPI_ISTREAM_START",        \ -  "HPI_ISTREAM_STOP",         \ -  "HPI_ISTREAM_RESET",        \ -  "HPI_ISTREAM_GET_INFO",     \ -  "HPI_ISTREAM_QUERY_FORMAT", \ -  "HPI_ISTREAM_ANC_RESET",      \ -  "HPI_ISTREAM_ANC_GET_INFO",   \ -  "HPI_ISTREAM_ANC_WRITE",   \ -  "HPI_ISTREAM_HOSTBUFFER_ALLOC",\ -  "HPI_ISTREAM_HOSTBUFFER_FREE", \ -  "HPI_ISTREAM_GROUP_ADD", \ -  "HPI_ISTREAM_GROUP_GETMAP", \ -  "HPI_ISTREAM_GROUP_RESET", \ -  "HPI_ISTREAM_HOSTBUFFER_GET_INFO", \ -  "HPI_ISTREAM_WAIT_START", \ -} -function_count_check(HPI_ISTREAM, 19); - -#define HPI_MIXER_STRINGS       \ -{                               \ -  "HPI_MIXER_OPEN",           \ -  "HPI_MIXER_CLOSE",          \ -  "HPI_MIXER_GET_INFO",       \ -  "HPI_MIXER_GET_NODE_INFO",  \ -  "HPI_MIXER_GET_CONTROL",    \ -  "HPI_MIXER_SET_CONNECTION", \ -  "HPI_MIXER_GET_CONNECTIONS",        \ -  "HPI_MIXER_GET_CONTROL_BY_INDEX",   \ -  "HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX",     \ -  "HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES",    \ -  "HPI_MIXER_STORE",  \ -} -function_count_check(HPI_MIXER, 11); - -#define HPI_CONTROL_STRINGS     \ -{                               \ -  "HPI_CONTROL_GET_INFO",     \ -  "HPI_CONTROL_GET_STATE",    \ -  "HPI_CONTROL_SET_STATE"     \ -} -function_count_check(HPI_CONTROL, 3); - -#define HPI_NVMEMORY_STRINGS    \ -{                               \ -  "HPI_NVMEMORY_OPEN",        \ -  "HPI_NVMEMORY_READ_BYTE",   \ -  "HPI_NVMEMORY_WRITE_BYTE"   \ -} -function_count_check(HPI_NVMEMORY, 3); - -#define HPI_DIGITALIO_STRINGS   \ -{                               \ -  "HPI_GPIO_OPEN",            \ -  "HPI_GPIO_READ_BIT",        \ -  "HPI_GPIO_WRITE_BIT",       \ -  "HPI_GPIO_READ_ALL",                \ -  "HPI_GPIO_WRITE_STATUS"\ -} -function_count_check(HPI_GPIO, 5); - -#define HPI_WATCHDOG_STRINGS    \ -{                               \ -  "HPI_WATCHDOG_OPEN",        \ -  "HPI_WATCHDOG_SET_TIME",    \ -  "HPI_WATCHDOG_PING"         \ -} - -#define HPI_CLOCK_STRINGS       \ -{                               \ -  "HPI_CLOCK_OPEN",           \ -  "HPI_CLOCK_SET_TIME",       \ -  "HPI_CLOCK_GET_TIME"        \ -} - -#define HPI_PROFILE_STRINGS     \ -{                               \ -  "HPI_PROFILE_OPEN_ALL",     \ -  "HPI_PROFILE_START_ALL",    \ -  "HPI_PROFILE_STOP_ALL",     \ -  "HPI_PROFILE_GET",          \ -  "HPI_PROFILE_GET_IDLECOUNT",  \ -  "HPI_PROFILE_GET_NAME",       \ -  "HPI_PROFILE_GET_UTILIZATION" \ -} -function_count_check(HPI_PROFILE, 7); - -#define HPI_ASYNCEVENT_STRINGS  \ -{                               \ -  "HPI_ASYNCEVENT_OPEN",\ -  "HPI_ASYNCEVENT_CLOSE  ",\ -  "HPI_ASYNCEVENT_WAIT",\ -  "HPI_ASYNCEVENT_GETCOUNT",\ -  "HPI_ASYNCEVENT_GET",\ -  "HPI_ASYNCEVENT_SENDEVENTS"\ -} -function_count_check(HPI_ASYNCEVENT, 6); - -#define HPI_CONTROL_TYPE_STRINGS \ -{ \ -	"null control", \ -	"HPI_CONTROL_CONNECTION", \ -	"HPI_CONTROL_VOLUME", \ -	"HPI_CONTROL_METER", \ -	"HPI_CONTROL_MUTE", \ -	"HPI_CONTROL_MULTIPLEXER", \ -	"HPI_CONTROL_AESEBU_TRANSMITTER", \ -	"HPI_CONTROL_AESEBU_RECEIVER", \ -	"HPI_CONTROL_LEVEL", \ -	"HPI_CONTROL_TUNER", \ -	"HPI_CONTROL_ONOFFSWITCH", \ -	"HPI_CONTROL_VOX", \ -	"HPI_CONTROL_AES18_TRANSMITTER", \ -	"HPI_CONTROL_AES18_RECEIVER", \ -	"HPI_CONTROL_AES18_BLOCKGENERATOR", \ -	"HPI_CONTROL_CHANNEL_MODE", \ -	"HPI_CONTROL_BITSTREAM", \ -	"HPI_CONTROL_SAMPLECLOCK", \ -	"HPI_CONTROL_MICROPHONE", \ -	"HPI_CONTROL_PARAMETRIC_EQ", \ -	"HPI_CONTROL_COMPANDER", \ -	"HPI_CONTROL_COBRANET", \ -	"HPI_CONTROL_TONE_DETECT", \ -	"HPI_CONTROL_SILENCE_DETECT", \ -	"HPI_CONTROL_PAD", \ -	"HPI_CONTROL_SRC" ,\ -	"HPI_CONTROL_UNIVERSAL" \ -} - -compile_time_assert((HPI_CONTROL_LAST_INDEX + 1 == 27), -	controltype_strings_match_defs); - -#define HPI_SOURCENODE_STRINGS \ -{ \ -	"no source", \ -	"HPI_SOURCENODE_OSTREAM", \ -	"HPI_SOURCENODE_LINEIN", \ -	"HPI_SOURCENODE_AESEBU_IN", \ -	"HPI_SOURCENODE_TUNER", \ -	"HPI_SOURCENODE_RF", \ -	"HPI_SOURCENODE_CLOCK_SOURCE", \ -	"HPI_SOURCENODE_RAW_BITSTREAM", \ -	"HPI_SOURCENODE_MICROPHONE", \ -	"HPI_SOURCENODE_COBRANET", \ -	"HPI_SOURCENODE_ANALOG", \ -	"HPI_SOURCENODE_ADAPTER" \ -} - -compile_time_assert((HPI_SOURCENODE_LAST_INDEX - HPI_SOURCENODE_NONE + 1) == -	(12), sourcenode_strings_match_defs); - -#define HPI_DESTNODE_STRINGS \ -{ \ -	"no destination", \ -	"HPI_DESTNODE_ISTREAM", \ -	"HPI_DESTNODE_LINEOUT", \ -	"HPI_DESTNODE_AESEBU_OUT", \ -	"HPI_DESTNODE_RF", \ -	"HPI_DESTNODE_SPEAKER", \ -	"HPI_DESTNODE_COBRANET", \ -	"HPI_DESTNODE_ANALOG" \ -} -compile_time_assert((HPI_DESTNODE_LAST_INDEX - HPI_DESTNODE_NONE + 1) == (8), -	destnode_strings_match_defs); - -#define HPI_CONTROL_CHANNEL_MODE_STRINGS \ -{ \ -	"XXX HPI_CHANNEL_MODE_ERROR XXX", \ -	"HPI_CHANNEL_MODE_NORMAL", \ -	"HPI_CHANNEL_MODE_SWAP", \ -	"HPI_CHANNEL_MODE_LEFT_ONLY", \ -	"HPI_CHANNEL_MODE_RIGHT_ONLY" \ -} - -#endif				/* _HPIDEBUG_H  */ +#endif				/* _HPIDEBUG_H_  */ diff --git a/sound/pci/asihpi/hpidspcd.c b/sound/pci/asihpi/hpidspcd.c index 9b10d9a5c25..ac916377001 100644 --- a/sound/pci/asihpi/hpidspcd.c +++ b/sound/pci/asihpi/hpidspcd.c @@ -1,8 +1,8 @@  /***********************************************************************/ -/*! +/**      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -18,155 +18,127 @@      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  \file -Functions for reading DSP code to load into DSP - -(Linux only:) If DSPCODE_FIRMWARE_LOADER is defined, code is read using +Functions for reading DSP code using  hotplug firmware loader from individual dsp code files - -If neither of the above is defined, code is read from linked arrays. -DSPCODE_ARRAY is defined. - -HPI_INCLUDE_**** must be defined -and the appropriate hzz?????.c or hex?????.c linked in - - */ +*/  /***********************************************************************/  #define SOURCEFILE_NAME "hpidspcd.c"  #include "hpidspcd.h"  #include "hpidebug.h" +#include "hpi_version.h" -/** - Header structure for binary dsp code file (see asidsp.doc) - This structure must match that used in s2bin.c for generation of asidsp.bin - */ - -#ifndef DISABLE_PRAGMA_PACK1 -#pragma pack(push, 1) -#endif - -struct code_header { -	u32 size; -	char type[4]; -	u32 adapter; -	u32 version; -	u32 crc; +struct dsp_code_private { +	/**  Firmware descriptor */ +	const struct firmware *firmware; +	struct pci_dev *dev;  }; -#ifndef DISABLE_PRAGMA_PACK1 -#pragma pack(pop) -#endif - -#define HPI_VER_DECIMAL ((int)(HPI_VER_MAJOR(HPI_VER) * 10000 + \ -	    HPI_VER_MINOR(HPI_VER) * 100 + HPI_VER_RELEASE(HPI_VER))) - -/***********************************************************************/ -#include "linux/pci.h"  /*-------------------------------------------------------------------*/ -short hpi_dsp_code_open(u32 adapter, struct dsp_code *ps_dsp_code, -	u32 *pos_error_code) +short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code, +	u32 *os_error_code)  { -	const struct firmware *ps_firmware = ps_dsp_code->ps_firmware; +	const struct firmware *firmware; +	struct pci_dev *dev = os_data;  	struct code_header header;  	char fw_name[20]; +	short err_ret = HPI_ERROR_DSP_FILE_NOT_FOUND;  	int err;  	sprintf(fw_name, "asihpi/dsp%04x.bin", adapter); -	HPI_DEBUG_LOG(INFO, "requesting firmware for %s\n", fw_name); -	err = request_firmware(&ps_firmware, fw_name, -		&ps_dsp_code->ps_dev->dev); -	if (err != 0) { -		HPI_DEBUG_LOG(ERROR, "%d, request_firmware failed for  %s\n", +	err = request_firmware(&firmware, fw_name, &dev->dev); + +	if (err || !firmware) { +		dev_err(&dev->dev, "%d, request_firmware failed for %s\n",  			err, fw_name);  		goto error1;  	} -	if (ps_firmware->size < sizeof(header)) { -		HPI_DEBUG_LOG(ERROR, "header size too small %s\n", fw_name); +	if (firmware->size < sizeof(header)) { +		dev_err(&dev->dev, "Header size too small %s\n", fw_name);  		goto error2;  	} -	memcpy(&header, ps_firmware->data, sizeof(header)); -	if (header.adapter != adapter) { -		HPI_DEBUG_LOG(ERROR, "adapter type incorrect %4x != %4x\n", -			header.adapter, adapter); +	memcpy(&header, firmware->data, sizeof(header)); + +	if ((header.type != 0x45444F43) ||	/* "CODE" */ +		(header.adapter != adapter) +		|| (header.size != firmware->size)) { +		dev_err(&dev->dev, +			"Invalid firmware header size %d != file %zd\n", +			header.size, firmware->size);  		goto error2;  	} -	if (header.size != ps_firmware->size) { -		HPI_DEBUG_LOG(ERROR, "code size wrong  %d != %ld\n", -			header.size, (unsigned long)ps_firmware->size); + +	if ((header.version >> 9) != (HPI_VER >> 9)) { +		/* Consider even and subsequent odd minor versions to be compatible */ +		dev_err(&dev->dev, "Incompatible firmware version DSP image %X != Driver %X\n", +			header.version, HPI_VER);  		goto error2;  	} -	if (header.version / 10000 != HPI_VER_DECIMAL / 10000) { -		HPI_DEBUG_LOG(ERROR, -			"firmware major version mismatch " -			"DSP image %d != driver %d\n", header.version, -			HPI_VER_DECIMAL); -		goto error2; +	if (header.version != HPI_VER) { +		dev_info(&dev->dev, +			 "Firmware: release version mismatch  DSP image %X != Driver %X\n", +			 header.version, HPI_VER);  	} -	if (header.version != HPI_VER_DECIMAL) { -		HPI_DEBUG_LOG(WARNING, -			"version mismatch  DSP image %d != driver %d\n", -			header.version, HPI_VER_DECIMAL); -		/* goto error2;  still allow driver to load */ +	HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name); +	dsp_code->pvt = kmalloc(sizeof(*dsp_code->pvt), GFP_KERNEL); +	if (!dsp_code->pvt) { +		err_ret = HPI_ERROR_MEMORY_ALLOC; +		goto error2;  	} -	HPI_DEBUG_LOG(INFO, "dsp code %s opened\n", fw_name); -	ps_dsp_code->ps_firmware = ps_firmware; -	ps_dsp_code->block_length = header.size / sizeof(u32); -	ps_dsp_code->word_count = sizeof(header) / sizeof(u32); -	ps_dsp_code->version = header.version; -	ps_dsp_code->crc = header.crc; +	dsp_code->pvt->dev = dev; +	dsp_code->pvt->firmware = firmware; +	dsp_code->header = header; +	dsp_code->block_length = header.size / sizeof(u32); +	dsp_code->word_count = sizeof(header) / sizeof(u32);  	return 0;  error2: -	release_firmware(ps_firmware); +	release_firmware(firmware);  error1: -	ps_dsp_code->ps_firmware = NULL; -	ps_dsp_code->block_length = 0; -	return HPI_ERROR_DSP_FILE_NOT_FOUND; +	dsp_code->block_length = 0; +	return err_ret;  }  /*-------------------------------------------------------------------*/ -void hpi_dsp_code_close(struct dsp_code *ps_dsp_code) +void hpi_dsp_code_close(struct dsp_code *dsp_code)  { -	if (ps_dsp_code->ps_firmware != NULL) { -		HPI_DEBUG_LOG(DEBUG, "dsp code closed\n"); -		release_firmware(ps_dsp_code->ps_firmware); -		ps_dsp_code->ps_firmware = NULL; -	} +	HPI_DEBUG_LOG(DEBUG, "dsp code closed\n"); +	release_firmware(dsp_code->pvt->firmware); +	kfree(dsp_code->pvt);  }  /*-------------------------------------------------------------------*/ -void hpi_dsp_code_rewind(struct dsp_code *ps_dsp_code) +void hpi_dsp_code_rewind(struct dsp_code *dsp_code)  {  	/* Go back to start of  data, after header */ -	ps_dsp_code->word_count = sizeof(struct code_header) / sizeof(u32); +	dsp_code->word_count = sizeof(struct code_header) / sizeof(u32);  }  /*-------------------------------------------------------------------*/ -short hpi_dsp_code_read_word(struct dsp_code *ps_dsp_code, u32 *pword) +short hpi_dsp_code_read_word(struct dsp_code *dsp_code, u32 *pword)  { -	if (ps_dsp_code->word_count + 1 > ps_dsp_code->block_length) -		return (HPI_ERROR_DSP_FILE_FORMAT); +	if (dsp_code->word_count + 1 > dsp_code->block_length) +		return HPI_ERROR_DSP_FILE_FORMAT; -	*pword = ((u32 *)(ps_dsp_code->ps_firmware->data))[ps_dsp_code-> +	*pword = ((u32 *)(dsp_code->pvt->firmware->data))[dsp_code->  		word_count]; -	ps_dsp_code->word_count++; +	dsp_code->word_count++;  	return 0;  }  /*-------------------------------------------------------------------*/  short hpi_dsp_code_read_block(size_t words_requested, -	struct dsp_code *ps_dsp_code, u32 **ppblock) +	struct dsp_code *dsp_code, u32 **ppblock)  { -	if (ps_dsp_code->word_count + words_requested > -		ps_dsp_code->block_length) +	if (dsp_code->word_count + words_requested > dsp_code->block_length)  		return HPI_ERROR_DSP_FILE_FORMAT;  	*ppblock = -		((u32 *)(ps_dsp_code->ps_firmware->data)) + -		ps_dsp_code->word_count; -	ps_dsp_code->word_count += words_requested; +		((u32 *)(dsp_code->pvt->firmware->data)) + +		dsp_code->word_count; +	dsp_code->word_count += words_requested;  	return 0;  } diff --git a/sound/pci/asihpi/hpidspcd.h b/sound/pci/asihpi/hpidspcd.h index d7c24039822..659d19ca6d4 100644 --- a/sound/pci/asihpi/hpidspcd.h +++ b/sound/pci/asihpi/hpidspcd.h @@ -2,7 +2,7 @@  /**      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -20,19 +20,6 @@  \file  Functions for reading DSP code to load into DSP - hpi_dspcode_defines HPI DSP code loading method -Define exactly one of these to select how the DSP code is supplied to -the adapter. - -End users writing applications that use the HPI interface do not have to -use any of the below defines; they are only necessary for building drivers - -HPI_DSPCODE_FILE: -DSP code is supplied as a file that is opened and read from by the driver. - -HPI_DSPCODE_FIRMWARE: -DSP code is read using the hotplug firmware loader module. -     Only valid when compiling the HPI kernel driver under Linux.  */  /***********************************************************************/  #ifndef _HPIDSPCD_H_ @@ -40,37 +27,52 @@ DSP code is read using the hotplug firmware loader module.  #include "hpi_internal.h" -#ifndef DISABLE_PRAGMA_PACK1 -#pragma pack(push, 1) -#endif +/** Header structure for dsp firmware file + This structure must match that used in s2bin.c for generation of asidsp.bin + */ +/*#ifndef DISABLE_PRAGMA_PACK1 */ +/*#pragma pack(push, 1) */ +/*#endif */ +struct code_header { +	/** Size in bytes including header */ +	u32 size; +	/** File type tag "CODE" == 0x45444F43 */ +	u32 type; +	/** Adapter model number */ +	u32 adapter; +	/** Firmware version*/ +	u32 version; +	/** Data checksum */ +	u32 checksum; +}; +/*#ifndef DISABLE_PRAGMA_PACK1 */ +/*#pragma pack(pop) */ +/*#endif */ + +/*? Don't need the pragmas? */ +compile_time_assert((sizeof(struct code_header) == 20), code_header_size);  /** Descriptor for dspcode from firmware loader */  struct dsp_code { -	/**  Firmware descriptor */ -	const struct firmware *ps_firmware; -	struct pci_dev *ps_dev; +	/** copy of  file header */ +	struct code_header header;  	/** Expected number of words in the whole dsp code,INCL header */ -	long int block_length; +	u32 block_length;  	/** Number of words read so far */ -	long int word_count; -	/** Version read from dsp code file */ -	u32 version; -	/** CRC read from dsp code file */ -	u32 crc; -}; +	u32 word_count; -#ifndef DISABLE_PRAGMA_PACK1 -#pragma pack(pop) -#endif +	/** internal state of DSP code reader */ +	struct dsp_code_private *pvt; +}; -/** Prepare *psDspCode to refer to the requuested adapter. - Searches the file, or selects the appropriate linked array +/** Prepare *psDspCode to refer to the requested adapter's firmware. +Code file name is obtained from HpiOs_GetDspCodePath  \return 0 for success, or error code if requested code is not available  */  short hpi_dsp_code_open(  	/** Code identifier, usually adapter family */ -	u32 adapter, +	u32 adapter, void *pci_dev,  	/** Pointer to DSP code control structure */  	struct dsp_code *ps_dsp_code,  	/** Pointer to dword to receive OS specific error code */ @@ -87,7 +89,7 @@ void hpi_dsp_code_rewind(struct dsp_code *ps_dsp_code);  */  short hpi_dsp_code_read_word(struct dsp_code *ps_dsp_code,  				      /**< DSP code descriptor */ -	u32 *pword /**< where to store the read word */ +	u32 *pword /**< Where to store the read word */  	);  /** Get a block of dsp code into an internal buffer, and provide a pointer to diff --git a/sound/pci/asihpi/hpifunc.c b/sound/pci/asihpi/hpifunc.c index 1e92eb6dd50..510e56cffd3 100644 --- a/sound/pci/asihpi/hpifunc.c +++ b/sound/pci/asihpi/hpifunc.c @@ -30,16 +30,25 @@ u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,  	return handle.w;  } -void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index, -	u16 *pw_object_index) +static u16 hpi_handle_indexes(const u32 h, u16 *p1, u16 *p2)  {  	union handle_word uhandle; -	uhandle.w = handle; +	if (!h) +		return HPI_ERROR_INVALID_HANDLE; + +	uhandle.w = h; + +	*p1 = (u16)uhandle.h.adapter_index; +	if (p2) +		*p2 = (u16)uhandle.h.obj_index; -	if (pw_adapter_index) -		*pw_adapter_index = (u16)uhandle.h.adapter_index; -	if (pw_object_index) -		*pw_object_index = (u16)uhandle.h.obj_index; +	return 0; +} + +void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index, +	u16 *pw_object_index) +{ +	hpi_handle_indexes(handle, pw_adapter_index, pw_object_index);  }  char hpi_handle_object(const u32 handle) @@ -49,22 +58,6 @@ char hpi_handle_object(const u32 handle)  	return (char)uhandle.h.obj_type;  } -#define u32TOINDEX(h, i1) \ -do {\ -	if (h == 0) \ -		return HPI_ERROR_INVALID_OBJ; \ -	else \ -		hpi_handle_to_indexes(h, i1, NULL); \ -} while (0) - -#define u32TOINDEXES(h, i1, i2) \ -do {\ -	if (h == 0) \ -		return HPI_ERROR_INVALID_OBJ; \ -	else \ -		hpi_handle_to_indexes(h, i1, i2);\ -} while (0) -  void hpi_format_to_msg(struct hpi_msg_format *pMF,  	const struct hpi_format *pF)  { @@ -94,52 +87,13 @@ void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)  	pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;  } -static struct hpi_hsubsys gh_subsys; - -struct hpi_hsubsys *hpi_subsys_create(void) -{ -	struct hpi_message hm; -	struct hpi_response hr; - -	memset(&gh_subsys, 0, sizeof(struct hpi_hsubsys)); - -	{ -		hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -			HPI_SUBSYS_OPEN); -		hpi_send_recv(&hm, &hr); - -		if (hr.error == 0) -			return &gh_subsys; - -	} -	return NULL; -} - -void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys) +static inline void hpi_send_recvV1(struct hpi_message_header *m, +	struct hpi_response_header *r)  { -	struct hpi_message hm; -	struct hpi_response hr; - -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_CLOSE); -	hpi_send_recv(&hm, &hr); - +	hpi_send_recv((struct hpi_message *)m, (struct hpi_response *)r);  } -u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, u32 *pversion) -{ -	struct hpi_message hm; -	struct hpi_response hr; - -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_GET_VERSION); -	hpi_send_recv(&hm, &hr); -	*pversion = hr.u.s.version; -	return hr.error; -} - -u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys, -	u32 *pversion_ex) +u16 hpi_subsys_get_version_ex(u32 *pversion_ex)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -151,79 +105,7 @@ u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion, -	u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_GET_INFO); - -	hpi_send_recv(&hm, &hr); - -	*pversion = hr.u.s.version; -	if (list_length > HPI_MAX_ADAPTERS) -		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, -			HPI_MAX_ADAPTERS); -	else -		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, list_length); -	*pw_num_adapters = hr.u.s.num_adapters; -	return hr.error; -} - -u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys, -	u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_FIND_ADAPTERS); - -	hpi_send_recv(&hm, &hr); - -	if (list_length > HPI_MAX_ADAPTERS) { -		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, -			HPI_MAX_ADAPTERS * sizeof(u16)); -		memset(&aw_adapter_list[HPI_MAX_ADAPTERS], 0, -			(list_length - HPI_MAX_ADAPTERS) * sizeof(u16)); -	} else -		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, -			list_length * sizeof(u16)); -	*pw_num_adapters = hr.u.s.num_adapters; - -	return hr.error; -} - -u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys, -	const struct hpi_resource *p_resource, u16 *pw_adapter_index) -{ -	struct hpi_message hm; -	struct hpi_response hr; - -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_CREATE_ADAPTER); -	hm.u.s.resource = *p_resource; - -	hpi_send_recv(&hm, &hr); - -	*pw_adapter_index = hr.u.s.adapter_index; -	return hr.error; -} - -u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_DELETE_ADAPTER); -	hm.adapter_index = adapter_index; -	hpi_send_recv(&hm, &hr); -	return hr.error; -} - -u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys, -	int *pn_num_adapters) +u16 hpi_subsys_get_num_adapters(int *pn_num_adapters)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -234,35 +116,22 @@ u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator, -	u32 *padapter_index, u16 *pw_adapter_type) +u16 hpi_subsys_get_adapter(int iterator, u32 *padapter_index, +	u16 *pw_adapter_type)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,  		HPI_SUBSYS_GET_ADAPTER); -	hm.adapter_index = (u16)iterator; +	hm.obj_index = (u16)iterator;  	hpi_send_recv(&hm, &hr);  	*padapter_index = (int)hr.u.s.adapter_index; -	*pw_adapter_type = hr.u.s.aw_adapter_list[0]; -	return hr.error; -} +	*pw_adapter_type = hr.u.s.adapter_type; -u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys, -	const char *sz_interface) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_SET_NETWORK_INTERFACE); -	if (sz_interface == NULL) -		return HPI_ERROR_INVALID_RESOURCE; -	hm.u.s.resource.r.net_if = sz_interface; -	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index) +u16 hpi_adapter_open(u16 adapter_index)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -276,7 +145,7 @@ u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)  } -u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index) +u16 hpi_adapter_close(u16 adapter_index)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -289,15 +158,14 @@ u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)  	return hr.error;  } -u16 hpi_adapter_set_mode(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 adapter_mode) +u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode)  { -	return hpi_adapter_set_mode_ex(ph_subsys, adapter_index, adapter_mode, +	return hpi_adapter_set_mode_ex(adapter_index, adapter_mode,  		HPI_ADAPTER_MODE_SET);  } -u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 adapter_mode, u16 query_or_set) +u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode, +	u16 query_or_set)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -305,14 +173,13 @@ u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,  		HPI_ADAPTER_SET_MODE);  	hm.adapter_index = adapter_index; -	hm.u.a.adapter_mode = adapter_mode; -	hm.u.a.assert_id = query_or_set; +	hm.u.ax.mode.adapter_mode = adapter_mode; +	hm.u.ax.mode.query_or_set = query_or_set;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 *padapter_mode) +u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -321,13 +188,13 @@ u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,  	hm.adapter_index = adapter_index;  	hpi_send_recv(&hm, &hr);  	if (padapter_mode) -		*padapter_mode = hr.u.a.serial_number; +		*padapter_mode = hr.u.ax.mode.adapter_mode;  	return hr.error;  } -u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 *pw_num_outstreams, u16 *pw_num_instreams, -	u16 *pw_version, u32 *pserial_number, u16 *pw_adapter_type) +u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams, +	u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number, +	u16 *pw_adapter_type)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -337,18 +204,17 @@ u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,  	hpi_send_recv(&hm, &hr); -	*pw_adapter_type = hr.u.a.adapter_type; -	*pw_num_outstreams = hr.u.a.num_outstreams; -	*pw_num_instreams = hr.u.a.num_instreams; -	*pw_version = hr.u.a.version; -	*pserial_number = hr.u.a.serial_number; +	*pw_adapter_type = hr.u.ax.info.adapter_type; +	*pw_num_outstreams = hr.u.ax.info.num_outstreams; +	*pw_num_instreams = hr.u.ax.info.num_instreams; +	*pw_version = hr.u.ax.info.version; +	*pserial_number = hr.u.ax.info.serial_number;  	return hr.error;  } -u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 module_index, u16 *pw_num_outputs, -	u16 *pw_num_inputs, u16 *pw_version, u32 *pserial_number, -	u16 *pw_module_type, u32 *ph_module) +u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index, +	u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version, +	u32 *pserial_number, u16 *pw_module_type, u32 *ph_module)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -360,173 +226,18 @@ u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,  	hpi_send_recv(&hm, &hr); -	*pw_module_type = hr.u.a.adapter_type; -	*pw_num_outputs = hr.u.a.num_outstreams; -	*pw_num_inputs = hr.u.a.num_instreams; -	*pw_version = hr.u.a.version; -	*pserial_number = hr.u.a.serial_number; +	*pw_module_type = hr.u.ax.info.adapter_type; +	*pw_num_outputs = hr.u.ax.info.num_outstreams; +	*pw_num_inputs = hr.u.ax.info.num_instreams; +	*pw_version = hr.u.ax.info.version; +	*pserial_number = hr.u.ax.info.serial_number;  	*ph_module = 0;  	return hr.error;  } -u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 *assert_present, char *psz_assert, -	u16 *pw_line_number) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, -		HPI_ADAPTER_GET_ASSERT); -	hm.adapter_index = adapter_index; -	hpi_send_recv(&hm, &hr); - -	*assert_present = 0; - -	if (!hr.error) { - -		*pw_line_number = (u16)hr.u.a.serial_number; -		if (*pw_line_number) { - -			int i; -			char *src = (char *)hr.u.a.sz_adapter_assert; -			char *dst = psz_assert; - -			*assert_present = 1; - -			for (i = 0; i < HPI_STRING_LEN; i++) { -				char c; -				c = *src++; -				*dst++ = c; -				if (c == 0) -					break; -			} - -		} -	} -	return hr.error; -} - -u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 *assert_present, char *psz_assert, -	u32 *pline_number, u16 *pw_assert_on_dsp) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, -		HPI_ADAPTER_GET_ASSERT); -	hm.adapter_index = adapter_index; - -	hpi_send_recv(&hm, &hr); - -	*assert_present = 0; - -	if (!hr.error) { - -		*pline_number = hr.u.a.serial_number; - -		*assert_present = hr.u.a.adapter_type; - -		*pw_assert_on_dsp = hr.u.a.adapter_index; - -		if (!*assert_present && *pline_number) - -			*assert_present = 1; - -		if (*assert_present) { - -			int i; -			char *src = (char *)hr.u.a.sz_adapter_assert; -			char *dst = psz_assert; - -			for (i = 0; i < HPI_STRING_LEN; i++) { -				char c; -				c = *src++; -				*dst++ = c; -				if (c == 0) -					break; -			} - -		} else { -			*psz_assert = 0; -		} -	} -	return hr.error; -} - -u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 assert_id) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, -		HPI_ADAPTER_TEST_ASSERT); -	hm.adapter_index = adapter_index; -	hm.u.a.assert_id = assert_id; - -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 capability, u32 key) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, -		HPI_ADAPTER_ENABLE_CAPABILITY); -	hm.adapter_index = adapter_index; -	hm.u.a.assert_id = capability; -	hm.u.a.adapter_mode = key; - -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, -		HPI_ADAPTER_SELFTEST); -	hm.adapter_index = adapter_index; -	hpi_send_recv(&hm, &hr); -	return hr.error; -} - -u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, -		HPI_ADAPTER_DEBUG_READ); - -	hr.size = sizeof(hr); - -	hm.adapter_index = adapter_index; -	hm.u.ax.debug_read.dsp_address = dsp_address; - -	if (*count_bytes > (int)sizeof(hr.u.bytes)) -		*count_bytes = sizeof(hr.u.bytes); - -	hm.u.ax.debug_read.count_bytes = *count_bytes; - -	hpi_send_recv(&hm, &hr); - -	if (!hr.error) { -		*count_bytes = hr.size - 12; -		memcpy(p_buffer, &hr.u.bytes, *count_bytes); -	} else -		*count_bytes = 0; -	return hr.error; -} - -u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 property, u16 parameter1, u16 parameter2) +u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 parameter1, +	u16 parameter2)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -542,9 +253,8 @@ u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 property, u16 *pw_parameter1, -	u16 *pw_parameter2) +u16 hpi_adapter_get_property(u16 adapter_index, u16 property, +	u16 *pw_parameter1, u16 *pw_parameter2)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -564,9 +274,8 @@ u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 index, u16 what_to_enumerate, -	u16 property_index, u32 *psetting) +u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index, +	u16 what_to_enumerate, u16 property_index, u32 *psetting)  {  	return 0;  } @@ -574,7 +283,7 @@ u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys,  u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,  	u32 sample_rate, u32 bit_rate, u32 attributes)  { -	u16 error = 0; +	u16 err = 0;  	struct hpi_msg_format fmt;  	switch (channels) { @@ -586,8 +295,8 @@ u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,  	case 16:  		break;  	default: -		error = HPI_ERROR_INVALID_CHANNELS; -		return error; +		err = HPI_ERROR_INVALID_CHANNELS; +		return err;  	}  	fmt.channels = channels; @@ -610,17 +319,17 @@ u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,  	case HPI_FORMAT_OEM2:  		break;  	default: -		error = HPI_ERROR_INVALID_FORMAT; -		return error; +		err = HPI_ERROR_INVALID_FORMAT; +		return err;  	}  	fmt.format = format;  	if (sample_rate < 8000L) { -		error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE; +		err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;  		sample_rate = 8000L;  	}  	if (sample_rate > 200000L) { -		error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE; +		err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;  		sample_rate = 200000L;  	}  	fmt.sample_rate = sample_rate; @@ -651,10 +360,10 @@ u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,  		if ((channels == 1)  			&& (attributes != HPI_MPEG_MODE_DEFAULT)) {  			attributes = HPI_MPEG_MODE_DEFAULT; -			error = HPI_ERROR_INVALID_FORMAT; +			err = HPI_ERROR_INVALID_FORMAT;  		} else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {  			attributes = HPI_MPEG_MODE_DEFAULT; -			error = HPI_ERROR_INVALID_FORMAT; +			err = HPI_ERROR_INVALID_FORMAT;  		}  		fmt.attributes = attributes;  		break; @@ -663,7 +372,7 @@ u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,  	}  	hpi_msg_to_format(p_format, &fmt); -	return error; +	return err;  }  u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format, @@ -712,8 +421,8 @@ u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,  	return 0;  } -u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u16 outstream_index, u32 *ph_outstream) +u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index, +	u32 *ph_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -733,38 +442,41 @@ u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,  	return hr.error;  } -u16 hpi_outstream_close(const struct hpi_hsubsys *ph_subsys, u32 h_outstream) +u16 hpi_outstream_close(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_HOSTBUFFER_FREE); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; +  	hpi_send_recv(&hm, &hr);  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_GROUP_RESET); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);  	hpi_send_recv(&hm, &hr);  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_CLOSE); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_to_play, -	u32 *psamples_played, u32 *pauxiliary_data_to_play) +u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state, +	u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played, +	u32 *pauxiliary_data_to_play)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_GET_INFO); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr); @@ -782,15 +494,15 @@ u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, const u8 *pb_data, u32 bytes_to_write, -	const struct hpi_format *p_format) +u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_data, +	u32 bytes_to_write, const struct hpi_format *p_format)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_WRITE); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.pb_data = (u8 *)pb_data;  	hm.u.d.u.data.data_size = bytes_to_write; @@ -801,82 +513,85 @@ u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_start(const struct hpi_hsubsys *ph_subsys, u32 h_outstream) +u16 hpi_outstream_start(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_START); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_wait_start(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream) +u16 hpi_outstream_wait_start(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_WAIT_START); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_outstream) +u16 hpi_outstream_stop(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_STOP); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_sinegen(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream) +u16 hpi_outstream_sinegen(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_SINEGEN); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_outstream) +u16 hpi_outstream_reset(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_RESET); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, struct hpi_format *p_format) +u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_QUERY_FORMAT); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_format_to_msg(&hm.u.d.u.data.format, p_format); @@ -885,15 +600,15 @@ u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, struct hpi_format *p_format) +u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_SET_FORMAT); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_format_to_msg(&hm.u.d.u.data.format, p_format); @@ -902,15 +617,15 @@ u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, short velocity) +u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_SET_VELOCITY); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.velocity = velocity;  	hpi_send_recv(&hm, &hr); @@ -918,15 +633,16 @@ u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 punch_in_sample, u32 punch_out_sample) +u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample, +	u32 punch_out_sample)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_SET_PUNCHINOUT); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.pio.punch_in_sample = punch_in_sample;  	hm.u.d.u.pio.punch_out_sample = punch_out_sample; @@ -936,29 +652,29 @@ u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_ancillary_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u16 mode) +u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_ANC_RESET); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.format.channels = mode;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 *pframes_available) +u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_ANC_GET_INFO); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	if (hr.error == 0) {  		if (pframes_available) @@ -969,8 +685,8 @@ u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, struct hpi_anc_frame *p_anc_frame_buffer, +u16 hpi_outstream_ancillary_read(u32 h_outstream, +	struct hpi_anc_frame *p_anc_frame_buffer,  	u32 anc_frame_buffer_size_in_bytes,  	u32 number_of_ancillary_frames_to_read)  { @@ -979,7 +695,8 @@ u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_ANC_READ); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;  	hm.u.d.u.data.data_size =  		number_of_ancillary_frames_to_read * @@ -987,19 +704,19 @@ u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys,  	if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)  		hpi_send_recv(&hm, &hr);  	else -		hr.error = HPI_ERROR_INVALID_DATA_TRANSFER; +		hr.error = HPI_ERROR_INVALID_DATASIZE;  	return hr.error;  } -u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 time_scale) +u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scale)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_SET_TIMESCALE); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.time_scale = time_scale; @@ -1008,22 +725,21 @@ u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 size_in_bytes) +u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_HOSTBUFFER_ALLOC); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.data_size = size_in_bytes;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u8 **pp_buffer, +u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,  	struct hpi_hostbuffer_status **pp_status)  {  	struct hpi_message hm; @@ -1031,7 +747,8 @@ u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_HOSTBUFFER_GET_INFO); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	if (hr.error == 0) { @@ -1043,21 +760,20 @@ u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_host_buffer_free(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream) +u16 hpi_outstream_host_buffer_free(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_HOSTBUFFER_FREE); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 h_stream) +u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -1066,22 +782,22 @@ u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_GROUP_ADD); -	hr.error = 0; -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); + +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; + +	if (hpi_handle_indexes(h_stream, &adapter, +			&hm.u.d.u.stream.stream_index)) +		return HPI_ERROR_INVALID_HANDLE; +  	c_obj_type = hpi_handle_object(h_stream);  	switch (c_obj_type) {  	case HPI_OBJ_OSTREAM: -		hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM; -		u32TOINDEXES(h_stream, &adapter, -			&hm.u.d.u.stream.stream_index); -		break;  	case HPI_OBJ_ISTREAM: -		hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM; -		u32TOINDEXES(h_stream, &adapter, -			&hm.u.d.u.stream.stream_index); +		hm.u.d.u.stream.object_type = c_obj_type;  		break;  	default: -		return HPI_ERROR_INVALID_STREAM; +		return HPI_ERROR_INVALID_OBJ;  	}  	if (adapter != hm.adapter_index)  		return HPI_ERROR_NO_INTERADAPTER_GROUPS; @@ -1090,15 +806,16 @@ u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream, u32 *poutstream_map, u32 *pinstream_map) +u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map, +	u32 *pinstream_map)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_GROUP_GETMAP); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	if (poutstream_map) @@ -1109,21 +826,20 @@ u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_outstream_group_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_outstream) +u16 hpi_outstream_group_reset(u32 h_outstream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  		HPI_OSTREAM_GROUP_RESET); -	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u16 instream_index, u32 *ph_instream) +u16 hpi_instream_open(u16 adapter_index, u16 instream_index, u32 *ph_instream)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -1145,38 +861,40 @@ u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,  	return hr.error;  } -u16 hpi_instream_close(const struct hpi_hsubsys *ph_subsys, u32 h_instream) +u16 hpi_instream_close(u32 h_instream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_HOSTBUFFER_FREE); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_GROUP_RESET); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);  	hpi_send_recv(&hm, &hr);  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_CLOSE); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, const struct hpi_format *p_format) +u16 hpi_instream_query_format(u32 h_instream, +	const struct hpi_format *p_format)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_QUERY_FORMAT); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);  	hpi_send_recv(&hm, &hr); @@ -1184,15 +902,15 @@ u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, const struct hpi_format *p_format) +u16 hpi_instream_set_format(u32 h_instream, const struct hpi_format *p_format)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_SET_FORMAT); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);  	hpi_send_recv(&hm, &hr); @@ -1200,15 +918,15 @@ u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream, -	u8 *pb_data, u32 bytes_to_read) +u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_data, u32 bytes_to_read)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_READ); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.data_size = bytes_to_read;  	hm.u.d.u.data.pb_data = pb_data; @@ -1217,72 +935,76 @@ u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream,  	return hr.error;  } -u16 hpi_instream_start(const struct hpi_hsubsys *ph_subsys, u32 h_instream) +u16 hpi_instream_start(u32 h_instream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_START); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_wait_start(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream) +u16 hpi_instream_wait_start(u32 h_instream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_WAIT_START); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_instream) +u16 hpi_instream_stop(u32 h_instream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_STOP); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_instream) +u16 hpi_instream_reset(u32 h_instream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_RESET); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_recorded, -	u32 *psamples_recorded, u32 *pauxiliary_data_recorded) +u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size, +	u32 *pdata_recorded, u32 *psamples_recorded, +	u32 *pauxiliary_data_recorded)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_GET_INFO); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr); @@ -1300,15 +1022,15 @@ u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u16 bytes_per_frame, u16 mode, u16 alignment, -	u16 idle_bit) +u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame, +	u16 mode, u16 alignment, u16 idle_bit)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_ANC_RESET); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.format.attributes = bytes_per_frame;  	hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);  	hm.u.d.u.data.format.channels = idle_bit; @@ -1316,14 +1038,14 @@ u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 *pframe_space) +u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_ANC_GET_INFO); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	if (pframe_space)  		*pframe_space = @@ -1333,8 +1055,8 @@ u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, const struct hpi_anc_frame *p_anc_frame_buffer, +u16 hpi_instream_ancillary_write(u32 h_instream, +	const struct hpi_anc_frame *p_anc_frame_buffer,  	u32 anc_frame_buffer_size_in_bytes,  	u32 number_of_ancillary_frames_to_write)  { @@ -1343,7 +1065,8 @@ u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_ANC_WRITE); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;  	hm.u.d.u.data.data_size =  		number_of_ancillary_frames_to_write * @@ -1351,12 +1074,11 @@ u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys,  	if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)  		hpi_send_recv(&hm, &hr);  	else -		hr.error = HPI_ERROR_INVALID_DATA_TRANSFER; +		hr.error = HPI_ERROR_INVALID_DATASIZE;  	return hr.error;  } -u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 size_in_bytes) +u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes)  {  	struct hpi_message hm; @@ -1364,14 +1086,14 @@ u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_HOSTBUFFER_ALLOC); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.d.u.data.data_size = size_in_bytes;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u8 **pp_buffer, +u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,  	struct hpi_hostbuffer_status **pp_status)  {  	struct hpi_message hm; @@ -1379,7 +1101,8 @@ u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_HOSTBUFFER_GET_INFO); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	if (hr.error == 0) { @@ -1391,8 +1114,7 @@ u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream) +u16 hpi_instream_host_buffer_free(u32 h_instream)  {  	struct hpi_message hm; @@ -1400,13 +1122,13 @@ u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_HOSTBUFFER_FREE); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 h_stream) +u16 hpi_instream_group_add(u32 h_instream, u32 h_stream)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -1416,22 +1138,23 @@ u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_GROUP_ADD);  	hr.error = 0; -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); + +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; + +	if (hpi_handle_indexes(h_stream, &adapter, +			&hm.u.d.u.stream.stream_index)) +		return HPI_ERROR_INVALID_HANDLE; +  	c_obj_type = hpi_handle_object(h_stream);  	switch (c_obj_type) {  	case HPI_OBJ_OSTREAM: -		hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM; -		u32TOINDEXES(h_stream, &adapter, -			&hm.u.d.u.stream.stream_index); -		break;  	case HPI_OBJ_ISTREAM: -		hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM; -		u32TOINDEXES(h_stream, &adapter, -			&hm.u.d.u.stream.stream_index); +		hm.u.d.u.stream.object_type = c_obj_type;  		break;  	default: -		return HPI_ERROR_INVALID_STREAM; +		return HPI_ERROR_INVALID_OBJ;  	}  	if (adapter != hm.adapter_index) @@ -1441,15 +1164,16 @@ u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream, u32 *poutstream_map, u32 *pinstream_map) +u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map, +	u32 *pinstream_map)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_HOSTBUFFER_FREE); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	if (poutstream_map) @@ -1460,21 +1184,20 @@ u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_instream_group_reset(const struct hpi_hsubsys *ph_subsys, -	u32 h_instream) +u16 hpi_instream_group_reset(u32 h_instream)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  		HPI_ISTREAM_GROUP_RESET); -	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_mixer) +u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer)  {  	struct hpi_message hm;  	struct hpi_response hr; @@ -1492,25 +1215,29 @@ u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,  	return hr.error;  } -u16 hpi_mixer_close(const struct hpi_hsubsys *ph_subsys, u32 h_mixer) +u16 hpi_mixer_close(u32 h_mixer)  {  	struct hpi_message hm;  	struct hpi_response hr; +  	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE); -	u32TOINDEX(h_mixer, &hm.adapter_index); +	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL)) +		return HPI_ERROR_INVALID_HANDLE; +  	hpi_send_recv(&hm, &hr);  	return hr.error;  } -u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer, -	u16 src_node_type, u16 src_node_type_index, u16 dst_node_type, -	u16 dst_node_type_index, u16 control_type, u32 *ph_control) +u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type, +	u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index, +	u16 control_type, u32 *ph_control)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,  		HPI_MIXER_GET_CONTROL); -	u32TOINDEX(h_mixer, &hm.adapter_index); +	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.m.node_type1 = src_node_type;  	hm.u.m.node_index1 = src_node_type_index;  	hm.u.m.node_type2 = dst_node_type; @@ -1528,16 +1255,16 @@ u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,  	return hr.error;  } -u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys, -	u32 h_mixer, u16 control_index, u16 *pw_src_node_type, -	u16 *pw_src_node_index, u16 *pw_dst_node_type, u16 *pw_dst_node_index, -	u16 *pw_control_type, u32 *ph_control) +u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index, +	u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type, +	u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,  		HPI_MIXER_GET_CONTROL_BY_INDEX); -	u32TOINDEX(h_mixer, &hm.adapter_index); +	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.m.control_index = control_index;  	hpi_send_recv(&hm, &hr); @@ -1562,13 +1289,14 @@ u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer, -	enum HPI_MIXER_STORE_COMMAND command, u16 index) +u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command, +	u16 index)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE); -	u32TOINDEX(h_mixer, &hm.adapter_index); +	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.mx.store.command = command;  	hm.u.mx.store.index = index;  	hpi_send_recv(&hm, &hr); @@ -1576,16 +1304,16 @@ u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,  }  static -u16 hpi_control_param_set(const struct hpi_hsubsys *ph_subsys, -	const u32 h_control, const u16 attrib, const u32 param1, -	const u32 param2) +u16 hpi_control_param_set(const u32 h_control, const u16 attrib, +	const u32 param1, const u32 param2)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_SET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = attrib;  	hm.u.c.param1 = param1;  	hm.u.c.param2 = param2; @@ -1601,7 +1329,8 @@ static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_SET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = attrib;  	hm.u.c.an_log_value[0] = sv0;  	hm.u.c.an_log_value[1] = sv1; @@ -1610,16 +1339,16 @@ static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,  }  static -u16 hpi_control_param_get(const struct hpi_hsubsys *ph_subsys, -	const u32 h_control, const u16 attrib, u32 param1, u32 param2, -	u32 *pparam1, u32 *pparam2) +u16 hpi_control_param_get(const u32 h_control, const u16 attrib, u32 param1, +	u32 param2, u32 *pparam1, u32 *pparam2)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = attrib;  	hm.u.c.param1 = param1;  	hm.u.c.param2 = param2; @@ -1632,19 +1361,20 @@ u16 hpi_control_param_get(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -#define hpi_control_param1_get(s, h, a, p1) \ -		hpi_control_param_get(s, h, a, 0, 0, p1, NULL) -#define hpi_control_param2_get(s, h, a, p1, p2) \ -		hpi_control_param_get(s, h, a, 0, 0, p1, p2) +#define hpi_control_param1_get(h, a, p1) \ +		hpi_control_param_get(h, a, 0, 0, p1, NULL) +#define hpi_control_param2_get(h, a, p1, p2) \ +		hpi_control_param_get(h, a, 0, 0, p1, p2) -static u16 hpi_control_log_get2(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 attrib, short *sv0, short *sv1) +static u16 hpi_control_log_get2(u32 h_control, u16 attrib, short *sv0, +	short *sv1)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = attrib;  	hpi_send_recv(&hm, &hr); @@ -1655,8 +1385,7 @@ static u16 hpi_control_log_get2(const struct hpi_hsubsys *ph_subsys,  }  static -u16 hpi_control_query(const struct hpi_hsubsys *ph_subsys, -	const u32 h_control, const u16 attrib, const u32 index, +u16 hpi_control_query(const u32 h_control, const u16 attrib, const u32 index,  	const u32 param, u32 *psetting)  {  	struct hpi_message hm; @@ -1664,7 +1393,8 @@ u16 hpi_control_query(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_INFO); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = attrib;  	hm.u.c.param1 = index; @@ -1682,7 +1412,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,  	unsigned int sub_string_index = 0, j = 0;  	char c = 0;  	unsigned int n = 0; -	u16 hE = 0; +	u16 err = 0;  	if ((string_length < 1) || (string_length > 256))  		return HPI_ERROR_INVALID_CONTROL_VALUE; @@ -1693,7 +1423,9 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,  		hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  			HPI_CONTROL_GET_STATE); -		u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +		if (hpi_handle_indexes(h_control, &hm.adapter_index, +				&hm.obj_index)) +			return HPI_ERROR_INVALID_HANDLE;  		hm.u.c.attribute = attribute;  		hm.u.c.param1 = sub_string_index;  		hm.u.c.param2 = 0; @@ -1705,7 +1437,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,  			return HPI_ERROR_INVALID_CONTROL_VALUE;  		if (hr.error) { -			hE = hr.error; +			err = hr.error;  			break;  		}  		for (j = 0; j < 8; j++) { @@ -1714,7 +1446,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,  			n++;  			if (n >= string_length) {  				psz_string[string_length - 1] = 0; -				hE = HPI_ERROR_INVALID_CONTROL_VALUE; +				err = HPI_ERROR_INVALID_CONTROL_VALUE;  				break;  			}  			if (c == 0) @@ -1730,57 +1462,52 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,  		if (c == 0)  			break;  	} -	return hE; +	return err;  } -u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys, -	const u32 h_aes_rx, const u32 index, u16 *pw_format) +u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index, +	u16 *pw_format)  {  	u32 qr;  	u16 err; -	err = hpi_control_query(ph_subsys, h_aes_rx, HPI_AESEBURX_FORMAT, -		index, 0, &qr); +	err = hpi_control_query(h_aes_rx, HPI_AESEBURX_FORMAT, index, 0, &qr);  	*pw_format = (u16)qr;  	return err;  } -u16 HPI_AESEBU__receiver_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 format) +u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 format)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_AESEBURX_FORMAT, format, 0); +	return hpi_control_param_set(h_control, HPI_AESEBURX_FORMAT, format, +		0);  } -u16 HPI_AESEBU__receiver_get_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_format) +u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_format)  {  	u16 err;  	u32 param; -	err = hpi_control_param1_get(ph_subsys, h_control, -		HPI_AESEBURX_FORMAT, ¶m); +	err = hpi_control_param1_get(h_control, HPI_AESEBURX_FORMAT, ¶m);  	if (!err && pw_format)  		*pw_format = (u16)param;  	return err;  } -u16 HPI_AESEBU__receiver_get_sample_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *psample_rate) +u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_AESEBURX_SAMPLERATE, psample_rate); +	return hpi_control_param1_get(h_control, HPI_AESEBURX_SAMPLERATE, +		psample_rate);  } -u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 *pw_data) +u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_AESEBURX_USERDATA;  	hm.u.c.param1 = index; @@ -1791,14 +1518,15 @@ u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u16 index, u16 *pw_data) +u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index, +	u16 *pw_data)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;  	hm.u.c.param1 = index; @@ -1809,101 +1537,93 @@ u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys  	return hr.error;  } -u16 HPI_AESEBU__receiver_get_error_status(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_error_data) +u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data)  {  	u32 error_data = 0; -	u16 error = 0; +	u16 err = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, -		HPI_AESEBURX_ERRORSTATUS, &error_data); +	err = hpi_control_param1_get(h_control, HPI_AESEBURX_ERRORSTATUS, +		&error_data);  	if (pw_error_data)  		*pw_error_data = (u16)error_data; -	return error; +	return err;  } -u16 HPI_AESEBU__transmitter_set_sample_rate(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u32 sample_rate) +u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_AESEBUTX_SAMPLERATE, sample_rate, 0); +	return hpi_control_param_set(h_control, HPI_AESEBUTX_SAMPLERATE, +		sample_rate, 0);  } -u16 HPI_AESEBU__transmitter_set_user_data(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 data) +u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_AESEBUTX_USERDATA, index, data); +	return hpi_control_param_set(h_control, HPI_AESEBUTX_USERDATA, index, +		data);  } -u16 HPI_AESEBU__transmitter_set_channel_status(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u16 index, u16 data) +u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index, +	u16 data)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_AESEBUTX_CHANNELSTATUS, index, data); +	return hpi_control_param_set(h_control, HPI_AESEBUTX_CHANNELSTATUS, +		index, data);  } -u16 HPI_AESEBU__transmitter_get_channel_status(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, u16 index, u16 *pw_data) +u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index, +	u16 *pw_data)  {  	return HPI_ERROR_INVALID_OPERATION;  } -u16 HPI_AESEBU__transmitter_query_format(const struct hpi_hsubsys *ph_subsys, -	const u32 h_aes_tx, const u32 index, u16 *pw_format) +u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index, +	u16 *pw_format)  {  	u32 qr;  	u16 err; -	err = hpi_control_query(ph_subsys, h_aes_tx, HPI_AESEBUTX_FORMAT, -		index, 0, &qr); +	err = hpi_control_query(h_aes_tx, HPI_AESEBUTX_FORMAT, index, 0, &qr);  	*pw_format = (u16)qr;  	return err;  } -u16 HPI_AESEBU__transmitter_set_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 output_format) +u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_AESEBUTX_FORMAT, output_format, 0); +	return hpi_control_param_set(h_control, HPI_AESEBUTX_FORMAT, +		output_format, 0);  } -u16 HPI_AESEBU__transmitter_get_format(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_output_format) +u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format)  {  	u16 err;  	u32 param; -	err = hpi_control_param1_get(ph_subsys, h_control, -		HPI_AESEBUTX_FORMAT, ¶m); +	err = hpi_control_param1_get(h_control, HPI_AESEBUTX_FORMAT, ¶m);  	if (!err && pw_output_format)  		*pw_output_format = (u16)param;  	return err;  } -u16 hpi_bitstream_set_clock_edge(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 edge_type) +u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_BITSTREAM_CLOCK_EDGE, edge_type, 0); +	return hpi_control_param_set(h_control, HPI_BITSTREAM_CLOCK_EDGE, +		edge_type, 0);  } -u16 hpi_bitstream_set_data_polarity(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 polarity) +u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_BITSTREAM_DATA_POLARITY, polarity, 0); +	return hpi_control_param_set(h_control, HPI_BITSTREAM_DATA_POLARITY, +		polarity, 0);  } -u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_clk_activity, u16 *pw_data_activity) +u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity, +	u16 *pw_data_activity)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;  	hpi_send_recv(&hm, &hr);  	if (pw_clk_activity) @@ -1913,299 +1633,293 @@ u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_channel_mode_query_mode(const struct hpi_hsubsys *ph_subsys, -	const u32 h_mode, const u32 index, u16 *pw_mode) +u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index, +	u16 *pw_mode)  {  	u32 qr;  	u16 err; -	err = hpi_control_query(ph_subsys, h_mode, HPI_CHANNEL_MODE_MODE, -		index, 0, &qr); +	err = hpi_control_query(h_mode, HPI_CHANNEL_MODE_MODE, index, 0, &qr);  	*pw_mode = (u16)qr;  	return err;  } -u16 hpi_channel_mode_set(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 mode) +u16 hpi_channel_mode_set(u32 h_control, u16 mode)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_CHANNEL_MODE_MODE, mode, 0); +	return hpi_control_param_set(h_control, HPI_CHANNEL_MODE_MODE, mode, +		0);  } -u16 hpi_channel_mode_get(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 *mode) +u16 hpi_channel_mode_get(u32 h_control, u16 *mode)  {  	u32 mode32 = 0; -	u16 error = hpi_control_param1_get(ph_subsys, h_control, +	u16 err = hpi_control_param1_get(h_control,  		HPI_CHANNEL_MODE_MODE, &mode32);  	if (mode)  		*mode = (u16)mode32; -	return error; +	return err;  } -u16 hpi_cobranet_hmi_write(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 hmi_address, u32 byte_count, u8 *pb_data) +u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count, +	u8 *pb_data)  { -	struct hpi_message hm; -	struct hpi_response hr; +	struct hpi_msg_cobranet_hmiwrite hm; +	struct hpi_response_header hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX, -		HPI_CONTROL_SET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr, sizeof(hr), +		HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE); -	hm.u.cx.u.cobranet_data.byte_count = byte_count; -	hm.u.cx.u.cobranet_data.hmi_address = hmi_address; +	if (hpi_handle_indexes(h_control, &hm.h.adapter_index, +			&hm.h.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; -	if (byte_count <= 8) { -		memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count); -		hm.u.cx.attribute = HPI_COBRANET_SET; -	} else { -		hm.u.cx.u.cobranet_bigdata.pb_data = pb_data; -		hm.u.cx.attribute = HPI_COBRANET_SET_DATA; -	} +	if (byte_count > sizeof(hm.bytes)) +		return HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL; -	hpi_send_recv(&hm, &hr); +	hm.p.attribute = HPI_COBRANET_SET; +	hm.p.byte_count = byte_count; +	hm.p.hmi_address = hmi_address; +	memcpy(hm.bytes, pb_data, byte_count); +	hm.h.size = (u16)(sizeof(hm.h) + sizeof(hm.p) + byte_count); +	hpi_send_recvV1(&hm.h, &hr);  	return hr.error;  } -u16 hpi_cobranet_hmi_read(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 hmi_address, u32 max_byte_count, u32 *pbyte_count, u8 *pb_data) +u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count, +	u32 *pbyte_count, u8 *pb_data)  { -	struct hpi_message hm; -	struct hpi_response hr; +	struct hpi_msg_cobranet_hmiread hm; +	struct hpi_res_cobranet_hmiread hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX, -		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr), +		HPI_OBJ_CONTROL, HPI_CONTROL_GET_STATE); -	hm.u.cx.u.cobranet_data.byte_count = max_byte_count; -	hm.u.cx.u.cobranet_data.hmi_address = hmi_address; +	if (hpi_handle_indexes(h_control, &hm.h.adapter_index, +			&hm.h.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; -	if (max_byte_count <= 8) { -		hm.u.cx.attribute = HPI_COBRANET_GET; -	} else { -		hm.u.cx.u.cobranet_bigdata.pb_data = pb_data; -		hm.u.cx.attribute = HPI_COBRANET_GET_DATA; -	} +	if (max_byte_count > sizeof(hr.bytes)) +		return HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL; -	hpi_send_recv(&hm, &hr); -	if (!hr.error && pb_data) { +	hm.p.attribute = HPI_COBRANET_GET; +	hm.p.byte_count = max_byte_count; +	hm.p.hmi_address = hmi_address; -		*pbyte_count = hr.u.cx.u.cobranet_data.byte_count; +	hpi_send_recvV1(&hm.h, &hr.h); -		if (*pbyte_count < max_byte_count) -			max_byte_count = *pbyte_count; +	if (!hr.h.error && pb_data) { +		if (hr.byte_count > sizeof(hr.bytes)) -		if (hm.u.cx.attribute == HPI_COBRANET_GET) { -			memcpy(pb_data, hr.u.cx.u.cobranet_data.data, -				max_byte_count); -		} else { +			return HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL; -		} +		*pbyte_count = hr.byte_count; +		if (hr.byte_count < max_byte_count) +			max_byte_count = *pbyte_count; + +		memcpy(pb_data, hr.bytes, max_byte_count);  	} -	return hr.error; +	return hr.h.error;  } -u16 hpi_cobranet_hmi_get_status(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pstatus, u32 *preadable_size, -	u32 *pwriteable_size) +u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus, +	u32 *preadable_size, u32 *pwriteable_size)  {  	struct hpi_message hm;  	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX, +	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; -	hm.u.cx.attribute = HPI_COBRANET_GET_STATUS; +	hm.u.c.attribute = HPI_COBRANET_GET_STATUS;  	hpi_send_recv(&hm, &hr);  	if (!hr.error) {  		if (pstatus) -			*pstatus = hr.u.cx.u.cobranet_status.status; +			*pstatus = hr.u.cu.cobranet.status.status;  		if (preadable_size)  			*preadable_size = -				hr.u.cx.u.cobranet_status.readable_size; +				hr.u.cu.cobranet.status.readable_size;  		if (pwriteable_size)  			*pwriteable_size = -				hr.u.cx.u.cobranet_status.writeable_size; +				hr.u.cu.cobranet.status.writeable_size;  	}  	return hr.error;  } -u16 hpi_cobranet_getI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pi_paddress) +u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address)  {  	u32 byte_count;  	u32 iP; -	u16 error; +	u16 err; -	error = hpi_cobranet_hmi_read(ph_subsys, h_control, +	err = hpi_cobranet_hmi_read(h_control,  		HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,  		(u8 *)&iP); -	*pi_paddress = +	*pdw_ip_address =  		((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &  			0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8); -	if (error) -		*pi_paddress = 0; +	if (err) +		*pdw_ip_address = 0; -	return error; +	return err;  } -u16 hpi_cobranet_setI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 i_paddress) +u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address)  {  	u32 iP; -	u16 error; +	u16 err; -	iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) << -		8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress & -			0x000000ff) << 8); +	iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address & +			0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >> +		8) | ((dw_ip_address & 0x000000ff) << 8); -	error = hpi_cobranet_hmi_write(ph_subsys, h_control, +	err = hpi_cobranet_hmi_write(h_control,  		HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP); -	return error; +	return err;  } -u16 hpi_cobranet_get_staticI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pi_paddress) +u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address)  {  	u32 byte_count;  	u32 iP; -	u16 error; -	error = hpi_cobranet_hmi_read(ph_subsys, h_control, +	u16 err; +	err = hpi_cobranet_hmi_read(h_control,  		HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,  		(u8 *)&iP); -	*pi_paddress = +	*pdw_ip_address =  		((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &  			0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8); -	if (error) -		*pi_paddress = 0; +	if (err) +		*pdw_ip_address = 0; -	return error; +	return err;  } -u16 hpi_cobranet_set_staticI_paddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 i_paddress) +u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address)  {  	u32 iP; -	u16 error; +	u16 err; -	iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) << -		8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress & -			0x000000ff) << 8); +	iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address & +			0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >> +		8) | ((dw_ip_address & 0x000000ff) << 8); -	error = hpi_cobranet_hmi_write(ph_subsys, h_control, +	err = hpi_cobranet_hmi_write(h_control,  		HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP); -	return error; +	return err;  } -u16 hpi_cobranet_getMA_caddress(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pmAC_MS_bs, u32 *pmAC_LS_bs) +u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *p_mac_msbs, +	u32 *p_mac_lsbs)  {  	u32 byte_count; -	u16 error; -	u32 mAC; +	u16 err; +	u32 mac; -	error = hpi_cobranet_hmi_read(ph_subsys, h_control, +	err = hpi_cobranet_hmi_read(h_control,  		HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count, -		(u8 *)&mAC); -	*pmAC_MS_bs = -		((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC -			& 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8); -	error += hpi_cobranet_hmi_read(ph_subsys, h_control, -		HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count, -		(u8 *)&mAC); -	*pmAC_LS_bs = -		((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC -			& 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8); - -	if (error) { -		*pmAC_MS_bs = 0; -		*pmAC_LS_bs = 0; +		(u8 *)&mac); + +	if (!err) { +		*p_mac_msbs = +			((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8) +			| ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) << +			8); + +		err = hpi_cobranet_hmi_read(h_control, +			HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, +			&byte_count, (u8 *)&mac);  	} -	return error; +	if (!err) { +		*p_mac_lsbs = +			((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8) +			| ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) << +			8); +	} else { +		*p_mac_msbs = 0; +		*p_mac_lsbs = 0; +	} + +	return err;  } -u16 hpi_compander_set_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 enable) +u16 hpi_compander_set_enable(u32 h_control, u32 enable)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE, -		enable, 0); +	return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable, +		0);  } -u16 hpi_compander_get_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *enable) +u16 hpi_compander_get_enable(u32 h_control, u32 *enable)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_GENERIC_ENABLE, enable); +	return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);  } -u16 hpi_compander_set_makeup_gain(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short makeup_gain0_01dB) +u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB)  {  	return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,  		makeup_gain0_01dB, 0);  } -u16 hpi_compander_get_makeup_gain(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short *makeup_gain0_01dB) +u16 hpi_compander_get_makeup_gain(u32 h_control, short *makeup_gain0_01dB)  { -	return hpi_control_log_get2(ph_subsys, h_control, -		HPI_COMPANDER_MAKEUPGAIN, makeup_gain0_01dB, NULL); +	return hpi_control_log_get2(h_control, HPI_COMPANDER_MAKEUPGAIN, +		makeup_gain0_01dB, NULL);  } -u16 hpi_compander_set_attack_time_constant(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, unsigned int index, u32 attack) +u16 hpi_compander_set_attack_time_constant(u32 h_control, unsigned int index, +	u32 attack)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_COMPANDER_ATTACK, attack, index); +	return hpi_control_param_set(h_control, HPI_COMPANDER_ATTACK, attack, +		index);  } -u16 hpi_compander_get_attack_time_constant(const struct hpi_hsubsys -	*ph_subsys, u32 h_control, unsigned int index, u32 *attack) +u16 hpi_compander_get_attack_time_constant(u32 h_control, unsigned int index, +	u32 *attack)  { -	return hpi_control_param_get(ph_subsys, h_control, -		HPI_COMPANDER_ATTACK, 0, index, attack, NULL); +	return hpi_control_param_get(h_control, HPI_COMPANDER_ATTACK, 0, +		index, attack, NULL);  } -u16 hpi_compander_set_decay_time_constant(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, unsigned int index, u32 decay) +u16 hpi_compander_set_decay_time_constant(u32 h_control, unsigned int index, +	u32 decay)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_COMPANDER_DECAY, decay, index); +	return hpi_control_param_set(h_control, HPI_COMPANDER_DECAY, decay, +		index);  } -u16 hpi_compander_get_decay_time_constant(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, unsigned int index, u32 *decay) +u16 hpi_compander_get_decay_time_constant(u32 h_control, unsigned int index, +	u32 *decay)  { -	return hpi_control_param_get(ph_subsys, h_control, -		HPI_COMPANDER_DECAY, 0, index, decay, NULL); +	return hpi_control_param_get(h_control, HPI_COMPANDER_DECAY, 0, index, +		decay, NULL);  } -u16 hpi_compander_set_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, unsigned int index, short threshold0_01dB) +u16 hpi_compander_set_threshold(u32 h_control, unsigned int index, +	short threshold0_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_SET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;  	hm.u.c.param2 = index;  	hm.u.c.an_log_value[0] = threshold0_01dB; @@ -2215,15 +1929,16 @@ u16 hpi_compander_set_threshold(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_compander_get_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, unsigned int index, short *threshold0_01dB) +u16 hpi_compander_get_threshold(u32 h_control, unsigned int index, +	short *threshold0_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;  	hm.u.c.param2 = index; @@ -2233,29 +1948,28 @@ u16 hpi_compander_get_threshold(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_compander_set_ratio(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, u32 ratio100) +u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_COMPANDER_RATIO, ratio100, index); +	return hpi_control_param_set(h_control, HPI_COMPANDER_RATIO, ratio100, +		index);  } -u16 hpi_compander_get_ratio(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, u32 *ratio100) +u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *ratio100)  { -	return hpi_control_param_get(ph_subsys, h_control, -		HPI_COMPANDER_RATIO, 0, index, ratio100, NULL); +	return hpi_control_param_get(h_control, HPI_COMPANDER_RATIO, 0, index, +		ratio100, NULL);  } -u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB) +u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB, +	short *max_gain_01dB, short *step_gain_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_LEVEL_RANGE;  	hpi_send_recv(&hm, &hr); @@ -2273,31 +1987,27 @@ u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return hr.error;  } -u16 hpi_level_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_gain0_01dB[HPI_MAX_CHANNELS] +u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]  	)  {  	return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,  		an_gain0_01dB[0], an_gain0_01dB[1]);  } -u16 hpi_level_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_gain0_01dB[HPI_MAX_CHANNELS] +u16 hpi_level_get_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]  	)  { -	return hpi_control_log_get2(ph_subsys, h_control, HPI_LEVEL_GAIN, +	return hpi_control_log_get2(h_control, HPI_LEVEL_GAIN,  		&an_gain0_01dB[0], &an_gain0_01dB[1]);  } -u16 hpi_meter_query_channels(const struct hpi_hsubsys *ph_subsys, -	const u32 h_meter, u32 *p_channels) +u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels)  { -	return hpi_control_query(ph_subsys, h_meter, HPI_METER_NUM_CHANNELS, -		0, 0, p_channels); +	return hpi_control_query(h_meter, HPI_METER_NUM_CHANNELS, 0, 0, +		p_channels);  } -u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_peakdB[HPI_MAX_CHANNELS] +u16 hpi_meter_get_peak(u32 h_control, short an_peakdB[HPI_MAX_CHANNELS]  	)  {  	short i = 0; @@ -2307,7 +2017,8 @@ u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.obj_index = hm.obj_index;  	hm.u.c.attribute = HPI_METER_PEAK; @@ -2322,8 +2033,7 @@ u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return hr.error;  } -u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_rmsdB[HPI_MAX_CHANNELS] +u16 hpi_meter_get_rms(u32 h_control, short an_rmsdB[HPI_MAX_CHANNELS]  	)  {  	short i = 0; @@ -2333,7 +2043,8 @@ u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_METER_RMS;  	hpi_send_recv(&hm, &hr); @@ -2348,22 +2059,20 @@ u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return hr.error;  } -u16 hpi_meter_set_rms_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 attack, u16 decay) +u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_METER_RMS_BALLISTICS, attack, decay); +	return hpi_control_param_set(h_control, HPI_METER_RMS_BALLISTICS, +		attack, decay);  } -u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pn_attack, u16 *pn_decay) +u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *pn_attack, u16 *pn_decay)  {  	u32 attack;  	u32 decay;  	u16 error; -	error = hpi_control_param2_get(ph_subsys, h_control, -		HPI_METER_RMS_BALLISTICS, &attack, &decay); +	error = hpi_control_param2_get(h_control, HPI_METER_RMS_BALLISTICS, +		&attack, &decay);  	if (pn_attack)  		*pn_attack = (unsigned short)attack; @@ -2373,22 +2082,21 @@ u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys,  	return error;  } -u16 hpi_meter_set_peak_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 attack, u16 decay) +u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_METER_PEAK_BALLISTICS, attack, decay); +	return hpi_control_param_set(h_control, HPI_METER_PEAK_BALLISTICS, +		attack, decay);  } -u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pn_attack, u16 *pn_decay) +u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *pn_attack, +	u16 *pn_decay)  {  	u32 attack;  	u32 decay;  	u16 error; -	error = hpi_control_param2_get(ph_subsys, h_control, -		HPI_METER_PEAK_BALLISTICS, &attack, &decay); +	error = hpi_control_param2_get(h_control, HPI_METER_PEAK_BALLISTICS, +		&attack, &decay);  	if (pn_attack)  		*pn_attack = (short)attack; @@ -2398,55 +2106,53 @@ u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys,  	return error;  } -u16 hpi_microphone_set_phantom_power(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 on_off) +u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_MICROPHONE_PHANTOM_POWER, (u32)on_off, 0); +	return hpi_control_param_set(h_control, HPI_MICROPHONE_PHANTOM_POWER, +		(u32)on_off, 0);  } -u16 hpi_microphone_get_phantom_power(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_on_off) +u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off)  {  	u16 error = 0;  	u32 on_off = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, +	error = hpi_control_param1_get(h_control,  		HPI_MICROPHONE_PHANTOM_POWER, &on_off);  	if (pw_on_off)  		*pw_on_off = (u16)on_off;  	return error;  } -u16 hpi_multiplexer_set_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 source_node_type, u16 source_node_index) +u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type, +	u16 source_node_index)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_MULTIPLEXER_SOURCE, source_node_type, source_node_index); +	return hpi_control_param_set(h_control, HPI_MULTIPLEXER_SOURCE, +		source_node_type, source_node_index);  } -u16 hpi_multiplexer_get_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *source_node_type, u16 *source_node_index) +u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type, +	u16 *source_node_index)  {  	u32 node, index; -	u16 error = hpi_control_param2_get(ph_subsys, h_control, +	u16 err = hpi_control_param2_get(h_control,  		HPI_MULTIPLEXER_SOURCE, &node,  		&index);  	if (source_node_type)  		*source_node_type = (u16)node;  	if (source_node_index)  		*source_node_index = (u16)index; -	return error; +	return err;  } -u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 *source_node_type, -	u16 *source_node_index) +u16 hpi_multiplexer_query_source(u32 h_control, u16 index, +	u16 *source_node_type, u16 *source_node_index)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;  	hm.u.c.param1 = index; @@ -2459,15 +2165,15 @@ u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_number_of_bands, u16 *pw_on_off) +u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands, +	u16 *pw_on_off)  {  	u32 oB = 0;  	u32 oO = 0;  	u16 error = 0; -	error = hpi_control_param2_get(ph_subsys, h_control, -		HPI_EQUALIZER_NUM_FILTERS, &oO, &oB); +	error = hpi_control_param2_get(h_control, HPI_EQUALIZER_NUM_FILTERS, +		&oO, &oB);  	if (pw_number_of_bands)  		*pw_number_of_bands = (u16)oB;  	if (pw_on_off) @@ -2475,23 +2181,22 @@ u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys,  	return error;  } -u16 hpi_parametricEQ__set_state(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 on_off) +u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_EQUALIZER_NUM_FILTERS, on_off, 0); +	return hpi_control_param_set(h_control, HPI_EQUALIZER_NUM_FILTERS, +		on_off, 0);  } -u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 *pn_type, u32 *pfrequency_hz, -	short *pnQ100, short *pn_gain0_01dB) +u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type, +	u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_EQUALIZER_FILTER;  	hm.u.c.param2 = index; @@ -2509,16 +2214,16 @@ u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, u16 type, u32 frequency_hz, short q100, -	short gain0_01dB) +u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type, +	u32 frequency_hz, short q100, short gain0_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_SET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.param1 = frequency_hz;  	hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16); @@ -2531,8 +2236,7 @@ u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 index, short coeffs[5] +u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]  	)  {  	struct hpi_message hm; @@ -2540,7 +2244,8 @@ u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys,  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;  	hm.u.c.param2 = index; @@ -2555,444 +2260,388 @@ u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_sample_clock_query_source(const struct hpi_hsubsys *ph_subsys, -	const u32 h_clock, const u32 index, u16 *pw_source) +u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index, +	u16 *pw_source)  {  	u32 qr;  	u16 err; -	err = hpi_control_query(ph_subsys, h_clock, HPI_SAMPLECLOCK_SOURCE, -		index, 0, &qr); +	err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE, index, 0, +		&qr);  	*pw_source = (u16)qr;  	return err;  } -u16 hpi_sample_clock_set_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 source) +u16 hpi_sample_clock_set_source(u32 h_control, u16 source)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_SAMPLECLOCK_SOURCE, source, 0); +	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE, +		source, 0);  } -u16 hpi_sample_clock_get_source(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_source) +u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source)  { -	u16 error = 0; +	u16 err = 0;  	u32 source = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, -		HPI_SAMPLECLOCK_SOURCE, &source); -	if (!error) +	err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE, +		&source); +	if (!err)  		if (pw_source)  			*pw_source = (u16)source; -	return error; +	return err;  } -u16 hpi_sample_clock_query_source_index(const struct hpi_hsubsys *ph_subsys, -	const u32 h_clock, const u32 index, const u32 source, -	u16 *pw_source_index) +u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index, +	const u32 source, u16 *pw_source_index)  {  	u32 qr;  	u16 err; -	err = hpi_control_query(ph_subsys, h_clock, -		HPI_SAMPLECLOCK_SOURCE_INDEX, index, source, &qr); +	err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE_INDEX, index, +		source, &qr);  	*pw_source_index = (u16)qr;  	return err;  } -u16 hpi_sample_clock_set_source_index(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 source_index) +u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_SAMPLECLOCK_SOURCE_INDEX, source_index, 0); +	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX, +		source_index, 0);  } -u16 hpi_sample_clock_get_source_index(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u16 *pw_source_index) +u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index)  { -	u16 error = 0; +	u16 err = 0;  	u32 source_index = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, -		HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index); -	if (!error) +	err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX, +		&source_index); +	if (!err)  		if (pw_source_index)  			*pw_source_index = (u16)source_index; -	return error; +	return err;  } -u16 hpi_sample_clock_query_local_rate(const struct hpi_hsubsys *ph_subsys, -	const u32 h_clock, const u32 index, u32 *prate) +u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index, +	u32 *prate)  {  	u16 err; -	err = hpi_control_query(ph_subsys, h_clock, -		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, index, 0, prate); +	err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, +		index, 0, prate);  	return err;  } -u16 hpi_sample_clock_set_local_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 sample_rate) +u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)  { -	return hpi_control_param_set(ph_subsys, h_control, +	return hpi_control_param_set(h_control,  		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);  } -u16 hpi_sample_clock_get_local_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *psample_rate) +u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate)  { -	u16 error = 0; +	u16 err = 0;  	u32 sample_rate = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, +	err = hpi_control_param1_get(h_control,  		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate); -	if (!error) +	if (!err)  		if (psample_rate)  			*psample_rate = sample_rate; -	return error; +	return err;  } -u16 hpi_sample_clock_get_sample_rate(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *psample_rate) +u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate)  { -	u16 error = 0; +	u16 err = 0;  	u32 sample_rate = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, -		HPI_SAMPLECLOCK_SAMPLERATE, &sample_rate); -	if (!error) +	err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SAMPLERATE, +		&sample_rate); +	if (!err)  		if (psample_rate)  			*psample_rate = sample_rate; -	return error; +	return err;  } -u16 hpi_sample_clock_set_auto(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 enable) +u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_SAMPLECLOCK_AUTO, enable, 0); +	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_AUTO, enable, +		0);  } -u16 hpi_sample_clock_get_auto(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *penable) +u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_SAMPLECLOCK_AUTO, penable); +	return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_AUTO, +		penable);  } -u16 hpi_sample_clock_set_local_rate_lock(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 lock) +u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_SAMPLECLOCK_LOCAL_LOCK, lock, 0); +	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK, +		lock, 0);  } -u16 hpi_sample_clock_get_local_rate_lock(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *plock) +u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_SAMPLECLOCK_LOCAL_LOCK, plock); +	return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK, +		plock);  } -u16 hpi_tone_detector_get_frequency(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 index, u32 *frequency) +u16 hpi_tone_detector_get_frequency(u32 h_control, u32 index, u32 *frequency)  { -	return hpi_control_param_get(ph_subsys, h_control, -		HPI_TONEDETECTOR_FREQUENCY, index, 0, frequency, NULL); +	return hpi_control_param_get(h_control, HPI_TONEDETECTOR_FREQUENCY, +		index, 0, frequency, NULL);  } -u16 hpi_tone_detector_get_state(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *state) +u16 hpi_tone_detector_get_state(u32 h_control, u32 *state)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_TONEDETECTOR_STATE, state); +	return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_STATE, +		state);  } -u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 enable) +u16 hpi_tone_detector_set_enable(u32 h_control, u32 enable)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE, -		(u32)enable, 0); +	return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable, +		0);  } -u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *enable) +u16 hpi_tone_detector_get_enable(u32 h_control, u32 *enable)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_GENERIC_ENABLE, enable); +	return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);  } -u16 hpi_tone_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 event_enable) +u16 hpi_tone_detector_set_event_enable(u32 h_control, u32 event_enable)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0); +	return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE, +		(u32)event_enable, 0);  } -u16 hpi_tone_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *event_enable) +u16 hpi_tone_detector_get_event_enable(u32 h_control, u32 *event_enable)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_GENERIC_EVENT_ENABLE, event_enable); +	return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE, +		event_enable);  } -u16 hpi_tone_detector_set_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, int threshold) +u16 hpi_tone_detector_set_threshold(u32 h_control, int threshold)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_TONEDETECTOR_THRESHOLD, (u32)threshold, 0); +	return hpi_control_param_set(h_control, HPI_TONEDETECTOR_THRESHOLD, +		(u32)threshold, 0);  } -u16 hpi_tone_detector_get_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, int *threshold) +u16 hpi_tone_detector_get_threshold(u32 h_control, int *threshold)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_TONEDETECTOR_THRESHOLD, (u32 *)threshold); +	return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_THRESHOLD, +		(u32 *)threshold);  } -u16 hpi_silence_detector_get_state(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *state) +u16 hpi_silence_detector_get_state(u32 h_control, u32 *state)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_SILENCEDETECTOR_STATE, state); +	return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_STATE, +		state);  } -u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 enable) +u16 hpi_silence_detector_set_enable(u32 h_control, u32 enable)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE, -		(u32)enable, 0); +	return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable, +		0);  } -u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *enable) +u16 hpi_silence_detector_get_enable(u32 h_control, u32 *enable)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_GENERIC_ENABLE, enable); +	return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);  } -u16 hpi_silence_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 event_enable) +u16 hpi_silence_detector_set_event_enable(u32 h_control, u32 event_enable)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_GENERIC_EVENT_ENABLE, event_enable, 0); +	return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE, +		event_enable, 0);  } -u16 hpi_silence_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *event_enable) +u16 hpi_silence_detector_get_event_enable(u32 h_control, u32 *event_enable)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_GENERIC_EVENT_ENABLE, event_enable); +	return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE, +		event_enable);  } -u16 hpi_silence_detector_set_delay(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 delay) +u16 hpi_silence_detector_set_delay(u32 h_control, u32 delay)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_SILENCEDETECTOR_DELAY, delay, 0); +	return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_DELAY, +		delay, 0);  } -u16 hpi_silence_detector_get_delay(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *delay) +u16 hpi_silence_detector_get_delay(u32 h_control, u32 *delay)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_SILENCEDETECTOR_DELAY, delay); +	return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_DELAY, +		delay);  } -u16 hpi_silence_detector_set_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, int threshold) +u16 hpi_silence_detector_set_threshold(u32 h_control, int threshold)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_SILENCEDETECTOR_THRESHOLD, threshold, 0); +	return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_THRESHOLD, +		threshold, 0);  } -u16 hpi_silence_detector_get_threshold(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, int *threshold) +u16 hpi_silence_detector_get_threshold(u32 h_control, int *threshold)  { -	return hpi_control_param1_get(ph_subsys, h_control, +	return hpi_control_param1_get(h_control,  		HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);  } -u16 hpi_tuner_query_band(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, u16 *pw_band) +u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band)  {  	u32 qr;  	u16 err; -	err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0, -		&qr); +	err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);  	*pw_band = (u16)qr;  	return err;  } -u16 hpi_tuner_set_band(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 band) +u16 hpi_tuner_set_band(u32 h_control, u16 band)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_BAND, -		band, 0); +	return hpi_control_param_set(h_control, HPI_TUNER_BAND, band, 0);  } -u16 hpi_tuner_get_band(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 *pw_band) +u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band)  {  	u32 band = 0;  	u16 error = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_BAND, -		&band); +	error = hpi_control_param1_get(h_control, HPI_TUNER_BAND, &band);  	if (pw_band)  		*pw_band = (u16)band;  	return error;  } -u16 hpi_tuner_query_frequency(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, const u16 band, u32 *pfreq) +u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index, +	const u16 band, u32 *pfreq)  { -	return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_FREQ, index, -		band, pfreq); +	return hpi_control_query(h_tuner, HPI_TUNER_FREQ, index, band, pfreq);  } -u16 hpi_tuner_set_frequency(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 freq_ink_hz) +u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_FREQ, -		freq_ink_hz, 0); +	return hpi_control_param_set(h_control, HPI_TUNER_FREQ, freq_ink_hz, +		0);  } -u16 hpi_tuner_get_frequency(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pw_freq_ink_hz) +u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz)  { -	return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_FREQ, +	return hpi_control_param1_get(h_control, HPI_TUNER_FREQ,  		pw_freq_ink_hz);  } -u16 hpi_tuner_query_gain(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, u16 *pw_gain) +u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain)  {  	u32 qr;  	u16 err; -	err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0, -		&qr); +	err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);  	*pw_gain = (u16)qr;  	return err;  } -u16 hpi_tuner_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short gain) +u16 hpi_tuner_set_gain(u32 h_control, short gain)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_GAIN, -		gain, 0); +	return hpi_control_param_set(h_control, HPI_TUNER_GAIN, gain, 0);  } -u16 hpi_tuner_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *pn_gain) +u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain)  {  	u32 gain = 0;  	u16 error = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_GAIN, -		&gain); +	error = hpi_control_param1_get(h_control, HPI_TUNER_GAIN, &gain);  	if (pn_gain)  		*pn_gain = (u16)gain;  	return error;  } -u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *pw_level) +u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); -	hm.u.c.attribute = HPI_TUNER_LEVEL; -	hm.u.c.param1 = HPI_TUNER_LEVEL_AVERAGE; +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; +	hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;  	hpi_send_recv(&hm, &hr);  	if (pw_level) -		*pw_level = (short)hr.u.c.param1; +		*pw_level = hr.u.cu.tuner.s_level;  	return hr.error;  } -u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short *pw_level) +u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); -	hm.u.c.attribute = HPI_TUNER_LEVEL; -	hm.u.c.param1 = HPI_TUNER_LEVEL_RAW; +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE; +	hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;  	hpi_send_recv(&hm, &hr);  	if (pw_level) -		*pw_level = (short)hr.u.c.param1; +		*pw_level = hr.u.cu.tuner.s_level;  	return hr.error;  } -u16 hpi_tuner_query_deemphasis(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, const u32 index, const u16 band, u32 *pdeemphasis) +u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index, +	const u16 band, u32 *pdeemphasis)  { -	return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_DEEMPHASIS, -		index, band, pdeemphasis); +	return hpi_control_query(h_tuner, HPI_TUNER_DEEMPHASIS, index, band, +		pdeemphasis);  } -u16 hpi_tuner_set_deemphasis(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 deemphasis) +u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_TUNER_DEEMPHASIS, deemphasis, 0); +	return hpi_control_param_set(h_control, HPI_TUNER_DEEMPHASIS, +		deemphasis, 0);  } -u16 hpi_tuner_get_deemphasis(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pdeemphasis) +u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_TUNER_DEEMPHASIS, pdeemphasis); +	return hpi_control_param1_get(h_control, HPI_TUNER_DEEMPHASIS, +		pdeemphasis);  } -u16 hpi_tuner_query_program(const struct hpi_hsubsys *ph_subsys, -	const u32 h_tuner, u32 *pbitmap_program) +u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program)  { -	return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_PROGRAM, 0, 0, +	return hpi_control_query(h_tuner, HPI_TUNER_PROGRAM, 0, 0,  		pbitmap_program);  } -u16 hpi_tuner_set_program(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 program) +u16 hpi_tuner_set_program(u32 h_control, u32 program)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_PROGRAM, -		program, 0); +	return hpi_control_param_set(h_control, HPI_TUNER_PROGRAM, program, +		0);  } -u16 hpi_tuner_get_program(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 *pprogram) +u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram)  { -	return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_PROGRAM, -		pprogram); +	return hpi_control_param1_get(h_control, HPI_TUNER_PROGRAM, pprogram);  } -u16 hpi_tuner_get_hd_radio_dsp_version(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, char *psz_dsp_version, const u32 string_size) +u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version, +	const u32 string_size)  {  	return hpi_control_get_string(h_control,  		HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);  } -u16 hpi_tuner_get_hd_radio_sdk_version(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, char *psz_sdk_version, const u32 string_size) +u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version, +	const u32 string_size)  {  	return hpi_control_get_string(h_control,  		HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);  } -u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u16 *pw_status_mask, u16 *pw_status) +u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status)  {  	u32 status = 0;  	u16 error = 0; -	error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_STATUS, -		&status); +	error = hpi_control_param1_get(h_control, HPI_TUNER_STATUS, &status);  	if (pw_status) {  		if (!error) {  			*pw_status_mask = (u16)(status >> 16); @@ -3005,50 +2654,44 @@ u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return error;  } -u16 hpi_tuner_set_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 mode, u32 value) +u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value)  { -	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_MODE, -		mode, value); +	return hpi_control_param_set(h_control, HPI_TUNER_MODE, mode, value);  } -u16 hpi_tuner_get_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 mode, u32 *pn_value) +u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value)  { -	return hpi_control_param_get(ph_subsys, h_control, HPI_TUNER_MODE, -		mode, 0, pn_value, NULL); +	return hpi_control_param_get(h_control, HPI_TUNER_MODE, mode, 0, +		pn_value, NULL);  } -u16 hpi_tuner_get_hd_radio_signal_quality(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pquality) +u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality)  { -	return hpi_control_param1_get(ph_subsys, h_control, +	return hpi_control_param1_get(h_control,  		HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);  } -u16 hpi_tuner_get_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *pblend) +u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_TUNER_HDRADIO_BLEND, pblend); +	return hpi_control_param1_get(h_control, HPI_TUNER_HDRADIO_BLEND, +		pblend);  } -u16 hpi_tuner_set_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, const u32 blend) +u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend)  { -	return hpi_control_param_set(ph_subsys, h_control, -		HPI_TUNER_HDRADIO_BLEND, blend, 0); +	return hpi_control_param_set(h_control, HPI_TUNER_HDRADIO_BLEND, +		blend, 0);  } -u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *p_data) +u16 hpi_tuner_get_rds(u32 h_control, char *p_data)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_TUNER_RDS;  	hpi_send_recv(&hm, &hr);  	if (p_data) { @@ -3059,80 +2702,82 @@ u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return hr.error;  } -u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, char *psz_string, const u32 data_length) +u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string, +	const u32 data_length)  {  	return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,  		psz_string, data_length);  } -u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *psz_string, const u32 data_length) +u16 hpi_pad_get_artist(u32 h_control, char *psz_string, const u32 data_length)  {  	return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,  		data_length);  } -u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *psz_string, const u32 data_length) +u16 hpi_pad_get_title(u32 h_control, char *psz_string, const u32 data_length)  {  	return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,  		data_length);  } -u16 HPI_PAD__get_comment(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	char *psz_string, const u32 data_length) +u16 hpi_pad_get_comment(u32 h_control, char *psz_string, +	const u32 data_length)  {  	return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,  		data_length);  } -u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, u32 *ppTY) +u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_PAD_PROGRAM_TYPE, ppTY); +	return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_TYPE, ppTY);  } -u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	u32 *ppI) +u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI)  { -	return hpi_control_param1_get(ph_subsys, h_control, -		HPI_PAD_PROGRAM_ID, ppI); +	return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_ID, ppI);  } -u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys, -	const u32 h_volume, u32 *p_channels) +u16 hpi_volume_query_channels(const u32 h_volume, u32 *p_channels)  { -	return hpi_control_query(ph_subsys, h_volume, HPI_VOLUME_NUM_CHANNELS, -		0, 0, p_channels); +	return hpi_control_query(h_volume, HPI_VOLUME_NUM_CHANNELS, 0, 0, +		p_channels);  } -u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_log_gain[HPI_MAX_CHANNELS] +u16 hpi_volume_set_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]  	)  {  	return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,  		an_log_gain[0], an_log_gain[1]);  } -u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_log_gain[HPI_MAX_CHANNELS] +u16 hpi_volume_get_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]  	)  { -	return hpi_control_log_get2(ph_subsys, h_control, HPI_VOLUME_GAIN, +	return hpi_control_log_get2(h_control, HPI_VOLUME_GAIN,  		&an_log_gain[0], &an_log_gain[1]);  } -u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB) +u16 hpi_volume_set_mute(u32 h_control, u32 mute) +{ +	return hpi_control_param_set(h_control, HPI_VOLUME_MUTE, mute, 0); +} + +u16 hpi_volume_get_mute(u32 h_control, u32 *mute) +{ +	return hpi_control_param1_get(h_control, HPI_VOLUME_MUTE, mute); +} + +u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB, +	short *max_gain_01dB, short *step_gain_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_VOLUME_RANGE;  	hpi_send_recv(&hm, &hr); @@ -3150,16 +2795,17 @@ u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return hr.error;  } -u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys, -	u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS], -	u32 duration_ms, u16 profile) +u16 hpi_volume_auto_fade_profile(u32 h_control, +	short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms, +	u16 profile)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_SET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,  		sizeof(short) * HPI_MAX_CHANNELS); @@ -3173,21 +2819,31 @@ u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys,  	return hr.error;  } -u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control, +u16 hpi_volume_auto_fade(u32 h_control,  	short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)  { -	return hpi_volume_auto_fade_profile(ph_subsys, h_control, -		an_stop_gain0_01dB, duration_ms, HPI_VOLUME_AUTOFADE_LOG); +	return hpi_volume_auto_fade_profile(h_control, an_stop_gain0_01dB, +		duration_ms, HPI_VOLUME_AUTOFADE_LOG);  } -u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short an_gain0_01dB) +u16 hpi_volume_query_auto_fade_profile(const u32 h_volume, const u32 i, +	u16 *profile) +{ +	u16 e; +	u32 u; +	e = hpi_control_query(h_volume, HPI_VOLUME_AUTOFADE, i, 0, &u); +	*profile = (u16)u; +	return e; +} + +u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_SET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_VOX_THRESHOLD;  	hm.u.c.an_log_value[0] = an_gain0_01dB; @@ -3197,14 +2853,14 @@ u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return hr.error;  } -u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control, -	short *an_gain0_01dB) +u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB)  {  	struct hpi_message hm;  	struct hpi_response hr;  	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,  		HPI_CONTROL_GET_STATE); -	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); +	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index)) +		return HPI_ERROR_INVALID_HANDLE;  	hm.u.c.attribute = HPI_VOX_THRESHOLD;  	hpi_send_recv(&hm, &hr); @@ -3213,728 +2869,3 @@ u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,  	return hr.error;  } - -static size_t strv_packet_size = MIN_STRV_PACKET_SIZE; - -static size_t entity_type_to_size[LAST_ENTITY_TYPE] = { -	0, -	sizeof(struct hpi_entity), -	sizeof(void *), - -	sizeof(int), -	sizeof(float), -	sizeof(double), - -	sizeof(char), -	sizeof(char), - -	4 * sizeof(char), -	16 * sizeof(char), -	6 * sizeof(char), -}; - -static inline size_t hpi_entity_size(struct hpi_entity *entity_ptr) -{ -	return entity_ptr->header.size; -} - -static inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr) -{ -	return sizeof(entity_ptr->header); -} - -static inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr) -{ -	return hpi_entity_size(entity_ptr) - -		hpi_entity_header_size(entity_ptr); -} - -static inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr) -{ -	return hpi_entity_value_size(entity_ptr) / -		entity_type_to_size[entity_ptr->header.type]; -} - -static inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity -	*entity_ptr) -{ -	return (void *)(((u8 *)entity_ptr) + hpi_entity_size(entity_ptr)); -} - -static inline u16 hpi_entity_check_type(const enum e_entity_type t) -{ -	if (t >= 0 && t < STR_TYPE_FIELD_MAX) -		return 0; -	return HPI_ERROR_ENTITY_TYPE_INVALID; -} - -static inline u16 hpi_entity_check_role(const enum e_entity_role r) -{ -	if (r >= 0 && r < STR_ROLE_FIELD_MAX) -		return 0; -	return HPI_ERROR_ENTITY_ROLE_INVALID; -} - -static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag, -	void *guard_p, struct hpi_entity **next) -{ -	HPI_DEBUG_ASSERT(entity != NULL); -	HPI_DEBUG_ASSERT(next != NULL); -	HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0); - -	if (guard_p <= (void *)entity) { -		*next = NULL; -		return 0; -	} - -	if (recursive_flag && entity->header.type == entity_type_sequence) -		*next = (struct hpi_entity *)entity->value; -	else -		*next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity); - -	if (guard_p <= (void *)*next) { -		*next = NULL; -		return 0; -	} - -	HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next)); -	return 0; -} - -u16 hpi_entity_find_next(struct hpi_entity *container_entity, -	enum e_entity_type type, enum e_entity_role role, int recursive_flag, -	struct hpi_entity **current_match) -{ -	struct hpi_entity *tmp = NULL; -	void *guard_p = NULL; - -	HPI_DEBUG_ASSERT(container_entity != NULL); -	guard_p = hpi_entity_ptr_to_next(container_entity); - -	if (*current_match != NULL) -		hpi_entity_get_next(*current_match, recursive_flag, guard_p, -			&tmp); -	else -		hpi_entity_get_next(container_entity, 1, guard_p, &tmp); - -	while (tmp) { -		u16 err; - -		HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity); - -		if ((!type || tmp->header.type == type) && (!role -				|| tmp->header.role == role)) { -			*current_match = tmp; -			return 0; -		} - -		err = hpi_entity_get_next(tmp, recursive_flag, guard_p, -			current_match); -		if (err) -			return err; - -		tmp = *current_match; -	} - -	*current_match = NULL; -	return 0; -} - -void hpi_entity_free(struct hpi_entity *entity) -{ -	kfree(entity); -} - -static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src, -	struct hpi_entity **dst) -{ -	size_t buf_size; -	HPI_DEBUG_ASSERT(dst != NULL); -	HPI_DEBUG_ASSERT(src != NULL); - -	buf_size = hpi_entity_size(src); -	*dst = kmalloc(buf_size, GFP_KERNEL); -	if (*dst == NULL) -		return HPI_ERROR_MEMORY_ALLOC; -	memcpy(*dst, src, buf_size); -	return 0; -} - -u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC, -	struct hpi_entity **info) -{ -	struct hpi_msg_strv hm; -	struct hpi_res_strv *phr; -	u16 hpi_err; -	int remaining_attempts = 2; -	size_t resp_packet_size = 1024; - -	*info = NULL; - -	while (remaining_attempts--) { -		phr = kmalloc(resp_packet_size, GFP_KERNEL); -		HPI_DEBUG_ASSERT(phr != NULL); - -		hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h, -			(u16)resp_packet_size, HPI_OBJ_CONTROL, -			HPI_CONTROL_GET_INFO); -		u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index); - -		hm.strv.header.size = sizeof(hm.strv); -		phr->strv.header.size = resp_packet_size - sizeof(phr->h); - -		hpi_send_recv((struct hpi_message *)&hm.h, -			(struct hpi_response *)&phr->h); -		if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) { - -			HPI_DEBUG_ASSERT(phr->h.specific_error > -				MIN_STRV_PACKET_SIZE -				&& phr->h.specific_error < 1500); -			resp_packet_size = phr->h.specific_error; -		} else { -			remaining_attempts = 0; -			if (!phr->h.error) -				hpi_entity_alloc_and_copy(&phr->strv, info); -		} - -		hpi_err = phr->h.error; -		kfree(phr); -	} - -	return hpi_err; -} - -u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC, -	struct hpi_entity **value) -{ -	struct hpi_msg_strv hm; -	struct hpi_res_strv *phr; -	u16 hpi_err; -	int remaining_attempts = 2; - -	*value = NULL; - -	while (remaining_attempts--) { -		phr = kmalloc(strv_packet_size, GFP_KERNEL); -		if (!phr) -			return HPI_ERROR_MEMORY_ALLOC; - -		hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h, -			(u16)strv_packet_size, HPI_OBJ_CONTROL, -			HPI_CONTROL_GET_STATE); -		u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index); - -		hm.strv.header.size = sizeof(hm.strv); -		phr->strv.header.size = strv_packet_size - sizeof(phr->h); - -		hpi_send_recv((struct hpi_message *)&hm.h, -			(struct hpi_response *)&phr->h); -		if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) { - -			HPI_DEBUG_ASSERT(phr->h.specific_error > -				MIN_STRV_PACKET_SIZE -				&& phr->h.specific_error < 1000); -			strv_packet_size = phr->h.specific_error; -		} else { -			remaining_attempts = 0; -			if (!phr->h.error) -				hpi_entity_alloc_and_copy(&phr->strv, value); -		} - -		hpi_err = phr->h.error; -		kfree(phr); -	} - -	return hpi_err; -} - -u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC, -	struct hpi_entity *value) -{ -	struct hpi_msg_strv *phm; -	struct hpi_res_strv hr; - -	phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL); -	HPI_DEBUG_ASSERT(phm != NULL); - -	hpi_init_message_responseV1(&phm->h, -		sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr), -		HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE); -	u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index); -	hr.strv.header.size = sizeof(hr.strv); - -	memcpy(&phm->strv, value, value->header.size); -	hpi_send_recv((struct hpi_message *)&phm->h, -		(struct hpi_response *)&hr.h); - -	return hr.h.error; -} - -u16 hpi_entity_alloc_and_pack(const enum e_entity_type type, -	const size_t item_count, const enum e_entity_role role, void *value, -	struct hpi_entity **entity) -{ -	size_t bytes_to_copy, total_size; -	u16 hE = 0; -	*entity = NULL; - -	hE = hpi_entity_check_type(type); -	if (hE) -		return hE; - -	HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE); - -	bytes_to_copy = entity_type_to_size[type] * item_count; -	total_size = hpi_entity_header_size(*entity) + bytes_to_copy; - -	HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity) -		&& total_size < STR_SIZE_FIELD_MAX); - -	*entity = kmalloc(total_size, GFP_KERNEL); -	if (*entity == NULL) -		return HPI_ERROR_MEMORY_ALLOC; -	memcpy((*entity)->value, value, bytes_to_copy); -	(*entity)->header.size = -		hpi_entity_header_size(*entity) + bytes_to_copy; -	(*entity)->header.type = type; -	(*entity)->header.role = role; -	return 0; -} - -u16 hpi_entity_copy_value_from(struct hpi_entity *entity, -	enum e_entity_type type, size_t item_count, void *value_dst_p) -{ -	size_t bytes_to_copy; - -	if (entity->header.type != type) -		return HPI_ERROR_ENTITY_TYPE_MISMATCH; - -	if (hpi_entity_item_count(entity) != item_count) -		return HPI_ERROR_ENTITY_ITEM_COUNT; - -	bytes_to_copy = entity_type_to_size[type] * item_count; -	memcpy(value_dst_p, entity->value, bytes_to_copy); -	return 0; -} - -u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type, -	size_t *item_count, enum e_entity_role *role, void **value) -{ -	u16 err = 0; -	HPI_DEBUG_ASSERT(entity != NULL); - -	if (type) -		*type = entity->header.type; - -	if (role) -		*role = entity->header.role; - -	if (value) -		*value = entity->value; - -	if (item_count != NULL) { -		if (entity->header.type == entity_type_sequence) { -			void *guard_p = hpi_entity_ptr_to_next(entity); -			struct hpi_entity *next = NULL; -			void *contents = entity->value; - -			*item_count = 0; -			while (contents < guard_p) { -				(*item_count)++; -				err = hpi_entity_get_next(contents, 0, -					guard_p, &next); -				if (next == NULL || err) -					break; -				contents = next; -			} -		} else { -			*item_count = hpi_entity_item_count(entity); -		} -	} -	return err; -} - -u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN); -	hm.adapter_index = adapter_index; - -	hpi_send_recv(&hm, &hr); - -	if (hr.error == 0) { -		*ph_gpio = -			hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0); -		if (pw_number_input_bits) -			*pw_number_input_bits = hr.u.l.number_input_bits; -		if (pw_number_output_bits) -			*pw_number_output_bits = hr.u.l.number_output_bits; -	} else -		*ph_gpio = 0; -	return hr.error; -} - -u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 bit_index, u16 *pw_bit_data) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT); -	u32TOINDEX(h_gpio, &hm.adapter_index); -	hm.u.l.bit_index = bit_index; - -	hpi_send_recv(&hm, &hr); - -	*pw_bit_data = hr.u.l.bit_data[0]; -	return hr.error; -} - -u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 aw_all_bit_data[4] -	) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL); -	u32TOINDEX(h_gpio, &hm.adapter_index); - -	hpi_send_recv(&hm, &hr); - -	if (aw_all_bit_data) { -		aw_all_bit_data[0] = hr.u.l.bit_data[0]; -		aw_all_bit_data[1] = hr.u.l.bit_data[1]; -		aw_all_bit_data[2] = hr.u.l.bit_data[2]; -		aw_all_bit_data[3] = hr.u.l.bit_data[3]; -	} -	return hr.error; -} - -u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 bit_index, u16 bit_data) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT); -	u32TOINDEX(h_gpio, &hm.adapter_index); -	hm.u.l.bit_index = bit_index; -	hm.u.l.bit_data = bit_data; - -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio, -	u16 aw_all_bit_data[4] -	) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, -		HPI_GPIO_WRITE_STATUS); -	u32TOINDEX(h_gpio, &hm.adapter_index); - -	hpi_send_recv(&hm, &hr); - -	if (aw_all_bit_data) { -		aw_all_bit_data[0] = hr.u.l.bit_data[0]; -		aw_all_bit_data[1] = hr.u.l.bit_data[1]; -		aw_all_bit_data[2] = hr.u.l.bit_data[2]; -		aw_all_bit_data[3] = hr.u.l.bit_data[3]; -	} -	return hr.error; -} - -u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u32 *ph_async) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT, -		HPI_ASYNCEVENT_OPEN); -	hm.adapter_index = adapter_index; - -	hpi_send_recv(&hm, &hr); - -	if (hr.error == 0) - -		*ph_async = -			hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT, -			adapter_index, 0); -	else -		*ph_async = 0; -	return hr.error; - -} - -u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT, -		HPI_ASYNCEVENT_OPEN); -	u32TOINDEX(h_async, &hm.adapter_index); - -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async, -	u16 maximum_events, struct hpi_async_event *p_events, -	u16 *pw_number_returned) -{ - -	return 0; -} - -u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys, -	u32 h_async, u16 *pw_count) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT, -		HPI_ASYNCEVENT_GETCOUNT); -	u32TOINDEX(h_async, &hm.adapter_index); - -	hpi_send_recv(&hm, &hr); - -	if (hr.error == 0) -		if (pw_count) -			*pw_count = hr.u.as.u.count.count; - -	return hr.error; -} - -u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async, -	u16 maximum_events, struct hpi_async_event *p_events, -	u16 *pw_number_returned) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT, -		HPI_ASYNCEVENT_GET); -	u32TOINDEX(h_async, &hm.adapter_index); - -	hpi_send_recv(&hm, &hr); -	if (!hr.error) { -		memcpy(p_events, &hr.u.as.u.event, -			sizeof(struct hpi_async_event)); -		*pw_number_returned = 1; -	} - -	return hr.error; -} - -u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_nv_memory, u16 *pw_size_in_bytes) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY, -		HPI_NVMEMORY_OPEN); -	hm.adapter_index = adapter_index; - -	hpi_send_recv(&hm, &hr); - -	if (hr.error == 0) { -		*ph_nv_memory = -			hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index, -			0); -		if (pw_size_in_bytes) -			*pw_size_in_bytes = hr.u.n.size_in_bytes; -	} else -		*ph_nv_memory = 0; -	return hr.error; -} - -u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys, -	u32 h_nv_memory, u16 index, u16 *pw_data) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY, -		HPI_NVMEMORY_READ_BYTE); -	u32TOINDEX(h_nv_memory, &hm.adapter_index); -	hm.u.n.address = index; - -	hpi_send_recv(&hm, &hr); - -	*pw_data = hr.u.n.data; -	return hr.error; -} - -u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys, -	u32 h_nv_memory, u16 index, u16 data) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY, -		HPI_NVMEMORY_WRITE_BYTE); -	u32TOINDEX(h_nv_memory, &hm.adapter_index); -	hm.u.n.address = index; -	hm.u.n.data = data; - -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys, -	u16 adapter_index, u16 profile_index, u32 *ph_profile, -	u16 *pw_max_profiles) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, -		HPI_PROFILE_OPEN_ALL); -	hm.adapter_index = adapter_index; -	hm.obj_index = profile_index; -	hpi_send_recv(&hm, &hr); - -	*pw_max_profiles = hr.u.p.u.o.max_profiles; -	if (hr.error == 0) -		*ph_profile = -			hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index, -			profile_index); -	else -		*ph_profile = 0; -	return hr.error; -} - -u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile, -	u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count, -	u32 *pmax_micro_seconds, u32 *pmin_micro_seconds) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET); -	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index); -	hm.u.p.bin_index = bin_index; -	hpi_send_recv(&hm, &hr); -	if (pw_seconds) -		*pw_seconds = hr.u.p.u.t.seconds; -	if (pmicro_seconds) -		*pmicro_seconds = hr.u.p.u.t.micro_seconds; -	if (pcall_count) -		*pcall_count = hr.u.p.u.t.call_count; -	if (pmax_micro_seconds) -		*pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds; -	if (pmin_micro_seconds) -		*pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds; -	return hr.error; -} - -u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys, -	u32 h_profile, u32 *putilization) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, -		HPI_PROFILE_GET_UTILIZATION); -	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index); -	hpi_send_recv(&hm, &hr); -	if (hr.error) { -		if (putilization) -			*putilization = 0; -	} else { -		if (putilization) -			*putilization = hr.u.p.u.t.call_count; -	} -	return hr.error; -} - -u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile, -	u16 bin_index, char *sz_name, u16 name_length) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, -		HPI_PROFILE_GET_NAME); -	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index); -	hm.u.p.bin_index = bin_index; -	hpi_send_recv(&hm, &hr); -	if (hr.error) { -		if (sz_name) -			strcpy(sz_name, "??"); -	} else { -		if (sz_name) -			memcpy(sz_name, (char *)hr.u.p.u.n.sz_name, -				name_length); -	} -	return hr.error; -} - -u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, -		HPI_PROFILE_START_ALL); -	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index); -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, -		HPI_PROFILE_STOP_ALL); -	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index); -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index, -	u32 *ph_watchdog) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG, -		HPI_WATCHDOG_OPEN); -	hm.adapter_index = adapter_index; - -	hpi_send_recv(&hm, &hr); - -	if (hr.error == 0) -		*ph_watchdog = -			hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index, -			0); -	else -		*ph_watchdog = 0; -	return hr.error; -} - -u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog, -	u32 time_millisec) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG, -		HPI_WATCHDOG_SET_TIME); -	u32TOINDEX(h_watchdog, &hm.adapter_index); -	hm.u.w.time_ms = time_millisec; - -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} - -u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog) -{ -	struct hpi_message hm; -	struct hpi_response hr; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG, -		HPI_WATCHDOG_PING); -	u32TOINDEX(h_watchdog, &hm.adapter_index); - -	hpi_send_recv(&hm, &hr); - -	return hr.error; -} diff --git a/sound/pci/asihpi/hpimsginit.c b/sound/pci/asihpi/hpimsginit.c index 8e1d099ed7e..032d563e370 100644 --- a/sound/pci/asihpi/hpimsginit.c +++ b/sound/pci/asihpi/hpimsginit.c @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -32,21 +32,6 @@ static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;  static u16 gwSSX2_bypass;  /** \internal -  * Used by ASIO driver to disable SSX2 for a single process -  * \param phSubSys Pointer to HPI subsystem handle. -  * \param wBypass New bypass setting 0 = off, nonzero = on -  * \return Previous bypass setting. -  */ -u16 hpi_subsys_ssx2_bypass(const struct hpi_hsubsys *ph_subsys, u16 bypass) -{ -	u16 old_value = gwSSX2_bypass; - -	gwSSX2_bypass = bypass; - -	return old_value; -} - -/** \internal    * initialize the HPI message structure    */  static void hpi_init_message(struct hpi_message *phm, u16 object, @@ -61,11 +46,12 @@ static void hpi_init_message(struct hpi_message *phm, u16 object,  	if (gwSSX2_bypass)  		phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;  	else -		phm->type = HPI_TYPE_MESSAGE; +		phm->type = HPI_TYPE_REQUEST;  	phm->object = object;  	phm->function = function;  	phm->version = 0; -	/* Expect adapter index to be set by caller */ +	phm->adapter_index = HPI_ADAPTER_INDEX_INVALID; +	/* Expect actual adapter index to be set by caller */  }  /** \internal @@ -103,7 +89,7 @@ static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,  	memset(phm, 0, sizeof(*phm));  	if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {  		phm->size = size; -		phm->type = HPI_TYPE_MESSAGE; +		phm->type = HPI_TYPE_REQUEST;  		phm->object = object;  		phm->function = function;  		phm->version = 1; diff --git a/sound/pci/asihpi/hpimsginit.h b/sound/pci/asihpi/hpimsginit.h index 864ad020c9b..5b48708c7d1 100644 --- a/sound/pci/asihpi/hpimsginit.h +++ b/sound/pci/asihpi/hpimsginit.h @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -21,11 +21,15 @@   (C) Copyright AudioScience Inc. 2007  *******************************************************************************/  /* Initialise response headers, or msg/response pairs. -Note that it is valid to just init a response e.g. when a lower level is preparing -a response to a message. -However, when sending a message, a matching response buffer always must be prepared +Note that it is valid to just init a response e.g. when a lower level is +preparing a response to a message. +However, when sending a message, a matching response buffer must always be +prepared.  */ +#ifndef _HPIMSGINIT_H_ +#define _HPIMSGINIT_H_ +  void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,  	u16 error); @@ -38,3 +42,5 @@ void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,  void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,  	struct hpi_response_header *phr, u16 res_size, u16 object,  	u16 function); + +#endif				/* _HPIMSGINIT_H_ */ diff --git a/sound/pci/asihpi/hpimsgx.c b/sound/pci/asihpi/hpimsgx.c index f01ab964f60..d4790ddc225 100644 --- a/sound/pci/asihpi/hpimsgx.c +++ b/sound/pci/asihpi/hpimsgx.c @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -16,13 +16,15 @@      along with this program; if not, write to the Free Software      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA -Extended Message Function With Response Cacheing +Extended Message Function With Response Caching  (C) Copyright AudioScience Inc. 2002  *****************************************************************************/  #define SOURCEFILE_NAME "hpimsgx.c"  #include "hpi_internal.h" +#include "hpi_version.h"  #include "hpimsginit.h" +#include "hpicmn.h"  #include "hpimsgx.h"  #include "hpidebug.h" @@ -42,22 +44,24 @@ static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci  	for (i = 0; asihpi_pci_tbl[i].vendor != 0; i++) {  		if (asihpi_pci_tbl[i].vendor != PCI_ANY_ID -			&& asihpi_pci_tbl[i].vendor != pci_info->vendor_id) +			&& asihpi_pci_tbl[i].vendor != +			pci_info->pci_dev->vendor)  			continue;  		if (asihpi_pci_tbl[i].device != PCI_ANY_ID -			&& asihpi_pci_tbl[i].device != pci_info->device_id) +			&& asihpi_pci_tbl[i].device != +			pci_info->pci_dev->device)  			continue;  		if (asihpi_pci_tbl[i].subvendor != PCI_ANY_ID  			&& asihpi_pci_tbl[i].subvendor != -			pci_info->subsys_vendor_id) +			pci_info->pci_dev->subsystem_vendor)  			continue;  		if (asihpi_pci_tbl[i].subdevice != PCI_ANY_ID  			&& asihpi_pci_tbl[i].subdevice != -			pci_info->subsys_device_id) +			pci_info->pci_dev->subsystem_device)  			continue; -		HPI_DEBUG_LOG(DEBUG, " %x,%lu\n", i, -			asihpi_pci_tbl[i].driver_data); +		/* HPI_DEBUG_LOG(DEBUG, " %x,%lx\n", i, +		   asihpi_pci_tbl[i].driver_data); */  		return (hpi_handler_func *) asihpi_pci_tbl[i].driver_data;  	} @@ -67,21 +71,12 @@ static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci  static inline void hw_entry_point(struct hpi_message *phm,  	struct hpi_response *phr)  { - -	hpi_handler_func *ep; - -	if (phm->adapter_index < HPI_MAX_ADAPTERS) { -		ep = (hpi_handler_func *) hpi_entry_points[phm-> -			adapter_index]; -		if (ep) { -			HPI_DEBUG_MESSAGE(DEBUG, phm); -			ep(phm, phr); -			HPI_DEBUG_RESPONSE(phr); -			return; -		} -	} -	hpi_init_response(phr, phm->object, phm->function, -		HPI_ERROR_PROCESSING_MESSAGE); +	if ((phm->adapter_index < HPI_MAX_ADAPTERS) +		&& hpi_entry_points[phm->adapter_index]) +		hpi_entry_points[phm->adapter_index] (phm, phr); +	else +		hpi_init_response(phr, phm->object, phm->function, +			HPI_ERROR_PROCESSING_MESSAGE);  }  static void adapter_open(struct hpi_message *phm, struct hpi_response *phr); @@ -100,6 +95,7 @@ static void instream_close(struct hpi_message *phm, struct hpi_response *phr,  	void *h_owner);  static void HPIMSGX__reset(u16 adapter_index); +  static u16 HPIMSGX__init(struct hpi_message *phm, struct hpi_response *phr);  static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner); @@ -153,8 +149,6 @@ static struct hpi_stream_response  static struct hpi_mixer_response rESP_HPI_MIXER_OPEN[HPI_MAX_ADAPTERS]; -static struct hpi_subsys_response gRESP_HPI_SUBSYS_FIND_ADAPTERS; -  static struct adapter_info aDAPTER_INFO[HPI_MAX_ADAPTERS];  /* use these to keep track of opens from user mode apps/DLLs */ @@ -167,6 +161,11 @@ static struct asi_open_state  static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,  	void *h_owner)  { +	if (phm->adapter_index != HPI_ADAPTER_INDEX_INVALID) +		HPI_DEBUG_LOG(WARNING, +			"suspicious adapter index %d in subsys message 0x%x.\n", +			phm->adapter_index, phm->function); +  	switch (phm->function) {  	case HPI_SUBSYS_GET_VERSION:  		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, @@ -188,7 +187,6 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,  		/* Initialize this module's internal state */  		hpios_msgxlock_init(&msgx_lock);  		memset(&hpi_entry_points, 0, sizeof(hpi_entry_points)); -		hpios_locked_mem_init();  		/* Init subsys_findadapters response to no-adapters */  		HPIMSGX__reset(HPIMSGX_ALLADAPTERS);  		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, @@ -199,90 +197,23 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,  	case HPI_SUBSYS_DRIVER_UNLOAD:  		HPI_COMMON(phm, phr);  		HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS, h_owner); -		hpios_locked_mem_free_all();  		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,  			HPI_SUBSYS_DRIVER_UNLOAD, 0);  		return; -	case HPI_SUBSYS_GET_INFO: -		HPI_COMMON(phm, phr); -		break; - -	case HPI_SUBSYS_FIND_ADAPTERS: -		memcpy(phr, &gRESP_HPI_SUBSYS_FIND_ADAPTERS, -			sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS)); -		break;  	case HPI_SUBSYS_GET_NUM_ADAPTERS: -		memcpy(phr, &gRESP_HPI_SUBSYS_FIND_ADAPTERS, -			sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS)); -		phr->function = HPI_SUBSYS_GET_NUM_ADAPTERS; -		break;  	case HPI_SUBSYS_GET_ADAPTER: -		{ -			int count = phm->adapter_index; -			int index = 0; -			hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, -				HPI_SUBSYS_GET_ADAPTER, 0); - -			/* This is complicated by the fact that we want to -			 * "skip" 0's in the adapter list. -			 * First, make sure we are pointing to a -			 * non-zero adapter type. -			 */ -			while (gRESP_HPI_SUBSYS_FIND_ADAPTERS. -				s.aw_adapter_list[index] == 0) { -				index++; -				if (index >= HPI_MAX_ADAPTERS) -					break; -			} -			while (count) { -				/* move on to the next adapter */ -				index++; -				if (index >= HPI_MAX_ADAPTERS) -					break; -				while (gRESP_HPI_SUBSYS_FIND_ADAPTERS. -					s.aw_adapter_list[index] == 0) { -					index++; -					if (index >= HPI_MAX_ADAPTERS) -						break; -				} -				count--; -			} +		HPI_COMMON(phm, phr); +		break; -			if (index < HPI_MAX_ADAPTERS) { -				phr->u.s.adapter_index = (u16)index; -				phr->u.s.aw_adapter_list[0] = -					gRESP_HPI_SUBSYS_FIND_ADAPTERS. -					s.aw_adapter_list[index]; -			} else { -				phr->u.s.adapter_index = 0; -				phr->u.s.aw_adapter_list[0] = 0; -				phr->error = HPI_ERROR_BAD_ADAPTER_NUMBER; -			} -			break; -		}  	case HPI_SUBSYS_CREATE_ADAPTER:  		HPIMSGX__init(phm, phr);  		break; -	case HPI_SUBSYS_DELETE_ADAPTER: -		HPIMSGX__cleanup(phm->adapter_index, h_owner); -		{ -			struct hpi_message hm; -			struct hpi_response hr; -			/* call to HPI_ADAPTER_CLOSE */ -			hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, -				HPI_ADAPTER_CLOSE); -			hm.adapter_index = phm->adapter_index; -			hw_entry_point(&hm, &hr); -		} -		hw_entry_point(phm, phr); -		gRESP_HPI_SUBSYS_FIND_ADAPTERS.s. -			aw_adapter_list[phm->adapter_index] -			= 0; -		hpi_entry_points[phm->adapter_index] = NULL; -		break; +  	default: -		hw_entry_point(phm, phr); +		/* Must explicitly handle every subsys message in this switch */ +		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function, +			HPI_ERROR_INVALID_FUNC);  		break;  	}  } @@ -297,6 +228,19 @@ static void adapter_message(struct hpi_message *phm, struct hpi_response *phr,  	case HPI_ADAPTER_CLOSE:  		adapter_close(phm, phr);  		break; +	case HPI_ADAPTER_DELETE: +		HPIMSGX__cleanup(phm->adapter_index, h_owner); +		{ +			struct hpi_message hm; +			struct hpi_response hr; +			hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, +				HPI_ADAPTER_CLOSE); +			hm.adapter_index = phm->adapter_index; +			hw_entry_point(&hm, &hr); +		} +		hw_entry_point(phm, phr); +		break; +  	default:  		hw_entry_point(phm, phr);  		break; @@ -370,7 +314,7 @@ void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,  {  	HPI_DEBUG_MESSAGE(DEBUG, phm); -	if (phm->type != HPI_TYPE_MESSAGE) { +	if (phm->type != HPI_TYPE_REQUEST) {  		hpi_init_response(phr, phm->object, phm->function,  			HPI_ERROR_INVALID_TYPE);  		return; @@ -409,33 +353,7 @@ void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,  		break;  	}  	HPI_DEBUG_RESPONSE(phr); -#if 1 -	if (phr->error >= HPI_ERROR_BACKEND_BASE) { -		void *ep = NULL; -		char *ep_name; - -		HPI_DEBUG_MESSAGE(ERROR, phm); - -		if (phm->adapter_index < HPI_MAX_ADAPTERS) -			ep = hpi_entry_points[phm->adapter_index]; - -		/* Don't need this? Have adapter index in debug info -		   Know at driver load time index->backend mapping */ -		if (ep == HPI_6000) -			ep_name = "HPI_6000"; -		else if (ep == HPI_6205) -			ep_name = "HPI_6205"; -		else -			ep_name = "unknown"; - -		HPI_DEBUG_LOG(ERROR, "HPI %s response - error# %d\n", ep_name, -			phr->error); - -		if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) -			hpi_debug_data((u16 *)phm, -				sizeof(*phm) / sizeof(u16)); -	} -#endif +  }  static void adapter_open(struct hpi_message *phm, struct hpi_response *phr) @@ -484,7 +402,7 @@ static void instream_open(struct hpi_message *phm, struct hpi_response *phr,  	else {  		instream_user_open[phm->adapter_index][phm->  			obj_index].open_flag = 1; -		hpios_msgxlock_un_lock(&msgx_lock); +		hpios_msgxlock_unlock(&msgx_lock);  		/* issue a reset */  		hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM, @@ -509,7 +427,7 @@ static void instream_open(struct hpi_message *phm, struct hpi_response *phr,  				sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));  		}  	} -	hpios_msgxlock_un_lock(&msgx_lock); +	hpios_msgxlock_unlock(&msgx_lock);  }  static void instream_close(struct hpi_message *phm, struct hpi_response *phr, @@ -530,7 +448,7 @@ static void instream_close(struct hpi_message *phm, struct hpi_response *phr,  		   phm->wAdapterIndex, phm->wObjIndex, hOwner); */  		instream_user_open[phm->adapter_index][phm->  			obj_index].h_owner = NULL; -		hpios_msgxlock_un_lock(&msgx_lock); +		hpios_msgxlock_unlock(&msgx_lock);  		/* issue a reset */  		hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,  			HPI_ISTREAM_RESET); @@ -556,7 +474,7 @@ static void instream_close(struct hpi_message *phm, struct hpi_response *phr,  				obj_index].h_owner);  		phr->error = HPI_ERROR_OBJ_NOT_OPEN;  	} -	hpios_msgxlock_un_lock(&msgx_lock); +	hpios_msgxlock_unlock(&msgx_lock);  }  static void outstream_open(struct hpi_message *phm, struct hpi_response *phr, @@ -581,7 +499,7 @@ static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,  	else {  		outstream_user_open[phm->adapter_index][phm->  			obj_index].open_flag = 1; -		hpios_msgxlock_un_lock(&msgx_lock); +		hpios_msgxlock_unlock(&msgx_lock);  		/* issue a reset */  		hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM, @@ -606,7 +524,7 @@ static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,  				sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));  		}  	} -	hpios_msgxlock_un_lock(&msgx_lock); +	hpios_msgxlock_unlock(&msgx_lock);  }  static void outstream_close(struct hpi_message *phm, struct hpi_response *phr, @@ -628,7 +546,7 @@ static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,  		   phm->wAdapterIndex, phm->wObjIndex, hOwner); */  		outstream_user_open[phm->adapter_index][phm->  			obj_index].h_owner = NULL; -		hpios_msgxlock_un_lock(&msgx_lock); +		hpios_msgxlock_unlock(&msgx_lock);  		/* issue a reset */  		hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,  			HPI_OSTREAM_RESET); @@ -654,7 +572,7 @@ static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,  				obj_index].h_owner);  		phr->error = HPI_ERROR_OBJ_NOT_OPEN;  	} -	hpios_msgxlock_un_lock(&msgx_lock); +	hpios_msgxlock_unlock(&msgx_lock);  }  static u16 adapter_prepare(u16 adapter) @@ -683,16 +601,9 @@ static u16 adapter_prepare(u16 adapter)  	if (hr.error)  		return hr.error; -	aDAPTER_INFO[adapter].num_outstreams = hr.u.a.num_outstreams; -	aDAPTER_INFO[adapter].num_instreams = hr.u.a.num_instreams; -	aDAPTER_INFO[adapter].type = hr.u.a.adapter_type; - -	gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list[adapter] = -		hr.u.a.adapter_type; -	gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters++; -	if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters > HPI_MAX_ADAPTERS) -		gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters = -			HPI_MAX_ADAPTERS; +	aDAPTER_INFO[adapter].num_outstreams = hr.u.ax.info.num_outstreams; +	aDAPTER_INFO[adapter].num_instreams = hr.u.ax.info.num_instreams; +	aDAPTER_INFO[adapter].type = hr.u.ax.info.adapter_type;  	/* call to HPI_OSTREAM_OPEN */  	for (i = 0; i < aDAPTER_INFO[adapter].num_outstreams; i++) { @@ -727,7 +638,7 @@ static u16 adapter_prepare(u16 adapter)  	memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,  		sizeof(rESP_HPI_MIXER_OPEN[0])); -	return gRESP_HPI_SUBSYS_FIND_ADAPTERS.h.error; +	return 0;  }  static void HPIMSGX__reset(u16 adapter_index) @@ -737,12 +648,6 @@ static void HPIMSGX__reset(u16 adapter_index)  	struct hpi_response hr;  	if (adapter_index == HPIMSGX_ALLADAPTERS) { -		/* reset all responses to contain errors */ -		hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, -			HPI_SUBSYS_FIND_ADAPTERS, 0); -		memcpy(&gRESP_HPI_SUBSYS_FIND_ADAPTERS, &hr, -			sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS)); -  		for (adapter = 0; adapter < HPI_MAX_ADAPTERS; adapter++) {  			hpi_init_response(&hr, HPI_OBJ_ADAPTER, @@ -783,12 +688,6 @@ static void HPIMSGX__reset(u16 adapter_index)  			rESP_HPI_ISTREAM_OPEN[adapter_index][i].h.error =  				HPI_ERROR_INVALID_OBJ;  		} -		if (gRESP_HPI_SUBSYS_FIND_ADAPTERS. -			s.aw_adapter_list[adapter_index]) { -			gRESP_HPI_SUBSYS_FIND_ADAPTERS. -				s.aw_adapter_list[adapter_index] = 0; -			gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters--; -		}  	}  } @@ -802,15 +701,9 @@ static u16 HPIMSGX__init(struct hpi_message *phm,  	hpi_handler_func *entry_point_func;  	struct hpi_response hr; -	if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters >= HPI_MAX_ADAPTERS) -		return HPI_ERROR_BAD_ADAPTER_NUMBER; -  	/* Init response here so we can pass in previous adapter list */  	hpi_init_response(&hr, phm->object, phm->function,  		HPI_ERROR_INVALID_OBJ); -	memcpy(hr.u.s.aw_adapter_list, -		gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list, -		sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list));  	entry_point_func =  		hpi_lookup_entry_point_function(phm->u.s.resource.r.pci); @@ -823,7 +716,7 @@ static u16 HPIMSGX__init(struct hpi_message *phm,  		return phr->error;  	}  	if (hr.error == 0) { -		/* the adapter was created succesfully +		/* the adapter was created successfully  		   save the mapping for future use */  		hpi_entry_points[hr.u.s.adapter_index] = entry_point_func;  		/* prepare adapter (pre-open streams etc.) */ @@ -860,7 +753,7 @@ static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner)  				struct hpi_response hr;  				HPI_DEBUG_LOG(DEBUG, -					"close adapter %d ostream %d\n", +					"Close adapter %d ostream %d\n",  					adapter, i);  				hpi_init_message_response(&hm, &hr, @@ -884,7 +777,7 @@ static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner)  				struct hpi_response hr;  				HPI_DEBUG_LOG(DEBUG, -					"close adapter %d istream %d\n", +					"Close adapter %d istream %d\n",  					adapter, i);  				hpi_init_message_response(&hm, &hr, diff --git a/sound/pci/asihpi/hpimsgx.h b/sound/pci/asihpi/hpimsgx.h index fd49e7542a8..37f3efd95a7 100644 --- a/sound/pci/asihpi/hpimsgx.h +++ b/sound/pci/asihpi/hpimsgx.h @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c index 62895a719fc..7f0272032fb 100644 --- a/sound/pci/asihpi/hpioctl.c +++ b/sound/pci/asihpi/hpioctl.c @@ -1,7 +1,7 @@  /*******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -21,16 +21,20 @@ Common Linux HPI ioctl and module probe/remove functions  #define SOURCEFILE_NAME "hpioctl.c"  #include "hpi_internal.h" +#include "hpi_version.h"  #include "hpimsginit.h"  #include "hpidebug.h"  #include "hpimsgx.h"  #include "hpioctl.h" +#include "hpicmn.h"  #include <linux/fs.h>  #include <linux/slab.h>  #include <linux/moduleparam.h>  #include <asm/uaccess.h> +#include <linux/pci.h>  #include <linux/stringify.h> +#include <linux/module.h>  #ifdef MODULE_FIRMWARE  MODULE_FIRMWARE("asihpi/dsp5000.bin"); @@ -45,7 +49,7 @@ MODULE_FIRMWARE("asihpi/dsp8900.bin");  static int prealloc_stream_buf;  module_param(prealloc_stream_buf, int, S_IRUGO);  MODULE_PARM_DESC(prealloc_stream_buf, -	"preallocate size for per-adapter stream buffer"); +	"Preallocate size for per-adapter stream buffer");  /* Allow the debug level to be changed after module load.   E.g.   echo 2 > /sys/module/asihpi/parameters/hpiDebugLevel @@ -62,9 +66,7 @@ static struct hpi_adapter adapters[HPI_MAX_ADAPTERS];  static void hpi_send_recv_f(struct hpi_message *phm, struct hpi_response *phr,  	struct file *file)  { -	int adapter = phm->adapter_index; - -	if ((adapter >= HPI_MAX_ADAPTERS || adapter < 0) +	if ((phm->adapter_index >= HPI_MAX_ADAPTERS)  		&& (phm->object != HPI_OBJ_SUBSYSTEM))  		phr->error = HPI_ERROR_INVALID_OBJ_INDEX;  	else @@ -105,7 +107,6 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  	union hpi_response_buffer_v1 *hr;  	u16 res_max_size;  	u32 uncopied_bytes; -	struct hpi_adapter *pa = NULL;  	int err = 0;  	if (cmd != HPI_IOCTL_LINUX) @@ -121,8 +122,8 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  	phpi_ioctl_data = (struct hpi_ioctl_linux __user *)arg;  	/* Read the message and response pointers from user space.  */ -	if (get_user(puhm, &phpi_ioctl_data->phm) || -	    get_user(puhr, &phpi_ioctl_data->phr)) { +	if (get_user(puhm, &phpi_ioctl_data->phm) +		|| get_user(puhr, &phpi_ioctl_data->phr)) {  		err = -EFAULT;  		goto out;  	} @@ -135,7 +136,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  	if (hm->h.size > sizeof(*hm))  		hm->h.size = sizeof(*hm); -	/*printk(KERN_INFO "message size %d\n", hm->h.wSize); */ +	/* printk(KERN_INFO "message size %d\n", hm->h.wSize); */  	uncopied_bytes = copy_from_user(hm, puhm, hm->h.size);  	if (uncopied_bytes) { @@ -155,38 +156,37 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  		goto out;  	} -	pa = &adapters[hm->h.adapter_index]; -	hr->h.size = 0; -	if (hm->h.object == HPI_OBJ_SUBSYSTEM) { -		switch (hm->h.function) { -		case HPI_SUBSYS_CREATE_ADAPTER: -		case HPI_SUBSYS_DELETE_ADAPTER: -			/* Application must not use these functions! */ -			hr->h.size = sizeof(hr->h); -			hr->h.error = HPI_ERROR_INVALID_OPERATION; -			hr->h.function = hm->h.function; -			uncopied_bytes = copy_to_user(puhr, hr, hr->h.size); -			if (uncopied_bytes) -				err = -EFAULT; -			else -				err = 0; -			goto out; +	switch (hm->h.function) { +	case HPI_SUBSYS_CREATE_ADAPTER: +	case HPI_ADAPTER_DELETE: +		/* Application must not use these functions! */ +		hr->h.size = sizeof(hr->h); +		hr->h.error = HPI_ERROR_INVALID_OPERATION; +		hr->h.function = hm->h.function; +		uncopied_bytes = copy_to_user(puhr, hr, hr->h.size); +		if (uncopied_bytes) +			err = -EFAULT; +		else +			err = 0; +		goto out; +	} -		default: -			hpi_send_recv_f(&hm->m0, &hr->r0, file); -		} +	hr->h.size = res_max_size; +	if (hm->h.object == HPI_OBJ_SUBSYSTEM) { +		hpi_send_recv_f(&hm->m0, &hr->r0, file);  	} else {  		u16 __user *ptr = NULL;  		u32 size = 0; -  		/* -1=no data 0=read from user mem, 1=write to user mem */  		int wrflag = -1; -		u32 adapter = hm->h.adapter_index; +		struct hpi_adapter *pa = NULL; + +		if (hm->h.adapter_index < ARRAY_SIZE(adapters)) +			pa = &adapters[hm->h.adapter_index]; -		if ((hm->h.adapter_index > HPI_MAX_ADAPTERS) || (!pa->type)) { -			hpi_init_response(&hr->r0, HPI_OBJ_ADAPTER, -				HPI_ADAPTER_OPEN, -				HPI_ERROR_BAD_ADAPTER_NUMBER); +		if (!pa || !pa->adapter || !pa->adapter->type) { +			hpi_init_response(&hr->r0, hm->h.object, +				hm->h.function, HPI_ERROR_BAD_ADAPTER_NUMBER);  			uncopied_bytes =  				copy_to_user(puhr, hr, sizeof(hr->h)); @@ -197,7 +197,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  			goto out;  		} -		if (mutex_lock_interruptible(&adapters[adapter].mutex)) { +		if (mutex_lock_interruptible(&pa->mutex)) {  			err = -EINTR;  			goto out;  		} @@ -216,7 +216,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  				 */  				if (pa->buffer_size < size) {  					HPI_DEBUG_LOG(DEBUG, -						"realloc adapter %d stream " +						"Realloc adapter %d stream "  						"buffer from %zd to %d\n",  						hm->h.adapter_index,  						pa->buffer_size, size); @@ -233,8 +233,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  							"stream buffer size %d\n",  							size); -						mutex_unlock(&adapters -							[adapter].mutex); +						mutex_unlock(&pa->mutex);  						err = -EINVAL;  						goto out;  					} @@ -259,7 +258,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  				copy_from_user(pa->p_buffer, ptr, size);  			if (uncopied_bytes)  				HPI_DEBUG_LOG(WARNING, -					"missed %d of %d " +					"Missed %d of %d "  					"bytes from user\n", uncopied_bytes,  					size);  		} @@ -271,11 +270,11 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  				copy_to_user(ptr, pa->p_buffer, size);  			if (uncopied_bytes)  				HPI_DEBUG_LOG(WARNING, -					"missed %d of %d " "bytes to user\n", +					"Missed %d of %d " "bytes to user\n",  					uncopied_bytes, size);  		} -		mutex_unlock(&adapters[adapter].mutex); +		mutex_unlock(&pa->mutex);  	}  	/* on return response size must be set */ @@ -290,9 +289,9 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)  	if (hr->h.size > res_max_size) {  		HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size,  			res_max_size); -		/*HPI_DEBUG_MESSAGE(ERROR, hm); */ -		err = -EFAULT; -		goto out; +		hr->h.error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL; +		hr->h.specific_error = hr->h.size; +		hr->h.size = sizeof(hr->h);  	}  	uncopied_bytes = copy_to_user(puhr, hr, hr->h.size); @@ -308,10 +307,11 @@ out:  	return err;  } -int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev, -	const struct pci_device_id *pci_id) +int asihpi_adapter_probe(struct pci_dev *pci_dev, +			 const struct pci_device_id *pci_id)  { -	int err, idx, nm; +	int idx, nm; +	int adapter_index;  	unsigned int memlen;  	struct hpi_message hm;  	struct hpi_response hr; @@ -320,58 +320,47 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,  	memset(&adapter, 0, sizeof(adapter)); -	printk(KERN_DEBUG "probe PCI device (%04x:%04x,%04x:%04x,%04x)\n", -		pci_dev->vendor, pci_dev->device, pci_dev->subsystem_vendor, +	dev_printk(KERN_DEBUG, &pci_dev->dev, +		"probe %04x:%04x,%04x:%04x,%04x\n", pci_dev->vendor, +		pci_dev->device, pci_dev->subsystem_vendor,  		pci_dev->subsystem_device, pci_dev->devfn); +	if (pci_enable_device(pci_dev) < 0) { +		dev_err(&pci_dev->dev, +			"pci_enable_device failed, disabling device\n"); +		return -EIO; +	} + +	pci_set_master(pci_dev);	/* also sets latency timer if < 16 */ +  	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,  		HPI_SUBSYS_CREATE_ADAPTER);  	hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER,  		HPI_ERROR_PROCESSING_MESSAGE); -	hm.adapter_index = -1;	/* an invalid index */ - -	/* fill in HPI_PCI information from kernel provided information */ -	adapter.pci = pci_dev; +	hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;  	nm = HPI_MAX_ADAPTER_MEM_SPACES;  	for (idx = 0; idx < nm; idx++) { -		HPI_DEBUG_LOG(INFO, "resource %d %s %08llx-%08llx %04llx\n", -			idx, pci_dev->resource[idx].name, -			(unsigned long long)pci_resource_start(pci_dev, idx), -			(unsigned long long)pci_resource_end(pci_dev, idx), -			(unsigned long long)pci_resource_flags(pci_dev, idx)); +		HPI_DEBUG_LOG(INFO, "resource %d %pR\n", idx, +			&pci_dev->resource[idx]);  		if (pci_resource_flags(pci_dev, idx) & IORESOURCE_MEM) {  			memlen = pci_resource_len(pci_dev, idx); -			adapter.ap_remapped_mem_base[idx] = +			pci.ap_mem_base[idx] =  				ioremap(pci_resource_start(pci_dev, idx),  				memlen); -			if (!adapter.ap_remapped_mem_base[idx]) { +			if (!pci.ap_mem_base[idx]) {  				HPI_DEBUG_LOG(ERROR,  					"ioremap failed, aborting\n");  				/* unmap previously mapped pci mem space */  				goto err;  			}  		} - -		pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx];  	} -	/* could replace Pci with direct pointer to pci_dev for linux -	   Instead wrap accessor functions for IDs etc. -	   Would it work for windows? -	 */ -	pci.bus_number = pci_dev->bus->number; -	pci.vendor_id = (u16)pci_dev->vendor; -	pci.device_id = (u16)pci_dev->device; -	pci.subsys_vendor_id = (u16)(pci_dev->subsystem_vendor & 0xffff); -	pci.subsys_device_id = (u16)(pci_dev->subsystem_device & 0xffff); -	pci.device_number = pci_dev->devfn; -	pci.interrupt = pci_dev->irq; -	pci.p_os_data = pci_dev; - +	pci.pci_dev = pci_dev;  	hm.u.s.resource.bus_type = HPI_BUS_PCI;  	hm.u.s.resource.r.pci = &pci; @@ -380,6 +369,9 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,  	if (hr.error)  		goto err; +	adapter_index = hr.u.s.adapter_index; +	adapter.adapter = hpi_find_adapter(adapter_index); +  	if (prealloc_stream_buf) {  		adapter.p_buffer = vmalloc(prealloc_stream_buf);  		if (!adapter.p_buffer) { @@ -391,32 +383,31 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,  		}  	} -	adapter.index = hr.u.s.adapter_index; -	adapter.type = hr.u.s.aw_adapter_list[adapter.index]; -	hm.adapter_index = adapter.index; +	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, +		HPI_ADAPTER_OPEN); +	hm.adapter_index = adapter.adapter->index; +	hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL); -	err = hpi_adapter_open(NULL, adapter.index); -	if (err) +	if (hr.error)  		goto err; -	adapter.snd_card_asihpi = NULL;  	/* WARNING can't init mutex in 'adapter'  	 * and then copy it to adapters[] ?!?!  	 */ -	adapters[hr.u.s.adapter_index] = adapter; -	mutex_init(&adapters[adapter.index].mutex); -	pci_set_drvdata(pci_dev, &adapters[adapter.index]); +	adapters[adapter_index] = adapter; +	mutex_init(&adapters[adapter_index].mutex); +	pci_set_drvdata(pci_dev, &adapters[adapter_index]); -	printk(KERN_INFO "probe found adapter ASI%04X HPI index #%d.\n", -		adapter.type, adapter.index); +	dev_info(&pci_dev->dev, "probe succeeded for ASI%04X HPI index %d\n", +		 adapter.adapter->type, adapter_index);  	return 0;  err:  	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) { -		if (adapter.ap_remapped_mem_base[idx]) { -			iounmap(adapter.ap_remapped_mem_base[idx]); -			adapter.ap_remapped_mem_base[idx] = NULL; +		if (pci.ap_mem_base[idx]) { +			iounmap(pci.ap_mem_base[idx]); +			pci.ap_mem_base[idx] = NULL;  		}  	} @@ -429,41 +420,39 @@ err:  	return -ENODEV;  } -void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev) +void asihpi_adapter_remove(struct pci_dev *pci_dev)  {  	int idx;  	struct hpi_message hm;  	struct hpi_response hr;  	struct hpi_adapter *pa; -	pa = (struct hpi_adapter *)pci_get_drvdata(pci_dev); +	struct hpi_pci pci; -	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, -		HPI_SUBSYS_DELETE_ADAPTER); -	hm.adapter_index = pa->index; +	pa = pci_get_drvdata(pci_dev); +	pci = pa->adapter->pci; + +	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, +		HPI_ADAPTER_DELETE); +	hm.adapter_index = pa->adapter->index;  	hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);  	/* unmap PCI memory space, mapped during device init. */  	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) { -		if (pa->ap_remapped_mem_base[idx]) { -			iounmap(pa->ap_remapped_mem_base[idx]); -			pa->ap_remapped_mem_base[idx] = NULL; -		} +		if (pci.ap_mem_base[idx]) +			iounmap(pci.ap_mem_base[idx]);  	} -	if (pa->p_buffer) { -		pa->buffer_size = 0; +	if (pa->p_buffer)  		vfree(pa->p_buffer); -	} -	pci_set_drvdata(pci_dev, NULL); -	/* -	   printk(KERN_INFO "PCI device (%04x:%04x,%04x:%04x,%04x)," -	   " HPI index # %d, removed.\n", -	   pci_dev->vendor, pci_dev->device, -	   pci_dev->subsystem_vendor, -	   pci_dev->subsystem_device, pci_dev->devfn, -	   pa->index); -	 */ +	if (1) +		dev_info(&pci_dev->dev, +			 "remove %04x:%04x,%04x:%04x,%04x, HPI index %d\n", +			 pci_dev->vendor, pci_dev->device, +			 pci_dev->subsystem_vendor, pci_dev->subsystem_device, +			 pci_dev->devfn, pa->adapter->index); + +	memset(pa, 0, sizeof(*pa));  }  void __init asihpi_init(void) diff --git a/sound/pci/asihpi/hpioctl.h b/sound/pci/asihpi/hpioctl.h index 847f72f03fe..0d767e10ac4 100644 --- a/sound/pci/asihpi/hpioctl.h +++ b/sound/pci/asihpi/hpioctl.h @@ -1,7 +1,7 @@  /*******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -19,9 +19,9 @@  Linux HPI ioctl, and shared module init functions  *******************************************************************************/ -int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev, -	const struct pci_device_id *pci_id); -void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev); +int asihpi_adapter_probe(struct pci_dev *pci_dev, +			 const struct pci_device_id *pci_id); +void asihpi_adapter_remove(struct pci_dev *pci_dev);  void __init asihpi_init(void);  void __exit asihpi_exit(void); diff --git a/sound/pci/asihpi/hpios.c b/sound/pci/asihpi/hpios.c index 742ee12a9e1..5ef4fe96436 100644 --- a/sound/pci/asihpi/hpios.c +++ b/sound/pci/asihpi/hpios.c @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2012  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -39,13 +39,9 @@ void hpios_delay_micro_seconds(u32 num_micro_sec)  } -void hpios_locked_mem_init(void) -{ -} +/** Allocate an area of locked memory for bus master DMA operations. -/** Allocated an area of locked memory for bus master DMA operations. - -On error, return -ENOMEM, and *pMemArea.size = 0 +If allocation fails, return 1, and *pMemArea.size = 0  */  u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_mem_area, u32 size,  	struct pci_dev *pdev) @@ -66,7 +62,7 @@ u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_mem_area, u32 size,  		HPI_DEBUG_LOG(WARNING,  			"failed to allocate %d bytes locked memory\n", size);  		p_mem_area->size = 0; -		return -ENOMEM; +		return 1;  	}  } @@ -85,7 +81,3 @@ u16 hpios_locked_mem_free(struct consistent_dma_area *p_mem_area)  		return 1;  	}  } - -void hpios_locked_mem_free_all(void) -{ -} diff --git a/sound/pci/asihpi/hpios.h b/sound/pci/asihpi/hpios.h index 370f39b43f8..d3fbd0d76c3 100644 --- a/sound/pci/asihpi/hpios.h +++ b/sound/pci/asihpi/hpios.h @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as @@ -27,12 +27,9 @@ HPI Operating System Specific macros for Linux Kernel driver  #define HPI_OS_LINUX_KERNEL  #define HPI_OS_DEFINED -#define HPI_KERNEL_MODE - -#define HPI_REASSIGN_DUPLICATE_ADAPTER_IDX +#define HPI_BUILD_KERNEL_MODE  #include <linux/io.h> -#include <asm/system.h>  #include <linux/ioctl.h>  #include <linux/kernel.h>  #include <linux/string.h> @@ -40,6 +37,7 @@ HPI Operating System Specific macros for Linux Kernel driver  #include <linux/firmware.h>  #include <linux/interrupt.h>  #include <linux/pci.h> +#include <linux/mutex.h>  #define HPI_NO_OS_FILE_OPS @@ -135,35 +133,33 @@ static inline void cond_unlock(struct hpios_spinlock *l)  #define hpios_msgxlock_init(obj)      spin_lock_init(&(obj)->lock)  #define hpios_msgxlock_lock(obj)   cond_lock(obj) -#define hpios_msgxlock_un_lock(obj) cond_unlock(obj) +#define hpios_msgxlock_unlock(obj) cond_unlock(obj)  #define hpios_dsplock_init(obj)       spin_lock_init(&(obj)->dsp_lock.lock)  #define hpios_dsplock_lock(obj)    cond_lock(&(obj)->dsp_lock)  #define hpios_dsplock_unlock(obj)  cond_unlock(&(obj)->dsp_lock)  #ifdef CONFIG_SND_DEBUG -#define HPI_DEBUG +#define HPI_BUILD_DEBUG  #endif  #define HPI_ALIST_LOCKING  #define hpios_alistlock_init(obj)    spin_lock_init(&((obj)->list_lock.lock))  #define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock)) -#define hpios_alistlock_un_lock(obj) spin_unlock(&((obj)->list_lock.lock)) +#define hpios_alistlock_unlock(obj) spin_unlock(&((obj)->list_lock.lock)) + +struct snd_card; +/** pci drvdata points to an instance of this struct */  struct hpi_adapter { +	struct hpi_adapter_obj *adapter; +	struct snd_card *snd_card; +  	/* mutex prevents contention for one card  	   between multiple user programs (via ioctl) */  	struct mutex mutex; -	u16 index; -	u16 type; - -	/* ALSA card structure */ -	void *snd_card_asihpi; -  	char *p_buffer;  	size_t buffer_size; -	struct pci_dev *pci; -	void __iomem *ap_remapped_mem_base[HPI_MAX_ADAPTER_MEM_SPACES];  };  #endif diff --git a/sound/pci/asihpi/hpipcida.h b/sound/pci/asihpi/hpipcida.h index bb30868ce1a..db570ddf64b 100644 --- a/sound/pci/asihpi/hpipcida.h +++ b/sound/pci/asihpi/hpipcida.h @@ -1,7 +1,7 @@  /******************************************************************************      AudioScience HPI driver -    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com> +    Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as  | 
