cmd_pn62.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <malloc.h>
  9. #include <net.h>
  10. #include <asm/io.h>
  11. #include <pci.h>
  12. #include <command.h>
  13. #include "pn62.h"
  14. #if defined(CONFIG_CMD_BSP)
  15. /*
  16. * Command led: controls the various LEDs 0..11 on the PN62 card.
  17. */
  18. int do_led(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
  19. {
  20. unsigned int number, function;
  21. if (argc != 3)
  22. return cmd_usage(cmdtp);
  23. number = simple_strtoul(argv[1], NULL, 10);
  24. if (number > PN62_LED_MAX)
  25. return 1;
  26. function = simple_strtoul(argv[2], NULL, 16);
  27. set_led(number, function);
  28. return 0;
  29. }
  30. U_BOOT_CMD(
  31. led , 3, 1, do_led,
  32. "set LED 0..11 on the PN62 board",
  33. "i fun"
  34. " - set 'i'th LED to function 'fun'"
  35. );
  36. /*
  37. * Command loadpci: loads a image over PCI.
  38. */
  39. #define CMD_MOVE_WINDOW 0x1
  40. #define CMD_BOOT_IMAGE 0x2
  41. int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  42. {
  43. char *s;
  44. ulong addr = 0, count = 0;
  45. u32 off;
  46. int cmd, rcode = 0;
  47. /* pre-set load_addr */
  48. if ((s = getenv("loadaddr")) != NULL) {
  49. addr = simple_strtoul(s, NULL, 16);
  50. }
  51. switch (argc) {
  52. case 1:
  53. break;
  54. case 2:
  55. addr = simple_strtoul(argv[1], NULL, 16);
  56. break;
  57. default:
  58. return cmd_usage(cmdtp);
  59. }
  60. printf ("## Ready for image download ...\n");
  61. show_startup_phase(12);
  62. while (1) {
  63. /* Alive indicator */
  64. i2155x_write_scrapad(BOOT_PROTO, BOOT_PROTO_READY);
  65. /* Toggle status LEDs */
  66. cmd = (count / 200) % 4; /* downscale */
  67. set_led(4, cmd == 0 ? LED_1 : LED_0);
  68. set_led(5, cmd == 1 ? LED_1 : LED_0);
  69. set_led(6, cmd == 2 ? LED_1 : LED_0);
  70. set_led(7, cmd == 3 ? LED_1 : LED_0);
  71. udelay(1000);
  72. count++;
  73. cmd = i2155x_read_scrapad(BOOT_CMD);
  74. if (cmd == BOOT_CMD_MOVE) {
  75. off = i2155x_read_scrapad(BOOT_DATA);
  76. off += addr;
  77. i2155x_set_bar_base(3, off);
  78. printf ("## BAR3 Addr moved = 0x%08x\n", off);
  79. i2155x_write_scrapad(BOOT_CMD, ~cmd);
  80. show_startup_phase(13);
  81. }
  82. else if (cmd == BOOT_CMD_BOOT) {
  83. set_led(4, LED_1);
  84. set_led(5, LED_1);
  85. set_led(6, LED_1);
  86. set_led(7, LED_1);
  87. i2155x_write_scrapad(BOOT_CMD, ~cmd);
  88. show_startup_phase(14);
  89. break;
  90. }
  91. /* Abort if ctrl-c was pressed */
  92. if (ctrlc()) {
  93. printf("\nAbort\n");
  94. return 0;
  95. }
  96. }
  97. /* Repoint to the default shared memory */
  98. i2155x_set_bar_base(3, PN62_SMEM_DEFAULT);
  99. load_addr = addr;
  100. printf ("## Start Addr = 0x%08lx\n", addr);
  101. show_startup_phase(15);
  102. /* Loading ok, check if we should attempt an auto-start */
  103. if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
  104. char *local_args[2];
  105. local_args[0] = argv[0];
  106. local_args[1] = NULL;
  107. printf ("Automatic boot of image at addr 0x%08lX ...\n",
  108. load_addr);
  109. rcode = do_bootm (cmdtp, 0, 1, local_args);
  110. }
  111. return rcode;
  112. }
  113. U_BOOT_CMD(
  114. loadpci, 2, 1, do_loadpci,
  115. "load binary file over PCI",
  116. "[addr]\n"
  117. " - load binary file over PCI to address 'addr'"
  118. );
  119. #endif