## diffname mpc/devrtc.c 1999/0121 ## diff -e /dev/null /n/emeliedump/1999/0121/sys/src/brazil/mpc/devrtc.c 0a #include "u.h" #include "../port/lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "../port/error.h" #include "io.h" /* * MPC8xx real time clock * FADS board option switch * interrupt statistics */ enum{ Qrtc = 1, Qswitch, Qintstat, /* sccr */ RTDIV= 1<<24, RTSEL= 1<<23, /* rtcsc */ RTE= 1<<0, R38K= 1<<4, }; static QLock rtclock; /* mutex on clock operations */ static Dirtab rtcdir[]={ "rtc", {Qrtc, 0}, 12, 0666, "switch", {Qswitch, 0}, 0, 0444, "intstat", {Qintstat, 0}, 0, 0444, }; #define NRTC (sizeof(rtcdir)/sizeof(rtcdir[0])) static void rtcreset(void) { IMM *io; int n; io = m->iomem; io->rtcsck = KEEP_ALIVE_KEY; n = (RTClevel<<8)|RTE; if(m->oscclk == 5) n |= R38K; io->rtcsc = n; io->rtcsck = ~KEEP_ALIVE_KEY; print("sccr=#%8.8lux plprcr=#%8.8lux\n", io->sccr, io->plprcr); } static Chan* rtcattach(char *spec) { return devattach('r', spec); } static int rtcwalk(Chan *c, char *name) { return devwalk(c, name, rtcdir, NRTC, devgen); } static void rtcstat(Chan *c, char *dp) { devstat(c, dp, rtcdir, NRTC, devgen); } static Chan* rtcopen(Chan *c, int omode) { omode = openmode(omode); switch(c->qid.path){ case Qrtc: if(strcmp(up->user, eve)!=0 && omode!=OREAD) error(Eperm); break; case Qswitch: case Qintstat: if(omode!=OREAD) error(Eperm); break; } return devopen(c, omode, rtcdir, NRTC, devgen); } static void rtcclose(Chan*) { } static long rtcread(Chan *c, void *buf, long n, vlong offset) { ulong t; char *b; if(c->qid.path & CHDIR) return devdirread(c, buf, n, rtcdir, NRTC, devgen); switch(c->qid.path){ case Qrtc: t = m->iomem->rtc; n = readnum(offset, buf, n, t, 12); return n; case Qswitch: return readnum(offset, buf, n, (m->bcsr[2]>>19)&0xF, 12); } error(Egreg); return 0; /* not reached */ } static long rtcwrite(Chan *c, void *buf, long n, vlong offset) { ulong secs; char *cp, *ep; IMM *io; switch(c->qid.path){ case Qrtc: if(offset!=0) error(Ebadarg); /* * read the time */ cp = ep = buf; ep += n; while(cp < ep){ if(*cp>='0' && *cp<='9') break; cp++; } secs = strtoul(cp, 0, 0); /* * set it */ io = ioplock(); io->rtck = KEEP_ALIVE_KEY; io->rtc = secs; io->rtck = ~KEEP_ALIVE_KEY; iopunlock(); return n; case Qswitch: return 0; } error(Egreg); return 0; /* not reached */ } long rtctime(void) { return m->iomem->rtc; } Dev rtcdevtab = { 'r', "rtc", rtcreset, devinit, rtcattach, devclone, rtcwalk, rtcstat, rtcopen, devcreate, rtcclose, rtcread, devbread, rtcwrite, devbwrite, devremove, devwstat, }; . ## diffname mpc/devrtc.c 1999/0122 ## diff -e /n/emeliedump/1999/0121/sys/src/brazil/mpc/devrtc.c /n/emeliedump/1999/0122/sys/src/brazil/mpc/devrtc.c 111c return readnum(offset, buf, n, 0xf/*(m->bcsr[2]>>19)&0xF*/, 12); . 100c // char *b; . ## diffname mpc/devrtc.c 1999/0608 ## diff -e /n/emeliedump/1999/0122/sys/src/brazil/mpc/devrtc.c /n/emeliedump/1999/0608/sys/src/brazil/mpc/devrtc.c 148,149c case Qnvram: if(offset >= Nvsize) return 0; t = offset; if(t + n > Nvsize) n = Nvsize - t; ilock(&nvrtlock); memmove((uchar*)(NVRAMMEM + Nvoff + offset), buf, n); iunlock(&nvrtlock); return n; . 122a ulong t; . 110,111c case Qnvram: if(offset >= Nvsize) return 0; t = offset; if(t + n > Nvsize) n = Nvsize - t; ilock(&nvrtlock); memmove(buf, (uchar*)(NVRAMMEM + Nvoff + t), n); iunlock(&nvrtlock); return n; . 100d 82,84c case Qnvram: if(strcmp(up->user, eve)!=0) . 34,35c "nvram", {Qnvram, 0}, Nvsize, 0664, . 31a . 30a static Lock nvrtlock; . 27a Nvoff= 4*1024, /* where usable nvram lives */ Nvsize= 4*1024, . 18,19c Qnvram, . 10,15d ## diffname mpc/devrtc.c 1999/0612 ## diff -e /n/emeliedump/1999/0608/sys/src/brazil/mpc/devrtc.c /n/emeliedump/1999/0612/sys/src/brazil/mpc/devrtc.c 159a iunlock(&nvrtlock); return n; case Qnvram2: if(offset >= Nvsize2) return 0; t = offset; if(t + n > Nvsize2) n = Nvsize2 - t; ilock(&nvrtlock); memmove((uchar*)(NVRAMMEM + Nvoff2 + offset), buf, n); . 114a case Qnvram2: if(offset >= Nvsize2) return 0; t = offset; if(t + n > Nvsize2) n = Nvsize2 - t; ilock(&nvrtlock); memmove(buf, (uchar*)(NVRAMMEM + Nvoff2 + t), n); iunlock(&nvrtlock); return n; . 79a case Qnvram2: . 32a "nvram2", {Qnvram2, 0}, Nvsize, 0664, . 23a Nvoff2= 8*1024, /* where usable nvram lives */ Nvsize2= 4*1024, . 12a Qnvram2, . ## diffname mpc/devrtc.c 1999/0618 ## diff -e /n/emeliedump/1999/0612/sys/src/brazil/mpc/devrtc.c /n/emeliedump/1999/0618/sys/src/brazil/mpc/devrtc.c 25c Nvoff2= 8*1024, /* where second usable nvram lives */ . ## diffname mpc/devrtc.c 2000/0516 ## diff -e /n/emeliedump/1999/0618/sys/src/brazil/mpc/devrtc.c /n/emeliedump/2000/0516/sys/src/9/mpc/devrtc.c 185a return n; case Qled: if(strncmp(buf, "on", 2) == 0) powerupled(); else if(strncmp(buf, "off", 3) == 0) powerdownled(); else error("unknown command"); . 177a return 0; . 167a return 0; . 129a case Qled: return 0; . 120a return 0; . 110a return 0; . 79a case Qled: . 36a "led", {Qled, 0}, 0, 0664, . 32d 13a Qled, . ## diffname mpc/devrtc.c 2000/0817 ## diff -e /n/emeliedump/2000/0516/sys/src/9/mpc/devrtc.c /n/emeliedump/2000/0817/sys/src/9/mpc/devrtc.c 184a memmove((uchar*)spibuf,(uchar*)buf,2); spiwriteall(spibuf); . 183a . 180,182c ilock(&eepromlock); index=0; spienwrite(); /*if the writing addr starts at an odd address, we need to read in the higher byte first, combined it with the lower byte, and then write them out */ if(t%2!=0){ print("not starting from an even address\n"); readaddr=(t-1)/2; spiread(readaddr,spibuf); memmove((uchar*)spibuf+1,(uchar*)buf+index,1); //spienwrite(); spiwrite(readaddr,spibuf); //spidiswrite(); index++; writeaddr=readaddr+1; } else writeaddr=t/2; while(index= 5) return 0; t = offset; if(t + n > 5) n = 5 - t; memmove(buf, "kitty" + t, n); return n; . 123a print("ram 2\n"); . 119,121c ilock(&eepromlock); /* read from eeprom through spi, two bytes a time*/ index=0; if(t%2!=0){ print("not starting from an even address\n"); readaddr=(t-1)/2; spiread(readaddr,spibuf); memmove((uchar*)buf+index,(uchar *)spibuf+1,1); index++; readaddr++; } else readaddr=t/2; while(index