2017-11-07 20:07:52 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2009-06-13 11:38:31 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-03-26 16:49:01 +00:00
|
|
|
#include <linux/compiler.h>
|
2009-06-13 11:38:31 +00:00
|
|
|
#include "firmware.h"
|
2014-05-26 12:59:07 +00:00
|
|
|
#include "usbpipe.h"
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-01-09 04:16:48 +00:00
|
|
|
#define FIRMWARE_VERSION 0x133 /* version 1.51 */
|
|
|
|
#define FIRMWARE_NAME "vntwusb.fw"
|
|
|
|
|
|
|
|
#define FIRMWARE_CHUNK_SIZE 0x400
|
|
|
|
|
2014-06-04 17:25:31 +00:00
|
|
|
int vnt_download_firmware(struct vnt_private *priv)
|
2009-06-13 11:38:31 +00:00
|
|
|
{
|
2014-06-04 17:25:27 +00:00
|
|
|
struct device *dev = &priv->usb->dev;
|
2011-01-09 04:16:48 +00:00
|
|
|
const struct firmware *fw;
|
2014-06-04 17:25:27 +00:00
|
|
|
int status;
|
|
|
|
void *buffer = NULL;
|
2013-02-13 01:36:29 +00:00
|
|
|
bool result = false;
|
2014-06-04 17:25:27 +00:00
|
|
|
u16 length;
|
2012-10-07 10:41:31 +00:00
|
|
|
int ii, rc;
|
|
|
|
|
2014-06-04 17:25:30 +00:00
|
|
|
dev_dbg(dev, "---->Download firmware\n");
|
2011-01-09 04:16:48 +00:00
|
|
|
|
2012-10-07 10:41:31 +00:00
|
|
|
rc = request_firmware(&fw, FIRMWARE_NAME, dev);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(dev, "firmware file %s request failed (%d)\n",
|
|
|
|
FIRMWARE_NAME, rc);
|
2011-01-09 04:16:48 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-06-04 17:25:27 +00:00
|
|
|
buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
|
|
|
|
if (!buffer)
|
2015-02-11 19:33:15 +00:00
|
|
|
goto free_fw;
|
2011-01-09 04:16:48 +00:00
|
|
|
|
|
|
|
for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
|
2014-06-04 17:25:27 +00:00
|
|
|
length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
|
|
|
|
memcpy(buffer, fw->data + ii, length);
|
2011-01-09 04:16:48 +00:00
|
|
|
|
2014-06-04 17:25:27 +00:00
|
|
|
status = vnt_control_out(priv,
|
2017-02-14 18:09:15 +00:00
|
|
|
0,
|
2017-06-30 21:38:51 +00:00
|
|
|
0x1200 + ii,
|
2017-02-14 18:09:15 +00:00
|
|
|
0x0000,
|
|
|
|
length,
|
|
|
|
buffer);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:30 +00:00
|
|
|
dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
|
|
|
|
|
2014-06-04 17:25:27 +00:00
|
|
|
if (status != STATUS_SUCCESS)
|
2012-10-07 10:41:31 +00:00
|
|
|
goto free_fw;
|
2013-10-17 18:52:23 +00:00
|
|
|
}
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2013-02-13 01:36:30 +00:00
|
|
|
result = true;
|
2012-10-07 10:41:31 +00:00
|
|
|
free_fw:
|
|
|
|
release_firmware(fw);
|
2011-01-09 04:16:48 +00:00
|
|
|
|
|
|
|
out:
|
2014-06-04 17:25:27 +00:00
|
|
|
kfree(buffer);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-01-09 04:16:48 +00:00
|
|
|
return result;
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|
2011-01-09 04:16:48 +00:00
|
|
|
MODULE_FIRMWARE(FIRMWARE_NAME);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:32 +00:00
|
|
|
int vnt_firmware_branch_to_sram(struct vnt_private *priv)
|
2009-06-13 11:38:31 +00:00
|
|
|
{
|
2014-06-04 17:25:28 +00:00
|
|
|
int status;
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:30 +00:00
|
|
|
dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
|
2013-10-17 18:52:23 +00:00
|
|
|
|
2014-06-04 17:25:28 +00:00
|
|
|
status = vnt_control_out(priv,
|
2017-02-14 18:09:15 +00:00
|
|
|
1,
|
|
|
|
0x1200,
|
|
|
|
0x0000,
|
|
|
|
0,
|
|
|
|
NULL);
|
2014-09-28 12:41:54 +00:00
|
|
|
return status == STATUS_SUCCESS;
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-04 17:25:33 +00:00
|
|
|
int vnt_check_firmware_version(struct vnt_private *priv)
|
2009-06-13 11:38:31 +00:00
|
|
|
{
|
2014-06-04 17:25:29 +00:00
|
|
|
int status;
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2014-06-04 17:25:29 +00:00
|
|
|
status = vnt_control_in(priv,
|
2017-02-14 18:09:15 +00:00
|
|
|
MESSAGE_TYPE_READ,
|
|
|
|
0,
|
|
|
|
MESSAGE_REQUEST_VERSION,
|
|
|
|
2,
|
|
|
|
(u8 *)&priv->firmware_version);
|
2013-10-17 18:52:23 +00:00
|
|
|
|
2014-06-04 17:25:30 +00:00
|
|
|
dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
|
2017-02-14 18:09:15 +00:00
|
|
|
priv->firmware_version);
|
2014-06-04 17:25:30 +00:00
|
|
|
|
2014-06-04 17:25:29 +00:00
|
|
|
if (status != STATUS_SUCCESS) {
|
2014-06-04 17:25:30 +00:00
|
|
|
dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
|
2013-10-17 18:52:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-19 11:30:05 +00:00
|
|
|
if (priv->firmware_version == 0xFFFF) {
|
2014-06-04 17:25:30 +00:00
|
|
|
dev_dbg(&priv->usb->dev, "In Loader.\n");
|
2013-10-17 18:52:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-06-04 17:25:30 +00:00
|
|
|
|
|
|
|
dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
|
2017-02-14 18:09:15 +00:00
|
|
|
priv->firmware_version);
|
2014-06-04 17:25:30 +00:00
|
|
|
|
2014-07-19 11:30:05 +00:00
|
|
|
if (priv->firmware_version < FIRMWARE_VERSION) {
|
2013-10-17 18:52:26 +00:00
|
|
|
/* branch to loader for download new firmware */
|
2014-06-04 17:25:32 +00:00
|
|
|
vnt_firmware_branch_to_sram(priv);
|
2013-10-17 18:52:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|