/drivers/staging/vt6656/firmware.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 174 lines · 104 code · 30 blank · 40 comment · 14 complexity · 48d817b1c4eec5db1d66529486b8cc42 MD5 · raw file

  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 "firmware.h"
  34. #include "control.h"
  35. #include "rndis.h"
  36. /*--------------------- Static Definitions -------------------------*/
  37. static int msglevel =MSG_LEVEL_INFO;
  38. //static int msglevel =MSG_LEVEL_DEBUG;
  39. #define FIRMWARE_VERSION 0x133 /* version 1.51 */
  40. #define FIRMWARE_NAME "vntwusb.fw"
  41. #define FIRMWARE_CHUNK_SIZE 0x400
  42. /*--------------------- Static Classes ----------------------------*/
  43. /*--------------------- Static Variables --------------------------*/
  44. /*--------------------- Static Functions --------------------------*/
  45. /*--------------------- Export Variables --------------------------*/
  46. /*--------------------- Export Functions --------------------------*/
  47. BOOL
  48. FIRMWAREbDownload(
  49. PSDevice pDevice
  50. )
  51. {
  52. const struct firmware *fw;
  53. int NdisStatus;
  54. void *pBuffer = NULL;
  55. BOOL result = FALSE;
  56. u16 wLength;
  57. int ii;
  58. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
  59. spin_unlock_irq(&pDevice->lock);
  60. if (!pDevice->firmware) {
  61. struct device *dev = &pDevice->usb->dev;
  62. int rc;
  63. rc = request_firmware(&pDevice->firmware, FIRMWARE_NAME, dev);
  64. if (rc) {
  65. dev_err(dev, "firmware file %s request failed (%d)\n",
  66. FIRMWARE_NAME, rc);
  67. goto out;
  68. }
  69. }
  70. fw = pDevice->firmware;
  71. pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
  72. if (!pBuffer)
  73. goto out;
  74. for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
  75. wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
  76. memcpy(pBuffer, fw->data + ii, wLength);
  77. NdisStatus = CONTROLnsRequestOutAsyn(pDevice,
  78. 0,
  79. 0x1200+ii,
  80. 0x0000,
  81. wLength,
  82. pBuffer
  83. );
  84. DBG_PRT(MSG_LEVEL_DEBUG,
  85. KERN_INFO"Download firmware...%d %zu\n", ii, fw->size);
  86. if (NdisStatus != STATUS_SUCCESS)
  87. goto out;
  88. }
  89. result = TRUE;
  90. out:
  91. kfree(pBuffer);
  92. spin_lock_irq(&pDevice->lock);
  93. return result;
  94. }
  95. MODULE_FIRMWARE(FIRMWARE_NAME);
  96. BOOL
  97. FIRMWAREbBrach2Sram(
  98. PSDevice pDevice
  99. )
  100. {
  101. int NdisStatus;
  102. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
  103. NdisStatus = CONTROLnsRequestOut(pDevice,
  104. 1,
  105. 0x1200,
  106. 0x0000,
  107. 0,
  108. NULL
  109. );
  110. if (NdisStatus != STATUS_SUCCESS) {
  111. return (FALSE);
  112. } else {
  113. return (TRUE);
  114. }
  115. }
  116. BOOL
  117. FIRMWAREbCheckVersion(
  118. PSDevice pDevice
  119. )
  120. {
  121. int ntStatus;
  122. ntStatus = CONTROLnsRequestIn(pDevice,
  123. MESSAGE_TYPE_READ,
  124. 0,
  125. MESSAGE_REQUEST_VERSION,
  126. 2,
  127. (PBYTE) &(pDevice->wFirmwareVersion));
  128. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
  129. if (ntStatus != STATUS_SUCCESS) {
  130. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
  131. return FALSE;
  132. }
  133. if (pDevice->wFirmwareVersion == 0xFFFF) {
  134. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
  135. return FALSE;
  136. }
  137. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
  138. if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
  139. // branch to loader for download new firmware
  140. FIRMWAREbBrach2Sram(pDevice);
  141. return FALSE;
  142. }
  143. return TRUE;
  144. }