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