[openfirmware] r1251 - cpu/x86/pc/olpc/via dev/hdaudio

svn at openfirmware.info svn at openfirmware.info
Fri Jul 24 21:38:21 CEST 2009


Author: wmb
Date: 2009-07-24 21:38:21 +0200 (Fri, 24 Jul 2009)
New Revision: 1251

Added:
   cpu/x86/pc/olpc/via/sound.fth
Modified:
   cpu/x86/pc/olpc/via/fw.bth
   dev/hdaudio/conexant.fth
   dev/hdaudio/core.fth
Log:
Via audio - added completion alarm to stop startup sound.




Modified: cpu/x86/pc/olpc/via/fw.bth
===================================================================
--- cpu/x86/pc/olpc/via/fw.bth	2009-07-24 19:36:19 UTC (rev 1250)
+++ cpu/x86/pc/olpc/via/fw.bth	2009-07-24 19:38:21 UTC (rev 1251)
@@ -347,6 +347,7 @@
 
 fload ${BP}/cpu/x86/pc/olpc/setwp.fth
 fload ${BP}/cpu/x86/pc/olpc/sound.fth
+fload ${BP}/cpu/x86/pc/olpc/via/sound.fth
 fload ${BP}/cpu/x86/pc/olpc/security.fth
 fload ${BP}/ofw/gui/ofpong.fth
 fload ${BP}/cpu/x86/pc/olpc/life.fth

