1 // SPDX-License-Identifier: GPL-2.0+
3 * bdc_pci.c - BRCM BDC USB3.0 device controller PCI interface file.
5 * Copyright (C) 2014 Broadcom Corporation
7 * Author: Ashwini Pahuja
9 * Based on drivers under drivers/usb/
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/pci.h>
16 #include <linux/pci_ids.h>
17 #include <linux/platform_device.h>
21 #define BDC_PCI_PID 0x1570
25 struct platform_device
*bdc
;
28 static int bdc_setup_msi(struct pci_dev
*pci
)
32 ret
= pci_enable_msi(pci
);
34 pr_err("failed to allocate MSI entry\n");
41 static int bdc_pci_probe(struct pci_dev
*pci
, const struct pci_device_id
*id
)
43 struct resource res
[2];
44 struct platform_device
*bdc
;
48 glue
= devm_kzalloc(&pci
->dev
, sizeof(*glue
), GFP_KERNEL
);
52 glue
->dev
= &pci
->dev
;
53 ret
= pci_enable_device(pci
);
55 dev_err(&pci
->dev
, "failed to enable pci device\n");
60 bdc
= platform_device_alloc(BRCM_BDC_NAME
, PLATFORM_DEVID_AUTO
);
64 memset(res
, 0x00, sizeof(struct resource
) * ARRAY_SIZE(res
));
67 res
[0].start
= pci_resource_start(pci
, 0);
68 res
[0].end
= pci_resource_end(pci
, 0);
69 res
[0].name
= BRCM_BDC_NAME
;
70 res
[0].flags
= IORESOURCE_MEM
;
72 res
[1].start
= pci
->irq
;
73 res
[1].name
= BRCM_BDC_NAME
;
74 res
[1].flags
= IORESOURCE_IRQ
;
76 ret
= platform_device_add_resources(bdc
, res
, ARRAY_SIZE(res
));
79 "couldn't add resources to bdc device\n");
80 platform_device_put(bdc
);
84 pci_set_drvdata(pci
, glue
);
86 dma_set_coherent_mask(&bdc
->dev
, pci
->dev
.coherent_dma_mask
);
88 bdc
->dev
.dma_mask
= pci
->dev
.dma_mask
;
89 bdc
->dev
.dma_parms
= pci
->dev
.dma_parms
;
90 bdc
->dev
.parent
= &pci
->dev
;
93 ret
= platform_device_add(bdc
);
95 dev_err(&pci
->dev
, "failed to register bdc device\n");
96 platform_device_put(bdc
);
103 static void bdc_pci_remove(struct pci_dev
*pci
)
105 struct bdc_pci
*glue
= pci_get_drvdata(pci
);
107 platform_device_unregister(glue
->bdc
);
108 pci_disable_msi(pci
);
111 static struct pci_device_id bdc_pci_id_table
[] = {
112 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, BDC_PCI_PID
), },
113 {} /* Terminating Entry */
116 MODULE_DEVICE_TABLE(pci
, bdc_pci_id_table
);
118 static struct pci_driver bdc_pci_driver
= {
120 .id_table
= bdc_pci_id_table
,
121 .probe
= bdc_pci_probe
,
122 .remove
= bdc_pci_remove
,
125 MODULE_AUTHOR("Ashwini Pahuja <ashwini.linux@gmail.com>");
126 MODULE_LICENSE("GPL");
127 MODULE_DESCRIPTION("BRCM BDC USB3 PCI Glue layer");
128 module_pci_driver(bdc_pci_driver
);