Author: wmb Date: 2009-11-09 21:04:45 +0000 (Mon, 09 Nov 2009) New Revision: 1465
Added: cpu/x86/pc/olpc/via/clkgen.fth Modified: cpu/x86/pc/olpc/via/devices.fth cpu/x86/pc/olpc/via/smbus.fth Log: OLPC trac 9481 - turn off unused clock generator outputs to save power. New commands "enable-unused-clocks" and "disable-unused-clocks" for power testing.
Added: cpu/x86/pc/olpc/via/clkgen.fth =================================================================== --- cpu/x86/pc/olpc/via/clkgen.fth (rev 0) +++ cpu/x86/pc/olpc/via/clkgen.fth 2009-11-09 21:04:45 UTC (rev 1465) @@ -0,0 +1,56 @@ +\ See license at end of file +purpose: Driver for the clock generator chip connected to the SMBus + +h# d2 2/ constant clkgen-smbus-id +h# 15 constant /clkgen-buf +d# 32 buffer: clkgen-buf \ Extra large in case the clock generator changes + +: clkgen-read ( -- ) + enable-smbus ( ) + clkgen-smbus-id smbus-acquire ( ) + clkgen-buf /clkgen-buf 0 smbus-read ( #read ) + /clkgen-buf <> abort" clkgen-read: smbus-read returned wrong byte count" + smbus-release ( ) +; + +: clkgen-b@ ( reg# -- value ) clkgen-read clkgen-buf + c@ ; + +: clkgen-b! ( value reg# -- ) + enable-smbus ( value reg# ) + clkgen-smbus-id smbus-acquire ( value reg# ) + swap clkgen-buf c! ( reg# ) + clkgen-buf 1 rot smbus-write ( ) + smbus-release ( ) +; + +: disable-unused-clocks ( -- ) h# 02 5 clkgen-b! ; +: enable-unused-clocks ( -- ) h# de 5 clkgen-b! ; + +stand-init: Clock generator + disable-unused-clocks +; + + +\ LICENSE_BEGIN +\ Copyright (c) 2009 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
Modified: cpu/x86/pc/olpc/via/devices.fth =================================================================== --- cpu/x86/pc/olpc/via/devices.fth 2009-11-09 08:40:32 UTC (rev 1464) +++ cpu/x86/pc/olpc/via/devices.fth 2009-11-09 21:04:45 UTC (rev 1465) @@ -18,6 +18,7 @@ fload ${BP}/cpu/x86/acpitimer.fth
fload ${BP}/cpu/x86/pc/olpc/via/smbus.fth \ SMBUS driver +fload ${BP}/cpu/x86/pc/olpc/via/clkgen.fth \ SMBus-connected clock generator driver fload ${BP}/cpu/x86/apic.fth \ APIC driver
stand-init: APIC
Modified: cpu/x86/pc/olpc/via/smbus.fth =================================================================== --- cpu/x86/pc/olpc/via/smbus.fth 2009-11-09 08:40:32 UTC (rev 1464) +++ cpu/x86/pc/olpc/via/smbus.fth 2009-11-09 21:04:45 UTC (rev 1465) @@ -34,6 +34,7 @@ h# 40 or smb-hostctl! ( ) \ 40 is go bit smbus-wait ( ) smb-hoststat@ ( stat ) + h# 9e smb-hoststat! ( ) \ Clear all status bits dup h# 9c and if ( stat ) dup h# 80 and abort" SMBUS error: PEC" dup h# 10 and abort" SMBUS error: FailedBusTransaction" @@ -42,7 +43,6 @@ drop then ( stat ) drop ( ) - h# 9e smb-hoststat! ( ) \ Clear all status bits ;
\ Bracket groups of SMBUS usage with smbus-acquire ... smbus-release @@ -57,23 +57,40 @@ \ Release semaphore so it will read back as 0 the next time someone looks : smbus-release ( -- ) h# 40 smb-hoststat! ;
-: smbus-write ( adr len offset -- ) \ Up to 32 bytes +: i2c-write ( adr len offset -- ) \ Up to 32 bytes smbus-target smb-xmitadr! ( adr len offset ) smb-hostcmd! ( adr len ) \ Starting offset dup smb-hostdata0! ( adr len ) \ Length - smb-hoststat@ drop ( adr len ) \ Reset block transfer counter + smb-hostcmd@ drop ( adr len ) \ Reset block transfer counter bounds ?do i c@ smb-blockdata! loop ( ) \ Copy data to chip h# 34 smbus-cmd ( ) \ I2C block command ; -: smbus-read ( adr maxlen offset -- actlen ) \ Up to 32 bytes +: i2c-read ( adr maxlen offset -- actlen ) \ Up to 32 bytes smbus-target 1 or smb-xmitadr! ( adr maxlen offset ) smb-hostcmd! ( adr maxlen ) \ Starting offset h# 34 smbus-cmd ( adr maxlen ) \ I2C block command smb-hostdata0@ min ( adr actlen ) \ Number of bytes returned - smb-hoststat@ drop ( adr actlen ) \ Reset block transfer counter + smb-hostcmd@ drop ( adr actlen ) \ Reset block transfer counter tuck bounds ?do smb-blockdata@ i c! loop ( actlen ) \ Copy data from chip ;
+: smbus-write ( adr len offset -- ) \ Up to 32 bytes + smbus-target smb-xmitadr! ( adr len offset ) + smb-hostcmd! ( adr len ) \ Starting offset + dup smb-hostdata0! ( adr len ) \ Length + smb-hostcmd@ drop ( adr len ) \ Reset block transfer counter + bounds ?do i c@ smb-blockdata! loop ( ) \ Copy data to chip + h# 14 smbus-cmd ( ) \ SMBus block command +; +: smbus-read ( adr maxlen offset -- actlen ) \ Up to 32 bytes + smbus-target 1 or smb-xmitadr! ( adr maxlen offset ) + smb-hostcmd! ( adr maxlen ) \ Starting offset + h# 14 smbus-cmd ( adr maxlen ) \ SMBus block command + smb-hostdata0@ min ( adr actlen ) \ Number of bytes returned + smb-hostcmd@ drop ( adr actlen ) \ Reset block transfer counter + tuck bounds ?do smb-blockdata@ i c! loop ( actlen ) \ Copy data from chip +; + : smbus-b! ( byte offset -- ) smbus-target smb-xmitadr! ( byte offset ) smb-hostcmd! ( byte )