[MINI2440] Shuffle/rework init code
[sniper_test.git] / hw / mini2440.c
blobac45d7fd0fc780036beab906aa1e9cebddfa046f
1 /*
2 * Neo1973 mobile telephone platforms emulation.
3 * Detailed information at openmoko.org.
5 * Copyright (c) 2007 OpenMoko, Inc.
6 * Author: Andrzej Zaborowski <andrew@openedhand.com>
8 * This code is licensed under the GNU GPL v2.
9 */
11 #include "hw.h"
12 #include "s3c.h"
13 #include "arm-misc.h"
14 #include "sysemu.h"
15 #include "i2c.h"
16 #include "qemu-timer.h"
17 #include "devices.h"
18 #include "audio/audio.h"
19 #include "boards.h"
20 #include "console.h"
21 #include "usb.h"
22 #include "net.h"
23 #include "sd.h"
24 #include "dm9000.h"
25 #include "eeprom24c0x.h"
27 #define mini2440_printf(format, ...) \
28 fprintf(stderr, "%s: " format, __FUNCTION__, ##__VA_ARGS__)
30 /* Wiring common to all revisions */
31 #define MINI2440_GPIO_BACKLIGHT S3C_GPB(1)
32 #define MINI2440_GPIO_LCD_RESET S3C_GPC(6)
33 #define MINI2440_GPIO_nSD_DETECT S3C_GPG(8)
34 #define MINI2440_IRQ_nSD_DETECT S3C_EINT(16)
35 #define MINI2440_IRQ_DM9000 S3C_EINT(7)
36 #define MINI2440_GPIO_DM9000 S3C_GPF(7)
38 #define MINI2440_GPIO_SDMMC_ON S3C_GPB(2)
39 #define MINI2440_GPIO_USB_PULLUP S3C_GPB(9)
40 #define MINI2440_GPIO_USB_ATTACH S3C_GPB(10)
42 struct mini2440_board_s {
43 struct s3c_state_s *cpu;
44 unsigned int ram;
45 i2c_slave * eeprom;
46 const char * kernel;
47 SDState * mmc;
51 static void mini2440_gpio_setup(struct mini2440_board_s *s)
53 // s3c_gpio_out_set(s->cpu->io, MINI2440_GPIO_BACKLIGHT,
54 // *qemu_allocate_irqs(mini2440_bl_switch, s, 1));
56 // s3c_timers_cmp_handler_set(s->cpu->timers, 0, mini2440_bl_intensity, s);
58 sd_set_cb(s->mmc, 0, s3c_gpio_in_get(s->cpu->io)[MINI2440_IRQ_nSD_DETECT]);
61 static void mini2440_reset(void *opaque)
63 struct mini2440_board_s *s = (struct mini2440_board_s *) opaque;
64 uint32_t image_size;
66 #if 0
68 * Performs Samsung S3C2440 bootup, but loading 4KB of the nand at the base of the RAM
69 * and jumping there
71 uint8_t * src = s->cpu->nand->storage;
72 uint8_t * dst = phys_ram_base;
73 int page = 0;
74 for (page = 0; page < 4 page++, src += 264, dst += 256)
75 memcpy(dst, src, 256);
76 s->cpu->env->regs[15] = S3C_RAM_BASE; // start address, u-boot relocating code
77 #endif
78 if (1) {
79 image_size = load_image("u-boot.bin", phys_ram_base + 0x03f80000);
80 if (image_size) {
81 if (image_size & (512 -1)) /* round size to a NAND block size */
82 image_size = (image_size + 512) & ~(512-1);
83 fprintf(stderr, "%s: loaded override u-boot (size %x)\n", __FUNCTION__, image_size);
84 s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; // start address, u-boot already relocated
87 image_size = load_image(s->kernel, phys_ram_base + 0x02000000);
91 /* Typical touchscreen calibration values */
92 static const int mini2440_ts_scale[6] = {
93 0, (90 - 960) * 256 / 1021, -90 * 256 * 32,
94 (940 - 75) * 256 / 1021, 0, 75 * 256 * 32,
97 /* Board init. */
98 static struct mini2440_board_s *mini2440_init_common(int ram_size,
99 const char *kernel_filename, const char *cpu_model,
100 SDState *mmc)
102 struct mini2440_board_s *s = (struct mini2440_board_s *)
103 qemu_mallocz(sizeof(struct mini2440_board_s));
105 s->ram = 0x08000000;
106 s->kernel = kernel_filename;
107 s->mmc = mmc;
109 /* Setup CPU & memory */
110 if (ram_size < s->ram + S3C_SRAM_SIZE) {
111 fprintf(stderr, "This platform requires %i bytes of memory (not %d)\n",
112 s->ram + S3C_SRAM_SIZE, ram_size);
113 exit(1);
115 if (cpu_model && strcmp(cpu_model, "arm920t")) {
116 fprintf(stderr, "This platform requires an ARM920T core\n");
117 exit(2);
119 s->cpu = s3c24xx_init(S3C_CPU_2440, s->ram, s->mmc);
121 /* Setup peripherals */
122 mini2440_gpio_setup(s);
124 // if (usb_enabled)
125 // usb_device_attach(usb_bt_init(local_piconet));
128 NICInfo* nd;
129 nd = &nd_table[0];
130 if (!nd->model)
131 nd->model = "dm9000";
132 if (strcmp(nd->model, "dm9000") == 0) {
133 // s3c_gpio_out_set(s->cpu->io, MINI2440_GPIO_DM9000,
134 // *qemu_allocate_irqs(mini2440_bl_switch, s, 1));
136 dm9000_init(nd, 0x20000000, 0x300, 0x304, s3c_gpio_in_get(s->cpu->io)[7]);
140 s3c_adc_setscale(s->cpu->adc, mini2440_ts_scale);
142 /* Setup initial (reset) machine state */
143 qemu_register_reset(mini2440_reset, s);
144 #if 0
145 arm_load_kernel(s->ram, kernel_filename, kernel_cmdline,
146 initrd_filename, 0x49e, S3C_RAM_BASE);
147 #endif
149 // dpy_resize(ds, 240, 320);
151 return s;
154 static void mini2440_init(ram_addr_t ram_size, int vga_ram_size,
155 const char *boot_device,
156 const char *kernel_filename, const char *kernel_cmdline,
157 const char *initrd_filename, const char *cpu_model)
159 struct mini2440_board_s *mini;
160 int sd_idx = drive_get_index(IF_SD, 0, 0);
161 SDState *sd = 0;
163 if (sd_idx >= 0)
164 sd = sd_init(drives_table[sd_idx].bdrv, 0);
166 mini = mini2440_init_common(ram_size,
167 kernel_filename, cpu_model, sd);
169 mini->cpu->nand->reg(mini->cpu->nand, nand_init(NAND_MFR_SAMSUNG, 0x36));
171 mini2440_reset(mini);
174 QEMUMachine mini2440_machine = {
175 "mini2440",
176 "MINI2440 Chinese Samsung SoC dev board (S3C2440A)",
177 .init = mini2440_init,