4 * Copyright (c) 2008 Shin-ichiro KAWASAKI
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 #include "qdev-addr.h"
35 * - Minimum implementation for Linux console : mmio regs and CRT layer.
36 * - Always updates full screen.
40 * - Hardware cursor support
41 * - Touch panel support
44 * - Performance tuning
48 //#define DEBUG_BITBLT
51 #define SM501_DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
53 #define SM501_DPRINTF(fmt, ...) do {} while(0)
57 #define MMIO_BASE_OFFSET 0x3e00000
59 /* SM501 register definitions taken from "linux/include/linux/sm501-regs.h" */
61 /* System Configuration area */
62 /* System config base */
63 #define SM501_SYS_CONFIG (0x000000)
66 #define SM501_SYSTEM_CONTROL (0x000000)
68 #define SM501_SYSCTRL_PANEL_TRISTATE (1<<0)
69 #define SM501_SYSCTRL_MEM_TRISTATE (1<<1)
70 #define SM501_SYSCTRL_CRT_TRISTATE (1<<2)
72 #define SM501_SYSCTRL_PCI_SLAVE_BURST_MASK (3<<4)
73 #define SM501_SYSCTRL_PCI_SLAVE_BURST_1 (0<<4)
74 #define SM501_SYSCTRL_PCI_SLAVE_BURST_2 (1<<4)
75 #define SM501_SYSCTRL_PCI_SLAVE_BURST_4 (2<<4)
76 #define SM501_SYSCTRL_PCI_SLAVE_BURST_8 (3<<4)
78 #define SM501_SYSCTRL_PCI_CLOCK_RUN_EN (1<<6)
79 #define SM501_SYSCTRL_PCI_RETRY_DISABLE (1<<7)
80 #define SM501_SYSCTRL_PCI_SUBSYS_LOCK (1<<11)
81 #define SM501_SYSCTRL_PCI_BURST_READ_EN (1<<15)
83 /* miscellaneous control */
85 #define SM501_MISC_CONTROL (0x000004)
87 #define SM501_MISC_BUS_SH (0x0)
88 #define SM501_MISC_BUS_PCI (0x1)
89 #define SM501_MISC_BUS_XSCALE (0x2)
90 #define SM501_MISC_BUS_NEC (0x6)
91 #define SM501_MISC_BUS_MASK (0x7)
93 #define SM501_MISC_VR_62MB (1<<3)
94 #define SM501_MISC_CDR_RESET (1<<7)
95 #define SM501_MISC_USB_LB (1<<8)
96 #define SM501_MISC_USB_SLAVE (1<<9)
97 #define SM501_MISC_BL_1 (1<<10)
98 #define SM501_MISC_MC (1<<11)
99 #define SM501_MISC_DAC_POWER (1<<12)
100 #define SM501_MISC_IRQ_INVERT (1<<16)
101 #define SM501_MISC_SH (1<<17)
103 #define SM501_MISC_HOLD_EMPTY (0<<18)
104 #define SM501_MISC_HOLD_8 (1<<18)
105 #define SM501_MISC_HOLD_16 (2<<18)
106 #define SM501_MISC_HOLD_24 (3<<18)
107 #define SM501_MISC_HOLD_32 (4<<18)
108 #define SM501_MISC_HOLD_MASK (7<<18)
110 #define SM501_MISC_FREQ_12 (1<<24)
111 #define SM501_MISC_PNL_24BIT (1<<25)
112 #define SM501_MISC_8051_LE (1<<26)
116 #define SM501_GPIO31_0_CONTROL (0x000008)
117 #define SM501_GPIO63_32_CONTROL (0x00000C)
118 #define SM501_DRAM_CONTROL (0x000010)
121 #define SM501_ARBTRTN_CONTROL (0x000014)
124 #define SM501_COMMAND_LIST_STATUS (0x000024)
126 /* interrupt debug */
127 #define SM501_RAW_IRQ_STATUS (0x000028)
128 #define SM501_RAW_IRQ_CLEAR (0x000028)
129 #define SM501_IRQ_STATUS (0x00002C)
130 #define SM501_IRQ_MASK (0x000030)
131 #define SM501_DEBUG_CONTROL (0x000034)
133 /* power management */
134 #define SM501_POWERMODE_P2X_SRC (1<<29)
135 #define SM501_POWERMODE_V2X_SRC (1<<20)
136 #define SM501_POWERMODE_M_SRC (1<<12)
137 #define SM501_POWERMODE_M1_SRC (1<<4)
139 #define SM501_CURRENT_GATE (0x000038)
140 #define SM501_CURRENT_CLOCK (0x00003C)
141 #define SM501_POWER_MODE_0_GATE (0x000040)
142 #define SM501_POWER_MODE_0_CLOCK (0x000044)
143 #define SM501_POWER_MODE_1_GATE (0x000048)
144 #define SM501_POWER_MODE_1_CLOCK (0x00004C)
145 #define SM501_SLEEP_MODE_GATE (0x000050)
146 #define SM501_POWER_MODE_CONTROL (0x000054)
148 /* power gates for units within the 501 */
149 #define SM501_GATE_HOST (0)
150 #define SM501_GATE_MEMORY (1)
151 #define SM501_GATE_DISPLAY (2)
152 #define SM501_GATE_2D_ENGINE (3)
153 #define SM501_GATE_CSC (4)
154 #define SM501_GATE_ZVPORT (5)
155 #define SM501_GATE_GPIO (6)
156 #define SM501_GATE_UART0 (7)
157 #define SM501_GATE_UART1 (8)
158 #define SM501_GATE_SSP (10)
159 #define SM501_GATE_USB_HOST (11)
160 #define SM501_GATE_USB_GADGET (12)
161 #define SM501_GATE_UCONTROLLER (17)
162 #define SM501_GATE_AC97 (18)
165 #define SM501_CLOCK_P2XCLK (24)
167 #define SM501_CLOCK_V2XCLK (16)
169 #define SM501_CLOCK_MCLK (8)
170 /* SDRAM controller clock */
171 #define SM501_CLOCK_M1XCLK (0)
174 #define SM501_PCI_MASTER_BASE (0x000058)
175 #define SM501_ENDIAN_CONTROL (0x00005C)
176 #define SM501_DEVICEID (0x000060)
179 #define SM501_DEVICEID_SM501 (0x05010000)
180 #define SM501_DEVICEID_IDMASK (0xffff0000)
181 #define SM501_DEVICEID_REVMASK (0x000000ff)
183 #define SM501_PLLCLOCK_COUNT (0x000064)
184 #define SM501_MISC_TIMING (0x000068)
185 #define SM501_CURRENT_SDRAM_CLOCK (0x00006C)
187 #define SM501_PROGRAMMABLE_PLL_CONTROL (0x000074)
190 #define SM501_GPIO (0x010000)
191 #define SM501_GPIO_DATA_LOW (0x00)
192 #define SM501_GPIO_DATA_HIGH (0x04)
193 #define SM501_GPIO_DDR_LOW (0x08)
194 #define SM501_GPIO_DDR_HIGH (0x0C)
195 #define SM501_GPIO_IRQ_SETUP (0x10)
196 #define SM501_GPIO_IRQ_STATUS (0x14)
197 #define SM501_GPIO_IRQ_RESET (0x14)
199 /* I2C controller base */
200 #define SM501_I2C (0x010040)
201 #define SM501_I2C_BYTE_COUNT (0x00)
202 #define SM501_I2C_CONTROL (0x01)
203 #define SM501_I2C_STATUS (0x02)
204 #define SM501_I2C_RESET (0x02)
205 #define SM501_I2C_SLAVE_ADDRESS (0x03)
206 #define SM501_I2C_DATA (0x04)
209 #define SM501_SSP (0x020000)
212 #define SM501_UART0 (0x030000)
215 #define SM501_UART1 (0x030020)
217 /* USB host port base */
218 #define SM501_USB_HOST (0x040000)
220 /* USB slave/gadget base */
221 #define SM501_USB_GADGET (0x060000)
223 /* USB slave/gadget data port base */
224 #define SM501_USB_GADGET_DATA (0x070000)
226 /* Display controller/video engine base */
227 #define SM501_DC (0x080000)
229 /* common defines for the SM501 address registers */
230 #define SM501_ADDR_FLIP (1<<31)
231 #define SM501_ADDR_EXT (1<<27)
232 #define SM501_ADDR_CS1 (1<<26)
233 #define SM501_ADDR_MASK (0x3f << 26)
235 #define SM501_FIFO_MASK (0x3 << 16)
236 #define SM501_FIFO_1 (0x0 << 16)
237 #define SM501_FIFO_3 (0x1 << 16)
238 #define SM501_FIFO_7 (0x2 << 16)
239 #define SM501_FIFO_11 (0x3 << 16)
241 /* common registers for panel and the crt */
242 #define SM501_OFF_DC_H_TOT (0x000)
243 #define SM501_OFF_DC_V_TOT (0x008)
244 #define SM501_OFF_DC_H_SYNC (0x004)
245 #define SM501_OFF_DC_V_SYNC (0x00C)
247 #define SM501_DC_PANEL_CONTROL (0x000)
249 #define SM501_DC_PANEL_CONTROL_FPEN (1<<27)
250 #define SM501_DC_PANEL_CONTROL_BIAS (1<<26)
251 #define SM501_DC_PANEL_CONTROL_DATA (1<<25)
252 #define SM501_DC_PANEL_CONTROL_VDD (1<<24)
253 #define SM501_DC_PANEL_CONTROL_DP (1<<23)
255 #define SM501_DC_PANEL_CONTROL_TFT_888 (0<<21)
256 #define SM501_DC_PANEL_CONTROL_TFT_333 (1<<21)
257 #define SM501_DC_PANEL_CONTROL_TFT_444 (2<<21)
259 #define SM501_DC_PANEL_CONTROL_DE (1<<20)
261 #define SM501_DC_PANEL_CONTROL_LCD_TFT (0<<18)
262 #define SM501_DC_PANEL_CONTROL_LCD_STN8 (1<<18)
263 #define SM501_DC_PANEL_CONTROL_LCD_STN12 (2<<18)
265 #define SM501_DC_PANEL_CONTROL_CP (1<<14)
266 #define SM501_DC_PANEL_CONTROL_VSP (1<<13)
267 #define SM501_DC_PANEL_CONTROL_HSP (1<<12)
268 #define SM501_DC_PANEL_CONTROL_CK (1<<9)
269 #define SM501_DC_PANEL_CONTROL_TE (1<<8)
270 #define SM501_DC_PANEL_CONTROL_VPD (1<<7)
271 #define SM501_DC_PANEL_CONTROL_VP (1<<6)
272 #define SM501_DC_PANEL_CONTROL_HPD (1<<5)
273 #define SM501_DC_PANEL_CONTROL_HP (1<<4)
274 #define SM501_DC_PANEL_CONTROL_GAMMA (1<<3)
275 #define SM501_DC_PANEL_CONTROL_EN (1<<2)
277 #define SM501_DC_PANEL_CONTROL_8BPP (0<<0)
278 #define SM501_DC_PANEL_CONTROL_16BPP (1<<0)
279 #define SM501_DC_PANEL_CONTROL_32BPP (2<<0)
282 #define SM501_DC_PANEL_PANNING_CONTROL (0x004)
283 #define SM501_DC_PANEL_COLOR_KEY (0x008)
284 #define SM501_DC_PANEL_FB_ADDR (0x00C)
285 #define SM501_DC_PANEL_FB_OFFSET (0x010)
286 #define SM501_DC_PANEL_FB_WIDTH (0x014)
287 #define SM501_DC_PANEL_FB_HEIGHT (0x018)
288 #define SM501_DC_PANEL_TL_LOC (0x01C)
289 #define SM501_DC_PANEL_BR_LOC (0x020)
290 #define SM501_DC_PANEL_H_TOT (0x024)
291 #define SM501_DC_PANEL_H_SYNC (0x028)
292 #define SM501_DC_PANEL_V_TOT (0x02C)
293 #define SM501_DC_PANEL_V_SYNC (0x030)
294 #define SM501_DC_PANEL_CUR_LINE (0x034)
296 #define SM501_DC_VIDEO_CONTROL (0x040)
297 #define SM501_DC_VIDEO_FB0_ADDR (0x044)
298 #define SM501_DC_VIDEO_FB_WIDTH (0x048)
299 #define SM501_DC_VIDEO_FB0_LAST_ADDR (0x04C)
300 #define SM501_DC_VIDEO_TL_LOC (0x050)
301 #define SM501_DC_VIDEO_BR_LOC (0x054)
302 #define SM501_DC_VIDEO_SCALE (0x058)
303 #define SM501_DC_VIDEO_INIT_SCALE (0x05C)
304 #define SM501_DC_VIDEO_YUV_CONSTANTS (0x060)
305 #define SM501_DC_VIDEO_FB1_ADDR (0x064)
306 #define SM501_DC_VIDEO_FB1_LAST_ADDR (0x068)
308 #define SM501_DC_VIDEO_ALPHA_CONTROL (0x080)
309 #define SM501_DC_VIDEO_ALPHA_FB_ADDR (0x084)
310 #define SM501_DC_VIDEO_ALPHA_FB_OFFSET (0x088)
311 #define SM501_DC_VIDEO_ALPHA_FB_LAST_ADDR (0x08C)
312 #define SM501_DC_VIDEO_ALPHA_TL_LOC (0x090)
313 #define SM501_DC_VIDEO_ALPHA_BR_LOC (0x094)
314 #define SM501_DC_VIDEO_ALPHA_SCALE (0x098)
315 #define SM501_DC_VIDEO_ALPHA_INIT_SCALE (0x09C)
316 #define SM501_DC_VIDEO_ALPHA_CHROMA_KEY (0x0A0)
317 #define SM501_DC_VIDEO_ALPHA_COLOR_LOOKUP (0x0A4)
319 #define SM501_DC_PANEL_HWC_BASE (0x0F0)
320 #define SM501_DC_PANEL_HWC_ADDR (0x0F0)
321 #define SM501_DC_PANEL_HWC_LOC (0x0F4)
322 #define SM501_DC_PANEL_HWC_COLOR_1_2 (0x0F8)
323 #define SM501_DC_PANEL_HWC_COLOR_3 (0x0FC)
325 #define SM501_HWC_EN (1<<31)
327 #define SM501_OFF_HWC_ADDR (0x00)
328 #define SM501_OFF_HWC_LOC (0x04)
329 #define SM501_OFF_HWC_COLOR_1_2 (0x08)
330 #define SM501_OFF_HWC_COLOR_3 (0x0C)
332 #define SM501_DC_ALPHA_CONTROL (0x100)
333 #define SM501_DC_ALPHA_FB_ADDR (0x104)
334 #define SM501_DC_ALPHA_FB_OFFSET (0x108)
335 #define SM501_DC_ALPHA_TL_LOC (0x10C)
336 #define SM501_DC_ALPHA_BR_LOC (0x110)
337 #define SM501_DC_ALPHA_CHROMA_KEY (0x114)
338 #define SM501_DC_ALPHA_COLOR_LOOKUP (0x118)
340 #define SM501_DC_CRT_CONTROL (0x200)
342 #define SM501_DC_CRT_CONTROL_TVP (1<<15)
343 #define SM501_DC_CRT_CONTROL_CP (1<<14)
344 #define SM501_DC_CRT_CONTROL_VSP (1<<13)
345 #define SM501_DC_CRT_CONTROL_HSP (1<<12)
346 #define SM501_DC_CRT_CONTROL_VS (1<<11)
347 #define SM501_DC_CRT_CONTROL_BLANK (1<<10)
348 #define SM501_DC_CRT_CONTROL_SEL (1<<9)
349 #define SM501_DC_CRT_CONTROL_TE (1<<8)
350 #define SM501_DC_CRT_CONTROL_PIXEL_MASK (0xF << 4)
351 #define SM501_DC_CRT_CONTROL_GAMMA (1<<3)
352 #define SM501_DC_CRT_CONTROL_ENABLE (1<<2)
354 #define SM501_DC_CRT_CONTROL_8BPP (0<<0)
355 #define SM501_DC_CRT_CONTROL_16BPP (1<<0)
356 #define SM501_DC_CRT_CONTROL_32BPP (2<<0)
358 #define SM501_DC_CRT_FB_ADDR (0x204)
359 #define SM501_DC_CRT_FB_OFFSET (0x208)
360 #define SM501_DC_CRT_H_TOT (0x20C)
361 #define SM501_DC_CRT_H_SYNC (0x210)
362 #define SM501_DC_CRT_V_TOT (0x214)
363 #define SM501_DC_CRT_V_SYNC (0x218)
364 #define SM501_DC_CRT_SIGNATURE_ANALYZER (0x21C)
365 #define SM501_DC_CRT_CUR_LINE (0x220)
366 #define SM501_DC_CRT_MONITOR_DETECT (0x224)
368 #define SM501_DC_CRT_HWC_BASE (0x230)
369 #define SM501_DC_CRT_HWC_ADDR (0x230)
370 #define SM501_DC_CRT_HWC_LOC (0x234)
371 #define SM501_DC_CRT_HWC_COLOR_1_2 (0x238)
372 #define SM501_DC_CRT_HWC_COLOR_3 (0x23C)
374 #define SM501_DC_PANEL_PALETTE (0x400)
376 #define SM501_DC_VIDEO_PALETTE (0x800)
378 #define SM501_DC_CRT_PALETTE (0xC00)
380 /* Zoom Video port base */
381 #define SM501_ZVPORT (0x090000)
384 #define SM501_AC97 (0x0A0000)
386 /* 8051 micro controller base */
387 #define SM501_UCONTROLLER (0x0B0000)
389 /* 8051 micro controller SRAM base */
390 #define SM501_UCONTROLLER_SRAM (0x0C0000)
393 #define SM501_DMA (0x0D0000)
396 #define SM501_2D_ENGINE (0x100000)
397 #define SM501_2D_SOURCE (0x00)
398 #define SM501_2D_DESTINATION (0x04)
399 #define SM501_2D_DIMENSION (0x08)
400 #define SM501_2D_CONTROL (0x0C)
401 #define SM501_2D_PITCH (0x10)
402 #define SM501_2D_FOREGROUND (0x14)
403 #define SM501_2D_BACKGROUND (0x18)
404 #define SM501_2D_STRETCH (0x1C)
405 #define SM501_2D_COLOR_COMPARE (0x20)
406 #define SM501_2D_COLOR_COMPARE_MASK (0x24)
407 #define SM501_2D_MASK (0x28)
408 #define SM501_2D_CLIP_TL (0x2C)
409 #define SM501_2D_CLIP_BR (0x30)
410 #define SM501_2D_MONO_PATTERN_LOW (0x34)
411 #define SM501_2D_MONO_PATTERN_HIGH (0x38)
412 #define SM501_2D_WINDOW_WIDTH (0x3C)
413 #define SM501_2D_SOURCE_BASE (0x40)
414 #define SM501_2D_DESTINATION_BASE (0x44)
415 #define SM501_2D_ALPHA (0x48)
416 #define SM501_2D_WRAP (0x4C)
417 #define SM501_2D_STATUS (0x50)
419 #define SM501_CSC_Y_SOURCE_BASE (0xC8)
420 #define SM501_CSC_CONSTANTS (0xCC)
421 #define SM501_CSC_Y_SOURCE_X (0xD0)
422 #define SM501_CSC_Y_SOURCE_Y (0xD4)
423 #define SM501_CSC_U_SOURCE_BASE (0xD8)
424 #define SM501_CSC_V_SOURCE_BASE (0xDC)
425 #define SM501_CSC_SOURCE_DIMENSION (0xE0)
426 #define SM501_CSC_SOURCE_PITCH (0xE4)
427 #define SM501_CSC_DESTINATION (0xE8)
428 #define SM501_CSC_DESTINATION_DIMENSION (0xEC)
429 #define SM501_CSC_DESTINATION_PITCH (0xF0)
430 #define SM501_CSC_SCALE_FACTOR (0xF4)
431 #define SM501_CSC_DESTINATION_BASE (0xF8)
432 #define SM501_CSC_CONTROL (0xFC)
434 /* 2d engine data port base */
435 #define SM501_2D_ENGINE_DATA (0x110000)
437 /* end of register definitions */
439 #define SM501_HWC_WIDTH (64)
440 #define SM501_HWC_HEIGHT (64)
442 /* SM501 local memory size taken from "linux/drivers/mfd/sm501.c" */
443 static const uint32_t sm501_mem_local_size
[] = {
451 #define get_local_mem_size(s) sm501_mem_local_size[(s)->local_mem_size_index]
453 typedef struct SM501State
{
454 /* graphic console status */
457 /* status & internal resources */
458 target_phys_addr_t base
;
459 uint32_t local_mem_size_index
;
461 ram_addr_t local_mem_offset
;
463 uint32_t last_height
;
466 uint32_t system_control
;
467 uint32_t misc_control
;
468 uint32_t gpio_31_0_control
;
469 uint32_t gpio_63_32_control
;
470 uint32_t dram_control
;
472 uint32_t misc_timing
;
473 uint32_t power_mode_control
;
480 uint8_t dc_palette
[0x400 * 3];
482 uint32_t dc_panel_control
;
483 uint32_t dc_panel_panning_control
;
484 uint32_t dc_panel_fb_addr
;
485 uint32_t dc_panel_fb_offset
;
486 uint32_t dc_panel_fb_width
;
487 uint32_t dc_panel_fb_height
;
488 uint32_t dc_panel_tl_location
;
489 uint32_t dc_panel_br_location
;
490 uint32_t dc_panel_h_total
;
491 uint32_t dc_panel_h_sync
;
492 uint32_t dc_panel_v_total
;
493 uint32_t dc_panel_v_sync
;
495 uint32_t dc_panel_hwc_addr
;
496 uint32_t dc_panel_hwc_location
;
497 uint32_t dc_panel_hwc_color_1_2
;
498 uint32_t dc_panel_hwc_color_3
;
500 uint32_t dc_crt_control
;
501 uint32_t dc_crt_fb_addr
;
502 uint32_t dc_crt_fb_offset
;
503 uint32_t dc_crt_h_total
;
504 uint32_t dc_crt_h_sync
;
505 uint32_t dc_crt_v_total
;
506 uint32_t dc_crt_v_sync
;
508 uint32_t dc_crt_hwc_addr
;
509 uint32_t dc_crt_hwc_location
;
510 uint32_t dc_crt_hwc_color_1_2
;
511 uint32_t dc_crt_hwc_color_3
;
515 static uint32_t get_local_mem_size_index(uint32_t size
)
517 uint32_t norm_size
= 0;
520 for (i
= 0; i
< ARRAY_SIZE(sm501_mem_local_size
); i
++) {
521 uint32_t new_size
= sm501_mem_local_size
[i
];
522 if (new_size
>= size
) {
523 if (norm_size
== 0 || norm_size
> new_size
) {
524 norm_size
= new_size
;
534 * Check the availability of hardware cursor.
535 * @param crt 0 for PANEL, 1 for CRT.
537 static inline int is_hwc_enabled(SM501State
*state
, int crt
)
539 uint32_t addr
= crt
? state
->dc_crt_hwc_addr
: state
->dc_panel_hwc_addr
;
540 return addr
& 0x80000000;
544 * Get the address which holds cursor pattern data.
545 * @param crt 0 for PANEL, 1 for CRT.
547 static inline uint32_t get_hwc_address(SM501State
*state
, int crt
)
549 uint32_t addr
= crt
? state
->dc_crt_hwc_addr
: state
->dc_panel_hwc_addr
;
550 return (addr
& 0x03FFFFF0)/* >> 4*/;
554 * Get the cursor position in y coordinate.
555 * @param crt 0 for PANEL, 1 for CRT.
557 static inline uint32_t get_hwc_y(SM501State
*state
, int crt
)
559 uint32_t location
= crt
? state
->dc_crt_hwc_location
560 : state
->dc_panel_hwc_location
;
561 return (location
& 0x07FF0000) >> 16;
565 * Get the cursor position in x coordinate.
566 * @param crt 0 for PANEL, 1 for CRT.
568 static inline uint32_t get_hwc_x(SM501State
*state
, int crt
)
570 uint32_t location
= crt
? state
->dc_crt_hwc_location
571 : state
->dc_panel_hwc_location
;
572 return location
& 0x000007FF;
576 * Get the cursor position in x coordinate.
577 * @param crt 0 for PANEL, 1 for CRT.
578 * @param index 0, 1, 2 or 3 which specifies color of corsor dot.
580 static inline uint16_t get_hwc_color(SM501State
*state
, int crt
, int index
)
582 uint16_t color_reg
= 0;
583 uint16_t color_565
= 0;
592 color_reg
= crt
? state
->dc_crt_hwc_color_1_2
593 : state
->dc_panel_hwc_color_1_2
;
596 color_reg
= crt
? state
->dc_crt_hwc_color_3
597 : state
->dc_panel_hwc_color_3
;
600 printf("invalid hw cursor color.\n");
607 color_565
= (uint16_t)(color_reg
& 0xFFFF);
610 color_565
= (uint16_t)((color_reg
>> 16) & 0xFFFF);
616 static int within_hwc_y_range(SM501State
*state
, int y
, int crt
)
618 int hwc_y
= get_hwc_y(state
, crt
);
619 return (hwc_y
<= y
&& y
< hwc_y
+ SM501_HWC_HEIGHT
);
622 static uint32_t sm501_system_config_read(void *opaque
, target_phys_addr_t addr
)
624 SM501State
* s
= (SM501State
*)opaque
;
626 SM501_DPRINTF("sm501 system config regs : read addr=%x\n", (int)addr
);
629 case SM501_SYSTEM_CONTROL
:
630 ret
= s
->system_control
;
632 case SM501_MISC_CONTROL
:
633 ret
= s
->misc_control
;
635 case SM501_GPIO31_0_CONTROL
:
636 ret
= s
->gpio_31_0_control
;
638 case SM501_GPIO63_32_CONTROL
:
639 ret
= s
->gpio_63_32_control
;
644 case SM501_DRAM_CONTROL
:
645 ret
= (s
->dram_control
& 0x07F107C0) | s
->local_mem_size_index
<< 13;
650 case SM501_MISC_TIMING
:
651 /* TODO : simulate gate control */
652 ret
= s
->misc_timing
;
654 case SM501_CURRENT_GATE
:
655 /* TODO : simulate gate control */
658 case SM501_CURRENT_CLOCK
:
661 case SM501_POWER_MODE_CONTROL
:
662 ret
= s
->power_mode_control
;
666 printf("sm501 system config : not implemented register read."
667 " addr=%x\n", (int)addr
);
674 static void sm501_system_config_write(void *opaque
,
675 target_phys_addr_t addr
, uint32_t value
)
677 SM501State
* s
= (SM501State
*)opaque
;
678 SM501_DPRINTF("sm501 system config regs : write addr=%x, val=%x\n",
682 case SM501_SYSTEM_CONTROL
:
683 s
->system_control
= value
& 0xE300B8F7;
685 case SM501_MISC_CONTROL
:
686 s
->misc_control
= value
& 0xFF7FFF20;
688 case SM501_GPIO31_0_CONTROL
:
689 s
->gpio_31_0_control
= value
;
691 case SM501_GPIO63_32_CONTROL
:
692 s
->gpio_63_32_control
= value
;
694 case SM501_DRAM_CONTROL
:
695 s
->local_mem_size_index
= (value
>> 13) & 0x7;
696 /* rODO : check validity of size change */
697 s
->dram_control
|= value
& 0x7FFFFFC3;
702 case SM501_MISC_TIMING
:
703 s
->misc_timing
= value
& 0xF31F1FFF;
705 case SM501_POWER_MODE_0_GATE
:
706 case SM501_POWER_MODE_1_GATE
:
707 case SM501_POWER_MODE_0_CLOCK
:
708 case SM501_POWER_MODE_1_CLOCK
:
709 /* TODO : simulate gate & clock control */
711 case SM501_POWER_MODE_CONTROL
:
712 s
->power_mode_control
= value
& 0x00000003;
716 printf("sm501 system config : not implemented register write."
717 " addr=%x, val=%x\n", (int)addr
, value
);
722 static CPUReadMemoryFunc
* const sm501_system_config_readfn
[] = {
725 &sm501_system_config_read
,
728 static CPUWriteMemoryFunc
* const sm501_system_config_writefn
[] = {
731 &sm501_system_config_write
,
734 static uint32_t sm501_palette_read(void *opaque
, target_phys_addr_t addr
)
736 SM501State
* s
= (SM501State
*)opaque
;
737 SM501_DPRINTF("sm501 palette read addr=%x\n", (int)addr
);
739 /* TODO : consider BYTE/WORD access */
740 /* TODO : consider endian */
742 assert(0 <= addr
&& addr
< 0x400 * 3);
743 return *(uint32_t*)&s
->dc_palette
[addr
];
746 static void sm501_palette_write(void *opaque
,
747 target_phys_addr_t addr
, uint32_t value
)
749 SM501State
* s
= (SM501State
*)opaque
;
750 SM501_DPRINTF("sm501 palette write addr=%x, val=%x\n",
753 /* TODO : consider BYTE/WORD access */
754 /* TODO : consider endian */
756 assert(0 <= addr
&& addr
< 0x400 * 3);
757 *(uint32_t*)&s
->dc_palette
[addr
] = value
;
760 static uint32_t sm501_disp_ctrl_read(void *opaque
, target_phys_addr_t addr
)
762 SM501State
* s
= (SM501State
*)opaque
;
764 SM501_DPRINTF("sm501 disp ctrl regs : read addr=%x\n", (int)addr
);
768 case SM501_DC_PANEL_CONTROL
:
769 ret
= s
->dc_panel_control
;
771 case SM501_DC_PANEL_PANNING_CONTROL
:
772 ret
= s
->dc_panel_panning_control
;
774 case SM501_DC_PANEL_FB_ADDR
:
775 ret
= s
->dc_panel_fb_addr
;
777 case SM501_DC_PANEL_FB_OFFSET
:
778 ret
= s
->dc_panel_fb_offset
;
780 case SM501_DC_PANEL_FB_WIDTH
:
781 ret
= s
->dc_panel_fb_width
;
783 case SM501_DC_PANEL_FB_HEIGHT
:
784 ret
= s
->dc_panel_fb_height
;
786 case SM501_DC_PANEL_TL_LOC
:
787 ret
= s
->dc_panel_tl_location
;
789 case SM501_DC_PANEL_BR_LOC
:
790 ret
= s
->dc_panel_br_location
;
793 case SM501_DC_PANEL_H_TOT
:
794 ret
= s
->dc_panel_h_total
;
796 case SM501_DC_PANEL_H_SYNC
:
797 ret
= s
->dc_panel_h_sync
;
799 case SM501_DC_PANEL_V_TOT
:
800 ret
= s
->dc_panel_v_total
;
802 case SM501_DC_PANEL_V_SYNC
:
803 ret
= s
->dc_panel_v_sync
;
806 case SM501_DC_CRT_CONTROL
:
807 ret
= s
->dc_crt_control
;
809 case SM501_DC_CRT_FB_ADDR
:
810 ret
= s
->dc_crt_fb_addr
;
812 case SM501_DC_CRT_FB_OFFSET
:
813 ret
= s
->dc_crt_fb_offset
;
815 case SM501_DC_CRT_H_TOT
:
816 ret
= s
->dc_crt_h_total
;
818 case SM501_DC_CRT_H_SYNC
:
819 ret
= s
->dc_crt_h_sync
;
821 case SM501_DC_CRT_V_TOT
:
822 ret
= s
->dc_crt_v_total
;
824 case SM501_DC_CRT_V_SYNC
:
825 ret
= s
->dc_crt_v_sync
;
828 case SM501_DC_CRT_HWC_ADDR
:
829 ret
= s
->dc_crt_hwc_addr
;
831 case SM501_DC_CRT_HWC_LOC
:
832 ret
= s
->dc_crt_hwc_location
;
834 case SM501_DC_CRT_HWC_COLOR_1_2
:
835 ret
= s
->dc_crt_hwc_color_1_2
;
837 case SM501_DC_CRT_HWC_COLOR_3
:
838 ret
= s
->dc_crt_hwc_color_3
;
841 case SM501_DC_PANEL_PALETTE
... SM501_DC_PANEL_PALETTE
+ 0x400*3 - 4:
842 ret
= sm501_palette_read(opaque
, addr
- SM501_DC_PANEL_PALETTE
);
846 printf("sm501 disp ctrl : not implemented register read."
847 " addr=%x\n", (int)addr
);
854 static void sm501_disp_ctrl_write(void *opaque
,
855 target_phys_addr_t addr
,
858 SM501State
* s
= (SM501State
*)opaque
;
859 SM501_DPRINTF("sm501 disp ctrl regs : write addr=%x, val=%x\n",
863 case SM501_DC_PANEL_CONTROL
:
864 s
->dc_panel_control
= value
& 0x0FFF73FF;
866 case SM501_DC_PANEL_PANNING_CONTROL
:
867 s
->dc_panel_panning_control
= value
& 0xFF3FFF3F;
869 case SM501_DC_PANEL_FB_ADDR
:
870 s
->dc_panel_fb_addr
= value
& 0x8FFFFFF0;
872 case SM501_DC_PANEL_FB_OFFSET
:
873 s
->dc_panel_fb_offset
= value
& 0x3FF03FF0;
875 case SM501_DC_PANEL_FB_WIDTH
:
876 s
->dc_panel_fb_width
= value
& 0x0FFF0FFF;
878 case SM501_DC_PANEL_FB_HEIGHT
:
879 s
->dc_panel_fb_height
= value
& 0x0FFF0FFF;
881 case SM501_DC_PANEL_TL_LOC
:
882 s
->dc_panel_tl_location
= value
& 0x07FF07FF;
884 case SM501_DC_PANEL_BR_LOC
:
885 s
->dc_panel_br_location
= value
& 0x07FF07FF;
888 case SM501_DC_PANEL_H_TOT
:
889 s
->dc_panel_h_total
= value
& 0x0FFF0FFF;
891 case SM501_DC_PANEL_H_SYNC
:
892 s
->dc_panel_h_sync
= value
& 0x00FF0FFF;
894 case SM501_DC_PANEL_V_TOT
:
895 s
->dc_panel_v_total
= value
& 0x0FFF0FFF;
897 case SM501_DC_PANEL_V_SYNC
:
898 s
->dc_panel_v_sync
= value
& 0x003F0FFF;
901 case SM501_DC_PANEL_HWC_ADDR
:
902 s
->dc_panel_hwc_addr
= value
& 0x8FFFFFF0;
904 case SM501_DC_PANEL_HWC_LOC
:
905 s
->dc_panel_hwc_location
= value
& 0x0FFF0FFF;
907 case SM501_DC_PANEL_HWC_COLOR_1_2
:
908 s
->dc_panel_hwc_color_1_2
= value
;
910 case SM501_DC_PANEL_HWC_COLOR_3
:
911 s
->dc_panel_hwc_color_3
= value
& 0x0000FFFF;
914 case SM501_DC_CRT_CONTROL
:
915 s
->dc_crt_control
= value
& 0x0003FFFF;
917 case SM501_DC_CRT_FB_ADDR
:
918 s
->dc_crt_fb_addr
= value
& 0x8FFFFFF0;
920 case SM501_DC_CRT_FB_OFFSET
:
921 s
->dc_crt_fb_offset
= value
& 0x3FF03FF0;
923 case SM501_DC_CRT_H_TOT
:
924 s
->dc_crt_h_total
= value
& 0x0FFF0FFF;
926 case SM501_DC_CRT_H_SYNC
:
927 s
->dc_crt_h_sync
= value
& 0x00FF0FFF;
929 case SM501_DC_CRT_V_TOT
:
930 s
->dc_crt_v_total
= value
& 0x0FFF0FFF;
932 case SM501_DC_CRT_V_SYNC
:
933 s
->dc_crt_v_sync
= value
& 0x003F0FFF;
936 case SM501_DC_CRT_HWC_ADDR
:
937 s
->dc_crt_hwc_addr
= value
& 0x8FFFFFF0;
939 case SM501_DC_CRT_HWC_LOC
:
940 s
->dc_crt_hwc_location
= value
& 0x0FFF0FFF;
942 case SM501_DC_CRT_HWC_COLOR_1_2
:
943 s
->dc_crt_hwc_color_1_2
= value
;
945 case SM501_DC_CRT_HWC_COLOR_3
:
946 s
->dc_crt_hwc_color_3
= value
& 0x0000FFFF;
949 case SM501_DC_PANEL_PALETTE
... SM501_DC_PANEL_PALETTE
+ 0x400*3 - 4:
950 sm501_palette_write(opaque
, addr
- SM501_DC_PANEL_PALETTE
, value
);
954 printf("sm501 disp ctrl : not implemented register write."
955 " addr=%x, val=%x\n", (int)addr
, value
);
960 static CPUReadMemoryFunc
* const sm501_disp_ctrl_readfn
[] = {
963 &sm501_disp_ctrl_read
,
966 static CPUWriteMemoryFunc
* const sm501_disp_ctrl_writefn
[] = {
969 &sm501_disp_ctrl_write
,
972 /* draw line functions for all console modes */
974 #include "pixel_ops.h"
976 typedef void draw_line_func(uint8_t *d
, const uint8_t *s
,
977 int width
, const uint32_t *pal
);
979 typedef void draw_hwc_line_func(SM501State
* s
, int crt
, uint8_t * palette
,
980 int c_y
, uint8_t *d
, int width
);
983 #include "sm501_template.h"
986 #include "sm501_template.h"
990 #include "sm501_template.h"
993 #include "sm501_template.h"
997 #include "sm501_template.h"
1000 #include "sm501_template.h"
1004 #include "sm501_template.h"
1006 static draw_line_func
* draw_line8_funcs
[] = {
1016 static draw_line_func
* draw_line16_funcs
[] = {
1026 static draw_line_func
* draw_line32_funcs
[] = {
1036 static draw_hwc_line_func
* draw_hwc_line_funcs
[] = {
1041 draw_hwc_line_32bgr
,
1042 draw_hwc_line_15bgr
,
1043 draw_hwc_line_16bgr
,
1046 static inline int get_depth_index(DisplayState
*s
)
1048 switch(ds_get_bits_per_pixel(s
)) {
1057 if (is_surface_bgr(s
->surface
))
1064 static void sm501_draw_crt(SM501State
* s
)
1067 int width
= (s
->dc_crt_h_total
& 0x00000FFF) + 1;
1068 int height
= (s
->dc_crt_v_total
& 0x00000FFF) + 1;
1070 uint8_t * src
= s
->local_mem
;
1072 int dst_bpp
= ds_get_bytes_per_pixel(s
->ds
) + (ds_get_bits_per_pixel(s
->ds
) % 8 ? 1 : 0);
1073 uint32_t * palette
= (uint32_t *)&s
->dc_palette
[SM501_DC_CRT_PALETTE
1074 - SM501_DC_PANEL_PALETTE
];
1075 uint8_t hwc_palette
[3 * 3];
1076 int ds_depth_index
= get_depth_index(s
->ds
);
1077 draw_line_func
* draw_line
= NULL
;
1078 draw_hwc_line_func
* draw_hwc_line
= NULL
;
1079 int full_update
= 0;
1081 int page_min
= 0x7fffffff;
1083 ram_addr_t offset
= s
->local_mem_offset
;
1085 /* choose draw_line function */
1086 switch (s
->dc_crt_control
& 3) {
1087 case SM501_DC_CRT_CONTROL_8BPP
:
1089 draw_line
= draw_line8_funcs
[ds_depth_index
];
1091 case SM501_DC_CRT_CONTROL_16BPP
:
1093 draw_line
= draw_line16_funcs
[ds_depth_index
];
1095 case SM501_DC_CRT_CONTROL_32BPP
:
1097 draw_line
= draw_line32_funcs
[ds_depth_index
];
1100 printf("sm501 draw crt : invalid DC_CRT_CONTROL=%x.\n",
1106 /* set up to draw hardware cursor */
1107 if (is_hwc_enabled(s
, 1)) {
1110 /* get cursor palette */
1111 for (i
= 0; i
< 3; i
++) {
1112 uint16_t rgb565
= get_hwc_color(s
, 1, i
+ 1);
1113 hwc_palette
[i
* 3 + 0] = (rgb565
& 0xf800) >> 8; /* red */
1114 hwc_palette
[i
* 3 + 1] = (rgb565
& 0x07e0) >> 3; /* green */
1115 hwc_palette
[i
* 3 + 2] = (rgb565
& 0x001f) << 3; /* blue */
1118 /* choose cursor draw line function */
1119 draw_hwc_line
= draw_hwc_line_funcs
[ds_depth_index
];
1122 /* adjust console size */
1123 if (s
->last_width
!= width
|| s
->last_height
!= height
) {
1124 qemu_console_resize(s
->ds
, width
, height
);
1125 s
->last_width
= width
;
1126 s
->last_height
= height
;
1130 /* draw each line according to conditions */
1131 for (y
= 0; y
< height
; y
++) {
1132 int update_hwc
= draw_hwc_line
? within_hwc_y_range(s
, y
, 1) : 0;
1133 int update
= full_update
|| update_hwc
;
1134 ram_addr_t page0
= offset
& TARGET_PAGE_MASK
;
1135 ram_addr_t page1
= (offset
+ width
* src_bpp
- 1) & TARGET_PAGE_MASK
;
1138 /* check dirty flags for each line */
1139 for (page
= page0
; page
<= page1
; page
+= TARGET_PAGE_SIZE
)
1140 if (cpu_physical_memory_get_dirty(page
, VGA_DIRTY_FLAG
))
1143 /* draw line and change status */
1145 uint8_t * d
= &(ds_get_data(s
->ds
)[y
* width
* dst_bpp
]);
1147 /* draw graphics layer */
1148 draw_line(d
, src
, width
, palette
);
1150 /* draw haredware cursor */
1152 draw_hwc_line(s
, 1, hwc_palette
, y
- get_hwc_y(s
, 1), d
, width
);
1157 if (page0
< page_min
)
1159 if (page1
> page_max
)
1163 /* flush to display */
1164 dpy_update(s
->ds
, 0, y_start
, width
, y
- y_start
);
1169 src
+= width
* src_bpp
;
1170 offset
+= width
* src_bpp
;
1173 /* complete flush to display */
1175 dpy_update(s
->ds
, 0, y_start
, width
, y
- y_start
);
1177 /* clear dirty flags */
1179 cpu_physical_memory_reset_dirty(page_min
, page_max
+ TARGET_PAGE_SIZE
,
1183 static void sm501_update_display(void *opaque
)
1185 SM501State
* s
= (SM501State
*)opaque
;
1187 if (s
->dc_crt_control
& SM501_DC_CRT_CONTROL_ENABLE
)
1191 void sm501_init(uint32_t base
, uint32_t local_mem_bytes
, qemu_irq irq
,
1192 CharDriverState
*chr
)
1196 int sm501_system_config_index
;
1197 int sm501_disp_ctrl_index
;
1199 /* allocate management data region */
1200 s
= (SM501State
*)qemu_mallocz(sizeof(SM501State
));
1202 s
->local_mem_size_index
1203 = get_local_mem_size_index(local_mem_bytes
);
1204 SM501_DPRINTF("local mem size=%x. index=%d\n", get_local_mem_size(s
),
1205 s
->local_mem_size_index
);
1206 s
->system_control
= 0x00100000;
1207 s
->misc_control
= 0x00001000; /* assumes SH, active=low */
1208 s
->dc_panel_control
= 0x00010000;
1209 s
->dc_crt_control
= 0x00010000;
1211 /* allocate local memory */
1212 s
->local_mem_offset
= qemu_ram_alloc(local_mem_bytes
);
1213 s
->local_mem
= qemu_get_ram_ptr(s
->local_mem_offset
);
1214 cpu_register_physical_memory(base
, local_mem_bytes
, s
->local_mem_offset
);
1217 sm501_system_config_index
1218 = cpu_register_io_memory(sm501_system_config_readfn
,
1219 sm501_system_config_writefn
, s
);
1220 cpu_register_physical_memory(base
+ MMIO_BASE_OFFSET
,
1221 0x6c, sm501_system_config_index
);
1222 sm501_disp_ctrl_index
= cpu_register_io_memory(sm501_disp_ctrl_readfn
,
1223 sm501_disp_ctrl_writefn
, s
);
1224 cpu_register_physical_memory(base
+ MMIO_BASE_OFFSET
+ SM501_DC
,
1225 0x1000, sm501_disp_ctrl_index
);
1227 /* bridge to usb host emulation module */
1228 dev
= qdev_create(NULL
, "sysbus-ohci");
1229 qdev_prop_set_uint32(dev
, "num-ports", 2);
1230 qdev_prop_set_taddr(dev
, "dma-offset", base
);
1231 qdev_init_nofail(dev
);
1232 sysbus_mmio_map(sysbus_from_qdev(dev
), 0,
1233 base
+ MMIO_BASE_OFFSET
+ SM501_USB_HOST
);
1234 sysbus_connect_irq(sysbus_from_qdev(dev
), 0, irq
);
1236 /* bridge to serial emulation module */
1238 #ifdef TARGET_WORDS_BIGENDIAN
1239 serial_mm_init(base
+ MMIO_BASE_OFFSET
+ SM501_UART0
, 2,
1240 NULL
, /* TODO : chain irq to IRL */
1243 serial_mm_init(base
+ MMIO_BASE_OFFSET
+ SM501_UART0
, 2,
1244 NULL
, /* TODO : chain irq to IRL */
1249 /* create qemu graphic console */
1250 s
->ds
= graphic_console_init(sm501_update_display
, NULL
,