1bbbbd900SAlistair Francis /* 2bbbbd900SAlistair Francis * STM32F2XX SYSCFG 3bbbbd900SAlistair Francis * 4bbbbd900SAlistair Francis * Copyright (c) 2014 Alistair Francis <alistair@alistair23.me> 5bbbbd900SAlistair Francis * 6bbbbd900SAlistair Francis * Permission is hereby granted, free of charge, to any person obtaining a copy 7bbbbd900SAlistair Francis * of this software and associated documentation files (the "Software"), to deal 8bbbbd900SAlistair Francis * in the Software without restriction, including without limitation the rights 9bbbbd900SAlistair Francis * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10bbbbd900SAlistair Francis * copies of the Software, and to permit persons to whom the Software is 11bbbbd900SAlistair Francis * furnished to do so, subject to the following conditions: 12bbbbd900SAlistair Francis * 13bbbbd900SAlistair Francis * The above copyright notice and this permission notice shall be included in 14bbbbd900SAlistair Francis * all copies or substantial portions of the Software. 15bbbbd900SAlistair Francis * 16bbbbd900SAlistair Francis * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bbbbd900SAlistair Francis * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bbbbd900SAlistair Francis * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bbbbd900SAlistair Francis * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bbbbd900SAlistair Francis * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21bbbbd900SAlistair Francis * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22bbbbd900SAlistair Francis * THE SOFTWARE. 23bbbbd900SAlistair Francis */ 24bbbbd900SAlistair Francis 250d1c9782SPeter Maydell #include "qemu/osdep.h" 26bbbbd900SAlistair Francis #include "hw/misc/stm32f2xx_syscfg.h" 2703dd024fSPaolo Bonzini #include "qemu/log.h" 28*0b8fa32fSMarkus Armbruster #include "qemu/module.h" 29bbbbd900SAlistair Francis 30bbbbd900SAlistair Francis #ifndef STM_SYSCFG_ERR_DEBUG 31bbbbd900SAlistair Francis #define STM_SYSCFG_ERR_DEBUG 0 32bbbbd900SAlistair Francis #endif 33bbbbd900SAlistair Francis 34bbbbd900SAlistair Francis #define DB_PRINT_L(lvl, fmt, args...) do { \ 35bbbbd900SAlistair Francis if (STM_SYSCFG_ERR_DEBUG >= lvl) { \ 36bbbbd900SAlistair Francis qemu_log("%s: " fmt, __func__, ## args); \ 37bbbbd900SAlistair Francis } \ 382562755eSEric Blake } while (0) 39bbbbd900SAlistair Francis 40bbbbd900SAlistair Francis #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 41bbbbd900SAlistair Francis 42bbbbd900SAlistair Francis static void stm32f2xx_syscfg_reset(DeviceState *dev) 43bbbbd900SAlistair Francis { 44bbbbd900SAlistair Francis STM32F2XXSyscfgState *s = STM32F2XX_SYSCFG(dev); 45bbbbd900SAlistair Francis 46bbbbd900SAlistair Francis s->syscfg_memrmp = 0x00000000; 47bbbbd900SAlistair Francis s->syscfg_pmc = 0x00000000; 48bbbbd900SAlistair Francis s->syscfg_exticr1 = 0x00000000; 49bbbbd900SAlistair Francis s->syscfg_exticr2 = 0x00000000; 50bbbbd900SAlistair Francis s->syscfg_exticr3 = 0x00000000; 51bbbbd900SAlistair Francis s->syscfg_exticr4 = 0x00000000; 52bbbbd900SAlistair Francis s->syscfg_cmpcr = 0x00000000; 53bbbbd900SAlistair Francis } 54bbbbd900SAlistair Francis 55bbbbd900SAlistair Francis static uint64_t stm32f2xx_syscfg_read(void *opaque, hwaddr addr, 56bbbbd900SAlistair Francis unsigned int size) 57bbbbd900SAlistair Francis { 58bbbbd900SAlistair Francis STM32F2XXSyscfgState *s = opaque; 59bbbbd900SAlistair Francis 60bbbbd900SAlistair Francis DB_PRINT("0x%"HWADDR_PRIx"\n", addr); 61bbbbd900SAlistair Francis 62bbbbd900SAlistair Francis switch (addr) { 63bbbbd900SAlistair Francis case SYSCFG_MEMRMP: 64bbbbd900SAlistair Francis return s->syscfg_memrmp; 65bbbbd900SAlistair Francis case SYSCFG_PMC: 66bbbbd900SAlistair Francis return s->syscfg_pmc; 67bbbbd900SAlistair Francis case SYSCFG_EXTICR1: 68bbbbd900SAlistair Francis return s->syscfg_exticr1; 69bbbbd900SAlistair Francis case SYSCFG_EXTICR2: 70bbbbd900SAlistair Francis return s->syscfg_exticr2; 71bbbbd900SAlistair Francis case SYSCFG_EXTICR3: 72bbbbd900SAlistair Francis return s->syscfg_exticr3; 73bbbbd900SAlistair Francis case SYSCFG_EXTICR4: 74bbbbd900SAlistair Francis return s->syscfg_exticr4; 75bbbbd900SAlistair Francis case SYSCFG_CMPCR: 76bbbbd900SAlistair Francis return s->syscfg_cmpcr; 77bbbbd900SAlistair Francis default: 78bbbbd900SAlistair Francis qemu_log_mask(LOG_GUEST_ERROR, 79bbbbd900SAlistair Francis "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); 80bbbbd900SAlistair Francis return 0; 81bbbbd900SAlistair Francis } 82bbbbd900SAlistair Francis 83bbbbd900SAlistair Francis return 0; 84bbbbd900SAlistair Francis } 85bbbbd900SAlistair Francis 86bbbbd900SAlistair Francis static void stm32f2xx_syscfg_write(void *opaque, hwaddr addr, 87bbbbd900SAlistair Francis uint64_t val64, unsigned int size) 88bbbbd900SAlistair Francis { 89bbbbd900SAlistair Francis STM32F2XXSyscfgState *s = opaque; 90bbbbd900SAlistair Francis uint32_t value = val64; 91bbbbd900SAlistair Francis 92bbbbd900SAlistair Francis DB_PRINT("0x%x, 0x%"HWADDR_PRIx"\n", value, addr); 93bbbbd900SAlistair Francis 94bbbbd900SAlistair Francis switch (addr) { 95bbbbd900SAlistair Francis case SYSCFG_MEMRMP: 96bbbbd900SAlistair Francis qemu_log_mask(LOG_UNIMP, 97bbbbd900SAlistair Francis "%s: Changeing the memory mapping isn't supported " \ 98bbbbd900SAlistair Francis "in QEMU\n", __func__); 99bbbbd900SAlistair Francis return; 100bbbbd900SAlistair Francis case SYSCFG_PMC: 101bbbbd900SAlistair Francis qemu_log_mask(LOG_UNIMP, 102bbbbd900SAlistair Francis "%s: Changeing the memory mapping isn't supported " \ 103bbbbd900SAlistair Francis "in QEMU\n", __func__); 104bbbbd900SAlistair Francis return; 105bbbbd900SAlistair Francis case SYSCFG_EXTICR1: 106bbbbd900SAlistair Francis s->syscfg_exticr1 = (value & 0xFFFF); 107bbbbd900SAlistair Francis return; 108bbbbd900SAlistair Francis case SYSCFG_EXTICR2: 109bbbbd900SAlistair Francis s->syscfg_exticr2 = (value & 0xFFFF); 110bbbbd900SAlistair Francis return; 111bbbbd900SAlistair Francis case SYSCFG_EXTICR3: 112bbbbd900SAlistair Francis s->syscfg_exticr3 = (value & 0xFFFF); 113bbbbd900SAlistair Francis return; 114bbbbd900SAlistair Francis case SYSCFG_EXTICR4: 115bbbbd900SAlistair Francis s->syscfg_exticr4 = (value & 0xFFFF); 116bbbbd900SAlistair Francis return; 117bbbbd900SAlistair Francis case SYSCFG_CMPCR: 118bbbbd900SAlistair Francis s->syscfg_cmpcr = value; 119bbbbd900SAlistair Francis return; 120bbbbd900SAlistair Francis default: 121bbbbd900SAlistair Francis qemu_log_mask(LOG_GUEST_ERROR, 122bbbbd900SAlistair Francis "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); 123bbbbd900SAlistair Francis } 124bbbbd900SAlistair Francis } 125bbbbd900SAlistair Francis 126bbbbd900SAlistair Francis static const MemoryRegionOps stm32f2xx_syscfg_ops = { 127bbbbd900SAlistair Francis .read = stm32f2xx_syscfg_read, 128bbbbd900SAlistair Francis .write = stm32f2xx_syscfg_write, 129bbbbd900SAlistair Francis .endianness = DEVICE_NATIVE_ENDIAN, 130bbbbd900SAlistair Francis }; 131bbbbd900SAlistair Francis 132bbbbd900SAlistair Francis static void stm32f2xx_syscfg_init(Object *obj) 133bbbbd900SAlistair Francis { 134bbbbd900SAlistair Francis STM32F2XXSyscfgState *s = STM32F2XX_SYSCFG(obj); 135bbbbd900SAlistair Francis 136bbbbd900SAlistair Francis sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); 137bbbbd900SAlistair Francis 138bbbbd900SAlistair Francis memory_region_init_io(&s->mmio, obj, &stm32f2xx_syscfg_ops, s, 139bbbbd900SAlistair Francis TYPE_STM32F2XX_SYSCFG, 0x400); 140bbbbd900SAlistair Francis sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); 141bbbbd900SAlistair Francis } 142bbbbd900SAlistair Francis 143bbbbd900SAlistair Francis static void stm32f2xx_syscfg_class_init(ObjectClass *klass, void *data) 144bbbbd900SAlistair Francis { 145bbbbd900SAlistair Francis DeviceClass *dc = DEVICE_CLASS(klass); 146bbbbd900SAlistair Francis 147bbbbd900SAlistair Francis dc->reset = stm32f2xx_syscfg_reset; 148bbbbd900SAlistair Francis } 149bbbbd900SAlistair Francis 150bbbbd900SAlistair Francis static const TypeInfo stm32f2xx_syscfg_info = { 151bbbbd900SAlistair Francis .name = TYPE_STM32F2XX_SYSCFG, 152bbbbd900SAlistair Francis .parent = TYPE_SYS_BUS_DEVICE, 153bbbbd900SAlistair Francis .instance_size = sizeof(STM32F2XXSyscfgState), 154bbbbd900SAlistair Francis .instance_init = stm32f2xx_syscfg_init, 155bbbbd900SAlistair Francis .class_init = stm32f2xx_syscfg_class_init, 156bbbbd900SAlistair Francis }; 157bbbbd900SAlistair Francis 158bbbbd900SAlistair Francis static void stm32f2xx_syscfg_register_types(void) 159bbbbd900SAlistair Francis { 160bbbbd900SAlistair Francis type_register_static(&stm32f2xx_syscfg_info); 161bbbbd900SAlistair Francis } 162bbbbd900SAlistair Francis 163bbbbd900SAlistair Francis type_init(stm32f2xx_syscfg_register_types) 164