from /n/sources/patch/bcm-cputemp. track pi's cpu temperature. needs to be retested. Reference: /n/atom/patch/applied2013/picputemp Date: Sat Dec 14 13:55:15 CET 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/bcm/devarch.c Sat Dec 14 13:54:04 2013 +++ /sys/src/9/bcm/devarch.c Sat Dec 14 13:54:04 2013 @@ -156,8 +156,17 @@ return readstr(offset, a, n, str); } +static long +cputempread(Chan*, void *a, long n, vlong offset) +{ + char str[128]; + snprint(str, sizeof str, "%d±%d\n", gettemp(TempDefault) / 1000, 1); + return readstr(offset, a, n, str); +} + void archinit(void) { addarchfile("cputype", 0444, cputyperead, nil); + addarchfile("cputemp", 0444, cputempread, nil); } --- /sys/src/9/bcm/fns.h Sat Dec 14 13:54:05 2013 +++ /sys/src/9/bcm/fns.h Sat Dec 14 13:54:06 2013 @@ -40,6 +40,7 @@ extern uint getfirmware(void); extern int getpower(int); extern void getramsize(Confmem*); +extern uint gettemp(int); extern u32int ifsrget(void); extern void irqenable(int, void (*)(Ureg*, void*), void*); #define intrenable(i, f, a, b, n) irqenable((i), (f), (a)) --- /sys/src/9/bcm/io.h Sat Dec 14 13:54:06 2013 +++ /sys/src/9/bcm/io.h Sat Dec 14 13:54:07 2013 @@ -42,4 +42,6 @@ ClkSdram, ClkPixel, ClkPwm, + + TempDefault = 0, /* Specification says "id should be 0" */ }; --- /sys/src/9/bcm/vcore.c Sat Dec 14 13:54:08 2013 +++ /sys/src/9/bcm/vcore.c Sat Dec 14 13:54:08 2013 @@ -39,6 +39,7 @@ TagSetpower = 0x00028001, Powerwait = 1<<1, TagGetclkspd= 0x00030002, + TagGettemp = 0x00030006, TagFballoc = 0x00040001, TagFbfree = 0x00048001, TagFbblank = 0x00040002, @@ -111,10 +112,10 @@ static int vcreq(int tag, void *buf, int vallen, int rsplen) { - static uintptr base = BUSDRAM; - Prophdr *prop; uintptr r; int n; + Prophdr *prop; + static uintptr base = BUSDRAM; if(rsplen < vallen) rsplen = vallen; @@ -142,7 +143,7 @@ if(prop->req == RspOk && prop->tag == tag && (prop->taglen&TagResp)) { - if((n = prop->taglen&~TagResp) < rsplen) + if((n = prop->taglen & ~TagResp) < rsplen) rsplen = n; memmove(buf, prop->data, rsplen); }else @@ -225,7 +226,7 @@ buf[0] = dev; buf[1] = 0; - if(vcreq(TagGetpower, buf, sizeof(buf[0]), sizeof buf) != sizeof buf) + if(vcreq(TagGetpower, buf, sizeof buf[0], sizeof buf) != sizeof buf) return -1; return buf[0] & 1; } @@ -238,9 +239,9 @@ getethermac(void) { uchar ea[8]; - static char buf[16]; char *p; int i; + static char buf[16]; memset(ea, 0, sizeof ea); vcreq(TagGetmac, ea, 0, sizeof ea); @@ -288,5 +289,19 @@ buf[0] = clkid; if(vcreq(TagGetclkspd, buf, sizeof(buf[0]), sizeof(buf)) != sizeof buf) return 0; + return buf[1]; +} + +/* +* Get temperature +*/ +uint +gettemp(int tempid) +{ + u32int buf[2]; + buf[0] = tempid; + if(vcreq(TagGettemp, buf, sizeof(buf[0]), sizeof(buf)) != sizeof buf) + return 0; + return buf[1]; }