ptp_pch.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. unsigned long flags;
  389. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  390. struct pch_ts_regs __iomem *regs = pch_dev->regs;
  391. spin_lock_irqsave(&pch_dev->register_lock, flags);
  392. ns = pch_systime_read(regs);
  393. spin_unlock_irqrestore(&pch_dev->register_lock, flags);
  394. *ts = ns_to_timespec64(ns);
  395. return 0;
  396. }
  397. static int ptp_pch_settime(struct ptp_clock_info *ptp,
  398. const struct timespec64 *ts)
  399. {
  400. u64 ns;
  401. unsigned long flags;
  402. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  403. struct pch_ts_regs __iomem *regs = pch_dev->regs;
  404. ns = timespec64_to_ns(ts);
  405. spin_lock_irqsave(&pch_dev->register_lock, flags);
  406. pch_systime_write(regs, ns);
  407. spin_unlock_irqrestore(&pch_dev->register_lock, flags);
  408. return 0;
  409. }
  410. static int ptp_pch_enable(struct ptp_clock_info *ptp,
  411. struct ptp_clock_request *rq, int on)
  412. {
  413. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  414. switch (rq->type) {
  415. case PTP_CLK_REQ_EXTTS:
  416. switch (rq->extts.index) {
  417. case 0:
  418. pch_dev->exts0_enabled = on ? 1 : 0;
  419. break;
  420. case 1:
  421. pch_dev->exts1_enabled = on ? 1 : 0;
  422. break;
  423. default:
  424. return -EINVAL;
  425. }
  426. return 0;
  427. default:
  428. break;
  429. }
  430. return -EOPNOTSUPP;
  431. }
  432. static const struct ptp_clock_info ptp_pch_caps = {
  433. .owner = THIS_MODULE,
  434. .name = "PCH timer",
  435. .max_adj = 50000000,
  436. .n_ext_ts = N_EXT_TS,
  437. .n_pins = 0,
  438. .pps = 0,
  439. .adjfreq = ptp_pch_adjfreq,
  440. .adjtime = ptp_pch_adjtime,
  441. .gettime64 = ptp_pch_gettime,
  442. .settime64 = ptp_pch_settime,
  443. .enable = ptp_pch_enable,
  444. };
  445. #ifdef CONFIG_PM
  446. static s32 pch_suspend(struct pci_dev *pdev, pm_message_t state)
  447. {
  448. pci_disable_device(pdev);
  449. pci_enable_wake(pdev, PCI_D3hot, 0);
  450. if (pci_save_state(pdev) != 0) {
  451. dev_err(&pdev->dev, "could not save PCI config state\n");
  452. return -ENOMEM;
  453. }
  454. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  455. return 0;
  456. }
  457. static s32 pch_resume(struct pci_dev *pdev)
  458. {
  459. s32 ret;
  460. pci_set_power_state(pdev, PCI_D0);
  461. pci_restore_state(pdev);
  462. ret = pci_enable_device(pdev);
  463. if (ret) {
  464. dev_err(&pdev->dev, "pci_enable_device failed\n");
  465. return ret;
  466. }
  467. pci_enable_wake(pdev, PCI_D3hot, 0);
  468. return 0;
  469. }
  470. #else
  471. #define pch_suspend NULL
  472. #define pch_resume NULL
  473. #endif
  474. static void pch_remove(struct pci_dev *pdev)
  475. {
  476. struct pch_dev *chip = pci_get_drvdata(pdev);
  477. ptp_clock_unregister(chip->ptp_clock);
  478. /* free the interrupt */
  479. if (pdev->irq != 0)
  480. free_irq(pdev->irq, chip);
  481. /* unmap the virtual IO memory space */
  482. if (chip->regs != NULL) {
  483. iounmap(chip->regs);
  484. chip->regs = NULL;
  485. }
  486. /* release the reserved IO memory space */
  487. if (chip->mem_base != 0) {
  488. release_mem_region(chip->mem_base, chip->mem_size);
  489. chip->mem_base = 0;
  490. }
  491. pci_disable_device(pdev);
  492. kfree(chip);
  493. dev_info(&pdev->dev, "complete\n");
  494. }
  495. static s32
  496. pch_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  497. {
  498. s32 ret;
  499. unsigned long flags;
  500. struct pch_dev *chip;
  501. chip = kzalloc(sizeof(struct pch_dev), GFP_KERNEL);
  502. if (chip == NULL)
  503. return -ENOMEM;
  504. /* enable the 1588 pci device */
  505. ret = pci_enable_device(pdev);
  506. if (ret != 0) {
  507. dev_err(&pdev->dev, "could not enable the pci device\n");
  508. goto err_pci_en;
  509. }
  510. chip->mem_base = pci_resource_start(pdev, IO_MEM_BAR);
  511. if (!chip->mem_base) {
  512. dev_err(&pdev->dev, "could not locate IO memory address\n");
  513. ret = -ENODEV;
  514. goto err_pci_start;
  515. }
  516. /* retrieve the available length of the IO memory space */
  517. chip->mem_size = pci_resource_len(pdev, IO_MEM_BAR);
  518. /* allocate the memory for the device registers */
  519. if (!request_mem_region(chip->mem_base, chip->mem_size, "1588_regs")) {
  520. dev_err(&pdev->dev,
  521. "could not allocate register memory space\n");
  522. ret = -EBUSY;
  523. goto err_req_mem_region;
  524. }
  525. /* get the virtual address to the 1588 registers */
  526. chip->regs = ioremap(chip->mem_base, chip->mem_size);
  527. if (!chip->regs) {
  528. dev_err(&pdev->dev, "Could not get virtual address\n");
  529. ret = -ENOMEM;
  530. goto err_ioremap;
  531. }
  532. chip->caps = ptp_pch_caps;
  533. chip->ptp_clock = ptp_clock_register(&chip->caps, &pdev->dev);
  534. if (IS_ERR(chip->ptp_clock)) {
  535. ret = PTR_ERR(chip->ptp_clock);
  536. goto err_ptp_clock_reg;
  537. }
  538. spin_lock_init(&chip->register_lock);
  539. ret = request_irq(pdev->irq, &isr, IRQF_SHARED, KBUILD_MODNAME, chip);
  540. if (ret != 0) {
  541. dev_err(&pdev->dev, "failed to get irq %d\n", pdev->irq);
  542. goto err_req_irq;
  543. }
  544. /* indicate success */
  545. chip->irq = pdev->irq;
  546. chip->pdev = pdev;
  547. pci_set_drvdata(pdev, chip);
  548. spin_lock_irqsave(&chip->register_lock, flags);
  549. /* reset the ieee1588 h/w */
  550. pch_reset(chip);
  551. iowrite32(DEFAULT_ADDEND, &chip->regs->addend);
  552. iowrite32(1, &chip->regs->trgt_lo);
  553. iowrite32(0, &chip->regs->trgt_hi);
  554. iowrite32(PCH_TSE_TTIPEND, &chip->regs->event);
  555. pch_eth_enable_set(chip);
  556. if (strcmp(pch_param.station, "00:00:00:00:00:00") != 0) {
  557. if (pch_set_station_address(pch_param.station, pdev) != 0) {
  558. dev_err(&pdev->dev,
  559. "Invalid station address parameter\n"
  560. "Module loaded but station address not set correctly\n"
  561. );
  562. }
  563. }
  564. spin_unlock_irqrestore(&chip->register_lock, flags);
  565. return 0;
  566. err_req_irq:
  567. ptp_clock_unregister(chip->ptp_clock);
  568. err_ptp_clock_reg:
  569. iounmap(chip->regs);
  570. chip->regs = NULL;
  571. err_ioremap:
  572. release_mem_region(chip->mem_base, chip->mem_size);
  573. err_req_mem_region:
  574. chip->mem_base = 0;
  575. err_pci_start:
  576. pci_disable_device(pdev);
  577. err_pci_en:
  578. kfree(chip);
  579. dev_err(&pdev->dev, "probe failed(ret=0x%x)\n", ret);
  580. return ret;
  581. }
  582. static const struct pci_device_id pch_ieee1588_pcidev_id[] = {
  583. {
  584. .vendor = PCI_VENDOR_ID_INTEL,
  585. .device = PCI_DEVICE_ID_PCH_1588
  586. },
  587. {0}
  588. };
  589. static struct pci_driver pch_driver = {
  590. .name = KBUILD_MODNAME,
  591. .id_table = pch_ieee1588_pcidev_id,
  592. .probe = pch_probe,
  593. .remove = pch_remove,
  594. .suspend = pch_suspend,
  595. .resume = pch_resume,
  596. };
  597. static void __exit ptp_pch_exit(void)
  598. {
  599. pci_unregister_driver(&pch_driver);
  600. }
  601. static s32 __init ptp_pch_init(void)
  602. {
  603. s32 ret;
  604. /* register the driver with the pci core */
  605. ret = pci_register_driver(&pch_driver);
  606. return ret;
  607. }
  608. module_init(ptp_pch_init);
  609. module_exit(ptp_pch_exit);
  610. module_param_string(station,
  611. pch_param.station, sizeof(pch_param.station), 0444);
  612. MODULE_PARM_DESC(station,
  613. "IEEE 1588 station address to use - colon separated hex values");
  614. MODULE_AUTHOR("LAPIS SEMICONDUCTOR, <tshimizu818@gmail.com>");
  615. MODULE_DESCRIPTION("PTP clock using the EG20T timer");
  616. MODULE_LICENSE("GPL");