archbcm.c 1.4 KB

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