fpgad.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2013
  4. * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
  5. *
  6. * based on cmd_mem.c
  7. * (C) Copyright 2000
  8. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  9. */
  10. #include <common.h>
  11. #include <command.h>
  12. #include <console.h>
  13. #include <gdsys_fpga.h>
  14. static uint dp_last_fpga;
  15. static uint dp_last_addr;
  16. static uint dp_last_length = 0x40;
  17. /*
  18. * FPGA Memory Display
  19. *
  20. * Syntax:
  21. * fpgad {fpga} {addr} {len}
  22. */
  23. #define DISP_LINE_LEN 16
  24. int do_fpga_md(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  25. {
  26. unsigned int k;
  27. unsigned int fpga;
  28. ulong addr, length;
  29. int rc = 0;
  30. u16 linebuf[DISP_LINE_LEN/sizeof(u16)];
  31. ulong nbytes;
  32. /*
  33. * We use the last specified parameters, unless new ones are
  34. * entered.
  35. */
  36. fpga = dp_last_fpga;
  37. addr = dp_last_addr;
  38. length = dp_last_length;
  39. if (argc < 3)
  40. return CMD_RET_USAGE;
  41. if ((flag & CMD_FLAG_REPEAT) == 0) {
  42. /*
  43. * FPGA is specified since argc > 2
  44. */
  45. fpga = hextoul(argv[1], NULL);
  46. /*
  47. * Address is specified since argc > 2
  48. */
  49. addr = hextoul(argv[2], NULL);
  50. /*
  51. * If another parameter, it is the length to display.
  52. * Length is the number of objects, not number of bytes.
  53. */
  54. if (argc > 3)
  55. length = hextoul(argv[3], NULL);
  56. }
  57. nbytes = length * sizeof(u16);
  58. do {
  59. ulong linebytes = (nbytes > DISP_LINE_LEN) ?
  60. DISP_LINE_LEN : nbytes;
  61. for (k = 0; k < linebytes / sizeof(u16); ++k)
  62. fpga_get_reg(fpga,
  63. (u16 *)fpga_ptr[fpga] + addr
  64. / sizeof(u16) + k,
  65. addr + k * sizeof(u16),
  66. &linebuf[k]);
  67. print_buffer(addr, (void *)linebuf, sizeof(u16),
  68. linebytes / sizeof(u16),
  69. DISP_LINE_LEN / sizeof(u16));
  70. nbytes -= linebytes;
  71. addr += linebytes;
  72. if (ctrlc()) {
  73. rc = 1;
  74. break;
  75. }
  76. } while (nbytes > 0);
  77. dp_last_fpga = fpga;
  78. dp_last_addr = addr;
  79. dp_last_length = length;
  80. return rc;
  81. }
  82. U_BOOT_CMD(
  83. fpgad, 4, 1, do_fpga_md,
  84. "fpga register display",
  85. "fpga address [# of objects]"
  86. );