Skip to content

Commit b3d39a8

Browse files
hormsdavem330
authored andcommitted
ravb: use clock rate as basis for GTI.TIV
The GTI.TIV may be set to 2GHz^2 / rate, where rate is that of the clock of the device. Rather than assuming a rate of 130MHz use the actual rate of the clock. The motivation for this is to use the correct rate on the r8a7795/Salvator-X which is advertised as 133MHz but may differ depending on the extal present on the Salvator-X. Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1777ddb commit b3d39a8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

drivers/net/ethernet/renesas/ravb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ enum GTI_BIT {
576576
GTI_TIV = 0x0FFFFFFF,
577577
};
578578

579+
#define GTI_TIV_MAX GTI_TIV
580+
#define GTI_TIV_MIN 0x20
581+
579582
/* GIC */
580583
enum GIC_BIT {
581584
GIC_PTCE = 0x00000001, /* Undocumented? */

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <linux/slab.h>
3333
#include <linux/spinlock.h>
3434

35+
#include <asm/div64.h>
36+
3537
#include "ravb.h"
3638

3739
#define RAVB_DEF_MSG_ENABLE \
@@ -1659,6 +1661,38 @@ static const struct of_device_id ravb_match_table[] = {
16591661
};
16601662
MODULE_DEVICE_TABLE(of, ravb_match_table);
16611663

1664+
static int ravb_set_gti(struct net_device *ndev)
1665+
{
1666+
1667+
struct device *dev = ndev->dev.parent;
1668+
struct device_node *np = dev->of_node;
1669+
unsigned long rate;
1670+
struct clk *clk;
1671+
uint64_t inc;
1672+
1673+
clk = of_clk_get(np, 0);
1674+
if (IS_ERR(clk)) {
1675+
dev_err(dev, "could not get clock\n");
1676+
return PTR_ERR(clk);
1677+
}
1678+
1679+
rate = clk_get_rate(clk);
1680+
clk_put(clk);
1681+
1682+
inc = 1000000000ULL << 20;
1683+
do_div(inc, rate);
1684+
1685+
if (inc < GTI_TIV_MIN || inc > GTI_TIV_MAX) {
1686+
dev_err(dev, "gti.tiv increment 0x%llx is outside the range 0x%x - 0x%x\n",
1687+
inc, GTI_TIV_MIN, GTI_TIV_MAX);
1688+
return -EINVAL;
1689+
}
1690+
1691+
ravb_write(ndev, inc, GTI);
1692+
1693+
return 0;
1694+
}
1695+
16621696
static int ravb_probe(struct platform_device *pdev)
16631697
{
16641698
struct device_node *np = pdev->dev.of_node;
@@ -1755,7 +1789,9 @@ static int ravb_probe(struct platform_device *pdev)
17551789
CCC);
17561790

17571791
/* Set GTI value */
1758-
ravb_write(ndev, ((1000 << 20) / 130) & GTI_TIV, GTI);
1792+
error = ravb_set_gti(ndev);
1793+
if (error)
1794+
goto out_release;
17591795

17601796
/* Request GTI loading */
17611797
ravb_write(ndev, ravb_read(ndev, GCCR) | GCCR_LTI, GCCR);

0 commit comments

Comments
 (0)