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 381d300b5fSAndreas Färber #define TYPE_OMAP1_GPIO "omap-gpio" 391d300b5fSAndreas Färber #define OMAP1_GPIO(obj) \ 401d300b5fSAndreas Färber OBJECT_CHECK(struct omap_gpif_s, (obj), TYPE_OMAP1_GPIO) 411d300b5fSAndreas Färber 425193899aSPaolo Bonzini struct omap_gpif_s { 431d300b5fSAndreas Färber SysBusDevice parent_obj; 441d300b5fSAndreas Färber 455193899aSPaolo Bonzini MemoryRegion iomem; 465193899aSPaolo Bonzini int mpu_model; 475193899aSPaolo Bonzini void *clk; 485193899aSPaolo Bonzini struct omap_gpio_s omap1; 495193899aSPaolo Bonzini }; 505193899aSPaolo Bonzini 515193899aSPaolo Bonzini /* General-Purpose I/O of OMAP1 */ 525193899aSPaolo Bonzini static void omap_gpio_set(void *opaque, int line, int level) 535193899aSPaolo Bonzini { 545193899aSPaolo Bonzini struct omap_gpio_s *s = &((struct omap_gpif_s *) opaque)->omap1; 555193899aSPaolo Bonzini uint16_t prev = s->inputs; 565193899aSPaolo Bonzini 575193899aSPaolo Bonzini if (level) 585193899aSPaolo Bonzini s->inputs |= 1 << line; 595193899aSPaolo Bonzini else 605193899aSPaolo Bonzini s->inputs &= ~(1 << line); 615193899aSPaolo Bonzini 625193899aSPaolo Bonzini if (((s->edge & s->inputs & ~prev) | (~s->edge & ~s->inputs & prev)) & 635193899aSPaolo Bonzini (1 << line) & s->dir & ~s->mask) { 645193899aSPaolo Bonzini s->ints |= 1 << line; 655193899aSPaolo Bonzini qemu_irq_raise(s->irq); 665193899aSPaolo Bonzini } 675193899aSPaolo Bonzini } 685193899aSPaolo Bonzini 695193899aSPaolo Bonzini static uint64_t omap_gpio_read(void *opaque, hwaddr addr, 705193899aSPaolo Bonzini unsigned size) 715193899aSPaolo Bonzini { 725193899aSPaolo Bonzini struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; 735193899aSPaolo Bonzini int offset = addr & OMAP_MPUI_REG_MASK; 745193899aSPaolo Bonzini 755193899aSPaolo Bonzini if (size != 2) { 765193899aSPaolo Bonzini return omap_badwidth_read16(opaque, addr); 775193899aSPaolo Bonzini } 785193899aSPaolo Bonzini 795193899aSPaolo Bonzini switch (offset) { 805193899aSPaolo Bonzini case 0x00: /* DATA_INPUT */ 815193899aSPaolo Bonzini return s->inputs & s->pins; 825193899aSPaolo Bonzini 835193899aSPaolo Bonzini case 0x04: /* DATA_OUTPUT */ 845193899aSPaolo Bonzini return s->outputs; 855193899aSPaolo Bonzini 865193899aSPaolo Bonzini case 0x08: /* DIRECTION_CONTROL */ 875193899aSPaolo Bonzini return s->dir; 885193899aSPaolo Bonzini 895193899aSPaolo Bonzini case 0x0c: /* INTERRUPT_CONTROL */ 905193899aSPaolo Bonzini return s->edge; 915193899aSPaolo Bonzini 925193899aSPaolo Bonzini case 0x10: /* INTERRUPT_MASK */ 935193899aSPaolo Bonzini return s->mask; 945193899aSPaolo Bonzini 955193899aSPaolo Bonzini case 0x14: /* INTERRUPT_STATUS */ 965193899aSPaolo Bonzini return s->ints; 975193899aSPaolo Bonzini 985193899aSPaolo Bonzini case 0x18: /* PIN_CONTROL (not in OMAP310) */ 995193899aSPaolo Bonzini OMAP_BAD_REG(addr); 1005193899aSPaolo Bonzini return s->pins; 1015193899aSPaolo Bonzini } 1025193899aSPaolo Bonzini 1035193899aSPaolo Bonzini OMAP_BAD_REG(addr); 1045193899aSPaolo Bonzini return 0; 1055193899aSPaolo Bonzini } 1065193899aSPaolo Bonzini 1075193899aSPaolo Bonzini static void omap_gpio_write(void *opaque, hwaddr addr, 1085193899aSPaolo Bonzini uint64_t value, unsigned size) 1095193899aSPaolo Bonzini { 1105193899aSPaolo Bonzini struct omap_gpio_s *s = (struct omap_gpio_s *) opaque; 1115193899aSPaolo Bonzini int offset = addr & OMAP_MPUI_REG_MASK; 1125193899aSPaolo Bonzini uint16_t diff; 1135193899aSPaolo Bonzini int ln; 1145193899aSPaolo Bonzini 1155193899aSPaolo Bonzini if (size != 2) { 11677a8257eSStefan Weil omap_badwidth_write16(opaque, addr, value); 11777a8257eSStefan Weil return; 1185193899aSPaolo Bonzini } 1195193899aSPaolo Bonzini 1205193899aSPaolo Bonzini switch (offset) { 1215193899aSPaolo Bonzini case 0x00: /* DATA_INPUT */ 1225193899aSPaolo Bonzini OMAP_RO_REG(addr); 1235193899aSPaolo Bonzini return; 1245193899aSPaolo Bonzini 1255193899aSPaolo Bonzini case 0x04: /* DATA_OUTPUT */ 1265193899aSPaolo Bonzini diff = (s->outputs ^ value) & ~s->dir; 1275193899aSPaolo Bonzini s->outputs = value; 128bd2a8884SStefan Hajnoczi while ((ln = ctz32(diff)) != 32) { 1295193899aSPaolo Bonzini if (s->handler[ln]) 1305193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (value >> ln) & 1); 1315193899aSPaolo Bonzini diff &= ~(1 << ln); 1325193899aSPaolo Bonzini } 1335193899aSPaolo Bonzini break; 1345193899aSPaolo Bonzini 1355193899aSPaolo Bonzini case 0x08: /* DIRECTION_CONTROL */ 1365193899aSPaolo Bonzini diff = s->outputs & (s->dir ^ value); 1375193899aSPaolo Bonzini s->dir = value; 1385193899aSPaolo Bonzini 1395193899aSPaolo Bonzini value = s->outputs & ~s->dir; 140bd2a8884SStefan Hajnoczi while ((ln = ctz32(diff)) != 32) { 1415193899aSPaolo Bonzini if (s->handler[ln]) 1425193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (value >> ln) & 1); 1435193899aSPaolo Bonzini diff &= ~(1 << ln); 1445193899aSPaolo Bonzini } 1455193899aSPaolo Bonzini break; 1465193899aSPaolo Bonzini 1475193899aSPaolo Bonzini case 0x0c: /* INTERRUPT_CONTROL */ 1485193899aSPaolo Bonzini s->edge = value; 1495193899aSPaolo Bonzini break; 1505193899aSPaolo Bonzini 1515193899aSPaolo Bonzini case 0x10: /* INTERRUPT_MASK */ 1525193899aSPaolo Bonzini s->mask = value; 1535193899aSPaolo Bonzini break; 1545193899aSPaolo Bonzini 1555193899aSPaolo Bonzini case 0x14: /* INTERRUPT_STATUS */ 1565193899aSPaolo Bonzini s->ints &= ~value; 1575193899aSPaolo Bonzini if (!s->ints) 1585193899aSPaolo Bonzini qemu_irq_lower(s->irq); 1595193899aSPaolo Bonzini break; 1605193899aSPaolo Bonzini 1615193899aSPaolo Bonzini case 0x18: /* PIN_CONTROL (not in OMAP310 TRM) */ 1625193899aSPaolo Bonzini OMAP_BAD_REG(addr); 1635193899aSPaolo Bonzini s->pins = value; 1645193899aSPaolo Bonzini break; 1655193899aSPaolo Bonzini 1665193899aSPaolo Bonzini default: 1675193899aSPaolo Bonzini OMAP_BAD_REG(addr); 1685193899aSPaolo Bonzini return; 1695193899aSPaolo Bonzini } 1705193899aSPaolo Bonzini } 1715193899aSPaolo Bonzini 1725193899aSPaolo Bonzini /* *Some* sources say the memory region is 32-bit. */ 1735193899aSPaolo Bonzini static const MemoryRegionOps omap_gpio_ops = { 1745193899aSPaolo Bonzini .read = omap_gpio_read, 1755193899aSPaolo Bonzini .write = omap_gpio_write, 1765193899aSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 1775193899aSPaolo Bonzini }; 1785193899aSPaolo Bonzini 1795193899aSPaolo Bonzini static void omap_gpio_reset(struct omap_gpio_s *s) 1805193899aSPaolo Bonzini { 1815193899aSPaolo Bonzini s->inputs = 0; 1825193899aSPaolo Bonzini s->outputs = ~0; 1835193899aSPaolo Bonzini s->dir = ~0; 1845193899aSPaolo Bonzini s->edge = ~0; 1855193899aSPaolo Bonzini s->mask = ~0; 1865193899aSPaolo Bonzini s->ints = 0; 1875193899aSPaolo Bonzini s->pins = ~0; 1885193899aSPaolo Bonzini } 1895193899aSPaolo Bonzini 1905193899aSPaolo Bonzini struct omap2_gpio_s { 1915193899aSPaolo Bonzini qemu_irq irq[2]; 1925193899aSPaolo Bonzini qemu_irq wkup; 1935193899aSPaolo Bonzini qemu_irq *handler; 1945193899aSPaolo Bonzini MemoryRegion iomem; 1955193899aSPaolo Bonzini 1965193899aSPaolo Bonzini uint8_t revision; 1975193899aSPaolo Bonzini uint8_t config[2]; 1985193899aSPaolo Bonzini uint32_t inputs; 1995193899aSPaolo Bonzini uint32_t outputs; 2005193899aSPaolo Bonzini uint32_t dir; 2015193899aSPaolo Bonzini uint32_t level[2]; 2025193899aSPaolo Bonzini uint32_t edge[2]; 2035193899aSPaolo Bonzini uint32_t mask[2]; 2045193899aSPaolo Bonzini uint32_t wumask; 2055193899aSPaolo Bonzini uint32_t ints[2]; 2065193899aSPaolo Bonzini uint32_t debounce; 2075193899aSPaolo Bonzini uint8_t delay; 2085193899aSPaolo Bonzini }; 2095193899aSPaolo Bonzini 21074d1e352SAndreas Färber #define TYPE_OMAP2_GPIO "omap2-gpio" 21174d1e352SAndreas Färber #define OMAP2_GPIO(obj) \ 21274d1e352SAndreas Färber OBJECT_CHECK(struct omap2_gpif_s, (obj), TYPE_OMAP2_GPIO) 21374d1e352SAndreas Färber 2145193899aSPaolo Bonzini struct omap2_gpif_s { 21574d1e352SAndreas Färber SysBusDevice parent_obj; 21674d1e352SAndreas Färber 2175193899aSPaolo Bonzini MemoryRegion iomem; 2185193899aSPaolo Bonzini int mpu_model; 2195193899aSPaolo Bonzini void *iclk; 2205193899aSPaolo Bonzini void *fclk[6]; 2215193899aSPaolo Bonzini int modulecount; 2225193899aSPaolo Bonzini struct omap2_gpio_s *modules; 2235193899aSPaolo Bonzini qemu_irq *handler; 2245193899aSPaolo Bonzini int autoidle; 2255193899aSPaolo Bonzini int gpo; 2265193899aSPaolo Bonzini }; 2275193899aSPaolo Bonzini 2285193899aSPaolo Bonzini /* General-Purpose Interface of OMAP2/3 */ 2295193899aSPaolo Bonzini static inline void omap2_gpio_module_int_update(struct omap2_gpio_s *s, 2305193899aSPaolo Bonzini int line) 2315193899aSPaolo Bonzini { 2325193899aSPaolo Bonzini qemu_set_irq(s->irq[line], s->ints[line] & s->mask[line]); 2335193899aSPaolo Bonzini } 2345193899aSPaolo Bonzini 2355193899aSPaolo Bonzini static void omap2_gpio_module_wake(struct omap2_gpio_s *s, int line) 2365193899aSPaolo Bonzini { 2375193899aSPaolo Bonzini if (!(s->config[0] & (1 << 2))) /* ENAWAKEUP */ 2385193899aSPaolo Bonzini return; 2395193899aSPaolo Bonzini if (!(s->config[0] & (3 << 3))) /* Force Idle */ 2405193899aSPaolo Bonzini return; 2415193899aSPaolo Bonzini if (!(s->wumask & (1 << line))) 2425193899aSPaolo Bonzini return; 2435193899aSPaolo Bonzini 2445193899aSPaolo Bonzini qemu_irq_raise(s->wkup); 2455193899aSPaolo Bonzini } 2465193899aSPaolo Bonzini 2475193899aSPaolo Bonzini static inline void omap2_gpio_module_out_update(struct omap2_gpio_s *s, 2485193899aSPaolo Bonzini uint32_t diff) 2495193899aSPaolo Bonzini { 2505193899aSPaolo Bonzini int ln; 2515193899aSPaolo Bonzini 2525193899aSPaolo Bonzini s->outputs ^= diff; 2535193899aSPaolo Bonzini diff &= ~s->dir; 254bd2a8884SStefan Hajnoczi while ((ln = ctz32(diff)) != 32) { 2555193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (s->outputs >> ln) & 1); 2565193899aSPaolo Bonzini diff &= ~(1 << ln); 2575193899aSPaolo Bonzini } 2585193899aSPaolo Bonzini } 2595193899aSPaolo Bonzini 2605193899aSPaolo Bonzini static void omap2_gpio_module_level_update(struct omap2_gpio_s *s, int line) 2615193899aSPaolo Bonzini { 2625193899aSPaolo Bonzini s->ints[line] |= s->dir & 2635193899aSPaolo Bonzini ((s->inputs & s->level[1]) | (~s->inputs & s->level[0])); 2645193899aSPaolo Bonzini omap2_gpio_module_int_update(s, line); 2655193899aSPaolo Bonzini } 2665193899aSPaolo Bonzini 2675193899aSPaolo Bonzini static inline void omap2_gpio_module_int(struct omap2_gpio_s *s, int line) 2685193899aSPaolo Bonzini { 2695193899aSPaolo Bonzini s->ints[0] |= 1 << line; 2705193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 2715193899aSPaolo Bonzini s->ints[1] |= 1 << line; 2725193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 2735193899aSPaolo Bonzini omap2_gpio_module_wake(s, line); 2745193899aSPaolo Bonzini } 2755193899aSPaolo Bonzini 2765193899aSPaolo Bonzini static void omap2_gpio_set(void *opaque, int line, int level) 2775193899aSPaolo Bonzini { 2785193899aSPaolo Bonzini struct omap2_gpif_s *p = opaque; 2795193899aSPaolo Bonzini struct omap2_gpio_s *s = &p->modules[line >> 5]; 2805193899aSPaolo Bonzini 2815193899aSPaolo Bonzini line &= 31; 2825193899aSPaolo Bonzini if (level) { 2835193899aSPaolo Bonzini if (s->dir & (1 << line) & ((~s->inputs & s->edge[0]) | s->level[1])) 2845193899aSPaolo Bonzini omap2_gpio_module_int(s, line); 2855193899aSPaolo Bonzini s->inputs |= 1 << line; 2865193899aSPaolo Bonzini } else { 2875193899aSPaolo Bonzini if (s->dir & (1 << line) & ((s->inputs & s->edge[1]) | s->level[0])) 2885193899aSPaolo Bonzini omap2_gpio_module_int(s, line); 2895193899aSPaolo Bonzini s->inputs &= ~(1 << line); 2905193899aSPaolo Bonzini } 2915193899aSPaolo Bonzini } 2925193899aSPaolo Bonzini 2935193899aSPaolo Bonzini static void omap2_gpio_module_reset(struct omap2_gpio_s *s) 2945193899aSPaolo Bonzini { 2955193899aSPaolo Bonzini s->config[0] = 0; 2965193899aSPaolo Bonzini s->config[1] = 2; 2975193899aSPaolo Bonzini s->ints[0] = 0; 2985193899aSPaolo Bonzini s->ints[1] = 0; 2995193899aSPaolo Bonzini s->mask[0] = 0; 3005193899aSPaolo Bonzini s->mask[1] = 0; 3015193899aSPaolo Bonzini s->wumask = 0; 3025193899aSPaolo Bonzini s->dir = ~0; 3035193899aSPaolo Bonzini s->level[0] = 0; 3045193899aSPaolo Bonzini s->level[1] = 0; 3055193899aSPaolo Bonzini s->edge[0] = 0; 3065193899aSPaolo Bonzini s->edge[1] = 0; 3075193899aSPaolo Bonzini s->debounce = 0; 3085193899aSPaolo Bonzini s->delay = 0; 3095193899aSPaolo Bonzini } 3105193899aSPaolo Bonzini 3115193899aSPaolo Bonzini static uint32_t omap2_gpio_module_read(void *opaque, hwaddr addr) 3125193899aSPaolo Bonzini { 3135193899aSPaolo Bonzini struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque; 3145193899aSPaolo Bonzini 3155193899aSPaolo Bonzini switch (addr) { 3165193899aSPaolo Bonzini case 0x00: /* GPIO_REVISION */ 3175193899aSPaolo Bonzini return s->revision; 3185193899aSPaolo Bonzini 3195193899aSPaolo Bonzini case 0x10: /* GPIO_SYSCONFIG */ 3205193899aSPaolo Bonzini return s->config[0]; 3215193899aSPaolo Bonzini 3225193899aSPaolo Bonzini case 0x14: /* GPIO_SYSSTATUS */ 3235193899aSPaolo Bonzini return 0x01; 3245193899aSPaolo Bonzini 3255193899aSPaolo Bonzini case 0x18: /* GPIO_IRQSTATUS1 */ 3265193899aSPaolo Bonzini return s->ints[0]; 3275193899aSPaolo Bonzini 3285193899aSPaolo Bonzini case 0x1c: /* GPIO_IRQENABLE1 */ 3295193899aSPaolo Bonzini case 0x60: /* GPIO_CLEARIRQENABLE1 */ 3305193899aSPaolo Bonzini case 0x64: /* GPIO_SETIRQENABLE1 */ 3315193899aSPaolo Bonzini return s->mask[0]; 3325193899aSPaolo Bonzini 3335193899aSPaolo Bonzini case 0x20: /* GPIO_WAKEUPENABLE */ 3345193899aSPaolo Bonzini case 0x80: /* GPIO_CLEARWKUENA */ 3355193899aSPaolo Bonzini case 0x84: /* GPIO_SETWKUENA */ 3365193899aSPaolo Bonzini return s->wumask; 3375193899aSPaolo Bonzini 3385193899aSPaolo Bonzini case 0x28: /* GPIO_IRQSTATUS2 */ 3395193899aSPaolo Bonzini return s->ints[1]; 3405193899aSPaolo Bonzini 3415193899aSPaolo Bonzini case 0x2c: /* GPIO_IRQENABLE2 */ 3425193899aSPaolo Bonzini case 0x70: /* GPIO_CLEARIRQENABLE2 */ 3435193899aSPaolo Bonzini case 0x74: /* GPIO_SETIREQNEABLE2 */ 3445193899aSPaolo Bonzini return s->mask[1]; 3455193899aSPaolo Bonzini 3465193899aSPaolo Bonzini case 0x30: /* GPIO_CTRL */ 3475193899aSPaolo Bonzini return s->config[1]; 3485193899aSPaolo Bonzini 3495193899aSPaolo Bonzini case 0x34: /* GPIO_OE */ 3505193899aSPaolo Bonzini return s->dir; 3515193899aSPaolo Bonzini 3525193899aSPaolo Bonzini case 0x38: /* GPIO_DATAIN */ 3535193899aSPaolo Bonzini return s->inputs; 3545193899aSPaolo Bonzini 3555193899aSPaolo Bonzini case 0x3c: /* GPIO_DATAOUT */ 3565193899aSPaolo Bonzini case 0x90: /* GPIO_CLEARDATAOUT */ 3575193899aSPaolo Bonzini case 0x94: /* GPIO_SETDATAOUT */ 3585193899aSPaolo Bonzini return s->outputs; 3595193899aSPaolo Bonzini 3605193899aSPaolo Bonzini case 0x40: /* GPIO_LEVELDETECT0 */ 3615193899aSPaolo Bonzini return s->level[0]; 3625193899aSPaolo Bonzini 3635193899aSPaolo Bonzini case 0x44: /* GPIO_LEVELDETECT1 */ 3645193899aSPaolo Bonzini return s->level[1]; 3655193899aSPaolo Bonzini 3665193899aSPaolo Bonzini case 0x48: /* GPIO_RISINGDETECT */ 3675193899aSPaolo Bonzini return s->edge[0]; 3685193899aSPaolo Bonzini 3695193899aSPaolo Bonzini case 0x4c: /* GPIO_FALLINGDETECT */ 3705193899aSPaolo Bonzini return s->edge[1]; 3715193899aSPaolo Bonzini 3725193899aSPaolo Bonzini case 0x50: /* GPIO_DEBOUNCENABLE */ 3735193899aSPaolo Bonzini return s->debounce; 3745193899aSPaolo Bonzini 3755193899aSPaolo Bonzini case 0x54: /* GPIO_DEBOUNCINGTIME */ 3765193899aSPaolo Bonzini return s->delay; 3775193899aSPaolo Bonzini } 3785193899aSPaolo Bonzini 3795193899aSPaolo Bonzini OMAP_BAD_REG(addr); 3805193899aSPaolo Bonzini return 0; 3815193899aSPaolo Bonzini } 3825193899aSPaolo Bonzini 3835193899aSPaolo Bonzini static void omap2_gpio_module_write(void *opaque, hwaddr addr, 3845193899aSPaolo Bonzini uint32_t value) 3855193899aSPaolo Bonzini { 3865193899aSPaolo Bonzini struct omap2_gpio_s *s = (struct omap2_gpio_s *) opaque; 3875193899aSPaolo Bonzini uint32_t diff; 3885193899aSPaolo Bonzini int ln; 3895193899aSPaolo Bonzini 3905193899aSPaolo Bonzini switch (addr) { 3915193899aSPaolo Bonzini case 0x00: /* GPIO_REVISION */ 3925193899aSPaolo Bonzini case 0x14: /* GPIO_SYSSTATUS */ 3935193899aSPaolo Bonzini case 0x38: /* GPIO_DATAIN */ 3945193899aSPaolo Bonzini OMAP_RO_REG(addr); 3955193899aSPaolo Bonzini break; 3965193899aSPaolo Bonzini 3975193899aSPaolo Bonzini case 0x10: /* GPIO_SYSCONFIG */ 3985193899aSPaolo Bonzini if (((value >> 3) & 3) == 3) 3995193899aSPaolo Bonzini fprintf(stderr, "%s: bad IDLEMODE value\n", __FUNCTION__); 4005193899aSPaolo Bonzini if (value & 2) 4015193899aSPaolo Bonzini omap2_gpio_module_reset(s); 4025193899aSPaolo Bonzini s->config[0] = value & 0x1d; 4035193899aSPaolo Bonzini break; 4045193899aSPaolo Bonzini 4055193899aSPaolo Bonzini case 0x18: /* GPIO_IRQSTATUS1 */ 4065193899aSPaolo Bonzini if (s->ints[0] & value) { 4075193899aSPaolo Bonzini s->ints[0] &= ~value; 4085193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4095193899aSPaolo Bonzini } 4105193899aSPaolo Bonzini break; 4115193899aSPaolo Bonzini 4125193899aSPaolo Bonzini case 0x1c: /* GPIO_IRQENABLE1 */ 4135193899aSPaolo Bonzini s->mask[0] = value; 4145193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 4155193899aSPaolo Bonzini break; 4165193899aSPaolo Bonzini 4175193899aSPaolo Bonzini case 0x20: /* GPIO_WAKEUPENABLE */ 4185193899aSPaolo Bonzini s->wumask = value; 4195193899aSPaolo Bonzini break; 4205193899aSPaolo Bonzini 4215193899aSPaolo Bonzini case 0x28: /* GPIO_IRQSTATUS2 */ 4225193899aSPaolo Bonzini if (s->ints[1] & value) { 4235193899aSPaolo Bonzini s->ints[1] &= ~value; 4245193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4255193899aSPaolo Bonzini } 4265193899aSPaolo Bonzini break; 4275193899aSPaolo Bonzini 4285193899aSPaolo Bonzini case 0x2c: /* GPIO_IRQENABLE2 */ 4295193899aSPaolo Bonzini s->mask[1] = value; 4305193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 4315193899aSPaolo Bonzini break; 4325193899aSPaolo Bonzini 4335193899aSPaolo Bonzini case 0x30: /* GPIO_CTRL */ 4345193899aSPaolo Bonzini s->config[1] = value & 7; 4355193899aSPaolo Bonzini break; 4365193899aSPaolo Bonzini 4375193899aSPaolo Bonzini case 0x34: /* GPIO_OE */ 4385193899aSPaolo Bonzini diff = s->outputs & (s->dir ^ value); 4395193899aSPaolo Bonzini s->dir = value; 4405193899aSPaolo Bonzini 4415193899aSPaolo Bonzini value = s->outputs & ~s->dir; 442bd2a8884SStefan Hajnoczi while ((ln = ctz32(diff)) != 32) { 443bd2a8884SStefan Hajnoczi diff &= ~(1 << ln); 4445193899aSPaolo Bonzini qemu_set_irq(s->handler[ln], (value >> ln) & 1); 4455193899aSPaolo Bonzini } 4465193899aSPaolo Bonzini 4475193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4485193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4495193899aSPaolo Bonzini break; 4505193899aSPaolo Bonzini 4515193899aSPaolo Bonzini case 0x3c: /* GPIO_DATAOUT */ 4525193899aSPaolo Bonzini omap2_gpio_module_out_update(s, s->outputs ^ value); 4535193899aSPaolo Bonzini break; 4545193899aSPaolo Bonzini 4555193899aSPaolo Bonzini case 0x40: /* GPIO_LEVELDETECT0 */ 4565193899aSPaolo Bonzini s->level[0] = value; 4575193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4585193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4595193899aSPaolo Bonzini break; 4605193899aSPaolo Bonzini 4615193899aSPaolo Bonzini case 0x44: /* GPIO_LEVELDETECT1 */ 4625193899aSPaolo Bonzini s->level[1] = value; 4635193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 0); 4645193899aSPaolo Bonzini omap2_gpio_module_level_update(s, 1); 4655193899aSPaolo Bonzini break; 4665193899aSPaolo Bonzini 4675193899aSPaolo Bonzini case 0x48: /* GPIO_RISINGDETECT */ 4685193899aSPaolo Bonzini s->edge[0] = value; 4695193899aSPaolo Bonzini break; 4705193899aSPaolo Bonzini 4715193899aSPaolo Bonzini case 0x4c: /* GPIO_FALLINGDETECT */ 4725193899aSPaolo Bonzini s->edge[1] = value; 4735193899aSPaolo Bonzini break; 4745193899aSPaolo Bonzini 4755193899aSPaolo Bonzini case 0x50: /* GPIO_DEBOUNCENABLE */ 4765193899aSPaolo Bonzini s->debounce = value; 4775193899aSPaolo Bonzini break; 4785193899aSPaolo Bonzini 4795193899aSPaolo Bonzini case 0x54: /* GPIO_DEBOUNCINGTIME */ 4805193899aSPaolo Bonzini s->delay = value; 4815193899aSPaolo Bonzini break; 4825193899aSPaolo Bonzini 4835193899aSPaolo Bonzini case 0x60: /* GPIO_CLEARIRQENABLE1 */ 4845193899aSPaolo Bonzini s->mask[0] &= ~value; 4855193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 4865193899aSPaolo Bonzini break; 4875193899aSPaolo Bonzini 4885193899aSPaolo Bonzini case 0x64: /* GPIO_SETIRQENABLE1 */ 4895193899aSPaolo Bonzini s->mask[0] |= value; 4905193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 0); 4915193899aSPaolo Bonzini break; 4925193899aSPaolo Bonzini 4935193899aSPaolo Bonzini case 0x70: /* GPIO_CLEARIRQENABLE2 */ 4945193899aSPaolo Bonzini s->mask[1] &= ~value; 4955193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 4965193899aSPaolo Bonzini break; 4975193899aSPaolo Bonzini 4985193899aSPaolo Bonzini case 0x74: /* GPIO_SETIREQNEABLE2 */ 4995193899aSPaolo Bonzini s->mask[1] |= value; 5005193899aSPaolo Bonzini omap2_gpio_module_int_update(s, 1); 5015193899aSPaolo Bonzini break; 5025193899aSPaolo Bonzini 5035193899aSPaolo Bonzini case 0x80: /* GPIO_CLEARWKUENA */ 5045193899aSPaolo Bonzini s->wumask &= ~value; 5055193899aSPaolo Bonzini break; 5065193899aSPaolo Bonzini 5075193899aSPaolo Bonzini case 0x84: /* GPIO_SETWKUENA */ 5085193899aSPaolo Bonzini s->wumask |= value; 5095193899aSPaolo Bonzini break; 5105193899aSPaolo Bonzini 5115193899aSPaolo Bonzini case 0x90: /* GPIO_CLEARDATAOUT */ 5125193899aSPaolo Bonzini omap2_gpio_module_out_update(s, s->outputs & value); 5135193899aSPaolo Bonzini break; 5145193899aSPaolo Bonzini 5155193899aSPaolo Bonzini case 0x94: /* GPIO_SETDATAOUT */ 5165193899aSPaolo Bonzini omap2_gpio_module_out_update(s, ~s->outputs & value); 5175193899aSPaolo Bonzini break; 5185193899aSPaolo Bonzini 5195193899aSPaolo Bonzini default: 5205193899aSPaolo Bonzini OMAP_BAD_REG(addr); 5215193899aSPaolo Bonzini return; 5225193899aSPaolo Bonzini } 5235193899aSPaolo Bonzini } 5245193899aSPaolo Bonzini 5255193899aSPaolo Bonzini static uint32_t omap2_gpio_module_readp(void *opaque, hwaddr addr) 5265193899aSPaolo Bonzini { 5275193899aSPaolo Bonzini return omap2_gpio_module_read(opaque, addr & ~3) >> ((addr & 3) << 3); 5285193899aSPaolo Bonzini } 5295193899aSPaolo Bonzini 5305193899aSPaolo Bonzini static void omap2_gpio_module_writep(void *opaque, hwaddr addr, 5315193899aSPaolo Bonzini uint32_t value) 5325193899aSPaolo Bonzini { 5335193899aSPaolo Bonzini uint32_t cur = 0; 5345193899aSPaolo Bonzini uint32_t mask = 0xffff; 5355193899aSPaolo Bonzini 5365193899aSPaolo Bonzini switch (addr & ~3) { 5375193899aSPaolo Bonzini case 0x00: /* GPIO_REVISION */ 5385193899aSPaolo Bonzini case 0x14: /* GPIO_SYSSTATUS */ 5395193899aSPaolo Bonzini case 0x38: /* GPIO_DATAIN */ 5405193899aSPaolo Bonzini OMAP_RO_REG(addr); 5415193899aSPaolo Bonzini break; 5425193899aSPaolo Bonzini 5435193899aSPaolo Bonzini case 0x10: /* GPIO_SYSCONFIG */ 5445193899aSPaolo Bonzini case 0x1c: /* GPIO_IRQENABLE1 */ 5455193899aSPaolo Bonzini case 0x20: /* GPIO_WAKEUPENABLE */ 5465193899aSPaolo Bonzini case 0x2c: /* GPIO_IRQENABLE2 */ 5475193899aSPaolo Bonzini case 0x30: /* GPIO_CTRL */ 5485193899aSPaolo Bonzini case 0x34: /* GPIO_OE */ 5495193899aSPaolo Bonzini case 0x3c: /* GPIO_DATAOUT */ 5505193899aSPaolo Bonzini case 0x40: /* GPIO_LEVELDETECT0 */ 5515193899aSPaolo Bonzini case 0x44: /* GPIO_LEVELDETECT1 */ 5525193899aSPaolo Bonzini case 0x48: /* GPIO_RISINGDETECT */ 5535193899aSPaolo Bonzini case 0x4c: /* GPIO_FALLINGDETECT */ 5545193899aSPaolo Bonzini case 0x50: /* GPIO_DEBOUNCENABLE */ 5555193899aSPaolo Bonzini case 0x54: /* GPIO_DEBOUNCINGTIME */ 5565193899aSPaolo Bonzini cur = omap2_gpio_module_read(opaque, addr & ~3) & 5575193899aSPaolo Bonzini ~(mask << ((addr & 3) << 3)); 5585193899aSPaolo Bonzini 5595193899aSPaolo Bonzini /* Fall through. */ 5605193899aSPaolo Bonzini case 0x18: /* GPIO_IRQSTATUS1 */ 5615193899aSPaolo Bonzini case 0x28: /* GPIO_IRQSTATUS2 */ 5625193899aSPaolo Bonzini case 0x60: /* GPIO_CLEARIRQENABLE1 */ 5635193899aSPaolo Bonzini case 0x64: /* GPIO_SETIRQENABLE1 */ 5645193899aSPaolo Bonzini case 0x70: /* GPIO_CLEARIRQENABLE2 */ 5655193899aSPaolo Bonzini case 0x74: /* GPIO_SETIREQNEABLE2 */ 5665193899aSPaolo Bonzini case 0x80: /* GPIO_CLEARWKUENA */ 5675193899aSPaolo Bonzini case 0x84: /* GPIO_SETWKUENA */ 5685193899aSPaolo Bonzini case 0x90: /* GPIO_CLEARDATAOUT */ 5695193899aSPaolo Bonzini case 0x94: /* GPIO_SETDATAOUT */ 5705193899aSPaolo Bonzini value <<= (addr & 3) << 3; 5715193899aSPaolo Bonzini omap2_gpio_module_write(opaque, addr, cur | value); 5725193899aSPaolo Bonzini break; 5735193899aSPaolo Bonzini 5745193899aSPaolo Bonzini default: 5755193899aSPaolo Bonzini OMAP_BAD_REG(addr); 5765193899aSPaolo Bonzini return; 5775193899aSPaolo Bonzini } 5785193899aSPaolo Bonzini } 5795193899aSPaolo Bonzini 5805193899aSPaolo Bonzini static const MemoryRegionOps omap2_gpio_module_ops = { 5815193899aSPaolo Bonzini .old_mmio = { 5825193899aSPaolo Bonzini .read = { 5835193899aSPaolo Bonzini omap2_gpio_module_readp, 5845193899aSPaolo Bonzini omap2_gpio_module_readp, 5855193899aSPaolo Bonzini omap2_gpio_module_read, 5865193899aSPaolo Bonzini }, 5875193899aSPaolo Bonzini .write = { 5885193899aSPaolo Bonzini omap2_gpio_module_writep, 5895193899aSPaolo Bonzini omap2_gpio_module_writep, 5905193899aSPaolo Bonzini omap2_gpio_module_write, 5915193899aSPaolo Bonzini }, 5925193899aSPaolo Bonzini }, 5935193899aSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 5945193899aSPaolo Bonzini }; 5955193899aSPaolo Bonzini 5965193899aSPaolo Bonzini static void omap_gpif_reset(DeviceState *dev) 5975193899aSPaolo Bonzini { 5981d300b5fSAndreas Färber struct omap_gpif_s *s = OMAP1_GPIO(dev); 5991d300b5fSAndreas Färber 6005193899aSPaolo Bonzini omap_gpio_reset(&s->omap1); 6015193899aSPaolo Bonzini } 6025193899aSPaolo Bonzini 6035193899aSPaolo Bonzini static void omap2_gpif_reset(DeviceState *dev) 6045193899aSPaolo Bonzini { 60574d1e352SAndreas Färber struct omap2_gpif_s *s = OMAP2_GPIO(dev); 6065193899aSPaolo Bonzini int i; 60774d1e352SAndreas Färber 6085193899aSPaolo Bonzini for (i = 0; i < s->modulecount; i++) { 6095193899aSPaolo Bonzini omap2_gpio_module_reset(&s->modules[i]); 6105193899aSPaolo Bonzini } 6115193899aSPaolo Bonzini s->autoidle = 0; 6125193899aSPaolo Bonzini s->gpo = 0; 6135193899aSPaolo Bonzini } 6145193899aSPaolo Bonzini 6155193899aSPaolo Bonzini static uint64_t omap2_gpif_top_read(void *opaque, hwaddr addr, 6165193899aSPaolo Bonzini unsigned size) 6175193899aSPaolo Bonzini { 6185193899aSPaolo Bonzini struct omap2_gpif_s *s = (struct omap2_gpif_s *) opaque; 6195193899aSPaolo Bonzini 6205193899aSPaolo Bonzini switch (addr) { 6215193899aSPaolo Bonzini case 0x00: /* IPGENERICOCPSPL_REVISION */ 6225193899aSPaolo Bonzini return 0x18; 6235193899aSPaolo Bonzini 6245193899aSPaolo Bonzini case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */ 6255193899aSPaolo Bonzini return s->autoidle; 6265193899aSPaolo Bonzini 6275193899aSPaolo Bonzini case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */ 6285193899aSPaolo Bonzini return 0x01; 6295193899aSPaolo Bonzini 6305193899aSPaolo Bonzini case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */ 6315193899aSPaolo Bonzini return 0x00; 6325193899aSPaolo Bonzini 6335193899aSPaolo Bonzini case 0x40: /* IPGENERICOCPSPL_GPO */ 6345193899aSPaolo Bonzini return s->gpo; 6355193899aSPaolo Bonzini 6365193899aSPaolo Bonzini case 0x50: /* IPGENERICOCPSPL_GPI */ 6375193899aSPaolo Bonzini return 0x00; 6385193899aSPaolo Bonzini } 6395193899aSPaolo Bonzini 6405193899aSPaolo Bonzini OMAP_BAD_REG(addr); 6415193899aSPaolo Bonzini return 0; 6425193899aSPaolo Bonzini } 6435193899aSPaolo Bonzini 6445193899aSPaolo Bonzini static void omap2_gpif_top_write(void *opaque, hwaddr addr, 6455193899aSPaolo Bonzini uint64_t value, unsigned size) 6465193899aSPaolo Bonzini { 6475193899aSPaolo Bonzini struct omap2_gpif_s *s = (struct omap2_gpif_s *) opaque; 6485193899aSPaolo Bonzini 6495193899aSPaolo Bonzini switch (addr) { 6505193899aSPaolo Bonzini case 0x00: /* IPGENERICOCPSPL_REVISION */ 6515193899aSPaolo Bonzini case 0x14: /* IPGENERICOCPSPL_SYSSTATUS */ 6525193899aSPaolo Bonzini case 0x18: /* IPGENERICOCPSPL_IRQSTATUS */ 6535193899aSPaolo Bonzini case 0x50: /* IPGENERICOCPSPL_GPI */ 6545193899aSPaolo Bonzini OMAP_RO_REG(addr); 6555193899aSPaolo Bonzini break; 6565193899aSPaolo Bonzini 6575193899aSPaolo Bonzini case 0x10: /* IPGENERICOCPSPL_SYSCONFIG */ 6585193899aSPaolo Bonzini if (value & (1 << 1)) /* SOFTRESET */ 65974d1e352SAndreas Färber omap2_gpif_reset(DEVICE(s)); 6605193899aSPaolo Bonzini s->autoidle = value & 1; 6615193899aSPaolo Bonzini break; 6625193899aSPaolo Bonzini 6635193899aSPaolo Bonzini case 0x40: /* IPGENERICOCPSPL_GPO */ 6645193899aSPaolo Bonzini s->gpo = value & 1; 6655193899aSPaolo Bonzini break; 6665193899aSPaolo Bonzini 6675193899aSPaolo Bonzini default: 6685193899aSPaolo Bonzini OMAP_BAD_REG(addr); 6695193899aSPaolo Bonzini return; 6705193899aSPaolo Bonzini } 6715193899aSPaolo Bonzini } 6725193899aSPaolo Bonzini 6735193899aSPaolo Bonzini static const MemoryRegionOps omap2_gpif_top_ops = { 6745193899aSPaolo Bonzini .read = omap2_gpif_top_read, 6755193899aSPaolo Bonzini .write = omap2_gpif_top_write, 6765193899aSPaolo Bonzini .endianness = DEVICE_NATIVE_ENDIAN, 6775193899aSPaolo Bonzini }; 6785193899aSPaolo Bonzini 6791d300b5fSAndreas Färber static int omap_gpio_init(SysBusDevice *sbd) 6805193899aSPaolo Bonzini { 6811d300b5fSAndreas Färber DeviceState *dev = DEVICE(sbd); 6821d300b5fSAndreas Färber struct omap_gpif_s *s = OMAP1_GPIO(dev); 6831d300b5fSAndreas Färber 6845193899aSPaolo Bonzini if (!s->clk) { 6855193899aSPaolo Bonzini hw_error("omap-gpio: clk not connected\n"); 6865193899aSPaolo Bonzini } 6871d300b5fSAndreas Färber qdev_init_gpio_in(dev, omap_gpio_set, 16); 6881d300b5fSAndreas Färber qdev_init_gpio_out(dev, s->omap1.handler, 16); 6891d300b5fSAndreas Färber sysbus_init_irq(sbd, &s->omap1.irq); 690b7163687SPaolo Bonzini memory_region_init_io(&s->iomem, OBJECT(s), &omap_gpio_ops, &s->omap1, 6915193899aSPaolo Bonzini "omap.gpio", 0x1000); 6921d300b5fSAndreas Färber sysbus_init_mmio(sbd, &s->iomem); 6935193899aSPaolo Bonzini return 0; 6945193899aSPaolo Bonzini } 6955193899aSPaolo Bonzini 69674d1e352SAndreas Färber static int omap2_gpio_init(SysBusDevice *sbd) 6975193899aSPaolo Bonzini { 69874d1e352SAndreas Färber DeviceState *dev = DEVICE(sbd); 69974d1e352SAndreas Färber struct omap2_gpif_s *s = OMAP2_GPIO(dev); 7005193899aSPaolo Bonzini int i; 70174d1e352SAndreas Färber 7025193899aSPaolo Bonzini if (!s->iclk) { 7035193899aSPaolo Bonzini hw_error("omap2-gpio: iclk not connected\n"); 7045193899aSPaolo Bonzini } 7055193899aSPaolo Bonzini if (s->mpu_model < omap3430) { 7065193899aSPaolo Bonzini s->modulecount = (s->mpu_model < omap2430) ? 4 : 5; 707b7163687SPaolo Bonzini memory_region_init_io(&s->iomem, OBJECT(s), &omap2_gpif_top_ops, s, 7085193899aSPaolo Bonzini "omap2.gpio", 0x1000); 70974d1e352SAndreas Färber sysbus_init_mmio(sbd, &s->iomem); 7105193899aSPaolo Bonzini } else { 7115193899aSPaolo Bonzini s->modulecount = 6; 7125193899aSPaolo Bonzini } 713*b45c03f5SMarkus Armbruster s->modules = g_new0(struct omap2_gpio_s, s->modulecount); 714*b45c03f5SMarkus Armbruster s->handler = g_new0(qemu_irq, s->modulecount * 32); 71574d1e352SAndreas Färber qdev_init_gpio_in(dev, omap2_gpio_set, s->modulecount * 32); 71674d1e352SAndreas Färber qdev_init_gpio_out(dev, s->handler, s->modulecount * 32); 7175193899aSPaolo Bonzini for (i = 0; i < s->modulecount; i++) { 7185193899aSPaolo Bonzini struct omap2_gpio_s *m = &s->modules[i]; 7195193899aSPaolo Bonzini if (!s->fclk[i]) { 7205193899aSPaolo Bonzini hw_error("omap2-gpio: fclk%d not connected\n", i); 7215193899aSPaolo Bonzini } 7225193899aSPaolo Bonzini m->revision = (s->mpu_model < omap3430) ? 0x18 : 0x25; 7235193899aSPaolo Bonzini m->handler = &s->handler[i * 32]; 72474d1e352SAndreas Färber sysbus_init_irq(sbd, &m->irq[0]); /* mpu irq */ 72574d1e352SAndreas Färber sysbus_init_irq(sbd, &m->irq[1]); /* dsp irq */ 72674d1e352SAndreas Färber sysbus_init_irq(sbd, &m->wkup); 727b7163687SPaolo Bonzini memory_region_init_io(&m->iomem, OBJECT(s), &omap2_gpio_module_ops, m, 7285193899aSPaolo Bonzini "omap.gpio-module", 0x1000); 72974d1e352SAndreas Färber sysbus_init_mmio(sbd, &m->iomem); 7305193899aSPaolo Bonzini } 7315193899aSPaolo Bonzini return 0; 7325193899aSPaolo Bonzini } 7335193899aSPaolo Bonzini 7345193899aSPaolo Bonzini /* Using qdev pointer properties for the clocks is not ideal. 7355193899aSPaolo Bonzini * qdev should support a generic means of defining a 'port' with 7365193899aSPaolo Bonzini * an arbitrary interface for connecting two devices. Then we 7375193899aSPaolo Bonzini * could reframe the omap clock API in terms of clock ports, 7385193899aSPaolo Bonzini * and get some type safety. For now the best qdev provides is 7395193899aSPaolo Bonzini * passing an arbitrary pointer. 7405193899aSPaolo Bonzini * (It's not possible to pass in the string which is the clock 7415193899aSPaolo Bonzini * name, because this device does not have the necessary information 7425193899aSPaolo Bonzini * (ie the struct omap_mpu_state_s*) to do the clockname to pointer 7435193899aSPaolo Bonzini * translation.) 7445193899aSPaolo Bonzini */ 7455193899aSPaolo Bonzini 7465193899aSPaolo Bonzini static Property omap_gpio_properties[] = { 7475193899aSPaolo Bonzini DEFINE_PROP_INT32("mpu_model", struct omap_gpif_s, mpu_model, 0), 7485193899aSPaolo Bonzini DEFINE_PROP_PTR("clk", struct omap_gpif_s, clk), 7495193899aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 7505193899aSPaolo Bonzini }; 7515193899aSPaolo Bonzini 7525193899aSPaolo Bonzini static void omap_gpio_class_init(ObjectClass *klass, void *data) 7535193899aSPaolo Bonzini { 7545193899aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 7555193899aSPaolo Bonzini SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 7565193899aSPaolo Bonzini 7575193899aSPaolo Bonzini k->init = omap_gpio_init; 7585193899aSPaolo Bonzini dc->reset = omap_gpif_reset; 7595193899aSPaolo Bonzini dc->props = omap_gpio_properties; 7601b111dc1SMarkus Armbruster /* Reason: pointer property "clk" */ 7611b111dc1SMarkus Armbruster dc->cannot_instantiate_with_device_add_yet = true; 7625193899aSPaolo Bonzini } 7635193899aSPaolo Bonzini 7645193899aSPaolo Bonzini static const TypeInfo omap_gpio_info = { 7651d300b5fSAndreas Färber .name = TYPE_OMAP1_GPIO, 7665193899aSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 7675193899aSPaolo Bonzini .instance_size = sizeof(struct omap_gpif_s), 7685193899aSPaolo Bonzini .class_init = omap_gpio_class_init, 7695193899aSPaolo Bonzini }; 7705193899aSPaolo Bonzini 7715193899aSPaolo Bonzini static Property omap2_gpio_properties[] = { 7725193899aSPaolo Bonzini DEFINE_PROP_INT32("mpu_model", struct omap2_gpif_s, mpu_model, 0), 7735193899aSPaolo Bonzini DEFINE_PROP_PTR("iclk", struct omap2_gpif_s, iclk), 7745193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk0", struct omap2_gpif_s, fclk[0]), 7755193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk1", struct omap2_gpif_s, fclk[1]), 7765193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk2", struct omap2_gpif_s, fclk[2]), 7775193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk3", struct omap2_gpif_s, fclk[3]), 7785193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk4", struct omap2_gpif_s, fclk[4]), 7795193899aSPaolo Bonzini DEFINE_PROP_PTR("fclk5", struct omap2_gpif_s, fclk[5]), 7805193899aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 7815193899aSPaolo Bonzini }; 7825193899aSPaolo Bonzini 7835193899aSPaolo Bonzini static void omap2_gpio_class_init(ObjectClass *klass, void *data) 7845193899aSPaolo Bonzini { 7855193899aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 7865193899aSPaolo Bonzini SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 7875193899aSPaolo Bonzini 7885193899aSPaolo Bonzini k->init = omap2_gpio_init; 7895193899aSPaolo Bonzini dc->reset = omap2_gpif_reset; 7905193899aSPaolo Bonzini dc->props = omap2_gpio_properties; 7911b111dc1SMarkus Armbruster /* Reason: pointer properties "iclk", "fclk0", ..., "fclk5" */ 7921b111dc1SMarkus Armbruster dc->cannot_instantiate_with_device_add_yet = true; 7935193899aSPaolo Bonzini } 7945193899aSPaolo Bonzini 7955193899aSPaolo Bonzini static const TypeInfo omap2_gpio_info = { 79674d1e352SAndreas Färber .name = TYPE_OMAP2_GPIO, 7975193899aSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 7985193899aSPaolo Bonzini .instance_size = sizeof(struct omap2_gpif_s), 7995193899aSPaolo Bonzini .class_init = omap2_gpio_class_init, 8005193899aSPaolo Bonzini }; 8015193899aSPaolo Bonzini 8025193899aSPaolo Bonzini static void omap_gpio_register_types(void) 8035193899aSPaolo Bonzini { 8045193899aSPaolo Bonzini type_register_static(&omap_gpio_info); 8055193899aSPaolo Bonzini type_register_static(&omap2_gpio_info); 8065193899aSPaolo Bonzini } 8075193899aSPaolo Bonzini 8085193899aSPaolo Bonzini type_init(omap_gpio_register_types) 809