Commit 72d55ebb authored by Malcolm Priestley's avatar Malcolm Priestley Committed by Greg Kroah-Hartman

staging: vt6656: Move firmware functions into main_usb.

The firmware function are not that complicated so
move them into main_usb as static functions in callers
visibility

Firmware definitions moved to device.h and MODULE_FIRMWARE
move to below module_usb_driver.
Signed-off-by: default avatarMalcolm Priestley <tvboxspy@gmail.com>
Link: https://lore.kernel.org/r/7b384871-826b-9365-e3ed-5717ecefd31c@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 37073089
......@@ -13,7 +13,6 @@ vt6656_stage-y += main_usb.o \
key.o \
rf.o \
usbpipe.o \
channel.o \
firmware.o
channel.o
obj-$(CONFIG_VT6656) += vt6656_stage.o
......@@ -73,6 +73,10 @@
#define DEVICE_VERSION "mac80211"
#define FIRMWARE_VERSION 0x133 /* version 1.51 */
#define FIRMWARE_NAME "vntwusb.fw"
#define FIRMWARE_CHUNK_SIZE 0x400
#define CONFIG_PATH "/etc/vntconfiguration.dat"
#define MAX_UINTS 8
......
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* File: baseband.c
*
* Purpose: Implement functions to access baseband
*
* Author: Yiching Chen
*
* Date: May 20, 2004
*
* Functions:
*
* Revision History:
*
*/
#include <linux/compiler.h>
#include "firmware.h"
#include "usbpipe.h"
#define FIRMWARE_VERSION 0x133 /* version 1.51 */
#define FIRMWARE_NAME "vntwusb.fw"
#define FIRMWARE_CHUNK_SIZE 0x400
int vnt_download_firmware(struct vnt_private *priv)
{
struct device *dev = &priv->usb->dev;
const struct firmware *fw;
u16 length;
int ii;
int ret = 0;
dev_dbg(dev, "---->Download firmware\n");
ret = request_firmware(&fw, FIRMWARE_NAME, dev);
if (ret) {
dev_err(dev, "firmware file %s request failed (%d)\n",
FIRMWARE_NAME, ret);
goto end;
}
for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
fw->data + ii);
if (ret)
goto free_fw;
dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
}
free_fw:
release_firmware(fw);
end:
return ret;
}
MODULE_FIRMWARE(FIRMWARE_NAME);
int vnt_firmware_branch_to_sram(struct vnt_private *priv)
{
dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
}
int vnt_check_firmware_version(struct vnt_private *priv)
{
int ret = 0;
ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
MESSAGE_REQUEST_VERSION, 2,
(u8 *)&priv->firmware_version);
if (ret) {
dev_dbg(&priv->usb->dev,
"Could not get firmware version: %d.\n", ret);
goto end;
}
dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
priv->firmware_version);
if (priv->firmware_version == 0xFFFF) {
dev_dbg(&priv->usb->dev, "In Loader.\n");
ret = -EINVAL;
goto end;
}
if (priv->firmware_version < FIRMWARE_VERSION) {
/* branch to loader for download new firmware */
ret = vnt_firmware_branch_to_sram(priv);
if (ret) {
dev_dbg(&priv->usb->dev,
"Could not branch to SRAM: %d.\n", ret);
} else {
ret = -EINVAL;
}
}
end:
return ret;
}
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* File: firmware.h
*
* Purpose: Version and Release Information
*
* Author: Yiching Chen
*
* Date: May 20, 2004
*
*/
#ifndef __FIRMWARE_H__
#define __FIRMWARE_H__
#include "device.h"
int vnt_download_firmware(struct vnt_private *priv);
int vnt_firmware_branch_to_sram(struct vnt_private *priv);
int vnt_check_firmware_version(struct vnt_private *priv);
#endif /* __FIRMWARE_H__ */
......@@ -33,7 +33,6 @@
#include "wcmd.h"
#include "rxtx.h"
#include "rf.h"
#include "firmware.h"
#include "usbpipe.h"
#include "channel.h"
......@@ -103,6 +102,84 @@ static void vnt_set_options(struct vnt_private *priv)
priv->exist_sw_net_addr = false;
}
static int vnt_download_firmware(struct vnt_private *priv)
{
struct device *dev = &priv->usb->dev;
const struct firmware *fw;
u16 length;
int ii;
int ret = 0;
dev_dbg(dev, "---->Download firmware\n");
ret = request_firmware(&fw, FIRMWARE_NAME, dev);
if (ret) {
dev_err(dev, "firmware file %s request failed (%d)\n",
FIRMWARE_NAME, ret);
goto end;
}
for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
fw->data + ii);
if (ret)
goto free_fw;
dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
}
free_fw:
release_firmware(fw);
end:
return ret;
}
static int vnt_firmware_branch_to_sram(struct vnt_private *priv)
{
dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
}
static int vnt_check_firmware_version(struct vnt_private *priv)
{
int ret = 0;
ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
MESSAGE_REQUEST_VERSION, 2,
(u8 *)&priv->firmware_version);
if (ret) {
dev_dbg(&priv->usb->dev,
"Could not get firmware version: %d.\n", ret);
goto end;
}
dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
priv->firmware_version);
if (priv->firmware_version == 0xFFFF) {
dev_dbg(&priv->usb->dev, "In Loader.\n");
ret = -EINVAL;
goto end;
}
if (priv->firmware_version < FIRMWARE_VERSION) {
/* branch to loader for download new firmware */
ret = vnt_firmware_branch_to_sram(priv);
if (ret) {
dev_dbg(&priv->usb->dev,
"Could not branch to SRAM: %d.\n", ret);
} else {
ret = -EINVAL;
}
}
end:
return ret;
}
/*
* initialization of MAC & BBP registers
*/
......@@ -1067,3 +1144,5 @@ static struct usb_driver vt6656_driver = {
};
module_usb_driver(vt6656_driver);
MODULE_FIRMWARE(FIRMWARE_NAME);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment