Linux Audio

Check our new training course

Loading...
v3.15
  1/*
  2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3 * All rights reserved.
  4 *
  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.
  9 *
 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.
 14 *
 15 * You should have received a copy of the GNU General Public License along
 16 * with this program; if not, write to the Free Software Foundation, Inc.,
 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 18 *
 19 *
 20 * File: baseband.c
 21 *
 22 * Purpose: Implement functions to access baseband
 23 *
 24 * Author: Yiching Chen
 25 *
 26 * Date: May 20, 2004
 27 *
 28 * Functions:
 29 *
 30 * Revision History:
 31 *
 32 */
 33
 34#include "firmware.h"
 35#include "control.h"
 36#include "rndis.h"
 37
 38static int msglevel = MSG_LEVEL_INFO;
 39/* static int msglevel = MSG_LEVEL_DEBUG; */
 
 
 40
 41#define FIRMWARE_VERSION	0x133		/* version 1.51 */
 42#define FIRMWARE_NAME		"vntwusb.fw"
 43
 44#define FIRMWARE_CHUNK_SIZE	0x400
 45
 46int FIRMWAREbDownload(struct vnt_private *pDevice)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 47{
 48	struct device *dev = &pDevice->usb->dev;
 49	const struct firmware *fw;
 50	int NdisStatus;
 51	void *pBuffer = NULL;
 52	bool result = false;
 53	u16 wLength;
 54	int ii, rc;
 55
 56	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
 57	spin_unlock_irq(&pDevice->lock);
 58
 59	rc = request_firmware(&fw, FIRMWARE_NAME, dev);
 60	if (rc) {
 61		dev_err(dev, "firmware file %s request failed (%d)\n",
 62			FIRMWARE_NAME, rc);
 
 
 
 
 63			goto out;
 
 64	}
 
 65
 66	pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
 67	if (!pBuffer)
 68		goto out;
 69
 70	for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
 71		wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
 72		memcpy(pBuffer, fw->data + ii, wLength);
 73
 74		NdisStatus = CONTROLnsRequestOutAsyn(pDevice,
 75						0,
 76						0x1200+ii,
 77						0x0000,
 78						wLength,
 79						pBuffer);
 
 80
 81		DBG_PRT(MSG_LEVEL_DEBUG,
 82			KERN_INFO"Download firmware...%d %zu\n", ii, fw->size);
 83		if (NdisStatus != STATUS_SUCCESS)
 84			goto free_fw;
 85	}
 86
 87	result = true;
 88free_fw:
 89	release_firmware(fw);
 90
 91out:
 92	kfree(pBuffer);
 93
 94	spin_lock_irq(&pDevice->lock);
 95	return result;
 96}
 97MODULE_FIRMWARE(FIRMWARE_NAME);
 98
 99int FIRMWAREbBrach2Sram(struct vnt_private *pDevice)
 
 
 
