2 * WHCI UWB Multi-interface Controller enumerator.
4 * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
6 * This file is released under the GNU GPL v2.
8 #include <linux/delay.h>
9 #include <linux/kernel.h>
10 #include <linux/pci.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/uwb/whci.h>
13 #include <linux/uwb/umc.h>
17 void __iomem
*uwbbase
;
19 struct umc_dev
*devs
[0];
23 /* Fix faulty HW :( */
25 u64
whci_capdata_quirks(struct whci_card
*card
, u64 capdata
)
27 u64 capdata_orig
= capdata
;
28 struct pci_dev
*pci_dev
= card
->pci
;
29 if (pci_dev
->vendor
== PCI_VENDOR_ID_INTEL
30 && (pci_dev
->device
== 0x0c3b || pci_dev
->device
== 0004)
31 && pci_dev
->class == 0x0d1010) {
32 switch (UWBCAPDATA_TO_CAP_ID(capdata
)) {
33 /* WLP capability has 0x100 bytes of aperture */
35 capdata
|= 0x40 << 8; break;
36 /* WUSB capability has 0x80 bytes of aperture
44 if (capdata_orig
!= capdata
)
45 dev_warn(&pci_dev
->dev
,
46 "PCI v%04x d%04x c%06x#%02x: "
47 "corrected capdata from %016Lx to %016Lx\n",
48 pci_dev
->vendor
, pci_dev
->device
, pci_dev
->class,
49 (unsigned)UWBCAPDATA_TO_CAP_ID(capdata
),
50 (unsigned long long)capdata_orig
,
51 (unsigned long long)capdata
);
57 * whci_wait_for - wait for a WHCI register to be set
59 * Polls (for at most @max_ms ms) until '*@reg & @mask == @result'.
61 int whci_wait_for(struct device
*dev
, u32 __iomem
*reg
, u32 mask
, u32 result
,
62 unsigned long max_ms
, const char *tag
)
68 if ((val
& mask
) == result
)
71 dev_err(dev
, "%s timed out\n", tag
);
79 EXPORT_SYMBOL_GPL(whci_wait_for
);
83 * NOTE: the capinfo and capdata registers are slightly different
84 * (size and cap-id fields). So for cap #0, we need to fill
85 * in. Size comes from the size of the register block
86 * (statically calculated); cap_id comes from nowhere, we use
87 * zero, that is reserved, for the radio controller, because
88 * none was defined at the spec level.
90 static int whci_add_cap(struct whci_card
*card
, int n
)
96 umc
= umc_device_create(&card
->pci
->dev
, n
);
100 capdata
= le_readq(card
->uwbbase
+ UWBCAPDATA(n
));
102 bar
= UWBCAPDATA_TO_BAR(capdata
) << 1;
104 capdata
= whci_capdata_quirks(card
, capdata
);
105 /* Capability 0 is the radio controller. It's size is 32
106 * bytes (WHCI0.95[2.3, T2-9]). */
107 umc
->version
= UWBCAPDATA_TO_VERSION(capdata
);
108 umc
->cap_id
= n
== 0 ? 0 : UWBCAPDATA_TO_CAP_ID(capdata
);
110 umc
->resource
.start
= pci_resource_start(card
->pci
, bar
)
111 + UWBCAPDATA_TO_OFFSET(capdata
);
112 umc
->resource
.end
= umc
->resource
.start
113 + (n
== 0 ? 0x20 : UWBCAPDATA_TO_SIZE(capdata
)) - 1;
114 umc
->resource
.name
= dev_name(&umc
->dev
);
115 umc
->resource
.flags
= card
->pci
->resource
[bar
].flags
;
116 umc
->resource
.parent
= &card
->pci
->resource
[bar
];
117 umc
->irq
= card
->pci
->irq
;
119 err
= umc_device_register(umc
);
130 static void whci_del_cap(struct whci_card
*card
, int n
)
132 struct umc_dev
*umc
= card
->devs
[n
];
135 umc_device_unregister(umc
);
138 static int whci_n_caps(struct pci_dev
*pci
)
140 void __iomem
*uwbbase
;
143 uwbbase
= pci_iomap(pci
, 0, 8);
146 capinfo
= le_readq(uwbbase
+ UWBCAPINFO
);
147 pci_iounmap(pci
, uwbbase
);
149 return UWBCAPINFO_TO_N_CAPS(capinfo
);
152 static int whci_probe(struct pci_dev
*pci
, const struct pci_device_id
*id
)
154 struct whci_card
*card
;
157 err
= pci_enable_device(pci
);
163 if (!pci_set_dma_mask(pci
, DMA_64BIT_MASK
))
164 pci_set_consistent_dma_mask(pci
, DMA_64BIT_MASK
);
165 else if (!pci_set_dma_mask(pci
, DMA_32BIT_MASK
))
166 pci_set_consistent_dma_mask(pci
, DMA_32BIT_MASK
);
170 err
= n_caps
= whci_n_caps(pci
);
175 card
= kzalloc(sizeof(struct whci_card
)
176 + sizeof(struct whci_dev
*) * (n_caps
+ 1),
181 card
->n_caps
= n_caps
;
184 if (!request_mem_region(pci_resource_start(pci
, 0),
185 UWBCAPDATA_SIZE(card
->n_caps
),
186 "whci (capability data)"))
187 goto error_request_memregion
;
189 card
->uwbbase
= pci_iomap(pci
, 0, UWBCAPDATA_SIZE(card
->n_caps
));
193 /* Add each capability. */
194 for (n
= 0; n
<= card
->n_caps
; n
++) {
195 err
= whci_add_cap(card
, n
);
196 if (err
< 0 && n
== 0) {
197 dev_err(&pci
->dev
, "cannot bind UWB radio controller:"
202 dev_warn(&pci
->dev
, "warning: cannot bind capability "
203 "#%u: %d\n", n
, err
);
205 pci_set_drvdata(pci
, card
);
209 pci_iounmap(pci
, card
->uwbbase
);
211 release_mem_region(pci_resource_start(pci
, 0), UWBCAPDATA_SIZE(card
->n_caps
));
212 error_request_memregion
:
217 pci_disable_msi(pci
);
218 pci_disable_device(pci
);
223 static void whci_remove(struct pci_dev
*pci
)
225 struct whci_card
*card
= pci_get_drvdata(pci
);
228 pci_set_drvdata(pci
, NULL
);
229 /* Unregister each capability in reverse (so the master device
230 * is unregistered last). */
231 for (n
= card
->n_caps
; n
>= 0 ; n
--)
232 whci_del_cap(card
, n
);
233 pci_iounmap(pci
, card
->uwbbase
);
234 release_mem_region(pci_resource_start(pci
, 0), UWBCAPDATA_SIZE(card
->n_caps
));
236 pci_disable_msi(pci
);
237 pci_disable_device(pci
);
240 static struct pci_device_id whci_id_table
[] = {
241 { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI
, ~0) },
244 MODULE_DEVICE_TABLE(pci
, whci_id_table
);
247 static struct pci_driver whci_driver
= {
249 .id_table
= whci_id_table
,
251 .remove
= whci_remove
,
254 static int __init
whci_init(void)
256 return pci_register_driver(&whci_driver
);
259 static void __exit
whci_exit(void)
261 pci_unregister_driver(&whci_driver
);
264 module_init(whci_init
);
265 module_exit(whci_exit
);
267 MODULE_DESCRIPTION("WHCI UWB Multi-interface Controller enumerator");
268 MODULE_AUTHOR("Cambridge Silicon Radio Ltd.");
269 MODULE_LICENSE("GPL");