2009-06-13 11:38:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2013-10-17 18:52:23 +00:00
|
|
|
static int msglevel = MSG_LEVEL_INFO;
|
2013-10-17 18:52:26 +00:00
|
|
|
/* static int msglevel = MSG_LEVEL_DEBUG; */
|
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:27 +00:00
|
|
|
int FIRMWAREbDownload(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;
|
|
|
|
|
2011-01-09 04:16:48 +00:00
|
|
|
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
|
|
|
|
|
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)
|
2011-01-09 04:16:48 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
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,
|
2013-10-17 18:52:23 +00:00
|
|
|
0,
|
|
|
|
0x1200+ii,
|
|
|
|
0x0000,
|
2014-06-04 17:25:27 +00:00
|
|
|
length,
|
|
|
|
buffer);
|
2009-06-13 11:38:31 +00:00
|
|
|
|
2011-01-09 04:16:48 +00:00
|
|
|
DBG_PRT(MSG_LEVEL_DEBUG,
|
|
|
|
KERN_INFO"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:28 +00:00
|
|
|
int FIRMWAREbBrach2Sram(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
|
|
|
|
2013-10-17 18:52:23 +00:00
|
|
|
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
|
|
|
|
|
2014-06-04 17:25:28 +00:00
|
|
|
status = vnt_control_out(priv,
|
2013-10-17 18:52:23 +00:00
|
|
|
1,
|
|
|
|
0x1200,
|
|
|
|
0x0000,
|
|
|
|
0,
|
|
|
|
NULL);
|
2014-06-04 17:25:28 +00:00
|
|
|
if (status != STATUS_SUCCESS)
|
2013-10-17 18:52:25 +00:00
|
|
|
return false;
|
2013-10-17 18:52:24 +00:00
|
|
|
else
|
2013-10-17 18:52:25 +00:00
|
|
|
return true;
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-04 17:25:29 +00:00
|
|
|
int FIRMWAREbCheckVersion(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,
|
2013-10-17 18:52:23 +00:00
|
|
|
MESSAGE_TYPE_READ,
|
|
|
|
0,
|
|
|
|
MESSAGE_REQUEST_VERSION,
|
|
|
|
2,
|
2014-06-04 17:25:29 +00:00
|
|
|
(u8 *) &(priv->wFirmwareVersion));
|
2013-10-17 18:52:23 +00:00
|
|
|
|
2013-10-17 18:52:27 +00:00
|
|
|
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n",
|
2014-06-04 17:25:29 +00:00
|
|
|
priv->wFirmwareVersion);
|
|
|
|
if (status != STATUS_SUCCESS) {
|
2013-10-17 18:52:23 +00:00
|
|
|
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-04 17:25:29 +00:00
|
|
|
if (priv->wFirmwareVersion == 0xFFFF) {
|
2013-10-17 18:52:23 +00:00
|
|
|
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-17 18:52:27 +00:00
|
|
|
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n",
|
2014-06-04 17:25:29 +00:00
|
|
|
priv->wFirmwareVersion);
|
|
|
|
if (priv->wFirmwareVersion < FIRMWARE_VERSION) {
|
2013-10-17 18:52:26 +00:00
|
|
|
/* branch to loader for download new firmware */
|
2014-06-04 17:25:29 +00:00
|
|
|
FIRMWAREbBrach2Sram(priv);
|
2013-10-17 18:52:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2009-06-13 11:38:31 +00:00
|
|
|
}
|