Skip to content

Commit 2e12d79

Browse files
Merge patch series "can: xilinx_can: Add support for reset"
Michal Simek <[email protected]> says: IP core has option reset line which can be wired that's why add support for optional reset. Changes in v2: - Add Conor's ACK - Fix use-after-free in xcan_remove reported by Marc. - Link to v1: https://lore.kernel.org/all/[email protected] Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
2 parents 22d8e8d + 25000fc commit 2e12d79

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Documentation/devicetree/bindings/net/can/xilinx,can.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ properties:
4646
$ref: /schemas/types.yaml#/definitions/uint32
4747
description: CAN Tx mailbox buffer count (CAN FD)
4848

49+
resets:
50+
maxItems: 1
51+
4952
required:
5053
- compatible
5154
- reg

drivers/net/can/xilinx_can.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/can/error.h>
3131
#include <linux/phy/phy.h>
3232
#include <linux/pm_runtime.h>
33+
#include <linux/reset.h>
3334

3435
#define DRIVER_NAME "xilinx_can"
3536

@@ -200,6 +201,7 @@ struct xcan_devtype_data {
200201
* @can_clk: Pointer to struct clk
201202
* @devtype: Device type specific constants
202203
* @transceiver: Optional pointer to associated CAN transceiver
204+
* @rstc: Pointer to reset control
203205
*/
204206
struct xcan_priv {
205207
struct can_priv can;
@@ -218,6 +220,7 @@ struct xcan_priv {
218220
struct clk *can_clk;
219221
struct xcan_devtype_data devtype;
220222
struct phy *transceiver;
223+
struct reset_control *rstc;
221224
};
222225

223226
/* CAN Bittiming constants as per Xilinx CAN specs */
@@ -1799,6 +1802,16 @@ static int xcan_probe(struct platform_device *pdev)
17991802
priv->can.do_get_berr_counter = xcan_get_berr_counter;
18001803
priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
18011804
CAN_CTRLMODE_BERR_REPORTING;
1805+
priv->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
1806+
if (IS_ERR(priv->rstc)) {
1807+
dev_err(&pdev->dev, "Cannot get CAN reset.\n");
1808+
ret = PTR_ERR(priv->rstc);
1809+
goto err_free;
1810+
}
1811+
1812+
ret = reset_control_reset(priv->rstc);
1813+
if (ret)
1814+
goto err_free;
18021815

18031816
if (devtype->cantype == XAXI_CANFD) {
18041817
priv->can.data_bittiming_const =
@@ -1827,7 +1840,7 @@ static int xcan_probe(struct platform_device *pdev)
18271840
/* Get IRQ for the device */
18281841
ret = platform_get_irq(pdev, 0);
18291842
if (ret < 0)
1830-
goto err_free;
1843+
goto err_reset;
18311844

18321845
ndev->irq = ret;
18331846

@@ -1843,21 +1856,21 @@ static int xcan_probe(struct platform_device *pdev)
18431856
if (IS_ERR(priv->can_clk)) {
18441857
ret = dev_err_probe(&pdev->dev, PTR_ERR(priv->can_clk),
18451858
"device clock not found\n");
1846-
goto err_free;
1859+
goto err_reset;
18471860
}
18481861

18491862
priv->bus_clk = devm_clk_get(&pdev->dev, devtype->bus_clk_name);
18501863
if (IS_ERR(priv->bus_clk)) {
18511864
ret = dev_err_probe(&pdev->dev, PTR_ERR(priv->bus_clk),
18521865
"bus clock not found\n");
1853-
goto err_free;
1866+
goto err_reset;
18541867
}
18551868

18561869
transceiver = devm_phy_optional_get(&pdev->dev, NULL);
18571870
if (IS_ERR(transceiver)) {
18581871
ret = PTR_ERR(transceiver);
18591872
dev_err_probe(&pdev->dev, ret, "failed to get phy\n");
1860-
goto err_free;
1873+
goto err_reset;
18611874
}
18621875
priv->transceiver = transceiver;
18631876

@@ -1904,6 +1917,8 @@ static int xcan_probe(struct platform_device *pdev)
19041917
err_disableclks:
19051918
pm_runtime_put(priv->dev);
19061919
pm_runtime_disable(&pdev->dev);
1920+
err_reset:
1921+
reset_control_assert(priv->rstc);
19071922
err_free:
19081923
free_candev(ndev);
19091924
err:
@@ -1920,9 +1935,11 @@ static int xcan_probe(struct platform_device *pdev)
19201935
static void xcan_remove(struct platform_device *pdev)
19211936
{
19221937
struct net_device *ndev = platform_get_drvdata(pdev);
1938+
struct xcan_priv *priv = netdev_priv(ndev);
19231939

19241940
unregister_candev(ndev);
19251941
pm_runtime_disable(&pdev->dev);
1942+
reset_control_assert(priv->rstc);
19261943
free_candev(ndev);
19271944
}
19281945

0 commit comments

Comments
 (0)