15193899aSPaolo Bonzini /* 25193899aSPaolo Bonzini * TI OMAP processors GPIO emulation. 35193899aSPaolo Bonzini * 45193899aSPaolo Bonzini * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org> 55193899aSPaolo Bonzini * Copyright (C) 2007-2009 Nokia Corporation 65193899aSPaolo Bonzini * 75193899aSPaolo Bonzini * This program is free software; you can redistribute it and/or 85193899aSPaolo Bonzini * modify it under the terms of the GNU General Public License as 95193899aSPaolo Bonzini * published by the Free Software Foundation; either version 2 or 105193899aSPaolo Bonzini * (at your option) version 3 of the License. 115193899aSPaolo Bonzini * 125193899aSPaolo Bonzini * This program is distributed in the hope that it will be useful, 135193899aSPaolo Bonzini * but WITHOUT ANY WARRANTY; without even the implied warranty of 145193899aSPaolo Bonzini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155193899aSPaolo Bonzini * GNU General Public License for more details. 165193899aSPaolo Bonzini * 175193899aSPaolo Bonzini * You should have received a copy of the GNU General Public License along 185193899aSPaolo Bonzini * with this program; if not, see <http://www.gnu.org/licenses/>. 195193899aSPaolo Bonzini */ 205193899aSPaolo Bonzini 215193899aSPaolo Bonzini #include "hw/hw.h" 225193899aSPaolo Bonzini #include "hw/arm/omap.h" 235193899aSPaolo Bonzini #include "hw/sysbus.h" 245193899aSPaolo Bonzini 255193899aSPaolo Bonzini struct omap_gpio_s { 265193899aSPaolo Bonzini qemu_irq irq; 275193899aSPaolo Bonzini qemu_irq handler[16]; 285193899aSPaolo Bonzini 295193899aSPaolo Bonzini uint16_t inputs; 305193899aSPaolo Bonzini uint16_t outputs; 315193899aSPaolo Bonzini uint16_t dir; 325193899aSPaolo Bonzini uint16_t edge; 335193899aSPaolo Bonzini uint16_t mask; 345193899aSPaolo Bonzini uint16_t ints; 355193899aSPaolo Bonzini uint16_t pins; 365193899aSPaolo Bonzini }; 375193899aSPaolo Bonzini 385193899aSPaolo Bonzini struct omap_gpif_s { 395193899aSPaolo Bonzini SysBusDevice busdev; 405193899aSPaolo Bonzini MemoryRegion iomem; 415193899aSPaolo Bonzini int mpu_model; 425193899aSPaolo Bonzini void *clk; 435193899aSPaolo Bonzini struct omap_gpio_s omap1; 445193899aSPaolo Bonzini }; 455193899aSPaolo Bonzini 465193899aSPaolo Bonzini /* General-Purpose I/O of OMAP1 */ 475193899aSPaolo Bonzini static void omap_gpio_set(void *opaque, int line, int level) 485193899aSPaolo Bonzini { 495193899aSPaolo Bonzini struct omap_gpio_s *s = &((struct omap_gpif_s *) opaque)->omap1; 505193899aSPaolo Bonzini uint16_t prev = s->inputs; 515193899aSPaolo Bonzini 525193899aSPaolo Bonzini if (level) 535193899aSPaolo Bonzini s->inputs |= 1 << line; 545193899aSPaolo Bonzini else 555193899aSPaolo Bonzini s->inputs &= ~(1 << line); 565193899aSPaolo Bonzini 575193899aSPaolo Bonzini if (((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) & 585193899aSPaolo Bonzini (1 << line) & s->dir & ~s->mask) { 595193899aSPaolo Bonzini s->ints |= 1 << line; 605193899aSPaolo Bonzini qemu_irq_raise(s->irq); 615193899aSPaolo Bonzini } 625193899aSPaolo Bonzini } 635193899aSPaolo Bonzini 645193899aSPaolo Bonzini static uint64_t omap_gpio_read(void *opaque, hwaddr addr, 655193899aSPaolo Bonzini unsigned size) 665193899aSPaolo Bonzini { 675193899aSPaolo Bonzini struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; 685193899aSPaolo Bonzini int offset = addr & OMAP_MPUI_REG_MASK; 695193899aSPaolo Bonzini 705193899aSPaolo Bonzini if (size != 2) { 715193899aSPaolo Bonzini return omap_badwidth_read16(opaque, addr); 725193899aSPaolo Bonzini } 735193899aSPaolo Bonzini 745193899aSPaolo Bonzini switch (offset) { 755193899aSPaolo Bonzini case 0x00: /* DATA_INPUT */ 765193899aSPaolo Bonzini return s->inputs & s->pins; 775193899aSPaolo Bonzini 785193899aSPaolo Bonzini case 0x04: /* DATA_OUTPUT */ 795193899aSPaolo Bonzini return s->outputs; 805193899aSPaolo Bonzini 815193899aSPaolo Bonzini case 0x08: /* DIRECTION_CONTROL */ 825193899aSPaolo Bonzini return s->dir; 835193899aSPaolo Bonzini 845193899aSPaolo Bonzini case 0x0c: /* INTERRUPT_CONTROL */ 855193899aSPaolo Bonzini return s->edge; 865193899aSPaolo Bonzini 875193899aSPaolo Bonzini case 0x10: /* INTERRUPT_MASK */ 885193899aSPaolo Bonzini return s->mask; 895193899aSPaolo Bonzini 905193899aSPaolo Bonzini case 0x14: /* INTERRUPT_STATUS */ 915193899aSPaolo Bonzini return s->ints; 925193899aSPaolo Bonzini 935193899aSPaolo Bonzini case 0x18: /* PIN_CONTROL (not in OMAP310) */ 945193899aSPaolo Bonzini OMAP_BAD_REG(addr); 955193899aSPaolo Bonzini return s->pins; 965193899aSPaolo Bonzini } 975193899aSPaolo Bonzini 985193899aSPaolo Bonzini OMAP_BAD_REG(addr); 995193899aSPaolo Bonzini return 0; 1005193899aSPaolo Bonzini } 1015193899aSPaolo Bonzini 1025193899aSPaolo Bonzini static void omap_gpio_write(void *opaque, hwaddr addr, 1035193899aSPaolo Bonzini uint64_t value, unsigned size) 1045193899aSPaolo Bonzini { 1055193899aSPaolo Bonzini struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; 1065193899aSPaolo Bonzini int offset = addr & OMAP_MPUI_REG_MASK; 1075193899aSPaolo Bonzini uint16_t diff; 1085193899aSPaolo Bonzini int ln; 1095193899aSPaolo Bonzini 1105193899aSPaolo Bonzini if (size != 2) { 1115193899aSPaolo Bonzini return omap_badwidth_write16(opaque, addr, value); 1125193899aSPaolo Bonzini } 1135193899aSPaolo Bonzini 1145193899aSPaolo Bonzini switch (offset) { 1155193899aSPaolo Bonzini case 0x00: /* DATA_INPUT */ 1165193899aSPaolo Bonzini OMAP_RO_REG(addr); 1175193899aSPaolo Bonzini return; 1185193899aSPaolo Bonzini 1195193899aSPaolo Bonzini case 0x04: /* DATA_OUTPUT */ 1205193899aSPaolo Bonzini diff = (s->outputs ^ value) & ~s->dir; 1215193899aSPaolo Bonzini s->outputs = value; 1225193899aSPaolo Bonzini while ((ln = ffs(diff))) { 1235193899aSPaolo Bonzini ln --; 1245193899aSPaolo Bonzini if (s->handler[ln]) 1255193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (value >> ln) & 1); 1265193899aSPaolo Bonzini diff &= ~(1 << ln); 1275193899aSPaolo Bonzini } 1285193899aSPaolo Bonzini break; 1295193899aSPaolo Bonzini 1305193899aSPaolo Bonzini case 0x08: /* DIRECTION_CONTROL */ 1315193899aSPaolo Bonzini diff = s->outputs & (s->dir ^ value); 1325193899aSPaolo Bonzini s->dir = value; 1335193899aSPaolo Bonzini 1345193899aSPaolo Bonzini value = s->outputs & ~s->dir; 1355193899aSPaolo Bonzini while ((ln = ffs(diff))) { 1365193899aSPaolo Bonzini ln --; 1375193899aSPaolo Bonzini if (s->handler[ln]) 1385193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (value >> ln) & 1); 1395193899aSPaolo Bonzini diff &= ~(1 << ln); 1405193899aSPaolo Bonzini } 1415193899aSPaolo Bonzini break; 1425193899aSPaolo Bonzini 1435193899aSPaolo Bonzini case 0x0c: /* INTERRUPT_CONTROL */ 1445193899aSPaolo Bonzini s->edge = value; 1455193899aSPaolo Bonzini break; 1465193899aSPaolo Bonzini 1475193899aSPaolo Bonzini case 0x10: /* INTERRUPT_MASK */ 1485193899aSPaolo Bonzini s->mask = value; 1495193899aSPaolo Bonzini break; 1505193899aSPaolo Bonzini 1515193899aSPaolo Bonzini case 0x14: /* INTERRUPT_STATUS */ 1525193899aSPaolo Bonzini s->ints &= ~value; 1535193899aSPaolo Bonzini if (!s->ints) 1545193899aSPaolo Bonzini qemu_irq_lower(s->irq); 1555193899aSPaolo Bonzini break; 1565193899aSPaolo Bonzini 1575193899aSPaolo Bonzini case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */ 1585193899aSPaolo Bonzini OMAP_BAD_REG(addr); 1595193899aSPaolo Bonzini s->pins = value; 1605193899aSPaolo Bonzini break; 1615193899aSPaolo Bonzini 1625193899aSPaolo Bonzini default: 1635193899aSPaolo Bonzini OMAP_BAD_REG(addr); 1645193899aSPaolo Bonzini return; 1655193899aSPaolo Bonzini } 1665193899aSPaolo Bonzini } 1675193899aSPaolo Bonzini 1685193899aSPaolo Bonzini /* *Some* sources say the memory region is 32-bit. */ 1695193899aSPaolo Bonzini static const MemoryRegionOps omap_gpio_ops = { 1705193899aSPaolo Bonzini .read = omap_gpio_read, 1715193899aSPaolo Bonzini .write = omap_gpio_write, 1725193899aSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 1735193899aSPaolo Bonzini }; 1745193899aSPaolo Bonzini 1755193899aSPaolo Bonzini static void omap_gpio_reset(struct omap_gpio_s *s) 1765193899aSPaolo Bonzini { 1775193899aSPaolo Bonzini s->inputs = 0; 1785193899aSPaolo Bonzini s->outputs = ~0; 1795193899aSPaolo Bonzini s->dir = ~0; 1805193899aSPaolo Bonzini s->edge = ~0; 1815193899aSPaolo Bonzini s->mask = ~0; 1825193899aSPaolo Bonzini s->ints = 0; 1835193899aSPaolo Bonzini s->pins = ~0; 1845193899aSPaolo Bonzini } 1855193899aSPaolo Bonzini 1865193899aSPaolo Bonzini struct omap2_gpio_s { 1875193899aSPaolo Bonzini qemu_irq irq[2]; 1885193899aSPaolo Bonzini qemu_irq wkup; 1895193899aSPaolo Bonzini qemu_irq *handler; 1905193899aSPaolo Bonzini MemoryRegion iomem; 1915193899aSPaolo Bonzini 1925193899aSPaolo Bonzini uint8_t revision; 1935193899aSPaolo Bonzini uint8_t config[2]; 1945193899aSPaolo Bonzini uint32_t inputs; 1955193899aSPaolo Bonzini uint32_t outputs; 1965193899aSPaolo Bonzini uint32_t dir; 1975193899aSPaolo Bonzini uint32_t level[2]; 1985193899aSPaolo Bonzini uint32_t edge[2]; 1995193899aSPaolo Bonzini uint32_t mask[2]; 2005193899aSPaolo Bonzini uint32_t wumask; 2015193899aSPaolo Bonzini uint32_t ints[2]; 2025193899aSPaolo Bonzini uint32_t debounce; 2035193899aSPaolo Bonzini uint8_t delay; 2045193899aSPaolo Bonzini }; 2055193899aSPaolo Bonzini 2065193899aSPaolo Bonzini struct omap2_gpif_s { 2075193899aSPaolo Bonzini SysBusDevice busdev; 2085193899aSPaolo Bonzini MemoryRegion iomem; 2095193899aSPaolo Bonzini int mpu_model; 2105193899aSPaolo Bonzini void *iclk; 2115193899aSPaolo Bonzini void *fclk[6]; 2125193899aSPaolo Bonzini int modulecount; 2135193899aSPaolo Bonzini struct omap2_gpio_s *modules; 2145193899aSPaolo Bonzini qemu_irq *handler; 2155193899aSPaolo Bonzini int autoidle; 2165193899aSPaolo Bonzini int gpo; 2175193899aSPaolo Bonzini }; 2185193899aSPaolo Bonzini 2195193899aSPaolo Bonzini /* General-Purpose Interface of OMAP2/3 */ 2205193899aSPaolo Bonzini static inline void omap2_gpio_module_int_update(struct omap2_gpio_s *s, 2215193899aSPaolo Bonzini int line) 2225193899aSPaolo Bonzini { 2235193899aSPaolo Bonzini qemu_set_irq(s->irq[line], s->ints[line] & s->mask[line]); 2245193899aSPaolo Bonzini } 2255193899aSPaolo Bonzini 2265193899aSPaolo Bonzini static void omap2_gpio_module_wake(struct omap2_gpio_s *s, int line) 2275193899aSPaolo Bonzini { 2285193899aSPaolo Bonzini if (!(s->config[0] & (1 << 2))) /* ENAWAKEUP */ 2295193899aSPaolo Bonzini return; 2305193899aSPaolo Bonzini if (!(s->config[0] & (3 << 3))) /* Force Idle */ 2315193899aSPaolo Bonzini return; 2325193899aSPaolo Bonzini if (!(s->wumask & (1 << line))) 2335193899aSPaolo Bonzini return; 2345193899aSPaolo Bonzini 2355193899aSPaolo Bonzini qemu_irq_raise(s->wkup); 2365193899aSPaolo Bonzini } 2375193899aSPaolo Bonzini 2385193899aSPaolo Bonzini static inline void omap2_gpio_module_out_update(struct omap2_gpio_s *s, 2395193899aSPaolo Bonzini uint32_t diff) 2405193899aSPaolo Bonzini { 2415193899aSPaolo Bonzini int ln; 2425193899aSPaolo Bonzini 2435193899aSPaolo Bonzini s->outputs ^= diff; 2445193899aSPaolo Bonzini diff &= ~s->dir; 2455193899aSPaolo Bonzini while ((ln = ffs(diff))) { 2465193899aSPaolo Bonzini ln --; 2475193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (s->outputs >> ln) & 1); 2485193899aSPaolo Bonzini diff &= ~(1 << ln); 2495193899aSPaolo Bonzini } 2505193899aSPaolo Bonzini } 2515193899aSPaolo Bonzini 2525193899aSPaolo Bonzini static void omap2_gpio_module_level_update(struct omap2_gpio_s *s, int line) 2535193899aSPaolo Bonzini { 2545193899aSPaolo Bonzini s->ints[line] |= s->dir & 2555193899aSPaolo Bonzini ((s->inputs & s->level[1]) | (~s->inputs & s->level[0])); 2565193899aSPaolo Bonzini omap2_gpio_module_int_update(s, line); 2575193899aSPaolo Bonzini } 2585193899aSPaolo Bonzini 2595193899aSPaolo Bonzini static inline void omap2_gpio_module_int(struct omap2_gpio_s *s, int line) 2605193899aSPaolo Bonzini { 2615193899aSPaolo Bonzini s->ints[0] |= 1 << line; 2625193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 2635193899aSPaolo Bonzini s->ints[1] |= 1 << line; 2645193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 2655193899aSPaolo Bonzini omap2_gpio_module_wake(s, line); 2665193899aSPaolo Bonzini } 2675193899aSPaolo Bonzini 2685193899aSPaolo Bonzini static void omap2_gpio_set(void *opaque, int line, int level) 2695193899aSPaolo Bonzini { 2705193899aSPaolo Bonzini struct omap2_gpif_s *p = opaque; 2715193899aSPaolo Bonzini struct omap2_gpio_s *s = &p->modules[line >> 5]; 2725193899aSPaolo Bonzini 2735193899aSPaolo Bonzini line &= 31; 2745193899aSPaolo Bonzini if (level) { 2755193899aSPaolo Bonzini if (s->dir & (1 << line) & ((~s->inputs & s->edge[0]) | s->level[1])) 2765193899aSPaolo Bonzini omap2_gpio_module_int(s, line); 2775193899aSPaolo Bonzini s->inputs |= 1 << line; 2785193899aSPaolo Bonzini } else { 2795193899aSPaolo Bonzini if (s->dir & (1 << line) & ((s->inputs & s->edge[1]) | s->level[0])) 2805193899aSPaolo Bonzini omap2_gpio_module_int(s, line); 2815193899aSPaolo Bonzini s->inputs &= ~(1 << line); 2825193899aSPaolo Bonzini } 2835193899aSPaolo Bonzini } 2845193899aSPaolo Bonzini 2855193899aSPaolo Bonzini static void omap2_gpio_module_reset(struct omap2_gpio_s *s) 2865193899aSPaolo Bonzini { 2875193899aSPaolo Bonzini s->config[0] = 0; 2885193899aSPaolo Bonzini s->config[1] = 2; 2895193899aSPaolo Bonzini s->ints[0] = 0; 2905193899aSPaolo Bonzini s->ints[1] = 0; 2915193899aSPaolo Bonzini s->mask[0] = 0; 2925193899aSPaolo Bonzini s->mask[1] = 0; 2935193899aSPaolo Bonzini s->wumask = 0; 2945193899aSPaolo Bonzini s->dir = ~0; 2955193899aSPaolo Bonzini s->level[0] = 0; 2965193899aSPaolo Bonzini s->level[1] = 0; 2975193899aSPaolo Bonzini s->edge[0] = 0; 2985193899aSPaolo Bonzini s->edge[1] = 0; 2995193899aSPaolo Bonzini s->debounce = 0; 3005193899aSPaolo Bonzini s->delay = 0; 3015193899aSPaolo Bonzini } 3025193899aSPaolo Bonzini 3035193899aSPaolo Bonzini static uint32_t omap2_gpio_module_read(void *opaque, hwaddr addr) 3045193899aSPaolo Bonzini { 3055193899aSPaolo Bonzini struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque; 3065193899aSPaolo Bonzini 3075193899aSPaolo Bonzini switch (addr) { 3085193899aSPaolo Bonzini case 0x00: /* GPIO_REVISION */ 3095193899aSPaolo Bonzini return s->revision; 3105193899aSPaolo Bonzini 3115193899aSPaolo Bonzini case 0x10: /* GPIO_SYSCONFIG */ 3125193899aSPaolo Bonzini return s->config[0]; 3135193899aSPaolo Bonzini 3145193899aSPaolo Bonzini case 0x14: /* GPIO_SYSSTATUS */ 3155193899aSPaolo Bonzini return 0x01; 3165193899aSPaolo Bonzini 3175193899aSPaolo Bonzini case 0x18: /* GPIO_IRQSTATUS1 */ 3185193899aSPaolo Bonzini return s->ints[0]; 3195193899aSPaolo Bonzini 3205193899aSPaolo Bonzini case 0x1c: /* GPIO_IRQENABLE1 */ 3215193899aSPaolo Bonzini case 0x60: /* GPIO_CLEARIRQENABLE1 */ 3225193899aSPaolo Bonzini case 0x64: /* GPIO_SETIRQENABLE1 */ 3235193899aSPaolo Bonzini return s->mask[0]; 3245193899aSPaolo Bonzini 3255193899aSPaolo Bonzini case 0x20: /* GPIO_WAKEUPENABLE */ 3265193899aSPaolo Bonzini case 0x80: /* GPIO_CLEARWKUENA */ 3275193899aSPaolo Bonzini case 0x84: /* GPIO_SETWKUENA */ 3285193899aSPaolo Bonzini return s->wumask; 3295193899aSPaolo Bonzini 3305193899aSPaolo Bonzini case 0x28: /* GPIO_IRQSTATUS2 */ 3315193899aSPaolo Bonzini return s->ints[1]; 3325193899aSPaolo Bonzini 3335193899aSPaolo Bonzini case 0x2c: /* GPIO_IRQENABLE2 */ 3345193899aSPaolo Bonzini case 0x70: /* GPIO_CLEARIRQENABLE2 */ 3355193899aSPaolo Bonzini case 0x74: /* GPIO_SETIREQNEABLE2 */ 3365193899aSPaolo Bonzini return s->mask[1]; 3375193899aSPaolo Bonzini 3385193899aSPaolo Bonzini case 0x30: /* GPIO_CTRL */ 3395193899aSPaolo Bonzini return s->config[1]; 3405193899aSPaolo Bonzini 3415193899aSPaolo Bonzini case 0x34: /* GPIO_OE */ 3425193899aSPaolo Bonzini return s->dir; 3435193899aSPaolo Bonzini 3445193899aSPaolo Bonzini case 0x38: /* GPIO_DATAIN */ 3455193899aSPaolo Bonzini return s->inputs; 3465193899aSPaolo Bonzini 3475193899aSPaolo Bonzini case 0x3c: /* GPIO_DATAOUT */ 3485193899aSPaolo Bonzini case 0x90: /* GPIO_CLEARDATAOUT */ 3495193899aSPaolo Bonzini case 0x94: /* GPIO_SETDATAOUT */ 3505193899aSPaolo Bonzini return s->outputs; 3515193899aSPaolo Bonzini 3525193899aSPaolo Bonzini case 0x40: /* GPIO_LEVELDETECT0 */ 3535193899aSPaolo Bonzini return s->level[0]; 3545193899aSPaolo Bonzini 3555193899aSPaolo Bonzini case 0x44: /* GPIO_LEVELDETECT1 */ 3565193899aSPaolo Bonzini return s->level[1]; 3575193899aSPaolo Bonzini 3585193899aSPaolo Bonzini case 0x48: /* GPIO_RISINGDETECT */ 3595193899aSPaolo Bonzini return s->edge[0]; 3605193899aSPaolo Bonzini 3615193899aSPaolo Bonzini case 0x4c: /* GPIO_FALLINGDETECT */ 3625193899aSPaolo Bonzini return s->edge[1]; 3635193899aSPaolo Bonzini 3645193899aSPaolo Bonzini case 0x50: /* GPIO_DEBOUNCENABLE */ 3655193899aSPaolo Bonzini return s->debounce; 3665193899aSPaolo Bonzini 3675193899aSPaolo Bonzini case 0x54: /* GPIO_DEBOUNCINGTIME */ 3685193899aSPaolo Bonzini return s->delay; 3695193899aSPaolo Bonzini } 3705193899aSPaolo Bonzini 3715193899aSPaolo Bonzini OMAP_BAD_REG(addr); 3725193899aSPaolo Bonzini return 0; 3735193899aSPaolo Bonzini } 3745193899aSPaolo Bonzini 3755193899aSPaolo Bonzini static void omap2_gpio_module_write(void *opaque, hwaddr addr, 3765193899aSPaolo Bonzini uint32_t value) 3775193899aSPaolo Bonzini { 3785193899aSPaolo Bonzini struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque; 3795193899aSPaolo Bonzini uint32_t diff; 3805193899aSPaolo Bonzini int ln; 3815193899aSPaolo Bonzini 3825193899aSPaolo Bonzini switch (addr) { 3835193899aSPaolo Bonzini case 0x00: /* GPIO_REVISION */ 3845193899aSPaolo Bonzini case 0x14: /* GPIO_SYSSTATUS */ 3855193899aSPaolo Bonzini case 0x38: /* GPIO_DATAIN */ 3865193899aSPaolo Bonzini OMAP_RO_REG(addr); 3875193899aSPaolo Bonzini break; 3885193899aSPaolo Bonzini 3895193899aSPaolo Bonzini case 0x10: /* GPIO_SYSCONFIG */ 3905193899aSPaolo Bonzini if (((value >> 3) & 3) == 3) 3915193899aSPaolo Bonzini fprintf(stderr, "%s: bad IDLEMODE value\n", __FUNCTION__); 3925193899aSPaolo Bonzini if (value & 2) 3935193899aSPaolo Bonzini omap2_gpio_module_reset(s); 3945193899aSPaolo Bonzini s->config[0] = value & 0x1d; 3955193899aSPaolo Bonzini break; 3965193899aSPaolo Bonzini 3975193899aSPaolo Bonzini case 0x18: /* GPIO_IRQSTATUS1 */ 3985193899aSPaolo Bonzini if (s->ints[0] & value) { 3995193899aSPaolo Bonzini s->ints[0] &= ~value; 4005193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4015193899aSPaolo Bonzini } 4025193899aSPaolo Bonzini break; 4035193899aSPaolo Bonzini 4045193899aSPaolo Bonzini case 0x1c: /* GPIO_IRQENABLE1 */ 4055193899aSPaolo Bonzini s->mask[0] = value; 4065193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 4075193899aSPaolo Bonzini break; 4085193899aSPaolo Bonzini 4095193899aSPaolo Bonzini case 0x20: /* GPIO_WAKEUPENABLE */ 4105193899aSPaolo Bonzini s->wumask = value; 4115193899aSPaolo Bonzini break; 4125193899aSPaolo Bonzini 4135193899aSPaolo Bonzini case 0x28: /* GPIO_IRQSTATUS2 */ 4145193899aSPaolo Bonzini if (s->ints[1] & value) { 4155193899aSPaolo Bonzini s->ints[1] &= ~value; 4165193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4175193899aSPaolo Bonzini } 4185193899aSPaolo Bonzini break; 4195193899aSPaolo Bonzini 4205193899aSPaolo Bonzini case 0x2c: /* GPIO_IRQENABLE2 */ 4215193899aSPaolo Bonzini s->mask[1] = value; 4225193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 4235193899aSPaolo Bonzini break; 4245193899aSPaolo Bonzini 4255193899aSPaolo Bonzini case 0x30: /* GPIO_CTRL */ 4265193899aSPaolo Bonzini s->config[1] = value & 7; 4275193899aSPaolo Bonzini break; 4285193899aSPaolo Bonzini 4295193899aSPaolo Bonzini case 0x34: /* GPIO_OE */ 4305193899aSPaolo Bonzini diff = s->outputs & (s->dir ^ value); 4315193899aSPaolo Bonzini s->dir = value; 4325193899aSPaolo Bonzini 4335193899aSPaolo Bonzini value = s->outputs & ~s->dir; 4345193899aSPaolo Bonzini while ((ln = ffs(diff))) { 4355193899aSPaolo Bonzini diff &= ~(1 <<-- ln); 4365193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (value >> ln) & 1); 4375193899aSPaolo Bonzini } 4385193899aSPaolo Bonzini 4395193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4405193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4415193899aSPaolo Bonzini break; 4425193899aSPaolo Bonzini 4435193899aSPaolo Bonzini case 0x3c: /* GPIO_DATAOUT */ 4445193899aSPaolo Bonzini omap2_gpio_module_out_update(s, s->outputs ^ value); 4455193899aSPaolo Bonzini break; 4465193899aSPaolo Bonzini 4475193899aSPaolo Bonzini case 0x40: /* GPIO_LEVELDETECT0 */ 4485193899aSPaolo Bonzini s->level[0] = value; 4495193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4505193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4515193899aSPaolo Bonzini break; 4525193899aSPaolo Bonzini 4535193899aSPaolo Bonzini case 0x44: /* GPIO_LEVELDETECT1 */ 4545193899aSPaolo Bonzini s->level[1] = value; 4555193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4565193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4575193899aSPaolo Bonzini break; 4585193899aSPaolo Bonzini 4595193899aSPaolo Bonzini case 0x48: /* GPIO_RISINGDETECT */ 4605193899aSPaolo Bonzini s->edge[0] = value; 4615193899aSPaolo Bonzini break; 4625193899aSPaolo Bonzini 4635193899aSPaolo Bonzini case 0x4c: /* GPIO_FALLINGDETECT */ 4645193899aSPaolo Bonzini s->edge[1] = value; 4655193899aSPaolo Bonzini break; 4665193899aSPaolo Bonzini 4675193899aSPaolo Bonzini case 0x50: /* GPIO_DEBOUNCENABLE */ 4685193899aSPaolo Bonzini s->debounce = value; 4695193899aSPaolo Bonzini break; 4705193899aSPaolo Bonzini 4715193899aSPaolo Bonzini case 0x54: /* GPIO_DEBOUNCINGTIME */ 4725193899aSPaolo Bonzini s->delay = value; 4735193899aSPaolo Bonzini break; 4745193899aSPaolo Bonzini 4755193899aSPaolo Bonzini case 0x60: /* GPIO_CLEARIRQENABLE1 */ 4765193899aSPaolo Bonzini s->mask[0] &= ~value; 4775193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 4785193899aSPaolo Bonzini break; 4795193899aSPaolo Bonzini 4805193899aSPaolo Bonzini case 0x64: /* GPIO_SETIRQENABLE1 */ 4815193899aSPaolo Bonzini s->mask[0] |= value; 4825193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 4835193899aSPaolo Bonzini break; 4845193899aSPaolo Bonzini 4855193899aSPaolo Bonzini case 0x70: /* GPIO_CLEARIRQENABLE2 */ 4865193899aSPaolo Bonzini s->mask[1] &= ~value; 4875193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 4885193899aSPaolo Bonzini break; 4895193899aSPaolo Bonzini 4905193899aSPaolo Bonzini case 0x74: /* GPIO_SETIREQNEABLE2 */ 4915193899aSPaolo Bonzini s->mask[1] |= value; 4925193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 4935193899aSPaolo Bonzini break; 4945193899aSPaolo Bonzini 4955193899aSPaolo Bonzini case 0x80: /* GPIO_CLEARWKUENA */ 4965193899aSPaolo Bonzini s->wumask &= ~value; 4975193899aSPaolo Bonzini break; 4985193899aSPaolo Bonzini 4995193899aSPaolo Bonzini case 0x84: /* GPIO_SETWKUENA */ 5005193899aSPaolo Bonzini s->wumask |= value; 5015193899aSPaolo Bonzini break; 5025193899aSPaolo Bonzini 5035193899aSPaolo Bonzini case 0x90: /* GPIO_CLEARDATAOUT */ 5045193899aSPaolo Bonzini omap2_gpio_module_out_update(s, s->outputs & value); 5055193899aSPaolo Bonzini break; 5065193899aSPaolo Bonzini 5075193899aSPaolo Bonzini case 0x94: /* GPIO_SETDATAOUT */ 5085193899aSPaolo Bonzini omap2_gpio_module_out_update(s, ~s->outputs & value); 5095193899aSPaolo Bonzini break; 5105193899aSPaolo Bonzini 5115193899aSPaolo Bonzini default: 5125193899aSPaolo Bonzini OMAP_BAD_REG(addr); 5135193899aSPaolo Bonzini return; 5145193899aSPaolo Bonzini } 5155193899aSPaolo Bonzini } 5165193899aSPaolo Bonzini 5175193899aSPaolo Bonzini static uint32_t omap2_gpio_module_readp(void *opaque, hwaddr addr) 5185193899aSPaolo Bonzini { 5195193899aSPaolo Bonzini return omap2_gpio_module_read(opaque, addr & ~3) >> ((addr & 3) << 3); 5205193899aSPaolo Bonzini } 5215193899aSPaolo Bonzini 5225193899aSPaolo Bonzini static void omap2_gpio_module_writep(void *opaque, hwaddr addr, 5235193899aSPaolo Bonzini uint32_t value) 5245193899aSPaolo Bonzini { 5255193899aSPaolo Bonzini uint32_t cur = 0; 5265193899aSPaolo Bonzini uint32_t mask = 0xffff; 5275193899aSPaolo Bonzini 5285193899aSPaolo Bonzini switch (addr & ~3) { 5295193899aSPaolo Bonzini case 0x00: /* GPIO_REVISION */ 5305193899aSPaolo Bonzini case 0x14: /* GPIO_SYSSTATUS */ 5315193899aSPaolo Bonzini case 0x38: /* GPIO_DATAIN */ 5325193899aSPaolo Bonzini OMAP_RO_REG(addr); 5335193899aSPaolo Bonzini break; 5345193899aSPaolo Bonzini 5355193899aSPaolo Bonzini case 0x10: /* GPIO_SYSCONFIG */ 5365193899aSPaolo Bonzini case 0x1c: /* GPIO_IRQENABLE1 */ 5375193899aSPaolo Bonzini case 0x20: /* GPIO_WAKEUPENABLE */ 5385193899aSPaolo Bonzini case 0x2c: /* GPIO_IRQENABLE2 */ 5395193899aSPaolo Bonzini case 0x30: /* GPIO_CTRL */ 5405193899aSPaolo Bonzini case 0x34: /* GPIO_OE */ 5415193899aSPaolo Bonzini case 0x3c: /* GPIO_DATAOUT */ 5425193899aSPaolo Bonzini case 0x40: /* GPIO_LEVELDETECT0 */ 5435193899aSPaolo Bonzini case 0x44: /* GPIO_LEVELDETECT1 */ 5445193899aSPaolo Bonzini case 0x48: /* GPIO_RISINGDETECT */ 5455193899aSPaolo Bonzini case 0x4c: /* GPIO_FALLINGDETECT */ 5465193899aSPaolo Bonzini case 0x50: /* GPIO_DEBOUNCENABLE */ 5475193899aSPaolo Bonzini case 0x54: /* GPIO_DEBOUNCINGTIME */ 5485193899aSPaolo Bonzini cur = omap2_gpio_module_read(opaque, addr & ~3) & 5495193899aSPaolo Bonzini ~(mask << ((addr & 3) << 3)); 5505193899aSPaolo Bonzini 5515193899aSPaolo Bonzini /* Fall through. */ 5525193899aSPaolo Bonzini case 0x18: /* GPIO_IRQSTATUS1 */ 5535193899aSPaolo Bonzini case 0x28: /* GPIO_IRQSTATUS2 */ 5545193899aSPaolo Bonzini case 0x60: /* GPIO_CLEARIRQENABLE1 */ 5555193899aSPaolo Bonzini case 0x64: /* GPIO_SETIRQENABLE1 */ 5565193899aSPaolo Bonzini case 0x70: /* GPIO_CLEARIRQENABLE2 */ 5575193899aSPaolo Bonzini case 0x74: /* GPIO_SETIREQNEABLE2 */ 5585193899aSPaolo Bonzini case 0x80: /* GPIO_CLEARWKUENA */ 5595193899aSPaolo Bonzini case 0x84: /* GPIO_SETWKUENA */ 5605193899aSPaolo Bonzini case 0x90: /* GPIO_CLEARDATAOUT */ 5615193899aSPaolo Bonzini case 0x94: /* GPIO_SETDATAOUT */ 5625193899aSPaolo Bonzini value <<= (addr & 3) << 3; 5635193899aSPaolo Bonzini omap2_gpio_module_write(opaque, addr, cur | value); 5645193899aSPaolo Bonzini break; 5655193899aSPaolo Bonzini 5665193899aSPaolo Bonzini default: 5675193899aSPaolo Bonzini OMAP_BAD_REG(addr); 5685193899aSPaolo Bonzini return; 5695193899aSPaolo Bonzini } 5705193899aSPaolo Bonzini } 5715193899aSPaolo Bonzini 5725193899aSPaolo Bonzini static const MemoryRegionOps omap2_gpio_module_ops = { 5735193899aSPaolo Bonzini .old_mmio = { 5745193899aSPaolo Bonzini .read = { 5755193899aSPaolo Bonzini omap2_gpio_module_readp, 5765193899aSPaolo Bonzini omap2_gpio_module_readp, 5775193899aSPaolo Bonzini omap2_gpio_module_read, 5785193899aSPaolo Bonzini }, 5795193899aSPaolo Bonzini .write = { 5805193899aSPaolo Bonzini omap2_gpio_module_writep, 5815193899aSPaolo Bonzini omap2_gpio_module_writep, 5825193899aSPaolo Bonzini omap2_gpio_module_write, 5835193899aSPaolo Bonzini }, 5845193899aSPaolo Bonzini }, 5855193899aSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 5865193899aSPaolo Bonzini }; 5875193899aSPaolo Bonzini 5885193899aSPaolo Bonzini static void omap_gpif_reset(DeviceState *dev) 5895193899aSPaolo Bonzini { 5905193899aSPaolo Bonzini struct omap_gpif_s *s = FROM_SYSBUS(struct omap_gpif_s, 5915193899aSPaolo Bonzini SYS_BUS_DEVICE(dev)); 5925193899aSPaolo Bonzini omap_gpio_reset(&s->omap1); 5935193899aSPaolo Bonzini } 5945193899aSPaolo Bonzini 5955193899aSPaolo Bonzini static void omap2_gpif_reset(DeviceState *dev) 5965193899aSPaolo Bonzini { 5975193899aSPaolo Bonzini int i; 5985193899aSPaolo Bonzini struct omap2_gpif_s *s = FROM_SYSBUS(struct omap2_gpif_s, 5995193899aSPaolo Bonzini SYS_BUS_DEVICE(dev)); 6005193899aSPaolo Bonzini for (i = 0; i < s->modulecount; i++) { 6015193899aSPaolo Bonzini omap2_gpio_module_reset(&s->modules[i]); 6025193899aSPaolo Bonzini } 6035193899aSPaolo Bonzini s->autoidle = 0; 6045193899aSPaolo Bonzini s->gpo = 0; 6055193899aSPaolo Bonzini } 6065193899aSPaolo Bonzini 6075193899aSPaolo Bonzini static uint64_t omap2_gpif_top_read(void *opaque, hwaddr addr, 6085193899aSPaolo Bonzini unsigned size) 6095193899aSPaolo Bonzini { 6105193899aSPaolo Bonzini struct omap2_gpif_s *s = (struct omap2_gpif_s *) opaque; 6115193899aSPaolo Bonzini 6125193899aSPaolo Bonzini switch (addr) { 6135193899aSPaolo Bonzini case 0x00: /* IPGENERICOCPSPL_REVISION */ 6145193899aSPaolo Bonzini return 0x18; 6155193899aSPaolo Bonzini 6165193899aSPaolo Bonzini case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */ 6175193899aSPaolo Bonzini return s->autoidle; 6185193899aSPaolo Bonzini 6195193899aSPaolo Bonzini case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */ 6205193899aSPaolo Bonzini return 0x01; 6215193899aSPaolo Bonzini 6225193899aSPaolo Bonzini case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */ 6235193899aSPaolo Bonzini return 0x00; 6245193899aSPaolo Bonzini 6255193899aSPaolo Bonzini case 0x40: /* IPGENERICOCPSPL_GPO */ 6265193899aSPaolo Bonzini return s->gpo; 6275193899aSPaolo Bonzini 6285193899aSPaolo Bonzini case 0x50: /* IPGENERICOCPSPL_GPI */ 6295193899aSPaolo Bonzini return 0x00; 6305193899aSPaolo Bonzini } 6315193899aSPaolo Bonzini 6325193899aSPaolo Bonzini OMAP_BAD_REG(addr); 6335193899aSPaolo Bonzini return 0; 6345193899aSPaolo Bonzini } 6355193899aSPaolo Bonzini 6365193899aSPaolo Bonzini static void omap2_gpif_top_write(void *opaque, hwaddr addr, 6375193899aSPaolo Bonzini uint64_t value, unsigned size) 6385193899aSPaolo Bonzini { 6395193899aSPaolo Bonzini struct omap2_gpif_s *s = (struct omap2_gpif_s *) opaque; 6405193899aSPaolo Bonzini 6415193899aSPaolo Bonzini switch (addr) { 6425193899aSPaolo Bonzini case 0x00: /* IPGENERICOCPSPL_REVISION */ 6435193899aSPaolo Bonzini case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */ 6445193899aSPaolo Bonzini case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */ 6455193899aSPaolo Bonzini case 0x50: /* IPGENERICOCPSPL_GPI */ 6465193899aSPaolo Bonzini OMAP_RO_REG(addr); 6475193899aSPaolo Bonzini break; 6485193899aSPaolo Bonzini 6495193899aSPaolo Bonzini case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */ 6505193899aSPaolo Bonzini if (value & (1 << 1)) /* SOFTRESET */ 6515193899aSPaolo Bonzini omap2_gpif_reset(&s->busdev.qdev); 6525193899aSPaolo Bonzini s->autoidle = value & 1; 6535193899aSPaolo Bonzini break; 6545193899aSPaolo Bonzini 6555193899aSPaolo Bonzini case 0x40: /* IPGENERICOCPSPL_GPO */ 6565193899aSPaolo Bonzini s->gpo = value & 1; 6575193899aSPaolo Bonzini break; 6585193899aSPaolo Bonzini 6595193899aSPaolo Bonzini default: 6605193899aSPaolo Bonzini OMAP_BAD_REG(addr); 6615193899aSPaolo Bonzini return; 6625193899aSPaolo Bonzini } 6635193899aSPaolo Bonzini } 6645193899aSPaolo Bonzini 6655193899aSPaolo Bonzini static const MemoryRegionOps omap2_gpif_top_ops = { 6665193899aSPaolo Bonzini .read = omap2_gpif_top_read, 6675193899aSPaolo Bonzini .write = omap2_gpif_top_write, 6685193899aSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 6695193899aSPaolo Bonzini }; 6705193899aSPaolo Bonzini 6715193899aSPaolo Bonzini static int omap_gpio_init(SysBusDevice *dev) 6725193899aSPaolo Bonzini { 6735193899aSPaolo Bonzini struct omap_gpif_s *s = FROM_SYSBUS(struct omap_gpif_s, dev); 6745193899aSPaolo Bonzini if (!s->clk) { 6755193899aSPaolo Bonzini hw_error("omap-gpio: clk not connected\n"); 6765193899aSPaolo Bonzini } 6775193899aSPaolo Bonzini qdev_init_gpio_in(&dev->qdev, omap_gpio_set, 16); 6785193899aSPaolo Bonzini qdev_init_gpio_out(&dev->qdev, s->omap1.handler, 16); 6795193899aSPaolo Bonzini sysbus_init_irq(dev, &s->omap1.irq); 680*b7163687SPaolo Bonzini memory_region_init_io(&s->iomem, OBJECT(s), &omap_gpio_ops, &s->omap1, 6815193899aSPaolo Bonzini "omap.gpio", 0x1000); 6825193899aSPaolo Bonzini sysbus_init_mmio(dev, &s->iomem); 6835193899aSPaolo Bonzini return 0; 6845193899aSPaolo Bonzini } 6855193899aSPaolo Bonzini 6865193899aSPaolo Bonzini static int omap2_gpio_init(SysBusDevice *dev) 6875193899aSPaolo Bonzini { 6885193899aSPaolo Bonzini int i; 6895193899aSPaolo Bonzini struct omap2_gpif_s *s = FROM_SYSBUS(struct omap2_gpif_s, dev); 6905193899aSPaolo Bonzini if (!s->iclk) { 6915193899aSPaolo Bonzini hw_error("omap2-gpio: iclk not connected\n"); 6925193899aSPaolo Bonzini } 6935193899aSPaolo Bonzini if (s->mpu_model < omap3430) { 6945193899aSPaolo Bonzini s->modulecount = (s->mpu_model < omap2430) ? 4 : 5; 695*b7163687SPaolo Bonzini memory_region_init_io(&s->iomem, OBJECT(s), &omap2_gpif_top_ops, s, 6965193899aSPaolo Bonzini "omap2.gpio", 0x1000); 6975193899aSPaolo Bonzini sysbus_init_mmio(dev, &s->iomem); 6985193899aSPaolo Bonzini } else { 6995193899aSPaolo Bonzini s->modulecount = 6; 7005193899aSPaolo Bonzini } 7015193899aSPaolo Bonzini s->modules = g_malloc0(s->modulecount * sizeof(struct omap2_gpio_s)); 7025193899aSPaolo Bonzini s->handler = g_malloc0(s->modulecount * 32 * sizeof(qemu_irq)); 7035193899aSPaolo Bonzini qdev_init_gpio_in(&dev->qdev, omap2_gpio_set, s->modulecount * 32); 7045193899aSPaolo Bonzini qdev_init_gpio_out(&dev->qdev, s->handler, s->modulecount * 32); 7055193899aSPaolo Bonzini for (i = 0; i < s->modulecount; i++) { 7065193899aSPaolo Bonzini struct omap2_gpio_s *m = &s->modules[i]; 7075193899aSPaolo Bonzini if (!s->fclk[i]) { 7085193899aSPaolo Bonzini hw_error("omap2-gpio: fclk%d not connected\n", i); 7095193899aSPaolo Bonzini } 7105193899aSPaolo Bonzini m->revision = (s->mpu_model < omap3430) ? 0x18 : 0x25; 7115193899aSPaolo Bonzini m->handler = &s->handler[i * 32]; 7125193899aSPaolo Bonzini sysbus_init_irq(dev, &m->irq[0]); /* mpu irq */ 7135193899aSPaolo Bonzini sysbus_init_irq(dev, &m->irq[1]); /* dsp irq */ 7145193899aSPaolo Bonzini sysbus_init_irq(dev, &m->wkup); 715*b7163687SPaolo Bonzini memory_region_init_io(&m->iomem, OBJECT(s), &omap2_gpio_module_ops, m, 7165193899aSPaolo Bonzini "omap.gpio-module", 0x1000); 7175193899aSPaolo Bonzini sysbus_init_mmio(dev, &m->iomem); 7185193899aSPaolo Bonzini } 7195193899aSPaolo Bonzini return 0; 7205193899aSPaolo Bonzini } 7215193899aSPaolo Bonzini 7225193899aSPaolo Bonzini /* Using qdev pointer properties for the clocks is not ideal. 7235193899aSPaolo Bonzini * qdev should support a generic means of defining a 'port' with 7245193899aSPaolo Bonzini * an arbitrary interface for connecting two devices. Then we 7255193899aSPaolo Bonzini * could reframe the omap clock API in terms of clock ports, 7265193899aSPaolo Bonzini * and get some type safety. For now the best qdev provides is 7275193899aSPaolo Bonzini * passing an arbitrary pointer. 7285193899aSPaolo Bonzini * (It's not possible to pass in the string which is the clock 7295193899aSPaolo Bonzini * name, because this device does not have the necessary information 7305193899aSPaolo Bonzini * (ie the struct omap_mpu_state_s*) to do the clockname to pointer 7315193899aSPaolo Bonzini * translation.) 7325193899aSPaolo Bonzini */ 7335193899aSPaolo Bonzini 7345193899aSPaolo Bonzini static Property omap_gpio_properties[] = { 7355193899aSPaolo Bonzini DEFINE_PROP_INT32("mpu_model", struct omap_gpif_s, mpu_model, 0), 7365193899aSPaolo Bonzini DEFINE_PROP_PTR("clk", struct omap_gpif_s, clk), 7375193899aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 7385193899aSPaolo Bonzini }; 7395193899aSPaolo Bonzini 7405193899aSPaolo Bonzini static void omap_gpio_class_init(ObjectClass *klass, void *data) 7415193899aSPaolo Bonzini { 7425193899aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 7435193899aSPaolo Bonzini SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 7445193899aSPaolo Bonzini 7455193899aSPaolo Bonzini k->init = omap_gpio_init; 7465193899aSPaolo Bonzini dc->reset = omap_gpif_reset; 7475193899aSPaolo Bonzini dc->props = omap_gpio_properties; 7485193899aSPaolo Bonzini } 7495193899aSPaolo Bonzini 7505193899aSPaolo Bonzini static const TypeInfo omap_gpio_info = { 7515193899aSPaolo Bonzini .name = "omap-gpio", 7525193899aSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 7535193899aSPaolo Bonzini .instance_size = sizeof(struct omap_gpif_s), 7545193899aSPaolo Bonzini .class_init = omap_gpio_class_init, 7555193899aSPaolo Bonzini }; 7565193899aSPaolo Bonzini 7575193899aSPaolo Bonzini static Property omap2_gpio_properties[] = { 7585193899aSPaolo Bonzini DEFINE_PROP_INT32("mpu_model", struct omap2_gpif_s, mpu_model, 0), 7595193899aSPaolo Bonzini DEFINE_PROP_PTR("iclk", struct omap2_gpif_s, iclk), 7605193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk0", struct omap2_gpif_s, fclk[0]), 7615193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk1", struct omap2_gpif_s, fclk[1]), 7625193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk2", struct omap2_gpif_s, fclk[2]), 7635193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk3", struct omap2_gpif_s, fclk[3]), 7645193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk4", struct omap2_gpif_s, fclk[4]), 7655193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk5", struct omap2_gpif_s, fclk[5]), 7665193899aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 7675193899aSPaolo Bonzini }; 7685193899aSPaolo Bonzini 7695193899aSPaolo Bonzini static void omap2_gpio_class_init(ObjectClass *klass, void *data) 7705193899aSPaolo Bonzini { 7715193899aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 7725193899aSPaolo Bonzini SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 7735193899aSPaolo Bonzini 7745193899aSPaolo Bonzini k->init = omap2_gpio_init; 7755193899aSPaolo Bonzini dc->reset = omap2_gpif_reset; 7765193899aSPaolo Bonzini dc->props = omap2_gpio_properties; 7775193899aSPaolo Bonzini } 7785193899aSPaolo Bonzini 7795193899aSPaolo Bonzini static const TypeInfo omap2_gpio_info = { 7805193899aSPaolo Bonzini .name = "omap2-gpio", 7815193899aSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 7825193899aSPaolo Bonzini .instance_size = sizeof(struct omap2_gpif_s), 7835193899aSPaolo Bonzini .class_init = omap2_gpio_class_init, 7845193899aSPaolo Bonzini }; 7855193899aSPaolo Bonzini 7865193899aSPaolo Bonzini static void omap_gpio_register_types(void) 7875193899aSPaolo Bonzini { 7885193899aSPaolo Bonzini type_register_static(&omap_gpio_info); 7895193899aSPaolo Bonzini type_register_static(&omap2_gpio_info); 7905193899aSPaolo Bonzini } 7915193899aSPaolo Bonzini 7925193899aSPaolo Bonzini type_init(omap_gpio_register_types) 793