]> Pileus Git - ~andy/linux/blob - drivers/staging/vt6656/firmware.c
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[~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 int FIRMWAREbDownload(struct vnt_private *pDevice)
60 {
61         struct device *dev = &pDevice->usb->dev;
62         const struct firmware *fw;
63         int NdisStatus;
64         void *pBuffer = NULL;
65         bool result = false;
66         u16 wLength;
67         int ii, rc;
68
69
70         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
71         spin_unlock_irq(&pDevice->lock);
72
73         rc = request_firmware(&fw, FIRMWARE_NAME, dev);
74         if (rc) {
75                 dev_err(dev, "firmware file %s request failed (%d)\n",
76                         FIRMWARE_NAME, rc);
77                         goto out;
78         }
79
80         pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
81         if (!pBuffer)
82                 goto out;
83
84         for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
85                 wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
86                 memcpy(pBuffer, fw->data + ii, wLength);
87
88                 NdisStatus = CONTROLnsRequestOutAsyn(pDevice,
89                                             0,
90                                             0x1200+ii,
91                                             0x0000,
92                                             wLength,
93                                             pBuffer
94                                             );
95
96                 DBG_PRT(MSG_LEVEL_DEBUG,
97                         KERN_INFO"Download firmware...%d %zu\n", ii, fw->size);
98                 if (NdisStatus != STATUS_SUCCESS)
99                         goto free_fw;
100         }
101
102         result = true;
103 free_fw:
104         release_firmware(fw);
105
106 out:
107         kfree(pBuffer);
108
109         spin_lock_irq(&pDevice->lock);
110         return result;
111 }
112 MODULE_FIRMWARE(FIRMWARE_NAME);
113
114 int FIRMWAREbBrach2Sram(struct vnt_private *pDevice)
115 {
116         int NdisStatus;
117
118     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
119
120     NdisStatus = CONTROLnsRequestOut(pDevice,
121                                     1,
122                                     0x1200,
123                                     0x0000,
124                                     0,
125                                     NULL
126                                     );
127
128     if (NdisStatus != STATUS_SUCCESS) {
129         return (false);
130     } else {
131         return (true);
132     }
133 }
134
135
136 int FIRMWAREbCheckVersion(struct vnt_private *pDevice)
137 {
138         int ntStatus;
139
140     ntStatus = CONTROLnsRequestIn(pDevice,
141                                     MESSAGE_TYPE_READ,
142                                     0,
143                                     MESSAGE_REQUEST_VERSION,
144                                     2,
145                                     (PBYTE) &(pDevice->wFirmwareVersion));
146
147     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
148     if (ntStatus != STATUS_SUCCESS) {
149         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
150         return false;
151     }
152     if (pDevice->wFirmwareVersion == 0xFFFF) {
153         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
154         return false;
155     }
156     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
157     if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
158         // branch to loader for download new firmware
159         FIRMWAREbBrach2Sram(pDevice);
160         return false;
161     }
162     return true;
163 }