2
0

stm32l4x5_soc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. * STM32L4x5 SoC family
  3. *
  4. * Copyright (c) 2023-2024 Arnaud Minier <arnaud.minier@telecom-paris.fr>
  5. * Copyright (c) 2023-2024 Inès Varhol <ines.varhol@telecom-paris.fr>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0-or-later
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. *
  12. * This work is heavily inspired by the stm32f405_soc by Alistair Francis.
  13. * Original code is licensed under the MIT License:
  14. *
  15. * Copyright (c) 2014 Alistair Francis <alistair@alistair23.me>
  16. */
  17. /*
  18. * The reference used is the STMicroElectronics RM0351 Reference manual
  19. * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs.
  20. * https://www.st.com/en/microcontrollers-microprocessors/stm32l4x5/documentation.html
  21. */
  22. #include "qemu/osdep.h"
  23. #include "qemu/units.h"
  24. #include "qapi/error.h"
  25. #include "exec/address-spaces.h"
  26. #include "system/system.h"
  27. #include "hw/or-irq.h"
  28. #include "hw/arm/stm32l4x5_soc.h"
  29. #include "hw/char/stm32l4x5_usart.h"
  30. #include "hw/gpio/stm32l4x5_gpio.h"
  31. #include "hw/qdev-clock.h"
  32. #include "hw/misc/unimp.h"
  33. #define FLASH_BASE_ADDRESS 0x08000000
  34. #define SRAM1_BASE_ADDRESS 0x20000000
  35. #define SRAM1_SIZE (96 * KiB)
  36. #define SRAM2_BASE_ADDRESS 0x10000000
  37. #define SRAM2_SIZE (32 * KiB)
  38. #define EXTI_ADDR 0x40010400
  39. #define SYSCFG_ADDR 0x40010000
  40. #define NUM_EXTI_IRQ 40
  41. /* Match exti line connections with their CPU IRQ number */
  42. /* See Vector Table (Reference Manual p.396) */
  43. /*
  44. * Some IRQs are connected to the same CPU IRQ (denoted by -1)
  45. * and require an intermediary OR gate to function correctly.
  46. */
  47. static const int exti_irq[NUM_EXTI_IRQ] = {
  48. 6, /* GPIO[0] */
  49. 7, /* GPIO[1] */
  50. 8, /* GPIO[2] */
  51. 9, /* GPIO[3] */
  52. 10, /* GPIO[4] */
  53. -1, -1, -1, -1, -1, /* GPIO[5..9] OR gate 23 */
  54. -1, -1, -1, -1, -1, -1, /* GPIO[10..15] OR gate 40 */
  55. -1, /* PVD OR gate 1 */
  56. 67, /* OTG_FS_WKUP, Direct */
  57. 41, /* RTC_ALARM */
  58. 2, /* RTC_TAMP_STAMP2/CSS_LSE */
  59. 3, /* RTC wakeup timer */
  60. -1, -1, /* COMP[1..2] OR gate 63 */
  61. 31, /* I2C1 wakeup, Direct */
  62. 33, /* I2C2 wakeup, Direct */
  63. 72, /* I2C3 wakeup, Direct */
  64. 37, /* USART1 wakeup, Direct */
  65. 38, /* USART2 wakeup, Direct */
  66. 39, /* USART3 wakeup, Direct */
  67. 52, /* UART4 wakeup, Direct */
  68. 53, /* UART4 wakeup, Direct */
  69. 70, /* LPUART1 wakeup, Direct */
  70. 65, /* LPTIM1, Direct */
  71. 66, /* LPTIM2, Direct */
  72. 76, /* SWPMI1 wakeup, Direct */
  73. -1, -1, -1, -1, /* PVM[1..4] OR gate 1 */
  74. 78 /* LCD wakeup, Direct */
  75. };
  76. #define RCC_BASE_ADDRESS 0x40021000
  77. #define RCC_IRQ 5
  78. #define EXTI_USART1_IRQ 26
  79. #define EXTI_UART4_IRQ 29
  80. #define EXTI_LPUART1_IRQ 31
  81. static const int exti_or_gates_out[NUM_EXTI_OR_GATES] = {
  82. 23, 40, 63, 1,
  83. };
  84. static const int exti_or_gates_num_lines_in[NUM_EXTI_OR_GATES] = {
  85. 5, 6, 2, 5,
  86. };
  87. /* 3 OR gates with consecutive inputs */
  88. #define NUM_EXTI_SIMPLE_OR_GATES 3
  89. static const int exti_or_gates_first_line_in[NUM_EXTI_SIMPLE_OR_GATES] = {
  90. 5, 10, 21,
  91. };
  92. /* 1 OR gate with non-consecutive inputs */
  93. #define EXTI_OR_GATE1_NUM_LINES_IN 5
  94. static const int exti_or_gate1_lines_in[EXTI_OR_GATE1_NUM_LINES_IN] = {
  95. 16, 35, 36, 37, 38,
  96. };
  97. static const struct {
  98. uint32_t addr;
  99. uint32_t moder_reset;
  100. uint32_t ospeedr_reset;
  101. uint32_t pupdr_reset;
  102. } stm32l4x5_gpio_cfg[NUM_GPIOS] = {
  103. { 0x48000000, 0xABFFFFFF, 0x0C000000, 0x64000000 },
  104. { 0x48000400, 0xFFFFFEBF, 0x00000000, 0x00000100 },
  105. { 0x48000800, 0xFFFFFFFF, 0x00000000, 0x00000000 },
  106. { 0x48000C00, 0xFFFFFFFF, 0x00000000, 0x00000000 },
  107. { 0x48001000, 0xFFFFFFFF, 0x00000000, 0x00000000 },
  108. { 0x48001400, 0xFFFFFFFF, 0x00000000, 0x00000000 },
  109. { 0x48001800, 0xFFFFFFFF, 0x00000000, 0x00000000 },
  110. { 0x48001C00, 0x0000000F, 0x00000000, 0x00000000 },
  111. };
  112. static const hwaddr usart_addr[] = {
  113. 0x40013800, /* "USART1", 0x400 */
  114. 0x40004400, /* "USART2", 0x400 */
  115. 0x40004800, /* "USART3", 0x400 */
  116. };
  117. static const hwaddr uart_addr[] = {
  118. 0x40004C00, /* "UART4" , 0x400 */
  119. 0x40005000 /* "UART5" , 0x400 */
  120. };
  121. #define LPUART_BASE_ADDRESS 0x40008000
  122. static void stm32l4x5_soc_initfn(Object *obj)
  123. {
  124. Stm32l4x5SocState *s = STM32L4X5_SOC(obj);
  125. object_initialize_child(obj, "exti", &s->exti, TYPE_STM32L4X5_EXTI);
  126. for (unsigned i = 0; i < NUM_EXTI_OR_GATES; i++) {
  127. object_initialize_child(obj, "exti_or_gates[*]", &s->exti_or_gates[i],
  128. TYPE_OR_IRQ);
  129. }
  130. object_initialize_child(obj, "syscfg", &s->syscfg, TYPE_STM32L4X5_SYSCFG);
  131. object_initialize_child(obj, "rcc", &s->rcc, TYPE_STM32L4X5_RCC);
  132. for (unsigned i = 0; i < NUM_GPIOS; i++) {
  133. g_autofree char *name = g_strdup_printf("gpio%c", 'a' + i);
  134. object_initialize_child(obj, name, &s->gpio[i], TYPE_STM32L4X5_GPIO);
  135. }
  136. for (int i = 0; i < STM_NUM_USARTS; i++) {
  137. object_initialize_child(obj, "usart[*]", &s->usart[i],
  138. TYPE_STM32L4X5_USART);
  139. }
  140. for (int i = 0; i < STM_NUM_UARTS; i++) {
  141. object_initialize_child(obj, "uart[*]", &s->uart[i],
  142. TYPE_STM32L4X5_UART);
  143. }
  144. object_initialize_child(obj, "lpuart1", &s->lpuart,
  145. TYPE_STM32L4X5_LPUART);
  146. }
  147. static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp)
  148. {
  149. ERRP_GUARD();
  150. Stm32l4x5SocState *s = STM32L4X5_SOC(dev_soc);
  151. const Stm32l4x5SocClass *sc = STM32L4X5_SOC_GET_CLASS(dev_soc);
  152. MemoryRegion *system_memory = get_system_memory();
  153. DeviceState *armv7m, *dev;
  154. SysBusDevice *busdev;
  155. uint32_t pin_index;
  156. if (!memory_region_init_rom(&s->flash, OBJECT(dev_soc), "flash",
  157. sc->flash_size, errp)) {
  158. return;
  159. }
  160. memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc),
  161. "flash_boot_alias", &s->flash, 0,
  162. sc->flash_size);
  163. memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash);
  164. memory_region_add_subregion(system_memory, 0, &s->flash_alias);
  165. if (!memory_region_init_ram(&s->sram1, OBJECT(dev_soc), "SRAM1", SRAM1_SIZE,
  166. errp)) {
  167. return;
  168. }
  169. memory_region_add_subregion(system_memory, SRAM1_BASE_ADDRESS, &s->sram1);
  170. if (!memory_region_init_ram(&s->sram2, OBJECT(dev_soc), "SRAM2", SRAM2_SIZE,
  171. errp)) {
  172. return;
  173. }
  174. memory_region_add_subregion(system_memory, SRAM2_BASE_ADDRESS, &s->sram2);
  175. object_initialize_child(OBJECT(dev_soc), "armv7m", &s->armv7m, TYPE_ARMV7M);
  176. armv7m = DEVICE(&s->armv7m);
  177. qdev_prop_set_uint32(armv7m, "num-irq", 96);
  178. qdev_prop_set_uint32(armv7m, "num-prio-bits", 4);
  179. qdev_prop_set_string(armv7m, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4"));
  180. qdev_prop_set_bit(armv7m, "enable-bitband", true);
  181. qdev_connect_clock_in(armv7m, "cpuclk",
  182. qdev_get_clock_out(DEVICE(&(s->rcc)), "cortex-fclk-out"));
  183. qdev_connect_clock_in(armv7m, "refclk",
  184. qdev_get_clock_out(DEVICE(&(s->rcc)), "cortex-refclk-out"));
  185. object_property_set_link(OBJECT(&s->armv7m), "memory",
  186. OBJECT(system_memory), &error_abort);
  187. if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) {
  188. return;
  189. }
  190. /* GPIOs */
  191. for (unsigned i = 0; i < NUM_GPIOS; i++) {
  192. g_autofree char *name = g_strdup_printf("%c", 'A' + i);
  193. dev = DEVICE(&s->gpio[i]);
  194. qdev_prop_set_string(dev, "name", name);
  195. qdev_prop_set_uint32(dev, "mode-reset",
  196. stm32l4x5_gpio_cfg[i].moder_reset);
  197. qdev_prop_set_uint32(dev, "ospeed-reset",
  198. stm32l4x5_gpio_cfg[i].ospeedr_reset);
  199. qdev_prop_set_uint32(dev, "pupd-reset",
  200. stm32l4x5_gpio_cfg[i].pupdr_reset);
  201. busdev = SYS_BUS_DEVICE(&s->gpio[i]);
  202. g_free(name);
  203. name = g_strdup_printf("gpio%c-out", 'a' + i);
  204. qdev_connect_clock_in(DEVICE(&s->gpio[i]), "clk",
  205. qdev_get_clock_out(DEVICE(&(s->rcc)), name));
  206. if (!sysbus_realize(busdev, errp)) {
  207. return;
  208. }
  209. sysbus_mmio_map(busdev, 0, stm32l4x5_gpio_cfg[i].addr);
  210. }
  211. /* System configuration controller */
  212. busdev = SYS_BUS_DEVICE(&s->syscfg);
  213. qdev_connect_clock_in(DEVICE(&s->syscfg), "clk",
  214. qdev_get_clock_out(DEVICE(&(s->rcc)), "syscfg-out"));
  215. if (!sysbus_realize(busdev, errp)) {
  216. return;
  217. }
  218. sysbus_mmio_map(busdev, 0, SYSCFG_ADDR);
  219. for (unsigned i = 0; i < NUM_GPIOS; i++) {
  220. for (unsigned j = 0; j < GPIO_NUM_PINS; j++) {
  221. pin_index = GPIO_NUM_PINS * i + j;
  222. qdev_connect_gpio_out(DEVICE(&s->gpio[i]), j,
  223. qdev_get_gpio_in(DEVICE(&s->syscfg),
  224. pin_index));
  225. }
  226. }
  227. qdev_pass_gpios(DEVICE(&s->syscfg), dev_soc, NULL);
  228. /* EXTI device */
  229. busdev = SYS_BUS_DEVICE(&s->exti);
  230. if (!sysbus_realize(busdev, errp)) {
  231. return;
  232. }
  233. sysbus_mmio_map(busdev, 0, EXTI_ADDR);
  234. /* IRQs with fan-in that require an OR gate */
  235. for (unsigned i = 0; i < NUM_EXTI_OR_GATES; i++) {
  236. if (!object_property_set_int(OBJECT(&s->exti_or_gates[i]), "num-lines",
  237. exti_or_gates_num_lines_in[i], errp)) {
  238. return;
  239. }
  240. if (!qdev_realize(DEVICE(&s->exti_or_gates[i]), NULL, errp)) {
  241. return;
  242. }
  243. qdev_connect_gpio_out(DEVICE(&s->exti_or_gates[i]), 0,
  244. qdev_get_gpio_in(armv7m, exti_or_gates_out[i]));
  245. if (i < NUM_EXTI_SIMPLE_OR_GATES) {
  246. /* consecutive inputs for OR gates 23, 40, 63 */
  247. for (unsigned j = 0; j < exti_or_gates_num_lines_in[i]; j++) {
  248. sysbus_connect_irq(SYS_BUS_DEVICE(&s->exti),
  249. exti_or_gates_first_line_in[i] + j,
  250. qdev_get_gpio_in(DEVICE(&s->exti_or_gates[i]), j));
  251. }
  252. } else {
  253. /* non-consecutive inputs for OR gate 1 */
  254. for (unsigned j = 0; j < EXTI_OR_GATE1_NUM_LINES_IN; j++) {
  255. sysbus_connect_irq(SYS_BUS_DEVICE(&s->exti),
  256. exti_or_gate1_lines_in[j],
  257. qdev_get_gpio_in(DEVICE(&s->exti_or_gates[i]), j));
  258. }
  259. }
  260. }
  261. /* IRQs that don't require fan-in */
  262. for (unsigned i = 0; i < NUM_EXTI_IRQ; i++) {
  263. if (exti_irq[i] != -1) {
  264. sysbus_connect_irq(busdev, i,
  265. qdev_get_gpio_in(armv7m, exti_irq[i]));
  266. }
  267. }
  268. /* Connect SYSCFG to EXTI */
  269. for (unsigned i = 0; i < GPIO_NUM_PINS; i++) {
  270. qdev_connect_gpio_out(DEVICE(&s->syscfg), i,
  271. qdev_get_gpio_in(DEVICE(&s->exti), i));
  272. }
  273. /* RCC device */
  274. busdev = SYS_BUS_DEVICE(&s->rcc);
  275. if (!sysbus_realize(busdev, errp)) {
  276. return;
  277. }
  278. sysbus_mmio_map(busdev, 0, RCC_BASE_ADDRESS);
  279. sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, RCC_IRQ));
  280. /* USART devices */
  281. for (int i = 0; i < STM_NUM_USARTS; i++) {
  282. g_autofree char *name = g_strdup_printf("usart%d-out", i + 1);
  283. dev = DEVICE(&(s->usart[i]));
  284. qdev_prop_set_chr(dev, "chardev", serial_hd(i));
  285. qdev_connect_clock_in(dev, "clk",
  286. qdev_get_clock_out(DEVICE(&(s->rcc)), name));
  287. busdev = SYS_BUS_DEVICE(dev);
  288. if (!sysbus_realize(busdev, errp)) {
  289. return;
  290. }
  291. sysbus_mmio_map(busdev, 0, usart_addr[i]);
  292. sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(DEVICE(&s->exti),
  293. EXTI_USART1_IRQ + i));
  294. }
  295. /* UART devices */
  296. for (int i = 0; i < STM_NUM_UARTS; i++) {
  297. g_autofree char *name = g_strdup_printf("uart%d-out", STM_NUM_USARTS + i + 1);
  298. dev = DEVICE(&(s->uart[i]));
  299. qdev_prop_set_chr(dev, "chardev", serial_hd(STM_NUM_USARTS + i));
  300. qdev_connect_clock_in(dev, "clk",
  301. qdev_get_clock_out(DEVICE(&(s->rcc)), name));
  302. busdev = SYS_BUS_DEVICE(dev);
  303. if (!sysbus_realize(busdev, errp)) {
  304. return;
  305. }
  306. sysbus_mmio_map(busdev, 0, uart_addr[i]);
  307. sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(DEVICE(&s->exti),
  308. EXTI_UART4_IRQ + i));
  309. }
  310. /* LPUART device*/
  311. dev = DEVICE(&(s->lpuart));
  312. qdev_prop_set_chr(dev, "chardev", serial_hd(STM_NUM_USARTS + STM_NUM_UARTS));
  313. qdev_connect_clock_in(dev, "clk",
  314. qdev_get_clock_out(DEVICE(&(s->rcc)), "lpuart1-out"));
  315. busdev = SYS_BUS_DEVICE(dev);
  316. if (!sysbus_realize(busdev, errp)) {
  317. return;
  318. }
  319. sysbus_mmio_map(busdev, 0, LPUART_BASE_ADDRESS);
  320. sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(DEVICE(&s->exti),
  321. EXTI_LPUART1_IRQ));
  322. /* APB1 BUS */
  323. create_unimplemented_device("TIM2", 0x40000000, 0x400);
  324. create_unimplemented_device("TIM3", 0x40000400, 0x400);
  325. create_unimplemented_device("TIM4", 0x40000800, 0x400);
  326. create_unimplemented_device("TIM5", 0x40000C00, 0x400);
  327. create_unimplemented_device("TIM6", 0x40001000, 0x400);
  328. create_unimplemented_device("TIM7", 0x40001400, 0x400);
  329. /* RESERVED: 0x40001800, 0x1000 */
  330. create_unimplemented_device("RTC", 0x40002800, 0x400);
  331. create_unimplemented_device("WWDG", 0x40002C00, 0x400);
  332. create_unimplemented_device("IWDG", 0x40003000, 0x400);
  333. /* RESERVED: 0x40001800, 0x400 */
  334. create_unimplemented_device("SPI2", 0x40003800, 0x400);
  335. create_unimplemented_device("SPI3", 0x40003C00, 0x400);
  336. /* RESERVED: 0x40004000, 0x400 */
  337. create_unimplemented_device("I2C1", 0x40005400, 0x400);
  338. create_unimplemented_device("I2C2", 0x40005800, 0x400);
  339. create_unimplemented_device("I2C3", 0x40005C00, 0x400);
  340. /* RESERVED: 0x40006000, 0x400 */
  341. create_unimplemented_device("CAN1", 0x40006400, 0x400);
  342. /* RESERVED: 0x40006800, 0x400 */
  343. create_unimplemented_device("PWR", 0x40007000, 0x400);
  344. create_unimplemented_device("DAC1", 0x40007400, 0x400);
  345. create_unimplemented_device("OPAMP", 0x40007800, 0x400);
  346. create_unimplemented_device("LPTIM1", 0x40007C00, 0x400);
  347. /* RESERVED: 0x40008400, 0x400 */
  348. create_unimplemented_device("SWPMI1", 0x40008800, 0x400);
  349. /* RESERVED: 0x40008C00, 0x800 */
  350. create_unimplemented_device("LPTIM2", 0x40009400, 0x400);
  351. /* RESERVED: 0x40009800, 0x6800 */
  352. /* APB2 BUS */
  353. create_unimplemented_device("VREFBUF", 0x40010030, 0x1D0);
  354. create_unimplemented_device("COMP", 0x40010200, 0x200);
  355. /* RESERVED: 0x40010800, 0x1400 */
  356. create_unimplemented_device("FIREWALL", 0x40011C00, 0x400);
  357. /* RESERVED: 0x40012000, 0x800 */
  358. create_unimplemented_device("SDMMC1", 0x40012800, 0x400);
  359. create_unimplemented_device("TIM1", 0x40012C00, 0x400);
  360. create_unimplemented_device("SPI1", 0x40013000, 0x400);
  361. create_unimplemented_device("TIM8", 0x40013400, 0x400);
  362. /* RESERVED: 0x40013C00, 0x400 */
  363. create_unimplemented_device("TIM15", 0x40014000, 0x400);
  364. create_unimplemented_device("TIM16", 0x40014400, 0x400);
  365. create_unimplemented_device("TIM17", 0x40014800, 0x400);
  366. /* RESERVED: 0x40014C00, 0x800 */
  367. create_unimplemented_device("SAI1", 0x40015400, 0x400);
  368. create_unimplemented_device("SAI2", 0x40015800, 0x400);
  369. /* RESERVED: 0x40015C00, 0x400 */
  370. create_unimplemented_device("DFSDM1", 0x40016000, 0x400);
  371. /* RESERVED: 0x40016400, 0x9C00 */
  372. /* AHB1 BUS */
  373. create_unimplemented_device("DMA1", 0x40020000, 0x400);
  374. create_unimplemented_device("DMA2", 0x40020400, 0x400);
  375. /* RESERVED: 0x40020800, 0x800 */
  376. /* RESERVED: 0x40021400, 0xC00 */
  377. create_unimplemented_device("FLASH", 0x40022000, 0x400);
  378. /* RESERVED: 0x40022400, 0xC00 */
  379. create_unimplemented_device("CRC", 0x40023000, 0x400);
  380. /* RESERVED: 0x40023400, 0x400 */
  381. create_unimplemented_device("TSC", 0x40024000, 0x400);
  382. /* RESERVED: 0x40024400, 0x7FDBC00 */
  383. /* AHB2 BUS */
  384. /* RESERVED: 0x48002000, 0x7FDBC00 */
  385. create_unimplemented_device("OTG_FS", 0x50000000, 0x40000);
  386. create_unimplemented_device("ADC", 0x50040000, 0x400);
  387. /* RESERVED: 0x50040400, 0x20400 */
  388. create_unimplemented_device("RNG", 0x50060800, 0x400);
  389. /* AHB3 BUS */
  390. create_unimplemented_device("FMC", 0xA0000000, 0x1000);
  391. create_unimplemented_device("QUADSPI", 0xA0001000, 0x400);
  392. }
  393. static void stm32l4x5_soc_class_init(ObjectClass *klass, void *data)
  394. {
  395. DeviceClass *dc = DEVICE_CLASS(klass);
  396. dc->realize = stm32l4x5_soc_realize;
  397. /* Reason: Mapped at fixed location on the system bus */
  398. dc->user_creatable = false;
  399. /* No vmstate or reset required: device has no internal state */
  400. }
  401. static void stm32l4x5xc_soc_class_init(ObjectClass *oc, void *data)
  402. {
  403. Stm32l4x5SocClass *ssc = STM32L4X5_SOC_CLASS(oc);
  404. ssc->flash_size = 256 * KiB;
  405. }
  406. static void stm32l4x5xe_soc_class_init(ObjectClass *oc, void *data)
  407. {
  408. Stm32l4x5SocClass *ssc = STM32L4X5_SOC_CLASS(oc);
  409. ssc->flash_size = 512 * KiB;
  410. }
  411. static void stm32l4x5xg_soc_class_init(ObjectClass *oc, void *data)
  412. {
  413. Stm32l4x5SocClass *ssc = STM32L4X5_SOC_CLASS(oc);
  414. ssc->flash_size = 1 * MiB;
  415. }
  416. static const TypeInfo stm32l4x5_soc_types[] = {
  417. {
  418. .name = TYPE_STM32L4X5XC_SOC,
  419. .parent = TYPE_STM32L4X5_SOC,
  420. .class_init = stm32l4x5xc_soc_class_init,
  421. }, {
  422. .name = TYPE_STM32L4X5XE_SOC,
  423. .parent = TYPE_STM32L4X5_SOC,
  424. .class_init = stm32l4x5xe_soc_class_init,
  425. }, {
  426. .name = TYPE_STM32L4X5XG_SOC,
  427. .parent = TYPE_STM32L4X5_SOC,
  428. .class_init = stm32l4x5xg_soc_class_init,
  429. }, {
  430. .name = TYPE_STM32L4X5_SOC,
  431. .parent = TYPE_SYS_BUS_DEVICE,
  432. .instance_size = sizeof(Stm32l4x5SocState),
  433. .instance_init = stm32l4x5_soc_initfn,
  434. .class_size = sizeof(Stm32l4x5SocClass),
  435. .class_init = stm32l4x5_soc_class_init,
  436. .abstract = true,
  437. }
  438. };
  439. DEFINE_TYPES(stm32l4x5_soc_types)