Author: wmb Date: Wed Jun 16 13:41:36 2010 New Revision: 1823 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/1823
Log: ARM MMP2 port - Initial checkin of mmp2 directory and preliminary versions of some drivers. Needs cleanup, but basically works.
Added: cpu/arm/mmp2/ cpu/arm/mmp2/addrs.fth cpu/arm/mmp2/dsi.fth cpu/arm/mmp2/gpio.fth cpu/arm/mmp2/lcd.fth cpu/arm/mmp2/lcdcfg.fth cpu/arm/mmp2/mfpr.fth cpu/arm/mmp2/mmp2.bth (contents, props changed) cpu/arm/mmp2/physaddr.fth cpu/arm/mmp2/probemem.fth cpu/arm/mmp2/rootnode.fth cpu/arm/mmp2/sdhcimmp2.fth cpu/arm/mmp2/sdregs.fth cpu/arm/mmp2/timer.fth cpu/arm/mmp2/twsi.fth cpu/arm/mmp2/virtaddr.fth cpu/arm/rootnode.fth
Added: cpu/arm/mmp2/addrs.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/addrs.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,13 @@ +h# d401.9000 constant gpio-base +h# d405.1024 constant acgr-pa +h# d401.5000 constant clock-unit-pa +h# d405.0000 constant main-pmu-pa +h# d428.2800 constant pmua-pa \ Application processor PMU register base +h# d420.b800 constant dsi1-pa \ 4-lane controller +h# d420.ba00 constant dsi2-pa \ 3-lane controller +h# d420.b000 constant lcd-pa +h# d401.4000 constant timer-pa + + +h# 08.0000 constant fb-pa +
Added: cpu/arm/mmp2/dsi.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/dsi.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,378 @@ +h# 004c constant pmua_display1_clk_res_ctrl_offset \ DISPLAY1 Clock/Reset Control Register +h# 0110 constant pmua_display2_clk_res_ctrl_offset \ DISPLAY2 Clock/Reset Control Register +h# 0050 constant pmua_ccic_clk_res_ctrl_offset \ CCIC Clock/Reset Control Register + + + +: pmua@ ( offset -- n ) pmua-pa + l@ ; +: pmua! ( n offset -- ) pmua-pa + l! ; + +: dsi-twsi! ( l reg# -- ) + >r lbsplit swap 2swap swap r> wbsplit 6 twsi-write +; +: dsi-twsi-w! ( w reg# -- ) + >r wbsplit swap r> wbsplit 4 twsi-write +; +: dsi-twsi@ ( reg# -- l ) wbsplit 2 4 twsi-get bljoin ; +: dsi-twsi-w@ ( reg# -- w ) wbsplit 2 2 twsi-get bwjoin ; +: dsi1! ( n offset -- ) dsi1-pa + l! ; +: dsi1@ ( n offset -- ) dsi1-pa + l@ ; +: dsi2! ( n offset -- ) dsi2-pa + l! ; +: dsi2@ ( n offset -- ) dsi2-pa + l@ ; + +0 value dsi-base +: dsi! ( n offset -- ) dsi-base + l! ; +: dsi@ ( n offset -- ) dsi-base + l@ ; + +: bitset ( mask reg-adr -- ) tuck l@ or swap l! ; +: bitclr ( mask reg-adr -- ) tuck l@ swap invert and swap l! ; +: init-dsi1 ( -- ) + \ Ensure that the pins are set up properly + h# c0 d# 83 gpio>mfpr l! \ Configure GPIO83 for function 0 - GPIO + d# 83 gpio-dir-out \ Set the direction control to output + + h# d123f h# 4c pmua! \ Send clock to TC358762 MIPI DSI bridge + \ Enable the M/N clock output + main-pmu-pa h# 1024 + l@ h# 200 or main-pmu-pa h# 1024 + l! \ Set (GPC) G_CLK_OUT ena in clock gating register + \ Set the M/N value and re-enable the clock gate register + h# 20001 main-pmu-pa h# 30 + l! \ Set M/N divider values in PMUM_GPCR register + h# 4000 mfpr-base h# 160 + bitset \ pull-up + + \ Disable DSI + 0 h# 00 dsi1! \ Stop the interface + h# c000.0000 dsi1-pa h# 00 + bitset + 1 ms + h# c000.0000 dsi1-pa h# 00 + bitclr + 1 ms + d# 83 gpio-clr 1 ms d# 83 gpio-set 1 ms \ LCD_RST_N line resets DSI bridge + + 5 set-address h# 16 set-slave \ TWSI address of TC358762 MIPI DSI bridge + \ Data Reg#....... + 0 h# 047c dsi-twsi! \ Turn off sleep mode + 2 ms + 7 h# 0210 dsi-twsi! \ Enable 2 lanes + clock lane + h# b8230000 h# 0470 dsi-twsi! \ Set PCLK to 33.2 MHz + 5 ms + h# 0400 h# 0464 dsi-twsi! \ Set PCLK divider + 5 ms + 1 h# 204 dsi-twsi! \ Start RX + 0 h# 144 dsi-twsi! \ Analog timer setup for lane 0 + 0 h# 148 dsi-twsi! \ Analog timer setup for lane 1 + + \ Set asserting period for the duration between LP-00 detect and + \ High Speed data reception for each lane. (This is for LANE 0) + \ Set between 85ns + 6*UI and 145 ns + 10*UI based on HSBCLK + h# a h# 164 dsi-twsi! \ D0S_CLRSIPOCOUNT register + + \ Set asserting period for the duration between LP-00 detect and + \ High Speed data reception for each lane. (This is for LANE 1) + \ Set between 85ns + 6*UI and 145 ns + 10*UI based on HSBCLK + h# a h# 168 dsi-twsi! \ D1S_CLRSIPOCOUNT register + + h# 150 h# 420 dsi-twsi! \ LCDCTR0 - RGB888 24-bit color + + h# 3FF0000 h# 0450 dsi-twsi! \ SPIRCMR/SPICTRL + + 1 h# 0104 dsi-twsi! \ STARTPPI + + \ High speed mode setup + h# 2102 h# 0020 dsi-twsi! \ CLW_DLYCNTRL = 20pS -> CLW_DPHYCONTRX + h# 2002 h# 0024 dsi-twsi! \ D0W_DLYCNTRL = 10pS -> D0W_DPHYCONTRX + h# 2002 h# 0028 dsi-twsi! \ D1W_DLYCNTRL = 10pS -> D1W_DPHYCONTRX + + 1 h# 204 dsi-twsi! \ Start RX -> STARTDSI (repeat) + + h# 152 h# 420 dsi-twsi! \ LCDCTR0 - RGB888 24-bit color + + hsync h# 424 dsi-twsi-w! \ HSYNC width + hbp h# 426 dsi-twsi-w! \ Horizontal back porch + hdisp h# 428 dsi-twsi-w! \ Horizontal display + hfp h# 42a dsi-twsi-w! \ Horizontal front porch + vsync h# 42c dsi-twsi-w! \ VSYNC + vbp h# 42e dsi-twsi-w! \ Vertical back porch + vdisp h# 430 dsi-twsi-w! \ Vertical display + vfp h# 432 dsi-twsi-w! \ Vertical front porch + + \ Magic numbers, tuned with scope + h# 07320302 h# c0 dsi1! \ PHY time 0 + h# 370afff0 h# c4 dsi1! \ PHY time 1 + h# 070a1504 h# c8 dsi1! \ PHY time 2 + h# 00000400 h# cc dsi1! \ PHY time 3 + + h# 30 h# 88 dsi1! \ PHY control 2 - enable 2 lanes + h# 30.0000 h# 24 dsi1! \ Packet command 1 - enable low power tx on 2 lanes + + htotal bytes/pixel * #lanes / ( total-chunks ) + hdisp bytes/pixel * #lanes / ( total-chunks disp-chunks ) + + wljoin h# 110 dsi1! \ DSI_LCD1_TIMING_0 + hbp hsync wljoin h# 114 dsi1! \ DSI_LCD1_TIMING_1 + +\ For now the active size is set really low (we'll use 10) to allow +\ the hardware to attain V Sync. Once the DSI bus is up and running, +\ the final value will be put in place for the active size (this is +\ done below). In a later stepping of the processor this workaround +\ will not be required. + + vtotal ( vdisp ) d# 10 wljoin h# 118 dsi1! \ DSI_LCD1_TIMING_2 + + \ The 1- below is for debugging, to get first line positioned properly + vbp 1- vsync wljoin h# 11c dsi1! \ DSI_LCD1_TIMING_3 + + hsync >bytes d# 11 - 0 max 4 - 6 - ( low ) + hbp hsync + >bytes 4 - 6 - ( low high ) + wljoin h# 120 dsi1! \ DSI_LCD1_WC_0 + + hdisp >bytes hfp >bytes 6 - 6 - wljoin h# 124 dsi1! \ DSI_LCD1_WC_1 + + h# 0040.0010 h# 100 dsi1! \ DSI_LCD1_CTRL_0 + h# 0014.0007 h# 104 dsi1! \ DSI_LCD1_CTRL_1 - non-burst w/ sync, 24bpp + + h# e4 h# 4 dsi1! \ DSI_CTRL_1 - virtual channel setup + h# 1 h# 0 dsi1! \ DSI_CTRL_0 - active panel 1 enable + d# 100 ms + + \ Reset timing register 2 to its final value (workaround) + h# 118 dsi1@ \ DSI_LCD1_TIMING_2 + lwsplit drop + vdisp 2- wljoin + h# 118 dsi1! \ DSI_LCD1_TIMING_2 +; +: .dsi ( index -- ) dup 3 u.r space dsi-twsi@ 8 u.r cr ; +: .dsiw ( index -- ) dup 3 u.r space dsi-twsi-w@ 8 u.r cr ; +: dump-dsi ( -- ) + 5 set-address 16 set-slave + 47c .dsi + 210 .dsi + 470 .dsi + 464 .dsi + 204 .dsi + 144 .dsi + 148 .dsi + 164 .dsi + 168 .dsi + 420 .dsi + 450 .dsi + 104 .dsi + 20 .dsi + 24 .dsi + 28 .dsi + 204 .dsi + 420 .dsi + 424 .dsiw + 426 .dsiw + 428 .dsiw + 42a .dsiw + 42c .dsiw + 42e .dsiw + 430 .dsiw + 432 .dsiw +; +[ifdef] support-low-speed-dsi +: parity ( n -- 0|1 ) + dup d# 16 rshift xor + dup 8 rshift xor + dup 4 rshift xor + dup 2 rshift xor + dup u2/ xor + 1 and +; + +\ ECC bits +\ 10 11 12 13 14 15 16 17 18 19 21 22 23 ->ecc[5] h# effc00 +\ 4 5 6 7 8 9 16 17 18 19 20 22 23 ->ecc[4] h# df03f0 +\ 1 2 3 7 8 9 13 14 15 19 20 21 23 ->ecc[3] h# b8e38e +\ 0 2 3 5 6 9 11 12 15 18 20 21 22 ->ecc[2] h# 749a6d +\ 0 1 3 4 6 8 10 12 14 17 20 21 22 23 ->ecc[1] h# f2555b +\ 0 1 2 4 5 7 10 11 13 16 20 21 22 23 ->ecc[0] h# f12cb7 + +: calc-ecc ( l -- ) + >r + \ The following masks are all 00 in the low byte, because the calculation + \ skips the first byte in the array + r@ 00ef.fc00 and parity d# 29 lshift + r@ 00df.03f0 and parity d# 28 lshift or + r@ 00b8.e38e and parity d# 27 lshift or + r@ 009a.746d and parity d# 26 lshift or + r@ 00f2.555b and parity d# 25 lshift or + r@ 00f1.2cb7 and parity d# 24 lshift or ( ecc ) + r> or +; +: updcrc ( byte crc -- crc' ) + 8 0 do ( byte crc ) + 2dup xor 1 and if ( byte crc ) + u2/ h# 8408 xor ( byte crc' ) + else + u2/ ( byte crc' ) + then ( byte crc ) + swap u2/ swap ( byte' crc ) + loop ( byte crc ) + nip ( crc ) +; +: calc-crc16 ( adr len -- ) \ Len includes the CRC + swap 4 + swap 6 - ( payload-adr payload-len ) + h# ffff >r ( adr len r: crc ) + begin dup while ( adr len r: crc ) + over c@ ( adr len byte r: crc ) + r> updcrc >r ( adr len r: crc' ) + repeat ( adr len r: crc' ) + drop r> ( adr crc ) + swap le-w! ( ) +; +: calc-checksums ( adr len low-speed? -- ) + \ Calculate ECC and maybe CRC if low speed - hardware does it in high speed mode + third if ( adr len ) + over le-l@ calc-ecc ( adr len ecc ) + third le-l! ( adr len ) + \ Calculate CRC if long packet + dup 4 <> if ( adr len ) + 2dup calc-crc16 ( adr len ) + then ( adr len ) + then ( adr len ) +; + +[then] +[ifdef] use-dsi2 +: set-dsi-data ( l index -- ) + swap h# 30 dsi! ( index ) \ Data register + d# 16 lshift h# c000.0000 or h# 2c dsi! \ Packet data address to CPU_CMD_3 register + h# 400 0 do h# 2c dsi@ 0>= abort" DSI timeout" loop +; +: stuff-dsi-fifo ( adr len -- ) + 0 ?do ( adr' ) + dup le-l@ i la1+ set-dsi-data ( adr ) + la1+ ( adr' ) + 4 +loop ( adr ) + drop ( ) +; +: run-dsi-cmd ( cmd -- ) + h# 20 dsi! ( ) + h# 400 0 do ( ) + h# 20 dsi@ 0>= ?leave ( ) + loop ( ) +; +: dsi-write-short ( l -- ) \ high speed short packet +\ calc-ecc ( l' ) + 0 set-dsi-data ( ) + h# c000.0000 run-dsi-cmd ( ) +; + +: dsi-write ( adr len -- ) + \ Send the long payload code and the length as the first word + dup 8 lshift h# 29 or 0 set-dsi-data ( adr len ) + tuck stuff-dsi-fifo ( len ) + h# 8000.0000 or run-dsi-cmd +; + +: setup-lcd ( -- ) + " "(F1 5A 5A)" dsi-write + " "(FC 5A 5A)" dsi-write + " "(B7 00 11 11)" dsi-write + " "(B8 2d 21)" dsi-write + " "(B8 00 06)" dsi-write + " "(2a 00 00 01 df)" dsi-write + " "(2b 00 00 02 7f)" dsi-write + h# 00001105 dsi-write-short + 5 ms + " "(F4 00 23 00 64 5C 00 64 5C 00 00)" dsi-write + " "(F5 00 00 0E 00 04 02 03 03 03 03)" dsi-write + " "(EE 32 29 00)" dsi-write + " "(F2 00 30 88 88 57 57 10 00 04)" dsi-write + " "(F3 00 10 25 01 2D 2D 24 2D 10 12 12 73)" dsi-write + " "(F6 21 AE BF 62 22 62)" dsi-write + " "(F7 00 01 00 F2 0A 0A 0A 30 0A 00 0F 00 0F 00 4B 00 8C)" dsi-write + " "(F8 00 01 00 F2 0A 0A 0A 30 0A 00 0F 00 0F 00 4B 00 8C)" dsi-write + " "(F9 11 10 0F 00 01 02 04 05 08 00 0A 00 00 00 0F 10 11 00 00 C3 FF 7F)" dsi-write + d# 120 ms + h# 00002905 dsi-write-short +; + +\ This is for the TV path +: init-dsi2 ( -- ) + \ Send clock to TC358762 MIPI DSI bridge + h# d123f h# 4c pmua! \ Display 1 clock + h# d123f h# 110 pmua! \ Display 2 clock + + \ Disable DSI + 0 h# 00 dsi2! \ Stop the interface + h# c000.0000 dsi2-pa h# 00 + bitset + 1 ms + h# c000.0000 dsi2-pa h# 00 + bitclr + 1 ms + + \ Magic numbers, tuned with scope + h# 07320302 h# c0 dsi2! \ PHY time 0 + h# 370afff0 h# c4 dsi2! \ PHY time 1 + h# 070a1504 h# c8 dsi2! \ PHY time 2 + h# 00000400 h# cc dsi2! \ PHY time 3 + + h# 30 h# 88 dsi2! \ PHY control 2 - enable 2 lanes + h# 30.0000 h# 24 dsi2! \ Packet command 1 - enable low power tx on 2 lanes + + setup-lcd + htotal >chunks hdisp >chunks wljoin h# 190 dsi2! \ DSI_LCD2_TIMING_0 + hbp hsync wljoin h# 194 dsi2! \ DSI_LCD2_TIMING_1 + + \ For now the active size is set really low (we'll use 10) to allow + \ the hardware to attain V Sync. Once the DSI bus is up and running, + \ the final value will be put in place for the active size (this is + \ done below). In a later stepping of the processor this workaround + \ will not be required. + + vtotal vdisp wljoin h# 198 dsi2! \ DSI_LCD2_TIMING_2 + + \ The 1- below is for debugging, to get first line positioned properly + vbp 1- vsync wljoin h# 19c dsi2! \ DSI_LCD2_TIMING_3 + + hsync bytes/pixel * d# 11 - 0 max 4 - 6 - ( low ) + hbp hsync + bytes/pixel * 4 - 6 - ( low high ) + wljoin h# 1a0 dsi2! \ DSI_LCD2_WC_0 + + hdisp hfp bytes/pixel * wljoin h# 124 dsi1! \ DSI_LCD1_WC_1 + + h# 0050.0010 h# 180 dsi2! \ DSI_LCD2_CTRL_0 + h# 0014.0007 h# 184 dsi2! \ DSI_LCD2_CTRL_1 - non-burst w/ sync, 24bpp + + h# e4 h# 4 dsi2! \ DSI_CTRL_1 - virtual channel setup + h# 1 h# 0 dsi2! \ DSI_CTRL_0 - active panel 1 enable + d# 100 ms + + \ Reset timing register 2 to its final value (workaround) + h# 198 dsi2@ \ DSI_LCD2_TIMING_2 + lwsplit drop + vdisp 2- wljoin + h# 198 dsi2! \ DSI_LCD2_TIMING_2 + +; +: dsi-read ( -- n ) h# 64 dsi2@ ; +: dsi-lcd ( enable? -- ) + 0 dsi1@ 7 invert and 0 dsi1! \ Disable all panels + h# 4c pmua@ 2 invert and h# 4c pmua! \ stop clock? + ( enable? ) if + d# 100 ms + h# 4c pmua@ 2 or h# 4c pmua! \ start clock + d# 100 ms + 0 dsi1@ 1 or 0 dsi1! \ Enable panel 0 + then +; + +h# 106 buffer: dsi-cmd-buf + +: lcd-send-some ( code adr len -- code' adr' len' ) + rot dup dsi-cmd-buf c! ( adr len code ) + h# 10 or -rot ( code' adr len ) \ Change code to 3c after first time + dup d# 240 min ( code adr len thislen ) + third dsi-cmd-buf 1+ third ( code adr len thislen adr dst thislen ) + move ( code adr len thislen ) + dsi-cmd-buf over dsi-write ( code adr len thislen ) + /string ( code adr' len' ) +; + +: lcd-send ( adr len -- ) + h# 2c -rot ( code adr len ) + begin dup while ( code adr len ) + lcd-send-some ( code' adr' len' ) + repeat ( code' adr' len' ) + 3drop +; +[then]
Added: cpu/arm/mmp2/gpio.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/gpio.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,43 @@ +create gpio-offsets +\ 0 1 2 3 4 5 + 0 , 4 , 8 , h# 100 , h# 104 , h# 108 , + +: >gpio-pin ( gpio# -- mask pa ) + dup h# 1f and ( gpio# bit# ) + 1 swap lshift ( gpio# mask ) + swap 5 rshift gpio-offsets swap na+ @ gpio-base + ( mask pa ) +; +: gpio-pin@ ( gpio# -- flag ) >gpio-pin l@ and 0<> ; + +: >gpio-dir ( gpio# -- mask pa ) >gpio-pin h# 0c + ; +: gpio-out? ( gpio# -- out? ) >gpio-dir l@ and 0<> ; + +: gpio-set ( gpio# -- ) >gpio-pin h# 18 + l! ; +: gpio-clr ( gpio# -- ) >gpio-pin h# 24 + l! ; + +: >gpio-rer ( gpio# -- mask pa ) >gpio-pin h# 30 + ; +: gpio-rise@ ( gpio# -- flag ) >gpio-rer l@ and 0<> ; + +: >gpio-fer ( gpio# -- mask pa ) >gpio-pin h# 3c + ; +: gpio-fall@ ( gpio# -- flag ) >gpio-fer l@ and 0<> ; + +: >gpio-edr ( gpio# -- mask pa ) >gpio-pin h# 48 + ; +: gpio-edge@ ( gpio# -- flag ) >gpio-edr l@ and 0<> ; +: gpio-clr-edge ( gpio# -- ) >gpio-edr l! ; + +: gpio-dir-out ( gpio# -- ) >gpio-pin h# 54 + l! ; +: gpio-dir-in ( gpio# -- ) >gpio-pin h# 60 + l! ; +: gpio-set-rer ( gpio# -- ) >gpio-pin h# 6c + l! ; +: gpio-clr-rer ( gpio# -- ) >gpio-pin h# 78 + l! ; +: gpio-set-fer ( gpio# -- ) >gpio-pin h# 84 + l! ; +: gpio-clr-fer ( gpio# -- ) >gpio-pin h# 90 + l! ; + +: >gpio-mask ( gpio# -- mask pa ) >gpio-pin h# 9c + ; +: gpio-set-mask ( gpio# -- ) >gpio-mask l! ; + +: >gpio-xmsk ( gpio# -- mask pa ) >gpio-pin h# a8 + ; +: gpio-set-xmsk ( gpio# -- ) >gpio-xmsk l! ; + + + +
Added: cpu/arm/mmp2/lcd.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/lcd.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,76 @@ +: lcd@ ( offset -- l ) lcd-pa + l@ ; +: lcd! ( l offset -- ) lcd-pa + l! ; + +: spi-clr-irq ( -- ) + h# 1c4 lcd@ h# 00040000 invert and h# 1c4 lcd! \ Clear SPI_IRQ bit +; +: lcd-spi ( w -- ) + spi-clr-irq + 1 us + h# 180 lcd@ h# 40 or h# 180 lcd! \ Set CFG_KEEPXFER, set CS LOW + ( w ) h# 184 lcd! \ Set TX data + h# 180 lcd@ 1 or h# 180 lcd! \ Set SPI_START + begin h# 1c4 lcd@ h# 00040000 and until + spi-clr-irq + h# 180 lcd@ h# 41 invert and h# 180 lcd! \ Clear CFG_KEEPXFER and SPI_START, set CS HITH +; +: init-tpo ( -- ) + h# 0f000f0a h# 180 lcd! \ Set LCD SPI controller for 16bit tranmit + h# 080f lcd-spi \ Invert pixel clockA + h# 0c5f lcd-spi + h# 1017 lcd-spi + h# 1420 lcd-spi + h# 1808 lcd-spi + h# 1c20 lcd-spi + h# 2020 lcd-spi + h# 2420 lcd-spi + h# 2820 lcd-spi + h# 2c20 lcd-spi + h# 3020 lcd-spi + h# 3420 lcd-spi + h# 3810 lcd-spi + h# 3c10 lcd-spi + h# 4010 lcd-spi + h# 4415 lcd-spi + h# 48aa lcd-spi + h# 4cff lcd-spi + h# 5086 lcd-spi + h# 548d lcd-spi + h# 58d4 lcd-spi + h# 5cfb lcd-spi + h# 602e lcd-spi + h# 645a lcd-spi + h# 6889 lcd-spi + h# 6cfe lcd-spi + h# 705a lcd-spi + h# 749b lcd-spi + h# 78c5 lcd-spi + h# 7cff lcd-spi + h# 80f0 lcd-spi + h# 84f0 lcd-spi + h# 8808 lcd-spi +; + +: init-lcd ( -- ) + 0 h# 190 lcd! \ Disable LCD DMA controller + fb-pa h# f4 lcd! \ Frame buffer area 0 + 0 h# f8 lcd! \ Frame buffer area 1 + hdisp bytes/pixel * h# fc lcd! \ Pitch in bytes + + hdisp vdisp wljoin dup h# 104 lcd! dup h# 108 lcd! h# 118 lcd! \ size, size after zoom, disp + + htotal >chunks vtotal wljoin h# 114 lcd! \ SPUT_V_H_TOTAL + + htotal >chunks hdisp - hbp >chunks - 6 - ( low ) + hbp >chunks wljoin h# 11c lcd! + + vfp vbp wljoin h# 120 lcd! + h# 2000FF00 h# 194 lcd! \ DMA CTRL 1 + h# d h# 1b8 lcd! \ Dumb panel controller + h# 01330133 h# 13c lcd! \ Panel VSYNC Pulse Pixel Edge Control + h# 40001108 h# 1a8 lcd! \ Clock divider + h# 00021100 h# 190 lcd! \ DMA CTRL 0 - enable DMA, 24 bpp mode + init-dsi1 + init-tpo + h# c0 lcd-backlight! +;
Added: cpu/arm/mmp2/lcdcfg.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/lcdcfg.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,19 @@ +d# 4 value hsync +d# 800 value hdisp +d# 1056 value htotal +d# 212 value hbp + +d# 4 value vsync +d# 480 value vdisp +d# 525 value vtotal +d# 31 value vbp + +: hfp ( -- n ) htotal hdisp - hsync - hbp - ; +: vfp ( -- n ) vtotal vdisp - vsync - vbp - ; + +2 constant #lanes +3 constant bytes/pixel +d# 24 constant bpp + +: >bytes ( pixels -- chunks ) bytes/pixel * ; +: >chunks ( pixels -- chunks ) >bytes #lanes / ;
Added: cpu/arm/mmp2/mfpr.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/mfpr.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,261 @@ +: set-camera-domain-voltage + h# baba h# d4015068 l! \ Unlock sequence + h# ec10 h# d401506c l! + h# d401e80c l@ 4 or ( n ) \ Set 1.8V selector bit in AIB_GPIO2_IO + h# baba h# d4015068 l! \ Unlock sequence + h# ec10 h# d401506c l! + h# d401e80c l! +; +: acgr-clocks-on ( -- ) + h# 0818.F33C acgr-pa l! \ Turn on all clocks +; +: set-gpio-directions ( -- ) + 3 h# 38 clock-unit-pa + l! \ Enable clocks in GPIO clock reset register + + h# 000e.0000 gpio-base h# 0c + l! \ Bits 19, 18, 17 + h# 0704.2000 gpio-base h# 10 + l! \ Bits 58,57,56,50 and 45 + h# 03ec.3e00 gpio-base h# 14 + l! \ Bits 89:85,83,82, and 77:73 + + h# 0200.3c00 gpio-base h# 20 + l! \ Turn off LEDS (3c00) and turn on 5V (0200.0000) +; + +hex +create mfpr-offsets \ GPIOs + 054 w, 058 w, 05C w, 060 w, 064 w, 068 w, 06C w, 070 w, \ 0->7 + 074 w, 078 w, 07C w, 080 w, 084 w, 088 w, 08C w, 090 w, \ 8->15 + 094 w, 098 w, 09C w, 0A0 w, 0A4 w, 0A8 w, 0AC w, 0B0 w, \ 16->23 + 0B4 w, 0B8 w, 0BC w, 0C0 w, 0C4 w, 0C8 w, 0CC w, 0D0 w, \ 24->31 + 0D4 w, 0D8 w, 0DC w, 0E0 w, 0E4 w, 0E8 w, 0EC w, 0F0 w, \ 32->39 + 0F4 w, 0F8 w, 0FC w, 100 w, 104 w, 108 w, 10C w, 110 w, \ 40->47 + 114 w, 118 w, 11C w, 120 w, 124 w, 128 w, 12C w, 130 w, \ 48->55 + 134 w, 138 w, 13C w, 280 w, 284 w, 288 w, 28C w, 290 w, \ 56->63 + 294 w, 298 w, 29C w, 2A0 w, 2A4 w, 2A8 w, 2AC w, 2B0 w, \ 64->71 + 2B4 w, 2B8 w, 170 w, 174 w, 178 w, 17C w, 180 w, 184 w, \ 72->79 + 188 w, 18C w, 190 w, 194 w, 198 w, 19C w, 1A0 w, 1A4 w, \ 80->87 + 1A8 w, 1AC w, 1B0 w, 1B4 w, 1B8 w, 1BC w, 1C0 w, 1C4 w, \ 88->95 + 1C8 w, 1CC w, 1D0 w, 1D4 w, 1D8 w, 1DC w, 000 w, 004 w, \ 96->103 + 1FC w, 1F8 w, 1F4 w, 1F0 w, 21C w, 218 w, 214 w, 200 w, \ 104->111 + 244 w, 25C w, 164 w, 260 w, 264 w, 268 w, 26C w, 270 w, \ 112->119 + 274 w, 278 w, 27C w, 148 w, 00C w, 010 w, 014 w, 018 w, \ 120->127 + 01C w, 020 w, 024 w, 028 w, 02C w, 030 w, 034 w, 038 w, \ 128->135 + 03C w, 040 w, 044 w, 048 w, 04C w, 050 w, 008 w, 220 w, \ 136->143 + 224 w, 228 w, 22C w, 230 w, 234 w, 238 w, 23C w, 240 w, \ 144->151 + 248 w, 24C w, 254 w, 258 w, 14C w, 150 w, 154 w, 158 w, \ 152->159 + 250 w, 210 w, 20C w, 208 w, 204 w, 1EC w, 1E8 w, 1E4 w, \ 160->167 + 1E0 w, \ 168 + +h# d401.e000 constant mfpr-base +: gpio>mfpr ( gpio# -- mfpr-pa ) + mfpr-offsets swap wa+ w@ + mfpr-base + +; + +: dump-mfprs ( -- ) + base @ + d# 169 0 do decimal i 3 u.r space i gpio>mfpr l@ 4 hex u.r cr loop + base ! +; + +: no-update, ( -- ) 8 w, ; \ 8 is a reserved bit; the code skips these +: af, ( n -- ) h# c0 + w, ; +: pull-up, ( n -- ) h# c0c0 + w, ; +: pull-dn, ( n -- ) h# a0c0 + w, ; + +create mfpr-table + 1 af, \ GPIO_00 - KP_MKIN[0] + 1 af, \ GPIO_01 - KP_MKOUT[0] + 1 af, \ GPIO_02 - KP_MKIN[1] + 1 af, \ GPIO_03 - KP_MKOUT[1] + 1 af, \ GPIO_04 - KP_MKIN[2] + 1 af, \ GPIO_05 - KP_MKOUT[2] + no-update, \ GPIO_06 - Not used + no-update, \ GPIO_07 - Not used + no-update, \ GPIO_08 - Not used + no-update, \ GPIO_09 - Not used + no-update, \ GPIO_10 - Not used + no-update, \ GPIO_11 - Not used + no-update, \ GPIO_12 - Not used + no-update, \ GPIO_13 - Not used + no-update, \ GPIO_14 - Not used + no-update, \ GPIO_15 - Not used + no-update, \ GPIO_16 - Not used + 0 af, \ GPIO_17 - BB_GPIO1 (use as GPIO out) + 0 af, \ GPIO_18 - BB_GPIO2 (use as GPIO out) + 0 af, \ GPIO_19 - BB_GPIO3 (use as GPIO out) + 0 af, \ GPIO_20 - ISP_INT (use as GPIO in) + 0 af, \ GPIO_21 - WIFI_GPIO2 (use as GPIO i/o) + 0 af, \ GPIO_22 - WIFI_GPIO3 (use as GPIO i/o) + 0 af, \ GPIO_23 - CODEC_INT (use as GPIO in) + 1 af, \ GPIO_24 - I2S_SYSCLK (Codec - HI-FI) + 1 af, \ GPIO_25 - SSPA2_SCLK (Codec - HI-FI) + 1 af, \ GPIO_26 - SSPA2_SFRM (Codec - HI-FI) + 1 af, \ GPIO_27 - SSPA2_TXD (Codec - HI-FI) + 1 af, \ GPIO_28 - SSPA2_RXD (Codec - HI-FI) + 1 af, \ GPIO_29 - UART1_RXD (Bluetooth) + 1 af, \ GPIO_30 - UART1_TXD (Bluetooth) + 1 af, \ GPIO_31 - UART1_CTS (Bluetooth) +\ + 1 af, \ GPIO_32 - UART1_RTS (Bluetooth) + 0 af, \ GPIO_33 - SSPA2_CLK (Codec - LO-FI) + 0 af, \ GPIO_34 - SSPA2_FRM (Codec - LO-FI) + 0 af, \ GPIO_35 - SSPA2_TXD (Codec - LO-FI) + 0 af, \ GPIO_36 - SSPA2_RXD (Codec - LO-FI) + 1 af, \ GPIO_37 - MMC2_DAT<3> + 1 af, \ GPIO_38 - MMC2_DAT<2> + 1 af, \ GPIO_39 - MMC2_DAT<1> + 1 af, \ GPIO_40 - MMC2_DAT<0> + 1 af, \ GPIO_41 - MMC2_CMD + 1 af, \ GPIO_42 - MMC2_CLK + 1 af, \ GPIO_43 - TWSI2_SCL (for codec/noise/FM) + 1 af, \ GPIO_44 - TWSI2_SDA (for codec/noise/FM) + 0 af, \ GPIO_45 - WM8994_LDOEN (use as GPIO out) + 0 af, \ GPIO_46 - HDMI_DET (use as GPIO in) + 2 af, \ GPIO_47 - SSP2_CLK + 2 af, \ GPIO_48 - SSP2_FRM + 2 af, \ GPIO_49 - SSP2_RXD + 0 af, \ GPIO_50 - GPS_STBY (use as GPIO out) + 1 af, \ GPIO_51 - UART3_RXD (debug port) + 1 af, \ GPIO_52 - UART3_TXD (debug port) + 5 af, \ GPIO_53 - PWM3 (Keypad backlight) + 4 af, \ GPIO_54 - HDMI_CEC (MOVED to GPIO 113?) + 0 af, \ GPIO_55 - WIFI_GPIO0 (use as GPIO in) + 0 af, \ GPIO_56 - WIFI_GPIO1 (use as GPIO out) + 0 af, \ GPIO_57 - WIFI_PD_N (use as GPIO out) + 0 af, \ GPIO_58 - WIFI_RST_N (use as GPIO out) + 1 af, \ GPIO_59 - CCIC_IN<7> + 1 af, \ GPIO_60 - CCIC_IN<6> + 1 af, \ GPIO_61 - CCIC_IN<5> + 1 af, \ GPIO_62 - CCIC_IN<4> + 1 af, \ GPIO_63 - CCIC_IN<3> +\ + 1 af, \ GPIO_64 - CCIC_IN<2> + 1 af, \ GPIO_65 - CCIC_IN<1> + 1 af, \ GPIO_66 - CCIC_IN<0> + 1 af, \ GPIO_67 - CAM_HSYNC + 1 af, \ GPIO_68 - CAM_VSYNC + 1 af, \ GPIO_69 - CAM_MCLK + 1 af, \ GPIO_70 - CAM_PCLK + 1 af, \ GPIO_71 - TWSI3_SCL (for CAM) + 1 af, \ GPIO_72 - TWSI3_CLK (for CAM) + 0 af, \ GPIO_73 - CCIC_RST_N (use as GPIO out) + 0 af, \ GPIO_74 - LED - ORANGE (use as GPIO out) LCD VSYNC + 0 af, \ GPIO_75 - LED - BLUE (use as GPIO out) LCD HSYNV + 0 af, \ GPIO_76 - LED - RED (use as GPIO out) LCD PCLK + 0 af, \ GPIO_77 - LED - GREEN (use as GPIO out) + 5 af, \ GPIO_78 - SSP4_CLK + 5 af, \ GPIO_79 - SSP4_FRM + 5 af, \ GPIO_80 - SSP4_SDA + 0 af, \ GPIO_81 - VBUS_FLT_N (use as GPIO in) + 0 af, \ GPIO_82 - VBUS_EN (use as GPIO out) + 0 af, \ GPIO_83 - LCD_RST_N (use as GPIO out) + 0 af, \ GPIO_84 - USB_INT_N (use as GPIO in) + 0 af, \ GPIO_85 - USB_RST_N (use as GPIO out) + 0 af, \ GPIO_86 - USB_PWDN_N (use as GPIO out) + 0 af, \ GPIO_87 - USB_HUB_EN (use as GPIO out) + 0 af, \ GPIO_88 - USB_MMC_EN (use as GPIO out) + 0 af, \ GPIO_89 - 5V_Enable (use as GPIO out) + no-update, \ GPIO_90 - Not used + 0 af, \ GPIO_91 - ACC_INT (use as GPIO in) + 0 af, \ GPIO_92 - PROX1_INT (use as GPIO in) + no-update, \ GPIO_93 - Not used + 3 pull-dn, \ GPIO_94 - SPI_CLK + 3 pull-up, \ GPIO_95 - SPI_CSO +\ + 3 pull-dn, \ GPIO_96 - SPI_SDA + 2 af, \ GPIO_97 - TWSI6_SCL (HDMI EDID) + 2 af, \ GPIO_98 - TWSI6_SDA (HDMI EDID) + 4 af, \ GPIO_99 - TWSI5_SCL (CAP TOUCH) + 4 af, \ GPIO_100 - TWSI5_SDA (CAP TOUCH) + 0 af, \ GPIO_101 - TSI_INT (use as GPIO in) + 0 af, \ GPIO_102 - USIM_UCLK + 0 af, \ GPIO_103 - USIM_UIO + 0 af, \ GPIO_104 - ND_IO[7] + 0 af, \ GPIO_105 - ND_IO[6] + 0 af, \ GPIO_106 - ND_IO[5] + 0 af, \ GPIO_107 - ND_IO[4] + 0 af, \ GPIO_108 - ND_IO[15] + 0 af, \ GPIO_109 - ND_IO[14] + 0 af, \ GPIO_110 - ND_IO[13] + 0 af, \ GPIO_111 - ND_IO[8] Use 2 af, for eMMC + 0 af, \ GPIO_112 - ND_RDY[0] Use 2 af, for eMMC + no-update, \ GPIO_113 - Not used + 1 af, \ GPIO_114 - M/N_CLK_OUT (G_CLK_OUT) + 0 af, \ GPIO_115 - GPIO_115 (i/o) + 0 af, \ GPIO_116 - GPIO_116 (i/o) + 0 af, \ GPIO_117 - GPIO_117 (i/o) + 0 af, \ GPIO_118 - GPIO_118 (i/o) + 0 af, \ GPIO_119 - GPIO_119 (i/o) + 0 af, \ GPIO_120 - GPIO_120 (i/o) + 0 af, \ GPIO_121 - GPIO_121 (i/o) + 0 af, \ GPIO_122 - GPIO_122 (i/o) + 0 af, \ GPIO_123 - MBFLT_N (use as GPIO in) + 1 af, \ GPIO_124 - MMC1_DAT[7] + 1 af, \ GPIO_125 - MMC1_DAT[6] + 0 pull-up, \ GPIO_126 - Board Rev ID bit 0 + 0 pull-up, \ GPIO_127 - Board Rev ID bit 1 +\ + 0 pull-up, \ GPIO_128 - Board Rev ID bit 2 + 1 af, \ GPIO_129 - MMC1_DAT[5] + 1 af, \ GPIO_130 - MMC1_DAT[4] + 1 af, \ GPIO_131 - MMC1_DAT[3] + 1 af, \ GPIO_132 - MMC1_DAT[2] + 1 af, \ GPIO_133 - MMC1_DAT[1] + 1 af, \ GPIO_134 - MMC1_DAT[0] + no-update, \ GPIO_135 - Not used + 1 af, \ GPIO_136 - MMC1_CMD + no-update, \ GPIO_137 - Not used + no-update, \ GPIO_138 - Not used + 1 af, \ GPIO_139 - MMC1_CLK + 1 af, \ GPIO_140 - MMC1_CD + 1 af, \ GPIO_141 - MMC1_WP + 0 af, \ GPIO_142 - USIM_RSTn + 0 af, \ GPIO_143 - ND_CS[0] + 0 af, \ GPIO_144 - ND_CS[1] + no-update, \ GPIO_145 - Not used + no-update, \ GPIO_146 - Not used + 0 af, \ GPIO_147 - ND_WE_N + 0 af, \ GPIO_148 - ND_RE_N + 0 af, \ GPIO_149 - ND_CLE + 0 af, \ GPIO_150 - ND_ALE + 2 af, \ GPIO_151 - MMC3_CLK + no-update, \ GPIO_152 - Not used + no-update, \ GPIO_153 - Not used + 0 af, \ GPIO_154 - SM_INT + 1 af, \ MMC3_RST_N (use as GPIO) + no-update, \ GPIO_156 - PRI_TDI (JTAG) + no-update, \ GPIO_157 - PRI_TDS (JTAG) + no-update, \ GPIO_158 - PRI_TDK (JTAG) + no-update, \ GPIO_159 - PRI_TDO (JTAG) +\ + 0 af, \ GPIO_160 - ND_RDY[1] + 0 af, \ GPIO_161 - ND_IO[12] + 0 af, \ GPIO_162 - ND_IO[11] Use 2 af, for eMMC + 0 af, \ GPIO_163 - ND_IO[10] Use 2 af, for eMMC + 0 af, \ GPIO_164 - ND_IO[9] Use 2 af, for eMMC + 0 af, \ GPIO_165 - ND_IO[3] Use 2 af, for eMMC + 0 af, \ GPIO_166 - ND_IO[2] Use 2 af, for eMMC + 0 af, \ GPIO_167 - ND_IO[1] Use 2 af, for eMMC + 0 af, \ GPIO_168 - ND_IO[0] Use 2 af, for eMMC + +: init-mfprs + d# 169 0 do + mfpr-table i wa+ w@ ( code ) + dup 8 = if ( code ) + drop ( ) + else ( code ) + i gpio>mfpr l! ( ) + then + loop +; + +: af! ( function# gpio# -- ) gpio>mfpr l! ; +: gpios-for-nand ( -- ) + h# c0 d# 111 af! + h# c0 d# 112 af! + d# 169 d# 162 do h# c0 i af! loop +; +: gpios-for-emmc ( -- ) + h# c2 d# 111 af! + h# c2 d# 112 af! + d# 169 d# 162 do h# c2 i af! loop +;
Added: cpu/arm/mmp2/mmp2.bth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/mmp2.bth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,178 @@ +purpose: Load file for OFW on Marvell MMP2 ARM demo board +\ See license at end of file + +dictionary: ${BP}/cpu/arm/build/basefw.dic +command: &armforth &dictionary &this +build-now + +" mmp2.tag" r/w create-file drop tag-file ! + +\ ' $report-name is include-hook + +use-movable-vector-base \ CortexA8 CPU core has a movable vector base + +h# 8.0000 constant initial-heap-size + +: (initial-heap) ( -- adr len ) limit initial-heap-size ; +' (initial-heap) to initial-heap + +fload ${BP}/dev/omap/diaguart.fth \ OMAP UART +h# d4018000 to uart-base \ UART# base address on MMP2 + +fload ${BP}/forth/lib/sysuart.fth \ Set console I/O vectors to UART + + +\ Install the simple UART driver from the standalone I/O init chain +: stand-init-io ( -- ) + stand-init-io + inituarts install-uart-io +; + +\ --- +\ ' $report-name to include-hook + +h# 1000 to pagesize +d# 12 to pageshift + +fload ${BP}/cpu/arm/mmp2/physaddr.fth \ Architecture-generic phys. addresses +fload ${BP}/cpu/arm/mmp2/virtaddr.fth \ Virtual addresses for the firmware + +fload ${BP}/cpu/arm/mmp2/addrs.fth +fload ${BP}/cpu/arm/mmp2/twsi.fth +fload ${BP}/cpu/arm/mmp2/timer.fth +fload ${BP}/cpu/arm/mmp2/mfpr.fth +: init-stuff + set-camera-domain-voltage + acgr-clocks-on + init-mfprs + set-gpio-directions + init-timers + init-twsi + power-on-dsi +; +fload ${BP}/cpu/arm/mmp2/gpio.fth +fload ${BP}/cpu/arm/mmp2/lcdcfg.fth +fload ${BP}/cpu/arm/mmp2/dsi.fth +fload ${BP}/cpu/arm/mmp2/lcd.fth +: display-on + init-stuff + init-lcd + fb-pa hdisp vdisp * >bytes h# ff fill +; + + +\ fload ${BP}/cpu/arm/rootnode.fth \ Root node mapping +fload ${BP}/cpu/arm/mmp2/rootnode.fth \ Root node mapping - physical mode +dev / + " Marvell,Bonnell" model + " ARM SOC" encode-string " architecture" property + d# 1,000,000,000 " clock-frequency" integer-property +device-end + +: (cpu-arch ( -- adr len ) + " architecture" ['] root-node get-package-property drop + get-encoded-string +; +' (cpu-arch to cpu-arch + +\ Memory management services +fload ${BP}/ofw/core/clntmem1.fth \ client services for memory +fload ${BP}/ofw/core/memlist.fth \ Resource list common routines +fload ${BP}/ofw/core/showlist.fth \ Linked list display tool +fload ${BP}/ofw/core/allocph1.fth \ S Physical memory allocator +fload ${BP}/ofw/core/availpm.fth \ Available memory list + +fload ${BP}/cpu/arm/mmp2/probemem.fth \ Populate memory node +stand-init: Probing memory + " probe" memory-node @ $call-method +; + +fload ${BP}/cpu/arm/loadvmem.fth \ /mmu node +stand-init: MMU + " /mmu" open-dev mmu-node ! +; +\ fload ${BP}/pkg/console/bailout.fth \ Keyboard bailout code + +hex +warning on + +" /openprom" find-device + " FirmWorks,3.0" encode-string " model" property +device-end + +\ fload ${BP}/arch/dna/mmusetup.fth \ Initial values for MMU lists + +\ fload ${BP}/arch/dna/boot.fth + +\ false ' auto-boot? set-config-int-default + +\ 1 section before origin section table +h# 10.0000 h# 8000 - h# 4000 - dictionary-size ! + +\ dev /mmu +\ patch instruction! l! section! +\ device-end + +defer probe-all +: (probe-all) ( -- ) + " probe-" do-drop-in + " probe+" do-drop-in +; +' (probe-all) to probe-all + +\ --- + +d# 3000 to ms-factor + +fload ${BP}/cpu/arm/mmp2/sdhcimmp2.fth + +tag-file @ fclose tag-file off + +fload ${BP}/cpu/arm/saverom.fth \ Save the dictionary for standalone startup + +.( --- Saving mmp2.dic --- ) cr " mmp2.dic" $save-forth + +\ This is some glue code to convert the machine setup that QEMU gives us +\ to the setup that start-forth (see arm/boot.fth) wants. +\ We get here via a call instruction at origin+8, which is inserted below + +code stand-cold-code ( r0: 0 r1: board-id r2: &kernel-args lr: &aif_header+8c ) + here origin 8 + put-call \ Insert call instruction + + \ Put the arguments in safe registers + sub r6,lr,#0x8c \ r6 points to header (lr set by code at origin) + mov r7,#0 \ r7: functions + add r8,r6,0x200000 \ r8: memtop - 2MiB above load address + \ r9 is up + mov r10,#0 \ r10: argc + mov r11,r2 \ r11: argv (kernel args) + mov r12,`initial-heap-size` \ r12: initial-heap-size + + b 'code start-forth \ Branch to the generic startup code +end-code + +.( --- Saving mmp2.rom --- ) cr " mmp2.rom" $save-rom + +\ LICENSE_BEGIN +\ Copyright (c) 2010 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Added: cpu/arm/mmp2/physaddr.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/physaddr.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,4 @@ +h# 2000.0000 constant sdram-size + +: (memory?) ( phys -- flag ) sdram-size u< ; +' (memory?) to memory?
Added: cpu/arm/mmp2/probemem.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/probemem.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,29 @@ +purpose: Memory probing +copyright: Copyright 1994 FirmWorks All Rights Reserved + +" /memory" find-device + +headerless + +h# ffff.ffff value low +h# 0 value high + +: log&release ( adr len -- ) + over low umin to low ( adr len ) + 2dup + high umax to high ( adr len ) + release +; + +headers +: probe ( -- ) + 0 sdram-size log&release + + 0 0 encode-bytes ( adr 0 ) + physavail ['] make-phys-memlist find-node ( adr len prev 0 ) + 2drop " reg" property + + \ Claim the memory used by OFW +\ high h# 10.0000 - h# 10.0000 0 claim drop +; + +device-end
Added: cpu/arm/mmp2/rootnode.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/rootnode.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,99 @@ +purpose: Methods for root node +\ See license at end of file + +: root-map-in ( phys len -- virt ) + " /" " map-in" execute-device-method drop +; +: root-map-out ( virt len -- ) + " /" " map-out" execute-device-method drop +; + +dev / +extend-package + +1 encode-int " #address-cells" property + +hex + +\ Static methods +: decode-unit ( adr len -- phys ) push-hex $number if 0 then pop-base ; +: encode-unit ( phys -- adr len ) push-hex (u.) pop-base ; + +\ Not-necessarily-static methods +: open ( -- true ) true ; +: close ( -- ) ; + +: map-in ( phys size -- virt ) + drop +; +: map-out ( virtual size -- ) + 2drop +; + +: dma-alloc ( size -- virt ) alloc-mem ; +: dma-free ( virt size -- ) free-mem ; + +: dma-map-in ( virt size cacheable -- devaddr ) + drop 2dup flush-d$-range drop ( virt ) +; +: dma-map-out ( virt devaddr size -- ) nip flush-d$-range ; + +: dma-sync ( virt devaddr size -- ) nip flush-d$-range ; +: dma-push ( virt devaddr size -- ) nip flush-d$-range ; +: dma-pull ( virt devaddr size -- ) nip flush-d$-range ; + +finish-device + +device-end + +\ Call this after the system-mac-address is determined, which is typically +\ done near the end of the probing process. +: set-system-id ( -- ) + system-mac-address dup if ( adr 6 ) + " /" find-device ( adr 6 ) + + \ Convert the six bytes of the MAC address into a string of the + \ form 0NNNNNNNNNN, where N is an uppercase hex digit. + push-hex ( adr 6 ) + + <# bounds swap 1- ?do ( ) + i c@ u# u# drop ( ) + -1 +loop ( ) + 0 u# u#> ( adr len ) + + 2dup upper ( adr len ) \ Force upper case + + pop-base ( adr len ) + + encode-string " system-id" property ( ) + + device-end + else + 2drop + then +; +headers + +\ LICENSE_BEGIN +\ Copyright (c) 2007 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Added: cpu/arm/mmp2/sdhcimmp2.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/sdhcimmp2.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,27 @@ +purpose: Load file for SDHCI (Secure Digital Host Controller Interface) + +0 0 " d4280000" " /" begin-package + + fload ${BP}/cpu/arm/mmp2/sdregs.fth + fload ${BP}/dev/mmc/sdhci/sdhci.fth + + new-device + 3 encode-int " reg" property + fload ${BP}/dev/mmc/sdhci/sdmmc.fth + \ fload ${BP}/dev/mmc/sdhci/selftest.fth + " internal" " slot-name" string-property + finish-device + +\ new-device +\ 2 encode-int " reg" property +\ " mv8686" " $load-driver" eval drop +\ finish-device + + new-device + 1 encode-int " reg" property + fload ${BP}/dev/mmc/sdhci/sdmmc.fth + \ fload ${BP}/dev/mmc/sdhci/selftest.fth + " external" " slot-name" string-property + finish-device + +end-package
Added: cpu/arm/mmp2/sdregs.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/sdregs.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,27 @@ +h# 100 value /regs \ Standard size of SDHCI register block +4 value #slots + +0 instance value slot +0 instance value chip + +0 0 encode-bytes +h# d4280000 encode-phys encode+ /regs encode-int encode+ +h# d4280800 encode-phys encode+ /regs encode-int encode+ +h# d4281000 encode-phys encode+ /regs encode-int encode+ +h# d4281800 encode-phys encode+ /regs encode-int encode+ +" reg" property + +: map-regs ( -- ) + chip if exit then + slot 1- h# 800 * my-space + /regs " map-in" $call-parent + to chip +; +: unmap-regs ( -- ) + chip 0= if exit then + chip /regs " map-out" $call-parent + 0 to chip +; + +: vendor-modes ( -- ) ; +: ?cafe-fpga-quirk ( -- ) ; +: ?via-quirk ( -- ) ;
Added: cpu/arm/mmp2/timer.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/timer.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,50 @@ +: +!@ ( value offset base -- ) + tuck l! l@ drop ; +: timer! ( value offset -- ) timer-pa +!@ ; +: init-timers ( -- ) + h# 13 h# 24 clock-unit-pa + l! + 0 h# 84 timer-pa + l! \ TMR_CER - count enable + begin h# 84 timer-pa + l@ 7 and 0= until + h# 24 h# 00 timer-pa +!@ \ TMR_CCR - clock control + h# 200 0 do loop + 0 h# 88 timer! \ count mode - periodic + 0 h# 4c timer! \ preload value timer 0 + 0 h# 50 timer! \ preload value timer 1 + 0 h# 54 timer! \ preload value timer 2 + 0 h# 58 timer! \ free run timer 0 + 0 h# 5c timer! \ free run timer 1 + 0 h# 60 timer! \ free run timer 2 + 7 h# 74 timer! \ interrupt clear timer 0 + h# 100 h# 4 timer! \ Force match + h# 100 h# 8 timer! \ Force match + h# 100 h# c timer! \ Force match + h# 200 0 do loop + 7 h# 84 timer! +; + + +code timer0@ ( -- n ) \ 3.25 MHz + psh tos,sp + set r1,0xD4014000 + mov r0,#1 + str r0,[r1,#0xa4] + mov r0,r0 + ldr tos,[r1,#0x28] +c; + +code timer1@ ( -- n ) \ 32.768 kHz + psh tos,sp + set r1,0xD4014000 + mov r0,#1 + str r0,[r1,#0xa8] + mov r0,r0 + ldr tos,[r1,#0x2c] +c; + +code timer2@ ( -- n ) \ 1 kHz + psh tos,sp + set r1,0xD4014000 + mov r0,#1 + str r0,[r1,#0xac] + mov r0,r0 + ldr tos,[r1,#0x30] +c;
Added: cpu/arm/mmp2/twsi.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/twsi.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,316 @@ +purpose: Driver for Two Wire Serial Interface on Marvell Armada 610 + +\ 0 0 " d4011000" " /" begin-package + +0 value chip +0 value clock-reg +0 value slave-address + +: dbr@ ( -- n ) chip h# 08 + l@ ; +: cr@ ( -- n ) chip h# 10 + l@ ; +: sr@ ( -- n ) chip h# 18 + l@ ; +: sar@ ( -- n ) chip h# 20 + l@ ; +: lcr@ ( -- n ) chip h# 28 + l@ ; +: dbr! ( n -- ) chip h# 08 + l! ; +: cr! ( n -- ) chip h# 10 + l! ; +: sr! ( n -- ) chip h# 18 + l! ; +: sar! ( n -- ) chip h# 20 + l! ; +: lcr! ( n -- ) chip h# 28 + l! ; + +create channel-bases +h# D4011000 , h# D4031000 , h# D4032000 , h# D4033000 , h# D4033800 , h# D4034000 , + +create clock-offsets +h# 04 c, h# 08 c, h# 0c c, h# 10 c, h# 7c c, h# 80 c, + +create slave-addresses \ per channel +h# 78 c, \ 1 MAX8925 PMIC MAIN 78, PMIC ADC 8e, PMIC RTC d0, MAX8649 c0 +h# 34 c, \ 2 WM8994 Audio Codec 34, WM2000 Noise Canceler 74 +h# 3e c, \ 3 m6M0 Camera ISP 3e, OV8810 Camera 6c +h# 3c c, \ 4 HMC5843 compass 3c, CM3623 ALS/PS 20+22+b0, BMA150 accelerometer 70 +h# 16 c, \ 5 TC358762 MIPI bridge 16, TM-1210 or TM1414 touchscreen 40 +h# a0 c, \ 6 HDMI DDC EDID a0 + +: set-slave ( n -- ) to slave-address ; +: set-address ( n -- ) \ Channel numbers range from 1 to 6 + 1- + channel-bases over na+ @ to chip ( n ) + dup clock-offsets + c@ clock-unit-pa + to clock-reg ( n ) + slave-addresses + c@ set-slave +; + +\ Bit defines + +h# 4000 constant bbu_ICR_UR \ Unit Reset bit +h# 0040 constant bbu_ICR_IUE \ ICR TWSI Unit enable bit +h# 0020 constant bbu_ICR_SCLE \ ICR TWSI SCL Enable bit +h# 0010 constant bbu_ICR_MA \ ICR Master Abort bit +h# 0008 constant bbu_ICR_TB \ ICR Transfer Byte bit +h# 0004 constant bbu_ICR_ACKNAK \ ICR ACK bit +h# 0002 constant bbu_ICR_STOP \ ICR STOP bit +h# 0001 constant bbu_ICR_START \ ICR START bit +h# 0040 constant bbu_ISR_ITE \ ISR Transmit empty bit +h# 0400 constant bbu_ISR_BED \ Bus Error Detect bit + +h# 1000 constant BBU_TWSI_TimeOut \ TWSI bus timeout loop counter value + +bbu_ICR_IUE bbu_ICR_SCLE or constant iue+scle +: init-twsi-channel ( channel# -- ) + set-address + 7 clock-reg l! 3 clock-reg l! \ Set then clear reset bit + 1 us + iue+scle bbu_ICR_UR or cr! \ Reset the unit + iue+scle cr! \ Release the reset + 0 sar! \ Set host slave address + 0 cr! \ Disable interrupts +; + +: twsi-run ( extra-flags -- ) + iue+scle or bbu_ICR_TB or cr! ( ) + + h# 1000 0 do + cr@ bbu_ICR_TB and 0= if unloop exit then + loop + true abort" TWSI timeout" +; +: twsi-putbyte ( byte extra-flags -- ) + swap dbr! ( extra-flags ) + twsi-run +; +: twsi-getbyte ( extra-flags -- byte ) + twsi-run ( ) + dbr@ ( byte ) + sr@ sr! ( byte ) +; + +: twsi-start ( slave-address -- ) + bbu_ICR_START twsi-putbyte ( ) + sr@ bbu_ISR_BED and if ( ) + bbu_ISR_BED sr! ( ) + iue+scle bbu_ICR_MA or cr! ( ) + true abort" TWSI bus error" + then ( ) +; + +: twsi-get ( register-address .. #reg-bytes #data-bytes -- data-byte ... ) + >r ( reg-adr .. #regs r: #data-bytes ) + \ Handle the case where the device does not require that a write register address be sent + slave-address ( reg-adr .. #regs slave-address r: #data-bytes ) + over 0= if ( reg-adr .. #regs slave-address r: #data-bytes ) + r@ if ( reg-adr .. #regs slave-address r: #data-bytes ) + 1 or ( reg-adr .. #regs slave-address' r: #data-bytes ) + then ( reg-adr .. #regs slave-address' r: #data-bytes ) + then ( reg-adr .. #regs slave-address' r: #data-bytes ) + + twsi-start ( reg-adr .. #regs r: #data-bytes ) + + \ Abort the transaction if both #reg-bytes and #data-bytes are 0 + dup r@ or 0= if ( #regs r: #data-bytes ) + iue+scle bbu_ICR_MA or cr! ( #regs r: #data-bytes ) \ Master abort + r> 2drop exit ( -- ) + then ( reg-adr .. #regs r: #data-bytes ) + + \ Send register addresses, if any + 0 ?do 0 twsi-putbyte loop ( r: #data-bytes ) + + \ If no result data requested, quit now + r> dup 0= if ( #data-bytes ) + drop ( ) + iue+scle bbu_ICR_STOP or cr! ( ) + exit + then ( #data-bytes ) + + \ Otherwise send the read address with another start bit + slave-address 1 or bbu_ICR_START twsi-putbyte ( #data-bytes ) + sr@ sr! \ clear ITE and IRF status bits ( #data-bytes ) + \ Bug on line 367 of bbu_TWSI.s - writes SR without first reading it + + 1- 0 ?do 0 twsi-getbyte loop ( bytes ) + + \ Set the stop bit on the final byte + bbu_ICR_STOP bbu_ICR_ACKNAK or twsi-getbyte ( bytes ) +; + +: twsi-write ( byte .. #bytes -- ) + slave-address twsi-start ( byte .. #bytes ) + + 1- 0 ?do 0 twsi-putbyte loop ( byte ) + bbu_ICR_STOP twsi-putbyte ( ) +; + +: twsi-b@ ( reg -- byte ) 1 1 twsi-get ; +: twsi-b! ( byte reg -- ) 2 twsi-write ; + +: select-touch-panel ( -- ) + 5 set-address + h# 40 set-slave +; +: touch-panel-type ( -- n ) + select-touch-panel + h# bd twsi-b@ +; +: get-tm1414-data ( -- x y finger-mask ) + select-touch-panel ( ) + h# 1a twsi-b@ ( low-y,low-x ) + dup h# f and h# 18 twsi-b@ 4 lshift or ( low-y,low-x x ) + swap 4 rshift h# f and h# 19 twsi-b@ 4 lshift or ( x y ) + h# 15 twsi-b@ ( x y mask ) +; +: touchpad@ ( -- x y finger-mask ) get-tm1414-data ; + +: get-tm1210-data ( -- x y reg7-flick-magnitude reg6-gesture reg0-finger-count ) + 3 twsi-b@ 2 twsi-b@ bwjoin ( x ) + 5 twsi-b@ 4 twsi-b@ bwjoin ( x y ) + + 7 twsi-b@ + 6 twsi-b@ + 0 twsi-b@ +; + +: select-compass ( -- ) + 4 set-address + h# 3c set-slave +; + +: compass@ ( -- x y z temp id ) + select-compass + 0 0 twsi-b! \ Config register A + h# 50 1 twsi-b! \ Config register B + 0 2 twsi-b! \ Mode register + 4 twsi-b@ 3 twsi-b@ bwjoin ( x ) + 6 twsi-b@ 5 twsi-b@ bwjoin ( x y ) + 8 twsi-b@ 7 twsi-b@ bwjoin ( x y z ) + h# b twsi-b@ ( x y z temp ) + h# a twsi-b@ 9 twsi-b@ bwjoin ( x y z temp id ) +; + +: select-pmic ( -- ) 1 set-address h# 78 set-slave ; + +: accel-power-on ( -- ) \ LDO8 - vout is 36, ctl is 34 + select-pmic + d# 3000 d# 750 - d# 50 / h# 36 twsi-b! \ want 3.0V + h# 1f h# 34 twsi-b! +; +: accel-power-off ( -- ) \ LDO8 - vout is 36, ctl is 34 + select-pmic + h# 1e h# 34 twsi-b! +; +: accel@ ( -- x y z temp id ) + 4 set-address + h# 70 set-slave + + 2 twsi-b@ 6 rshift ( x-low ) + 3 twsi-b@ 2 lshift or ( x ) + + 4 twsi-b@ 6 rshift ( x y-low ) + 5 twsi-b@ 2 lshift or ( x y ) + + 6 twsi-b@ 6 rshift ( x y z-low ) + 7 twsi-b@ 2 lshift or ( x y z ) + + 8 twsi-b@ 0 twsi-b@ ( x y z temp id ) +; + +: init-pals ( -- ) + 4 set-address + + h# b0 set-slave \ Set PS parameters address + 0 1 twsi-write \ clear interrupt settings + + h# 22 set-slave \ Device init address + h# 10 1 twsi-write \ Init device + + h# 20 set-slave \ Ambient Light Sensor address + 2 1 twsi-write \ Enable ALS in most sensitive mode, 16-bit data +; +: als@ ( -- n ) + 4 set-address + h# 22 set-slave \ Ambient Light Sensor LSB address + 0 1 twsi-get ( low ) + h# 20 set-slave \ Ambient Light Sensor MSB address + 0 1 twsi-get bwjoin ( n ) +; + +: proximity@ ( -- byte ) + 4 set-address + h# b0 set-slave \ Proximity Sensor address + 0 1 twsi-get ( byte ) +; + +: lcd-backlight! ( b.intensity -- ) + select-pmic ( b.intensity ) + dup if ( b.intensity ) + h# 85 twsi-b! ( ) + h# 84 twsi-b@ 1 or h# 84 twsi-b! \ Turn on first LED string + else ( 0 ) + drop ( ) + h# 84 twsi-b@ 1 invert and h# 84 twsi-b! \ Turn off first LED string + then +; + +: keypad-backlight! ( b.intensity -- ) + select-pmic ( b.intensity ) + dup if ( b.intensity ) + h# 85 twsi-b! ( ) + h# 84 twsi-b@ 3 or h# 84 twsi-b! \ Turn on both LED strings + else ( ) + h# 84 twsi-b@ 3 invert and h# 84 twsi-b! \ Turn off both LED strings + then +; + +: init-twsi ( -- ) + 7 1 do i init-twsi-channel loop +; +: power-on-dsi ( -- ) + select-pmic + + h# 16 h# 22 twsi-b! \ 1.2 volts for LDO3 + h# 1f h# 20 twsi-b! \ LDO3 enable + + h# 16 h# 16 twsi-b! \ 1.2 volts for LDO17 + h# 1f h# 14 twsi-b! \ LDO17 enable + + h# 1f h# 34 twsi-b! \ LDO8 enable + + d# 10 ms +; + +: bcd> ( bcd -- binary ) + dup h# f and swap 4 rshift d# 10 * + +; +: twsi-bcd@ ( reg# -- binary ) twsi-b@ bcd> ; +: get-rtc ( -- ) + 1 set-address + h# d0 set-slave + +\ 3 twsi-b@ ( dow ) +\ + + 0 twsi-bcd@ ( sec ) + 1 twsi-bcd@ ( sec min ) + 2 twsi-bcd@ ( sec min hr ) + 4 twsi-bcd@ ( sec min hr day ) + 5 twsi-bcd@ ( sec min hr day mon ) + 6 twsi-bcd@ d# 2000 + ( sec min hr day yr ) +; + +: core-voltage! ( mv -- ) + 1 set-address h# c0 set-slave \ MAX8649 power management IC + + d# 750 umax d# 1350 umin \ Clipped voltage + d# 750 - d# 10 / ( offset-in-mv/10 ) + h# 80 or ( code ) + 2 twsi-b! +; +: core-voltage@ ( -- mv ) + 1 set-address h# c0 set-slave \ MAX8649 power management IC + 2 twsi-b@ ( code ) + h# 7f and ( offset-mv/10 ) + d# 10 * ( offset-mv ) + d# 750 + +; +: .core-voltage ( -- ) core-voltage@ .d ; + +: vibrate-on ( -- ) select-pmic h# 1f h# 3c twsi-b! ; \ LDO10 +: vibrate-off ( -- ) select-pmic h# 1e h# 3c twsi-b! ; +
Added: cpu/arm/mmp2/virtaddr.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/mmp2/virtaddr.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,3 @@ +h# 10.0000 constant fw-virt-base +h# 40.0000 constant fw-virt-size +
Added: cpu/arm/rootnode.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ cpu/arm/rootnode.fth Wed Jun 16 13:41:36 2010 (r1823) @@ -0,0 +1,105 @@ +purpose: Methods for root node +\ See license at end of file + +: root-map-in ( phys len -- virt ) + " /" " map-in" execute-device-method drop +; +: root-map-out ( virt len -- ) + " /" " map-out" execute-device-method drop +; + +dev / +extend-package + +1 encode-int " #address-cells" property + +hex + +\ Static methods +: decode-unit ( adr len -- phys ) push-hex $number if 0 then pop-base ; +: encode-unit ( phys -- adr len ) push-hex (u.) pop-base ; + +\ Not-necessarily-static methods +: open ( -- true ) true ; +: close ( -- ) ; + +: map-in ( phys size -- virt ) + over mmu-lowbits + pagesize round-up >r ( phys r: size' ) + r@ pagesize mmu-claim ( phys virt r: size' ) + >r dup mmu-highbits ( phys phys' r: size' virt ) + r> r> over >r ( phys phys' virt size r: virt ) + -1 mmu-map ( phys r: virt ) + mmu-lowbits r> + ( virtual ) +; +: map-out ( virtual size -- ) + 2dup mmu-unmap mmu-release +; + +: dma-alloc ( size -- virt ) alloc-mem ; +: dma-free ( virt size -- ) free-mem ; + +: dma-map-in ( virt size cacheable -- devaddr ) + drop 2dup flush-d$-range drop ( virt ) + mmu-translate 0= abort" Invalid DMA address" drop ( phys ) +; +: dma-map-out ( virt devaddr size -- ) nip flush-d$-range ; + +: dma-sync ( virt devaddr size -- ) nip flush-d$-range ; +: dma-push ( virt devaddr size -- ) nip flush-d$-range ; +: dma-pull ( virt devaddr size -- ) nip flush-d$-range ; + +finish-device + +device-end + +\ Call this after the system-mac-address is determined, which is typically +\ done near the end of the probing process. +: set-system-id ( -- ) + system-mac-address dup if ( adr 6 ) + " /" find-device ( adr 6 ) + + \ Convert the six bytes of the MAC address into a string of the + \ form 0NNNNNNNNNN, where N is an uppercase hex digit. + push-hex ( adr 6 ) + + <# bounds swap 1- ?do ( ) + i c@ u# u# drop ( ) + -1 +loop ( ) + 0 u# u#> ( adr len ) + + 2dup upper ( adr len ) \ Force upper case + + pop-base ( adr len ) + + encode-string " system-id" property ( ) + + device-end + else + 2drop + then +; +headers + +\ LICENSE_BEGIN +\ Copyright (c) 2007 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END