archipaq.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * ipaq
  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 "draw.h"
  12. #include <memdraw.h>
  13. #include "screen.h"
  14. #include "../port/netif.h"
  15. #include "etherif.h"
  16. #include "../port/flashif.h"
  17. #define EGPIOADDR 0x49000000 /* physical and virtual address of write only register in CS5 space */
  18. static ulong egpiocopy;
  19. static void
  20. egpiosc(ulong set, ulong clr)
  21. {
  22. int s;
  23. s = splhi();
  24. egpiocopy = (egpiocopy & ~clr) | set;
  25. *(ulong*)EGPIOADDR = egpiocopy;
  26. splx(s);
  27. }
  28. void
  29. archreset(void)
  30. {
  31. GpioReg *g;
  32. PpcReg *p;
  33. g = GPIOREG;
  34. g->grer = 0;
  35. g->gfer = 0;
  36. g->gedr = g->gedr;
  37. g->gpcr = ~0;
  38. g->gpdr = GPIO_CLK_SET0_o | GPIO_CLK_SET1_o; // | GPIO_LDD8_15_o;
  39. g->gafr |= GPIO_SYS_CLK_i; // | GPIO_LDD8_15_o;
  40. p = PPCREG;
  41. p->ppdr |= PPC_TXD4 | PPC_SCLK | PPC_SFRM; /* not sure about PPC_TXD4 here */
  42. p->ppsr &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  43. archuartpower(3, 1); /* allow console to work sooner rather than later */
  44. L3init();
  45. }
  46. void
  47. archpowerdown(void)
  48. {
  49. PmgrReg *p = PMGRREG;
  50. p->pwer = GPIO_PWR_ON_i; /* only power button for now, not RTC */
  51. p->pcfr = PCFR_opde; /* stop 3.6MHz oscillator, and drive pcmcia and chip select low */
  52. p->pgsr = 0; /* drive all outputs to zero in sleep */
  53. PPCREG->psdr = 0; /* all peripheral pins as outputs during sleep */
  54. }
  55. void
  56. archpowerup(void)
  57. {
  58. GpioReg *g;
  59. int i;
  60. g = GPIOREG;
  61. g->gpdr |= GPIO_COM_RTS_o; /* just in case it's off */
  62. g->gpsr = GPIO_COM_RTS_o;
  63. *(ulong*)EGPIOADDR = egpiocopy;
  64. for(i=0; i<50*1000; i++)
  65. ;
  66. while((g->gplr & GPIO_PWR_ON_i) == 0)
  67. ; /* wait for it to come up */
  68. }
  69. void
  70. archconfinit(void)
  71. {
  72. int w;
  73. conf.topofmem = 0xC0000000+32*MB;
  74. w = PMGRREG->ppcr & 0x1f;
  75. m->cpuhz = CLOCKFREQ*(w*4+16);
  76. conf.useminicache = 1;
  77. conf.portrait = 1; /* should take from param flash or allow dynamic change */
  78. }
  79. void
  80. kbdinit(void)
  81. {
  82. addclock0link(kbdclock, MS2HZ);
  83. }
  84. static LCDmode lcd320x240x16tft =
  85. {
  86. // .x = 320, .y = 240, .depth = 16, .hz = 70,
  87. // .pbs = 2, .dual = 0, .mono = 0, .active = 1,
  88. // .hsync_wid = 4-2, .sol_wait = 12-1, .eol_wait = 17-1,
  89. // .vsync_hgt = 3-1, .soft_wait = 10, .eof_wait = 1,
  90. // .lines_per_int = 0, .palette_delay = 0, .acbias_lines = 0,
  91. // .obits = 16,
  92. // .vsynclow = 1, .hsynclow = 1,
  93. 320, 240, 16, 70,
  94. 2, 0, 0, 1,
  95. 4-2, 12-1, 17-1,
  96. 3-1, 10, 1,
  97. 0, 0, 0,
  98. 16,
  99. 1, 1,
  100. };
  101. int
  102. archlcdmode(LCDmode *m)
  103. {
  104. *m = lcd320x240x16tft;
  105. return 0;
  106. }
  107. void
  108. archlcdenable(int on)
  109. {
  110. if(on)
  111. egpiosc(EGPIO_LCD_ON|EGPIO_LCD_PCI|EGPIO_LCD_5V_ON|EGPIO_LVDD_ON, 0);
  112. else
  113. egpiosc(0, EGPIO_LCD_ON|EGPIO_LCD_PCI|EGPIO_LCD_5V_ON|EGPIO_LVDD_ON);
  114. }
  115. void
  116. archconsole(void)
  117. {
  118. uartspecial(0, 115200, 'n', &kbdq, &printq, kbdcr2nl);
  119. }
  120. void
  121. archuartpower(int port, int on)
  122. {
  123. int s;
  124. if(port != 3)
  125. return;
  126. s = splhi();
  127. GPIOREG->gpdr |= GPIO_COM_RTS_o; /* should be done elsewhere */
  128. GPIOREG->gpsr = GPIO_COM_RTS_o;
  129. splx(s);
  130. if(on)
  131. egpiosc(EGPIO_RS232_ON, 0);
  132. else
  133. egpiosc(0, EGPIO_RS232_ON);
  134. }
  135. void
  136. archreboot(void)
  137. {
  138. dcflushall();
  139. GPIOREG->gedr = 1<<0;
  140. mmuputctl(mmugetctl() & ~CpCaltivec); /* restore bootstrap's vectors */
  141. RESETREG->rsrr = 1; /* software reset */
  142. for(;;)
  143. spllo();
  144. }
  145. void
  146. archflashwp(Flash*, int wp)
  147. {
  148. if(wp)
  149. egpiosc(0, EGPIO_VPEN);
  150. else
  151. egpiosc(EGPIO_VPEN, 0);
  152. }
  153. /*
  154. * for ../port/devflash.c:/^flashreset
  155. * retrieve flash type, virtual base and length and return 0;
  156. * return -1 on error (no flash)
  157. */
  158. int
  159. archflashreset(int bank, Flash *f)
  160. {
  161. if(bank != 0)
  162. return -1;
  163. f->type = "cfi16";
  164. f->addr = KADDR(FLASHMEM);
  165. if((MEMCFGREG->msc0 & (1<<2)) == 0){
  166. f->interleave = 1;
  167. f->width = 4;
  168. }else
  169. f->width = 2;
  170. return 0;
  171. }
  172. int
  173. archaudiopower(int on)
  174. {
  175. int s;
  176. if(on)
  177. egpiosc(EGPIO_CODEC_RESET | EGPIO_AUD_PWR_ON, 0);
  178. else
  179. egpiosc(0, EGPIO_CODEC_RESET | EGPIO_AUD_ON | EGPIO_AUD_PWR_ON | EGPIO_QMUTE);
  180. s = splhi();
  181. GPIOREG->gafr |= GPIO_SYS_CLK_i;
  182. GPIOREG->gpdr |= GPIO_CLK_SET0_o | GPIO_CLK_SET1_o;
  183. GPIOREG->gpsr = GPIO_CLK_SET0_o;
  184. GPIOREG->gpcr = GPIO_CLK_SET1_o;
  185. splx(s);
  186. return 0;
  187. }
  188. void
  189. archcodecreset(void)
  190. {
  191. // egpiosc(0, EGPIO_CODEC_RESET);
  192. // egpiosc(EGPIO_CODEC_RESET, 0);
  193. }
  194. void
  195. archaudiomute(int on)
  196. {
  197. if(on)
  198. egpiosc(EGPIO_QMUTE, 0);
  199. else
  200. egpiosc(0, EGPIO_QMUTE);
  201. }
  202. void
  203. archaudioamp(int on)
  204. {
  205. if(on)
  206. egpiosc(EGPIO_AUD_ON, 0);
  207. else
  208. egpiosc(0, EGPIO_AUD_ON);
  209. }
  210. enum {
  211. Fs512 = 0,
  212. Fs384 = 1,
  213. Fs256 = 2,
  214. MHz4_096 = GPIO_CLK_SET1_o,
  215. MHz5_6245 = GPIO_CLK_SET1_o|GPIO_CLK_SET0_o,
  216. MHz11_2896 = GPIO_CLK_SET0_o,
  217. MHz12_288 = 0
  218. };
  219. typedef struct Csel Csel;
  220. struct Csel{
  221. int speed;
  222. int cfs; /* codec system clock multiplier */
  223. int gclk; /* gpio clock generator setting */
  224. int div; /* ssp clock divisor */
  225. };
  226. static Csel csel[] = {
  227. {8000, Fs512, MHz4_096, 16},
  228. {11025, Fs512, MHz5_6245, 16},
  229. {16000, Fs256 , MHz4_096, 8},
  230. {22050, Fs512, MHz11_2896, 16},
  231. {32000, Fs384, MHz12_288, 12},
  232. {44100, Fs256, MHz11_2896, 8},
  233. {48000, Fs256, MHz12_288, 8},
  234. {0},
  235. };
  236. int
  237. archaudiospeed(int clock, int set)
  238. {
  239. GpioReg *g;
  240. SspReg *ssp;
  241. Csel *cs;
  242. int s, div, cr0;
  243. for(cs = csel; cs->speed > 0; cs++)
  244. if(cs->speed == clock){
  245. if(!set)
  246. return cs->cfs;
  247. div = cs->div;
  248. if(div == 0)
  249. div = 4;
  250. div = div/2 - 1;
  251. s = splhi();
  252. g = GPIOREG;
  253. g->gpsr = cs->gclk;
  254. g->gpcr = ~cs->gclk & (GPIO_CLK_SET0_o|GPIO_CLK_SET1_o);
  255. ssp = SSPREG;
  256. cr0 = (div<<8) | 0x1f; /* 16 bits, TI frames, not enabled */
  257. ssp->sscr0 = cr0;
  258. ssp->sscr1 = 0x0020; /* ext clock */
  259. ssp->sscr0 = cr0 | 0x80; /* enable */
  260. splx(s);
  261. return cs->cfs;
  262. }
  263. return -1;
  264. }
  265. /*
  266. * pcmcia
  267. */
  268. int
  269. pcmpowered(int slotno)
  270. {
  271. if(slotno)
  272. return 0;
  273. if(egpiocopy & EGPIO_OPT_PWR_ON)
  274. return 3;
  275. return 0;
  276. }
  277. void
  278. pcmpower(int slotno, int on)
  279. {
  280. USED(slotno); /* the pack powers both or none */
  281. if(on){
  282. if((egpiocopy & EGPIO_OPT_PWR_ON) == 0){
  283. egpiosc(EGPIO_OPT_PWR_ON | EGPIO_OPT_ON, 0);
  284. delay(200);
  285. }
  286. }else
  287. egpiosc(0, EGPIO_OPT_PWR_ON | EGPIO_OPT_ON);
  288. }
  289. void
  290. pcmreset(int slot)
  291. {
  292. USED(slot);
  293. egpiosc(EGPIO_CARD_RESET, 0);
  294. delay(100); // microdelay(10);
  295. egpiosc(0, EGPIO_CARD_RESET);
  296. }
  297. int
  298. pcmpin(int slot, int type)
  299. {
  300. switch(type){
  301. case PCMready:
  302. return slot==0? 21: 11;
  303. case PCMeject:
  304. return slot==0? 17: 10;
  305. case PCMstschng:
  306. return -1;
  307. default:
  308. return -1;
  309. }
  310. }
  311. void
  312. pcmsetvpp(int slot, int vpp)
  313. {
  314. USED(slot, vpp);
  315. }
  316. /*
  317. * set ether parameters: the contents should be derived from EEPROM or NVRAM
  318. */
  319. int
  320. archether(int ctlno, Ether *ether)
  321. {
  322. static char opt[128];
  323. if(ctlno == 1){
  324. sprint(ether->type, "EC2T");
  325. return 1;
  326. }
  327. if(ctlno > 0)
  328. return -1;
  329. sprint(ether->type, "wavelan");
  330. if(0)
  331. strcpy(opt, "mode=0 essid=Limbo station=ipaq1 crypt=off"); /* peertopeer */
  332. else
  333. strcpy(opt, "mode=managed essid=Vitanuova1 station=ipaq1 crypt=off");
  334. ether->nopt = tokenize(opt, ether->opt, nelem(ether->opt));
  335. return 1;
  336. }