Added: cpu/x86/pc/olpc/via/sound.fth
===================================================================
--- cpu/x86/pc/olpc/via/sound.fth	                        (rev 0)
+++ cpu/x86/pc/olpc/via/sound.fth	2009-07-24 19:38:21 UTC (rev 1251)
@@ -0,0 +1,8 @@
+: audio-quiet  ( -- )
+   [ ' go-hook behavior compile, ]    \ Chain to old behavior
+   audio-ih  if
+      audio-ih close-dev
+      0 to audio-ih
+   then
+;
+' audio-quiet to go-hook

Modified: dev/hdaudio/conexant.fth
===================================================================
--- dev/hdaudio/conexant.fth	2009-07-24 19:36:19 UTC (rev 1250)
+++ dev/hdaudio/conexant.fth	2009-07-24 19:38:21 UTC (rev 1251)
@@ -20,17 +20,6 @@
    h# 10 to node  h# 3a03e cmd  h# 3903e cmd
 ;
 
-: cx2058x-open  ( -- )
-   h# 10 to dac
-   h# 14 to adc
-   power-on-all
-   volume-on-all
-;
-
-: cx2058x-close  ( -- )
-   1 to node ( function group) power-off
-;
-
 h# 1a value mic-in   \ Port B
 h# 1b value mic      \ Port C
 h# 17 value mux      \ mux between the two
@@ -54,13 +43,109 @@
 ;
 : cx2058x-disable-playback  ( -- )  ;
 
-: cx2058x-init ( -- )
+: 1/8"        ( u -- u )  h#    10000 or  ;
+: green       ( u -- u )  h#     4000 or  ;
+: pink        ( u -- u )  h#     9000 or  ;
+: hp-out      ( u -- u )  h#   200000 or  ;
+: spdiff-out  ( u -- u )  h#   400000 or  ;
+: mic-in      ( u -- u )  h#   a00000 or  ;
+: line-in     ( u -- u )  h#   800000 or  ;
+: line-out    ( u -- u )                  ;
+: speaker     ( u -- u )  h#   100000 or  ;
+: left        ( u -- u )  h#  3000000 or  ;
+: front       ( u -- u )  h#  2000000 or  ;
+: internal    ( u -- u )  h# 10000000 or  ;
+: jack        ( u -- u )  h# 00000000 or  ;
+: unused      ( u -- u )  h# 40000000 or  ;
+: builtin     ( u -- u )  h# 80000000 or  ;
+
+: config(   ( node -- null-config-default )  to node  0  ;
+
+: )config  ( config-default -- )
+   \ set the high 24 bits of the config-default value
+   \ the low 8 bits (default association, sequence) are preserved
+   8 rshift  dup h# ff and  71d00 or  cmd
+   8 rshift  dup h# ff and  71e00 or  cmd
+   8 rshift      h# ff and  71f00 or  cmd
+;
+
+: port-a  ( -- u )  19 config(  1/8" green left hp-out jack     )config  ;
+: port-b  ( -- u )  1a config(  1/8" pink left mic-in jack      )config  ;
+: port-c  ( -- u )  1b config(  builtin front mic-in            )config  ;
+: port-d  ( -- u )  1c config(  unused line-out                 )config  ;
+: port-e  ( -- u )  1d config(  unused line-out                 )config  ;
+: port-f  ( -- u )  1e config(  1/8" pink left line-in jack     )config  ;
+: port-g  ( -- u )  1f config(  builtin front speaker           )config  ;
+: port-h  ( -- u )  20 config(  unused spdiff-out               )config  ;
+: port-i  ( -- u )  22 config(  unused spdiff-out               )config  ;
+: port-j  ( -- u )  23 config(  unused mic-in                   )config  ;
+
+: config-default  ( -- u )  f1c00 cmd?  ;
+
+: setup-config-default  ( -- )
+   port-a port-b port-c port-d port-e port-f port-g port-h port-i port-j
+;
+
+: vendor-settings  ( -- )
+   h# 25 to node
+   h# 290a8 cmd \ high-pass filter, semi-manual mode, 600Hz cutoff
+   h# 34001 cmd \ speaker power 1 dB gain
+   h# 38001 cmd \ over-current / short-circuit protection, 2.6A threshold
+   h# 39019 cmd \ temperature protection at 130C
+   h# 42011 cmd \ over-temperature shutdown of class-D
+;
+
+\ check (expect) that cmd yields value
+: check-cmd  ( value cmd -- )
+   dup . ." cmd? => "
+   cmd?                                        ( value actual )
+   push-hex  dup 0 <# # # # #> type pop-base   ( value actual )
+   over = if                                   ( value )
+      ."  (ok)" drop
+   else
+      ."  but expected " .
+   then
+   cr
+;
+
+: over-temperature?  ( -- ? )  h# c3000 cmd? 4 and 0<>  ;
+
+\ Test word to make sure the right settings are configured
+: .vendor-settings  ( -- )
+   h# 25 to node
+   h# 0a8 h# a9000 check-cmd
+   h# 001 h# b4000 check-cmd
+   h# 001 h# b8000 check-cmd
+   h# 019 h# b9000 check-cmd
+   h# 011 h# c2000 check-cmd
+   over-temperature? if
+      ." over temperature!"
+   else
+      ." temperature is within bounds
+   then
+;
+
+: cx2058x-open  ( -- )
+   h# 10 to dac
+   h# 14 to adc
+   power-on-all
+   volume-on-all
+   vendor-settings
+   setup-config-default
+;
+
+: cx2058x-close  ( -- )
+   1 to node ( function group) power-off
+;
+
+: cx2058x-init  ( -- )
    ['] cx2058x-open  to open-codec
    ['] cx2058x-close to close-codec
    ['] cx2058x-enable-recording  to enable-codec-recording
    ['] cx2058x-disable-recording to disable-codec-recording
    ['] cx2058x-enable-playback   to enable-codec-playback
    ['] cx2058x-enable-playback   to disable-codec-playback
+\   setup-config-default
 ;
 
 \ LICENSE_BEGIN

Modified: dev/hdaudio/core.fth
===================================================================
--- dev/hdaudio/core.fth	2009-07-24 19:36:19 UTC (rev 1250)
+++ dev/hdaudio/core.fth	2009-07-24 19:38:21 UTC (rev 1251)
@@ -108,7 +108,7 @@
 
 \ Stream descriptor register interface.
 \ There are multiple stream descriptors, each with their own register set.
-0 constant sd#
+0 instance value sd#
 : sd+  ( offset -- adr )  sd# h# 20 * + au +  ;
 
 : sdctl    h# 80 sd+  ;
@@ -214,9 +214,17 @@
 : deassert-stream-reset  ( -- )  0 sdctl rb!  begin  sdctl rb@ 1 and 0 =  until  ;
 
 : reset-stream  ( -- )  assert-stream-reset deassert-stream-reset  ;
-: stop-stream   ( -- )  0 sdctl rb! begin  sdctl rb@ 2 and  0=  until  ;
 : start-stream  ( -- )  2 sdctl rb! begin  sdctl rb@ 2 and  0<> until  ;
+: stop-stream   ( -- )
+   0 sdctl rb! begin  sdctl rb@ 2 and  0=  until
+   4 sdsts rb! \ clear completion flag
+;
 
+defer playback-alarm
+
+: install-playback-alarm     ( -- )  ['] playback-alarm d# 20 alarm  ;
+: uninstall-playback-alarm   ( -- )  ['] playback-alarm d#  0 alarm  ;
+
 \ \ Device open and close
 
 : restart-controller  ( -- )  reset  start  1 ms ( 250us wait required )  ;
@@ -225,7 +233,7 @@
 : close-controller    ( -- )  reset  unmap-regs  ;
 
 : open   ( -- flag )  init-controller  init-codec  true  ;
-: close  ( -- )       close-codec  close-controller  ;
+: close  ( -- )       uninstall-playback-alarm  close-codec  close-controller  ;
 
 d# 48.000 value sample-rate
 
@@ -233,7 +241,7 @@
 
 : set-sample-rate  ( Hz -- )
    dup to sample-rate  ( Hz )
-   dup low-rate? if    ( Hz )
+   dup low-rate?  if   ( Hz )
       48kHz  d# 48.000 swap / to scale-factor
    else                ( Hz )
       1 to scale-factor
@@ -267,7 +275,7 @@
 
 0 value pad-buffer
 0 value pad-buffer-phys
-d# 2048 value /pad-buffer
+d# 8092 value /pad-buffer
 
 : alloc-pad-buffer  ( -- )
    /pad-buffer dma-alloc to pad-buffer
@@ -329,7 +337,7 @@
    /sound-buffer /pad-buffer + sdcbl rl! \ bytes of stream data
    h# 440000 sdctl rl!            \ stream 4
    1 sdlvi rw!                    \ two buffers
-   1c sdsts c!                    \ clear status flags
+   1c sdsts rb!                   \ clear status flags
    bdl-phys sdbdpl rl!
    0        sdbdpu rl!
    stream-format sdfmt rw!
@@ -401,7 +409,7 @@
 : open-out  ( -- )
    4 to sd#
    48kHz
-   upsampling? if  scale-factor upsample  then  ( adr len )
+   upsampling?  if  scale-factor upsample  then  ( adr len )
 ;
 
 : audio-out  ( adr len -- actual ) 
@@ -415,7 +423,7 @@
 
 : release-sound-buffer  ( -- )
    sound-buffer sound-buffer-phys /sound-buffer dma-map-out
-   upsampling? if  sound-buffer /sound-buffer dma-free  then
+   upsampling?  if  sound-buffer /sound-buffer dma-free  then
 ;
 
 : write-done  ( -- )
@@ -426,13 +434,21 @@
 ;
 
 : write  ( adr len -- actual )
-   open-out  audio-out
+   open-out  audio-out  install-playback-alarm
 ;
 
-\ XXX remove when write is fixed to set up a completion handler
-: wait-sound  ( -- )  write-done  ;
-    
+\ Alarm handle to stop the stream when the content has been played.
+: playback-completed-alarm  ( -- )
+   sd#                                 ( sd# )
+   4 to sd#                            ( sd# )
+   stream-done?  if  write-done  then  ( sd# )
+   to sd#                              ( )
+;
 
+' playback-completed-alarm is playback-alarm
+
+: wait-sound  ( -- )  ; \ sound stops with asynchronous alarm handler
+
 : set-volume  ( dB -- )  dac to node  step# output-gain  ;
 
 \ \\ Recording
@@ -484,6 +500,7 @@
 : in-gain-steps  ( -- n )  in-amp-caps  8 rshift h# 7f and  1+  ;
 : set-record-gain  ( dB -- )  drop ( hardcoded for now ) adc to node  h# 40 input-gain  ;
 
+
 \ LICENSE_BEGIN
 \ Copyright (c) 2009 Luke Gorrie <luke at bup.co.nz>
 \ 




More information about the openfirmware mailing list