Commit 0838921b authored by Biju Das's avatar Biju Das Committed by Marc Kleine-Budde
Browse files

can: sja1000: Add support for RZ/N1 SJA1000 CAN Controller



The SJA1000 CAN controller on RZ/N1 SoC has no clock divider register
(CDR) support compared to others.

This patch adds support for RZ/N1 SJA1000 CAN Controller, by adding
SoC specific compatible to handle this difference as well as using
clk framework to retrieve the CAN clock frequency.

Signed-off-by: default avatarBiju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/all/20220710115248.190280-7-biju.das.jz@bp.renesas.com


Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent f4dda244
Loading
Loading
Loading
Loading
+33 −5
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include <linux/irq.h>
#include <linux/can/dev.h>
#include <linux/can/platform/sja1000.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_device.h>
@@ -103,6 +104,11 @@ static void sp_technologic_init(struct sja1000_priv *priv, struct device_node *o
	spin_lock_init(&tp->io_lock);
}

static void sp_rzn1_init(struct sja1000_priv *priv, struct device_node *of)
{
	priv->flags = SJA1000_QUIRK_NO_CDR_REG;
}

static void sp_populate(struct sja1000_priv *priv,
			struct sja1000_platform_data *pdata,
			unsigned long resource_mem_flags)
@@ -153,11 +159,13 @@ static void sp_populate_of(struct sja1000_priv *priv, struct device_node *of)
		priv->write_reg = sp_write_reg8;
	}

	if (!priv->can.clock.freq) {
		err = of_property_read_u32(of, "nxp,external-clock-frequency", &prop);
		if (!err)
			priv->can.clock.freq = prop / 2;
		else
			priv->can.clock.freq = SP_CAN_CLOCK; /* default */
	}

	err = of_property_read_u32(of, "nxp,tx-output-mode", &prop);
	if (!err)
@@ -192,8 +200,13 @@ static struct sja1000_of_data technologic_data = {
	.init = sp_technologic_init,
};

static struct sja1000_of_data renesas_data = {
	.init = sp_rzn1_init,
};

static const struct of_device_id sp_of_table[] = {
	{ .compatible = "nxp,sja1000", .data = NULL, },
	{ .compatible = "renesas,rzn1-sja1000", .data = &renesas_data, },
	{ .compatible = "technologic,sja1000", .data = &technologic_data, },
	{ /* sentinel */ },
};
@@ -210,6 +223,7 @@ static int sp_probe(struct platform_device *pdev)
	struct device_node *of = pdev->dev.of_node;
	const struct sja1000_of_data *of_data = NULL;
	size_t priv_sz = 0;
	struct clk *clk;

	pdata = dev_get_platdata(&pdev->dev);
	if (!pdata && !of) {
@@ -234,6 +248,11 @@ static int sp_probe(struct platform_device *pdev)
		irq = platform_get_irq(pdev, 0);
		if (irq < 0)
			return irq;

		clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
		if (IS_ERR(clk))
			return dev_err_probe(&pdev->dev, PTR_ERR(clk),
					     "CAN clk operation failed");
	} else {
		res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
		if (!res_irq)
@@ -262,6 +281,15 @@ static int sp_probe(struct platform_device *pdev)
	priv->reg_base = addr;

	if (of) {
		if (clk) {
			priv->can.clock.freq  = clk_get_rate(clk) / 2;
			if (!priv->can.clock.freq) {
				err = -EINVAL;
				dev_err(&pdev->dev, "Zero CAN clk rate");
				goto exit_free;
			}
		}

		sp_populate_of(priv, of);

		if (of_data && of_data->init)