^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 1) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 2) * Creation Date: <2003/03/14 20:54:13 samuel>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 3) * Time-stamp: <2004/03/20 14:20:59 samuel>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 4) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 5) * <therm_windtunnel.c>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 6) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 7) * The G4 "windtunnel" has a single fan controlled by an
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 8) * ADM1030 fan controller and a DS1775 thermostat.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 9) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 10) * The fan controller is equipped with a temperature sensor
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 11) * which measures the case temperature. The DS1775 sensor
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12) * measures the CPU temperature. This driver tunes the
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) * behavior of the fan. It is based upon empirical observations
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 14) * of the 'AppleFan' driver under Mac OS X.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 15) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 16) * WARNING: This driver has only been testen on Apple's
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 17) * 1.25 MHz Dual G4 (March 03). It is tuned for a CPU
af901ca181d92 (André Goddard Rosa 2009-11-14 13:09:05 -0200 18) * temperature around 57 C.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 21) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22) * Loosely based upon 'thermostat.c' written by Benjamin Herrenschmidt
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 23) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 24) * This program is free software; you can redistribute it and/or
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 25) * modify it under the terms of the GNU General Public License
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 26) * as published by the Free Software Foundation
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 27) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 28) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 29)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 30) #include <linux/types.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 31) #include <linux/module.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 32) #include <linux/errno.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 33) #include <linux/kernel.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 34) #include <linux/delay.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 35) #include <linux/sched.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 36) #include <linux/i2c.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 37) #include <linux/init.h>
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 38) #include <linux/kthread.h>
ad9e05aef7c86 (Stephen Rothwell 2008-05-23 16:27:02 +1000 39) #include <linux/of_platform.h>
7eebde700fe6f (Benjamin Herrenschmidt 2006-11-11 17:24:59 +1100 40)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 41) #include <asm/prom.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 42) #include <asm/machdep.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 43) #include <asm/io.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 44) #include <asm/sections.h>
5e6557722e698 (Jeff Mahoney 2005-07-06 15:44:41 -0400 45) #include <asm/macio.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 46)
25985edcedea6 (Lucas De Marchi 2011-03-30 22:57:33 -0300 47) #define LOG_TEMP 0 /* continuously log temperature */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 48)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 49) static struct {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 50) volatile int running;
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 51) struct task_struct *poll_task;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 52)
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 53) struct mutex lock;
2dc1158137682 (Grant Likely 2010-08-06 09:25:50 -0600 54) struct platform_device *of_dev;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 55)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 56) struct i2c_client *thermostat;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 57) struct i2c_client *fan;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 58)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 59) int overheat_temp; /* 100% fan at this temp */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 60) int overheat_hyst;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 61) int temp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 62) int casetemp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 63) int fan_level; /* active fan_table setting */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 64)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 65) int downind;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 66) int upind;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 67)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 68) int r0, r1, r20, r23, r25; /* saved register */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 69) } x;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 70)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 71) #define T(x,y) (((x)<<8) | (y)*0x100/10 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 72)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 73) static struct {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 74) int fan_down_setting;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 75) int temp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 76) int fan_up_setting;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 77) } fan_table[] = {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 78) { 11, T(0,0), 11 }, /* min fan */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 79) { 11, T(55,0), 11 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 80) { 6, T(55,3), 11 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 81) { 7, T(56,0), 11 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 82) { 8, T(57,0), 8 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 83) { 7, T(58,3), 7 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 84) { 6, T(58,8), 6 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 85) { 5, T(59,2), 5 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 86) { 4, T(59,6), 4 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 87) { 3, T(59,9), 3 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 88) { 2, T(60,1), 2 },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 89) { 1, 0xfffff, 1 } /* on fire */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 90) };
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 91)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 92) static void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 93) print_temp( const char *s, int temp )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 94) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 95) printk("%s%d.%d C", s ? s : "", temp>>8, (temp & 255)*10/256 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 96) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 97)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 98) static ssize_t
e404e274f6266 (Yani Ioannou 2005-05-17 06:42:58 -0400 99) show_cpu_temperature( struct device *dev, struct device_attribute *attr, char *buf )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 100) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 101) return sprintf(buf, "%d.%d\n", x.temp>>8, (x.temp & 255)*10/256 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 102) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 103)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 104) static ssize_t
e404e274f6266 (Yani Ioannou 2005-05-17 06:42:58 -0400 105) show_case_temperature( struct device *dev, struct device_attribute *attr, char *buf )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 106) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 107) return sprintf(buf, "%d.%d\n", x.casetemp>>8, (x.casetemp & 255)*10/256 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 108) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 109)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 110) static DEVICE_ATTR(cpu_temperature, S_IRUGO, show_cpu_temperature, NULL );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 111) static DEVICE_ATTR(case_temperature, S_IRUGO, show_case_temperature, NULL );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 112)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 113)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 114)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 115) /************************************************************************/
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 116) /* controller thread */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 117) /************************************************************************/
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 118)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 119) static int
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 120) write_reg( struct i2c_client *cl, int reg, int data, int len )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 121) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 122) u8 tmp[3];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 123)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 124) if( len < 1 || len > 2 || data < 0 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 125) return -EINVAL;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 126)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 127) tmp[0] = reg;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 128) tmp[1] = (len == 1) ? data : (data >> 8);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 129) tmp[2] = data;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 130) len++;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 131)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 132) if( i2c_master_send(cl, tmp, len) != len )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 133) return -ENODEV;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 134) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 135) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 136)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 137) static int
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 138) read_reg( struct i2c_client *cl, int reg, int len )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 139) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 140) u8 buf[2];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 141)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 142) if( len != 1 && len != 2 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 143) return -EINVAL;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 144) buf[0] = reg;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 145) if( i2c_master_send(cl, buf, 1) != 1 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 146) return -ENODEV;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 147) if( i2c_master_recv(cl, buf, len) != len )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 148) return -ENODEV;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 149) return (len == 2)? ((unsigned int)buf[0] << 8) | buf[1] : buf[0];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 150) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 151)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 152) static void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 153) tune_fan( int fan_setting )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 154) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 155) int val = (fan_setting << 3) | 7;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 156)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 157) /* write_reg( x.fan, 0x24, val, 1 ); */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 158) write_reg( x.fan, 0x25, val, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 159) write_reg( x.fan, 0x20, 0, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 160) print_temp("CPU-temp: ", x.temp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 161) if( x.casetemp )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 162) print_temp(", Case: ", x.casetemp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 163) printk(", Fan: %d (tuned %+d)\n", 11-fan_setting, x.fan_level-fan_setting );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 164)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 165) x.fan_level = fan_setting;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 166) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 167)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 168) static void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 169) poll_temp( void )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 170) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 171) int temp, i, level, casetemp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 172)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 173) temp = read_reg( x.thermostat, 0, 2 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 174)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 175) /* this actually occurs when the computer is loaded */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 176) if( temp < 0 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 177) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 178)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 179) casetemp = read_reg(x.fan, 0x0b, 1) << 8;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 180) casetemp |= (read_reg(x.fan, 0x06, 1) & 0x7) << 5;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 181)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 182) if( LOG_TEMP && x.temp != temp ) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 183) print_temp("CPU-temp: ", temp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 184) print_temp(", Case: ", casetemp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 185) printk(", Fan: %d\n", 11-x.fan_level );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 186) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 187) x.temp = temp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 188) x.casetemp = casetemp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 189)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 190) level = -1;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 191) for( i=0; (temp & 0xffff) > fan_table[i].temp ; i++ )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 192) ;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 193) if( i < x.downind )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 194) level = fan_table[i].fan_down_setting;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 195) x.downind = i;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 196)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 197) for( i=0; (temp & 0xffff) >= fan_table[i+1].temp ; i++ )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 198) ;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 199) if( x.upind < i )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 200) level = fan_table[i].fan_up_setting;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 201) x.upind = i;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 202)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 203) if( level >= 0 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 204) tune_fan( level );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 205) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 206)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 207)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 208) static void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 209) setup_hardware( void )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 210) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 211) int val;
98894dffaf119 (Stephen Rothwell 2008-01-03 15:15:28 +1100 212) int err;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 213)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 214) /* save registers (if we unload the module) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 215) x.r0 = read_reg( x.fan, 0x00, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 216) x.r1 = read_reg( x.fan, 0x01, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 217) x.r20 = read_reg( x.fan, 0x20, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 218) x.r23 = read_reg( x.fan, 0x23, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 219) x.r25 = read_reg( x.fan, 0x25, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 220)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 221) /* improve measurement resolution (convergence time 1.5s) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 222) if( (val=read_reg(x.thermostat, 1, 1)) >= 0 ) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 223) val |= 0x60;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 224) if( write_reg( x.thermostat, 1, val, 1 ) )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 225) printk("Failed writing config register\n");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 226) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 227) /* disable interrupts and TAC input */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 228) write_reg( x.fan, 0x01, 0x01, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 229) /* enable filter */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 230) write_reg( x.fan, 0x23, 0x91, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 231) /* remote temp. controls fan */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 232) write_reg( x.fan, 0x00, 0x95, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 233)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 234) /* The thermostat (which besides measureing temperature controls
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 235) * has a THERM output which puts the fan on 100%) is usually
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 236) * set to kick in at 80 C (chip default). We reduce this a bit
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 237) * to be on the safe side (OSX doesn't)...
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 238) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 239) if( x.overheat_temp == (80 << 8) ) {
b8e4a7dae5376 (Lyonel Vincent 2009-08-30 08:54:20 +0000 240) x.overheat_temp = 75 << 8;
b8e4a7dae5376 (Lyonel Vincent 2009-08-30 08:54:20 +0000 241) x.overheat_hyst = 70 << 8;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 242) write_reg( x.thermostat, 2, x.overheat_hyst, 2 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 243) write_reg( x.thermostat, 3, x.overheat_temp, 2 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 244)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 245) print_temp("Reducing overheating limit to ", x.overheat_temp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 246) print_temp(" (Hyst: ", x.overheat_hyst );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 247) printk(")\n");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 248) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 249)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 250) /* set an initial fan setting */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 251) x.downind = 0xffff;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 252) x.upind = -1;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 253) /* tune_fan( fan_up_table[x.upind].fan_setting ); */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 254)
98894dffaf119 (Stephen Rothwell 2008-01-03 15:15:28 +1100 255) err = device_create_file( &x.of_dev->dev, &dev_attr_cpu_temperature );
98894dffaf119 (Stephen Rothwell 2008-01-03 15:15:28 +1100 256) err |= device_create_file( &x.of_dev->dev, &dev_attr_case_temperature );
98894dffaf119 (Stephen Rothwell 2008-01-03 15:15:28 +1100 257) if (err)
98894dffaf119 (Stephen Rothwell 2008-01-03 15:15:28 +1100 258) printk(KERN_WARNING
98894dffaf119 (Stephen Rothwell 2008-01-03 15:15:28 +1100 259) "Failed to create temperature attribute file(s).\n");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 260) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 261)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 262) static void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 263) restore_regs( void )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 264) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 265) device_remove_file( &x.of_dev->dev, &dev_attr_cpu_temperature );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 266) device_remove_file( &x.of_dev->dev, &dev_attr_case_temperature );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 267)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 268) write_reg( x.fan, 0x01, x.r1, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 269) write_reg( x.fan, 0x20, x.r20, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 270) write_reg( x.fan, 0x23, x.r23, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 271) write_reg( x.fan, 0x25, x.r25, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 272) write_reg( x.fan, 0x00, x.r0, 1 );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 273) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 274)
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 275) static int control_loop(void *dummy)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 276) {
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 277) mutex_lock(&x.lock);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 278) setup_hardware();
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 279) mutex_unlock(&x.lock);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 280)
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 281) for (;;) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 282) msleep_interruptible(8000);
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 283) if (kthread_should_stop())
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 284) break;
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 285)
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 286) mutex_lock(&x.lock);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 287) poll_temp();
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 288) mutex_unlock(&x.lock);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 289) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 290)
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 291) mutex_lock(&x.lock);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 292) restore_regs();
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 293) mutex_unlock(&x.lock);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 294)
98f6740ea6d53 (Paul Mackerras 2007-12-13 15:57:45 +1100 295) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 296) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 297)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 298)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 299) /************************************************************************/
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 300) /* i2c probing and setup */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 301) /************************************************************************/
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 302)
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 303) static void do_attach(struct i2c_adapter *adapter)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 304) {
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 305) struct i2c_board_info info = { };
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 306) struct device_node *np;
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 307)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 308) /* scan 0x48-0x4f (DS1775) and 0x2c-2x2f (ADM1030) */
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 309) static const unsigned short scan_ds1775[] = {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 310) 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 311) I2C_CLIENT_END
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 312) };
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 313) static const unsigned short scan_adm1030[] = {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 314) 0x2c, 0x2d, 0x2e, 0x2f,
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 315) I2C_CLIENT_END
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 316) };
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 317)
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 318) if (x.running || strncmp(adapter->name, "uni-n", 5))
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 319) return;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 320)
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 321) np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,ds1775");
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 322) if (np) {
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 323) of_node_put(np);
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 324) } else {
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 325) strlcpy(info.type, "MAC,ds1775", I2C_NAME_SIZE);
624d1be7a1266 (Wolfram Sang 2020-02-10 18:04:01 +0100 326) i2c_new_scanned_device(adapter, &info, scan_ds1775, NULL);
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 327) }
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 328)
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 329) np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,adm1030");
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 330) if (np) {
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 331) of_node_put(np);
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 332) } else {
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 333) strlcpy(info.type, "MAC,adm1030", I2C_NAME_SIZE);
624d1be7a1266 (Wolfram Sang 2020-02-10 18:04:01 +0100 334) i2c_new_scanned_device(adapter, &info, scan_adm1030, NULL);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 335) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 336) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 337)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 338) static int
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 339) do_remove(struct i2c_client *client)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 340) {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 341) if (x.running) {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 342) x.running = 0;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 343) kthread_stop(x.poll_task);
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 344) x.poll_task = NULL;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 345) }
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 346) if (client == x.thermostat)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 347) x.thermostat = NULL;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 348) else if (client == x.fan)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 349) x.fan = NULL;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 350) else
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 351) printk(KERN_ERR "g4fan: bad client\n");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 352)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 353) return 0;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 354) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 355)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 356) static int
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 357) attach_fan( struct i2c_client *cl )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 358) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 359) if( x.fan )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 360) goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 361)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 362) /* check that this is an ADM1030 */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 363) if( read_reg(cl, 0x3d, 1) != 0x30 || read_reg(cl, 0x3e, 1) != 0x41 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 364) goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 365) printk("ADM1030 fan controller [@%02x]\n", cl->addr );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 366)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 367) x.fan = cl;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 368) out:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 369) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 370) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 371)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 372) static int
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 373) attach_thermostat( struct i2c_client *cl )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 374) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 375) int hyst_temp, os_temp, temp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 376)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 377) if( x.thermostat )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 378) goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 379)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 380) if( (temp=read_reg(cl, 0, 2)) < 0 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 381) goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 382)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 383) /* temperature sanity check */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 384) if( temp < 0x1600 || temp > 0x3c00 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 385) goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 386) hyst_temp = read_reg(cl, 2, 2);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 387) os_temp = read_reg(cl, 3, 2);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 388) if( hyst_temp < 0 || os_temp < 0 )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 389) goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 390)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 391) printk("DS1775 digital thermometer [@%02x]\n", cl->addr );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 392) print_temp("Temp: ", temp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 393) print_temp(" Hyst: ", hyst_temp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 394) print_temp(" OS: ", os_temp );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 395) printk("\n");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 396)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 397) x.temp = temp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 398) x.overheat_temp = os_temp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 399) x.overheat_hyst = hyst_temp;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 400) x.thermostat = cl;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 401) out:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 402) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 403) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 404)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 405) enum chip { ds1775, adm1030 };
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 406)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 407) static const struct i2c_device_id therm_windtunnel_id[] = {
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 408) { "MAC,ds1775", ds1775 },
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 409) { "MAC,adm1030", adm1030 },
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 410) { }
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 411) };
cb0eefcc3271e (Javier Martinez Canillas 2015-07-30 18:18:30 +0200 412) MODULE_DEVICE_TABLE(i2c, therm_windtunnel_id);
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 413)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 414) static int
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 415) do_probe(struct i2c_client *cl, const struct i2c_device_id *id)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 416) {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 417) struct i2c_adapter *adapter = cl->adapter;
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 418) int ret = 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 419)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 420) if( !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 421) | I2C_FUNC_SMBUS_WRITE_BYTE) )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 422) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 423)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 424) switch (id->driver_data) {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 425) case adm1030:
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 426) ret = attach_fan(cl);
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 427) break;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 428) case ds1775:
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 429) ret = attach_thermostat(cl);
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 430) break;
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 431) }
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 432)
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 433) if (!x.running && x.thermostat && x.fan) {
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 434) x.running = 1;
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 435) x.poll_task = kthread_run(control_loop, NULL, "g4fand");
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 436) }
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 437)
38b17afb0ebb9 (Wolfram Sang 2020-02-25 15:12:29 +0100 438) return ret;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 439) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 440)
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 441) static struct i2c_driver g4fan_driver = {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 442) .driver = {
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 443) .name = "therm_windtunnel",
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 444) },
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 445) .probe = do_probe,
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 446) .remove = do_remove,
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 447) .id_table = therm_windtunnel_id,
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 448) };
036533e232922 (Jean Delvare 2009-06-15 18:01:52 +0200 449)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 450)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 451) /************************************************************************/
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 452) /* initialization / cleanup */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 453) /************************************************************************/
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 454)
000061245a679 (Grant Likely 2011-02-22 19:59:54 -0700 455) static int therm_of_probe(struct platform_device *dev)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 456) {
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 457) struct i2c_adapter *adap;
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 458) int ret, i = 0;
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 459)
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 460) adap = i2c_get_adapter(0);
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 461) if (!adap)
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 462) return -EPROBE_DEFER;
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 463)
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 464) ret = i2c_add_driver(&g4fan_driver);
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 465) if (ret) {
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 466) i2c_put_adapter(adap);
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 467) return ret;
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 468) }
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 469)
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 470) /* We assume Macs have consecutive I2C bus numbers starting at 0 */
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 471) while (adap) {
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 472) do_attach(adap);
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 473) if (x.running)
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 474) return 0;
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 475) i2c_put_adapter(adap);
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 476) adap = i2c_get_adapter(++i);
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 477) }
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 478)
3e7bed52719de (Wolfram Sang 2018-08-21 17:02:39 +0200 479) return -ENODEV;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 480) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 481)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 482) static int
2dc1158137682 (Grant Likely 2010-08-06 09:25:50 -0600 483) therm_of_remove( struct platform_device *dev )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 484) {
b3e820968ad47 (Jean Delvare 2007-05-01 23:26:32 +0200 485) i2c_del_driver( &g4fan_driver );
b3e820968ad47 (Jean Delvare 2007-05-01 23:26:32 +0200 486) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 487) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 488)
46759a7c13264 (Márton Németh 2010-01-10 01:43:14 +0000 489) static const struct of_device_id therm_of_match[] = {{
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 490) .name = "fan",
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 491) .compatible = "adm1030"
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 492) }, {}
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 493) };
a1a42b7920ba5 (Javier Martinez Canillas 2015-07-30 18:18:47 +0200 494) MODULE_DEVICE_TABLE(of, therm_of_match);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 495)
000061245a679 (Grant Likely 2011-02-22 19:59:54 -0700 496) static struct platform_driver therm_of_driver = {
4018294b53d1d (Grant Likely 2010-04-13 16:13:02 -0700 497) .driver = {
4018294b53d1d (Grant Likely 2010-04-13 16:13:02 -0700 498) .name = "temperature",
4018294b53d1d (Grant Likely 2010-04-13 16:13:02 -0700 499) .of_match_table = therm_of_match,
4018294b53d1d (Grant Likely 2010-04-13 16:13:02 -0700 500) },
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 501) .probe = therm_of_probe,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 502) .remove = therm_of_remove,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 503) };
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 504)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 505) struct apple_thermal_info {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 506) u8 id; /* implementation ID */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 507) u8 fan_count; /* number of fans */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 508) u8 thermostat_count; /* number of thermostats */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 509) u8 unused;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 510) };
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 511)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 512) static int __init
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 513) g4fan_init( void )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 514) {
018a3d1db7cdb (Jeremy Kerr 2006-07-12 15:40:29 +1000 515) const struct apple_thermal_info *info;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 516) struct device_node *np;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 517)
1baaeea005947 (Daniel Walker 2008-06-10 09:26:08 +1000 518) mutex_init(&x.lock);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 519)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 520) if( !(np=of_find_node_by_name(NULL, "power-mgt")) )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 521) return -ENODEV;
01b2726dd11ef (Stephen Rothwell 2007-04-27 13:41:15 +1000 522) info = of_get_property(np, "thermal-info", NULL);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 523) of_node_put(np);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 524)
71a157e8edca5 (Grant Likely 2010-02-01 21:34:14 -0700 525) if( !info || !of_machine_is_compatible("PowerMac3,6") )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 526) return -ENODEV;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 527)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 528) if( info->id != 3 ) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 529) printk(KERN_ERR "therm_windtunnel: unsupported thermal design %d\n", info->id );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 530) return -ENODEV;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 531) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 532) if( !(np=of_find_node_by_name(NULL, "fan")) )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 533) return -ENODEV;
0365ba7fb1fa9 (Benjamin Herrenschmidt 2005-09-22 21:44:06 -0700 534) x.of_dev = of_platform_device_create(np, "temperature", NULL);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 535) of_node_put( np );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 536)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 537) if( !x.of_dev ) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 538) printk(KERN_ERR "Can't register fan controller!\n");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 539) return -ENODEV;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 540) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 541)
000061245a679 (Grant Likely 2011-02-22 19:59:54 -0700 542) platform_driver_register( &therm_of_driver );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 543) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 544) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 545)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 546) static void __exit
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 547) g4fan_exit( void )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 548) {
000061245a679 (Grant Likely 2011-02-22 19:59:54 -0700 549) platform_driver_unregister( &therm_of_driver );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 550)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 551) if( x.of_dev )
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 552) of_device_unregister( x.of_dev );
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 553) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 554)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 555) module_init(g4fan_init);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 556) module_exit(g4fan_exit);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 557)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 558) MODULE_AUTHOR("Samuel Rydh <samuel@ibrium.se>");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 559) MODULE_DESCRIPTION("Apple G4 (windtunnel) fan controller");
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 560) MODULE_LICENSE("GPL");