Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1 | /***********************************************************************/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 2 | /** |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3 | |
| 4 | AudioScience HPI driver |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 5 | Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 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 |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 21 | Functions for reading DSP code using |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 22 | hotplug firmware loader from individual dsp code files |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 23 | */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 24 | /***********************************************************************/ |
| 25 | #define SOURCEFILE_NAME "hpidspcd.c" |
| 26 | #include "hpidspcd.h" |
| 27 | #include "hpidebug.h" |
| 28 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 29 | struct dsp_code_private { |
| 30 | /** Firmware descriptor */ |
| 31 | const struct firmware *firmware; |
| 32 | struct pci_dev *dev; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 33 | }; |
| 34 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 35 | #define HPI_VER_DECIMAL ((int)(HPI_VER_MAJOR(HPI_VER) * 10000 + \ |
| 36 | HPI_VER_MINOR(HPI_VER) * 100 + HPI_VER_RELEASE(HPI_VER))) |
| 37 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 38 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 39 | short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code, |
| 40 | u32 *os_error_code) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 41 | { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 42 | const struct firmware *firmware; |
| 43 | struct pci_dev *dev = os_data; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 44 | struct code_header header; |
| 45 | char fw_name[20]; |
Jesper Juhl | dc889f1 | 2011-07-31 23:16:43 +0200 | [diff] [blame^] | 46 | short err_ret = HPI_ERROR_DSP_FILE_NOT_FOUND; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 47 | int err; |
| 48 | |
| 49 | sprintf(fw_name, "asihpi/dsp%04x.bin", adapter); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 50 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 51 | err = request_firmware(&firmware, fw_name, &dev->dev); |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 52 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 53 | if (err || !firmware) { |
| 54 | dev_printk(KERN_ERR, &dev->dev, |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 55 | "%d, request_firmware failed for %s\n", err, |
| 56 | fw_name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 57 | goto error1; |
| 58 | } |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 59 | if (firmware->size < sizeof(header)) { |
| 60 | dev_printk(KERN_ERR, &dev->dev, "Header size too small %s\n", |
| 61 | fw_name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 62 | goto error2; |
| 63 | } |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 64 | memcpy(&header, firmware->data, sizeof(header)); |
| 65 | |
| 66 | if ((header.type != 0x45444F43) || /* "CODE" */ |
| 67 | (header.adapter != adapter) |
| 68 | || (header.size != firmware->size)) { |
| 69 | dev_printk(KERN_ERR, &dev->dev, "Invalid firmware file\n"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 70 | goto error2; |
| 71 | } |
| 72 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 73 | if ((header.version / 100 & ~1) != (HPI_VER_DECIMAL / 100 & ~1)) { |
| 74 | dev_printk(KERN_ERR, &dev->dev, |
Eliot Blennerhassett | 7f41b61 | 2011-02-10 17:26:19 +1300 | [diff] [blame] | 75 | "Incompatible firmware version " |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 76 | "DSP image %d != Driver %d\n", header.version, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 77 | HPI_VER_DECIMAL); |
| 78 | goto error2; |
| 79 | } |
| 80 | |
| 81 | if (header.version != HPI_VER_DECIMAL) { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 82 | dev_printk(KERN_WARNING, &dev->dev, |
Eliot Blennerhassett | 7f41b61 | 2011-02-10 17:26:19 +1300 | [diff] [blame] | 83 | "Firmware: release version mismatch DSP image %d != Driver %d\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 84 | header.version, HPI_VER_DECIMAL); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 87 | HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name); |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 88 | dsp_code->pvt = kmalloc(sizeof(*dsp_code->pvt), GFP_KERNEL); |
Jesper Juhl | dc889f1 | 2011-07-31 23:16:43 +0200 | [diff] [blame^] | 89 | if (!dsp_code->pvt) { |
| 90 | err_ret = HPI_ERROR_MEMORY_ALLOC; |
| 91 | goto error2; |
| 92 | } |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 93 | |
| 94 | dsp_code->pvt->dev = dev; |
| 95 | dsp_code->pvt->firmware = firmware; |
| 96 | dsp_code->header = header; |
| 97 | dsp_code->block_length = header.size / sizeof(u32); |
| 98 | dsp_code->word_count = sizeof(header) / sizeof(u32); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 99 | return 0; |
| 100 | |
| 101 | error2: |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 102 | release_firmware(firmware); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 103 | error1: |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 104 | dsp_code->block_length = 0; |
Jesper Juhl | dc889f1 | 2011-07-31 23:16:43 +0200 | [diff] [blame^] | 105 | return err_ret; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 109 | void hpi_dsp_code_close(struct dsp_code *dsp_code) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 110 | { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 111 | if (dsp_code->pvt->firmware) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 112 | HPI_DEBUG_LOG(DEBUG, "dsp code closed\n"); |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 113 | release_firmware(dsp_code->pvt->firmware); |
| 114 | dsp_code->pvt->firmware = NULL; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 115 | } |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 116 | kfree(dsp_code->pvt); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 120 | void hpi_dsp_code_rewind(struct dsp_code *dsp_code) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 121 | { |
| 122 | /* Go back to start of data, after header */ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 123 | dsp_code->word_count = sizeof(struct code_header) / sizeof(u32); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 127 | short hpi_dsp_code_read_word(struct dsp_code *dsp_code, u32 *pword) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 128 | { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 129 | if (dsp_code->word_count + 1 > dsp_code->block_length) |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 130 | return HPI_ERROR_DSP_FILE_FORMAT; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 131 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 132 | *pword = ((u32 *)(dsp_code->pvt->firmware->data))[dsp_code-> |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 133 | word_count]; |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 134 | dsp_code->word_count++; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /*-------------------------------------------------------------------*/ |
| 139 | short hpi_dsp_code_read_block(size_t words_requested, |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 140 | struct dsp_code *dsp_code, u32 **ppblock) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 141 | { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 142 | if (dsp_code->word_count + words_requested > dsp_code->block_length) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 143 | return HPI_ERROR_DSP_FILE_FORMAT; |
| 144 | |
| 145 | *ppblock = |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 146 | ((u32 *)(dsp_code->pvt->firmware->data)) + |
| 147 | dsp_code->word_count; |
| 148 | dsp_code->word_count += words_requested; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 149 | return 0; |
| 150 | } |