Skip to content

Commit a9d517a

Browse files
committed
Merge branch 'net-ethernet-renesas-rcar_gen4_ptp-simplify-register-layout'
Niklas Söderlund says: ==================== net: ethernet: renesas: rcar_gen4_ptp: Simplify register layout The daughter driver rcar_gen4_ptp used by both rswitch and rtsn where upstreamed with support for possible different memory layouts on different users. With all Gen4 boards upstream no such setup is documented. There are other issues related to how the rcar_gen4_ptp driver is shared between multiple useres that needs to be cleaned up. But that will be a larger work. So before that get some simple fixes done. Patch 1/3 and 2/3 removes the support to allow different register layouts on different SoCs by looking up offsets at runtime with a much simpler interface. The new interface computes the offsets at compile time. While patch 3/3 is a drive-by patch taking a spurs comment and making a lockdep check of it. There is no intentional functional change in this series just cleaning up in preparation of larger works to follow. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 43adad3 + fd2b242 commit a9d517a

File tree

4 files changed

+32
-83
lines changed

4 files changed

+32
-83
lines changed

drivers/net/ethernet/renesas/rcar_gen4_ptp.c

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
#include <linux/slab.h>
1313

1414
#include "rcar_gen4_ptp.h"
15-
#define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info)
1615

17-
static const struct rcar_gen4_ptp_reg_offset gen4_offs = {
18-
.enable = PTPTMEC,
19-
.disable = PTPTMDC,
20-
.increment = PTPTIVC0,
21-
.config_t0 = PTPTOVC00,
22-
.config_t1 = PTPTOVC10,
23-
.config_t2 = PTPTOVC20,
24-
.monitor_t0 = PTPGPTPTM00,
25-
.monitor_t1 = PTPGPTPTM10,
26-
.monitor_t2 = PTPGPTPTM20,
27-
};
16+
#define PTPTMEC_REG 0x0010
17+
#define PTPTMDC_REG 0x0014
18+
#define PTPTIVC0_REG 0x0020
19+
#define PTPTOVC00_REG 0x0030
20+
#define PTPTOVC10_REG 0x0034
21+
#define PTPTOVC20_REG 0x0038
22+
#define PTPGPTPTM00_REG 0x0050
23+
#define PTPGPTPTM10_REG 0x0054
24+
#define PTPGPTPTM20_REG 0x0058
25+
26+
#define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info)
2827

2928
static int rcar_gen4_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
3029
{
@@ -38,20 +37,21 @@ static int rcar_gen4_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
3837
diff = div_s64(addend * scaled_ppm_to_ppb(scaled_ppm), NSEC_PER_SEC);
3938
addend = neg_adj ? addend - diff : addend + diff;
4039

41-
iowrite32(addend, ptp_priv->addr + ptp_priv->offs->increment);
40+
iowrite32(addend, ptp_priv->addr + PTPTIVC0_REG);
4241

4342
return 0;
4443
}
4544

46-
/* Caller must hold the lock */
4745
static void _rcar_gen4_ptp_gettime(struct ptp_clock_info *ptp,
4846
struct timespec64 *ts)
4947
{
5048
struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp);
5149

52-
ts->tv_nsec = ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t0);
53-
ts->tv_sec = ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t1) |
54-
((s64)ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t2) << 32);
50+
lockdep_assert_held(&ptp_priv->lock);
51+
52+
ts->tv_nsec = ioread32(ptp_priv->addr + PTPGPTPTM00_REG);
53+
ts->tv_sec = ioread32(ptp_priv->addr + PTPGPTPTM10_REG) |
54+
((s64)ioread32(ptp_priv->addr + PTPGPTPTM20_REG) << 32);
5555
}
5656