100{
101	int NdisStatus;
102
103	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
104
105	NdisStatus = CONTROLnsRequestOut(pDevice,
106					1,
107					0x1200,
108					0x0000,
109					0,
110					NULL);
111	if (NdisStatus != STATUS_SUCCESS)
112		return false;
113	else
114		return true;
 
 
 
115}
116
117int FIRMWAREbCheckVersion(struct vnt_private *pDevice)
 
 
 
 
118{
119	int ntStatus;
120
121	ntStatus = CONTROLnsRequestIn(pDevice,
122					MESSAGE_TYPE_READ,
123					0,
124					MESSAGE_REQUEST_VERSION,
125					2,
126					(u8 *) &(pDevice->wFirmwareVersion));
127
128	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n",
129						pDevice->wFirmwareVersion);
130	if (ntStatus != STATUS_SUCCESS) {
131		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
132		return false;
133	}
134	if (pDevice->wFirmwareVersion == 0xFFFF) {
135		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
136		return false;
137	}
138	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n",
139						pDevice->wFirmwareVersion);
140	if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
141		/* branch to loader for download new firmware */
142		FIRMWAREbBrach2Sram(pDevice);
143		return false;
144	}
145	return true;
146}
v3.5.6
  1/*
  2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3 * All rights reserved.
  4 *
  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.
  9 *
 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.
 14 *
 15 * You should have received a copy of the GNU General Public License along
 16 * with this program; if not, write to the Free Software Foundation, Inc.,
 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 18 *
 19 *
 20 * File: baseband.c
 21 *
 22 * Purpose: Implement functions to access baseband
 23 *
 24 * Author: Yiching Chen
 25 *
 26 * Date: May 20, 2004
 27 *
 28 * Functions:
 29 *
 30 * Revision History:
 31 *
 32 */
 33
 34#include "firmware.h"
 35#include "control.h"
 36#include "rndis.h"
 37
 38/*---------------------  Static Definitions -------------------------*/
 39
 40static int          msglevel                =MSG_LEVEL_INFO;
 41//static int          msglevel                =MSG_LEVEL_DEBUG;
 42
 43#define FIRMWARE_VERSION	0x133		/* version 1.51 */
 44#define FIRMWARE_NAME		"vntwusb.fw"
 45
 46#define FIRMWARE_CHUNK_SIZE	0x400
 47
 48/*---------------------  Static Classes  ----------------------------*/
 49
 50/*---------------------  Static Variables  --------------------------*/
 51
 52/*---------------------  Static Functions  --------------------------*/
 53
 54/*---------------------  Export Variables  --------------------------*/
 55
 56/*---------------------  Export Functions  --------------------------*/
 57
 58
 59BOOL
 60FIRMWAREbDownload(
 61     PSDevice pDevice
 62    )
 63{
 
 64	const struct firmware *fw;
 65	int NdisStatus;
 66	void *pBuffer = NULL;
 67	BOOL result = FALSE;
 68	u16 wLength;
 69	int ii;
 70
 71	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
 72	spin_unlock_irq(&pDevice->lock);
 73
 74	if (!pDevice->firmware) {
 75		struct device *dev = &pDevice->usb->dev;
 76		int rc;
 77
 78		rc = request_firmware(&pDevice->firmware, FIRMWARE_NAME, dev);
 79		if (rc) {
 80			dev_err(dev, "firmware file %s request failed (%d)\n",
 81				FIRMWARE_NAME, rc);
 82			goto out;
 83		}
 84	}
 85	fw = pDevice->firmware;
 86
 87	pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
 88	if (!pBuffer)
 89		goto out;
 90
 91	for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
 92		wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
 93		memcpy(pBuffer, fw->data + ii, wLength);
 94
 95		NdisStatus = CONTROLnsRequestOutAsyn(pDevice,
 96                                            0,
 97                                            0x1200+ii,
 98                                            0x0000,
 99                                            wLength,
100                                            pBuffer
101                                            );
102
103		DBG_PRT(MSG_LEVEL_DEBUG,
104			KERN_INFO"Download firmware...%d %zu\n", ii, fw->size);
105		if (NdisStatus != STATUS_SUCCESS)
106			goto out;
107        }
108
109	result = TRUE;
 
 
110
111out:
112	kfree(pBuffer);
113
114	spin_lock_irq(&pDevice->lock);
115	return result;
116}
117MODULE_FIRMWARE(FIRMWARE_NAME);
118
119BOOL
120FIRMWAREbBrach2Sram(
121     PSDevice pDevice
122    )
123{
124    int NdisStatus;
125
126    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
127
128    NdisStatus = CONTROLnsRequestOut(pDevice,
129                                    1,
130                                    0x1200,
131                                    0x0000,
132                                    0,
133                                    NULL
134                                    );
135
136    if (NdisStatus != STATUS_SUCCESS) {
137        return (FALSE);
138    } else {
139        return (TRUE);
140    }
141}
142
143
144BOOL
145FIRMWAREbCheckVersion(
146     PSDevice pDevice
147    )
148{
149	int ntStatus;
150
151    ntStatus = CONTROLnsRequestIn(pDevice,
152                                    MESSAGE_TYPE_READ,
153                                    0,
154                                    MESSAGE_REQUEST_VERSION,
155                                    2,
156                                    (PBYTE) &(pDevice->wFirmwareVersion));
157
158    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
159    if (ntStatus != STATUS_SUCCESS) {
160        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
161        return FALSE;
162    }
163    if (pDevice->wFirmwareVersion == 0xFFFF) {
164        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
165        return FALSE;
166    }
167    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
168    if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
169        // branch to loader for download new firmware
170        FIRMWAREbBrach2Sram(pDevice);
171        return FALSE;
172    }
173    return TRUE;
 
 
174}