aboutsummaryrefslogtreecommitdiffstats
path: root/meta-rcar-gen3-adas/recipes-kernel/linux/linux-renesas/0066-pci-pcie-rcar-add-regulators-support.patch
blob: 2a9a2a08f9d73ca3679c87d9c0b8ef123627990a (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
From d5a3dee65f4ee9d320128bbf79df80d51aec7687 Mon Sep 17 00:00:00 2001
From: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
Date: Mon, 24 Jul 2017 20:22:03 +0300
Subject: [PATCH] pci: pcie-rcar: add regulators support

Add PCIE regulators

Signed-off-by: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
---
 drivers/pci/host/pcie-rcar.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
index 8e24d5f88415..6994ea2ac936 100644
--- a/drivers/pci/host/pcie-rcar.c
+++ b/drivers/pci/host/pcie-rcar.c
@@ -16,6 +16,7 @@
 
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/regulator/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
@@ -155,6 +156,8 @@ struct rcar_pcie {
 	int			root_bus_nr;
 	struct clk		*clk;
 	struct clk		*bus_clk;
+	struct regulator	*pcie3v3; /* 3.3V power supply */
+	struct regulator	*pcie1v8; /* 1.8V power supply */
 	struct			rcar_msi msi;
 };
 
@@ -1193,6 +1196,36 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci)
 	return err;
 }
 
+static int rcar_pcie_set_vpcie(struct rcar_pcie *pcie)
+{
+	struct device *dev = pcie->dev;
+	int err;
+
+	if (!IS_ERR(pcie->pcie3v3)) {
+		err = regulator_enable(pcie->pcie3v3);
+		if (err) {
+			dev_err(dev, "fail to enable vpcie3v3 regulator\n");
+			goto err_out;
+		}
+	}
+
+	if (!IS_ERR(pcie->pcie1v8)) {
+		err = regulator_enable(pcie->pcie1v8);
+		if (err) {
+			dev_err(dev, "fail to enable vpcie1v8 regulator\n");
+			goto err_disable_3v3;
+		}
+	}
+
+	return 0;
+
+err_disable_3v3:
+	if (!IS_ERR(pcie->pcie3v3))
+		regulator_disable(pcie->pcie3v3);
+err_out:
+	return err;
+}
+
 static int rcar_pcie_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -1209,6 +1242,26 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	pcie->dev = dev;
 	platform_set_drvdata(pdev, pcie);
 
+	pcie->pcie3v3 = devm_regulator_get_optional(dev, "pcie3v3");
+	if (IS_ERR(pcie->pcie3v3)) {
+		if (PTR_ERR(pcie->pcie3v3) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		dev_info(dev, "no pcie3v3 regulator found\n");
+	}
+
+	pcie->pcie1v8 = devm_regulator_get_optional(dev, "pcie1v8");
+	if (IS_ERR(pcie->pcie1v8)) {
+		if (PTR_ERR(pcie->pcie1v8) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		dev_info(dev, "no pcie1v8 regulator found\n");
+	}
+
+	err = rcar_pcie_set_vpcie(pcie);
+	if (err) {
+		dev_err(dev, "failed to set pcie regulators\n");
+		goto err_set_pcie;
+	}
+
 	INIT_LIST_HEAD(&pcie->resources);
 
 	rcar_pcie_parse_request_of_pci_ranges(pcie);
@@ -1267,6 +1320,7 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_disable:
 	pm_runtime_disable(dev);
+err_set_pcie:
 	return err;
 }
 
-- 
2.13.0