vsc7385.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifdef CONFIG_VSC7385_ENET
  16. #include <common.h>
  17. #include <asm/io.h>
  18. #include <asm/errno.h>
  19. /*
  20. * Upload a Vitesse VSC7385 firmware image to the hardware
  21. *
  22. * This function takes a pointer to a VSC7385 firmware image and a size, and
  23. * uploads that firmware to the VSC7385.
  24. *
  25. * This firmware is typically located at a board-specific flash address,
  26. * and the size is typically 8KB.
  27. *
  28. * The firmware is Vitesse proprietary.
  29. *
  30. * Further details on the register information can be obtained from Vitesse.
  31. */
  32. int vsc7385_upload_firmware(void *firmware, unsigned int size)
  33. {
  34. u8 *fw = firmware;
  35. unsigned int i;
  36. u32 *gloreset = (u32 *) (CFG_VSC7385_BASE + 0x1c050);
  37. u32 *icpu_ctrl = (u32 *) (CFG_VSC7385_BASE + 0x1c040);
  38. u32 *icpu_addr = (u32 *) (CFG_VSC7385_BASE + 0x1c044);
  39. u32 *icpu_data = (u32 *) (CFG_VSC7385_BASE + 0x1c048);
  40. u32 *icpu_rom_map = (u32 *) (CFG_VSC7385_BASE + 0x1c070);
  41. #ifdef DEBUG
  42. u32 *chipid = (u32 *) (CFG_VSC7385_BASE + 0x1c060);
  43. #endif
  44. out_be32(gloreset, 3);
  45. udelay(200);
  46. out_be32(icpu_ctrl, 0x8E);
  47. udelay(20);
  48. out_be32(icpu_rom_map, 1);
  49. udelay(20);
  50. /* Write the firmware to I-RAM */
  51. out_be32(icpu_addr, 0);
  52. udelay(20);
  53. for (i = 0; i < size; i++) {
  54. out_be32(icpu_data, fw[i]);
  55. udelay(20);
  56. if (ctrlc())
  57. return -EINTR;
  58. }
  59. /* Read back and compare */
  60. out_be32(icpu_addr, 0);
  61. udelay(20);
  62. for (i = 0; i < size; i++) {
  63. u8 value;
  64. value = (u8) in_be32(icpu_data);
  65. udelay(20);
  66. if (value != fw[i]) {
  67. debug("VSC7385: Upload mismatch: address 0x%x, "
  68. "read value 0x%x, image value 0x%x\n",
  69. i, value, fw[i]);
  70. return -EIO;
  71. }
  72. if (ctrlc())
  73. break;
  74. }
  75. out_be32(icpu_ctrl, 0x0B);
  76. udelay(20);
  77. #ifdef DEBUG
  78. printf("VSC7385: Chip ID is %08x\n", in_be32(chipid));
  79. udelay(20);
  80. #endif
  81. return 0;
  82. }
  83. #endif