Lines Matching +full:tx +full:- +full:clk +full:- +full:adj +full:- +full:enabled
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com
8 #include <linux/clk.h>
9 #include <linux/clk-provider.h>
23 #include "am65-cpts.h"
164 struct clk *refclk;
201 #define am65_cpts_write32(c, v, r) writel(v, &(c)->reg->r)
202 #define am65_cpts_read32(c, r) readl(&(c)->reg->r)
219 cpts->ts_add_val = (NSEC_PER_SEC / cpts->refclk_freq - 1) & 0x7; in am65_cpts_set_add_val()
221 am65_cpts_write32(cpts, cpts->ts_add_val, ts_add_val); in am65_cpts_set_add_val()
232 return (event->event1 & AM65_CPTS_EVENT_1_PORT_NUMBER_MASK) >> in am65_cpts_event_get_port()
238 return (event->event1 & AM65_CPTS_EVENT_1_EVENT_TYPE_MASK) >> in am65_cpts_event_get_type()
248 list_for_each_safe(this, next, &cpts->events) { in am65_cpts_cpts_purge_events()
250 if (time_after(jiffies, event->tmo)) { in am65_cpts_cpts_purge_events()
251 list_del_init(&event->list); in am65_cpts_cpts_purge_events()
252 list_add(&event->list, &cpts->pool); in am65_cpts_cpts_purge_events()
258 dev_dbg(cpts->dev, "event pool cleaned up %d\n", removed); in am65_cpts_cpts_purge_events()
259 return removed ? 0 : -1; in am65_cpts_cpts_purge_events()
268 event->timestamp = am65_cpts_read32(cpts, event_0); in am65_cpts_fifo_pop_event()
269 event->event1 = am65_cpts_read32(cpts, event_1); in am65_cpts_fifo_pop_event()
270 event->event2 = am65_cpts_read32(cpts, event_2); in am65_cpts_fifo_pop_event()
271 event->timestamp |= (u64)am65_cpts_read32(cpts, event_3) << 32; in am65_cpts_fifo_pop_event()
286 event = list_first_entry_or_null(&cpts->pool, in __am65_cpts_fifo_read()
291 dev_err(cpts->dev, "cpts: event pool empty\n"); in __am65_cpts_fifo_read()
292 ret = -1; in __am65_cpts_fifo_read()
304 cpts->timestamp = event->timestamp; in __am65_cpts_fifo_read()
305 dev_dbg(cpts->dev, "AM65_CPTS_EV_PUSH t:%llu\n", in __am65_cpts_fifo_read()
306 cpts->timestamp); in __am65_cpts_fifo_read()
310 event->tmo = jiffies + in __am65_cpts_fifo_read()
313 list_move_tail(&event->list, &cpts->events); in __am65_cpts_fifo_read()
315 dev_dbg(cpts->dev, in __am65_cpts_fifo_read()
317 event->event1, event->event2, in __am65_cpts_fifo_read()
318 event->timestamp); in __am65_cpts_fifo_read()
322 pevent.index = am65_cpts_event_get_port(event) - 1; in __am65_cpts_fifo_read()
323 pevent.timestamp = event->timestamp; in __am65_cpts_fifo_read()
324 if (cpts->pps_enabled && pevent.index == cpts->pps_hw_ts_idx) { in __am65_cpts_fifo_read()
330 dev_dbg(cpts->dev, "AM65_CPTS_EV_HW:%s p:%d t:%llu\n", in __am65_cpts_fifo_read()
333 pevent.index, event->timestamp); in __am65_cpts_fifo_read()
335 ptp_clock_event(cpts->ptp_clock, &pevent); in __am65_cpts_fifo_read()
342 dev_dbg(cpts->dev, in __am65_cpts_fifo_read()
345 event->event1, event->event2, in __am65_cpts_fifo_read()
346 event->timestamp); in __am65_cpts_fifo_read()
349 dev_err(cpts->dev, "cpts: unknown event type\n"); in __am65_cpts_fifo_read()
350 ret = -1; in __am65_cpts_fifo_read()
357 ptp_schedule_worker(cpts->ptp_clock, 0); in __am65_cpts_fifo_read()
367 spin_lock_irqsave(&cpts->lock, flags); in am65_cpts_fifo_read()
369 spin_unlock_irqrestore(&cpts->lock, flags); in am65_cpts_fifo_read()
381 * doubled read. Interrupt can be in-flight - it's Ok. in am65_cpts_gettime()
386 spin_lock_irqsave(&cpts->lock, flags); in am65_cpts_gettime()
391 spin_unlock_irqrestore(&cpts->lock, flags); in am65_cpts_gettime()
397 val = cpts->timestamp; in am65_cpts_gettime()
407 dev_dbg(cpts->dev, "cpts: unable to obtain a time stamp\n"); in am65_cpts_interrupt()
418 int pps_index = cpts->pps_genf_idx; in am65_cpts_ptp_adjfine()
426 ppb = -ppb; in am65_cpts_ptp_adjfine()
438 adj_period = div_u64(cpts->refclk_freq, ppb); in am65_cpts_ptp_adjfine()
440 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_ptp_adjfine()
451 if (cpts->pps_enabled) { in am65_cpts_ptp_adjfine()
459 * (cpts->ts_add_val + 1) ns, so GenF length PPM adj period in am65_cpts_ptp_adjfine()
462 pps_adj_period = adj_period * (cpts->ts_add_val + 1); in am65_cpts_ptp_adjfine()
467 spin_lock_irqsave(&cpts->lock, flags); in am65_cpts_ptp_adjfine()
470 * - delay between PPM dir and PPM value changes can cause err due old in am65_cpts_ptp_adjfine()
472 * - delay between CPTS-clock PPM cfg and GenF PPM cfg can cause err in am65_cpts_ptp_adjfine()
473 * due CPTS-clock PPM working with new cfg while GenF PPM cfg still in am65_cpts_ptp_adjfine()
481 if (cpts->pps_enabled) { in am65_cpts_ptp_adjfine()
488 if (cpts->estf_enable & BIT(i)) { in am65_cpts_ptp_adjfine()
495 spin_unlock_irqrestore(&cpts->lock, flags); in am65_cpts_ptp_adjfine()
497 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_ptp_adjfine()
507 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_ptp_adjtime()
511 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_ptp_adjtime()
523 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_ptp_gettimex()
525 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_ptp_gettimex()
536 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_ns_gettime()
538 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_ns_gettime()
551 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_ptp_settime()
553 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_ptp_settime()
565 cpts->hw_ts_enable |= BIT(index); in am65_cpts_extts_enable_hw()
568 cpts->hw_ts_enable &= ~BIT(index); in am65_cpts_extts_enable_hw()
575 if (index >= cpts->ptp_info.n_ext_ts) in am65_cpts_extts_enable()
576 return -ENXIO; in am65_cpts_extts_enable()
578 if (cpts->pps_present && index == cpts->pps_hw_ts_idx) in am65_cpts_extts_enable()
579 return -EINVAL; in am65_cpts_extts_enable()
581 if (((cpts->hw_ts_enable & BIT(index)) >> index) == on) in am65_cpts_extts_enable()
584 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_extts_enable()
586 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_extts_enable()
588 dev_dbg(cpts->dev, "%s: ExtTS:%u %s\n", in am65_cpts_extts_enable()
589 __func__, index, on ? "enabled" : "disabled"); in am65_cpts_extts_enable()
600 cycles = cfg->ns_period * cpts->refclk_freq; in am65_cpts_estf_enable()
603 return -EINVAL; in am65_cpts_estf_enable()
608 val = upper_32_bits(cfg->ns_start); in am65_cpts_estf_enable()
610 val = lower_32_bits(cfg->ns_start); in am65_cpts_estf_enable()
618 cpts->estf_enable |= BIT(idx); in am65_cpts_estf_enable()
620 dev_dbg(cpts->dev, "%s: ESTF:%u enabled\n", __func__, idx); in am65_cpts_estf_enable()
629 cpts->estf_enable &= ~BIT(idx); in am65_cpts_estf_disable()
631 dev_dbg(cpts->dev, "%s: ESTF:%u disabled\n", __func__, idx); in am65_cpts_estf_disable()
643 ts.tv_sec = req->period.sec; in am65_cpts_perout_enable_hw()
644 ts.tv_nsec = req->period.nsec; in am65_cpts_perout_enable_hw()
647 cycles = (ns_period * cpts->refclk_freq) / NSEC_PER_SEC; in am65_cpts_perout_enable_hw()
649 ts.tv_sec = req->start.sec; in am65_cpts_perout_enable_hw()
650 ts.tv_nsec = req->start.nsec; in am65_cpts_perout_enable_hw()
654 am65_cpts_write32(cpts, val, genf[req->index].comp_hi); in am65_cpts_perout_enable_hw()
656 am65_cpts_write32(cpts, val, genf[req->index].comp_lo); in am65_cpts_perout_enable_hw()
658 am65_cpts_write32(cpts, val, genf[req->index].length); in am65_cpts_perout_enable_hw()
660 am65_cpts_write32(cpts, 0, genf[req->index].control); in am65_cpts_perout_enable_hw()
661 am65_cpts_write32(cpts, 0, genf[req->index].ppm_hi); in am65_cpts_perout_enable_hw()
662 am65_cpts_write32(cpts, 0, genf[req->index].ppm_low); in am65_cpts_perout_enable_hw()
664 cpts->genf_enable |= BIT(req->index); in am65_cpts_perout_enable_hw()
666 am65_cpts_write32(cpts, 0, genf[req->index].length); in am65_cpts_perout_enable_hw()
668 cpts->genf_enable &= ~BIT(req->index); in am65_cpts_perout_enable_hw()
675 if (req->index >= cpts->ptp_info.n_per_out) in am65_cpts_perout_enable()
676 return -ENXIO; in am65_cpts_perout_enable()
678 if (cpts->pps_present && req->index == cpts->pps_genf_idx) in am65_cpts_perout_enable()
679 return -EINVAL; in am65_cpts_perout_enable()
681 if (!!(cpts->genf_enable & BIT(req->index)) == !!on) in am65_cpts_perout_enable()
684 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_perout_enable()
686 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_perout_enable()
688 dev_dbg(cpts->dev, "%s: GenF:%u %s\n", in am65_cpts_perout_enable()
689 __func__, req->index, on ? "enabled" : "disabled"); in am65_cpts_perout_enable()
701 if (!cpts->pps_present) in am65_cpts_pps_enable()
702 return -EINVAL; in am65_cpts_pps_enable()
704 if (cpts->pps_enabled == !!on) in am65_cpts_pps_enable()
707 mutex_lock(&cpts->ptp_clk_lock); in am65_cpts_pps_enable()
710 am65_cpts_extts_enable_hw(cpts, cpts->pps_hw_ts_idx, on); in am65_cpts_pps_enable()
718 rq.perout.index = cpts->pps_genf_idx; in am65_cpts_pps_enable()
721 cpts->pps_enabled = true; in am65_cpts_pps_enable()
723 rq.perout.index = cpts->pps_genf_idx; in am65_cpts_pps_enable()
725 am65_cpts_extts_enable_hw(cpts, cpts->pps_hw_ts_idx, on); in am65_cpts_pps_enable()
726 cpts->pps_enabled = false; in am65_cpts_pps_enable()
729 mutex_unlock(&cpts->ptp_clk_lock); in am65_cpts_pps_enable()
731 dev_dbg(cpts->dev, "%s: pps: %s\n", in am65_cpts_pps_enable()
732 __func__, on ? "enabled" : "disabled"); in am65_cpts_pps_enable()
741 switch (rq->type) { in am65_cpts_ptp_enable()
743 return am65_cpts_extts_enable(cpts, rq->extts.index, on); in am65_cpts_ptp_enable()
745 return am65_cpts_perout_enable(cpts, &rq->perout, on); in am65_cpts_ptp_enable()
752 return -EOPNOTSUPP; in am65_cpts_ptp_enable()
777 mtype_seqid = event->event1 & in am65_cpts_match_tx_ts()
784 spin_lock_irqsave(&cpts->txq.lock, flags); in am65_cpts_match_tx_ts()
785 skb_queue_splice_init(&cpts->txq, &txq_list); in am65_cpts_match_tx_ts()
786 spin_unlock_irqrestore(&cpts->txq.lock, flags); in am65_cpts_match_tx_ts()
788 /* no need to grab txq.lock as access is always done under cpts->lock */ in am65_cpts_match_tx_ts()
792 (struct am65_cpts_skb_cb_data *)skb->cb; in am65_cpts_match_tx_ts()
796 (skb_cb->skb_mtype_seqid & AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK))) in am65_cpts_match_tx_ts()
797 mtype_seqid = skb_cb->skb_mtype_seqid; in am65_cpts_match_tx_ts()
799 if (mtype_seqid == skb_cb->skb_mtype_seqid) { in am65_cpts_match_tx_ts()
800 u64 ns = event->timestamp; in am65_cpts_match_tx_ts()
808 dev_dbg(cpts->dev, in am65_cpts_match_tx_ts()
809 "match tx timestamp mtype_seqid %08x\n", in am65_cpts_match_tx_ts()
814 if (time_after(jiffies, skb_cb->tmo)) { in am65_cpts_match_tx_ts()
816 dev_dbg(cpts->dev, in am65_cpts_match_tx_ts()
817 "expiring tx timestamp mtype_seqid %08x\n", in am65_cpts_match_tx_ts()
824 spin_lock_irqsave(&cpts->txq.lock, flags); in am65_cpts_match_tx_ts()
825 skb_queue_splice(&txq_list, &cpts->txq); in am65_cpts_match_tx_ts()
826 spin_unlock_irqrestore(&cpts->txq.lock, flags); in am65_cpts_match_tx_ts()
839 spin_lock_irqsave(&cpts->lock, flags); in am65_cpts_find_ts()
840 list_splice_init(&cpts->events, &events); in am65_cpts_find_ts()
841 spin_unlock_irqrestore(&cpts->lock, flags); in am65_cpts_find_ts()
846 time_after(jiffies, event->tmo)) { in am65_cpts_find_ts()
847 list_del_init(&event->list); in am65_cpts_find_ts()
848 list_add(&event->list, &events_free); in am65_cpts_find_ts()
852 spin_lock_irqsave(&cpts->lock, flags); in am65_cpts_find_ts()
853 list_splice_tail(&events, &cpts->events); in am65_cpts_find_ts()
854 list_splice_tail(&events_free, &cpts->pool); in am65_cpts_find_ts()
855 spin_unlock_irqrestore(&cpts->lock, flags); in am65_cpts_find_ts()
862 long delay = -1; in am65_cpts_ts_work()
866 spin_lock_irqsave(&cpts->txq.lock, flags); in am65_cpts_ts_work()
867 if (!skb_queue_empty(&cpts->txq)) in am65_cpts_ts_work()
869 spin_unlock_irqrestore(&cpts->txq.lock, flags); in am65_cpts_ts_work()
889 seqid = ntohs(hdr->sequence_id); in am65_skb_get_mtype_seqid()
906 spin_lock_irqsave(&cpts->lock, flags); in am65_cpts_find_rx_ts()
908 list_for_each_safe(this, next, &cpts->events) { in am65_cpts_find_rx_ts()
910 if (time_after(jiffies, event->tmo)) { in am65_cpts_find_rx_ts()
911 list_move(&event->list, &cpts->pool); in am65_cpts_find_rx_ts()
915 mtype_seqid = event->event1 & in am65_cpts_find_rx_ts()
921 ns = event->timestamp; in am65_cpts_find_rx_ts()
922 list_move(&event->list, &cpts->pool); in am65_cpts_find_rx_ts()
926 spin_unlock_irqrestore(&cpts->lock, flags); in am65_cpts_find_rx_ts()
933 struct am65_cpts_skb_cb_data *skb_cb = (struct am65_cpts_skb_cb_data *)skb->cb; in am65_cpts_rx_timestamp()
943 ret = am65_skb_get_mtype_seqid(skb, &skb_cb->skb_mtype_seqid); in am65_cpts_rx_timestamp()
947 skb_cb->skb_mtype_seqid |= (AM65_CPTS_EV_RX << AM65_CPTS_EVENT_1_EVENT_TYPE_SHIFT); in am65_cpts_rx_timestamp()
949 dev_dbg(cpts->dev, "%s mtype seqid %08x\n", __func__, skb_cb->skb_mtype_seqid); in am65_cpts_rx_timestamp()
951 ns = am65_cpts_find_rx_ts(cpts, skb_cb->skb_mtype_seqid); in am65_cpts_rx_timestamp()
957 ssh->hwtstamp = ns_to_ktime(ns); in am65_cpts_rx_timestamp()
962 * am65_cpts_tx_timestamp - save tx packet for timestamping
966 * This functions saves tx packet for timestamping if packet can be timestamped.
971 struct am65_cpts_skb_cb_data *skb_cb = (void *)skb->cb; in am65_cpts_tx_timestamp()
973 if (!(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) in am65_cpts_tx_timestamp()
981 skb_cb->tmo = jiffies + msecs_to_jiffies(100); in am65_cpts_tx_timestamp()
982 skb_queue_tail(&cpts->txq, skb); in am65_cpts_tx_timestamp()
983 ptp_schedule_worker(cpts->ptp_clock, 0); in am65_cpts_tx_timestamp()
988 * am65_cpts_prep_tx_timestamp - check and prepare tx packet for timestamping
994 * in skb-cb and marks packet as SKBTX_IN_PROGRESS.
998 struct am65_cpts_skb_cb_data *skb_cb = (void *)skb->cb; in am65_cpts_prep_tx_timestamp()
1001 if (!(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) in am65_cpts_prep_tx_timestamp()
1004 ret = am65_skb_get_mtype_seqid(skb, &skb_cb->skb_mtype_seqid); in am65_cpts_prep_tx_timestamp()
1007 skb_cb->skb_mtype_seqid |= (AM65_CPTS_EV_TX << in am65_cpts_prep_tx_timestamp()
1010 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in am65_cpts_prep_tx_timestamp()
1016 return cpts->phc_index; in am65_cpts_phc_index()
1024 of_clk_del_provider(cpts->clk_mux_np); in cpts_free_clk_mux()
1025 clk_hw_unregister_mux(cpts->clk_mux_hw); in cpts_free_clk_mux()
1026 of_node_put(cpts->clk_mux_np); in cpts_free_clk_mux()
1036 int ret = -EINVAL; in cpts_of_mux_clk_setup()
1038 cpts->clk_mux_np = of_get_child_by_name(node, "refclk-mux"); in cpts_of_mux_clk_setup()
1039 if (!cpts->clk_mux_np) in cpts_of_mux_clk_setup()
1042 num_parents = of_clk_get_parent_count(cpts->clk_mux_np); in cpts_of_mux_clk_setup()
1044 dev_err(cpts->dev, "mux-clock %pOF must have parents\n", in cpts_of_mux_clk_setup()
1045 cpts->clk_mux_np); in cpts_of_mux_clk_setup()
1049 parent_names = devm_kcalloc(cpts->dev, sizeof(char *), num_parents, in cpts_of_mux_clk_setup()
1052 ret = -ENOMEM; in cpts_of_mux_clk_setup()
1056 of_clk_parent_fill(cpts->clk_mux_np, parent_names, num_parents); in cpts_of_mux_clk_setup()
1058 clk_mux_name = devm_kasprintf(cpts->dev, GFP_KERNEL, "%s.%pOFn", in cpts_of_mux_clk_setup()
1059 dev_name(cpts->dev), cpts->clk_mux_np); in cpts_of_mux_clk_setup()
1061 ret = -ENOMEM; in cpts_of_mux_clk_setup()
1065 reg = &cpts->reg->rftclk_sel; in cpts_of_mux_clk_setup()
1069 cpts->clk_mux_hw = clk_hw_register_mux(NULL, clk_mux_name, in cpts_of_mux_clk_setup()
1072 if (IS_ERR(cpts->clk_mux_hw)) { in cpts_of_mux_clk_setup()
1073 ret = PTR_ERR(cpts->clk_mux_hw); in cpts_of_mux_clk_setup()
1077 ret = of_clk_add_hw_provider(cpts->clk_mux_np, of_clk_hw_simple_get, in cpts_of_mux_clk_setup()
1078 cpts->clk_mux_hw); in cpts_of_mux_clk_setup()
1082 ret = devm_add_action_or_reset(cpts->dev, cpts_free_clk_mux, cpts); in cpts_of_mux_clk_setup()
1084 dev_err(cpts->dev, "failed to add clkmux reset action %d", ret); in cpts_of_mux_clk_setup()
1089 clk_hw_unregister_mux(cpts->clk_mux_hw); in cpts_of_mux_clk_setup()
1091 of_node_put(cpts->clk_mux_np); in cpts_of_mux_clk_setup()
1099 if (!of_property_read_u32(node, "ti,cpts-ext-ts-inputs", &prop[0])) in am65_cpts_of_parse()
1100 cpts->ext_ts_inputs = prop[0]; in am65_cpts_of_parse()
1102 if (!of_property_read_u32(node, "ti,cpts-periodic-outputs", &prop[0])) in am65_cpts_of_parse()
1103 cpts->genf_num = prop[0]; in am65_cpts_of_parse()
1106 cpts->pps_present = true; in am65_cpts_of_parse()
1109 dev_err(cpts->dev, "invalid HWx_TS_PUSH index: %u provided\n", prop[0]); in am65_cpts_of_parse()
1110 cpts->pps_present = false; in am65_cpts_of_parse()
1113 dev_err(cpts->dev, "invalid GENFy index: %u provided\n", prop[1]); in am65_cpts_of_parse()
1114 cpts->pps_present = false; in am65_cpts_of_parse()
1116 if (cpts->pps_present) { in am65_cpts_of_parse()
1117 cpts->pps_hw_ts_idx = prop[0]; in am65_cpts_of_parse()
1118 cpts->pps_genf_idx = prop[1]; in am65_cpts_of_parse()
1127 ptp_clock_unregister(cpts->ptp_clock); in am65_cpts_release()
1129 clk_disable_unprepare(cpts->refclk); in am65_cpts_release()
1141 return ERR_PTR(-ENOMEM); in am65_cpts_create()
1143 cpts->dev = dev; in am65_cpts_create()
1144 cpts->reg = (struct am65_cpts_regs __iomem *)regs; in am65_cpts_create()
1146 cpts->irq = of_irq_get_byname(node, "cpts"); in am65_cpts_create()
1147 if (cpts->irq <= 0) { in am65_cpts_create()
1148 ret = cpts->irq ?: -ENXIO; in am65_cpts_create()
1157 mutex_init(&cpts->ptp_clk_lock); in am65_cpts_create()
1158 INIT_LIST_HEAD(&cpts->events); in am65_cpts_create()
1159 INIT_LIST_HEAD(&cpts->pool); in am65_cpts_create()
1160 spin_lock_init(&cpts->lock); in am65_cpts_create()
1161 skb_queue_head_init(&cpts->txq); in am65_cpts_create()
1164 list_add(&cpts->pool_data[i].list, &cpts->pool); in am65_cpts_create()
1166 cpts->refclk = devm_get_clk_from_child(dev, node, "cpts"); in am65_cpts_create()
1167 if (IS_ERR(cpts->refclk)) { in am65_cpts_create()
1168 ret = PTR_ERR(cpts->refclk); in am65_cpts_create()
1173 ret = clk_prepare_enable(cpts->refclk); in am65_cpts_create()
1179 cpts->refclk_freq = clk_get_rate(cpts->refclk); in am65_cpts_create()
1181 am65_ptp_info.max_adj = cpts->refclk_freq / AM65_CPTS_MIN_PPM; in am65_cpts_create()
1182 cpts->ptp_info = am65_ptp_info; in am65_cpts_create()
1184 if (cpts->ext_ts_inputs) in am65_cpts_create()
1185 cpts->ptp_info.n_ext_ts = cpts->ext_ts_inputs; in am65_cpts_create()
1186 if (cpts->genf_num) in am65_cpts_create()
1187 cpts->ptp_info.n_per_out = cpts->genf_num; in am65_cpts_create()
1188 if (cpts->pps_present) in am65_cpts_create()
1189 cpts->ptp_info.pps = 1; in am65_cpts_create()
1202 cpts->ptp_clock = ptp_clock_register(&cpts->ptp_info, cpts->dev); in am65_cpts_create()
1203 if (IS_ERR_OR_NULL(cpts->ptp_clock)) { in am65_cpts_create()
1204 dev_err(dev, "Failed to register ptp clk %ld\n", in am65_cpts_create()
1205 PTR_ERR(cpts->ptp_clock)); in am65_cpts_create()
1206 ret = cpts->ptp_clock ? PTR_ERR(cpts->ptp_clock) : -ENODEV; in am65_cpts_create()
1209 cpts->phc_index = ptp_clock_index(cpts->ptp_clock); in am65_cpts_create()
1211 ret = devm_request_threaded_irq(dev, cpts->irq, NULL, in am65_cpts_create()
1215 dev_err(cpts->dev, "error attaching irq %d\n", ret); in am65_cpts_create()
1221 cpts->refclk_freq, cpts->ts_add_val, cpts->pps_present); in am65_cpts_create()
1228 clk_disable_unprepare(cpts->refclk); in am65_cpts_create()
1236 cpts->sr_control = am65_cpts_read32(cpts, control); in am65_cpts_suspend()
1237 cpts->sr_int_enable = am65_cpts_read32(cpts, int_enable); in am65_cpts_suspend()
1238 cpts->sr_rftclk_sel = am65_cpts_read32(cpts, rftclk_sel); in am65_cpts_suspend()
1239 cpts->sr_ts_ppm_hi = am65_cpts_read32(cpts, ts_ppm_hi); in am65_cpts_suspend()
1240 cpts->sr_ts_ppm_low = am65_cpts_read32(cpts, ts_ppm_low); in am65_cpts_suspend()
1241 cpts->sr_cpts_ns = am65_cpts_gettime(cpts, NULL); in am65_cpts_suspend()
1242 cpts->sr_ktime_ns = ktime_to_ns(ktime_get_real()); in am65_cpts_suspend()
1244 clk_disable(cpts->refclk); in am65_cpts_suspend()
1247 memcpy_fromio(&cpts->sr_genf, &cpts->reg->genf, sizeof(cpts->sr_genf)); in am65_cpts_suspend()
1250 memcpy_fromio(&cpts->sr_estf, &cpts->reg->estf, sizeof(cpts->sr_estf)); in am65_cpts_suspend()
1260 clk_enable(cpts->refclk); in am65_cpts_resume()
1261 am65_cpts_write32(cpts, cpts->sr_rftclk_sel, rftclk_sel); in am65_cpts_resume()
1263 am65_cpts_write32(cpts, cpts->sr_control, control); in am65_cpts_resume()
1264 am65_cpts_write32(cpts, cpts->sr_int_enable, int_enable); in am65_cpts_resume()
1268 ktime_ns -= cpts->sr_ktime_ns; in am65_cpts_resume()
1269 am65_cpts_settime(cpts, cpts->sr_cpts_ns + ktime_ns); in am65_cpts_resume()
1272 am65_cpts_write32(cpts, cpts->sr_ts_ppm_hi, ts_ppm_hi); in am65_cpts_resume()
1273 am65_cpts_write32(cpts, cpts->sr_ts_ppm_low, ts_ppm_low); in am65_cpts_resume()
1278 am65_cpts_write32(cpts, cpts->sr_genf[i].comp_hi, genf[i].comp_hi); in am65_cpts_resume()
1279 am65_cpts_write32(cpts, cpts->sr_genf[i].comp_lo, genf[i].comp_lo); in am65_cpts_resume()
1280 am65_cpts_write32(cpts, cpts->sr_genf[i].length, genf[i].length); in am65_cpts_resume()
1281 am65_cpts_write32(cpts, cpts->sr_genf[i].control, genf[i].control); in am65_cpts_resume()
1282 am65_cpts_write32(cpts, cpts->sr_genf[i].ppm_hi, genf[i].ppm_hi); in am65_cpts_resume()
1283 am65_cpts_write32(cpts, cpts->sr_genf[i].ppm_low, genf[i].ppm_low); in am65_cpts_resume()
1289 am65_cpts_write32(cpts, cpts->sr_estf[i].comp_hi, estf[i].comp_hi); in am65_cpts_resume()
1290 am65_cpts_write32(cpts, cpts->sr_estf[i].comp_lo, estf[i].comp_lo); in am65_cpts_resume()
1291 am65_cpts_write32(cpts, cpts->sr_estf[i].length, estf[i].length); in am65_cpts_resume()
1292 am65_cpts_write32(cpts, cpts->sr_estf[i].control, estf[i].control); in am65_cpts_resume()
1293 am65_cpts_write32(cpts, cpts->sr_estf[i].ppm_hi, estf[i].ppm_hi); in am65_cpts_resume()
1294 am65_cpts_write32(cpts, cpts->sr_estf[i].ppm_low, estf[i].ppm_low); in am65_cpts_resume()
1301 struct device_node *node = pdev->dev.of_node; in am65_cpts_probe()
1302 struct device *dev = &pdev->dev; in am65_cpts_probe()
1315 { .compatible = "ti,am65-cpts", },
1316 { .compatible = "ti,j721e-cpts", },
1324 .name = "am65-cpts",