Skip to content

Commit 4097197

Browse files
MeghanaMalladiTIopsiff
authored andcommitted
net: ti: icss-iep: Add phase offset configuration for perout signal
[ Upstream commit 220cb1b ] icss_iep_perout_enable_hw() is a common function for generating both pps and perout signals. When enabling pps, the application needs to only pass enable/disable argument, whereas for perout it supports different flags to configure the signal. In case the app passes a valid phase offset value, the signal should start toggling after that phase offset, else start immediately or as soon as possible. ICSS_IEP_SYNC_START_REG register take number of clock cycles to wait before starting the signal after activation time. Set appropriate value to this register to support phase offset. Signed-off-by: Meghana Malladi <m-malladi@ti.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Kory Maincent <kory.maincent@bootlin.com> Link: https://patch.msgid.link/20250304105753.1552159-3-m-malladi@ti.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: 7349c9e ("net: ti: icss-iep: Fix possible NULL pointer dereference for perout request") Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 8b9808b)
1 parent 2c5e95d commit 4097197

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

drivers/net/ethernet/ti/icssg/icss_iep.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ static int icss_iep_perout_enable_hw(struct icss_iep *iep,
477477
struct ptp_perout_request *req, int on)
478478
{
479479
struct timespec64 ts;
480+
u64 ns_start;
480481
u64 ns_width;
481482
int ret;
482483
u64 cmp;
@@ -486,6 +487,14 @@ static int icss_iep_perout_enable_hw(struct icss_iep *iep,
486487
ts.tv_nsec = req->on.nsec;
487488
ns_width = timespec64_to_ns(&ts);
488489

490+
if (req->flags & PTP_PEROUT_PHASE) {
491+
ts.tv_sec = req->phase.sec;
492+
ts.tv_nsec = req->phase.nsec;
493+
ns_start = timespec64_to_ns(&ts);
494+
} else {
495+
ns_start = 0;
496+
}
497+
489498
if (iep->ops && iep->ops->perout_enable) {
490499
ret = iep->ops->perout_enable(iep->clockops_data, req, on, &cmp);
491500
if (ret)
@@ -500,7 +509,8 @@ static int icss_iep_perout_enable_hw(struct icss_iep *iep,
500509
regmap_write(iep->map, ICSS_IEP_SYNC_PWIDTH_REG,
501510
div_u64(ns_width, iep->def_inc));
502511
regmap_write(iep->map, ICSS_IEP_SYNC0_PERIOD_REG, 0);
503-
regmap_write(iep->map, ICSS_IEP_SYNC_START_REG, 0);
512+
regmap_write(iep->map, ICSS_IEP_SYNC_START_REG,
513+
div_u64(ns_start, iep->def_inc));
504514
regmap_write(iep->map, ICSS_IEP_SYNC_CTRL_REG, 0); /* one-shot mode */
505515
/* Enable CMP 1 */
506516
regmap_update_bits(iep->map, ICSS_IEP_CMP_CFG_REG,
@@ -527,6 +537,8 @@ static int icss_iep_perout_enable_hw(struct icss_iep *iep,
527537

528538
regmap_write(iep->map, ICSS_IEP_SYNC_PWIDTH_REG,
529539
div_u64(ns_width, iep->def_inc));
540+
regmap_write(iep->map, ICSS_IEP_SYNC_START_REG,
541+
div_u64(ns_start, iep->def_inc));
530542
/* Enable Sync in single shot mode */
531543
regmap_write(iep->map, ICSS_IEP_SYNC_CTRL_REG,
532544
IEP_SYNC_CTRL_SYNC_N_EN(0) | IEP_SYNC_CTRL_SYNC_EN);
@@ -557,7 +569,8 @@ static int icss_iep_perout_enable(struct icss_iep *iep,
557569
int ret = 0;
558570

559571
/* Reject requests with unsupported flags */
560-
if (req->flags & ~PTP_PEROUT_DUTY_CYCLE)
572+
if (req->flags & ~(PTP_PEROUT_DUTY_CYCLE |
573+
PTP_PEROUT_PHASE))
561574
return -EOPNOTSUPP;
562575

563576
mutex_lock(&iep->ptp_clk_mutex);
@@ -607,6 +620,7 @@ static int icss_iep_pps_enable(struct icss_iep *iep, int on)
607620
if (on) {
608621
ns = icss_iep_gettime(iep, NULL);
609622
ts = ns_to_timespec64(ns);
623+
rq.perout.flags = 0;
610624
rq.perout.period.sec = 1;
611625
rq.perout.period.nsec = 0;
612626
rq.perout.start.sec = ts.tv_sec + 2;

0 commit comments

Comments
 (0)