vsc7385.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Vitesse 7385 Switch Firmware Upload
  3. *
  4. * Author: Timur Tabi <timur@freescale.com>
  5. *
  6. * Copyright 2008 Freescale Semiconductor, Inc. This file is licensed
  7. * under the terms of the GNU General Public License version 2. This
  8. * program is licensed "as is" without any warranty of any kind, whether
  9. * express or implied.
  10. *
  11. * This module uploads proprietary firmware for the Vitesse VSC7385 5-port
  12. * switch.
  13. */
  14. #include <config.h>
  15. #include <common.h>
  16. #include <console.h>
  17. #include <asm/io.h>
  18. #include <linux/errno.h>
  19. #include "vsc7385.h"
  20. /*
  21. * Upload a Vitesse VSC7385 firmware image to the hardware
  22. *
  23. * This function takes a pointer to a VSC7385 firmware image and a size, and
  24. * uploads that firmware to the VSC7385.
  25. *
  26. * This firmware is typically located at a board-specific flash address,
  27. * and the size is typically 8KB.
  28. *
  29. * The firmware is Vitesse proprietary.
  30. *
  31. * Further details on the register information can be obtained from Vitesse.
  32. */
  33. int vsc7385_upload_firmware(void *firmware, unsigned int size)
  34. {
  35. u8 *fw = firmware;
  36. unsigned int i;
  37. u32 *gloreset = (u32 *) (CONFIG_SYS_VSC7385_BASE + 0x1c050);
  38. u32 *icpu_ctrl = (u32 *) (CONFIG_SYS_VSC7385_BASE + 0x1c040);
  39. u32 *icpu_addr = (u32 *) (CONFIG_SYS_VSC7385_BASE + 0x1c044);
  40. u32 *icpu_data = (u32 *) (CONFIG_SYS_VSC7385_BASE + 0x1c048);
  41. u32 *icpu_rom_map = (u32 *) (CONFIG_SYS_VSC7385_BASE + 0x1c070);
  42. #ifdef DEBUG
  43. u32 *chipid = (u32 *) (CONFIG_SYS_VSC7385_BASE + 0x1c060);
  44. #endif
  45. out_be32(gloreset, 3);
  46. udelay(200);
  47. out_be32(icpu_ctrl, 0x8E);
  48. udelay(20);
  49. out_be32(icpu_rom_map, 1);
  50. udelay(20);
  51. /* Write the firmware to I-RAM */
  52. out_be32(icpu_addr, 0);
  53. udelay(20);
  54. for (i = 0; i < size; i++) {
  55. out_be32(icpu_data, fw[i]);
  56. udelay(20);
  57. if (ctrlc())
  58. return -EINTR;
  59. }
  60. /* Read back and compare */
  61. out_be32(icpu_addr, 0);
  62. udelay(20);
  63. for (i = 0; i < size; i++) {
  64. u8 value;
  65. value = (u8) in_be32(icpu_data);
  66. udelay(20);
  67. if (value != fw[i]) {
  68. debug("VSC7385: Upload mismatch: address 0x%x, "
  69. "read value 0x%x, image value 0x%x\n",
  70. i, value, fw[i]);
  71. return -EIO;
  72. }
  73. if (ctrlc())
  74. break;
  75. }
  76. out_be32(icpu_ctrl, 0x0B);
  77. udelay(20);
  78. #ifdef DEBUG
  79. printf("VSC7385: Chip ID is %08x\n", in_be32(chipid));
  80. udelay(20);
  81. #endif
  82. return 0;
  83. }