2 * Luminary Micro Stellaris peripherals
4 * Copyright (c) 2006 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GPL.
10 #include "qemu/osdep.h"
11 #include "qapi/error.h"
12 #include "hw/sysbus.h"
13 #include "hw/ssi/ssi.h"
14 #include "hw/arm/boot.h"
15 #include "qemu/timer.h"
16 #include "hw/i2c/i2c.h"
18 #include "hw/boards.h"
20 #include "exec/address-spaces.h"
21 #include "sysemu/sysemu.h"
22 #include "hw/arm/armv7m.h"
23 #include "hw/char/pl011.h"
24 #include "hw/input/gamepad.h"
26 #include "hw/watchdog/cmsdk-apb-watchdog.h"
27 #include "migration/vmstate.h"
28 #include "hw/misc/unimp.h"
29 #include "hw/qdev-clock.h"
31 #include "qom/object.h"
41 #define BP_OLED_I2C 0x01
42 #define BP_OLED_SSI 0x02
43 #define BP_GAMEPAD 0x04
45 #define NUM_IRQ_LINES 64
47 typedef const struct {
57 } stellaris_board_info
;
59 /* General purpose timer module. */
61 #define TYPE_STELLARIS_GPTM "stellaris-gptm"
62 OBJECT_DECLARE_SIMPLE_TYPE(gptm_state
, STELLARIS_GPTM
)
65 SysBusDevice parent_obj
;
76 uint32_t match_prescale
[2];
79 struct gptm_state
*opaque
[2];
81 /* The timers have an alternate output used to trigger the ADC. */
86 static void gptm_update_irq(gptm_state
*s
)
89 level
= (s
->state
& s
->mask
) != 0;
90 qemu_set_irq(s
->irq
, level
);
93 static void gptm_stop(gptm_state
*s
, int n
)
95 timer_del(s
->timer
[n
]);
98 static void gptm_reload(gptm_state
*s
, int n
, int reset
)
102 tick
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
106 if (s
->config
== 0) {
107 /* 32-bit CountDown. */
109 count
= s
->load
[0] | (s
->load
[1] << 16);
110 tick
+= (int64_t)count
* system_clock_scale
;
111 } else if (s
->config
== 1) {
112 /* 32-bit RTC. 1Hz tick. */
113 tick
+= NANOSECONDS_PER_SECOND
;
114 } else if (s
->mode
[n
] == 0xa) {
115 /* PWM mode. Not implemented. */
117 qemu_log_mask(LOG_UNIMP
,
118 "GPTM: 16-bit timer mode unimplemented: 0x%x\n",
123 timer_mod(s
->timer
[n
], tick
);
126 static void gptm_tick(void *opaque
)
128 gptm_state
**p
= (gptm_state
**)opaque
;
134 if (s
->config
== 0) {
136 if ((s
->control
& 0x20)) {
137 /* Output trigger. */
138 qemu_irq_pulse(s
->trigger
);
140 if (s
->mode
[0] & 1) {
145 gptm_reload(s
, 0, 0);
147 } else if (s
->config
== 1) {
151 match
= s
->match
[0] | (s
->match
[1] << 16);
157 gptm_reload(s
, 0, 0);
158 } else if (s
->mode
[n
] == 0xa) {
159 /* PWM mode. Not implemented. */
161 qemu_log_mask(LOG_UNIMP
,
162 "GPTM: 16-bit timer mode unimplemented: 0x%x\n",
168 static uint64_t gptm_read(void *opaque
, hwaddr offset
,
171 gptm_state
*s
= (gptm_state
*)opaque
;
176 case 0x04: /* TAMR */
178 case 0x08: /* TBMR */
187 return s
->state
& s
->mask
;
190 case 0x28: /* TAILR */
191 return s
->load
[0] | ((s
->config
< 4) ? (s
->load
[1] << 16) : 0);
192 case 0x2c: /* TBILR */
194 case 0x30: /* TAMARCHR */
195 return s
->match
[0] | ((s
->config
< 4) ? (s
->match
[1] << 16) : 0);
196 case 0x34: /* TBMATCHR */
198 case 0x38: /* TAPR */
199 return s
->prescale
[0];
200 case 0x3c: /* TBPR */
201 return s
->prescale
[1];
202 case 0x40: /* TAPMR */
203 return s
->match_prescale
[0];
204 case 0x44: /* TBPMR */
205 return s
->match_prescale
[1];
207 if (s
->config
== 1) {
210 qemu_log_mask(LOG_UNIMP
,
211 "GPTM: read of TAR but timer read not supported\n");
214 qemu_log_mask(LOG_UNIMP
,
215 "GPTM: read of TBR but timer read not supported\n");
218 qemu_log_mask(LOG_GUEST_ERROR
,
219 "GPTM: read at bad offset 0x02%" HWADDR_PRIx
"\n",
225 static void gptm_write(void *opaque
, hwaddr offset
,
226 uint64_t value
, unsigned size
)
228 gptm_state
*s
= (gptm_state
*)opaque
;
231 /* The timers should be disabled before changing the configuration.
232 We take advantage of this and defer everything until the timer
238 case 0x04: /* TAMR */
241 case 0x08: /* TBMR */
247 /* TODO: Implement pause. */
248 if ((oldval
^ value
) & 1) {
250 gptm_reload(s
, 0, 1);
255 if (((oldval
^ value
) & 0x100) && s
->config
>= 4) {
257 gptm_reload(s
, 1, 1);
264 s
->mask
= value
& 0x77;
270 case 0x28: /* TAILR */
271 s
->load
[0] = value
& 0xffff;
273 s
->load
[1] = value
>> 16;
276 case 0x2c: /* TBILR */
277 s
->load
[1] = value
& 0xffff;
279 case 0x30: /* TAMARCHR */
280 s
->match
[0] = value
& 0xffff;
282 s
->match
[1] = value
>> 16;
285 case 0x34: /* TBMATCHR */
286 s
->match
[1] = value
>> 16;
288 case 0x38: /* TAPR */
289 s
->prescale
[0] = value
;
291 case 0x3c: /* TBPR */
292 s
->prescale
[1] = value
;
294 case 0x40: /* TAPMR */
295 s
->match_prescale
[0] = value
;
297 case 0x44: /* TBPMR */
298 s
->match_prescale
[0] = value
;
301 qemu_log_mask(LOG_GUEST_ERROR
,
302 "GPTM: write at bad offset 0x02%" HWADDR_PRIx
"\n",
308 static const MemoryRegionOps gptm_ops
= {
311 .endianness
= DEVICE_NATIVE_ENDIAN
,
314 static const VMStateDescription vmstate_stellaris_gptm
= {
315 .name
= "stellaris_gptm",
317 .minimum_version_id
= 1,
318 .fields
= (VMStateField
[]) {
319 VMSTATE_UINT32(config
, gptm_state
),
320 VMSTATE_UINT32_ARRAY(mode
, gptm_state
, 2),
321 VMSTATE_UINT32(control
, gptm_state
),
322 VMSTATE_UINT32(state
, gptm_state
),
323 VMSTATE_UINT32(mask
, gptm_state
),
325 VMSTATE_UINT32_ARRAY(load
, gptm_state
, 2),
326 VMSTATE_UINT32_ARRAY(match
, gptm_state
, 2),
327 VMSTATE_UINT32_ARRAY(prescale
, gptm_state
, 2),
328 VMSTATE_UINT32_ARRAY(match_prescale
, gptm_state
, 2),
329 VMSTATE_UINT32(rtc
, gptm_state
),
330 VMSTATE_INT64_ARRAY(tick
, gptm_state
, 2),
331 VMSTATE_TIMER_PTR_ARRAY(timer
, gptm_state
, 2),
332 VMSTATE_END_OF_LIST()
336 static void stellaris_gptm_init(Object
*obj
)
338 DeviceState
*dev
= DEVICE(obj
);
339 gptm_state
*s
= STELLARIS_GPTM(obj
);
340 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
342 sysbus_init_irq(sbd
, &s
->irq
);
343 qdev_init_gpio_out(dev
, &s
->trigger
, 1);
345 memory_region_init_io(&s
->iomem
, obj
, &gptm_ops
, s
,
347 sysbus_init_mmio(sbd
, &s
->iomem
);
349 s
->opaque
[0] = s
->opaque
[1] = s
;
352 static void stellaris_gptm_realize(DeviceState
*dev
, Error
**errp
)
354 gptm_state
*s
= STELLARIS_GPTM(dev
);
355 s
->timer
[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL
, gptm_tick
, &s
->opaque
[0]);
356 s
->timer
[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL
, gptm_tick
, &s
->opaque
[1]);
359 /* System controller. */
361 #define TYPE_STELLARIS_SYS "stellaris-sys"
362 OBJECT_DECLARE_SIMPLE_TYPE(ssys_state
, STELLARIS_SYS
)
365 SysBusDevice parent_obj
;
382 /* Properties (all read-only registers) */
394 static void ssys_update(ssys_state
*s
)
396 qemu_set_irq(s
->irq
, (s
->int_status
& s
->int_mask
) != 0);
399 static uint32_t pllcfg_sandstorm
[16] = {
401 0x1ae0, /* 1.8432 Mhz */
403 0xd573, /* 2.4576 Mhz */
404 0x37a6, /* 3.57954 Mhz */
405 0x1ae2, /* 3.6864 Mhz */
407 0x98bc, /* 4.906 Mhz */
408 0x935b, /* 4.9152 Mhz */
410 0x4dee, /* 5.12 Mhz */
412 0x75db, /* 6.144 Mhz */
413 0x1ae6, /* 7.3728 Mhz */
415 0x585b /* 8.192 Mhz */
418 static uint32_t pllcfg_fury
[16] = {
420 0x1b20, /* 1.8432 Mhz */
422 0xf42b, /* 2.4576 Mhz */
423 0x37e3, /* 3.57954 Mhz */
424 0x1b21, /* 3.6864 Mhz */
426 0x98ee, /* 4.906 Mhz */
427 0xd5b4, /* 4.9152 Mhz */
429 0x4e27, /* 5.12 Mhz */
431 0xec1c, /* 6.144 Mhz */
432 0x1b23, /* 7.3728 Mhz */
434 0xb11c /* 8.192 Mhz */
437 #define DID0_VER_MASK 0x70000000
438 #define DID0_VER_0 0x00000000
439 #define DID0_VER_1 0x10000000
441 #define DID0_CLASS_MASK 0x00FF0000
442 #define DID0_CLASS_SANDSTORM 0x00000000
443 #define DID0_CLASS_FURY 0x00010000
445 static int ssys_board_class(const ssys_state
*s
)
447 uint32_t did0
= s
->did0
;
448 switch (did0
& DID0_VER_MASK
) {
450 return DID0_CLASS_SANDSTORM
;
452 switch (did0
& DID0_CLASS_MASK
) {
453 case DID0_CLASS_SANDSTORM
:
454 case DID0_CLASS_FURY
:
455 return did0
& DID0_CLASS_MASK
;
457 /* for unknown classes, fall through */
459 /* This can only happen if the hardwired constant did0 value
460 * in this board's stellaris_board_info struct is wrong.
462 g_assert_not_reached();
466 static uint64_t ssys_read(void *opaque
, hwaddr offset
,
469 ssys_state
*s
= (ssys_state
*)opaque
;
472 case 0x000: /* DID0 */
474 case 0x004: /* DID1 */
476 case 0x008: /* DC0 */
478 case 0x010: /* DC1 */
480 case 0x014: /* DC2 */
482 case 0x018: /* DC3 */
484 case 0x01c: /* DC4 */
486 case 0x030: /* PBORCTL */
488 case 0x034: /* LDOPCTL */
490 case 0x040: /* SRCR0 */
492 case 0x044: /* SRCR1 */
494 case 0x048: /* SRCR2 */
496 case 0x050: /* RIS */
497 return s
->int_status
;
498 case 0x054: /* IMC */
500 case 0x058: /* MISC */
501 return s
->int_status
& s
->int_mask
;
502 case 0x05c: /* RESC */
504 case 0x060: /* RCC */
506 case 0x064: /* PLLCFG */
509 xtal
= (s
->rcc
>> 6) & 0xf;
510 switch (ssys_board_class(s
)) {
511 case DID0_CLASS_FURY
:
512 return pllcfg_fury
[xtal
];
513 case DID0_CLASS_SANDSTORM
:
514 return pllcfg_sandstorm
[xtal
];
516 g_assert_not_reached();
519 case 0x070: /* RCC2 */
521 case 0x100: /* RCGC0 */
523 case 0x104: /* RCGC1 */
525 case 0x108: /* RCGC2 */
527 case 0x110: /* SCGC0 */
529 case 0x114: /* SCGC1 */
531 case 0x118: /* SCGC2 */
533 case 0x120: /* DCGC0 */
535 case 0x124: /* DCGC1 */
537 case 0x128: /* DCGC2 */
539 case 0x150: /* CLKVCLR */
541 case 0x160: /* LDOARST */
543 case 0x1e0: /* USER0 */
545 case 0x1e4: /* USER1 */
548 qemu_log_mask(LOG_GUEST_ERROR
,
549 "SSYS: read at bad offset 0x%x\n", (int)offset
);
554 static bool ssys_use_rcc2(ssys_state
*s
)
556 return (s
->rcc2
>> 31) & 0x1;
560 * Calculate the system clock period. We only want to propagate
561 * this change to the rest of the system if we're not being called
562 * from migration post-load.
564 static void ssys_calculate_system_clock(ssys_state
*s
, bool propagate_clock
)
567 * SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc. Input
568 * clock is 200MHz, which is a period of 5 ns. Dividing the clock
569 * frequency by X is the same as multiplying the period by X.
571 if (ssys_use_rcc2(s
)) {
572 system_clock_scale
= 5 * (((s
->rcc2
>> 23) & 0x3f) + 1);
574 system_clock_scale
= 5 * (((s
->rcc
>> 23) & 0xf) + 1);
576 clock_set_ns(s
->sysclk
, system_clock_scale
);
577 if (propagate_clock
) {
578 clock_propagate(s
->sysclk
);
582 static void ssys_write(void *opaque
, hwaddr offset
,
583 uint64_t value
, unsigned size
)
585 ssys_state
*s
= (ssys_state
*)opaque
;
588 case 0x030: /* PBORCTL */
589 s
->pborctl
= value
& 0xffff;
591 case 0x034: /* LDOPCTL */
592 s
->ldopctl
= value
& 0x1f;
594 case 0x040: /* SRCR0 */
595 case 0x044: /* SRCR1 */
596 case 0x048: /* SRCR2 */
597 qemu_log_mask(LOG_UNIMP
, "Peripheral reset not implemented\n");
599 case 0x054: /* IMC */
600 s
->int_mask
= value
& 0x7f;
602 case 0x058: /* MISC */
603 s
->int_status
&= ~value
;
605 case 0x05c: /* RESC */
606 s
->resc
= value
& 0x3f;
608 case 0x060: /* RCC */
609 if ((s
->rcc
& (1 << 13)) != 0 && (value
& (1 << 13)) == 0) {
611 s
->int_status
|= (1 << 6);
614 ssys_calculate_system_clock(s
, true);
616 case 0x070: /* RCC2 */
617 if (ssys_board_class(s
) == DID0_CLASS_SANDSTORM
) {
621 if ((s
->rcc2
& (1 << 13)) != 0 && (value
& (1 << 13)) == 0) {
623 s
->int_status
|= (1 << 6);
626 ssys_calculate_system_clock(s
, true);
628 case 0x100: /* RCGC0 */
631 case 0x104: /* RCGC1 */
634 case 0x108: /* RCGC2 */
637 case 0x110: /* SCGC0 */
640 case 0x114: /* SCGC1 */
643 case 0x118: /* SCGC2 */
646 case 0x120: /* DCGC0 */
649 case 0x124: /* DCGC1 */
652 case 0x128: /* DCGC2 */
655 case 0x150: /* CLKVCLR */
658 case 0x160: /* LDOARST */
662 qemu_log_mask(LOG_GUEST_ERROR
,
663 "SSYS: write at bad offset 0x%x\n", (int)offset
);
668 static const MemoryRegionOps ssys_ops
= {
671 .endianness
= DEVICE_NATIVE_ENDIAN
,
674 static void stellaris_sys_reset_enter(Object
*obj
, ResetType type
)
676 ssys_state
*s
= STELLARIS_SYS(obj
);
681 if (ssys_board_class(s
) == DID0_CLASS_SANDSTORM
) {
684 s
->rcc2
= 0x07802810;
691 static void stellaris_sys_reset_hold(Object
*obj
)
693 ssys_state
*s
= STELLARIS_SYS(obj
);
695 /* OK to propagate clocks from the hold phase */
696 ssys_calculate_system_clock(s
, true);
699 static void stellaris_sys_reset_exit(Object
*obj
)
703 static int stellaris_sys_post_load(void *opaque
, int version_id
)
705 ssys_state
*s
= opaque
;
707 ssys_calculate_system_clock(s
, false);
712 static const VMStateDescription vmstate_stellaris_sys
= {
713 .name
= "stellaris_sys",
715 .minimum_version_id
= 1,
716 .post_load
= stellaris_sys_post_load
,
717 .fields
= (VMStateField
[]) {
718 VMSTATE_UINT32(pborctl
, ssys_state
),
719 VMSTATE_UINT32(ldopctl
, ssys_state
),
720 VMSTATE_UINT32(int_mask
, ssys_state
),
721 VMSTATE_UINT32(int_status
, ssys_state
),
722 VMSTATE_UINT32(resc
, ssys_state
),
723 VMSTATE_UINT32(rcc
, ssys_state
),
724 VMSTATE_UINT32_V(rcc2
, ssys_state
, 2),
725 VMSTATE_UINT32_ARRAY(rcgc
, ssys_state
, 3),
726 VMSTATE_UINT32_ARRAY(scgc
, ssys_state
, 3),
727 VMSTATE_UINT32_ARRAY(dcgc
, ssys_state
, 3),
728 VMSTATE_UINT32(clkvclr
, ssys_state
),
729 VMSTATE_UINT32(ldoarst
, ssys_state
),
730 /* No field for sysclk -- handled in post-load instead */
731 VMSTATE_END_OF_LIST()
735 static Property stellaris_sys_properties
[] = {
736 DEFINE_PROP_UINT32("user0", ssys_state
, user0
, 0),
737 DEFINE_PROP_UINT32("user1", ssys_state
, user1
, 0),
738 DEFINE_PROP_UINT32("did0", ssys_state
, did0
, 0),
739 DEFINE_PROP_UINT32("did1", ssys_state
, did1
, 0),
740 DEFINE_PROP_UINT32("dc0", ssys_state
, dc0
, 0),
741 DEFINE_PROP_UINT32("dc1", ssys_state
, dc1
, 0),
742 DEFINE_PROP_UINT32("dc2", ssys_state
, dc2
, 0),
743 DEFINE_PROP_UINT32("dc3", ssys_state
, dc3
, 0),
744 DEFINE_PROP_UINT32("dc4", ssys_state
, dc4
, 0),
745 DEFINE_PROP_END_OF_LIST()
748 static void stellaris_sys_instance_init(Object
*obj
)
750 ssys_state
*s
= STELLARIS_SYS(obj
);
751 SysBusDevice
*sbd
= SYS_BUS_DEVICE(s
);
753 memory_region_init_io(&s
->iomem
, obj
, &ssys_ops
, s
, "ssys", 0x00001000);
754 sysbus_init_mmio(sbd
, &s
->iomem
);
755 sysbus_init_irq(sbd
, &s
->irq
);
756 s
->sysclk
= qdev_init_clock_out(DEVICE(s
), "SYSCLK");
759 static DeviceState
*stellaris_sys_init(uint32_t base
, qemu_irq irq
,
760 stellaris_board_info
*board
,
763 DeviceState
*dev
= qdev_new(TYPE_STELLARIS_SYS
);
764 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
766 /* Most devices come preprogrammed with a MAC address in the user data. */
767 qdev_prop_set_uint32(dev
, "user0",
768 macaddr
[0] | (macaddr
[1] << 8) | (macaddr
[2] << 16));
769 qdev_prop_set_uint32(dev
, "user1",
770 macaddr
[3] | (macaddr
[4] << 8) | (macaddr
[5] << 16));
771 qdev_prop_set_uint32(dev
, "did0", board
->did0
);
772 qdev_prop_set_uint32(dev
, "did1", board
->did1
);
773 qdev_prop_set_uint32(dev
, "dc0", board
->dc0
);
774 qdev_prop_set_uint32(dev
, "dc1", board
->dc1
);
775 qdev_prop_set_uint32(dev
, "dc2", board
->dc2
);
776 qdev_prop_set_uint32(dev
, "dc3", board
->dc3
);
777 qdev_prop_set_uint32(dev
, "dc4", board
->dc4
);
779 sysbus_realize_and_unref(sbd
, &error_fatal
);
780 sysbus_mmio_map(sbd
, 0, base
);
781 sysbus_connect_irq(sbd
, 0, irq
);
784 * Normally we should not be resetting devices like this during
785 * board creation. For the moment we need to do so, because
786 * system_clock_scale will only get set when the STELLARIS_SYS
787 * device is reset, and we need its initial value to pass to
788 * the watchdog device. This hack can be removed once the
789 * watchdog has been converted to use a Clock input instead.
791 device_cold_reset(dev
);
796 /* I2C controller. */
798 #define TYPE_STELLARIS_I2C "stellaris-i2c"
799 OBJECT_DECLARE_SIMPLE_TYPE(stellaris_i2c_state
, STELLARIS_I2C
)
801 struct stellaris_i2c_state
{
802 SysBusDevice parent_obj
;
816 #define STELLARIS_I2C_MCS_BUSY 0x01
817 #define STELLARIS_I2C_MCS_ERROR 0x02
818 #define STELLARIS_I2C_MCS_ADRACK 0x04
819 #define STELLARIS_I2C_MCS_DATACK 0x08
820 #define STELLARIS_I2C_MCS_ARBLST 0x10
821 #define STELLARIS_I2C_MCS_IDLE 0x20
822 #define STELLARIS_I2C_MCS_BUSBSY 0x40
824 static uint64_t stellaris_i2c_read(void *opaque
, hwaddr offset
,
827 stellaris_i2c_state
*s
= (stellaris_i2c_state
*)opaque
;
833 /* We don't emulate timing, so the controller is never busy. */
834 return s
->mcs
| STELLARIS_I2C_MCS_IDLE
;
837 case 0x0c: /* MTPR */
839 case 0x10: /* MIMR */
841 case 0x14: /* MRIS */
843 case 0x18: /* MMIS */
844 return s
->mris
& s
->mimr
;
848 qemu_log_mask(LOG_GUEST_ERROR
,
849 "stellaris_i2c: read at bad offset 0x%x\n", (int)offset
);
854 static void stellaris_i2c_update(stellaris_i2c_state
*s
)
858 level
= (s
->mris
& s
->mimr
) != 0;
859 qemu_set_irq(s
->irq
, level
);
862 static void stellaris_i2c_write(void *opaque
, hwaddr offset
,
863 uint64_t value
, unsigned size
)
865 stellaris_i2c_state
*s
= (stellaris_i2c_state
*)opaque
;
869 s
->msa
= value
& 0xff;
872 if ((s
->mcr
& 0x10) == 0) {
873 /* Disabled. Do nothing. */
876 /* Grab the bus if this is starting a transfer. */
877 if ((value
& 2) && (s
->mcs
& STELLARIS_I2C_MCS_BUSBSY
) == 0) {
878 if (i2c_start_transfer(s
->bus
, s
->msa
>> 1, s
->msa
& 1)) {
879 s
->mcs
|= STELLARIS_I2C_MCS_ARBLST
;
881 s
->mcs
&= ~STELLARIS_I2C_MCS_ARBLST
;
882 s
->mcs
|= STELLARIS_I2C_MCS_BUSBSY
;
885 /* If we don't have the bus then indicate an error. */
886 if (!i2c_bus_busy(s
->bus
)
887 || (s
->mcs
& STELLARIS_I2C_MCS_BUSBSY
) == 0) {
888 s
->mcs
|= STELLARIS_I2C_MCS_ERROR
;
891 s
->mcs
&= ~STELLARIS_I2C_MCS_ERROR
;
893 /* Transfer a byte. */
894 /* TODO: Handle errors. */
897 s
->mdr
= i2c_recv(s
->bus
);
900 i2c_send(s
->bus
, s
->mdr
);
902 /* Raise an interrupt. */
906 /* Finish transfer. */
907 i2c_end_transfer(s
->bus
);
908 s
->mcs
&= ~STELLARIS_I2C_MCS_BUSBSY
;
912 s
->mdr
= value
& 0xff;
914 case 0x0c: /* MTPR */
915 s
->mtpr
= value
& 0xff;
917 case 0x10: /* MIMR */
920 case 0x1c: /* MICR */
925 qemu_log_mask(LOG_UNIMP
,
926 "stellaris_i2c: Loopback not implemented\n");
929 qemu_log_mask(LOG_UNIMP
,
930 "stellaris_i2c: Slave mode not implemented\n");
932 s
->mcr
= value
& 0x31;
935 qemu_log_mask(LOG_GUEST_ERROR
,
936 "stellaris_i2c: write at bad offset 0x%x\n", (int)offset
);
938 stellaris_i2c_update(s
);
941 static void stellaris_i2c_reset(stellaris_i2c_state
*s
)
943 if (s
->mcs
& STELLARIS_I2C_MCS_BUSBSY
)
944 i2c_end_transfer(s
->bus
);
953 stellaris_i2c_update(s
);
956 static const MemoryRegionOps stellaris_i2c_ops
= {
957 .read
= stellaris_i2c_read
,
958 .write
= stellaris_i2c_write
,
959 .endianness
= DEVICE_NATIVE_ENDIAN
,
962 static const VMStateDescription vmstate_stellaris_i2c
= {
963 .name
= "stellaris_i2c",
965 .minimum_version_id
= 1,
966 .fields
= (VMStateField
[]) {
967 VMSTATE_UINT32(msa
, stellaris_i2c_state
),
968 VMSTATE_UINT32(mcs
, stellaris_i2c_state
),
969 VMSTATE_UINT32(mdr
, stellaris_i2c_state
),
970 VMSTATE_UINT32(mtpr
, stellaris_i2c_state
),
971 VMSTATE_UINT32(mimr
, stellaris_i2c_state
),
972 VMSTATE_UINT32(mris
, stellaris_i2c_state
),
973 VMSTATE_UINT32(mcr
, stellaris_i2c_state
),
974 VMSTATE_END_OF_LIST()
978 static void stellaris_i2c_init(Object
*obj
)
980 DeviceState
*dev
= DEVICE(obj
);
981 stellaris_i2c_state
*s
= STELLARIS_I2C(obj
);
982 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
985 sysbus_init_irq(sbd
, &s
->irq
);
986 bus
= i2c_init_bus(dev
, "i2c");
989 memory_region_init_io(&s
->iomem
, obj
, &stellaris_i2c_ops
, s
,
991 sysbus_init_mmio(sbd
, &s
->iomem
);
992 /* ??? For now we only implement the master interface. */
993 stellaris_i2c_reset(s
);
996 /* Analogue to Digital Converter. This is only partially implemented,
997 enough for applications that use a combined ADC and timer tick. */
999 #define STELLARIS_ADC_EM_CONTROLLER 0
1000 #define STELLARIS_ADC_EM_COMP 1
1001 #define STELLARIS_ADC_EM_EXTERNAL 4
1002 #define STELLARIS_ADC_EM_TIMER 5
1003 #define STELLARIS_ADC_EM_PWM0 6
1004 #define STELLARIS_ADC_EM_PWM1 7
1005 #define STELLARIS_ADC_EM_PWM2 8
1007 #define STELLARIS_ADC_FIFO_EMPTY 0x0100
1008 #define STELLARIS_ADC_FIFO_FULL 0x1000
1010 #define TYPE_STELLARIS_ADC "stellaris-adc"
1011 typedef struct StellarisADCState stellaris_adc_state
;
1012 DECLARE_INSTANCE_CHECKER(stellaris_adc_state
, STELLARIS_ADC
,
1015 struct StellarisADCState
{
1016 SysBusDevice parent_obj
;
1037 static uint32_t stellaris_adc_fifo_read(stellaris_adc_state
*s
, int n
)
1041 tail
= s
->fifo
[n
].state
& 0xf;
1042 if (s
->fifo
[n
].state
& STELLARIS_ADC_FIFO_EMPTY
) {
1045 s
->fifo
[n
].state
= (s
->fifo
[n
].state
& ~0xf) | ((tail
+ 1) & 0xf);
1046 s
->fifo
[n
].state
&= ~STELLARIS_ADC_FIFO_FULL
;
1047 if (tail
+ 1 == ((s
->fifo
[n
].state
>> 4) & 0xf))
1048 s
->fifo
[n
].state
|= STELLARIS_ADC_FIFO_EMPTY
;
1050 return s
->fifo
[n
].data
[tail
];
1053 static void stellaris_adc_fifo_write(stellaris_adc_state
*s
, int n
,
1058 /* TODO: Real hardware has limited size FIFOs. We have a full 16 entry
1059 FIFO fir each sequencer. */
1060 head
= (s
->fifo
[n
].state
>> 4) & 0xf;
1061 if (s
->fifo
[n
].state
& STELLARIS_ADC_FIFO_FULL
) {
1065 s
->fifo
[n
].data
[head
] = value
;
1066 head
= (head
+ 1) & 0xf;
1067 s
->fifo
[n
].state
&= ~STELLARIS_ADC_FIFO_EMPTY
;
1068 s
->fifo
[n
].state
= (s
->fifo
[n
].state
& ~0xf0) | (head
<< 4);
1069 if ((s
->fifo
[n
].state
& 0xf) == head
)
1070 s
->fifo
[n
].state
|= STELLARIS_ADC_FIFO_FULL
;
1073 static void stellaris_adc_update(stellaris_adc_state
*s
)
1078 for (n
= 0; n
< 4; n
++) {
1079 level
= (s
->ris
& s
->im
& (1 << n
)) != 0;
1080 qemu_set_irq(s
->irq
[n
], level
);
1084 static void stellaris_adc_trigger(void *opaque
, int irq
, int level
)
1086 stellaris_adc_state
*s
= (stellaris_adc_state
*)opaque
;
1089 for (n
= 0; n
< 4; n
++) {
1090 if ((s
->actss
& (1 << n
)) == 0) {
1094 if (((s
->emux
>> (n
* 4)) & 0xff) != 5) {
1098 /* Some applications use the ADC as a random number source, so introduce
1099 some variation into the signal. */
1100 s
->noise
= s
->noise
* 314159 + 1;
1101 /* ??? actual inputs not implemented. Return an arbitrary value. */
1102 stellaris_adc_fifo_write(s
, n
, 0x200 + ((s
->noise
>> 16) & 7));
1104 stellaris_adc_update(s
);
1108 static void stellaris_adc_reset(stellaris_adc_state
*s
)
1112 for (n
= 0; n
< 4; n
++) {
1115 s
->fifo
[n
].state
= STELLARIS_ADC_FIFO_EMPTY
;
1119 static uint64_t stellaris_adc_read(void *opaque
, hwaddr offset
,
1122 stellaris_adc_state
*s
= (stellaris_adc_state
*)opaque
;
1124 /* TODO: Implement this. */
1125 if (offset
>= 0x40 && offset
< 0xc0) {
1127 n
= (offset
- 0x40) >> 5;
1128 switch (offset
& 0x1f) {
1129 case 0x00: /* SSMUX */
1131 case 0x04: /* SSCTL */
1133 case 0x08: /* SSFIFO */
1134 return stellaris_adc_fifo_read(s
, n
);
1135 case 0x0c: /* SSFSTAT */
1136 return s
->fifo
[n
].state
;
1142 case 0x00: /* ACTSS */
1144 case 0x04: /* RIS */
1148 case 0x0c: /* ISC */
1149 return s
->ris
& s
->im
;
1150 case 0x10: /* OSTAT */
1152 case 0x14: /* EMUX */
1154 case 0x18: /* USTAT */
1156 case 0x20: /* SSPRI */
1158 case 0x30: /* SAC */
1161 qemu_log_mask(LOG_GUEST_ERROR
,
1162 "stellaris_adc: read at bad offset 0x%x\n", (int)offset
);
1167 static void stellaris_adc_write(void *opaque
, hwaddr offset
,
1168 uint64_t value
, unsigned size
)
1170 stellaris_adc_state
*s
= (stellaris_adc_state
*)opaque
;
1172 /* TODO: Implement this. */
1173 if (offset
>= 0x40 && offset
< 0xc0) {
1175 n
= (offset
- 0x40) >> 5;
1176 switch (offset
& 0x1f) {
1177 case 0x00: /* SSMUX */
1178 s
->ssmux
[n
] = value
& 0x33333333;
1180 case 0x04: /* SSCTL */
1182 qemu_log_mask(LOG_UNIMP
,
1183 "ADC: Unimplemented sequence %" PRIx64
"\n",
1186 s
->ssctl
[n
] = value
;
1193 case 0x00: /* ACTSS */
1194 s
->actss
= value
& 0xf;
1199 case 0x0c: /* ISC */
1202 case 0x10: /* OSTAT */
1205 case 0x14: /* EMUX */
1208 case 0x18: /* USTAT */
1211 case 0x20: /* SSPRI */
1214 case 0x28: /* PSSI */
1215 qemu_log_mask(LOG_UNIMP
, "ADC: sample initiate unimplemented\n");
1217 case 0x30: /* SAC */
1221 qemu_log_mask(LOG_GUEST_ERROR
,
1222 "stellaris_adc: write at bad offset 0x%x\n", (int)offset
);
1224 stellaris_adc_update(s
);
1227 static const MemoryRegionOps stellaris_adc_ops
= {
1228 .read
= stellaris_adc_read
,
1229 .write
= stellaris_adc_write
,
1230 .endianness
= DEVICE_NATIVE_ENDIAN
,
1233 static const VMStateDescription vmstate_stellaris_adc
= {
1234 .name
= "stellaris_adc",
1236 .minimum_version_id
= 1,
1237 .fields
= (VMStateField
[]) {
1238 VMSTATE_UINT32(actss
, stellaris_adc_state
),
1239 VMSTATE_UINT32(ris
, stellaris_adc_state
),
1240 VMSTATE_UINT32(im
, stellaris_adc_state
),
1241 VMSTATE_UINT32(emux
, stellaris_adc_state
),
1242 VMSTATE_UINT32(ostat
, stellaris_adc_state
),
1243 VMSTATE_UINT32(ustat
, stellaris_adc_state
),
1244 VMSTATE_UINT32(sspri
, stellaris_adc_state
),
1245 VMSTATE_UINT32(sac
, stellaris_adc_state
),
1246 VMSTATE_UINT32(fifo
[0].state
, stellaris_adc_state
),
1247 VMSTATE_UINT32_ARRAY(fifo
[0].data
, stellaris_adc_state
, 16),
1248 VMSTATE_UINT32(ssmux
[0], stellaris_adc_state
),
1249 VMSTATE_UINT32(ssctl
[0], stellaris_adc_state
),
1250 VMSTATE_UINT32(fifo
[1].state
, stellaris_adc_state
),
1251 VMSTATE_UINT32_ARRAY(fifo
[1].data
, stellaris_adc_state
, 16),
1252 VMSTATE_UINT32(ssmux
[1], stellaris_adc_state
),
1253 VMSTATE_UINT32(ssctl
[1], stellaris_adc_state
),
1254 VMSTATE_UINT32(fifo
[2].state
, stellaris_adc_state
),
1255 VMSTATE_UINT32_ARRAY(fifo
[2].data
, stellaris_adc_state
, 16),
1256 VMSTATE_UINT32(ssmux
[2], stellaris_adc_state
),
1257 VMSTATE_UINT32(ssctl
[2], stellaris_adc_state
),
1258 VMSTATE_UINT32(fifo
[3].state
, stellaris_adc_state
),
1259 VMSTATE_UINT32_ARRAY(fifo
[3].data
, stellaris_adc_state
, 16),
1260 VMSTATE_UINT32(ssmux
[3], stellaris_adc_state
),
1261 VMSTATE_UINT32(ssctl
[3], stellaris_adc_state
),
1262 VMSTATE_UINT32(noise
, stellaris_adc_state
),
1263 VMSTATE_END_OF_LIST()
1267 static void stellaris_adc_init(Object
*obj
)
1269 DeviceState
*dev
= DEVICE(obj
);
1270 stellaris_adc_state
*s
= STELLARIS_ADC(obj
);
1271 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
1274 for (n
= 0; n
< 4; n
++) {
1275 sysbus_init_irq(sbd
, &s
->irq
[n
]);
1278 memory_region_init_io(&s
->iomem
, obj
, &stellaris_adc_ops
, s
,
1280 sysbus_init_mmio(sbd
, &s
->iomem
);
1281 stellaris_adc_reset(s
);
1282 qdev_init_gpio_in(dev
, stellaris_adc_trigger
, 1);
1286 static stellaris_board_info stellaris_boards
[] = {
1290 0x001f001f, /* dc0 */
1300 0x00ff007f, /* dc0 */
1305 BP_OLED_SSI
| BP_GAMEPAD
1309 static void stellaris_init(MachineState
*ms
, stellaris_board_info
*board
)
1311 static const int uart_irq
[] = {5, 6, 33, 34};
1312 static const int timer_irq
[] = {19, 21, 23, 35};
1313 static const uint32_t gpio_addr
[7] =
1314 { 0x40004000, 0x40005000, 0x40006000, 0x40007000,
1315 0x40024000, 0x40025000, 0x40026000};
1316 static const int gpio_irq
[7] = {0, 1, 2, 3, 4, 30, 31};
1318 /* Memory map of SoC devices, from
1319 * Stellaris LM3S6965 Microcontroller Data Sheet (rev I)
1320 * http://www.ti.com/lit/ds/symlink/lm3s6965.pdf
1323 * 40002000 i2c (unimplemented)
1333 * 40021000 i2c (unimplemented)
1337 * 40028000 PWM (unimplemented)
1338 * 4002c000 QEI (unimplemented)
1339 * 4002d000 QEI (unimplemented)
1345 * 4003c000 analogue comparator (unimplemented)
1347 * 400fc000 hibernation module (unimplemented)
1348 * 400fd000 flash memory control (unimplemented)
1349 * 400fe000 system control
1352 DeviceState
*gpio_dev
[7], *nvic
;
1353 qemu_irq gpio_in
[7][8];
1354 qemu_irq gpio_out
[7][8];
1360 DeviceState
*ssys_dev
;
1364 MemoryRegion
*sram
= g_new(MemoryRegion
, 1);
1365 MemoryRegion
*flash
= g_new(MemoryRegion
, 1);
1366 MemoryRegion
*system_memory
= get_system_memory();
1368 flash_size
= (((board
->dc0
& 0xffff) + 1) << 1) * 1024;
1369 sram_size
= ((board
->dc0
>> 18) + 1) * 1024;
1371 /* Flash programming is done via the SCU, so pretend it is ROM. */
1372 memory_region_init_rom(flash
, NULL
, "stellaris.flash", flash_size
,
1374 memory_region_add_subregion(system_memory
, 0, flash
);
1376 memory_region_init_ram(sram
, NULL
, "stellaris.sram", sram_size
,
1378 memory_region_add_subregion(system_memory
, 0x20000000, sram
);
1380 nvic
= qdev_new(TYPE_ARMV7M
);
1381 qdev_prop_set_uint32(nvic
, "num-irq", NUM_IRQ_LINES
);
1382 qdev_prop_set_string(nvic
, "cpu-type", ms
->cpu_type
);
1383 qdev_prop_set_bit(nvic
, "enable-bitband", true);
1384 object_property_set_link(OBJECT(nvic
), "memory",
1385 OBJECT(get_system_memory()), &error_abort
);
1386 /* This will exit with an error if the user passed us a bad cpu_type */
1387 sysbus_realize_and_unref(SYS_BUS_DEVICE(nvic
), &error_fatal
);
1389 if (board
->dc1
& (1 << 16)) {
1390 dev
= sysbus_create_varargs(TYPE_STELLARIS_ADC
, 0x40038000,
1391 qdev_get_gpio_in(nvic
, 14),
1392 qdev_get_gpio_in(nvic
, 15),
1393 qdev_get_gpio_in(nvic
, 16),
1394 qdev_get_gpio_in(nvic
, 17),
1396 adc
= qdev_get_gpio_in(dev
, 0);
1400 for (i
= 0; i
< 4; i
++) {
1401 if (board
->dc2
& (0x10000 << i
)) {
1402 dev
= sysbus_create_simple(TYPE_STELLARIS_GPTM
,
1403 0x40030000 + i
* 0x1000,
1404 qdev_get_gpio_in(nvic
, timer_irq
[i
]));
1405 /* TODO: This is incorrect, but we get away with it because
1406 the ADC output is only ever pulsed. */
1407 qdev_connect_gpio_out(dev
, 0, adc
);
1411 ssys_dev
= stellaris_sys_init(0x400fe000, qdev_get_gpio_in(nvic
, 28),
1412 board
, nd_table
[0].macaddr
.a
);
1415 if (board
->dc1
& (1 << 3)) { /* watchdog present */
1416 dev
= qdev_new(TYPE_LUMINARY_WATCHDOG
);
1418 qdev_connect_clock_in(dev
, "WDOGCLK",
1419 qdev_get_clock_out(ssys_dev
, "SYSCLK"));
1421 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
1422 sysbus_mmio_map(SYS_BUS_DEVICE(dev
),
1425 sysbus_connect_irq(SYS_BUS_DEVICE(dev
),
1427 qdev_get_gpio_in(nvic
, 18));
1431 for (i
= 0; i
< 7; i
++) {
1432 if (board
->dc4
& (1 << i
)) {
1433 gpio_dev
[i
] = sysbus_create_simple("pl061_luminary", gpio_addr
[i
],
1434 qdev_get_gpio_in(nvic
,
1436 for (j
= 0; j
< 8; j
++) {
1437 gpio_in
[i
][j
] = qdev_get_gpio_in(gpio_dev
[i
], j
);
1438 gpio_out
[i
][j
] = NULL
;
1443 if (board
->dc2
& (1 << 12)) {
1444 dev
= sysbus_create_simple(TYPE_STELLARIS_I2C
, 0x40020000,
1445 qdev_get_gpio_in(nvic
, 8));
1446 i2c
= (I2CBus
*)qdev_get_child_bus(dev
, "i2c");
1447 if (board
->peripherals
& BP_OLED_I2C
) {
1448 i2c_slave_create_simple(i2c
, "ssd0303", 0x3d);
1452 for (i
= 0; i
< 4; i
++) {
1453 if (board
->dc2
& (1 << i
)) {
1454 pl011_luminary_create(0x4000c000 + i
* 0x1000,
1455 qdev_get_gpio_in(nvic
, uart_irq
[i
]),
1459 if (board
->dc2
& (1 << 4)) {
1460 dev
= sysbus_create_simple("pl022", 0x40008000,
1461 qdev_get_gpio_in(nvic
, 7));
1462 if (board
->peripherals
& BP_OLED_SSI
) {
1465 DeviceState
*ssddev
;
1467 /* Some boards have both an OLED controller and SD card connected to
1468 * the same SSI port, with the SD card chip select connected to a
1469 * GPIO pin. Technically the OLED chip select is connected to the
1470 * SSI Fss pin. We do not bother emulating that as both devices
1471 * should never be selected simultaneously, and our OLED controller
1472 * ignores stray 0xff commands that occur when deselecting the SD
1475 bus
= qdev_get_child_bus(dev
, "ssi");
1477 sddev
= ssi_create_peripheral(bus
, "ssi-sd");
1478 ssddev
= ssi_create_peripheral(bus
, "ssd0323");
1479 gpio_out
[GPIO_D
][0] = qemu_irq_split(
1480 qdev_get_gpio_in_named(sddev
, SSI_GPIO_CS
, 0),
1481 qdev_get_gpio_in_named(ssddev
, SSI_GPIO_CS
, 0));
1482 gpio_out
[GPIO_C
][7] = qdev_get_gpio_in(ssddev
, 0);
1484 /* Make sure the select pin is high. */
1485 qemu_irq_raise(gpio_out
[GPIO_D
][0]);
1488 if (board
->dc4
& (1 << 28)) {
1491 qemu_check_nic_model(&nd_table
[0], "stellaris");
1493 enet
= qdev_new("stellaris_enet");
1494 qdev_set_nic_properties(enet
, &nd_table
[0]);
1495 sysbus_realize_and_unref(SYS_BUS_DEVICE(enet
), &error_fatal
);
1496 sysbus_mmio_map(SYS_BUS_DEVICE(enet
), 0, 0x40048000);
1497 sysbus_connect_irq(SYS_BUS_DEVICE(enet
), 0, qdev_get_gpio_in(nvic
, 42));
1499 if (board
->peripherals
& BP_GAMEPAD
) {
1500 qemu_irq gpad_irq
[5];
1501 static const int gpad_keycode
[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d };
1503 gpad_irq
[0] = qemu_irq_invert(gpio_in
[GPIO_E
][0]); /* up */
1504 gpad_irq
[1] = qemu_irq_invert(gpio_in
[GPIO_E
][1]); /* down */
1505 gpad_irq
[2] = qemu_irq_invert(gpio_in
[GPIO_E
][2]); /* left */
1506 gpad_irq
[3] = qemu_irq_invert(gpio_in
[GPIO_E
][3]); /* right */
1507 gpad_irq
[4] = qemu_irq_invert(gpio_in
[GPIO_F
][1]); /* select */
1509 stellaris_gamepad_init(5, gpad_irq
, gpad_keycode
);
1511 for (i
= 0; i
< 7; i
++) {
1512 if (board
->dc4
& (1 << i
)) {
1513 for (j
= 0; j
< 8; j
++) {
1514 if (gpio_out
[i
][j
]) {
1515 qdev_connect_gpio_out(gpio_dev
[i
], j
, gpio_out
[i
][j
]);
1521 /* Add dummy regions for the devices we don't implement yet,
1522 * so guest accesses don't cause unlogged crashes.
1524 create_unimplemented_device("i2c-0", 0x40002000, 0x1000);
1525 create_unimplemented_device("i2c-2", 0x40021000, 0x1000);
1526 create_unimplemented_device("PWM", 0x40028000, 0x1000);
1527 create_unimplemented_device("QEI-0", 0x4002c000, 0x1000);
1528 create_unimplemented_device("QEI-1", 0x4002d000, 0x1000);
1529 create_unimplemented_device("analogue-comparator", 0x4003c000, 0x1000);
1530 create_unimplemented_device("hibernation", 0x400fc000, 0x1000);
1531 create_unimplemented_device("flash-control", 0x400fd000, 0x1000);
1533 armv7m_load_kernel(ARM_CPU(first_cpu
), ms
->kernel_filename
, flash_size
);
1536 /* FIXME: Figure out how to generate these from stellaris_boards. */
1537 static void lm3s811evb_init(MachineState
*machine
)
1539 stellaris_init(machine
, &stellaris_boards
[0]);
1542 static void lm3s6965evb_init(MachineState
*machine
)
1544 stellaris_init(machine
, &stellaris_boards
[1]);
1547 static void lm3s811evb_class_init(ObjectClass
*oc
, void *data
)
1549 MachineClass
*mc
= MACHINE_CLASS(oc
);
1551 mc
->desc
= "Stellaris LM3S811EVB";
1552 mc
->init
= lm3s811evb_init
;
1553 mc
->ignore_memory_transaction_failures
= true;
1554 mc
->default_cpu_type
= ARM_CPU_TYPE_NAME("cortex-m3");
1557 static const TypeInfo lm3s811evb_type
= {
1558 .name
= MACHINE_TYPE_NAME("lm3s811evb"),
1559 .parent
= TYPE_MACHINE
,
1560 .class_init
= lm3s811evb_class_init
,
1563 static void lm3s6965evb_class_init(ObjectClass
*oc
, void *data
)
1565 MachineClass
*mc
= MACHINE_CLASS(oc
);
1567 mc
->desc
= "Stellaris LM3S6965EVB";
1568 mc
->init
= lm3s6965evb_init
;
1569 mc
->ignore_memory_transaction_failures
= true;
1570 mc
->default_cpu_type
= ARM_CPU_TYPE_NAME("cortex-m3");
1573 static const TypeInfo lm3s6965evb_type
= {
1574 .name
= MACHINE_TYPE_NAME("lm3s6965evb"),
1575 .parent
= TYPE_MACHINE
,
1576 .class_init
= lm3s6965evb_class_init
,
1579 static void stellaris_machine_init(void)
1581 type_register_static(&lm3s811evb_type
);
1582 type_register_static(&lm3s6965evb_type
);
1585 type_init(stellaris_machine_init
)
1587 static void stellaris_i2c_class_init(ObjectClass
*klass
, void *data
)
1589 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1591 dc
->vmsd
= &vmstate_stellaris_i2c
;
1594 static const TypeInfo stellaris_i2c_info
= {
1595 .name
= TYPE_STELLARIS_I2C
,
1596 .parent
= TYPE_SYS_BUS_DEVICE
,
1597 .instance_size
= sizeof(stellaris_i2c_state
),
1598 .instance_init
= stellaris_i2c_init
,
1599 .class_init
= stellaris_i2c_class_init
,
1602 static void stellaris_gptm_class_init(ObjectClass
*klass
, void *data
)
1604 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1606 dc
->vmsd
= &vmstate_stellaris_gptm
;
1607 dc
->realize
= stellaris_gptm_realize
;
1610 static const TypeInfo stellaris_gptm_info
= {
1611 .name
= TYPE_STELLARIS_GPTM
,
1612 .parent
= TYPE_SYS_BUS_DEVICE
,
1613 .instance_size
= sizeof(gptm_state
),
1614 .instance_init
= stellaris_gptm_init
,
1615 .class_init
= stellaris_gptm_class_init
,
1618 static void stellaris_adc_class_init(ObjectClass
*klass
, void *data
)
1620 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1622 dc
->vmsd
= &vmstate_stellaris_adc
;
1625 static const TypeInfo stellaris_adc_info
= {
1626 .name
= TYPE_STELLARIS_ADC
,
1627 .parent
= TYPE_SYS_BUS_DEVICE
,
1628 .instance_size
= sizeof(stellaris_adc_state
),
1629 .instance_init
= stellaris_adc_init
,
1630 .class_init
= stellaris_adc_class_init
,
1633 static void stellaris_sys_class_init(ObjectClass
*klass
, void *data
)
1635 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1636 ResettableClass
*rc
= RESETTABLE_CLASS(klass
);
1638 dc
->vmsd
= &vmstate_stellaris_sys
;
1639 rc
->phases
.enter
= stellaris_sys_reset_enter
;
1640 rc
->phases
.hold
= stellaris_sys_reset_hold
;
1641 rc
->phases
.exit
= stellaris_sys_reset_exit
;
1642 device_class_set_props(dc
, stellaris_sys_properties
);
1645 static const TypeInfo stellaris_sys_info
= {
1646 .name
= TYPE_STELLARIS_SYS
,
1647 .parent
= TYPE_SYS_BUS_DEVICE
,
1648 .instance_size
= sizeof(ssys_state
),
1649 .instance_init
= stellaris_sys_instance_init
,
1650 .class_init
= stellaris_sys_class_init
,
1653 static void stellaris_register_types(void)
1655 type_register_static(&stellaris_i2c_info
);
1656 type_register_static(&stellaris_gptm_info
);
1657 type_register_static(&stellaris_adc_info
);
1658 type_register_static(&stellaris_sys_info
);
1661 type_init(stellaris_register_types
)