From 1ade24f919b1822764663a9bf5df4c23ffc32fda Mon Sep 17 00:00:00 2001 From: Frodo Looijaard Date: Wed, 28 Apr 1999 18:18:12 +0000 Subject: [PATCH] Geert's PPC support and Hydra driver git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@430 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 4 + CONTRIBUTORS | 2 + INSTALL | 2 +- TODO | 2 + doc/busses/i2c-hydra | 30 ++++++ doc/developers/design | 2 +- i2c/MODIFICATIONS | 6 ++ i2c/algo-bit.h | 2 +- i2c/bit-lp.c | 1 + i2c/i2c.h | 5 +- kernel/busses/Module.mk | 3 +- kernel/busses/i2c-hydra.c | 184 +++++++++++++++++++++++++++++++++++++ kernel/smbus.c | 1 + prog/detect/sensors-detect | 8 ++ prog/dump/isadump.c | 9 +- 15 files changed, 254 insertions(+), 7 deletions(-) create mode 100644 doc/busses/i2c-hydra create mode 100644 kernel/busses/i2c-hydra.c diff --git a/CHANGES b/CHANGES index 95b914fd..6aa582b1 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,10 @@ ask CVS about it: for example: cvs diff -r V2-0-0 -r V2-0-1 -u +2.3.1 (199904??) + All: Now compiles on PPC + Module i2c-hydra: NEW + 2.3.0 (19990422) All: Many, many changes and improvements All: Many small bugs and problems removed diff --git a/CONTRIBUTORS b/CONTRIBUTORS index d89e0dce..c0752df2 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -24,6 +24,8 @@ problems. Author of the i2c-via and sis5595 drivers. * Mark D. Studebaker Author of the i2c-ali15x3 driver, as well as other drivers. +* Geert Uytterhoeven + Author of the i2c-hydra driver. * Adrian Baugh Author of wmsensors (get it at http://users.ox.ac.uk/~kebl0850/wmlm78); he also tested lots of things, and helped us out on several occasions. diff --git a/INSTALL b/INSTALL index 9410a1eb..c36f241e 100644 --- a/INSTALL +++ b/INSTALL @@ -169,5 +169,5 @@ USEFUL PROGRAMS The prog subdirectory contains lots of useful programs, many of which are not installed. doc/progs contains some documentation for each of them. Most important are prog/mkdev/mkdev.sh, which creates /dev/i2c-* files, -and prog/detect/dectect.pl, which tries to detect what adapters are +and prog/detect/detect.pl, which tries to detect what adapters are present on your system. diff --git a/TODO b/TODO index e5561732..f561f7bb 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,8 @@ Many, many things. Most notably: KERNEL MODULES ============== +* `modprobe w83781d force_w38781d=0,0x49' let to strange beeping on Frodo's + computer. Why? * Increase use count of adapter driver if directory of chip is entered * maxilife.c: Introduce new insmod variables * maxilife.c: Round REG_TO_VID correctly diff --git a/doc/busses/i2c-hydra b/doc/busses/i2c-hydra new file mode 100644 index 00000000..c2eea5d2 --- /dev/null +++ b/doc/busses/i2c-hydra @@ -0,0 +1,30 @@ +Kernel driver `i2c-hydra.o' + +Status: Complete and somewhat tested + +Supported adapters: + * Apple `Hydra' Mac I/O + Datasheet: Publicly available (?) + +Author: Geert Uytterhoeven + + +Module Parameters +----------------- + +(none) + + +Description +----------- + +i2c-hydra is an i2c bus driver for CHRP motherboards with the Apple Hydra Mac +I/O. + +Your /proc/pci or lspci listing must show this : + + Unknown class: Apple Hydra (rev 2) + +To install this driver, simply do + # modprobe i2c-hydra + diff --git a/doc/developers/design b/doc/developers/design index f7f0995f..9afb8075 100644 --- a/doc/developers/design +++ b/doc/developers/design @@ -183,7 +183,7 @@ Module i2c.o ============ This is Simon Vogl's i2c module (this one is different from the i2c module -included in kernels around 1.2.120!). +included in kernels around 2.1.120!). A driver -------- diff --git a/i2c/MODIFICATIONS b/i2c/MODIFICATIONS index e9f735b9..45517a60 100644 --- a/i2c/MODIFICATIONS +++ b/i2c/MODIFICATIONS @@ -48,3 +48,9 @@ Here come the changes: * Removed files: object files and executables Everywhere, remakeable files are removed, to keep the source distribution small and lean. + +* algo-bit.h: Removed comment typo (Geert) + +* bit-lp.c: Added #include (Geert) + +* i2c.h: Added HW_B_HYDRA, removed two comment typos (Geert) diff --git a/i2c/algo-bit.h b/i2c/algo-bit.h index 225b519e..5b1a0815 100644 --- a/i2c/algo-bit.h +++ b/i2c/algo-bit.h @@ -11,7 +11,7 @@ struct bit_adapter { char name[32]; /* give it a nice name */ unsigned int id; /* not used yet, maybe later */ - void *data; /* private data for lolevel routines */ + void *data; /* private data for lowlevel routines */ void (*setsda) (void *data, int state); void (*setscl) (void *data, int state); int (*getsda) (void *data); diff --git a/i2c/bit-lp.c b/i2c/bit-lp.c index 29fc0e38..7eb2453b 100644 --- a/i2c/bit-lp.c +++ b/i2c/bit-lp.c @@ -24,6 +24,7 @@ static char rcsid[] = "$Id: bit-lp.c,v 1.6 1998/12/30 08:36:08 i2c Exp i2c $"; #include #include #include +#include #include "i2c.h" #include "algo-bit.h" diff --git a/i2c/i2c.h b/i2c/i2c.h index d8ef5e11..e654a7ad 100644 --- a/i2c/i2c.h +++ b/i2c/i2c.h @@ -339,11 +339,12 @@ extern int i2c_adapter_id(struct i2c_adapter *adap); #define HW_B_BT848 0x05 /* BT848 video boards */ #define HW_B_WNV 0x06 /* Winnov Videums */ #define HW_B_VIA 0x07 /* Via vt82c586b */ +#define HW_B_HYDRA 0x08 /* Apple Hydra Mac I/O */ /* --- PCF 8584 based algorithms */ #define HW_P_LP 0x00 /* Parallel port interface */ -#define HW_P_ISA 0x01 /* generic ISA Bus inteface card */ -#define HW_P_ELEK 0x02 /* Elektor ISA Bus inteface card */ +#define HW_P_ISA 0x01 /* generic ISA Bus interface card */ +#define HW_P_ELEK 0x02 /* Elektor ISA Bus interface card */ diff --git a/kernel/busses/Module.mk b/kernel/busses/Module.mk index d4a2e756..d692dbcc 100644 --- a/kernel/busses/Module.mk +++ b/kernel/busses/Module.mk @@ -23,7 +23,8 @@ MODULE_DIR := kernel/busses # Regrettably, even 'simply expanded variables' will not put their currently # defined value verbatim into the command-list of rules... KERNELBUSSESTARGETS := $(MODULE_DIR)/i2c-piix4.o $(MODULE_DIR)/i2c-isa.o \ - $(MODULE_DIR)/i2c-via.o $(MODULE_DIR)/i2c-ali15x3.o + $(MODULE_DIR)/i2c-via.o $(MODULE_DIR)/i2c-ali15x3.o \ + $(MODULE_DIR)/i2c-hydra.o KERNELBUSSESOLD := bit-via.o bit-mb.o isa.o piix4.o diff --git a/kernel/busses/i2c-hydra.c b/kernel/busses/i2c-hydra.c new file mode 100644 index 00000000..98957495 --- /dev/null +++ b/kernel/busses/i2c-hydra.c @@ -0,0 +1,184 @@ +/* + i2c-hydra.c - Part of lm_sensors, Linux kernel modules + for hardware monitoring + + i2c Support for the Apple `Hydra' Mac I/O + + Copyright (c) 1999 Geert Uytterhoeven + + Based on i2c Support for Via Technologies 82C586B South Bridge + Copyright (c) 1998, 1999 Kyösti Mälkki + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include +#include +#include +#include +#include + +#include "i2c.h" +#include "algo-bit.h" + +/* PCI device */ +#define VENDOR PCI_VENDOR_ID_APPLE +#define DEVICE PCI_DEVICE_ID_APPLE_HYDRA + +#define HYDRA_CACHE_PD 0x00000030 + +#define HYDRA_CPD_PD0 0x00000001 /* CachePD lines */ +#define HYDRA_CPD_PD1 0x00000002 +#define HYDRA_CPD_PD2 0x00000004 +#define HYDRA_CPD_PD3 0x00000008 + +#define HYDRA_SCLK HYDRA_CPD_PD0 +#define HYDRA_SDAT HYDRA_CPD_PD1 +#define HYDRA_SCLK_OE 0x00000010 +#define HYDRA_SDAT_OE 0x00000020 + +static unsigned long hydra_base; + +static inline void pdregw(u32 val) +{ + writel(val, hydra_base+HYDRA_CACHE_PD); +} + +static inline u32 pdregr(void) +{ + u32 val = readl(hydra_base+HYDRA_CACHE_PD); + return val; +} + +static void bit_hydra_setscl(void *data, int state) +{ + u32 val = pdregr(); + if (state) + val &= ~ HYDRA_SCLK_OE; + else { + val &= ~HYDRA_SCLK; + val |= HYDRA_SCLK_OE; + } + pdregw(val); +} + +static void bit_hydra_setsda(void *data, int state) +{ + u32 val = pdregr(); + if (state) + val &= ~ HYDRA_SDAT_OE; + else { + val &= ~HYDRA_SDAT; + val |= HYDRA_SDAT_OE; + } + pdregw(val); +} + +static int bit_hydra_getscl(void *data) +{ + return (pdregr() & HYDRA_SCLK) != 0; +} + +static int bit_hydra_getsda(void *data) +{ + return (pdregr() & HYDRA_SDAT) != 0; +} + +static int bit_hydra_reg(struct i2c_client *client) +{ + MOD_INC_USE_COUNT; + return 0; +} + +static int bit_hydra_unreg(struct i2c_client *client) +{ + MOD_DEC_USE_COUNT; + return 0; +} + + +/* ------------------------------------------------------------------------ */ + +struct bit_adapter bit_hydra_ops = { + "Hydra i2c", + HW_B_HYDRA, + NULL, + bit_hydra_setsda, + bit_hydra_setscl, + bit_hydra_getsda, + bit_hydra_getscl, + bit_hydra_reg, + bit_hydra_unreg, + 5, 5, 100, /*waits, timeout */ +}; + + +static int find_hydra(void) +{ + struct pci_dev *dev; + + if (!pci_present()) + return -ENODEV; + + dev = pci_find_device(VENDOR, DEVICE, NULL); + + if (!dev) { + printk("Hydra not found\n"); + return -ENODEV; + } + + hydra_base = (unsigned long)ioremap(dev->base_address[0], 0x100); + + return 0; +} + +int init_i2c_hydra(void) +{ + if (find_hydra() < 0) { + printk("Error while reading PCI configuration\n"); + return -ENODEV; + } + + pdregw(0); /* clear SCLK_OE and SDAT_OE */ + + if (i2c_bit_add_bus(&bit_hydra_ops) == 0) { + printk("Hydra i2c: Module succesfully loaded\n"); + return 0; + } else { + iounmap((void *)hydra_base); + printk("Hydra i2c: Algo-bit error, couldn't register bus\n"); + return -ENODEV; + } +} + +#ifdef MODULE +MODULE_AUTHOR("Geert Uytterhoeven "); +MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O"); + +int init_module(void) +{ + return init_i2c_hydra(); +} + +void cleanup_module(void) +{ + i2c_bit_del_bus(&bit_hydra_ops); + if (hydra_base) { + pdregw(0); /* clear SCLK_OE and SDAT_OE */ + iounmap((void *)hydra_base); + } +} +#endif diff --git a/kernel/smbus.c b/kernel/smbus.c index aaa190a9..5bf8c41a 100644 --- a/kernel/smbus.c +++ b/kernel/smbus.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "i2c.h" #ifdef I2C_SPINLOCK diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index 27ea2751..b18aa682 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -78,6 +78,14 @@ use vars qw(@pci_adapters @chip_ids @undetectable_adapters); driver => "i2c-ali15x3", match => sub { $_[0] =~ /^SMBus ALI15X3 adapter at [0-9,a-f]{4}/ }, } + { + vendid => 0x106b, + devid => 0x000e, + func => 0, + procid => "Apple Computer Inc. Hydra Mac I/O", + driver => "i2c-hydra", + match => sub { $_[0] =~ /^Hydra i2c/ }, + }, ); use subs qw(lm78_detect lm78_isa_detect lm78_alias_detect lm75_detect diff --git a/prog/dump/isadump.c b/prog/dump/isadump.c index 8fa77899..06eeb1c6 100644 --- a/prog/dump/isadump.c +++ b/prog/dump/isadump.c @@ -22,11 +22,16 @@ #include #include + /* To keep glibc2 happy */ -#ifdef __GLIBC__ +#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 0 #include #endif +#ifdef __powerpc__ +unsigned long isa_io_base = 0; /* XXX for now */ +#endif /* __powerpc__ */ + char hexchar(int i) { if ((i >= 0) && (i <= 9)) @@ -93,6 +98,7 @@ int main(int argc, char *argv[]) fprintf(stderr," You have five seconds to reconsider and press CTRL-C!\n\n"); sleep(5); +#ifndef __powerpc__ if ((datareg < 0x400) && (datareg < 0x400)) { if(ioperm(datareg,1,1)) { fprintf(stderr,"Error: Could not ioperm() data register!\n"); @@ -108,6 +114,7 @@ int main(int argc, char *argv[]) exit(1); } } +#endif printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); for (i = 0; i < 256; i+=16) {