Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.25 182 lines 4.5 kB view raw
1/* 2 i2c-hydra.c - Part of lm_sensors, Linux kernel modules 3 for hardware monitoring 4 5 i2c Support for the Apple `Hydra' Mac I/O 6 7 Copyright (c) 1999-2004 Geert Uytterhoeven <geert@linux-m68k.org> 8 9 Based on i2c Support for Via Technologies 82C586B South Bridge 10 Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi> 11 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25*/ 26 27#include <linux/kernel.h> 28#include <linux/module.h> 29#include <linux/pci.h> 30#include <linux/types.h> 31#include <linux/i2c.h> 32#include <linux/i2c-algo-bit.h> 33#include <linux/init.h> 34#include <asm/io.h> 35#include <asm/hydra.h> 36 37 38#define HYDRA_CPD_PD0 0x00000001 /* CachePD lines */ 39#define HYDRA_CPD_PD1 0x00000002 40#define HYDRA_CPD_PD2 0x00000004 41#define HYDRA_CPD_PD3 0x00000008 42 43#define HYDRA_SCLK HYDRA_CPD_PD0 44#define HYDRA_SDAT HYDRA_CPD_PD1 45#define HYDRA_SCLK_OE 0x00000010 46#define HYDRA_SDAT_OE 0x00000020 47 48static inline void pdregw(void *data, u32 val) 49{ 50 struct Hydra *hydra = (struct Hydra *)data; 51 writel(val, &hydra->CachePD); 52} 53 54static inline u32 pdregr(void *data) 55{ 56 struct Hydra *hydra = (struct Hydra *)data; 57 return readl(&hydra->CachePD); 58} 59 60static void hydra_bit_setscl(void *data, int state) 61{ 62 u32 val = pdregr(data); 63 if (state) 64 val &= ~HYDRA_SCLK_OE; 65 else { 66 val &= ~HYDRA_SCLK; 67 val |= HYDRA_SCLK_OE; 68 } 69 pdregw(data, val); 70} 71 72static void hydra_bit_setsda(void *data, int state) 73{ 74 u32 val = pdregr(data); 75 if (state) 76 val &= ~HYDRA_SDAT_OE; 77 else { 78 val &= ~HYDRA_SDAT; 79 val |= HYDRA_SDAT_OE; 80 } 81 pdregw(data, val); 82} 83 84static int hydra_bit_getscl(void *data) 85{ 86 return (pdregr(data) & HYDRA_SCLK) != 0; 87} 88 89static int hydra_bit_getsda(void *data) 90{ 91 return (pdregr(data) & HYDRA_SDAT) != 0; 92} 93 94/* ------------------------------------------------------------------------ */ 95 96static struct i2c_algo_bit_data hydra_bit_data = { 97 .setsda = hydra_bit_setsda, 98 .setscl = hydra_bit_setscl, 99 .getsda = hydra_bit_getsda, 100 .getscl = hydra_bit_getscl, 101 .udelay = 5, 102 .timeout = HZ 103}; 104 105static struct i2c_adapter hydra_adap = { 106 .owner = THIS_MODULE, 107 .name = "Hydra i2c", 108 .id = I2C_HW_B_HYDRA, 109 .algo_data = &hydra_bit_data, 110}; 111 112static struct pci_device_id hydra_ids[] = { 113 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) }, 114 { 0, } 115}; 116 117MODULE_DEVICE_TABLE (pci, hydra_ids); 118 119static int __devinit hydra_probe(struct pci_dev *dev, 120 const struct pci_device_id *id) 121{ 122 unsigned long base = pci_resource_start(dev, 0); 123 int res; 124 125 if (!request_mem_region(base+offsetof(struct Hydra, CachePD), 4, 126 hydra_adap.name)) 127 return -EBUSY; 128 129 hydra_bit_data.data = ioremap(base, pci_resource_len(dev, 0)); 130 if (hydra_bit_data.data == NULL) { 131 release_mem_region(base+offsetof(struct Hydra, CachePD), 4); 132 return -ENODEV; 133 } 134 135 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */ 136 hydra_adap.dev.parent = &dev->dev; 137 res = i2c_bit_add_bus(&hydra_adap); 138 if (res < 0) { 139 iounmap(hydra_bit_data.data); 140 release_mem_region(base+offsetof(struct Hydra, CachePD), 4); 141 return res; 142 } 143 return 0; 144} 145 146static void __devexit hydra_remove(struct pci_dev *dev) 147{ 148 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */ 149 i2c_del_adapter(&hydra_adap); 150 iounmap(hydra_bit_data.data); 151 release_mem_region(pci_resource_start(dev, 0)+ 152 offsetof(struct Hydra, CachePD), 4); 153} 154 155 156static struct pci_driver hydra_driver = { 157 .name = "hydra_smbus", 158 .id_table = hydra_ids, 159 .probe = hydra_probe, 160 .remove = __devexit_p(hydra_remove), 161}; 162 163static int __init i2c_hydra_init(void) 164{ 165 return pci_register_driver(&hydra_driver); 166} 167 168 169static void __exit i2c_hydra_exit(void) 170{ 171 pci_unregister_driver(&hydra_driver); 172} 173 174 175 176MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); 177MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O"); 178MODULE_LICENSE("GPL"); 179 180module_init(i2c_hydra_init); 181module_exit(i2c_hydra_exit); 182