From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
kernel@pengutronix.de, Biju Das <biju.das.jz@bp.renesas.com>,
Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net-next 06/23] can: sja1000: Add support for RZ/N1 SJA1000 CAN Controller
Date: Thu, 15 Sep 2022 10:19:56 +0200 [thread overview]
Message-ID: <20220915082013.369072-7-mkl@pengutronix.de> (raw)
In-Reply-To: <20220915082013.369072-1-mkl@pengutronix.de>
From: Biju Das <biju.das.jz@bp.renesas.com>
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: Biju 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: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/sja1000/sja1000_platform.c | 38 +++++++++++++++++++---
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 81bc741905fd..6779d5357069 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -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;
}
- 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 */
+ 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)
--
2.35.1
next prev parent reply other threads:[~2022-09-15 8:20 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-15 8:19 [PATCH net-next 0/23] pull-request: can-next 2022-09-15 Marc Kleine-Budde
2022-09-15 8:19 ` [PATCH net-next 01/23] can: rx-offload: can_rx_offload_init_queue(): fix typo Marc Kleine-Budde
2022-09-17 19:20 ` patchwork-bot+netdevbpf
2022-09-15 8:19 ` [PATCH net-next 02/23] can: flexcan: fix typo: FLEXCAN_QUIRK_SUPPPORT_* -> FLEXCAN_QUIRK_SUPPORT_* Marc Kleine-Budde
2022-09-15 8:19 ` [PATCH net-next 03/23] can: rcar_canfd: Use dev_err_probe() to simplify code and better handle -EPROBE_DEFER Marc Kleine-Budde
2022-09-15 8:19 ` [PATCH net-next 04/23] can: kvaser_usb: kvaser_usb_hydra: Use kzalloc for allocating only one element Marc Kleine-Budde
2022-09-15 8:19 ` [PATCH net-next 05/23] dt-bindings: can: nxp,sja1000: Document RZ/N1 power-domains support Marc Kleine-Budde
2022-09-15 8:19 ` Marc Kleine-Budde [this message]
2022-09-15 8:19 ` [PATCH net-next 07/23] can: sja1000: remove redundant variable ret Marc Kleine-Budde
2022-09-15 8:19 ` [PATCH net-next 08/23] can: kvaser_pciefd: " Marc Kleine-Budde
2022-09-15 8:19 ` [PATCH net-next 09/23] can: gs_usb: use common spelling of GS_USB in macros Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 10/23] can: gs_usb: add RX and TX hardware timestamp support Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 11/23] can: etas_es58x: Replace zero-length array with DECLARE_FLEX_ARRAY() helper Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 12/23] dt-bindings: net: can: nxp,sja1000: drop ref from reg-io-width Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 13/23] docs: networking: device drivers: flexcan: fix invalid email Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 14/23] can: raw: process optimization in raw_init() Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 15/23] can: raw: use guard clause to optimize nesting in raw_rcv() Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 16/23] can: flexcan: Switch to use dev_err_probe() helper Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 17/23] can: skb: unify skb CAN frame identification helpers Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 18/23] can: skb: add skb CAN frame data length helpers Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 19/23] can: set CANFD_FDF flag in all CAN FD frame structures Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 20/23] can: canxl: introduce CAN XL data structure Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 21/23] can: canxl: update CAN infrastructure for CAN XL frames Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 22/23] can: dev: add CAN XL support to virtual CAN Marc Kleine-Budde
2022-09-15 8:20 ` [PATCH net-next 23/23] can: raw: add CAN XL support Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220915082013.369072-7-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=biju.das.jz@bp.renesas.com \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).