Author: wmb Date: Thu Nov 18 01:52:11 2010 New Revision: 2026 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2026
Log: OLPC XO-1.75 - Audio selftest and a few other selftests are now working. Some refactoring of common code to support same.
Modified: cpu/arm/mmp2/mmuon.fth cpu/arm/mmp2/rootnode.fth cpu/arm/olpc/1.75/addrs.fth cpu/arm/olpc/1.75/devices.fth cpu/arm/olpc/1.75/fw-version.fth cpu/arm/olpc/1.75/fw.bth cpu/arm/olpc/1.75/prefw.bth cpu/arm/olpc/1.75/rtc.fth cpu/arm/olpc/1.75/sdhci.fth cpu/arm/olpc/1.75/smbus.fth cpu/arm/olpc/1.75/sound.fth cpu/x86/adpcm.fth cpu/x86/pc/olpc/gridmap.fth cpu/x86/pc/olpc/via/banner.fth dev/olpc/keyboard/selftest.fth dev/olpc/mmp2camera/loadpkg.fth dev/olpc/touchpad/touchpad.fth dev/video/common/rectangle16.fth
Modified: cpu/arm/mmp2/mmuon.fth ============================================================================== --- cpu/arm/mmp2/mmuon.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/mmp2/mmuon.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -29,7 +29,7 @@ \ h# d100.0000 h# c0e over h# 0030.0000 map-sections \ Cache and write bufferable (SRAM) h# d100.0000 h# c02 over h# 0030.0000 map-sections \ I/O - no caching or buffering (SRAM) h# d400.0000 h# c02 over h# 0040.0000 map-sections \ I/O - no caching or buffering - h# e000.0000 h# c02 over /section map-sections \ I/O - no caching or buffering + h# e000.0000 h# c02 over /section map-sections \ Audio SRAM - no caching or buffering ;
: setup-sections
Modified: cpu/arm/mmp2/rootnode.fth ============================================================================== --- cpu/arm/mmp2/rootnode.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/mmp2/rootnode.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -31,8 +31,78 @@ 2drop ;
-: dma-alloc ( size -- virt ) alloc-mem ; -: dma-free ( virt size -- ) free-mem ; +: dma-range ( -- start end ) dma-base dup dma-size + ; + +h# 0 constant dma-map-mode \ XXX what should this be? + +\ Used with "find-node" to locate a physical memory node containing +\ enough memory in the DMA range. +\ We first compute the intersection between the memory piece and the +\ range reachable by DMA. If the regions are disjoint, then ok-high +\ will be (unsigned) less than ok-low. We then subtract ok-low from +\ ok-high to give the (possibly negative) size of the intersection. +: in-range? ( size mem-low mem-high range-low range-high -- flag ) + rot umin -rot ( size min-high mem-low mem-high ) + umax ( size min-high max-low ) + - <= ( flag ) +; + +: dma-ok? ( size node-adr -- size flag ) + node-range ( size mem-adr mem-len ) + over + ( size mem-adr mem-end ) + + 3dup dma-range in-range? if ( size mem-adr mem-end ) + 2drop true exit ( size true ) + then ( size mem-adr mem-end ) + + 2drop false ( size false ) +; + +\ Find an available physical address range suitable for DMA. This word +\ doesn't actually claim the memory (that is done later), but simply locates +\ a suitable range that can be successfully claimed. +: find-dma-address ( size -- true | adr false ) + " physavail" memory-node @ $call-method ( list ) + ['] dma-ok? find-node is next-node drop ( size' ) + next-node 0= if drop true exit then ( size' ) + next-end ( size mem-end ) + dma-range ( size mem-end range-l,h ) + nip umin swap - false ( adr false ) +; + +headers +: dma-alloc ( size -- virt ) + pagesize round-up + + \ Locate a suitable physical range + dup find-dma-address throw ( size' phys ) + + \ Claim it + over 0 mem-claim ( size' phys ) + +[ifdef] virtual-mode + \ Get a virtual range + over pagesize mmu-claim ( size' phys virt ) + + \ Map the physical and virtual ranges + dup >r ( size' phys virt ) + rot dma-map-mode ( phys virt size' mode ) + mmu-map ( ) + r> ( virt ) +[else] + nip +[then] +; +: dma-free ( virt size -- ) + pagesize round-up ( virt size' ) +[ifdef] virtual-mode + over mmu-translate 0= abort" Freeing unmapped dma memory" drop + ( virt size phys ) + -rot tuck ( phys size virt size ) + 2dup mmu-unmap mmu-release ( phys size ) +[then] + mem-release ( ) +;
: dma-map-in ( virt size cacheable -- devaddr ) drop 2dup flush-d$-range drop ( virt )
Modified: cpu/arm/olpc/1.75/addrs.fth ============================================================================== --- cpu/arm/olpc/1.75/addrs.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/addrs.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -6,6 +6,7 @@
fb-pa constant available-ram-size
+ h# 20000 constant dropin-offset \ Offset to dropin driver area in SPI FLASH [ifdef] use-flash-nvram h# d.0000 constant nvram-offset @@ -20,9 +21,11 @@ : (memory?) ( phys -- flag ) total-ram-size u< ;
\ OFW implementation choices -\ h# 1fe0.0000 constant fw-pa h# 1fa0.0000 constant fw-pa
+h# 1f00.0000 constant dma-base +h# a0.0000 constant dma-size + [ifdef] virtual-mode h# f700.0000 constant fw-virt-base h# 0100.0000 constant fw-virt-size \ 16 megs of mapping space
Modified: cpu/arm/olpc/1.75/devices.fth ============================================================================== --- cpu/arm/olpc/1.75/devices.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/devices.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -191,6 +191,9 @@ " ISO8859-1" encode-string " character-set" property 0 0 encode-bytes " iso6429-1983-colors" property
+ \ Used as temporary storage for images by $get-image + : graphmem ( -- adr ) dimensions * pixel* fb-pa + ; + : display-install ( -- ) display-on default-font set-font @@ -217,8 +220,8 @@
fload ${BP}/cpu/arm/olpc/1.75/sdhci.fth
-devalias int /sd@d4281000/disk -devalias ext /sd@d4280000/disk +devalias int /sd/disk@1 +devalias ext /sd/disk@3 devalias net /wlan \ XXX should report-net in case of USB Ethernet
fload ${BP}/dev/olpc/kb3700/spicmd.fth @@ -262,8 +265,14 @@
fload ${BP}/dev/olpc/mmp2camera/loadpkg.fth
+fload ${BP}/cpu/x86/adpcm.fth \ ADPCM decoding +d# 32 is playback-volume + fload ${BP}/cpu/arm/olpc/1.75/sound.fth fload ${BP}/cpu/arm/olpc/1.75/rtc.fth +stand-init: RTC + " /rtc" open-dev clock-node ! +; fload ${BP}/cpu/arm/olpc/1.75/accelerometer.fth fload ${BP}/cpu/arm/olpc/1.75/compass.fth
Modified: cpu/arm/olpc/1.75/fw-version.fth ============================================================================== --- cpu/arm/olpc/1.75/fw-version.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/fw-version.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -1,3 +1,3 @@ \ The overall firmware revision macro: FW_MAJOR A -macro: FW_MINOR 04c +macro: FW_MINOR 04d
Modified: cpu/arm/olpc/1.75/fw.bth ============================================================================== --- cpu/arm/olpc/1.75/fw.bth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/fw.bth Thu Nov 18 01:52:11 2010 (r2026) @@ -5,7 +5,7 @@ command: &armforth &dictionary &this build-now
-\ " fw.tag" r/w create-file drop tag-file ! +" fw.tag" r/w create-file drop tag-file !
hex \ ' $report-name is include-hook @@ -51,6 +51,8 @@ \ false to stand-init-debug? true to stand-init-debug?
+false value secure? + : protect-fw ( -- ) ;
hex @@ -90,8 +92,6 @@ ; ' (.firmware) to .firmware
-\ fload ${BP}/cpu/x86/pc/olpc/via/banner.fth - patch merge-rect-565 merge-rect merge-cursor \ Hack since we do all our user-level graphics in 565 patch merge-rect-565 merge-rect merge-cursor \ Hack since we do all our user-level graphics in 565
@@ -126,6 +126,12 @@
fload ${BP}/cpu/x86/pc/olpc/via/banner.fth
+h# d00 value board-revision \ Implement me!!! + +\ This must be defined after spiui.fth, otherwise spiui will choose some wrong code +: rom-pa ( -- adr ) mfg-data-buf mfg-data-offset - ; \ Fake out setwp.fth +fload ${BP}/cpu/x86/pc/olpc/setwp.fth + fload ${BP}/cpu/x86/pc/olpc/help.fth fload ${BP}/cpu/x86/pc/olpc/gui.fth fload ${BP}/cpu/x86/pc/olpc/strokes.fth @@ -142,24 +148,50 @@ end-package
fload ${BP}/dev/logdev.fth -[ifdef] notyet +0 value smt-test? \ !!! +0 value final-test? \ !!! +fload ${BP}/cpu/x86/pc/olpc/disptest.fth fload ${BP}/dev/olpc/keyboard/selftest.fth \ Keyboard diagnostic fload ${BP}/dev/olpc/touchpad/touchpad.fth \ Touchpad diagnostic -[then] fload ${BP}/cpu/x86/pc/olpc/gridmap.fth \ Gridded display tools fload ${BP}/cpu/x86/pc/olpc/via/copynand.fth
-[ifdef] notyet +: game-key@ ( -- n ) 0 ; \ Implement me!!! fload ${BP}/cpu/x86/pc/olpc/gamekeys.fth : emacs ( -- ) false to already-go? boot-getline to boot-file " rom:emacs" $boot ; defer rm-go-hook \ Not used, but makes security happy +: tsc@ ( -- d.ticks ) timer0@ u>d ; +d# 6500 constant ms-factor +0 value ec-indexed-io-off? \ !!! +: ec-indexed-io-off ( -- ) ; \ !!! +: ec-ixio-reboot ( -- ) ; \ !!! +: flash-base ( -- ) true abort" The stuff that relies on flash-base in security.fth needs to be reworked!" ; +: cmos@ ( index -- data ) h# 38 mod 8 + " rtc@" clock-node @ $call-method ; +: cmos! ( index data -- ) h# 38 mod 8 + " rtc!" clock-node @ $call-method ; +: halt ( -- ) c7-wfi ; +fload ${BP}/cpu/x86/pc/olpc/sound.fth fload ${BP}/cpu/x86/pc/olpc/security.fth
+[ifdef] notyet +create use-thinmac +fload ${BP}/cpu/x86/bootascall.fth +fload ${BP}/cpu/x86/pc/olpc/wifichannel.fth +fload ${BP}/cpu/x86/pc/olpc/via/nbtx.fth +fload ${BP}/cpu/x86/pc/olpc/via/nbrx.fth +fload ${BP}/cpu/x86/pc/olpc/via/blockfifo.fth +[else] +0 value nb-zd-#sectors +: nandblaster true abort" No nandblaster yet" ; +: show-temperature ; [then]
+fload ${BP}/cpu/x86/pc/olpc/via/fsupdate.fth +fload ${BP}/cpu/x86/pc/olpc/via/fsverify.fth +devalias fsdisk int:0 + fload ${BP}/ofw/gui/ofpong.fth [ifdef] notyet fload ${BP}/cpu/x86/pc/olpc/life.fth @@ -171,6 +203,8 @@ \needs ramdisk " " d# 128 config-string ramdisk " " ' boot-file set-config-string-default \ Let the boot script set the cmdline
+2 config-int auto-boot-countdown + \ Eliminate 4 second delay in install console for the case where \ there is no keyboard. The delay is unnecessary because the screen \ does not go blank when the device is closed. @@ -212,7 +246,9 @@ warning on only forth also definitions
+ show-child install-alarm + ['] sound catch drop
page-mode #line off @@ -251,6 +287,7 @@ ; [then]
+ : startup ( -- ) standalone? 0= if exit then
@@ -311,7 +348,7 @@ " devalias fsdisk //null" evaluate ;
-\ tag-file @ fclose tag-file off +tag-file @ fclose tag-file off
.( --- Saving fw.dic ...) " fw.dic" $save-forth cr
Modified: cpu/arm/olpc/1.75/prefw.bth ============================================================================== --- cpu/arm/olpc/1.75/prefw.bth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/prefw.bth Thu Nov 18 01:52:11 2010 (r2026) @@ -38,6 +38,8 @@ " com1" ' input-device set-config-string-default [then]
+fload ${BP}/ofw/core/memlist.fth \ Resource list common routines +fload ${BP}/ofw/core/showlist.fth \ Linked list display tool
fload ${BP}/cpu/arm/mmp2/rootnode.fth \ Root node mapping - physical mode dev / @@ -64,8 +66,7 @@ then ; [then] -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
@@ -197,18 +198,6 @@ : olpc-ssids ( -- $ ) " OLPCOFW" ; ' olpc-ssids to default-ssids
-[ifdef] notyet -create use-thinmac -fload ${BP}/cpu/x86/bootascall.fth -fload ${BP}/cpu/x86/pc/olpc/wifichannel.fth -fload ${BP}/cpu/x86/pc/olpc/via/nbtx.fth -fload ${BP}/cpu/x86/pc/olpc/via/nbrx.fth -fload ${BP}/cpu/x86/pc/olpc/via/blockfifo.fth -fload ${BP}/cpu/x86/pc/olpc/via/fsupdate.fth -fload ${BP}/cpu/x86/pc/olpc/via/fsverify.fth -devalias fsdisk int:0 -[then] - fload ${BP}/ofw/inet/sntp.fth : olpc-ntp-servers ( -- ) " DHCP time 172.18.0.1 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org"
Modified: cpu/arm/olpc/1.75/rtc.fth ============================================================================== --- cpu/arm/olpc/1.75/rtc.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/rtc.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -4,6 +4,48 @@ : set-address ( -- ) h# d0 2 set-twsi-target ; : rtc@ ( reg# -- byte ) set-address twsi-b@ ; : rtc! ( byte reg# -- ) set-address twsi-b! ; -: open ( -- okay ) true ; -: close ( -- ) ; + +headerless + +headerless + +headers +: open ( -- true ) + true +; +: close ( -- ) +; + +headerless +: bcd> ( bcd -- binary ) dup h# f and swap 4 >> d# 10 * + ; +: >bcd ( binary -- bcd ) d# 10 /mod 4 << + ; + +: bcd-time&date ( -- s m h d m y century ) + 0 1 7 twsi-get ( s m h dow d m y ) + 3 roll drop ( s m h dow d m y ) + d# 20 +; +: bcd! ( n offset -- ) swap >bcd swap rtc! ; + +headers +: get-time ( -- s m h d m y ) + bcd-time&date >r >r >r >r >r >r + bcd> r> bcd> r> bcd> r> bcd> r> bcd> r> bcd> r> bcd> ( s m h d m y c ) + + d# 100 * + \ Merge century with year +; +: set-time ( s m h d m y -- ) + d# 100 /mod h# 1a bcd! 9 bcd! 8 bcd! 7 bcd! 4 bcd! 2 bcd! 0 bcd! +; + +: selftest ( -- flag ) + open 0= if true close exit then + 0 rtc@ d# 1100 ms 0 rtc@ = if + ." RTC did not tick" cr + true close exit + then + close + false +; + end-package
Modified: cpu/arm/olpc/1.75/sdhci.fth ============================================================================== --- cpu/arm/olpc/1.75/sdhci.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/sdhci.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -30,7 +30,7 @@ new-device 1 encode-int " reg" property fload ${BP}/dev/mmc/sdhci/sdmmc.fth - \ fload ${BP}/dev/mmc/sdhci/selftest.fth + fload ${BP}/dev/mmc/sdhci/selftest.fth " external" " slot-name" string-property finish-device
@@ -42,7 +42,7 @@ new-device 3 encode-int " reg" property fload ${BP}/dev/mmc/sdhci/sdmmc.fth - \ fload ${BP}/dev/mmc/sdhci/selftest.fth + fload ${BP}/dev/mmc/sdhci/selftest.fth " internal" " slot-name" string-property finish-device
Modified: cpu/arm/olpc/1.75/smbus.fth ============================================================================== --- cpu/arm/olpc/1.75/smbus.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/smbus.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -11,7 +11,7 @@ : smb-data@ ( -- flag ) smb-data-gpio# gpio-pin@ ; : smb-clk@ ( -- flag ) smb-clock-gpio# gpio-pin@ ; : smb-off ( -- ) smb-data-gpio# gpio-dir-in ; -: smb-on ( -- ) smb-data-gpio# gpio-dir-out ; +: smb-on ( -- ) smb-data-gpio# gpio-dir-out smb-clock-gpio# gpio-dir-out ; : smb-data-dir-out ( -- ) smb-data-gpio# gpio-dir-out ; : smb-data-dir-in ( -- ) smb-data-gpio# gpio-dir-in ;
Modified: cpu/arm/olpc/1.75/sound.fth ============================================================================== --- cpu/arm/olpc/1.75/sound.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/arm/olpc/1.75/sound.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -2,10 +2,12 @@ " audio" name my-space h# 40 reg
-: sspa! ( n offset -- ) h# d42a.0c00 + l! ; \ Write a register in SSPA1 -: sspa@ ( offset -- n ) h# d42a.0c00 + l@ ; \ Read a register in SSPA1 -: adma! ( n offset -- ) h# d42a.0800 + l! ; -: adma@ ( offset -- n ) h# d42a.0800 + l@ ; +h# d42a.0c00 constant sspa-base +h# d42a.0800 constant adma-base +: sspa! ( n offset -- ) sspa-base + l! ; \ Write a register in SSPA1 +: sspa@ ( offset -- n ) sspa-base + l@ ; \ Read a register in SSPA1 +: adma! ( n offset -- ) adma-base + l! ; +: adma@ ( offset -- n ) adma-base + l@ ;
: audio-clock-on ( -- ) h# 600 h# d428.290c l! d# 10 us \ Enable @@ -14,22 +16,34 @@ h# 712 h# d428.290c l! d# 10 us \ Release reset
+[ifdef] 24mhz \ * 10 / 27 gives about 147.456 \ The M/N divisor gets 199.33 MHz (Figure 283 - clock tree - in Datasheet) \ But the M/N divisors always have an implicit /2 (section 7.3.7 in datasheet), \ so the input frequency is 99.67 with respect to NOM (sic) and DENOM. - \ we want 24.576 MHz SYSCLK. 99.67 * 18 / 73 = 24.575 - 50 ppm error. + \ we want 24.576 MHz SYSCLK. 99.67 * 18 / 73 = 24.575 so 50 ppm error. d# 18 d# 15 lshift d# 73 or h# d000.0000 or h# d4050040 l! +[else] + \ * 10 / 27 gives about 147.456 + \ The M/N divisor gets 199.33 MHz (Figure 283 - clock tree - in Datasheet) + \ But the M/N divisors always have an implicit /2 (section 7.3.7 in datasheet), + \ so the input frequency is 99.67 with respect to NOM (sic) and DENOM. + \ we want 12.288 MHz SYSCLK. 99.67 * 9 / 73 = 12.2876 so 50 ppm error. + d# 9 d# 15 lshift d# 73 or h# d000.0000 or h# d4050040 l! +[then]
h# d405.0024 l@ h# 20 or h# d405.0024 l! \ Enable 12S clock out to SSPA1
h# 10800 38 sspa! + +[ifdef] 24mhz \ Bits 14:9 set the divisor from SYSCLK to BITCLK. The setting below \ is d# 16, which gives BITCLK = 3.072 MHz. That's 32x 48000, just enough \ for two (stereo) 16-bit samples. -\ h# 2183 34 sspa! - - h# 2183 34 sspa! \ Divisor 16 - BITCLK = 3.072 Mhz + h# 2183 h# 34 sspa! \ Divisor 16 - BITCLK = 3.072 Mhz +[else] + h# 1183 h# 34 sspa! \ Divisor 8 - BITCLK = 3.072 Mhz +[then] ;
: setup-sspa-rx ( -- ) @@ -52,6 +66,8 @@ d# 31 d# 4 lshift or \ Frame sync period 1 d# 2 lshift or \ Flush the FIFO h# 0c sspa! + + h# 10 h# 10 sspa! \ Rx FIFO limit ; : enable-sspa-rx ( -- ) h# 0c sspa@ h# 8004.0001 or h# 0c sspa! ; : disable-sspa-rx ( -- ) h# 0c sspa@ h# 8000.0040 or h# 4.0001 invert and h# 0c sspa! ; @@ -68,7 +84,7 @@ 2 d# 5 lshift or \ 16 bit word in phase 1 0 d# 3 lshift or \ Left justified data 2 d# 0 lshift or \ 16-bit audio sample in phase 1 - h# 88 sspa! \ Receive control register + h# 88 sspa! \ Transmit control register
h# 8000.0000 \ Enable writes d# 15 d# 20 lshift or \ Frame sync width @@ -79,81 +95,78 @@ d# 31 d# 4 lshift or \ Frame sync period 1 d# 2 lshift or \ Flush the FIFO h# 8c sspa! + + h# 10 h# 90 sspa! \ Tx FIFO limit ; : enable-sspa-tx ( -- ) h# 8c sspa@ h# 8004.0001 or h# 8c sspa! ; : disable-sspa-tx ( -- ) h# 8c sspa@ h# 8000.0040 or h# 4.0001 invert and h# 8c sspa! ; -: set-tx-fifo-limit ( n -- ) h# 90 sspa! ; -: set-rx-fifo-limit ( n -- ) h# 10 sspa! ;
-: putsample ( w -- ) - d# 16 lshift \ Justify ( l ) - h# a0 sspa@ ( l fifo-size ) - begin dup h# 9c sspa@ <> until drop ( w ) - h# 80 sspa! -; -: getsample ( -- w ) - begin h# 1c sspa@ until - 0 sspa@ d# 16 rshift +h# e000.0000 constant audio-sram +h# fc0 constant /audio-buf +audio-sram constant out-bufs +audio-sram h# 1f80 + constant out-desc +audio-sram h# 2000 + constant in-bufs +audio-sram h# 3f80 + constant in-desc + +\ Descriptor format: +\ Byte count +\ Source +\ Destination +\ link + +0 value my-out-desc \ out-desc or out-desc h# 20 + +0 value out-adr +0 value out-len +0 value my-in-desc \ in-desc or in-desc h# 20 + +0 value in-adr +0 value in-len +: set-descriptor ( next dest source length adr -- ) + >r r@ l! r@ la1+ l! r@ 2 la+ l! r> 3 la+ l! +; +: make-out-ring ( adr len -- ) + out-desc h# 10 + sspa-base h# 80 + out-bufs /audio-buf out-desc set-descriptor + out-desc sspa-base h# 80 + out-bufs /audio-buf + /audio-buf out-desc h# 10 + set-descriptor + out-desc h# 30 adma! \ Link to first descriptor + out-desc to my-out-desc +; +: start-out-ring ( -- ) + 1 h# 80 adma! \ Enable DMA completion interrupts + h# 0081.3020 h# 40 adma! \ 16 bits, pack, fetch next, enable, chain, hold dest, inc src +; +: make-in-ring ( adr len -- ) + in-desc h# 10 + in-bufs sspa-base /audio-buf in-desc set-descriptor + in-desc in-bufs /audio-buf + sspa-base /audio-buf in-desc h# 10 + set-descriptor + in-desc h# 34 adma! \ Link to first descriptor + in-desc to my-in-desc +; +: start-in-ring ( -- ) + 1 h# 84 adma! \ Enable DMA completion interrupts +\ h# 0081.3008 h# 44 adma! \ 16 bits, pack, fetch next, enable, chain, inc dest, hold src + h# 00a1.31c8 h# 44 adma! \ 16 bits, pack, fetch next, enable, chain, burst32, inc dest, hold src +; + +: copy-out ( -- ) + my-out-desc >r ( r: desc ) + out-len /audio-buf min ( this-len r: desc ) + dup r@ l! ( this-len r: desc ) + out-adr r@ la1+ l@ third move ( this-len r: desc ) + out-adr over + to out-adr ( this-len r: desc ) + out-len swap - to out-len ( r: desc ) + out-len if + r> 3 la+ l@ to my-out-desc + else + 0 r> 3 la+ l! \ When there is no more data, terminate the list + then ; -: audio-in ( adr len -- actual ) - tuck bounds ?do - getsample i w! - /w +loop + +: copy-in ( -- ) + in-len /audio-buf min ( this-len ) + my-in-desc 2 la+ l@ in-adr third move ( this-len ) + in-adr over + to in-adr ( this-len ) + in-len over - to in-len ( this-len ) + drop ( ) + my-in-desc 3 la+ l@ to my-in-desc ; -: audio-out ( adr len -- actual ) - tuck bounds ?do - i w@ putsample - /w +loop -; -0 value descriptors -0 value /descriptors -: make-out-dma-descriptor-chain ( adr len -- ) - dup h# 8000 round-up h# 8000 / to /descriptors - /descriptors alloc-mem to descriptors ( adr len ) - descriptors /descriptors bounds ?do ( adr len ) - dup h# 8000 max i l! ( adr len ) - over i 1 la+ l! ( adr len ) - h# d42a.0c80 i 2 la+ l! ( adr len ) - i h# 10 + i 3 la+ l! ( adr len ) - h# 8000 /string ( adr' len' ) - h# 10 +loop ( adr len ) - 2drop - 0 descriptors /descriptors + -1 la+ l! -; -: make-in-dma-descriptor-chain ( adr len -- ) - dup h# 8000 round-up h# 8000 / to /descriptors - /descriptors alloc-mem to descriptors ( adr len ) - descriptors /descriptors bounds ?do ( adr len ) - dup h# 8000 max i l! ( adr len ) - h# d42a.0c00 i 1 la+ l! ( adr len ) - over i 2 la+ l! ( adr len ) - i h# 10 + i 3 la+ l! ( adr len ) - h# 8000 /string ( adr' len' ) - h# 10 +loop ( adr len ) - 2drop - 0 descriptors /descriptors + -1 la+ l! -; -: dma-audio-in ( adr len -- ) - make-in-dma-descriptor-chain - \ Channel 1 - tuck 4 adma! h# 14 adma! \ Address and length - h# d42a.0c00 h# 24 adma! \ RX Data register - 0 h# 34 adma! \ Next descriptor - h# 0081.1208 h# 44 adma! \ 16 bits, pack, enable, non-chain, inc dest, hold src -; -: dma-audio-out ( adr len -- ) - \ Channel 0 - tuck 0 adma! h# 10 adma! \ Address and length - h# d42a.0c80 h# 20 adma! \ Tx data register - 0 h# 30 adma! \ Next descriptor - h# 0081.1220 h# 40 adma! \ 16 bits, pack, enable, non-chain, hold dest, inc src -; -: write-done ; - -: open-in ( -- ) h# 10 set-tx-fifo-limit enable-sspa-rx ; -: close-in ( -- ) disable-sspa-rx ; -: open-out ( -- ) h# 10 set-tx-fifo-limit enable-sspa-tx ; -: close-out ( -- ) disable-sspa-tx ;
\ Reset is unconnected on current boards \ : audio-reset ( -- ) 8 gpio-clr ; @@ -203,6 +216,25 @@ : codec-off ( -- ) h# ef00 h# 26 codec! \ Power down everything ; +d# 48000 value sample-rate + +\ Longest time to wait for a buffer event - a little more +\ than the time it takes to output /audio-buf samples +\ at the current sample rate. +0 value buf-timeout + +: set-sample-rate ( rate -- ) + to sample-rate + sample-rate case + d# 8000 of h# 2222 h# 5272 d# 48 d# 129 endof + d# 16000 of h# 2020 h# 2272 d# 24 d# 65 endof + d# 32000 of h# 2121 h# 2172 d# 12 d# 33 endof + d# 48000 of h# 0000 h# 3072 d# 8 d# 23 endof + ( default ) true abort" Unsupported audio sample rate" + endcase ( reg62val2 reg60val sspareg34val timeout ) + to buf-timeout + 9 lshift h# 183 or h# 34 sspa! h# 60 codec! h# 62 codec! +;
\ Mic bias 2 is for external mic \ I think we don't need to use the audio PLL, because we are using the PMUM M/N divider @@ -213,19 +245,57 @@ \ h# 0000.0000 h# 3c sspa! \ ;
-: init-audio ( -- ) - audio-clock-on - codec-on - setup-sspa-rx - setup-sspa-tx +: dma-alloc ( len -- adr ) " dma-alloc" $call-parent ; +: dma-free ( adr len -- ) " dma-free" $call-parent ; + +: open-in ( -- ) setup-sspa-rx ; +: close-in ( -- ) ; +: open-out ( -- ) setup-sspa-tx ; +: close-out ( -- ) ; +: write-done ( -- ) ; + +: wait-out ( -- ) + buf-timeout 0 do + 1 ms h# a0 adma@ 1 and ?leave + loop + 0 h# a0 adma! ; -: test-setup ( -- ) - h# 2000 0 do - i h# e000.0000 i wa+ w! +: audio-out ( adr len -- actual ) + tuck to out-len to out-adr + make-out-ring + copy-out + start-out-ring + enable-sspa-tx + begin out-len while + copy-out + wait-out + repeat + wait-out + disable-sspa-tx +; +: write ( adr len -- actual ) open-out audio-out ; + +: wait-in ( -- ) + buf-timeout 0 do + 1 ms h# a4 adma@ 1 and ?leave loop + 0 h# a4 adma! +; +: audio-in ( adr len -- actual ) + tuck to in-len to in-adr ( actual ) + make-in-ring ( actual ) + enable-sspa-rx ( actual ) + start-in-ring ( actual ) + begin in-len while ( actual ) + wait-in ( actual ) + copy-in ( actual ) + repeat ( actual ) + disable-sspa-rx ( actual ) ; -: dma h# e000.0000 h# 4000 dma-audio-out ; -: run open-out d# 200 ms close-out ; +: read ( adr len -- actual ) open-in audio-in ; + +: wait-sound ( -- ) ; +: stop-sound ( -- ) ;
0 [if] \ Notes: @@ -246,7 +316,6 @@ : mic+30db ( -- ) h# a00 mic-gain ; : mic+40db ( -- ) h# f00 mic-gain ;
- : mic-bias-off ( -- ) h# 000c h# 3a codec-clr ; : mic-bias-on ( -- ) h# 000c h# 3a codec-set ;
@@ -283,23 +352,22 @@
: headphones-inserted? ( -- flag ) h# 54 codec@ 2 and 0<> ;
-\ 0 is off, 1 is softest non-off, etc -: set-record-gain ( n -- ) - 0 max h# 1f max dup 7 lshift h# 0f9f h# 12 codec-field -; -: attenuation>lr ( n -- true | regval false ) - 0 max ( n' ) - ?dup if ( n ) - h# 1f min - h# 20 swap - +\ The range is from -34.5 db to +12 dB +: gain>lr ( db -- true | regval false ) + 2* 3 / ( steps ) \ Converts -34.5 .. 12 db to -23 .. 8 steps + dup d# -23 < if ( steps ) + drop true + else ( steps ) + 8 swap - ( -steps ) + 0 max ( clipped-steps ) dup 8 lshift or ( regval ) false - else ( ) - true then -; -: >output-volume ( n -- regval mask ) - attenuation>lr if h# 8080 then h# 9f9f +; +\ The range is from -46.5 db to 0 dB +: >output-volume ( db -- regval mask ) + d# 12 + \ Bias to the range used by gain>lr + gain>lr if h# 8080 then h# 9f9f ; : set-speaker-volume ( n -- ) >output-volume 2 codec-field ; : set-headphone-volume ( n -- ) >output-volume 4 codec-field ; @@ -307,19 +375,21 @@ : set-volume ( n -- ) dup set-speaker-volume set-headphone-volume ; -d# 8 constant default-dac-gain - -d# 20 constant default-volume +d# 0 constant default-adc-gain \ 0 dB - range is -16.5 to +30 +d# 0 constant default-dac-gain \ 0 dB - range is -34.5 to +12 +d# 44 constant default-mic-gain \ 44 dB - range is -34.5 to +d# 0 constant default-speaker-volume \ 0 dB - range is -46.5 to 0 +d# 0 constant default-headphone-volume \ 0 dB - range is -46.5 to 0
: select-headphones ( -- ) h# 300 h# 1c codec! ; : select-speakers-ab ( -- ) h# 4800 h# 1c codec! ; \ ClassAB, headphone mixer : select-speakers ( -- ) h# 6800 h# 1c codec! ; \ ClassD, headphone mixer
: set-line-in-gain ( n -- ) - attenuation>lr if h# e000 then h# ff1f h# a codec-field + gain>lr if h# e000 then h# ff1f h# 0a codec-field ; : set-dac-gain ( n -- ) - attenuation>lr if h# e000 then h# ff1f h# c codec-field + gain>lr if h# e000 then h# ff1f h# 0c codec-field ; false value external-mic? : mic-routing ( -- n ) @@ -328,34 +398,65 @@ \ For internal, we send MIC1 to both left and right external-mic? if h# 2040 else h# 2020 then ; -: set-mic-gain ( n -- ) - attenuation>lr if ( ) \ Mute +: set-mic-boost ( db -- db' ) + dup d# 26 > if mic+40db d# 40 - exit then + dup d# 16 > if mic+30db d# 30 - exit then + dup d# 06 > if mic+20db d# 20 - exit then + mic+0db +; +: set-mic-gain ( db -- ) + set-mic-boost ( db' ) + gain>lr if ( ) \ Mute \ Turn everything off + mic-bias-off ( ) 0 h# 6060 h# e0e0 ( gain adc-mute mic-output-mute ) else ( gain ) + mic-bias-on ( gain ) \ Mic routing to ADC depends on internal or external mic - \ We route the mic only to the headphone output - mic-routing h# 6060 ( gain adc-mute mic-output-mute ) + mic-routing ( gain adc-mute ) + \ To avoid feedback, we do not feedthrough the mic + h# e0e0 ( gain adc-mute mic-output-mute ) then ( gain adc-mute mic-output-mute ) h# e0e0 h# 10 codec-field ( gain adc-mute ) h# 6060 h# 14 codec-field ( gain ) - h# 1f1f h# 0c codec-field + h# 1f1f h# 0e codec-field +; +: set-adc-gain ( db -- ) \ Range is -16.5 dB to +30 dB + d# 18 - ( db' ) + gain>lr if 0 then ( gain ) + h# f9f h# 12 codec-field + h# 60 h# 12 codec-set \ Enable ADC zero-cross detectors +; + +\ This is called from "record" in "mic-test" in "selftest" +: set-record-gain ( db -- ) + \ translate value from ac97 selftest code into our default value + dup h# 808 = if ( db ) + drop default-adc-gain ( db' ) + d# 40 set-mic-gain ( db ) + then ( db ) + set-adc-gain ;
: stereo ; : mono ;
-d# 48000 value sample-rate : open ( -- flag ) - init-audio + audio-clock-on + codec-on headphones-inserted? if select-headphones else select-speakers then - default-volume set-volume + default-speaker-volume set-speaker-volume + default-headphone-volume set-headphone-volume default-dac-gain set-dac-gain + default-mic-gain set-mic-gain + default-adc-gain set-adc-gain + d# 48000 set-sample-rate true ; : close ( -- ) ;
fload ${BP}/forth/lib/isin.fth fload ${BP}/forth/lib/tones.fth +fload ${BP}/dev/geode/ac97/selftest.fth
end-package
Modified: cpu/x86/adpcm.fth ============================================================================== --- cpu/x86/adpcm.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/x86/adpcm.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -55,6 +55,7 @@ swap in-skip + swap ;
+[ifdef] 386-assembler code adpcm-decode-sample ( in out sample# -- in' out' ) \ Get the delta value eax pop ( in out ) @@ -106,6 +107,34 @@ d# 88 # eax cmp > if d# 88 # eax mov then eax 'user index mov \ Update index c; +[then] +[ifndef] adpcm-decode-sample +: adpcm-decode-sample ( in out sample# -- in' out' ) + 7 and if ( in out ) + in-val 4 rshift ( in out delta ) + else ( in out ) + over l@ ( in out delta ) + rot la1+ -rot ( in' out delta ) + then ( in out delta ) + dup to in-val ( in out delta ) + h# f and >r ( in out r: delta' ) + + \ Compute difference and new predicated value + \ Computes 'vpdiff = (delta+0.5)*step/4', but see comment in adpcm-coder. + 'stepsize-table index la+ l@ ( in out step r: delta ) + dup 3 rshift ( in out step vpdiff r: delta ) + r@ 4 and if over + then ( in out step vpdiff' r: delta ) + r@ 2 and if over /w* + then ( in out step vpdiff' r: delta ) + r@ 1 and if over /l* + then ( in out step vpdiff' r: delta ) + nip ( in out vpdiff r: delta ) + + r@ 8 and if val-pred + else val-pred swap - then ( in out vp r: delta ) + d# 32767 min d# -32768 max dup to val-pred ( in out vp r: delta ) + over w! ( in out r: delta ) + out-skip + ( in out' r: delta ) + 'index-table r> la+ l@ index + 0 max d# 88 min to index ( in out ) +; +[then]
: adpcm-decode-ch ( in out #sample -- ) 0 ?do
Modified: cpu/x86/pc/olpc/gridmap.fth ============================================================================== --- cpu/x86/pc/olpc/gridmap.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/x86/pc/olpc/gridmap.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -60,5 +60,3 @@ [then]
: show-color ( eblock# color32 -- ) map-color show-state ; - -dev screen : erase-screen erase-screen ; dend
Modified: cpu/x86/pc/olpc/via/banner.fth ============================================================================== --- cpu/x86/pc/olpc/via/banner.fth Wed Nov 17 01:21:03 2010 (r2025) +++ cpu/x86/pc/olpc/via/banner.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -97,11 +97,11 @@
: ofw-model$ ( -- adr len ) " /openprom" find-package drop ( phandle ) - " model" rot get-package-property if - " ??? ????? ???" - else - decode-string - then + " model" rot get-package-property if ( ) + " ??? ????? ???" ( adr len ) + else ( adr len ) + decode-string 2nip ( adr len' ) + then ( adr len ) ; : ofw-version$ ( -- adr len ) ofw-model$ drop 6 + 7 -trailing
Modified: dev/olpc/keyboard/selftest.fth ============================================================================== --- dev/olpc/keyboard/selftest.fth Wed Nov 17 01:21:03 2010 (r2025) +++ dev/olpc/keyboard/selftest.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -4,7 +4,7 @@ \needs final-test? 0 value final-test? \needs smt-test? 0 value smt-test?
-dev /8042/keyboard +dev /keyboard hex
\ This is 1 for the original rubber keyboard and 2 for the mechanical keyboard
Modified: dev/olpc/mmp2camera/loadpkg.fth ============================================================================== --- dev/olpc/mmp2camera/loadpkg.fth Wed Nov 17 01:21:03 2010 (r2025) +++ dev/olpc/mmp2camera/loadpkg.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -22,7 +22,6 @@ ; [then]
- fload ${BP}/cpu/arm/olpc/1.75/smbus.fth fload ${BP}/dev/olpc/mmp2camera/platform.fth fload ${BP}/dev/olpc/mmp2camera/ov.fth fload ${BP}/dev/olpc/mmp2camera/ccic.fth
Modified: dev/olpc/touchpad/touchpad.fth ============================================================================== --- dev/olpc/touchpad/touchpad.fth Wed Nov 17 01:21:03 2010 (r2025) +++ dev/olpc/touchpad/touchpad.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -1,6 +1,6 @@ \ See license at end of file \ Add this code to the existing mouse driver -dev /pci/isa/8042@i60/mouse +dev /mouse
variable 'get-data 'get-data off variable 'get-data? 'get-data? off
Modified: dev/video/common/rectangle16.fth ============================================================================== --- dev/video/common/rectangle16.fth Wed Nov 17 01:21:03 2010 (r2025) +++ dev/video/common/rectangle16.fth Thu Nov 18 01:52:11 2010 (r2026) @@ -247,6 +247,8 @@ 2drop then ; +\ This creates a device method from a termemu method +: erase-screen ( -- ) erase-screen ;
\ LICENSE_BEGIN \ Copyright (c) 2006 FirmWorks