xref: /OK3568_Linux_fs/kernel/sound/pci/asihpi/hpidspcd.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /***********************************************************************/
3*4882a593Smuzhiyun /**
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun     AudioScience HPI driver
6*4882a593Smuzhiyun     Copyright (C) 1997-2011  AudioScience Inc. <support@audioscience.com>
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun \file
10*4882a593Smuzhiyun Functions for reading DSP code to load into DSP
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun */
13*4882a593Smuzhiyun /***********************************************************************/
14*4882a593Smuzhiyun #ifndef _HPIDSPCD_H_
15*4882a593Smuzhiyun #define _HPIDSPCD_H_
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include "hpi_internal.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /** Header structure for dsp firmware file
20*4882a593Smuzhiyun  This structure must match that used in s2bin.c for generation of asidsp.bin
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun /*#ifndef DISABLE_PRAGMA_PACK1 */
23*4882a593Smuzhiyun /*#pragma pack(push, 1) */
24*4882a593Smuzhiyun /*#endif */
25*4882a593Smuzhiyun struct code_header {
26*4882a593Smuzhiyun 	/** Size in bytes including header */
27*4882a593Smuzhiyun 	u32 size;
28*4882a593Smuzhiyun 	/** File type tag "CODE" == 0x45444F43 */
29*4882a593Smuzhiyun 	u32 type;
30*4882a593Smuzhiyun 	/** Adapter model number */
31*4882a593Smuzhiyun 	u32 adapter;
32*4882a593Smuzhiyun 	/** Firmware version*/
33*4882a593Smuzhiyun 	u32 version;
34*4882a593Smuzhiyun 	/** Data checksum */
35*4882a593Smuzhiyun 	u32 checksum;
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun /*#ifndef DISABLE_PRAGMA_PACK1 */
38*4882a593Smuzhiyun /*#pragma pack(pop) */
39*4882a593Smuzhiyun /*#endif */
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /*? Don't need the pragmas? */
42*4882a593Smuzhiyun compile_time_assert((sizeof(struct code_header) == 20), code_header_size);
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /** Descriptor for dspcode from firmware loader */
45*4882a593Smuzhiyun struct dsp_code {
46*4882a593Smuzhiyun 	/** copy of  file header */
47*4882a593Smuzhiyun 	struct code_header header;
48*4882a593Smuzhiyun 	/** Expected number of words in the whole dsp code,INCL header */
49*4882a593Smuzhiyun 	u32 block_length;
50*4882a593Smuzhiyun 	/** Number of words read so far */
51*4882a593Smuzhiyun 	u32 word_count;
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	/** internal state of DSP code reader */
54*4882a593Smuzhiyun 	struct dsp_code_private *pvt;
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /** Prepare *psDspCode to refer to the requested adapter's firmware.
58*4882a593Smuzhiyun Code file name is obtained from HpiOs_GetDspCodePath
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun \return 0 for success, or error code if requested code is not available
61*4882a593Smuzhiyun */
62*4882a593Smuzhiyun short hpi_dsp_code_open(
63*4882a593Smuzhiyun 	/** Code identifier, usually adapter family */
64*4882a593Smuzhiyun 	u32 adapter, void *pci_dev,
65*4882a593Smuzhiyun 	/** Pointer to DSP code control structure */
66*4882a593Smuzhiyun 	struct dsp_code *ps_dsp_code,
67*4882a593Smuzhiyun 	/** Pointer to dword to receive OS specific error code */
68*4882a593Smuzhiyun 	u32 *pos_error_code);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /** Close the DSP code file */
71*4882a593Smuzhiyun void hpi_dsp_code_close(struct dsp_code *ps_dsp_code);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /** Rewind to the beginning of the DSP code file (for verify) */
74*4882a593Smuzhiyun void hpi_dsp_code_rewind(struct dsp_code *ps_dsp_code);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun /** Read one word from the dsp code file
77*4882a593Smuzhiyun 	\return 0 for success, or error code if eof, or block length exceeded
78*4882a593Smuzhiyun */
79*4882a593Smuzhiyun short hpi_dsp_code_read_word(struct dsp_code *ps_dsp_code,
80*4882a593Smuzhiyun 				      /**< DSP code descriptor */
81*4882a593Smuzhiyun 	u32 *pword /**< Where to store the read word */
82*4882a593Smuzhiyun 	);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /** Get a block of dsp code into an internal buffer, and provide a pointer to
85*4882a593Smuzhiyun that buffer. (If dsp code is already an array in memory, it is referenced,
86*4882a593Smuzhiyun not copied.)
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun \return Error if requested number of words are not available
89*4882a593Smuzhiyun */
90*4882a593Smuzhiyun short hpi_dsp_code_read_block(size_t words_requested,
91*4882a593Smuzhiyun 	struct dsp_code *ps_dsp_code,
92*4882a593Smuzhiyun 	/* Pointer to store (Pointer to code buffer) */
93*4882a593Smuzhiyun 	u32 **ppblock);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun #endif
96