qemu/hw/misc/fixed-clock.c
<<
>>
Prefs
   1/*
   2 * QEMU model of a Fixed Clock source.
   3 *
   4 * Copyright (c) 2013 Xilinx Inc.
   5 * Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
   6 *
   7 * Permission is hereby granted, free of charge, to any person obtaining a copy
   8 * of this software and associated documentation files (the "Software"), to deal
   9 * in the Software without restriction, including without limitation the rights
  10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11 * copies of the Software, and to permit persons to whom the Software is
  12 * furnished to do so, subject to the following conditions:
  13 *
  14 * The above copyright notice and this permission notice shall be included in
  15 * all copies or substantial portions of the Software.
  16 *
  17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23 * THE SOFTWARE.
  24 */
  25
  26#include "qemu/osdep.h"
  27#include "hw/sysbus.h"
  28
  29#include "hw/fdt_generic_util.h"
  30
  31#define TYPE_FIXED_CLOCK "fixed-clock"
  32
  33#define FIXED_CLOCK(obj) \
  34    OBJECT_CHECK(FixedClock, (obj), TYPE_FIXED_CLOCK)
  35
  36typedef struct FixedClock {
  37    /* private */
  38    DeviceState parent_obj;
  39    /*public */
  40    uint32_t freq_hz;
  41    qemu_irq clk;
  42} FixedClock;
  43
  44static void fixed_clock_reset(DeviceState *dev)
  45{
  46    FixedClock *s = FIXED_CLOCK(dev);
  47
  48    qemu_set_irq(s->clk, s->freq_hz);
  49}
  50
  51static void fixed_clock_init(Object *obj)
  52{
  53    FixedClock *s = FIXED_CLOCK(obj);
  54
  55    qdev_init_gpio_out(DEVICE(obj), &s->clk, 1);
  56}
  57
  58static Property fixed_clock_properties [] = {
  59    DEFINE_PROP_UINT32("clock-frequency", FixedClock, freq_hz, 10000000),
  60    DEFINE_PROP_END_OF_LIST(),
  61};
  62
  63static void fixed_clock_class_init(ObjectClass *oc, void *data)
  64{
  65    DeviceClass *dc = DEVICE_CLASS(oc);
  66
  67    dc->reset = fixed_clock_reset;
  68    dc->props = fixed_clock_properties;
  69}
  70
  71static const TypeInfo fixed_clock_info = {
  72    .name          = "fixed-clock",
  73    .parent        = TYPE_DEVICE,
  74    .instance_size = sizeof(FixedClock),
  75    .class_init    = fixed_clock_class_init,
  76    .instance_init = fixed_clock_init,
  77    .interfaces    = (InterfaceInfo []) {
  78        { TYPE_FDT_GENERIC_GPIO },
  79        { },
  80    },
  81};
  82
  83static void fixed_clock_register_types(void)
  84{
  85    type_register_static(&fixed_clock_info);
  86}
  87
  88type_init(fixed_clock_register_types)
  89