1 /* 2 * ARM CMSDK APB timer emulation 3 * 4 * Copyright (c) 2017 Linaro Limited 5 * Written by Peter Maydell 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 or 9 * (at your option) any later version. 10 */ 11 12 #ifndef CMSDK_APB_TIMER_H 13 #define CMSDK_APB_TIMER_H 14 15 #include "hw/qdev-properties.h" 16 #include "hw/sysbus.h" 17 #include "hw/ptimer.h" 18 #include "qom/object.h" 19 20 #define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer" 21 typedef struct CMSDKAPBTIMER CMSDKAPBTIMER; 22 DECLARE_INSTANCE_CHECKER(CMSDKAPBTIMER, CMSDK_APB_TIMER, 23 TYPE_CMSDK_APB_TIMER) 24 25 struct CMSDKAPBTIMER { 26 /*< private >*/ 27 SysBusDevice parent_obj; 28 29 /*< public >*/ 30 MemoryRegion iomem; 31 qemu_irq timerint; 32 uint32_t pclk_frq; 33 struct ptimer_state *timer; 34 35 uint32_t ctrl; 36 uint32_t value; 37 uint32_t reload; 38 uint32_t intstatus; 39 }; 40 41 /** 42 * cmsdk_apb_timer_create - convenience function to create TYPE_CMSDK_APB_TIMER 43 * @addr: location in system memory to map registers 44 * @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate) 45 */ 46 static inline DeviceState *cmsdk_apb_timer_create(hwaddr addr, 47 qemu_irq timerint, 48 uint32_t pclk_frq) 49 { 50 DeviceState *dev; 51 SysBusDevice *s; 52 53 dev = qdev_new(TYPE_CMSDK_APB_TIMER); 54 s = SYS_BUS_DEVICE(dev); 55 qdev_prop_set_uint32(dev, "pclk-frq", pclk_frq); 56 sysbus_realize_and_unref(s, &error_fatal); 57 sysbus_mmio_map(s, 0, addr); 58 sysbus_connect_irq(s, 0, timerint); 59 return dev; 60 } 61 62 #endif 63