ptp_pch.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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 *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 *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 *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. return ns;
  227. }
  228. EXPORT_SYMBOL(pch_rx_snap_read);
  229. u64 pch_tx_snap_read(struct pci_dev *pdev)
  230. {
  231. struct pch_dev *chip = pci_get_drvdata(pdev);
  232. u64 ns;
  233. u32 lo, hi;
  234. lo = ioread32(&chip->regs->tx_snap_lo);
  235. hi = ioread32(&chip->regs->tx_snap_hi);
  236. ns = ((u64) hi) << 32;
  237. ns |= lo;
  238. return ns;
  239. }
  240. EXPORT_SYMBOL(pch_tx_snap_read);
  241. /* This function enables all 64 bits in system time registers [high & low].
  242. This is a work-around for non continuous value in the SystemTime Register*/
  243. static void pch_set_system_time_count(struct pch_dev *chip)
  244. {
  245. iowrite32(0x01, &chip->regs->stl_max_set_en);
  246. iowrite32(0xFFFFFFFF, &chip->regs->stl_max_set);
  247. iowrite32(0x00, &chip->regs->stl_max_set_en);
  248. }
  249. static void pch_reset(struct pch_dev *chip)
  250. {
  251. /* Reset Hardware Assist */
  252. pch_block_reset(chip);
  253. /* enable all 32 bits in system time registers */
  254. pch_set_system_time_count(chip);
  255. }
  256. /**
  257. * pch_set_station_address() - This API sets the station address used by
  258. * IEEE 1588 hardware when looking at PTP
  259. * traffic on the ethernet interface
  260. * @addr: dress which contain the column separated address to be used.
  261. */
  262. static int pch_set_station_address(u8 *addr, struct pci_dev *pdev)
  263. {
  264. s32 i;
  265. struct pch_dev *chip = pci_get_drvdata(pdev);
  266. /* Verify the parameter */
  267. if ((chip->regs == 0) || addr == (u8 *)NULL) {
  268. dev_err(&pdev->dev,
  269. "invalid params returning PCH_INVALIDPARAM\n");
  270. return PCH_INVALIDPARAM;
  271. }
  272. /* For all station address bytes */
  273. for (i = 0; i < PCH_STATION_BYTES; i++) {
  274. u32 val;
  275. s32 tmp;
  276. tmp = hex_to_bin(addr[i * 3]);
  277. if (tmp < 0) {
  278. dev_err(&pdev->dev,
  279. "invalid params returning PCH_INVALIDPARAM\n");
  280. return PCH_INVALIDPARAM;
  281. }
  282. val = tmp * 16;
  283. tmp = hex_to_bin(addr[(i * 3) + 1]);
  284. if (tmp < 0) {
  285. dev_err(&pdev->dev,
  286. "invalid params returning PCH_INVALIDPARAM\n");
  287. return PCH_INVALIDPARAM;
  288. }
  289. val += tmp;
  290. /* Expects ':' separated addresses */
  291. if ((i < 5) && (addr[(i * 3) + 2] != ':')) {
  292. dev_err(&pdev->dev,
  293. "invalid params returning PCH_INVALIDPARAM\n");
  294. return PCH_INVALIDPARAM;
  295. }
  296. /* Ideally we should set the address only after validating
  297. entire string */
  298. dev_dbg(&pdev->dev, "invoking pch_station_set\n");
  299. iowrite32(val, &chip->regs->ts_st[i]);
  300. }
  301. return 0;
  302. }
  303. /*
  304. * Interrupt service routine
  305. */
  306. static irqreturn_t isr(int irq, void *priv)
  307. {
  308. struct pch_dev *pch_dev = priv;
  309. struct pch_ts_regs *regs = pch_dev->regs;
  310. struct ptp_clock_event event;
  311. u32 ack = 0, lo, hi, val;
  312. val = ioread32(&regs->event);
  313. if (val & PCH_TSE_SNS) {
  314. ack |= PCH_TSE_SNS;
  315. if (pch_dev->exts0_enabled) {
  316. hi = ioread32(&regs->asms_hi);
  317. lo = ioread32(&regs->asms_lo);
  318. event.type = PTP_CLOCK_EXTTS;
  319. event.index = 0;
  320. event.timestamp = ((u64) hi) << 32;
  321. event.timestamp |= lo;
  322. event.timestamp <<= TICKS_NS_SHIFT;
  323. ptp_clock_event(pch_dev->ptp_clock, &event);
  324. }
  325. }
  326. if (val & PCH_TSE_SNM) {
  327. ack |= PCH_TSE_SNM;
  328. if (pch_dev->exts1_enabled) {
  329. hi = ioread32(&regs->amms_hi);
  330. lo = ioread32(&regs->amms_lo);
  331. event.type = PTP_CLOCK_EXTTS;
  332. event.index = 1;
  333. event.timestamp = ((u64) hi) << 32;
  334. event.timestamp |= lo;
  335. event.timestamp <<= TICKS_NS_SHIFT;
  336. ptp_clock_event(pch_dev->ptp_clock, &event);
  337. }
  338. }
  339. if (val & PCH_TSE_TTIPEND)
  340. ack |= PCH_TSE_TTIPEND; /* this bit seems to be always set */
  341. if (ack) {
  342. iowrite32(ack, &regs->event);
  343. return IRQ_HANDLED;
  344. } else
  345. return IRQ_NONE;
  346. }
  347. /*
  348. * PTP clock operations
  349. */
  350. static int ptp_pch_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  351. {
  352. u64 adj;
  353. u32 diff, addend;
  354. int neg_adj = 0;
  355. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  356. struct pch_ts_regs *regs = pch_dev->regs;
  357. if (ppb < 0) {
  358. neg_adj = 1;
  359. ppb = -ppb;
  360. }
  361. addend = DEFAULT_ADDEND;
  362. adj = addend;
  363. adj *= ppb;
  364. diff = div_u64(adj, 1000000000ULL);
  365. addend = neg_adj ? addend - diff : addend + diff;
  366. iowrite32(addend, &regs->addend);
  367. return 0;
  368. }
  369. static int ptp_pch_adjtime(struct ptp_clock_info *ptp, s64 delta)
  370. {
  371. s64 now;
  372. unsigned long flags;
  373. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  374. struct pch_ts_regs *regs = pch_dev->regs;
  375. spin_lock_irqsave(&pch_dev->register_lock, flags);
  376. now = pch_systime_read(regs);
  377. now += delta;
  378. pch_systime_write(regs, now);
  379. spin_unlock_irqrestore(&pch_dev->register_lock, flags);
  380. return 0;
  381. }
  382. static int ptp_pch_gettime(struct ptp_clock_info *ptp, struct timespec *ts)
  383. {
  384. u64 ns;
  385. u32 remainder;
  386. unsigned long flags;
  387. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  388. struct pch_ts_regs *regs = pch_dev->regs;
  389. spin_lock_irqsave(&pch_dev->register_lock, flags);
  390. ns = pch_systime_read(regs);
  391. spin_unlock_irqrestore(&pch_dev->register_lock, flags);
  392. ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder);
  393. ts->tv_nsec = remainder;
  394. return 0;
  395. }
  396. static int ptp_pch_settime(struct ptp_clock_info *ptp,
  397. const struct timespec *ts)
  398. {
  399. u64 ns;
  400. unsigned long flags;
  401. struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
  402. struct pch_ts_regs *regs = pch_dev->regs;
  403. ns = ts->tv_sec * 1000000000ULL;
  404. ns += ts->tv_nsec;
  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 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. .pps = 0,
  438. .adjfreq = ptp_pch_adjfreq,
  439. .adjtime = ptp_pch_adjtime,
  440. .gettime = ptp_pch_gettime,
  441. .settime = ptp_pch_settime,
  442. .enable = ptp_pch_enable,
  443. };
  444. #ifdef CONFIG_PM
  445. static s32 pch_suspend(struct pci_dev *pdev, pm_message_t state)
  446. {
  447. pci_disable_device(pdev);
  448. pci_enable_wake(pdev, PCI_D3hot, 0);
  449. if (pci_save_state(pdev) != 0) {
  450. dev_err(&pdev->dev, "could not save PCI config state\n");
  451. return -ENOMEM;
  452. }
  453. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  454. return 0;
  455. }
  456. static s32 pch_resume(struct pci_dev *pdev)
  457. {
  458. s32 ret;
  459. pci_set_power_state(pdev, PCI_D0);
  460. pci_restore_state(pdev);
  461. ret = pci_enable_device(pdev);
  462. if (ret) {
  463. dev_err(&pdev->dev, "pci_enable_device failed\n");
  464. return ret;
  465. }
  466. pci_enable_wake(pdev, PCI_D3hot, 0);
  467. return 0;
  468. }
  469. #else
  470. #define pch_suspend NULL
  471. #define pch_resume NULL
  472. #endif
  473. static void __devexit pch_remove(struct pci_dev *pdev)
  474. {
  475. struct pch_dev *chip = pci_get_drvdata(pdev);
  476. ptp_clock_unregister(chip->ptp_clock);
  477. /* free the interrupt */
  478. if (pdev->irq != 0)
  479. free_irq(pdev->irq, chip);
  480. /* unmap the virtual IO memory space */
  481. if (chip->regs != 0) {
  482. iounmap(chip->regs);
  483. chip->regs = 0;
  484. }
  485. /* release the reserved IO memory space */
  486. if (chip->mem_base != 0) {
  487. release_mem_region(chip->mem_base, chip->mem_size);
  488. chip->mem_base = 0;
  489. }
  490. pci_disable_device(pdev);
  491. kfree(chip);
  492. dev_info(&pdev->dev, "complete\n");
  493. }
  494. static s32 __devinit
  495. pch_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  496. {
  497. s32 ret;
  498. unsigned long flags;
  499. struct pch_dev *chip;
  500. chip = kzalloc(sizeof(struct pch_dev), GFP_KERNEL);
  501. if (chip == NULL)
  502. return -ENOMEM;
  503. /* enable the 1588 pci device */
  504. ret = pci_enable_device(pdev);
  505. if (ret != 0) {
  506. dev_err(&pdev->dev, "could not enable the pci device\n");
  507. goto err_pci_en;
  508. }
  509. chip->mem_base = pci_resource_start(pdev, IO_MEM_BAR);
  510. if (!chip->mem_base) {
  511. dev_err(&pdev->dev, "could not locate IO memory address\n");
  512. ret = -ENODEV;
  513. goto err_pci_start;
  514. }
  515. /* retrieve the available length of the IO memory space */
  516. chip->mem_size = pci_resource_len(pdev, IO_MEM_BAR);
  517. /* allocate the memory for the device registers */
  518. if (!request_mem_region(chip->mem_base, chip->mem_size, "1588_regs")) {
  519. dev_err(&pdev->dev,
  520. "could not allocate register memory space\n");
  521. ret = -EBUSY;
  522. goto err_req_mem_region;
  523. }
  524. /* get the virtual address to the 1588 registers */
  525. chip->regs = ioremap(chip->mem_base, chip->mem_size);
  526. if (!chip->regs) {
  527. dev_err(&pdev->dev, "Could not get virtual address\n");
  528. ret = -ENOMEM;
  529. goto err_ioremap;
  530. }
  531. chip->caps = ptp_pch_caps;
  532. chip->ptp_clock = ptp_clock_register(&chip->caps);
  533. if (IS_ERR(chip->ptp_clock))
  534. return PTR_ERR(chip->ptp_clock);
  535. spin_lock_init(&chip->register_lock);
  536. ret = request_irq(pdev->irq, &isr, IRQF_SHARED, KBUILD_MODNAME, chip);
  537. if (ret != 0) {
  538. dev_err(&pdev->dev, "failed to get irq %d\n", pdev->irq);
  539. goto err_req_irq;
  540. }
  541. /* indicate success */
  542. chip->irq = pdev->irq;
  543. chip->pdev = pdev;
  544. pci_set_drvdata(pdev, chip);
  545. spin_lock_irqsave(&chip->register_lock, flags);
  546. /* reset the ieee1588 h/w */
  547. pch_reset(chip);
  548. iowrite32(DEFAULT_ADDEND, &chip->regs->addend);
  549. iowrite32(1, &chip->regs->trgt_lo);
  550. iowrite32(0, &chip->regs->trgt_hi);
  551. iowrite32(PCH_TSE_TTIPEND, &chip->regs->event);
  552. /* Version: IEEE1588 v1 and IEEE1588-2008, Mode: All Evwnt, Locked */
  553. iowrite32(0x80020000, &chip->regs->ch_control);
  554. pch_eth_enable_set(chip);
  555. if (strcmp(pch_param.station, "00:00:00:00:00:00") != 0) {
  556. if (pch_set_station_address(pch_param.station, pdev) != 0) {
  557. dev_err(&pdev->dev,
  558. "Invalid station address parameter\n"
  559. "Module loaded but station address not set correctly\n"
  560. );
  561. }
  562. }
  563. spin_unlock_irqrestore(&chip->register_lock, flags);
  564. return 0;
  565. err_req_irq:
  566. ptp_clock_unregister(chip->ptp_clock);
  567. iounmap(chip->regs);
  568. chip->regs = 0;
  569. err_ioremap:
  570. release_mem_region(chip->mem_base, chip->mem_size);
  571. err_req_mem_region:
  572. chip->mem_base = 0;
  573. err_pci_start:
  574. pci_disable_device(pdev);
  575. err_pci_en:
  576. kfree(chip);
  577. dev_err(&pdev->dev, "probe failed(ret=0x%x)\n", ret);
  578. return ret;
  579. }
  580. static DEFINE_PCI_DEVICE_TABLE(pch_ieee1588_pcidev_id) = {
  581. {
  582. .vendor = PCI_VENDOR_ID_INTEL,
  583. .device = PCI_DEVICE_ID_PCH_1588
  584. },
  585. {0}
  586. };
  587. static struct pci_driver pch_driver = {
  588. .name = KBUILD_MODNAME,
  589. .id_table = pch_ieee1588_pcidev_id,
  590. .probe = pch_probe,
  591. .remove = pch_remove,
  592. .suspend = pch_suspend,
  593. .resume = pch_resume,
  594. };
  595. static void __exit ptp_pch_exit(void)
  596. {
  597. pci_unregister_driver(&pch_driver);
  598. }
  599. static s32 __init ptp_pch_init(void)
  600. {
  601. s32 ret;
  602. /* register the driver with the pci core */
  603. ret = pci_register_driver(&pch_driver);
  604. return ret;
  605. }
  606. module_init(ptp_pch_init);
  607. module_exit(ptp_pch_exit);
  608. module_param_string(station, pch_param.station, sizeof pch_param.station, 0444);
  609. MODULE_PARM_DESC(station,
  610. "IEEE 1588 station address to use - column separated hex values");
  611. MODULE_AUTHOR("LAPIS SEMICONDUCTOR, <tshimizu818@gmail.com>");
  612. MODULE_DESCRIPTION("PTP clock using the EG20T timer");
  613. MODULE_LICENSE("GPL");