summaryrefslogtreecommitdiffstats
path: root/meta-rcar-gen3-adas/recipes-kernel/linux/linux-renesas/0108-can-mcp251x-add-reset-gpio-support.patch
blob: 646aa0c78953180153b47b8ee4c34a8335c754b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From b69e3fdc91fbc88cc32eb6794872e1f058681b04 Mon Sep 17 00:00:00 2001
From: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
Date: Mon, 26 Mar 2018 13:51:49 +0300
Subject: [PATCH] can: mcp251x: add reset gpio support

Signed-off-by: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
---
 drivers/net/can/spi/mcp251x.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index f3f05fe..ac78ce3 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -71,6 +71,7 @@
 #include <linux/netdevice.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
@@ -270,6 +271,7 @@ struct mcp251x_priv {
 	struct regulator *power;
 	struct regulator *transceiver;
 	struct clk *clk;
+	struct gpio_desc *rst;
 };
 
 #define MCP251X_IS(_model) \
@@ -1031,9 +1033,21 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	struct mcp251x_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct net_device *net;
 	struct mcp251x_priv *priv;
+	struct gpio_desc *reset_gpio;
 	struct clk *clk;
 	int freq, ret;
 
+	reset_gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(reset_gpio)) {
+		if (PTR_ERR(reset_gpio) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		dev_err(&spi->dev, "cannot get reset-gpios %ld\n",
+			PTR_ERR(reset_gpio));
+		reset_gpio = NULL;
+	} else {
+		gpiod_set_value_cansleep(reset_gpio, 1);
+	}
+
 	clk = devm_clk_get(&spi->dev, NULL);
 	if (IS_ERR(clk)) {
 		if (pdata)
@@ -1074,6 +1088,7 @@ static int mcp251x_can_probe(struct spi_device *spi)
 		priv->model = spi_get_device_id(spi)->driver_data;
 	priv->net = net;
 	priv->clk = clk;
+	priv->rst = reset_gpio;
 
 	spi_set_drvdata(spi, priv);
 
@@ -1185,6 +1200,8 @@ static int mcp251x_can_remove(struct spi_device *spi)
 
 	mcp251x_power_enable(priv->power, 0);
 
+	gpiod_set_value_cansleep(priv->rst, 0);
+
 	if (!IS_ERR(priv->clk))
 		clk_disable_unprepare(priv->clk);
 
-- 
1.9.1