Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/bitsy/power.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname bitsy/power.c 2000/1122
## diff -e /dev/null /n/emeliedump/2000/1122/sys/src/9/bitsy/power.c
0a
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"ureg.h"
#include	"init.h"
#include	"pool.h"

/* Power management for the bitsy */

static void
powerintr(Ureg*, void *x)
{
	/* Power button interrupt */
	int i;

	/* debounce, 50 ms*/
	for (i = 0; i < 50; i++) {
		delay(1);
		if ((gpioregs->level & GPIO_PWR_ON_i) == 0)
			return;	/* bounced */
	}
	rs232power(0);
}
.
## diffname bitsy/power.c 2000/1123
## diff -e /n/emeliedump/2000/1122/sys/src/9/bitsy/power.c /n/emeliedump/2000/1123/sys/src/9/bitsy/power.c
25c
}

static void
sa1100_power_off(void)
{
	delay(100);
	splhi();
	/* disable internal oscillator, float CS lines */
	powerregs->pcfr = 1<<pcfr_opde | 1<<pcfr_fp | 1<<pcfr_fs;
	/* set lowest clock */
	powerregs->ppcr = 0;
	/* set all GPIOs to input mode */
	gpioregs->direction = 0;
	/* enter sleep mode */
	powerregs->pmcr = 1<<pmcr_sf;
.
19,23c
	if (powerup) {
		/* Power back up */
		powerup = 0;
		exit(0);
	} else {
		/* Power down */

		/* debounce, 50 ms*/
		for (i = 0; i < 50; i++) {
			delay(1);
			if ((gpioregs->level & GPIO_PWR_ON_i) == 0)
				return;	/* bounced */
		}
		powerup = 1;
		irpower(0);
		audiopower(0);
		lcdpower(0);
		rs232power(0);
		sa1100_power_off();
.
16c
	/* On/off button interrupt */
.
14c
onoffintr(Ureg*, void *x)
.
12a
int powerup;

enum {
	pmcr_sf		= 0,

	pcfr_opde	= 0,
	pcfr_fp		= 1,
	pcfr_fs		= 2,
	pcfr_fo		= 3,
};

.
## diffname bitsy/power.c 2000/1125
## diff -e /n/emeliedump/2000/1123/sys/src/9/bitsy/power.c /n/emeliedump/2000/1125/sys/src/9/bitsy/power.c
56a
	/* enable wakeup by µcontroller, on/off switch or real-time clock alarm */
	powerregs->pwer = 0x80000003;
.
49a
	if (i = setjmp(power_resume)) {
		/* power back up */
		rs232power(1);
		lcdpower(1);
		audiopower(1);
		irpower(1);
		return;
	}
	/* Power down */
	irpower(0);
	audiopower(0);
	lcdpower(0);
	rs232power(0);
	sa1100_power_off();
	/* no return */
.
30,48c
	/* debounce, 50 ms*/
	for (i = 0; i < 50; i++) {
		delay(1);
		if ((gpioregs->level & GPIO_PWR_ON_i) == 0)
			return;	/* bounced */
.
23a
jmp_buf power_resume;

.
13,14d
## diffname bitsy/power.c 2000/1130
## diff -e /n/emeliedump/2000/1125/sys/src/9/bitsy/power.c /n/emeliedump/2000/1130/sys/src/9/bitsy/power.c
67a
}

void
idlehands(void)
{
}
#endif

void
idlehands(void)
{
	doze();
.
12a
#ifdef NOTDEF
.
8d
## diffname bitsy/power.c 2000/1207
## diff -e /n/emeliedump/2000/1130/sys/src/9/bitsy/power.c /n/emeliedump/2000/1207/sys/src/9/bitsy/power.c
79c
//	doze();
.
## diffname bitsy/power.c 2000/1209
## diff -e /n/emeliedump/2000/1207/sys/src/9/bitsy/power.c /n/emeliedump/2000/1209/sys/src/9/bitsy/power.c
79c
	doze();
.
## diffname bitsy/power.c 2001/0324
## diff -e /n/emeliedump/2000/1209/sys/src/9/bitsy/power.c /n/emeliedump/2001/0324/sys/src/9/bitsy/power.c
79c
//	doze();
.
## diffname bitsy/power.c 2001/0325
## diff -e /n/emeliedump/2001/0324/sys/src/9/bitsy/power.c /n/emeliedump/2001/0325/sys/src/9/bitsy/power.c
79c
	char *msgb = "idlehands called with splhi\n";
	char *msga = "doze returns with splhi\n";

	if(!islo()){
		serialputs(msga, strlen(msga));
		spllo();
	}
	doze();
	if(!islo()){
		serialputs(msgb, strlen(msgb));
		spllo();
	}
.
## diffname bitsy/power.c 2001/0618
## diff -e /n/emeliedump/2001/0325/sys/src/9/bitsy/power.c /n/emeliedump/2001/0618/sys/src/9/bitsy/power.c
91a

.
90a
#endif
.
78a
#ifdef notdef
.
75a


.
74d
72a
	intrenable(GPIOrising, bitno(GPIO_PWR_ON_i), onoffintr, (void*)0x12344321, "on/off");
.
71c
powerinit(void)
.
56,67c
	int i;

	for(i = 0; i < 8*sizeof(x); i++)
		if((1<<i) & x)
			break;
	return i;
.
53,54c


static int
bitno(ulong x)
.
47c
	screenpower(0);
	µcpower(0);
.
44a
	iprint("\nentering suspend mode\n");
	gpiocpy(&savedgpioregs, gpioregs);
	intrcpy(&savedintrregs, intrregs);
	uartcpy(&saveduart3regs, uart3regs);
	uartcpy(&saveduart1regs, uart1regs);
	delay(400);
	clockpower(0);
.
41a
		audiopower(1);
		clockpower(1);
		gpclkregs->r0 = 1<<0;
		gpiocpy(gpioregs, &savedgpioregs);
		intrcpy(intrregs, &savedintrregs);
		if (intrregs->icip & (1<<IRQgpio0)){
			// don't want to sleep now. clear on/off irq.
			gpioregs->edgestatus = (1<<IRQgpio0);
			intrregs->icip = (1<<IRQgpio0);
		}
		uartcpy(uart3regs,&saveduart3regs);
		uart3regs->status[0] = uart3regs->status[0];
		uartcpy(uart1regs,&saveduart1regs);
		uart1regs->status[0] = uart1regs->status[0];
		µcpower(1);
		screenpower(1);
		iprint("\nresuming execution\n");
//		dumpitall();
		delay(800);
		splx(power_pl);
.
39,40d
36,37c
	power_pl = splhi();
	cachewb();
	delay(500);
	if (setpowerlabel()) {
		mmuinvalidate();
		mmuenable();
		cacheflush();
		trapresume();
.
30,31c
	
}

static void
intrcpy(Intrregs *to, Intrregs *from)
{
	to->iclr = from->iclr;
	to->iccr = from->iccr;
	to->icmr = from->icmr;	// interrupts enabled
}

static  void
uartcpy(Uartregs *to, Uartregs *from)
{
	to->ctl[0] = from->ctl[0];
//	to->ctl[1] = from->ctl[1];
//	to->ctl[2] = from->ctl[2];
	to->ctl[3] = from->ctl[3];

}

static void
gpiocpy(GPIOregs *to, GPIOregs *from)
{
	to->rising = from->rising;		// gpio intrs enabled
	to->falling= from->falling;		// gpio intrs enabled
	to->altfunc = from->altfunc;
	to->direction = from->direction;
}

static void
sa1100_power_off(void)
{
	/* enable wakeup by µcontroller, on/off switch or real-time clock alarm */
	powerregs->pwer =  1 << IRQrtc | 1 << IRQgpio0 | 1 << IRQgpio1;

	/* clear previous reset status */
	resetregs->rcsr =  RCSR_all;

	/* disable internal oscillator, float CS lines */
	powerregs->pcfr = PCFR_opde | PCFR_fp | PCFR_fs;
	powerregs->pgsr = 0;
	/* set resume address. The loader jumps to it */
	powerregs->pspr = (ulong)sa1100_power_resume;
	/* set lowest clock; delay to avoid resume hangs on fast sa1110 */
	delay(90);
	powerregs->ppcr = 0;
	delay(90);

	/* set all GPIOs to input mode  */
	gpioregs->direction = 0;
	delay(100);
	/* enter sleep mode */
	powerregs->pmcr = PCFR_suspend;
	for(;;);
}

void
onoffintr(Ureg* , void*)
{
	static int power_pl;
	int i;
	for (i = 0; i < 100; i++) {
.
27,28c
	iprint("intr: icip %lux iclr %lux iccr %lux icmr %lux\n",
		intrregs->icip,
		intrregs->iclr, intrregs->iccr, intrregs->icmr );
	iprint("gpio: lvl %lux dir %lux, re %lux, fe %lux sts %lux alt %lux\n",
		gpioregs->level,
		gpioregs->direction, gpioregs->rising, gpioregs->falling,
		gpioregs->edgestatus, gpioregs->altfunc);
	iprint("uart1: %lux %lux %lux \nuart3: %lux %lux %lux\n", 
		uart1regs->ctl[0], uart1regs->status[0], uart1regs->status[1], 
		uart3regs->ctl[0], uart3regs->status[0], uart3regs->status[1]); 
	iprint("tmr: osmr %lux %lux %lux %lux oscr %lux ossr %lux oier %lux\n",
		timerregs->osmr[0], timerregs->osmr[1],
		timerregs->osmr[2], timerregs->osmr[3],
		timerregs->oscr, timerregs->ossr, timerregs->oier);
	iprint("dram: mdcnfg %lux mdrefr %lux cas %lux %lux %lux %lux %lux %lux\n",
		memconfregs->mdcnfg, memconfregs->mdrefr,
		memconfregs->mdcas00, memconfregs->mdcas01,memconfregs->mdcas02,
		memconfregs->mdcas20, memconfregs->mdcas21,memconfregs->mdcas22); 
	iprint("dram: mdcnfg msc %lux %lux %lux mecr %lux\n",
		memconfregs->msc0, memconfregs->msc1,memconfregs->msc2,
		memconfregs->mecr);
.
25c
dumpitall(void)
.
23a
GPIOregs savedgpioregs;
Uartregs saveduart3regs;
Uartregs saveduart1regs;
Intrregs savedintrregs;


.
22d
16,20c
extern void sa1100_power_resume(void);
extern int setpowerlabel(void);
.
12,14c
/* saved state during power down. 
 * it's only used up to 164/4.
 * it's only used by routines in l.s
 */
ulong power_resume[200/4];
.
## diffname bitsy/power.c 2001/0619
## diff -e /n/emeliedump/2001/0618/sys/src/9/bitsy/power.c /n/emeliedump/2001/0619/sys/src/9/bitsy/power.c
164a
	iprint("10..");
.
163a
	uartpower(0);
	iprint("rs\n");
.
156,157d
145a
		irpower(1);
		audiopower(1);
.
140,143c
		uartpower(1);
.
129,130d
87a
	iprint("12..");
.
85a
	iprint("11..");
.
64,73d
39,40c
		R(&sa1110uart[0])->ctl[0], R(&sa1110uart[0])->status[0], R(&sa1110uart[0])->status[1], 
		R(&sa1110uart[1])->ctl[0], R(&sa1110uart[1])->status[0], R(&sa1110uart[1])->status[1]); 
.
26a
#define R(p) ((Uartregs*)((p)->regs))
.
23,24d
21d
18,19c
extern void	sa1100_power_resume(void);
extern int		setpowerlabel(void);
extern Uart	sa1110uart[];
.
## diffname bitsy/power.c 2001/0620
## diff -e /n/emeliedump/2001/0619/sys/src/9/bitsy/power.c /n/emeliedump/2001/0620/sys/src/9/bitsy/power.c
176,177d
165,168c
//		irpower(0);
//		audiopower(0);
		screenpower(0);
		µcpower(0);
		clockpower(0);

		rs232power(0);
		uartpower(0);

		deepsleep();

		rs232power(1);
		uartpower(1);

		clockpower(1);
		µcpower(1);
		screenpower(1);
//		audiopower(1);
//		irpower(1);

		splx(power_pl);

		iprint("power restored\n");
	}
.
160,163c
		power_pl = splhi();
.
158a
	for(;;){
		while(powerflag == 0)
			sleep(&powerr, powerdown, 0);
		iprint("starting power down\n");
		powerflag = 0;
.
157a
void
powerkproc(void*)
{
	static int power_pl;
.
145,153d
141d
129,134d
119,120d
114a
		/* return from longjmp, turn everything back on */
.
113a

	/* Save state and setjmp */
.
111a

	/* flush cache */
.
110a

	powerflag = 1;
	wakeup(&powerr);
}

int
powerdown(void *)
{
	return powerflag;
}

void
deepsleep(void) {
	static int power_pl;

.
105a

	/* Power down interrupt comes on power button release.
	 * Act only after button has been released a full 100 ms
	 */

	if (powerflag)
		return;

.
104d
100a
static int
bitno(ulong x)
{
	int i;

	for(i = 0; i < 8*sizeof(x); i++)
		if((1<<i) & x)
			break;
	return i;
}

.
78d
75d
16c
ulong	power_resume[200/4];
Rendez	powerr;
ulong	powerflag = 0;	/* set to start power-off sequence */
.
## diffname bitsy/power.c 2001/0621
## diff -e /n/emeliedump/2001/0620/sys/src/9/bitsy/power.c /n/emeliedump/2001/0621/sys/src/9/bitsy/power.c
205,213d
202,203c
		delay(1000);
		xsp = getsp();
		xlink = getlink();
		iprint("power restored, sp = %lux, link = %lux\n", xsp, xlink);
.
191,199d
189c
		xsp = getsp();
		xlink = getlink();
		iprint("starting power down, sp = %lux, link = %lux\n", xsp, xlink);
		delay(1000);
.
186c

.
181c
	void *xsp, *xlink;
.
173a
	clockpower(0);
	irpower(0);
	audiopower(0);
	screenpower(0);
	µcpower(0);
	rs232power(0);
.
172a
	uartpower(0);
.
170a
	iprint("entering suspend mode\n");
.
164a
		uartpower(1);
		µcpower(1);
		screenpower(1);
		iprint("\nresuming execution\n");
.
156a
		rs232power(1);
		irpower(1);
		audiopower(1);
		clockpower(1);
.
152d
149,150d
145,146d
## diffname bitsy/power.c 2001/0622
## diff -e /n/emeliedump/2001/0621/sys/src/9/bitsy/power.c /n/emeliedump/2001/0622/sys/src/9/bitsy/power.c
218c
	intrenable(GPIOrising, bitno(GPIO_PWR_ON_i), onoffintr, nil, "on/off");
.
212a

	deepsleep();
//	powerflag = 1;
//	wakeup(&powerr);
.
211a
	if (powerflag)
		return;

	for (i = 0; i < 100; i++) {
		delay(1);
		if ((gpioregs->level & GPIO_PWR_ON_i) == 0)
			return;	/* bounced */
.
207,210c
	/* Power down interrupt comes on power button release.
	 * Act only after button has been released a full 100 ms
	 */
.
205c
void
onoffintr(Ureg* , void*)
{
	int i;
.
200,203c
	}
}
.
197a

		deepsleep();

		delay(2000);

.
192d
169a
		delay(1000);
		xsp = getsp();
		xlink = getlink();
		iprint("power restored, sp = %lux, link = %lux\n", xsp, xlink);

.
144a
	xsp = getsp();
	xlink = getlink();
	iprint("starting power down, sp = %lux, link = %lux\n", xsp, xlink);
	delay(1000);
.
142a
	void *xsp, *xlink;
.
112,133d
96a

.
90c
//	powerregs->ppcr = 0;
.
88a

.
87c
//	powerregs->pspr = (ulong)sa1100_power_resume;
//	powerregs->pspr = (ulong)_start;
.
82a
sa1100_power_resume();

.
76a
	cacheflush();
	mmuinvalidate();
	mmudisable();

.
73a
void	(*restart)(void) = nil;

.
21a
extern void	_start(void);
.
## diffname bitsy/power.c 2001/0623
## diff -e /n/emeliedump/2001/0622/sys/src/9/bitsy/power.c /n/emeliedump/2001/0623/sys/src/9/bitsy/power.c
184c
//	rs232power(0);
.
182c
//	screenpower(0);
.
101c
	powerregs->ppcr = 0;
.
97c
	powerregs->pspr = (ulong)_start;
.
90,91d
83a
iprint("calling resume\n");
sa1100_power_resume();

.
80,82d
## diffname bitsy/power.c 2001/0626
## diff -e /n/emeliedump/2001/0623/sys/src/9/bitsy/power.c /n/emeliedump/2001/0626/sys/src/9/bitsy/power.c
81,83d
## diffname bitsy/power.c 2001/0731
## diff -e /n/emeliedump/2001/0626/sys/src/9/bitsy/power.c /n/emeliedump/2001/0731/sys/src/9/bitsy/power.c
220,222c
	powerflag = 1;
	wakeup(&powerr);
.
198d
192d
179c
	rs232power(0);
.
177c
	screenpower(0);
.
160,163c
xsp = getsp();
xlink = getlink();
iprint("power restored, sp = %lux, link = %lux\n", xsp, xlink);
delay(1000);
.
131,134c
xsp = getsp();
xlink = getlink();
iprint("starting power down, sp = %lux, link = %lux\n", xsp, xlink);
delay(1000);
.
91,92c
	powerregs->pspr = (ulong)sa1100_power_resume;
.
## diffname bitsy/power.c 2001/0808
## diff -e /n/emeliedump/2001/0731/sys/src/9/bitsy/power.c /n/emeliedump/2001/0808/sys/src/9/bitsy/power.c
91c
//	powerregs->pspr = (ulong)sa1100_power_resume;
	powerregs->pspr = 0;
.
81c
	/* enable wakeup by µcontroller, on/off switch
	 * or real-time clock alarm
	 */
.
## diffname bitsy/power.c 2001/0809
## diff -e /n/emeliedump/2001/0808/sys/src/9/bitsy/power.c /n/emeliedump/2001/0809/sys/src/9/bitsy/power.c
162,166d
156d
145,146c
		uartpower(1);
//		irpower(1);
//		audiopower(1);
.
133,136d
96a
sa1100_power_resume();
.
## diffname bitsy/power.c 2001/0810
## diff -e /n/emeliedump/2001/0809/sys/src/9/bitsy/power.c /n/emeliedump/2001/0810/sys/src/9/bitsy/power.c
162,173d
147,153d
137,139c
		mmurestart();
		gpiorestore(gpioregs, &savedgpioregs);
		delay(50);
		intrcpy(intrregs, &savedintrregs);
		if (intrregs->icip & (1<<IRQgpio0)){
			// don't want to sleep now. clear on/off irq.
			gpioregs->edgestatus = (1<<IRQgpio0);
			intrregs->icip = (1<<IRQgpio0);
		}
.
134,135c
	delay(50);
	/* Power down */
	iprint("entering suspend mode\n");
	uartpower(0);
	clockpower(0);
	irpower(0);
	audiopower(0);
	screenpower(0);
	µcpower(0);
	rs232power(0);
	gpiosave(&savedgpioregs, gpioregs);
	intrcpy(&savedintrregs, intrregs);
	cacheflush();
	delay(50);
.
101a
	/* set lowest clock; delay to avoid resume hangs on fast sa1110 */
//	delay(90);
//	powerregs->ppcr = 0;
//	delay(90);

.
97,100c
//sa1100_power_resume();
.
93,95c
	powerregs->pspr = (ulong)sa1100_power_resume;
//	powerregs->pspr = 0;
.
74a
static void
gpiorestore(GPIOregs *to, GPIOregs *from)
{
	to->rising = from->rising;		// gpio intrs enabled
	to->falling= from->falling;		// gpio intrs enabled
	to->altfunc = from->altfunc;
	to->direction = from->direction;
	to->set = from->level & 0x0fffffff;
	to->clear = ~from->level & 0x0fffffff;
}

.
68a
	to->level = from->level;
.
67c
gpiosave(GPIOregs *to, GPIOregs *from)
.
## diffname bitsy/power.c 2001/0811
## diff -e /n/emeliedump/2001/0810/sys/src/9/bitsy/power.c /n/emeliedump/2001/0811/sys/src/9/bitsy/power.c
198a
		iprint("deepsleep returned\n");
.
197a
		iprint("call deepsleep\n");
.
181c
		dumpitall();
.
161a
		/* Turn off memory auto power */
		memconfregs->mdrefr &= ~0x30000000;
.
149a
	dumpitall();
.
## diffname bitsy/power.c 2001/0812
## diff -e /n/emeliedump/2001/0811/sys/src/9/bitsy/power.c /n/emeliedump/2001/0812/sys/src/9/bitsy/power.c
184a
		xlink = getcallerpc(&xlink);
		iprint("\nresuming execution, sp = 0x%lux, pc = 0x%lux, psw = 0x%lux\n", &xsp, xlink, splhi());
.
183d
149c
	iprint("entering suspend mode, sp = 0x%lux, pc = 0x%lux, psw = 0x%lux\n", &xsp, xlink, power_pl);
.
147a
	xlink = getcallerpc(&xlink);
.
144c
	ulong xsp, xlink;
.
## diffname bitsy/power.c 2001/0813
## diff -e /n/emeliedump/2001/0812/sys/src/9/bitsy/power.c /n/emeliedump/2001/0813/sys/src/9/bitsy/power.c
190a
	wbflush();
	delay(50);
.
188a
//		irpower(1);
//		audiopower(1);
		µcpower(1);
		screenpower(1);
.
187d
184a
		delay(100);
.
182,183c
		rs232power(1);
		uartpower(1);
.
176,179d
158a
	clockpower(0);
.
157a
	power_pl = splhi();
	iprint("entering suspend mode, sp = 0x%lux, pc = 0x%lux, psw = 0x%lux\n", &xsp, xlink, power_pl);
	dumpitall();
	delay(100);
	uartpower(0);
.
150,153d
146,147d
84a
	to->rising = from->rising;		// gpio intrs enabled
	to->falling= from->falling;		// gpio intrs enabled
.
82a
	to->altfunc = from->altfunc;
.
79,81d
54,55c
	iprint("powerregs: pmcr %lux pssr %lux pcfr %lux ppcr %lux pwer %lux pspr %lux pgsr %lux posr %lux\n",
		powerregs->pmcr, powerregs->pssr, powerregs->pcfr, powerregs->ppcr,
		powerregs->pwer, powerregs->pspr, powerregs->pgsr, powerregs->posr);
.
## diffname bitsy/power.c 2001/0814
## diff -e /n/emeliedump/2001/0813/sys/src/9/bitsy/power.c /n/emeliedump/2001/0814/sys/src/9/bitsy/power.c
208c
		xlink1 = getcallerpc(&xlink1);

		iprint("deepsleep returned, pc = 0x%lux, sp = 0x%lux\n", xlink1, &xlink);
.
206c
		xlink = getcallerpc(&xlink);

		iprint("call deepsleep, pc = 0x%lux, sp = 0x%lux\n", xlink, &xlink);
.
200a
	ulong xlink, xlink1;
.
193a
	mmuinvalidate();
	delay(10);
.
176a
//		mmurestart();
.
171c
		if(intrregs->icip & (1<<IRQgpio0)){
.
167d
164c
	if(setpowerlabel()){
.
154c
	iprint("entering suspend mode, sp = 0x%lux, pc = 0x%lux, psw = 0x%lux\n\n", &xsp, xlink, power_pl);
.
147a
	iprint("l1table at 0x%8.8lux\n", l1table);
	setpowerlabel();
	for (i = 0; i < 168/4; i++){
		if (i % 4 == 0) iprint("\n");
		iprint("%3d: 0x%8.8lux	", i*4, power_resume[i]);
	}
.
145a
	int i;
	extern ulong l1table;
.
53a
	iprint("mmu: CpControl %lux CpTTB %lux CpDAC %lux\n",
		getcontrol(), getttb(), getdac());
.
## diffname bitsy/power.c 2001/0815
## diff -e /n/emeliedump/2001/0814/sys/src/9/bitsy/power.c /n/emeliedump/2001/0815/sys/src/9/bitsy/power.c
204,205d
202c
	cacheflush();
.
199a
		splx(power_pl);
.
194,195c
		iprint("\nresuming execution, sp = 0x%lux, pc = 0x%lux, psw = 0x%ux\n", &xsp, xlink, splhi());
.
186d
176c
//		memconfregs->mdrefr &= ~0x30000000;
		memconfregs->mecr = mecr;

.
174a
		/* return here with mmu back on */

.
173a
	mecr = memconfregs->mecr;
.
163,164c
	iprint("entering suspend mode, sp = 0x%lux, pc = 0x%lux, psw = 0x%ux\n", &xsp, xlink, power_pl);
.
152,157d
150a
	power_pl = splhi();
.
147,149c
	ulong xsp, xlink, mecr;
.
114,116c
/*	Doesn't work [sjm]
	delay(90);
	powerregs->ppcr = 0;
	delay(90);
*/
.
58a
	checkpagetab();
	checkflash();
//	checkktext();
	iprint("\n\n");
.
54,55c
	iprint("mmu: CpControl %lux CpTTB %lux CpDAC %lux l1table 0x%lux\n",
		getcontrol(), getttb(), getdac(), l1table);
.
32a
	extern ulong l1table;

.
30a
checkflash(void)
{
	ulong *p;
	ulong s;

	s = 0;
	for (p = (ulong*)FLASHZERO; p < (ulong*)(FLASHZERO+8*1024*1024); p++)
		s += *p;
	iprint("flash checksum is 0x%lux\n", s);
}

static void
checkpagetab(void)
{
	extern ulong l1table;
	ulong *p;
	ulong s;

	s = 0;
	for (p = (ulong*)l1table; p < (ulong*)(l1table+16*1024); p++)
		s += *p;
	iprint("page table checksum is 0x%lux\n", s);
}

static void
checkktext(void)
{
	/* check the kernel text */
	ulong *p, *q;
	ulong s;

	s = 0;
	if (savedtext == nil){
		savedtext=malloc((ulong)etext-(ulong)_start);
		if (savedtext == nil)
			iprint("can't malloc savedtext\n");
		memmove(savedtext, _start, (ulong)etext-(ulong)_start);
	}else{
		for (p = (ulong*)_start, q = (ulong*)savedtext; p < (ulong*)(etext); p++,q++) {
			if (*p != *q) {
				iprint("0x%lux: 0x%lux != 0x%lux\n", p, *p, *q);
				s++;
			}
		}
		if (s == 0) iprint("ktext ok\n");
	}
}

static void
.
29a
uchar *savedtext;

.
## diffname bitsy/power.c 2001/0816
## diff -e /n/emeliedump/2001/0815/sys/src/9/bitsy/power.c /n/emeliedump/2001/0816/sys/src/9/bitsy/power.c
249a
		dumpitall();
		delay(1000);
.
246d
241d
227a
		trapresume();
.
217c
	delay(1000);
.
181a
/*	Doesn't work [sjm]
	powerregs->ppcr = 0;
*/
.
171,175d
162c
	powerregs->pcfr = PCFR_opde;
.
151a
	/* Set KAPD and EAPD bits */
	memconfregs->mdrefr |= 0x30000000;
.
114c
	checkktext();
.
80a

.
65,78c
	for (p = (ulong*)l1table; p < (ulong*)(l1table+16*1024); p++)
		s += *p;
	iprint("page table checksum is 0x%lux\n", s);
.
60,61c
	extern ulong l1table;
	ulong *p;
.
58c
checkpagetab(void)
.
54c
	}
	iprint("page 0x%lux checksum 0x%lux\n", (ulong)(p-1)&~0x1fff, s);
.
52c
	for (p = (ulong*)_start; p < (ulong*)etext; p++){
		if(*p == 0)
			iprint("0x%lux->0\n", p);
		if (((ulong)p & 0x1fff) == 0){
			iprint("page 0x%lux checksum 0x%lux\n",
				(ulong)(p-1)&~0x1fff, s);
			s = 0;
		}
.
47d
45c
checkktext(void)
.
## diffname bitsy/power.c 2001/0817
## diff -e /n/emeliedump/2001/0816/sys/src/9/bitsy/power.c /n/emeliedump/2001/0817/sys/src/9/bitsy/power.c
256c
	delay(100);
.
178a
	
	memconfregs->mdrefr |= 0x80000000;
.
177a
	delay(500);
.
176c
	/* set lowest clock; delay to avoid resume hangs on fast sa1110 */
/*	Doesn't work [sjm] 
.
167,170d
165d
161c
	powerregs->pcfr = PCFR_opde|PCFR_fp|PCFR_fs;
.
150c
//	memconfregs->mdrefr |= 0x30000000;
.
## diffname bitsy/power.c 2001/0818
## diff -e /n/emeliedump/2001/0817/sys/src/9/bitsy/power.c /n/emeliedump/2001/0818/sys/src/9/bitsy/power.c
174,177c
	µdelay(90);

	memconfregs->msc0 &= ~0x30003;
	memconfregs->msc1 &= ~0x30003;
	memconfregs->msc2 &= ~0x30003;
	memconfregs->mdrefr = refr;	/* Clear dri 0 ⋯ 11 */
	refr |= 1<<REFR_slfrsh;
//	memconfregs->mdrefr = refr;	/* Set selfrefresh */
.
172c
	memconfregs->mdrefr |= 1<<22;
	µdelay(90);
.
168,169d
150c
	refr = memconfregs->mdrefr;
	refr |= 1<<REFR_kapd | 1 <<REFR_eapd | 1<<REFR_k1db2;
.
148a
	ulong refr;

.
## diffname bitsy/power.c 2001/0820
## diff -e /n/emeliedump/2001/0818/sys/src/9/bitsy/power.c /n/emeliedump/2001/0820/sys/src/9/bitsy/power.c
262c
	power_down();
//	sa1100_power_off();
.
183c

	memconfregs->mdrefr = refr;	/* Set selfrefresh */
.
180a
	refr &= ~0xfff0;
.
## diffname bitsy/power.c 2001/0821
## diff -e /n/emeliedump/2001/0820/sys/src/9/bitsy/power.c /n/emeliedump/2001/0821/sys/src/9/bitsy/power.c
265d
146,189d
20c
extern void	power_resume(void);
.
16c
ulong	power_state[200/4];
.
## diffname bitsy/power.c 2001/0822
## diff -e /n/emeliedump/2001/0821/sys/src/9/bitsy/power.c /n/emeliedump/2001/0822/sys/src/9/bitsy/power.c
291d
278d
## diffname bitsy/power.c 2002/0408
## diff -e /n/emeliedump/2001/0822/sys/src/9/bitsy/power.c /n/emeliedump/2002/0408/sys/src/9/bitsy/power.c
239c
//		iprint("deepsleep returned, pc = 0x%lux, sp = 0x%lux\n", xlink1, &xlink);
.
235c
//		iprint("call deepsleep, pc = 0x%lux, sp = 0x%lux\n", xlink, &xlink);
.
209c
//		dumpitall();
.
176c
//	dumpitall();
.
## diffname bitsy/power.c 2002/0411
## diff -e /n/emeliedump/2002/0408/sys/src/9/bitsy/power.c /n/emeliedump/2002/0411/sys/src/9/bitsy/power.c
271a
	addclock0link(blanktimer);
.
268a
static void
blanktimer(void)
{
	drawactive(0);
}

.
## diffname bitsy/power.c 2002/0412
## diff -e /n/emeliedump/2002/0411/sys/src/9/bitsy/power.c /n/emeliedump/2002/0412/sys/src/9/bitsy/power.c
294c
		uartputs(msgb, strlen(msgb));
.
289c
		uartputs(msga, strlen(msga));
.
## diffname bitsy/power.c 2002/0424
## diff -e /n/emeliedump/2002/0412/sys/src/9/bitsy/power.c /n/emeliedump/2002/0424/sys/src/9/bitsy/power.c
212c
		audiopower(1);
.
209c
		dumpitall();
.
176c
	dumpitall();
.
## diffname bitsy/power.c 2002/0518
## diff -e /n/emeliedump/2002/0424/sys/src/9/bitsy/power.c /n/emeliedump/2002/0518/sys/src/9/bitsy/power.c
242a
//		iprint("deepsleep returned, pc = 0x%lux, sp = 0x%lux\n", xlink1, &xlink);
.
239d
212c
//		audiopower(1);
.
209c
//		dumpitall();
.
192c
//		memconfregs->mecr = mecr;
.
176c
//	dumpitall();
.
169a

	*resumeaddr = (ulong) power_resume;
//	*resumeaddr = nil;
.
166a
	extern void power_resume(void);
.
31a

.
16a
ulong	resumeaddr[1];
.
## diffname bitsy/power.c 2002/0604
## diff -e /n/emeliedump/2002/0518/sys/src/9/bitsy/power.c /n/emeliedump/2002/0604/sys/src/9/bitsy/power.c
283a
	extern ulong power_magic;
	extern ulong power_code;
	extern ulong doze_code;
	ulong *p, *q, i;

	p = (ulong*)(((ulong)&power_magic + 0x1f) & ~0x1f);
	q = &power_code;
	for (i = 0; i < 8; i++)
		*p++ = *q++;
	p = (ulong*)(((ulong)doze + 0x3f) & ~0x1f);
	q = &doze_code;
	for (i = 0; i < 3; i++)
		*p++ = *q++;


	*resumeaddr = (ulong) power_resume;
.
191c
//	mecr = memconfregs->mecr;
.
174,175d
168c
	ulong xsp, xlink;
//	ulong mecr;
.
33d
## diffname bitsy/power.c 2002/0618
## diff -e /n/emeliedump/2002/0604/sys/src/9/bitsy/power.c /n/emeliedump/2002/0618/sys/src/9/bitsy/power.c
218a
		pcmciapower(1);
.
174a
	pcmciapower(0);
.
## diffname bitsy/power.c 2002/0619
## diff -e /n/emeliedump/2002/0618/sys/src/9/bitsy/power.c /n/emeliedump/2002/0619/sys/src/9/bitsy/power.c
320d
298d
## diffname bitsy/power.c 2002/0625
## diff -e /n/emeliedump/2002/0619/sys/src/9/bitsy/power.c /n/emeliedump/2002/0625/sys/src/9/bitsy/power.c
220c
	//	pcmciapower(1);
.
217c
		audiopower(1);
.
195,198d
190d
## diffname bitsy/power.c 2002/0626
## diff -e /n/emeliedump/2002/0625/sys/src/9/bitsy/power.c /n/emeliedump/2002/0626/sys/src/9/bitsy/power.c
215c
		pcmciapower(1);
.
## diffname bitsy/power.c 2002/1017
## diff -e /n/emeliedump/2002/0626/sys/src/9/bitsy/power.c /n/emeliedump/2002/1017/sys/src/9/bitsy/power.c
294c
	addclock0link(blanktimer, 1000/HZ);
.
## diffname bitsy/power.c 2002/1112
## diff -e /n/emeliedump/2002/1017/sys/src/9/bitsy/power.c /n/emeliedump/2002/1112/sys/src/9/bitsy/power.c
313a

.
294a
	addclock0link(suspendtimer, 1000/HZ);
.
276a
resetsuspendtimer(void)
{
	suspendtime = 60 * HZ;
}

static void
suspendtimer(void)
{
	uvlong	now;

	return;	// does not work well.

	if (suspendtime > 0)
		suspendtime--;
	if (suspendtime == 0){
		now = seconds();
		if (now < lastsuspend + 10){
			resetsuspendtimer();
			return;
		}
		lastsuspend = seconds();
		deepsleep();
		lastsuspend = seconds();
		return;
	}
}

void
.
275a
static ulong suspendtime = 120 * HZ;
static int lastsuspend;

.
220a
	savedtod = todgetoff();
.
203a
		todsetoff( savedtod + clkd * TODFREQ);
		resetsuspendtimer();
.
202c
		clkd = clockpower(1);
.
168a
	ulong clkd;
	vlong savedtod;
.
33a
todsetoff(vlong off)
{
	tod.off = off;
}

static void
.
32a
static vlong
todgetoff(void)
{
	return tod.off;
}

.
11a

/*
 * Very ugly. This is just to get/set the offset field without
 * touching port/tod.c.
 */
#define TODFREQ	1000000000LL
extern struct {
	ulong	cnt;
	Lock;
	vlong	multiplier;	// t = off + (multiplier*ticks)>>31
	vlong	hz;		// frequency of fast clock
	vlong	last;		// last reading of fast clock
	vlong	off;		// offset from epoch to last
	vlong	lasttime;	// last return value from todget
	vlong	delta;	// add 'delta' each slow clock tick from sstart to send
	ulong	sstart;	// ...
	ulong	send;	// ...
} tod;


.
## diffname bitsy/power.c 2002/1121
## diff -e /n/emeliedump/2002/1112/sys/src/9/bitsy/power.c /n/emeliedump/2002/1121/sys/src/9/bitsy/power.c
257c
	savedtod = todget(nil);
.
238c
		todset(savedtod + clkd * TODFREQ, 0LL, 0);
.
60,65d
53,58d
36a

.
31d
18,29d
12,16d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].