1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <soc/aml-a113/a113-gpio.h>
6 
7 static aml_gpio_block_t a113_gpio_blocks[] = {
8     // GPIO X Block
9     {
10         .start_pin = (A113_GPIOX_START + 0),
11         .pin_block = A113_GPIOX_START,
12         .pin_count = 8,
13         .mux_offset = A113_PERIPHS_PIN_MUX_4,
14         .oen_offset = A113_GPIO_REG2_EN_N,
15         .input_offset = A113_GPIO_REG2_I,
16         .output_offset = A113_GPIO_REG2_O,
17         .output_shift = 0,
18         .pull_offset = A113_GPIO_PULL_UP_REG2,
19         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG2,
20         .mmio_index = 0,
21         .pin_start = A113_GPIOX_PIN_START,
22         .lock = MTX_INIT,
23     },
24     {
25         .start_pin = (A113_GPIOX_START + 8),
26         .pin_block = A113_GPIOX_START,
27         .pin_count = 8,
28         .mux_offset = A113_PERIPHS_PIN_MUX_5,
29         .oen_offset = A113_GPIO_REG2_EN_N,
30         .input_offset = A113_GPIO_REG2_I,
31         .output_offset = A113_GPIO_REG2_O,
32         .output_shift = 0,
33         .pull_offset = A113_GPIO_PULL_UP_REG2,
34         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG2,
35         .mmio_index = 0,
36         .pin_start = A113_GPIOX_PIN_START,
37         .lock = MTX_INIT,
38     },
39     {
40         .start_pin = (A113_GPIOX_START + 16),
41         .pin_block = A113_GPIOX_START,
42         .pin_count = 7,
43         .mux_offset = A113_PERIPHS_PIN_MUX_6,
44         .oen_offset = A113_GPIO_REG2_EN_N,
45         .input_offset = A113_GPIO_REG2_I,
46         .output_offset = A113_GPIO_REG2_O,
47         .output_shift = 0,
48         .pull_offset = A113_GPIO_PULL_UP_REG2,
49         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG2,
50         .mmio_index = 0,
51         .pin_start = A113_GPIOX_PIN_START,
52         .lock = MTX_INIT,
53     },
54 
55     // GPIO A Block
56     {
57         .start_pin = (A113_GPIOA_START + 0),
58         .pin_block = A113_GPIOA_START,
59         .pin_count = 8,
60         .mux_offset = A113_PERIPHS_PIN_MUX_B,
61         .oen_offset = A113_GPIO_REG0_EN_N,
62         .input_offset = A113_GPIO_REG0_I,
63         .output_offset = A113_GPIO_REG0_O,
64         .output_shift = 0,
65         .pull_offset = A113_GPIO_PULL_UP_REG0,
66         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG0,
67         .mmio_index = 0,
68         .pin_start = A113_GPIOA_PIN_START,
69         .lock = MTX_INIT,
70     },
71     {
72         .start_pin = (A113_GPIOA_START + 8),
73         .pin_block = A113_GPIOA_START,
74         .pin_count = 8,
75         .mux_offset = A113_PERIPHS_PIN_MUX_C,
76         .oen_offset = A113_GPIO_REG0_EN_N,
77         .input_offset = A113_GPIO_REG0_I,
78         .output_offset = A113_GPIO_REG0_O,
79         .output_shift = 0,
80         .pull_offset = A113_GPIO_PULL_UP_REG0,
81         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG0,
82         .mmio_index = 0,
83         .pin_start = A113_GPIOA_PIN_START,
84         .lock = MTX_INIT,
85     },
86     {
87         .start_pin = (A113_GPIOA_START + 16),
88         .pin_block = A113_GPIOA_START,
89         .pin_count = 5,
90         .mux_offset = A113_PERIPHS_PIN_MUX_D,
91         .oen_offset = A113_GPIO_REG0_EN_N,
92         .input_offset = A113_GPIO_REG0_I,
93         .output_offset = A113_GPIO_REG0_O,
94         .output_shift = 0,
95         .pull_offset = A113_GPIO_PULL_UP_REG0,
96         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG0,
97         .mmio_index = 0,
98         .pin_start = A113_GPIOA_PIN_START,
99         .lock = MTX_INIT,
100     },
101 
102     // GPIO Boot Block
103     {
104         .start_pin = (A113_GPIOBOOT_START + 0),
105         .pin_block = A113_GPIOBOOT_START,
106         .pin_count = 8,
107         .mux_offset = A113_PERIPHS_PIN_MUX_0,
108         .oen_offset = A113_GPIO_REG4_EN_N,
109         .input_offset = A113_GPIO_REG4_I,
110         .output_offset = A113_GPIO_REG4_O,
111         .output_shift = 0,
112         .pull_offset = A113_GPIO_PULL_UP_REG4,
113         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG4,
114         .mmio_index = 0,
115         .pin_start = A113_GPIOBOOT_PIN_START,
116         .lock = MTX_INIT,
117     },
118     {
119         .start_pin = (A113_GPIOBOOT_START + 8),
120         .pin_block = A113_GPIOBOOT_START,
121         .pin_count = 7,
122         .mux_offset = A113_PERIPHS_PIN_MUX_1,
123         .oen_offset = A113_GPIO_REG4_EN_N,
124         .input_offset = A113_GPIO_REG4_I,
125         .output_offset = A113_GPIO_REG4_O,
126         .output_shift = 0,
127         .pull_offset = A113_GPIO_PULL_UP_REG4,
128         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG4,
129         .mmio_index = 0,
130         .pin_start = A113_GPIOBOOT_PIN_START,
131         .lock = MTX_INIT,
132     },
133 
134     // GPIO Y Block
135     {
136         .start_pin = (A113_GPIOY_START + 0),
137         .pin_block = A113_GPIOY_START,
138         .pin_count = 8,
139         .mux_offset = A113_PERIPHS_PIN_MUX_8,
140         .oen_offset = A113_GPIO_REG1_EN_N,
141         .input_offset = A113_GPIO_REG1_I,
142         .output_offset = A113_GPIO_REG1_O,
143         .output_shift = 0,
144         .pull_offset = A113_GPIO_PULL_UP_REG1,
145         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG1,
146         .mmio_index = 0,
147         .pin_start = A113_GPIOY_PIN_START,
148         .lock = MTX_INIT,
149     },
150     {
151         .start_pin = (A113_GPIOY_START + 8),
152         .pin_block = A113_GPIOY_START,
153         .pin_count = 8,
154         .mux_offset = A113_PERIPHS_PIN_MUX_9,
155         .oen_offset = A113_GPIO_REG1_EN_N,
156         .input_offset = A113_GPIO_REG1_I,
157         .output_offset = A113_GPIO_REG1_O,
158         .output_shift = 0,
159         .pull_offset = A113_GPIO_PULL_UP_REG1,
160         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG1,
161         .mmio_index = 0,
162         .pin_start = A113_GPIOY_PIN_START,
163         .lock = MTX_INIT,
164     },
165 
166     // GPIO Z Block
167     {
168         .start_pin = (A113_GPIOZ_START + 0),
169         .pin_block = A113_GPIOZ_START,
170         .pin_count = 8,
171         .mux_offset = A113_PERIPHS_PIN_MUX_2,
172         .oen_offset = A113_GPIO_REG3_EN_N,
173         .input_offset = A113_GPIO_REG3_I,
174         .output_offset = A113_GPIO_REG3_O,
175         .output_shift = 0,
176         .pull_offset = A113_GPIO_PULL_UP_REG3,
177         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG3,
178         .mmio_index = 0,
179         .pin_start = A113_GPIOZ_PIN_START,
180         .lock = MTX_INIT,
181     },
182     {
183         .start_pin = (A113_GPIOZ_START + 8),
184         .pin_block = A113_GPIOZ_START,
185         .pin_count = 3,
186         .mux_offset = A113_PERIPHS_PIN_MUX_3,
187         .oen_offset = A113_GPIO_REG3_EN_N,
188         .input_offset = A113_GPIO_REG3_I,
189         .output_offset = A113_GPIO_REG3_O,
190         .output_shift = 0,
191         .pull_offset = A113_GPIO_PULL_UP_REG3,
192         .pull_en_offset = A113_GPIO_PULL_UP_EN_REG3,
193         .mmio_index = 0,
194         .pin_start = A113_GPIOZ_PIN_START,
195         .lock = MTX_INIT,
196     },
197 
198     // GPIO AO Block
199     // NOTE: The GPIO AO block has a separate control block than the other
200     //       GPIO blocks.
201     {
202         .start_pin = (A113_GPIOAO_START + 0),
203         .pin_block = A113_GPIOAO_START,
204         .pin_count = 8,
205         .mux_offset = A113_AO_RTI_PIN_MUX_REG0,
206         .oen_offset = A113_AO_GPIO_O_EN,
207         .input_offset = A113_AO_GPIO_I,
208         .output_offset = A113_AO_GPIO_O_EN,
209         .output_shift = 16,
210         .pull_offset = A113_GPIO_AO_RTI_PULL_UP,
211         .pull_en_offset = A113_GPIO_AO_RTI_PULL_UP,
212         .mmio_index = 1,
213         .pin_start = A113_GPIOA0_PIN_START,
214         .lock = MTX_INIT,
215     },
216     {
217         .start_pin = (A113_GPIOAO_START + 8),
218         .pin_block = A113_GPIOAO_START,
219         .pin_count = 6,
220         .mux_offset = A113_AO_RTI_PIN_MUX_REG1,
221         .oen_offset = A113_AO_GPIO_O_EN,
222         .input_offset = A113_AO_GPIO_I,
223         .output_offset = A113_AO_GPIO_O_EN,
224         .output_shift = 16,
225         .pull_offset = A113_GPIO_AO_RTI_PULL_UP,
226         .pull_en_offset = A113_GPIO_AO_RTI_PULL_UP,
227         .mmio_index = 1,
228         .pin_start = A113_GPIOA0_PIN_START,
229         .lock = MTX_INIT,
230     },
231 };
232 
233 static aml_gpio_interrupt_t a113_interrupt_block = {
234     .pin_0_3_select_offset = A113_GPIO_0_3_PIN_SELECT,
235     .pin_4_7_select_offset = A113_GPIO_4_7_PIN_SELECT,
236     .edge_polarity_offset = A113_GPIO_INT_EDGE_POLARITY,
237     .filter_select_offset = A113_GPIO_FILTER_SELECT,
238 };
239