1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2019 NXP */
4 #include <linux/module.h>
6 #include <linux/fsl/ptp_qoriq.h>
10 int enetc_phc_index = -1;
11 EXPORT_SYMBOL_GPL(enetc_phc_index);
13 static struct ptp_clock_info enetc_ptp_caps = {
15 .name = "ENETC PTP clock",
22 .adjfine = ptp_qoriq_adjfine,
23 .adjtime = ptp_qoriq_adjtime,
24 .gettime64 = ptp_qoriq_gettime,
25 .settime64 = ptp_qoriq_settime,
26 .enable = ptp_qoriq_enable,
29 static int enetc_ptp_probe(struct pci_dev *pdev,
30 const struct pci_device_id *ent)
32 struct ptp_qoriq *ptp_qoriq;
36 if (pdev->dev.of_node && !of_device_is_available(pdev->dev.of_node)) {
37 dev_info(&pdev->dev, "device is disabled, skipping\n");
41 err = pci_enable_device_mem(pdev);
43 return dev_err_probe(&pdev->dev, err, "device enable failed\n");
45 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
47 dev_err(&pdev->dev, "DMA configuration failed: 0x%x\n", err);
51 err = pci_request_mem_regions(pdev, KBUILD_MODNAME);
53 dev_err(&pdev->dev, "pci_request_regions failed err=%d\n", err);
59 ptp_qoriq = kzalloc(sizeof(*ptp_qoriq), GFP_KERNEL);
65 len = pci_resource_len(pdev, ENETC_BAR_REGS);
67 base = ioremap(pci_resource_start(pdev, ENETC_BAR_REGS), len);
70 dev_err(&pdev->dev, "ioremap() failed\n");
74 /* Allocate 1 interrupt */
75 n = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX);
81 ptp_qoriq->irq = pci_irq_vector(pdev, 0);
83 err = request_irq(ptp_qoriq->irq, ptp_qoriq_isr, 0, DRIVER, ptp_qoriq);
85 dev_err(&pdev->dev, "request_irq() failed!\n");
89 ptp_qoriq->dev = &pdev->dev;
91 err = ptp_qoriq_init(ptp_qoriq, base, &enetc_ptp_caps);
95 enetc_phc_index = ptp_qoriq->phc_index;
96 pci_set_drvdata(pdev, ptp_qoriq);
101 free_irq(ptp_qoriq->irq, ptp_qoriq);
103 pci_free_irq_vectors(pdev);
109 pci_release_mem_regions(pdev);
112 pci_disable_device(pdev);
117 static void enetc_ptp_remove(struct pci_dev *pdev)
119 struct ptp_qoriq *ptp_qoriq = pci_get_drvdata(pdev);
121 enetc_phc_index = -1;
122 ptp_qoriq_free(ptp_qoriq);
123 pci_free_irq_vectors(pdev);
126 pci_release_mem_regions(pdev);
127 pci_disable_device(pdev);
130 static const struct pci_device_id enetc_ptp_id_table[] = {
131 { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, ENETC_DEV_ID_PTP) },
132 { 0, } /* End of table. */
134 MODULE_DEVICE_TABLE(pci, enetc_ptp_id_table);
136 static struct pci_driver enetc_ptp_driver = {
137 .name = KBUILD_MODNAME,
138 .id_table = enetc_ptp_id_table,
139 .probe = enetc_ptp_probe,
140 .remove = enetc_ptp_remove,
142 module_pci_driver(enetc_ptp_driver);
144 MODULE_DESCRIPTION("ENETC PTP clock driver");
145 MODULE_LICENSE("Dual BSD/GPL");