mei: me: add cannon point device ids
[linux/fpc-iii.git] / drivers / staging / vt6656 / firmware.c
blob093a6048bd223f0fb9898b17f3f51be3bfd88421
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.
16 * File: baseband.c
18 * Purpose: Implement functions to access baseband
20 * Author: Yiching Chen
22 * Date: May 20, 2004
24 * Functions:
26 * Revision History:
30 #include <linux/compiler.h>
31 #include "firmware.h"
32 #include "usbpipe.h"
34 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
35 #define FIRMWARE_NAME "vntwusb.fw"
37 #define FIRMWARE_CHUNK_SIZE 0x400
39 int vnt_download_firmware(struct vnt_private *priv)
41 struct device *dev = &priv->usb->dev;
42 const struct firmware *fw;
43 int status;
44 void *buffer = NULL;
45 bool result = false;
46 u16 length;
47 int ii, rc;
49 dev_dbg(dev, "---->Download firmware\n");
51 rc = request_firmware(&fw, FIRMWARE_NAME, dev);
52 if (rc) {
53 dev_err(dev, "firmware file %s request failed (%d)\n",
54 FIRMWARE_NAME, rc);
55 goto out;
58 buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
59 if (!buffer)
60 goto free_fw;
62 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
63 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
64 memcpy(buffer, fw->data + ii, length);
66 status = vnt_control_out(priv,
68 0x1200 + ii,
69 0x0000,
70 length,
71 buffer);
73 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
75 if (status != STATUS_SUCCESS)
76 goto free_fw;
79 result = true;
80 free_fw:
81 release_firmware(fw);
83 out:
84 kfree(buffer);
86 return result;
88 MODULE_FIRMWARE(FIRMWARE_NAME);
90 int vnt_firmware_branch_to_sram(struct vnt_private *priv)
92 int status;
94 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
96 status = vnt_control_out(priv,
98 0x1200,
99 0x0000,
101 NULL);
102 return status == STATUS_SUCCESS;
105 int vnt_check_firmware_version(struct vnt_private *priv)
107 int status;
109 status = vnt_control_in(priv,
110 MESSAGE_TYPE_READ,
112 MESSAGE_REQUEST_VERSION,
114 (u8 *)&priv->firmware_version);
116 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
117 priv->firmware_version);
119 if (status != STATUS_SUCCESS) {
120 dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
121 return false;
123 if (priv->firmware_version == 0xFFFF) {
124 dev_dbg(&priv->usb->dev, "In Loader.\n");
125 return false;
128 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
129 priv->firmware_version);
131 if (priv->firmware_version < FIRMWARE_VERSION) {
132 /* branch to loader for download new firmware */
133 vnt_firmware_branch_to_sram(priv);
134 return false;
136 return true;