changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: bcm: cleanup timer code

changeset 6870: 338996d96b6a
parent 6869: 194ab9426a0c
child 6871: b90924e837f6
author: cinap_lenrek@felloff.net
date: Wed, 07 Nov 2018 17:02:09 +0100
files: sys/src/9/bcm/clock.c
description: bcm: cleanup timer code

- calculate hardcoded constants for more clarity
- avoid unneccesary modification of cntpns ctl register
- revert enabling IRQcntpns for cpu0
- remove unused Localintpending register offset constant
     1.1--- a/sys/src/9/bcm/clock.c
     1.2+++ b/sys/src/9/bcm/clock.c
     1.3@@ -28,7 +28,6 @@ enum {
     1.4 
     1.5 	Localctl	= 0x00,
     1.6 	Prescaler	= 0x08,
     1.7-	Localintpending	= 0x60,
     1.8 
     1.9 	SystimerFreq	= 1*Mhz,
    1.10 	MaxPeriod	= SystimerFreq / HZ,
    1.11@@ -98,7 +97,6 @@ localclockintr(Ureg *ureg, void *)
    1.12 {
    1.13 	if(m->machno == 0)
    1.14 		panic("cpu0: Unexpected local generic timer interrupt");
    1.15-	cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask);
    1.16 	timerintr(ureg, 0);
    1.17 }
    1.18 
    1.19@@ -116,16 +114,22 @@ clockinit(void)
    1.20 {
    1.21 	Systimers *tn;
    1.22 	Armtimer *tm;
    1.23-	u32int t0, t1, tstart, tend;
    1.24+	ulong t0, t1, tstart, tend;
    1.25 
    1.26 	if(((cprdsc(0, CpID, CpIDfeat, 1) >> 16) & 0xF) != 0) {
    1.27 		/* generic timer supported */
    1.28+		cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysval, ~0);
    1.29 		if(m->machno == 0){
    1.30-			*(ulong*)(ARMLOCAL + Localctl) = 0;		/* input clock is 19.2Mhz crystal */
    1.31-			*(ulong*)(ARMLOCAL + Prescaler) = 0x06aaaaab;	/* divide by (2^31/Prescaler) for 1Mhz */
    1.32+			cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask);
    1.33+
    1.34+			/* input clock is 19.2Mhz crystal */
    1.35+			*(ulong*)(ARMLOCAL + Localctl) = 0;
    1.36+			/* divide by (2^31/Prescaler) */
    1.37+			*(ulong*)(ARMLOCAL + Prescaler) = (((uvlong)SystimerFreq<<31)/19200000)&~1UL;
    1.38+		} else {
    1.39+			cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Enable);
    1.40+			intrenable(IRQcntpns, localclockintr, nil, 0, "clock");
    1.41 		}
    1.42-		cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask);
    1.43-		intrenable(IRQcntpns, localclockintr, nil, 0, "clock");
    1.44 	}
    1.45 
    1.46 	tn = (Systimers*)SYSTIMERS;
    1.47@@ -133,7 +137,7 @@ clockinit(void)
    1.48 	do{
    1.49 		t0 = lcycles();
    1.50 	}while(tn->clo == tstart);
    1.51-	tend = tstart + 10000;
    1.52+	tend = tstart + (SystimerFreq/100);
    1.53 	do{
    1.54 		t1 = lcycles();
    1.55 	}while(tn->clo != tend);
    1.56@@ -141,12 +145,14 @@ clockinit(void)
    1.57 	m->cpuhz = 100 * t1;
    1.58 	m->cpumhz = (m->cpuhz + Mhz/2 - 1) / Mhz;
    1.59 	m->cyclefreq = m->cpuhz;
    1.60+
    1.61 	if(m->machno == 0){
    1.62 		tn->c3 = tn->clo - 1;
    1.63+		intrenable(IRQtimer3, clockintr, nil, 0, "clock");
    1.64+
    1.65 		tm = (Armtimer*)ARMTIMER;
    1.66 		tm->load = 0;
    1.67 		tm->ctl = TmrPrescale1|CntEnable|CntWidth32;
    1.68-		intrenable(IRQtimer3, clockintr, nil, 0, "clock");
    1.69 	}
    1.70 }
    1.71 
    1.72@@ -163,10 +169,9 @@ timerset(uvlong next)
    1.73 		period = MinPeriod;
    1.74 	else if(period > MaxPeriod)
    1.75 		period = MaxPeriod;
    1.76-	if(m->machno > 0){
    1.77+	if(m->machno)
    1.78 		cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysval, period);
    1.79-		cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Enable);
    1.80-	}else{
    1.81+	else{
    1.82 		tn = (Systimers*)SYSTIMERS;
    1.83 		tn->c3 = tn->clo + period;
    1.84 	}