[MINI2440] Disable useless debug trace
[qemu/mini2440/sniper_sniper_test.git] / hw / mini2440.c
blobcd68d0aa21a7c31cb988dbeab34890d0510ef8a1
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;
48 struct nand_flash_s *nand;
49 int bl_level;
53 /* Handlers for output ports */
54 static void mini2440_bl_switch(void *opaque, int line, int level)
56 printf("%s: LCD Backlight now %s.\n", __FUNCTION__, level ? "on" : "off");
59 static void mini2440_bl_intensity(int line, int level, void *opaque)
61 struct mini2440_board_s *s = (struct mini2440_board_s *) opaque;
63 if ((level >> 8) != s->bl_level) {
64 s->bl_level = level >> 8;
65 // printf("%s: LCD Backlight now at %i/64.\n", __FUNCTION__, s->bl_level);
69 static void mini2440_gpio_setup(struct mini2440_board_s *s)
71 s3c_gpio_out_set(s->cpu->io, MINI2440_GPIO_BACKLIGHT,
72 *qemu_allocate_irqs(mini2440_bl_switch, s, 1));
74 s3c_timers_cmp_handler_set(s->cpu->timers, 1, mini2440_bl_intensity, s);
76 // this confuses the kernel, we will need a way to bridge this IRQ to the SD system
77 // right now without this, qemu will not know how to pass the SD card insert/remove
78 // properly to the kernel
79 // sd_set_cb(s->mmc, 0, s3c_gpio_in_get(s->cpu->io)[MINI2440_IRQ_nSD_DETECT]);
82 static void hexdump(const void* address, uint32_t len)
84 const unsigned char* p = address;
85 int i, j;
87 for (i = 0; i < len; i += 16) {
88 for (j = 0; j < 16 && i + j < len; j++)
89 fprintf(stderr, "%02x ", p[i + j]);
90 for (; j < 16; j++)
91 fprintf(stderr, " ");
92 fprintf(stderr, " ");
93 for (j = 0; j < 16 && i + j < len; j++)
94 fprintf(stderr, "%c", (p[i + j] < ' ' || p[i + j] > 0x7f) ? '.' : p[i + j]);
95 fprintf(stderr, "\n");
99 static void mini2440_reset(void *opaque)
101 struct mini2440_board_s *s = (struct mini2440_board_s *) opaque;
102 uint32_t image_size;
104 if (1) {
105 image_size = load_image("mini2440/u-boot.bin", phys_ram_base + 0x03f80000);
106 if (!image_size)
107 image_size = load_image("u-boot.bin", phys_ram_base + 0x03f80000);
108 if (image_size) {
109 if (image_size & (512 -1)) /* round size to a NAND block size */
110 image_size = (image_size + 512) & ~(512-1);
111 fprintf(stderr, "%s: loaded default u-boot (size %x)\n", __FUNCTION__, image_size);
112 s->cpu->env->regs[15] = S3C_RAM_BASE | 0x03f80000; // start address, u-boot already relocated
115 #if 0
117 * Performs Samsung S3C2440 bootup, but loading 4KB of the nand at the base of the RAM
118 * and jumping there
120 if (s->nand) {
121 uint32_t src = 0;
122 int page = 0;
123 uint8_t stone[S3C_SRAM_SIZE];
124 uint8_t * dst = stone;
126 fprintf(stderr, "%s: attempting boot from NAND\n", __FUNCTION__);
128 for (page = 0; page < (S3C_SRAM_SIZE / 512); page++, src += 512+16, dst += 512)
129 if (nand_readraw(s->nand, src, dst, 512) == 0) {
130 fprintf(stderr, "%s: failed to load nand %d:%d\n", __FUNCTION__, src, 512+16);
132 cpu_physical_memory_write(S3C_SRAM_BASE_NANDBOOT, stone, S3C_SRAM_SIZE);
133 s->cpu->env->regs[15] = S3C_SRAM_BASE_NANDBOOT; // start address, u-boot relocating code
134 fprintf(stderr, "%s: 4KB SteppingStone loaded from NAND\n", __FUNCTION__);
136 #endif
137 if (1) {
138 image_size = load_image(s->kernel, phys_ram_base + 0x02000000);
139 if (image_size) {
140 if (image_size & (512 -1)) /* round size to a NAND block size */
141 image_size = (image_size + 512) & ~(512-1);
142 fprintf(stderr, "%s: loaded %s (size %x)\n", __FUNCTION__, s->kernel, image_size);
145 if (0) {
146 image_size = load_image("/tftpboot/minimalist-image-mini2440.jffs2", phys_ram_base);
147 if (image_size) {
148 if (image_size & (512 -1)) /* round size to a NAND block size */
149 image_size = (image_size + 512) & ~(512-1);
150 fprintf(stderr, "%s: loaded jffs2 (size %x)\n", __FUNCTION__, image_size);
156 /* Typical touchscreen calibration values */
157 static const int mini2440_ts_scale[6] = {
158 0, (90 - 960) * 256 / 1021, -90 * 256 * 32,
159 (940 - 75) * 256 / 1021, 0, 75 * 256 * 32,
162 /* Board init. */
163 static struct mini2440_board_s *mini2440_init_common(int ram_size,
164 const char *kernel_filename, const char *cpu_model,
165 SDState *mmc)
167 struct mini2440_board_s *s = (struct mini2440_board_s *)
168 qemu_mallocz(sizeof(struct mini2440_board_s));
170 s->ram = 0x04000000;
171 s->kernel = kernel_filename;
172 s->mmc = mmc;
174 /* Setup CPU & memory */
175 if (ram_size < s->ram + S3C_SRAM_SIZE) {
176 fprintf(stderr, "This platform requires %i bytes of memory (not %d)\n",
177 s->ram + S3C_SRAM_SIZE, ram_size);
178 exit(1);
180 if (cpu_model && strcmp(cpu_model, "arm920t")) {
181 fprintf(stderr, "This platform requires an ARM920T core\n");
182 exit(2);
184 s->cpu = s3c24xx_init(S3C_CPU_2440, s->ram, S3C_SRAM_BASE_NANDBOOT, s->mmc);
186 /* Setup peripherals */
187 mini2440_gpio_setup(s);
189 // if (usb_enabled)
190 // usb_device_attach(usb_bt_init(local_piconet));
193 NICInfo* nd;
194 nd = &nd_table[0];
195 if (!nd->model)
196 nd->model = "dm9000";
197 if (strcmp(nd->model, "dm9000") == 0) {
198 dm9000_init(nd, 0x20000000, 0x300, 0x304, s3c_gpio_in_get(s->cpu->io)[MINI2440_IRQ_DM9000]);
202 s3c_adc_setscale(s->cpu->adc, mini2440_ts_scale);
204 /* Setup initial (reset) machine state */
205 qemu_register_reset(mini2440_reset, s);
206 #if 0
207 arm_load_kernel(s->ram, kernel_filename, kernel_cmdline,
208 initrd_filename, 0x49e, S3C_RAM_BASE);
209 #endif
211 // dpy_resize(ds, 240, 320);
213 return s;
216 static void mini2440_init(ram_addr_t ram_size, int vga_ram_size,
217 const char *boot_device,
218 const char *kernel_filename, const char *kernel_cmdline,
219 const char *initrd_filename, const char *cpu_model)
221 struct mini2440_board_s *mini;
222 int sd_idx = drive_get_index(IF_SD, 0, 0);
223 SDState *sd = 0;
225 if (sd_idx >= 0)
226 sd = sd_init(drives_table[sd_idx].bdrv, 0);
228 mini = mini2440_init_common(ram_size,
229 kernel_filename, cpu_model, sd);
231 mini->nand = nand_init(NAND_MFR_SAMSUNG, 0x36);
232 mini->cpu->nand->reg(mini->cpu->nand, mini->nand);
234 mini2440_reset(mini);
237 QEMUMachine mini2440_machine = {
238 "mini2440",
239 "MINI2440 Chinese Samsung SoC dev board (S3C2440A)",
240 .init = mini2440_init,