5757
static int rcar_gen4_ptp_gettime(struct ptp_clock_info *ptp,
@@ -73,14 +73,14 @@ static void _rcar_gen4_ptp_settime(struct ptp_clock_info *ptp,
7373
{
7474
struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp);
7575

76-
iowrite32(1, ptp_priv->addr + ptp_priv->offs->disable);
77-
iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t2);
78-
iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t1);
79-
iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t0);
80-
iowrite32(1, ptp_priv->addr + ptp_priv->offs->enable);
81-
iowrite32(ts->tv_sec >> 32, ptp_priv->addr + ptp_priv->offs->config_t2);
82-
iowrite32(ts->tv_sec, ptp_priv->addr + ptp_priv->offs->config_t1);
83-
iowrite32(ts->tv_nsec, ptp_priv->addr + ptp_priv->offs->config_t0);
76+
iowrite32(1, ptp_priv->addr + PTPTMDC_REG);
77+
iowrite32(0, ptp_priv->addr + PTPTOVC20_REG);
78+
iowrite32(0, ptp_priv->addr + PTPTOVC10_REG);
79+
iowrite32(0, ptp_priv->addr + PTPTOVC00_REG);
80+
iowrite32(1, ptp_priv->addr + PTPTMEC_REG);
81+
iowrite32(ts->tv_sec >> 32, ptp_priv->addr + PTPTOVC20_REG);
82+
iowrite32(ts->tv_sec, ptp_priv->addr + PTPTOVC10_REG);
83+
iowrite32(ts->tv_nsec, ptp_priv->addr + PTPTOVC00_REG);
8484
}
8585

