paul@0 | 1 | /* |
paul@0 | 2 | * LCD peripheral support for the JZ4740 and related SoCs. |
paul@0 | 3 | * |
paul@0 | 4 | * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc> |
paul@64 | 5 | * Copyright (C) 2015, 2016, 2017, 2018, |
paul@64 | 6 | * 2020 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 7 | * |
paul@0 | 8 | * This program is free software; you can redistribute it and/or |
paul@0 | 9 | * modify it under the terms of the GNU General Public License as |
paul@0 | 10 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 11 | * the License, or (at your option) any later version. |
paul@0 | 12 | * |
paul@0 | 13 | * This program is distributed in the hope that it will be useful, |
paul@0 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 16 | * GNU General Public License for more details. |
paul@0 | 17 | * |
paul@0 | 18 | * You should have received a copy of the GNU General Public License |
paul@0 | 19 | * along with this program; if not, write to the Free Software |
paul@0 | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 21 | * Boston, MA 02110-1301, USA |
paul@0 | 22 | */ |
paul@0 | 23 | |
paul@0 | 24 | #include <l4/devices/hw_mmio_register_block.h> |
paul@0 | 25 | #include <l4/sys/cache.h> |
paul@69 | 26 | #include <l4/sys/irq.h> |
paul@0 | 27 | #include <l4/sys/types.h> |
paul@69 | 28 | #include <l4/util/util.h> |
paul@0 | 29 | |
paul@0 | 30 | #include "lcd-jz4740.h" |
paul@0 | 31 | #include "lcd-jz4740-config.h" |
paul@0 | 32 | |
paul@0 | 33 | #include <stdint.h> |
paul@69 | 34 | #include <stdio.h> |
paul@0 | 35 | |
paul@0 | 36 | enum Regs : unsigned |
paul@0 | 37 | { |
paul@0 | 38 | Lcd_config = 0x000, // LCD_CFG |
paul@0 | 39 | Lcd_vsync = 0x004, // LCD_VSYNC |
paul@0 | 40 | Lcd_hsync = 0x008, // LCD_HSYNC |
paul@69 | 41 | Virtual_area = 0x00c, // LCD_VAT |
paul@0 | 42 | Display_hlimits = 0x010, // LCD_DAH |
paul@0 | 43 | Display_vlimits = 0x014, // LCD_DAV |
paul@0 | 44 | Lcd_ps = 0x018, // LCD_PS |
paul@0 | 45 | Lcd_cls = 0x01c, // LCD_CLS |
paul@0 | 46 | Lcd_spl = 0x020, // LCD_SPL |
paul@0 | 47 | Lcd_rev = 0x024, // LCD_REV |
paul@0 | 48 | Lcd_control = 0x030, // LCD_CTRL |
paul@0 | 49 | Lcd_status = 0x034, // LCD_STATE |
paul@0 | 50 | Lcd_irq_id = 0x038, // LCD_IID |
paul@0 | 51 | Desc_address_0 = 0x040, // LCD_DA0 |
paul@0 | 52 | Source_address_0 = 0x044, // LCD_SA0 |
paul@0 | 53 | Frame_id_0 = 0x048, // LCD_FID0 |
paul@0 | 54 | Command_0 = 0x04c, // LCD_CMD0 |
paul@0 | 55 | Desc_address_1 = 0x050, // LCD_DA1 |
paul@0 | 56 | Source_address_1 = 0x054, // LCD_SA1 |
paul@0 | 57 | Frame_id_1 = 0x058, // LCD_FID1 |
paul@0 | 58 | Command_1 = 0x05c, // LCD_CMD1 |
paul@69 | 59 | Rgb_control = 0x090, // LCD_RGBC (JZ4780) |
paul@69 | 60 | Priority_level = 0x2c0, // LCD_PCFG |
paul@69 | 61 | |
paul@69 | 62 | // OSD registers. |
paul@69 | 63 | |
paul@69 | 64 | Osd_config = 0x100, // LCD_OSDC |
paul@69 | 65 | Osd_control = 0x104, // LCD_OSDCTRL |
paul@69 | 66 | Osd_status = 0x108, // LCD_OSDS |
paul@0 | 67 | }; |
paul@0 | 68 | |
paul@0 | 69 | // Lcd_config descriptions. |
paul@0 | 70 | |
paul@0 | 71 | enum Config_values : unsigned |
paul@0 | 72 | { |
paul@0 | 73 | Config_stn_pins_mask = 0x3, |
paul@0 | 74 | Config_mode_mask = 0xf, |
paul@0 | 75 | }; |
paul@0 | 76 | |
paul@0 | 77 | // Field positions for registers employing two values, with the first typically |
paul@0 | 78 | // being the start value and the second being an end value. |
paul@0 | 79 | |
paul@0 | 80 | enum Value_pair_bits : unsigned |
paul@0 | 81 | { |
paul@0 | 82 | Value_first = 16, |
paul@0 | 83 | Value_second = 0, |
paul@0 | 84 | }; |
paul@0 | 85 | |
paul@69 | 86 | // Virtual area bits. |
paul@0 | 87 | |
paul@69 | 88 | enum Virtual_area_values : unsigned |
paul@0 | 89 | { |
paul@69 | 90 | Virtual_area_horizontal_size = Value_first, // sum of display and blank regions (dot/pixel clock periods) |
paul@69 | 91 | Virtual_area_vertical_size = Value_second, // sum of display and blank regions (line periods) |
paul@0 | 92 | }; |
paul@0 | 93 | |
paul@0 | 94 | // Lcd_control descriptions. |
paul@0 | 95 | |
paul@0 | 96 | enum Control_bits : unsigned |
paul@0 | 97 | { |
paul@64 | 98 | Control_pin_modify = 31, // PINMD (change pin usage from 15..0 to 17..10, 8..1) |
paul@64 | 99 | Control_burst_length = 28, // BST (burst length selection) |
paul@64 | 100 | Control_rgb_mode = 27, // RGB (RGB mode) |
paul@64 | 101 | Control_out_underrun = 26, // OFUP (output FIFO underrun protection) |
paul@64 | 102 | Control_frc_algorithm = 24, // FRC (STN FRC algorithm selection) |
paul@64 | 103 | Control_palette_delay = 16, // PDD (load palette delay counter) |
paul@64 | 104 | Control_dac_loopback_test = 14, // DACTE (DAC loopback test) |
paul@64 | 105 | Control_frame_end_irq_enable = 13, // EOFM (end of frame interrupt enable) |
paul@64 | 106 | Control_frame_start_irq_enable = 12, // SOFM (start of frame interrupt enable) |
paul@64 | 107 | Control_out_underrun_irq_enable = 11, // OFUM (output FIFO underrun interrupt enable) |
paul@64 | 108 | Control_in0_underrun_irq_enable = 10, // IFUM0 (input FIFO 0 underrun interrupt enable) |
paul@64 | 109 | Control_in1_underrun_irq_enable = 9, // IFUM1 (input FIFO 1 underrun interrupt enable) |
paul@64 | 110 | Control_disabled_irq_enable = 8, // LDDM (LCD disable done interrupt enable) |
paul@64 | 111 | Control_quick_disabled_irq_enable = 7, // QDM (LCD quick disable done interrupt enable) |
paul@64 | 112 | Control_endian_select = 6, // BEDN (endian selection) |
paul@64 | 113 | Control_bit_order = 5, // PEDN (bit order in bytes) |
paul@64 | 114 | Control_disable = 4, // DIS (disable controller) |
paul@64 | 115 | Control_enable = 3, // ENA (enable controller) |
paul@64 | 116 | Control_bpp = 0, // BPP (bits per pixel) |
paul@0 | 117 | }; |
paul@0 | 118 | |
paul@0 | 119 | enum Burst_length_values : unsigned |
paul@0 | 120 | { |
paul@0 | 121 | Burst_length_4 = 0, // 4 word |
paul@0 | 122 | Burst_length_8 = 1, // 8 word |
paul@0 | 123 | Burst_length_16 = 2, // 16 word |
paul@0 | 124 | |
paul@0 | 125 | // JZ4780 extensions. |
paul@0 | 126 | |
paul@0 | 127 | Burst_length_32 = 3, // 32 word |
paul@0 | 128 | Burst_length_64 = 4, // 64 word |
paul@0 | 129 | Burst_length_mask = 0x7, |
paul@0 | 130 | }; |
paul@0 | 131 | |
paul@0 | 132 | enum Rgb_mode_values : unsigned |
paul@0 | 133 | { |
paul@0 | 134 | Rgb_mode_565 = 0, |
paul@0 | 135 | Rgb_mode_555 = 1, |
paul@0 | 136 | Rgb_mode_mask = 0x1, |
paul@0 | 137 | }; |
paul@0 | 138 | |
paul@0 | 139 | enum Frc_algorithm_values : unsigned |
paul@0 | 140 | { |
paul@0 | 141 | Frc_greyscales_16 = 0, |
paul@0 | 142 | Frc_greyscales_4 = 1, |
paul@0 | 143 | Frc_greyscales_2 = 2, |
paul@0 | 144 | Frc_greyscales_mask = 0x3, |
paul@0 | 145 | }; |
paul@0 | 146 | |
paul@0 | 147 | enum Control_bpp_values : unsigned |
paul@0 | 148 | { |
paul@0 | 149 | Control_bpp_1bpp = 0, |
paul@0 | 150 | Control_bpp_2bpp = 1, |
paul@0 | 151 | Control_bpp_4bpp = 2, |
paul@0 | 152 | Control_bpp_8bpp = 3, |
paul@0 | 153 | Control_bpp_15bpp = 4, |
paul@0 | 154 | Control_bpp_16bpp = 4, |
paul@0 | 155 | Control_bpp_18bpp = 5, |
paul@0 | 156 | Control_bpp_24bpp = 5, |
paul@0 | 157 | Control_bpp_24bpp_comp = 6, |
paul@0 | 158 | Control_bpp_30bpp = 7, |
paul@0 | 159 | Control_bpp_32bpp = 7, |
paul@0 | 160 | Control_bpp_mask = 0x7, |
paul@0 | 161 | }; |
paul@0 | 162 | |
paul@0 | 163 | // Command descriptions. |
paul@0 | 164 | |
paul@0 | 165 | enum Command_bits : unsigned |
paul@0 | 166 | { |
paul@0 | 167 | Command_frame_start_irq = 31, // SOFINT (start of frame interrupt) |
paul@0 | 168 | Command_frame_end_irq = 30, // EOFINT (end of frame interrupt) |
paul@0 | 169 | Command_lcm_command = 29, // JZ4780: CMD (LCM command/data via DMA0) |
paul@0 | 170 | Command_palette_buffer = 28, // PAL (descriptor references palette, not display data) |
paul@0 | 171 | Command_frame_compressed = 27, // JZ4780: COMPEN (16/24bpp compression enabled) |
paul@0 | 172 | Command_frame_enable = 26, // JZ4780: FRM_EN |
paul@0 | 173 | Command_field_even = 25, // JZ4780: FIELD_SEL (interlace even field) |
paul@0 | 174 | Command_16x16_block = 24, // JZ4780: 16x16BLOCK (fetch data by 16x16 block) |
paul@0 | 175 | Command_buffer_length = 0, // LEN |
paul@0 | 176 | }; |
paul@0 | 177 | |
paul@0 | 178 | enum Command_values : unsigned |
paul@0 | 179 | { |
paul@0 | 180 | Command_buffer_length_mask = 0x00ffffff, |
paul@0 | 181 | }; |
paul@0 | 182 | |
paul@69 | 183 | // Status descriptions. |
paul@69 | 184 | |
paul@69 | 185 | enum Status_bits : unsigned |
paul@69 | 186 | { |
paul@69 | 187 | Status_frame_end_irq = 5, |
paul@69 | 188 | Status_frame_start_irq = 4, |
paul@69 | 189 | Status_disabled = 0, |
paul@69 | 190 | }; |
paul@69 | 191 | |
paul@69 | 192 | // OSD configuration bits (JZ4780). |
paul@69 | 193 | |
paul@69 | 194 | enum Osd_config_bits : unsigned |
paul@69 | 195 | { |
paul@69 | 196 | Osd_config_fg1_frame_start_irq_enable = 15, |
paul@69 | 197 | Osd_config_fg1_frame_end_irq_enable = 14, |
paul@69 | 198 | Osd_config_fg0_frame_start_irq_enable = 11, |
paul@69 | 199 | Osd_config_fg0_frame_end_irq_enable = 10, |
paul@69 | 200 | Osd_config_enable = 0, |
paul@69 | 201 | }; |
paul@69 | 202 | |
paul@69 | 203 | // RGB control (JZ4780). |
paul@69 | 204 | |
paul@69 | 205 | enum Rgb_control_bits : unsigned |
paul@69 | 206 | { |
paul@69 | 207 | Rgb_data_padded = 15, // RGBDM |
paul@69 | 208 | Rgb_padding_mode = 14, // DMM |
paul@69 | 209 | Rgb_422 = 8, // 422 |
paul@69 | 210 | Rgb_format_enable = 7, // RGBFMT |
paul@69 | 211 | Rgb_odd_line = 4, // OddRGB |
paul@69 | 212 | Rgb_even_line = 0, // EvenRGB |
paul@69 | 213 | }; |
paul@69 | 214 | |
paul@69 | 215 | enum Rgb_control_values : unsigned |
paul@69 | 216 | { |
paul@69 | 217 | Rgb_padding_end = 0U << Rgb_padding_mode, |
paul@69 | 218 | Rgb_padding_start = 1U << Rgb_padding_mode, |
paul@69 | 219 | Rgb_odd_line_rgb = 0U << Rgb_odd_line, |
paul@69 | 220 | Rgb_odd_line_rbg = 1U << Rgb_odd_line, |
paul@69 | 221 | Rgb_odd_line_grb = 2U << Rgb_odd_line, |
paul@69 | 222 | Rgb_odd_line_gbr = 3U << Rgb_odd_line, |
paul@69 | 223 | Rgb_odd_line_brg = 4U << Rgb_odd_line, |
paul@69 | 224 | Rgb_odd_line_bgr = 5U << Rgb_odd_line, |
paul@69 | 225 | Rgb_even_line_rgb = 0U << Rgb_even_line, |
paul@69 | 226 | Rgb_even_line_rbg = 1U << Rgb_even_line, |
paul@69 | 227 | Rgb_even_line_grb = 2U << Rgb_even_line, |
paul@69 | 228 | Rgb_even_line_gbr = 3U << Rgb_even_line, |
paul@69 | 229 | Rgb_even_line_brg = 4U << Rgb_even_line, |
paul@69 | 230 | Rgb_even_line_bgr = 5U << Rgb_even_line, |
paul@69 | 231 | }; |
paul@69 | 232 | |
paul@69 | 233 | // Priority level. |
paul@69 | 234 | |
paul@69 | 235 | enum Priority_level_bits : unsigned |
paul@69 | 236 | { |
paul@69 | 237 | Priority_mode = 31, |
paul@69 | 238 | Priority_highest_burst = 28, |
paul@69 | 239 | Priority_threshold2 = 18, |
paul@69 | 240 | Priority_threshold1 = 9, |
paul@69 | 241 | Priority_threshold0 = 0, |
paul@69 | 242 | }; |
paul@69 | 243 | |
paul@69 | 244 | enum Priority_level_values : unsigned |
paul@69 | 245 | { |
paul@69 | 246 | Priority_mode_dynamic = 0U << Priority_mode, |
paul@69 | 247 | Priority_mode_arbiter = 1U << Priority_mode, |
paul@69 | 248 | }; |
paul@69 | 249 | |
paul@69 | 250 | enum Priority_burst_values : unsigned |
paul@69 | 251 | { |
paul@69 | 252 | Priority_burst_4 = 0, |
paul@69 | 253 | Priority_burst_8 = 1, |
paul@69 | 254 | Priority_burst_16 = 2, |
paul@69 | 255 | Priority_burst_32 = 3, |
paul@69 | 256 | Priority_burst_64 = 4, |
paul@69 | 257 | Priority_burst_16_cont = 5, |
paul@69 | 258 | Priority_burst_disable = 7, |
paul@69 | 259 | }; |
paul@69 | 260 | |
paul@69 | 261 | // Position descriptor member. |
paul@69 | 262 | |
paul@69 | 263 | enum Position_bits : unsigned |
paul@69 | 264 | { |
paul@69 | 265 | Position_bpp = 27, |
paul@69 | 266 | Position_premultiply_lcd = 26, |
paul@69 | 267 | Position_coefficient = 24, |
paul@69 | 268 | Position_y_position = 12, |
paul@69 | 269 | Position_x_position = 0, |
paul@69 | 270 | }; |
paul@69 | 271 | |
paul@69 | 272 | enum Position_values : unsigned |
paul@69 | 273 | { |
paul@69 | 274 | Position_bpp_15_16bpp = 4, |
paul@69 | 275 | Position_bpp_18_24bpp = 5, |
paul@69 | 276 | Position_bpp_30bpp = 7, |
paul@69 | 277 | }; |
paul@69 | 278 | |
paul@0 | 279 | |
paul@0 | 280 | |
paul@0 | 281 | // Utility functions. |
paul@0 | 282 | |
paul@0 | 283 | // Round values up according to the resolution. |
paul@0 | 284 | |
paul@0 | 285 | static uint32_t align(uint32_t value, uint32_t resolution) |
paul@0 | 286 | { |
paul@0 | 287 | return (value + (resolution - 1)) & ~(resolution - 1); |
paul@0 | 288 | } |
paul@0 | 289 | |
paul@0 | 290 | // Value pair encoding. |
paul@0 | 291 | |
paul@0 | 292 | static uint32_t encode_pair(uint32_t start, uint32_t end) |
paul@0 | 293 | { |
paul@0 | 294 | return (start << Value_first) | (end << Value_second); |
paul@0 | 295 | } |
paul@0 | 296 | |
paul@0 | 297 | // RGB conversions. |
paul@0 | 298 | |
paul@0 | 299 | static uint16_t rgb8_to_rgb16(uint8_t rgb) |
paul@0 | 300 | { |
paul@0 | 301 | return ((((rgb & 0xe0) >> 5) * 4) << 11) | ((((rgb & 0x1c) >> 2) * 9) << 6) | ((rgb & 0x03) * 10); |
paul@0 | 302 | } |
paul@0 | 303 | |
paul@0 | 304 | static uint16_t rgb4_to_rgb16(uint8_t rgb) |
paul@0 | 305 | { |
paul@0 | 306 | return ((((rgb & 8) >> 3) * 0x1f) << 11) | ((((rgb & 6) >> 1) * 0x15) << 5) | ((rgb & 1) * 0x1f); |
paul@0 | 307 | } |
paul@0 | 308 | |
paul@0 | 309 | |
paul@0 | 310 | |
paul@0 | 311 | |
paul@0 | 312 | // If implemented as a Hw::Device, various properties would be |
paul@0 | 313 | // initialised in the constructor and obtained from the device tree |
paul@0 | 314 | // definitions. |
paul@0 | 315 | |
paul@0 | 316 | Lcd_jz4740_chip::Lcd_jz4740_chip(l4_addr_t addr, Jz4740_lcd_panel *panel) |
paul@0 | 317 | : _panel(panel) |
paul@0 | 318 | { |
paul@0 | 319 | _regs = new Hw::Mmio_register_block<32>(addr); |
paul@69 | 320 | //_burst_size = 64; // 64-word burst size (JZ4780) |
paul@0 | 321 | _burst_size = 16; // 16-word burst size |
paul@0 | 322 | |
paul@0 | 323 | // add_cid("lcd"); |
paul@0 | 324 | // add_cid("lcd-jz4740"); |
paul@0 | 325 | } |
paul@0 | 326 | |
paul@0 | 327 | struct Jz4740_lcd_panel * |
paul@0 | 328 | Lcd_jz4740_chip::get_panel() |
paul@0 | 329 | { |
paul@0 | 330 | return _panel; |
paul@0 | 331 | } |
paul@0 | 332 | |
paul@0 | 333 | void |
paul@0 | 334 | Lcd_jz4740_chip::disable() |
paul@0 | 335 | { |
paul@0 | 336 | // Set the disable bit for normal shutdown. |
paul@0 | 337 | |
paul@69 | 338 | _regs[Lcd_control] = _regs[Lcd_control] | (1U << Control_disable); |
paul@0 | 339 | } |
paul@0 | 340 | |
paul@0 | 341 | void |
paul@0 | 342 | Lcd_jz4740_chip::disable_quick() |
paul@0 | 343 | { |
paul@0 | 344 | // Clear the enable bit for quick shutdown. |
paul@0 | 345 | |
paul@69 | 346 | _regs[Lcd_control] = _regs[Lcd_control] & ~(1U << Control_enable); |
paul@0 | 347 | } |
paul@0 | 348 | |
paul@0 | 349 | void |
paul@0 | 350 | Lcd_jz4740_chip::enable() |
paul@0 | 351 | { |
paul@0 | 352 | // Clear the disable bit and set the enable bit. |
paul@69 | 353 | // JZ4780: OSD status set. |
paul@0 | 354 | |
paul@69 | 355 | _regs[Osd_status] = 0; |
paul@69 | 356 | _regs[Lcd_status] = 0; |
paul@69 | 357 | _regs[Lcd_control] = (_regs[Lcd_control] & ~(1U << Control_disable)) | (1U << Control_enable); |
paul@69 | 358 | printf("LCD control: %x\n", (unsigned int) _regs[Lcd_control]); |
paul@69 | 359 | } |
paul@69 | 360 | |
paul@69 | 361 | bool |
paul@69 | 362 | Lcd_jz4740_chip::enabled() |
paul@69 | 363 | { |
paul@69 | 364 | return !(_regs[Lcd_status] & (1U << Status_disabled)); |
paul@0 | 365 | } |
paul@0 | 366 | |
paul@0 | 367 | // Calculate and return the pixel clock frequency. |
paul@0 | 368 | |
paul@0 | 369 | int |
paul@0 | 370 | Lcd_jz4740_chip::get_pixel_clock() |
paul@0 | 371 | { |
paul@0 | 372 | int pclk, multiplier; |
paul@0 | 373 | |
paul@0 | 374 | // Serial mode: 3 pixel clock cycles per pixel (one per channel). |
paul@0 | 375 | // Parallel mode: 1 pixel clock cycle per pixel. |
paul@0 | 376 | |
paul@0 | 377 | multiplier = have_serial_tft() ? 3 : 1; |
paul@0 | 378 | |
paul@0 | 379 | // Derive pixel clock rate from frame rate. |
paul@0 | 380 | // This multiplies the number of pixel periods in a line by the number of |
paul@0 | 381 | // lines in a frame, thus obtaining the number of such periods in a frame. |
paul@0 | 382 | // Multiplying this result with the frame rate yields the pixel frequency. |
paul@0 | 383 | |
paul@0 | 384 | pclk = _panel->frame_rate * |
paul@0 | 385 | (_panel->width * multiplier + |
paul@0 | 386 | _panel->hsync + _panel->line_start + _panel->line_end) * |
paul@0 | 387 | (_panel->height + |
paul@0 | 388 | _panel->vsync + _panel->frame_start + _panel->frame_end); |
paul@0 | 389 | |
paul@0 | 390 | // STN panel adjustments. |
paul@0 | 391 | |
paul@0 | 392 | if (have_stn_panel()) |
paul@0 | 393 | { |
paul@0 | 394 | // Colour STN panels apparently need to be driven at three times the rate. |
paul@0 | 395 | |
paul@0 | 396 | if (have_colour_stn()) pclk = (pclk * 3); |
paul@0 | 397 | |
paul@0 | 398 | // Reduce the rate according to the width of the STN connection. |
paul@0 | 399 | // Since the pins setting employs log2(pins), a shift by this value is |
paul@0 | 400 | // equivalent to a division by the number of pins. |
paul@0 | 401 | |
paul@0 | 402 | pclk = pclk >> ((_panel->config & Config_stn_pins_mask) >> Jz4740_lcd_config_stn_pins); |
paul@0 | 403 | |
paul@0 | 404 | // Divide the rate by the number of panels. |
paul@0 | 405 | |
paul@0 | 406 | pclk /= get_panels(); |
paul@0 | 407 | } |
paul@0 | 408 | |
paul@0 | 409 | return pclk; |
paul@0 | 410 | } |
paul@0 | 411 | |
paul@0 | 412 | |
paul@0 | 413 | |
paul@0 | 414 | // Return the panel mode. |
paul@0 | 415 | |
paul@0 | 416 | uint32_t |
paul@0 | 417 | Lcd_jz4740_chip::_mode() |
paul@0 | 418 | { |
paul@0 | 419 | return _panel->config & Config_mode_mask; |
paul@0 | 420 | } |
paul@0 | 421 | |
paul@0 | 422 | // Return the number of panels available. |
paul@0 | 423 | |
paul@0 | 424 | int |
paul@0 | 425 | Lcd_jz4740_chip::get_panels() |
paul@0 | 426 | { |
paul@0 | 427 | uint32_t mode = _mode(); |
paul@0 | 428 | |
paul@0 | 429 | return (mode == Jz4740_lcd_mode_stn_dual_colour) || |
paul@0 | 430 | (mode == Jz4740_lcd_mode_stn_dual_mono) ? 2 : 1; |
paul@0 | 431 | } |
paul@0 | 432 | |
paul@0 | 433 | // Return whether the panel is STN. |
paul@0 | 434 | |
paul@0 | 435 | int |
paul@0 | 436 | Lcd_jz4740_chip::have_stn_panel() |
paul@0 | 437 | { |
paul@0 | 438 | uint32_t mode = _mode(); |
paul@0 | 439 | |
paul@0 | 440 | return ((mode == Jz4740_lcd_mode_stn_single_colour) || |
paul@0 | 441 | (mode == Jz4740_lcd_mode_stn_dual_colour) || |
paul@0 | 442 | (mode == Jz4740_lcd_mode_stn_single_mono) || |
paul@0 | 443 | (mode == Jz4740_lcd_mode_stn_dual_mono)); |
paul@0 | 444 | } |
paul@0 | 445 | |
paul@0 | 446 | // Return whether the panel is colour STN. |
paul@0 | 447 | |
paul@0 | 448 | int |
paul@0 | 449 | Lcd_jz4740_chip::have_colour_stn() |
paul@0 | 450 | { |
paul@0 | 451 | uint32_t mode = _mode(); |
paul@0 | 452 | |
paul@0 | 453 | return ((mode == Jz4740_lcd_mode_stn_single_colour) || |
paul@0 | 454 | (mode == Jz4740_lcd_mode_stn_dual_colour)); |
paul@0 | 455 | } |
paul@0 | 456 | |
paul@0 | 457 | // Return whether the panel is colour STN. |
paul@0 | 458 | |
paul@0 | 459 | int |
paul@0 | 460 | Lcd_jz4740_chip::have_serial_tft() |
paul@0 | 461 | { |
paul@0 | 462 | return _mode() == Jz4740_lcd_mode_tft_serial; |
paul@0 | 463 | } |
paul@0 | 464 | |
paul@0 | 465 | |
paul@0 | 466 | |
paul@69 | 467 | // Return the pixel memory size in bits. |
paul@69 | 468 | |
paul@69 | 469 | l4_size_t |
paul@69 | 470 | Lcd_jz4740_chip::get_pixel_size() |
paul@69 | 471 | { |
paul@69 | 472 | if (_panel->bpp > 16) |
paul@69 | 473 | return 32; |
paul@69 | 474 | else if (_panel->bpp > 8) |
paul@69 | 475 | return 16; |
paul@69 | 476 | else |
paul@69 | 477 | return _panel->bpp; |
paul@69 | 478 | } |
paul@69 | 479 | |
paul@0 | 480 | // Return the line memory size. |
paul@0 | 481 | |
paul@0 | 482 | l4_size_t |
paul@0 | 483 | Lcd_jz4740_chip::get_line_size() |
paul@0 | 484 | { |
paul@0 | 485 | // Lines must be aligned to a word boundary. |
paul@0 | 486 | |
paul@69 | 487 | return align((_panel->width * get_pixel_size()) / 8, sizeof(uint32_t)); |
paul@0 | 488 | } |
paul@0 | 489 | |
paul@0 | 490 | // Return the screen memory size. |
paul@0 | 491 | |
paul@0 | 492 | l4_size_t |
paul@0 | 493 | Lcd_jz4740_chip::get_screen_size() |
paul@0 | 494 | { |
paul@0 | 495 | return get_line_size() * _panel->height; |
paul@0 | 496 | } |
paul@0 | 497 | |
paul@0 | 498 | // Return the aligned size for the DMA transfer. |
paul@0 | 499 | |
paul@0 | 500 | l4_size_t |
paul@0 | 501 | Lcd_jz4740_chip::get_aligned_size() |
paul@0 | 502 | { |
paul@0 | 503 | return align(get_screen_size(), _burst_size * sizeof(uint32_t)); |
paul@0 | 504 | } |
paul@0 | 505 | |
paul@0 | 506 | // Return the size of the palette. |
paul@0 | 507 | |
paul@0 | 508 | l4_size_t |
paul@0 | 509 | Lcd_jz4740_chip::get_palette_size() |
paul@0 | 510 | { |
paul@0 | 511 | // No palette for modes with more than eight bits per pixel. |
paul@0 | 512 | |
paul@0 | 513 | if (_panel->bpp > 8) return 0; |
paul@0 | 514 | |
paul@0 | 515 | // Get the size of a collection of two-byte entries, one per colour. |
paul@0 | 516 | |
paul@69 | 517 | return (1U << (_panel->bpp)) * sizeof(uint16_t); |
paul@0 | 518 | } |
paul@0 | 519 | |
paul@0 | 520 | // Return the aligned size of the palette for the DMA transfer. |
paul@0 | 521 | |
paul@0 | 522 | l4_size_t |
paul@0 | 523 | Lcd_jz4740_chip::get_aligned_palette_size() |
paul@0 | 524 | { |
paul@0 | 525 | return align(get_palette_size(), _burst_size * sizeof(uint32_t)); |
paul@0 | 526 | } |
paul@0 | 527 | |
paul@0 | 528 | // Return the total memory requirements of the framebuffers and palette. |
paul@0 | 529 | |
paul@0 | 530 | l4_size_t |
paul@0 | 531 | Lcd_jz4740_chip::get_total_size() |
paul@0 | 532 | { |
paul@0 | 533 | return get_aligned_size() * get_panels() + get_aligned_palette_size(); |
paul@0 | 534 | } |
paul@0 | 535 | |
paul@0 | 536 | // Return the total memory requirements of any DMA descriptors. |
paul@0 | 537 | |
paul@0 | 538 | l4_size_t |
paul@0 | 539 | Lcd_jz4740_chip::get_descriptors_size() |
paul@0 | 540 | { |
paul@0 | 541 | return 3 * sizeof(struct Jz4740_lcd_descriptor); |
paul@0 | 542 | } |
paul@0 | 543 | |
paul@0 | 544 | |
paul@0 | 545 | |
paul@0 | 546 | // Functions returning addresses of each data region. |
paul@0 | 547 | // The base parameter permits the retrieval of virtual or physical addresses. |
paul@0 | 548 | |
paul@0 | 549 | l4_addr_t |
paul@0 | 550 | Lcd_jz4740_chip::get_palette(l4_addr_t base) |
paul@0 | 551 | { |
paul@0 | 552 | // Use memory at the end of the allocated region for the palette. |
paul@0 | 553 | |
paul@0 | 554 | return base + (get_panels() * get_aligned_size()) - get_aligned_palette_size(); |
paul@0 | 555 | } |
paul@0 | 556 | |
paul@0 | 557 | l4_addr_t |
paul@0 | 558 | Lcd_jz4740_chip::get_framebuffer(int panel, l4_addr_t base) |
paul@0 | 559 | { |
paul@0 | 560 | // Framebuffers for panels are allocated at the start of the region. |
paul@0 | 561 | |
paul@0 | 562 | return base + (panel * get_aligned_size()); |
paul@0 | 563 | } |
paul@0 | 564 | |
paul@0 | 565 | |
paul@0 | 566 | |
paul@0 | 567 | // Palette initialisation. |
paul@0 | 568 | |
paul@0 | 569 | void |
paul@0 | 570 | Lcd_jz4740_chip::init_palette(l4_addr_t palette) |
paul@0 | 571 | { |
paul@69 | 572 | uint8_t colours = 1U << (_panel->bpp); |
paul@0 | 573 | uint16_t *entry = (uint16_t *) palette; |
paul@0 | 574 | uint16_t *end = entry + colours; |
paul@0 | 575 | uint8_t value = 0; |
paul@0 | 576 | |
paul@0 | 577 | while (entry < end) |
paul@0 | 578 | { |
paul@0 | 579 | switch (_panel->bpp) |
paul@0 | 580 | { |
paul@0 | 581 | case 4: |
paul@0 | 582 | *entry = rgb4_to_rgb16(value); |
paul@0 | 583 | break; |
paul@0 | 584 | |
paul@0 | 585 | case 8: |
paul@0 | 586 | *entry = rgb8_to_rgb16(value); |
paul@0 | 587 | break; |
paul@0 | 588 | |
paul@0 | 589 | default: |
paul@0 | 590 | break; |
paul@0 | 591 | } |
paul@0 | 592 | |
paul@0 | 593 | value++; |
paul@0 | 594 | entry++; |
paul@0 | 595 | } |
paul@0 | 596 | } |
paul@0 | 597 | |
paul@0 | 598 | |
paul@0 | 599 | |
paul@0 | 600 | // Return colour depth control value. |
paul@0 | 601 | // NOTE: Not supporting JZ4780 options. |
paul@0 | 602 | |
paul@0 | 603 | uint32_t |
paul@0 | 604 | Lcd_jz4740_chip::_control_bpp() |
paul@0 | 605 | { |
paul@0 | 606 | switch (_panel->bpp) |
paul@0 | 607 | { |
paul@0 | 608 | case 1: return Control_bpp_1bpp; |
paul@0 | 609 | case 2: return Control_bpp_2bpp; |
paul@0 | 610 | case 3 ... 4: return Control_bpp_4bpp; |
paul@0 | 611 | case 5 ... 8: return Control_bpp_8bpp; |
paul@0 | 612 | case 9 ... 15: return Control_bpp_15bpp | (Rgb_mode_555 << Control_rgb_mode); |
paul@0 | 613 | case 17 ... 18: return Control_bpp_18bpp; |
paul@0 | 614 | case 19 ... 32: return Control_bpp_24bpp; |
paul@0 | 615 | case 16: |
paul@0 | 616 | default: return Control_bpp_16bpp; |
paul@0 | 617 | } |
paul@0 | 618 | } |
paul@0 | 619 | |
paul@69 | 620 | // Return colour depth control value. |
paul@69 | 621 | // JZ4780 position details only. |
paul@69 | 622 | |
paul@69 | 623 | uint32_t |
paul@69 | 624 | Lcd_jz4740_chip::_position_bpp() |
paul@69 | 625 | { |
paul@69 | 626 | uint32_t value; |
paul@69 | 627 | |
paul@69 | 628 | switch (_panel->bpp) |
paul@69 | 629 | { |
paul@69 | 630 | case 15: case 16: value = Position_bpp_15_16bpp; break; |
paul@69 | 631 | case 18: case 24: value = Position_bpp_18_24bpp; break; |
paul@69 | 632 | case 30: value = Position_bpp_30bpp; break; |
paul@69 | 633 | default: value = 0; break; |
paul@69 | 634 | } |
paul@69 | 635 | |
paul@69 | 636 | return value << Position_bpp; |
paul@69 | 637 | } |
paul@69 | 638 | |
paul@0 | 639 | // Return a panel-related control value. |
paul@0 | 640 | |
paul@0 | 641 | uint32_t |
paul@0 | 642 | Lcd_jz4740_chip::_control_panel() |
paul@0 | 643 | { |
paul@0 | 644 | if (have_stn_panel()) |
paul@69 | 645 | return _control_stn_frc() << Control_frc_algorithm; |
paul@0 | 646 | else |
paul@0 | 647 | return 0; |
paul@0 | 648 | } |
paul@0 | 649 | |
paul@0 | 650 | // Return a STN-related control value. |
paul@0 | 651 | |
paul@0 | 652 | uint32_t |
paul@0 | 653 | Lcd_jz4740_chip::_control_stn_frc() |
paul@0 | 654 | { |
paul@0 | 655 | if (_panel->bpp <= 2) |
paul@0 | 656 | return Frc_greyscales_2; |
paul@0 | 657 | if (_panel->bpp <= 4) |
paul@0 | 658 | return Frc_greyscales_4; |
paul@0 | 659 | return Frc_greyscales_16; |
paul@0 | 660 | } |
paul@0 | 661 | |
paul@0 | 662 | // Return a transfer-related control value. |
paul@0 | 663 | |
paul@0 | 664 | uint32_t |
paul@0 | 665 | Lcd_jz4740_chip::_control_transfer() |
paul@0 | 666 | { |
paul@0 | 667 | uint32_t length; |
paul@0 | 668 | |
paul@0 | 669 | switch (_burst_size) |
paul@0 | 670 | { |
paul@0 | 671 | case 4: length = Burst_length_4; break; |
paul@0 | 672 | case 8: length = Burst_length_8; break; |
paul@0 | 673 | case 32: length = Burst_length_32; break; |
paul@0 | 674 | case 64: length = Burst_length_64; break; |
paul@0 | 675 | case 16: |
paul@0 | 676 | default: length = Burst_length_16; break; |
paul@0 | 677 | } |
paul@0 | 678 | |
paul@69 | 679 | return (length << Control_burst_length) | (1U << Control_out_underrun); |
paul@69 | 680 | } |
paul@69 | 681 | |
paul@69 | 682 | // Return an interrupt-related control value. |
paul@69 | 683 | |
paul@69 | 684 | uint32_t |
paul@69 | 685 | Lcd_jz4740_chip::_control_irq() |
paul@69 | 686 | { |
paul@69 | 687 | return ((_irq_conditions & Lcd_irq_frame_start) ? (1U << Control_frame_start_irq_enable) : 0) | |
paul@69 | 688 | ((_irq_conditions & Lcd_irq_frame_end) ? (1U << Control_frame_end_irq_enable) : 0); |
paul@69 | 689 | } |
paul@69 | 690 | |
paul@69 | 691 | // Return an interrupt-related OSD configuration value. |
paul@69 | 692 | |
paul@69 | 693 | uint32_t |
paul@69 | 694 | Lcd_jz4740_chip::_osd_config_irq() |
paul@69 | 695 | { |
paul@69 | 696 | return ((_irq_conditions & Lcd_irq_frame_start) ? (1U << Osd_config_fg0_frame_start_irq_enable) : 0) | |
paul@69 | 697 | ((_irq_conditions & Lcd_irq_frame_end) ? (1U << Osd_config_fg0_frame_end_irq_enable) : 0); |
paul@69 | 698 | } |
paul@69 | 699 | |
paul@69 | 700 | // Return an interrupt-related command value. |
paul@69 | 701 | |
paul@69 | 702 | uint32_t |
paul@69 | 703 | Lcd_jz4740_chip::_command_irq() |
paul@69 | 704 | { |
paul@69 | 705 | return ((_irq_conditions & Lcd_irq_frame_start) ? (1U << Command_frame_start_irq) : 0) | |
paul@69 | 706 | ((_irq_conditions & Lcd_irq_frame_end) ? (1U << Command_frame_end_irq) : 0); |
paul@69 | 707 | } |
paul@69 | 708 | |
paul@69 | 709 | // Return an interrupt-related status value. |
paul@69 | 710 | |
paul@69 | 711 | uint32_t |
paul@69 | 712 | Lcd_jz4740_chip::_status_irq() |
paul@69 | 713 | { |
paul@69 | 714 | return ((_irq_conditions & Lcd_irq_frame_start) ? (1U << Status_frame_start_irq) : 0) | |
paul@69 | 715 | ((_irq_conditions & Lcd_irq_frame_end) ? (1U << Status_frame_end_irq) : 0); |
paul@69 | 716 | } |
paul@69 | 717 | |
paul@69 | 718 | uint32_t |
paul@69 | 719 | Lcd_jz4740_chip::_priority_transfer() |
paul@69 | 720 | { |
paul@69 | 721 | uint32_t length; |
paul@69 | 722 | |
paul@69 | 723 | switch (_burst_size) |
paul@69 | 724 | { |
paul@69 | 725 | case 4: length = Priority_burst_4; break; |
paul@69 | 726 | case 8: length = Priority_burst_8; break; |
paul@69 | 727 | case 32: length = Priority_burst_32; break; |
paul@69 | 728 | case 64: length = Priority_burst_64; break; |
paul@69 | 729 | case 16: |
paul@69 | 730 | default: length = Priority_burst_16; break; |
paul@69 | 731 | } |
paul@69 | 732 | |
paul@69 | 733 | return Priority_mode_arbiter | |
paul@69 | 734 | (length << Priority_highest_burst) | |
paul@69 | 735 | (511U << Priority_threshold2) | |
paul@69 | 736 | (400U << Priority_threshold1) | |
paul@69 | 737 | (256U << Priority_threshold0); |
paul@0 | 738 | } |
paul@0 | 739 | |
paul@0 | 740 | // STN panel-specific initialisation. |
paul@0 | 741 | |
paul@0 | 742 | void |
paul@0 | 743 | Lcd_jz4740_chip::_init_stn() |
paul@0 | 744 | { |
paul@0 | 745 | // Divide the height by the number of panels. |
paul@0 | 746 | |
paul@0 | 747 | uint32_t height = _panel->height / get_panels(); |
paul@0 | 748 | |
paul@0 | 749 | // Since the value is log2(pins), 1 << value yields the number of pins. |
paul@0 | 750 | |
paul@0 | 751 | int pins = 1 << ((_panel->config & Config_stn_pins_mask) >> Jz4740_lcd_config_stn_pins); |
paul@0 | 752 | |
paul@0 | 753 | // Round parameters up to a multiple of the number of pins. |
paul@0 | 754 | |
paul@0 | 755 | uint32_t hsync = align(_panel->hsync, pins); |
paul@0 | 756 | uint32_t line_start = align(_panel->line_start, pins); |
paul@0 | 757 | uint32_t line_end = align(_panel->line_end, pins); |
paul@0 | 758 | |
paul@0 | 759 | // Define the start and end positions of visible data on a line and in a frame. |
paul@0 | 760 | // Visible frame data is anchored at line zero, with the start region |
paul@0 | 761 | // preceding this line (and thus appearing at the end of the preceding frame). |
paul@0 | 762 | |
paul@0 | 763 | uint32_t line_start_pos = line_start; |
paul@0 | 764 | uint32_t line_end_pos = line_start_pos + _panel->width; |
paul@0 | 765 | uint32_t frame_start_pos = 0; |
paul@0 | 766 | uint32_t frame_end_pos = frame_start_pos + height; |
paul@0 | 767 | |
paul@0 | 768 | // Define sync pulse locations, with hsync occurring after the visible data. |
paul@0 | 769 | |
paul@0 | 770 | _regs[Lcd_hsync] = encode_pair(line_end_pos, line_end_pos + hsync); |
paul@0 | 771 | _regs[Lcd_vsync] = encode_pair(0, _panel->vsync); |
paul@0 | 772 | |
paul@0 | 773 | // Set the display area and limits. |
paul@0 | 774 | |
paul@69 | 775 | _regs[Virtual_area] = encode_pair(line_end_pos + hsync + line_end, |
paul@69 | 776 | frame_end_pos + _panel->vsync + _panel->frame_end + _panel->frame_start); |
paul@0 | 777 | |
paul@0 | 778 | _regs[Display_hlimits] = encode_pair(line_start_pos, line_end_pos); |
paul@0 | 779 | _regs[Display_vlimits] = encode_pair(frame_start_pos, frame_end_pos); |
paul@0 | 780 | |
paul@0 | 781 | // Set the AC bias signal. |
paul@0 | 782 | |
paul@0 | 783 | _regs[Lcd_ps] = encode_pair(0, _panel->frame_start + height + _panel->vsync + _panel->frame_end); |
paul@0 | 784 | } |
paul@0 | 785 | |
paul@0 | 786 | // TFT panel-specific initialisation. |
paul@0 | 787 | |
paul@0 | 788 | void |
paul@0 | 789 | Lcd_jz4740_chip::_init_tft() |
paul@0 | 790 | { |
paul@0 | 791 | // Define the start and end positions of visible data on a line and in a frame. |
paul@0 | 792 | |
paul@0 | 793 | uint32_t line_start_pos = _panel->line_start + _panel->hsync; |
paul@0 | 794 | uint32_t line_end_pos = line_start_pos + _panel->width; |
paul@0 | 795 | uint32_t frame_start_pos = _panel->frame_start + _panel->vsync; |
paul@0 | 796 | uint32_t frame_end_pos = frame_start_pos + _panel->height; |
paul@0 | 797 | |
paul@0 | 798 | // Define sync pulse locations, with pulses appearing before visible data. |
paul@0 | 799 | |
paul@0 | 800 | _regs[Lcd_hsync] = encode_pair(0, _panel->hsync); |
paul@0 | 801 | _regs[Lcd_vsync] = encode_pair(0, _panel->vsync); |
paul@0 | 802 | |
paul@0 | 803 | // Set the display area and limits. |
paul@0 | 804 | |
paul@69 | 805 | _regs[Virtual_area] = encode_pair(line_end_pos + _panel->line_end, |
paul@69 | 806 | frame_end_pos + _panel->frame_end); |
paul@0 | 807 | |
paul@0 | 808 | _regs[Display_hlimits] = encode_pair(line_start_pos, line_end_pos); |
paul@0 | 809 | _regs[Display_vlimits] = encode_pair(frame_start_pos, frame_end_pos); |
paul@0 | 810 | } |
paul@0 | 811 | |
paul@0 | 812 | // Initialise the panel. |
paul@0 | 813 | // NOTE: Only generic STN and TFT panels are supported. |
paul@0 | 814 | |
paul@0 | 815 | void |
paul@0 | 816 | Lcd_jz4740_chip::_init_panel() |
paul@0 | 817 | { |
paul@0 | 818 | if (have_stn_panel()) |
paul@0 | 819 | _init_stn(); |
paul@0 | 820 | else |
paul@0 | 821 | switch (_mode()) |
paul@0 | 822 | { |
paul@0 | 823 | case Jz4740_lcd_mode_tft_generic: |
paul@0 | 824 | case Jz4740_lcd_mode_tft_casio: |
paul@0 | 825 | case Jz4740_lcd_mode_tft_serial: _init_tft(); |
paul@0 | 826 | |
paul@0 | 827 | default: break; |
paul@0 | 828 | } |
paul@0 | 829 | } |
paul@0 | 830 | |
paul@0 | 831 | // Initialise a DMA descriptor. |
paul@0 | 832 | |
paul@0 | 833 | void |
paul@0 | 834 | Lcd_jz4740_chip::_set_descriptor(struct Jz4740_lcd_descriptor &desc, |
paul@0 | 835 | l4_addr_t source, l4_size_t size, |
paul@0 | 836 | struct Jz4740_lcd_descriptor *next, |
paul@0 | 837 | uint32_t flags) |
paul@0 | 838 | { |
paul@0 | 839 | // In the command, indicate the number of words from the source for transfer. |
paul@0 | 840 | |
paul@0 | 841 | desc.next = next; |
paul@0 | 842 | desc.source = source; |
paul@69 | 843 | desc.identifier = source; |
paul@69 | 844 | desc.command = ((size / sizeof(uint32_t)) & Command_buffer_length_mask) | |
paul@69 | 845 | (1U << Command_frame_enable) | |
paul@69 | 846 | flags; |
paul@69 | 847 | |
paul@69 | 848 | printf("next = %08x\n", desc.next); |
paul@69 | 849 | printf("source = %08x\n", desc.source); |
paul@69 | 850 | printf("identifier = %08x\n", desc.identifier); |
paul@69 | 851 | printf("command = %08x\n", desc.command); |
paul@69 | 852 | |
paul@69 | 853 | // Initialise "new" descriptor fields. |
paul@69 | 854 | |
paul@69 | 855 | desc.offset = 0; |
paul@69 | 856 | desc.page_width = 0; |
paul@69 | 857 | desc.command_position = (1UL << Position_premultiply_lcd) | |
paul@69 | 858 | (1UL << Position_coefficient) | |
paul@69 | 859 | _position_bpp(); |
paul@69 | 860 | desc.fg_size = 0xff000000 | (1023 << 12) | (1279 << 0); // JZ4780 driver magic |
paul@0 | 861 | } |
paul@0 | 862 | |
paul@0 | 863 | |
paul@0 | 864 | |
paul@0 | 865 | // Initialise the LCD controller with the memory, panel and framebuffer details. |
paul@0 | 866 | // Any palette must be initialised separately using get_palette and init_palette. |
paul@0 | 867 | |
paul@0 | 868 | void |
paul@0 | 869 | Lcd_jz4740_chip::config(struct Jz4740_lcd_descriptor *desc_vaddr, |
paul@0 | 870 | struct Jz4740_lcd_descriptor *desc_paddr, |
paul@0 | 871 | l4_addr_t fb_paddr) |
paul@0 | 872 | { |
paul@69 | 873 | // NOTE: Remarks in the Ingenic Linux 3.0.8 driver suggest that the JZ4775 and |
paul@69 | 874 | // NOTE: JZ4780 do not support palettes. |
paul@69 | 875 | |
paul@0 | 876 | int have_palette = (_panel->bpp <= 8); |
paul@0 | 877 | |
paul@0 | 878 | // Provide the first framebuffer descriptor in single and dual modes. |
paul@0 | 879 | // Flip back and forth between any palette and the framebuffer. |
paul@0 | 880 | |
paul@0 | 881 | _set_descriptor(desc_vaddr[0], get_framebuffer(0, fb_paddr), |
paul@69 | 882 | get_aligned_size(), |
paul@69 | 883 | have_palette ? desc_paddr + 2 : desc_paddr, |
paul@69 | 884 | _command_irq()); |
paul@0 | 885 | |
paul@0 | 886 | // Provide the second framebuffer descriptor only in dual-panel mode. |
paul@0 | 887 | // Only employ this descriptor in the second DMA channel. |
paul@0 | 888 | |
paul@0 | 889 | if (get_panels() == 2) |
paul@0 | 890 | _set_descriptor(desc_vaddr[1], get_framebuffer(1, fb_paddr), |
paul@69 | 891 | get_aligned_size(), |
paul@69 | 892 | desc_paddr + 1, |
paul@69 | 893 | _command_irq()); |
paul@0 | 894 | |
paul@0 | 895 | // Initialise palette descriptor details for lower colour depths. |
paul@0 | 896 | |
paul@0 | 897 | if (have_palette) |
paul@0 | 898 | _set_descriptor(desc_vaddr[2], get_palette(fb_paddr), |
paul@69 | 899 | get_aligned_palette_size(), |
paul@0 | 900 | desc_paddr, |
paul@0 | 901 | Command_palette_buffer); |
paul@0 | 902 | |
paul@0 | 903 | // Flush cached structure data. |
paul@0 | 904 | |
paul@0 | 905 | l4_cache_clean_data((unsigned long) desc_vaddr, |
paul@0 | 906 | (unsigned long) desc_vaddr + get_descriptors_size()); |
paul@0 | 907 | |
paul@0 | 908 | // Configure DMA by setting frame descriptor addresses. |
paul@0 | 909 | |
paul@0 | 910 | // Provide the palette descriptor address first, if employed. |
paul@0 | 911 | |
paul@0 | 912 | _regs[Desc_address_0] = (uint32_t) (have_palette ? desc_paddr + 2 : desc_paddr); |
paul@69 | 913 | printf("descriptor = %08x\n", (uint32_t) _regs[Desc_address_0]); |
paul@0 | 914 | |
paul@0 | 915 | // Provide a descriptor for the second DMA channel in dual-panel mode. |
paul@0 | 916 | |
paul@0 | 917 | if (get_panels() == 2) |
paul@0 | 918 | _regs[Desc_address_1] = (uint32_t) (desc_paddr + 1); |
paul@0 | 919 | |
paul@0 | 920 | // Initialise panel-related registers. |
paul@0 | 921 | |
paul@0 | 922 | _init_panel(); |
paul@0 | 923 | |
paul@0 | 924 | // Initialise the control and configuration registers. |
paul@69 | 925 | // NOTE: JZ4780 does not support bpp setting here. |
paul@0 | 926 | |
paul@69 | 927 | _regs[Lcd_control] = _control_panel() | _control_bpp() | _control_transfer() | _control_irq(); |
paul@0 | 928 | _regs[Lcd_config] = _panel->config; |
paul@69 | 929 | |
paul@69 | 930 | // NOTE: JZ4780 only. |
paul@69 | 931 | |
paul@69 | 932 | _regs[Rgb_control] = (1U << Rgb_format_enable) | Rgb_odd_line_rgb | Rgb_even_line_rgb; |
paul@69 | 933 | _regs[Priority_level] = _priority_transfer(); |
paul@69 | 934 | _regs[Osd_config] = 0; // (1U << Osd_config_enable) | _osd_config_irq(); |
paul@69 | 935 | |
paul@69 | 936 | printf("LCD control: %08x\n", (unsigned int) _regs[Lcd_control]); |
paul@69 | 937 | printf("LCD status: %08x\n", (unsigned int) _regs[Lcd_status]); |
paul@69 | 938 | printf("OSD config: %08x\n", (unsigned int) _regs[Osd_config]); |
paul@69 | 939 | printf("OSD status: %08x\n", (unsigned int) _regs[Osd_status]); |
paul@69 | 940 | } |
paul@69 | 941 | |
paul@69 | 942 | // Set the interrupt for controller-related events. |
paul@69 | 943 | |
paul@69 | 944 | void |
paul@69 | 945 | Lcd_jz4740_chip::set_irq(l4_cap_idx_t irq, enum Jz4740_lcd_irq_condition conditions) |
paul@69 | 946 | { |
paul@69 | 947 | _irq = irq; |
paul@69 | 948 | _irq_conditions = conditions; |
paul@69 | 949 | } |
paul@69 | 950 | |
paul@69 | 951 | // Wait for an interrupt condition. |
paul@69 | 952 | |
paul@69 | 953 | long |
paul@69 | 954 | Lcd_jz4740_chip::wait_for_irq() |
paul@69 | 955 | { |
paul@69 | 956 | long err; |
paul@69 | 957 | l4_msgtag_t tag; |
paul@69 | 958 | |
paul@69 | 959 | _regs[Lcd_status] = _regs[Lcd_status] & ~(_status_irq()); |
paul@69 | 960 | |
paul@69 | 961 | // Wait for a condition. |
paul@69 | 962 | |
paul@69 | 963 | printf("Waiting for IRQ...\n"); |
paul@69 | 964 | tag = l4_irq_receive(_irq, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4util_micros2l4to(1000000))); |
paul@69 | 965 | printf("LCD status: %08x\n", (unsigned int) _regs[Lcd_status]); |
paul@69 | 966 | printf("OSD status: %08x\n", (unsigned int) _regs[Osd_status]); |
paul@69 | 967 | printf("LCD control: %08x\n", (unsigned int) _regs[Lcd_control]); |
paul@69 | 968 | printf("LCD command: %08x\n", (unsigned int) _regs[Command_0]); |
paul@69 | 969 | printf("LCD IRQ id: %08x\n", (unsigned int) _regs[Lcd_irq_id]); |
paul@69 | 970 | printf("LCD descriptor: %08x\n", (unsigned int) _regs[Desc_address_0]); |
paul@69 | 971 | printf("LCD source: %08x\n", (unsigned int) _regs[Source_address_0]); |
paul@69 | 972 | printf("LCD frame id: %08x\n", (unsigned int) _regs[Frame_id_0]); |
paul@69 | 973 | |
paul@69 | 974 | // Return errors immediately. |
paul@69 | 975 | |
paul@69 | 976 | err = l4_ipc_error(tag, l4_utcb()); |
paul@69 | 977 | if (err) |
paul@69 | 978 | return err; |
paul@69 | 979 | |
paul@69 | 980 | // Acknowledge interrupts. |
paul@69 | 981 | |
paul@69 | 982 | _regs[Lcd_status] = _regs[Lcd_status] & ~(_status_irq()); |
paul@69 | 983 | |
paul@69 | 984 | return L4_EOK; |
paul@0 | 985 | } |
paul@0 | 986 | |
paul@0 | 987 | |
paul@0 | 988 | |
paul@0 | 989 | // C language interface functions. |
paul@0 | 990 | |
paul@0 | 991 | void * |
paul@0 | 992 | jz4740_lcd_init(l4_addr_t lcd_base, struct Jz4740_lcd_panel *panel) |
paul@0 | 993 | { |
paul@0 | 994 | return (void *) new Lcd_jz4740_chip(lcd_base, panel); |
paul@0 | 995 | } |
paul@0 | 996 | |
paul@0 | 997 | void |
paul@0 | 998 | jz4740_lcd_config(void *lcd, struct Jz4740_lcd_descriptor *desc_vaddr, |
paul@0 | 999 | struct Jz4740_lcd_descriptor *desc_paddr, |
paul@0 | 1000 | l4_addr_t fb_paddr) |
paul@0 | 1001 | { |
paul@0 | 1002 | static_cast<Lcd_jz4740_chip *>(lcd)->config(desc_vaddr, desc_paddr, fb_paddr); |
paul@0 | 1003 | } |
paul@0 | 1004 | |
paul@0 | 1005 | void |
paul@69 | 1006 | jz4740_lcd_set_irq(void *lcd, l4_cap_idx_t irq, enum Jz4740_lcd_irq_condition conditions) |
paul@69 | 1007 | { |
paul@69 | 1008 | static_cast<Lcd_jz4740_chip *>(lcd)->set_irq(irq, conditions); |
paul@69 | 1009 | } |
paul@69 | 1010 | |
paul@69 | 1011 | long |
paul@69 | 1012 | jz4740_lcd_wait_for_irq(void *lcd) |
paul@69 | 1013 | { |
paul@69 | 1014 | return static_cast<Lcd_jz4740_chip *>(lcd)->wait_for_irq(); |
paul@69 | 1015 | } |
paul@69 | 1016 | |
paul@69 | 1017 | void |
paul@0 | 1018 | jz4740_lcd_disable(void *lcd) |
paul@0 | 1019 | { |
paul@0 | 1020 | static_cast<Lcd_jz4740_chip *>(lcd)->disable(); |
paul@0 | 1021 | } |
paul@0 | 1022 | |
paul@0 | 1023 | void |
paul@0 | 1024 | jz4740_lcd_disable_quick(void *lcd) |
paul@0 | 1025 | { |
paul@0 | 1026 | static_cast<Lcd_jz4740_chip *>(lcd)->disable_quick(); |
paul@0 | 1027 | } |
paul@0 | 1028 | |
paul@0 | 1029 | void |
paul@0 | 1030 | jz4740_lcd_enable(void *lcd) |
paul@0 | 1031 | { |
paul@0 | 1032 | static_cast<Lcd_jz4740_chip *>(lcd)->enable(); |
paul@0 | 1033 | } |
paul@0 | 1034 | |
paul@0 | 1035 | int |
paul@69 | 1036 | jz4740_lcd_enabled(void *lcd) |
paul@69 | 1037 | { |
paul@69 | 1038 | return (int) static_cast<Lcd_jz4740_chip *>(lcd)->enabled(); |
paul@69 | 1039 | } |
paul@69 | 1040 | |
paul@69 | 1041 | int |
paul@0 | 1042 | jz4740_lcd_get_pixel_clock(void *lcd) |
paul@0 | 1043 | { |
paul@0 | 1044 | return static_cast<Lcd_jz4740_chip *>(lcd)->get_pixel_clock(); |
paul@0 | 1045 | } |
paul@0 | 1046 | |
paul@69 | 1047 | l4_size_t |
paul@69 | 1048 | jz4740_lcd_get_descriptors_size(void *lcd) |
paul@69 | 1049 | { |
paul@69 | 1050 | return static_cast<Lcd_jz4740_chip *>(lcd)->get_descriptors_size(); |
paul@69 | 1051 | } |
paul@69 | 1052 | |
paul@69 | 1053 | l4_size_t |
paul@69 | 1054 | jz4740_lcd_get_screen_size(void *lcd) |
paul@69 | 1055 | { |
paul@69 | 1056 | return static_cast<Lcd_jz4740_chip *>(lcd)->get_screen_size(); |
paul@69 | 1057 | } |
paul@69 | 1058 | |
paul@0 | 1059 | l4_addr_t |
paul@0 | 1060 | jz4740_lcd_get_palette(void *lcd, l4_addr_t base) |
paul@0 | 1061 | { |
paul@0 | 1062 | return static_cast<Lcd_jz4740_chip *>(lcd)->get_palette(base); |
paul@0 | 1063 | } |
paul@0 | 1064 | |
paul@0 | 1065 | void |
paul@0 | 1066 | jz4740_lcd_init_palette(void *lcd, l4_addr_t palette) |
paul@0 | 1067 | { |
paul@0 | 1068 | static_cast<Lcd_jz4740_chip *>(lcd)->init_palette(palette); |
paul@0 | 1069 | } |