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
;
37 dev_dbg(dev
, "---->Download firmware\n");
39 ret
= request_firmware(&fw
, FIRMWARE_NAME
, dev
);
41 dev_err(dev
, "firmware file %s request failed (%d)\n",
46 for (ii
= 0; ii
< fw
->size
; ii
+= FIRMWARE_CHUNK_SIZE
) {
47 length
= min_t(int, fw
->size
- ii
, FIRMWARE_CHUNK_SIZE
);
49 ret
= vnt_control_out(priv
, 0, 0x1200 + ii
, 0x0000, length
,
54 dev_dbg(dev
, "Download firmware...%d %zu\n", ii
, fw
->size
);
62 MODULE_FIRMWARE(FIRMWARE_NAME
);
64 int vnt_firmware_branch_to_sram(struct vnt_private
*priv
)
66 dev_dbg(&priv
->usb
->dev
, "---->Branch to Sram\n");
68 return vnt_control_out(priv
, 1, 0x1200, 0x0000, 0, NULL
);
71 int vnt_check_firmware_version(struct vnt_private
*priv
)
75 ret
= vnt_control_in(priv
, MESSAGE_TYPE_READ
, 0,
76 MESSAGE_REQUEST_VERSION
, 2,
77 (u8
*)&priv
->firmware_version
);
79 dev_dbg(&priv
->usb
->dev
,
80 "Could not get firmware version: %d.\n", ret
);
84 dev_dbg(&priv
->usb
->dev
, "Firmware Version [%04x]\n",
85 priv
->firmware_version
);
87 if (priv
->firmware_version
== 0xFFFF) {
88 dev_dbg(&priv
->usb
->dev
, "In Loader.\n");
93 if (priv
->firmware_version
< FIRMWARE_VERSION
) {
94 /* branch to loader for download new firmware */
95 ret
= vnt_firmware_branch_to_sram(priv
);
97 dev_dbg(&priv
->usb
->dev
,
98 "Could not branch to SRAM: %d.\n", ret
);