archomap.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /*
  2. * omap3530 SoC (e.g. beagleboard) architecture-specific stuff
  3. *
  4. * errata: usb port 3 cannot operate in ulpi mode, only serial or
  5. * utmi tll mode
  6. */
  7. #include "u.h"
  8. #include "../port/lib.h"
  9. #include "mem.h"
  10. #include "dat.h"
  11. #include "fns.h"
  12. #include "../port/error.h"
  13. #include "io.h"
  14. #include "arm.h"
  15. #include "../port/netif.h"
  16. #include "etherif.h"
  17. #include "../port/flashif.h"
  18. #include "../port/usb.h"
  19. #include "../port/portusbehci.h"
  20. #include "usbehci.h"
  21. #define FREQSEL(x) ((x) << 4)
  22. typedef struct Cm Cm;
  23. typedef struct Cntrl Cntrl;
  24. typedef struct Gen Gen;
  25. typedef struct Gpio Gpio;
  26. typedef struct L3agent L3agent;
  27. typedef struct L3protreg L3protreg;
  28. typedef struct L3regs L3regs;
  29. typedef struct Prm Prm;
  30. typedef struct Usbotg Usbotg;
  31. typedef struct Usbtll Usbtll;
  32. /* omap3 non-standard usb stuff */
  33. struct Usbotg {
  34. uchar faddr;
  35. uchar power;
  36. ushort intrtx;
  37. ushort intrrx;
  38. ushort intrtxe;
  39. ushort intrrxe;
  40. uchar intrusb;
  41. uchar intrusbe;
  42. ushort frame;
  43. uchar index;
  44. uchar testmode;
  45. /* indexed registers follow; ignore for now */
  46. uchar _pad0[0x400 - 0x10];
  47. ulong otgrev;
  48. ulong otgsyscfg;
  49. ulong otgsyssts;
  50. ulong otgifcsel; /* interface selection */
  51. uchar _pad1[0x414 - 0x410];
  52. ulong otgforcestdby;
  53. };
  54. enum {
  55. /* power bits */
  56. Hsen = 1<<5, /* high-speed enable */
  57. /* testmode bits */
  58. Forcehost = 1<<7, /* force host (vs peripheral) mode */
  59. Forcehs = 1<<4, /* force high-speed at reset */
  60. /* otgsyscfg bits */
  61. Midle = 1<<12, /* no standby mode */
  62. Sidle = 1<<3, /* no idle mode */
  63. // Softreset = 1<<1,
  64. /* otgsyssts bits, per sysstatus */
  65. };
  66. struct Usbtll {
  67. ulong revision; /* ro */
  68. uchar _pad0[0x10-0x4];
  69. ulong sysconfig;
  70. ulong sysstatus; /* ro */
  71. ulong irqstatus;
  72. ulong irqenable;
  73. };
  74. enum {
  75. /* sysconfig bits */
  76. Softreset = 1<<1,
  77. /* sysstatus bits */
  78. Resetdone = 1<<0,
  79. /* only in uhh->sysstatus */
  80. Ehci_resetdone = 1<<2,
  81. Ohci_resetdone = 1<<1,
  82. };
  83. /*
  84. * an array of these structs is preceded by error_log at 0x20, control,
  85. * error_clear_single, error_clear_multi. first struct is at offset 0x48.
  86. */
  87. struct L3protreg { /* hw: an L3 protection region */
  88. uvlong req_info_perm;
  89. uvlong read_perm;
  90. uvlong write_perm;
  91. uvlong addr_match; /* ro? write this one last, then flush */
  92. };
  93. // TODO: set these permission bits (e.g., for usb)?
  94. enum {
  95. Permusbhost = 1<<9,
  96. Permusbotg = 1<<4,
  97. Permsysdma = 1<<3,
  98. Permmpu = 1<<1,
  99. };
  100. struct L3agent { /* hw registers */
  101. uchar _pad0[0x20];
  102. uvlong ctl;
  103. uvlong sts;
  104. uchar _pad1[0x58 - 0x30];
  105. uvlong errlog;
  106. uvlong errlogaddr;
  107. };
  108. struct L3regs {
  109. L3protreg *base; /* base of array */
  110. int upper; /* index maximum */
  111. char *name;
  112. };
  113. L3regs l3regs[] = {
  114. (L3protreg *)(PHYSL3GPMCPM+0x48), 7, "gpmc", /* known to be first */
  115. (L3protreg *)(PHYSL3PMRT+0x48), 1, "rt", /* l3 config */
  116. (L3protreg *)(PHYSL3OCTRAM+0x48), 7, "ocm ram",
  117. (L3protreg *)(PHYSL3OCTROM+0x48), 1, "ocm rom",
  118. (L3protreg *)(PHYSL3MAD2D+0x48), 7, "mad2d", /* die-to-die */
  119. (L3protreg *)(PHYSL3IVA+0x48), 3, "iva2.2", /* a/v */
  120. };
  121. /*
  122. * PRM_CLKSEL (0x48306d40) low 3 bits are system clock speed, assuming
  123. * units of MHz: 0 = 12, 1 = 13, 2 = 19.2, 3 = 26, 4 = 38.4, 5 = 16.8
  124. */
  125. struct Cm { /* clock management */
  126. ulong fclken; /* ``functional'' clock enable */
  127. ulong fclken2;
  128. ulong fclken3;
  129. uchar _pad0[0x10 - 0xc];
  130. ulong iclken; /* ``interface'' clock enable */
  131. ulong iclken2;
  132. ulong iclken3;
  133. uchar _pad1[0x20 - 0x1c];
  134. ulong idlest; /* idle status */
  135. ulong idlest2;
  136. ulong idlest3;
  137. uchar _pad2[0x30 - 0x2c];
  138. ulong autoidle;
  139. ulong autoidle2;
  140. ulong autoidle3;
  141. uchar _pad3[0x40 - 0x3c];
  142. union {
  143. ulong clksel[5];
  144. struct unused {
  145. ulong sleepdep;
  146. ulong clkstctrl;
  147. ulong clkstst;
  148. };
  149. uchar _pad4[0x70 - 0x40];
  150. };
  151. ulong clkoutctrl;
  152. };
  153. struct Prm { /* power & reset management */
  154. uchar _pad[0x50];
  155. ulong rstctrl;
  156. };
  157. struct Gpio {
  158. ulong _pad0[4];
  159. ulong sysconfig;
  160. ulong sysstatus;
  161. ulong irqsts1; /* for mpu */
  162. ulong irqen1;
  163. ulong wkupen;
  164. ulong _pad1;
  165. ulong irqsts2; /* for iva */
  166. ulong irqen2;
  167. ulong ctrl;
  168. ulong oe;
  169. ulong datain;
  170. ulong dataout;
  171. ulong lvldet0;
  172. ulong lvldet1;
  173. ulong risingdet;
  174. ulong fallingdet;
  175. /* rest are uninteresting */
  176. ulong deben; /* debouncing enable */
  177. ulong debtime;
  178. ulong _pad2[2];
  179. ulong clrirqen1;
  180. ulong setirqen1;
  181. ulong _pad3[2];
  182. ulong clrirqen2;
  183. ulong setirqen2;
  184. ulong _pad4[2];
  185. ulong clrwkupen;
  186. ulong setwkupen;
  187. ulong _pad5[2];
  188. ulong clrdataout;
  189. ulong setdataout;
  190. };
  191. enum {
  192. /* clock enable & idle status bits */
  193. Wkusimocp = 1 << 9, /* SIM card: uses 120MHz clock */
  194. Wkwdt2 = 1 << 5, /* wdt2 clock enable bit for wakeup */
  195. Wkgpio1 = 1 << 3, /* gpio1 " */
  196. Wkgpt1 = 1 << 0, /* gpt1 " */
  197. Dssl3l4 = 1 << 0, /* dss l3, l4 i clks */
  198. Dsstv = 1 << 2, /* dss tv f clock */
  199. Dss2 = 1 << 1, /* dss clock 2 */
  200. Dss1 = 1 << 0, /* dss clock 1 */
  201. Pergpio6 = 1 << 17,
  202. Pergpio5 = 1 << 16,
  203. Pergpio4 = 1 << 15,
  204. Pergpio3 = 1 << 14,
  205. Pergpio2 = 1 << 13,
  206. Perwdt3 = 1 << 12, /* wdt3 clock enable bit for periphs */
  207. Peruart3 = 1 << 11, /* console uart */
  208. Pergpt9 = 1 << 10,
  209. Pergpt8 = 1 << 9,
  210. Pergpt7 = 1 << 8,
  211. Pergpt6 = 1 << 7,
  212. Pergpt5 = 1 << 6,
  213. Pergpt4 = 1 << 5,
  214. Pergpt3 = 1 << 4,
  215. Pergpt2 = 1 << 3, /* gpt2 clock enable bit for periphs */
  216. Perenable = Pergpio6 | Pergpio5 | Perwdt3 | Pergpt2 | Peruart3,
  217. Usbhost2 = 1 << 1, /* 120MHz clock enable */
  218. Usbhost1 = 1 << 0, /* 48MHz clock enable */
  219. Usbhost = Usbhost1, /* iclock enable */
  220. Usbhostidle = 1 << 1,
  221. Usbhoststdby = 1 << 0,
  222. Coreusbhsotg = 1 << 4, /* usb hs otg enable bit */
  223. Core3usbtll = 1 << 2, /* usb tll enable bit */
  224. /* core->idlest bits */
  225. Coreusbhsotgidle = 1 << 5,
  226. Coreusbhsotgstdby= 1 << 4,
  227. Dplllock = 7,
  228. /* mpu->idlest2 bits */
  229. Dplllocked = 1,
  230. Dpllbypassed = 0,
  231. /* wkup->idlest bits */
  232. Gpio1idle = 1 << 3,
  233. /* dss->idlest bits */
  234. Dssidle = 1 << 1,
  235. Gpio1vidmagic = 1<<24 | 1<<8 | 1<<5, /* gpio 1 pins for video */
  236. };
  237. enum {
  238. Rstgs = 1 << 1, /* global sw. reset */
  239. /* fp control regs. most are read-only */
  240. Fpsid = 0,
  241. Fpscr, /* rw */
  242. Mvfr1 = 6,
  243. Mvfr0,
  244. Fpexc, /* rw */
  245. };
  246. /* see ether9221.c for explanation */
  247. enum {
  248. Ethergpio = 176,
  249. Etherchanbit = 1 << (Ethergpio % 32),
  250. };
  251. /*
  252. * these shift values are for the Cortex-A8 L1 cache (A=2, L=6) and
  253. * the Cortex-A8 L2 cache (A=3, L=6).
  254. * A = log2(# of ways), L = log2(bytes per cache line).
  255. * see armv7 arch ref p. 1403.
  256. *
  257. * #define L1WAYSH 30
  258. * #define L1SETSH 6
  259. * #define L2WAYSH 29
  260. * #define L2SETSH 6
  261. */
  262. enum {
  263. /*
  264. * cache capabilities. write-back vs write-through is controlled
  265. * by the Buffered bit in PTEs.
  266. */
  267. Cawt = 1 << 31,
  268. Cawb = 1 << 30,
  269. Cara = 1 << 29,
  270. Cawa = 1 << 28,
  271. };
  272. struct Gen {
  273. ulong padconf_off;
  274. ulong devconf0;
  275. uchar _pad0[0x68 - 8];
  276. ulong devconf1;
  277. };
  278. struct Cntrl {
  279. ulong _pad0;
  280. ulong id;
  281. ulong _pad1;
  282. ulong skuid;
  283. };
  284. static char *
  285. devidstr(ulong)
  286. {
  287. return "ARM Cortex-A8";
  288. }
  289. void
  290. archomaplink(void)
  291. {
  292. }
  293. int
  294. ispow2(uvlong ul)
  295. {
  296. /* see Hacker's Delight if this isn't obvious */
  297. return (ul & (ul - 1)) == 0;
  298. }
  299. /*
  300. * return exponent of smallest power of 2 ≥ n
  301. */
  302. int
  303. log2(ulong n)
  304. {
  305. int i;
  306. i = 31 - clz(n);
  307. if (n == 0 || !ispow2(n))
  308. i++;
  309. return i;
  310. }
  311. void
  312. archconfinit(void)
  313. {
  314. char *p;
  315. ulong mhz;
  316. assert(m != nil);
  317. m->cpuhz = 500 * Mhz; /* beagle speed */
  318. p = getconf("*cpumhz");
  319. if (p) {
  320. mhz = atoi(p) * Mhz;
  321. if (mhz >= 100*Mhz && mhz <= 3000UL*Mhz)
  322. m->cpuhz = mhz;
  323. }
  324. m->delayloop = m->cpuhz/2000; /* initial estimate */
  325. }
  326. static void
  327. prperm(uvlong perm)
  328. {
  329. if (perm == MASK(16))
  330. print("all");
  331. else
  332. print("%#llux", perm);
  333. }
  334. static void
  335. prl3region(L3protreg *pr, int r)
  336. {
  337. int level, size, addrspace;
  338. uvlong am, base;
  339. if (r == 0)
  340. am = 0;
  341. else
  342. am = pr->addr_match;
  343. size = (am >> 3) & MASK(5);
  344. if (r > 0 && size == 0) /* disabled? */
  345. return;
  346. print(" %d: perms req ", r);
  347. prperm(pr->req_info_perm);
  348. if (pr->read_perm == pr->write_perm && pr->read_perm == MASK(16))
  349. print(" rw all");
  350. else {
  351. print(" read ");
  352. prperm(pr->read_perm);
  353. print(" write ");
  354. prperm(pr->write_perm);
  355. }
  356. if (r == 0)
  357. print(", all addrs level 0");
  358. else {
  359. size = 1 << size; /* 2^size */
  360. level = (am >> 9) & 1;
  361. if (r == 1)
  362. level = 3;
  363. else
  364. level++;
  365. addrspace = am & 7;
  366. base = am & ~MASK(10);
  367. print(", base %#llux size %dKB level %d addrspace %d",
  368. base, size, level, addrspace);
  369. }
  370. print("\n");
  371. delay(100);
  372. }
  373. /*
  374. * dump the l3 interconnect firewall settings by protection region.
  375. * mpu, sys dma and both usbs (0x21a) should be set in all read & write
  376. * permission registers.
  377. */
  378. static void
  379. dumpl3pr(void)
  380. {
  381. int r;
  382. L3regs *reg;
  383. L3protreg *pr;
  384. for (reg = l3regs; reg < l3regs + nelem(l3regs); reg++) {
  385. print("%#p (%s) enabled l3 regions:\n", reg->base, reg->name);
  386. for (r = 0; r <= reg->upper; r++)
  387. prl3region(reg->base + r, r);
  388. }
  389. if (0) { // TODO
  390. /* touch up gpmc perms */
  391. reg = l3regs; /* first entry is gpmc */
  392. for (r = 0; r <= reg->upper; r++) {
  393. pr = reg->base + r;
  394. // TODO
  395. }
  396. print("%#p (%s) modified l3 regions:\n", reg->base, reg->name);
  397. for (r = 0; r <= reg->upper; r++)
  398. prl3region(reg->base + r, r);
  399. }
  400. }
  401. static void
  402. p16(uchar *p, ulong v)
  403. {
  404. *p++ = v>>8;
  405. *p = v;
  406. }
  407. static void
  408. p32(uchar *p, ulong v)
  409. {
  410. *p++ = v>>24;
  411. *p++ = v>>16;
  412. *p++ = v>>8;
  413. *p = v;
  414. }
  415. int
  416. archether(unsigned ctlrno, Ether *ether)
  417. {
  418. switch(ctlrno) {
  419. case 0:
  420. /* there's no built-in ether on the beagle but igepv2 has 1 */
  421. ether->type = "9221";
  422. ether->ctlrno = ctlrno;
  423. ether->irq = 34;
  424. ether->nopt = 0;
  425. ether->mbps = 100;
  426. return 1;
  427. }
  428. return -1;
  429. }
  430. /*
  431. * turn on all the necessary clocks on the SoC.
  432. *
  433. * a ``functional'' clock drives a device; an ``interface'' clock drives
  434. * its communication with the rest of the system. so the interface
  435. * clock must be enabled to reach the device's registers.
  436. *
  437. * dplls: 1 mpu, 2 iva2, 3 core, 4 per, 5 per2.
  438. */
  439. static void
  440. configmpu(void)
  441. {
  442. ulong clk, mhz, nmhz, maxmhz;
  443. Cm *mpu = (Cm *)PHYSSCMMPU;
  444. Cntrl *id = (Cntrl *)PHYSCNTRL;
  445. if ((id->skuid & MASK(4)) == 8)
  446. maxmhz = 720;
  447. else
  448. maxmhz = 600;
  449. iprint("cpu capable of %ldMHz operation", maxmhz);
  450. clk = mpu->clksel[0];
  451. mhz = (clk >> 8) & MASK(11); /* configured speed */
  452. // iprint("\tfclk src %ld; dpll1 mult %ld (MHz) div %ld",
  453. // (clk >> 19) & MASK(3), mhz, clk & MASK(7));
  454. iprint("; at %ldMHz", mhz);
  455. nmhz = m->cpuhz / Mhz; /* nominal speed */
  456. if (mhz == nmhz) {
  457. iprint("\n");
  458. return;
  459. }
  460. mhz = nmhz;
  461. if (mhz > maxmhz) {
  462. mhz = maxmhz;
  463. iprint("; limiting operation to %ldMHz", mhz);
  464. }
  465. /* disable dpll1 lock mode; put into low-power bypass mode */
  466. mpu->fclken2 = mpu->fclken2 & ~MASK(3) | 5;
  467. coherence();
  468. while (mpu->idlest2 != Dpllbypassed)
  469. ;
  470. /*
  471. * there's a dance to change processor speed,
  472. * prescribed in spruf98d §4.7.6.9.
  473. */
  474. /* just change multiplier; leave divider alone at 12 (meaning 13?) */
  475. mpu->clksel[0] = clk & ~(MASK(11) << 8) | mhz << 8;
  476. coherence();
  477. /* set output divider (M2) in clksel[1]: leave at 1 */
  478. /*
  479. * u-boot calls us with just freqsel 3 (~1MHz) & dpll1 lock mode.
  480. */
  481. /* set FREQSEL */
  482. mpu->fclken2 = mpu->fclken2 & ~FREQSEL(MASK(4)) | FREQSEL(3);
  483. coherence();
  484. /* set ramp-up delay to `fast' */
  485. mpu->fclken2 = mpu->fclken2 & ~(MASK(2) << 8) | 3 << 8;
  486. coherence();
  487. /* set auto-recalibration (off) */
  488. mpu->fclken2 &= ~(1 << 3);
  489. coherence();
  490. /* disable auto-idle: ? */
  491. /* unmask clock intr: later */
  492. /* enable dpll lock mode */
  493. mpu->fclken2 |= Dplllock;
  494. coherence();
  495. while (mpu->idlest2 != Dplllocked)
  496. ;
  497. delay(200); /* allow time for speed to ramp up */
  498. if (((mpu->clksel[0] >> 8) & MASK(11)) != mhz)
  499. panic("mpu clock speed change didn't stick");
  500. iprint("; now at %ldMHz\n", mhz);
  501. }
  502. static void
  503. configpll(void)
  504. {
  505. int i;
  506. Cm *pll = (Cm *)PHYSSCMPLL;
  507. pll->clkoutctrl |= 1 << 7; /* enable sys_clkout2 */
  508. coherence();
  509. delay(10);
  510. /*
  511. * u-boot calls us with just freqsel 3 (~1MHz) & lock mode
  512. * for both dplls (3 & 4). ensure that.
  513. */
  514. if ((pll->idlest & 3) != 3) {
  515. /* put dpll[34] into low-power bypass mode */
  516. pll->fclken = pll->fclken & ~(MASK(3) << 16 | MASK(3)) |
  517. 1 << 16 | 5;
  518. coherence();
  519. while (pll->idlest & 3) /* wait for both to bypass or stop */
  520. ;
  521. pll->fclken = (FREQSEL(3) | Dplllock) << 16 |
  522. FREQSEL(3) | Dplllock;
  523. coherence();
  524. while ((pll->idlest & 3) != 3) /* wait for both to lock */
  525. ;
  526. }
  527. /*
  528. * u-boot calls us with just freqsel 1 (default but undefined)
  529. * & stop mode for dpll5. try to lock it at 120MHz.
  530. */
  531. if (!(pll->idlest2 & Dplllocked)) {
  532. /* force dpll5 into low-power bypass mode */
  533. pll->fclken2 = 3 << 8 | FREQSEL(1) | 1;
  534. coherence();
  535. for (i = 0; pll->idlest2 & Dplllocked && i < 20; i++)
  536. delay(50);
  537. if (i >= 20)
  538. iprint(" [dpll5 failed to stop]");
  539. /*
  540. * CORE_CLK is 26MHz.
  541. */
  542. pll->clksel[4-1] = 120 << 8 | 12; /* M=120, N=12+1 */
  543. /* M2 divisor: 120MHz clock is exactly the DPLL5 clock */
  544. pll->clksel[5-1] = 1;
  545. coherence();
  546. pll->fclken2 = 3 << 8 | FREQSEL(1) | Dplllock; /* def. freq */
  547. coherence();
  548. for (i = 0; !(pll->idlest2 & Dplllocked) && i < 20; i++)
  549. delay(50);
  550. if (i >= 20)
  551. iprint(" [dpll5 failed to lock]");
  552. }
  553. if (!(pll->idlest2 & (1<<1)))
  554. iprint(" [no 120MHz clock]");
  555. if (!(pll->idlest2 & (1<<3)))
  556. iprint(" [no dpll5 120MHz clock output]");
  557. }
  558. static void
  559. configper(void)
  560. {
  561. Cm *per = (Cm *)PHYSSCMPER;
  562. per->clksel[0] &= ~MASK(8); /* select 32kHz clock for GPTIMER2-9 */
  563. per->iclken |= Perenable;
  564. coherence();
  565. per->fclken |= Perenable;
  566. coherence();
  567. while (per->idlest & Perenable)
  568. ;
  569. per->autoidle = 0;
  570. coherence();
  571. }
  572. static void
  573. configwkup(void)
  574. {
  575. Cm *wkup = (Cm *)PHYSSCMWKUP;
  576. /* select 32kHz clock (not system clock) for GPTIMER1 */
  577. wkup->clksel[0] &= ~1;
  578. wkup->iclken |= Wkusimocp | Wkwdt2 | Wkgpt1;
  579. coherence();
  580. wkup->fclken |= Wkusimocp | Wkwdt2 | Wkgpt1;
  581. coherence();
  582. while (wkup->idlest & (Wkusimocp | Wkwdt2 | Wkgpt1))
  583. ;
  584. }
  585. static void
  586. configusb(void)
  587. {
  588. int i;
  589. Cm *usb = (Cm *)PHYSSCMUSB;
  590. /*
  591. * make the usb registers accessible without address faults,
  592. * notably uhh, ochi & ehci. tll seems to be separate & otg is okay.
  593. */
  594. usb->iclken |= Usbhost;
  595. coherence();
  596. usb->fclken |= Usbhost1 | Usbhost2; /* includes 120MHz clock */
  597. coherence();
  598. for (i = 0; usb->idlest & Usbhostidle && i < 20; i++)
  599. delay(50);
  600. if (i >= 20)
  601. iprint(" [usb inaccessible]");
  602. }
  603. static void
  604. configcore(void)
  605. {
  606. Cm *core = (Cm *)PHYSSCMCORE;
  607. /*
  608. * make the usb tll registers accessible.
  609. */
  610. core->iclken |= Coreusbhsotg;
  611. core->iclken3 |= Core3usbtll;
  612. coherence();
  613. core->fclken3 |= Core3usbtll;
  614. coherence();
  615. delay(100);
  616. while (core->idlest & Coreusbhsotgidle)
  617. ;
  618. if (core->idlest3 & Core3usbtll)
  619. iprint(" [no usb tll]");
  620. }
  621. static void
  622. configclks(void)
  623. {
  624. int s;
  625. Gen *gen = (Gen *)PHYSSCMPCONF;
  626. delay(20);
  627. s = splhi();
  628. configmpu(); /* sets cpu clock rate, turns on dplls 1 & 2 */
  629. /*
  630. * the main goal is to get enough clocks running, in the right order,
  631. * so that usb has all the necessary clock signals.
  632. */
  633. iprint("clocks:");
  634. iprint(" usb");
  635. configusb(); /* starts usb clocks & 120MHz clock */
  636. iprint(", pll");
  637. configpll(); /* starts dplls 3, 4 & 5 & 120MHz clock */
  638. iprint(", wakeup");
  639. configwkup(); /* starts timer clocks and usim clock */
  640. iprint(", per");
  641. configper(); /* starts timer & gpio (ether) clocks */
  642. iprint(", core");
  643. configcore(); /* starts usb tll */
  644. iprint("\n");
  645. gen->devconf0 |= 1 << 1 | 1 << 0; /* dmareq[01] edge sensitive */
  646. /* make dmareq[2-6] edge sensitive */
  647. gen->devconf1 |= 1 << 23 | 1 << 22 | 1 << 21 | 1 << 8 | 1 << 7;
  648. coherence();
  649. splx(s);
  650. delay(20);
  651. }
  652. static void
  653. resetwait(ulong *reg)
  654. {
  655. long bound;
  656. for (bound = 400*Mhz; !(*reg & Resetdone) && bound > 0; bound--)
  657. ;
  658. if (bound <= 0)
  659. iprint("archomap: Resetdone didn't come ready\n");
  660. }
  661. /*
  662. * gpio irq 1 goes to the mpu intr ctlr; irq 2 goes to the iva's.
  663. * this stuff is magic and without it, we won't get irq 34 interrupts
  664. * from the 9221 ethernet controller.
  665. */
  666. static void
  667. configgpio(void)
  668. {
  669. Gpio *gpio = (Gpio *)PHYSGPIO6;
  670. gpio->sysconfig = Softreset;
  671. coherence();
  672. resetwait(&gpio->sysstatus);
  673. gpio->ctrl = 1<<1 | 0; /* enable this gpio module, gating ratio 1 */
  674. gpio->oe |= Etherchanbit; /* cfg ether pin as input */
  675. coherence();
  676. gpio->irqen1 = Etherchanbit; /* channel # == pin # */
  677. gpio->irqen2 = 0;
  678. gpio->lvldet0 = Etherchanbit; /* enable irq ass'n on low det'n */
  679. gpio->lvldet1 = 0; /* disable irq ass'n on high det'n */
  680. gpio->risingdet = 0; /* enable irq rising edge det'n */
  681. gpio->fallingdet = 0; /* disable irq falling edge det'n */
  682. gpio->wkupen = 0;
  683. gpio->deben = 0; /* no de-bouncing */
  684. gpio->debtime = 0;
  685. coherence();
  686. gpio->irqsts1 = ~0; /* dismiss all outstanding intrs */
  687. gpio->irqsts2 = ~0;
  688. coherence();
  689. }
  690. void
  691. configscreengpio(void)
  692. {
  693. Cm *wkup = (Cm *)PHYSSCMWKUP;
  694. Gpio *gpio = (Gpio *)PHYSGPIO1;
  695. /* no clocksel needed */
  696. wkup->iclken |= Wkgpio1;
  697. coherence();
  698. wkup->fclken |= Wkgpio1; /* turn gpio clock on */
  699. coherence();
  700. // wkup->autoidle |= Wkgpio1; /* set gpio clock on auto */
  701. wkup->autoidle = 0;
  702. coherence();
  703. while (wkup->idlest & Gpio1idle)
  704. ;
  705. /*
  706. * 0 bits in oe are output signals.
  707. * enable output for gpio 1 (first gpio) video magic pins.
  708. */
  709. gpio->oe &= ~Gpio1vidmagic;
  710. coherence();
  711. gpio->dataout |= Gpio1vidmagic; /* set output pins to 1 */
  712. coherence();
  713. delay(50);
  714. }
  715. void
  716. screenclockson(void)
  717. {
  718. Cm *dss = (Cm *)PHYSSCMDSS;
  719. dss->iclken |= Dssl3l4;
  720. coherence();
  721. dss->fclken = Dsstv | Dss2 | Dss1;
  722. coherence();
  723. /* tv fclk is dpll4 clk; dpll4 m4 divide factor for dss1 fclk is 2 */
  724. dss->clksel[0] = 1<<12 | 2;
  725. coherence();
  726. delay(50);
  727. while (dss->idlest & Dssidle)
  728. ;
  729. }
  730. void
  731. gpioirqclr(void)
  732. {
  733. Gpio *gpio = (Gpio *)PHYSGPIO6;
  734. gpio->irqsts1 = gpio->irqsts1;
  735. coherence();
  736. }
  737. static char *
  738. l1iptype(uint type)
  739. {
  740. static char *types[] = {
  741. "reserved",
  742. "asid-tagged VIVT",
  743. "VIPT",
  744. "PIPT",
  745. };
  746. if (type >= nelem(types) || types[type] == nil)
  747. return "GOK";
  748. return types[type];
  749. }
  750. void
  751. cacheinfo(int level, Memcache *cp)
  752. {
  753. ulong setsways;
  754. /* select cache level */
  755. cpwrsc(CpIDcssel, CpID, CpIDid, 0, (level - 1) << 1);
  756. setsways = cprdsc(CpIDcsize, CpID, CpIDid, 0);
  757. cp->l1ip = cprdsc(0, CpID, CpIDidct, CpIDct);
  758. cp->level = level;
  759. cp->nways = ((setsways >> 3) & MASK(10)) + 1;
  760. cp->nsets = ((setsways >> 13) & MASK(15)) + 1;
  761. cp->log2linelen = (setsways & MASK(2)) + 2 + 2;
  762. cp->linelen = 1 << cp->log2linelen;
  763. cp->setsways = setsways;
  764. cp->setsh = cp->log2linelen;
  765. cp->waysh = 32 - log2(cp->nways);
  766. }
  767. static void
  768. prcachecfg(void)
  769. {
  770. int cache;
  771. Memcache mc;
  772. for (cache = 1; cache <= 2; cache++) {
  773. cacheinfo(cache, &mc);
  774. iprint("l%d: %d ways %d sets %d bytes/line",
  775. mc.level, mc.nways, mc.nsets, mc.linelen);
  776. if (mc.linelen != CACHELINESZ)
  777. iprint(" *should* be %d", CACHELINESZ);
  778. if (mc.setsways & Cawt)
  779. iprint("; can WT");
  780. if (mc.setsways & Cawb)
  781. iprint("; can WB");
  782. #ifdef COMPULSIVE /* both caches can do this */
  783. if (mc.setsways & Cara)
  784. iprint("; can read-allocate");
  785. #endif
  786. if (mc.setsways & Cawa)
  787. iprint("; can write-allocate");
  788. if (cache == 1)
  789. iprint("; l1 I policy %s",
  790. l1iptype((mc.l1ip >> 14) & MASK(2)));
  791. iprint("\n");
  792. }
  793. }
  794. static char *
  795. subarch(int impl, uint sa)
  796. {
  797. static char *armarchs[] = {
  798. "VFPv1 (pre-armv7)",
  799. "VFPv2 (pre-armv7)",
  800. "VFPv3+ with common VFP subarch v2",
  801. "VFPv3+ with null subarch",
  802. "VFPv3+ with common VFP subarch v3",
  803. };
  804. if (impl != 'A' || sa >= nelem(armarchs))
  805. return "GOK";
  806. else
  807. return armarchs[sa];
  808. }
  809. /*
  810. * padconf bits in a short, 2 per long register
  811. * 15 wakeupevent
  812. * 14 wakeupenable
  813. * 13 offpulltypeselect
  814. * 12 offpulludenable
  815. * 11 offoutvalue
  816. * 10 offoutenable
  817. * 9 offenable
  818. * 8 inputenable
  819. * 4 pulltypeselect
  820. * 3 pulludenable
  821. * 2-0 muxmode
  822. *
  823. * see table 7-5 in §7.4.4.3 of spruf98d
  824. */
  825. enum {
  826. /* pad config register bits */
  827. Inena = 1 << 8, /* input enable */
  828. Indis = 0 << 8, /* input disable */
  829. Ptup = 1 << 4, /* pull type up */
  830. Ptdown = 0 << 4, /* pull type down */
  831. Ptena = 1 << 3, /* pull type selection is active */
  832. Ptdis = 0 << 3, /* pull type selection is inactive */
  833. Muxmode = MASK(3),
  834. /* pad config registers relevant to flash */
  835. GpmcA1 = 0x4800207A,
  836. GpmcA2 = 0x4800207C,
  837. GpmcA3 = 0x4800207E,
  838. GpmcA4 = 0x48002080,
  839. GpmcA5 = 0x48002082,
  840. GpmcA6 = 0x48002084,
  841. GpmcA7 = 0x48002086,
  842. GpmcA8 = 0x48002088,
  843. GpmcA9 = 0x4800208A,
  844. GpmcA10 = 0x4800208C,
  845. GpmcD0 = 0x4800208E,
  846. GpmcD1 = 0x48002090,
  847. GpmcD2 = 0x48002092,
  848. GpmcD3 = 0x48002094,
  849. GpmcD4 = 0x48002096,
  850. GpmcD5 = 0x48002098,
  851. GpmcD6 = 0x4800209A,
  852. GpmcD7 = 0x4800209C,
  853. GpmcD8 = 0x4800209E,
  854. GpmcD9 = 0x480020A0,
  855. GpmcD10 = 0x480020A2,
  856. GpmcD11 = 0x480020A4,
  857. GpmcD12 = 0x480020A6,
  858. GpmcD13 = 0x480020A8,
  859. GpmcD14 = 0x480020AA,
  860. GpmcD15 = 0x480020AC,
  861. GpmcNCS0 = 0x480020AE,
  862. GpmcNCS1 = 0x480020B0,
  863. GpmcNCS2 = 0x480020B2,
  864. GpmcNCS3 = 0x480020B4,
  865. GpmcNCS4 = 0x480020B6,
  866. GpmcNCS5 = 0x480020B8,
  867. GpmcNCS6 = 0x480020BA,
  868. GpmcNCS7 = 0x480020BC,
  869. GpmcCLK = 0x480020BE,
  870. GpmcNADV_ALE = 0x480020C0,
  871. GpmcNOE = 0x480020C2,
  872. GpmcNWE = 0x480020C4,
  873. GpmcNBE0_CLE = 0x480020C6,
  874. GpmcNBE1 = 0x480020C8,
  875. GpmcNWP = 0x480020CA,
  876. GpmcWAIT0 = 0x480020CC,
  877. GpmcWAIT1 = 0x480020CE,
  878. GpmcWAIT2 = 0x480020D0,
  879. GpmcWAIT3 = 0x480020D2,
  880. };
  881. /* set SCM pad config mux mode */
  882. void
  883. setmuxmode(ulong addr, int shorts, int mode)
  884. {
  885. int omode;
  886. ushort *ptr;
  887. mode &= Muxmode;
  888. for (ptr = (ushort *)addr; shorts-- > 0; ptr++) {
  889. omode = *ptr & Muxmode;
  890. if (omode != mode)
  891. *ptr = *ptr & ~Muxmode | mode;
  892. }
  893. coherence();
  894. }
  895. static void
  896. setpadmodes(void)
  897. {
  898. int off;
  899. /* set scm pad modes for usb; hasn't made any difference yet */
  900. setmuxmode(0x48002166, 7, 5); /* hsusb3_tll* in mode 5; is mode 4 */
  901. setmuxmode(0x48002180, 1, 5); /* hsusb3_tll_clk; is mode 4 */
  902. setmuxmode(0x48002184, 4, 5); /* hsusb3_tll_data?; is mode 1 */
  903. setmuxmode(0x480021a2, 12, 0); /* hsusb0 (console) in mode 0 */
  904. setmuxmode(0x480021d4, 6, 2); /* hsusb2_tll* (ehci port 2) in mode 2 */
  905. /* mode 3 is hsusb2_data* */
  906. setmuxmode(0x480025d8, 18, 6); /* hsusb[12]_tll*; mode 3 is */
  907. /* hsusb1_data*, hsusb2* */
  908. setmuxmode(0x480020e4, 2, 5); /* uart3_rx_* in mode 5 */
  909. setmuxmode(0x4800219a, 4, 0); /* uart3_* in mode 0 */
  910. /* uart3_* in mode 2; TODO: conflicts with hsusb0 */
  911. setmuxmode(0x480021aa, 4, 2);
  912. setmuxmode(0x48002240, 2, 3); /* uart3_* in mode 3 */
  913. /*
  914. * igep/gumstix only: mode 4 of 21d2 is gpio_176 (smsc9221 ether irq).
  915. * see ether9221.c for more.
  916. */
  917. *(ushort *)0x480021d2 = Inena | Ptup | Ptena | 4;
  918. /* magic from u-boot for flash */
  919. *(ushort *)GpmcA1 = Indis | Ptup | Ptena | 0;
  920. *(ushort *)GpmcA2 = Indis | Ptup | Ptena | 0;
  921. *(ushort *)GpmcA3 = Indis | Ptup | Ptena | 0;
  922. *(ushort *)GpmcA4 = Indis | Ptup | Ptena | 0;
  923. *(ushort *)GpmcA5 = Indis | Ptup | Ptena | 0;
  924. *(ushort *)GpmcA6 = Indis | Ptup | Ptena | 0;
  925. *(ushort *)GpmcA7 = Indis | Ptup | Ptena | 0;
  926. *(ushort *)GpmcA8 = Indis | Ptup | Ptena | 0;
  927. *(ushort *)GpmcA9 = Indis | Ptup | Ptena | 0;
  928. *(ushort *)GpmcA10 = Indis | Ptup | Ptena | 0;
  929. *(ushort *)GpmcD0 = Inena | Ptup | Ptena | 0;
  930. *(ushort *)GpmcD1 = Inena | Ptup | Ptena | 0;
  931. *(ushort *)GpmcD2 = Inena | Ptup | Ptena | 0;
  932. *(ushort *)GpmcD3 = Inena | Ptup | Ptena | 0;
  933. *(ushort *)GpmcD4 = Inena | Ptup | Ptena | 0;
  934. *(ushort *)GpmcD5 = Inena | Ptup | Ptena | 0;
  935. *(ushort *)GpmcD6 = Inena | Ptup | Ptena | 0;
  936. *(ushort *)GpmcD7 = Inena | Ptup | Ptena | 0;
  937. *(ushort *)GpmcD8 = Inena | Ptup | Ptena | 0;
  938. *(ushort *)GpmcD9 = Inena | Ptup | Ptena | 0;
  939. *(ushort *)GpmcD10 = Inena | Ptup | Ptena | 0;
  940. *(ushort *)GpmcD11 = Inena | Ptup | Ptena | 0;
  941. *(ushort *)GpmcD12 = Inena | Ptup | Ptena | 0;
  942. *(ushort *)GpmcD13 = Inena | Ptup | Ptena | 0;
  943. *(ushort *)GpmcD14 = Inena | Ptup | Ptena | 0;
  944. *(ushort *)GpmcD15 = Inena | Ptup | Ptena | 0;
  945. *(ushort *)GpmcNCS0 = Indis | Ptup | Ptena | 0;
  946. *(ushort *)GpmcNCS1 = Indis | Ptup | Ptena | 0;
  947. *(ushort *)GpmcNCS2 = Indis | Ptup | Ptena | 0;
  948. *(ushort *)GpmcNCS3 = Indis | Ptup | Ptena | 0;
  949. *(ushort *)GpmcNCS4 = Indis | Ptup | Ptena | 0;
  950. *(ushort *)GpmcNCS5 = Indis | Ptup | Ptena | 0;
  951. *(ushort *)GpmcNCS6 = Indis | Ptup | Ptena | 0;
  952. *(ushort *)GpmcNOE = Indis | Ptdown | Ptdis | 0;
  953. *(ushort *)GpmcNWE = Indis | Ptdown | Ptdis | 0;
  954. *(ushort *)GpmcWAIT2 = Inena | Ptup | Ptena | 4; /* GPIO_64 -ETH_NRESET */
  955. *(ushort *)GpmcNCS7 = Inena | Ptup | Ptena | 1; /* SYS_nDMA_REQ3 */
  956. *(ushort *)GpmcCLK = Indis | Ptdown | Ptdis | 0;
  957. *(ushort *)GpmcNBE1 = Inena | Ptdown | Ptdis | 0;
  958. *(ushort *)GpmcNADV_ALE = Indis | Ptdown | Ptdis | 0;
  959. *(ushort *)GpmcNBE0_CLE = Indis | Ptdown | Ptdis | 0;
  960. *(ushort *)GpmcNWP = Inena | Ptdown | Ptdis | 0;
  961. *(ushort *)GpmcWAIT0 = Inena | Ptup | Ptena | 0;
  962. *(ushort *)GpmcWAIT1 = Inena | Ptup | Ptena | 0;
  963. *(ushort *)GpmcWAIT3 = Inena | Ptup | Ptena | 0;
  964. /*
  965. * magic from u-boot: set 0xe00 bits in gpmc_(nwe|noe|nadv_ale)
  966. * to enable `off' mode for each.
  967. */
  968. for (off = 0xc0; off <= 0xc4; off += sizeof(short))
  969. *((ushort *)(PHYSSCM + off)) |= 0xe00;
  970. coherence();
  971. }
  972. static char *
  973. implement(uchar impl)
  974. {
  975. if (impl == 'A')
  976. return "arm";
  977. else
  978. return "unknown";
  979. }
  980. static void
  981. fpon(void)
  982. {
  983. int gotfp, impl;
  984. ulong acc, scr;
  985. gotfp = 1 << CpFP | 1 << CpDFP;
  986. cpwrsc(0, CpCONTROL, 0, CpCPaccess, MASK(28));
  987. acc = cprdsc(0, CpCONTROL, 0, CpCPaccess);
  988. if ((acc & (MASK(2) << (2*CpFP))) == 0) {
  989. gotfp &= ~(1 << CpFP);
  990. print("fpon: no single FP coprocessor\n");
  991. }
  992. if ((acc & (MASK(2) << (2*CpDFP))) == 0) {
  993. gotfp &= ~(1 << CpDFP);
  994. print("fpon: no double FP coprocessor\n");
  995. }
  996. if (!gotfp) {
  997. print("fpon: no FP coprocessors\n");
  998. return;
  999. }
  1000. /* enable fp. must be first operation on the FPUs. */
  1001. fpwr(Fpexc, fprd(Fpexc) | 1 << 30);
  1002. scr = fprd(Fpsid);
  1003. impl = scr >> 24;
  1004. print("fp: %s arch %s", implement(impl),
  1005. subarch(impl, (scr >> 16) & MASK(7)));
  1006. scr = fprd(Fpscr);
  1007. // TODO configure Fpscr further
  1008. scr |= 1 << 9; /* div-by-0 exception */
  1009. scr &= ~(MASK(2) << 20 | MASK(3) << 16); /* all ops are scalar */
  1010. fpwr(Fpscr, scr);
  1011. print("\n");
  1012. /* we should now be able to execute VFP-style FP instr'ns natively */
  1013. }
  1014. static void
  1015. resetusb(void)
  1016. {
  1017. int bound;
  1018. Uhh *uhh;
  1019. Usbotg *otg;
  1020. Usbtll *tll;
  1021. iprint("resetting usb: otg...");
  1022. otg = (Usbotg *)PHYSUSBOTG;
  1023. otg->otgsyscfg = Softreset; /* see omap35x errata 3.1.1.144 */
  1024. coherence();
  1025. resetwait(&otg->otgsyssts);
  1026. otg->otgsyscfg |= Sidle | Midle;
  1027. coherence();
  1028. iprint("uhh...");
  1029. uhh = (Uhh *)PHYSUHH;
  1030. uhh->sysconfig |= Softreset;
  1031. coherence();
  1032. resetwait(&uhh->sysstatus);
  1033. for (bound = 400*Mhz; !(uhh->sysstatus & Resetdone) && bound > 0;
  1034. bound--)
  1035. ;
  1036. uhh->sysconfig |= Sidle | Midle;
  1037. /*
  1038. * using the TLL seems to be an optimisation when talking
  1039. * to another identical SoC, thus not very useful, so
  1040. * force PHY (ULPI) mode.
  1041. */
  1042. /* this bit is normally off when we get here */
  1043. uhh->hostconfig &= ~P1ulpi_bypass;
  1044. coherence();
  1045. if (uhh->hostconfig & P1ulpi_bypass)
  1046. iprint("utmi (tll) mode..."); /* via tll */
  1047. else
  1048. /* external transceiver (phy), no tll */
  1049. iprint("ulpi (phy) mode...");
  1050. tll = (Usbtll *)PHYSUSBTLL;
  1051. if (probeaddr(PHYSUSBTLL) >= 0) {
  1052. iprint("tll...");
  1053. tll->sysconfig |= Softreset;
  1054. coherence();
  1055. resetwait(&tll->sysstatus);
  1056. tll->sysconfig |= Sidle;
  1057. coherence();
  1058. } else
  1059. iprint("no tll...");
  1060. iprint("\n");
  1061. }
  1062. /*
  1063. * there are secure sdrc registers at 0x48002460
  1064. * sdrc regs at PHYSSDRC; see spruf98c §1.2.8.2.
  1065. * set or dump l4 prot regs at PHYSL4?
  1066. */
  1067. void
  1068. archreset(void)
  1069. {
  1070. static int beenhere;
  1071. if (beenhere)
  1072. return;
  1073. beenhere = 1;
  1074. /* conservative temporary values until archconfinit runs */
  1075. m->cpuhz = 500 * Mhz; /* beagle speed */
  1076. m->delayloop = m->cpuhz/2000; /* initial estimate */
  1077. // dumpl3pr();
  1078. prcachecfg();
  1079. /* fight omap35x errata 2.0.1.104 */
  1080. memset((void *)PHYSSWBOOTCFG, 0, 240);
  1081. coherence();
  1082. setpadmodes();
  1083. configclks(); /* may change cpu speed */
  1084. configgpio();
  1085. archconfinit();
  1086. resetusb();
  1087. fpon();
  1088. }
  1089. void
  1090. archreboot(void)
  1091. {
  1092. Prm *prm = (Prm *)PHYSPRMGLBL;
  1093. iprint("archreboot: reset!\n");
  1094. delay(20);
  1095. prm->rstctrl |= Rstgs;
  1096. coherence();
  1097. delay(500);
  1098. /* shouldn't get here */
  1099. splhi();
  1100. iprint("awaiting reset");
  1101. for(;;) {
  1102. delay(1000);
  1103. print(".");
  1104. }
  1105. }
  1106. void
  1107. kbdinit(void)
  1108. {
  1109. }
  1110. void
  1111. lastresortprint(char *buf, long bp)
  1112. {
  1113. iprint("%.*s", (int)bp, buf); /* nothing else seems to work */
  1114. }
  1115. static void
  1116. scmdump(ulong addr, int shorts)
  1117. {
  1118. ushort reg;
  1119. ushort *ptr;
  1120. ptr = (ushort *)addr;
  1121. print("scm regs:\n");
  1122. while (shorts-- > 0) {
  1123. reg = *ptr++;
  1124. print("%#p: %#ux\tinputenable %d pulltypeselect %d "
  1125. "pulludenable %d muxmode %d\n",
  1126. ptr, reg, (reg>>8) & 1, (reg>>4) & 1, (reg>>3) & 1,
  1127. reg & 7);
  1128. }
  1129. }
  1130. char *cputype2name(char *buf, int size);
  1131. void
  1132. cpuidprint(void)
  1133. {
  1134. char name[64];
  1135. cputype2name(name, sizeof name);
  1136. delay(250); /* let uart catch up */
  1137. iprint("cpu%d: %lldMHz ARM %s\n", m->machno, m->cpuhz / Mhz, name);
  1138. }
  1139. static void
  1140. missing(ulong addr, char *name)
  1141. {
  1142. static int firstmiss = 1;
  1143. if (probeaddr(addr) >= 0)
  1144. return;
  1145. if (firstmiss) {
  1146. iprint("missing:");
  1147. firstmiss = 0;
  1148. } else
  1149. iprint(",\n\t");
  1150. iprint(" %s at %#lux", name, addr);
  1151. }
  1152. /* verify that all the necessary device registers are accessible */
  1153. void
  1154. chkmissing(void)
  1155. {
  1156. delay(20);
  1157. missing(PHYSSCM, "scm");
  1158. missing(KZERO, "dram");
  1159. missing(PHYSL3, "l3 config");
  1160. missing(PHYSINTC, "intr ctlr");
  1161. missing(PHYSTIMER1, "timer1");
  1162. missing(PHYSCONS, "console uart2");
  1163. missing(PHYSUART0, "uart0");
  1164. missing(PHYSUART1, "uart1");
  1165. missing(PHYSETHER, "smc9221"); /* not on beagle */
  1166. missing(PHYSUSBOTG, "usb otg");
  1167. missing(PHYSUHH, "usb uhh");
  1168. missing(PHYSOHCI, "usb ohci");
  1169. missing(PHYSEHCI, "usb ehci");
  1170. missing(PHYSSDMA, "dma");
  1171. missing(PHYSWDOG, "watchdog timer");
  1172. missing(PHYSUSBTLL, "usb tll");
  1173. iprint("\n");
  1174. delay(20);
  1175. }
  1176. void
  1177. archflashwp(Flash*, int)
  1178. {
  1179. }
  1180. /*
  1181. * for ../port/devflash.c:/^flashreset
  1182. * retrieve flash type, virtual base and length and return 0;
  1183. * return -1 on error (no flash)
  1184. */
  1185. int
  1186. archflashreset(int bank, Flash *f)
  1187. {
  1188. if(bank != 0)
  1189. return -1;
  1190. /*
  1191. * this is set up for the igepv2 board.
  1192. * if the beagleboard ever works, we'll have to sort this out.
  1193. */
  1194. f->type = "onenand";
  1195. f->addr = (void*)PHYSNAND; /* mapped here by archreset */
  1196. f->size = 0; /* done by probe */
  1197. f->width = 1;
  1198. f->interleave = 0;
  1199. return 0;
  1200. }