116020011SCédric Le Goater /* 216020011SCédric Le Goater * ASPEED AST2400 I2C Controller 316020011SCédric Le Goater * 416020011SCédric Le Goater * Copyright (C) 2016 IBM Corp. 516020011SCédric Le Goater * 616020011SCédric Le Goater * This program is free software; you can redistribute it and/or modify 716020011SCédric Le Goater * it under the terms of the GNU General Public License as published by 816020011SCédric Le Goater * the Free Software Foundation; either version 2 of the License, or 916020011SCédric Le Goater * (at your option) any later version. 1016020011SCédric Le Goater * 1116020011SCédric Le Goater * This program is distributed in the hope that it will be useful, 1216020011SCédric Le Goater * but WITHOUT ANY WARRANTY; without even the implied warranty of 1316020011SCédric Le Goater * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1416020011SCédric Le Goater * GNU General Public License for more details. 1516020011SCédric Le Goater * 1616020011SCédric Le Goater * You should have received a copy of the GNU General Public License along 1716020011SCédric Le Goater * with this program; if not, write to the Free Software Foundation, Inc., 1816020011SCédric Le Goater * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 1916020011SCédric Le Goater */ 20ec150c7eSMarkus Armbruster 2116020011SCédric Le Goater #ifndef ASPEED_I2C_H 2216020011SCédric Le Goater #define ASPEED_I2C_H 2316020011SCédric Le Goater 2416020011SCédric Le Goater #include "hw/i2c/i2c.h" 25ec150c7eSMarkus Armbruster #include "hw/sysbus.h" 2616020011SCédric Le Goater 2716020011SCédric Le Goater #define TYPE_ASPEED_I2C "aspeed.i2c" 28f7da1aa8SCédric Le Goater #define TYPE_ASPEED_2400_I2C TYPE_ASPEED_I2C "-ast2400" 29f7da1aa8SCédric Le Goater #define TYPE_ASPEED_2500_I2C TYPE_ASPEED_I2C "-ast2500" 3051dd4923SCédric Le Goater #define TYPE_ASPEED_2600_I2C TYPE_ASPEED_I2C "-ast2600" 3116020011SCédric Le Goater #define ASPEED_I2C(obj) \ 3216020011SCédric Le Goater OBJECT_CHECK(AspeedI2CState, (obj), TYPE_ASPEED_I2C) 3316020011SCédric Le Goater 3451dd4923SCédric Le Goater #define ASPEED_I2C_NR_BUSSES 16 35*6054fc73SCédric Le Goater #define ASPEED_I2C_MAX_POOL_SIZE 0x800 3616020011SCédric Le Goater 3716020011SCédric Le Goater struct AspeedI2CState; 3816020011SCédric Le Goater 3916020011SCédric Le Goater typedef struct AspeedI2CBus { 4016020011SCédric Le Goater struct AspeedI2CState *controller; 4116020011SCédric Le Goater 4216020011SCédric Le Goater MemoryRegion mr; 4316020011SCédric Le Goater 4416020011SCédric Le Goater I2CBus *bus; 4516020011SCédric Le Goater uint8_t id; 4651dd4923SCédric Le Goater qemu_irq irq; 4716020011SCédric Le Goater 4816020011SCédric Le Goater uint32_t ctrl; 4916020011SCédric Le Goater uint32_t timing[2]; 5016020011SCédric Le Goater uint32_t intr_ctrl; 5116020011SCédric Le Goater uint32_t intr_status; 5216020011SCédric Le Goater uint32_t cmd; 5316020011SCédric Le Goater uint32_t buf; 54*6054fc73SCédric Le Goater uint32_t pool_ctrl; 5516020011SCédric Le Goater } AspeedI2CBus; 5616020011SCédric Le Goater 5716020011SCédric Le Goater typedef struct AspeedI2CState { 5816020011SCédric Le Goater SysBusDevice parent_obj; 5916020011SCédric Le Goater 6016020011SCédric Le Goater MemoryRegion iomem; 6116020011SCédric Le Goater qemu_irq irq; 6216020011SCédric Le Goater 6316020011SCédric Le Goater uint32_t intr_status; 64*6054fc73SCédric Le Goater MemoryRegion pool_iomem; 65*6054fc73SCédric Le Goater uint8_t pool[ASPEED_I2C_MAX_POOL_SIZE]; 6616020011SCédric Le Goater 6716020011SCédric Le Goater AspeedI2CBus busses[ASPEED_I2C_NR_BUSSES]; 6816020011SCédric Le Goater } AspeedI2CState; 6916020011SCédric Le Goater 70f7da1aa8SCédric Le Goater #define ASPEED_I2C_CLASS(klass) \ 71f7da1aa8SCédric Le Goater OBJECT_CLASS_CHECK(AspeedI2CClass, (klass), TYPE_ASPEED_I2C) 72f7da1aa8SCédric Le Goater #define ASPEED_I2C_GET_CLASS(obj) \ 73f7da1aa8SCédric Le Goater OBJECT_GET_CLASS(AspeedI2CClass, (obj), TYPE_ASPEED_I2C) 74f7da1aa8SCédric Le Goater 75f7da1aa8SCédric Le Goater typedef struct AspeedI2CClass { 76f7da1aa8SCédric Le Goater SysBusDeviceClass parent_class; 77f7da1aa8SCédric Le Goater 78f7da1aa8SCédric Le Goater uint8_t num_busses; 79f7da1aa8SCédric Le Goater uint8_t reg_size; 80f7da1aa8SCédric Le Goater uint8_t gap; 8151dd4923SCédric Le Goater qemu_irq (*bus_get_irq)(AspeedI2CBus *); 82*6054fc73SCédric Le Goater 83*6054fc73SCédric Le Goater uint64_t pool_size; 84*6054fc73SCédric Le Goater hwaddr pool_base; 85*6054fc73SCédric Le Goater uint8_t *(*bus_pool_base)(AspeedI2CBus *); 86f7da1aa8SCédric Le Goater } AspeedI2CClass; 87f7da1aa8SCédric Le Goater 8816020011SCédric Le Goater I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr); 8916020011SCédric Le Goater 9016020011SCédric Le Goater #endif /* ASPEED_I2C_H */ 91