[S3C] Added a method to set the GPIO pins/registers from the emulation
[qemu/mini2440.git] / hw / s3c.h
blob5afbb314b2ccd74fc2053d7a55a39086ec04fe1b
1 /*
2 * Samsung S3C2410A RISC Microprocessor support (ARM920T based SoC).
4 * Copyright (c) 2007 OpenMoko, Inc.
5 * Author: Andrzej Zaborowski <andrew@openedhand.com>
7 * This code is licenced under the GNU GPL v2.
8 */
9 #ifndef S3C_H
10 # define S3C_H "s3c.h"
12 # include "qemu-common.h"
13 # include "flash.h"
14 # include "sd.h"
16 #define S3C_CPU_2410 0x32410002
17 #define S3C_CPU_2440 0x32440001
19 /* Interrupt numbers */
20 # define S3C_PIC_EINT0 0
21 # define S3C_PIC_EINT1 1
22 # define S3C_PIC_EINT2 2
23 # define S3C_PIC_EINT3 3
24 # define S3C_PIC_EINT4 4
25 # define S3C_PIC_EINT8 5
26 # define S3C_PIC_WDT 9
27 # define S3C_PIC_TIMER0 10
28 # define S3C_PIC_TIMER1 11
29 # define S3C_PIC_TIMER2 12
30 # define S3C_PIC_TIMER3 13
31 # define S3C_PIC_TIMER4 14
32 # define S3C_PIC_UART2 15
33 # define S3C_PIC_LCD 16
34 # define S3C_PIC_DMA0 17
35 # define S3C_PIC_DMA1 18
36 # define S3C_PIC_DMA2 19
37 # define S3C_PIC_DMA3 20
38 # define S3C_PIC_SDI 21
39 # define S3C_PIC_SPI0 22
40 # define S3C_PIC_UART1 23
41 # define S3C_PIC_USBD 25
42 # define S3C_PIC_USBH 26
43 # define S3C_PIC_IIC 27
44 # define S3C_PIC_UART0 28
45 # define S3C_PIC_SPI1 29
46 # define S3C_PIC_RTC 30
47 # define S3C_PIC_ADC 31
48 /* "Sub source" interrupt numbers */
49 # define S3C_PICS_RXD0 32
50 # define S3C_PICS_TXD0 33
51 # define S3C_PICS_ERR0 34
52 # define S3C_PICS_RXD1 35
53 # define S3C_PICS_TXD1 36
54 # define S3C_PICS_ERR1 37
55 # define S3C_PICS_RXD2 38
56 # define S3C_PICS_TXD2 39
57 # define S3C_PICS_ERR2 40
58 # define S3C_PICS_TC 41
59 # define S3C_PICS_ADC 42
61 # define S3C_PIC_MAX 43
62 /* External interrupt numbers */
63 # define S3C_EINT(n) ((n >= 8) ? (6 << 5) | (n - 8) : (5 << 5) | n)
65 /* DMA requests */
66 # define S3C_RQ_nXDREQ0 0x00
67 # define S3C_RQ_nXDREQ1 0x10
68 # define S3C_RQ_I2SSDO 0x20
69 # define S3C_RQ_UART2 0x30
70 # define S3C_RQ_UART0 0x01
71 # define S3C_RQ_UART1 0x11
72 # define S3C_RQ_I2SSDI0 0x21
73 # define S3C_RQ_SDI0 0x31
74 # define S3C_RQ_SDI1 0x02
75 # define S3C_RQ_I2SSDI1 0x12
76 # define S3C_RQ_SDI2 0x22
77 # define S3C_RQ_SPI1 0x32
78 # define S3C_RQ_TIMER0 0x03
79 # define S3C_RQ_SPI0 0x13
80 # define S3C_RQ_TIMER1 0x23
81 # define S3C_RQ_TIMER2 0x33
82 # define S3C_RQ_USB_EP1 0x04
83 # define S3C_RQ_USB_EP2 0x14
84 # define S3C_RQ_USB_EP3 0x24
85 # define S3C_RQ_USB_EP4 0x34
87 # define S3C_RQ_MAX 0x35
89 /* I/O port numbers */
90 # define S3C_GP(b, n) (((b) << 5) | n)
91 # define S3C_GPA(n) S3C_GP(0, n)
92 # define S3C_GPB(n) S3C_GP(1, n)
93 # define S3C_GPC(n) S3C_GP(2, n)
94 # define S3C_GPD(n) S3C_GP(3, n)
95 # define S3C_GPE(n) S3C_GP(4, n)
96 # define S3C_GPF(n) S3C_GP(5, n)
97 # define S3C_GPG(n) S3C_GP(6, n)
98 # define S3C_GPH(n) S3C_GP(7, n)
99 # define S3C_GP_MAX S3C_GP(8, 0)
101 # define S3C_RAM_BASE 0x30000000
102 # define S3C_SRAM_BASE_NORBOOT 0x40000000
103 # define S3C_SRAM_BASE_NANDBOOT 0x00000000
104 # define S3C_SRAM_SIZE 0x00001000
106 # define S3C_PCLK_FREQ 66500000 /* Hz */
107 # define S3C_XTAL_FREQ 32768 /* Hz */
109 /* s3c2410.c */
110 struct s3c_pic_state_s;
111 struct s3c_pic_state_s *s3c_pic_init(target_phys_addr_t base,
112 qemu_irq *arm_pic);
113 qemu_irq *s3c_pic_get(struct s3c_pic_state_s *s);
115 struct s3c_dma_state_s;
116 struct s3c_dma_state_s *s3c_dma_init(target_phys_addr_t base, qemu_irq *pic);
117 qemu_irq *s3c_dma_get(struct s3c_dma_state_s *s);
119 /* GPIO TODO: remove this out, replace with qemu_irq or sumpthin */
120 typedef void (*gpio_handler_t)(int line, int level, void *opaque);
122 struct s3c_timers_state_s;
123 struct s3c_timers_state_s *s3c_timers_init(target_phys_addr_t base,
124 qemu_irq *pic, qemu_irq *dma);
125 void s3c_timers_cmp_handler_set(void *opaque, int line,
126 gpio_handler_t handler, void *cmp_opaque);
128 struct s3c_uart_state_s;
129 struct s3c_uart_state_s *s3c_uart_init(target_phys_addr_t base,
130 qemu_irq *irqs, qemu_irq *dma);
131 void s3c_uart_attach(struct s3c_uart_state_s *s, CharDriverState *chr);
133 struct s3c_adc_state_s;
134 struct s3c_adc_state_s *s3c_adc_init(target_phys_addr_t base, qemu_irq irq,
135 qemu_irq tcirq);
136 void s3c_adc_setscale(struct s3c_adc_state_s *adc, const int m[]);
138 struct s3c_i2c_state_s;
139 struct s3c_i2c_state_s *s3c_i2c_init(target_phys_addr_t base, qemu_irq irq);
140 i2c_bus *s3c_i2c_bus(struct s3c_i2c_state_s *s);
142 struct s3c_i2s_state_s;
143 struct s3c_i2s_state_s *s3c_i2s_init(target_phys_addr_t base, qemu_irq *dma);
145 struct s3c_wdt_state_s;
146 struct s3c_wdt_state_s *s3c_wdt_init(target_phys_addr_t base, qemu_irq irq);
148 /* s3c24xx_gpio.c */
149 struct s3c_gpio_state_s;
150 struct s3c_gpio_state_s *s3c_gpio_init(target_phys_addr_t base, qemu_irq *pic, uint32_t cpu_id);
151 qemu_irq *s3c_gpio_in_get(struct s3c_gpio_state_s *s);
152 void s3c_gpio_out_set(struct s3c_gpio_state_s *s, int line, qemu_irq handler);
153 void s3c_gpio_setpwrstat(struct s3c_gpio_state_s *s, int stat);
154 void s3c_gpio_reset(struct s3c_gpio_state_s *s);
155 void s3c_gpio_set_dat(struct s3c_gpio_state_s *s, int gpio, int level);
157 /* s3c24xx_lcd.c */
158 struct s3c_lcd_state_s;
159 struct s3c_lcd_state_s *s3c_lcd_init(target_phys_addr_t base,
160 qemu_irq irq);
161 void s3c_lcd_reset(struct s3c_lcd_state_s *s);
163 /* s3c24xx_mmci.c */
164 struct s3c_mmci_state_s;
165 struct s3c_mmci_state_s *s3c_mmci_init(target_phys_addr_t base, uint32_t cpu_id,
166 SDState *mmc, qemu_irq irq, qemu_irq *dma);
167 void s3c_mmci_reset(struct s3c_mmci_state_s *s);
169 /* s3c24xx_rtc.c */
170 struct s3c_rtc_state_s;
171 struct s3c_rtc_state_s *s3c_rtc_init(target_phys_addr_t base, qemu_irq irq);
172 void s3c_rtc_reset(struct s3c_rtc_state_s *s);
174 /* s3c24xx_udc.c */
175 struct s3c_udc_state_s;
176 struct s3c_udc_state_s *s3c_udc_init(target_phys_addr_t base, qemu_irq irq,
177 qemu_irq *dma);
178 void s3c_udc_reset(struct s3c_udc_state_s *s);
180 struct s3c_nand_driver_s {
181 void (*reset)(void * opaque);
182 void (*setwp)(void * opaque, int wp);
183 void (*reg)(void * opaque, struct nand_flash_s *chip);
186 /* s3c2410_nand.c */
187 struct s3c_nand_driver_s * s3c2410_nand_init(void);
188 /* s3c2440_nand.c */
189 struct s3c_nand_driver_s * s3c2440_nand_init(void);
191 /* s3c2410.c */
192 struct s3c_spi_state_s;
193 struct s3c_spi_state_s *s3c_spi_init(target_phys_addr_t base,
194 qemu_irq irq0, qemu_irq drq0, qemu_irq irq1, qemu_irq drq1,
195 struct s3c_gpio_state_s *gpio);
196 void s3c_spi_attach(struct s3c_spi_state_s *s, int ch,
197 uint8_t (*txrx)(void *opaque, uint8_t value),
198 uint8_t (*btxrx)(void *opaque, uint8_t value), void *opaque);
200 struct s3c_state_s {
201 CPUState *env;
202 uint32_t cpu_id;
203 qemu_irq *irq;
204 qemu_irq *drq;
205 struct s3c_pic_state_s *pic;
206 struct s3c_dma_state_s *dma;
207 struct s3c_gpio_state_s *io;
208 struct s3c_lcd_state_s *lcd;
209 struct s3c_timers_state_s *timers;
210 struct s3c_uart_state_s *uart[3];
211 struct s3c_mmci_state_s *mmci;
212 struct s3c_adc_state_s *adc;
213 struct s3c_i2c_state_s *i2c;
214 struct s3c_i2s_state_s *i2s;
215 struct s3c_rtc_state_s *rtc;
216 struct s3c_spi_state_s *spi;
217 struct s3c_udc_state_s *udc;
218 struct s3c_wdt_state_s *wdt;
219 struct s3c_nand_driver_s *nand;
221 /* Memory controller */
222 target_phys_addr_t mc_base;
223 uint32_t mc_regs[13];
225 /* Clock & power management */
226 target_phys_addr_t clkpwr_base;
227 uint32_t clkpwr_regs[6 + 1]; // 6 2410. 1 2440
230 /* s3c2410.c */
231 struct s3c_state_s *s3c24xx_init(uint32_t cpu_id, unsigned int sdram_size, uint32_t sram_address,
232 SDState *mmc);
235 struct s3c_i2s_state_s { /* XXX move to .c */
236 target_phys_addr_t base;
237 qemu_irq *dma;
238 void (*data_req)(void *, int, int);
240 uint16_t control;
241 uint16_t mode;
242 uint16_t prescaler;
243 uint16_t fcontrol;
245 int tx_en;
246 int rx_en;
247 int tx_len;
248 int rx_len;
249 void (*codec_out)(void *, uint32_t);
250 uint32_t (*codec_in)(void *);
251 void *opaque;
253 uint16_t buffer;
254 int cycle;
257 #endif /* S3C_H */