2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
18 * Purpose: Implement functions to access baseband
20 * Author: Yiching Chen
30 #include <linux/compiler.h>
34 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
35 #define FIRMWARE_NAME "vntwusb.fw"
37 #define FIRMWARE_CHUNK_SIZE 0x400
39 int vnt_download_firmware(struct vnt_private *priv)
41 struct device *dev = &priv->usb->dev;
42 const struct firmware *fw;
49 dev_dbg(dev, "---->Download firmware\n");
51 rc = request_firmware(&fw, FIRMWARE_NAME, dev);
53 dev_err(dev, "firmware file %s request failed (%d)\n",
58 buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
62 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
63 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
64 memcpy(buffer, fw->data + ii, length);
66 status = vnt_control_out(priv,
73 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
75 if (status != STATUS_SUCCESS)
88 MODULE_FIRMWARE(FIRMWARE_NAME);
90 int vnt_firmware_branch_to_sram(struct vnt_private *priv)
94 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
96 status = vnt_control_out(priv,
102 return status == STATUS_SUCCESS;
105 int vnt_check_firmware_version(struct vnt_private *priv)
109 status = vnt_control_in(priv,
112 MESSAGE_REQUEST_VERSION,
114 (u8 *)&priv->firmware_version);
116 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
117 priv->firmware_version);
119 if (status != STATUS_SUCCESS) {
120 dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
123 if (priv->firmware_version == 0xFFFF) {
124 dev_dbg(&priv->usb->dev, "In Loader.\n");
128 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
129 priv->firmware_version);
131 if (priv->firmware_version < FIRMWARE_VERSION) {
132 /* branch to loader for download new firmware */
133 vnt_firmware_branch_to_sram(priv);