Merge commit 'origin/upstream' into juha-devel
[qemu] / hw / beagle.c
1 /*
2  * Beagle board emulation. http://beagleboard.org/
3  * 
4  * Original code Copyright (C) 2008 yajin(yajin@vm-kernel.org)
5  * Rewrite Copyright (C) 2009 Nokia Corporation
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 or
10  * (at your option) version 3 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include "qemu-common.h"
24 #include "sysemu.h"
25 #include "omap.h"
26 #include "arm-misc.h"
27 #include "boards.h"
28 #include "i2c.h"
29 #include "net.h"
30 #include "devices.h"
31 #include "flash.h"
32
33 #define BEAGLE_NAND_CS       0
34 #define BEAGLE_SMC_CS        1
35 #define BEAGLE_NAND_PAGESIZE 0x800
36 #define BEAGLE_SDRAM_SIZE    (128 * 1024 * 1024) /* 128MB */
37
38 /* Beagle board support */
39 struct beagle_s {
40     struct omap_mpu_state_s *cpu;
41     
42     struct nand_flash_s *nand;
43     struct omap3_lcd_panel_s *lcd_panel;
44     i2c_bus *i2c;
45     struct twl4030_s *twl4030;
46 };
47
48 static void beagle_init(ram_addr_t ram_size, int vga_ram_size,
49                 const char *boot_device,
50                 const char *kernel_filename, const char *kernel_cmdline,
51                 const char *initrd_filename, const char *cpu_model)
52 {
53     struct beagle_s *s = (struct beagle_s *) qemu_mallocz(sizeof(*s));
54     int sdindex = drive_get_index(IF_SD, 0, 0);
55     void *opaque;
56     
57     if (sdindex == -1) {
58         fprintf(stderr, "%s: missing SecureDigital device\n", __FUNCTION__);
59         exit(1);
60     }
61         s->cpu = omap3530_mpu_init(ram_size, NULL, NULL, serial_hds[0]);
62
63         s->nand = nand_init(NAND_MFR_MICRON, 0xba); /* MT29F2G16ABC */
64         nand_setpins(s->nand, 0, 0, 0, 1, 0); /* no write-protect */
65     omap_gpmc_attach(s->cpu->gpmc, BEAGLE_NAND_CS, 0, NULL, NULL, s->nand, 2);
66     omap3_mmc_attach(s->cpu->omap3_mmc[0], drives_table[sdindex].bdrv);
67
68     s->i2c = omap_i2c_bus(s->cpu->i2c[0]);
69     s->twl4030 = twl4030_init(s->i2c, s->cpu->irq[0][OMAP_INT_3XXX_SYS_NIRQ]);
70     opaque = smc91c111_init(&nd_table[0], 0x08000000,
71                     omap2_gpio_in_get(s->cpu->gpif, 54)[0], 0);
72     omap_gpmc_attach(s->cpu->gpmc, BEAGLE_SMC_CS, smc91c111_iomemtype(opaque),
73                      0, 0, opaque, 0);
74
75         s->lcd_panel = omap3_lcd_panel_init();
76         omap3_lcd_panel_attach(s->cpu->dss, 0, s->lcd_panel);
77     
78     omap3_boot_rom_emu(s->cpu);
79 }
80
81 QEMUMachine beagle_machine = {
82     .name =        "beagle",
83     .desc =        "Beagle board (OMAP3530)",
84     .init =        beagle_init,
85     .ram_require = OMAP3XXX_SRAM_SIZE + OMAP3XXX_BOOTROM_SIZE,
86 };
87