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@0 | 31 | /* Descriptor referenced by the DMA mechanism. */ |
paul@0 | 32 | |
paul@0 | 33 | struct Jz4740_lcd_descriptor |
paul@0 | 34 | { |
paul@0 | 35 | struct Jz4740_lcd_descriptor *next; /* FDADR: frame descriptor address */ |
paul@0 | 36 | uint32_t source; /* FSADR: frame source address */ |
paul@0 | 37 | uint32_t identifier; /* FIDR: frame identifier */ |
paul@0 | 38 | uint32_t command; /* CMD: command */ |
paul@0 | 39 | }; |
paul@0 | 40 | |
paul@62 | 41 | /* 8-word "new descriptor" variant for the JZ4780. */ |
paul@62 | 42 | |
paul@62 | 43 | struct Jz4780_lcd_descriptor |
paul@62 | 44 | { |
paul@62 | 45 | struct Jz4780_lcd_descriptor *next; /* FDADR: frame descriptor address */ |
paul@62 | 46 | uint32_t source; /* FSADR: frame source address */ |
paul@62 | 47 | uint32_t identifier; /* FIDR: frame identifier */ |
paul@62 | 48 | uint32_t command; /* CMD: command */ |
paul@62 | 49 | uint32_t offset; /* OFFSIZE: offset in words between lines */ |
paul@62 | 50 | uint32_t page_width; /* PW: number of words per line (16x16 block mode) */ |
paul@62 | 51 | uint32_t command_position; /* CNUM: command number (smart LCD mode) or |
paul@62 | 52 | CPOS: foreground position and properties */ |
paul@62 | 53 | uint32_t fg_size; /* DESSIZE: foreground size and alpha properties */ |
paul@62 | 54 | }; |
paul@62 | 55 | |
paul@0 | 56 | |
paul@0 | 57 | |
paul@0 | 58 | /* C++ language interface. */ |
paul@0 | 59 | |
paul@0 | 60 | #ifdef __cplusplus |
paul@0 | 61 | |
paul@0 | 62 | #include <l4/devices/hw_mmio_register_block.h> |
paul@0 | 63 | |
paul@0 | 64 | /* General JZ4740 LCD controller support. */ |
paul@0 | 65 | |
paul@0 | 66 | class Lcd_jz4740_chip : public Lcd_chip |
paul@0 | 67 | { |
paul@0 | 68 | private: |
paul@0 | 69 | Hw::Register_block<32> _regs; |
paul@0 | 70 | Jz4740_lcd_panel *_panel; |
paul@0 | 71 | int _burst_size; |
paul@0 | 72 | |
paul@0 | 73 | /* Control register value calculation. */ |
paul@0 | 74 | |
paul@0 | 75 | uint32_t _control_bpp(); |
paul@0 | 76 | uint32_t _control_panel(); |
paul@0 | 77 | uint32_t _control_stn_frc(); |
paul@0 | 78 | uint32_t _control_transfer(); |
paul@0 | 79 | |
paul@0 | 80 | /* Panel mode access. */ |
paul@0 | 81 | |
paul@0 | 82 | uint32_t _mode(); |
paul@0 | 83 | |
paul@0 | 84 | /* Panel initialisation. */ |
paul@0 | 85 | |
paul@0 | 86 | void _init_stn(); |
paul@0 | 87 | void _init_tft(); |
paul@0 | 88 | void _init_panel(); |
paul@0 | 89 | |
paul@0 | 90 | /* Descriptor initialisation. */ |
paul@0 | 91 | |
paul@0 | 92 | void _set_descriptor(struct Jz4740_lcd_descriptor &desc, l4_addr_t source, |
paul@0 | 93 | l4_size_t size, struct Jz4740_lcd_descriptor *next, |
paul@0 | 94 | uint32_t flags = 0); |
paul@0 | 95 | |
paul@0 | 96 | public: |
paul@0 | 97 | Lcd_jz4740_chip(l4_addr_t addr, Jz4740_lcd_panel *panel); |
paul@0 | 98 | |
paul@0 | 99 | struct Jz4740_lcd_panel *get_panel(); |
paul@0 | 100 | |
paul@0 | 101 | /* Peripheral control. */ |
paul@0 | 102 | |
paul@0 | 103 | void disable(); |
paul@0 | 104 | void disable_quick(); |
paul@0 | 105 | void enable(); |
paul@0 | 106 | |
paul@0 | 107 | /* Peripheral properties. */ |
paul@0 | 108 | |
paul@0 | 109 | int get_pixel_clock(); |
paul@0 | 110 | |
paul@0 | 111 | /* Panel properties. */ |
paul@0 | 112 | |
paul@0 | 113 | int get_panels(); |
paul@0 | 114 | int have_stn_panel(); |
paul@0 | 115 | int have_colour_stn(); |
paul@0 | 116 | int have_serial_tft(); |
paul@0 | 117 | |
paul@0 | 118 | /* Memory properties. */ |
paul@0 | 119 | |
paul@0 | 120 | l4_size_t get_line_size(); |
paul@0 | 121 | l4_size_t get_screen_size(); |
paul@0 | 122 | l4_size_t get_aligned_size(); |
paul@0 | 123 | l4_size_t get_palette_size(); |
paul@0 | 124 | l4_size_t get_aligned_palette_size(); |
paul@0 | 125 | |
paul@0 | 126 | /* Memory properties for allocation purposes. */ |
paul@0 | 127 | |
paul@0 | 128 | l4_size_t get_total_size(); |
paul@0 | 129 | l4_size_t get_descriptors_size(); |
paul@0 | 130 | |
paul@0 | 131 | /* Memory region access. */ |
paul@0 | 132 | |
paul@0 | 133 | l4_addr_t get_palette(l4_addr_t screen); |
paul@0 | 134 | l4_addr_t get_framebuffer(int panel, l4_addr_t screen); |
paul@0 | 135 | |
paul@0 | 136 | /* Convenience methods. */ |
paul@0 | 137 | |
paul@0 | 138 | void init_palette(l4_addr_t palette); |
paul@0 | 139 | |
paul@0 | 140 | /* Configuration. */ |
paul@0 | 141 | |
paul@0 | 142 | void config(struct Jz4740_lcd_descriptor *desc_vaddr, |
paul@0 | 143 | struct Jz4740_lcd_descriptor *desc_paddr, |
paul@0 | 144 | l4_addr_t fb_paddr); |
paul@0 | 145 | }; |
paul@0 | 146 | |
paul@0 | 147 | #endif |
paul@0 | 148 | |
paul@0 | 149 | |
paul@0 | 150 | |
paul@0 | 151 | /* C language interface. */ |
paul@0 | 152 | |
paul@0 | 153 | EXTERN_C_BEGIN |
paul@0 | 154 | |
paul@0 | 155 | void *jz4740_lcd_init(l4_addr_t lcd_base, struct Jz4740_lcd_panel *panel); |
paul@0 | 156 | |
paul@0 | 157 | void jz4740_lcd_config(void *lcd, struct Jz4740_lcd_descriptor *desc_vaddr, |
paul@0 | 158 | struct Jz4740_lcd_descriptor *desc_paddr, |
paul@0 | 159 | l4_addr_t fb_paddr); |
paul@0 | 160 | |
paul@0 | 161 | void jz4740_lcd_disable(void *lcd); |
paul@0 | 162 | void jz4740_lcd_disable_quick(void *lcd); |
paul@0 | 163 | void jz4740_lcd_enable(void *lcd); |
paul@0 | 164 | |
paul@0 | 165 | l4_addr_t jz4740_lcd_get_palette(void *lcd, l4_addr_t base); |
paul@0 | 166 | int jz4740_lcd_get_pixel_clock(void *lcd); |
paul@0 | 167 | |
paul@0 | 168 | void jz4740_lcd_init_palette(void *lcd, l4_addr_t palette); |
paul@0 | 169 | |
paul@0 | 170 | EXTERN_C_END |