1 // SPDX-License-Identifier: GPL-2.0-only
3 * cardbus.c -- 16-bit PCMCIA core support
5 * The initial developer of the original code is David A. Hinds
7 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
9 * (C) 1999 David A. Hinds
13 * Cardbus handling has been re-written to be more of a PCI bridge thing,
14 * and the PCI code basically does all the resource handling.
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
24 #include <pcmcia/ss.h>
27 static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq)
31 list_for_each_entry(dev, &bus->devices, bus_list) {
35 * Since there is only one interrupt available to
36 * CardBus devices, all devices downstream of this
37 * device must be using this IRQ.
39 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &irq_pin);
42 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
46 * Some controllers transfer very slowly with 0 CLS.
47 * Configure it. This may fail as CLS configuration
48 * is mandatory only for MWI.
50 pci_set_cacheline_size(dev);
53 cardbus_config_irq_and_cls(dev->subordinate, irq);
58 * cb_alloc() - add CardBus device
59 * @s: the pcmcia_socket where the CardBus device is located
61 * cb_alloc() allocates the kernel data structures for a Cardbus device
62 * and handles the lowest level PCI device setup issues.
64 int __ref cb_alloc(struct pcmcia_socket *s)
66 struct pci_bus *bus = s->cb_dev->subordinate;
68 unsigned int max, pass;
70 pci_lock_rescan_remove();
72 s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0));
73 pci_fixup_cardbus(bus);
75 max = bus->busn_res.start;
76 for (pass = 0; pass < 2; pass++)
77 for_each_pci_bridge(dev, bus)
78 max = pci_scan_bridge(bus, dev, max, pass);
81 * Size all resources below the CardBus controller.
83 pci_bus_size_bridges(bus);
84 pci_bus_assign_resources(bus);
85 cardbus_config_irq_and_cls(bus, s->pci_irq);
87 /* socket specific tune function */
89 s->tune_bridge(s, bus);
91 pci_bus_add_devices(bus);
93 pci_unlock_rescan_remove();
98 * cb_free() - remove CardBus device
99 * @s: the pcmcia_socket where the CardBus device was located
101 * cb_free() handles the lowest level PCI device cleanup.
103 void cb_free(struct pcmcia_socket *s)
105 struct pci_dev *bridge, *dev, *tmp;
112 bus = bridge->subordinate;
116 pci_lock_rescan_remove();
118 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list)
119 pci_stop_and_remove_bus_device(dev);
121 pci_unlock_rescan_remove();