hub75_init_inject.v 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * hub75_init_inject.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  7. * All rights reserved.
  8. *
  9. * LGPL v3+, see LICENSE.lgpl3
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 3 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with this program; if not, write to the Free Software Foundation,
  23. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25. `default_nettype none
  26. module hub75_init_inject #(
  27. parameter integer N_BANKS = 2,
  28. parameter integer N_ROWS = 32,
  29. parameter integer N_COLS = 64,
  30. parameter integer N_CHANS = 3,
  31. parameter INIT_R1 = 16'h7FFF,
  32. parameter INIT_R2 = 16'h0040,
  33. // Auto-set
  34. parameter integer SDW = N_BANKS * N_CHANS,
  35. parameter integer LOG_N_ROWS = $clog2(N_ROWS),
  36. parameter integer LOG_N_COLS = $clog2(N_COLS)
  37. )(
  38. // PHY interface signals input
  39. input wire phy_in_addr_inc,
  40. input wire phy_in_addr_rst,
  41. input wire [LOG_N_ROWS-1:0] phy_in_addr,
  42. input wire [SDW-1:0] phy_in_data,
  43. input wire phy_in_clk,
  44. input wire phy_in_le,
  45. input wire phy_in_blank,
  46. // PHY interface signals input
  47. output reg phy_out_addr_inc,
  48. output reg phy_out_addr_rst,
  49. output reg [LOG_N_ROWS-1:0] phy_out_addr,
  50. output reg [SDW-1:0] phy_out_data,
  51. output reg phy_out_clk,
  52. output reg phy_out_le,
  53. output reg phy_out_blank,
  54. // Control
  55. input wire init_req,
  56. input wire scan_go_in,
  57. input wire bcm_rdy_in,
  58. output wire bcm_rdy_out,
  59. input wire shift_rdy_in,
  60. input wire blank_rdy_in,
  61. // Clock / Reset
  62. input wire clk,
  63. input wire rst
  64. );
  65. // Signals
  66. // -------
  67. // FSM
  68. localparam
  69. ST_IDLE = 0, // Idle
  70. ST_WAIT = 1, // Wait for all activity to be done so we can use the PHY
  71. ST_SHIFT = 2, // Shift the init
  72. ST_GO = 3; // Issue go to scan block
  73. reg [1:0] fsm_state;
  74. reg [1:0] fsm_state_next;
  75. // Request
  76. reg init_done;
  77. // Injection
  78. wire active;
  79. wire inject_data;
  80. wire inject_le;
  81. // Shift logic
  82. reg [LOG_N_COLS:0] col_cnt;
  83. reg col_last;
  84. reg col_le;
  85. wire col_rst;
  86. reg reg_sel;
  87. (* keep="true" *) wire [1:0] reg_bit;
  88. // FSM
  89. // ---
  90. // State register
  91. always @(posedge clk or posedge rst)
  92. if (rst)
  93. fsm_state <= ST_IDLE;
  94. else
  95. fsm_state <= fsm_state_next;
  96. // Next-State logic
  97. always @(*)
  98. begin
  99. // Default is to not move
  100. fsm_state_next = fsm_state;
  101. // Transistions ?
  102. case (fsm_state)
  103. ST_IDLE:
  104. if (scan_go_in & ~init_done)
  105. fsm_state_next = ST_WAIT;
  106. ST_WAIT:
  107. if (bcm_rdy_in & shift_rdy_in & blank_rdy_in)
  108. fsm_state_next = ST_SHIFT;
  109. ST_SHIFT:
  110. if (col_last & reg_sel)
  111. fsm_state_next = ST_GO;
  112. ST_GO:
  113. fsm_state_next = ST_IDLE;
  114. endcase
  115. end
  116. // Control
  117. // -------
  118. always @(posedge clk)
  119. if (rst)
  120. init_done <= 1'b0;
  121. else
  122. init_done <= (init_done | (fsm_state == ST_GO)) & ~init_req;
  123. // External handshake
  124. assign bcm_rdy_out = (fsm_state == ST_IDLE) & bcm_rdy_in;
  125. // Init sequence shift
  126. // -------------------
  127. // Flag
  128. assign active = (fsm_state == ST_SHIFT);
  129. // Column counter
  130. assign col_rst = col_last | (fsm_state != ST_SHIFT);
  131. always @(posedge clk)
  132. if (col_rst) begin
  133. col_cnt <= N_COLS - 17;
  134. col_last <= 1'b0;
  135. col_le <= 1'b0;
  136. end else begin
  137. col_cnt <= col_cnt - 1;
  138. col_last <= col_cnt[LOG_N_COLS] & (col_cnt[3:0] == 4'h1);
  139. col_le <= col_cnt[LOG_N_COLS] & (col_cnt[3:0] < (reg_sel ? 4'hd : 4'hc));
  140. end
  141. // Reg select
  142. always @(posedge clk)
  143. reg_sel <= (fsm_state == ST_SHIFT) ? (reg_sel ^ col_last) : 1'b0;
  144. // ROM
  145. assign reg_bit[0] = INIT_R1[col_cnt[3:0]];
  146. assign reg_bit[1] = INIT_R2[col_cnt[3:0]];
  147. // Outputs
  148. assign inject_data = reg_bit[reg_sel];
  149. assign inject_le = col_le;
  150. // PHY signal injection
  151. // --------------------
  152. always @(posedge clk)
  153. begin
  154. phy_out_addr_inc <= ~active ? phy_in_addr_inc : 1'b0;
  155. phy_out_addr_rst <= ~active ? phy_in_addr_rst : 1'b0;
  156. phy_out_addr <= ~active ? phy_in_addr : { LOG_N_ROWS{1'b0} };
  157. phy_out_data <= ~active ? phy_in_data : { SDW{inject_data} };
  158. phy_out_clk <= ~active ? phy_in_clk : 1'b1;
  159. phy_out_le <= ~active ? phy_in_le : inject_le;
  160. phy_out_blank <= ~active ? phy_in_blank : 1'b1;
  161. end
  162. endmodule