aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/layerscape/patches-5.4/701-net-0313-staging-fsl_ppfe-eth-reorganize-platform-phy-paramet.patch
blob: 7e4c6ae6aa1b40e92217acbb919b8245fa7c9ea6 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
From bb13c3cfaaac3bb50a7f59d0cfa54ff463c2ca86 Mon Sep 17 00:00:00 2001
From: Calvin Johnson <calvin.johnson@nxp.com>
Date: Tue, 20 Nov 2018 21:50:51 +0530
Subject: [PATCH] staging: fsl_ppfe/eth: reorganize platform phy parameters

- Use "phy-handle" and of_* functions to get phy node and fixed-link
parameters

- Reorganize phy parameters and initialize them only if phy-handle
or fixed-link is defined in the dtb.

- correct typo pfe_get_gemac_if_proprties to pfe_get_gemac_if_properties

Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
---
 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c | 91 ++++++++++++++-----------
 1 file changed, 50 insertions(+), 41 deletions(-)

--- a/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
+++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
@@ -20,12 +20,12 @@
 
 struct ls1012a_pfe_platform_data pfe_platform_data;
 
-static int pfe_get_gemac_if_proprties(struct device_node *parent, int port, int
+static int pfe_get_gemac_if_properties(struct device_node *parent, int port, int
 					if_cnt,
 					struct ls1012a_pfe_platform_data
 					*pdata)
 {
-	struct device_node *gem = NULL, *phy = NULL;
+	struct device_node *gem = NULL, *phy = NULL, *phy_node = NULL;
 	int size;
 	int ii = 0, phy_id = 0;
 	const u32 *addr;
@@ -49,18 +49,11 @@ static int pfe_get_gemac_if_proprties(st
 	pdata->ls1012a_eth_pdata[port].gem_id = port;
 
 	mac_addr = of_get_mac_address(gem);
-
 	if (mac_addr) {
 		memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
 		       ETH_ALEN);
 	}
 
-	pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
-
-	if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
-		pr_err("%s:%d Incorrect Phy mode....\n", __func__,
-		       __LINE__);
-
 	addr = of_get_property(gem, "fsl,gemac-bus-id", &size);
 	if (!addr)
 		pr_err("%s:%d Invalid gemac-bus-id....\n", __func__,
@@ -68,16 +61,55 @@ static int pfe_get_gemac_if_proprties(st
 	else
 		pdata->ls1012a_eth_pdata[port].bus_id = be32_to_cpup(addr);
 
-	addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
-	if (!addr) {
-		pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
-		       __LINE__);
+	phy_node = of_parse_phandle(gem, "phy-handle", 0);
+	pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
+	if (phy_node) {
+		goto process_phynode;
+	} else if (of_phy_is_fixed_link(gem)) {
+		if (of_phy_register_fixed_link(gem) < 0) {
+			pr_err("broken fixed-link specification\n");
+			goto err;
+		}
+		phy_node = of_node_get(gem);
+		pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
+	} else if (of_get_property(gem, "fsl,pfe-phy-if-flags", &size)) {
+		/* Use old dts properties for phy handling */
+		addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
+		pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
+
+		addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
+		if (!addr) {
+			pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
+			       __LINE__);
+		} else {
+			phy_id = be32_to_cpup(addr);
+			pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
+			pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
+		}
+
+		/* If PHY is enabled, read mdio properties */
+		if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
+			goto done;
+
+		phy = of_get_next_child(gem, NULL);
+		addr = of_get_property(phy, "reg", &size);
+		if (!addr)
+			pr_err("%s:%d Invalid phy enable flag....\n",
+			       __func__, __LINE__);
+		else
+			pdata->ls1012a_mdio_pdata[port].enabled =
+							be32_to_cpup(addr);
 	} else {
-		phy_id = be32_to_cpup(addr);
-		pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
-		pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
+		pr_info("%s: No PHY or fixed-link\n", __func__);
+		return 0;
 	}
 
+process_phynode:
+	pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
+	if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
+		pr_err("%s:%d Incorrect Phy mode....\n", __func__,
+		       __LINE__);
+
 	addr = of_get_property(gem, "fsl,mdio-mux-val", &size);
 	if (!addr) {
 		pr_err("%s: Invalid mdio-mux-val....\n", __func__);
@@ -90,33 +122,10 @@ static int pfe_get_gemac_if_proprties(st
 		pfe->mdio_muxval[pdata->ls1012a_eth_pdata[port].phy_id] =
 			 pdata->ls1012a_eth_pdata[port].mdio_muxval;
 
-	addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
-	if (!addr)
-		pr_err("%s:%d Invalid pfe-phy-if-flags....\n",
-		       __func__, __LINE__);
-	else
-		pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
-
-	/* If PHY is enabled, read mdio properties */
-	if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
-		goto done;
-
-	phy = of_get_next_child(gem, NULL);
-
-	addr = of_get_property(phy, "reg", &size);
-
-	if (!addr)
-		pr_err("%s:%d Invalid phy enable flag....\n",
-		       __func__, __LINE__);
-	else
-		pdata->ls1012a_mdio_pdata[port].enabled = be32_to_cpup(addr);
 
 	pdata->ls1012a_mdio_pdata[port].irq[0] = PHY_POLL;
 
 done:
-	if (of_phy_is_fixed_link(gem))
-		pdata->ls1012a_eth_pdata[port].phy_node = of_node_get(gem);
-
 	return 0;
 
 err:
@@ -218,8 +227,8 @@ static int pfe_platform_probe(struct pla
 	pfe_platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
 
 	for (ii = 0; ii < interface_count; ii++) {
-		pfe_get_gemac_if_proprties(np, ii, interface_count,
-					   &pfe_platform_data);
+		pfe_get_gemac_if_properties(np, ii, interface_count,
+					    &pfe_platform_data);
 	}
 
 	pfe->dev = &pdev->dev;