aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-hydra.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/i2c/busses/i2c-hydra.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/i2c/busses/i2c-hydra.c')
-rw-r--r--drivers/i2c/busses/i2c-hydra.c183
1 files changed, 183 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
new file mode 100644
index 000000000000..e0cb3b0f92fa
--- /dev/null
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -0,0 +1,183 @@
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 .mdelay = 5,
103 .timeout = HZ
104};
105
106static struct i2c_adapter hydra_adap = {
107 .owner = THIS_MODULE,
108 .name = "Hydra i2c",
109 .id = I2C_HW_B_HYDRA,
110 .algo_data = &hydra_bit_data,
111};
112
113static struct pci_device_id hydra_ids[] = {
114 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) },
115 { 0, }
116};
117
118MODULE_DEVICE_TABLE (pci, hydra_ids);
119
120static int __devinit hydra_probe(struct pci_dev *dev,
121 const struct pci_device_id *id)
122{
123 unsigned long base = pci_resource_start(dev, 0);
124 int res;
125
126 if (!request_mem_region(base+offsetof(struct Hydra, CachePD), 4,
127 hydra_adap.name))
128 return -EBUSY;
129
130 hydra_bit_data.data = ioremap(base, pci_resource_len(dev, 0));
131 if (hydra_bit_data.data == NULL) {
132 release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
133 return -ENODEV;
134 }
135
136 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
137 hydra_adap.dev.parent = &dev->dev;
138 res = i2c_bit_add_bus(&hydra_adap);
139 if (res < 0) {
140 iounmap(hydra_bit_data.data);
141 release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
142 return res;
143 }
144 return 0;
145}
146
147static void __devexit hydra_remove(struct pci_dev *dev)
148{
149 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
150 i2c_bit_del_bus(&hydra_adap);
151 iounmap(hydra_bit_data.data);
152 release_mem_region(pci_resource_start(dev, 0)+
153 offsetof(struct Hydra, CachePD), 4);
154}
155
156
157static struct pci_driver hydra_driver = {
158 .name = "hydra_smbus",
159 .id_table = hydra_ids,
160 .probe = hydra_probe,
161 .remove = __devexit_p(hydra_remove),
162};
163
164static int __init i2c_hydra_init(void)
165{
166 return pci_register_driver(&hydra_driver);
167}
168
169
170static void __exit i2c_hydra_exit(void)
171{
172 pci_unregister_driver(&hydra_driver);
173}
174
175
176
177MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
178MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O");
179MODULE_LICENSE("GPL");
180
181module_init(i2c_hydra_init);
182module_exit(i2c_hydra_exit);
183