2007-04-30 03:26:42 +02:00
|
|
|
/*
|
|
|
|
* Intel XScale PXA255/270 GPIO controller emulation.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Openedhand Ltd.
|
|
|
|
* Written by Andrzej Zaborowski <balrog@zabor.org>
|
|
|
|
*
|
|
|
|
* This code is licensed under the GPL.
|
|
|
|
*/
|
|
|
|
|
2015-12-07 17:23:45 +01:00
|
|
|
#include "qemu/osdep.h"
|
2016-03-15 16:58:45 +01:00
|
|
|
#include "cpu.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/arm/pxa.h"
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
#include "qapi/error.h"
|
2015-12-15 13:16:16 +01:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2007-04-30 03:26:42 +02:00
|
|
|
|
|
|
|
#define PXA2XX_GPIO_BANKS 4
|
|
|
|
|
2013-07-24 02:03:39 +02:00
|
|
|
#define TYPE_PXA2XX_GPIO "pxa2xx-gpio"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(PXA2xxGPIOInfo, PXA2XX_GPIO)
|
2013-07-24 02:03:39 +02:00
|
|
|
|
2009-05-10 02:44:56 +02:00
|
|
|
struct PXA2xxGPIOInfo {
|
2013-07-24 02:03:39 +02:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2011-10-30 14:50:11 +01:00
|
|
|
MemoryRegion iomem;
|
2011-01-21 17:57:50 +01:00
|
|
|
qemu_irq irq0, irq1, irqX;
|
2007-04-30 03:26:42 +02:00
|
|
|
int lines;
|
2011-01-21 17:57:50 +01:00
|
|
|
int ncpu;
|
2012-05-04 00:23:14 +02:00
|
|
|
ARMCPU *cpu;
|
2007-04-30 03:26:42 +02:00
|
|
|
|
|
|
|
/* XXX: GNU C vectors are more suitable */
|
|
|
|
uint32_t ilevel[PXA2XX_GPIO_BANKS];
|
|
|
|
uint32_t olevel[PXA2XX_GPIO_BANKS];
|
|
|
|
uint32_t dir[PXA2XX_GPIO_BANKS];
|
|
|
|
uint32_t rising[PXA2XX_GPIO_BANKS];
|
|
|
|
uint32_t falling[PXA2XX_GPIO_BANKS];
|
|
|
|
uint32_t status[PXA2XX_GPIO_BANKS];
|
|
|
|
uint32_t gafr[PXA2XX_GPIO_BANKS * 2];
|
|
|
|
|
|
|
|
uint32_t prev_level[PXA2XX_GPIO_BANKS];
|
2007-11-17 15:07:13 +01:00
|
|
|
qemu_irq handler[PXA2XX_GPIO_BANKS * 32];
|
|
|
|
qemu_irq read_notify;
|
2007-04-30 03:26:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
enum {
|
|
|
|
GPIO_NONE,
|
|
|
|
GPLR,
|
|
|
|
GPSR,
|
|
|
|
GPCR,
|
|
|
|
GPDR,
|
|
|
|
GRER,
|
|
|
|
GFER,
|
|
|
|
GEDR,
|
|
|
|
GAFR_L,
|
|
|
|
GAFR_U,
|
|
|
|
} reg;
|
|
|
|
int bank;
|
|
|
|
} pxa2xx_gpio_regs[0x200] = {
|
|
|
|
[0 ... 0x1ff] = { GPIO_NONE, 0 },
|
|
|
|
#define PXA2XX_REG(reg, a0, a1, a2, a3) \
|
2007-09-16 23:08:06 +02:00
|
|
|
[a0] = { reg, 0 }, [a1] = { reg, 1 }, [a2] = { reg, 2 }, [a3] = { reg, 3 },
|
2007-04-30 03:26:42 +02:00
|
|
|
|
|
|
|
PXA2XX_REG(GPLR, 0x000, 0x004, 0x008, 0x100)
|
|
|
|
PXA2XX_REG(GPSR, 0x018, 0x01c, 0x020, 0x118)
|
|
|
|
PXA2XX_REG(GPCR, 0x024, 0x028, 0x02c, 0x124)
|
|
|
|
PXA2XX_REG(GPDR, 0x00c, 0x010, 0x014, 0x10c)
|
|
|
|
PXA2XX_REG(GRER, 0x030, 0x034, 0x038, 0x130)
|
|
|
|
PXA2XX_REG(GFER, 0x03c, 0x040, 0x044, 0x13c)
|
|
|
|
PXA2XX_REG(GEDR, 0x048, 0x04c, 0x050, 0x148)
|
|
|
|
PXA2XX_REG(GAFR_L, 0x054, 0x05c, 0x064, 0x06c)
|
|
|
|
PXA2XX_REG(GAFR_U, 0x058, 0x060, 0x068, 0x070)
|
|
|
|
};
|
|
|
|
|
2009-05-10 02:44:56 +02:00
|
|
|
static void pxa2xx_gpio_irq_update(PXA2xxGPIOInfo *s)
|
2007-04-30 03:26:42 +02:00
|
|
|
{
|
|
|
|
if (s->status[0] & (1 << 0))
|
2011-01-21 17:57:50 +01:00
|
|
|
qemu_irq_raise(s->irq0);
|
2007-04-30 03:26:42 +02:00
|
|
|
else
|
2011-01-21 17:57:50 +01:00
|
|
|
qemu_irq_lower(s->irq0);
|
2007-04-30 03:26:42 +02:00
|
|
|
|
|
|
|
if (s->status[0] & (1 << 1))
|
2011-01-21 17:57:50 +01:00
|
|
|
qemu_irq_raise(s->irq1);
|
2007-04-30 03:26:42 +02:00
|
|
|
else
|
2011-01-21 17:57:50 +01:00
|
|
|
qemu_irq_lower(s->irq1);
|
2007-04-30 03:26:42 +02:00
|
|
|
|
|
|
|
if ((s->status[0] & ~3) | s->status[1] | s->status[2] | s->status[3])
|
2011-01-21 17:57:50 +01:00
|
|
|
qemu_irq_raise(s->irqX);
|
2007-04-30 03:26:42 +02:00
|
|
|
else
|
2011-01-21 17:57:50 +01:00
|
|
|
qemu_irq_lower(s->irqX);
|
2007-04-30 03:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Bitmap of pins used as standby and sleep wake-up sources. */
|
2007-11-17 15:07:13 +01:00
|
|
|
static const int pxa2xx_gpio_wake[PXA2XX_GPIO_BANKS] = {
|
2007-04-30 03:26:42 +02:00
|
|
|
0x8003fe1b, 0x002001fc, 0xec080000, 0x0012007f,
|
|
|
|
};
|
|
|
|
|
2007-11-17 15:07:13 +01:00
|
|
|
static void pxa2xx_gpio_set(void *opaque, int line, int level)
|
2007-04-30 03:26:42 +02:00
|
|
|
{
|
2009-05-10 02:44:56 +02:00
|
|
|
PXA2xxGPIOInfo *s = (PXA2xxGPIOInfo *) opaque;
|
2013-01-17 18:51:17 +01:00
|
|
|
CPUState *cpu = CPU(s->cpu);
|
2007-04-30 03:26:42 +02:00
|
|
|
int bank;
|
|
|
|
uint32_t mask;
|
|
|
|
|
|
|
|
if (line >= s->lines) {
|
2017-11-08 23:56:31 +01:00
|
|
|
printf("%s: No GPIO pin %i\n", __func__, line);
|
2007-04-30 03:26:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bank = line >> 5;
|
2014-03-10 15:56:29 +01:00
|
|
|
mask = 1U << (line & 31);
|
2007-04-30 03:26:42 +02:00
|
|
|
|
|
|
|
if (level) {
|
|
|
|
s->status[bank] |= s->rising[bank] & mask &
|
|
|
|
~s->ilevel[bank] & ~s->dir[bank];
|
|
|
|
s->ilevel[bank] |= mask;
|
|
|
|
} else {
|
|
|
|
s->status[bank] |= s->falling[bank] & mask &
|
|
|
|
s->ilevel[bank] & ~s->dir[bank];
|
|
|
|
s->ilevel[bank] &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->status[bank] & mask)
|
|
|
|
pxa2xx_gpio_irq_update(s);
|
|
|
|
|
|
|
|
/* Wake-up GPIOs */
|
2013-01-17 18:51:17 +01:00
|
|
|
if (cpu->halted && (mask & ~s->dir[bank] & pxa2xx_gpio_wake[bank])) {
|
2013-01-18 15:03:43 +01:00
|
|
|
cpu_interrupt(cpu, CPU_INTERRUPT_EXITTB);
|
2012-05-04 00:23:14 +02:00
|
|
|
}
|
2007-04-30 03:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-05-10 02:44:56 +02:00
|
|
|
static void pxa2xx_gpio_handler_update(PXA2xxGPIOInfo *s) {
|
2007-04-30 03:26:42 +02:00
|
|
|
uint32_t level, diff;
|
|
|
|
int i, bit, line;
|
|
|
|
for (i = 0; i < PXA2XX_GPIO_BANKS; i ++) {
|
|
|
|
level = s->olevel[i] & s->dir[i];
|
|
|
|
|
|
|
|
for (diff = s->prev_level[i] ^ level; diff; diff ^= 1 << bit) {
|
2015-03-23 16:29:26 +01:00
|
|
|
bit = ctz32(diff);
|
2007-04-30 03:26:42 +02:00
|
|
|
line = bit + 32 * i;
|
2007-11-17 15:07:13 +01:00
|
|
|
qemu_set_irq(s->handler[line], (level >> bit) & 1);
|
2007-04-30 03:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s->prev_level[i] = level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t pxa2xx_gpio_read(void *opaque, hwaddr offset,
|
2011-10-30 14:50:11 +01:00
|
|
|
unsigned size)
|
2007-04-30 03:26:42 +02:00
|
|
|
{
|
2009-05-10 02:44:56 +02:00
|
|
|
PXA2xxGPIOInfo *s = (PXA2xxGPIOInfo *) opaque;
|
2007-04-30 03:26:42 +02:00
|
|
|
uint32_t ret;
|
|
|
|
int bank;
|
|
|
|
if (offset >= 0x200)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bank = pxa2xx_gpio_regs[offset].bank;
|
|
|
|
switch (pxa2xx_gpio_regs[offset].reg) {
|
|
|
|
case GPDR: /* GPIO Pin-Direction registers */
|
|
|
|
return s->dir[bank];
|
|
|
|
|
2007-10-04 21:41:17 +02:00
|
|
|
case GPSR: /* GPIO Pin-Output Set registers */
|
2014-06-29 19:38:40 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"pxa2xx GPIO: read from write only register GPSR\n");
|
|
|
|
return 0;
|
2007-10-04 21:41:17 +02:00
|
|
|
|
2007-11-17 19:43:47 +01:00
|
|
|
case GPCR: /* GPIO Pin-Output Clear registers */
|
2014-06-29 19:38:40 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"pxa2xx GPIO: read from write only register GPCR\n");
|
|
|
|
return 0;
|
2007-11-17 19:43:47 +01:00
|
|
|
|
2007-04-30 03:26:42 +02:00
|
|
|
case GRER: /* GPIO Rising-Edge Detect Enable registers */
|
|
|
|
return s->rising[bank];
|
|
|
|
|
|
|
|
case GFER: /* GPIO Falling-Edge Detect Enable registers */
|
|
|
|
return s->falling[bank];
|
|
|
|
|
|
|
|
case GAFR_L: /* GPIO Alternate Function registers */
|
|
|
|
return s->gafr[bank * 2];
|
|
|
|
|
|
|
|
case GAFR_U: /* GPIO Alternate Function registers */
|
|
|
|
return s->gafr[bank * 2 + 1];
|
|
|
|
|
|
|
|
case GPLR: /* GPIO Pin-Level registers */
|
|
|
|
ret = (s->olevel[bank] & s->dir[bank]) |
|
|
|
|
(s->ilevel[bank] & ~s->dir[bank]);
|
2007-11-17 15:07:13 +01:00
|
|
|
qemu_irq_raise(s->read_notify);
|
2007-04-30 03:26:42 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
case GEDR: /* GPIO Edge Detect Status registers */
|
|
|
|
return s->status[bank];
|
|
|
|
|
|
|
|
default:
|
2020-05-18 16:03:07 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIX "\n",
|
|
|
|
__func__, offset);
|
2007-04-30 03:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void pxa2xx_gpio_write(void *opaque, hwaddr offset,
|
2011-10-30 14:50:11 +01:00
|
|
|
uint64_t value, unsigned size)
|
2007-04-30 03:26:42 +02:00
|
|
|
{
|
2009-05-10 02:44:56 +02:00
|
|
|
PXA2xxGPIOInfo *s = (PXA2xxGPIOInfo *) opaque;
|
2007-04-30 03:26:42 +02:00
|
|
|
int bank;
|
|
|
|
if (offset >= 0x200)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bank = pxa2xx_gpio_regs[offset].bank;
|
|
|
|
switch (pxa2xx_gpio_regs[offset].reg) {
|
|
|
|
case GPDR: /* GPIO Pin-Direction registers */
|
|
|
|
s->dir[bank] = value;
|
|
|
|
pxa2xx_gpio_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPSR: /* GPIO Pin-Output Set registers */
|
|
|
|
s->olevel[bank] |= value;
|
|
|
|
pxa2xx_gpio_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPCR: /* GPIO Pin-Output Clear registers */
|
|
|
|
s->olevel[bank] &= ~value;
|
|
|
|
pxa2xx_gpio_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRER: /* GPIO Rising-Edge Detect Enable registers */
|
|
|
|
s->rising[bank] = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFER: /* GPIO Falling-Edge Detect Enable registers */
|
|
|
|
s->falling[bank] = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAFR_L: /* GPIO Alternate Function registers */
|
|
|
|
s->gafr[bank * 2] = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAFR_U: /* GPIO Alternate Function registers */
|
|
|
|
s->gafr[bank * 2 + 1] = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEDR: /* GPIO Edge Detect Status registers */
|
|
|
|
s->status[bank] &= ~value;
|
|
|
|
pxa2xx_gpio_irq_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-05-18 16:03:07 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIX "\n",
|
|
|
|
__func__, offset);
|
2007-04-30 03:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-30 14:50:11 +01:00
|
|
|
static const MemoryRegionOps pxa_gpio_ops = {
|
|
|
|
.read = pxa2xx_gpio_read,
|
|
|
|
.write = pxa2xx_gpio_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-30 03:26:42 +02:00
|
|
|
};
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
DeviceState *pxa2xx_gpio_init(hwaddr base,
|
2012-12-17 06:18:02 +01:00
|
|
|
ARMCPU *cpu, DeviceState *pic, int lines)
|
2007-05-24 20:50:09 +02:00
|
|
|
{
|
2012-12-17 06:18:02 +01:00
|
|
|
CPUState *cs = CPU(cpu);
|
2011-01-21 17:57:50 +01:00
|
|
|
DeviceState *dev;
|
2007-05-24 20:50:09 +02:00
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new(TYPE_PXA2XX_GPIO);
|
2011-01-21 17:57:50 +01:00
|
|
|
qdev_prop_set_int32(dev, "lines", lines);
|
2012-12-17 06:18:02 +01:00
|
|
|
qdev_prop_set_int32(dev, "ncpu", cs->cpu_index);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
2007-05-24 20:50:09 +02:00
|
|
|
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
|
2011-02-25 12:13:38 +01:00
|
|
|
qdev_get_gpio_in(pic, PXA2XX_PIC_GPIO_0));
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 1,
|
2011-02-25 12:13:38 +01:00
|
|
|
qdev_get_gpio_in(pic, PXA2XX_PIC_GPIO_1));
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 2,
|
2011-02-25 12:13:38 +01:00
|
|
|
qdev_get_gpio_in(pic, PXA2XX_PIC_GPIO_X));
|
2007-05-24 20:50:09 +02:00
|
|
|
|
2011-01-21 17:57:50 +01:00
|
|
|
return dev;
|
2007-05-24 20:50:09 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void pxa2xx_gpio_initfn(Object *obj)
|
2007-04-30 03:26:42 +02:00
|
|
|
{
|
2016-10-24 17:26:55 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-07-24 02:03:39 +02:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
PXA2xxGPIOInfo *s = PXA2XX_GPIO(dev);
|
2007-04-30 03:26:42 +02:00
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &pxa_gpio_ops,
|
|
|
|
s, "pxa2xx-gpio", 0x1000);
|
2013-07-24 02:03:39 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
|
|
sysbus_init_irq(sbd, &s->irq0);
|
|
|
|
sysbus_init_irq(sbd, &s->irq1);
|
|
|
|
sysbus_init_irq(sbd, &s->irqX);
|
2016-10-24 17:26:55 +02:00
|
|
|
}
|
2007-04-30 03:26:42 +02:00
|
|
|
|
2016-10-24 17:26:55 +02:00
|
|
|
static void pxa2xx_gpio_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
PXA2xxGPIOInfo *s = PXA2XX_GPIO(dev);
|
|
|
|
|
|
|
|
s->cpu = ARM_CPU(qemu_get_cpu(s->ncpu));
|
|
|
|
|
|
|
|
qdev_init_gpio_in(dev, pxa2xx_gpio_set, s->lines);
|
|
|
|
qdev_init_gpio_out(dev, s->handler, s->lines);
|
2007-04-30 03:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Registers a callback to notify on GPLR reads. This normally
|
|
|
|
* shouldn't be needed but it is used for the hack on Spitz machines.
|
|
|
|
*/
|
2011-01-21 17:57:50 +01:00
|
|
|
void pxa2xx_gpio_read_notifier(DeviceState *dev, qemu_irq handler)
|
2007-11-17 15:07:13 +01:00
|
|
|
{
|
2013-07-24 02:03:39 +02:00
|
|
|
PXA2xxGPIOInfo *s = PXA2XX_GPIO(dev);
|
|
|
|
|
2007-04-30 03:26:42 +02:00
|
|
|
s->read_notify = handler;
|
|
|
|
}
|
2011-01-21 17:57:50 +01:00
|
|
|
|
|
|
|
static const VMStateDescription vmstate_pxa2xx_gpio_regs = {
|
|
|
|
.name = "pxa2xx-gpio",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-05-13 17:09:35 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2011-01-21 17:57:50 +01:00
|
|
|
VMSTATE_UINT32_ARRAY(ilevel, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS),
|
|
|
|
VMSTATE_UINT32_ARRAY(olevel, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS),
|
|
|
|
VMSTATE_UINT32_ARRAY(dir, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS),
|
|
|
|
VMSTATE_UINT32_ARRAY(rising, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS),
|
|
|
|
VMSTATE_UINT32_ARRAY(falling, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS),
|
|
|
|
VMSTATE_UINT32_ARRAY(status, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS),
|
|
|
|
VMSTATE_UINT32_ARRAY(gafr, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS * 2),
|
2014-06-29 19:38:40 +02:00
|
|
|
VMSTATE_UINT32_ARRAY(prev_level, PXA2xxGPIOInfo, PXA2XX_GPIO_BANKS),
|
2011-01-21 17:57:50 +01:00
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static Property pxa2xx_gpio_properties[] = {
|
|
|
|
DEFINE_PROP_INT32("lines", PXA2xxGPIOInfo, lines, 0),
|
|
|
|
DEFINE_PROP_INT32("ncpu", PXA2xxGPIOInfo, ncpu, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pxa2xx_gpio_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "PXA2xx GPIO controller";
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, pxa2xx_gpio_properties);
|
2014-06-29 19:38:40 +02:00
|
|
|
dc->vmsd = &vmstate_pxa2xx_gpio_regs;
|
2016-10-24 17:26:55 +02:00
|
|
|
dc->realize = pxa2xx_gpio_realize;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo pxa2xx_gpio_info = {
|
2013-07-24 02:03:39 +02:00
|
|
|
.name = TYPE_PXA2XX_GPIO,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(PXA2xxGPIOInfo),
|
2016-10-24 17:26:55 +02:00
|
|
|
.instance_init = pxa2xx_gpio_initfn,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = pxa2xx_gpio_class_init,
|
2011-01-21 17:57:50 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void pxa2xx_gpio_register_types(void)
|
2011-01-21 17:57:50 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&pxa2xx_gpio_info);
|
2011-01-21 17:57:50 +01:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(pxa2xx_gpio_register_types)
|