1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/compiler.h>
21#include "firmware.h"
22#include "usbpipe.h"
23
24#define FIRMWARE_VERSION 0x133
25#define FIRMWARE_NAME "vntwusb.fw"
26
27#define FIRMWARE_CHUNK_SIZE 0x400
28
29int vnt_download_firmware(struct vnt_private *priv)
30{
31 struct device *dev = &priv->usb->dev;
32 const struct firmware *fw;
33 u16 length;
34 int ii;
35 int ret = 0;
36
37 dev_dbg(dev, "---->Download firmware\n");
38
39 ret = request_firmware(&fw, FIRMWARE_NAME, dev);
40 if (ret) {
41 dev_err(dev, "firmware file %s request failed (%d)\n",
42 FIRMWARE_NAME, ret);
43 goto end;
44 }
45
46 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
47 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
48
49 ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
50 fw->data + ii);
51 if (ret)
52 goto free_fw;
53
54 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
55 }
56
57free_fw:
58 release_firmware(fw);
59end:
60 return ret;
61}
62MODULE_FIRMWARE(FIRMWARE_NAME);
63
64int vnt_firmware_branch_to_sram(struct vnt_private *priv)
65{
66 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
67
68 return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
69}
70
71int vnt_check_firmware_version(struct vnt_private *priv)
72{
73 int ret = 0;
74
75 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
76 MESSAGE_REQUEST_VERSION, 2,
77 (u8 *)&priv->firmware_version);
78 if (ret) {
79 dev_dbg(&priv->usb->dev,
80 "Could not get firmware version: %d.\n", ret);
81 goto end;
82 }
83
84 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
85 priv->firmware_version);
86
87 if (priv->firmware_version == 0xFFFF) {
88 dev_dbg(&priv->usb->dev, "In Loader.\n");
89 ret = -EINVAL;
90 goto end;
91 }
92
93 if (priv->firmware_version < FIRMWARE_VERSION) {
94
95 ret = vnt_firmware_branch_to_sram(priv);
96 if (ret) {
97 dev_dbg(&priv->usb->dev,
98 "Could not branch to SRAM: %d.\n", ret);
99 } else {
100 ret = -EINVAL;
101 }
102 }
103
104end:
105 return ret;
106}
107