drm/i915: Implement Wa4x4STCOptimizationDisable:chv
[linux-2.6/btrfs-unstable.git] / drivers / staging / vt6656 / firmware.c
bloba177645af83e6e8d5b37491b0b6096f74fdf55b9
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
20 * File: baseband.c
22 * Purpose: Implement functions to access baseband
24 * Author: Yiching Chen
26 * Date: May 20, 2004
28 * Functions:
30 * Revision History:
34 #include <linux/compiler.h>
35 #include "firmware.h"
36 #include "usbpipe.h"
38 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
39 #define FIRMWARE_NAME "vntwusb.fw"
41 #define FIRMWARE_CHUNK_SIZE 0x400
43 int vnt_download_firmware(struct vnt_private *priv)
45 struct device *dev = &priv->usb->dev;
46 const struct firmware *fw;
47 int status;
48 void *buffer = NULL;
49 bool result = false;
50 u16 length;
51 int ii, rc;
53 dev_dbg(dev, "---->Download firmware\n");
55 rc = request_firmware(&fw, FIRMWARE_NAME, dev);
56 if (rc) {
57 dev_err(dev, "firmware file %s request failed (%d)\n",
58 FIRMWARE_NAME, rc);
59 goto out;
62 buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
63 if (!buffer)
64 goto out;
66 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
67 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
68 memcpy(buffer, fw->data + ii, length);
70 status = vnt_control_out(priv,
72 0x1200+ii,
73 0x0000,
74 length,
75 buffer);
77 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
79 if (status != STATUS_SUCCESS)
80 goto free_fw;
83 result = true;
84 free_fw:
85 release_firmware(fw);
87 out:
88 kfree(buffer);
90 return result;
92 MODULE_FIRMWARE(FIRMWARE_NAME);
94 int vnt_firmware_branch_to_sram(struct vnt_private *priv)
96 int status;
98 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
100 status = vnt_control_out(priv,
102 0x1200,
103 0x0000,
105 NULL);
106 return status == STATUS_SUCCESS;
109 int vnt_check_firmware_version(struct vnt_private *priv)
111 int status;
113 status = vnt_control_in(priv,
114 MESSAGE_TYPE_READ,
116 MESSAGE_REQUEST_VERSION,
118 (u8 *)&priv->firmware_version);
120 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
121 priv->firmware_version);
123 if (status != STATUS_SUCCESS) {
124 dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
125 return false;
127 if (priv->firmware_version == 0xFFFF) {
128 dev_dbg(&priv->usb->dev, "In Loader.\n");
129 return false;
132 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
133 priv->firmware_version);
135 if (priv->firmware_version < FIRMWARE_VERSION) {
136 /* branch to loader for download new firmware */
137 vnt_firmware_branch_to_sram(priv);
138 return false;
140 return true;