1 /* 2 * LCD peripheral support for the JZ4740 and related SoCs. 3 * 4 * Copyright (C) 2018 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 42 43 /* C++ language interface. */ 44 45 #ifdef __cplusplus 46 47 #include <l4/devices/hw_mmio_register_block.h> 48 49 /* General JZ4740 LCD controller support. */ 50 51 class Lcd_jz4740_chip : public Lcd_chip 52 { 53 private: 54 Hw::Register_block<32> _regs; 55 Jz4740_lcd_panel *_panel; 56 int _burst_size; 57 58 /* Control register value calculation. */ 59 60 uint32_t _control_bpp(); 61 uint32_t _control_panel(); 62 uint32_t _control_stn_frc(); 63 uint32_t _control_transfer(); 64 65 /* Panel mode access. */ 66 67 uint32_t _mode(); 68 69 /* Panel initialisation. */ 70 71 void _init_stn(); 72 void _init_tft(); 73 void _init_panel(); 74 75 /* Descriptor initialisation. */ 76 77 void _set_descriptor(struct Jz4740_lcd_descriptor &desc, l4_addr_t source, 78 l4_size_t size, struct Jz4740_lcd_descriptor *next, 79 uint32_t flags = 0); 80 81 public: 82 Lcd_jz4740_chip(l4_addr_t addr, Jz4740_lcd_panel *panel); 83 84 struct Jz4740_lcd_panel *get_panel(); 85 86 /* Peripheral control. */ 87 88 void disable(); 89 void disable_quick(); 90 void enable(); 91 92 /* Peripheral properties. */ 93 94 int get_pixel_clock(); 95 96 /* Panel properties. */ 97 98 int get_panels(); 99 int have_stn_panel(); 100 int have_colour_stn(); 101 int have_serial_tft(); 102 103 /* Memory properties. */ 104 105 l4_size_t get_line_size(); 106 l4_size_t get_screen_size(); 107 l4_size_t get_aligned_size(); 108 l4_size_t get_palette_size(); 109 l4_size_t get_aligned_palette_size(); 110 111 /* Memory properties for allocation purposes. */ 112 113 l4_size_t get_total_size(); 114 l4_size_t get_descriptors_size(); 115 116 /* Memory region access. */ 117 118 l4_addr_t get_palette(l4_addr_t screen); 119 l4_addr_t get_framebuffer(int panel, l4_addr_t screen); 120 121 /* Convenience methods. */ 122 123 void init_palette(l4_addr_t palette); 124 125 /* Configuration. */ 126 127 void config(struct Jz4740_lcd_descriptor *desc_vaddr, 128 struct Jz4740_lcd_descriptor *desc_paddr, 129 l4_addr_t fb_paddr); 130 }; 131 132 #endif 133 134 135 136 /* C language interface. */ 137 138 EXTERN_C_BEGIN 139 140 void *jz4740_lcd_init(l4_addr_t lcd_base, struct Jz4740_lcd_panel *panel); 141 142 void jz4740_lcd_config(void *lcd, struct Jz4740_lcd_descriptor *desc_vaddr, 143 struct Jz4740_lcd_descriptor *desc_paddr, 144 l4_addr_t fb_paddr); 145 146 void jz4740_lcd_disable(void *lcd); 147 void jz4740_lcd_disable_quick(void *lcd); 148 void jz4740_lcd_enable(void *lcd); 149 150 l4_addr_t jz4740_lcd_get_palette(void *lcd, l4_addr_t base); 151 int jz4740_lcd_get_pixel_clock(void *lcd); 152 153 void jz4740_lcd_init_palette(void *lcd, l4_addr_t palette); 154 155 EXTERN_C_END