2 * macb_pci.c - Cadence GEM PCI wrapper.
4 * Copyright (C) 2016 Cadence Design Systems - http://www.cadence.com
6 * Authors: Rafal Ozieblo <rafalo@cadence.com>
7 * Bartosz Folta <bfolta@cadence.com>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 of
11 * the License as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/clk.h>
23 #include <linux/clk-provider.h>
24 #include <linux/etherdevice.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27 #include <linux/platform_data/macb.h>
28 #include <linux/platform_device.h>
31 #define PCI_DRIVER_NAME "macb_pci"
32 #define PLAT_DRIVER_NAME "macb"
34 #define CDNS_VENDOR_ID 0x17cd
35 #define CDNS_DEVICE_ID 0xe007
37 #define GEM_PCLK_RATE 50000000
38 #define GEM_HCLK_RATE 50000000
40 static int macb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
43 struct platform_device
*plat_dev
;
44 struct platform_device_info plat_info
;
45 struct macb_platform_data plat_data
;
46 struct resource res
[2];
52 /* enable pci device */
53 err
= pci_enable_device(pdev
);
55 dev_err(&pdev
->dev
, "Enabling PCI device has failed: 0x%04X",
62 /* set up resources */
63 memset(res
, 0x00, sizeof(struct resource
) * ARRAY_SIZE(res
));
64 res
[0].start
= pdev
->resource
[0].start
;
65 res
[0].end
= pdev
->resource
[0].end
;
66 res
[0].name
= PCI_DRIVER_NAME
;
67 res
[0].flags
= IORESOURCE_MEM
;
68 res
[1].start
= pdev
->irq
;
69 res
[1].name
= PCI_DRIVER_NAME
;
70 res
[1].flags
= IORESOURCE_IRQ
;
72 dev_info(&pdev
->dev
, "EMAC physical base addr = 0x%p\n",
73 (void *)(uintptr_t)pci_resource_start(pdev
, 0));
75 /* set up macb platform data */
76 memset(&plat_data
, 0, sizeof(plat_data
));
78 /* initialize clocks */
79 plat_data
.pclk
= clk_register_fixed_rate(&pdev
->dev
, "pclk", NULL
, 0,
81 if (IS_ERR(plat_data
.pclk
)) {
82 err
= PTR_ERR(plat_data
.pclk
);
83 goto err_pclk_register
;
86 plat_data
.hclk
= clk_register_fixed_rate(&pdev
->dev
, "hclk", NULL
, 0,
88 if (IS_ERR(plat_data
.hclk
)) {
89 err
= PTR_ERR(plat_data
.hclk
);
90 goto err_hclk_register
;
93 /* set up platform device info */
94 memset(&plat_info
, 0, sizeof(plat_info
));
95 plat_info
.parent
= &pdev
->dev
;
96 plat_info
.fwnode
= pdev
->dev
.fwnode
;
97 plat_info
.name
= PLAT_DRIVER_NAME
;
98 plat_info
.id
= pdev
->devfn
;
100 plat_info
.num_res
= ARRAY_SIZE(res
);
101 plat_info
.data
= &plat_data
;
102 plat_info
.size_data
= sizeof(plat_data
);
103 plat_info
.dma_mask
= DMA_BIT_MASK(32);
105 /* register platform device */
106 plat_dev
= platform_device_register_full(&plat_info
);
107 if (IS_ERR(plat_dev
)) {
108 err
= PTR_ERR(plat_dev
);
109 goto err_plat_dev_register
;
112 pci_set_drvdata(pdev
, plat_dev
);
116 err_plat_dev_register
:
117 clk_unregister(plat_data
.hclk
);
120 clk_unregister(plat_data
.pclk
);
123 pci_disable_device(pdev
);
127 static void macb_remove(struct pci_dev
*pdev
)
129 struct platform_device
*plat_dev
= pci_get_drvdata(pdev
);
130 struct macb_platform_data
*plat_data
= dev_get_platdata(&plat_dev
->dev
);
132 platform_device_unregister(plat_dev
);
133 pci_disable_device(pdev
);
134 clk_unregister(plat_data
->pclk
);
135 clk_unregister(plat_data
->hclk
);
138 static struct pci_device_id dev_id_table
[] = {
139 { PCI_DEVICE(CDNS_VENDOR_ID
, CDNS_DEVICE_ID
), },
143 static struct pci_driver macb_pci_driver
= {
144 .name
= PCI_DRIVER_NAME
,
145 .id_table
= dev_id_table
,
147 .remove
= macb_remove
,
150 module_pci_driver(macb_pci_driver
);
151 MODULE_DEVICE_TABLE(pci
, dev_id_table
);
152 MODULE_LICENSE("GPL");
153 MODULE_DESCRIPTION("Cadence NIC PCI wrapper");