blob: 8c4ef3f956cf52a48527e3bf044b6ed890514d38 [file] [log] [blame]
agorararmard6c766a82020-12-10 18:13:12 +02001// SPDX-FileCopyrightText: 2020 Efabless Corporation
agorararmarde5780bf2020-12-09 21:27:56 +00002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
agorararmardafa96ea2020-12-09 23:37:31 +020014// SPDX-License-Identifier: Apache-2.0
agorararmarde5780bf2020-12-09 21:27:56 +000015
Matt Venn08cd6eb2020-11-16 12:01:14 +010016`default_nettype none
Tim Edwards04ba17f2020-10-02 22:27:50 -040017/*
18 *---------------------------------------------------------------------
Tim Edwards251e0df2020-10-05 11:02:12 -040019 * See gpio_control_block for description. This module is like
20 * gpio_contro_block except that it has an additional two management-
21 * Soc-facing pins, which are the out_enb line and the output line.
22 * If the chip is configured for output with the oeb control
23 * register = 1, then the oeb line is controlled by the additional
24 * signal from the management SoC. If the oeb control register = 0,
25 * then the output is disabled completely. The "io" line is input
26 * only in this module.
Tim Edwards04ba17f2020-10-02 22:27:50 -040027 *
28 *---------------------------------------------------------------------
29 */
30
31/*
32 *---------------------------------------------------------------------
33 *
34 * This module instantiates a shift register chain that passes through
35 * each gpio cell. These are connected end-to-end around the padframe
36 * periphery. The purpose is to avoid a massive number of control
37 * wires between the digital core and I/O, passing through the user area.
38 *
39 * See mprj_ctrl.v for the module that registers the data for each
40 * I/O and drives the input to the shift register.
41 *
42 *---------------------------------------------------------------------
43 */
44
45module gpio_control_block #(
Tim Edwards44bab472020-10-04 22:09:54 -040046 parameter PAD_CTRL_BITS = 13,
47 // Parameterized initial startup state of the pad.
48 // The default parameters if unspecified is for the pad to be
49 // an input with no pull-up or pull-down, so that it is disconnected
50 // from the outside world.
51 parameter HOLD_INIT = 1'b0,
52 parameter SLOW_INIT = 1'b0,
53 parameter TRIP_INIT = 1'b0,
54 parameter IB_INIT = 1'b0,
55 parameter IENB_INIT = 1'b0,
manarabdelaty589a5282020-12-05 01:06:48 +020056 parameter OENB_INIT = `OENB_INIT,
57 parameter DM_INIT = `DM_INIT,
Tim Edwards44bab472020-10-04 22:09:54 -040058 parameter AENA_INIT = 1'b0,
59 parameter ASEL_INIT = 1'b0,
60 parameter APOL_INIT = 1'b0
Tim Edwards04ba17f2020-10-02 22:27:50 -040061) (
Manar61dce922020-11-10 19:26:28 +020062 `ifdef USE_POWER_PINS
Tim Edwards53d92182020-10-11 21:47:40 -040063 inout vccd,
64 inout vssd,
65 inout vccd1,
66 inout vssd1,
67 `endif
68
Tim Edwards04ba17f2020-10-02 22:27:50 -040069 // Management Soc-facing signals
70 input resetn, // Global reset
71 input serial_clock,
72
Tim Edwards251e0df2020-10-05 11:02:12 -040073 output mgmt_gpio_in, // Management from pad (input only)
74 input mgmt_gpio_out, // Management to pad (output only)
75 input mgmt_gpio_oeb, // Management to pad (output only)
Tim Edwards04ba17f2020-10-02 22:27:50 -040076
77 // Serial data chain for pad configuration
78 input serial_data_in,
79 output serial_data_out,
80
81 // User-facing signals
82 input user_gpio_out, // User space to pad
Tim Edwards44bab472020-10-04 22:09:54 -040083 input user_gpio_oeb, // Output enable (user)
Tim Edwards04ba17f2020-10-02 22:27:50 -040084 output user_gpio_in, // Pad to user space
85
86 // Pad-facing signals (Pad GPIOv2)
87 output pad_gpio_holdover,
88 output pad_gpio_slow_sel,
89 output pad_gpio_vtrip_sel,
90 output pad_gpio_inenb,
91 output pad_gpio_ib_mode_sel,
92 output pad_gpio_ana_en,
93 output pad_gpio_ana_sel,
94 output pad_gpio_ana_pol,
95 output [2:0] pad_gpio_dm,
Tim Edwards251e0df2020-10-05 11:02:12 -040096 output pad_gpio_outenb,
Tim Edwards04ba17f2020-10-02 22:27:50 -040097 output pad_gpio_out,
98 input pad_gpio_in
99);
100
101 /* Parameters defining the bit offset of each function in the chain */
102 localparam MGMT_EN = 0;
103 localparam OEB = 1;
104 localparam HLDH = 2;
Tim Edwards251e0df2020-10-05 11:02:12 -0400105 localparam INP_DIS = 3;
Tim Edwards44bab472020-10-04 22:09:54 -0400106 localparam MOD_SEL = 4;
107 localparam AN_EN = 5;
108 localparam AN_SEL = 6;
109 localparam AN_POL = 7;
110 localparam SLOW = 8;
111 localparam TRIP = 9;
112 localparam DM = 10;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400113
114 /* Internally registered signals */
115 reg mgmt_ena; // Enable management SoC to access pad
116 reg gpio_holdover;
117 reg gpio_slow_sel;
118 reg gpio_vtrip_sel;
119 reg gpio_inenb;
120 reg gpio_ib_mode_sel;
121 reg gpio_outenb;
122 reg [2:0] gpio_dm;
123 reg gpio_ana_en;
124 reg gpio_ana_sel;
125 reg gpio_ana_pol;
126
127 /* Derived output values */
128 wire pad_gpio_holdover;
129 wire pad_gpio_slow_sel;
130 wire pad_gpio_vtrip_sel;
131 wire pad_gpio_inenb;
132 wire pad_gpio_ib_mode_sel;
133 wire pad_gpio_ana_en;
134 wire pad_gpio_ana_sel;
135 wire pad_gpio_ana_pol;
136 wire [2:0] pad_gpio_dm;
137 wire pad_gpio_outenb;
138 wire pad_gpio_out;
139 wire pad_gpio_in;
140
Tim Edwards53d92182020-10-11 21:47:40 -0400141 wire user_gpio_in;
142 wire gpio_in_unbuf;
Tim Edwards581068f2020-11-19 12:45:25 -0500143 wire gpio_logic1;
Tim Edwards53d92182020-10-11 21:47:40 -0400144
Tim Edwards04ba17f2020-10-02 22:27:50 -0400145 /* Serial shift for the above (latched) values */
146 reg [PAD_CTRL_BITS-1:0] shift_register;
147
148 /* Utilize reset and clock to encode a load operation */
149 wire load_data;
150 wire int_reset;
151
152 /* Create internal reset and load signals from input reset and clock */
153 assign serial_data_out = shift_register[PAD_CTRL_BITS-1];
154 assign int_reset = (~resetn) & (~serial_clock);
155 assign load_data = (~resetn) & serial_clock;
156
157 always @(posedge serial_clock or posedge int_reset) begin
158 if (int_reset == 1'b1) begin
159 /* Clear shift register */
160 shift_register <= 'd0;
161 end else begin
162 /* Shift data in */
163 shift_register <= {shift_register[PAD_CTRL_BITS-2:0], serial_data_in};
164 end
165 end
166
167 always @(posedge load_data or posedge int_reset) begin
168 if (int_reset == 1'b1) begin
169 /* Initial state on reset: Pad set to management input */
Tim Edwards44bab472020-10-04 22:09:54 -0400170 mgmt_ena <= 1'b1; // Management SoC has control over all I/O
171 gpio_holdover <= HOLD_INIT; // All signals latched in hold mode
172 gpio_slow_sel <= SLOW_INIT; // Fast slew rate
173 gpio_vtrip_sel <= TRIP_INIT; // CMOS mode
174 gpio_ib_mode_sel <= IB_INIT; // CMOS mode
175 gpio_inenb <= IENB_INIT; // Input enabled
Tim Edwards251e0df2020-10-05 11:02:12 -0400176 gpio_outenb <= OENB_INIT; // (unused placeholder)
Tim Edwards44bab472020-10-04 22:09:54 -0400177 gpio_dm <= DM_INIT; // Configured as input only
178 gpio_ana_en <= AENA_INIT; // Digital enabled
179 gpio_ana_sel <= ASEL_INIT; // Don't-care when gpio_ana_en = 0
180 gpio_ana_pol <= APOL_INIT; // Don't-care when gpio_ana_en = 0
Tim Edwards04ba17f2020-10-02 22:27:50 -0400181 end else begin
182 /* Load data */
183 mgmt_ena <= shift_register[MGMT_EN];
184 gpio_outenb <= shift_register[OEB];
185 gpio_holdover <= shift_register[HLDH];
186 gpio_inenb <= shift_register[INP_DIS];
187 gpio_ib_mode_sel <= shift_register[MOD_SEL];
188 gpio_ana_en <= shift_register[AN_EN];
189 gpio_ana_sel <= shift_register[AN_SEL];
190 gpio_ana_pol <= shift_register[AN_POL];
191 gpio_slow_sel <= shift_register[SLOW];
192 gpio_vtrip_sel <= shift_register[TRIP];
193 gpio_dm <= shift_register[DM+2:DM];
194
195 end
196 end
197
198 /* These pad configuration signals are static and do not change */
199 /* after setup. */
200
201 assign pad_gpio_holdover = gpio_holdover;
202 assign pad_gpio_slow_sel = gpio_slow_sel;
203 assign pad_gpio_vtrip_sel = gpio_vtrip_sel;
204 assign pad_gpio_ib_mode_sel = gpio_ib_mode_sel;
205 assign pad_gpio_ana_en = gpio_ana_en;
206 assign pad_gpio_ana_sel = gpio_ana_sel;
207 assign pad_gpio_ana_pol = gpio_ana_pol;
208 assign pad_gpio_dm = gpio_dm;
209 assign pad_gpio_inenb = gpio_inenb;
210
211 /* Implement pad control behavior depending on state of mgmt_ena */
212
Tim Edwards53d92182020-10-11 21:47:40 -0400213 assign gpio_in_unbuf = (mgmt_ena) ? 1'b0 : pad_gpio_in;
Tim Edwards89f09242020-10-05 15:17:34 -0400214 assign mgmt_gpio_in = (mgmt_ena) ? ((gpio_inenb == 1'b0) ?
215 pad_gpio_in : 1'bz) : 1'b0;
216
217 assign pad_gpio_outenb = (mgmt_ena) ? ((mgmt_gpio_oeb == 1'b1) ? gpio_outenb :
218 1'b0) : user_gpio_oeb;
219 assign pad_gpio_out = (mgmt_ena) ?
220 ((mgmt_gpio_oeb == 1'b1) ?
221 ((gpio_dm[2:1] == 2'b01) ? ~gpio_dm[0] : mgmt_gpio_out) :
222 mgmt_gpio_out) :
223 user_gpio_out;
224
Tim Edwards53d92182020-10-11 21:47:40 -0400225 /* Buffer user_gpio_in with an enable that is set by the user domain vccd */
226
227 sky130_fd_sc_hd__conb_1 gpio_logic_high (
Ahmed Ghazy64c17e82020-11-18 20:17:26 +0200228`ifdef USE_POWER_PINS
Tim Edwards53d92182020-10-11 21:47:40 -0400229 .VPWR(vccd1),
230 .VGND(vssd1),
231 .VPB(vccd1),
232 .VNB(vssd1),
Ahmed Ghazy64c17e82020-11-18 20:17:26 +0200233`endif
Tim Edwards53d92182020-10-11 21:47:40 -0400234 .HI(gpio_logic1),
235 .LO()
236 );
237
238 sky130_fd_sc_hd__einvp_8 gpio_in_buf (
Ahmed Ghazy64c17e82020-11-18 20:17:26 +0200239`ifdef USE_POWER_PINS
Tim Edwards53d92182020-10-11 21:47:40 -0400240 .VPWR(vccd),
241 .VGND(vssd),
242 .VPB(vccd),
243 .VNB(vssd),
Ahmed Ghazy64c17e82020-11-18 20:17:26 +0200244`endif
Tim Edwards53d92182020-10-11 21:47:40 -0400245 .Z(user_gpio_in),
246 .A(~gpio_in_unbuf),
247 .TE(gpio_logic1)
248 );
Tim Edwards04ba17f2020-10-02 22:27:50 -0400249
250endmodule
Tim Edwards581068f2020-11-19 12:45:25 -0500251`default_nettype wire