spi: sprd: adi: Add a reset reason for watchdog mode
[linux/fpc-iii.git] / drivers / pcmcia / cardbus.c
blobc502dfbf66e331d8c9cd46495a07c85fa458bd57
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
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.
16 * Linus, Jan 2000
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)
29 struct pci_dev *dev;
31 list_for_each_entry(dev, &bus->devices, bus_list) {
32 u8 irq_pin;
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);
40 if (irq_pin) {
41 dev->irq = irq;
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);
52 if (dev->subordinate)
53 cardbus_config_irq_and_cls(dev->subordinate, irq);
57 /**
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;
67 struct pci_dev *dev;
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 */
88 if (s->tune_bridge)
89 s->tune_bridge(s, bus);
91 pci_bus_add_devices(bus);
93 pci_unlock_rescan_remove();
94 return 0;
97 /**
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;
106 struct pci_bus *bus;
108 bridge = s->cb_dev;
109 if (!bridge)
110 return;
112 bus = bridge->subordinate;
113 if (!bus)
114 return;
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();