]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/vt6656/firmware.c
Merge commit 'v3.17' into next
[mirror_ubuntu-artful-kernel.git] / 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 <linux/compiler.h>
35 #include "firmware.h"
36 #include "usbpipe.h"
37
38 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
39 #define FIRMWARE_NAME "vntwusb.fw"
40
41 #define FIRMWARE_CHUNK_SIZE 0x400
42
43 int vnt_download_firmware(struct vnt_private *priv)
44 {
45 struct device *dev = &priv->usb->dev;
46 const struct firmware *fw;
47 int status;
48 void *buffer = NULL;
49 bool result = false;
50 u16 length;
51 int ii, rc;
52
53 dev_dbg(dev, "---->Download firmware\n");
54
55 rc = request_firmware(&fw, FIRMWARE_NAME, dev);
56 if (rc) {
57 dev_err(dev, "firmware file %s request failed (%d)\n",
58 FIRMWARE_NAME, rc);
59 goto out;
60 }
61
62 buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
63 if (!buffer)
64 goto out;
65
66 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
67 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
68 memcpy(buffer, fw->data + ii, length);
69
70 status = vnt_control_out(priv,
71 0,
72 0x1200+ii,
73 0x0000,
74 length,
75 buffer);
76
77 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
78
79 if (status != STATUS_SUCCESS)
80 goto free_fw;
81 }
82
83 result = true;
84 free_fw:
85 release_firmware(fw);
86
87 out:
88 kfree(buffer);
89
90 return result;
91 }
92 MODULE_FIRMWARE(FIRMWARE_NAME);
93
94 int vnt_firmware_branch_to_sram(struct vnt_private *priv)
95 {
96 int status;
97
98 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
99
100 status = vnt_control_out(priv,
101 1,
102 0x1200,
103 0x0000,
104 0,
105 NULL);
106 if (status != STATUS_SUCCESS)
107 return false;
108 else
109 return true;
110 }
111
112 int vnt_check_firmware_version(struct vnt_private *priv)
113 {
114 int status;
115
116 status = vnt_control_in(priv,
117 MESSAGE_TYPE_READ,
118 0,
119 MESSAGE_REQUEST_VERSION,
120 2,
121 (u8 *)&priv->firmware_version);
122
123 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
124 priv->firmware_version);
125
126 if (status != STATUS_SUCCESS) {
127 dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
128 return false;
129 }
130 if (priv->firmware_version == 0xFFFF) {
131 dev_dbg(&priv->usb->dev, "In Loader.\n");
132 return false;
133 }
134
135 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
136 priv->firmware_version);
137
138 if (priv->firmware_version < FIRMWARE_VERSION) {
139 /* branch to loader for download new firmware */
140 vnt_firmware_branch_to_sram(priv);
141 return false;
142 }
143 return true;
144 }