fix timer calculation

This commit is contained in:
Markus Fröschle
2016-10-17 15:53:17 +00:00
parent 1c435cbb6a
commit 1a6d6c3375
3 changed files with 66 additions and 52 deletions

View File

@@ -536,17 +536,18 @@ struct fb_videomode {
extern const struct fb_videomode vesa_modes[]; extern const struct fb_videomode vesa_modes[];
/* timer */ /* timer */
#ifdef COLDFIRE
#ifdef MCF5445X #if defined(MACHINE_FIREBEE)
#define US_TO_TIMER(a) (((a) * 256) / 5000)
#define TIMER_TO_US(a) (((a) * 5000) / 256)
#elif defined(MACHINE_M5484LITE)
#define US_TO_TIMER(a) ((a) * 100)
#define TIMER_TO_US(a) ((a) / 100)
#elif defined(MACHINE_M54455)
#define US_TO_TIMER(a) (a) #define US_TO_TIMER(a) (a)
#define TIMER_TO_US(a) (a) #define TIMER_TO_US(a) (a)
#else /* MCF548X */
#define US_TO_TIMER(a) ((a)*100)
#define TIMER_TO_US(a) ((a)/100)
#endif
#else #else
#define US_TO_TIMER(a) (((a)*256)/5000) #error Unknown machine!
#define TIMER_TO_US(a) (((a)*5000)/256)
#endif #endif
extern void start_timeout(void); extern void start_timeout(void);

View File

@@ -332,12 +332,12 @@ void __OUTPLLP(struct radeonfb_info *rinfo, uint32_t index, uint32_t val, uint32
__OUTPLL(rinfo, index, tmp); __OUTPLL(rinfo, index, tmp);
} }
static int round_div(int num, int den) static __inline int round_div(int num, int den)
{ {
return(num + (den / 2)) / den; return(num + (den / 2)) / den;
} }
static uint32_t read_vline_crnt(struct radeonfb_info *rinfo) static __inline uint32_t read_vline_crnt(struct radeonfb_info *rinfo)
{ {
return((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3FF); return((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3FF);
} }
@@ -357,10 +357,6 @@ static int radeon_map_ROM(struct radeonfb_info *rinfo)
uint32_t temp; uint32_t temp;
dbg("mmio_base=%p\r\n", rinfo->mmio_base);
dbg("bios_seg=%p\r\n", rinfo->bios_seg);
dbg("bios_seg_phys=%p\r\n", rinfo->bios_seg_phys);
temp = inreg(MPP_TB_CONFIG); temp = inreg(MPP_TB_CONFIG);
dbg("temp=%d\r\n", temp); dbg("temp=%d\r\n", temp);
@@ -371,14 +367,14 @@ static int radeon_map_ROM(struct radeonfb_info *rinfo)
if (rinfo->bios_seg == NULL) if (rinfo->bios_seg == NULL)
{ {
dbg("ROM failed to map\r\n"); err("no ROM found on ATI card\r\n");
return -1; return -1;
} }
/* Very simple test to make sure it appeared */ /* Very simple test to make sure it appeared */
if (BIOS_IN16(0) != 0xaa55) if (BIOS_IN16(0) != 0xaa55)
{ {
dbg("Invalid ROM signature"); dbg("Invalid ROM signature 0x%04x instead of 0x%04x found\r\n", BIOS_IN16(0), 0xaa55);
goto failed; goto failed;
} }
@@ -394,27 +390,30 @@ static int radeon_map_ROM(struct radeonfb_info *rinfo)
* them all, and we should use fb_bios_start relative to start of image and not * them all, and we should use fb_bios_start relative to start of image and not
* relative start of ROM, but so far, I never found a dual-image ATI card * relative start of ROM, but so far, I never found a dual-image ATI card
* *
* typedef struct { * typedef struct
* u32 signature; + 0x00 * {
* u16 vendor; + 0x04 * u32 signature; + 0x00
* u16 device; + 0x06 * u16 vendor; + 0x04
* u16 reserved_1; + 0x08 * u16 device; + 0x06
* u16 dlen; + 0x0a * u16 reserved_1; + 0x08
* u8 drevision; + 0x0c * u16 dlen; + 0x0a
* u8 class_hi; + 0x0d * u8 drevision; + 0x0c
* u16 class_lo; + 0x0e * u8 class_hi; + 0x0d
* u16 ilen; + 0x10 * u16 class_lo; + 0x0e
* u16 irevision; + 0x12 * u16 ilen; + 0x10
* u8 type; + 0x14 * u16 irevision; + 0x12
* u8 indicator; + 0x15 * u8 type; + 0x14
* u16 reserved_2; + 0x16 * u8 indicator; + 0x15
* u16 reserved_2; + 0x16
* } pci_data_t; * } pci_data_t;
*/ */
if (BIOS_IN32(dptr) != (('R' << 24) | ('I' << 16) | ('C' << 8) | 'P')) if (BIOS_IN32(dptr) != (('R' << 24) | ('I' << 16) | ('C' << 8) | 'P'))
{ {
dbg("PCI DATA signature in ROM incorrect: %p\r\n", BIOS_IN32(dptr)); dbg("PCI DATA signature in ROM incorrect: %p\r\n", BIOS_IN32(dptr));
goto anyway; goto anyway;
} }
rom_type = BIOS_IN8(dptr + 0x14); rom_type = BIOS_IN8(dptr + 0x14);
switch(rom_type) switch(rom_type)
{ {
@@ -431,23 +430,24 @@ static int radeon_map_ROM(struct radeonfb_info *rinfo)
dbg("Found unknown type %d ROM Image\r\n", rom_type); dbg("Found unknown type %d ROM Image\r\n", rom_type);
goto failed; goto failed;
} }
anyway: anyway:
/* Locate the flat panel infos, do some sanity checking !!! */ /* Locate the flat panel infos, do some sanity checking !!! */
rinfo->fp_bios_start = BIOS_IN16(0x48); rinfo->fp_bios_start = BIOS_IN16(0x48);
dbg("BIOS start offset: %p\r\n", BIOS_IN16(0x48)); dbg("BIOS start offset: %p\r\n", BIOS_IN16(0x48));
/* Save BIOS PLL informations */ /* Save BIOS PLL informations */
{
uint16_t pll_info_block = BIOS_IN16(rinfo->fp_bios_start + 0x30);
dbg("BIOS PLL info block offset: %p\r\n", BIOS_IN16(rinfo->fp_bios_start + 0x30)); uint16_t pll_info_block = BIOS_IN16(rinfo->fp_bios_start + 0x30);
rinfo->bios_pll.sclk = BIOS_IN16(pll_info_block + 0x08);
rinfo->bios_pll.mclk = BIOS_IN16(pll_info_block + 0x0a); dbg("BIOS PLL info block offset: %p\r\n", BIOS_IN16(rinfo->fp_bios_start + 0x30));
rinfo->bios_pll.ref_clk = BIOS_IN16(pll_info_block + 0x0e); rinfo->bios_pll.sclk = BIOS_IN16(pll_info_block + 0x08);
rinfo->bios_pll.ref_div = BIOS_IN16(pll_info_block + 0x10); rinfo->bios_pll.mclk = BIOS_IN16(pll_info_block + 0x0a);
rinfo->bios_pll.ppll_min = BIOS_IN32(pll_info_block + 0x12); rinfo->bios_pll.ref_clk = BIOS_IN16(pll_info_block + 0x0e);
rinfo->bios_pll.ppll_max = BIOS_IN32(pll_info_block + 0x16); rinfo->bios_pll.ref_div = BIOS_IN16(pll_info_block + 0x10);
} rinfo->bios_pll.ppll_min = BIOS_IN32(pll_info_block + 0x12);
rinfo->bios_pll.ppll_max = BIOS_IN32(pll_info_block + 0x16);
return 0; return 0;
failed: failed:
@@ -461,12 +461,24 @@ failed:
static int radeon_probe_pll_params(struct radeonfb_info *rinfo) static int radeon_probe_pll_params(struct radeonfb_info *rinfo)
{ {
uint8_t ppll_div_sel; uint8_t ppll_div_sel;
unsigned Ns, Nm, M; unsigned Ns;
unsigned sclk, mclk, tmp, ref_div; unsigned Nm;
int hTotal, vTotal, num, denom, m, n; unsigned M;
double hz, vclk; unsigned sclk;
unsigned mclk;
unsigned tmp;
unsigned ref_div;
int hTotal;
int vTotal;
int num;
int denom;
int m;
int n;
double hz;
double vclk;
int32_t xtal; int32_t xtal;
uint32_t start_tv, stop_tv; uint32_t start_tv;
uint32_t stop_tv;
int timeout = 0; int timeout = 0;
int ipl; int ipl;
@@ -474,13 +486,13 @@ static int radeon_probe_pll_params(struct radeonfb_info *rinfo)
* Ugh, we cut interrupts, bad bad bad, but we want some precision * Ugh, we cut interrupts, bad bad bad, but we want some precision
* here, so... --BenH * here, so... --BenH
*/ */
ipl = set_ipl(0);
dbg("radeon_probe_pll_params\r\n"); dbg("radeon_probe_pll_params\r\n");
/* Flush PCI buffers ? */ /* Flush PCI buffers ? */
tmp = INREG16(DEVICE_ID); tmp = INREG16(DEVICE_ID);
ipl = set_ipl(0);
start_tv = get_timer(); start_tv = get_timer();
while (read_vline_crnt(rinfo) != 0) while (read_vline_crnt(rinfo) != 0)
{ {
@@ -504,6 +516,7 @@ static int radeon_probe_pll_params(struct radeonfb_info *rinfo)
break; break;
} }
} }
if (!timeout) if (!timeout)
{ {
while (read_vline_crnt(rinfo) != 0) while (read_vline_crnt(rinfo) != 0)

View File

@@ -18,18 +18,18 @@ int x86_pcibios_handler(struct X86EMU *emu)
{ {
case PCI_BIOS_PRESENT: case PCI_BIOS_PRESENT:
dbg("PCI_BIOS_PRESENT\r\n"); dbg("PCI_BIOS_PRESENT\r\n");
emu->x86.R_AH = 0x00; /* no config space/special cycle support */ emu->x86.R_AH = 0x00; /* no config space/special cycle support */
emu->x86.R_AL = 0x01; /* config mechanism 1 */ emu->x86.R_AL = 0x01; /* config mechanism 1 */
emu->x86.R_EDX = 'P' | 'C' << 8 | 'I' << 16 | ' ' << 24; emu->x86.R_EDX = 'P' | 'C' << 8 | 'I' << 16 | ' ' << 24;
emu->x86.R_EBX = 0x0210; /* Version 2.10 */ emu->x86.R_EBX = 0x0210; /* Version 2.10 */
emu->x86.R_ECX = 0xFF00; /* FixME: Max bus number */ emu->x86.R_ECX = 0xFF00; /* FixME: Max bus number */
emu->x86.R_EFLG &= ~FB_CF; /* clear carry flag */ emu->x86.R_EFLG &= ~FB_CF; /* clear carry flag */
ret = 1; ret = 1;
break; break;
case FIND_PCI_DEVICE: case FIND_PCI_DEVICE:
dbg("FIND_PCI_DEVICE vendor = %04x, device = %04x\r\n", emu->x86.R_DX, emu->x86.R_CX); dbg("FIND_PCI_DEVICE vendor = %04x, device = %04x\r\n", emu->x86.R_DX, emu->x86.R_CX);
dev = pci_find_device((unsigned long) emu->x86.R_DX, ((unsigned long) emu->x86.R_CX), 0); dev = pci_find_device((uintptr_t) emu->x86.R_DX, ((unsigned long) emu->x86.R_CX), 0);
if (dev != 0) if (dev != 0)
{ {