8a16edf285d3f1dec3a86be3fa76469bd0af07f9
[openwrt/staging/ynezz.git] /
1 From bb13c3cfaaac3bb50a7f59d0cfa54ff463c2ca86 Mon Sep 17 00:00:00 2001
2 From: Calvin Johnson <calvin.johnson@nxp.com>
3 Date: Tue, 20 Nov 2018 21:50:51 +0530
4 Subject: [PATCH] staging: fsl_ppfe/eth: reorganize platform phy parameters
5
6 - Use "phy-handle" and of_* functions to get phy node and fixed-link
7 parameters
8
9 - Reorganize phy parameters and initialize them only if phy-handle
10 or fixed-link is defined in the dtb.
11
12 - correct typo pfe_get_gemac_if_proprties to pfe_get_gemac_if_properties
13
14 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
15 ---
16 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c | 91 ++++++++++++++-----------
17 1 file changed, 50 insertions(+), 41 deletions(-)
18
19 --- a/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
20 +++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
21 @@ -20,12 +20,12 @@
22
23 struct ls1012a_pfe_platform_data pfe_platform_data;
24
25 -static int pfe_get_gemac_if_proprties(struct device_node *parent, int port, int
26 +static int pfe_get_gemac_if_properties(struct device_node *parent, int port, int
27 if_cnt,
28 struct ls1012a_pfe_platform_data
29 *pdata)
30 {
31 - struct device_node *gem = NULL, *phy = NULL;
32 + struct device_node *gem = NULL, *phy = NULL, *phy_node = NULL;
33 int size;
34 int ii = 0, phy_id = 0;
35 const u32 *addr;
36 @@ -49,12 +49,6 @@ static int pfe_get_gemac_if_proprties(st
37
38 of_get_mac_address(gem, pdata->ls1012a_eth_pdata[port].mac_addr);
39
40 - pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
41 -
42 - if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
43 - pr_err("%s:%d Incorrect Phy mode....\n", __func__,
44 - __LINE__);
45 -
46 addr = of_get_property(gem, "fsl,gemac-bus-id", &size);
47 if (!addr)
48 pr_err("%s:%d Invalid gemac-bus-id....\n", __func__,
49 @@ -62,16 +56,55 @@ static int pfe_get_gemac_if_proprties(st
50 else
51 pdata->ls1012a_eth_pdata[port].bus_id = be32_to_cpup(addr);
52
53 - addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
54 - if (!addr) {
55 - pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
56 - __LINE__);
57 + phy_node = of_parse_phandle(gem, "phy-handle", 0);
58 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
59 + if (phy_node) {
60 + goto process_phynode;
61 + } else if (of_phy_is_fixed_link(gem)) {
62 + if (of_phy_register_fixed_link(gem) < 0) {
63 + pr_err("broken fixed-link specification\n");
64 + goto err;
65 + }
66 + phy_node = of_node_get(gem);
67 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
68 + } else if (of_get_property(gem, "fsl,pfe-phy-if-flags", &size)) {
69 + /* Use old dts properties for phy handling */
70 + addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
71 + pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
72 +
73 + addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
74 + if (!addr) {
75 + pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
76 + __LINE__);
77 + } else {
78 + phy_id = be32_to_cpup(addr);
79 + pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
80 + pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
81 + }
82 +
83 + /* If PHY is enabled, read mdio properties */
84 + if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
85 + goto done;
86 +
87 + phy = of_get_next_child(gem, NULL);
88 + addr = of_get_property(phy, "reg", &size);
89 + if (!addr)
90 + pr_err("%s:%d Invalid phy enable flag....\n",
91 + __func__, __LINE__);
92 + else
93 + pdata->ls1012a_mdio_pdata[port].enabled =
94 + be32_to_cpup(addr);
95 } else {
96 - phy_id = be32_to_cpup(addr);
97 - pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
98 - pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
99 + pr_info("%s: No PHY or fixed-link\n", __func__);
100 + return 0;
101 }
102
103 +process_phynode:
104 + pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
105 + if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
106 + pr_err("%s:%d Incorrect Phy mode....\n", __func__,
107 + __LINE__);
108 +
109 addr = of_get_property(gem, "fsl,mdio-mux-val", &size);
110 if (!addr) {
111 pr_err("%s: Invalid mdio-mux-val....\n", __func__);
112 @@ -84,33 +117,10 @@ static int pfe_get_gemac_if_proprties(st
113 pfe->mdio_muxval[pdata->ls1012a_eth_pdata[port].phy_id] =
114 pdata->ls1012a_eth_pdata[port].mdio_muxval;
115
116 - addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
117 - if (!addr)
118 - pr_err("%s:%d Invalid pfe-phy-if-flags....\n",
119 - __func__, __LINE__);
120 - else
121 - pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
122 -
123 - /* If PHY is enabled, read mdio properties */
124 - if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
125 - goto done;
126 -
127 - phy = of_get_next_child(gem, NULL);
128 -
129 - addr = of_get_property(phy, "reg", &size);
130 -
131 - if (!addr)
132 - pr_err("%s:%d Invalid phy enable flag....\n",
133 - __func__, __LINE__);
134 - else
135 - pdata->ls1012a_mdio_pdata[port].enabled = be32_to_cpup(addr);
136
137 pdata->ls1012a_mdio_pdata[port].irq[0] = PHY_POLL;
138
139 done:
140 - if (of_phy_is_fixed_link(gem))
141 - pdata->ls1012a_eth_pdata[port].phy_node = of_node_get(gem);
142 -
143 return 0;
144
145 err:
146 @@ -212,8 +222,8 @@ static int pfe_platform_probe(struct pla
147 pfe_platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
148
149 for (ii = 0; ii < interface_count; ii++) {
150 - pfe_get_gemac_if_proprties(np, ii, interface_count,
151 - &pfe_platform_data);
152 + pfe_get_gemac_if_properties(np, ii, interface_count,
153 + &pfe_platform_data);
154 }
155
156 pfe->dev = &pdev->dev;