blob: 8e646bdb556c8d52b2fb4852a57f94e5cbb4d4af [file] [log] [blame]
Ben Gardner99c3adb2006-01-18 22:41:50 +01001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
3
4 National Semiconductor SCx200 ACCESS.bus support
Ben Gardner16ffc5c2006-01-18 22:48:26 +01005 Also supports the AMD CS5535 and AMD CS5536
Ben Gardner99c3adb2006-01-18 22:41:50 +01006
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 Based on i2c-keywest.c which is:
8 Copyright (c) 2001 Benjamin Herrenschmidt <benh@kernel.crashing.org>
9 Copyright (c) 2000 Philip Edelbrock <phil@stimpy.netroedge.com>
Ben Gardner99c3adb2006-01-18 22:41:50 +010010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
Ben Gardner99c3adb2006-01-18 22:41:50 +010015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
Ben Gardner99c3adb2006-01-18 22:41:50 +010020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070024*/
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/module.h>
27#include <linux/errno.h>
28#include <linux/kernel.h>
29#include <linux/init.h>
30#include <linux/i2c.h>
31#include <linux/smp_lock.h>
32#include <linux/pci.h>
33#include <linux/delay.h>
34#include <asm/io.h>
Ben Gardner16ffc5c2006-01-18 22:48:26 +010035#include <asm/msr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <linux/scx200.h>
38
39#define NAME "scx200_acb"
40
41MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
42MODULE_DESCRIPTION("NatSemi SCx200 ACCESS.bus Driver");
43MODULE_LICENSE("GPL");
44
45#define MAX_DEVICES 4
46static int base[MAX_DEVICES] = { 0x820, 0x840 };
47module_param_array(base, int, NULL, 0);
48MODULE_PARM_DESC(base, "Base addresses for the ACCESS.bus controllers");
49
Ben Gardnerf933ff52006-01-18 22:52:06 +010050#define POLL_TIMEOUT (HZ/5)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52enum scx200_acb_state {
53 state_idle,
54 state_address,
55 state_command,
56 state_repeat_start,
57 state_quick,
58 state_read,
59 state_write,
60};
61
62static const char *scx200_acb_state_name[] = {
63 "idle",
64 "address",
65 "command",
66 "repeat_start",
67 "quick",
68 "read",
69 "write",
70};
71
72/* Physical interface */
Ben Gardner99c3adb2006-01-18 22:41:50 +010073struct scx200_acb_iface {
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 struct scx200_acb_iface *next;
75 struct i2c_adapter adapter;
76 unsigned base;
77 struct semaphore sem;
78
79 /* State machine data */
80 enum scx200_acb_state state;
81 int result;
82 u8 address_byte;
83 u8 command;
84 u8 *ptr;
85 char needs_reset;
86 unsigned len;
87};
88
89/* Register Definitions */
90#define ACBSDA (iface->base + 0)
91#define ACBST (iface->base + 1)
92#define ACBST_SDAST 0x40 /* SDA Status */
Ben Gardner99c3adb2006-01-18 22:41:50 +010093#define ACBST_BER 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define ACBST_NEGACK 0x10 /* Negative Acknowledge */
95#define ACBST_STASTR 0x08 /* Stall After Start */
96#define ACBST_MASTER 0x02
97#define ACBCST (iface->base + 2)
98#define ACBCST_BB 0x02
99#define ACBCTL1 (iface->base + 3)
100#define ACBCTL1_STASTRE 0x80
101#define ACBCTL1_NMINTE 0x40
Ben Gardner99c3adb2006-01-18 22:41:50 +0100102#define ACBCTL1_ACK 0x10
103#define ACBCTL1_STOP 0x02
104#define ACBCTL1_START 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#define ACBADDR (iface->base + 4)
106#define ACBCTL2 (iface->base + 5)
107#define ACBCTL2_ENABLE 0x01
108
109/************************************************************************/
110
111static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
112{
113 const char *errmsg;
114
Ben Gardneref4d9272006-01-18 22:43:10 +0100115 dev_dbg(&iface->adapter.dev, "state %s, status = 0x%02x\n",
116 scx200_acb_state_name[iface->state], status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 if (status & ACBST_BER) {
119 errmsg = "bus error";
120 goto error;
121 }
122 if (!(status & ACBST_MASTER)) {
123 errmsg = "not master";
124 goto error;
125 }
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100126 if (status & ACBST_NEGACK) {
127 dev_dbg(&iface->adapter.dev, "negative ack in state %s\n",
128 scx200_acb_state_name[iface->state]);
129
130 iface->state = state_idle;
131 iface->result = -ENXIO;
132
133 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
134 outb(ACBST_STASTR | ACBST_NEGACK, ACBST);
135 return;
136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 switch (iface->state) {
139 case state_idle:
140 dev_warn(&iface->adapter.dev, "interrupt in idle state\n");
141 break;
142
143 case state_address:
144 /* Do a pointer write first */
145 outb(iface->address_byte & ~1, ACBSDA);
146
147 iface->state = state_command;
148 break;
149
150 case state_command:
151 outb(iface->command, ACBSDA);
152
153 if (iface->address_byte & 1)
154 iface->state = state_repeat_start;
155 else
156 iface->state = state_write;
157 break;
158
159 case state_repeat_start:
160 outb(inb(ACBCTL1) | ACBCTL1_START, ACBCTL1);
161 /* fallthrough */
Ben Gardner99c3adb2006-01-18 22:41:50 +0100162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 case state_quick:
164 if (iface->address_byte & 1) {
Ben Gardner99c3adb2006-01-18 22:41:50 +0100165 if (iface->len == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 outb(inb(ACBCTL1) | ACBCTL1_ACK, ACBCTL1);
167 else
168 outb(inb(ACBCTL1) & ~ACBCTL1_ACK, ACBCTL1);
169 outb(iface->address_byte, ACBSDA);
170
171 iface->state = state_read;
172 } else {
173 outb(iface->address_byte, ACBSDA);
174
175 iface->state = state_write;
176 }
177 break;
178
179 case state_read:
180 /* Set ACK if receiving the last byte */
181 if (iface->len == 1)
182 outb(inb(ACBCTL1) | ACBCTL1_ACK, ACBCTL1);
183 else
184 outb(inb(ACBCTL1) & ~ACBCTL1_ACK, ACBCTL1);
185
186 *iface->ptr++ = inb(ACBSDA);
187 --iface->len;
188
189 if (iface->len == 0) {
190 iface->result = 0;
191 iface->state = state_idle;
192 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
193 }
194
195 break;
196
197 case state_write:
198 if (iface->len == 0) {
199 iface->result = 0;
200 iface->state = state_idle;
201 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
202 break;
203 }
Ben Gardner99c3adb2006-01-18 22:41:50 +0100204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 outb(*iface->ptr++, ACBSDA);
206 --iface->len;
Ben Gardner99c3adb2006-01-18 22:41:50 +0100207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 break;
209 }
210
211 return;
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 error:
214 dev_err(&iface->adapter.dev, "%s in state %s\n", errmsg,
215 scx200_acb_state_name[iface->state]);
216
217 iface->state = state_idle;
218 iface->result = -EIO;
219 iface->needs_reset = 1;
220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static void scx200_acb_poll(struct scx200_acb_iface *iface)
223{
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100224 u8 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 unsigned long timeout;
226
227 timeout = jiffies + POLL_TIMEOUT;
228 while (time_before(jiffies, timeout)) {
229 status = inb(ACBST);
230 if ((status & (ACBST_SDAST|ACBST_BER|ACBST_NEGACK)) != 0) {
231 scx200_acb_machine(iface, status);
232 return;
233 }
Ben Gardnerf933ff52006-01-18 22:52:06 +0100234 yield();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
236
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100237 dev_err(&iface->adapter.dev, "timeout in state %s\n",
238 scx200_acb_state_name[iface->state]);
239
240 iface->state = state_idle;
241 iface->result = -EIO;
242 iface->needs_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245static void scx200_acb_reset(struct scx200_acb_iface *iface)
246{
247 /* Disable the ACCESS.bus device and Configure the SCL
Ben Gardner99c3adb2006-01-18 22:41:50 +0100248 frequency: 16 clock cycles */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 outb(0x70, ACBCTL2);
250 /* Polling mode */
251 outb(0, ACBCTL1);
252 /* Disable slave address */
253 outb(0, ACBADDR);
254 /* Enable the ACCESS.bus device */
255 outb(inb(ACBCTL2) | ACBCTL2_ENABLE, ACBCTL2);
256 /* Free STALL after START */
257 outb(inb(ACBCTL1) & ~(ACBCTL1_STASTRE | ACBCTL1_NMINTE), ACBCTL1);
258 /* Send a STOP */
259 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
260 /* Clear BER, NEGACK and STASTR bits */
261 outb(ACBST_BER | ACBST_NEGACK | ACBST_STASTR, ACBST);
262 /* Clear BB bit */
263 outb(inb(ACBCST) | ACBCST_BB, ACBCST);
264}
265
266static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
Ben Gardner99c3adb2006-01-18 22:41:50 +0100267 u16 address, unsigned short flags,
268 char rw, u8 command, int size,
269 union i2c_smbus_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
271 struct scx200_acb_iface *iface = i2c_get_adapdata(adapter);
272 int len;
273 u8 *buffer;
274 u16 cur_word;
275 int rc;
276
277 switch (size) {
278 case I2C_SMBUS_QUICK:
Ben Gardner99c3adb2006-01-18 22:41:50 +0100279 len = 0;
280 buffer = NULL;
281 break;
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 case I2C_SMBUS_BYTE:
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100284 len = 1;
285 buffer = rw ? &data->byte : &command;
Ben Gardner99c3adb2006-01-18 22:41:50 +0100286 break;
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 case I2C_SMBUS_BYTE_DATA:
Ben Gardner99c3adb2006-01-18 22:41:50 +0100289 len = 1;
290 buffer = &data->byte;
291 break;
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 case I2C_SMBUS_WORD_DATA:
294 len = 2;
Ben Gardner99c3adb2006-01-18 22:41:50 +0100295 cur_word = cpu_to_le16(data->word);
296 buffer = (u8 *)&cur_word;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 break;
Ben Gardner99c3adb2006-01-18 22:41:50 +0100298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 case I2C_SMBUS_BLOCK_DATA:
Ben Gardner99c3adb2006-01-18 22:41:50 +0100300 len = data->block[0];
301 buffer = &data->block[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 break;
Ben Gardner99c3adb2006-01-18 22:41:50 +0100303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 default:
Ben Gardner99c3adb2006-01-18 22:41:50 +0100305 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307
Ben Gardneref4d9272006-01-18 22:43:10 +0100308 dev_dbg(&adapter->dev,
309 "size=%d, address=0x%x, command=0x%x, len=%d, read=%d\n",
310 size, address, command, len, rw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 if (!len && rw == I2C_SMBUS_READ) {
Ben Gardneref4d9272006-01-18 22:43:10 +0100313 dev_dbg(&adapter->dev, "zero length read\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 return -EINVAL;
315 }
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 down(&iface->sem);
318
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100319 iface->address_byte = (address << 1) | rw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 iface->command = command;
321 iface->ptr = buffer;
322 iface->len = len;
323 iface->result = -EINVAL;
324 iface->needs_reset = 0;
325
326 outb(inb(ACBCTL1) | ACBCTL1_START, ACBCTL1);
327
328 if (size == I2C_SMBUS_QUICK || size == I2C_SMBUS_BYTE)
329 iface->state = state_quick;
330 else
331 iface->state = state_address;
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 while (iface->state != state_idle)
334 scx200_acb_poll(iface);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 if (iface->needs_reset)
337 scx200_acb_reset(iface);
338
339 rc = iface->result;
340
341 up(&iface->sem);
342
343 if (rc == 0 && size == I2C_SMBUS_WORD_DATA && rw == I2C_SMBUS_READ)
Ben Gardner99c3adb2006-01-18 22:41:50 +0100344 data->word = le16_to_cpu(cur_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346#ifdef DEBUG
Ben Gardneref4d9272006-01-18 22:43:10 +0100347 dev_dbg(&adapter->dev, "transfer done, result: %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (buffer) {
349 int i;
350 printk(" data:");
351 for (i = 0; i < len; ++i)
352 printk(" %02x", buffer[i]);
353 }
354 printk("\n");
355#endif
356
357 return rc;
358}
359
360static u32 scx200_acb_func(struct i2c_adapter *adapter)
361{
362 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
363 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
364 I2C_FUNC_SMBUS_BLOCK_DATA;
365}
366
367/* For now, we only handle combined mode (smbus) */
368static struct i2c_algorithm scx200_acb_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 .smbus_xfer = scx200_acb_smbus_xfer,
370 .functionality = scx200_acb_func,
371};
372
373static struct scx200_acb_iface *scx200_acb_list;
Ben Gardner8a059402006-01-18 22:46:26 +0100374static DECLARE_MUTEX(scx200_acb_list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376static int scx200_acb_probe(struct scx200_acb_iface *iface)
377{
378 u8 val;
379
380 /* Disable the ACCESS.bus device and Configure the SCL
Ben Gardner99c3adb2006-01-18 22:41:50 +0100381 frequency: 16 clock cycles */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 outb(0x70, ACBCTL2);
383
384 if (inb(ACBCTL2) != 0x70) {
Ben Gardneref4d9272006-01-18 22:43:10 +0100385 pr_debug(NAME ": ACBCTL2 readback failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 return -ENXIO;
387 }
388
389 outb(inb(ACBCTL1) | ACBCTL1_NMINTE, ACBCTL1);
390
391 val = inb(ACBCTL1);
392 if (val) {
Ben Gardneref4d9272006-01-18 22:43:10 +0100393 pr_debug(NAME ": disabled, but ACBCTL1=0x%02x\n",
394 val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return -ENXIO;
396 }
397
398 outb(inb(ACBCTL2) | ACBCTL2_ENABLE, ACBCTL2);
399
400 outb(inb(ACBCTL1) | ACBCTL1_NMINTE, ACBCTL1);
401
402 val = inb(ACBCTL1);
403 if ((val & ACBCTL1_NMINTE) != ACBCTL1_NMINTE) {
Ben Gardneref4d9272006-01-18 22:43:10 +0100404 pr_debug(NAME ": enabled, but NMINTE won't be set, "
405 "ACBCTL1=0x%02x\n", val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return -ENXIO;
407 }
408
409 return 0;
410}
411
Ben Gardner16ffc5c2006-01-18 22:48:26 +0100412static int __init scx200_acb_create(const char *text, int base, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
414 struct scx200_acb_iface *iface;
415 struct i2c_adapter *adapter;
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100416 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 char description[64];
418
Deepak Saxena5263ebb2005-10-17 23:09:43 +0200419 iface = kzalloc(sizeof(*iface), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (!iface) {
421 printk(KERN_ERR NAME ": can't allocate memory\n");
422 rc = -ENOMEM;
423 goto errout;
424 }
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 adapter = &iface->adapter;
427 i2c_set_adapdata(adapter, iface);
Ben Gardner16ffc5c2006-01-18 22:48:26 +0100428 snprintf(adapter->name, I2C_NAME_SIZE, "%s ACB%d", text, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 adapter->owner = THIS_MODULE;
Jean Delvare1684a9842005-08-11 23:51:10 +0200430 adapter->id = I2C_HW_SMBUS_SCX200;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 adapter->algo = &scx200_acb_algorithm;
432 adapter->class = I2C_CLASS_HWMON;
433
434 init_MUTEX(&iface->sem);
435
Ben Gardner16ffc5c2006-01-18 22:48:26 +0100436 snprintf(description, sizeof(description), "%s ACCESS.bus [%s]",
437 text, adapter->name);
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (request_region(base, 8, description) == 0) {
Ben Gardneref4d9272006-01-18 22:43:10 +0100440 printk(KERN_ERR NAME ": can't allocate io 0x%x-0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 base, base + 8-1);
442 rc = -EBUSY;
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100443 goto errout_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445 iface->base = base;
446
447 rc = scx200_acb_probe(iface);
448 if (rc) {
Ben Gardneref4d9272006-01-18 22:43:10 +0100449 printk(KERN_WARNING NAME ": probe failed\n");
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100450 goto errout_release;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
452
453 scx200_acb_reset(iface);
454
455 if (i2c_add_adapter(adapter) < 0) {
Ben Gardneref4d9272006-01-18 22:43:10 +0100456 printk(KERN_ERR NAME ": failed to register\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 rc = -ENODEV;
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100458 goto errout_release;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
460
Ben Gardner8a059402006-01-18 22:46:26 +0100461 down(&scx200_acb_list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 iface->next = scx200_acb_list;
463 scx200_acb_list = iface;
Ben Gardner8a059402006-01-18 22:46:26 +0100464 up(&scx200_acb_list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 return 0;
467
Ben Gardner9b7b6d32006-01-18 22:44:04 +0100468 errout_release:
469 release_region(iface->base, 8);
470 errout_free:
471 kfree(iface);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 errout:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return rc;
474}
475
476static struct pci_device_id scx200[] = {
477 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
478 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
479 { },
480};
481
Ben Gardner16ffc5c2006-01-18 22:48:26 +0100482static struct pci_device_id divil_pci[] = {
483 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
484 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
485 { } /* NULL entry */
486};
487
488#define MSR_LBAR_SMB 0x5140000B
489
490static int scx200_add_cs553x(void)
491{
492 u32 low, hi;
493 u32 smb_base;
494
495 /* Grab & reserve the SMB I/O range */
496 rdmsr(MSR_LBAR_SMB, low, hi);
497
498 /* Check the IO mask and whether SMB is enabled */
499 if (hi != 0x0000F001) {
500 printk(KERN_WARNING NAME ": SMBus not enabled\n");
501 return -ENODEV;
502 }
503
504 /* SMBus IO size is 8 bytes */
505 smb_base = low & 0x0000FFF8;
506
507 return scx200_acb_create("CS5535", smb_base, 0);
508}
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510static int __init scx200_acb_init(void)
511{
512 int i;
Ben Gardner16ffc5c2006-01-18 22:48:26 +0100513 int rc = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 pr_debug(NAME ": NatSemi SCx200 ACCESS.bus Driver\n");
516
517 /* Verify that this really is a SCx200 processor */
Ben Gardner16ffc5c2006-01-18 22:48:26 +0100518 if (pci_dev_present(scx200)) {
519 for (i = 0; i < MAX_DEVICES; ++i) {
520 if (base[i] > 0)
521 rc = scx200_acb_create("SCx200", base[i], i);
522 }
523 } else if (pci_dev_present(divil_pci))
524 rc = scx200_add_cs553x();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return rc;
527}
528
529static void __exit scx200_acb_cleanup(void)
530{
531 struct scx200_acb_iface *iface;
Ben Gardner99c3adb2006-01-18 22:41:50 +0100532
Ben Gardner8a059402006-01-18 22:46:26 +0100533 down(&scx200_acb_list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 while ((iface = scx200_acb_list) != NULL) {
535 scx200_acb_list = iface->next;
Ben Gardner8a059402006-01-18 22:46:26 +0100536 up(&scx200_acb_list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 i2c_del_adapter(&iface->adapter);
539 release_region(iface->base, 8);
540 kfree(iface);
Ben Gardner8a059402006-01-18 22:46:26 +0100541 down(&scx200_acb_list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
Ben Gardner8a059402006-01-18 22:46:26 +0100543 up(&scx200_acb_list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
546module_init(scx200_acb_init);
547module_exit(scx200_acb_cleanup);