xref: /qemu/hw/arm/msf2-som.c (revision d23b6caadbfaf56092593e8ff22fb5797db38488)
16d262dcbSSubbaraya Sundeep /*
26d262dcbSSubbaraya Sundeep  * SmartFusion2 SOM starter kit(from Emcraft) emulation.
36d262dcbSSubbaraya Sundeep  *
46d262dcbSSubbaraya Sundeep  * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
56d262dcbSSubbaraya Sundeep  *
66d262dcbSSubbaraya Sundeep  * Permission is hereby granted, free of charge, to any person obtaining a copy
76d262dcbSSubbaraya Sundeep  * of this software and associated documentation files (the "Software"), to deal
86d262dcbSSubbaraya Sundeep  * in the Software without restriction, including without limitation the rights
96d262dcbSSubbaraya Sundeep  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
106d262dcbSSubbaraya Sundeep  * copies of the Software, and to permit persons to whom the Software is
116d262dcbSSubbaraya Sundeep  * furnished to do so, subject to the following conditions:
126d262dcbSSubbaraya Sundeep  *
136d262dcbSSubbaraya Sundeep  * The above copyright notice and this permission notice shall be included in
146d262dcbSSubbaraya Sundeep  * all copies or substantial portions of the Software.
156d262dcbSSubbaraya Sundeep  *
166d262dcbSSubbaraya Sundeep  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
176d262dcbSSubbaraya Sundeep  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
186d262dcbSSubbaraya Sundeep  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
196d262dcbSSubbaraya Sundeep  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
206d262dcbSSubbaraya Sundeep  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
216d262dcbSSubbaraya Sundeep  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
226d262dcbSSubbaraya Sundeep  * THE SOFTWARE.
236d262dcbSSubbaraya Sundeep  */
246d262dcbSSubbaraya Sundeep 
256d262dcbSSubbaraya Sundeep #include "qemu/osdep.h"
266d262dcbSSubbaraya Sundeep #include "qapi/error.h"
276d262dcbSSubbaraya Sundeep #include "qemu/error-report.h"
286d262dcbSSubbaraya Sundeep #include "hw/boards.h"
296d262dcbSSubbaraya Sundeep #include "hw/arm/arm.h"
306d262dcbSSubbaraya Sundeep #include "exec/address-spaces.h"
316d262dcbSSubbaraya Sundeep #include "qemu/cutils.h"
326d262dcbSSubbaraya Sundeep #include "hw/arm/msf2-soc.h"
336d262dcbSSubbaraya Sundeep #include "cpu.h"
346d262dcbSSubbaraya Sundeep 
356d262dcbSSubbaraya Sundeep #define DDR_BASE_ADDRESS      0xA0000000
36*d23b6caaSPhilippe Mathieu-Daudé #define DDR_SIZE              (64 * MiB)
376d262dcbSSubbaraya Sundeep 
38*d23b6caaSPhilippe Mathieu-Daudé #define M2S010_ENVM_SIZE      (256 * KiB)
39*d23b6caaSPhilippe Mathieu-Daudé #define M2S010_ESRAM_SIZE     (64 * KiB)
406d262dcbSSubbaraya Sundeep 
416d262dcbSSubbaraya Sundeep static void emcraft_sf2_s2s010_init(MachineState *machine)
426d262dcbSSubbaraya Sundeep {
436d262dcbSSubbaraya Sundeep     DeviceState *dev;
446d262dcbSSubbaraya Sundeep     DeviceState *spi_flash;
456d262dcbSSubbaraya Sundeep     MSF2State *soc;
466d262dcbSSubbaraya Sundeep     MachineClass *mc = MACHINE_GET_CLASS(machine);
476d262dcbSSubbaraya Sundeep     DriveInfo *dinfo = drive_get_next(IF_MTD);
486d262dcbSSubbaraya Sundeep     qemu_irq cs_line;
496d262dcbSSubbaraya Sundeep     SSIBus *spi_bus;
506d262dcbSSubbaraya Sundeep     MemoryRegion *sysmem = get_system_memory();
516d262dcbSSubbaraya Sundeep     MemoryRegion *ddr = g_new(MemoryRegion, 1);
526d262dcbSSubbaraya Sundeep 
536d262dcbSSubbaraya Sundeep     if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
546d262dcbSSubbaraya Sundeep         error_report("This board can only be used with CPU %s",
556d262dcbSSubbaraya Sundeep                      mc->default_cpu_type);
566d262dcbSSubbaraya Sundeep     }
576d262dcbSSubbaraya Sundeep 
586d262dcbSSubbaraya Sundeep     memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE,
596d262dcbSSubbaraya Sundeep                            &error_fatal);
606d262dcbSSubbaraya Sundeep     memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr);
616d262dcbSSubbaraya Sundeep 
626d262dcbSSubbaraya Sundeep     dev = qdev_create(NULL, TYPE_MSF2_SOC);
636d262dcbSSubbaraya Sundeep     qdev_prop_set_string(dev, "part-name", "M2S010");
646d262dcbSSubbaraya Sundeep     qdev_prop_set_string(dev, "cpu-type", mc->default_cpu_type);
656d262dcbSSubbaraya Sundeep 
666d262dcbSSubbaraya Sundeep     qdev_prop_set_uint64(dev, "eNVM-size", M2S010_ENVM_SIZE);
676d262dcbSSubbaraya Sundeep     qdev_prop_set_uint64(dev, "eSRAM-size", M2S010_ESRAM_SIZE);
686d262dcbSSubbaraya Sundeep 
696d262dcbSSubbaraya Sundeep     /*
706d262dcbSSubbaraya Sundeep      * CPU clock and peripheral clocks(APB0, APB1)are configurable
716d262dcbSSubbaraya Sundeep      * in Libero. CPU clock is divided by APB0 and APB1 divisors for
726d262dcbSSubbaraya Sundeep      * peripherals. Emcraft's SoM kit comes with these settings by default.
736d262dcbSSubbaraya Sundeep      */
746d262dcbSSubbaraya Sundeep     qdev_prop_set_uint32(dev, "m3clk", 142 * 1000000);
756d262dcbSSubbaraya Sundeep     qdev_prop_set_uint32(dev, "apb0div", 2);
766d262dcbSSubbaraya Sundeep     qdev_prop_set_uint32(dev, "apb1div", 2);
776d262dcbSSubbaraya Sundeep 
786d262dcbSSubbaraya Sundeep     object_property_set_bool(OBJECT(dev), true, "realized", &error_fatal);
796d262dcbSSubbaraya Sundeep 
806d262dcbSSubbaraya Sundeep     soc = MSF2_SOC(dev);
816d262dcbSSubbaraya Sundeep 
826d262dcbSSubbaraya Sundeep     /* Attach SPI flash to SPI0 controller */
836d262dcbSSubbaraya Sundeep     spi_bus = (SSIBus *)qdev_get_child_bus(dev, "spi0");
846d262dcbSSubbaraya Sundeep     spi_flash = ssi_create_slave_no_init(spi_bus, "s25sl12801");
856d262dcbSSubbaraya Sundeep     qdev_prop_set_uint8(spi_flash, "spansion-cr2nv", 1);
866d262dcbSSubbaraya Sundeep     if (dinfo) {
876d262dcbSSubbaraya Sundeep         qdev_prop_set_drive(spi_flash, "drive", blk_by_legacy_dinfo(dinfo),
886d262dcbSSubbaraya Sundeep                                     &error_fatal);
896d262dcbSSubbaraya Sundeep     }
906d262dcbSSubbaraya Sundeep     qdev_init_nofail(spi_flash);
916d262dcbSSubbaraya Sundeep     cs_line = qdev_get_gpio_in_named(spi_flash, SSI_GPIO_CS, 0);
926d262dcbSSubbaraya Sundeep     sysbus_connect_irq(SYS_BUS_DEVICE(&soc->spi[0]), 1, cs_line);
936d262dcbSSubbaraya Sundeep 
946d262dcbSSubbaraya Sundeep     armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
956d262dcbSSubbaraya Sundeep                        soc->envm_size);
966d262dcbSSubbaraya Sundeep }
976d262dcbSSubbaraya Sundeep 
986d262dcbSSubbaraya Sundeep static void emcraft_sf2_machine_init(MachineClass *mc)
996d262dcbSSubbaraya Sundeep {
1006d262dcbSSubbaraya Sundeep     mc->desc = "SmartFusion2 SOM kit from Emcraft (M2S010)";
1016d262dcbSSubbaraya Sundeep     mc->init = emcraft_sf2_s2s010_init;
1026d262dcbSSubbaraya Sundeep     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
1036d262dcbSSubbaraya Sundeep }
1046d262dcbSSubbaraya Sundeep 
1056d262dcbSSubbaraya Sundeep DEFINE_MACHINE("emcraft-sf2", emcraft_sf2_machine_init)
106