2 i2c Support for the Apple `Hydra' Mac I/O
4 Copyright (c) 1999-2004 Geert Uytterhoeven <geert@linux-m68k.org>
6 Based on i2c Support for Via Technologies 82C586B South Bridge
7 Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27 #include <linux/types.h>
28 #include <linux/i2c.h>
29 #include <linux/i2c-algo-bit.h>
30 #include <linux/init.h>
32 #include <asm/hydra.h>
35 #define HYDRA_CPD_PD0 0x00000001 /* CachePD lines */
36 #define HYDRA_CPD_PD1 0x00000002
37 #define HYDRA_CPD_PD2 0x00000004
38 #define HYDRA_CPD_PD3 0x00000008
40 #define HYDRA_SCLK HYDRA_CPD_PD0
41 #define HYDRA_SDAT HYDRA_CPD_PD1
42 #define HYDRA_SCLK_OE 0x00000010
43 #define HYDRA_SDAT_OE 0x00000020
45 static inline void pdregw(void *data, u32 val)
47 struct Hydra *hydra = (struct Hydra *)data;
48 writel(val, &hydra->CachePD);
51 static inline u32 pdregr(void *data)
53 struct Hydra *hydra = (struct Hydra *)data;
54 return readl(&hydra->CachePD);
57 static void hydra_bit_setscl(void *data, int state)
59 u32 val = pdregr(data);
61 val &= ~HYDRA_SCLK_OE;
69 static void hydra_bit_setsda(void *data, int state)
71 u32 val = pdregr(data);
73 val &= ~HYDRA_SDAT_OE;
81 static int hydra_bit_getscl(void *data)
83 return (pdregr(data) & HYDRA_SCLK) != 0;
86 static int hydra_bit_getsda(void *data)
88 return (pdregr(data) & HYDRA_SDAT) != 0;
91 /* ------------------------------------------------------------------------ */
93 static struct i2c_algo_bit_data hydra_bit_data = {
94 .setsda = hydra_bit_setsda,
95 .setscl = hydra_bit_setscl,
96 .getsda = hydra_bit_getsda,
97 .getscl = hydra_bit_getscl,
102 static struct i2c_adapter hydra_adap = {
103 .owner = THIS_MODULE,
105 .id = I2C_HW_B_HYDRA,
106 .algo_data = &hydra_bit_data,
109 static struct pci_device_id hydra_ids[] = {
110 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) },
114 MODULE_DEVICE_TABLE (pci, hydra_ids);
116 static int __devinit hydra_probe(struct pci_dev *dev,
117 const struct pci_device_id *id)
119 unsigned long base = pci_resource_start(dev, 0);
122 if (!request_mem_region(base+offsetof(struct Hydra, CachePD), 4,
126 hydra_bit_data.data = pci_ioremap_bar(dev, 0);
127 if (hydra_bit_data.data == NULL) {
128 release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
132 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
133 hydra_adap.dev.parent = &dev->dev;
134 res = i2c_bit_add_bus(&hydra_adap);
136 iounmap(hydra_bit_data.data);
137 release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
143 static void __devexit hydra_remove(struct pci_dev *dev)
145 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
146 i2c_del_adapter(&hydra_adap);
147 iounmap(hydra_bit_data.data);
148 release_mem_region(pci_resource_start(dev, 0)+
149 offsetof(struct Hydra, CachePD), 4);
153 static struct pci_driver hydra_driver = {
154 .name = "hydra_smbus",
155 .id_table = hydra_ids,
156 .probe = hydra_probe,
157 .remove = __devexit_p(hydra_remove),
160 static int __init i2c_hydra_init(void)
162 return pci_register_driver(&hydra_driver);
166 static void __exit i2c_hydra_exit(void)
168 pci_unregister_driver(&hydra_driver);
173 MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
174 MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O");
175 MODULE_LICENSE("GPL");
177 module_init(i2c_hydra_init);
178 module_exit(i2c_hydra_exit);