Subject: Re: Driver for Analog Devices ADT7467 environmental controller -
To: None <port-macppc@netbsd.org>
From: Michael <macallan18@earthlink.net>
List: port-macppc
Date: 12/15/2004 12:51:00
Hello,

> I'll post a patch ( will be pretty big - 3 new drivers ( uni-n and deq don't do much more than attaching, adt7467c is the driver for
> the environmental controller ), changes to two others (snapper and ki2n) ) when I'm done cleaning it up a bit.

Here's the patch. IF you have the right kind of thermal monitor chip you'll end up with something like this:
cpu0 at mainbus0: 7455 (Revision 3.3), ID 0 (primary)
cpu0: HID0 8450c0bc<EMCP,TBEN,NAP,DPM,ICE,DCE,SGE,BTIC,LRSTK,FOLD,BHT>, PS=1
cpu0: 614.39 MHz, 256KB L2 cache
uni_n0 at mainbus0 address f8000000
hw-clock at uni_n0 not configured
ki2c0 at uni_n0 address 0xf8001000
iic0 at ki2c0: I2C bus
adt7467c0 at ki2c0 address 0x15c ADT7467 thermal monitor and fan controller
adt7467c0: found 5 sensors
 1: temperature PWR/MEMORY BOTTOMSIDE
 2: temperature CPU BOTTOMSIDE
 3: temperature GPU ON DIE
 4: voltage CPU CORE
 5: fanspeed REAR MAIN ENCLOSURE
i2c-hwclock at ki2c0 address 0x1d2 not configured
cereal at ki2c0 address 0x1c0 not configured
...
ki2c1 at obio0
iic1 at ki2c1: I2C bus
cereal at ki2c1 address 0x1c0 not configured
deq0 at ki2c1 address 0x6a Apple Digital Equalizer
i2c-modem at ki2c1 not configured
...
audio0 at snapper0: full duplex
snapper0: using ki2c1

Audio should work, more or less, it has a bunch of other issues so don't hold your breath.

Anyway, back to thermal monitor stuff:
~# envstat -r
PWR/MEMORY BOTTOMSIDE:     39.000 degC
       CPU BOTTOMSIDE:     52.000 degC
           GPU ON DIE:     39.000 degC
             CPU CORE:      1.602 V
  REAR MAIN ENCLOSURE:       6809 RPM
... that's the current readings. To change the fan behaviour you need to use sysctl:
~# sysctl -a
...
machdep.adt7467c0.temp0 = 56
machdep.adt7467c0.temp1 = 85
machdep.adt7467c0.temp2 = 76
These are the threshold registers belonging to the thermal sensors listed by envstat. 
~# sysctl -d
...
machdep.adt7467c0.temp0: PWR/MEMORY BOTTOMSIDE
machdep.adt7467c0.temp1: CPU BOTTOMSIDE
machdep.adt7467c0.temp2: GPU ON DIE

The temperatures are in degrees Celsius, not because I'm european but because the chip wants them like this. So if you want the fan to spin up when the CPU temperature reaches 55C just do this:
~# sysctl -w machdep.adt7467c0.temp1=55
machdep.adt7467c0.temp1: 85 -> 55
...and the fan will spin up within a couple of seconds when this sensor reaches 55C.

To make it work you need to do this:
- apply the patch, it will change snapper.c, ki2c.c and files.macppc.
- put the .c files you get with this mail into macppc/dev/
- add a bunch of new devices to your kernel config ( see below )
- config, make depend, make...
- cross fingers
- reboot
- tell me it if works for you.

your kernel config should contain something like this:
uni_n*	at mainbus?
ki2c*	at obio?			# Keywest I2C
ki2c*	at uni_n?			# Keywest I2C
iic*	at ki2c?			# attach an I2C bus to each Keywest. Mainly because we can.
adt7467c*	at ki2c?		# Analog Devices ADT7467 thermal monitor, fan controller and so on
deq*	at ki2c?			# mixer/equalizer, needed by snapper
snapper* at obio?			# Snapper audio device