1 /* 2 * LCD peripheral support for the JZ4740 and related SoCs. 3 * 4 * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include "lcd.h" 25 #include "lcd-jz4740-panel.h" 26 27 #include <l4/sys/types.h> 28 29 #include <stdint.h> 30 31 /* Descriptor referenced by the DMA mechanism. */ 32 33 struct Jz4740_lcd_descriptor 34 { 35 struct Jz4740_lcd_descriptor *next; /* FDADR: frame descriptor address */ 36 uint32_t source; /* FSADR: frame source address */ 37 uint32_t identifier; /* FIDR: frame identifier */ 38 uint32_t command; /* CMD: command */ 39 }; 40 41 /* 8-word "new descriptor" variant for the JZ4780. */ 42 43 struct Jz4780_lcd_descriptor 44 { 45 struct Jz4780_lcd_descriptor *next; /* FDADR: frame descriptor address */ 46 uint32_t source; /* FSADR: frame source address */ 47 uint32_t identifier; /* FIDR: frame identifier */ 48 uint32_t command; /* CMD: command */ 49 uint32_t offset; /* OFFSIZE: offset in words between lines */ 50 uint32_t page_width; /* PW: number of words per line (16x16 block mode) */ 51 uint32_t command_position; /* CNUM: command number (smart LCD mode) or 52 CPOS: foreground position and properties */ 53 uint32_t fg_size; /* DESSIZE: foreground size and alpha properties */ 54 }; 55 56 57 58 /* C++ language interface. */ 59 60 #ifdef __cplusplus 61 62 #include <l4/devices/hw_mmio_register_block.h> 63 64 /* General JZ4740 LCD controller support. */ 65 66 class Lcd_jz4740_chip : public Lcd_chip 67 { 68 private: 69 Hw::Register_block<32> _regs; 70 Jz4740_lcd_panel *_panel; 71 int _burst_size; 72 73 /* Control register value calculation. */ 74 75 uint32_t _control_bpp(); 76 uint32_t _control_panel(); 77 uint32_t _control_stn_frc(); 78 uint32_t _control_transfer(); 79 80 /* Panel mode access. */ 81 82 uint32_t _mode(); 83 84 /* Panel initialisation. */ 85 86 void _init_stn(); 87 void _init_tft(); 88 void _init_panel(); 89 90 /* Descriptor initialisation. */ 91 92 void _set_descriptor(struct Jz4740_lcd_descriptor &desc, l4_addr_t source, 93 l4_size_t size, struct Jz4740_lcd_descriptor *next, 94 uint32_t flags = 0); 95 96 public: 97 Lcd_jz4740_chip(l4_addr_t addr, Jz4740_lcd_panel *panel); 98 99 struct Jz4740_lcd_panel *get_panel(); 100 101 /* Peripheral control. */ 102 103 void disable(); 104 void disable_quick(); 105 void enable(); 106 107 /* Peripheral properties. */ 108 109 int get_pixel_clock(); 110 111 /* Panel properties. */ 112 113 int get_panels(); 114 int have_stn_panel(); 115 int have_colour_stn(); 116 int have_serial_tft(); 117 118 /* Memory properties. */ 119 120 l4_size_t get_line_size(); 121 l4_size_t get_screen_size(); 122 l4_size_t get_aligned_size(); 123 l4_size_t get_palette_size(); 124 l4_size_t get_aligned_palette_size(); 125 126 /* Memory properties for allocation purposes. */ 127 128 l4_size_t get_total_size(); 129 l4_size_t get_descriptors_size(); 130 131 /* Memory region access. */ 132 133 l4_addr_t get_palette(l4_addr_t screen); 134 l4_addr_t get_framebuffer(int panel, l4_addr_t screen); 135 136 /* Convenience methods. */ 137 138 void init_palette(l4_addr_t palette); 139 140 /* Configuration. */ 141 142 void config(struct Jz4740_lcd_descriptor *desc_vaddr, 143 struct Jz4740_lcd_descriptor *desc_paddr, 144 l4_addr_t fb_paddr); 145 }; 146 147 #endif 148 149 150 151 /* C language interface. */ 152 153 EXTERN_C_BEGIN 154 155 void *jz4740_lcd_init(l4_addr_t lcd_base, struct Jz4740_lcd_panel *panel); 156 157 void jz4740_lcd_config(void *lcd, struct Jz4740_lcd_descriptor *desc_vaddr, 158 struct Jz4740_lcd_descriptor *desc_paddr, 159 l4_addr_t fb_paddr); 160 161 void jz4740_lcd_disable(void *lcd); 162 void jz4740_lcd_disable_quick(void *lcd); 163 void jz4740_lcd_enable(void *lcd); 164 165 l4_addr_t jz4740_lcd_get_palette(void *lcd, l4_addr_t base); 166 int jz4740_lcd_get_pixel_clock(void *lcd); 167 168 void jz4740_lcd_init_palette(void *lcd, l4_addr_t palette); 169 170 EXTERN_C_END