Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 1 | /* |
| 2 | * SmartFusion2 SOM starter kit(from Emcraft) emulation. |
| 3 | * |
| 4 | * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com> |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include "qemu/osdep.h" |
Philippe Mathieu-Daudé | fc6b3cf | 2018-06-25 09:41:58 -0300 | [diff] [blame] | 26 | #include "qemu/units.h" |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 27 | #include "qapi/error.h" |
| 28 | #include "qemu/error-report.h" |
| 29 | #include "hw/boards.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 30 | #include "hw/qdev-properties.h" |
Peter Maydell | 12ec8bd | 2019-05-23 14:47:43 +0100 | [diff] [blame] | 31 | #include "hw/arm/boot.h" |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 32 | #include "exec/address-spaces.h" |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 33 | #include "hw/arm/msf2-soc.h" |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 34 | |
| 35 | #define DDR_BASE_ADDRESS 0xA0000000 |
Philippe Mathieu-Daudé | d23b6ca | 2018-06-25 09:41:57 -0300 | [diff] [blame] | 36 | #define DDR_SIZE (64 * MiB) |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 37 | |
Philippe Mathieu-Daudé | d23b6ca | 2018-06-25 09:41:57 -0300 | [diff] [blame] | 38 | #define M2S010_ENVM_SIZE (256 * KiB) |
| 39 | #define M2S010_ESRAM_SIZE (64 * KiB) |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 40 | |
| 41 | static void emcraft_sf2_s2s010_init(MachineState *machine) |
| 42 | { |
| 43 | DeviceState *dev; |
| 44 | DeviceState *spi_flash; |
| 45 | MSF2State *soc; |
| 46 | MachineClass *mc = MACHINE_GET_CLASS(machine); |
| 47 | DriveInfo *dinfo = drive_get_next(IF_MTD); |
| 48 | qemu_irq cs_line; |
Markus Armbruster | 57d479c | 2020-06-10 07:32:12 +0200 | [diff] [blame] | 49 | BusState *spi_bus; |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 50 | MemoryRegion *sysmem = get_system_memory(); |
| 51 | MemoryRegion *ddr = g_new(MemoryRegion, 1); |
| 52 | |
| 53 | if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) { |
| 54 | error_report("This board can only be used with CPU %s", |
| 55 | mc->default_cpu_type); |
Philippe Mathieu-Daudé | dd97ef0 | 2019-07-01 17:26:14 +0100 | [diff] [blame] | 56 | exit(1); |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE, |
| 60 | &error_fatal); |
| 61 | memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr); |
| 62 | |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 63 | dev = qdev_new(TYPE_MSF2_SOC); |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 64 | qdev_prop_set_string(dev, "part-name", "M2S010"); |
| 65 | qdev_prop_set_string(dev, "cpu-type", mc->default_cpu_type); |
| 66 | |
| 67 | qdev_prop_set_uint64(dev, "eNVM-size", M2S010_ENVM_SIZE); |
| 68 | qdev_prop_set_uint64(dev, "eSRAM-size", M2S010_ESRAM_SIZE); |
| 69 | |
| 70 | /* |
| 71 | * CPU clock and peripheral clocks(APB0, APB1)are configurable |
| 72 | * in Libero. CPU clock is divided by APB0 and APB1 divisors for |
| 73 | * peripherals. Emcraft's SoM kit comes with these settings by default. |
| 74 | */ |
| 75 | qdev_prop_set_uint32(dev, "m3clk", 142 * 1000000); |
| 76 | qdev_prop_set_uint32(dev, "apb0div", 2); |
| 77 | qdev_prop_set_uint32(dev, "apb1div", 2); |
| 78 | |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 79 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 80 | |
| 81 | soc = MSF2_SOC(dev); |
| 82 | |
| 83 | /* Attach SPI flash to SPI0 controller */ |
Markus Armbruster | 57d479c | 2020-06-10 07:32:12 +0200 | [diff] [blame] | 84 | spi_bus = qdev_get_child_bus(dev, "spi0"); |
| 85 | spi_flash = qdev_new("s25sl12801"); |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 86 | qdev_prop_set_uint8(spi_flash, "spansion-cr2nv", 1); |
| 87 | if (dinfo) { |
Markus Armbruster | 934df91 | 2020-06-22 11:42:24 +0200 | [diff] [blame] | 88 | qdev_prop_set_drive_err(spi_flash, "drive", |
| 89 | blk_by_legacy_dinfo(dinfo), &error_fatal); |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 90 | } |
Markus Armbruster | 57d479c | 2020-06-10 07:32:12 +0200 | [diff] [blame] | 91 | qdev_realize_and_unref(spi_flash, spi_bus, &error_fatal); |
Subbaraya Sundeep | 6d262dc | 2017-09-20 17:17:37 -0300 | [diff] [blame] | 92 | cs_line = qdev_get_gpio_in_named(spi_flash, SSI_GPIO_CS, 0); |
| 93 | sysbus_connect_irq(SYS_BUS_DEVICE(&soc->spi[0]), 1, cs_line); |
| 94 | |
| 95 | armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, |
| 96 | soc->envm_size); |
| 97 | } |
| 98 | |
| 99 | static void emcraft_sf2_machine_init(MachineClass *mc) |
| 100 | { |
| 101 | mc->desc = "SmartFusion2 SOM kit from Emcraft (M2S010)"; |
| 102 | mc->init = emcraft_sf2_s2s010_init; |
| 103 | mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3"); |
| 104 | } |
| 105 | |
| 106 | DEFINE_MACHINE("emcraft-sf2", emcraft_sf2_machine_init) |