treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / staging / vt6656 / firmware.c
blob70358d427211a089ca8c54baf3d2ecf55837a62b
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
6 * File: baseband.c
8 * Purpose: Implement functions to access baseband
10 * Author: Yiching Chen
12 * Date: May 20, 2004
14 * Functions:
16 * Revision History:
20 #include <linux/compiler.h>
21 #include "firmware.h"
22 #include "usbpipe.h"
24 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
25 #define FIRMWARE_NAME "vntwusb.fw"
27 #define FIRMWARE_CHUNK_SIZE 0x400
29 int vnt_download_firmware(struct vnt_private *priv)
31 struct device *dev = &priv->usb->dev;
32 const struct firmware *fw;
33 u16 length;
34 int ii;
35 int ret = 0;
37 dev_dbg(dev, "---->Download firmware\n");
39 ret = request_firmware(&fw, FIRMWARE_NAME, dev);
40 if (ret) {
41 dev_err(dev, "firmware file %s request failed (%d)\n",
42 FIRMWARE_NAME, ret);
43 goto end;
46 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
47 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
49 ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
50 fw->data + ii);
51 if (ret)
52 goto free_fw;
54 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
57 free_fw:
58 release_firmware(fw);
59 end:
60 return ret;
62 MODULE_FIRMWARE(FIRMWARE_NAME);
64 int vnt_firmware_branch_to_sram(struct vnt_private *priv)
66 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
68 return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
71 int vnt_check_firmware_version(struct vnt_private *priv)
73 int ret = 0;
75 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
76 MESSAGE_REQUEST_VERSION, 2,
77 (u8 *)&priv->firmware_version);
78 if (ret) {
79 dev_dbg(&priv->usb->dev,
80 "Could not get firmware version: %d.\n", ret);
81 goto end;
84 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
85 priv->firmware_version);
87 if (priv->firmware_version == 0xFFFF) {
88 dev_dbg(&priv->usb->dev, "In Loader.\n");
89 ret = -EINVAL;
90 goto end;
93 if (priv->firmware_version < FIRMWARE_VERSION) {
94 /* branch to loader for download new firmware */
95 ret = vnt_firmware_branch_to_sram(priv);
96 if (ret) {
97 dev_dbg(&priv->usb->dev,
98 "Could not branch to SRAM: %d.\n", ret);
99 } else {
100 ret = -EINVAL;
104 end:
105 return ret;