1 /*
2 * bcm2835 (e.g. raspberry pi) architecture-specific stuff
3 */
4
5 #include "u.h"
6 #include "../port/lib.h"
7 #include "mem.h"
8 #include "dat.h"
9 #include "fns.h"
10 #include "../port/error.h"
11 #include "io.h"
12 #include "arm.h"
13
14 #include "../port/netif.h"
15 #include "etherif.h"
16
17 #define POWERREGS (VIRTIO+0x100000)
18
19 enum {
20 Wdogfreq = 65536,
21 Wdogtime = 5, /* seconds, ≤ 15 */
22 };
23
24 /*
25 * Power management / watchdog registers
26 */
27 enum {
28 Rstc = 0x1c>>2,
29 Password = 0x5A<<24,
30 CfgMask = 0x03<<4,
31 CfgReset = 0x02<<4,
32 Rsts = 0x20>>2,
33 Wdog = 0x24>>2,
34 };
35
36 void
archreset(void)37 archreset(void)
38 {
39 fpon();
40 }
41
42 void
archreboot(void)43 archreboot(void)
44 {
45 u32int *r;
46
47 r = (u32int*)POWERREGS;
48 r[Wdog] = Password | 1;
49 r[Rstc] = Password | (r[Rstc] & ~CfgMask) | CfgReset;
50 coherence();
51 for(;;)
52 ;
53 }
54
55 static void
wdogfeed(void)56 wdogfeed(void)
57 {
58 u32int *r;
59
60 r = (u32int*)POWERREGS;
61 r[Wdog] = Password | (Wdogtime * Wdogfreq);
62 r[Rstc] = Password | (r[Rstc] & ~CfgMask) | CfgReset;
63 }
64
65 void
wdogoff(void)66 wdogoff(void)
67 {
68 u32int *r;
69
70 r = (u32int*)POWERREGS;
71 r[Rstc] = Password | (r[Rstc] & ~CfgMask);
72 }
73
74 void
cpuidprint(void)75 cpuidprint(void)
76 {
77 print("cpu%d: %dMHz ARM1176JZF-S\n", m->machno, m->cpumhz);
78 }
79
80 void
archbcmlink(void)81 archbcmlink(void)
82 {
83 addclock0link(wdogfeed, HZ);
84 }
85
86 int
archether(unsigned ctlrno,Ether * ether)87 archether(unsigned ctlrno, Ether *ether)
88 {
89 switch(ctlrno) {
90 case 0:
91 ether->type = "usb";
92 ether->ctlrno = ctlrno;
93 ether->irq = -1;
94 ether->nopt = 0;
95 ether->mbps = 100;
96 return 1;
97 }
98 return -1;
99 }
100
101