Merge branch 'perf/core' into perf/urgent, to pick up the latest fixes
[deliverable/linux.git] / drivers / staging / vt6656 / firmware.c
CommitLineData
92b96797
FB
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
f2ca407b 34#include <linux/compiler.h>
92b96797 35#include "firmware.h"
62c8526d 36#include "usbpipe.h"
92b96797 37
1266ed76 38static int msglevel = MSG_LEVEL_INFO;
efbe5182 39/* static int msglevel = MSG_LEVEL_DEBUG; */
31d5bbf3
BH
40
41#define FIRMWARE_VERSION 0x133 /* version 1.51 */
42#define FIRMWARE_NAME "vntwusb.fw"
43
44#define FIRMWARE_CHUNK_SIZE 0x400
45
7af94000 46int FIRMWAREbDownload(struct vnt_private *pDevice)
92b96797 47{
f20fbdf8 48 struct device *dev = &pDevice->usb->dev;
31d5bbf3
BH
49 const struct firmware *fw;
50 int NdisStatus;
51 void *pBuffer = NULL;
e269fc2d 52 bool result = false;
31d5bbf3 53 u16 wLength;
f20fbdf8
MP
54 int ii, rc;
55
31d5bbf3 56 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
31d5bbf3 57
f20fbdf8
MP
58 rc = request_firmware(&fw, FIRMWARE_NAME, dev);
59 if (rc) {
60 dev_err(dev, "firmware file %s request failed (%d)\n",
61 FIRMWARE_NAME, rc);
31d5bbf3 62 goto out;
31d5bbf3 63 }
31d5bbf3
BH
64
65 pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
66 if (!pBuffer)
67 goto out;
68
69 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
70 wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
71 memcpy(pBuffer, fw->data + ii, wLength);
72
1390b02a 73 NdisStatus = vnt_control_out(pDevice,
1266ed76
NH
74 0,
75 0x1200+ii,
76 0x0000,
77 wLength,
78 pBuffer);
92b96797 79
31d5bbf3
BH
80 DBG_PRT(MSG_LEVEL_DEBUG,
81 KERN_INFO"Download firmware...%d %zu\n", ii, fw->size);
82 if (NdisStatus != STATUS_SUCCESS)
f20fbdf8 83 goto free_fw;
1266ed76 84 }
92b96797 85
4e9b5e2b 86 result = true;
f20fbdf8
MP
87free_fw:
88 release_firmware(fw);
31d5bbf3
BH
89
90out:
1d5c536e 91 kfree(pBuffer);
92b96797 92
31d5bbf3 93 return result;
92b96797 94}
31d5bbf3 95MODULE_FIRMWARE(FIRMWARE_NAME);
92b96797 96
fe5d00eb 97int FIRMWAREbBrach2Sram(struct vnt_private *pDevice)
92b96797 98{
fe5d00eb 99 int NdisStatus;
92b96797 100
1266ed76
NH
101 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
102
1390b02a 103 NdisStatus = vnt_control_out(pDevice,
1266ed76
NH
104 1,
105 0x1200,
106 0x0000,
107 0,
108 NULL);
fc044ac3 109 if (NdisStatus != STATUS_SUCCESS)
5a69f36d 110 return false;
fc044ac3 111 else
5a69f36d 112 return true;
92b96797
FB
113}
114
fe5d00eb 115int FIRMWAREbCheckVersion(struct vnt_private *pDevice)
92b96797 116{
6487c49e 117 int ntStatus;
92b96797 118
441c21c3 119 ntStatus = vnt_control_in(pDevice,
1266ed76
NH
120 MESSAGE_TYPE_READ,
121 0,
122 MESSAGE_REQUEST_VERSION,
123 2,
124 (u8 *) &(pDevice->wFirmwareVersion));
125
1c3e56f9
NH
126 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n",
127 pDevice->wFirmwareVersion);
1266ed76
NH
128 if (ntStatus != STATUS_SUCCESS) {
129 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
130 return false;
131 }
132 if (pDevice->wFirmwareVersion == 0xFFFF) {
133 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
134 return false;
135 }
1c3e56f9
NH
136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n",
137 pDevice->wFirmwareVersion);
1266ed76 138 if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
efbe5182 139 /* branch to loader for download new firmware */
1266ed76
NH
140 FIRMWAREbBrach2Sram(pDevice);
141 return false;
142 }
143 return true;
92b96797 144}
This page took 0.488603 seconds and 5 git commands to generate.