paul@62 | 1 | /* |
paul@62 | 2 | * Access the HDMI I2C peripheral on the MIPS Creator CI20 board. |
paul@65 | 3 | * |
paul@65 | 4 | * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk> |
paul@65 | 5 | * |
paul@65 | 6 | * This program is free software; you can redistribute it and/or |
paul@65 | 7 | * modify it under the terms of the GNU General Public License as |
paul@65 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@65 | 9 | * the License, or (at your option) any later version. |
paul@65 | 10 | * |
paul@65 | 11 | * This program is distributed in the hope that it will be useful, |
paul@65 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@65 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@65 | 14 | * GNU General Public License for more details. |
paul@65 | 15 | * |
paul@65 | 16 | * You should have received a copy of the GNU General Public License |
paul@65 | 17 | * along with this program; if not, write to the Free Software |
paul@65 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@65 | 19 | * Boston, MA 02110-1301, USA |
paul@62 | 20 | */ |
paul@62 | 21 | |
paul@62 | 22 | #include <l4/devices/cpm-jz4780.h> |
paul@62 | 23 | #include <l4/devices/gpio-jz4780.h> |
paul@62 | 24 | #include <l4/devices/hdmi-jz4780.h> |
paul@64 | 25 | |
paul@75 | 26 | #include <l4/devices/lcd-jz4780.h> |
paul@64 | 27 | #include <l4/devices/lcd-jz4740-config.h> |
paul@64 | 28 | #include <l4/devices/lcd-jz4740-panel.h> |
paul@64 | 29 | |
paul@62 | 30 | #include <l4/devices/memory.h> |
paul@74 | 31 | |
paul@74 | 32 | #include <l4/re/c/dataspace.h> |
paul@74 | 33 | #include <l4/re/c/mem_alloc.h> |
paul@74 | 34 | #include <l4/re/c/rm.h> |
paul@74 | 35 | #include <l4/re/c/util/cap_alloc.h> |
paul@62 | 36 | #include <l4/re/env.h> |
paul@74 | 37 | |
paul@74 | 38 | #include <l4/sys/cache.h> |
paul@62 | 39 | #include <l4/sys/factory.h> |
paul@62 | 40 | #include <l4/sys/icu.h> |
paul@62 | 41 | #include <l4/sys/ipc.h> |
paul@62 | 42 | #include <l4/sys/irq.h> |
paul@62 | 43 | #include <l4/sys/rcv_endpoint.h> |
paul@74 | 44 | |
paul@74 | 45 | #include <l4/io/io.h> |
paul@74 | 46 | #include <l4/libedid/edid.h> |
paul@62 | 47 | #include <l4/vbus/vbus.h> |
paul@74 | 48 | |
paul@62 | 49 | #include <stdio.h> |
paul@62 | 50 | #include <unistd.h> |
paul@62 | 51 | #include <stdint.h> |
paul@62 | 52 | #include <string.h> |
paul@74 | 53 | #include <stdlib.h> |
paul@62 | 54 | |
paul@62 | 55 | |
paul@62 | 56 | |
paul@62 | 57 | enum { |
paul@62 | 58 | DDCSCL = 24, /* via PORTF */ |
paul@62 | 59 | DDCSDA = 25, /* via PORTF */ |
paul@62 | 60 | }; |
paul@62 | 61 | |
paul@62 | 62 | |
paul@62 | 63 | |
paul@64 | 64 | /* Test panel. */ |
paul@64 | 65 | |
paul@64 | 66 | static struct Jz4740_lcd_panel panel = { |
paul@64 | 67 | .config = ( |
paul@64 | 68 | Jz4740_lcd_mode_tft_generic |
paul@74 | 69 | | Jz4740_lcd_bpp_24 |
paul@74 | 70 | | Jz4740_lcd_desc_8_word |
paul@74 | 71 | | Jz4740_lcd_underrun_recover |
paul@74 | 72 | | Jz4740_lcd_ps_disabled |
paul@74 | 73 | | Jz4740_lcd_cls_disabled |
paul@74 | 74 | | Jz4740_lcd_spl_disabled |
paul@74 | 75 | | Jz4740_lcd_rev_disabled |
paul@64 | 76 | | Jz4740_lcd_pclock_negative |
paul@64 | 77 | | Jz4740_lcd_hsync_positive |
paul@64 | 78 | | Jz4740_lcd_vsync_positive |
paul@64 | 79 | | Jz4740_lcd_de_positive), |
paul@64 | 80 | |
paul@64 | 81 | .width = 1280, |
paul@64 | 82 | .height = 1024, |
paul@74 | 83 | .bpp = 24, |
paul@64 | 84 | .frame_rate = 60, |
paul@64 | 85 | .hsync = 112, |
paul@64 | 86 | .vsync = 3, |
paul@74 | 87 | .line_start = 248, // back porch (blanking - hsync - offset) |
paul@64 | 88 | .line_end = 48, // front porch (sync offset) |
paul@74 | 89 | .frame_start = 36, // back porch (blanking - vsync - offset) |
paul@64 | 90 | .frame_end = 3, // front porch (sync offset) |
paul@64 | 91 | }; |
paul@64 | 92 | |
paul@64 | 93 | |
paul@64 | 94 | |
paul@62 | 95 | /* Device and resource discovery. */ |
paul@62 | 96 | |
paul@62 | 97 | static long item_in_range(long start, long end, long index) |
paul@62 | 98 | { |
paul@62 | 99 | if (start < end) |
paul@62 | 100 | return start + index; |
paul@62 | 101 | else |
paul@62 | 102 | return start - index; |
paul@62 | 103 | } |
paul@62 | 104 | |
paul@62 | 105 | static void show_timings(uint8_t *buf) |
paul@62 | 106 | { |
paul@62 | 107 | unsigned int width, height; |
paul@62 | 108 | |
paul@62 | 109 | /* Attempt to decode EDID information. */ |
paul@62 | 110 | |
paul@62 | 111 | libedid_prefered_resolution(buf, &width, &height); |
paul@62 | 112 | printf("Preferred resolution: %d x %d\n", width, height); |
paul@62 | 113 | |
paul@62 | 114 | libedid_dump_standard_timings(buf); |
paul@62 | 115 | } |
paul@62 | 116 | |
paul@62 | 117 | int main(void) |
paul@62 | 118 | { |
paul@62 | 119 | long err; |
paul@62 | 120 | |
paul@62 | 121 | /* Buffer for EDID data. */ |
paul@62 | 122 | |
paul@62 | 123 | uint8_t edid[128]; |
paul@62 | 124 | unsigned int length = 0, i; |
paul@62 | 125 | |
paul@62 | 126 | /* Version details. */ |
paul@62 | 127 | |
paul@62 | 128 | uint8_t hdmi_major; |
paul@62 | 129 | uint16_t hdmi_minor; |
paul@74 | 130 | const struct Phy_capabilities *phy_def; |
paul@62 | 131 | |
paul@62 | 132 | /* Peripheral memory. */ |
paul@62 | 133 | |
paul@62 | 134 | l4_addr_t cpm_base = 0, cpm_base_end = 0; |
paul@62 | 135 | l4_addr_t gpio_base = 0, gpio_base_end = 0; |
paul@62 | 136 | l4_addr_t hdmi_base = 0, hdmi_base_end = 0; |
paul@64 | 137 | l4_addr_t lcd_base = 0, lcd_base_end = 0; |
paul@62 | 138 | l4_addr_t port_f, port_f_end; |
paul@62 | 139 | |
paul@62 | 140 | /* Peripheral abstractions. */ |
paul@62 | 141 | |
paul@62 | 142 | void *cpm; |
paul@62 | 143 | void *gpio_port_f; |
paul@62 | 144 | void *hdmi; |
paul@64 | 145 | void *lcd; |
paul@62 | 146 | |
paul@74 | 147 | /* Allocated memory. */ |
paul@74 | 148 | |
paul@74 | 149 | l4_cap_idx_t desc_mem, fb_mem; |
paul@74 | 150 | l4_size_t desc_size, desc_psize, fb_size, fb_psize; |
paul@74 | 151 | l4_addr_t desc_addr, desc_paddr, fb_addr, fb_paddr; |
paul@74 | 152 | unsigned char *picture; |
paul@74 | 153 | unsigned char *fb_picture, *fb_picture_row; |
paul@74 | 154 | unsigned int x, y; |
paul@74 | 155 | |
paul@62 | 156 | /* Access to IRQs. */ |
paul@62 | 157 | |
paul@62 | 158 | l4_uint32_t hdmi_irq_start = 0, hdmi_irq_end = 0; |
paul@64 | 159 | l4_uint32_t lcd_irq_start = 0, lcd_irq_end = 0; |
paul@64 | 160 | l4_cap_idx_t icucap, hdmi_irq, lcd_irq; |
paul@62 | 161 | |
paul@74 | 162 | /* Capability allocation. */ |
paul@74 | 163 | |
paul@74 | 164 | desc_mem = l4re_util_cap_alloc(); |
paul@74 | 165 | fb_mem = l4re_util_cap_alloc(); |
paul@64 | 166 | hdmi_irq = l4re_util_cap_alloc(); |
paul@64 | 167 | lcd_irq = l4re_util_cap_alloc(); |
paul@62 | 168 | icucap = l4re_env_get_cap("icu"); |
paul@62 | 169 | |
paul@62 | 170 | if (l4_is_invalid_cap(icucap)) |
paul@62 | 171 | { |
paul@62 | 172 | printf("No 'icu' capability available in the virtual bus.\n"); |
paul@62 | 173 | return 1; |
paul@62 | 174 | } |
paul@62 | 175 | |
paul@74 | 176 | if (l4_is_invalid_cap(desc_mem) || l4_is_invalid_cap(fb_mem) || |
paul@74 | 177 | l4_is_invalid_cap(hdmi_irq) || l4_is_invalid_cap(lcd_irq)) |
paul@62 | 178 | { |
paul@74 | 179 | printf("Capabilities could not be reserved.\n"); |
paul@62 | 180 | return 1; |
paul@62 | 181 | } |
paul@62 | 182 | |
paul@62 | 183 | /* Obtain resource details describing the interrupt for HDMI I2C. */ |
paul@62 | 184 | |
paul@62 | 185 | printf("Access IRQ...\n"); |
paul@62 | 186 | |
paul@62 | 187 | if (get_irq("jz4780-hdmi", &hdmi_irq_start, &hdmi_irq_end) < 0) |
paul@62 | 188 | return 1; |
paul@62 | 189 | |
paul@64 | 190 | printf("HDMI IRQ range at %d...%d.\n", hdmi_irq_start, hdmi_irq_end); |
paul@64 | 191 | |
paul@64 | 192 | if (get_irq("jz4780-lcd", &lcd_irq_start, &lcd_irq_end) < 0) |
paul@64 | 193 | return 1; |
paul@64 | 194 | |
paul@64 | 195 | printf("LCD IRQ range at %d...%d.\n", lcd_irq_start, lcd_irq_end); |
paul@62 | 196 | |
paul@62 | 197 | /* Create interrupt objects. */ |
paul@62 | 198 | |
paul@64 | 199 | err = l4_error(l4_factory_create_irq(l4re_global_env->factory, hdmi_irq)) || |
paul@64 | 200 | l4_error(l4_factory_create_irq(l4re_global_env->factory, lcd_irq)); |
paul@62 | 201 | |
paul@62 | 202 | if (err) |
paul@62 | 203 | { |
paul@62 | 204 | printf("Could not create IRQ object: %lx\n", err); |
paul@62 | 205 | return 1; |
paul@62 | 206 | } |
paul@62 | 207 | |
paul@62 | 208 | /* Bind interrupt objects to IRQ numbers. Here, the first HDMI interrupt is |
paul@62 | 209 | bound, this being the general HDMI interrupt. */ |
paul@62 | 210 | |
paul@62 | 211 | err = l4_error(l4_icu_bind(icucap, |
paul@62 | 212 | item_in_range(hdmi_irq_start, hdmi_irq_end, 0), |
paul@64 | 213 | hdmi_irq)) || |
paul@64 | 214 | l4_error(l4_icu_bind(icucap, |
paul@64 | 215 | item_in_range(lcd_irq_start, lcd_irq_end, 0), |
paul@64 | 216 | lcd_irq)); |
paul@62 | 217 | |
paul@62 | 218 | if (err) |
paul@62 | 219 | { |
paul@62 | 220 | printf("Could not bind IRQ to the ICU: %ld\n", err); |
paul@62 | 221 | return 1; |
paul@62 | 222 | } |
paul@62 | 223 | |
paul@74 | 224 | /* Attach ourselves to the interrupt handler with some arbitrary labels. */ |
paul@62 | 225 | |
paul@74 | 226 | err = l4_error(l4_rcv_ep_bind_thread(hdmi_irq, l4re_env()->main_thread, 0x00)) || |
paul@74 | 227 | l4_error(l4_rcv_ep_bind_thread(lcd_irq, l4re_env()->main_thread, 0x10)); |
paul@62 | 228 | |
paul@62 | 229 | if (err) |
paul@62 | 230 | { |
paul@62 | 231 | printf("Could not attach to IRQs: %ld\n", err); |
paul@62 | 232 | return 1; |
paul@62 | 233 | } |
paul@62 | 234 | |
paul@62 | 235 | /* Obtain resource details describing I/O memory. */ |
paul@62 | 236 | |
paul@62 | 237 | printf("Access CPM...\n"); |
paul@62 | 238 | |
paul@62 | 239 | if (get_memory("jz4780-cpm", &cpm_base, &cpm_base_end) < 0) |
paul@62 | 240 | return 1; |
paul@62 | 241 | |
paul@62 | 242 | printf("CPM at 0x%lx...0x%lx.\n", cpm_base, cpm_base_end); |
paul@62 | 243 | |
paul@62 | 244 | printf("Access GPIO...\n"); |
paul@62 | 245 | |
paul@62 | 246 | if (get_memory("jz4780-gpio", &gpio_base, &gpio_base_end) < 0) |
paul@62 | 247 | return 1; |
paul@62 | 248 | |
paul@62 | 249 | printf("GPIO at 0x%lx...0x%lx.\n", gpio_base, gpio_base_end); |
paul@62 | 250 | |
paul@62 | 251 | printf("Access HDMI...\n"); |
paul@62 | 252 | |
paul@62 | 253 | if (get_memory("jz4780-hdmi", &hdmi_base, &hdmi_base_end) < 0) |
paul@62 | 254 | return 1; |
paul@62 | 255 | |
paul@62 | 256 | printf("HDMI at 0x%lx...0x%lx.\n", hdmi_base, hdmi_base_end); |
paul@62 | 257 | |
paul@64 | 258 | printf("Access LCD...\n"); |
paul@64 | 259 | |
paul@64 | 260 | if (get_memory("jz4780-lcd", &lcd_base, &lcd_base_end) < 0) |
paul@64 | 261 | return 1; |
paul@64 | 262 | |
paul@64 | 263 | printf("LCD at 0x%lx...0x%lx.\n", lcd_base, lcd_base_end); |
paul@64 | 264 | |
paul@62 | 265 | /* Obtain CPM object. */ |
paul@62 | 266 | |
paul@62 | 267 | cpm = jz4780_cpm_init(cpm_base); |
paul@62 | 268 | |
paul@62 | 269 | printf("VPLL frequency: %d\n", jz4780_cpm_get_vpll_frequency(cpm)); |
paul@62 | 270 | printf("HDMI divider: %d\n", jz4780_cpm_get_hdmi_divider(cpm)); |
paul@62 | 271 | printf("HDMI frequency: %d\n", jz4780_cpm_get_hdmi_frequency(cpm)); |
paul@62 | 272 | |
paul@62 | 273 | jz4780_cpm_stop_hdmi(cpm); |
paul@62 | 274 | jz4780_cpm_set_hdmi_frequency(cpm, 27000000); |
paul@62 | 275 | |
paul@62 | 276 | printf("HDMI divider: %d\n", jz4780_cpm_get_hdmi_divider(cpm)); |
paul@62 | 277 | printf("HDMI frequency: %d\n", jz4780_cpm_get_hdmi_frequency(cpm)); |
paul@62 | 278 | |
paul@62 | 279 | jz4780_cpm_start_hdmi(cpm); |
paul@62 | 280 | |
paul@62 | 281 | /* Configure pins. */ |
paul@62 | 282 | |
paul@62 | 283 | port_f = gpio_base + 0x500; |
paul@62 | 284 | port_f_end = port_f + 0x100; |
paul@62 | 285 | |
paul@62 | 286 | printf("PORTF at 0x%lx...0x%lx.\n", port_f, port_f_end); |
paul@62 | 287 | |
paul@62 | 288 | gpio_port_f = jz4780_gpio_init(port_f, port_f_end, 32, 0x7fa7f00f, 0x00580ff0); |
paul@62 | 289 | |
paul@62 | 290 | printf("Set up GPIO pins...\n"); |
paul@62 | 291 | |
paul@62 | 292 | jz4780_gpio_config_pad(gpio_port_f, DDCSCL, Function_alt, 0); |
paul@62 | 293 | jz4780_gpio_config_pad(gpio_port_f, DDCSDA, Function_alt, 0); |
paul@62 | 294 | |
paul@62 | 295 | /* Obtain HDMI reference. */ |
paul@62 | 296 | |
paul@62 | 297 | printf("Set up HDMI...\n"); |
paul@62 | 298 | |
paul@74 | 299 | hdmi = jz4780_hdmi_init(hdmi_base, hdmi_base_end, hdmi_irq, &panel); |
paul@62 | 300 | |
paul@62 | 301 | printf("Read version...\n"); |
paul@62 | 302 | |
paul@62 | 303 | jz4780_hdmi_get_version(hdmi, &hdmi_major, &hdmi_minor); |
paul@62 | 304 | |
paul@62 | 305 | printf("HDMI version is %x.%03x\n", hdmi_major, hdmi_minor); |
paul@62 | 306 | |
paul@74 | 307 | jz4780_hdmi_get_phy_capabilities(hdmi, &phy_def); |
paul@74 | 308 | |
paul@74 | 309 | printf("PHY type: %s\n", phy_def->name); |
paul@74 | 310 | |
paul@65 | 311 | printf("Connected: %s\n", jz4780_hdmi_connected(hdmi) ? "yes" : "no"); |
paul@65 | 312 | |
paul@65 | 313 | while (!jz4780_hdmi_connected(hdmi)) |
paul@65 | 314 | jz4780_hdmi_wait_for_connection(hdmi); |
paul@65 | 315 | |
paul@62 | 316 | printf("Read EDID...\n"); |
paul@62 | 317 | |
paul@62 | 318 | jz4780_hdmi_i2c_set_address(hdmi, 0x50); |
paul@62 | 319 | length = jz4780_hdmi_i2c_read(hdmi, edid, 128); |
paul@62 | 320 | |
paul@62 | 321 | if (length) |
paul@62 | 322 | { |
paul@62 | 323 | for (i = 0; i < length; i++) |
paul@62 | 324 | printf("%02x%c", edid[i], ((i % 16) != 15) ? ' ' : '\n'); |
paul@62 | 325 | } |
paul@62 | 326 | |
paul@62 | 327 | show_timings(edid); |
paul@62 | 328 | |
paul@64 | 329 | /* Obtain LCD reference. */ |
paul@64 | 330 | |
paul@64 | 331 | printf("Set up LCD...\n"); |
paul@64 | 332 | |
paul@75 | 333 | lcd = jz4780_lcd_init(lcd_base, &panel); |
paul@64 | 334 | |
paul@64 | 335 | /* Test initialisation with a frequency appropriate for the test panel. */ |
paul@64 | 336 | |
paul@74 | 337 | printf("LCD source: %d\n", jz4780_cpm_get_lcd_source(cpm)); |
paul@64 | 338 | printf("LCD divider: %d\n", jz4780_cpm_get_lcd_pixel_divider(cpm)); |
paul@64 | 339 | printf("LCD frequency: %d\n", jz4780_cpm_get_lcd_pixel_frequency(cpm)); |
paul@64 | 340 | printf("Desired frequency: %d\n", jz4740_lcd_get_pixel_clock(lcd)); |
paul@62 | 341 | |
paul@64 | 342 | jz4780_cpm_stop_lcd(cpm); |
paul@64 | 343 | jz4780_cpm_set_lcd_frequencies(cpm, jz4740_lcd_get_pixel_clock(lcd), 3); |
paul@64 | 344 | |
paul@74 | 345 | printf("LCD source: %d\n", jz4780_cpm_get_lcd_source(cpm)); |
paul@64 | 346 | printf("LCD divider: %d\n", jz4780_cpm_get_lcd_pixel_divider(cpm)); |
paul@64 | 347 | printf("LCD frequency: %d\n", jz4780_cpm_get_lcd_pixel_frequency(cpm)); |
paul@74 | 348 | printf("AHB0 frequency: %d\n", jz4780_cpm_get_hclock0_frequency(cpm)); |
paul@74 | 349 | |
paul@74 | 350 | /* With the LCD pixel clock set up, bring up the HDMI. */ |
paul@74 | 351 | |
paul@74 | 352 | printf("Enable HDMI output...\n"); |
paul@74 | 353 | |
paul@74 | 354 | jz4780_hdmi_enable(hdmi, jz4780_cpm_get_lcd_pixel_frequency(cpm)); |
paul@74 | 355 | |
paul@74 | 356 | /* Allocate descriptors and framebuffer at 2**8 == 256 byte == 64 word alignment. */ |
paul@74 | 357 | |
paul@74 | 358 | desc_size = jz4740_lcd_get_descriptors_size(lcd); |
paul@74 | 359 | fb_size = jz4740_lcd_get_screen_size(lcd); |
paul@74 | 360 | |
paul@74 | 361 | if (l4re_ma_alloc_align(desc_size, desc_mem, L4RE_MA_CONTINUOUS | L4RE_MA_PINNED, 8) || |
paul@74 | 362 | l4re_ma_alloc_align(fb_size, fb_mem, L4RE_MA_CONTINUOUS | L4RE_MA_PINNED, 8)) |
paul@74 | 363 | { |
paul@74 | 364 | printf("Could not allocate memory.\n"); |
paul@74 | 365 | return 1; |
paul@74 | 366 | } |
paul@74 | 367 | |
paul@74 | 368 | if (l4re_rm_attach((void **) &desc_addr, desc_size, |
paul@74 | 369 | L4RE_RM_SEARCH_ADDR | L4RE_RM_EAGER_MAP, |
paul@74 | 370 | desc_mem, 0, L4_PAGESHIFT) || |
paul@74 | 371 | l4re_rm_attach((void **) &fb_addr, fb_size, |
paul@74 | 372 | L4RE_RM_SEARCH_ADDR | L4RE_RM_EAGER_MAP, |
paul@74 | 373 | fb_mem, 0, L4_PAGESHIFT)) |
paul@74 | 374 | { |
paul@74 | 375 | printf("Could not map memory.\n"); |
paul@74 | 376 | return 1; |
paul@74 | 377 | } |
paul@74 | 378 | |
paul@74 | 379 | if (l4re_ds_phys(desc_mem, 0, &desc_paddr, &desc_psize) || |
paul@74 | 380 | l4re_ds_phys(fb_mem, 0, &fb_paddr, &fb_psize)) |
paul@74 | 381 | { |
paul@74 | 382 | printf("Could not get physical addresses for memory.\n"); |
paul@74 | 383 | return 1; |
paul@74 | 384 | } |
paul@74 | 385 | |
paul@74 | 386 | printf("Descriptors at %lx/%lx, size %d/%d.\n", desc_addr, desc_paddr, desc_size, desc_psize); |
paul@74 | 387 | printf("Framebuffer at %lx/%lx, size %d/%d.\n", fb_addr, fb_paddr, fb_size, fb_psize); |
paul@74 | 388 | |
paul@74 | 389 | //memset((void *) fb_addr, 0x7f, fb_size); |
paul@74 | 390 | |
paul@74 | 391 | picture = (unsigned char *) malloc(gimp_image.width * gimp_image.height * gimp_image.bytes_per_pixel); |
paul@74 | 392 | |
paul@74 | 393 | GIMP_IMAGE_RUN_LENGTH_DECODE(picture, |
paul@74 | 394 | gimp_image.rle_pixel_data, |
paul@74 | 395 | gimp_image.width * gimp_image.height, |
paul@74 | 396 | gimp_image.bytes_per_pixel); |
paul@74 | 397 | |
paul@74 | 398 | fb_picture_row = (unsigned char *) fb_addr; |
paul@74 | 399 | |
paul@74 | 400 | for (y = 0; y < gimp_image.height; y++) |
paul@74 | 401 | { |
paul@74 | 402 | fb_picture = fb_picture_row; |
paul@74 | 403 | |
paul@74 | 404 | for (x = 0; x < gimp_image.width; x++) |
paul@74 | 405 | { |
paul@74 | 406 | *(fb_picture + 2) = *picture++; |
paul@74 | 407 | *(fb_picture + 1) = *picture++; |
paul@74 | 408 | *fb_picture = *picture++; |
paul@74 | 409 | *(fb_picture + 3) = 0; |
paul@74 | 410 | fb_picture += 4; |
paul@74 | 411 | } |
paul@74 | 412 | |
paul@74 | 413 | fb_picture_row += jz4740_lcd_get_line_size(lcd); |
paul@74 | 414 | } |
paul@74 | 415 | |
paul@74 | 416 | l4_cache_clean_data((unsigned long) fb_addr, (unsigned long) fb_addr + fb_size); |
paul@74 | 417 | |
paul@74 | 418 | printf("Start LCD clock and initialise LCD...\n"); |
paul@64 | 419 | |
paul@64 | 420 | jz4780_cpm_start_lcd(cpm); |
paul@74 | 421 | l4_sleep(1); // 1ms == 1000us |
paul@74 | 422 | |
paul@74 | 423 | jz4740_lcd_disable(lcd); |
paul@74 | 424 | |
paul@74 | 425 | jz4740_lcd_set_irq(lcd, lcd_irq, Lcd_irq_frame_end); |
paul@74 | 426 | |
paul@74 | 427 | jz4740_lcd_config(lcd, (struct Jz4740_lcd_descriptor *) desc_addr, |
paul@74 | 428 | (struct Jz4740_lcd_descriptor *) desc_paddr, |
paul@74 | 429 | fb_paddr); |
paul@74 | 430 | |
paul@74 | 431 | jz4740_lcd_enable(lcd); |
paul@74 | 432 | |
paul@74 | 433 | printf("LCD enabled: %s\n", jz4740_lcd_enabled(lcd) ? "yes" : "no"); |
paul@74 | 434 | |
paul@74 | 435 | printf("Wait for interrupt conditions...\n"); |
paul@74 | 436 | |
paul@74 | 437 | for (i = 0; i < 30000; i++) |
paul@74 | 438 | { |
paul@74 | 439 | if (jz4740_lcd_wait_for_irq(lcd)) |
paul@74 | 440 | continue; |
paul@74 | 441 | |
paul@74 | 442 | if (!(i % 60)) |
paul@74 | 443 | printf("IRQ #%d\n", i); |
paul@74 | 444 | } |
paul@64 | 445 | |
paul@64 | 446 | /* Detach from the interrupts. */ |
paul@64 | 447 | |
paul@64 | 448 | err = l4_error(l4_irq_detach(hdmi_irq)) || |
paul@64 | 449 | l4_error(l4_irq_detach(lcd_irq)); |
paul@62 | 450 | |
paul@62 | 451 | if (err) |
paul@62 | 452 | printf("Error detaching from IRQ: %ld\n", err); |
paul@62 | 453 | |
paul@62 | 454 | printf("Done.\n"); |
paul@62 | 455 | |
paul@62 | 456 | return 0; |
paul@62 | 457 | } |