ptp_pch.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * PTP 1588 clock using the EG20T PCH
  4. *
  5. * Copyright (C) 2010 OMICRON electronics GmbH
  6. * Copyright (C) 2011-2012 LAPIS SEMICONDUCTOR Co., LTD.
  7. *
  8. * This code was derived from the IXP46X driver.
  9. */
  10. #include <linux/device.h>
  11. #include <linux/err.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/irq.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/pci.h>
  19. #include <linux/ptp_clock_kernel.h>
  20. #include <linux/slab.h>
  21. #define STATION_ADDR_LEN 20
  22. #define PCI_DEVICE_ID_PCH_1588 0x8819
  23. #define IO_MEM_BAR 1
  24. #define DEFAULT_ADDEND 0xA0000000
  25. #define TICKS_NS_SHIFT 5
  26. #define N_EXT_TS 2
  27. enum pch_status {
  28. PCH_SUCCESS,
  29. PCH_INVALIDPARAM,
  30. PCH_NOTIMESTAMP,
  31. PCH_INTERRUPTMODEINUSE,
  32. PCH_FAILED,
  33. PCH_UNSUPPORTED,
  34. };
  35. /**
  36. * struct pch_ts_regs - IEEE 1588 registers
  37. */
  38. struct pch_ts_regs {
  39. u32 control;
  40. u32 event;
  41. u32 addend;
  42. u32 accum;
  43. u32 test;
  44. u32 ts_compare;
  45. u32 rsystime_lo;
  46. u32 rsystime_hi;
  47. u32 systime_lo;
  48. u32 systime_hi;
  49. u32 trgt_lo;
  50. u32 trgt_hi;
  51. u32 asms_lo;
  52. u32 asms_hi;
  53. u32 amms_lo;
  54. u32 amms_hi;
  55. u32 ch_control;
  56. u32 ch_event;
  57. u32 tx_snap_lo;
  58. u32 tx_snap_hi;
  59. u32 rx_snap_lo;
  60. u32 rx_snap_hi;
  61. u32 src_uuid_lo;
  62. u32 src_uuid_hi;
  63. u32 can_status;
  64. u32 can_snap_lo;
  65. u32 can_snap_hi;
  66. u32 ts_sel;
  67. u32 ts_st[6];
  68. u32 reserve1[14];
  69. u32 stl_max_set_en;
  70. u32 stl_max_set;
  71. u32 reserve2[13];
  72. u32 srst;
  73. };
  74. #define PCH_TSC_RESET (1 << 0)
  75. #define PCH_TSC_TTM_MASK (1 << 1)
  76. #define PCH_TSC_ASMS_MASK (1 << 2)
  77. #define PCH_TSC_AMMS_MASK (1 << 3)
  78. #define PCH_TSC_PPSM_MASK (1 << 4)
  79. #define PCH_TSE_TTIPEND (1 << 1)
  80. #define PCH_TSE_SNS (1 << 2)
  81. #define PCH_TSE_SNM (1 << 3)
  82. #define PCH_TSE_PPS (1 << 4)
  83. #define PCH_CC_MM (1 << 0)
  84. #define PCH_CC_TA (1 << 1)
  85. #define PCH_CC_MODE_SHIFT 16
  86. #define PCH_CC_MODE_MASK 0x001F0000
  87. #define PCH_CC_VERSION (1 << 31)
  88. #define PCH_CE_TXS (1 << 0)
  89. #define PCH_CE_RXS (1 << 1)
  90. #define PCH_CE_OVR (1 << 0)
  91. #define PCH_CE_VAL (1 << 1)
  92. #define PCH_ECS_ETH (1 << 0)
  93. #define PCH_ECS_CAN (1 << 1)
  94. #define PCH_STATION_BYTES 6
  95. #define PCH_IEEE1588_ETH (1 << 0)
  96. #define PCH_IEEE1588_CAN (1 << 1)
  97. /**
  98. * struct pch_dev - Driver private data
  99. */
  100. struct pch_dev {
  101. struct pch_ts_regs __iomem *regs;
  102. struct ptp_clock *ptp_clock;
  103. struct ptp_clock_info caps;
  104. int exts0_enabled;
  105. int exts1_enabled;
  106. u32 mem_base;
  107. u32 mem_size;
  108. u32 irq;
  109. struct pci_dev *pdev;
  110. spinlock_t register_lock;
  111. };
  112. /**
  113. * struct pch_params - 1588 module parameter
  114. */
  115. struct pch_params {
  116. u8 station[STATION_ADDR_LEN];
  117. };
  118. /* structure to hold the module parameters */
  119. static struct pch_params pch_param = {
  120. "00:00:00:00:00:00"
  121. };
  122. /*
  123. * Register access functions
  124. */
  125. static inline void pch_eth_enable_set(struct pch_dev *chip)
  126. {
  127. u32 val;
  128. /* SET the eth_enable bit */
  129. val = ioread32(&chip->regs->ts_sel) | (PCH_ECS_ETH);
  130. iowrite32(val, (&chip->regs->ts_sel));
  131. }
  132. static u64 pch_systime_read(struct pch_ts_regs __iomem *regs)
  133. {
  134. u64 ns;
  135. u32 lo, hi;
  136. lo = ioread32(&regs->systime_lo);
  137. hi = ioread32(&regs->systime_hi);
  138. ns = ((u64) hi) << 32;
  139. ns |= lo;
  140. ns <<= TICKS_NS_SHIFT;
  141. return ns;
  142. }
  143. static void pch_systime_write(struct pch_ts_regs __iomem *regs, u64 ns)
  144. {
  145. u32 hi, lo;
  146. ns >>= TICKS_NS_SHIFT;
  147. hi = ns >> 32;
  148. lo = ns & 0xffffffff;
  149. iowrite32(lo, &regs->systime_lo);
  150. iowrite32(hi, &regs->systime_hi);
  151. }
  152. static inline void pch_block_reset(struct pch_dev *chip)
  153. {
  154. u32 val;
  155. /* Reset Hardware Assist block */
  156. val = ioread32(&chip->regs->control) | PCH_TSC_RESET;
  157. iowrite32(val, (&chip->regs->control));
  158. val = val & ~PCH_TSC_RESET;
  159. iowrite32(val, (&chip->regs->control));
  160. }
  161. u32 pch_ch_control_read(struct pci_dev *pdev)
  162. {
  163. struct pch_dev *chip = pci_get_drvdata(pdev);
  164. u32 val;
  165. val = ioread32(&chip->regs->ch_control);
  166. return val;
  167. }
  168. EXPORT_SYMBOL(pch_ch_control_read);
  169. void pch_ch_control_write(struct pci_dev *pdev, u32 val)
  170. {
  171. struct pch_dev *chip = pci_get_drvdata(pdev);
  172. iowrite32(val, (&chip->regs->ch_control));
  173. }
  174. EXPORT_SYMBOL(pch_ch_control_write);
  175. u32 pch_ch_event_read(struct pci_dev *pdev)
  176. {
  177. struct pch_dev *chip = pci_get_drvdata(pdev);
  178. u32 val;
  179. val = ioread32(&chip->regs->ch_event);
  180. return val;
  181. }
  182. EXPORT_SYMBOL(pch_ch_event_read);
  183. void pch_ch_event_write(struct pci_dev *pdev, u32 val)
  184. {
  185. struct pch_dev *chip = pci_get_drvdata(pdev);
  186. iowrite32(val, (&chip->regs->ch_event));
  187. }
  188. EXPORT_SYMBOL(pch_ch_event_write);
  189. u32 pch_src_uuid_lo_read(struct pci_dev *pdev)
  190. {
  191. struct pch_dev *chip = pci_get_drvdata(pdev);
  192. u32 val;
  193. val = ioread32(&chip->regs->src_uuid_lo);
  194. return val;
  195. }
  196. EXPORT_SYMBOL(pch_src_uuid_lo_read);
  197. u32 pch_src_uuid_hi_read(struct pci_dev *pdev)
  198. {
  199. struct pch_dev *chip = pci_get_drvdata(pdev);
  200. u32 val;
  201. val = ioread32(&chip->regs->src_uuid_hi);
  202. return val;
  203. }
  204. EXPORT_SYMBOL(pch_src_uuid_hi_read);
  205. u64 pch_rx_snap_read(struct pci_dev *pdev)
  206. {
  207. struct pch_dev *chip = pci_get_drvdata(pdev);
  208. u64 ns;
  209. u32 lo, hi;
  210. lo = ioread32(&chip->regs->rx_snap_lo);
  211. hi = ioread32(&chip->regs->rx_snap_hi);
  212. ns = ((u64) hi) << 32;
  213. ns |= lo;
  214. ns <<= TICKS_NS_SHIFT;
  215. return ns;
  216. }
  217. EXPORT_SYMBOL(pch_rx_snap_read);
  218. u64 pch_tx_snap_read(struct pci_dev *pdev)
  219. {
  220. struct pch_dev *chip = pci_get_drvdata(pdev);
  221. u64 ns;
  222. u32 lo, hi;
  223. lo = ioread32(&chip->regs->tx_snap_lo);
  224. hi = ioread32(&chip->regs->tx_snap_hi);
  225. ns = ((u64) hi) << 32;
  226. ns |= lo;
  227. ns <<= TICKS_NS_SHIFT;
  228. return ns;
  229. }
  230. EXPORT_SYMBOL(pch_tx_snap_read);
  231. /* This function enables all 64 bits in system time registers [high & low].
  232. This is a work-around for non continuous value in the SystemTime Register*/
  233. static void pch_set_system_time_count(struct pch_dev *chip)
  234. {
  235. iowrite32(0x01, &chip->regs->stl_max_set_en);
  236. iowrite32(0xFFFFFFFF, &chip->regs->stl_max_set);
  237. iowrite32(0x00, &chip->regs->stl_max_set_en);
  238. }
  239. static void pch_reset(struct pch_dev *chip)
  240. {
  241. /* Reset Hardware Assist */
  242. pch_block_reset(chip);
  243. /* enable all 32 bits in system time registers */
  244. pch_set_system_time_count(chip);
  245. }
  246. /**
  247. * pch_set_station_address() - This API sets the station address used by
  248. * IEEE 1588 hardware when looking at PTP
  249. * traffic on the ethernet interface
  250. * @addr: dress which contain the column separated address to be used.
  251. */
  252. int pch_set_station_address(u8 *addr, struct pci_dev *pdev)
  253. {
  254. s32 i;
  255. struct pch_dev *chip = pci_get_drvdata(pdev);
  256. /* Verify the parameter */
  257. if ((chip->regs == NULL) || addr == (u8 *)NULL) {
  258. dev_err(&pdev->dev,
  259. "invalid params returning PCH_INVALIDPARAM\n");
  260. return PCH_INVALIDPARAM;
  261. }
  262. /* For all station address bytes */
  263. for (i = 0; i < PCH_STATION_BYTES; i++) {
  264. u32 val;
  265. s32 tmp;
  266. tmp = hex_to_bin(addr[i * 3]);
  267. if (tmp < 0) {
  268. dev_err(&pdev->dev,
  269. "invalid params returning PCH_INVALIDPARAM\n");
  270. return PCH_INVALIDPARAM;
  271. }
  272. val = tmp * 16;
  273. tmp = hex_to_bin(addr[(i * 3) + 1]);
  274. if (tmp < 0) {
  275. dev_err(&pdev->dev,
  276. "invalid params returning PCH_INVALIDPARAM\n");
  277. return PCH_INVALIDPARAM;
  278. }
  279. val += tmp;
  280. /* Expects ':' separated addresses */
  281. if ((i < 5) && (addr[(i * 3) + 2] != ':')) {
  282. dev_err(&pdev->dev,
  283. "invalid params returning PCH_INVALIDPARAM\n");
  284. return PCH_INVALIDPARAM;
  285. }
  286. /* Ideally we should set the address only after validating
  287. entire string */
  288. dev_dbg(&pdev->dev, "invoking pch_station_set\n");
  289. iowrite32(val, &chip->regs->ts_st[i]);
  290. }
  291. return 0;
  292. }
  293. EXPORT_SYMBOL(pch_set_station_address);
  294. /*
  295. * Interrupt service routine
  296. */
  297. static irqreturn_t isr(int irq, void *priv)
  298. {
  299. struct pch_dev *pch_dev = priv;
  300. struct pch_ts_regs __iomem *regs = pch_dev->regs;
  301. struct ptp_clock_event event;
  302. u32 ack = 0, lo, hi, val;
  303. val = ioread32(&regs->event);
  304. if (val & PCH_TSE_SNS) {
  305. ack |= PCH_TSE_SNS;
  306. if (pch_dev->exts0_enabled) {
  307. hi = ioread32(&regs->asms_hi);
  308. lo = ioread32(&regs->asms_lo);
  309. event.type = PTP_CLOCK_EXTTS;
  310. event.index = 0;
  311. event.timestamp = ((u64) hi) << 32;
  312. event.timestamp |= lo;
  313. event.timestamp <<= TICKS_NS_SHIFT;
  314. ptp_clock_event(pch_dev->ptp_clock, &event);
  315. }
  316. }
  317. if (val & PCH_TSE_SNM) {
  318. ack |= PCH_TSE_SNM;
  319. if (pch_dev->exts1_enabled) {
  320. hi = ioread32(&regs->amms_hi);
  321. lo = ioread32(&regs->amms_lo);
  322. event.type = PTP_CLOCK_EXTTS;
  323. event.index = 1;
  324. event.timestamp = ((u64) hi) << 32;
  325. event.timestamp |= lo;
  326. event.timestamp <<= TICKS_NS_SHIFT;
  327. ptp_clock_event(pch_dev->ptp_clock, &event);
  328. }
  329. }
  330. if (val & PCH_TSE_TTIPEND)
  331. ack |= PCH_TSE_TTIPEND; /* this bit seems to be always set */
  332. if (ack) {
  333. iowrite32(ack, &regs->event);
  334. return IRQ_HANDLED;
  335. } else
  336. return IRQ_NONE;
  337. }
  338. /*
  339. * PTP clock operations
  340. */
  341. static int ptp_pch_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  342. {
  343. u64 adj;
  344. u32 diff, addend;
  345. int neg_adj = 0;
  346. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  347. struct pch_ts_regs __iomem *regs = pch_dev->regs;
  348. if (ppb < 0) {
  349. neg_adj = 1;
  350. ppb = -ppb;
  351. }
  352. addend = DEFAULT_ADDEND;
  353. adj = addend;
  354. adj *= ppb;
  355. diff = div_u64(adj, 1000000000ULL);
  356. addend = neg_adj ? addend - diff : addend + diff;
  357. iowrite32(addend, &regs->addend);
  358. return 0;
  359. }
  360. static int ptp_pch_adjtime(struct ptp_clock_info *ptp, s64 delta)
  361. {
  362. s64 now;
  363. unsigned long flags;
  364. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  365. struct pch_ts_regs __iomem *regs = pch_dev->regs;
  366. spin_lock_irqsave(&pch_dev->register_lock, flags);
  367. now = pch_systime_read(regs);
  368. now += delta;
  369. pch_systime_write(regs, now);
  370. spin_unlock_irqrestore(&pch_dev->register_lock, flags);
  371. return 0;
  372. }
  373. static int ptp_pch_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
  374. {
  375. u64 ns;
  376. unsigned long flags;
  377. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  378. struct pch_ts_regs __iomem *regs = pch_dev->regs;
  379. spin_lock_irqsave(&pch_dev->register_lock, flags);
  380. ns = pch_systime_read(regs);
  381. spin_unlock_irqrestore(&pch_dev->register_lock, flags);
  382. *ts = ns_to_timespec64(ns);
  383. return 0;
  384. }
  385. static int ptp_pch_settime(struct ptp_clock_info *ptp,
  386. const struct timespec64 *ts)
  387. {
  388. u64 ns;
  389. unsigned long flags;
  390. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  391. struct pch_ts_regs __iomem *regs = pch_dev->regs;
  392. ns = timespec64_to_ns(ts);
  393. spin_lock_irqsave(&pch_dev->register_lock, flags);
  394. pch_systime_write(regs, ns);
  395. spin_unlock_irqrestore(&pch_dev->register_lock, flags);
  396. return 0;
  397. }
  398. static int ptp_pch_enable(struct ptp_clock_info *ptp,
  399. struct ptp_clock_request *rq, int on)
  400. {
  401. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  402. switch (rq->type) {
  403. case PTP_CLK_REQ_EXTTS:
  404. switch (rq->extts.index) {
  405. case 0:
  406. pch_dev->exts0_enabled = on ? 1 : 0;
  407. break;
  408. case 1:
  409. pch_dev->exts1_enabled = on ? 1 : 0;
  410. break;
  411. default:
  412. return -EINVAL;
  413. }
  414. return 0;
  415. default:
  416. break;
  417. }
  418. return -EOPNOTSUPP;
  419. }
  420. static const struct ptp_clock_info ptp_pch_caps = {
  421. .owner = THIS_MODULE,
  422. .name = "PCH timer",
  423. .max_adj = 50000000,
  424. .n_ext_ts = N_EXT_TS,
  425. .n_pins = 0,
  426. .pps = 0,
  427. .adjfreq = ptp_pch_adjfreq,
  428. .adjtime = ptp_pch_adjtime,
  429. .gettime64 = ptp_pch_gettime,
  430. .settime64 = ptp_pch_settime,
  431. .enable = ptp_pch_enable,
  432. };
  433. #ifdef CONFIG_PM
  434. static s32 pch_suspend(struct pci_dev *pdev, pm_message_t state)
  435. {
  436. pci_disable_device(pdev);
  437. pci_enable_wake(pdev, PCI_D3hot, 0);
  438. if (pci_save_state(pdev) != 0) {
  439. dev_err(&pdev->dev, "could not save PCI config state\n");
  440. return -ENOMEM;
  441. }
  442. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  443. return 0;
  444. }
  445. static s32 pch_resume(struct pci_dev *pdev)
  446. {
  447. s32 ret;
  448. pci_set_power_state(pdev, PCI_D0);
  449. pci_restore_state(pdev);
  450. ret = pci_enable_device(pdev);
  451. if (ret) {
  452. dev_err(&pdev->dev, "pci_enable_device failed\n");
  453. return ret;
  454. }
  455. pci_enable_wake(pdev, PCI_D3hot, 0);
  456. return 0;
  457. }
  458. #else
  459. #define pch_suspend NULL
  460. #define pch_resume NULL
  461. #endif
  462. static void pch_remove(struct pci_dev *pdev)
  463. {
  464. struct pch_dev *chip = pci_get_drvdata(pdev);
  465. ptp_clock_unregister(chip->ptp_clock);
  466. /* free the interrupt */
  467. if (pdev->irq != 0)
  468. free_irq(pdev->irq, chip);
  469. /* unmap the virtual IO memory space */
  470. if (chip->regs != NULL) {
  471. iounmap(chip->regs);
  472. chip->regs = NULL;
  473. }
  474. /* release the reserved IO memory space */
  475. if (chip->mem_base != 0) {
  476. release_mem_region(chip->mem_base, chip->mem_size);
  477. chip->mem_base = 0;
  478. }
  479. pci_disable_device(pdev);
  480. kfree(chip);
  481. dev_info(&pdev->dev, "complete\n");
  482. }
  483. static s32
  484. pch_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  485. {
  486. s32 ret;
  487. unsigned long flags;
  488. struct pch_dev *chip;
  489. chip = kzalloc(sizeof(struct pch_dev), GFP_KERNEL);
  490. if (chip == NULL)
  491. return -ENOMEM;
  492. /* enable the 1588 pci device */
  493. ret = pci_enable_device(pdev);
  494. if (ret != 0) {
  495. dev_err(&pdev->dev, "could not enable the pci device\n");
  496. goto err_pci_en;
  497. }
  498. chip->mem_base = pci_resource_start(pdev, IO_MEM_BAR);
  499. if (!chip->mem_base) {
  500. dev_err(&pdev->dev, "could not locate IO memory address\n");
  501. ret = -ENODEV;
  502. goto err_pci_start;
  503. }
  504. /* retrieve the available length of the IO memory space */
  505. chip->mem_size = pci_resource_len(pdev, IO_MEM_BAR);
  506. /* allocate the memory for the device registers */
  507. if (!request_mem_region(chip->mem_base, chip->mem_size, "1588_regs")) {
  508. dev_err(&pdev->dev,
  509. "could not allocate register memory space\n");
  510. ret = -EBUSY;
  511. goto err_req_mem_region;
  512. }
  513. /* get the virtual address to the 1588 registers */
  514. chip->regs = ioremap(chip->mem_base, chip->mem_size);
  515. if (!chip->regs) {
  516. dev_err(&pdev->dev, "Could not get virtual address\n");
  517. ret = -ENOMEM;
  518. goto err_ioremap;
  519. }
  520. chip->caps = ptp_pch_caps;
  521. chip->ptp_clock = ptp_clock_register(&chip->caps, &pdev->dev);
  522. if (IS_ERR(chip->ptp_clock)) {
  523. ret = PTR_ERR(chip->ptp_clock);
  524. goto err_ptp_clock_reg;
  525. }
  526. spin_lock_init(&chip->register_lock);
  527. ret = request_irq(pdev->irq, &isr, IRQF_SHARED, KBUILD_MODNAME, chip);
  528. if (ret != 0) {
  529. dev_err(&pdev->dev, "failed to get irq %d\n", pdev->irq);
  530. goto err_req_irq;
  531. }
  532. /* indicate success */
  533. chip->irq = pdev->irq;
  534. chip->pdev = pdev;
  535. pci_set_drvdata(pdev, chip);
  536. spin_lock_irqsave(&chip->register_lock, flags);
  537. /* reset the ieee1588 h/w */
  538. pch_reset(chip);
  539. iowrite32(DEFAULT_ADDEND, &chip->regs->addend);
  540. iowrite32(1, &chip->regs->trgt_lo);
  541. iowrite32(0, &chip->regs->trgt_hi);
  542. iowrite32(PCH_TSE_TTIPEND, &chip->regs->event);
  543. pch_eth_enable_set(chip);
  544. if (strcmp(pch_param.station, "00:00:00:00:00:00") != 0) {
  545. if (pch_set_station_address(pch_param.station, pdev) != 0) {
  546. dev_err(&pdev->dev,
  547. "Invalid station address parameter\n"
  548. "Module loaded but station address not set correctly\n"
  549. );
  550. }
  551. }
  552. spin_unlock_irqrestore(&chip->register_lock, flags);
  553. return 0;
  554. err_req_irq:
  555. ptp_clock_unregister(chip->ptp_clock);
  556. err_ptp_clock_reg:
  557. iounmap(chip->regs);
  558. chip->regs = NULL;
  559. err_ioremap:
  560. release_mem_region(chip->mem_base, chip->mem_size);
  561. err_req_mem_region:
  562. chip->mem_base = 0;
  563. err_pci_start:
  564. pci_disable_device(pdev);
  565. err_pci_en:
  566. kfree(chip);
  567. dev_err(&pdev->dev, "probe failed(ret=0x%x)\n", ret);
  568. return ret;
  569. }
  570. static const struct pci_device_id pch_ieee1588_pcidev_id[] = {
  571. {
  572. .vendor = PCI_VENDOR_ID_INTEL,
  573. .device = PCI_DEVICE_ID_PCH_1588
  574. },
  575. {0}
  576. };
  577. static struct pci_driver pch_driver = {
  578. .name = KBUILD_MODNAME,
  579. .id_table = pch_ieee1588_pcidev_id,
  580. .probe = pch_probe,
  581. .remove = pch_remove,
  582. .suspend = pch_suspend,
  583. .resume = pch_resume,
  584. };
  585. static void __exit ptp_pch_exit(void)
  586. {
  587. pci_unregister_driver(&pch_driver);
  588. }
  589. static s32 __init ptp_pch_init(void)
  590. {
  591. s32 ret;
  592. /* register the driver with the pci core */
  593. ret = pci_register_driver(&pch_driver);
  594. return ret;
  595. }
  596. module_init(ptp_pch_init);
  597. module_exit(ptp_pch_exit);
  598. module_param_string(station,
  599. pch_param.station, sizeof(pch_param.station), 0444);
  600. MODULE_PARM_DESC(station,
  601. "IEEE 1588 station address to use - colon separated hex values");
  602. MODULE_AUTHOR("LAPIS SEMICONDUCTOR, <tshimizu818@gmail.com>");
  603. MODULE_DESCRIPTION("PTP clock using the EG20T timer");
  604. MODULE_LICENSE("GPL");