diff mbox series

[4/4] can: m_can_platform: Add support for transceiver as phy

Message ID 20210409134056.18740-5-a-govindraju@ti.com
State Superseded
Headers show
Series CAN TRANSCEIVER: Add support for CAN transceivers | expand

Commit Message

Aswath Govindraju April 9, 2021, 1:40 p.m. UTC
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_platform.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Marc Kleine-Budde April 12, 2021, 10:22 a.m. UTC | #1
On 4/9/21 3:40 PM, 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_platform.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
> index 599de0e08cd7..4a762b5a21d8 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,7 +68,9 @@ 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;
> +	u32 bitrate_max;
>  
>  	mcan_class = m_can_class_allocate_dev(&pdev->dev,
>  					      sizeof(struct m_can_plat_priv));
> @@ -101,6 +104,28 @@ static int m_can_plat_probe(struct platform_device *pdev)
>  		goto probe_fail;
>  	}
>  
> +	transceiver = devm_phy_optional_get(&pdev->dev, "can_transceiver");
> +	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_warn(&pdev->dev, "No transceiver phy found\n");

I think that's a bit to loud.

> +	} else {
> +		ret = phy_power_on(transceiver);

Please move the phy power on/off to the ndo_open and ndo_stop callbacks. There's
no need to power the transceivers if the CAN interface is down.

> +		if (ret) {
> +			dev_err(&pdev->dev, "error powering on phy, err=%d\n", ret);
> +			return ret;
> +		}
> +		/* converting from Mbps to bps */
> +		bitrate_max = (transceiver->attrs.max_link_rate) * 1000000;
> +		if (!bitrate_max)
> +			dev_warn(&pdev->dev, "Invalid value for transceiver max bitrate. Ignoring bitrate limit\n");

Please move this check to the generic transcevier code.

> +		priv->cdev.can.bitrate_max = bitrate_max;
> +	}
> +
>  	priv->base = addr;
>  	priv->mram_base = mram_addr;
>  
> 

Marc
diff mbox series

Patch

diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
index 599de0e08cd7..4a762b5a21d8 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,7 +68,9 @@  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;
+	u32 bitrate_max;
 
 	mcan_class = m_can_class_allocate_dev(&pdev->dev,
 					      sizeof(struct m_can_plat_priv));
@@ -101,6 +104,28 @@  static int m_can_plat_probe(struct platform_device *pdev)
 		goto probe_fail;
 	}
 
+	transceiver = devm_phy_optional_get(&pdev->dev, "can_transceiver");
+	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_warn(&pdev->dev, "No transceiver phy found\n");
+	} else {
+		ret = phy_power_on(transceiver);
+		if (ret) {
+			dev_err(&pdev->dev, "error powering on phy, err=%d\n", ret);
+			return ret;
+		}
+		/* converting from Mbps to bps */
+		bitrate_max = (transceiver->attrs.max_link_rate) * 1000000;
+		if (!bitrate_max)
+			dev_warn(&pdev->dev, "Invalid value for transceiver max bitrate. Ignoring bitrate limit\n");
+		priv->cdev.can.bitrate_max = bitrate_max;
+	}
+
 	priv->base = addr;
 	priv->mram_base = mram_addr;