Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1 | /***********************************************************************/ |
| 2 | /*! |
| 3 | |
| 4 | AudioScience HPI driver |
| 5 | Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com> |
| 6 | |
| 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; |
| 10 | |
| 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. |
| 15 | |
| 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 |
| 19 | |
| 20 | \file |
| 21 | Functions for reading DSP code to load into DSP |
| 22 | |
| 23 | (Linux only:) If DSPCODE_FIRMWARE_LOADER is defined, code is read using |
| 24 | hotplug firmware loader from individual dsp code files |
| 25 | |
| 26 | If neither of the above is defined, code is read from linked arrays. |
| 27 | DSPCODE_ARRAY is defined. |
| 28 | |
| 29 | HPI_INCLUDE_**** must be defined |
| 30 | and the appropriate hzz?????.c or hex?????.c linked in |
| 31 | |
| 32 | */ |
| 33 | /***********************************************************************/ |
| 34 | #define SOURCEFILE_NAME "hpidspcd.c" |
| 35 | #include "hpidspcd.h" |
| 36 | #include "hpidebug.h" |
| 37 | |
| 38 | /** |
| 39 | Header structure for binary dsp code file (see asidsp.doc) |
| 40 | This structure must match that used in s2bin.c for generation of asidsp.bin |
| 41 | */ |
| 42 | |
| 43 | #ifndef DISABLE_PRAGMA_PACK1 |
| 44 | #pragma pack(push, 1) |
| 45 | #endif |
| 46 | |
| 47 | struct code_header { |
| 48 | u32 size; |
| 49 | char type[4]; |
| 50 | u32 adapter; |
| 51 | u32 version; |
| 52 | u32 crc; |
| 53 | }; |
| 54 | |
| 55 | #ifndef DISABLE_PRAGMA_PACK1 |
| 56 | #pragma pack(pop) |
| 57 | #endif |
| 58 | |
| 59 | #define HPI_VER_DECIMAL ((int)(HPI_VER_MAJOR(HPI_VER) * 10000 + \ |
| 60 | HPI_VER_MINOR(HPI_VER) * 100 + HPI_VER_RELEASE(HPI_VER))) |
| 61 | |
| 62 | /***********************************************************************/ |
| 63 | #include "linux/pci.h" |
| 64 | /*-------------------------------------------------------------------*/ |
| 65 | short hpi_dsp_code_open(u32 adapter, struct dsp_code *ps_dsp_code, |
| 66 | u32 *pos_error_code) |
| 67 | { |
| 68 | const struct firmware *ps_firmware = ps_dsp_code->ps_firmware; |
| 69 | struct code_header header; |
| 70 | char fw_name[20]; |
| 71 | int err; |
| 72 | |
| 73 | sprintf(fw_name, "asihpi/dsp%04x.bin", adapter); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 74 | |
| 75 | err = request_firmware(&ps_firmware, fw_name, |
| 76 | &ps_dsp_code->ps_dev->dev); |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 77 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 78 | if (err != 0) { |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 79 | dev_printk(KERN_ERR, &ps_dsp_code->ps_dev->dev, |
| 80 | "%d, request_firmware failed for %s\n", err, |
| 81 | fw_name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 82 | goto error1; |
| 83 | } |
| 84 | if (ps_firmware->size < sizeof(header)) { |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 85 | dev_printk(KERN_ERR, &ps_dsp_code->ps_dev->dev, |
| 86 | "Header size too small %s\n", fw_name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 87 | goto error2; |
| 88 | } |
| 89 | memcpy(&header, ps_firmware->data, sizeof(header)); |
| 90 | if (header.adapter != adapter) { |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 91 | dev_printk(KERN_ERR, &ps_dsp_code->ps_dev->dev, |
| 92 | "Adapter type incorrect %4x != %4x\n", header.adapter, |
| 93 | adapter); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 94 | goto error2; |
| 95 | } |
| 96 | if (header.size != ps_firmware->size) { |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 97 | dev_printk(KERN_ERR, &ps_dsp_code->ps_dev->dev, |
| 98 | "Code size wrong %d != %ld\n", header.size, |
| 99 | (unsigned long)ps_firmware->size); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 100 | goto error2; |
| 101 | } |
| 102 | |
| 103 | if (header.version / 10000 != HPI_VER_DECIMAL / 10000) { |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 104 | dev_printk(KERN_ERR, &ps_dsp_code->ps_dev->dev, |
| 105 | "Firmware Major Version mismatch " |
| 106 | "DSP image %d != Driver %d\n", header.version, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 107 | HPI_VER_DECIMAL); |
| 108 | goto error2; |
| 109 | } |
| 110 | |
| 111 | if (header.version != HPI_VER_DECIMAL) { |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 112 | dev_printk(KERN_WARNING, &ps_dsp_code->ps_dev->dev, |
| 113 | "firmware: version mismatch DSP image %d != Driver %d\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 114 | header.version, HPI_VER_DECIMAL); |
| 115 | /* goto error2; still allow driver to load */ |
| 116 | } |
| 117 | |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 118 | HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 119 | ps_dsp_code->ps_firmware = ps_firmware; |
| 120 | ps_dsp_code->block_length = header.size / sizeof(u32); |
| 121 | ps_dsp_code->word_count = sizeof(header) / sizeof(u32); |
| 122 | ps_dsp_code->version = header.version; |
| 123 | ps_dsp_code->crc = header.crc; |
| 124 | return 0; |
| 125 | |
| 126 | error2: |
| 127 | release_firmware(ps_firmware); |
| 128 | error1: |
| 129 | ps_dsp_code->ps_firmware = NULL; |
| 130 | ps_dsp_code->block_length = 0; |
| 131 | return HPI_ERROR_DSP_FILE_NOT_FOUND; |
| 132 | } |
| 133 | |
| 134 | /*-------------------------------------------------------------------*/ |
| 135 | void hpi_dsp_code_close(struct dsp_code *ps_dsp_code) |
| 136 | { |
| 137 | if (ps_dsp_code->ps_firmware != NULL) { |
| 138 | HPI_DEBUG_LOG(DEBUG, "dsp code closed\n"); |
| 139 | release_firmware(ps_dsp_code->ps_firmware); |
| 140 | ps_dsp_code->ps_firmware = NULL; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /*-------------------------------------------------------------------*/ |
| 145 | void hpi_dsp_code_rewind(struct dsp_code *ps_dsp_code) |
| 146 | { |
| 147 | /* Go back to start of data, after header */ |
| 148 | ps_dsp_code->word_count = sizeof(struct code_header) / sizeof(u32); |
| 149 | } |
| 150 | |
| 151 | /*-------------------------------------------------------------------*/ |
| 152 | short hpi_dsp_code_read_word(struct dsp_code *ps_dsp_code, u32 *pword) |
| 153 | { |
| 154 | if (ps_dsp_code->word_count + 1 > ps_dsp_code->block_length) |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame^] | 155 | return HPI_ERROR_DSP_FILE_FORMAT; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 156 | |
| 157 | *pword = ((u32 *)(ps_dsp_code->ps_firmware->data))[ps_dsp_code-> |
| 158 | word_count]; |
| 159 | ps_dsp_code->word_count++; |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | /*-------------------------------------------------------------------*/ |
| 164 | short hpi_dsp_code_read_block(size_t words_requested, |
| 165 | struct dsp_code *ps_dsp_code, u32 **ppblock) |
| 166 | { |
| 167 | if (ps_dsp_code->word_count + words_requested > |
| 168 | ps_dsp_code->block_length) |
| 169 | return HPI_ERROR_DSP_FILE_FORMAT; |
| 170 | |
| 171 | *ppblock = |
| 172 | ((u32 *)(ps_dsp_code->ps_firmware->data)) + |
| 173 | ps_dsp_code->word_count; |
| 174 | ps_dsp_code->word_count += words_requested; |
| 175 | return 0; |
| 176 | } |