ptp_pch.c 16 KB

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