2 * GPIO device simulation in PKUnity SoC
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or any later version.
9 * See the COPYING file in the top-level directory.
12 #include "hw/sysbus.h"
27 static uint64_t puv3_gpio_read(void *opaque
, hwaddr offset
,
30 PUV3GPIOState
*s
= opaque
;
44 DPRINTF("Bad offset 0x%x\n", offset
);
46 DPRINTF("offset 0x%x, value 0x%x\n", offset
, ret
);
51 static void puv3_gpio_write(void *opaque
, hwaddr offset
,
52 uint64_t value
, unsigned size
)
54 PUV3GPIOState
*s
= opaque
;
56 DPRINTF("offset 0x%x, value 0x%x\n", offset
, value
);
62 if (s
->reg_GPDR
& value
) {
65 DPRINTF("Write gpio input port error!");
69 if (s
->reg_GPDR
& value
) {
70 s
->reg_GPLR
&= ~value
;
72 DPRINTF("Write gpio input port error!");
83 DPRINTF("Bad offset 0x%x\n", offset
);
87 static const MemoryRegionOps puv3_gpio_ops
= {
88 .read
= puv3_gpio_read
,
89 .write
= puv3_gpio_write
,
94 .endianness
= DEVICE_NATIVE_ENDIAN
,
97 static int puv3_gpio_init(SysBusDevice
*dev
)
99 PUV3GPIOState
*s
= FROM_SYSBUS(PUV3GPIOState
, dev
);
104 /* FIXME: these irqs not handled yet */
105 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW0
]);
106 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW1
]);
107 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW2
]);
108 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW3
]);
109 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW4
]);
110 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW5
]);
111 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW6
]);
112 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOLOW7
]);
113 sysbus_init_irq(dev
, &s
->irq
[PUV3_IRQS_GPIOHIGH
]);
115 memory_region_init_io(&s
->iomem
, &puv3_gpio_ops
, s
, "puv3_gpio",
117 sysbus_init_mmio(dev
, &s
->iomem
);
122 static void puv3_gpio_class_init(ObjectClass
*klass
, void *data
)
124 SysBusDeviceClass
*sdc
= SYS_BUS_DEVICE_CLASS(klass
);
126 sdc
->init
= puv3_gpio_init
;
129 static const TypeInfo puv3_gpio_info
= {
131 .parent
= TYPE_SYS_BUS_DEVICE
,
132 .instance_size
= sizeof(PUV3GPIOState
),
133 .class_init
= puv3_gpio_class_init
,
136 static void puv3_gpio_register_type(void)
138 type_register_static(&puv3_gpio_info
);
141 type_init(puv3_gpio_register_type
)