Merge tag 'stable/for-linus-3.8-rc7-tag-two' of git://git.kernel.org/pub/scm/linux...
[deliverable/linux.git] / sound / pci / asihpi / hpidspcd.c
CommitLineData
719f82d3 1/***********************************************************************/
95a4c6e7 2/**
719f82d3
EB
3
4 AudioScience HPI driver
95a4c6e7 5 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
719f82d3
EB
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
95a4c6e7 21Functions for reading DSP code using
719f82d3 22hotplug firmware loader from individual dsp code files
95a4c6e7 23*/
719f82d3
EB
24/***********************************************************************/
25#define SOURCEFILE_NAME "hpidspcd.c"
26#include "hpidspcd.h"
27#include "hpidebug.h"
f6baaec2 28#include "hpi_version.h"
719f82d3 29
95a4c6e7
EB
30struct dsp_code_private {
31 /** Firmware descriptor */
32 const struct firmware *firmware;
33 struct pci_dev *dev;
719f82d3
EB
34};
35
719f82d3 36/*-------------------------------------------------------------------*/
95a4c6e7
EB
37short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code,
38 u32 *os_error_code)
719f82d3 39{
95a4c6e7
EB
40 const struct firmware *firmware;
41 struct pci_dev *dev = os_data;
719f82d3
EB
42 struct code_header header;
43 char fw_name[20];
dc889f18 44 short err_ret = HPI_ERROR_DSP_FILE_NOT_FOUND;
719f82d3
EB
45 int err;
46
47 sprintf(fw_name, "asihpi/dsp%04x.bin", adapter);
719f82d3 48
95a4c6e7 49 err = request_firmware(&firmware, fw_name, &dev->dev);
5ed15daf 50
95a4c6e7 51 if (err || !firmware) {
4ee3bffc
JP
52 dev_err(&dev->dev, "%d, request_firmware failed for %s\n",
53 err, fw_name);
719f82d3
EB
54 goto error1;
55 }
95a4c6e7 56 if (firmware->size < sizeof(header)) {
4ee3bffc 57 dev_err(&dev->dev, "Header size too small %s\n", fw_name);
719f82d3
EB
58 goto error2;
59 }
95a4c6e7
EB
60 memcpy(&header, firmware->data, sizeof(header));
61
62 if ((header.type != 0x45444F43) || /* "CODE" */
63 (header.adapter != adapter)
64 || (header.size != firmware->size)) {
4ee3bffc 65 dev_err(&dev->dev,
f6baaec2
EB
66 "Invalid firmware header size %d != file %zd\n",
67 header.size, firmware->size);
719f82d3
EB
68 goto error2;
69 }
70
f6baaec2
EB
71 if ((header.version >> 9) != (HPI_VER >> 9)) {
72 /* Consider even and subsequent odd minor versions to be compatible */
4ee3bffc
JP
73 dev_err(&dev->dev, "Incompatible firmware version DSP image %X != Driver %X\n",
74 header.version, HPI_VER);
719f82d3
EB
75 goto error2;
76 }
77
f6baaec2 78 if (header.version != HPI_VER) {
4ee3bffc
JP
79 dev_info(&dev->dev,
80 "Firmware: release version mismatch DSP image %X != Driver %X\n",
81 header.version, HPI_VER);
719f82d3
EB
82 }
83
5ed15daf 84 HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name);
95a4c6e7 85 dsp_code->pvt = kmalloc(sizeof(*dsp_code->pvt), GFP_KERNEL);
dc889f18
JJ
86 if (!dsp_code->pvt) {
87 err_ret = HPI_ERROR_MEMORY_ALLOC;
88 goto error2;
89 }
95a4c6e7
EB
90
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);
719f82d3
EB
96 return 0;
97
98error2:
95a4c6e7 99 release_firmware(firmware);
719f82d3 100error1:
95a4c6e7 101 dsp_code->block_length = 0;
dc889f18 102 return err_ret;
719f82d3
EB
103}
104
105/*-------------------------------------------------------------------*/
95a4c6e7 106void hpi_dsp_code_close(struct dsp_code *dsp_code)
719f82d3 107{
50d5f773
EB
108 HPI_DEBUG_LOG(DEBUG, "dsp code closed\n");
109 release_firmware(dsp_code->pvt->firmware);
95a4c6e7 110 kfree(dsp_code->pvt);
719f82d3
EB
111}
112
113/*-------------------------------------------------------------------*/
95a4c6e7 114void hpi_dsp_code_rewind(struct dsp_code *dsp_code)
719f82d3
EB
115{
116 /* Go back to start of data, after header */
95a4c6e7 117 dsp_code->word_count = sizeof(struct code_header) / sizeof(u32);
719f82d3
EB
118}
119
120/*-------------------------------------------------------------------*/
95a4c6e7 121short hpi_dsp_code_read_word(struct dsp_code *dsp_code, u32 *pword)
719f82d3 122{
95a4c6e7 123 if (dsp_code->word_count + 1 > dsp_code->block_length)
5ed15daf 124 return HPI_ERROR_DSP_FILE_FORMAT;
719f82d3 125
95a4c6e7 126 *pword = ((u32 *)(dsp_code->pvt->firmware->data))[dsp_code->
719f82d3 127 word_count];
95a4c6e7 128 dsp_code->word_count++;
719f82d3
EB
129 return 0;
130}
131
132/*-------------------------------------------------------------------*/
133short hpi_dsp_code_read_block(size_t words_requested,
95a4c6e7 134 struct dsp_code *dsp_code, u32 **ppblock)
719f82d3 135{
95a4c6e7 136 if (dsp_code->word_count + words_requested > dsp_code->block_length)
719f82d3
EB
137 return HPI_ERROR_DSP_FILE_FORMAT;
138
139 *ppblock =
95a4c6e7
EB
140 ((u32 *)(dsp_code->pvt->firmware->data)) +
141 dsp_code->word_count;
142 dsp_code->word_count += words_requested;
719f82d3
EB
143 return 0;
144}
This page took 0.147402 seconds and 5 git commands to generate.