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
6 * <dahinds@users.sourceforge.net>. Portions created by 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>
25 #include <pcmcia/cistpl.h>
27 #include "cs_internal.h"
29 static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq)
33 list_for_each_entry(dev, &bus->devices, bus_list) {
37 * Since there is only one interrupt available to
38 * CardBus devices, all devices downstream of this
39 * device must be using this IRQ.
41 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &irq_pin);
44 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
48 * Some controllers transfer very slowly with 0 CLS.
49 * Configure it. This may fail as CLS configuration
50 * is mandatory only for MWI.
52 pci_set_cacheline_size(dev);
55 cardbus_config_irq_and_cls(dev->subordinate, irq);
60 * cb_alloc() - add CardBus device
61 * @s: the pcmcia_socket where the CardBus device is located
63 * cb_alloc() allocates the kernel data structures for a Cardbus device
64 * and handles the lowest level PCI device setup issues.
66 int __ref cb_alloc(struct pcmcia_socket *s)
68 struct pci_bus *bus = s->cb_dev->subordinate;
70 unsigned int max, pass;
72 pci_lock_rescan_remove();
74 s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0));
75 pci_fixup_cardbus(bus);
77 max = bus->busn_res.start;
78 for (pass = 0; pass < 2; pass++)
79 for_each_pci_bridge(dev, bus)
80 max = pci_scan_bridge(bus, dev, max, pass);
83 * Size all resources below the CardBus controller.
85 pci_bus_size_bridges(bus);
86 pci_bus_assign_resources(bus);
87 cardbus_config_irq_and_cls(bus, s->pci_irq);
89 /* socket specific tune function */
91 s->tune_bridge(s, bus);
93 pci_bus_add_devices(bus);
95 pci_unlock_rescan_remove();
100 * cb_free() - remove CardBus device
101 * @s: the pcmcia_socket where the CardBus device was located
103 * cb_free() handles the lowest level PCI device cleanup.
105 void cb_free(struct pcmcia_socket *s)
107 struct pci_dev *bridge, *dev, *tmp;
114 bus = bridge->subordinate;
118 pci_lock_rescan_remove();
120 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list)
121 pci_stop_and_remove_bus_device(dev);
123 pci_unlock_rescan_remove();