2011-04-24 05:26:42 +03:00
|
|
|
/*
|
2011-04-24 08:56:56 +03:00
|
|
|
* ubb-vga.c - Output video on UBB with more or less VGA timing
|
2011-04-24 05:26:42 +03:00
|
|
|
*
|
|
|
|
* Written 2011 by Werner Almesberger
|
|
|
|
* Copyright 2011 Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WARNING: this program does very nasty things to the Ben and it doesn't
|
|
|
|
* like company. In particular, it resents:
|
|
|
|
*
|
|
|
|
* - the MMC driver - disable it with
|
|
|
|
* echo jz4740-mmc.0 >/sys/bus/platform/drivers/jz4740-mmc/unbind
|
|
|
|
* - the AT86RF230/1 kernel driver - use a kernel that doesn't have it
|
|
|
|
* - anything that accesses the screen - kill GUI, X server, etc.
|
|
|
|
* - the screen blanker - either disable it or make sure the screen stays
|
|
|
|
* dark, e.g., with
|
|
|
|
* echo 1 >/sys/devices/platform/jz4740-fb/graphics/fb0/blank
|
|
|
|
* - probably a fair number of other daemons and things as well - best to
|
|
|
|
* kill them all.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
#include "regs4740.h"
|
|
|
|
#include "ubb-vga.h"
|
2011-04-24 05:26:42 +03:00
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
|
|
|
|
#define REG_BASE_PTR base
|
|
|
|
|
|
|
|
static volatile void *base;
|
|
|
|
|
|
|
|
static int bad;
|
2011-05-07 02:19:13 +03:00
|
|
|
static int keep_lcd = 0;
|
2011-04-24 18:12:36 +03:00
|
|
|
|
|
|
|
|
2011-05-01 21:08:02 +03:00
|
|
|
#define US(us) ((uint16_t) ((us)*112))
|
|
|
|
|
|
|
|
|
|
|
|
static const struct mode mode_db[] = {
|
2011-05-02 02:59:38 +03:00
|
|
|
/* name xres yres clkdiv vfront hsync hback htotal */
|
|
|
|
/* vsync vback */
|
2011-05-03 16:19:16 +03:00
|
|
|
{ "640x480", 640, 480, 12, 2, 32, 14, US(2.80), US(1.30), US(32.1) },
|
2011-05-02 11:16:19 +03:00
|
|
|
{ "640x480/58", 640, 480, 12, 2, 10, 33, US(3.81), US(1.91), US(32.7) },
|
2011-05-03 16:19:16 +03:00
|
|
|
{ "640x480/61", 640, 480, 11, 2, 9, 29, US(2.50), US(4.06), US(31.5) },
|
2011-05-02 11:16:19 +03:00
|
|
|
{ "640x480/70", 640, 480, 9, 2, 8, 29, US(1.90), US(2.06), US(24.8) },
|
2011-05-02 05:00:35 +03:00
|
|
|
|
2011-05-02 11:25:15 +03:00
|
|
|
{ "800x600/54", 800, 600, 8, 2, 32, 14, US(4.81), US(0.79), US(28.8) },
|
2011-05-02 05:00:35 +03:00
|
|
|
{ "800x600/56", 800, 600, 8, 2, 1, 22, US(2.00), US(3.56), US(28.5) },
|
|
|
|
{ "800x600/72", 800, 600, 5, 3, 1, 27, US(2.14), US(2.70), US(22.0) },
|
2011-05-02 02:59:38 +03:00
|
|
|
|
|
|
|
/* the 1024x768 below is not great but has good parameter tolerance */
|
|
|
|
{ "1024x768", 1024, 768, 8, 2, 32, 14, US(4.51), US(0.79), US(36.0) },
|
2011-05-02 05:00:35 +03:00
|
|
|
/* illustrate underruns (without DMA) */
|
2011-05-02 02:59:38 +03:00
|
|
|
{ "1024x768ur", 1024, 768, 7, 2, 32, 14, US(2.21), US(0.79), US(33.5) },
|
|
|
|
{ "1024x768/53",1024, 768, 5, 2, 32, 14, US(1.31), US(0.79), US(23.1) },
|
2011-05-02 05:00:35 +03:00
|
|
|
{ "1024x768/50",1024, 768, 5, 6, 3, 29, US(2.10), US(2.46), US(24.5) },
|
2011-05-02 02:59:38 +03:00
|
|
|
{ NULL }
|
2011-05-01 21:08:02 +03:00
|
|
|
};
|
|
|
|
|
2011-05-02 05:00:35 +03:00
|
|
|
/*
|
2011-05-02 13:10:52 +03:00
|
|
|
* 640x480: loosely based on the timing from "Build a VGA Monitor
|
|
|
|
* Controller" by Enoch Hwang
|
|
|
|
*
|
|
|
|
*
|
2011-05-02 05:00:35 +03:00
|
|
|
* 640x480/58: http://tinyvga.com/vga-timing/640x480@60Hz
|
|
|
|
*
|
|
|
|
* H: 3.81+0.64+25.42+1.91 us = 31.78 us
|
|
|
|
*
|
|
|
|
* Pixel clock is 25.175 MHz. We have 25.85 MHz, thus:
|
|
|
|
* 25.42/25.75*25.175 = 24.85
|
|
|
|
*
|
|
|
|
* htotal should be 31.77+(24.85-25.175) = 31.445, but we actually need more.
|
|
|
|
* Seems that our hfront is about 1.7 us.
|
|
|
|
*
|
|
|
|
* Observation: bad FIFO jitter.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 640x480/70: http://tinyvga.com/vga-timing/640x480@73Hz
|
|
|
|
*
|
|
|
|
* That's a pretty ugly adaptation. The DMA really seems to dislike the 73 Hz
|
|
|
|
* parameters.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 800x600/54: just a lucky combination
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 800x600/56: http://tinyvga.com/vga-timing/800x600@56Hz
|
|
|
|
*
|
|
|
|
* Note that we have the sync pulses upside-down.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 800x600/7: yet another lucky combination
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 1024x768/50: loosely based on http://tinyvga.com/vga-timing/1024x768@60Hz
|
|
|
|
*/
|
|
|
|
|
2011-05-01 21:08:02 +03:00
|
|
|
|
2011-05-01 21:16:01 +03:00
|
|
|
const struct mode *mode = mode_db;
|
2011-05-01 21:08:02 +03:00
|
|
|
|
2011-05-03 16:19:16 +03:00
|
|
|
static uint32_t clkrt = 0;
|
|
|
|
|
2011-05-01 21:08:02 +03:00
|
|
|
|
2011-04-24 18:12:36 +03:00
|
|
|
/* ----- I/O pin assignment ------------------------------------------------ */
|
|
|
|
|
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
#define DAT0 (1 << 10)
|
|
|
|
#define DAT1 (1 << 11)
|
|
|
|
#define DAT2 (1 << 12)
|
|
|
|
#define DAT3 (1 << 13)
|
|
|
|
#define CMD (1 << 8)
|
|
|
|
#define CLK (1 << 9)
|
|
|
|
|
2011-04-27 22:48:07 +03:00
|
|
|
#define R DAT3
|
2011-04-24 05:26:42 +03:00
|
|
|
#define G DAT0
|
|
|
|
#define B DAT1
|
2011-04-29 20:03:07 +03:00
|
|
|
#define Y DAT2
|
2011-04-24 05:26:42 +03:00
|
|
|
#define HSYNC CMD
|
2011-04-27 22:48:07 +03:00
|
|
|
#define VSYNC CLK
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
|
2011-04-24 18:12:36 +03:00
|
|
|
/* ----- Ben hardware ------------------------------------------------------ */
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
|
2011-04-24 18:12:36 +03:00
|
|
|
#define TIMER 7
|
2011-05-01 18:22:23 +03:00
|
|
|
#define DMA 0
|
2011-05-01 22:41:32 +03:00
|
|
|
#define KEY_MASK 0x5f70000
|
2011-04-24 06:10:23 +03:00
|
|
|
|
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
static uint32_t old_icmr;
|
|
|
|
static uint32_t old_clkgr;
|
2011-05-07 02:19:13 +03:00
|
|
|
static uint32_t old_lcdctrl;
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void disable_interrupts(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* @@@ Race condition alert ! If we get interrupted/preempted between
|
|
|
|
* reading ICMR and masking all interrupts, and the code that runs
|
|
|
|
* between these two operations changes ICMR, then we may set an
|
|
|
|
* incorrect mask when restoring interrupts, which may hang the system.
|
|
|
|
*/
|
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
old_icmr = ICMR;
|
|
|
|
ICMSR = 0xffffffff;
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void enable_interrupts(void)
|
|
|
|
{
|
2011-04-29 20:03:07 +03:00
|
|
|
ICMCR = ~old_icmr;
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-04-24 18:12:36 +03:00
|
|
|
* @@@ Disabling the LCD clock will hang operations that depend on the LCD
|
2011-04-24 05:26:42 +03:00
|
|
|
* subsystem to advance. This includes the screen saver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void disable_lcd(void)
|
|
|
|
{
|
2011-04-29 20:03:07 +03:00
|
|
|
old_clkgr = CLKGR;
|
|
|
|
CLKGR = old_clkgr | 1 << 10;
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void enable_lcd(void)
|
|
|
|
{
|
2011-04-29 20:03:07 +03:00
|
|
|
CLKGR = old_clkgr;
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-07 02:19:13 +03:00
|
|
|
static void tame_lcd(void)
|
|
|
|
{
|
|
|
|
old_lcdctrl = LCDCTRL;
|
|
|
|
/* LCDCTRL.BST = 0, for 4 word burst, the shortest available */
|
|
|
|
LCDCTRL = old_lcdctrl & 0xfffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void restore_lcd(void)
|
|
|
|
{
|
|
|
|
LCDCTRL = old_lcdctrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
static void get_timer(void)
|
|
|
|
{
|
2011-04-29 20:03:07 +03:00
|
|
|
TSCR = 1 << TIMER; /* enable clock */
|
|
|
|
TCSR(TIMER) = 1; /* count at PCLK/1 */
|
|
|
|
TDFR(TIMER) = 0xffff; /* count to 0xffff */
|
|
|
|
TESR = 1 << TIMER;
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void release_timer(void)
|
|
|
|
{
|
2011-04-29 20:03:07 +03:00
|
|
|
TECR = 1 << TIMER;
|
|
|
|
TSSR = 1 << TIMER;
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
void *map(off_t addr, size_t size)
|
2011-04-24 05:26:42 +03:00
|
|
|
{
|
|
|
|
int fd;
|
2011-04-24 06:10:23 +03:00
|
|
|
void *mem;
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
fd = open("/dev/mem", O_RDWR | O_SYNC);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("/dev/mem");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-04-24 06:10:23 +03:00
|
|
|
mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, addr);
|
|
|
|
if (mem == MAP_FAILED) {
|
2011-04-24 05:26:42 +03:00
|
|
|
perror("mmap");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-04-24 06:10:23 +03:00
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ben_setup(void)
|
|
|
|
{
|
2011-04-30 04:22:51 +03:00
|
|
|
base = map(SOC_BASE, REG_WINDOW);
|
2011-04-24 06:10:23 +03:00
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
/* ----- Delay logic ------------------------------------------------------- */
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
|
2011-05-02 12:11:29 +03:00
|
|
|
static void delay(uint16_t cycles)
|
2011-04-24 05:26:42 +03:00
|
|
|
{
|
2011-05-02 12:11:29 +03:00
|
|
|
static uint16_t next = 0;
|
2011-05-03 18:09:24 +03:00
|
|
|
uint16_t t;
|
2011-05-02 12:11:29 +03:00
|
|
|
|
|
|
|
next += cycles;
|
|
|
|
TDHR(TIMER) = next;
|
|
|
|
TFCR = 1 << (TIMER+16);
|
|
|
|
while (!(TFR & (1 << (TIMER+16))));
|
2011-05-03 18:09:24 +03:00
|
|
|
t = next+24-TCNT(TIMER);
|
|
|
|
t >>= 1;
|
|
|
|
while (t--)
|
|
|
|
asm("");
|
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
2011-04-24 18:12:36 +03:00
|
|
|
|
2011-04-25 01:43:26 +03:00
|
|
|
/* ----- Frame buffer output ----------------------------------------------- */
|
2011-04-24 18:12:36 +03:00
|
|
|
|
|
|
|
|
2011-04-30 04:48:01 +03:00
|
|
|
static void setup(void)
|
2011-04-24 18:12:36 +03:00
|
|
|
{
|
|
|
|
mlockall(MCL_CURRENT | MCL_FUTURE);
|
|
|
|
ben_setup();
|
2011-04-29 20:03:07 +03:00
|
|
|
|
|
|
|
PDFUNS = R | G | B | Y;
|
|
|
|
PDFUNC = VSYNC | HSYNC;
|
|
|
|
PDDIRS = VSYNC | HSYNC | R | G | B | Y;
|
|
|
|
PDDATS = VSYNC | HSYNC;
|
|
|
|
PDDATC = R | G | B | Y;
|
|
|
|
|
|
|
|
MSCCDR = mode->clkdiv; /* set the MSC clock to 336 MHz / 12 = 28 MHz */
|
|
|
|
CLKGR &= ~(1 << 7); /* enable MSC clock */
|
2011-05-03 16:19:16 +03:00
|
|
|
while (MSCCDR & 1) {
|
|
|
|
MSCCDR >>= 1;
|
|
|
|
clkrt++;
|
|
|
|
}
|
2011-04-24 18:12:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-30 04:48:01 +03:00
|
|
|
static void setup_noirq(void)
|
|
|
|
{
|
2011-05-07 02:19:13 +03:00
|
|
|
if (keep_lcd)
|
|
|
|
tame_lcd();
|
|
|
|
else
|
|
|
|
disable_lcd();
|
2011-05-07 01:36:34 +03:00
|
|
|
get_timer();
|
|
|
|
|
2011-05-01 18:22:23 +03:00
|
|
|
DMAC = 1;
|
|
|
|
DCS(DMA) = (1 << 3) | (1 << 2);
|
|
|
|
DCS(DMA) = 0;
|
2011-05-01 19:54:54 +03:00
|
|
|
|
|
|
|
DCM(DMA) =
|
|
|
|
(1 << 23) | /* source address increment */
|
|
|
|
(4 << 8); /* transfer size is 32 bytes */
|
|
|
|
DRT(DMA) = 26; /* MSC transmit-fifo-empty transfer request */
|
2011-04-30 04:48:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void cleanup_noirq(void)
|
|
|
|
{
|
2011-05-01 18:22:23 +03:00
|
|
|
DMAC = 0;
|
|
|
|
DCS(DMA) = (1 << 3) | (1 << 2);
|
|
|
|
DCS(DMA) = 0;
|
2011-05-07 01:36:34 +03:00
|
|
|
|
|
|
|
release_timer();
|
2011-05-07 02:19:13 +03:00
|
|
|
if (keep_lcd)
|
|
|
|
restore_lcd();
|
|
|
|
else
|
|
|
|
enable_lcd();
|
2011-04-30 04:48:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-01 18:22:23 +03:00
|
|
|
static void line(unsigned long line)
|
2011-04-24 05:26:42 +03:00
|
|
|
{
|
2011-04-29 20:03:07 +03:00
|
|
|
/* Back porch */
|
|
|
|
|
|
|
|
MSC_STRPCL = 1 << 3; /* reset the MSC */
|
|
|
|
|
2011-05-01 19:22:08 +03:00
|
|
|
// DCS(DMA) = (1 << 31) | (1 << 3) | (1 << 2);
|
2011-05-01 18:22:23 +03:00
|
|
|
DCS(DMA) = 1 << 31;
|
|
|
|
DSA(DMA) = line;
|
2011-05-01 19:54:54 +03:00
|
|
|
DTA(DMA) = REG_PADDR(MSC_TXFIFO); /* MUST set this each time */
|
2011-05-02 11:25:15 +03:00
|
|
|
DTC(DMA) = (mode->xres+63) >> 6;
|
2011-04-29 20:03:07 +03:00
|
|
|
|
2011-05-02 12:11:29 +03:00
|
|
|
delay(mode->hback_cycles);
|
2011-04-24 17:48:32 +03:00
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
/* HSYNC */
|
2011-04-29 20:03:07 +03:00
|
|
|
|
|
|
|
PDDATC = HSYNC;
|
2011-05-03 16:19:16 +03:00
|
|
|
MSC_CLKRT = clkrt; /* bus clock = MSC clock / n */
|
2011-04-29 20:03:07 +03:00
|
|
|
MSC_STRPCL = 2; /* start MMC clock output */
|
|
|
|
MSC_RESTO = 0xffff;
|
|
|
|
|
|
|
|
MSC_CMDAT =
|
2011-04-30 04:22:51 +03:00
|
|
|
(2 << 9) | /* 4 bit bus */
|
2011-05-01 18:22:23 +03:00
|
|
|
(1 << 8) | /* DMA */
|
2011-04-29 20:03:07 +03:00
|
|
|
(1 << 4) | /* write */
|
|
|
|
(1 << 3) | /* with data transfer */
|
|
|
|
1; /* R1 response */
|
|
|
|
|
|
|
|
MSC_STRPCL = 4; /* START_OP */
|
|
|
|
|
2011-05-01 18:22:23 +03:00
|
|
|
DCS(DMA) =
|
|
|
|
(1 << 31) | /* no descriptor */
|
|
|
|
1;
|
|
|
|
|
2011-05-02 12:11:29 +03:00
|
|
|
delay(mode->hsync_cycles);
|
2011-04-24 05:26:42 +03:00
|
|
|
|
2011-05-01 18:22:23 +03:00
|
|
|
// MSC_TXFIFO = 0xffffffff;
|
2011-04-24 05:26:42 +03:00
|
|
|
|
2011-05-01 18:22:23 +03:00
|
|
|
/* Front porch */
|
2011-04-29 20:03:07 +03:00
|
|
|
|
|
|
|
PDFUNS = CMD;
|
|
|
|
PDDATS = HSYNC;
|
|
|
|
PDFUNC = CMD;
|
|
|
|
|
2011-05-02 12:11:29 +03:00
|
|
|
delay(mode->line_cycles-mode->hback_cycles-mode->hsync_cycles);
|
2011-05-02 11:16:19 +03:00
|
|
|
MSC_TXFIFO = 0;
|
2011-05-01 18:22:23 +03:00
|
|
|
if (MSC_STAT & 3)
|
|
|
|
bad++;
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hdelay(int cycles)
|
|
|
|
{
|
|
|
|
while (cycles--) {
|
2011-04-29 20:03:07 +03:00
|
|
|
PDDATC = HSYNC;
|
2011-05-02 12:11:29 +03:00
|
|
|
delay(mode->hsync_cycles);
|
2011-04-29 20:03:07 +03:00
|
|
|
PDDATS = HSYNC;
|
2011-05-02 12:11:29 +03:00
|
|
|
delay(mode->line_cycles-mode->hsync_cycles);
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-01 18:22:23 +03:00
|
|
|
static void frame(const unsigned long *f)
|
2011-04-24 05:26:42 +03:00
|
|
|
{
|
2011-05-01 18:22:23 +03:00
|
|
|
const unsigned long *p;
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
/* VSYNC */
|
2011-04-29 20:03:07 +03:00
|
|
|
PDDATC = VSYNC;
|
2011-05-02 02:59:38 +03:00
|
|
|
hdelay(mode->vsync_lines);
|
2011-04-29 20:03:07 +03:00
|
|
|
PDDATS = VSYNC;
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
/* Front porch */
|
|
|
|
|
2011-05-02 02:59:38 +03:00
|
|
|
hdelay(mode->vfront_lines-1);
|
2011-04-24 05:26:42 +03:00
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
/*
|
|
|
|
* The horizontal back porch of the previous line is handled inside
|
|
|
|
* "line", so we have to wait for less than a full line here.
|
|
|
|
*/
|
|
|
|
PDDATC = HSYNC;
|
2011-05-02 12:11:29 +03:00
|
|
|
delay(mode->hsync_cycles);
|
2011-04-29 20:03:07 +03:00
|
|
|
PDDATS = HSYNC;
|
2011-05-02 12:11:29 +03:00
|
|
|
delay(mode->line_cycles-mode->hback_cycles-mode->hsync_cycles);
|
2011-04-29 20:03:07 +03:00
|
|
|
|
2011-05-02 12:11:29 +03:00
|
|
|
for (p = f; p != f+mode->yres; p++)
|
2011-04-29 20:03:07 +03:00
|
|
|
line(*p);
|
2011-05-02 12:11:29 +03:00
|
|
|
|
|
|
|
delay(mode->hback_cycles);
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
/* Back porch */
|
2011-05-02 02:59:38 +03:00
|
|
|
hdelay(mode->vback_lines);
|
2011-04-24 05:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-25 01:43:26 +03:00
|
|
|
/* ----- Command-line parsing and main loop -------------------------------- */
|
|
|
|
|
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
static void session(void (*gen)(void **fb, int xres, int yres), int frames)
|
2011-04-24 05:26:42 +03:00
|
|
|
{
|
2011-05-01 18:22:23 +03:00
|
|
|
void **f_virt;
|
|
|
|
const unsigned long *f_phys;
|
2011-05-02 11:25:15 +03:00
|
|
|
int i, bytes;
|
2011-04-24 05:26:42 +03:00
|
|
|
|
2011-04-29 20:03:07 +03:00
|
|
|
ccube_init();
|
2011-05-02 11:25:15 +03:00
|
|
|
bytes = mode->xres/2;
|
|
|
|
bytes = (bytes+31) & ~31;
|
|
|
|
f_virt = calloc_phys_vec(mode->yres, bytes);
|
2011-05-01 18:22:23 +03:00
|
|
|
gen(f_virt, mode->xres, mode->yres);
|
|
|
|
f_phys = xlat_virt(f_virt, mode->yres);
|
2011-04-24 05:26:42 +03:00
|
|
|
|
|
|
|
disable_interrupts();
|
|
|
|
|
2011-04-30 04:48:01 +03:00
|
|
|
setup_noirq();
|
|
|
|
|
2011-05-02 12:11:29 +03:00
|
|
|
TCNT(TIMER) = 0;
|
2011-05-01 22:41:32 +03:00
|
|
|
for (i = 0; !frames || i != frames; i++) {
|
2011-05-01 18:22:23 +03:00
|
|
|
frame(f_phys);
|
|
|
|
if (DTC(DMA)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"DMA locked up. Need hardware reset.\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-05-01 22:41:32 +03:00
|
|
|
if (!frames && (PDPIN & KEY_MASK) != KEY_MASK)
|
|
|
|
break;
|
2011-05-01 18:22:23 +03:00
|
|
|
}
|
2011-04-24 05:26:42 +03:00
|
|
|
|
2011-04-30 04:48:01 +03:00
|
|
|
cleanup_noirq();
|
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
enable_interrupts();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-02 05:12:38 +03:00
|
|
|
static void list_modes(void)
|
|
|
|
{
|
|
|
|
const struct mode *m;
|
|
|
|
|
|
|
|
for (m = mode_db; m->name; m++) {
|
|
|
|
printf("\"%s\", %dx%d:\n", m->name, m->xres, m->yres);
|
|
|
|
printf("\t336/%d = %5.2f MHz\n",
|
|
|
|
m->clkdiv+1, 336.0/(m->clkdiv+1));
|
|
|
|
printf("\tH: %4.2f+...+%4.2f = %5.2f us\n",
|
|
|
|
CYCLES(m->hsync_cycles), CYCLES(m->hback_cycles),
|
|
|
|
CYCLES(m->line_cycles));
|
|
|
|
printf("\tV: %d+%d+%d+%d lines, %5.2f Hz\n",
|
|
|
|
m->vsync_lines, m->vfront_lines, m->yres, m->vback_lines,
|
|
|
|
112000000.0/m->line_cycles/
|
|
|
|
(m->vsync_lines+m->vfront_lines+m->yres+m->vback_lines));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-25 01:43:26 +03:00
|
|
|
static void usage(const char *name)
|
2011-04-24 05:26:42 +03:00
|
|
|
{
|
2011-04-25 03:09:50 +03:00
|
|
|
fprintf(stderr,
|
2011-07-04 21:09:22 +03:00
|
|
|
"usage: %s [-2] [-t] [-m resolution] [frames [file]]\n"
|
2011-05-02 05:12:38 +03:00
|
|
|
" %s -l\n\n"
|
2011-04-29 20:03:07 +03:00
|
|
|
" frames number of frames to display\n"
|
|
|
|
" file PPM file\n\n"
|
2011-05-07 02:19:13 +03:00
|
|
|
" -2 keep on refreshing the LCD display (experimental)\n"
|
2011-05-02 05:12:38 +03:00
|
|
|
" -l list available modes\n"
|
2011-04-29 20:03:07 +03:00
|
|
|
" -m mode select the display mode, default \"%s\"\n"
|
|
|
|
" -t generate a test image\n"
|
2011-05-02 05:12:38 +03:00
|
|
|
, name, name, mode_db[0].name);
|
2011-04-25 01:43:26 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *const *argv)
|
|
|
|
{
|
2011-04-29 20:03:07 +03:00
|
|
|
void (*gen)(void **fb, int xres, int yres) = grabfb;
|
2011-05-01 22:41:32 +03:00
|
|
|
int frames = 0;
|
2011-04-25 01:43:26 +03:00
|
|
|
int c;
|
|
|
|
|
2011-05-07 02:19:13 +03:00
|
|
|
while ((c = getopt(argc, argv, "2lm:t")) != EOF)
|
2011-04-25 01:43:26 +03:00
|
|
|
switch (c) {
|
2011-05-07 02:19:13 +03:00
|
|
|
case '2':
|
|
|
|
keep_lcd = 1;
|
|
|
|
break;
|
2011-05-02 05:12:38 +03:00
|
|
|
case 'l':
|
|
|
|
list_modes();
|
|
|
|
exit(0);
|
2011-04-29 20:03:07 +03:00
|
|
|
case 'm':
|
|
|
|
for (mode = mode_db; mode->name; mode++)
|
|
|
|
if (!strcmp(mode->name, optarg))
|
|
|
|
break;
|
|
|
|
if (!mode->name) {
|
|
|
|
fprintf(stderr, "no mode \"%s\"\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
gen = tstimg;
|
2011-04-25 03:09:50 +03:00
|
|
|
break;
|
2011-04-25 01:43:26 +03:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (argc-optind) {
|
|
|
|
case 2:
|
2011-04-29 20:03:07 +03:00
|
|
|
img_name = argv[optind+1];
|
|
|
|
gen = ppmimg;
|
2011-04-25 01:43:26 +03:00
|
|
|
/* fall through */
|
|
|
|
case 1:
|
|
|
|
frames = atoi(argv[optind]);
|
|
|
|
break;
|
2011-05-01 22:41:32 +03:00
|
|
|
case 0:
|
|
|
|
break;
|
2011-04-25 01:43:26 +03:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
2011-04-24 05:26:42 +03:00
|
|
|
setup();
|
2011-04-29 20:03:07 +03:00
|
|
|
session(gen, frames);
|
2011-04-25 01:43:26 +03:00
|
|
|
|
2011-05-03 16:19:16 +03:00
|
|
|
#if 0
|
|
|
|
printf("clkdiv: %d, /%d /%d\n", mode->clkdiv,
|
|
|
|
(MSCCDR & 15)+1, 1 << (MSC_CLKRT & 7));
|
|
|
|
#endif
|
2011-04-29 20:03:07 +03:00
|
|
|
if (bad)
|
|
|
|
printf("%d timeout%s\n", bad, bad == 1 ? "" : "s");
|
2011-04-24 05:26:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|