23 #include <linux/device.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/pci.h>
33 #include <linux/slab.h>
35 #define STATION_ADDR_LEN 20
36 #define PCI_DEVICE_ID_PCH_1588 0x8819
39 #define DEFAULT_ADDEND 0xA0000000
40 #define TICKS_NS_SHIFT 5
91 #define PCH_TSC_RESET (1 << 0)
92 #define PCH_TSC_TTM_MASK (1 << 1)
93 #define PCH_TSC_ASMS_MASK (1 << 2)
94 #define PCH_TSC_AMMS_MASK (1 << 3)
95 #define PCH_TSC_PPSM_MASK (1 << 4)
96 #define PCH_TSE_TTIPEND (1 << 1)
97 #define PCH_TSE_SNS (1 << 2)
98 #define PCH_TSE_SNM (1 << 3)
99 #define PCH_TSE_PPS (1 << 4)
100 #define PCH_CC_MM (1 << 0)
101 #define PCH_CC_TA (1 << 1)
103 #define PCH_CC_MODE_SHIFT 16
104 #define PCH_CC_MODE_MASK 0x001F0000
105 #define PCH_CC_VERSION (1 << 31)
106 #define PCH_CE_TXS (1 << 0)
107 #define PCH_CE_RXS (1 << 1)
108 #define PCH_CE_OVR (1 << 0)
109 #define PCH_CE_VAL (1 << 1)
110 #define PCH_ECS_ETH (1 << 0)
112 #define PCH_ECS_CAN (1 << 1)
113 #define PCH_STATION_BYTES 6
115 #define PCH_IEEE1588_ETH (1 << 0)
116 #define PCH_IEEE1588_CAN (1 << 1)
149 static inline void pch_eth_enable_set(
struct pch_dev *
chip)
165 ns = ((
u64) hi) << 32;
178 lo = ns & 0xffffffff;
184 static inline void pch_block_reset(
struct pch_dev *chip)
196 struct pch_dev *chip = pci_get_drvdata(pdev);
207 struct pch_dev *chip = pci_get_drvdata(pdev);
215 struct pch_dev *chip = pci_get_drvdata(pdev);
226 struct pch_dev *chip = pci_get_drvdata(pdev);
234 struct pch_dev *chip = pci_get_drvdata(pdev);
245 struct pch_dev *chip = pci_get_drvdata(pdev);
256 struct pch_dev *chip = pci_get_drvdata(pdev);
263 ns = ((
u64) hi) << 32;
273 struct pch_dev *chip = pci_get_drvdata(pdev);
280 ns = ((
u64) hi) << 32;
290 static void pch_set_system_time_count(
struct pch_dev *chip)
297 static void pch_reset(
struct pch_dev *chip)
300 pch_block_reset(chip);
303 pch_set_system_time_count(chip);
315 struct pch_dev *chip = pci_get_drvdata(pdev);
318 if ((chip->
regs == 0) || addr == (
u8 *)
NULL) {
320 "invalid params returning PCH_INVALIDPARAM\n");
331 "invalid params returning PCH_INVALIDPARAM\n");
338 "invalid params returning PCH_INVALIDPARAM\n");
343 if ((i < 5) && (addr[(i * 3) + 2] !=
':')) {
345 "invalid params returning PCH_INVALIDPARAM\n");
351 dev_dbg(&pdev->
dev,
"invoking pch_station_set\n");
377 event.timestamp = ((
u64) hi) << 32;
378 event.timestamp |=
lo;
391 event.timestamp = ((
u64) hi) << 32;
392 event.timestamp |=
lo;
427 diff = div_u64(adj, 1000000000ULL);
429 addend = neg_adj ? addend - diff : addend + diff;
444 now = pch_systime_read(regs);
446 pch_systime_write(regs, now);
461 ns = pch_systime_read(regs);
464 ts->
tv_sec = div_u64_rem(ns, 1000000000, &remainder);
477 ns = ts->
tv_sec * 1000000000ULL;
481 pch_systime_write(regs, ns);
493 case PTP_CLK_REQ_EXTTS:
494 switch (rq->
extts.index) {
518 .adjfreq = ptp_pch_adjfreq,
519 .adjtime = ptp_pch_adjtime,
520 .gettime = ptp_pch_gettime,
521 .settime = ptp_pch_settime,
522 .enable = ptp_pch_enable,
533 dev_err(&pdev->
dev,
"could not save PCI config state\n");
549 dev_err(&pdev->
dev,
"pci_enable_device failed\n");
556 #define pch_suspend NULL
557 #define pch_resume NULL
562 struct pch_dev *chip = pci_get_drvdata(pdev);
570 if (chip->
regs != 0) {
589 struct pch_dev *
chip;
591 chip = kzalloc(
sizeof(
struct pch_dev),
GFP_KERNEL);
598 dev_err(&pdev->
dev,
"could not enable the pci device\n");
604 dev_err(&pdev->
dev,
"could not locate IO memory address\n");
615 "could not allocate register memory space\n");
617 goto err_req_mem_region;
624 dev_err(&pdev->
dev,
"Could not get virtual address\n");
629 chip->
caps = ptp_pch_caps;
646 pci_set_drvdata(pdev, chip);
657 pch_eth_enable_set(chip);
662 "Invalid station address parameter\n"
663 "Module loaded but station address not set correctly\n"
686 dev_err(&pdev->
dev,
"probe failed(ret=0x%x)\n", ret);
700 .name = KBUILD_MODNAME,
701 .id_table = pch_ieee1588_pcidev_id,
703 .remove = pch_remove,
708 static void __exit ptp_pch_exit(
void)
718 ret = pci_register_driver(&pch_driver);
728 "IEEE 1588 station address to use - column separated hex values");