Lines Matching +full:clock +full:-
1 // SPDX-License-Identifier: GPL-2.0
6 static int mchp_rds_phy_read_mmd(struct mchp_rds_ptp_clock *clock, in mchp_rds_phy_read_mmd() argument
9 struct phy_device *phydev = clock->phydev; in mchp_rds_phy_read_mmd()
12 addr = (offset + ((base == MCHP_RDS_PTP_PORT) ? BASE_PORT(clock) : in mchp_rds_phy_read_mmd()
13 BASE_CLK(clock))); in mchp_rds_phy_read_mmd()
15 return phy_read_mmd(phydev, PTP_MMD(clock), addr); in mchp_rds_phy_read_mmd()
18 static int mchp_rds_phy_write_mmd(struct mchp_rds_ptp_clock *clock, in mchp_rds_phy_write_mmd() argument
22 struct phy_device *phydev = clock->phydev; in mchp_rds_phy_write_mmd()
25 addr = (offset + ((base == MCHP_RDS_PTP_PORT) ? BASE_PORT(clock) : in mchp_rds_phy_write_mmd()
26 BASE_CLK(clock))); in mchp_rds_phy_write_mmd()
28 return phy_write_mmd(phydev, PTP_MMD(clock), addr, val); in mchp_rds_phy_write_mmd()
31 static int mchp_rds_phy_modify_mmd(struct mchp_rds_ptp_clock *clock, in mchp_rds_phy_modify_mmd() argument
35 struct phy_device *phydev = clock->phydev; in mchp_rds_phy_modify_mmd()
38 addr = (offset + ((base == MCHP_RDS_PTP_PORT) ? BASE_PORT(clock) : in mchp_rds_phy_modify_mmd()
39 BASE_CLK(clock))); in mchp_rds_phy_modify_mmd()
41 return phy_modify_mmd(phydev, PTP_MMD(clock), addr, mask, val); in mchp_rds_phy_modify_mmd()
44 static int mchp_rds_phy_set_bits_mmd(struct mchp_rds_ptp_clock *clock, in mchp_rds_phy_set_bits_mmd() argument
48 struct phy_device *phydev = clock->phydev; in mchp_rds_phy_set_bits_mmd()
51 addr = (offset + ((base == MCHP_RDS_PTP_PORT) ? BASE_PORT(clock) : in mchp_rds_phy_set_bits_mmd()
52 BASE_CLK(clock))); in mchp_rds_phy_set_bits_mmd()
54 return phy_set_bits_mmd(phydev, PTP_MMD(clock), addr, val); in mchp_rds_phy_set_bits_mmd()
81 ts_period.tv_sec = perout_request->period.sec; in mchp_get_pulsewidth()
82 ts_period.tv_nsec = perout_request->period.nsec; in mchp_get_pulsewidth()
84 ts_on.tv_sec = perout_request->on.sec; in mchp_get_pulsewidth()
85 ts_on.tv_nsec = perout_request->on.nsec; in mchp_get_pulsewidth()
91 return -EOPNOTSUPP; in mchp_get_pulsewidth()
105 static int mchp_general_event_config(struct mchp_rds_ptp_clock *clock, in mchp_general_event_config() argument
110 general_config = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_GEN_CFG, in mchp_general_event_config()
120 return mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_GEN_CFG, in mchp_general_event_config()
124 static int mchp_set_clock_reload(struct mchp_rds_ptp_clock *clock, in mchp_set_clock_reload() argument
129 rc = mchp_rds_phy_write_mmd(clock, in mchp_set_clock_reload()
136 rc = mchp_rds_phy_write_mmd(clock, in mchp_set_clock_reload()
143 rc = mchp_rds_phy_write_mmd(clock, in mchp_set_clock_reload()
150 return mchp_rds_phy_write_mmd(clock, in mchp_set_clock_reload()
156 static int mchp_set_clock_target(struct mchp_rds_ptp_clock *clock, in mchp_set_clock_target() argument
162 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_CLK_TRGT_SEC_LO, in mchp_set_clock_target()
168 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_CLK_TRGT_SEC_HI, in mchp_set_clock_target()
174 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_CLK_TRGT_NS_LO, in mchp_set_clock_target()
180 return mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_CLK_TRGT_NS_HI, in mchp_set_clock_target()
185 static int mchp_rds_ptp_perout_off(struct mchp_rds_ptp_clock *clock) in mchp_rds_ptp_perout_off() argument
191 rc = mchp_set_clock_target(clock, 0xFFFFFFFF, 0); in mchp_rds_ptp_perout_off()
195 general_config = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_GEN_CFG, in mchp_rds_ptp_perout_off()
198 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_GEN_CFG, in mchp_rds_ptp_perout_off()
203 clock->mchp_rds_ptp_event = -1; in mchp_rds_ptp_perout_off()
208 static bool mchp_get_event(struct mchp_rds_ptp_clock *clock, int pin) in mchp_get_event() argument
210 if (clock->mchp_rds_ptp_event < 0 && pin == clock->event_pin) { in mchp_get_event()
211 clock->mchp_rds_ptp_event = pin; in mchp_get_event()
221 struct mchp_rds_ptp_clock *clock = container_of(ptpci, in mchp_rds_ptp_perout() local
224 struct phy_device *phydev = clock->phydev; in mchp_rds_ptp_perout()
228 if (perout->flags & ~PTP_PEROUT_DUTY_CYCLE) in mchp_rds_ptp_perout()
229 return -EOPNOTSUPP; in mchp_rds_ptp_perout()
231 event_pin = ptp_find_pin(clock->ptp_clock, PTP_PF_PEROUT, in mchp_rds_ptp_perout()
232 perout->index); in mchp_rds_ptp_perout()
233 if (event_pin != clock->event_pin) in mchp_rds_ptp_perout()
234 return -EINVAL; in mchp_rds_ptp_perout()
237 ret = mchp_rds_ptp_perout_off(clock); in mchp_rds_ptp_perout()
241 if (!mchp_get_event(clock, event_pin)) in mchp_rds_ptp_perout()
242 return -EINVAL; in mchp_rds_ptp_perout()
249 ret = mchp_general_event_config(clock, pulsewidth); in mchp_rds_ptp_perout()
253 ret = mchp_set_clock_target(clock, perout->start.sec, in mchp_rds_ptp_perout()
254 perout->start.nsec); in mchp_rds_ptp_perout()
258 return mchp_set_clock_reload(clock, perout->period.sec, in mchp_rds_ptp_perout()
259 perout->period.nsec); in mchp_rds_ptp_perout()
265 switch (request->type) { in mchp_rds_ptpci_enable()
267 return mchp_rds_ptp_perout(ptpci, &request->perout, on); in mchp_rds_ptpci_enable()
269 return -EINVAL; in mchp_rds_ptpci_enable()
276 struct mchp_rds_ptp_clock *clock = container_of(ptpci, in mchp_rds_ptpci_verify() local
280 if (!(pin == clock->event_pin && chan == 0)) in mchp_rds_ptpci_verify()
281 return -1; in mchp_rds_ptpci_verify()
288 return -1; in mchp_rds_ptpci_verify()
294 static int mchp_rds_ptp_flush_fifo(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_flush_fifo() argument
300 skb_queue_purge(&clock->tx_queue); in mchp_rds_ptp_flush_fifo()
302 skb_queue_purge(&clock->rx_queue); in mchp_rds_ptp_flush_fifo()
305 rc = mchp_rds_phy_read_mmd(clock, in mchp_rds_ptp_flush_fifo()
313 return mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_INT_STS, in mchp_rds_ptp_flush_fifo()
317 static int mchp_rds_ptp_config_intr(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_config_intr() argument
321 return mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_INT_EN, in mchp_rds_ptp_config_intr()
329 struct mchp_rds_ptp_clock *clock = container_of(mii_ts, in mchp_rds_ptp_txtstamp() local
333 switch (clock->hwts_tx_type) { in mchp_rds_ptp_txtstamp()
341 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in mchp_rds_ptp_txtstamp()
342 skb_queue_tail(&clock->tx_queue, skb); in mchp_rds_ptp_txtstamp()
367 *sig = (__force u16)(ntohs(ptp_header->sequence_id)); in mchp_rds_ptp_get_sig_rx()
372 static bool mchp_rds_ptp_match_skb(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_match_skb() argument
381 spin_lock_irqsave(&clock->rx_queue.lock, flags); in mchp_rds_ptp_match_skb()
382 skb_queue_walk_safe(&clock->rx_queue, skb, skb_tmp) { in mchp_rds_ptp_match_skb()
386 if (skb_sig != rx_ts->seq_id) in mchp_rds_ptp_match_skb()
389 __skb_unlink(skb, &clock->rx_queue); in mchp_rds_ptp_match_skb()
394 spin_unlock_irqrestore(&clock->rx_queue.lock, flags); in mchp_rds_ptp_match_skb()
398 shhwtstamps->hwtstamp = ktime_set(rx_ts->seconds, rx_ts->nsec); in mchp_rds_ptp_match_skb()
405 static void mchp_rds_ptp_match_rx_ts(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_match_rx_ts() argument
413 if (!mchp_rds_ptp_match_skb(clock, rx_ts)) { in mchp_rds_ptp_match_rx_ts()
414 spin_lock_irqsave(&clock->rx_ts_lock, flags); in mchp_rds_ptp_match_rx_ts()
415 list_add(&rx_ts->list, &clock->rx_ts_list); in mchp_rds_ptp_match_rx_ts()
416 spin_unlock_irqrestore(&clock->rx_ts_lock, flags); in mchp_rds_ptp_match_rx_ts()
422 static void mchp_rds_ptp_match_rx_skb(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_match_rx_skb() argument
434 spin_lock_irqsave(&clock->rx_ts_lock, flags); in mchp_rds_ptp_match_rx_skb()
435 list_for_each_entry_safe(rx_ts, tmp, &clock->rx_ts_list, list) { in mchp_rds_ptp_match_rx_skb()
437 if (skb_sig != rx_ts->seq_id) in mchp_rds_ptp_match_rx_skb()
441 shhwtstamps->hwtstamp = ktime_set(rx_ts->seconds, rx_ts->nsec); in mchp_rds_ptp_match_rx_skb()
448 spin_unlock_irqrestore(&clock->rx_ts_lock, flags); in mchp_rds_ptp_match_rx_skb()
451 list_del(&rx_ts_var->list); in mchp_rds_ptp_match_rx_skb()
454 skb_queue_tail(&clock->rx_queue, skb); in mchp_rds_ptp_match_rx_skb()
461 struct mchp_rds_ptp_clock *clock = container_of(mii_ts, in mchp_rds_ptp_rxtstamp() local
465 if (clock->rx_filter == HWTSTAMP_FILTER_NONE || in mchp_rds_ptp_rxtstamp()
469 if ((type & clock->version) == 0 || (type & clock->layer) == 0) in mchp_rds_ptp_rxtstamp()
478 mchp_rds_ptp_match_rx_skb(clock, skb); in mchp_rds_ptp_rxtstamp()
487 struct mchp_rds_ptp_clock *clock = in mchp_rds_ptp_hwtstamp() local
495 clock->hwts_tx_type = config->tx_type; in mchp_rds_ptp_hwtstamp()
496 clock->rx_filter = config->rx_filter; in mchp_rds_ptp_hwtstamp()
498 switch (config->rx_filter) { in mchp_rds_ptp_hwtstamp()
500 clock->layer = 0; in mchp_rds_ptp_hwtstamp()
501 clock->version = 0; in mchp_rds_ptp_hwtstamp()
506 clock->layer = PTP_CLASS_L4; in mchp_rds_ptp_hwtstamp()
507 clock->version = PTP_CLASS_V2; in mchp_rds_ptp_hwtstamp()
512 clock->layer = PTP_CLASS_L2; in mchp_rds_ptp_hwtstamp()
513 clock->version = PTP_CLASS_V2; in mchp_rds_ptp_hwtstamp()
518 clock->layer = PTP_CLASS_L4 | PTP_CLASS_L2; in mchp_rds_ptp_hwtstamp()
519 clock->version = PTP_CLASS_V2; in mchp_rds_ptp_hwtstamp()
522 return -ERANGE; in mchp_rds_ptp_hwtstamp()
528 if (clock->layer & PTP_CLASS_L2) { in mchp_rds_ptp_hwtstamp()
532 if (clock->layer & PTP_CLASS_L4) { in mchp_rds_ptp_hwtstamp()
538 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_RX_PARSE_CONFIG, in mchp_rds_ptp_hwtstamp()
543 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TX_PARSE_CONFIG, in mchp_rds_ptp_hwtstamp()
548 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_RX_TIMESTAMP_EN, in mchp_rds_ptp_hwtstamp()
554 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TX_TIMESTAMP_EN, in mchp_rds_ptp_hwtstamp()
560 if (clock->hwts_tx_type == HWTSTAMP_TX_ONESTEP_SYNC) in mchp_rds_ptp_hwtstamp()
562 rc = mchp_rds_phy_modify_mmd(clock, MCHP_RDS_PTP_TX_MOD, in mchp_rds_ptp_hwtstamp()
567 rc = mchp_rds_phy_modify_mmd(clock, MCHP_RDS_PTP_TX_MOD, in mchp_rds_ptp_hwtstamp()
576 spin_lock_irqsave(&clock->rx_ts_lock, flags); in mchp_rds_ptp_hwtstamp()
577 list_for_each_entry_safe(rx_ts, tmp, &clock->rx_ts_list, list) { in mchp_rds_ptp_hwtstamp()
578 list_del(&rx_ts->list); in mchp_rds_ptp_hwtstamp()
581 spin_unlock_irqrestore(&clock->rx_ts_lock, flags); in mchp_rds_ptp_hwtstamp()
583 rc = mchp_rds_ptp_flush_fifo(clock, MCHP_RDS_PTP_INGRESS_FIFO); in mchp_rds_ptp_hwtstamp()
587 rc = mchp_rds_ptp_flush_fifo(clock, MCHP_RDS_PTP_EGRESS_FIFO); in mchp_rds_ptp_hwtstamp()
592 rc = mchp_rds_ptp_config_intr(clock, in mchp_rds_ptp_hwtstamp()
593 config->rx_filter != HWTSTAMP_FILTER_NONE); in mchp_rds_ptp_hwtstamp()
601 struct mchp_rds_ptp_clock *clock = container_of(mii_ts, in mchp_rds_ptp_ts_info() local
605 info->phc_index = ptp_clock_index(clock->ptp_clock); in mchp_rds_ptp_ts_info()
607 info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | in mchp_rds_ptp_ts_info()
611 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON) | in mchp_rds_ptp_ts_info()
614 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | in mchp_rds_ptp_ts_info()
624 struct mchp_rds_ptp_clock *clock = container_of(info, in mchp_rds_ptp_ltc_adjtime() local
639 if (delta > 10000000000LL || delta < -10000000000LL) { in mchp_rds_ptp_ltc_adjtime()
643 info->gettime64(info, &ts); in mchp_rds_ptp_ltc_adjtime()
648 info->settime64(info, &ts); in mchp_rds_ptp_ltc_adjtime()
657 sec--; in mchp_rds_ptp_ltc_adjtime()
658 nsec = NSEC_PER_SEC - nsec; in mchp_rds_ptp_ltc_adjtime()
672 nsec -= NSEC_PER_SEC; in mchp_rds_ptp_ltc_adjtime()
676 mutex_lock(&clock->ptp_lock); in mchp_rds_ptp_ltc_adjtime()
680 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_STEP_ADJ_LO, in mchp_rds_ptp_ltc_adjtime()
685 rc = mchp_rds_phy_set_bits_mmd(clock, MCHP_RDS_PTP_STEP_ADJ_HI, in mchp_rds_ptp_ltc_adjtime()
694 rc = mchp_rds_phy_set_bits_mmd(clock, MCHP_RDS_PTP_CMD_CTL, in mchp_rds_ptp_ltc_adjtime()
702 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_STEP_ADJ_LO, in mchp_rds_ptp_ltc_adjtime()
708 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_STEP_ADJ_HI, in mchp_rds_ptp_ltc_adjtime()
714 rc = mchp_rds_phy_set_bits_mmd(clock, MCHP_RDS_PTP_CMD_CTL, in mchp_rds_ptp_ltc_adjtime()
719 mutex_unlock(&clock->ptp_lock); in mchp_rds_ptp_ltc_adjtime()
720 info->gettime64(info, &ts); in mchp_rds_ptp_ltc_adjtime()
721 mutex_lock(&clock->ptp_lock); in mchp_rds_ptp_ltc_adjtime()
726 if (clock->mchp_rds_ptp_event >= 0) in mchp_rds_ptp_ltc_adjtime()
727 mchp_set_clock_target(clock, in mchp_rds_ptp_ltc_adjtime()
730 mutex_unlock(&clock->ptp_lock); in mchp_rds_ptp_ltc_adjtime()
738 struct mchp_rds_ptp_clock *clock = container_of(info, in mchp_rds_ptp_ltc_adjfine() local
750 scaled_ppm = -scaled_ppm; in mchp_rds_ptp_ltc_adjfine()
763 mutex_lock(&clock->ptp_lock); in mchp_rds_ptp_ltc_adjfine()
764 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LTC_RATE_ADJ_HI, in mchp_rds_ptp_ltc_adjfine()
769 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LTC_RATE_ADJ_LO, in mchp_rds_ptp_ltc_adjfine()
774 mutex_unlock(&clock->ptp_lock); in mchp_rds_ptp_ltc_adjfine()
782 struct mchp_rds_ptp_clock *clock = container_of(info, in mchp_rds_ptp_ltc_gettime64() local
789 mutex_lock(&clock->ptp_lock); in mchp_rds_ptp_ltc_gettime64()
793 rc = mchp_rds_phy_set_bits_mmd(clock, MCHP_RDS_PTP_CMD_CTL, in mchp_rds_ptp_ltc_gettime64()
799 /* Get LTC clock values */ in mchp_rds_ptp_ltc_gettime64()
800 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_LTC_READ_SEC_HI, in mchp_rds_ptp_ltc_gettime64()
806 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_LTC_READ_SEC_MID, in mchp_rds_ptp_ltc_gettime64()
813 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_LTC_READ_SEC_LO, in mchp_rds_ptp_ltc_gettime64()
819 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_LTC_READ_NS_HI, in mchp_rds_ptp_ltc_gettime64()
826 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_LTC_READ_NS_LO, in mchp_rds_ptp_ltc_gettime64()
837 mutex_unlock(&clock->ptp_lock); in mchp_rds_ptp_ltc_gettime64()
845 struct mchp_rds_ptp_clock *clock = container_of(info, in mchp_rds_ptp_ltc_settime64() local
850 mutex_lock(&clock->ptp_lock); in mchp_rds_ptp_ltc_settime64()
851 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LTC_SEC_LO, in mchp_rds_ptp_ltc_settime64()
853 lower_16_bits(ts->tv_sec)); in mchp_rds_ptp_ltc_settime64()
857 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LTC_SEC_MID, in mchp_rds_ptp_ltc_settime64()
859 upper_16_bits(ts->tv_sec)); in mchp_rds_ptp_ltc_settime64()
863 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LTC_SEC_HI, in mchp_rds_ptp_ltc_settime64()
865 upper_32_bits(ts->tv_sec) & GENMASK(15, 0)); in mchp_rds_ptp_ltc_settime64()
869 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LTC_NS_LO, in mchp_rds_ptp_ltc_settime64()
871 lower_16_bits(ts->tv_nsec)); in mchp_rds_ptp_ltc_settime64()
875 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LTC_NS_HI, in mchp_rds_ptp_ltc_settime64()
877 upper_16_bits(ts->tv_nsec) & GENMASK(13, 0)); in mchp_rds_ptp_ltc_settime64()
884 rc = mchp_rds_phy_set_bits_mmd(clock, MCHP_RDS_PTP_CMD_CTL, in mchp_rds_ptp_ltc_settime64()
890 mutex_unlock(&clock->ptp_lock); in mchp_rds_ptp_ltc_settime64()
908 *sig = (__force u16)(ntohs(ptp_header->sequence_id)); in mchp_rds_ptp_get_sig_tx()
913 static void mchp_rds_ptp_match_tx_skb(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_match_tx_skb() argument
922 spin_lock_irqsave(&clock->tx_queue.lock, flags); in mchp_rds_ptp_match_tx_skb()
923 skb_queue_walk_safe(&clock->tx_queue, skb, skb_tmp) { in mchp_rds_ptp_match_tx_skb()
930 __skb_unlink(skb, &clock->tx_queue); in mchp_rds_ptp_match_tx_skb()
934 spin_unlock_irqrestore(&clock->tx_queue.lock, flags); in mchp_rds_ptp_match_tx_skb()
943 *mchp_rds_ptp_get_rx_ts(struct mchp_rds_ptp_clock *clock) in mchp_rds_ptp_get_rx_ts() argument
945 struct phy_device *phydev = clock->phydev; in mchp_rds_ptp_get_rx_ts()
950 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_RX_INGRESS_NS_HI, in mchp_rds_ptp_get_rx_ts()
960 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_RX_INGRESS_NS_LO, in mchp_rds_ptp_get_rx_ts()
966 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_RX_INGRESS_SEC_HI, in mchp_rds_ptp_get_rx_ts()
972 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_RX_INGRESS_SEC_LO, in mchp_rds_ptp_get_rx_ts()
978 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_RX_MSG_HDR2, in mchp_rds_ptp_get_rx_ts()
987 rx_ts->seconds = sec; in mchp_rds_ptp_get_rx_ts()
988 rx_ts->nsec = nsec; in mchp_rds_ptp_get_rx_ts()
989 rx_ts->seq_id = rc; in mchp_rds_ptp_get_rx_ts()
995 static void mchp_rds_ptp_process_rx_ts(struct mchp_rds_ptp_clock *clock) in mchp_rds_ptp_process_rx_ts() argument
1002 rx_ts = mchp_rds_ptp_get_rx_ts(clock); in mchp_rds_ptp_process_rx_ts()
1004 mchp_rds_ptp_match_rx_ts(clock, rx_ts); in mchp_rds_ptp_process_rx_ts()
1006 caps = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_CAP_INFO, in mchp_rds_ptp_process_rx_ts()
1013 static bool mchp_rds_ptp_get_tx_ts(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_get_tx_ts() argument
1018 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_TX_EGRESS_NS_HI, in mchp_rds_ptp_get_tx_ts()
1026 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_TX_EGRESS_NS_LO, in mchp_rds_ptp_get_tx_ts()
1032 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_TX_EGRESS_SEC_HI, in mchp_rds_ptp_get_tx_ts()
1038 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_TX_EGRESS_SEC_LO, in mchp_rds_ptp_get_tx_ts()
1044 rc = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_TX_MSG_HDR2, in mchp_rds_ptp_get_tx_ts()
1054 static void mchp_rds_ptp_process_tx_ts(struct mchp_rds_ptp_clock *clock) in mchp_rds_ptp_process_tx_ts() argument
1062 if (mchp_rds_ptp_get_tx_ts(clock, &sec, &nsec, &seq)) in mchp_rds_ptp_process_tx_ts()
1063 mchp_rds_ptp_match_tx_skb(clock, sec, nsec, seq); in mchp_rds_ptp_process_tx_ts()
1065 caps = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_CAP_INFO, in mchp_rds_ptp_process_tx_ts()
1072 int mchp_rds_ptp_top_config_intr(struct mchp_rds_ptp_clock *clock, in mchp_rds_ptp_top_config_intr() argument
1076 return phy_clear_bits_mmd(clock->phydev, PTP_MMD(clock), reg, in mchp_rds_ptp_top_config_intr()
1079 return phy_set_bits_mmd(clock->phydev, PTP_MMD(clock), reg, in mchp_rds_ptp_top_config_intr()
1084 irqreturn_t mchp_rds_ptp_handle_interrupt(struct mchp_rds_ptp_clock *clock) in mchp_rds_ptp_handle_interrupt() argument
1089 if (!clock) in mchp_rds_ptp_handle_interrupt()
1093 irq_sts = mchp_rds_phy_read_mmd(clock, MCHP_RDS_PTP_INT_STS, in mchp_rds_ptp_handle_interrupt()
1099 mchp_rds_ptp_process_rx_ts(clock); in mchp_rds_ptp_handle_interrupt()
1102 mchp_rds_ptp_process_tx_ts(clock); in mchp_rds_ptp_handle_interrupt()
1105 mchp_rds_ptp_flush_fifo(clock, in mchp_rds_ptp_handle_interrupt()
1109 mchp_rds_ptp_flush_fifo(clock, in mchp_rds_ptp_handle_interrupt()
1120 static int mchp_rds_ptp_init(struct mchp_rds_ptp_clock *clock) in mchp_rds_ptp_init() argument
1125 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_CMD_CTL, in mchp_rds_ptp_init()
1132 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TSU_GEN_CONFIG, in mchp_rds_ptp_init()
1138 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TSU_HARD_RESET, in mchp_rds_ptp_init()
1145 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_LATENCY_CORRECTION_CTL, in mchp_rds_ptp_init()
1152 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_OP_MODE, in mchp_rds_ptp_init()
1158 /* Reference clock configuration */ in mchp_rds_ptp_init()
1159 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_REF_CLK_CFG, in mchp_rds_ptp_init()
1166 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_RX_PARSE_CONFIG, in mchp_rds_ptp_init()
1171 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TX_PARSE_CONFIG, in mchp_rds_ptp_init()
1176 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TX_PARSE_L2_ADDR_EN, in mchp_rds_ptp_init()
1181 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_RX_PARSE_L2_ADDR_EN, in mchp_rds_ptp_init()
1186 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_RX_PARSE_IPV4_ADDR_EN, in mchp_rds_ptp_init()
1191 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TX_PARSE_IPV4_ADDR_EN, in mchp_rds_ptp_init()
1196 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_RX_VERSION, in mchp_rds_ptp_init()
1203 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TX_VERSION, in mchp_rds_ptp_init()
1211 rc = mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_TSU_GEN_CONFIG, in mchp_rds_ptp_init()
1218 return mchp_rds_phy_write_mmd(clock, MCHP_RDS_PTP_CMD_CTL, in mchp_rds_ptp_init()
1227 struct mchp_rds_ptp_clock *clock; in mchp_rds_ptp_probe() local
1230 clock = devm_kzalloc(&phydev->mdio.dev, sizeof(*clock), GFP_KERNEL); in mchp_rds_ptp_probe()
1231 if (!clock) in mchp_rds_ptp_probe()
1232 return ERR_PTR(-ENOMEM); in mchp_rds_ptp_probe()
1234 clock->port_base_addr = port_base_addr; in mchp_rds_ptp_probe()
1235 clock->clk_base_addr = clk_base_addr; in mchp_rds_ptp_probe()
1236 clock->mmd = mmd; in mchp_rds_ptp_probe()
1238 mutex_init(&clock->ptp_lock); in mchp_rds_ptp_probe()
1239 clock->pin_config = devm_kmalloc_array(&phydev->mdio.dev, in mchp_rds_ptp_probe()
1241 sizeof(*clock->pin_config), in mchp_rds_ptp_probe()
1243 if (!clock->pin_config) in mchp_rds_ptp_probe()
1244 return ERR_PTR(-ENOMEM); in mchp_rds_ptp_probe()
1247 struct ptp_pin_desc *p = &clock->pin_config[i]; in mchp_rds_ptp_probe()
1250 snprintf(p->name, sizeof(p->name), "pin%d", i); in mchp_rds_ptp_probe()
1251 p->index = i; in mchp_rds_ptp_probe()
1252 p->func = PTP_PF_NONE; in mchp_rds_ptp_probe()
1254 /* Register PTP clock */ in mchp_rds_ptp_probe()
1255 clock->caps.owner = THIS_MODULE; in mchp_rds_ptp_probe()
1256 snprintf(clock->caps.name, 30, "%s", phydev->drv->name); in mchp_rds_ptp_probe()
1257 clock->caps.max_adj = MCHP_RDS_PTP_MAX_ADJ; in mchp_rds_ptp_probe()
1258 clock->caps.n_ext_ts = 0; in mchp_rds_ptp_probe()
1259 clock->caps.pps = 0; in mchp_rds_ptp_probe()
1260 clock->caps.n_pins = MCHP_RDS_PTP_N_PIN; in mchp_rds_ptp_probe()
1261 clock->caps.n_per_out = MCHP_RDS_PTP_N_PEROUT; in mchp_rds_ptp_probe()
1262 clock->caps.pin_config = clock->pin_config; in mchp_rds_ptp_probe()
1263 clock->caps.adjfine = mchp_rds_ptp_ltc_adjfine; in mchp_rds_ptp_probe()
1264 clock->caps.adjtime = mchp_rds_ptp_ltc_adjtime; in mchp_rds_ptp_probe()
1265 clock->caps.gettime64 = mchp_rds_ptp_ltc_gettime64; in mchp_rds_ptp_probe()
1266 clock->caps.settime64 = mchp_rds_ptp_ltc_settime64; in mchp_rds_ptp_probe()
1267 clock->caps.enable = mchp_rds_ptpci_enable; in mchp_rds_ptp_probe()
1268 clock->caps.verify = mchp_rds_ptpci_verify; in mchp_rds_ptp_probe()
1269 clock->caps.getcrosststamp = NULL; in mchp_rds_ptp_probe()
1270 clock->ptp_clock = ptp_clock_register(&clock->caps, in mchp_rds_ptp_probe()
1271 &phydev->mdio.dev); in mchp_rds_ptp_probe()
1272 if (IS_ERR(clock->ptp_clock)) in mchp_rds_ptp_probe()
1273 return ERR_PTR(-EINVAL); in mchp_rds_ptp_probe()
1276 if (!clock->ptp_clock) in mchp_rds_ptp_probe()
1280 skb_queue_head_init(&clock->tx_queue); in mchp_rds_ptp_probe()
1281 skb_queue_head_init(&clock->rx_queue); in mchp_rds_ptp_probe()
1282 INIT_LIST_HEAD(&clock->rx_ts_list); in mchp_rds_ptp_probe()
1283 spin_lock_init(&clock->rx_ts_lock); in mchp_rds_ptp_probe()
1285 clock->mii_ts.rxtstamp = mchp_rds_ptp_rxtstamp; in mchp_rds_ptp_probe()
1286 clock->mii_ts.txtstamp = mchp_rds_ptp_txtstamp; in mchp_rds_ptp_probe()
1287 clock->mii_ts.hwtstamp = mchp_rds_ptp_hwtstamp; in mchp_rds_ptp_probe()
1288 clock->mii_ts.ts_info = mchp_rds_ptp_ts_info; in mchp_rds_ptp_probe()
1290 phydev->mii_ts = &clock->mii_ts; in mchp_rds_ptp_probe()
1292 clock->mchp_rds_ptp_event = -1; in mchp_rds_ptp_probe()
1295 phydev->default_timestamp = true; in mchp_rds_ptp_probe()
1297 clock->phydev = phydev; in mchp_rds_ptp_probe()
1299 rc = mchp_rds_ptp_init(clock); in mchp_rds_ptp_probe()
1303 return clock; in mchp_rds_ptp_probe()