ptp_pch.c 16 KB

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