]> Git Repo - qemu.git/blame - hw/arm/microbit.c
Move QOM typedefs and add missing includes
[qemu.git] / hw / arm / microbit.c
CommitLineData
b148ed46
JS
1/*
2 * BBC micro:bit machine
3 * http://tech.microbit.org/hardware/
4 *
5 * Copyright 2018 Joel Stanley <[email protected]>
6 *
7 * This code is licensed under the GPL version 2 or later. See
8 * the COPYING file in the top-level directory.
9 */
10
11#include "qemu/osdep.h"
12#include "qapi/error.h"
13#include "hw/boards.h"
12ec8bd5 14#include "hw/arm/boot.h"
b0014913 15#include "sysemu/sysemu.h"
b148ed46
JS
16#include "exec/address-spaces.h"
17
18#include "hw/arm/nrf51_soc.h"
9d68bf56 19#include "hw/i2c/microbit_i2c.h"
a27bd6c7 20#include "hw/qdev-properties.h"
db1015e9 21#include "qom/object.h"
b148ed46 22
db1015e9 23struct MicrobitMachineState {
b148ed46
JS
24 MachineState parent;
25
26 NRF51State nrf51;
9d68bf56 27 MicrobitI2CState i2c;
db1015e9
EH
28};
29typedef struct MicrobitMachineState MicrobitMachineState;
b148ed46
JS
30
31#define TYPE_MICROBIT_MACHINE MACHINE_TYPE_NAME("microbit")
32
33#define MICROBIT_MACHINE(obj) \
34 OBJECT_CHECK(MicrobitMachineState, obj, TYPE_MICROBIT_MACHINE)
35
36static void microbit_init(MachineState *machine)
37{
38 MicrobitMachineState *s = MICROBIT_MACHINE(machine);
39 MemoryRegion *system_memory = get_system_memory();
9d68bf56 40 MemoryRegion *mr;
b148ed46 41
5a147c8c
MA
42 object_initialize_child(OBJECT(machine), "nrf51", &s->nrf51,
43 TYPE_NRF51_SOC);
b0014913 44 qdev_prop_set_chr(DEVICE(&s->nrf51), "serial0", serial_hd(0));
5325cc34
MA
45 object_property_set_link(OBJECT(&s->nrf51), "memory",
46 OBJECT(system_memory), &error_fatal);
e9a82986 47 sysbus_realize(SYS_BUS_DEVICE(&s->nrf51), &error_fatal);
b148ed46 48
9d68bf56
SG
49 /*
50 * Overlap the TWI stub device into the SoC. This is a microbit-specific
51 * hack until we implement the nRF51 TWI controller properly and the
52 * magnetometer/accelerometer devices.
53 */
5a147c8c
MA
54 object_initialize_child(OBJECT(machine), "microbit.twi", &s->i2c,
55 TYPE_MICROBIT_I2C);
e9a82986
MA
56 sysbus_realize(SYS_BUS_DEVICE(&s->i2c), &error_fatal);
57 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->i2c), 0);
9d68bf56
SG
58 memory_region_add_subregion_overlap(&s->nrf51.container, NRF51_TWI_BASE,
59 mr, -1);
60
b148ed46 61 armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
e9a82986 62 s->nrf51.flash_size);
b148ed46
JS
63}
64
65static void microbit_machine_class_init(ObjectClass *oc, void *data)
66{
67 MachineClass *mc = MACHINE_CLASS(oc);
68
69 mc->desc = "BBC micro:bit";
70 mc->init = microbit_init;
71 mc->max_cpus = 1;
72}
73
74static const TypeInfo microbit_info = {
75 .name = TYPE_MICROBIT_MACHINE,
76 .parent = TYPE_MACHINE,
77 .instance_size = sizeof(MicrobitMachineState),
78 .class_init = microbit_machine_class_init,
79};
80
81static void microbit_machine_init(void)
82{
83 type_register_static(&microbit_info);
84}
85
86type_init(microbit_machine_init);
This page took 0.109823 seconds and 4 git commands to generate.