Skip to content

Commit

Permalink
can: m_can: Add support for transceiver as phy
Browse files Browse the repository at this point in the history
Add support for implementing transceiver node as phy. The max_bitrate
is obtained by getting a phy attribute.

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Faiz Abbas <[email protected]>
Signed-off-by: Aswath Govindraju <[email protected]>
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
Faiz-Abbas authored and marckleinebudde committed Jul 25, 2021
1 parent 9c0e7cc commit d836cb5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/net/can/m_can/m_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -1521,6 +1522,8 @@ static int m_can_close(struct net_device *dev)
close_candev(dev);
can_led_event(dev, CAN_LED_EVENT_STOP);

phy_power_off(cdev->transceiver);

return 0;
}

Expand Down Expand Up @@ -1706,10 +1709,14 @@ static int m_can_open(struct net_device *dev)
struct m_can_classdev *cdev = netdev_priv(dev);
int err;

err = m_can_clk_start(cdev);
err = phy_power_on(cdev->transceiver);
if (err)
return err;

err = m_can_clk_start(cdev);
if (err)
goto out_phy_power_off;

/* open the can device */
err = open_candev(dev);
if (err) {
Expand Down Expand Up @@ -1766,6 +1773,8 @@ static int m_can_open(struct net_device *dev)
close_candev(dev);
exit_disable_clks:
m_can_clk_stop(cdev);
out_phy_power_off:
phy_power_off(cdev->transceiver);
return err;
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/net/can/m_can/m_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions drivers/net/can/m_can/m_can_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -101,13 +103,24 @@ static int m_can_plat_probe(struct platform_device *pdev)
goto probe_fail;
}

transceiver = devm_phy_optional_get(&pdev->dev, NULL);
if (IS_ERR(transceiver)) {
ret = PTR_ERR(transceiver);
dev_err_probe(&pdev->dev, ret, "failed to get phy\n");
goto probe_fail;
}

if (transceiver)
mcan_class->can.bitrate_max = transceiver->attrs.max_link_rate;

priv->base = addr;
priv->mram_base = mram_addr;

mcan_class->net->irq = irq;
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;

Expand Down

0 comments on commit d836cb5

Please sign in to comment.