From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Aswath Govindraju <a-govindraju@ti.com>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-phy@lists.infradead.org,
Chandrasekar Ramakrishnan <rcsekar@samsung.com>,
Wolfgang Grandegger <wg@grandegger.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Kishon Vijay Abraham I <kishon@ti.com>,
Vinod Koul <vkoul@kernel.org>,
linux-can@vger.kernel.org, netdev@vger.kernel.org,
Vignesh Raghavendra <vigneshr@ti.com>,
Lokesh Vutla <lokeshvutla@ti.com>,
Grygorii Strashko <grygorii.strashko@ti.com>
Subject: Re: [PATCH v2 6/6] can: m_can: Add support for transceiver as phy
Date: Wed, 14 Apr 2021 17:15:44 +0200 [thread overview]
Message-ID: <20210414151544.uk756tddae3gdmvv@pengutronix.de> (raw)
In-Reply-To: <20210414140521.11463-7-a-govindraju@ti.com>
[-- Attachment #1: Type: text/plain, Size: 4801 bytes --]
On 14.04.2021 19:35:21, Aswath Govindraju wrote:
> From: Faiz Abbas <faiz_abbas@ti.com>
>
> Add support for implementing transceiver node as phy. The max_bitrate is
> obtained by getting a phy attribute.
>
> Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
> ---
> drivers/net/can/m_can/m_can.c | 18 ++++++++++++++++++
> drivers/net/can/m_can/m_can.h | 2 ++
> drivers/net/can/m_can/m_can_platform.c | 15 +++++++++++++++
> 3 files changed, 35 insertions(+)
>
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 34073cd077e4..4807a1f69cc7 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -21,6 +21,7 @@
> #include <linux/iopoll.h>
> #include <linux/can/dev.h>
> #include <linux/pinctrl/consumer.h>
> +#include <linux/phy/phy.h>
>
> #include "m_can.h"
>
> @@ -1514,6 +1515,7 @@ static void m_can_stop(struct net_device *dev)
> static int m_can_close(struct net_device *dev)
> {
> struct m_can_classdev *cdev = netdev_priv(dev);
> + int err;
>
> netif_stop_queue(dev);
>
> @@ -1536,6 +1538,14 @@ static int m_can_close(struct net_device *dev)
> close_candev(dev);
> can_led_event(dev, CAN_LED_EVENT_STOP);
>
> + if (cdev->transceiver) {
> + err = phy_power_off(cdev->transceiver);
phy_power_off() can handle NULL pointers
> + if (err) {
> + netdev_err(dev, "error powering off phy, err=%d\n", err);
> + return err;
As far as I can see it already print an error message in case of an
error.
> + }
> + }
> +
> return 0;
> }
>
> @@ -1720,6 +1730,14 @@ static int m_can_open(struct net_device *dev)
> struct m_can_classdev *cdev = netdev_priv(dev);
> int err;
>
> + if (cdev->transceiver) {
> + err = phy_power_on(cdev->transceiver);
> + if (err) {
> + netdev_err(dev, "error powering on phy, err=%d\n", err);
> + return err;
> + }
same here
> + }
> +
> err = m_can_clk_start(cdev);
> if (err)
> return err;
> diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
> index ace071c3e58c..38cad068abad 100644
> --- a/drivers/net/can/m_can/m_can.h
> +++ b/drivers/net/can/m_can/m_can.h
> @@ -28,6 +28,7 @@
> #include <linux/iopoll.h>
> #include <linux/can/dev.h>
> #include <linux/pinctrl/consumer.h>
> +#include <linux/phy/phy.h>
>
> /* m_can lec values */
> enum m_can_lec_type {
> @@ -82,6 +83,7 @@ struct m_can_classdev {
> struct workqueue_struct *tx_wq;
> struct work_struct tx_work;
> struct sk_buff *tx_skb;
> + struct phy *transceiver;
>
> struct can_bittiming_const *bit_timing;
> struct can_bittiming_const *data_timing;
> diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
> index 599de0e08cd7..566ba25fb186 100644
> --- a/drivers/net/can/m_can/m_can_platform.c
> +++ b/drivers/net/can/m_can/m_can_platform.c
> @@ -6,6 +6,7 @@
> // Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
>
> #include <linux/platform_device.h>
> +#include <linux/phy/phy.h>
>
> #include "m_can.h"
>
> @@ -67,6 +68,7 @@ static int m_can_plat_probe(struct platform_device *pdev)
> struct resource *res;
> void __iomem *addr;
> void __iomem *mram_addr;
> + struct phy *transceiver;
> int irq, ret = 0;
>
> mcan_class = m_can_class_allocate_dev(&pdev->dev,
> @@ -101,6 +103,18 @@ static int m_can_plat_probe(struct platform_device *pdev)
> goto probe_fail;
> }
>
> + transceiver = devm_of_phy_optional_get_by_index(&pdev->dev, pdev->dev.of_node, 0);
> + if (IS_ERR(transceiver)) {
> + ret = PTR_ERR(transceiver);
> + dev_err(&pdev->dev, "error while getting phy, err=%d\n", ret);
> + return ret;
> + }
> +
> + if (!transceiver)
> + dev_info(&pdev->dev, "No transceiver phy found\n");
I don't think you should print anything here...
If the driver was working before w/o a phy it will still work without one.
> + else
> + priv->cdev.can.bitrate_max = transceiver->attrs.max_link_rate;
> +
> priv->base = addr;
> priv->mram_base = mram_addr;
>
> @@ -108,6 +122,7 @@ static int m_can_plat_probe(struct platform_device *pdev)
> mcan_class->pm_clock_support = 1;
> mcan_class->can.clock.freq = clk_get_rate(mcan_class->cclk);
> mcan_class->dev = &pdev->dev;
> + mcan_class->transceiver = transceiver;
>
> mcan_class->ops = &m_can_plat_ops;
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2021-04-14 15:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-14 14:05 [PATCH v2 0/6] CAN TRANSCEIVER: Add support for CAN transceivers Aswath Govindraju
2021-04-14 14:05 ` [PATCH v2 1/6] phy: core: Reword the comment specifying the units of max_link_rate to be Mbps Aswath Govindraju
2021-04-14 14:05 ` [PATCH v2 2/6] phy: Add API for devm_of_phy_optional_get_by_index Aswath Govindraju
2021-04-14 14:05 ` [PATCH v2 3/6] dt-bindings: phy: Add binding for TI TCAN104x CAN transceivers Aswath Govindraju
2021-04-14 15:33 ` Marc Kleine-Budde
2021-04-15 6:27 ` Aswath Govindraju
2021-04-15 7:38 ` Marc Kleine-Budde
2021-04-15 9:11 ` Aswath Govindraju
2021-04-15 9:15 ` Marc Kleine-Budde
2021-04-14 14:05 ` [PATCH v2 4/6] phy: phy-can-transceiver: Add support for generic CAN transceiver driver Aswath Govindraju
2021-04-14 15:39 ` Marc Kleine-Budde
2021-04-14 15:40 ` Marc Kleine-Budde
2021-04-15 7:44 ` kernel test robot
2021-04-15 9:12 ` kernel test robot
2021-04-14 14:05 ` [PATCH v2 5/6] dt-bindings: net: can: Document transceiver implementation as phy Aswath Govindraju
2021-04-14 14:05 ` [PATCH v2 6/6] can: m_can: Add support for transceiver " Aswath Govindraju
2021-04-14 15:15 ` Marc Kleine-Budde [this message]
2021-04-14 15:43 ` [PATCH v2 0/6] CAN TRANSCEIVER: Add support for CAN transceivers 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=20210414151544.uk756tddae3gdmvv@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=a-govindraju@ti.com \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=grygorii.strashko@ti.com \
--cc=kishon@ti.com \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=lokeshvutla@ti.com \
--cc=netdev@vger.kernel.org \
--cc=rcsekar@samsung.com \
--cc=robh+dt@kernel.org \
--cc=vigneshr@ti.com \
--cc=vkoul@kernel.org \
--cc=wg@grandegger.com \
/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).