2 * bdc_pci.c - BRCM BDC USB3.0 device controller PCI interface file.
4 * Copyright (C) 2014 Broadcom Corporation
6 * Author: Ashwini Pahuja
8 * Based on drivers under drivers/usb/
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/pci.h>
21 #include <linux/pci_ids.h>
22 #include <linux/platform_device.h>
26 #define BDC_PCI_PID 0x1570
30 struct platform_device *bdc;
33 static int bdc_setup_msi(struct pci_dev *pci)
37 ret = pci_enable_msi(pci);
39 pr_err("failed to allocate MSI entry\n");
46 static int bdc_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
48 struct resource res[2];
49 struct platform_device *bdc;
53 glue = devm_kzalloc(&pci->dev, sizeof(*glue), GFP_KERNEL);
57 glue->dev = &pci->dev;
58 ret = pci_enable_device(pci);
60 dev_err(&pci->dev, "failed to enable pci device\n");
65 bdc = platform_device_alloc(BRCM_BDC_NAME, PLATFORM_DEVID_AUTO);
69 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
72 res[0].start = pci_resource_start(pci, 0);
73 res[0].end = pci_resource_end(pci, 0);
74 res[0].name = BRCM_BDC_NAME;
75 res[0].flags = IORESOURCE_MEM;
77 res[1].start = pci->irq;
78 res[1].name = BRCM_BDC_NAME;
79 res[1].flags = IORESOURCE_IRQ;
81 ret = platform_device_add_resources(bdc, res, ARRAY_SIZE(res));
84 "couldn't add resources to bdc device\n");
88 pci_set_drvdata(pci, glue);
90 dma_set_coherent_mask(&bdc->dev, pci->dev.coherent_dma_mask);
92 bdc->dev.dma_mask = pci->dev.dma_mask;
93 bdc->dev.dma_parms = pci->dev.dma_parms;
94 bdc->dev.parent = &pci->dev;
97 ret = platform_device_add(bdc);
99 dev_err(&pci->dev, "failed to register bdc device\n");
100 platform_device_put(bdc);
107 static void bdc_pci_remove(struct pci_dev *pci)
109 struct bdc_pci *glue = pci_get_drvdata(pci);
111 platform_device_unregister(glue->bdc);
112 pci_disable_msi(pci);
115 static struct pci_device_id bdc_pci_id_table[] = {
116 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BDC_PCI_PID), },
117 {} /* Terminating Entry */
120 MODULE_DEVICE_TABLE(pci, bdc_pci_id_table);
122 static struct pci_driver bdc_pci_driver = {
124 .id_table = bdc_pci_id_table,
125 .probe = bdc_pci_probe,
126 .remove = bdc_pci_remove,
129 MODULE_AUTHOR("Ashwini Pahuja <ashwini.linux@gmail.com>");
130 MODULE_LICENSE("GPL");
131 MODULE_DESCRIPTION("BRCM BDC USB3 PCI Glue layer");
132 module_pci_driver(bdc_pci_driver);