spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / staging / vt6656 / firmware.c
blob8c8126a3540b426a69756872968664dadad38aba
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * File: baseband.c
22 * Purpose: Implement functions to access baseband
24 * Author: Yiching Chen
26 * Date: May 20, 2004
28 * Functions:
30 * Revision History:
34 #include "firmware.h"
35 #include "control.h"
36 #include "rndis.h"
38 /*--------------------- Static Definitions -------------------------*/
40 static int msglevel =MSG_LEVEL_INFO;
41 //static int msglevel =MSG_LEVEL_DEBUG;
43 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
44 #define FIRMWARE_NAME "vntwusb.fw"
46 #define FIRMWARE_CHUNK_SIZE 0x400
48 /*--------------------- Static Classes ----------------------------*/
50 /*--------------------- Static Variables --------------------------*/
52 /*--------------------- Static Functions --------------------------*/
54 /*--------------------- Export Variables --------------------------*/
56 /*--------------------- Export Functions --------------------------*/
59 BOOL
60 FIRMWAREbDownload(
61 PSDevice pDevice
64 const struct firmware *fw;
65 int NdisStatus;
66 void *pBuffer = NULL;
67 BOOL result = FALSE;
68 u16 wLength;
69 int ii;
71 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
72 spin_unlock_irq(&pDevice->lock);
74 if (!pDevice->firmware) {
75 struct device *dev = &pDevice->usb->dev;
76 int rc;
78 rc = request_firmware(&pDevice->firmware, FIRMWARE_NAME, dev);
79 if (rc) {
80 dev_err(dev, "firmware file %s request failed (%d)\n",
81 FIRMWARE_NAME, rc);
82 goto out;
85 fw = pDevice->firmware;
87 pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
88 if (!pBuffer)
89 goto out;
91 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
92 wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
93 memcpy(pBuffer, fw->data + ii, wLength);
95 NdisStatus = CONTROLnsRequestOutAsyn(pDevice,
97 0x1200+ii,
98 0x0000,
99 wLength,
100 pBuffer
103 DBG_PRT(MSG_LEVEL_DEBUG,
104 KERN_INFO"Download firmware...%d %zu\n", ii, fw->size);
105 if (NdisStatus != STATUS_SUCCESS)
106 goto out;
109 result = TRUE;
111 out:
112 kfree(pBuffer);
114 spin_lock_irq(&pDevice->lock);
115 return result;
117 MODULE_FIRMWARE(FIRMWARE_NAME);
119 BOOL
120 FIRMWAREbBrach2Sram(
121 PSDevice pDevice
124 int NdisStatus;
126 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
128 NdisStatus = CONTROLnsRequestOut(pDevice,
130 0x1200,
131 0x0000,
133 NULL
136 if (NdisStatus != STATUS_SUCCESS) {
137 return (FALSE);
138 } else {
139 return (TRUE);
144 BOOL
145 FIRMWAREbCheckVersion(
146 PSDevice pDevice
149 int ntStatus;
151 ntStatus = CONTROLnsRequestIn(pDevice,
152 MESSAGE_TYPE_READ,
154 MESSAGE_REQUEST_VERSION,
156 (PBYTE) &(pDevice->wFirmwareVersion));
158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
159 if (ntStatus != STATUS_SUCCESS) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
161 return FALSE;
163 if (pDevice->wFirmwareVersion == 0xFFFF) {
164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
165 return FALSE;
167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
168 if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
169 // branch to loader for download new firmware
170 FIRMWAREbBrach2Sram(pDevice);
171 return FALSE;
173 return TRUE;