1 | Add some of these features for AVR GPIO: | 1 | Add some of these features for AVR GPIO: |
---|---|---|---|
2 | 2 | ||
3 | - GPIO I/O : PORTx registers | 3 | - GPIO I/O : PORTx registers |
4 | - Data Direction : DDRx registers | 4 | - Data Direction : DDRx registers |
5 | - DDRx toggling : PINx registers | 5 | - DDRx toggling : PINx registers |
6 | 6 | ||
7 | Following things are not supported yet: | 7 | Following things are not supported yet: |
8 | - MCUR registers | 8 | - MCUR registers |
9 | 9 | ||
10 | Signed-off-by: Heecheol Yang <heecheol.yang@outlook.com> | 10 | Signed-off-by: Heecheol Yang <heecheol.yang@outlook.com> |
11 | --- | 11 | --- |
12 | hw/avr/Kconfig | 1 + | 12 | hw/avr/Kconfig | 1 + |
13 | hw/avr/atmega.c | 7 +- | 13 | hw/avr/atmega.c | 7 +- |
14 | hw/avr/atmega.h | 2 + | 14 | hw/avr/atmega.h | 2 + |
15 | hw/gpio/Kconfig | 3 + | 15 | hw/gpio/Kconfig | 3 + |
16 | hw/gpio/avr_gpio.c | 136 +++++++++++++++++++++++++++++++++++++ | 16 | hw/gpio/avr_gpio.c | 136 +++++++++++++++++++++++++++++++++++++ |
17 | hw/gpio/meson.build | 2 + | 17 | hw/gpio/meson.build | 2 + |
18 | include/hw/gpio/avr_gpio.h | 53 +++++++++++++++ | 18 | include/hw/gpio/avr_gpio.h | 53 +++++++++++++++ |
19 | 7 files changed, 202 insertions(+), 2 deletions(-) | 19 | 7 files changed, 202 insertions(+), 2 deletions(-) |
20 | create mode 100644 hw/gpio/avr_gpio.c | 20 | create mode 100644 hw/gpio/avr_gpio.c |
21 | create mode 100644 include/hw/gpio/avr_gpio.h | 21 | create mode 100644 include/hw/gpio/avr_gpio.h |
22 | 22 | ||
23 | diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig | 23 | diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig |
24 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/hw/avr/Kconfig | 25 | --- a/hw/avr/Kconfig |
26 | +++ b/hw/avr/Kconfig | 26 | +++ b/hw/avr/Kconfig |
27 | @@ -XXX,XX +XXX,XX @@ config AVR_ATMEGA_MCU | 27 | @@ -XXX,XX +XXX,XX @@ config AVR_ATMEGA_MCU |
28 | select AVR_TIMER16 | 28 | select AVR_TIMER16 |
29 | select AVR_USART | 29 | select AVR_USART |
30 | select AVR_POWER | 30 | select AVR_POWER |
31 | + select AVR_GPIO | 31 | + select AVR_GPIO |
32 | 32 | ||
33 | config ARDUINO | 33 | config ARDUINO |
34 | select AVR_ATMEGA_MCU | 34 | select AVR_ATMEGA_MCU |
35 | diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c | 35 | diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c |
36 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/hw/avr/atmega.c | 37 | --- a/hw/avr/atmega.c |
38 | +++ b/hw/avr/atmega.c | 38 | +++ b/hw/avr/atmega.c |
39 | @@ -XXX,XX +XXX,XX @@ static void atmega_realize(DeviceState *dev, Error **errp) | 39 | @@ -XXX,XX +XXX,XX @@ static void atmega_realize(DeviceState *dev, Error **errp) |
40 | continue; | 40 | continue; |
41 | } | 41 | } |
42 | devname = g_strdup_printf("atmega-gpio-%c", 'a' + (char)i); | 42 | devname = g_strdup_printf("atmega-gpio-%c", 'a' + (char)i); |
43 | - create_unimplemented_device(devname, | 43 | - create_unimplemented_device(devname, |
44 | - OFFSET_DATA + mc->dev[idx].addr, 3); | 44 | - OFFSET_DATA + mc->dev[idx].addr, 3); |
45 | + object_initialize_child(OBJECT(dev), devname, &s->gpio[i], | 45 | + object_initialize_child(OBJECT(dev), devname, &s->gpio[i], |
46 | + TYPE_AVR_GPIO); | 46 | + TYPE_AVR_GPIO); |
47 | + sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), &error_abort); | 47 | + sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), &error_abort); |
48 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, | 48 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, |
49 | + OFFSET_DATA + mc->dev[idx].addr); | 49 | + OFFSET_DATA + mc->dev[idx].addr); |
50 | g_free(devname); | 50 | g_free(devname); |
51 | } | 51 | } |
52 | 52 | ||
53 | diff --git a/hw/avr/atmega.h b/hw/avr/atmega.h | 53 | diff --git a/hw/avr/atmega.h b/hw/avr/atmega.h |
54 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
55 | --- a/hw/avr/atmega.h | 55 | --- a/hw/avr/atmega.h |
56 | +++ b/hw/avr/atmega.h | 56 | +++ b/hw/avr/atmega.h |
57 | @@ -XXX,XX +XXX,XX @@ | 57 | @@ -XXX,XX +XXX,XX @@ |
58 | 58 | ||
59 | #include "hw/char/avr_usart.h" | 59 | #include "hw/char/avr_usart.h" |
60 | #include "hw/timer/avr_timer16.h" | 60 | #include "hw/timer/avr_timer16.h" |
61 | +#include "hw/gpio/avr_gpio.h" | 61 | +#include "hw/gpio/avr_gpio.h" |
62 | #include "hw/misc/avr_power.h" | 62 | #include "hw/misc/avr_power.h" |
63 | #include "target/avr/cpu.h" | 63 | #include "target/avr/cpu.h" |
64 | #include "qom/object.h" | 64 | #include "qom/object.h" |
65 | @@ -XXX,XX +XXX,XX @@ struct AtmegaMcuState { | 65 | @@ -XXX,XX +XXX,XX @@ struct AtmegaMcuState { |
66 | DeviceState *io; | 66 | DeviceState *io; |
67 | AVRMaskState pwr[POWER_MAX]; | 67 | AVRMaskState pwr[POWER_MAX]; |
68 | AVRUsartState usart[USART_MAX]; | 68 | AVRUsartState usart[USART_MAX]; |
69 | + AVRGPIOState gpio[GPIO_MAX]; | 69 | + AVRGPIOState gpio[GPIO_MAX]; |
70 | AVRTimer16State timer[TIMER_MAX]; | 70 | AVRTimer16State timer[TIMER_MAX]; |
71 | uint64_t xtal_freq_hz; | 71 | uint64_t xtal_freq_hz; |
72 | }; | 72 | }; |
73 | diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig | 73 | diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig |
74 | index XXXXXXX..XXXXXXX 100644 | 74 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/hw/gpio/Kconfig | 75 | --- a/hw/gpio/Kconfig |
76 | +++ b/hw/gpio/Kconfig | 76 | +++ b/hw/gpio/Kconfig |
77 | @@ -XXX,XX +XXX,XX @@ config GPIO_KEY | 77 | @@ -XXX,XX +XXX,XX @@ config GPIO_KEY |
78 | 78 | ||
79 | config SIFIVE_GPIO | 79 | config SIFIVE_GPIO |
80 | bool | 80 | bool |
81 | + | 81 | + |
82 | +config AVR_GPIO | 82 | +config AVR_GPIO |
83 | + bool | 83 | + bool |
84 | diff --git a/hw/gpio/avr_gpio.c b/hw/gpio/avr_gpio.c | 84 | diff --git a/hw/gpio/avr_gpio.c b/hw/gpio/avr_gpio.c |
85 | new file mode 100644 | 85 | new file mode 100644 |
86 | index XXXXXXX..XXXXXXX | 86 | index XXXXXXX..XXXXXXX |
87 | --- /dev/null | 87 | --- /dev/null |
88 | +++ b/hw/gpio/avr_gpio.c | 88 | +++ b/hw/gpio/avr_gpio.c |
89 | @@ -XXX,XX +XXX,XX @@ | 89 | @@ -XXX,XX +XXX,XX @@ |
90 | +/* | 90 | +/* |
91 | + * AVR processors GPIO registers emulation. | 91 | + * AVR processors GPIO registers emulation. |
92 | + * | 92 | + * |
93 | + * Copyright (C) 2020 Heecheol Yang <heecheol.yang@outlook.com> | 93 | + * Copyright (C) 2020 Heecheol Yang <heecheol.yang@outlook.com> |
94 | + * | 94 | + * |
95 | + * This program is free software; you can redistribute it and/or | 95 | + * This program is free software; you can redistribute it and/or |
96 | + * modify it under the terms of the GNU General Public License as | 96 | + * modify it under the terms of the GNU General Public License as |
97 | + * published by the Free Software Foundation; either version 2 or | 97 | + * published by the Free Software Foundation; either version 2 or |
98 | + * (at your option) version 3 of the License. | 98 | + * (at your option) version 3 of the License. |
99 | + * | 99 | + * |
100 | + * This program is distributed in the hope that it will be useful, | 100 | + * This program is distributed in the hope that it will be useful, |
101 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 101 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
102 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 102 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
103 | + * GNU General Public License for more details. | 103 | + * GNU General Public License for more details. |
104 | + * | 104 | + * |
105 | + * You should have received a copy of the GNU General Public License along | 105 | + * You should have received a copy of the GNU General Public License along |
106 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | 106 | + * with this program; if not, see <http://www.gnu.org/licenses/>. |
107 | + */ | 107 | + */ |
108 | +#include "qemu/osdep.h" | 108 | +#include "qemu/osdep.h" |
109 | +#include "qemu/log.h" | 109 | +#include "qemu/log.h" |
110 | +#include "qemu/module.h" | 110 | +#include "qemu/module.h" |
111 | +#include "qemu/osdep.h" | 111 | +#include "qemu/osdep.h" |
112 | +#include "qapi/error.h" | 112 | +#include "qapi/error.h" |
113 | +#include "hw/sysbus.h" | 113 | +#include "hw/sysbus.h" |
114 | +#include "hw/irq.h" | 114 | +#include "hw/irq.h" |
115 | +#include "hw/gpio/avr_gpio.h" | 115 | +#include "hw/gpio/avr_gpio.h" |
116 | +#include "hw/qdev-properties.h" | 116 | +#include "hw/qdev-properties.h" |
117 | + | 117 | + |
118 | +static void avr_gpio_reset(DeviceState *dev) | 118 | +static void avr_gpio_reset(DeviceState *dev) |
119 | +{ | 119 | +{ |
120 | + AVRGPIOState *gpio = AVR_GPIO(dev); | 120 | + AVRGPIOState *gpio = AVR_GPIO(dev); |
121 | + gpio->reg.pin = 0u; | 121 | + gpio->reg.pin = 0u; |
122 | + gpio->reg.ddr = 0u; | 122 | + gpio->reg.ddr = 0u; |
123 | + gpio->reg.port = 0u; | 123 | + gpio->reg.port = 0u; |
124 | +} | 124 | +} |
125 | + | 125 | + |
126 | +static void avr_gpio_write_port(AVRGPIOState *s, uint64_t value) | 126 | +static void avr_gpio_write_port(AVRGPIOState *s, uint64_t value) |
127 | +{ | 127 | +{ |
128 | + uint8_t pin; | 128 | + uint8_t pin; |
129 | + uint8_t cur_port_val = s->reg.port; | 129 | + uint8_t cur_port_val = s->reg.port; |
130 | + uint8_t cur_ddr_val = s->reg.ddr; | 130 | + uint8_t cur_ddr_val = s->reg.ddr; |
131 | + | 131 | + |
132 | + for (pin = 0u; pin < 8u ; pin++) { | 132 | + for (pin = 0u; pin < 8u ; pin++) { |
133 | + uint8_t cur_port_pin_val = cur_port_val & 0x01u; | 133 | + uint8_t cur_port_pin_val = cur_port_val & 0x01u; |
134 | + uint8_t cur_ddr_pin_val = cur_ddr_val & 0x01u; | 134 | + uint8_t cur_ddr_pin_val = cur_ddr_val & 0x01u; |
135 | + uint8_t new_port_pin_val = value & 0x01u; | 135 | + uint8_t new_port_pin_val = value & 0x01u; |
136 | + | 136 | + |
137 | + if (cur_ddr_pin_val && (cur_port_pin_val != new_port_pin_val)) { | 137 | + if (cur_ddr_pin_val && (cur_port_pin_val != new_port_pin_val)) { |
138 | + qemu_set_irq(s->out[pin], new_port_pin_val); | 138 | + qemu_set_irq(s->out[pin], new_port_pin_val); |
139 | + } | 139 | + } |
140 | + cur_port_val >>= 1u; | 140 | + cur_port_val >>= 1u; |
141 | + cur_ddr_val >>= 1u; | 141 | + cur_ddr_val >>= 1u; |
142 | + value >>= 1u; | 142 | + value >>= 1u; |
143 | + } | 143 | + } |
144 | + s->reg.port = value & s->reg.ddr; | 144 | + s->reg.port = value & s->reg.ddr; |
145 | +} | 145 | +} |
146 | +static uint64_t avr_gpio_read(void *opaque, hwaddr offset, unsigned int size) | 146 | +static uint64_t avr_gpio_read(void *opaque, hwaddr offset, unsigned int size) |
147 | +{ | 147 | +{ |
148 | + AVRGPIOState *s = (AVRGPIOState *)opaque; | 148 | + AVRGPIOState *s = (AVRGPIOState *)opaque; |
149 | + switch (offset) { | 149 | + switch (offset) { |
150 | + case GPIO_PIN: | 150 | + case GPIO_PIN: |
151 | + return s->reg.pin; | 151 | + return s->reg.pin; |
152 | + case GPIO_DDR: | 152 | + case GPIO_DDR: |
153 | + return s->reg.ddr; | 153 | + return s->reg.ddr; |
154 | + case GPIO_PORT: | 154 | + case GPIO_PORT: |
155 | + return s->reg.port; | 155 | + return s->reg.port; |
156 | + default: | 156 | + default: |
157 | + g_assert_not_reached(); | 157 | + g_assert_not_reached(); |
158 | + break; | 158 | + break; |
159 | + } | 159 | + } |
160 | + return 0; | 160 | + return 0; |
161 | +} | 161 | +} |
162 | + | 162 | + |
163 | +static void avr_gpio_write(void *opaque, hwaddr offset, uint64_t value, | 163 | +static void avr_gpio_write(void *opaque, hwaddr offset, uint64_t value, |
164 | + unsigned int size) | 164 | + unsigned int size) |
165 | +{ | 165 | +{ |
166 | + AVRGPIOState *s = (AVRGPIOState *)opaque; | 166 | + AVRGPIOState *s = (AVRGPIOState *)opaque; |
167 | + value = value & 0xF; | 167 | + value = value & 0xF; |
168 | + switch (offset) { | 168 | + switch (offset) { |
169 | + case GPIO_PIN: | 169 | + case GPIO_PIN: |
170 | + s->reg.pin = value; | 170 | + s->reg.pin = value; |
171 | + s->reg.port ^= s->reg.pin; | 171 | + s->reg.port ^= s->reg.pin; |
172 | + break; | 172 | + break; |
173 | + case GPIO_DDR: | 173 | + case GPIO_DDR: |
174 | + s->reg.ddr = value; | 174 | + s->reg.ddr = value; |
175 | + break; | 175 | + break; |
176 | + case GPIO_PORT: | 176 | + case GPIO_PORT: |
177 | + avr_gpio_write_port(s, value); | 177 | + avr_gpio_write_port(s, value); |
178 | + break; | 178 | + break; |
179 | + default: | 179 | + default: |
180 | + g_assert_not_reached(); | 180 | + g_assert_not_reached(); |
181 | + break; | 181 | + break; |
182 | + } | 182 | + } |
183 | +} | 183 | +} |
184 | + | 184 | + |
185 | +static const MemoryRegionOps avr_gpio_ops = { | 185 | +static const MemoryRegionOps avr_gpio_ops = { |
186 | + .read = avr_gpio_read, | 186 | + .read = avr_gpio_read, |
187 | + .write = avr_gpio_write, | 187 | + .write = avr_gpio_write, |
188 | + .endianness = DEVICE_NATIVE_ENDIAN, | 188 | + .endianness = DEVICE_NATIVE_ENDIAN, |
189 | +}; | 189 | +}; |
190 | + | 190 | + |
191 | +static void avr_gpio_init(Object *obj) | 191 | +static void avr_gpio_init(Object *obj) |
192 | +{ | 192 | +{ |
193 | + AVRGPIOState *s = AVR_GPIO(obj); | 193 | + AVRGPIOState *s = AVR_GPIO(obj); |
194 | + qdev_init_gpio_out(DEVICE(obj), s->out, ARRAY_SIZE(s->out)); | 194 | + qdev_init_gpio_out(DEVICE(obj), s->out, ARRAY_SIZE(s->out)); |
195 | + memory_region_init_io(&s->mmio, obj, &avr_gpio_ops, s, TYPE_AVR_GPIO, 3); | 195 | + memory_region_init_io(&s->mmio, obj, &avr_gpio_ops, s, TYPE_AVR_GPIO, 3); |
196 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); | 196 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); |
197 | +} | 197 | +} |
198 | +static void avr_gpio_realize(DeviceState *dev, Error **errp) | 198 | +static void avr_gpio_realize(DeviceState *dev, Error **errp) |
199 | +{ | 199 | +{ |
200 | + /* Do nothing currently */ | 200 | + /* Do nothing currently */ |
201 | +} | 201 | +} |
202 | + | 202 | + |
203 | + | 203 | + |
204 | +static void avr_gpio_class_init(ObjectClass *klass, void *data) | 204 | +static void avr_gpio_class_init(ObjectClass *klass, void *data) |
205 | +{ | 205 | +{ |
206 | + DeviceClass *dc = DEVICE_CLASS(klass); | 206 | + DeviceClass *dc = DEVICE_CLASS(klass); |
207 | + | 207 | + |
208 | + dc->reset = avr_gpio_reset; | 208 | + dc->reset = avr_gpio_reset; |
209 | + dc->realize = avr_gpio_realize; | 209 | + dc->realize = avr_gpio_realize; |
210 | +} | 210 | +} |
211 | + | 211 | + |
212 | +static const TypeInfo avr_gpio_info = { | 212 | +static const TypeInfo avr_gpio_info = { |
213 | + .name = TYPE_AVR_GPIO, | 213 | + .name = TYPE_AVR_GPIO, |
214 | + .parent = TYPE_SYS_BUS_DEVICE, | 214 | + .parent = TYPE_SYS_BUS_DEVICE, |
215 | + .instance_size = sizeof(AVRGPIOState), | 215 | + .instance_size = sizeof(AVRGPIOState), |
216 | + .instance_init = avr_gpio_init, | 216 | + .instance_init = avr_gpio_init, |
217 | + .class_init = avr_gpio_class_init, | 217 | + .class_init = avr_gpio_class_init, |
218 | +}; | 218 | +}; |
219 | + | 219 | + |
220 | +static void avr_gpio_register_types(void) | 220 | +static void avr_gpio_register_types(void) |
221 | +{ | 221 | +{ |
222 | + type_register_static(&avr_gpio_info); | 222 | + type_register_static(&avr_gpio_info); |
223 | +} | 223 | +} |
224 | + | 224 | + |
225 | +type_init(avr_gpio_register_types) | 225 | +type_init(avr_gpio_register_types) |
226 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build | 226 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build |
227 | index XXXXXXX..XXXXXXX 100644 | 227 | index XXXXXXX..XXXXXXX 100644 |
228 | --- a/hw/gpio/meson.build | 228 | --- a/hw/gpio/meson.build |
229 | +++ b/hw/gpio/meson.build | 229 | +++ b/hw/gpio/meson.build |
230 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) | 230 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) |
231 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) | 231 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) |
232 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) | 232 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) |
233 | softmmu_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) | 233 | softmmu_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) |
234 | + | 234 | + |
235 | +softmmu_ss.add(when: 'CONFIG_AVR_GPIO', if_true: files('avr_gpio.c')) | 235 | +softmmu_ss.add(when: 'CONFIG_AVR_GPIO', if_true: files('avr_gpio.c')) |
236 | diff --git a/include/hw/gpio/avr_gpio.h b/include/hw/gpio/avr_gpio.h | 236 | diff --git a/include/hw/gpio/avr_gpio.h b/include/hw/gpio/avr_gpio.h |
237 | new file mode 100644 | 237 | new file mode 100644 |
238 | index XXXXXXX..XXXXXXX | 238 | index XXXXXXX..XXXXXXX |
239 | --- /dev/null | 239 | --- /dev/null |
240 | +++ b/include/hw/gpio/avr_gpio.h | 240 | +++ b/include/hw/gpio/avr_gpio.h |
241 | @@ -XXX,XX +XXX,XX @@ | 241 | @@ -XXX,XX +XXX,XX @@ |
242 | +/* | 242 | +/* |
243 | + * AVR processors GPIO registers definition. | 243 | + * AVR processors GPIO registers definition. |
244 | + * | 244 | + * |
245 | + * Copyright (C) 2020 Heecheol Yang <heecheol.yang@outlook.com> | 245 | + * Copyright (C) 2020 Heecheol Yang <heecheol.yang@outlook.com> |
246 | + * | 246 | + * |
247 | + * This program is free software; you can redistribute it and/or | 247 | + * This program is free software; you can redistribute it and/or |
248 | + * modify it under the terms of the GNU General Public License as | 248 | + * modify it under the terms of the GNU General Public License as |
249 | + * published by the Free Software Foundation; either version 2 or | 249 | + * published by the Free Software Foundation; either version 2 or |
250 | + * (at your option) version 3 of the License. | 250 | + * (at your option) version 3 of the License. |
251 | + * | 251 | + * |
252 | + * This program is distributed in the hope that it will be useful, | 252 | + * This program is distributed in the hope that it will be useful, |
253 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 253 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
254 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 254 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
255 | + * GNU General Public License for more details. | 255 | + * GNU General Public License for more details. |
256 | + * | 256 | + * |
257 | + * You should have received a copy of the GNU General Public License along | 257 | + * You should have received a copy of the GNU General Public License along |
258 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | 258 | + * with this program; if not, see <http://www.gnu.org/licenses/>. |
259 | + */ | 259 | + */ |
260 | + | 260 | + |
261 | +#ifndef AVR_GPIO_H | 261 | +#ifndef AVR_GPIO_H |
262 | +#define AVR_GPIO_H | 262 | +#define AVR_GPIO_H |
263 | + | 263 | + |
264 | +#include "hw/sysbus.h" | 264 | +#include "hw/sysbus.h" |
265 | +#include "qom/object.h" | 265 | +#include "qom/object.h" |
266 | + | 266 | + |
267 | +/* Offsets of registers. */ | 267 | +/* Offsets of registers. */ |
268 | +#define GPIO_PIN 0x00 | 268 | +#define GPIO_PIN 0x00 |
269 | +#define GPIO_DDR 0x01 | 269 | +#define GPIO_DDR 0x01 |
270 | +#define GPIO_PORT 0x02 | 270 | +#define GPIO_PORT 0x02 |
271 | + | 271 | + |
272 | +#define TYPE_AVR_GPIO "avr-gpio" | 272 | +#define TYPE_AVR_GPIO "avr-gpio" |
273 | +OBJECT_DECLARE_SIMPLE_TYPE(AVRGPIOState, AVR_GPIO) | 273 | +OBJECT_DECLARE_SIMPLE_TYPE(AVRGPIOState, AVR_GPIO) |
274 | +#define AVR_GPIO_COUNT 8 | 274 | +#define AVR_GPIO_COUNT 8 |
275 | + | 275 | + |
276 | +struct AVRGPIOState { | 276 | +struct AVRGPIOState { |
277 | + /*< private >*/ | 277 | + /*< private >*/ |
278 | + SysBusDevice parent_obj; | 278 | + SysBusDevice parent_obj; |
279 | + | 279 | + |
280 | + /*< public >*/ | 280 | + /*< public >*/ |
281 | + MemoryRegion mmio; | 281 | + MemoryRegion mmio; |
282 | + | 282 | + |
283 | + struct { | 283 | + struct { |
284 | + uint8_t pin; | 284 | + uint8_t pin; |
285 | + uint8_t ddr; | 285 | + uint8_t ddr; |
286 | + uint8_t port; | 286 | + uint8_t port; |
287 | + } reg; | 287 | + } reg; |
288 | + | 288 | + |
289 | + /* PORTx data changed IRQs */ | 289 | + /* PORTx data changed IRQs */ |
290 | + qemu_irq out[8u]; | 290 | + qemu_irq out[8u]; |
291 | + | 291 | + |
292 | +}; | 292 | +}; |
293 | + | 293 | + |
294 | +#endif /* AVR_GPIO_H */ | 294 | +#endif /* AVR_GPIO_H */ |
295 | -- | 295 | -- |
296 | 2.17.1 | 296 | 2.17.1 |
297 | 297 | ||
298 | 298 | diff view generated by jsdifflib |