26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/module.h>
29 #include <linux/errno.h>
30 #include <linux/kernel.h>
32 #include <linux/i2c.h>
33 #include <linux/pci.h>
37 #include <linux/slab.h>
52 #define POLL_TIMEOUT (HZ/5)
64 static const char *scx200_acb_state_name[] = {
92 #define ACBSDA (iface->base + 0)
93 #define ACBST (iface->base + 1)
94 #define ACBST_SDAST 0x40
95 #define ACBST_BER 0x20
96 #define ACBST_NEGACK 0x10
97 #define ACBST_STASTR 0x08
98 #define ACBST_MASTER 0x02
99 #define ACBCST (iface->base + 2)
100 #define ACBCST_BB 0x02
101 #define ACBCTL1 (iface->base + 3)
102 #define ACBCTL1_STASTRE 0x80
103 #define ACBCTL1_NMINTE 0x40
104 #define ACBCTL1_ACK 0x10
105 #define ACBCTL1_STOP 0x02
106 #define ACBCTL1_START 0x01
107 #define ACBADDR (iface->base + 4)
108 #define ACBCTL2 (iface->base + 5)
109 #define ACBCTL2_ENABLE 0x01
118 scx200_acb_state_name[iface->
state], status);
121 errmsg =
"bus error";
125 errmsg =
"not master";
130 scx200_acb_state_name[iface->
state]);
143 switch (iface->
state) {
191 if (iface->
len == 1) {
203 if (iface->
len == 0) {
220 "%s in state %s (addr=0x%02x, len=%d, status=0x%02x)\n", errmsg,
242 scx200_acb_machine(iface, status);
252 scx200_acb_state_name[iface->
state]);
304 buffer = &data->
byte;
310 buffer = (
u8 *)&cur_word;
314 len = data->
block[0];
317 buffer = &data->
block[1];
325 "size=%d, address=0x%x, command=0x%x, len=%d, read=%d\n",
326 size, address, command, len, rw);
350 scx200_acb_poll(iface);
353 scx200_acb_reset(iface);
363 dev_dbg(&adapter->
dev,
"transfer done, result: %d", rc);
367 for (i = 0; i <
len; ++
i)
368 printk(
" %02x", buffer[i]);
385 .smbus_xfer = scx200_acb_smbus_xfer,
386 .functionality = scx200_acb_func,
401 pr_debug(
"ACBCTL2 readback failed\n");
409 pr_debug(
"disabled, but ACBCTL1=0x%02x\n", val);
419 pr_debug(
"enabled, but NMINTE won't be set, ACBCTL1=0x%02x\n",
435 pr_err(
"can't allocate memory\n");
440 i2c_set_adapdata(adapter, iface);
443 adapter->
algo = &scx200_acb_algorithm;
445 adapter->
dev.parent =
dev;
459 rc = scx200_acb_probe(iface);
465 scx200_acb_reset(iface);
468 pr_err(
"failed to register\n");
472 if (!adapter->
dev.parent) {
475 iface->
next = scx200_acb_list;
476 scx200_acb_list = iface;
484 unsigned long base,
int index,
struct device *dev)
489 iface = scx200_create_iface(text, dev, index);
495 pr_err(
"can't allocate io 0x%lx-0x%lx\n", base, base + 8 - 1);
500 rc = scx200_acb_create(iface);
518 dev_err(&pdev->
dev,
"can't fetch device resource info\n");
522 iface = scx200_create_dev(
"CS5535", res->
start, 0, &pdev->
dev);
526 dev_info(&pdev->
dev,
"SCx200 device '%s' registered\n",
528 platform_set_drvdata(pdev, iface);
544 iface = platform_get_drvdata(pdev);
545 platform_set_drvdata(pdev,
NULL);
546 scx200_cleanup_iface(iface);
553 .name =
"cs5535-smb",
556 .probe = scx200_probe,
566 static __init void scx200_scan_isa(
void)
578 scx200_create_dev(
"SCx200", base[i], i,
NULL);
582 static int __init scx200_acb_init(
void)
584 pr_debug(
"NatSemi SCx200 ACCESS.bus Driver\n");
597 static void __exit scx200_acb_cleanup(
void)
604 while ((iface = scx200_acb_list) !=
NULL) {
605 scx200_acb_list = iface->
next;
608 scx200_cleanup_iface(iface);