root / hw / sm501.c @ 07b7d053
History | View | Annotate | Download (29.7 kB)
1 | ffd39257 | blueswir1 | /*
|
---|---|---|---|
2 | ffd39257 | blueswir1 | * QEMU SM501 Device
|
3 | ffd39257 | blueswir1 | *
|
4 | ffd39257 | blueswir1 | * Copyright (c) 2008 Shin-ichiro KAWASAKI
|
5 | ffd39257 | blueswir1 | *
|
6 | ffd39257 | blueswir1 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | ffd39257 | blueswir1 | * of this software and associated documentation files (the "Software"), to deal
|
8 | ffd39257 | blueswir1 | * in the Software without restriction, including without limitation the rights
|
9 | ffd39257 | blueswir1 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | ffd39257 | blueswir1 | * copies of the Software, and to permit persons to whom the Software is
|
11 | ffd39257 | blueswir1 | * furnished to do so, subject to the following conditions:
|
12 | ffd39257 | blueswir1 | *
|
13 | ffd39257 | blueswir1 | * The above copyright notice and this permission notice shall be included in
|
14 | ffd39257 | blueswir1 | * all copies or substantial portions of the Software.
|
15 | ffd39257 | blueswir1 | *
|
16 | ffd39257 | blueswir1 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | ffd39257 | blueswir1 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | ffd39257 | blueswir1 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | ffd39257 | blueswir1 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | ffd39257 | blueswir1 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | ffd39257 | blueswir1 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | ffd39257 | blueswir1 | * THE SOFTWARE.
|
23 | ffd39257 | blueswir1 | */
|
24 | ffd39257 | blueswir1 | |
25 | ffd39257 | blueswir1 | #include <stdio.h> |
26 | ffd39257 | blueswir1 | #include "hw.h" |
27 | ffd39257 | blueswir1 | #include "pc.h" |
28 | ffd39257 | blueswir1 | #include "console.h" |
29 | b79e1752 | aurel32 | #include "devices.h" |
30 | ffd39257 | blueswir1 | |
31 | ffd39257 | blueswir1 | /*
|
32 | ffd39257 | blueswir1 | * Status: 2008/11/02
|
33 | ffd39257 | blueswir1 | * - Minimum implementation for Linux console : mmio regs and CRT layer.
|
34 | ffd39257 | blueswir1 | * - Always updates full screen.
|
35 | ffd39257 | blueswir1 | *
|
36 | ffd39257 | blueswir1 | * TODO:
|
37 | ffd39257 | blueswir1 | * - Panel support
|
38 | ffd39257 | blueswir1 | * - Hardware cursor support
|
39 | ffd39257 | blueswir1 | * - Touch panel support
|
40 | ffd39257 | blueswir1 | * - USB support
|
41 | ffd39257 | blueswir1 | * - UART support
|
42 | ffd39257 | blueswir1 | * - Performance tuning
|
43 | ffd39257 | blueswir1 | */
|
44 | ffd39257 | blueswir1 | |
45 | ffd39257 | blueswir1 | //#define DEBUG_SM501
|
46 | ffd39257 | blueswir1 | //#define DEBUG_BITBLT
|
47 | ffd39257 | blueswir1 | |
48 | ffd39257 | blueswir1 | #ifdef DEBUG_SM501
|
49 | 001faf32 | Blue Swirl | #define SM501_DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) |
50 | ffd39257 | blueswir1 | #else
|
51 | 001faf32 | Blue Swirl | #define SM501_DPRINTF(fmt, ...) do {} while(0) |
52 | ffd39257 | blueswir1 | #endif
|
53 | ffd39257 | blueswir1 | |
54 | ffd39257 | blueswir1 | |
55 | ffd39257 | blueswir1 | #define MMIO_BASE_OFFSET 0x3e00000 |
56 | ffd39257 | blueswir1 | |
57 | ffd39257 | blueswir1 | /* SM501 register definitions taken from "linux/include/linux/sm501-regs.h" */
|
58 | ffd39257 | blueswir1 | |
59 | ffd39257 | blueswir1 | /* System Configuration area */
|
60 | ffd39257 | blueswir1 | /* System config base */
|
61 | ffd39257 | blueswir1 | #define SM501_SYS_CONFIG (0x000000) |
62 | ffd39257 | blueswir1 | |
63 | ffd39257 | blueswir1 | /* config 1 */
|
64 | ffd39257 | blueswir1 | #define SM501_SYSTEM_CONTROL (0x000000) |
65 | ffd39257 | blueswir1 | |
66 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PANEL_TRISTATE (1<<0) |
67 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_MEM_TRISTATE (1<<1) |
68 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_CRT_TRISTATE (1<<2) |
69 | ffd39257 | blueswir1 | |
70 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_MASK (3<<4) |
71 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_1 (0<<4) |
72 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_2 (1<<4) |
73 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_4 (2<<4) |
74 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_8 (3<<4) |
75 | ffd39257 | blueswir1 | |
76 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_CLOCK_RUN_EN (1<<6) |
77 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_RETRY_DISABLE (1<<7) |
78 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_SUBSYS_LOCK (1<<11) |
79 | ffd39257 | blueswir1 | #define SM501_SYSCTRL_PCI_BURST_READ_EN (1<<15) |
80 | ffd39257 | blueswir1 | |
81 | ffd39257 | blueswir1 | /* miscellaneous control */
|
82 | ffd39257 | blueswir1 | |
83 | ffd39257 | blueswir1 | #define SM501_MISC_CONTROL (0x000004) |
84 | ffd39257 | blueswir1 | |
85 | ffd39257 | blueswir1 | #define SM501_MISC_BUS_SH (0x0) |
86 | ffd39257 | blueswir1 | #define SM501_MISC_BUS_PCI (0x1) |
87 | ffd39257 | blueswir1 | #define SM501_MISC_BUS_XSCALE (0x2) |
88 | ffd39257 | blueswir1 | #define SM501_MISC_BUS_NEC (0x6) |
89 | ffd39257 | blueswir1 | #define SM501_MISC_BUS_MASK (0x7) |
90 | ffd39257 | blueswir1 | |
91 | ffd39257 | blueswir1 | #define SM501_MISC_VR_62MB (1<<3) |
92 | ffd39257 | blueswir1 | #define SM501_MISC_CDR_RESET (1<<7) |
93 | ffd39257 | blueswir1 | #define SM501_MISC_USB_LB (1<<8) |
94 | ffd39257 | blueswir1 | #define SM501_MISC_USB_SLAVE (1<<9) |
95 | ffd39257 | blueswir1 | #define SM501_MISC_BL_1 (1<<10) |
96 | ffd39257 | blueswir1 | #define SM501_MISC_MC (1<<11) |
97 | ffd39257 | blueswir1 | #define SM501_MISC_DAC_POWER (1<<12) |
98 | ffd39257 | blueswir1 | #define SM501_MISC_IRQ_INVERT (1<<16) |
99 | ffd39257 | blueswir1 | #define SM501_MISC_SH (1<<17) |
100 | ffd39257 | blueswir1 | |
101 | ffd39257 | blueswir1 | #define SM501_MISC_HOLD_EMPTY (0<<18) |
102 | ffd39257 | blueswir1 | #define SM501_MISC_HOLD_8 (1<<18) |
103 | ffd39257 | blueswir1 | #define SM501_MISC_HOLD_16 (2<<18) |
104 | ffd39257 | blueswir1 | #define SM501_MISC_HOLD_24 (3<<18) |
105 | ffd39257 | blueswir1 | #define SM501_MISC_HOLD_32 (4<<18) |
106 | ffd39257 | blueswir1 | #define SM501_MISC_HOLD_MASK (7<<18) |
107 | ffd39257 | blueswir1 | |
108 | ffd39257 | blueswir1 | #define SM501_MISC_FREQ_12 (1<<24) |
109 | ffd39257 | blueswir1 | #define SM501_MISC_PNL_24BIT (1<<25) |
110 | ffd39257 | blueswir1 | #define SM501_MISC_8051_LE (1<<26) |
111 | ffd39257 | blueswir1 | |
112 | ffd39257 | blueswir1 | |
113 | ffd39257 | blueswir1 | |
114 | ffd39257 | blueswir1 | #define SM501_GPIO31_0_CONTROL (0x000008) |
115 | ffd39257 | blueswir1 | #define SM501_GPIO63_32_CONTROL (0x00000C) |
116 | ffd39257 | blueswir1 | #define SM501_DRAM_CONTROL (0x000010) |
117 | ffd39257 | blueswir1 | |
118 | ffd39257 | blueswir1 | /* command list */
|
119 | ffd39257 | blueswir1 | #define SM501_ARBTRTN_CONTROL (0x000014) |
120 | ffd39257 | blueswir1 | |
121 | ffd39257 | blueswir1 | /* command list */
|
122 | ffd39257 | blueswir1 | #define SM501_COMMAND_LIST_STATUS (0x000024) |
123 | ffd39257 | blueswir1 | |
124 | ffd39257 | blueswir1 | /* interrupt debug */
|
125 | ffd39257 | blueswir1 | #define SM501_RAW_IRQ_STATUS (0x000028) |
126 | ffd39257 | blueswir1 | #define SM501_RAW_IRQ_CLEAR (0x000028) |
127 | ffd39257 | blueswir1 | #define SM501_IRQ_STATUS (0x00002C) |
128 | ffd39257 | blueswir1 | #define SM501_IRQ_MASK (0x000030) |
129 | ffd39257 | blueswir1 | #define SM501_DEBUG_CONTROL (0x000034) |
130 | ffd39257 | blueswir1 | |
131 | ffd39257 | blueswir1 | /* power management */
|
132 | ffd39257 | blueswir1 | #define SM501_POWERMODE_P2X_SRC (1<<29) |
133 | ffd39257 | blueswir1 | #define SM501_POWERMODE_V2X_SRC (1<<20) |
134 | ffd39257 | blueswir1 | #define SM501_POWERMODE_M_SRC (1<<12) |
135 | ffd39257 | blueswir1 | #define SM501_POWERMODE_M1_SRC (1<<4) |
136 | ffd39257 | blueswir1 | |
137 | ffd39257 | blueswir1 | #define SM501_CURRENT_GATE (0x000038) |
138 | ffd39257 | blueswir1 | #define SM501_CURRENT_CLOCK (0x00003C) |
139 | ffd39257 | blueswir1 | #define SM501_POWER_MODE_0_GATE (0x000040) |
140 | ffd39257 | blueswir1 | #define SM501_POWER_MODE_0_CLOCK (0x000044) |
141 | ffd39257 | blueswir1 | #define SM501_POWER_MODE_1_GATE (0x000048) |
142 | ffd39257 | blueswir1 | #define SM501_POWER_MODE_1_CLOCK (0x00004C) |
143 | ffd39257 | blueswir1 | #define SM501_SLEEP_MODE_GATE (0x000050) |
144 | ffd39257 | blueswir1 | #define SM501_POWER_MODE_CONTROL (0x000054) |
145 | ffd39257 | blueswir1 | |
146 | ffd39257 | blueswir1 | /* power gates for units within the 501 */
|
147 | ffd39257 | blueswir1 | #define SM501_GATE_HOST (0) |
148 | ffd39257 | blueswir1 | #define SM501_GATE_MEMORY (1) |
149 | ffd39257 | blueswir1 | #define SM501_GATE_DISPLAY (2) |
150 | ffd39257 | blueswir1 | #define SM501_GATE_2D_ENGINE (3) |
151 | ffd39257 | blueswir1 | #define SM501_GATE_CSC (4) |
152 | ffd39257 | blueswir1 | #define SM501_GATE_ZVPORT (5) |
153 | ffd39257 | blueswir1 | #define SM501_GATE_GPIO (6) |
154 | ffd39257 | blueswir1 | #define SM501_GATE_UART0 (7) |
155 | ffd39257 | blueswir1 | #define SM501_GATE_UART1 (8) |
156 | ffd39257 | blueswir1 | #define SM501_GATE_SSP (10) |
157 | ffd39257 | blueswir1 | #define SM501_GATE_USB_HOST (11) |
158 | ffd39257 | blueswir1 | #define SM501_GATE_USB_GADGET (12) |
159 | ffd39257 | blueswir1 | #define SM501_GATE_UCONTROLLER (17) |
160 | ffd39257 | blueswir1 | #define SM501_GATE_AC97 (18) |
161 | ffd39257 | blueswir1 | |
162 | ffd39257 | blueswir1 | /* panel clock */
|
163 | ffd39257 | blueswir1 | #define SM501_CLOCK_P2XCLK (24) |
164 | ffd39257 | blueswir1 | /* crt clock */
|
165 | ffd39257 | blueswir1 | #define SM501_CLOCK_V2XCLK (16) |
166 | ffd39257 | blueswir1 | /* main clock */
|
167 | ffd39257 | blueswir1 | #define SM501_CLOCK_MCLK (8) |
168 | ffd39257 | blueswir1 | /* SDRAM controller clock */
|
169 | ffd39257 | blueswir1 | #define SM501_CLOCK_M1XCLK (0) |
170 | ffd39257 | blueswir1 | |
171 | ffd39257 | blueswir1 | /* config 2 */
|
172 | ffd39257 | blueswir1 | #define SM501_PCI_MASTER_BASE (0x000058) |
173 | ffd39257 | blueswir1 | #define SM501_ENDIAN_CONTROL (0x00005C) |
174 | ffd39257 | blueswir1 | #define SM501_DEVICEID (0x000060) |
175 | ffd39257 | blueswir1 | /* 0x050100A0 */
|
176 | ffd39257 | blueswir1 | |
177 | ffd39257 | blueswir1 | #define SM501_DEVICEID_SM501 (0x05010000) |
178 | ffd39257 | blueswir1 | #define SM501_DEVICEID_IDMASK (0xffff0000) |
179 | ffd39257 | blueswir1 | #define SM501_DEVICEID_REVMASK (0x000000ff) |
180 | ffd39257 | blueswir1 | |
181 | ffd39257 | blueswir1 | #define SM501_PLLCLOCK_COUNT (0x000064) |
182 | ffd39257 | blueswir1 | #define SM501_MISC_TIMING (0x000068) |
183 | ffd39257 | blueswir1 | #define SM501_CURRENT_SDRAM_CLOCK (0x00006C) |
184 | ffd39257 | blueswir1 | |
185 | ffd39257 | blueswir1 | #define SM501_PROGRAMMABLE_PLL_CONTROL (0x000074) |
186 | ffd39257 | blueswir1 | |
187 | ffd39257 | blueswir1 | /* GPIO base */
|
188 | ffd39257 | blueswir1 | #define SM501_GPIO (0x010000) |
189 | ffd39257 | blueswir1 | #define SM501_GPIO_DATA_LOW (0x00) |
190 | ffd39257 | blueswir1 | #define SM501_GPIO_DATA_HIGH (0x04) |
191 | ffd39257 | blueswir1 | #define SM501_GPIO_DDR_LOW (0x08) |
192 | ffd39257 | blueswir1 | #define SM501_GPIO_DDR_HIGH (0x0C) |
193 | ffd39257 | blueswir1 | #define SM501_GPIO_IRQ_SETUP (0x10) |
194 | ffd39257 | blueswir1 | #define SM501_GPIO_IRQ_STATUS (0x14) |
195 | ffd39257 | blueswir1 | #define SM501_GPIO_IRQ_RESET (0x14) |
196 | ffd39257 | blueswir1 | |
197 | ffd39257 | blueswir1 | /* I2C controller base */
|
198 | ffd39257 | blueswir1 | #define SM501_I2C (0x010040) |
199 | ffd39257 | blueswir1 | #define SM501_I2C_BYTE_COUNT (0x00) |
200 | ffd39257 | blueswir1 | #define SM501_I2C_CONTROL (0x01) |
201 | ffd39257 | blueswir1 | #define SM501_I2C_STATUS (0x02) |
202 | ffd39257 | blueswir1 | #define SM501_I2C_RESET (0x02) |
203 | ffd39257 | blueswir1 | #define SM501_I2C_SLAVE_ADDRESS (0x03) |
204 | ffd39257 | blueswir1 | #define SM501_I2C_DATA (0x04) |
205 | ffd39257 | blueswir1 | |
206 | ffd39257 | blueswir1 | /* SSP base */
|
207 | ffd39257 | blueswir1 | #define SM501_SSP (0x020000) |
208 | ffd39257 | blueswir1 | |
209 | ffd39257 | blueswir1 | /* Uart 0 base */
|
210 | ffd39257 | blueswir1 | #define SM501_UART0 (0x030000) |
211 | ffd39257 | blueswir1 | |
212 | ffd39257 | blueswir1 | /* Uart 1 base */
|
213 | ffd39257 | blueswir1 | #define SM501_UART1 (0x030020) |
214 | ffd39257 | blueswir1 | |
215 | ffd39257 | blueswir1 | /* USB host port base */
|
216 | ffd39257 | blueswir1 | #define SM501_USB_HOST (0x040000) |
217 | ffd39257 | blueswir1 | |
218 | ffd39257 | blueswir1 | /* USB slave/gadget base */
|
219 | ffd39257 | blueswir1 | #define SM501_USB_GADGET (0x060000) |
220 | ffd39257 | blueswir1 | |
221 | ffd39257 | blueswir1 | /* USB slave/gadget data port base */
|
222 | ffd39257 | blueswir1 | #define SM501_USB_GADGET_DATA (0x070000) |
223 | ffd39257 | blueswir1 | |
224 | ffd39257 | blueswir1 | /* Display controller/video engine base */
|
225 | ffd39257 | blueswir1 | #define SM501_DC (0x080000) |
226 | ffd39257 | blueswir1 | |
227 | ffd39257 | blueswir1 | /* common defines for the SM501 address registers */
|
228 | ffd39257 | blueswir1 | #define SM501_ADDR_FLIP (1<<31) |
229 | ffd39257 | blueswir1 | #define SM501_ADDR_EXT (1<<27) |
230 | ffd39257 | blueswir1 | #define SM501_ADDR_CS1 (1<<26) |
231 | ffd39257 | blueswir1 | #define SM501_ADDR_MASK (0x3f << 26) |
232 | ffd39257 | blueswir1 | |
233 | ffd39257 | blueswir1 | #define SM501_FIFO_MASK (0x3 << 16) |
234 | ffd39257 | blueswir1 | #define SM501_FIFO_1 (0x0 << 16) |
235 | ffd39257 | blueswir1 | #define SM501_FIFO_3 (0x1 << 16) |
236 | ffd39257 | blueswir1 | #define SM501_FIFO_7 (0x2 << 16) |
237 | ffd39257 | blueswir1 | #define SM501_FIFO_11 (0x3 << 16) |
238 | ffd39257 | blueswir1 | |
239 | ffd39257 | blueswir1 | /* common registers for panel and the crt */
|
240 | ffd39257 | blueswir1 | #define SM501_OFF_DC_H_TOT (0x000) |
241 | ffd39257 | blueswir1 | #define SM501_OFF_DC_V_TOT (0x008) |
242 | ffd39257 | blueswir1 | #define SM501_OFF_DC_H_SYNC (0x004) |
243 | ffd39257 | blueswir1 | #define SM501_OFF_DC_V_SYNC (0x00C) |
244 | ffd39257 | blueswir1 | |
245 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL (0x000) |
246 | ffd39257 | blueswir1 | |
247 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_FPEN (1<<27) |
248 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_BIAS (1<<26) |
249 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_DATA (1<<25) |
250 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_VDD (1<<24) |
251 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_DP (1<<23) |
252 | ffd39257 | blueswir1 | |
253 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_TFT_888 (0<<21) |
254 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_TFT_333 (1<<21) |
255 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_TFT_444 (2<<21) |
256 | ffd39257 | blueswir1 | |
257 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_DE (1<<20) |
258 | ffd39257 | blueswir1 | |
259 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_LCD_TFT (0<<18) |
260 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_LCD_STN8 (1<<18) |
261 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_LCD_STN12 (2<<18) |
262 | ffd39257 | blueswir1 | |
263 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_CP (1<<14) |
264 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_VSP (1<<13) |
265 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_HSP (1<<12) |
266 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_CK (1<<9) |
267 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_TE (1<<8) |
268 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_VPD (1<<7) |
269 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_VP (1<<6) |
270 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_HPD (1<<5) |
271 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_HP (1<<4) |
272 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_GAMMA (1<<3) |
273 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_EN (1<<2) |
274 | ffd39257 | blueswir1 | |
275 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_8BPP (0<<0) |
276 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_16BPP (1<<0) |
277 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CONTROL_32BPP (2<<0) |
278 | ffd39257 | blueswir1 | |
279 | ffd39257 | blueswir1 | |
280 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_PANNING_CONTROL (0x004) |
281 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_COLOR_KEY (0x008) |
282 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_FB_ADDR (0x00C) |
283 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_FB_OFFSET (0x010) |
284 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_FB_WIDTH (0x014) |
285 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_FB_HEIGHT (0x018) |
286 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_TL_LOC (0x01C) |
287 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_BR_LOC (0x020) |
288 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_H_TOT (0x024) |
289 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_H_SYNC (0x028) |
290 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_V_TOT (0x02C) |
291 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_V_SYNC (0x030) |
292 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_CUR_LINE (0x034) |
293 | ffd39257 | blueswir1 | |
294 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_CONTROL (0x040) |
295 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_FB0_ADDR (0x044) |
296 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_FB_WIDTH (0x048) |
297 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_FB0_LAST_ADDR (0x04C) |
298 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_TL_LOC (0x050) |
299 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_BR_LOC (0x054) |
300 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_SCALE (0x058) |
301 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_INIT_SCALE (0x05C) |
302 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_YUV_CONSTANTS (0x060) |
303 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_FB1_ADDR (0x064) |
304 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_FB1_LAST_ADDR (0x068) |
305 | ffd39257 | blueswir1 | |
306 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_CONTROL (0x080) |
307 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_FB_ADDR (0x084) |
308 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_FB_OFFSET (0x088) |
309 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_FB_LAST_ADDR (0x08C) |
310 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_TL_LOC (0x090) |
311 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_BR_LOC (0x094) |
312 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_SCALE (0x098) |
313 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_INIT_SCALE (0x09C) |
314 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_CHROMA_KEY (0x0A0) |
315 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_ALPHA_COLOR_LOOKUP (0x0A4) |
316 | ffd39257 | blueswir1 | |
317 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_HWC_BASE (0x0F0) |
318 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_HWC_ADDR (0x0F0) |
319 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_HWC_LOC (0x0F4) |
320 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_HWC_COLOR_1_2 (0x0F8) |
321 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_HWC_COLOR_3 (0x0FC) |
322 | ffd39257 | blueswir1 | |
323 | ffd39257 | blueswir1 | #define SM501_HWC_EN (1<<31) |
324 | ffd39257 | blueswir1 | |
325 | ffd39257 | blueswir1 | #define SM501_OFF_HWC_ADDR (0x00) |
326 | ffd39257 | blueswir1 | #define SM501_OFF_HWC_LOC (0x04) |
327 | ffd39257 | blueswir1 | #define SM501_OFF_HWC_COLOR_1_2 (0x08) |
328 | ffd39257 | blueswir1 | #define SM501_OFF_HWC_COLOR_3 (0x0C) |
329 | ffd39257 | blueswir1 | |
330 | ffd39257 | blueswir1 | #define SM501_DC_ALPHA_CONTROL (0x100) |
331 | ffd39257 | blueswir1 | #define SM501_DC_ALPHA_FB_ADDR (0x104) |
332 | ffd39257 | blueswir1 | #define SM501_DC_ALPHA_FB_OFFSET (0x108) |
333 | ffd39257 | blueswir1 | #define SM501_DC_ALPHA_TL_LOC (0x10C) |
334 | ffd39257 | blueswir1 | #define SM501_DC_ALPHA_BR_LOC (0x110) |
335 | ffd39257 | blueswir1 | #define SM501_DC_ALPHA_CHROMA_KEY (0x114) |
336 | ffd39257 | blueswir1 | #define SM501_DC_ALPHA_COLOR_LOOKUP (0x118) |
337 | ffd39257 | blueswir1 | |
338 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL (0x200) |
339 | ffd39257 | blueswir1 | |
340 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_TVP (1<<15) |
341 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_CP (1<<14) |
342 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_VSP (1<<13) |
343 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_HSP (1<<12) |
344 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_VS (1<<11) |
345 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_BLANK (1<<10) |
346 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_SEL (1<<9) |
347 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_TE (1<<8) |
348 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_PIXEL_MASK (0xF << 4) |
349 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_GAMMA (1<<3) |
350 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_ENABLE (1<<2) |
351 | ffd39257 | blueswir1 | |
352 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_8BPP (0<<0) |
353 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_16BPP (1<<0) |
354 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CONTROL_32BPP (2<<0) |
355 | ffd39257 | blueswir1 | |
356 | ffd39257 | blueswir1 | #define SM501_DC_CRT_FB_ADDR (0x204) |
357 | ffd39257 | blueswir1 | #define SM501_DC_CRT_FB_OFFSET (0x208) |
358 | ffd39257 | blueswir1 | #define SM501_DC_CRT_H_TOT (0x20C) |
359 | ffd39257 | blueswir1 | #define SM501_DC_CRT_H_SYNC (0x210) |
360 | ffd39257 | blueswir1 | #define SM501_DC_CRT_V_TOT (0x214) |
361 | ffd39257 | blueswir1 | #define SM501_DC_CRT_V_SYNC (0x218) |
362 | ffd39257 | blueswir1 | #define SM501_DC_CRT_SIGNATURE_ANALYZER (0x21C) |
363 | ffd39257 | blueswir1 | #define SM501_DC_CRT_CUR_LINE (0x220) |
364 | ffd39257 | blueswir1 | #define SM501_DC_CRT_MONITOR_DETECT (0x224) |
365 | ffd39257 | blueswir1 | |
366 | ffd39257 | blueswir1 | #define SM501_DC_CRT_HWC_BASE (0x230) |
367 | ffd39257 | blueswir1 | #define SM501_DC_CRT_HWC_ADDR (0x230) |
368 | ffd39257 | blueswir1 | #define SM501_DC_CRT_HWC_LOC (0x234) |
369 | ffd39257 | blueswir1 | #define SM501_DC_CRT_HWC_COLOR_1_2 (0x238) |
370 | ffd39257 | blueswir1 | #define SM501_DC_CRT_HWC_COLOR_3 (0x23C) |
371 | ffd39257 | blueswir1 | |
372 | ffd39257 | blueswir1 | #define SM501_DC_PANEL_PALETTE (0x400) |
373 | ffd39257 | blueswir1 | |
374 | ffd39257 | blueswir1 | #define SM501_DC_VIDEO_PALETTE (0x800) |
375 | ffd39257 | blueswir1 | |
376 | ffd39257 | blueswir1 | #define SM501_DC_CRT_PALETTE (0xC00) |
377 | ffd39257 | blueswir1 | |
378 | ffd39257 | blueswir1 | /* Zoom Video port base */
|
379 | ffd39257 | blueswir1 | #define SM501_ZVPORT (0x090000) |
380 | ffd39257 | blueswir1 | |
381 | ffd39257 | blueswir1 | /* AC97/I2S base */
|
382 | ffd39257 | blueswir1 | #define SM501_AC97 (0x0A0000) |
383 | ffd39257 | blueswir1 | |
384 | ffd39257 | blueswir1 | /* 8051 micro controller base */
|
385 | ffd39257 | blueswir1 | #define SM501_UCONTROLLER (0x0B0000) |
386 | ffd39257 | blueswir1 | |
387 | ffd39257 | blueswir1 | /* 8051 micro controller SRAM base */
|
388 | ffd39257 | blueswir1 | #define SM501_UCONTROLLER_SRAM (0x0C0000) |
389 | ffd39257 | blueswir1 | |
390 | ffd39257 | blueswir1 | /* DMA base */
|
391 | ffd39257 | blueswir1 | #define SM501_DMA (0x0D0000) |
392 | ffd39257 | blueswir1 | |
393 | ffd39257 | blueswir1 | /* 2d engine base */
|
394 | ffd39257 | blueswir1 | #define SM501_2D_ENGINE (0x100000) |
395 | ffd39257 | blueswir1 | #define SM501_2D_SOURCE (0x00) |
396 | ffd39257 | blueswir1 | #define SM501_2D_DESTINATION (0x04) |
397 | ffd39257 | blueswir1 | #define SM501_2D_DIMENSION (0x08) |
398 | ffd39257 | blueswir1 | #define SM501_2D_CONTROL (0x0C) |
399 | ffd39257 | blueswir1 | #define SM501_2D_PITCH (0x10) |
400 | ffd39257 | blueswir1 | #define SM501_2D_FOREGROUND (0x14) |
401 | ffd39257 | blueswir1 | #define SM501_2D_BACKGROUND (0x18) |
402 | ffd39257 | blueswir1 | #define SM501_2D_STRETCH (0x1C) |
403 | ffd39257 | blueswir1 | #define SM501_2D_COLOR_COMPARE (0x20) |
404 | ffd39257 | blueswir1 | #define SM501_2D_COLOR_COMPARE_MASK (0x24) |
405 | ffd39257 | blueswir1 | #define SM501_2D_MASK (0x28) |
406 | ffd39257 | blueswir1 | #define SM501_2D_CLIP_TL (0x2C) |
407 | ffd39257 | blueswir1 | #define SM501_2D_CLIP_BR (0x30) |
408 | ffd39257 | blueswir1 | #define SM501_2D_MONO_PATTERN_LOW (0x34) |
409 | ffd39257 | blueswir1 | #define SM501_2D_MONO_PATTERN_HIGH (0x38) |
410 | ffd39257 | blueswir1 | #define SM501_2D_WINDOW_WIDTH (0x3C) |
411 | ffd39257 | blueswir1 | #define SM501_2D_SOURCE_BASE (0x40) |
412 | ffd39257 | blueswir1 | #define SM501_2D_DESTINATION_BASE (0x44) |
413 | ffd39257 | blueswir1 | #define SM501_2D_ALPHA (0x48) |
414 | ffd39257 | blueswir1 | #define SM501_2D_WRAP (0x4C) |
415 | ffd39257 | blueswir1 | #define SM501_2D_STATUS (0x50) |
416 | ffd39257 | blueswir1 | |
417 | ffd39257 | blueswir1 | #define SM501_CSC_Y_SOURCE_BASE (0xC8) |
418 | ffd39257 | blueswir1 | #define SM501_CSC_CONSTANTS (0xCC) |
419 | ffd39257 | blueswir1 | #define SM501_CSC_Y_SOURCE_X (0xD0) |
420 | ffd39257 | blueswir1 | #define SM501_CSC_Y_SOURCE_Y (0xD4) |
421 | ffd39257 | blueswir1 | #define SM501_CSC_U_SOURCE_BASE (0xD8) |
422 | ffd39257 | blueswir1 | #define SM501_CSC_V_SOURCE_BASE (0xDC) |
423 | ffd39257 | blueswir1 | #define SM501_CSC_SOURCE_DIMENSION (0xE0) |
424 | ffd39257 | blueswir1 | #define SM501_CSC_SOURCE_PITCH (0xE4) |
425 | ffd39257 | blueswir1 | #define SM501_CSC_DESTINATION (0xE8) |
426 | ffd39257 | blueswir1 | #define SM501_CSC_DESTINATION_DIMENSION (0xEC) |
427 | ffd39257 | blueswir1 | #define SM501_CSC_DESTINATION_PITCH (0xF0) |
428 | ffd39257 | blueswir1 | #define SM501_CSC_SCALE_FACTOR (0xF4) |
429 | ffd39257 | blueswir1 | #define SM501_CSC_DESTINATION_BASE (0xF8) |
430 | ffd39257 | blueswir1 | #define SM501_CSC_CONTROL (0xFC) |
431 | ffd39257 | blueswir1 | |
432 | ffd39257 | blueswir1 | /* 2d engine data port base */
|
433 | ffd39257 | blueswir1 | #define SM501_2D_ENGINE_DATA (0x110000) |
434 | ffd39257 | blueswir1 | |
435 | ffd39257 | blueswir1 | /* end of register definitions */
|
436 | ffd39257 | blueswir1 | |
437 | ffd39257 | blueswir1 | |
438 | ffd39257 | blueswir1 | /* SM501 local memory size taken from "linux/drivers/mfd/sm501.c" */
|
439 | ffd39257 | blueswir1 | static const uint32_t sm501_mem_local_size[] = { |
440 | ffd39257 | blueswir1 | [0] = 4*1024*1024, |
441 | ffd39257 | blueswir1 | [1] = 8*1024*1024, |
442 | ffd39257 | blueswir1 | [2] = 16*1024*1024, |
443 | ffd39257 | blueswir1 | [3] = 32*1024*1024, |
444 | ffd39257 | blueswir1 | [4] = 64*1024*1024, |
445 | ffd39257 | blueswir1 | [5] = 2*1024*1024, |
446 | ffd39257 | blueswir1 | }; |
447 | ffd39257 | blueswir1 | #define get_local_mem_size(s) sm501_mem_local_size[(s)->local_mem_size_index]
|
448 | ffd39257 | blueswir1 | |
449 | ffd39257 | blueswir1 | typedef struct SM501State { |
450 | ffd39257 | blueswir1 | /* graphic console status */
|
451 | ffd39257 | blueswir1 | DisplayState *ds; |
452 | ffd39257 | blueswir1 | |
453 | ffd39257 | blueswir1 | /* status & internal resources */
|
454 | ffd39257 | blueswir1 | target_phys_addr_t base; |
455 | ffd39257 | blueswir1 | uint32_t local_mem_size_index; |
456 | ffd39257 | blueswir1 | uint8_t * local_mem; |
457 | 44654490 | pbrook | ram_addr_t local_mem_offset; |
458 | ffd39257 | blueswir1 | uint32_t last_width; |
459 | ffd39257 | blueswir1 | uint32_t last_height; |
460 | ffd39257 | blueswir1 | |
461 | ffd39257 | blueswir1 | /* mmio registers */
|
462 | ffd39257 | blueswir1 | uint32_t system_control; |
463 | ffd39257 | blueswir1 | uint32_t misc_control; |
464 | ffd39257 | blueswir1 | uint32_t gpio_31_0_control; |
465 | ffd39257 | blueswir1 | uint32_t gpio_63_32_control; |
466 | ffd39257 | blueswir1 | uint32_t dram_control; |
467 | ffd39257 | blueswir1 | uint32_t irq_mask; |
468 | ffd39257 | blueswir1 | uint32_t misc_timing; |
469 | ffd39257 | blueswir1 | uint32_t power_mode_control; |
470 | ffd39257 | blueswir1 | |
471 | ffd39257 | blueswir1 | uint32_t uart0_ier; |
472 | ffd39257 | blueswir1 | uint32_t uart0_lcr; |
473 | ffd39257 | blueswir1 | uint32_t uart0_mcr; |
474 | ffd39257 | blueswir1 | uint32_t uart0_scr; |
475 | ffd39257 | blueswir1 | |
476 | ffd39257 | blueswir1 | uint8_t dc_palette[0x400 * 3]; |
477 | ffd39257 | blueswir1 | |
478 | ffd39257 | blueswir1 | uint32_t dc_panel_control; |
479 | ffd39257 | blueswir1 | uint32_t dc_panel_panning_control; |
480 | ffd39257 | blueswir1 | uint32_t dc_panel_fb_addr; |
481 | ffd39257 | blueswir1 | uint32_t dc_panel_fb_offset; |
482 | ffd39257 | blueswir1 | uint32_t dc_panel_fb_width; |
483 | ffd39257 | blueswir1 | uint32_t dc_panel_fb_height; |
484 | ffd39257 | blueswir1 | uint32_t dc_panel_tl_location; |
485 | ffd39257 | blueswir1 | uint32_t dc_panel_br_location; |
486 | ffd39257 | blueswir1 | uint32_t dc_panel_h_total; |
487 | ffd39257 | blueswir1 | uint32_t dc_panel_h_sync; |
488 | ffd39257 | blueswir1 | uint32_t dc_panel_v_total; |
489 | ffd39257 | blueswir1 | uint32_t dc_panel_v_sync; |
490 | ffd39257 | blueswir1 | |
491 | ffd39257 | blueswir1 | uint32_t dc_panel_hwc_addr; |
492 | ffd39257 | blueswir1 | uint32_t dc_panel_hwc_location; |
493 | ffd39257 | blueswir1 | uint32_t dc_panel_hwc_color_1_2; |
494 | ffd39257 | blueswir1 | uint32_t dc_panel_hwc_color_3; |
495 | ffd39257 | blueswir1 | |
496 | ffd39257 | blueswir1 | uint32_t dc_crt_control; |
497 | ffd39257 | blueswir1 | uint32_t dc_crt_fb_addr; |
498 | ffd39257 | blueswir1 | uint32_t dc_crt_fb_offset; |
499 | ffd39257 | blueswir1 | uint32_t dc_crt_h_total; |
500 | ffd39257 | blueswir1 | uint32_t dc_crt_h_sync; |
501 | ffd39257 | blueswir1 | uint32_t dc_crt_v_total; |
502 | ffd39257 | blueswir1 | uint32_t dc_crt_v_sync; |
503 | ffd39257 | blueswir1 | |
504 | ffd39257 | blueswir1 | uint32_t dc_crt_hwc_addr; |
505 | ffd39257 | blueswir1 | uint32_t dc_crt_hwc_location; |
506 | ffd39257 | blueswir1 | uint32_t dc_crt_hwc_color_1_2; |
507 | ffd39257 | blueswir1 | uint32_t dc_crt_hwc_color_3; |
508 | ffd39257 | blueswir1 | |
509 | ffd39257 | blueswir1 | } SM501State; |
510 | ffd39257 | blueswir1 | |
511 | ffd39257 | blueswir1 | static uint32_t get_local_mem_size_index(uint32_t size)
|
512 | ffd39257 | blueswir1 | { |
513 | ffd39257 | blueswir1 | uint32_t norm_size = 0;
|
514 | ffd39257 | blueswir1 | int i, index = 0; |
515 | ffd39257 | blueswir1 | |
516 | b1503cda | malc | for (i = 0; i < ARRAY_SIZE(sm501_mem_local_size); i++) { |
517 | ffd39257 | blueswir1 | uint32_t new_size = sm501_mem_local_size[i]; |
518 | ffd39257 | blueswir1 | if (new_size >= size) {
|
519 | ffd39257 | blueswir1 | if (norm_size == 0 || norm_size > new_size) { |
520 | ffd39257 | blueswir1 | norm_size = new_size; |
521 | ffd39257 | blueswir1 | index = i; |
522 | ffd39257 | blueswir1 | } |
523 | ffd39257 | blueswir1 | } |
524 | ffd39257 | blueswir1 | } |
525 | ffd39257 | blueswir1 | |
526 | ffd39257 | blueswir1 | return index;
|
527 | ffd39257 | blueswir1 | } |
528 | ffd39257 | blueswir1 | |
529 | ffd39257 | blueswir1 | static uint32_t sm501_system_config_read(void *opaque, target_phys_addr_t addr) |
530 | ffd39257 | blueswir1 | { |
531 | ffd39257 | blueswir1 | SM501State * s = (SM501State *)opaque; |
532 | ffd39257 | blueswir1 | uint32_t ret = 0;
|
533 | 8da3ff18 | pbrook | SM501_DPRINTF("sm501 system config regs : read addr=%x\n", (int)addr); |
534 | ffd39257 | blueswir1 | |
535 | 8da3ff18 | pbrook | switch(addr) {
|
536 | ffd39257 | blueswir1 | case SM501_SYSTEM_CONTROL:
|
537 | ffd39257 | blueswir1 | ret = s->system_control; |
538 | ffd39257 | blueswir1 | break;
|
539 | ffd39257 | blueswir1 | case SM501_MISC_CONTROL:
|
540 | ffd39257 | blueswir1 | ret = s->misc_control; |
541 | ffd39257 | blueswir1 | break;
|
542 | ffd39257 | blueswir1 | case SM501_GPIO31_0_CONTROL:
|
543 | ffd39257 | blueswir1 | ret = s->gpio_31_0_control; |
544 | ffd39257 | blueswir1 | break;
|
545 | ffd39257 | blueswir1 | case SM501_GPIO63_32_CONTROL:
|
546 | ffd39257 | blueswir1 | ret = s->gpio_63_32_control; |
547 | ffd39257 | blueswir1 | break;
|
548 | ffd39257 | blueswir1 | case SM501_DEVICEID:
|
549 | ffd39257 | blueswir1 | ret = 0x050100A0;
|
550 | ffd39257 | blueswir1 | break;
|
551 | ffd39257 | blueswir1 | case SM501_DRAM_CONTROL:
|
552 | ffd39257 | blueswir1 | ret = (s->dram_control & 0x07F107C0) | s->local_mem_size_index << 13; |
553 | ffd39257 | blueswir1 | break;
|
554 | ffd39257 | blueswir1 | case SM501_IRQ_MASK:
|
555 | ffd39257 | blueswir1 | ret = s->irq_mask; |
556 | ffd39257 | blueswir1 | break;
|
557 | ffd39257 | blueswir1 | case SM501_MISC_TIMING:
|
558 | ffd39257 | blueswir1 | /* TODO : simulate gate control */
|
559 | ffd39257 | blueswir1 | ret = s->misc_timing; |
560 | ffd39257 | blueswir1 | break;
|
561 | ffd39257 | blueswir1 | case SM501_CURRENT_GATE:
|
562 | ffd39257 | blueswir1 | /* TODO : simulate gate control */
|
563 | ffd39257 | blueswir1 | ret = 0x00021807;
|
564 | ffd39257 | blueswir1 | break;
|
565 | ffd39257 | blueswir1 | case SM501_CURRENT_CLOCK:
|
566 | ffd39257 | blueswir1 | ret = 0x2A1A0A09;
|
567 | ffd39257 | blueswir1 | break;
|
568 | ffd39257 | blueswir1 | case SM501_POWER_MODE_CONTROL:
|
569 | ffd39257 | blueswir1 | ret = s->power_mode_control; |
570 | ffd39257 | blueswir1 | break;
|
571 | ffd39257 | blueswir1 | |
572 | ffd39257 | blueswir1 | default:
|
573 | ffd39257 | blueswir1 | printf("sm501 system config : not implemented register read."
|
574 | 8da3ff18 | pbrook | " addr=%x\n", (int)addr); |
575 | ffd39257 | blueswir1 | assert(0);
|
576 | ffd39257 | blueswir1 | } |
577 | ffd39257 | blueswir1 | |
578 | ffd39257 | blueswir1 | return ret;
|
579 | ffd39257 | blueswir1 | } |
580 | ffd39257 | blueswir1 | |
581 | ffd39257 | blueswir1 | static void sm501_system_config_write(void *opaque, |
582 | ffd39257 | blueswir1 | target_phys_addr_t addr, uint32_t value) |
583 | ffd39257 | blueswir1 | { |
584 | ffd39257 | blueswir1 | SM501State * s = (SM501State *)opaque; |
585 | 8da3ff18 | pbrook | SM501_DPRINTF("sm501 system config regs : write addr=%x, val=%x\n",
|
586 | 8da3ff18 | pbrook | addr, value); |
587 | ffd39257 | blueswir1 | |
588 | 8da3ff18 | pbrook | switch(addr) {
|
589 | ffd39257 | blueswir1 | case SM501_SYSTEM_CONTROL:
|
590 | ffd39257 | blueswir1 | s->system_control = value & 0xE300B8F7;
|
591 | ffd39257 | blueswir1 | break;
|
592 | ffd39257 | blueswir1 | case SM501_MISC_CONTROL:
|
593 | ffd39257 | blueswir1 | s->misc_control = value & 0xFF7FFF20;
|
594 | ffd39257 | blueswir1 | break;
|
595 | ffd39257 | blueswir1 | case SM501_GPIO31_0_CONTROL:
|
596 | ffd39257 | blueswir1 | s->gpio_31_0_control = value; |
597 | ffd39257 | blueswir1 | break;
|
598 | ffd39257 | blueswir1 | case SM501_GPIO63_32_CONTROL:
|
599 | ffd39257 | blueswir1 | s->gpio_63_32_control = value; |
600 | ffd39257 | blueswir1 | break;
|
601 | ffd39257 | blueswir1 | case SM501_DRAM_CONTROL:
|
602 | ffd39257 | blueswir1 | s->local_mem_size_index = (value >> 13) & 0x7; |
603 | ffd39257 | blueswir1 | /* rODO : check validity of size change */
|
604 | ffd39257 | blueswir1 | s->dram_control |= value & 0x7FFFFFC3;
|
605 | ffd39257 | blueswir1 | break;
|
606 | ffd39257 | blueswir1 | case SM501_IRQ_MASK:
|
607 | ffd39257 | blueswir1 | s->irq_mask = value; |
608 | ffd39257 | blueswir1 | break;
|
609 | ffd39257 | blueswir1 | case SM501_MISC_TIMING:
|
610 | ffd39257 | blueswir1 | s->misc_timing = value & 0xF31F1FFF;
|
611 | ffd39257 | blueswir1 | break;
|
612 | ffd39257 | blueswir1 | case SM501_POWER_MODE_0_GATE:
|
613 | ffd39257 | blueswir1 | case SM501_POWER_MODE_1_GATE:
|
614 | ffd39257 | blueswir1 | case SM501_POWER_MODE_0_CLOCK:
|
615 | ffd39257 | blueswir1 | case SM501_POWER_MODE_1_CLOCK:
|
616 | ffd39257 | blueswir1 | /* TODO : simulate gate & clock control */
|
617 | ffd39257 | blueswir1 | break;
|
618 | ffd39257 | blueswir1 | case SM501_POWER_MODE_CONTROL:
|
619 | ffd39257 | blueswir1 | s->power_mode_control = value & 0x00000003;
|
620 | ffd39257 | blueswir1 | break;
|
621 | ffd39257 | blueswir1 | |
622 | ffd39257 | blueswir1 | default:
|
623 | ffd39257 | blueswir1 | printf("sm501 system config : not implemented register write."
|
624 | 8da3ff18 | pbrook | " addr=%x, val=%x\n", (int)addr, value); |
625 | ffd39257 | blueswir1 | assert(0);
|
626 | ffd39257 | blueswir1 | } |
627 | ffd39257 | blueswir1 | } |
628 | ffd39257 | blueswir1 | |
629 | ffd39257 | blueswir1 | static CPUReadMemoryFunc *sm501_system_config_readfn[] = {
|
630 | ffd39257 | blueswir1 | NULL,
|
631 | ffd39257 | blueswir1 | NULL,
|
632 | ffd39257 | blueswir1 | &sm501_system_config_read, |
633 | ffd39257 | blueswir1 | }; |
634 | ffd39257 | blueswir1 | |
635 | ffd39257 | blueswir1 | static CPUWriteMemoryFunc *sm501_system_config_writefn[] = {
|
636 | ffd39257 | blueswir1 | NULL,
|
637 | ffd39257 | blueswir1 | NULL,
|
638 | ffd39257 | blueswir1 | &sm501_system_config_write, |
639 | ffd39257 | blueswir1 | }; |
640 | ffd39257 | blueswir1 | |
641 | 486579de | balrog | static uint32_t sm501_palette_read(void *opaque, target_phys_addr_t addr) |
642 | 486579de | balrog | { |
643 | 486579de | balrog | SM501State * s = (SM501State *)opaque; |
644 | 486579de | balrog | SM501_DPRINTF("sm501 palette read addr=%x\n", (int)addr); |
645 | 486579de | balrog | |
646 | 486579de | balrog | /* TODO : consider BYTE/WORD access */
|
647 | 486579de | balrog | /* TODO : consider endian */
|
648 | 486579de | balrog | |
649 | 486579de | balrog | assert(0 <= addr && addr < 0x400 * 3); |
650 | 486579de | balrog | return *(uint32_t*)&s->dc_palette[addr];
|
651 | 486579de | balrog | } |
652 | 486579de | balrog | |
653 | 486579de | balrog | static void sm501_palette_write(void *opaque, |
654 | 486579de | balrog | target_phys_addr_t addr, uint32_t value) |
655 | 486579de | balrog | { |
656 | 486579de | balrog | SM501State * s = (SM501State *)opaque; |
657 | 486579de | balrog | SM501_DPRINTF("sm501 palette write addr=%x, val=%x\n",
|
658 | 486579de | balrog | (int)addr, value);
|
659 | 486579de | balrog | |
660 | 486579de | balrog | /* TODO : consider BYTE/WORD access */
|
661 | 486579de | balrog | /* TODO : consider endian */
|
662 | 486579de | balrog | |
663 | 486579de | balrog | assert(0 <= addr && addr < 0x400 * 3); |
664 | 486579de | balrog | *(uint32_t*)&s->dc_palette[addr] = value; |
665 | 486579de | balrog | } |
666 | 486579de | balrog | |
667 | 8da3ff18 | pbrook | static uint32_t sm501_disp_ctrl_read(void *opaque, target_phys_addr_t addr) |
668 | ffd39257 | blueswir1 | { |
669 | ffd39257 | blueswir1 | SM501State * s = (SM501State *)opaque; |
670 | ffd39257 | blueswir1 | uint32_t ret = 0;
|
671 | 8da3ff18 | pbrook | SM501_DPRINTF("sm501 disp ctrl regs : read addr=%x\n", (int)addr); |
672 | ffd39257 | blueswir1 | |
673 | 8da3ff18 | pbrook | switch(addr) {
|
674 | ffd39257 | blueswir1 | |
675 | ffd39257 | blueswir1 | case SM501_DC_PANEL_CONTROL:
|
676 | ffd39257 | blueswir1 | ret = s->dc_panel_control; |
677 | ffd39257 | blueswir1 | break;
|
678 | ffd39257 | blueswir1 | case SM501_DC_PANEL_PANNING_CONTROL:
|
679 | ffd39257 | blueswir1 | ret = s->dc_panel_panning_control; |
680 | ffd39257 | blueswir1 | break;
|
681 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_ADDR:
|
682 | ffd39257 | blueswir1 | ret = s->dc_panel_fb_addr; |
683 | ffd39257 | blueswir1 | break;
|
684 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_OFFSET:
|
685 | ffd39257 | blueswir1 | ret = s->dc_panel_fb_offset; |
686 | ffd39257 | blueswir1 | break;
|
687 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_WIDTH:
|
688 | ffd39257 | blueswir1 | ret = s->dc_panel_fb_width; |
689 | ffd39257 | blueswir1 | break;
|
690 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_HEIGHT:
|
691 | ffd39257 | blueswir1 | ret = s->dc_panel_fb_height; |
692 | ffd39257 | blueswir1 | break;
|
693 | ffd39257 | blueswir1 | case SM501_DC_PANEL_TL_LOC:
|
694 | ffd39257 | blueswir1 | ret = s->dc_panel_tl_location; |
695 | ffd39257 | blueswir1 | break;
|
696 | ffd39257 | blueswir1 | case SM501_DC_PANEL_BR_LOC:
|
697 | ffd39257 | blueswir1 | ret = s->dc_panel_br_location; |
698 | ffd39257 | blueswir1 | break;
|
699 | ffd39257 | blueswir1 | |
700 | ffd39257 | blueswir1 | case SM501_DC_PANEL_H_TOT:
|
701 | ffd39257 | blueswir1 | ret = s->dc_panel_h_total; |
702 | ffd39257 | blueswir1 | break;
|
703 | ffd39257 | blueswir1 | case SM501_DC_PANEL_H_SYNC:
|
704 | ffd39257 | blueswir1 | ret = s->dc_panel_h_sync; |
705 | ffd39257 | blueswir1 | break;
|
706 | ffd39257 | blueswir1 | case SM501_DC_PANEL_V_TOT:
|
707 | ffd39257 | blueswir1 | ret = s->dc_panel_v_total; |
708 | ffd39257 | blueswir1 | break;
|
709 | ffd39257 | blueswir1 | case SM501_DC_PANEL_V_SYNC:
|
710 | ffd39257 | blueswir1 | ret = s->dc_panel_v_sync; |
711 | ffd39257 | blueswir1 | break;
|
712 | ffd39257 | blueswir1 | |
713 | ffd39257 | blueswir1 | case SM501_DC_CRT_CONTROL:
|
714 | ffd39257 | blueswir1 | ret = s->dc_crt_control; |
715 | ffd39257 | blueswir1 | break;
|
716 | ffd39257 | blueswir1 | case SM501_DC_CRT_FB_ADDR:
|
717 | ffd39257 | blueswir1 | ret = s->dc_crt_fb_addr; |
718 | ffd39257 | blueswir1 | break;
|
719 | ffd39257 | blueswir1 | case SM501_DC_CRT_FB_OFFSET:
|
720 | ffd39257 | blueswir1 | ret = s->dc_crt_fb_offset; |
721 | ffd39257 | blueswir1 | break;
|
722 | ffd39257 | blueswir1 | case SM501_DC_CRT_H_TOT:
|
723 | ffd39257 | blueswir1 | ret = s->dc_crt_h_total; |
724 | ffd39257 | blueswir1 | break;
|
725 | ffd39257 | blueswir1 | case SM501_DC_CRT_H_SYNC:
|
726 | ffd39257 | blueswir1 | ret = s->dc_crt_h_sync; |
727 | ffd39257 | blueswir1 | break;
|
728 | ffd39257 | blueswir1 | case SM501_DC_CRT_V_TOT:
|
729 | ffd39257 | blueswir1 | ret = s->dc_crt_v_total; |
730 | ffd39257 | blueswir1 | break;
|
731 | ffd39257 | blueswir1 | case SM501_DC_CRT_V_SYNC:
|
732 | ffd39257 | blueswir1 | ret = s->dc_crt_v_sync; |
733 | ffd39257 | blueswir1 | break;
|
734 | ffd39257 | blueswir1 | |
735 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_ADDR:
|
736 | ffd39257 | blueswir1 | ret = s->dc_crt_hwc_addr; |
737 | ffd39257 | blueswir1 | break;
|
738 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_LOC:
|
739 | ffd39257 | blueswir1 | ret = s->dc_crt_hwc_addr; |
740 | ffd39257 | blueswir1 | break;
|
741 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_COLOR_1_2:
|
742 | ffd39257 | blueswir1 | ret = s->dc_crt_hwc_addr; |
743 | ffd39257 | blueswir1 | break;
|
744 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_COLOR_3:
|
745 | ffd39257 | blueswir1 | ret = s->dc_crt_hwc_addr; |
746 | ffd39257 | blueswir1 | break;
|
747 | ffd39257 | blueswir1 | |
748 | 486579de | balrog | case SM501_DC_PANEL_PALETTE ... SM501_DC_PANEL_PALETTE + 0x400*3 - 4: |
749 | 486579de | balrog | ret = sm501_palette_read(opaque, addr - SM501_DC_PANEL_PALETTE); |
750 | 486579de | balrog | break;
|
751 | 486579de | balrog | |
752 | ffd39257 | blueswir1 | default:
|
753 | ffd39257 | blueswir1 | printf("sm501 disp ctrl : not implemented register read."
|
754 | 8da3ff18 | pbrook | " addr=%x\n", (int)addr); |
755 | ffd39257 | blueswir1 | assert(0);
|
756 | ffd39257 | blueswir1 | } |
757 | ffd39257 | blueswir1 | |
758 | ffd39257 | blueswir1 | return ret;
|
759 | ffd39257 | blueswir1 | } |
760 | ffd39257 | blueswir1 | |
761 | ffd39257 | blueswir1 | static void sm501_disp_ctrl_write(void *opaque, |
762 | ffd39257 | blueswir1 | target_phys_addr_t addr, |
763 | ffd39257 | blueswir1 | uint32_t value) |
764 | ffd39257 | blueswir1 | { |
765 | ffd39257 | blueswir1 | SM501State * s = (SM501State *)opaque; |
766 | 8da3ff18 | pbrook | SM501_DPRINTF("sm501 disp ctrl regs : write addr=%x, val=%x\n",
|
767 | 8da3ff18 | pbrook | addr, value); |
768 | ffd39257 | blueswir1 | |
769 | 8da3ff18 | pbrook | switch(addr) {
|
770 | ffd39257 | blueswir1 | case SM501_DC_PANEL_CONTROL:
|
771 | ffd39257 | blueswir1 | s->dc_panel_control = value & 0x0FFF73FF;
|
772 | ffd39257 | blueswir1 | break;
|
773 | ffd39257 | blueswir1 | case SM501_DC_PANEL_PANNING_CONTROL:
|
774 | ffd39257 | blueswir1 | s->dc_panel_panning_control = value & 0xFF3FFF3F;
|
775 | ffd39257 | blueswir1 | break;
|
776 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_ADDR:
|
777 | ffd39257 | blueswir1 | s->dc_panel_fb_addr = value & 0x8FFFFFF0;
|
778 | ffd39257 | blueswir1 | break;
|
779 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_OFFSET:
|
780 | ffd39257 | blueswir1 | s->dc_panel_fb_offset = value & 0x3FF03FF0;
|
781 | ffd39257 | blueswir1 | break;
|
782 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_WIDTH:
|
783 | ffd39257 | blueswir1 | s->dc_panel_fb_width = value & 0x0FFF0FFF;
|
784 | ffd39257 | blueswir1 | break;
|
785 | ffd39257 | blueswir1 | case SM501_DC_PANEL_FB_HEIGHT:
|
786 | ffd39257 | blueswir1 | s->dc_panel_fb_height = value & 0x0FFF0FFF;
|
787 | ffd39257 | blueswir1 | break;
|
788 | ffd39257 | blueswir1 | case SM501_DC_PANEL_TL_LOC:
|
789 | ffd39257 | blueswir1 | s->dc_panel_tl_location = value & 0x07FF07FF;
|
790 | ffd39257 | blueswir1 | break;
|
791 | ffd39257 | blueswir1 | case SM501_DC_PANEL_BR_LOC:
|
792 | ffd39257 | blueswir1 | s->dc_panel_br_location = value & 0x07FF07FF;
|
793 | ffd39257 | blueswir1 | break;
|
794 | ffd39257 | blueswir1 | |
795 | ffd39257 | blueswir1 | case SM501_DC_PANEL_H_TOT:
|
796 | ffd39257 | blueswir1 | s->dc_panel_h_total = value & 0x0FFF0FFF;
|
797 | ffd39257 | blueswir1 | break;
|
798 | ffd39257 | blueswir1 | case SM501_DC_PANEL_H_SYNC:
|
799 | ffd39257 | blueswir1 | s->dc_panel_h_sync = value & 0x00FF0FFF;
|
800 | ffd39257 | blueswir1 | break;
|
801 | ffd39257 | blueswir1 | case SM501_DC_PANEL_V_TOT:
|
802 | ffd39257 | blueswir1 | s->dc_panel_v_total = value & 0x0FFF0FFF;
|
803 | ffd39257 | blueswir1 | break;
|
804 | ffd39257 | blueswir1 | case SM501_DC_PANEL_V_SYNC:
|
805 | ffd39257 | blueswir1 | s->dc_panel_v_sync = value & 0x003F0FFF;
|
806 | ffd39257 | blueswir1 | break;
|
807 | ffd39257 | blueswir1 | |
808 | ffd39257 | blueswir1 | case SM501_DC_PANEL_HWC_ADDR:
|
809 | ffd39257 | blueswir1 | s->dc_panel_hwc_addr = value & 0x8FFFFFF0;
|
810 | ffd39257 | blueswir1 | break;
|
811 | ffd39257 | blueswir1 | case SM501_DC_PANEL_HWC_LOC:
|
812 | ffd39257 | blueswir1 | s->dc_panel_hwc_addr = value & 0x0FFF0FFF;
|
813 | ffd39257 | blueswir1 | break;
|
814 | ffd39257 | blueswir1 | case SM501_DC_PANEL_HWC_COLOR_1_2:
|
815 | ffd39257 | blueswir1 | s->dc_panel_hwc_addr = value; |
816 | ffd39257 | blueswir1 | break;
|
817 | ffd39257 | blueswir1 | case SM501_DC_PANEL_HWC_COLOR_3:
|
818 | ffd39257 | blueswir1 | s->dc_panel_hwc_addr = value & 0x0000FFFF;
|
819 | ffd39257 | blueswir1 | break;
|
820 | ffd39257 | blueswir1 | |
821 | ffd39257 | blueswir1 | case SM501_DC_CRT_CONTROL:
|
822 | ffd39257 | blueswir1 | s->dc_crt_control = value & 0x0003FFFF;
|
823 | ffd39257 | blueswir1 | break;
|
824 | ffd39257 | blueswir1 | case SM501_DC_CRT_FB_ADDR:
|
825 | ffd39257 | blueswir1 | s->dc_crt_fb_addr = value & 0x8FFFFFF0;
|
826 | ffd39257 | blueswir1 | break;
|
827 | ffd39257 | blueswir1 | case SM501_DC_CRT_FB_OFFSET:
|
828 | ffd39257 | blueswir1 | s->dc_crt_fb_offset = value & 0x3FF03FF0;
|
829 | ffd39257 | blueswir1 | break;
|
830 | ffd39257 | blueswir1 | case SM501_DC_CRT_H_TOT:
|
831 | ffd39257 | blueswir1 | s->dc_crt_h_total = value & 0x0FFF0FFF;
|
832 | ffd39257 | blueswir1 | break;
|
833 | ffd39257 | blueswir1 | case SM501_DC_CRT_H_SYNC:
|
834 | ffd39257 | blueswir1 | s->dc_crt_h_sync = value & 0x00FF0FFF;
|
835 | ffd39257 | blueswir1 | break;
|
836 | ffd39257 | blueswir1 | case SM501_DC_CRT_V_TOT:
|
837 | ffd39257 | blueswir1 | s->dc_crt_v_total = value & 0x0FFF0FFF;
|
838 | ffd39257 | blueswir1 | break;
|
839 | ffd39257 | blueswir1 | case SM501_DC_CRT_V_SYNC:
|
840 | ffd39257 | blueswir1 | s->dc_crt_v_sync = value & 0x003F0FFF;
|
841 | ffd39257 | blueswir1 | break;
|
842 | ffd39257 | blueswir1 | |
843 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_ADDR:
|
844 | ffd39257 | blueswir1 | s->dc_crt_hwc_addr = value & 0x8FFFFFF0;
|
845 | ffd39257 | blueswir1 | break;
|
846 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_LOC:
|
847 | ffd39257 | blueswir1 | s->dc_crt_hwc_addr = value & 0x0FFF0FFF;
|
848 | ffd39257 | blueswir1 | break;
|
849 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_COLOR_1_2:
|
850 | ffd39257 | blueswir1 | s->dc_crt_hwc_addr = value; |
851 | ffd39257 | blueswir1 | break;
|
852 | ffd39257 | blueswir1 | case SM501_DC_CRT_HWC_COLOR_3:
|
853 | ffd39257 | blueswir1 | s->dc_crt_hwc_addr = value & 0x0000FFFF;
|
854 | ffd39257 | blueswir1 | break;
|
855 | ffd39257 | blueswir1 | |
856 | 486579de | balrog | case SM501_DC_PANEL_PALETTE ... SM501_DC_PANEL_PALETTE + 0x400*3 - 4: |
857 | 486579de | balrog | sm501_palette_write(opaque, addr - SM501_DC_PANEL_PALETTE, value); |
858 | 486579de | balrog | break;
|
859 | 486579de | balrog | |
860 | ffd39257 | blueswir1 | default:
|
861 | ffd39257 | blueswir1 | printf("sm501 disp ctrl : not implemented register write."
|
862 | 8da3ff18 | pbrook | " addr=%x, val=%x\n", (int)addr, value); |
863 | ffd39257 | blueswir1 | assert(0);
|
864 | ffd39257 | blueswir1 | } |
865 | ffd39257 | blueswir1 | } |
866 | ffd39257 | blueswir1 | |
867 | ffd39257 | blueswir1 | static CPUReadMemoryFunc *sm501_disp_ctrl_readfn[] = {
|
868 | ffd39257 | blueswir1 | NULL,
|
869 | ffd39257 | blueswir1 | NULL,
|
870 | ffd39257 | blueswir1 | &sm501_disp_ctrl_read, |
871 | ffd39257 | blueswir1 | }; |
872 | ffd39257 | blueswir1 | |
873 | ffd39257 | blueswir1 | static CPUWriteMemoryFunc *sm501_disp_ctrl_writefn[] = {
|
874 | ffd39257 | blueswir1 | NULL,
|
875 | ffd39257 | blueswir1 | NULL,
|
876 | ffd39257 | blueswir1 | &sm501_disp_ctrl_write, |
877 | ffd39257 | blueswir1 | }; |
878 | ffd39257 | blueswir1 | |
879 | ffd39257 | blueswir1 | /* draw line functions for all console modes */
|
880 | ffd39257 | blueswir1 | |
881 | ffd39257 | blueswir1 | #include "pixel_ops.h" |
882 | ffd39257 | blueswir1 | |
883 | ffd39257 | blueswir1 | typedef void draw_line_func(uint8_t *d, const uint8_t *s, |
884 | ffd39257 | blueswir1 | int width, const uint32_t *pal); |
885 | ffd39257 | blueswir1 | |
886 | ffd39257 | blueswir1 | #define DEPTH 8 |
887 | ffd39257 | blueswir1 | #include "sm501_template.h" |
888 | ffd39257 | blueswir1 | |
889 | ffd39257 | blueswir1 | #define DEPTH 15 |
890 | ffd39257 | blueswir1 | #include "sm501_template.h" |
891 | ffd39257 | blueswir1 | |
892 | ffd39257 | blueswir1 | #define BGR_FORMAT
|
893 | ffd39257 | blueswir1 | #define DEPTH 15 |
894 | ffd39257 | blueswir1 | #include "sm501_template.h" |
895 | ffd39257 | blueswir1 | |
896 | ffd39257 | blueswir1 | #define DEPTH 16 |
897 | ffd39257 | blueswir1 | #include "sm501_template.h" |
898 | ffd39257 | blueswir1 | |
899 | ffd39257 | blueswir1 | #define BGR_FORMAT
|
900 | ffd39257 | blueswir1 | #define DEPTH 16 |
901 | ffd39257 | blueswir1 | #include "sm501_template.h" |
902 | ffd39257 | blueswir1 | |
903 | ffd39257 | blueswir1 | #define DEPTH 32 |
904 | ffd39257 | blueswir1 | #include "sm501_template.h" |
905 | ffd39257 | blueswir1 | |
906 | ffd39257 | blueswir1 | #define BGR_FORMAT
|
907 | ffd39257 | blueswir1 | #define DEPTH 32 |
908 | ffd39257 | blueswir1 | #include "sm501_template.h" |
909 | ffd39257 | blueswir1 | |
910 | ffd39257 | blueswir1 | static draw_line_func * draw_line8_funcs[] = {
|
911 | ffd39257 | blueswir1 | draw_line8_8, |
912 | ffd39257 | blueswir1 | draw_line8_15, |
913 | ffd39257 | blueswir1 | draw_line8_16, |
914 | ffd39257 | blueswir1 | draw_line8_32, |
915 | ffd39257 | blueswir1 | draw_line8_32bgr, |
916 | ffd39257 | blueswir1 | draw_line8_15bgr, |
917 | ffd39257 | blueswir1 | draw_line8_16bgr, |
918 | ffd39257 | blueswir1 | }; |
919 | ffd39257 | blueswir1 | |
920 | ffd39257 | blueswir1 | static draw_line_func * draw_line16_funcs[] = {
|
921 | ffd39257 | blueswir1 | draw_line16_8, |
922 | ffd39257 | blueswir1 | draw_line16_15, |
923 | ffd39257 | blueswir1 | draw_line16_16, |
924 | ffd39257 | blueswir1 | draw_line16_32, |
925 | ffd39257 | blueswir1 | draw_line16_32bgr, |
926 | ffd39257 | blueswir1 | draw_line16_15bgr, |
927 | ffd39257 | blueswir1 | draw_line16_16bgr, |
928 | ffd39257 | blueswir1 | }; |
929 | ffd39257 | blueswir1 | |
930 | ffd39257 | blueswir1 | static draw_line_func * draw_line32_funcs[] = {
|
931 | ffd39257 | blueswir1 | draw_line32_8, |
932 | ffd39257 | blueswir1 | draw_line32_15, |
933 | ffd39257 | blueswir1 | draw_line32_16, |
934 | ffd39257 | blueswir1 | draw_line32_32, |
935 | ffd39257 | blueswir1 | draw_line32_32bgr, |
936 | ffd39257 | blueswir1 | draw_line32_15bgr, |
937 | ffd39257 | blueswir1 | draw_line32_16bgr, |
938 | ffd39257 | blueswir1 | }; |
939 | ffd39257 | blueswir1 | |
940 | ffd39257 | blueswir1 | static inline int get_depth_index(DisplayState *s) |
941 | ffd39257 | blueswir1 | { |
942 | 8927bcfd | aliguori | switch(ds_get_bits_per_pixel(s)) {
|
943 | ffd39257 | blueswir1 | default:
|
944 | ffd39257 | blueswir1 | case 8: |
945 | ffd39257 | blueswir1 | return 0; |
946 | ffd39257 | blueswir1 | case 15: |
947 | 8927bcfd | aliguori | return 1; |
948 | ffd39257 | blueswir1 | case 16: |
949 | 8927bcfd | aliguori | return 2; |
950 | ffd39257 | blueswir1 | case 32: |
951 | 7b5d76da | aliguori | if (is_surface_bgr(s->surface))
|
952 | 7b5d76da | aliguori | return 4; |
953 | 7b5d76da | aliguori | else
|
954 | 7b5d76da | aliguori | return 3; |
955 | ffd39257 | blueswir1 | } |
956 | ffd39257 | blueswir1 | } |
957 | ffd39257 | blueswir1 | |
958 | ffd39257 | blueswir1 | static void sm501_draw_crt(SM501State * s) |
959 | ffd39257 | blueswir1 | { |
960 | ffd39257 | blueswir1 | int y;
|
961 | ffd39257 | blueswir1 | int width = (s->dc_crt_h_total & 0x00000FFF) + 1; |
962 | ffd39257 | blueswir1 | int height = (s->dc_crt_v_total & 0x00000FFF) + 1; |
963 | ffd39257 | blueswir1 | |
964 | ffd39257 | blueswir1 | uint8_t * src = s->local_mem; |
965 | ffd39257 | blueswir1 | int src_bpp = 0; |
966 | 8927bcfd | aliguori | int dst_bpp = ds_get_bytes_per_pixel(s->ds) + (ds_get_bits_per_pixel(s->ds) % 8 ? 1 : 0); |
967 | ffd39257 | blueswir1 | uint32_t * palette = (uint32_t *)&s->dc_palette[SM501_DC_CRT_PALETTE |
968 | ffd39257 | blueswir1 | - SM501_DC_PANEL_PALETTE]; |
969 | ffd39257 | blueswir1 | int ds_depth_index = get_depth_index(s->ds);
|
970 | ffd39257 | blueswir1 | draw_line_func * draw_line = NULL;
|
971 | ffd39257 | blueswir1 | int full_update = 0; |
972 | ffd39257 | blueswir1 | int y_start = -1; |
973 | ffd39257 | blueswir1 | int page_min = 0x7fffffff; |
974 | ffd39257 | blueswir1 | int page_max = -1; |
975 | 44654490 | pbrook | ram_addr_t offset = s->local_mem_offset; |
976 | ffd39257 | blueswir1 | |
977 | ffd39257 | blueswir1 | /* choose draw_line function */
|
978 | ffd39257 | blueswir1 | switch (s->dc_crt_control & 3) { |
979 | ffd39257 | blueswir1 | case SM501_DC_CRT_CONTROL_8BPP:
|
980 | ffd39257 | blueswir1 | src_bpp = 1;
|
981 | ffd39257 | blueswir1 | draw_line = draw_line8_funcs[ds_depth_index]; |
982 | ffd39257 | blueswir1 | break;
|
983 | ffd39257 | blueswir1 | case SM501_DC_CRT_CONTROL_16BPP:
|
984 | ffd39257 | blueswir1 | src_bpp = 2;
|
985 | ffd39257 | blueswir1 | draw_line = draw_line16_funcs[ds_depth_index]; |
986 | ffd39257 | blueswir1 | break;
|
987 | ffd39257 | blueswir1 | case SM501_DC_CRT_CONTROL_32BPP:
|
988 | ffd39257 | blueswir1 | src_bpp = 4;
|
989 | ffd39257 | blueswir1 | draw_line = draw_line32_funcs[ds_depth_index]; |
990 | ffd39257 | blueswir1 | break;
|
991 | ffd39257 | blueswir1 | default:
|
992 | ffd39257 | blueswir1 | printf("sm501 draw crt : invalid DC_CRT_CONTROL=%x.\n",
|
993 | ffd39257 | blueswir1 | s->dc_crt_control); |
994 | ffd39257 | blueswir1 | assert(0);
|
995 | ffd39257 | blueswir1 | break;
|
996 | ffd39257 | blueswir1 | } |
997 | ffd39257 | blueswir1 | |
998 | ffd39257 | blueswir1 | /* adjust console size */
|
999 | ffd39257 | blueswir1 | if (s->last_width != width || s->last_height != height) {
|
1000 | 3023f332 | aliguori | qemu_console_resize(s->ds, width, height); |
1001 | ffd39257 | blueswir1 | s->last_width = width; |
1002 | ffd39257 | blueswir1 | s->last_height = height; |
1003 | ffd39257 | blueswir1 | full_update = 1;
|
1004 | ffd39257 | blueswir1 | } |
1005 | ffd39257 | blueswir1 | |
1006 | ffd39257 | blueswir1 | /* draw each line according to conditions */
|
1007 | ffd39257 | blueswir1 | for (y = 0; y < height; y++) { |
1008 | ffd39257 | blueswir1 | int update = full_update;
|
1009 | 44654490 | pbrook | ram_addr_t page0 = offset & TARGET_PAGE_MASK; |
1010 | 44654490 | pbrook | ram_addr_t page1 = (offset + width * src_bpp - 1) & TARGET_PAGE_MASK;
|
1011 | 44654490 | pbrook | ram_addr_t page; |
1012 | ffd39257 | blueswir1 | |
1013 | ffd39257 | blueswir1 | /* check dirty flags for each line */
|
1014 | ffd39257 | blueswir1 | for (page = page0; page <= page1; page += TARGET_PAGE_SIZE)
|
1015 | ffd39257 | blueswir1 | if (cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG))
|
1016 | ffd39257 | blueswir1 | update = 1;
|
1017 | ffd39257 | blueswir1 | |
1018 | ffd39257 | blueswir1 | /* draw line and change status */
|
1019 | ffd39257 | blueswir1 | if (update) {
|
1020 | 8927bcfd | aliguori | draw_line(&(ds_get_data(s->ds)[y * width * dst_bpp]), src, width, palette); |
1021 | ffd39257 | blueswir1 | if (y_start < 0) |
1022 | ffd39257 | blueswir1 | y_start = y; |
1023 | ffd39257 | blueswir1 | if (page0 < page_min)
|
1024 | ffd39257 | blueswir1 | page_min = page0; |
1025 | ffd39257 | blueswir1 | if (page1 > page_max)
|
1026 | ffd39257 | blueswir1 | page_max = page1; |
1027 | ffd39257 | blueswir1 | } else {
|
1028 | ffd39257 | blueswir1 | if (y_start >= 0) { |
1029 | ffd39257 | blueswir1 | /* flush to display */
|
1030 | ffd39257 | blueswir1 | dpy_update(s->ds, 0, y_start, width, y - y_start);
|
1031 | ffd39257 | blueswir1 | y_start = -1;
|
1032 | ffd39257 | blueswir1 | } |
1033 | ffd39257 | blueswir1 | } |
1034 | ffd39257 | blueswir1 | |
1035 | ffd39257 | blueswir1 | src += width * src_bpp; |
1036 | 44654490 | pbrook | offset += width * src_bpp; |
1037 | ffd39257 | blueswir1 | } |
1038 | ffd39257 | blueswir1 | |
1039 | ffd39257 | blueswir1 | /* complete flush to display */
|
1040 | ffd39257 | blueswir1 | if (y_start >= 0) |
1041 | ffd39257 | blueswir1 | dpy_update(s->ds, 0, y_start, width, y - y_start);
|
1042 | ffd39257 | blueswir1 | |
1043 | ffd39257 | blueswir1 | /* clear dirty flags */
|
1044 | ffd39257 | blueswir1 | if (page_max != -1) |
1045 | ffd39257 | blueswir1 | cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE, |
1046 | ffd39257 | blueswir1 | VGA_DIRTY_FLAG); |
1047 | ffd39257 | blueswir1 | } |
1048 | ffd39257 | blueswir1 | |
1049 | ffd39257 | blueswir1 | static void sm501_update_display(void *opaque) |
1050 | ffd39257 | blueswir1 | { |
1051 | ffd39257 | blueswir1 | SM501State * s = (SM501State *)opaque; |
1052 | ffd39257 | blueswir1 | |
1053 | ffd39257 | blueswir1 | if (s->dc_crt_control & SM501_DC_CRT_CONTROL_ENABLE)
|
1054 | ffd39257 | blueswir1 | sm501_draw_crt(s); |
1055 | ffd39257 | blueswir1 | } |
1056 | ffd39257 | blueswir1 | |
1057 | ac611340 | aurel32 | void sm501_init(uint32_t base, uint32_t local_mem_bytes, qemu_irq irq,
|
1058 | ac611340 | aurel32 | CharDriverState *chr) |
1059 | ffd39257 | blueswir1 | { |
1060 | ffd39257 | blueswir1 | SM501State * s; |
1061 | ffd39257 | blueswir1 | int sm501_system_config_index;
|
1062 | ffd39257 | blueswir1 | int sm501_disp_ctrl_index;
|
1063 | ffd39257 | blueswir1 | |
1064 | ffd39257 | blueswir1 | /* allocate management data region */
|
1065 | ffd39257 | blueswir1 | s = (SM501State *)qemu_mallocz(sizeof(SM501State));
|
1066 | ffd39257 | blueswir1 | s->base = base; |
1067 | ffd39257 | blueswir1 | s->local_mem_size_index |
1068 | ffd39257 | blueswir1 | = get_local_mem_size_index(local_mem_bytes); |
1069 | ffd39257 | blueswir1 | SM501_DPRINTF("local mem size=%x. index=%d\n", get_local_mem_size(s),
|
1070 | ffd39257 | blueswir1 | s->local_mem_size_index); |
1071 | ffd39257 | blueswir1 | s->system_control = 0x00100000;
|
1072 | ffd39257 | blueswir1 | s->misc_control = 0x00001000; /* assumes SH, active=low */ |
1073 | ffd39257 | blueswir1 | s->dc_panel_control = 0x00010000;
|
1074 | ffd39257 | blueswir1 | s->dc_crt_control = 0x00010000;
|
1075 | ffd39257 | blueswir1 | |
1076 | ffd39257 | blueswir1 | /* allocate local memory */
|
1077 | 44654490 | pbrook | s->local_mem_offset = qemu_ram_alloc(local_mem_bytes); |
1078 | 44654490 | pbrook | s->local_mem = qemu_get_ram_ptr(s->local_mem_offset); |
1079 | 44654490 | pbrook | cpu_register_physical_memory(base, local_mem_bytes, s->local_mem_offset); |
1080 | ffd39257 | blueswir1 | |
1081 | ffd39257 | blueswir1 | /* map mmio */
|
1082 | ffd39257 | blueswir1 | sm501_system_config_index |
1083 | 1eed09cb | Avi Kivity | = cpu_register_io_memory(sm501_system_config_readfn, |
1084 | ffd39257 | blueswir1 | sm501_system_config_writefn, s); |
1085 | ffd39257 | blueswir1 | cpu_register_physical_memory(base + MMIO_BASE_OFFSET, |
1086 | ffd39257 | blueswir1 | 0x6c, sm501_system_config_index);
|
1087 | 1eed09cb | Avi Kivity | sm501_disp_ctrl_index = cpu_register_io_memory(sm501_disp_ctrl_readfn, |
1088 | ffd39257 | blueswir1 | sm501_disp_ctrl_writefn, s); |
1089 | ffd39257 | blueswir1 | cpu_register_physical_memory(base + MMIO_BASE_OFFSET + SM501_DC, |
1090 | 486579de | balrog | 0x1000, sm501_disp_ctrl_index);
|
1091 | ffd39257 | blueswir1 | |
1092 | ac611340 | aurel32 | /* bridge to usb host emulation module */
|
1093 | ac611340 | aurel32 | usb_ohci_init_sm501(base + MMIO_BASE_OFFSET + SM501_USB_HOST, base, |
1094 | ac611340 | aurel32 | 2, -1, irq); |
1095 | ac611340 | aurel32 | |
1096 | ffd39257 | blueswir1 | /* bridge to serial emulation module */
|
1097 | ffd39257 | blueswir1 | if (chr)
|
1098 | ffd39257 | blueswir1 | serial_mm_init(base + MMIO_BASE_OFFSET + SM501_UART0, 2,
|
1099 | ffd39257 | blueswir1 | 0, /* TODO : chain irq to IRL */ |
1100 | ffd39257 | blueswir1 | 115200, chr, 1); |
1101 | ffd39257 | blueswir1 | |
1102 | ffd39257 | blueswir1 | /* create qemu graphic console */
|
1103 | 3023f332 | aliguori | s->ds = graphic_console_init(sm501_update_display, NULL,
|
1104 | 3023f332 | aliguori | NULL, NULL, s); |
1105 | ffd39257 | blueswir1 | } |