Skip to content

Commit b78aba4

Browse files
grygoriySdavem330
authored andcommitted
net: ethernet: ti: cpts: add support for HW_TS_PUSH events
Hence CPTS IRQ support is in place the W_TS_PUSH events can be added. PWM capable DmTimers can be used to generete input signals for CPTS on TI AM335x/AM437x/DRA7 SoCs to be timestamped: AM335x/AM437x: timer4 - timer7 DRA7/AM57xx: timer13 - timer16 Signed-off-by: Grygorii Strashko <[email protected]> Acked-by: Richard Cochran <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8562441 commit b78aba4

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

drivers/net/ethernet/ti/cpsw_priv.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "cpsw_sl.h"
2929
#include "davinci_cpdma.h"
3030

31+
#define CPTS_N_ETX_TS 4
32+
3133
int (*cpsw_slave_index)(struct cpsw_common *cpsw, struct cpsw_priv *priv);
3234

3335
void cpsw_intr_enable(struct cpsw_common *cpsw)
@@ -522,7 +524,8 @@ int cpsw_init_common(struct cpsw_common *cpsw, void __iomem *ss_regs,
522524
if (!cpts_node)
523525
cpts_node = cpsw->dev->of_node;
524526

525-
cpsw->cpts = cpts_create(cpsw->dev, cpts_regs, cpts_node);
527+
cpsw->cpts = cpts_create(cpsw->dev, cpts_regs, cpts_node,
528+
CPTS_N_ETX_TS);
526529
if (IS_ERR(cpsw->cpts)) {
527530
ret = PTR_ERR(cpsw->cpts);
528531
cpdma_ctlr_destroy(cpsw->dma);

drivers/net/ethernet/ti/cpts.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ struct cpts_skb_cb_data {
3232
#define cpts_read32(c, r) readl_relaxed(&c->reg->r)
3333
#define cpts_write32(c, v, r) writel_relaxed(v, &c->reg->r)
3434

35+
static int cpts_event_port(struct cpts_event *event)
36+
{
37+
return (event->high >> PORT_NUMBER_SHIFT) & PORT_NUMBER_MASK;
38+
}
39+
3540
static int event_expired(struct cpts_event *event)
3641
{
3742
return time_after(jiffies, event->tmo);
@@ -99,6 +104,7 @@ static void cpts_purge_txq(struct cpts *cpts)
99104
*/
100105
static int cpts_fifo_read(struct cpts *cpts, int match)
101106
{
107+
struct ptp_clock_event pevent;
102108
bool need_schedule = false;
103109
struct cpts_event *event;
104110
unsigned long flags;
@@ -146,7 +152,12 @@ static int cpts_fifo_read(struct cpts *cpts, int match)
146152
break;
147153
case CPTS_EV_ROLL:
148154
case CPTS_EV_HALF:
155+
break;
149156
case CPTS_EV_HW:
157+
pevent.timestamp = event->timestamp;
158+
pevent.type = PTP_CLOCK_EXTTS;
159+
pevent.index = cpts_event_port(event) - 1;
160+
ptp_clock_event(cpts->clock, &pevent);
150161
break;
151162
default:
152163
dev_err(cpts->dev, "cpts: unknown event type\n");
@@ -273,9 +284,42 @@ static int cpts_ptp_settime(struct ptp_clock_info *ptp,
273284
return 0;
274285
}
275286

287+
static int cpts_extts_enable(struct cpts *cpts, u32 index, int on)
288+
{
289+
u32 v;
290+
291+
if (((cpts->hw_ts_enable & BIT(index)) >> index) == on)
292+
return 0;
293+
294+
mutex_lock(&cpts->ptp_clk_mutex);
295+
296+
v = cpts_read32(cpts, control);
297+
if (on) {
298+
v |= BIT(8 + index);
299+
cpts->hw_ts_enable |= BIT(index);
300+
} else {
301+
v &= ~BIT(8 + index);
302+
cpts->hw_ts_enable &= ~BIT(index);
303+
}
304+
cpts_write32(cpts, v, control);
305+
306+
mutex_unlock(&cpts->ptp_clk_mutex);
307+
308+
return 0;
309+
}
310+
276311
static int cpts_ptp_enable(struct ptp_clock_info *ptp,
277312
struct ptp_clock_request *rq, int on)
278313
{
314+
struct cpts *cpts = container_of(ptp, struct cpts, info);
315+
316+
switch (rq->type) {
317+
case PTP_CLK_REQ_EXTTS:
318+
return cpts_extts_enable(cpts, rq->extts.index, on);
319+
default:
320+
break;
321+
}
322+
279323
return -EOPNOTSUPP;
280324
}
281325

@@ -716,7 +760,7 @@ static int cpts_of_parse(struct cpts *cpts, struct device_node *node)
716760
}
717761

718762
struct cpts *cpts_create(struct device *dev, void __iomem *regs,
719-
struct device_node *node)
763+
struct device_node *node, u32 n_ext_ts)
720764
{
721765
struct cpts *cpts;
722766
int ret;
@@ -755,6 +799,9 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs,
755799
cpts->cc.mask = CLOCKSOURCE_MASK(32);
756800
cpts->info = cpts_info;
757801

802+
if (n_ext_ts)
803+
cpts->info.n_ext_ts = n_ext_ts;
804+
758805
cpts_calc_mult_shift(cpts);
759806
/* save cc.mult original value as it can be modified
760807
* by cpts_ptp_adjfreq().

drivers/net/ethernet/ti/cpts.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,15 @@ struct cpts {
120120
struct mutex ptp_clk_mutex; /* sync PTP interface and worker */
121121
bool irq_poll;
122122
struct completion ts_push_complete;
123+
u32 hw_ts_enable;
123124
};
124125

125126
void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb);
126127
void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb);
127128
int cpts_register(struct cpts *cpts);
128129
void cpts_unregister(struct cpts *cpts);
129130
struct cpts *cpts_create(struct device *dev, void __iomem *regs,
130-
struct device_node *node);
131+
struct device_node *node, u32 n_ext_ts);
131132
void cpts_release(struct cpts *cpts);
132133
void cpts_misc_interrupt(struct cpts *cpts);
133134

@@ -158,7 +159,7 @@ static inline void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb)
158159

159160
static inline
160161
struct cpts *cpts_create(struct device *dev, void __iomem *regs,
161-
struct device_node *node)
162+
struct device_node *node, u32 n_ext_ts)
162163
{
163164
return NULL;
164165
}

drivers/net/ethernet/ti/netcp_ethss.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3716,7 +3716,8 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
37163716
if (!cpts_node)
37173717
cpts_node = of_node_get(node);
37183718

3719-
gbe_dev->cpts = cpts_create(gbe_dev->dev, gbe_dev->cpts_reg, cpts_node);
3719+
gbe_dev->cpts = cpts_create(gbe_dev->dev, gbe_dev->cpts_reg,
3720+
cpts_node, 0);
37203721
of_node_put(cpts_node);
37213722
if (IS_ENABLED(CONFIG_TI_CPTS) && IS_ERR(gbe_dev->cpts)) {
37223723
ret = PTR_ERR(gbe_dev->cpts);

0 commit comments

Comments
 (0)