ALSA: asihpi - Remove redundant struct members.
[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
EB
51 if (err || !firmware) {
52 dev_printk(KERN_ERR, &dev->dev,
5ed15daf
EB
53 "%d, request_firmware failed for %s\n", err,
54 fw_name);
719f82d3
EB
55 goto error1;
56 }
95a4c6e7
EB
57 if (firmware->size < sizeof(header)) {
58 dev_printk(KERN_ERR, &dev->dev, "Header size too small %s\n",
59 fw_name);
719f82d3
EB
60 goto error2;
61 }
95a4c6e7
EB
62 memcpy(&header, firmware->data, sizeof(header));
63
64 if ((header.type != 0x45444F43) || /* "CODE" */
65 (header.adapter != adapter)
66 || (header.size != firmware->size)) {
f6baaec2
EB
67 dev_printk(KERN_ERR, &dev->dev,
68 "Invalid firmware header size %d != file %zd\n",
69 header.size, firmware->size);
719f82d3
EB
70 goto error2;
71 }
72
f6baaec2
EB
73 if ((header.version >> 9) != (HPI_VER >> 9)) {
74 /* Consider even and subsequent odd minor versions to be compatible */
95a4c6e7 75 dev_printk(KERN_ERR, &dev->dev,
7f41b61b 76 "Incompatible firmware version "
f6baaec2
EB
77 "DSP image %X != Driver %X\n", header.version,
78 HPI_VER);
719f82d3
EB
79 goto error2;
80 }
81
f6baaec2
EB
82 if (header.version != HPI_VER) {
83 dev_printk(KERN_INFO, &dev->dev,
84 "Firmware: release version mismatch DSP image %X != Driver %X\n",
85 header.version, HPI_VER);
719f82d3
EB
86 }
87
5ed15daf 88 HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name);
95a4c6e7 89 dsp_code->pvt = kmalloc(sizeof(*dsp_code->pvt), GFP_KERNEL);
dc889f18
JJ
90 if (!dsp_code->pvt) {
91 err_ret = HPI_ERROR_MEMORY_ALLOC;
92 goto error2;
93 }
95a4c6e7
EB
94
95 dsp_code->pvt->dev = dev;
96 dsp_code->pvt->firmware = firmware;
97 dsp_code->header = header;
98 dsp_code->block_length = header.size / sizeof(u32);
99 dsp_code->word_count = sizeof(header) / sizeof(u32);
719f82d3
EB
100 return 0;
101
102error2:
95a4c6e7 103 release_firmware(firmware);
719f82d3 104error1:
95a4c6e7 105 dsp_code->block_length = 0;
dc889f18 106 return err_ret;
719f82d3
EB
107}
108
109/*-------------------------------------------------------------------*/
95a4c6e7 110void hpi_dsp_code_close(struct dsp_code *dsp_code)
719f82d3 111{
95a4c6e7 112 if (dsp_code->pvt->firmware) {
719f82d3 113 HPI_DEBUG_LOG(DEBUG, "dsp code closed\n");
95a4c6e7
EB
114 release_firmware(dsp_code->pvt->firmware);
115 dsp_code->pvt->firmware = NULL;
719f82d3 116 }
95a4c6e7 117 kfree(dsp_code->pvt);
719f82d3
EB
118}
119
120/*-------------------------------------------------------------------*/
95a4c6e7 121void hpi_dsp_code_rewind(struct dsp_code *dsp_code)
719f82d3
EB
122{
123 /* Go back to start of data, after header */
95a4c6e7 124 dsp_code->word_count = sizeof(struct code_header) / sizeof(u32);
719f82d3
EB
125}
126
127/*-------------------------------------------------------------------*/
95a4c6e7 128short hpi_dsp_code_read_word(struct dsp_code *dsp_code, u32 *pword)
719f82d3 129{
95a4c6e7 130 if (dsp_code->word_count + 1 > dsp_code->block_length)
5ed15daf 131 return HPI_ERROR_DSP_FILE_FORMAT;
719f82d3 132
95a4c6e7 133 *pword = ((u32 *)(dsp_code->pvt->firmware->data))[dsp_code->
719f82d3 134 word_count];
95a4c6e7 135 dsp_code->word_count++;
719f82d3
EB
136 return 0;
137}
138
139/*-------------------------------------------------------------------*/
140short hpi_dsp_code_read_block(size_t words_requested,
95a4c6e7 141 struct dsp_code *dsp_code, u32 **ppblock)
719f82d3 142{
95a4c6e7 143 if (dsp_code->word_count + words_requested > dsp_code->block_length)
719f82d3
EB
144 return HPI_ERROR_DSP_FILE_FORMAT;
145
146 *ppblock =
95a4c6e7
EB
147 ((u32 *)(dsp_code->pvt->firmware->data)) +
148 dsp_code->word_count;
149 dsp_code->word_count += words_requested;
719f82d3
EB
150 return 0;
151}
This page took 0.102018 seconds and 5 git commands to generate.