qemu/include/hw/gpio/aspeed_gpio.h
Rashmica Gupta 4b7f956862 hw/gpio: Add basic Aspeed GPIO model for AST2400 and AST2500
GPIO pins are arranged in groups of 8 pins labeled A,B,..,Y,Z,AA,AB,AC.
(Note that the ast2400 controller only goes up to group AB).
A set has four groups (except set AC which only has one) and is
referred to by the groups it is composed of (eg ABCD,EFGH,...,YZAAAB).
Each set is accessed and controlled by a bank of 14 registers.

These registers operate on a per pin level where each bit in the register
corresponds to a pin, except for the command source registers. The command
source registers operate on a per group level where bits 24, 16, 8 and 0
correspond to each group in the set.

 eg. registers for set ABCD:
 |D7...D0|C7...C0|B7...B0|A7...A0| <- GPIOs
 |31...24|23...16|15....8|7.....0| <- bit position

Note that there are a couple of groups that only have 4 pins.

There are two ways that this model deviates from the behaviour of the
actual controller:
(1) The only control source driving the GPIO pins in the model is the ARM
model (as there currently aren't models for the LPC or Coprocessor).

(2) None of the registers in the model are reset tolerant (needs
integration with the watchdog).

Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
Tested-by: Andrew Jeffery <andrew@aj.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Message-id: 20190904070506.1052-2-clg@kaod.org
[clg: fixed missing header files
      made use of HWADDR_PRIx to fix compilation on windows ]
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2019-09-13 16:05:00 +01:00

101 lines
2.6 KiB
C

/*
* ASPEED GPIO Controller
*
* Copyright (C) 2017-2018 IBM Corp.
*
* This code is licensed under the GPL version 2 or later. See
* the COPYING file in the top-level directory.
*/
#ifndef ASPEED_GPIO_H
#define ASPEED_GPIO_H
#include "hw/sysbus.h"
#define TYPE_ASPEED_GPIO "aspeed.gpio"
#define ASPEED_GPIO(obj) OBJECT_CHECK(AspeedGPIOState, (obj), TYPE_ASPEED_GPIO)
#define ASPEED_GPIO_CLASS(klass) \
OBJECT_CLASS_CHECK(AspeedGPIOClass, (klass), TYPE_ASPEED_GPIO)
#define ASPEED_GPIO_GET_CLASS(obj) \
OBJECT_GET_CLASS(AspeedGPIOClass, (obj), TYPE_ASPEED_GPIO)
#define ASPEED_GPIO_MAX_NR_SETS 8
#define ASPEED_REGS_PER_BANK 14
#define ASPEED_GPIO_MAX_NR_REGS (ASPEED_REGS_PER_BANK * ASPEED_GPIO_MAX_NR_SETS)
#define ASPEED_GPIO_NR_PINS 228
#define ASPEED_GROUPS_PER_SET 4
#define ASPEED_GPIO_NR_DEBOUNCE_REGS 3
#define ASPEED_CHARS_PER_GROUP_LABEL 4
typedef struct GPIOSets GPIOSets;
typedef struct GPIOSetProperties {
uint32_t input;
uint32_t output;
char group_label[ASPEED_GROUPS_PER_SET][ASPEED_CHARS_PER_GROUP_LABEL];
} GPIOSetProperties;
enum GPIORegType {
gpio_not_a_reg,
gpio_reg_data_value,
gpio_reg_direction,
gpio_reg_int_enable,
gpio_reg_int_sens_0,
gpio_reg_int_sens_1,
gpio_reg_int_sens_2,
gpio_reg_int_status,
gpio_reg_reset_tolerant,
gpio_reg_debounce_1,
gpio_reg_debounce_2,
gpio_reg_cmd_source_0,
gpio_reg_cmd_source_1,
gpio_reg_data_read,
gpio_reg_input_mask,
};
typedef struct AspeedGPIOReg {
uint16_t set_idx;
enum GPIORegType type;
} AspeedGPIOReg;
typedef struct AspeedGPIOClass {
SysBusDevice parent_obj;
const GPIOSetProperties *props;
uint32_t nr_gpio_pins;
uint32_t nr_gpio_sets;
uint32_t gap;
const AspeedGPIOReg *reg_table;
} AspeedGPIOClass;
typedef struct AspeedGPIOState {
/* <private> */
SysBusDevice parent;
/*< public >*/
MemoryRegion iomem;
int pending;
qemu_irq irq;
qemu_irq gpios[ASPEED_GPIO_NR_PINS];
/* Parallel GPIO Registers */
uint32_t debounce_regs[ASPEED_GPIO_NR_DEBOUNCE_REGS];
struct GPIOSets {
uint32_t data_value; /* Reflects pin values */
uint32_t data_read; /* Contains last value written to data value */
uint32_t direction;
uint32_t int_enable;
uint32_t int_sens_0;
uint32_t int_sens_1;
uint32_t int_sens_2;
uint32_t int_status;
uint32_t reset_tol;
uint32_t cmd_source_0;
uint32_t cmd_source_1;
uint32_t debounce_1;
uint32_t debounce_2;
uint32_t input_mask;
} sets[ASPEED_GPIO_MAX_NR_SETS];
} AspeedGPIOState;
#endif /* _ASPEED_GPIO_H_ */