blob: 7a34a7fbb1890fd0c73a6bd9f9dcc6419fc28690 [file] [log] [blame]
shalanfd13eb52020-08-21 16:48:07 +02001module spi_sysctrl_wb #(
2 parameter BASE_ADR = 32'h2E00_0000,
3 parameter SPI_CFG = 8'h00,
4 parameter SPI_ENA = 8'h04,
5 parameter SPI_PLL_CFG = 8'h08,
6 parameter SPI_MFGR_ID = 8'h0c,
7 parameter SPI_PROD_ID = 8'h10,
8 parameter SPI_MASK_REV = 8'h14,
9 parameter SPI_PLL_BYPASS = 8'h18
10) (
11 input wb_clk_i,
12 input wb_rst_i,
13
14 input [31:0] wb_dat_i,
15 input [31:0] wb_adr_i,
16 input [3:0] wb_sel_i,
17 input wb_cyc_i,
18 input wb_stb_i,
19 input wb_we_i,
20
21 output [31:0] wb_dat_o,
22 output wb_ack_o,
23
24 // Read-Only HKSPI Registers
25 input [7:0] spi_ro_config, // (verify) wire input to the core not connected to HKSPI, what should it be connected to ?
26
27 input [4:0] spi_ro_pll_div,
28 input [2:0] spi_ro_pll_sel,
29 input spi_ro_xtal_ena,
30 input spi_ro_reg_ena,
31
32 input [25:0] spi_ro_pll_trim,
33 input spi_ro_pll_dco_ena,
34
35 input [11:0] spi_ro_mfgr_id,
36 input [7:0] spi_ro_prod_id,
37 input [3:0] spi_ro_mask_rev,
38 input pll_bypass
39);
40
41 wire resetn;
42 wire valid;
43 wire ready;
44 wire [3:0] iomem_we;
45
46 assign resetn = ~wb_rst_i;
47 assign valid = wb_stb_i && wb_cyc_i;
48
49 assign iomem_we = wb_sel_i & {4{wb_we_i}};
50 assign wb_ack_o = ready;
51
52 spi_sysctrl #(
53 .BASE_ADR(BASE_ADR),
54 .SPI_CFG(SPI_CFG),
55 .SPI_ENA(SPI_ENA),
56 .SPI_PLL_CFG(SPI_PLL_CFG),
57 .SPI_MFGR_ID(SPI_MFGR_ID),
58 .SPI_PROD_ID(SPI_PROD_ID),
59 .SPI_MASK_REV(SPI_MASK_REV),
60 .SPI_PLL_BYPASS(SPI_PLL_BYPASS)
61 ) spi_sysctrl (
62 .clk(wb_clk_i),
63 .resetn(resetn),
64
65 .iomem_addr(wb_adr_i),
66 .iomem_valid(valid),
67 .iomem_wstrb(iomem_we),
68 .iomem_wdata(wb_dat_i),
69 .iomem_rdata(wb_dat_o),
70 .iomem_ready(ready),
71
72 .spi_ro_config(spi_ro_config), // (verify) wire input to the core not connected to HKSPI, what should it be connected to ?
73 .spi_ro_pll_div(spi_ro_pll_div),
74 .spi_ro_pll_sel(spi_ro_pll_sel),
75 .spi_ro_xtal_ena(spi_ro_xtal_ena),
76 .spi_ro_reg_ena(spi_ro_reg_ena),
77
78 .spi_ro_pll_trim(spi_ro_pll_trim),
79 .spi_ro_pll_dco_ena(spi_ro_pll_dco_ena),
80
81 .spi_ro_mfgr_id(spi_ro_mfgr_id),
82 .spi_ro_prod_id(spi_ro_prod_id),
83 .spi_ro_mask_rev(spi_ro_mask_rev),
84 .pll_bypass(pll_bypass)
85 );
86
87endmodule
88
89module spi_sysctrl #(
90 parameter BASE_ADR = 32'h2300_0000,
91 parameter SPI_CFG = 8'h00,
92 parameter SPI_ENA = 8'h04,
93 parameter SPI_PLL_CFG = 8'h08,
94 parameter SPI_MFGR_ID = 8'h0c,
95 parameter SPI_PROD_ID = 8'h10,
96 parameter SPI_MASK_REV = 8'h14,
97 parameter SPI_PLL_BYPASS = 8'h18
98) (
99 input clk,
100 input resetn,
101
102 input [31:0] iomem_addr,
103 input iomem_valid,
104 input [3:0] iomem_wstrb,
105 input [31:0] iomem_wdata,
106 output reg [31:0] iomem_rdata,
107 output reg iomem_ready,
108
109 input [7:0] spi_ro_config, // (verify) wire input to the core not connected to HKSPI, what should it be connected to ?
110
111 input [4:0] spi_ro_pll_div,
112 input [2:0] spi_ro_pll_sel,
113 input spi_ro_xtal_ena,
114 input spi_ro_reg_ena,
115
116 input [25:0] spi_ro_pll_trim,
117 input spi_ro_pll_dco_ena,
118
119 input [11:0] spi_ro_mfgr_id,
120 input [7:0] spi_ro_prod_id,
121 input [3:0] spi_ro_mask_rev,
122 input pll_bypass
123);
124 // Read-only Registers
125
126 wire spi_cfg_sel;
127 wire spi_ena_sel;
128 wire pll_cfg_sel;
129 wire spi_mfgr_sel;
130 wire spi_prod_sel;
131 wire spi_maskrev_sel;
132 wire pll_bypass_sel;
133
134
135 assign spi_cfg_sel = (iomem_addr[7:0] == SPI_CFG);
136 assign spi_ena_sel = (iomem_addr[7:0] == SPI_ENA);
137 assign pll_cfg_sel = (iomem_addr[7:0] == SPI_PLL_CFG);
138 assign spi_mfgr_sel = (iomem_addr[7:0] == SPI_MFGR_ID);
139 assign spi_prod_sel = (iomem_addr[7:0] == SPI_PROD_ID);
140
141 assign spi_maskrev_sel = (iomem_addr[7:0] == SPI_MASK_REV);
142 assign pll_bypass_sel = (iomem_addr[7:0] == SPI_PLL_BYPASS);
143
144 always @(posedge clk) begin
145 iomem_ready <= 0;
146 if (iomem_valid && !iomem_ready && iomem_addr[31:8] == BASE_ADR[31:8]) begin
147 iomem_ready <= 1;
148 if (spi_cfg_sel) begin
149 iomem_rdata <= {24'd0, spi_ro_config};
150
151 end else if (spi_ena_sel) begin
152 iomem_rdata <= {
153 22'd0,
154 spi_ro_pll_div,
155 spi_ro_pll_sel,
156 spi_ro_xtal_ena,
157 spi_ro_reg_ena
158 };
159
160 end else if (pll_cfg_sel) begin
161 iomem_rdata <= {
162 5'd0,
163 spi_ro_pll_trim,
164 spi_ro_pll_dco_ena
165 };
166
167 end else if (spi_mfgr_sel) begin
168 iomem_rdata <= {20'd0, spi_ro_mfgr_id};
169
170 end else if (spi_prod_sel) begin
171 iomem_rdata <= {24'd0, spi_ro_prod_id};
172
173 end else if (spi_maskrev_sel) begin
174 iomem_rdata <= {28'd0, spi_ro_mask_rev};
175
176 end else if (pll_bypass_sel) begin
177 iomem_rdata <= {31'd0, pll_bypass};
178 end
179 end
180 end
181
182endmodule