7e4c6ae6aa1b40e92217acbb919b8245fa7c9ea6
[openwrt/staging/lynxis.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,18 +49,11 @@ static int pfe_get_gemac_if_proprties(st
37 pdata->ls1012a_eth_pdata[port].gem_id = port;
38
39 mac_addr = of_get_mac_address(gem);
40 -
41 if (mac_addr) {
42 memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
43 ETH_ALEN);
44 }
45
46 - pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
47 -
48 - if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
49 - pr_err("%s:%d Incorrect Phy mode....\n", __func__,
50 - __LINE__);
51 -
52 addr = of_get_property(gem, "fsl,gemac-bus-id", &size);
53 if (!addr)
54 pr_err("%s:%d Invalid gemac-bus-id....\n", __func__,
55 @@ -68,16 +61,55 @@ static int pfe_get_gemac_if_proprties(st
56 else
57 pdata->ls1012a_eth_pdata[port].bus_id = be32_to_cpup(addr);
58
59 - addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
60 - if (!addr) {
61 - pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
62 - __LINE__);
63 + phy_node = of_parse_phandle(gem, "phy-handle", 0);
64 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
65 + if (phy_node) {
66 + goto process_phynode;
67 + } else if (of_phy_is_fixed_link(gem)) {
68 + if (of_phy_register_fixed_link(gem) < 0) {
69 + pr_err("broken fixed-link specification\n");
70 + goto err;
71 + }
72 + phy_node = of_node_get(gem);
73 + pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
74 + } else if (of_get_property(gem, "fsl,pfe-phy-if-flags", &size)) {
75 + /* Use old dts properties for phy handling */
76 + addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
77 + pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
78 +
79 + addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
80 + if (!addr) {
81 + pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
82 + __LINE__);
83 + } else {
84 + phy_id = be32_to_cpup(addr);
85 + pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
86 + pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
87 + }
88 +
89 + /* If PHY is enabled, read mdio properties */
90 + if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
91 + goto done;
92 +
93 + phy = of_get_next_child(gem, NULL);
94 + addr = of_get_property(phy, "reg", &size);
95 + if (!addr)
96 + pr_err("%s:%d Invalid phy enable flag....\n",
97 + __func__, __LINE__);
98 + else
99 + pdata->ls1012a_mdio_pdata[port].enabled =
100 + be32_to_cpup(addr);
101 } else {
102 - phy_id = be32_to_cpup(addr);
103 - pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
104 - pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
105 + pr_info("%s: No PHY or fixed-link\n", __func__);
106 + return 0;
107 }
108
109 +process_phynode:
110 + pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
111 + if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
112 + pr_err("%s:%d Incorrect Phy mode....\n", __func__,
113 + __LINE__);
114 +
115 addr = of_get_property(gem, "fsl,mdio-mux-val", &size);
116 if (!addr) {
117 pr_err("%s: Invalid mdio-mux-val....\n", __func__);
118 @@ -90,33 +122,10 @@ static int pfe_get_gemac_if_proprties(st
119 pfe->mdio_muxval[pdata->ls1012a_eth_pdata[port].phy_id] =
120 pdata->ls1012a_eth_pdata[port].mdio_muxval;
121
122 - addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
123 - if (!addr)
124 - pr_err("%s:%d Invalid pfe-phy-if-flags....\n",
125 - __func__, __LINE__);
126 - else
127 - pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
128 -
129 - /* If PHY is enabled, read mdio properties */
130 - if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
131 - goto done;
132 -
133 - phy = of_get_next_child(gem, NULL);
134 -
135 - addr = of_get_property(phy, "reg", &size);
136 -
137 - if (!addr)
138 - pr_err("%s:%d Invalid phy enable flag....\n",
139 - __func__, __LINE__);
140 - else
141 - pdata->ls1012a_mdio_pdata[port].enabled = be32_to_cpup(addr);
142
143 pdata->ls1012a_mdio_pdata[port].irq[0] = PHY_POLL;
144
145 done:
146 - if (of_phy_is_fixed_link(gem))
147 - pdata->ls1012a_eth_pdata[port].phy_node = of_node_get(gem);
148 -
149 return 0;
150
151 err:
152 @@ -218,8 +227,8 @@ static int pfe_platform_probe(struct pla
153 pfe_platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
154
155 for (ii = 0; ii < interface_count; ii++) {
156 - pfe_get_gemac_if_proprties(np, ii, interface_count,
157 - &pfe_platform_data);
158 + pfe_get_gemac_if_properties(np, ii, interface_count,
159 + &pfe_platform_data);
160 }
161
162 pfe->dev = &pdev->dev;