Commit 7490a420 authored by Paolo Abeni's avatar Paolo Abeni

Merge branch 'net-ethernet-renesas-rcar_gen4_ptp-add-v4h-support'

Niklas Söderlund says:

====================
net: ethernet: renesas: rcar_gen4_ptp: Add V4H support

This small series prepares the rcar_gen4_ptp to be useable both on both
R-Car S4 and V4H. The only in-tree driver that make use of this is
rswtich on S4. A new Ethernet (R-Car Ethernet TSN) driver for V4H is on
it's way that also will make use of rcar_gen4_ptp functionality.

Patch 1-2 are small improvements to the existing driver. While patch 3-4
adds V4H support. Finally patch 5 turns rcar_gen4_ptp into a separate
module to allow the gPTP functionality to be shared between the two
users without having to duplicate the code in each.

See each patch for changelog.
====================

Link: https://lore.kernel.org/r/20231121155306.515446-1-niklas.soderlund+renesas@ragnatech.seSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 750011e2 8c1c6623
......@@ -44,7 +44,16 @@ config RENESAS_ETHER_SWITCH
select CRC32
select MII
select PHYLINK
select RENESAS_GEN4_PTP
help
Renesas Ethernet Switch device driver.
config RENESAS_GEN4_PTP
tristate "Renesas R-Car Gen4 gPTP support" if COMPILE_TEST
select CRC32
select MII
select PHYLIB
help
Renesas R-Car Gen4 gPTP device driver.
endif # NET_VENDOR_RENESAS
......@@ -8,5 +8,6 @@ obj-$(CONFIG_SH_ETH) += sh_eth.o
ravb-objs := ravb_main.o ravb_ptp.o
obj-$(CONFIG_RAVB) += ravb.o
rswitch_drv-objs := rswitch.o rcar_gen4_ptp.o
obj-$(CONFIG_RENESAS_ETHER_SWITCH) += rswitch_drv.o
obj-$(CONFIG_RENESAS_ETHER_SWITCH) += rswitch.o
obj-$(CONFIG_RENESAS_GEN4_PTP) += rcar_gen4_ptp.o
......@@ -14,7 +14,7 @@
#include "rcar_gen4_ptp.h"
#define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info)
static const struct rcar_gen4_ptp_reg_offset s4_offs = {
static const struct rcar_gen4_ptp_reg_offset gen4_offs = {
.enable = PTPTMEC,
.disable = PTPTMDC,
.increment = PTPTIVC0,
......@@ -130,25 +130,42 @@ static struct ptp_clock_info rcar_gen4_ptp_info = {
.enable = rcar_gen4_ptp_enable,
};
static void rcar_gen4_ptp_set_offs(struct rcar_gen4_ptp_private *ptp_priv,
enum rcar_gen4_ptp_reg_layout layout)
static int rcar_gen4_ptp_set_offs(struct rcar_gen4_ptp_private *ptp_priv,
enum rcar_gen4_ptp_reg_layout layout)
{
WARN_ON(layout != RCAR_GEN4_PTP_REG_LAYOUT_S4);
if (layout != RCAR_GEN4_PTP_REG_LAYOUT)
return -EINVAL;
ptp_priv->offs = &s4_offs;
ptp_priv->offs = &gen4_offs;
return 0;
}
static s64 rcar_gen4_ptp_rate_to_increment(u32 rate)
{
/* Timer increment in ns.
* bit[31:27] - integer
* bit[26:0] - decimal
* increment[ns] = perid[ns] * 2^27 => (1ns * 2^27) / rate[hz]
*/
return div_s64(1000000000LL << 27, rate);
}
int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv,
enum rcar_gen4_ptp_reg_layout layout, u32 clock)
enum rcar_gen4_ptp_reg_layout layout, u32 rate)
{
int ret;
if (ptp_priv->initialized)
return 0;
spin_lock_init(&ptp_priv->lock);
rcar_gen4_ptp_set_offs(ptp_priv, layout);
ret = rcar_gen4_ptp_set_offs(ptp_priv, layout);
if (ret)
return ret;
ptp_priv->default_addend = clock;
ptp_priv->default_addend = rcar_gen4_ptp_rate_to_increment(rate);
iowrite32(ptp_priv->default_addend, ptp_priv->addr + ptp_priv->offs->increment);
ptp_priv->clock = ptp_clock_register(&ptp_priv->info, NULL);
if (IS_ERR(ptp_priv->clock))
......@@ -159,6 +176,7 @@ int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv,
return 0;
}
EXPORT_SYMBOL_GPL(rcar_gen4_ptp_register);
int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv)
{
......@@ -166,6 +184,7 @@ int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv)
return ptp_clock_unregister(ptp_priv->clock);
}
EXPORT_SYMBOL_GPL(rcar_gen4_ptp_unregister);
struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev)
{
......@@ -179,3 +198,8 @@ struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev)
return ptp;
}
EXPORT_SYMBOL_GPL(rcar_gen4_ptp_alloc);
MODULE_AUTHOR("Yoshihiro Shimoda");
MODULE_DESCRIPTION("Renesas R-Car Gen4 gPTP driver");
MODULE_LICENSE("GPL");
......@@ -9,13 +9,10 @@
#include <linux/ptp_clock_kernel.h>
#define PTPTIVC_INIT 0x19000000 /* 320MHz */
#define RCAR_GEN4_PTP_CLOCK_S4 PTPTIVC_INIT
#define RCAR_GEN4_GPTP_OFFSET_S4 0x00018000
/* for rcar_gen4_ptp_init */
enum rcar_gen4_ptp_reg_layout {
RCAR_GEN4_PTP_REG_LAYOUT_S4
RCAR_GEN4_PTP_REG_LAYOUT
};
/* driver's definitions */
......@@ -28,7 +25,7 @@ enum rcar_gen4_ptp_reg_layout {
#define PTPRO 0
enum rcar_gen4_ptp_reg_s4 {
enum rcar_gen4_ptp_reg {
PTPTMEC = PTPRO + 0x0010,
PTPTMDC = PTPRO + 0x0014,
PTPTIVC0 = PTPRO + 0x0020,
......@@ -65,7 +62,7 @@ struct rcar_gen4_ptp_private {
};
int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv,
enum rcar_gen4_ptp_reg_layout layout, u32 clock);
enum rcar_gen4_ptp_reg_layout layout, u32 rate);
int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv);
struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev);
......
......@@ -1828,8 +1828,8 @@ static int rswitch_init(struct rswitch_private *priv)
rswitch_fwd_init(priv);
err = rcar_gen4_ptp_register(priv->ptp_priv, RCAR_GEN4_PTP_REG_LAYOUT_S4,
RCAR_GEN4_PTP_CLOCK_S4);
err = rcar_gen4_ptp_register(priv->ptp_priv, RCAR_GEN4_PTP_REG_LAYOUT,
clk_get_rate(priv->clk));
if (err < 0)
goto err_ptp_register;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment