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

svn at openfirmware.info svn at openfirmware.info
Fri Jan 8 03:23:07 CET 2010


Author: wmb
Date: 2010-01-08 03:23:07 +0100 (Fri, 08 Jan 2010)
New Revision: 1649

Added:
   dev/hdaudio/config.fth
   dev/hdaudio/cx2058x-nodes.fth
   dev/hdaudio/start-cx2058x.fth
Modified:
   cpu/x86/pc/olpc/via/addrs.fth
   cpu/x86/pc/olpc/via/romreset.bth
   dev/hdaudio/conexant.fth
Log:
OLPC trac 9970 - perform CODEC setup in early startup to ensure that thermal
and overcurrent protection is on after resume.


Modified: cpu/x86/pc/olpc/via/addrs.fth
===================================================================
--- cpu/x86/pc/olpc/via/addrs.fth	2010-01-07 21:12:26 UTC (rev 1648)
+++ cpu/x86/pc/olpc/via/addrs.fth	2010-01-08 02:23:07 UTC (rev 1649)
@@ -49,6 +49,8 @@
 h# fd00.0000 constant fw-map-base
 h# ffc0.0000 constant fw-map-limit
 
+h# 8fff.0000 constant hdac-pci-base  \ Temporary for use during early startup
+
 h# d000.0000 constant fb-pci-base
 h# f000.0000 constant gfx-pci-base
 \ h# fe01.a000 constant ohci-pci-base

Modified: cpu/x86/pc/olpc/via/romreset.bth
===================================================================
--- cpu/x86/pc/olpc/via/romreset.bth	2010-01-07 21:12:26 UTC (rev 1648)
+++ cpu/x86/pc/olpc/via/romreset.bth	2010-01-08 02:23:07 UTC (rev 1649)
@@ -86,6 +86,8 @@
 fload ${BP}/cpu/x86/pc/olpc/via/startcominit.fth   \ cominit subroutine
 [then]
 
+fload ${BP}/dev/hdaudio/start-cx2058x.fth
+
 label startup
    h# 10 port80
 
@@ -226,6 +228,8 @@
    \ Setup a small stack for subroutine calls
    h# 10.0000 # esp mov
 
+   init-codec #) call
+
    long-offsets on
    acpi-io-base 4 + port-rw           \ Get APCI Status register
    ax bx mov

Modified: dev/hdaudio/conexant.fth
===================================================================
--- dev/hdaudio/conexant.fth	2010-01-07 21:12:26 UTC (rev 1648)
+++ dev/hdaudio/conexant.fth	2010-01-08 02:23:07 UTC (rev 1649)
@@ -13,22 +13,7 @@
 
 : set-node  ( node-id -- )  to node  ;
 
-: afg    ( -- )      1 set-node  ;  \ Audio Function Group
-: dac1   ( -- )  h# 10 set-node  ;
-: adc1   ( -- )  h# 14 set-node  ;
-: mux    ( -- )  h# 17 set-node  ;      \ mux between port b and port c
-: mux2   ( -- )  h# 18 set-node  ;
-: porta  ( -- )  h# 19 set-node  ;
-: portb  ( -- )  h# 1a set-node  ;    \ Port B - OLPC external mic
-: portc  ( -- )  h# 1b set-node  ;    \ Port C - OLPC internal mic
-: portd  ( -- )  h# 1c set-node  ;    \ Port D - OLPC unused
-: porte  ( -- )  h# 1d set-node  ;    \ Port E - OLPC unused
-: portf  ( -- )  h# 1e set-node  ;    \ Port F - OLPC DC input
-: portg  ( -- )  h# 1f set-node  ;    \ Port G - speaker driver
-: porth  ( -- )  h# 20 set-node  ;    \ Port H - S/PDIF out
-: porti  ( -- )  h# 22 set-node  ;    \ Port I - S/PDIF out
-: portj  ( -- )  h# 23 set-node  ;    \ Digital mic
-: vendor ( -- )  h# 25 set-node  ;    \ Vendor-specific controls
+fload ${BP}/dev/hdaudio/cx2058x-nodes.fth
 
 : volume-on-all  ( -- )
    adc1   h# 36006 cmd  h# 35006 cmd  \ Left gain/mute, right gain/mute
@@ -68,23 +53,10 @@
 ;
 : cx2058x-disable-playback  ( -- )  ;
 
-: 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-default  ( -- u )  f1c00 cmd?  ;
 
-: config(   ( node -- null-config-default )   0  ;
+[ifdef] notdef  \ Unnecessary because we do it in early startup assembly language
+fload ${BP}/dev/hdaudio/config.fth    \ Names for configuration settings
 
 : )config  ( config-default -- )
    \ set the high 24 bits of the config-default value
@@ -94,17 +66,14 @@
    8 rshift      h# ff and  71f00 or  cmd
 ;
 
-
-: config-default  ( -- u )  f1c00 cmd?  ;
-
 : setup-config-default  ( -- )
    porta  config(  1/8" green left hp-out jack     )config
    portb  config(  1/8" pink left mic-in jack      )config
-   portc  config(  builtin front mic-in            )config
+   portc  config(  builtin internal front mic-in   )config
    portd  config(  unused line-out                 )config
    porte  config(  unused line-out                 )config
    portf  config(  1/8" pink left line-in jack     )config
-   portg  config(  builtin front speaker           )config
+   portg  config(  builtin internal front speaker  )config
    porth  config(  unused spdiff-out               )config
    porti  config(  unused spdiff-out               )config
    portj  config(  unused mic-in                   )config
@@ -113,11 +82,14 @@
 : vendor-settings  ( -- )
    vendor
    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# 34001 cmd \ speaker power 1 dB gain
+   h# 34003 cmd \ speaker power -2 dB gain (1.26W @ 4 ohms)
+   h# 38021 cmd \ over-current / short-circuit protection, 2.6A threshold
+\   h# 39019 cmd \ temperature protection at 130C
+   h# 390c5 cmd \ temperature protection at 79.5C
    h# 42011 cmd \ over-temperature shutdown of class-D
 ;
+[then]
 
 \ check (expect) that cmd yields value
 : check-cmd  ( value cmd -- )
@@ -154,8 +126,8 @@
    ['] adc1 to with-adc
    power-on-all
    volume-on-all
-   vendor-settings
-   setup-config-default
+\   vendor-settings
+\   setup-config-default
 ;
 
 : cx2058x-close  ( -- )  afg power-off  ;  \ Power off entire Audio Function Group

Added: dev/hdaudio/config.fth
===================================================================
--- dev/hdaudio/config.fth	                        (rev 0)
+++ dev/hdaudio/config.fth	2010-01-08 02:23:07 UTC (rev 1649)
@@ -0,0 +1,44 @@
+purpose: Names for HD Audio Configuration Default values
+\ See license at end of file
+
+: config(   ( -- null-config-default )   0  ;
+
+: 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  ;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 Luke Gorrie <luke at bup.co.nz>
+\ 
+\ 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: dev/hdaudio/cx2058x-nodes.fth
===================================================================
--- dev/hdaudio/cx2058x-nodes.fth	                        (rev 0)
+++ dev/hdaudio/cx2058x-nodes.fth	2010-01-08 02:23:07 UTC (rev 1649)
@@ -0,0 +1,43 @@
+purpose: Node names for Conexant CX2058x HD Audio CODEC
+\ See license at end of file
+
+: afg    ( -- )      1 set-node  ;  \ Audio Function Group
+: dac1   ( -- )  h# 10 set-node  ;
+: adc1   ( -- )  h# 14 set-node  ;
+: mux    ( -- )  h# 17 set-node  ;      \ mux between port b and port c
+: mux2   ( -- )  h# 18 set-node  ;
+: porta  ( -- )  h# 19 set-node  ;
+: portb  ( -- )  h# 1a set-node  ;    \ Port B - OLPC external mic
+: portc  ( -- )  h# 1b set-node  ;    \ Port C - OLPC internal mic
+: portd  ( -- )  h# 1c set-node  ;    \ Port D - OLPC unused
+: porte  ( -- )  h# 1d set-node  ;    \ Port E - OLPC unused
+: portf  ( -- )  h# 1e set-node  ;    \ Port F - OLPC DC input
+: portg  ( -- )  h# 1f set-node  ;    \ Port G - speaker driver
+: porth  ( -- )  h# 20 set-node  ;    \ Port H - S/PDIF out
+: porti  ( -- )  h# 22 set-node  ;    \ Port I - S/PDIF out
+: portj  ( -- )  h# 23 set-node  ;    \ Digital mic
+: vendor ( -- )  h# 25 set-node  ;    \ Vendor-specific controls
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 Luke Gorrie <luke at bup.co.nz>
+\ 
+\ 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: dev/hdaudio/start-cx2058x.fth
===================================================================
--- dev/hdaudio/start-cx2058x.fth	                        (rev 0)
+++ dev/hdaudio/start-cx2058x.fth	2010-01-08 02:23:07 UTC (rev 1649)
@@ -0,0 +1,241 @@
+purpose: Early-startup code for Conexant CX2058x codec
+\ See license at end of file
+
+\ This runs at early startup time when the system is still running assembly
+\ language.  It is used both for cold boot and for resume from S3.
+\ It compiles a verb table and blasts it out to the codec as quickly as possible.
+\ The reason we need to do this is to ensure that the critical settings for
+\ thermal and overcurrent protection in the Vendor node are always applied,
+\ especially in the resume-from-S3 case where we have no opportunity to run
+\ Forth code.  Secondarily, we also get a chance to set the Configuration
+\ Default registers.
+
+\ Put the words for compiling the verb table in the transient dictionary so
+\ the don't take up space in the ROM image
+transient
+
+0 value codec
+0 value node
+
+: set-node  ( node-id -- )  to node  ;
+
+fload ${BP}/dev/hdaudio/cx2058x-nodes.fth  \ Node names
+
+fload ${BP}/dev/hdaudio/config.fth    \ Names for configuration settings
+
+0 value #verbs
+
+: place-verb  ( verb+data -- )
+   node d# 20 lshift or
+   codec d# 28 lshift or
+   ,
+   #verbs 1+ to #verbs
+;
+: config-verb  ( data-byte verb-code -- )
+   8 lshift  or  place-verb
+;
+: )config  ( value -- )
+   h# f0 or                   ( value )  \ Null association
+   lbsplit  swap 2swap swap   ( high hmid lmid low )
+   h# 71c config-verb
+   h# 71d config-verb
+   h# 71e config-verb
+   h# 71f config-verb
+;
+
+: start-verb-table  ( -- )
+   " 0 to #verbs  label verb-table" evaluate
+;
+: end-verb-table  ( -- )  ;
+
+h# 100000 constant corb   \ Physical address of DMA command buffer
+h# 101000 constant rirb   \ Physical address of DMA response buffer
+
+resident
+
+hex
+start-verb-table
+   porta  f0700 place-verb  \ This is sacrificial, in case of problems with the first command
+
+   porta  config(  1/8" green left hp-out jack     )config
+   porta  config(  1/8" green left hp-out jack     )config
+   portb  config(  1/8" pink left mic-in jack      )config
+   portc  config(  builtin internal front mic-in   )config
+   portd  config(  unused line-out                 )config
+   porte  config(  unused line-out                 )config
+   portf  config(  1/8" pink left line-in jack     )config
+   portg  config(  builtin internal front speaker  )config
+   porth  config(  unused spdiff-out               )config
+   porti  config(  unused spdiff-out               )config
+   portj  config(  unused mic-in                   )config
+
+   vendor  \ Vendor node
+
+   \ Codec registers
+   21000 place-verb      \ Undocumented register
+   22000 place-verb      \ Undocumented register
+   23000 place-verb      \ Undocumented register
+   24000 place-verb      \ Undocumented register
+   25000 place-verb      \ Undocumented register
+   26000 place-verb      \ Undocumented register
+   27000 place-verb      \ Undocumented register
+   28000 place-verb      \ Undocumented register
+   290a8 place-verb      \ high-pass filter, semi-manual mode, 600Hz cutoff
+   2A000 place-verb      \ low-pass filter (for subwoofers) off
+   2B002 place-verb      \ Undocumented register
+   2C020 place-verb      \ Undocumented register
+   2D000 place-verb      \ Undocumented register
+   2E000 place-verb      \ Undocumented register
+   2F800 place-verb      \ Undocumented register
+   \ Analog registers
+   31000 place-verb      \ Undocumented register
+   32000 place-verb      \ Undocumented register
+   33000 place-verb      \ Undocumented register
+   34003 place-verb \ 4 ohm/1.59W  \ Comment disagrees with documentation - Class-DSpeakerPower.pdf says value 003 is 4 ohm/1.26W
+   35000 place-verb      \ Undocumented register
+   3600A place-verb      \ Undocumented register
+   37000 place-verb      \ Undocumented register
+   38021 place-verb      \ over-current / short-circuit protection, 2.6A threshold
+   390C5 place-verb      \ temperature protection at 79.5C
+   3A000 place-verb      \ Undocumented register
+   \ Digital registers
+   41541 place-verb      \ Undocumented register
+   42011 place-verb      \ over-temperature shutdown of class-D amplifier
+   43000 place-verb      \ This documented as a status register and thus is presumably read-only.  Why write to it?
+   44000 place-verb      \ Undocumented register
+   45600 place-verb      \ Undocumented register
+   4600C place-verb      \ Undocumented register
+   4701F place-verb      \ Undocumented register
+   48004 place-verb      \ Undocumented register
+   49040 place-verb      \ Undocumented register
+   4C000 place-verb      \ Undocumented register
+
+   afg  \ Audio Function Group node
+
+   71C01 place-verb      \ Undocumented register
+   71D00 place-verb      \ SPDIF OFF BUT Int-Mic on        \ Undocumented register
+   71E00 place-verb      \ Undocumented register
+   71F00 place-verb      \ disable software GSMark protection
+   71F00 place-verb      \ disable software GSMark protection - repeat in case of end condition issues
+end-verb-table
+
+\ Subroutine to turn on the HD Audio controller, push the verb table to the codec,
+\ then turn things back off.
+
+label init-codec
+   hdac-pci-base h# a010 config-wl  \ Set PCI base address for HD Audio
+   6 h# a004 config-ww              \ Enable it for memory space and bus mastering
+
+   h# 01 #  hdac-pci-base h# 08 + #)  mov  \ Release controller reset
+
+   h# 1000 # cx mov    \ Maximum number of wait loop iterations
+   begin
+      h# 80 # al in    \ ~1us delay
+      cx dec  0<>  if  \ Not timeout
+         hdac-pci-base h# 08 + #)  ax  mov  \ wait for controller to come out of reset
+         1 # al test
+      else
+         cx inc        \ Force exit from loop
+      then
+   0<> until
+
+   d# 350 wait-us   \ Wait for Codec to wake up (250 needed; extra for good measure)
+
+   h# 00 #  hdac-pci-base h# 4c + #)  byte  mov  \ CORB DMA off
+
+   h# 1000 # cx mov    \ Maximum number of wait loop iterations
+   begin
+      h# 80 # al in   \ ~1us delay
+      cx dec  0<>  if  \ Not timeout
+         hdac-pci-base h# 4c + #)  al  mov  \ wait for CORB DMA off
+         2 # al test
+      then
+   0= until
+
+       corb #  hdac-pci-base h# 40 + #)       mov  \ CORB lower base address
+          0 #  hdac-pci-base h# 44 + #)       mov  \ CORB upper base address
+op:       0 #  hdac-pci-base h# 48 + #)       mov  \ CORB write pointer
+op: h# 8000 #  hdac-pci-base h# 4a + #)       mov  \ CORB read pointer reset
+          2 #  hdac-pci-base h# 4e + #)  byte mov  \ CORB size - 256 entries
+
+          2 #  hdac-pci-base h# 4c + #)  byte mov  \ CORB DMA on
+
+   h# 00 #  hdac-pci-base h# 5c + #)  byte  mov  \ RIRB DMA off
+
+   h# 1000 # cx mov    \ Maximum number of wait loop iterations
+   begin
+      h# 80 # al in   \ ~1us delay
+      cx dec  0<>  if  \ Not timeout
+         hdac-pci-base h# 5c + #)  al  mov  \ wait for RIRB DMA off
+         2 # al test
+      then
+   0= until
+
+       rirb #  hdac-pci-base h# 50 + #)       mov  \ RIRB lower base address
+          0 #  hdac-pci-base h# 54 + #)       mov  \ RIRB upper base address
+op: h# 8000 #  hdac-pci-base h# 58 + #)       mov  \ RIRB write pointer reset
+          2 #  hdac-pci-base h# 5e + #)  byte mov  \ RIRB size - 256 entries
+
+          2 #  hdac-pci-base h# 5c + #)  byte mov  \ RIRB DMA on
+
+   \ Copy the verb table to the CORB DMA area
+   #verbs # cx mov
+   verb-table # si mov
+   corb # di mov
+   rep movs
+
+   op:  #verbs #  hdac-pci-base h# 48 + #)  mov   \ Hand off the verbs by setting the CORB write pointer
+
+   h# 1000 # cx mov    \ Maximum number of wait loop iterations
+   begin
+      h# 80 # al in   \ ~1us delay
+      cx dec  0<>  if  \ Not timeout
+         op: hdac-pci-base h# 4a + #)  ax  mov     \ Read CORB read pointer to catch up with write pointer
+         op: #verbs #  ax  cmp                     \ Wait for it to catch up
+      then
+   0= until
+
+   h# 1000 # cx mov
+   begin
+      h# 80 # al in   \ ~1us delay
+      cx dec  0<>  if  \ Not timeout
+         op: hdac-pci-base h# 58 + #)  ax  mov     \ Read RIRB write pointer
+         op: #verbs 1- #  ax  cmp                  \ Wait for it to catch up
+      then
+   0= until
+
+   d# 100 wait-us  \ Just in case
+
+   h# 00 #  hdac-pci-base h# 4c + #)  byte  mov    \ CORB DMA off
+   h# 00 #  hdac-pci-base h# 5c + #)  byte  mov    \ RIRB DMA off
+   h# 00 #  hdac-pci-base h# 08 + #)  mov          \ Reset controller
+
+   0 h# a004 config-ww              \ Disable memory space and bus mastering
+
+   ret
+end-code
+
+
+\ 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




More information about the openfirmware mailing list