8686
static int rcar_gen4_ptp_settime(struct ptp_clock_info *ptp,
@@ -130,17 +130,6 @@ static struct ptp_clock_info rcar_gen4_ptp_info = {
130130
.enable = rcar_gen4_ptp_enable,
131131
};
132132

133-
static int rcar_gen4_ptp_set_offs(struct rcar_gen4_ptp_private *ptp_priv,
134-
enum rcar_gen4_ptp_reg_layout layout)
135-
{
136-
if (layout != RCAR_GEN4_PTP_REG_LAYOUT)
137-
return -EINVAL;
138-
139-
ptp_priv->offs = &gen4_offs;
140-
141-
return 0;
142-
}
143-
144133
static s64 rcar_gen4_ptp_rate_to_increment(u32 rate)
145134
{
146135
/* Timer increment in ns.
@@ -151,27 +140,20 @@ static s64 rcar_gen4_ptp_rate_to_increment(u32 rate)
151140
return div_s64(1000000000LL << 27, rate);
152141
}
153142

154-
int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv,
155-
enum rcar_gen4_ptp_reg_layout layout, u32 rate)
143+
int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, u32 rate)
156144
{
157-
int ret;
158-
159145
if (ptp_priv->initialized)
160146
return 0;
161147

162148
spin_lock_init(&ptp_priv->lock);
163149

164-
ret = rcar_gen4_ptp_set_offs(ptp_priv, layout);
165-
if (ret)
166-
return ret;
167-
168150
ptp_priv->default_addend = rcar_gen4_ptp_rate_to_increment(rate);
169-
iowrite32(ptp_priv->default_addend, ptp_priv->addr + ptp_priv->offs->increment);
151+
iowrite32(ptp_priv->default_addend, ptp_priv->addr + PTPTIVC0_REG);
170152
ptp_priv->clock = ptp_clock_register(&ptp_priv->info, NULL);
171153
if (IS_ERR(ptp_priv->clock))
172154
return PTR_ERR(ptp_priv->clock);
173155

174-
iowrite32(0x01, ptp_priv->addr + ptp_priv->offs->enable);
156+
iowrite32(0x01, ptp_priv->addr + PTPTMEC_REG);
175157
ptp_priv->initialized = true;
176158

177159
return 0;
@@ -180,7 +162,7 @@ EXPORT_SYMBOL_GPL(rcar_gen4_ptp_register);
180162

181163
int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv)
182164
{
183-
iowrite32(1, ptp_priv->addr + ptp_priv->offs->disable);
165+
iowrite32(1, ptp_priv->addr + PTPTMDC_REG);
184166

185167
return ptp_clock_unregister(ptp_priv->clock);
186168
}

drivers/net/ethernet/renesas/rcar_gen4_ptp.h

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
#define RCAR_GEN4_GPTP_OFFSET_S4 0x00018000
1313

14-
enum rcar_gen4_ptp_reg_layout {
15-
RCAR_GEN4_PTP_REG_LAYOUT
16-
};
17-
1814
/* driver's definitions */
1915
#define RCAR_GEN4_RXTSTAMP_ENABLED BIT(0)
2016
#define RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT BIT(1)
@@ -23,46 +19,19 @@ enum rcar_gen4_ptp_reg_layout {
2319

2420
#define RCAR_GEN4_TXTSTAMP_ENABLED BIT(0)
2521

26-
#define PTPRO 0
27-
28-
enum rcar_gen4_ptp_reg {
29-
PTPTMEC = PTPRO + 0x0010,
30-
PTPTMDC = PTPRO + 0x0014,
31-
PTPTIVC0 = PTPRO + 0x0020,
32-
PTPTOVC00 = PTPRO + 0x0030,
33-
PTPTOVC10 = PTPRO + 0x0034,
34-
PTPTOVC20 = PTPRO + 0x0038,
35-
PTPGPTPTM00 = PTPRO + 0x0050,
36-
PTPGPTPTM10 = PTPRO + 0x0054,
37-
PTPGPTPTM20 = PTPRO + 0x0058,
38-
};
39-
40-
struct rcar_gen4_ptp_reg_offset {
41-
u16 enable;
42-
u16 disable;
43-
u16 increment;
44-
u16 config_t0;
45-
u16 config_t1;
46-
u16 config_t2;
47-
u16 monitor_t0;
48-
u16 monitor_t1;
49-
u16 monitor_t2;
50-
};
5122

5223
struct rcar_gen4_ptp_private {
5324
void __iomem *addr;
5425
struct ptp_clock *clock;
5526
struct ptp_clock_info info;
56-
const struct rcar_gen4_ptp_reg_offset *offs;
5727
spinlock_t lock; /* For multiple registers access */
5828
u32 tstamp_tx_ctrl;
5929
u32 tstamp_rx_ctrl;
6030
s64 default_addend;
6131
bool initialized;
6232
};
6333

64-
int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv,
65-
enum rcar_gen4_ptp_reg_layout layout, u32 rate);
34+
int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, u32 rate);
6635
int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv);
6736
struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev);
6837

drivers/net/ethernet/renesas/rswitch_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,8 +2090,7 @@ static int rswitch_init(struct rswitch_private *priv)
20902090
if (err < 0)
20912091
goto err_fwd_init;
20922092

2093-
err = rcar_gen4_ptp_register(priv->ptp_priv, RCAR_GEN4_PTP_REG_LAYOUT,
2094-
clk_get_rate(priv->clk));
2093+
err = rcar_gen4_ptp_register(priv->ptp_priv, clk_get_rate(priv->clk));
20952094
if (err < 0)
20962095
goto err_ptp_register;
20972096

drivers/net/ethernet/renesas/rtsn.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,8 +1330,7 @@ static int rtsn_probe(struct platform_device *pdev)
13301330

13311331
device_set_wakeup_capable(&pdev->dev, 1);
13321332

1333-
ret = rcar_gen4_ptp_register(priv->ptp_priv, RCAR_GEN4_PTP_REG_LAYOUT,
1334-
clk_get_rate(priv->clk));
1333+
ret = rcar_gen4_ptp_register(priv->ptp_priv, clk_get_rate(priv->clk));
13351334
if (ret)
13361335
goto error_pm;
13371336

0 commit comments

Comments
 (0)