archomap.c 30 KB

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