-
Notifications
You must be signed in to change notification settings - Fork 19
/
gpio.txt
175 lines (173 loc) · 5.32 KB
/
gpio.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
################################################################################
##
## Filename: gpio.txt
## {{{
## Project: AutoFPGA, a utility for composing FPGA designs from peripherals
##
## Purpose:
##
## Creator: Dan Gisselquist, Ph.D.
## Gisselquist Technology, LLC
##
################################################################################
## }}}
## Copyright (C) 2017-2024, Gisselquist Technology, LLC
## {{{
## This program is free software (firmware): you can redistribute it and/or
## modify it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program. (It's in the $(ROOT)/doc directory. Run make with no
## target there if the PDF file isn't present.) If not, see
## <http://www.gnu.org/licenses/> for a copy.
## }}}
## License: GPL, v3, as defined and found on www.gnu.org,
## {{{
## http://www.gnu.org/licenses/gpl.html
##
################################################################################
##
## }}}
@PREFIX=gpio
@DEVID=GPIO
@NADDR=1
@ACCESS=@$(DEVID)_ACCESS
@NGPI=16
@NGPO=16
@SLAVE.TYPE=SINGLE
@SLAVE.BUS=wb
# @SINGLE.OUTPUTS= o_gpio
# @SINGLE.INPUTS= i_gpio
@INT.GPIO.WIRE=gpio_int
@INT.GPIO.PIC=altpic
@TOP.PORTLIST=
// @$(DEVID) ports
io_hdmi_in_cec,
o_hdmi_in_hpa, // Hotplug assert
o_hdmi_in_txen,
io_hdmi_out_cec,
i_hdmi_out_hpd_n, // Hotplug detect
o_sd_reset,
i_gps_3df
@TOP.IODECL=
// GPIO wires
inout wire io_hdmi_in_cec;
output wire o_hdmi_in_hpa;
output wire o_hdmi_in_txen;
inout wire io_hdmi_out_cec;
input wire i_hdmi_out_hpd_n;
output wire o_sd_reset;
input wire i_gps_3df;
@TOP.DEFNS=
// GPIO declarations. The two wire busses are just virtual lists of
// input (or output) ports.
wire [@$(NGPI)-1:0] i_@$(PREFIX);
wire [@$(NGPO)-1:0] o_@$(PREFIX);
wire w_hdmi_out_en;
wire w_hdmi_bypass_sda;
wire w_hdmi_bypass_scl;
@TOP.MAIN=
// GPIO wires
i_@$(PREFIX), o_@$(PREFIX)
@TOP.INSERT=
////////////////////////////////////////////////////////////////////////
//
// GPIO adjustments
// {{{
assign i_gpio = { 10'h0,
w_hdmi_in_pll_locked,
sysclk_locked, i_gps_3df,
!i_hdmi_out_hpd_n, !i_sd_cd_n,
io_hdmi_out_cec, io_hdmi_in_cec };
assign io_hdmi_in_cec = o_gpio[0] ? 1'bz : 1'b0;
assign io_hdmi_out_cec = o_gpio[1] ? 1'bz : 1'b0;
assign w_hdmi_bypass_scl=o_gpio[2];
assign w_hdmi_bypass_sda=o_gpio[3];
assign o_hdmi_in_txen = o_gpio[4];
assign o_hdmi_in_hpa = o_gpio[5]; // Hotplug assert
assign o_sd_reset = o_gpio[6];
assign w_hdmi_out_en = o_gpio[7];
// }}}
@MAIN.PORTLIST=
// GPIO ports
i_@$(PREFIX), o_@$(PREFIX)
@MAIN.IODECL=
localparam NGPI = @$(NGPI), NGPO=@$(NGPO);
// @$(DEVID) ports
input wire [(NGPI-1):0] i_@$(PREFIX);
output wire [(NGPO-1):0] o_@$(PREFIX);
@MAIN.DEFNS=
wire sd_reset;
@MAIN.INSERT=
////////////////////////////////////////////////////////////////////////
//
// @$(DEVID)
// {{{
// This interface should allow us to control up to 16 @$(DEVID) inputs, and
// another 16 @$(DEVID) outputs. The interrupt trips when any of the inputs
// changes. (Sorry, which input isn't (yet) selectable.)
//
wbgpio #(
.NIN(NGPI), .NOUT(NGPO), .DEFAULT(INITIAL_@$(DEVID))
) @$(PREFIX)i(
// {{{
i_clk, @$(SLAVE.PORTLIST),
i_@$(PREFIX), o_@$(PREFIX), @$(PREFIX)_int
// }}}
);
// }}}
@REGS.N=1
@REGS.0= 0 R_@$(DEVID) @$(DEVID) GPI GPO
@BDEF.DEFN=
//
// @$(DEVID) input wires
//
#define GPIO_HDMI_IN_CEC 0x000010000
#define GPIO_HDMI_OUT_CEC 0x000020000
#define GPIO_SD_DETECTED 0x000040000
#define GPIO_HDMI_OUT_DETECT 0x000080000
#define GPIO_GPS_3DF 0x000100000
#define GPIO_SYSCLK_LOCKED 0x000200000
//
// @$(DEVID) output wires
//
#define @$(DEVID)_SET(WIRE) (((WIRE)<<16)|(WIRE))
#define @$(DEVID)_CLR(WIRE) ((WIRE)<<16)
//
#define GPIO_HDMI_IN_CEC_SET 0x000010001
#define GPIO_HDMI_IN_CEC_CLR 0x000010000
#define GPIO_HDMI_OUT_CEC_SET 0x000020002
#define GPIO_HDMI_OUT_CEC_CLR 0x000020000
#define GPIO_EDID_SCL 0x000000004
#define GPIO_EDID_SDA 0x000000008
//
#define GPIO_HDMI_IN_ENB 0x000000010
#define GPIO_HDMI_IN_HPA 0x000000020
#define GPIO_SD_RESET 0x000000040
#define GPIO_HDMI_OUT_EN 0x000000080
//
#define GPIO_EDID_SCL_SET GPIO_SET(GPIO_EDID_SCL)
#define GPIO_EDID_SCL_CLR GPIO_CLR(GPIO_EDID_SCL)
#define GPIO_EDID_SDA_SET GPIO_SET(GPIO_EDID_SDA)
#define GPIO_EDID_SDA_CLR GPIO_CLR(GPIO_EDID_SDA)
#define GPIO_HDMI_IN_ENB_SET GPIO_SET(GPIO_HDMI_IN_ENB)
#define GPIO_HDMI_IN_ENB_CLR GPIO_CLR(GPIO_HDMI_IN_ENB)
#define GPIO_HDMI_IN_HPA_SET GPIO_SET(GPIO_HDMI_IN_HPA)
#define GPIO_HDMI_IN_HPA_CLR GPIO_CLR(GPIO_HDMI_IN_HPA)
#define GPIO_SD_RESET_SET GPIO_SET(GPIO_SD_RESET)
#define GPIO_SD_RESET_CLR GPIO_CLR(GPIO_SD_RESET)
#define GPIO_HDMI_OUT_EN_SET GPIO_SET(GPIO_HDMI_OUT_EN)
#define GPIO_HDMI_OUT_EN_CLR GPIO_CLR(GPIO_HDMI_OUT_EN)
@BDEF.IONAME= i_@$(PREFIX)
@BDEF.IOTYPE= unsigned
@BDEF.OSDEF= _BOARD_HAS_@$(DEVID)
@BDEF.OSVAL= static volatile @$(BDEF.IOTYPE) *const @$(BDEF.IONAME) = ((@$(BDEF.IOTYPE) *)@$[0x%08x](REGBASE));
@RTL.MAKE.FILES=wbgpio.v
@RTL.MAKE.GROUP=@$(DEVID)