14 #include <linux/pci.h>
18 #include <linux/module.h>
20 #include <linux/slab.h>
27 static bool disable_clkrun;
29 MODULE_PARM_DESC(disable_clkrun,
"If PC card doesn't function properly, please try this option");
31 static bool isa_probe = 1;
33 MODULE_PARM_DESC(isa_probe,
"If set ISA interrupts are probed (default). Set to N to disable probing");
35 static bool pwr_irqs_off;
37 MODULE_PARM_DESC(pwr_irqs_off,
"Force IRQs off during power-on of slot. Use only when seeing IRQ storms!");
39 static char o2_speedup[] =
"default";
41 MODULE_PARM_DESC(o2_speedup,
"Use prefetch/burst for O2-bridges: 'on', 'off' "
42 "or 'default' (uses recommended behaviour for the detected bridge)");
53 static u32 isa_interrupts = 0x0ef8;
56 #define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args)
59 #define to_cycles(ns) ((ns)/120)
60 #define to_ns(cycles) ((cycles)*120)
66 #ifdef CONFIG_YENTA_TI
73 static unsigned int override_bios;
85 debug(
"%04x %08x\n", socket, reg, val);
91 debug(
"%04x %08x\n", socket, reg, val);
99 pci_read_config_byte(socket->
dev, offset, &val);
100 debug(
"%04x %02x\n", socket, offset, val);
107 pci_read_config_word(socket->
dev, offset, &val);
108 debug(
"%04x %04x\n", socket, offset, val);
115 pci_read_config_dword(socket->
dev, offset, &val);
116 debug(
"%04x %08x\n", socket, offset, val);
122 debug(
"%04x %02x\n", socket, offset, val);
123 pci_write_config_byte(socket->
dev, offset, val);
128 debug(
"%04x %04x\n", socket, offset, val);
129 pci_write_config_word(socket->
dev, offset, val);
134 debug(
"%04x %08x\n", socket, offset, val);
135 pci_write_config_dword(socket->
dev, offset, val);
141 debug(
"%04x %02x\n", socket, reg, val);
149 val |=
readb(socket->
base + 0x800 + reg + 1) << 8;
150 debug(
"%04x %04x\n", socket, reg, val);
156 debug(
"%04x %02x\n", socket, reg, val);
163 debug(
"%04x %04x\n", socket, reg, val);
165 writeb(val >> 8, socket->
base + 0x800 + reg + 1);
179 for (
i = 0;
i < 0x24;
i += 4) {
183 val = cb_readl(socket,
i);
188 for (
i = 0;
i < 0x45;
i++) {
192 memcpy(buf + offset,
" -", 2);
197 val = exca_readb(socket,
i);
200 buf[offset++] =
'\n';
256 switch (state->
Vcc) {
267 switch (state->
Vpp) {
278 switch (state->
Vcc) {
286 switch (state->
Vpp) {
300 switch (state->
Vcc) {
311 switch (state->
Vpp) {
334 yenta_set_power(socket, state);
344 intr = (intr & ~0xf);
345 if (!socket->
dev->irq) {
398 yenta_set_power(socket, state);
455 if (map > 4 || start > stop || ((start ^ stop) >> 24) ||
456 (card_start >> 26) || mem->
speed > 1000)
466 exca_writeb(socket,
CB_MEM_PAGE(map), start >> 24);
468 word = (start >> 12) & 0x0fff;
475 word = (stop >> 12) & 0x0fff;
491 word = ((card_start -
start) >> 12) & 0x3fff;
518 if (!(cb_event || csc))
537 static void yenta_interrupt_wrapper(
unsigned long data)
541 yenta_interrupt(0, (
void *)socket);
546 static void yenta_clear_maps(
struct yenta_socket *socket)
549 struct resource res = { .start = 0, .end = 0x0fff };
554 for (i = 0; i < 2; i++) {
556 yenta_set_io_map(&socket->
socket, &io);
558 for (i = 0; i < 5; i++) {
560 yenta_set_mem_map(&socket->
socket, &mem);
565 static void yenta_interrogate(
struct yenta_socket *socket)
572 ((state & (CB_16BITCARD | CB_CBCARD)) == (CB_16BITCARD | CB_CBCARD)))
585 yenta_interrogate(socket);
587 yenta_clear_maps(socket);
589 if (socket->
type && socket->
type->sock_init)
590 socket->
type->sock_init(socket);
615 #define BRIDGE_MEM_MAX (4*1024*1024)
616 #define BRIDGE_MEM_ACC (128*1024)
617 #define BRIDGE_MEM_MIN (16*1024)
619 #define BRIDGE_IO_MAX 512
620 #define BRIDGE_IO_ACC 256
621 #define BRIDGE_IO_MIN 32
623 #ifndef PCIBIOS_MIN_CARDBUS_IO
624 #define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO
627 static int yenta_search_one_res(
struct resource *root,
struct resource *res,
641 if (size > avail/8) {
645 while ((size /= 2) != 0)
663 }
while (size >= min);
675 pci_bus_for_each_resource(socket->
dev->bus, root, i) {
683 if (yenta_search_one_res(root, res, min))
689 static int yenta_allocate_res(
struct yenta_socket *socket,
int nr,
unsigned type,
int addr_start,
int addr_end)
709 region.start = config_readl(socket, addr_start) &
mask;
710 region.end = config_readl(socket, addr_end) | ~mask;
716 "Preassigned resource %d busy or not available, "
717 "reconfiguring...\n",
721 if (type & IORESOURCE_IO) {
742 "no resource of type %x available, trying to continue...\n",
751 static void yenta_allocate_resources(
struct yenta_socket *socket)
754 program += yenta_allocate_res(socket, 0, IORESOURCE_IO,
756 program += yenta_allocate_res(socket, 1, IORESOURCE_IO,
758 program += yenta_allocate_res(socket, 2,
IORESOURCE_MEM|IORESOURCE_PREFETCH,
770 static void yenta_free_resources(
struct yenta_socket *socket)
773 for (i = 0; i < 4; i++) {
776 if (res->
start != 0 && res->
end != 0)
807 yenta_free_resources(sock);
811 pci_set_drvdata(dev,
NULL);
816 .init = yenta_sock_init,
817 .suspend = yenta_sock_suspend,
818 .get_status = yenta_get_status,
819 .set_socket = yenta_set_socket,
820 .set_io_map = yenta_set_io_map,
821 .set_mem_map = yenta_set_mem_map,
825 #ifdef CONFIG_YENTA_TI
828 #ifdef CONFIG_YENTA_RICOH
831 #ifdef CONFIG_YENTA_TOSHIBA
834 #ifdef CONFIG_YENTA_O2
856 #ifdef CONFIG_YENTA_TI
859 .save_state = ti_save_state,
860 .restore_state = ti_restore_state,
861 .sock_init = ti_init,
864 .override = ti113x_override,
865 .save_state = ti_save_state,
866 .restore_state = ti_restore_state,
867 .sock_init = ti_init,
870 .override = ti12xx_override,
871 .save_state = ti_save_state,
872 .restore_state = ti_restore_state,
873 .sock_init = ti_init,
876 .override = ti1250_override,
877 .save_state = ti_save_state,
878 .restore_state = ti_restore_state,
879 .sock_init = ti_init,
883 .save_state = ti_save_state,
884 .restore_state = ti_restore_state,
885 .sock_init = ti_init,
888 #ifdef CONFIG_YENTA_RICOH
890 .override = ricoh_override,
891 .save_state = ricoh_save_state,
892 .restore_state = ricoh_restore_state,
895 #ifdef CONFIG_YENTA_TOSHIBA
897 .override = topic95_override,
900 .override = topic97_override,
903 #ifdef CONFIG_YENTA_O2
905 .override = o2micro_override,
906 .restore_state = o2micro_restore_state,
912 static unsigned int yenta_probe_irq(
struct yenta_socket *socket,
u32 isa_irq_mask)
928 for (i = 1; i < 16; i++) {
929 if (!((val >> i) & 1))
949 #ifdef CONFIG_YENTA_TI
952 static irqreturn_t yenta_probe_handler(
int irq,
void *dev_id)
963 if (cb_event || csc) {
972 static int yenta_probe_cb_irq(
struct yenta_socket *socket)
983 "request_irq() in yenta_probe_cb_irq() failed!\n");
988 if (!socket->
dev->irq)
1014 static void yenta_get_socket_capabilities(
struct yenta_socket *socket,
u32 isa_irq_mask)
1018 socket->
socket.irq_mask = yenta_probe_irq(socket, isa_irq_mask);
1020 socket->
socket.irq_mask = 0;
1023 "ISA IRQ mask 0x%04x, PCI irq %d\n",
1030 static void yenta_config_init(
struct yenta_socket *socket)
1051 ((
unsigned int)dev->
subordinate->busn_res.end << 16) |
1052 ((
unsigned int)dev->
subordinate->busn_res.start << 8) |
1077 static void yenta_fixup_parent_bridge(
struct pci_bus *cardbus_bridge)
1080 unsigned char upper_limit;
1092 if (!bridge_to_fix->
parent)
1096 upper_limit = bridge_to_fix->
parent->busn_res.end;
1108 && silbling->
busn_res.start <= upper_limit)
1109 upper_limit = silbling->
busn_res.start - 1;
1113 if (cardbus_bridge->
busn_res.end > upper_limit)
1115 "Upper limit for fixing this "
1116 "bridge's parent bridge: #%02x\n", upper_limit);
1119 if (bridge_to_fix->
busn_res.end < upper_limit) {
1122 unsigned char subordinate_to_assign =
1126 "Raising subordinate bus# of parent "
1127 "bus (#%02x) from #%02x to #%02x\n",
1129 (
int)bridge_to_fix->
busn_res.end, subordinate_to_assign);
1132 bridge_to_fix->
busn_res.end = subordinate_to_assign;
1135 pci_write_config_byte(bridge_to_fix->
self,
1156 dev_printk(
KERN_ERR, &dev->
dev,
"no bus associated! "
1157 "(try 'pci=assign-busses')\n");
1166 socket->
socket.ops = ¥ta_socket_operations;
1172 socket->
socket.map_size = 0x1000;
1177 pci_set_drvdata(dev, socket);
1192 dev_printk(
KERN_ERR, &dev->
dev,
"No cardbus resource!\n");
1202 if (!socket->
base) {
1211 dev_printk(
KERN_INFO, &dev->
dev,
"CardBus bridge found [%04x:%04x]\n",
1214 yenta_config_init(socket);
1220 yenta_allocate_resources(socket);
1227 socket->
type = &cardbus_type[
id->driver_data];
1229 ret = socket->
type->override(socket);
1240 socket->
poll_timer.function = yenta_interrupt_wrapper;
1245 "no PCI IRQ, CardBus support disabled for this "
1248 "check your BIOS CardBus, BIOS IRQ or ACPI "
1255 yenta_interrogate(socket);
1256 yenta_get_socket_capabilities(socket, isa_interrupts);
1287 static int yenta_dev_suspend_noirq(
struct device *dev)
1295 if (socket->
type && socket->
type->save_state)
1296 socket->
type->save_state(socket);
1299 pci_read_config_dword(pdev, 16*4, &socket->
saved_state[0]);
1300 pci_read_config_dword(pdev, 17*4, &socket->
saved_state[1]);
1306 static int yenta_dev_resume_noirq(
struct device *dev)
1315 pci_write_config_dword(pdev, 16*4, socket->
saved_state[0]);
1316 pci_write_config_dword(pdev, 17*4, socket->
saved_state[1]);
1324 if (socket->
type && socket->
type->restore_state)
1325 socket->
type->restore_state(socket);
1330 static const struct dev_pm_ops yenta_pm_ops = {
1332 .resume_noirq = yenta_dev_resume_noirq,
1333 .freeze_noirq = yenta_dev_suspend_noirq,
1334 .thaw_noirq = yenta_dev_resume_noirq,
1335 .poweroff_noirq = yenta_dev_suspend_noirq,
1336 .restore_noirq = yenta_dev_resume_noirq,
1339 #define YENTA_PM_OPS (¥ta_pm_ops)
1341 #define YENTA_PM_OPS NULL
1344 #define CB_ID(vend, dev, type) \
1348 .subvendor = PCI_ANY_ID, \
1349 .subdevice = PCI_ANY_ID, \
1350 .class = PCI_CLASS_BRIDGE_CARDBUS << 8, \
1352 .driver_data = CARDBUS_TYPE_##type, \
1363 #ifdef CONFIG_YENTA_TI
1409 #ifdef CONFIG_YENTA_RICOH
1417 #ifdef CONFIG_YENTA_TOSHIBA
1423 #ifdef CONFIG_YENTA_O2
1434 static struct pci_driver yenta_cardbus_driver = {
1435 .name =
"yenta_cardbus",
1436 .id_table = yenta_table,
1437 .probe = yenta_probe,
1443 static int __init yenta_socket_init(
void)
1445 return pci_register_driver(¥ta_cardbus_driver);
1449 static void __exit yenta_socket_exit(
void)