firmware.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #include <linux/compiler.h>
  34. #include "firmware.h"
  35. #include "usbpipe.h"
  36. #define FIRMWARE_VERSION 0x133 /* version 1.51 */
  37. #define FIRMWARE_NAME "vntwusb.fw"
  38. #define FIRMWARE_CHUNK_SIZE 0x400
  39. int vnt_download_firmware(struct vnt_private *priv)
  40. {
  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;
  48. dev_dbg(dev, "---->Download firmware\n");
  49. rc = request_firmware(&fw, FIRMWARE_NAME, dev);
  50. if (rc) {
  51. dev_err(dev, "firmware file %s request failed (%d)\n",
  52. FIRMWARE_NAME, rc);
  53. goto out;
  54. }
  55. buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
  56. if (!buffer)
  57. goto free_fw;
  58. for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
  59. length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
  60. memcpy(buffer, fw->data + ii, length);
  61. status = vnt_control_out(priv,
  62. 0,
  63. 0x1200+ii,
  64. 0x0000,
  65. length,
  66. buffer);
  67. dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
  68. if (status != STATUS_SUCCESS)
  69. goto free_fw;
  70. }
  71. result = true;
  72. free_fw:
  73. release_firmware(fw);
  74. out:
  75. kfree(buffer);
  76. return result;
  77. }
  78. MODULE_FIRMWARE(FIRMWARE_NAME);
  79. int vnt_firmware_branch_to_sram(struct vnt_private *priv)
  80. {
  81. int status;
  82. dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
  83. status = vnt_control_out(priv,
  84. 1,
  85. 0x1200,
  86. 0x0000,
  87. 0,
  88. NULL);
  89. return status == STATUS_SUCCESS;
  90. }
  91. int vnt_check_firmware_version(struct vnt_private *priv)
  92. {
  93. int status;
  94. status = vnt_control_in(priv,
  95. MESSAGE_TYPE_READ,
  96. 0,
  97. MESSAGE_REQUEST_VERSION,
  98. 2,
  99. (u8 *)&priv->firmware_version);
  100. dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
  101. priv->firmware_version);
  102. if (status != STATUS_SUCCESS) {
  103. dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
  104. return false;
  105. }
  106. if (priv->firmware_version == 0xFFFF) {
  107. dev_dbg(&priv->usb->dev, "In Loader.\n");
  108. return false;
  109. }
  110. dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
  111. priv->firmware_version);
  112. if (priv->firmware_version < FIRMWARE_VERSION) {
  113. /* branch to loader for download new firmware */
  114. vnt_firmware_branch_to_sram(priv);
  115. return false;
  116. }
  117. return true;
  118. }