1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose: Implement functions to access baseband
10 * Author: Yiching Chen
20 #include <linux/compiler.h>
24 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
25 #define FIRMWARE_NAME "vntwusb.fw"
27 #define FIRMWARE_CHUNK_SIZE 0x400
29 int vnt_download_firmware(struct vnt_private
*priv
)
31 struct device
*dev
= &priv
->usb
->dev
;
32 const struct firmware
*fw
;
39 dev_dbg(dev
, "---->Download firmware\n");
41 rc
= request_firmware(&fw
, FIRMWARE_NAME
, dev
);
43 dev_err(dev
, "firmware file %s request failed (%d)\n",
48 buffer
= kmalloc(FIRMWARE_CHUNK_SIZE
, GFP_KERNEL
);
52 for (ii
= 0; ii
< fw
->size
; ii
+= FIRMWARE_CHUNK_SIZE
) {
53 length
= min_t(int, fw
->size
- ii
, FIRMWARE_CHUNK_SIZE
);
54 memcpy(buffer
, fw
->data
+ ii
, length
);
56 status
= vnt_control_out(priv
,
63 dev_dbg(dev
, "Download firmware...%d %zu\n", ii
, fw
->size
);
65 if (status
!= STATUS_SUCCESS
)
78 MODULE_FIRMWARE(FIRMWARE_NAME
);
80 int vnt_firmware_branch_to_sram(struct vnt_private
*priv
)
84 dev_dbg(&priv
->usb
->dev
, "---->Branch to Sram\n");
86 status
= vnt_control_out(priv
,
92 return status
== STATUS_SUCCESS
;
95 int vnt_check_firmware_version(struct vnt_private
*priv
)
99 status
= vnt_control_in(priv
,
102 MESSAGE_REQUEST_VERSION
,
104 (u8
*)&priv
->firmware_version
);
106 dev_dbg(&priv
->usb
->dev
, "Firmware Version [%04x]\n",
107 priv
->firmware_version
);
109 if (status
!= STATUS_SUCCESS
) {
110 dev_dbg(&priv
->usb
->dev
, "Firmware Invalid.\n");
113 if (priv
->firmware_version
== 0xFFFF) {
114 dev_dbg(&priv
->usb
->dev
, "In Loader.\n");
118 dev_dbg(&priv
->usb
->dev
, "Firmware Version [%04x]\n",
119 priv
->firmware_version
);
121 if (priv
->firmware_version
< FIRMWARE_VERSION
) {
122 /* branch to loader for download new firmware */
123 vnt_firmware_branch_to_sram(priv
);