34 #include <linux/module.h>
37 #include <linux/types.h>
38 #include <linux/fcntl.h>
39 #include <linux/string.h>
40 #include <linux/kernel.h>
41 #include <linux/errno.h>
48 #include <linux/bitops.h>
64 static inline int _check_irq(
int irq,
int flags)
66 if (
request_irq(irq, i365_count_irq, flags,
"x", i365_count_irq) != 0)
77 static unsigned long i365_base = 0x3e0;
79 static int extra_sockets = 0;
81 static int ignore = -1;
83 static u_int irq_mask = 0xffff;
84 static int irq_list[16];
85 static unsigned int irq_list_count;
87 static int cs_irq = 0;
90 static int do_scan = 1;
92 static int poll_interval = 0;
94 static int cycle_time = 120;
97 static int has_dma = -1;
98 static int has_led = -1;
99 static int has_ring = -1;
100 static int dynamic_mode = 0;
101 static int freq_bypass = -1;
102 static int setup_time = -1;
103 static int cmd_time = -1;
104 static int recov_time = -1;
107 static int async_clock = -1;
108 static int cable_mode = -1;
109 static int wakeup = 0;
158 static int sockets = 0;
164 #define I365_MASK 0xdeb8
168 #define ISA_LOCK(n, f) spin_lock_irqsave(&isa_lock, f)
169 #define ISA_UNLOCK(n, f) spin_unlock_irqrestore(&isa_lock, f)
183 #define IS_VADEM 0x0001
184 #define IS_CIRRUS 0x0002
185 #define IS_VIA 0x0010
186 #define IS_UNKNOWN 0x0400
187 #define IS_VG_PWR 0x0800
188 #define IS_DF_PWR 0x1000
189 #define IS_REGISTERED 0x2000
190 #define IS_ALIVE 0x8000
198 {
"Intel i82365sl A step", 0 },
199 {
"Intel i82365sl B step", 0 },
202 {
"Ricoh RF5C296/396", 0 },
203 {
"VLSI 82C146", 0 },
211 #define PCIC_COUNT (sizeof(pcic)/sizeof(pcic_t))
224 reg =
I365_REG(socket[sock].psock, reg);
225 outb(reg, port); val =
inb(port+1);
226 spin_unlock_irqrestore(&
bus_lock,flags);
238 outb(val, port);
outb(data, port+1);
239 spin_unlock_irqrestore(&
bus_lock,flags);
245 u_char d = i365_get(sock, reg);
247 i365_set(sock, reg, d);
252 u_char d = i365_get(sock, reg);
254 i365_set(sock, reg, d);
259 u_char d = i365_get(sock, reg);
264 i365_set(sock, reg, d);
270 a = i365_get(sock, reg);
271 b = i365_get(sock, reg+1);
277 i365_set(sock, reg, data & 0xff);
278 i365_set(sock, reg+1, data >> 8);
292 #define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b))))
294 static void cirrus_get_state(
u_short s)
301 for (i = 0; i < 6; i++)
305 static void cirrus_set_state(
u_short s)
317 for (i = 0; i < 6; i++)
327 if (has_ring == -1) has_ring = 1;
334 strcat(buf,
" [dyn mode]");
336 strcat(buf,
" [freq bypass]");
353 p->
timer[1] = cmd_time;
354 p->
timer[4] = cmd_time*2+4;
356 if (p->
timer[1] == 0) {
358 if (p->
timer[0] == 0)
378 static void vg46x_get_state(
u_short s)
386 static void vg46x_set_state(
u_short s)
407 strcat(buf,
" [ext mode]");
409 strcat(buf,
" [isa buf]");
425 static void get_bridge_state(
u_short s)
434 static void set_bridge_state(
u_short s)
454 for (i = s; i < s+
ns; i++) {
462 m = cirrus_set_opts(i, buf);
463 else if (socket[i].flags &
IS_VADEM)
464 m = vg46x_set_opts(i, buf);
467 (*buf) ? buf :
" none");
478 static volatile u_int irq_hits;
485 pr_debug(
"i82365: -> hit on irq %d\n", irq);
491 pr_debug(
"i82365: testing ISA irq %d\n", irq);
493 i365_count_irq) != 0)
495 irq_hits = 0; irq_sock =
sock;
499 pr_debug(
"i82365: spurious hit!\n");
512 pr_debug(
"i82365: hits = %d\n", irq_hits);
514 return (irq_hits != 1);
525 mask0 &= ~(
inb(PIC) | (
inb(PIC+1) << 8));
529 set_bridge_state(sock);
531 for (i = 0; i < 16; i++)
532 if ((mask0 & (1 << i)) && (test_irq(sock, i) == 0))
534 for (i = 0; i < 16; i++)
535 if ((mask1 & (1 << i)) && (test_irq(sock, i) != 0))
544 for (i = 0; i < 16; i++)
549 if (!cs_irq && (poll_interval == 0)) poll_interval =
HZ;
553 for (i = 0; i < 16; i++)
555 printk(
"%s%d", ((mask1 & ((1<<i)-1)) ?
"," :
""), i);
556 if (mask1 == 0)
printk(
"none!");
567 return ns/cycle_time;
588 if ((val = i365_get(sockets,
I365_IDENT)) & 0x70)
597 case 0x88:
case 0x89:
case 0x8a:
621 if ((val & PD67_INFO_CHIP_ID) == 0) {
651 ((start & 0xfeef) != 0x02e8)) {
662 static void __init add_socket(
unsigned int port,
int psock,
int type)
668 if (is_alive(sockets))
673 static void __init add_pcic(
int ns,
int type)
680 if (base == 0)
printk(
"\n");
682 printk(
" ISA-to-PCMCIA at port %#x ofs 0x%02x",
684 printk(
", %d socket%s\n", ns, ((ns > 1) ?
"s" :
""));
687 if (irq_list_count == 0)
690 for (i = mask = 0; i < irq_list_count; i++)
691 mask |= (1<<irq_list[i]);
692 mask &=
I365_MASK & set_bridge_opts(base, ns);
694 mask = isa_scan(base, mask);
697 if (!poll_interval) {
700 if ((tmp & (tmp-1)) == 0)
704 if (!grab_irq && (cs_irq || !poll_interval)) {
706 u_int cs_mask = mask & ((
cs_irq) ? (1<<cs_irq) : ~(1<<12));
707 for (cs_irq = 15; cs_irq > 0; cs_irq--)
708 if ((cs_mask & (1 << cs_irq)) &&
714 printk(
" status change on irq %d\n", cs_irq);
719 if (poll_interval == 0)
721 printk(
" polling interval = %d ms\n",
722 poll_interval * 1000 /
HZ);
727 for (i = 0; i <
ns; i++) {
750 static struct pnp_dev *i82365_pnpdev;
753 static void __init isa_probe(
void)
761 for (devid = id_table; devid->
vendor; devid++) {
768 printk(
"activate failed\n");
773 if (!pnp_port_valid(dev, 0)) {
774 printk(
"invalid resources ?\n");
778 i365_base = pnp_port_start(dev, 0);
787 printk(
"port conflict at %#lx\n", i365_base);
791 id = identify(i365_base, 0);
792 if ((
id ==
IS_I82365DF) && (identify(i365_base, 1) !=
id)) {
793 for (i = 0; i < 4; i++) {
794 if (i == ignore)
continue;
795 port = i365_base + ((i & 1) << 2) + ((i & 2) << 1);
798 add_socket(port, sock,
IS_VLSI);
803 for (i = 0; i < 8; i += 2) {
804 if (sockets && !extra_sockets && (i == 4))
806 port = i365_base + 2*(i>>2);
808 id = identify(port, sock);
809 if (
id < 0)
continue;
811 for (j = ns = 0; j < 2; j++) {
813 if ((ignore == i+j) || (identify(port, sock+j) < 0))
816 for (k = 0; k <= sockets; k++)
818 for (k = 0; k <= sockets; k++)
821 if (k <= sockets)
break;
822 add_socket(port, sock+j,
id); ns++;
824 if (ns != 0) add_pcic(ns,
id);
831 static irqreturn_t pcic_interrupt(
int irq,
void *dev)
838 pr_debug(
"pcic_interrupt(%d)\n", irq);
840 for (j = 0; j < 20; j++) {
842 for (i = 0; i < sockets; i++) {
843 if (socket[i].cs_irq != irq)
848 if ((csc == 0) || (i365_get(i,
I365_IDENT) & 0x70)) {
862 pr_debug(
"socket %d event 0x%02x\n", i, events);
878 static void pcic_interrupt_wrapper(
u_long data)
880 pcic_interrupt(0,
NULL);
881 poll_timer.expires =
jiffies + poll_interval;
905 if (socket[sock].type ==
IS_VG469) {
907 if (socket[sock].psock & 1) {
916 pr_debug(
"GetStatus(%d) = %#4.4x\n", sock, *value);
927 pr_debug(
"SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
928 "io_irq %d, csc_mask %#2.2x)\n", sock, state->
flags,
932 set_bridge_state(sock);
945 if (t->
flags & IS_CIRRUS) {
946 if (state->
Vpp != 0) {
947 if (state->
Vpp == 120)
949 else if (state->
Vpp == state->
Vcc)
953 if (state->
Vcc != 0) {
955 if (state->
Vcc == 33)
957 else if (state->
Vcc == 50)
962 if (state->
Vpp != 0) {
963 if (state->
Vpp == 120)
965 else if (state->
Vpp == state->
Vcc)
969 if (state->
Vcc != 0) {
971 if (state->
Vcc == 33)
973 else if (state->
Vcc == 50)
978 switch (state->
Vcc) {
984 switch (state->
Vpp) {
991 switch (state->
Vcc) {
996 switch (state->
Vpp) {
1008 if (t->
flags & IS_CIRRUS) {
1036 pr_debug(
"SetIOMap(%d, %d, %#2.2x, %d ns, "
1038 (
unsigned long long)io->
start, (
unsigned long long)io->
stop);
1040 if ((map > 1) || (io->
start > 0xffff) || (io->
stop > 0xffff) ||
1066 pr_debug(
"SetMemMap(%d, %d, %#2.2x, %d ns, %#llx-%#llx, "
1068 (
unsigned long long)mem->
res->start,
1072 if ((map > 4) || (mem->
card_start > 0x3ffffff) ||
1073 (mem->
res->start > mem->
res->end) || (mem->
speed > 1000))
1075 if ((mem->
res->start > 0xffffff) || (mem->
res->end > 0xffffff))
1083 i = (mem->
res->start >> 12) & 0x0fff;
1088 i = (mem->
res->end >> 12) & 0x0fff;
1116 static ssize_t show_info(
struct class_device *class_dev,
char *buf)
1119 return sprintf(buf,
"type: %s\npsock: %d\n",
1123 static ssize_t show_exca(
struct class_device *class_dev,
char *buf)
1126 unsigned short sock;
1129 unsigned long flags = 0;
1134 for (i = 0; i < 0x40; i += 4) {
1135 ret +=
sprintf(buf,
"%02x %02x %02x %02x%s",
1136 i365_get(sock,i), i365_get(sock,i+1),
1137 i365_get(sock,i+2), i365_get(sock,i+3),
1138 ((i % 16) == 12) ?
"\n" :
" ");
1146 static CLASS_DEVICE_ATTR(exca,
S_IRUGO, show_exca,
NULL);
1154 #define LOCKED(x) do { \
1156 unsigned long flags; \
1157 spin_lock_irqsave(&isa_lock, flags); \
1159 spin_unlock_irqrestore(&isa_lock, flags); \
1168 if (socket[sock].flags & IS_ALIVE) {
1173 LOCKED(i365_get_status(sock, value));
1180 if (socket[sock].flags & IS_ALIVE)
1183 LOCKED(i365_set_socket(sock, state));
1189 if (socket[sock].flags & IS_ALIVE)
1192 LOCKED(i365_set_io_map(sock, io));
1198 if (socket[sock].flags & IS_ALIVE)
1201 LOCKED(i365_set_mem_map(sock, mem));
1207 struct resource res = { .start = 0, .end = 0x1000 };
1211 for (i = 0; i < 2; i++) {
1213 pcic_set_io_map(s, &io);
1215 for (i = 0; i < 5; i++) {
1217 pcic_set_mem_map(s, &mem);
1225 .get_status = pcic_get_status,
1226 .set_socket = pcic_set_socket,
1227 .set_io_map = pcic_set_io_map,
1228 .set_mem_map = pcic_set_mem_map,
1242 static int __init init_i82365(
void)
1251 if (i82365_device) {
1259 goto err_driver_unregister;
1269 goto err_dev_unregister;
1274 ret =
request_irq(cs_irq, pcic_interrupt, 0,
"i82365", pcic_interrupt);
1277 goto err_socket_release;
1280 for (i = 0; i < sockets; i++) {
1281 socket[
i].
socket.dev.parent = &i82365_device->
dev;
1282 socket[
i].
socket.ops = &pcic_operations;
1291 class_device_create_file(&socket[i].socket.dev,
1292 &class_device_attr_info);
1293 class_device_create_file(&socket[i].socket.dev,
1294 &class_device_attr_exca);
1299 if (poll_interval != 0) {
1300 poll_timer.function = pcic_interrupt_wrapper;
1301 poll_timer.data = 0;
1303 poll_timer.expires =
jiffies + poll_interval;
1309 for (i = 0; i < sockets; i++) {
1321 err_driver_unregister:
1327 static void __exit exit_i82365(
void)
1331 for (i = 0; i < sockets; i++) {
1336 if (poll_interval != 0)
1340 for (i = 0; i < sockets; i++) {