blob: ac0686efbf759de211fe1e78bb6ae5f58d2f0fca [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * cardbus.c -- 16-bit PCMCIA core support
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 *
12 * (C) 1999 David A. Hinds
13 */
14
15/*
16 * Cardbus handling has been re-written to be more of a PCI bridge thing,
17 * and the PCI code basically does all the resource handling.
18 *
19 * Linus, Jan 2000
20 */
21
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/kernel.h>
Dominik Brodowski57197b92010-01-02 17:27:33 +010024#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <pcmcia/ss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Tejun Heo15ea76d2009-09-22 17:34:48 +090030static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 struct pci_dev *dev;
33
34 list_for_each_entry(dev, &bus->devices, bus_list) {
35 u8 irq_pin;
36
Tejun Heo15ea76d2009-09-22 17:34:48 +090037 /*
38 * Since there is only one interrupt available to
39 * CardBus devices, all devices downstream of this
40 * device must be using this IRQ.
41 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &irq_pin);
43 if (irq_pin) {
44 dev->irq = irq;
45 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
46 }
47
Tejun Heo15ea76d2009-09-22 17:34:48 +090048 /*
49 * Some controllers transfer very slowly with 0 CLS.
50 * Configure it. This may fail as CLS configuration
51 * is mandatory only for MWI.
52 */
53 pci_set_cacheline_size(dev);
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 if (dev->subordinate)
Tejun Heo15ea76d2009-09-22 17:34:48 +090056 cardbus_config_irq_and_cls(dev->subordinate, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
58}
59
Dominik Brodowski57197b92010-01-02 17:27:33 +010060/**
61 * cb_alloc() - add CardBus device
62 * @s: the pcmcia_socket where the CardBus device is located
63 *
64 * cb_alloc() allocates the kernel data structures for a Cardbus device
65 * and handles the lowest level PCI device setup issues.
66 */
Dominik Brodowski9fea84f2009-12-07 22:11:45 +010067int __ref cb_alloc(struct pcmcia_socket *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 struct pci_bus *bus = s->cb_dev->subordinate;
70 struct pci_dev *dev;
71 unsigned int max, pass;
72
73 s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0));
Benjamin Herrenschmidt2d1c8612009-12-09 17:52:13 +110074 pci_fixup_cardbus(bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 max = bus->secondary;
77 for (pass = 0; pass < 2; pass++)
78 list_for_each_entry(dev, &bus->devices, bus_list)
79 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
80 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
81 max = pci_scan_bridge(bus, dev, max, pass);
82
83 /*
84 * Size all resources below the CardBus controller.
85 */
86 pci_bus_size_bridges(bus);
87 pci_bus_assign_resources(bus);
Tejun Heo15ea76d2009-09-22 17:34:48 +090088 cardbus_config_irq_and_cls(bus, s->pci_irq);
Daniel Ritz8c3520d2005-08-21 22:29:26 -070089
90 /* socket specific tune function */
91 if (s->tune_bridge)
92 s->tune_bridge(s, bus);
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 pci_enable_bridges(bus);
95 pci_bus_add_devices(bus);
96
97 s->irq.AssignedIRQ = s->pci_irq;
Dominik Brodowski4c89e882008-08-03 10:07:45 +020098 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Dominik Brodowski57197b92010-01-02 17:27:33 +0100101/**
102 * cb_free() - remove CardBus device
103 * @s: the pcmcia_socket where the CardBus device was located
104 *
105 * cb_free() handles the lowest level PCI device cleanup.
106 */
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100107void cb_free(struct pcmcia_socket *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 struct pci_dev *bridge = s->cb_dev;
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (bridge)
112 pci_remove_behind_bridge(bridge);
113}