Blame view

drivers/pcmcia/cardbus.c 2.75 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /*
   * cardbus.c -- 16-bit PCMCIA core support
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   * The initial developer of the original code is David A. Hinds
   * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
   * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
   *
   * (C) 1999		David A. Hinds
   */
  
  /*
   * Cardbus handling has been re-written to be more of a PCI bridge thing,
   * and the PCI code basically does all the resource handling.
   *
   *		Linus, Jan 2000
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  #include <linux/kernel.h>
57197b9b7   Dominik Brodowski   pcmcia: CardBus d...
22
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
  #include <linux/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
  #include <pcmcia/ss.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27

15ea76d40   Tejun Heo   pccard: configure...
28
  static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
  {
  	struct pci_dev *dev;
  
  	list_for_each_entry(dev, &bus->devices, bus_list) {
  		u8 irq_pin;
15ea76d40   Tejun Heo   pccard: configure...
34
35
36
37
38
  		/*
  		 * Since there is only one interrupt available to
  		 * CardBus devices, all devices downstream of this
  		 * device must be using this IRQ.
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
40
41
42
43
  		pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &irq_pin);
  		if (irq_pin) {
  			dev->irq = irq;
  			pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  		}
15ea76d40   Tejun Heo   pccard: configure...
44
45
46
47
48
49
  		/*
  		 * Some controllers transfer very slowly with 0 CLS.
  		 * Configure it.  This may fail as CLS configuration
  		 * is mandatory only for MWI.
  		 */
  		pci_set_cacheline_size(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  		if (dev->subordinate)
15ea76d40   Tejun Heo   pccard: configure...
51
  			cardbus_config_irq_and_cls(dev->subordinate, irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
  	}
  }
57197b9b7   Dominik Brodowski   pcmcia: CardBus d...
54
55
56
57
58
59
60
  /**
   * cb_alloc() - add CardBus device
   * @s:		the pcmcia_socket where the CardBus device is located
   *
   * cb_alloc() allocates the kernel data structures for a Cardbus device
   * and handles the lowest level PCI device setup issues.
   */
9fea84f46   Dominik Brodowski   pcmcia: CodingSty...
61
  int __ref cb_alloc(struct pcmcia_socket *s)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
64
65
66
67
  {
  	struct pci_bus *bus = s->cb_dev->subordinate;
  	struct pci_dev *dev;
  	unsigned int max, pass;
  
  	s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0));
6e83ee075   Dominik Brodowski   pcmcia: CodingSty...
68
  	pci_fixup_cardbus(bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
72
73
74
75
76
77
78
79
80
81
  
  	max = bus->secondary;
  	for (pass = 0; pass < 2; pass++)
  		list_for_each_entry(dev, &bus->devices, bus_list)
  			if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  			    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  				max = pci_scan_bridge(bus, dev, max, pass);
  
  	/*
  	 * Size all resources below the CardBus controller.
  	 */
  	pci_bus_size_bridges(bus);
  	pci_bus_assign_resources(bus);
15ea76d40   Tejun Heo   pccard: configure...
82
  	cardbus_config_irq_and_cls(bus, s->pci_irq);
8c3520d4e   Daniel Ritz   [PATCH] yenta: au...
83
84
85
86
  
  	/* socket specific tune function */
  	if (s->tune_bridge)
  		s->tune_bridge(s, bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
88
  	pci_enable_bridges(bus);
  	pci_bus_add_devices(bus);
4c89e88bf   Dominik Brodowski   pcmcia: deprecate...
89
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  }
57197b9b7   Dominik Brodowski   pcmcia: CardBus d...
91
92
93
94
95
96
  /**
   * cb_free() - remove CardBus device
   * @s:		the pcmcia_socket where the CardBus device was located
   *
   * cb_free() handles the lowest level PCI device cleanup.
   */
9fea84f46   Dominik Brodowski   pcmcia: CodingSty...
97
  void cb_free(struct pcmcia_socket *s)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
99
  {
  	struct pci_dev *bridge = s->cb_dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
  	if (bridge)
  		pci_remove_behind_bridge(bridge);
  }