]> Pileus Git - ~andy/linux/blob - drivers/staging/vt6656/firmware.c
Merge branch 'kbuild/rc-fixes' into kbuild/kconfig
[~andy/linux] / drivers / staging / vt6656 / firmware.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
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.
18  *
19  *
20  * File: baseband.c
21  *
22  * Purpose: Implement functions to access baseband
23  *
24  * Author: Yiching Chen
25  *
26  * Date: May 20, 2004
27  *
28  * Functions:
29  *
30  * Revision History:
31  *
32  */
33
34 #include "firmware.h"
35 #include "control.h"
36 #include "rndis.h"
37
38 /*---------------------  Static Definitions -------------------------*/
39
40 static int          msglevel                =MSG_LEVEL_INFO;
41 //static int          msglevel                =MSG_LEVEL_DEBUG;
42
43 #define FIRMWARE_VERSION        0x133           /* version 1.51 */
44 #define FIRMWARE_NAME           "vntwusb.fw"
45
46 #define FIRMWARE_CHUNK_SIZE     0x400
47
48 /*---------------------  Static Classes  ----------------------------*/
49
50 /*---------------------  Static Variables  --------------------------*/
51
52 /*---------------------  Static Functions  --------------------------*/
53
54 /*---------------------  Export Variables  --------------------------*/
55
56 /*---------------------  Export Functions  --------------------------*/
57
58
59 BOOL
60 FIRMWAREbDownload(
61      PSDevice pDevice
62     )
63 {
64         struct device *dev = &pDevice->usb->dev;
65         const struct firmware *fw;
66         int NdisStatus;
67         void *pBuffer = NULL;
68         BOOL result = FALSE;
69         u16 wLength;
70         int ii, rc;
71
72
73         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
74         spin_unlock_irq(&pDevice->lock);
75
76         rc = request_firmware(&fw, FIRMWARE_NAME, dev);
77         if (rc) {
78                 dev_err(dev, "firmware file %s request failed (%d)\n",
79                         FIRMWARE_NAME, rc);
80                         goto out;
81         }
82
83         pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
84         if (!pBuffer)
85                 goto out;
86
87         for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
88                 wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
89                 memcpy(pBuffer, fw->data + ii, wLength);
90
91                 NdisStatus = CONTROLnsRequestOutAsyn(pDevice,
92                                             0,
93                                             0x1200+ii,
94                                             0x0000,
95                                             wLength,
96                                             pBuffer
97                                             );
98
99                 DBG_PRT(MSG_LEVEL_DEBUG,
100                         KERN_INFO"Download firmware...%d %zu\n", ii, fw->size);
101                 if (NdisStatus != STATUS_SUCCESS)
102                         goto free_fw;
103         }
104
105         result = TRUE;
106 free_fw:
107         release_firmware(fw);
108
109 out:
110         kfree(pBuffer);
111
112         spin_lock_irq(&pDevice->lock);
113         return result;
114 }
115 MODULE_FIRMWARE(FIRMWARE_NAME);
116
117 BOOL
118 FIRMWAREbBrach2Sram(
119      PSDevice pDevice
120     )
121 {
122     int NdisStatus;
123
124     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
125
126     NdisStatus = CONTROLnsRequestOut(pDevice,
127                                     1,
128                                     0x1200,
129                                     0x0000,
130                                     0,
131                                     NULL
132                                     );
133
134     if (NdisStatus != STATUS_SUCCESS) {
135         return (FALSE);
136     } else {
137         return (TRUE);
138     }
139 }
140
141
142 BOOL
143 FIRMWAREbCheckVersion(
144      PSDevice pDevice
145     )
146 {
147         int ntStatus;
148
149     ntStatus = CONTROLnsRequestIn(pDevice,
150                                     MESSAGE_TYPE_READ,
151                                     0,
152                                     MESSAGE_REQUEST_VERSION,
153                                     2,
154                                     (PBYTE) &(pDevice->wFirmwareVersion));
155
156     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
157     if (ntStatus != STATUS_SUCCESS) {
158         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
159         return FALSE;
160     }
161     if (pDevice->wFirmwareVersion == 0xFFFF) {
162         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
163         return FALSE;
164     }
165     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
166     if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
167         // branch to loader for download new firmware
168         FIRMWAREbBrach2Sram(pDevice);
169         return FALSE;
170     }
171     return TRUE;
172 }