ngpixis.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Copyright 2010 Freescale Semiconductor
  3. * Author: Timur Tabi <timur@freescale.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 2 of the License, or (at your option)
  8. * any later version.
  9. *
  10. * This file provides support for the ngPIXIS, a board-specific FPGA used on
  11. * some Freescale reference boards.
  12. *
  13. * A "switch" is black rectangular block on the motherboard. It contains
  14. * eight "bits". The ngPIXIS has a set of memory-mapped registers (SWx) that
  15. * shadow the actual physical switches. There is also another set of
  16. * registers (ENx) that tell the ngPIXIS which bits of SWx should actually be
  17. * used to override the values of the bits in the physical switches.
  18. *
  19. * The following macros need to be defined:
  20. *
  21. * PIXIS_BASE - The virtual address of the base of the PIXIS register map
  22. *
  23. * PIXIS_LBMAP_SWITCH - The switch number (i.e. the "x" in "SWx"). This value
  24. * is used in the PIXIS_SW() macro to determine which offset in
  25. * the PIXIS register map corresponds to the physical switch that controls
  26. * the boot bank.
  27. *
  28. * PIXIS_LBMAP_MASK - A bit mask the defines which bits in SWx to use.
  29. *
  30. * PIXIS_LBMAP_SHIFT - The shift value that corresponds to PIXIS_LBMAP_MASK.
  31. *
  32. * PIXIS_LBMAP_ALTBANK - The value to program into SWx to tell the ngPIXIS to
  33. * boot from the alternate bank.
  34. */
  35. #include <common.h>
  36. #include <command.h>
  37. #include <watchdog.h>
  38. #include <asm/cache.h>
  39. #include <asm/io.h>
  40. #include "ngpixis.h"
  41. /*
  42. * Reset the board. This ignores the ENx registers.
  43. */
  44. void pixis_reset(void)
  45. {
  46. out_8(&pixis->rst, 0);
  47. while (1);
  48. }
  49. /*
  50. * Reset the board. Like pixis_reset(), but it honors the ENx registers.
  51. */
  52. void pixis_bank_reset(void)
  53. {
  54. out_8(&pixis->vctl, 0);
  55. out_8(&pixis->vctl, 1);
  56. while (1);
  57. }
  58. /**
  59. * Set the boot bank to the power-on default bank
  60. */
  61. void clear_altbank(void)
  62. {
  63. /* Tell the ngPIXIS to use this the bits in the physical switch for the
  64. * boot bank value, instead of the SWx register. We need to be careful
  65. * only to set the bits in SWx that correspond to the boot bank.
  66. */
  67. clrbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK);
  68. }
  69. /**
  70. * Set the boot bank to the alternate bank
  71. */
  72. void set_altbank(void)
  73. {
  74. /* Program the alternate bank number into the SWx register.
  75. */
  76. clrsetbits_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK,
  77. PIXIS_LBMAP_ALTBANK);
  78. /* Tell the ngPIXIS to use this the bits in the SWx register for the
  79. * boot bank value, instead of the physical switch. We need to be
  80. * careful only to set the bits in SWx that correspond to the boot bank.
  81. */
  82. setbits_8(&PIXIS_EN(PIXIS_LBMAP_SWITCH), PIXIS_LBMAP_MASK);
  83. }
  84. int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  85. {
  86. unsigned int i;
  87. char *p_altbank = NULL;
  88. char *unknown_param = NULL;
  89. /* No args is a simple reset request.
  90. */
  91. if (argc <= 1)
  92. pixis_reset();
  93. for (i = 1; i < argc; i++) {
  94. if (strcmp(argv[i], "altbank") == 0) {
  95. p_altbank = argv[i];
  96. continue;
  97. }
  98. unknown_param = argv[i];
  99. }
  100. if (unknown_param) {
  101. printf("Invalid option: %s\n", unknown_param);
  102. return 1;
  103. }
  104. if (p_altbank)
  105. set_altbank();
  106. else
  107. clear_altbank();
  108. pixis_bank_reset();
  109. /* Shouldn't be reached. */
  110. return 0;
  111. }
  112. U_BOOT_CMD(
  113. pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
  114. "Reset the board using the FPGA sequencer",
  115. "- hard reset to default bank\n"
  116. "pixis_reset altbank - reset to alternate bank\n"
  117. );