1 /***********************************************************************/
4 AudioScience HPI driver
5 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of version 2 of the GNU General Public License as
9 published by the Free Software Foundation;
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 Functions for reading DSP code using
22 hotplug firmware loader from individual dsp code files
24 /***********************************************************************/
25 #define SOURCEFILE_NAME "hpidspcd.c"
28 #include "hpi_version.h"
30 struct dsp_code_private
{
31 /** Firmware descriptor */
32 const struct firmware
*firmware
;
36 /*-------------------------------------------------------------------*/
37 short hpi_dsp_code_open(u32 adapter
, void *os_data
, struct dsp_code
*dsp_code
,
40 const struct firmware
*firmware
;
41 struct pci_dev
*dev
= os_data
;
42 struct code_header header
;
44 short err_ret
= HPI_ERROR_DSP_FILE_NOT_FOUND
;
47 sprintf(fw_name
, "asihpi/dsp%04x.bin", adapter
);
49 err
= request_firmware(&firmware
, fw_name
, &dev
->dev
);
51 if (err
|| !firmware
) {
52 dev_err(&dev
->dev
, "%d, request_firmware failed for %s\n",
56 if (firmware
->size
< sizeof(header
)) {
57 dev_err(&dev
->dev
, "Header size too small %s\n", fw_name
);
60 memcpy(&header
, firmware
->data
, sizeof(header
));
62 if ((header
.type
!= 0x45444F43) || /* "CODE" */
63 (header
.adapter
!= adapter
)
64 || (header
.size
!= firmware
->size
)) {
66 "Invalid firmware header size %d != file %zd\n",
67 header
.size
, firmware
->size
);
71 if ((header
.version
>> 9) != (HPI_VER
>> 9)) {
72 /* Consider even and subsequent odd minor versions to be compatible */
73 dev_err(&dev
->dev
, "Incompatible firmware version DSP image %X != Driver %X\n",
74 header
.version
, HPI_VER
);
78 if (header
.version
!= HPI_VER
) {
80 "Firmware: release version mismatch DSP image %X != Driver %X\n",
81 header
.version
, HPI_VER
);
84 HPI_DEBUG_LOG(DEBUG
, "dsp code %s opened\n", fw_name
);
85 dsp_code
->pvt
= kmalloc(sizeof(*dsp_code
->pvt
), GFP_KERNEL
);
87 err_ret
= HPI_ERROR_MEMORY_ALLOC
;
91 dsp_code
->pvt
->dev
= dev
;
92 dsp_code
->pvt
->firmware
= firmware
;
93 dsp_code
->header
= header
;
94 dsp_code
->block_length
= header
.size
/ sizeof(u32
);
95 dsp_code
->word_count
= sizeof(header
) / sizeof(u32
);
99 release_firmware(firmware
);
101 dsp_code
->block_length
= 0;
105 /*-------------------------------------------------------------------*/
106 void hpi_dsp_code_close(struct dsp_code
*dsp_code
)
108 HPI_DEBUG_LOG(DEBUG
, "dsp code closed\n");
109 release_firmware(dsp_code
->pvt
->firmware
);
110 kfree(dsp_code
->pvt
);
113 /*-------------------------------------------------------------------*/
114 void hpi_dsp_code_rewind(struct dsp_code
*dsp_code
)
116 /* Go back to start of data, after header */
117 dsp_code
->word_count
= sizeof(struct code_header
) / sizeof(u32
);
120 /*-------------------------------------------------------------------*/
121 short hpi_dsp_code_read_word(struct dsp_code
*dsp_code
, u32
*pword
)
123 if (dsp_code
->word_count
+ 1 > dsp_code
->block_length
)
124 return HPI_ERROR_DSP_FILE_FORMAT
;
126 *pword
= ((u32
*)(dsp_code
->pvt
->firmware
->data
))[dsp_code
->
128 dsp_code
->word_count
++;
132 /*-------------------------------------------------------------------*/
133 short hpi_dsp_code_read_block(size_t words_requested
,
134 struct dsp_code
*dsp_code
, u32
**ppblock
)
136 if (dsp_code
->word_count
+ words_requested
> dsp_code
->block_length
)
137 return HPI_ERROR_DSP_FILE_FORMAT
;
140 ((u32
*)(dsp_code
->pvt
->firmware
->data
)) +
141 dsp_code
->word_count
;
142 dsp_code
->word_count
+= words_requested
;