paul@33 | 1 | /* |
paul@38 | 2 | * U-Boot and JzRISC LCD controller definitions |
paul@33 | 3 | * |
paul@38 | 4 | * Copyright (C) 2001 Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
paul@33 | 5 | * Copyright (C) 2005-2007, Ingenic Semiconductor Inc. |
paul@38 | 6 | * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc> |
paul@217 | 7 | * Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk> |
paul@33 | 8 | * |
paul@33 | 9 | * This program is free software; you can redistribute it and/or |
paul@33 | 10 | * modify it under the terms of the GNU General Public License as |
paul@33 | 11 | * published by the Free Software Foundation; either version 2 of |
paul@33 | 12 | * the License, or (at your option) any later version. |
paul@33 | 13 | * |
paul@33 | 14 | * This program is distributed in the hope that it will be useful, |
paul@33 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@33 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@33 | 17 | * GNU General Public License for more details. |
paul@33 | 18 | * |
paul@33 | 19 | * You should have received a copy of the GNU General Public License |
paul@33 | 20 | * along with this program; if not, write to the Free Software |
paul@42 | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@42 | 22 | * Boston, MA 02110-1301, USA |
paul@33 | 23 | */ |
paul@33 | 24 | |
paul@33 | 25 | #ifndef __JZLCD_H__ |
paul@33 | 26 | #define __JZLCD_H__ |
paul@33 | 27 | |
paul@217 | 28 | #include <stdint.h> |
paul@106 | 29 | |
paul@223 | 30 | /* Framebuffer characteristics. */ |
paul@223 | 31 | |
paul@33 | 32 | struct jzfb_info { |
paul@217 | 33 | uint32_t cfg; /* panel mode and pin usage etc. */ |
paul@223 | 34 | uint16_t w; /* display width in pixels */ |
paul@223 | 35 | uint16_t h; /* display height in pixels */ |
paul@223 | 36 | uint8_t bpp; /* bits per pixel */ |
paul@223 | 37 | uint32_t fclk; /* frame clock */ |
paul@223 | 38 | uint32_t hsw; /* hsync width, in pixel clock */ |
paul@217 | 39 | uint32_t vsw; /* vsync width, in line count */ |
paul@223 | 40 | uint32_t elw; /* end of line, in pixel clock */ |
paul@223 | 41 | uint32_t blw; /* begin of line, in pixel clock */ |
paul@217 | 42 | uint32_t efw; /* end of frame, in line count */ |
paul@217 | 43 | uint32_t bfw; /* begin of frame, in line count */ |
paul@33 | 44 | }; |
paul@33 | 45 | |
paul@223 | 46 | /* LCD controller stucture for jz4740. */ |
paul@223 | 47 | |
paul@38 | 48 | struct jz_fb_dma_descriptor { |
paul@223 | 49 | struct jz_fb_dma_descriptor *fdadr; /* frame descriptor address register */ |
paul@223 | 50 | uint32_t fsadr; /* frame source address register */ |
paul@223 | 51 | uint32_t fidr; /* frame identifier register */ |
paul@223 | 52 | uint32_t ldcmd; /* command register */ |
paul@38 | 53 | }; |
paul@38 | 54 | |
paul@223 | 55 | /* Framebuffer and controller memory information. */ |
paul@223 | 56 | |
paul@221 | 57 | struct jz_mem_info { |
paul@38 | 58 | |
paul@223 | 59 | /* DMA descriptor references (updated for transfers). */ |
paul@223 | 60 | |
paul@224 | 61 | struct jz_fb_dma_descriptor *fdadr0; /* physical address of frame descriptor */ |
paul@224 | 62 | struct jz_fb_dma_descriptor *fdadr1; /* physical address of frame/palette descriptor */ |
paul@38 | 63 | |
paul@223 | 64 | /* DMA descriptor references (indicating allocated regions). */ |
paul@223 | 65 | |
paul@224 | 66 | struct jz_fb_dma_descriptor *dmadesc_fb0; |
paul@224 | 67 | struct jz_fb_dma_descriptor *dmadesc_fb1; |
paul@38 | 68 | struct jz_fb_dma_descriptor *dmadesc_palette; |
paul@93 | 69 | |
paul@223 | 70 | uint32_t screen; /* address of first frame buffer (base of memory used) */ |
paul@217 | 71 | uint32_t palette; /* address of palette memory */ |
paul@223 | 72 | uint32_t total; /* total memory used */ |
paul@38 | 73 | }; |
paul@38 | 74 | |
paul@223 | 75 | /* Display characteristics and memory resources. */ |
paul@223 | 76 | |
paul@38 | 77 | typedef struct vidinfo { |
paul@223 | 78 | struct jzfb_info *jz_fb; /* framebuffer and panel properties */ |
paul@223 | 79 | struct jz_mem_info jz_mem; /* framebuffer memory information */ |
paul@223 | 80 | void *lcd; /* address of LCD controller registers */ |
paul@38 | 81 | } vidinfo_t; |
paul@38 | 82 | |
paul@227 | 83 | /* Public functions. */ |
paul@227 | 84 | |
paul@227 | 85 | uint32_t jz4740_lcd_get_total_size(vidinfo_t *vid); |
paul@227 | 86 | uint32_t jz4740_lcd_get_pixel_clock(vidinfo_t *vid); |
paul@227 | 87 | void jz4740_lcd_ctrl_init(void *lcd_base, void *fb_vaddr, vidinfo_t *vid); |
paul@227 | 88 | void jz4740_lcd_hw_init(vidinfo_t *vid); |
paul@227 | 89 | void jz4740_lcd_dma_init(vidinfo_t *vid); |
paul@227 | 90 | void lcd_set_bpp(uint8_t bpp); |
paul@227 | 91 | uint32_t lcd_ctrl_init(); |
paul@227 | 92 | void lcd_enable(); |
paul@227 | 93 | void lcd_disable(); |
paul@227 | 94 | |
paul@100 | 95 | /* Alignment/rounding macros. */ |
paul@100 | 96 | |
paul@100 | 97 | #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1) |
paul@100 | 98 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
paul@100 | 99 | |
paul@38 | 100 | /* Transfer and display types. */ |
paul@38 | 101 | |
paul@33 | 102 | #define MODE_MASK 0x0f |
paul@33 | 103 | #define MODE_TFT_GEN 0x00 |
paul@33 | 104 | #define MODE_TFT_SHARP 0x01 |
paul@33 | 105 | #define MODE_TFT_CASIO 0x02 |
paul@33 | 106 | #define MODE_TFT_SAMSUNG 0x03 |
paul@33 | 107 | #define MODE_CCIR656_NONINT 0x04 |
paul@33 | 108 | #define MODE_CCIR656_INT 0x05 |
paul@33 | 109 | #define MODE_STN_COLOR_SINGLE 0x08 |
paul@33 | 110 | #define MODE_STN_MONO_SINGLE 0x09 |
paul@33 | 111 | #define MODE_STN_COLOR_DUAL 0x0a |
paul@33 | 112 | #define MODE_STN_MONO_DUAL 0x0b |
paul@33 | 113 | #define MODE_8BIT_SERIAL_TFT 0x0c |
paul@33 | 114 | |
paul@33 | 115 | #define MODE_TFT_18BIT (1<<7) |
paul@33 | 116 | |
paul@33 | 117 | #define STN_DAT_PIN1 (0x00 << 4) |
paul@33 | 118 | #define STN_DAT_PIN2 (0x01 << 4) |
paul@33 | 119 | #define STN_DAT_PIN4 (0x02 << 4) |
paul@33 | 120 | #define STN_DAT_PIN8 (0x03 << 4) |
paul@33 | 121 | #define STN_DAT_PINMASK STN_DAT_PIN8 |
paul@33 | 122 | |
paul@33 | 123 | #define STFT_PSHI (1 << 15) |
paul@33 | 124 | #define STFT_CLSHI (1 << 14) |
paul@33 | 125 | #define STFT_SPLHI (1 << 13) |
paul@33 | 126 | #define STFT_REVHI (1 << 12) |
paul@33 | 127 | |
paul@33 | 128 | #define SYNC_MASTER (0 << 16) |
paul@33 | 129 | #define SYNC_SLAVE (1 << 16) |
paul@33 | 130 | |
paul@33 | 131 | #define DE_P (0 << 9) |
paul@33 | 132 | #define DE_N (1 << 9) |
paul@33 | 133 | |
paul@33 | 134 | #define PCLK_P (0 << 10) |
paul@33 | 135 | #define PCLK_N (1 << 10) |
paul@33 | 136 | |
paul@33 | 137 | #define HSYNC_P (0 << 11) |
paul@33 | 138 | #define HSYNC_N (1 << 11) |
paul@33 | 139 | |
paul@33 | 140 | #define VSYNC_P (0 << 8) |
paul@33 | 141 | #define VSYNC_N (1 << 8) |
paul@33 | 142 | |
paul@33 | 143 | #define DATA_NORMAL (0 << 17) |
paul@33 | 144 | #define DATA_INVERSE (1 << 17) |
paul@33 | 145 | |
paul@225 | 146 | /* LCD register base. */ |
paul@225 | 147 | |
paul@225 | 148 | #define LCD_BASE_KSEG1 0xB3050000 |
paul@225 | 149 | |
paul@225 | 150 | /* Register offsets. */ |
paul@225 | 151 | |
paul@225 | 152 | #define LCD_CFG 0x00 /* LCD Configure Register */ |
paul@225 | 153 | #define LCD_VSYNC 0x04 /* Vertical Synchronize Register */ |
paul@225 | 154 | #define LCD_HSYNC 0x08 /* Horizontal Synchronize Register */ |
paul@225 | 155 | #define LCD_VAT 0x0c /* Virtual Area Setting Register */ |
paul@225 | 156 | #define LCD_DAH 0x10 /* Display Area Horizontal Start/End Point */ |
paul@225 | 157 | #define LCD_DAV 0x14 /* Display Area Vertical Start/End Point */ |
paul@225 | 158 | #define LCD_PS 0x18 /* PS Signal Setting */ |
paul@225 | 159 | #define LCD_CLS 0x1c /* CLS Signal Setting */ |
paul@225 | 160 | #define LCD_SPL 0x20 /* SPL Signal Setting */ |
paul@225 | 161 | #define LCD_REV 0x24 /* REV Signal Setting */ |
paul@225 | 162 | #define LCD_CTRL 0x30 /* LCD Control Register */ |
paul@225 | 163 | #define LCD_STATE 0x34 /* LCD Status Register */ |
paul@225 | 164 | #define LCD_IID 0x38 /* Interrupt ID Register */ |
paul@225 | 165 | #define LCD_DA0 0x40 /* Descriptor Address Register 0 */ |
paul@225 | 166 | #define LCD_SA0 0x44 /* Source Address Register 0 */ |
paul@225 | 167 | #define LCD_FID0 0x48 /* Frame ID Register 0 */ |
paul@225 | 168 | #define LCD_CMD0 0x4c /* DMA Command Register 0 */ |
paul@225 | 169 | #define LCD_DA1 0x50 /* Descriptor Address Register 1 */ |
paul@225 | 170 | #define LCD_SA1 0x54 /* Source Address Register 1 */ |
paul@225 | 171 | #define LCD_FID1 0x58 /* Frame ID Register 1 */ |
paul@225 | 172 | #define LCD_CMD1 0x5c /* DMA Command Register 1 */ |
paul@225 | 173 | |
paul@224 | 174 | /* Palette buffer (LCD_CMDx.PAL). */ |
paul@224 | 175 | |
paul@224 | 176 | #define LCD_CMD_PAL (1 << 28) |
paul@224 | 177 | |
paul@33 | 178 | #endif /* __JZLCD_H__ */ |