/*
 * Gumstix Platforms
 *
 * Copyright (c) 2007 by Thorsten Zitterell <info@bitmux.org>
 *
 * Code based on spitz platform by Andrzej Zaborowski <balrog@zabor.org>
 *
 * This code is licensed under the GNU GPL v2.
 */

#include "vl.h"

static void connex_smc_irq(void *opaque, int line, int level)
{
    /* Interrupt line of NIC is connected to GPIO line 36 */
    struct pxa2xx_state_s *cpu = (struct pxa2xx_state_s *) opaque;
    pxa2xx_gpio_set(cpu->gpio, 36, level);
}

/* Board init. */
enum gumstix_model_e { connex };

static void gumstix_common_init(int ram_size, int vga_ram_size,
                DisplayState *ds, const char *kernel_filename,
                const char *kernel_cmdline, const char *initrd_filename,
                const char *cpu_model, enum gumstix_model_e model)
{
    struct pxa2xx_state_s *cpu;

    uint32_t gumstix_rom = 0x02000000;
    uint32_t gumstix_ram = 0x08000000;

    if (ram_size < (gumstix_ram + gumstix_rom + PXA2XX_INTERNAL_SIZE)) {
        fprintf(stderr, "This platform requires %i bytes of memory\n",
                gumstix_ram + gumstix_rom + PXA2XX_INTERNAL_SIZE);
        exit(1);
    }

    cpu = pxa255_init(gumstix_ram, ds);

    if (pflash_table[0] == NULL) {
        fprintf(stderr, "A flash image must be given with the "
                "'pflash' parameter\n");
        exit(1);
    }

    if (!pflash_register(0x00000000, gumstix_ram + PXA2XX_INTERNAL_SIZE,
            pflash_table[0], 128 * 1024, 128, 2, 0, 0, 0, 0)) {
        fprintf(stderr, "qemu: Error register flash memory.\n");
        exit(1);
    }

    cpu->env->regs[15] = 0x00000000;

    qemu_irq *irq = qemu_allocate_irqs(connex_smc_irq, cpu, 1);
    smc91c111_init(&nd_table[0], 0x04000300, *irq);
}

static void connex_init(int ram_size, int vga_ram_size,
                const char *boot_device, DisplayState *ds,
                const char **fd_filename, int snapshot,
                const char *kernel_filename, const char *kernel_cmdline,
                const char *initrd_filename, const char *cpu_model)
{
    gumstix_common_init(ram_size, vga_ram_size, ds, kernel_filename,
                kernel_cmdline, initrd_filename, cpu_model, connex);
}

QEMUMachine connex_machine = {
    "connex",
    "Gumstix Connex (PXA255)",
    connex_init,
};
