can: rcar_canfd: Add transceiver support
Geert Uytterhoeven
maintainerv4 cover can: rcar_canfd: Add transceiver support
Hi all,
This patch series adds transceiver support to the Renesas R-Car CAN-FD driver, and improves the printing of error messages, as requested by Vincent.
Originally, both patches were submitted separately, but as the latter depends on the former, I absorbed it within this series for the resend.
Thanks!
Geert Uytterhoeven (2):
can: rcar_canfd: Add transceiver support
can: rcar_canfd: Improve error messages
drivers/net/can/rcar/rcar_canfd.c | 71 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 26 deletions(-)
Signature · 12 lines
2.34.1
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsGeert Uytterhoeven
maintainerPATCH v4 1/2 can: rcar_canfd: Add transceiver support
Add support for CAN transceivers described as PHYs.
While simple CAN transceivers can do without, this is needed for CAN transceivers like NXP TJR1443 that need a configuration step (like pulling standby or enable lines), and/or impose a bitrate limit.
---
v3:
- Add Reviewed-by,
v2:
- Add Reviewed-by.
--- drivers/net/can/rcar/rcar_canfd.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/net/can/rcar/rcar_canfd.c +25 -5
@@ -35,6 +35,7 @@#include <linux/netdevice.h> #include <linux/of.h> #include <linux/of_device.h> +#include <linux/phy/phy.h> #include <linux/platform_device.h> #include <linux/reset.h> #include <linux/types.h>
@@ -530,6 +531,7 @@ struct rcar_canfd_channel {struct net_device *ndev;struct rcar_canfd_global *gpriv;/* Controller reference */ void __iomem *base;/* Register base address */ +struct phy *transceiver;/* Optional transceiver */ struct napi_struct napi;u32 tx_head;/* Incremented on xmit */ u32 tx_tail;/* Incremented on xmit done */
@@ -1413,11 +1415,17 @@ static int rcar_canfd_open(struct net_device *ndev)struct rcar_canfd_global *gpriv = priv->gpriv;int err; + err =phy_power_on (priv->transceiver); +if (err) { +netdev_err (ndev,"failed to power on PHY, error %d\n" , err); +return err; + } +/* Peripheral clock is already enabled in probe */ err =clk_prepare_enable (gpriv->can_clk);if (err) {netdev_err (ndev,"failed to enable CAN clock, error %d\n" , err); - goto out_clock; + goto out_phy; } err =open_candev (ndev);
@@ -1437,7 +1445,8 @@ static int rcar_canfd_open(struct net_device *ndev)close_candev (ndev); out_can_clock:clk_disable_unprepare (gpriv->can_clk); -out_clock: +out_phy: +phy_power_off (priv->transceiver);return err; }
@@ -1480,6 +1489,7 @@ static int rcar_canfd_close(struct net_device *ndev)napi_disable (&priv->napi);clk_disable_unprepare (gpriv->can_clk);close_candev (ndev); +phy_power_off (priv->transceiver);return 0 ; }
@@ -1711,7 +1721,7 @@ static const struct ethtool_ops rcar_canfd_ethtool_ops = { };static int rcar_canfd_channel_probe (struct rcar_canfd_global *gpriv,u32 ch, -u32 fcan_freq) +u32 fcan_freq,struct phy *transceiver) {const struct rcar_canfd_hw_info *info = gpriv->info;struct platform_device *pdev = gpriv->pdev;
@@ -1732,8 +1742,11 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, ndev->flags |=IFF_ECHO ; priv->ndev = ndev; priv->base = gpriv->base; + priv->transceiver = transceiver; priv->channel = ch; priv->gpriv = gpriv; +if (transceiver) + priv->can.bitrate_max = transceiver->attrs.max_link_rate; priv->can.clock.freq = fcan_freq;dev_info (dev,"can_clk rate is %u\n" , priv->can.clock.freq);
@@ -1836,6 +1849,7 @@ static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch)static int rcar_canfd_probe (struct platform_device *pdev) { +struct phy *transceivers[RCANFD_NUM_CHANNELS ] = {0 , };const struct rcar_canfd_hw_info *info;struct device *dev = &pdev->dev;void __iomem *addr;
@@ -1857,9 +1871,14 @@ static int rcar_canfd_probe(struct platform_device *pdev)for (i =0 ; i < info->max_channels; ++i) { name[7 ] ='0' + i; of_child =of_get_child_by_name (dev->of_node, name); -if (of_child &&of_device_is_available (of_child)) +if (of_child &&of_device_is_available (of_child)) { channels_mask |=BIT (i); + transceivers[i] =devm_of_phy_optional_get (dev, + of_child,NULL ); + }of_node_put (of_child); +if (IS_ERR (transceivers[i])) +return PTR_ERR (transceivers[i]); }if (info->shared_global_irqs) {
@@ -2035,7 +2054,8 @@ static int rcar_canfd_probe(struct platform_device *pdev) }for_each_set_bit (ch, &gpriv->channels_mask, info->max_channels) { - err =rcar_canfd_channel_probe (gpriv, ch, fcan_freq); + err =rcar_canfd_channel_probe (gpriv, ch, fcan_freq, + transceivers[ch]);if (err) goto fail_channel; }
Signature · 1 line
2.34.1
Geert Uytterhoeven
maintainerPATCH v4 2/2 can: rcar_canfd: Improve error messages
In reply to Geert UytterhoevenImprove printed error messages:
- Replace numerical error codes by mnemotechnic error codes, to improve the user experience in case of errors,
- Drop parentheses around printed numbers, cfr. Documentation/process/coding-style.rst,
- Drop printing of an error message in case of out-of-memory, as the core memory allocation code already takes care of this.
---
v4:
- Reviewed-by: Simon Horman <[email protected]>,
v3:
- Add missing SoB,
v2:
- This is v2 of "[PATCH] can: rcar_canfd: Print mnemotechnic error codes". I haven't added any tags given on v1, as half of the printed message changed.
--- drivers/net/can/rcar/rcar_canfd.c | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-)
drivers/net/can/rcar/rcar_canfd.c +21 -22
@@ -1417,20 +1417,20 @@ static int rcar_canfd_open(struct net_device *ndev) err =phy_power_on (priv->transceiver);if (err) { -netdev_err (ndev,"failed to power on PHY, error %d\n" , err); +netdev_err (ndev,"failed to power on PHY, %pe\n" ,ERR_PTR (err));return err; }/* Peripheral clock is already enabled in probe */ err =clk_prepare_enable (gpriv->can_clk);if (err) { -netdev_err (ndev,"failed to enable CAN clock, error %d\n" , err); +netdev_err (ndev,"failed to enable CAN clock, %pe\n" ,ERR_PTR (err)); goto out_phy; } err =open_candev (ndev);if (err) { -netdev_err (ndev,"open_candev() failed, error %d\n" , err); +netdev_err (ndev,"open_candev() failed, %pe\n" ,ERR_PTR (err)); goto out_can_clock; }
@@ -1731,10 +1731,9 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,int err = -ENODEV ; ndev =alloc_candev (sizeof (*priv),RCANFD_FIFO_DEPTH ); -if (!ndev) { -dev_err (dev,"alloc_candev() failed\n" ); +if (!ndev)return -ENOMEM ; - } + priv =netdev_priv (ndev); ndev->netdev_ops = &rcar_canfd_netdev_ops;
@@ -1777,8 +1776,8 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, rcar_canfd_channel_err_interrupt,0 , irq_name, priv);if (err) { -dev_err (dev,"devm_request_irq CH Err(%d) failed, error %d\n" , - err_irq, err); +dev_err (dev,"devm_request_irq CH Err %d failed, %pe\n" , + err_irq,ERR_PTR (err)); goto fail; } irq_name = devm_kasprintf(dev, GFP_KERNEL, "canfd.ch%d_trx",
@@ -1791,8 +1790,8 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, rcar_canfd_channel_tx_interrupt,0 , irq_name, priv);if (err) { -dev_err (dev,"devm_request_irq Tx (%d) failed, error %d\n" , - tx_irq, err); +dev_err (dev,"devm_request_irq Tx %d failed, %pe\n" , + tx_irq,ERR_PTR (err)); goto fail; } }
@@ -1823,7 +1822,7 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, gpriv->ch[priv->channel] = priv; err =register_candev (ndev);if (err) { -dev_err (dev,"register_candev() failed, error %d\n" , err); +dev_err (dev,"register_candev() failed, %pe\n" ,ERR_PTR (err)); goto fail_candev; }dev_info (dev,"device registered (channel %u)\n" , priv->channel);
@@ -1967,16 +1966,16 @@ static int rcar_canfd_probe(struct platform_device *pdev) rcar_canfd_channel_interrupt,0 , "canfd.ch_int", gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - ch_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + ch_irq,ERR_PTR (err)); goto fail_dev; } err =devm_request_irq (dev, g_irq, rcar_canfd_global_interrupt,0 ,"canfd.g_int" , gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - g_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + g_irq,ERR_PTR (err)); goto fail_dev; } }else {
@@ -1985,8 +1984,8 @@ static int rcar_canfd_probe(struct platform_device *pdev) "canfd.g_recc", gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - g_recc_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + g_recc_irq,ERR_PTR (err)); goto fail_dev; }
@@ -1994,8 +1993,8 @@ static int rcar_canfd_probe(struct platform_device *pdev) rcar_canfd_global_err_interrupt,0 , "canfd.g_err", gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - g_err_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + g_err_irq,ERR_PTR (err)); goto fail_dev; } }
@@ -2012,14 +2011,14 @@ static int rcar_canfd_probe(struct platform_device *pdev)/* Enable peripheral clock for register access */ err =clk_prepare_enable (gpriv->clkp);if (err) { -dev_err (dev,"failed to enable peripheral clock, error %d\n" , - err); +dev_err (dev,"failed to enable peripheral clock, %pe\n" , +ERR_PTR (err)); goto fail_reset; } err =rcar_canfd_reset_controller (gpriv);if (err) { -dev_err (dev,"reset controller failed\n" ); +dev_err (dev,"reset controller failed, %pe\n" ,ERR_PTR (err)); goto fail_clk; }
Signature · 1 line
2.34.1
Quoted 8 lines · Geert Uytterhoeven
Hi all,
This patch series adds transceiver support to the Renesas R-Car CAN-FD driver, and improves the printing of error messages, as requested by Vincent.
Originally, both patches were submitted separately, but as the latter depends on the former, I absorbed it within this series for the resend.
Applied to linux-can-next. I've squashed the improved error message for the phy_power_on() into patch 1.
Thanks,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v4 2/2] can: rcar_canfd: Improve error messages
In reply to Geert UytterhoevenQuoted 11 lines · Geert Uytterhoeven
Improve printed error messages:
- Replace numerical error codes by mnemotechnic error codes, to improve the user experience in case of errors,
- Drop parentheses around printed numbers, cfr.Documentation/process/coding-style.rst,
- Drop printing of an error message in case of out-of-memory, as the core memory allocation code already takes care of this.Suggested-by Vincent Mailhol <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Reviewed-by Simon Horman <[email protected]>
I added a nitpick. If you prefer to keep as-is, OK for me.
Quoted 20 lines
---
v4:
- Reviewed-by: Simon Horman <[email protected]>,v3:
- Add missing SoB,v2:
- This is v2 of "[PATCH] can:rcar_canfd: Print mnemotechnic error codes". I haven't added any tags given on v1, as half of the printed message changed.--- drivers/net/can/rcar/rcar_canfd.c | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-)drivers/net/can/rcar/rcar_canfd.c +0
-0
drivers/net/can/rcar/rcar_canfd.c static int rcar_canfd_open(struct net_device *ndev) · line 1420
Quoted 5 lines
drivers/net/can/rcar/rcar_canfd.c +1
-1@@ -1417,20 +1417,20 @@ static int rcar_canfd_open(struct net_device *ndev) err =phy_power_on (priv->transceiver);if (err) { -netdev_err (ndev,"failed to power on PHY, error %d\n" , err); +netdev_err (ndev,"failed to power on PHY, %pe\n" ,ERR_PTR (err));
^
Nitpick, consider a colon instead of the coma:
netdev_err(ndev, "failed to power on PHY: %pe\n",ERR_PTR(err));
N.B. This is more a personal preference than an official Linux style. If you prefer the coma, you can ignore my nitpick and keep it as it is :)
Quoted 126 lines
drivers/net/can/rcar/rcar_canfd.c +20
-22return err; }/* Peripheral clock is already enabled in probe */ err =clk_prepare_enable (gpriv->can_clk);if (err) { -netdev_err (ndev,"failed to enable CAN clock, error %d\n" , err); +netdev_err (ndev,"failed to enable CAN clock, %pe\n" ,ERR_PTR (err)); goto out_phy; } err =open_candev (ndev);if (err) { -netdev_err (ndev,"open_candev() failed, error %d\n" , err); +netdev_err (ndev,"open_candev() failed, %pe\n" ,ERR_PTR (err)); goto out_can_clock; }@@ -1731,10 +1731,9 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,int err = -ENODEV ; ndev =alloc_candev (sizeof (*priv),RCANFD_FIFO_DEPTH ); -if (!ndev) { -dev_err (dev,"alloc_candev() failed\n" ); +if (!ndev)return -ENOMEM ; - } + priv =netdev_priv (ndev); ndev->netdev_ops = &rcar_canfd_netdev_ops;@@ -1777,8 +1776,8 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, rcar_canfd_channel_err_interrupt,0 , irq_name, priv);if (err) { -dev_err (dev,"devm_request_irq CH Err(%d) failed, error %d\n" , - err_irq, err); +dev_err (dev,"devm_request_irq CH Err %d failed, %pe\n" , + err_irq,ERR_PTR (err)); goto fail; } irq_name = devm_kasprintf(dev, GFP_KERNEL, "canfd.ch%d_trx",@@ -1791,8 +1790,8 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, rcar_canfd_channel_tx_interrupt,0 , irq_name, priv);if (err) { -dev_err (dev,"devm_request_irq Tx (%d) failed, error %d\n" , - tx_irq, err); +dev_err (dev,"devm_request_irq Tx %d failed, %pe\n" , + tx_irq,ERR_PTR (err)); goto fail; } }@@ -1823,7 +1822,7 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch, gpriv->ch[priv->channel] = priv; err =register_candev (ndev);if (err) { -dev_err (dev,"register_candev() failed, error %d\n" , err); +dev_err (dev,"register_candev() failed, %pe\n" ,ERR_PTR (err)); goto fail_candev; }dev_info (dev,"device registered (channel %u)\n" , priv->channel);@@ -1967,16 +1966,16 @@ static int rcar_canfd_probe(struct platform_device *pdev) rcar_canfd_channel_interrupt,0 , "canfd.ch_int", gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - ch_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + ch_irq,ERR_PTR (err)); goto fail_dev; } err =devm_request_irq (dev, g_irq, rcar_canfd_global_interrupt,0 ,"canfd.g_int" , gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - g_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + g_irq,ERR_PTR (err)); goto fail_dev; } }else {@@ -1985,8 +1984,8 @@ static int rcar_canfd_probe(struct platform_device *pdev) "canfd.g_recc", gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - g_recc_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + g_recc_irq,ERR_PTR (err)); goto fail_dev; }@@ -1994,8 +1993,8 @@ static int rcar_canfd_probe(struct platform_device *pdev) rcar_canfd_global_err_interrupt,0 , "canfd.g_err", gpriv);if (err) { -dev_err (dev,"devm_request_irq(%d) failed, error %d\n" , - g_err_irq, err); +dev_err (dev,"devm_request_irq %d failed, %pe\n" , + g_err_irq,ERR_PTR (err)); goto fail_dev; } }@@ -2012,14 +2011,14 @@ static int rcar_canfd_probe(struct platform_device *pdev)/* Enable peripheral clock for register access */ err =clk_prepare_enable (gpriv->clkp);if (err) { -dev_err (dev,"failed to enable peripheral clock, error %d\n" , - err); +dev_err (dev,"failed to enable peripheral clock, %pe\n" , +ERR_PTR (err)); goto fail_reset; } err =rcar_canfd_reset_controller (gpriv);if (err) { -dev_err (dev,"reset controller failed\n" ); +dev_err (dev,"reset controller failed, %pe\n" ,ERR_PTR (err)); goto fail_clk; } --2.34.1
Marc Kleine-Budde
maintainerQuoted 8 lines · Geert Uytterhoeven
Hi all,
This patch series adds transceiver support to the Renesas R-Car CAN-FD driver, and improves the printing of error messages, as requested by Vincent.
Originally, both patches were submitted separately, but as the latter depends on the former, I absorbed it within this series for the resend.
Thanks. Applied to can-next, I've replaced the colons by comma, as Vincent suggested.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Marc,
Quoted 10 lines · Marc Kleine-Budde
Quoted 6 lines · Geert Uytterhoeven
This patch series adds transceiver support to the Renesas R-Car CAN-FD driver, and improves the printing of error messages, as requested by Vincent.
Originally, both patches were submitted separately, but as the latter depends on the former, I absorbed it within this series for the resend.
Thanks. Applied to can-next, I've replaced the colons by comma, as Vincent suggested.
Thanks a lot!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds