Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 1 | /* Copyright Altera Corporation (C) 2014. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License, version 2, |
| 5 | * as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 | * |
| 15 | * Adopted from dwmac-sti.c |
| 16 | */ |
| 17 | |
| 18 | #include <linux/mfd/syscon.h> |
| 19 | #include <linux/of.h> |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 20 | #include <linux/of_address.h> |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 21 | #include <linux/of_net.h> |
| 22 | #include <linux/phy.h> |
| 23 | #include <linux/regmap.h> |
Vince Bridgers | 2d871aa | 2014-07-28 14:07:58 -0500 | [diff] [blame] | 24 | #include <linux/reset.h> |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 25 | #include <linux/stmmac.h> |
Andy Shevchenko | f10f9fb | 2014-11-07 16:46:42 +0200 | [diff] [blame] | 26 | |
Vince Bridgers | 2d871aa | 2014-07-28 14:07:58 -0500 | [diff] [blame] | 27 | #include "stmmac.h" |
Andy Shevchenko | f10f9fb | 2014-11-07 16:46:42 +0200 | [diff] [blame] | 28 | #include "stmmac_platform.h" |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 29 | |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 30 | #include "altr_tse_pcs.h" |
| 31 | |
| 32 | #define SGMII_ADAPTER_CTRL_REG 0x00 |
| 33 | #define SGMII_ADAPTER_DISABLE 0x0001 |
| 34 | |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 35 | #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0 |
| 36 | #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1 |
| 37 | #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII 0x2 |
| 38 | #define SYSMGR_EMACGRP_CTRL_PHYSEL_WIDTH 2 |
| 39 | #define SYSMGR_EMACGRP_CTRL_PHYSEL_MASK 0x00000003 |
Phil Reid | 4356981 | 2015-12-14 11:32:02 +0800 | [diff] [blame] | 40 | #define SYSMGR_EMACGRP_CTRL_PTP_REF_CLK_MASK 0x00000010 |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 41 | |
Phil Reid | 734e00fa | 2016-04-07 15:55:35 +0800 | [diff] [blame] | 42 | #define SYSMGR_FPGAGRP_MODULE_REG 0x00000028 |
| 43 | #define SYSMGR_FPGAGRP_MODULE_EMAC 0x00000004 |
| 44 | |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 45 | #define EMAC_SPLITTER_CTRL_REG 0x0 |
| 46 | #define EMAC_SPLITTER_CTRL_SPEED_MASK 0x3 |
| 47 | #define EMAC_SPLITTER_CTRL_SPEED_10 0x2 |
| 48 | #define EMAC_SPLITTER_CTRL_SPEED_100 0x3 |
| 49 | #define EMAC_SPLITTER_CTRL_SPEED_1000 0x0 |
| 50 | |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 51 | struct socfpga_dwmac { |
| 52 | int interface; |
| 53 | u32 reg_offset; |
| 54 | u32 reg_shift; |
| 55 | struct device *dev; |
| 56 | struct regmap *sys_mgr_base_addr; |
Joachim Eastwood | 70cb136 | 2016-05-01 22:58:21 +0200 | [diff] [blame] | 57 | struct reset_control *stmmac_rst; |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 58 | void __iomem *splitter_base; |
Phil Reid | 4356981 | 2015-12-14 11:32:02 +0800 | [diff] [blame] | 59 | bool f2h_ptp_ref_clk; |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 60 | struct tse_pcs pcs; |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 63 | static void socfpga_dwmac_fix_mac_speed(void *priv, unsigned int speed) |
| 64 | { |
| 65 | struct socfpga_dwmac *dwmac = (struct socfpga_dwmac *)priv; |
| 66 | void __iomem *splitter_base = dwmac->splitter_base; |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 67 | void __iomem *tse_pcs_base = dwmac->pcs.tse_pcs_base; |
| 68 | void __iomem *sgmii_adapter_base = dwmac->pcs.sgmii_adapter_base; |
| 69 | struct device *dev = dwmac->dev; |
| 70 | struct net_device *ndev = dev_get_drvdata(dev); |
| 71 | struct phy_device *phy_dev = ndev->phydev; |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 72 | u32 val; |
| 73 | |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 74 | if ((tse_pcs_base) && (sgmii_adapter_base)) |
| 75 | writew(SGMII_ADAPTER_DISABLE, |
| 76 | sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 77 | |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 78 | if (splitter_base) { |
| 79 | val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG); |
| 80 | val &= ~EMAC_SPLITTER_CTRL_SPEED_MASK; |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 81 | |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 82 | switch (speed) { |
| 83 | case 1000: |
| 84 | val |= EMAC_SPLITTER_CTRL_SPEED_1000; |
| 85 | break; |
| 86 | case 100: |
| 87 | val |= EMAC_SPLITTER_CTRL_SPEED_100; |
| 88 | break; |
| 89 | case 10: |
| 90 | val |= EMAC_SPLITTER_CTRL_SPEED_10; |
| 91 | break; |
| 92 | default: |
| 93 | return; |
| 94 | } |
| 95 | writel(val, splitter_base + EMAC_SPLITTER_CTRL_REG); |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 96 | } |
| 97 | |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 98 | if (tse_pcs_base && sgmii_adapter_base) |
| 99 | tse_pcs_fix_mac_speed(&dwmac->pcs, phy_dev, speed); |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 100 | } |
| 101 | |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 102 | static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *dev) |
| 103 | { |
| 104 | struct device_node *np = dev->of_node; |
| 105 | struct regmap *sys_mgr_base_addr; |
| 106 | u32 reg_offset, reg_shift; |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 107 | int ret, index; |
| 108 | struct device_node *np_splitter = NULL; |
| 109 | struct device_node *np_sgmii_adapter = NULL; |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 110 | struct resource res_splitter; |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 111 | struct resource res_tse_pcs; |
| 112 | struct resource res_sgmii_adapter; |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 113 | |
| 114 | dwmac->interface = of_get_phy_mode(np); |
| 115 | |
| 116 | sys_mgr_base_addr = syscon_regmap_lookup_by_phandle(np, "altr,sysmgr-syscon"); |
| 117 | if (IS_ERR(sys_mgr_base_addr)) { |
| 118 | dev_info(dev, "No sysmgr-syscon node found\n"); |
| 119 | return PTR_ERR(sys_mgr_base_addr); |
| 120 | } |
| 121 | |
| 122 | ret = of_property_read_u32_index(np, "altr,sysmgr-syscon", 1, ®_offset); |
| 123 | if (ret) { |
| 124 | dev_info(dev, "Could not read reg_offset from sysmgr-syscon!\n"); |
| 125 | return -EINVAL; |
| 126 | } |
| 127 | |
| 128 | ret = of_property_read_u32_index(np, "altr,sysmgr-syscon", 2, ®_shift); |
| 129 | if (ret) { |
| 130 | dev_info(dev, "Could not read reg_shift from sysmgr-syscon!\n"); |
| 131 | return -EINVAL; |
| 132 | } |
| 133 | |
Phil Reid | 4356981 | 2015-12-14 11:32:02 +0800 | [diff] [blame] | 134 | dwmac->f2h_ptp_ref_clk = of_property_read_bool(np, "altr,f2h_ptp_ref_clk"); |
| 135 | |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 136 | np_splitter = of_parse_phandle(np, "altr,emac-splitter", 0); |
| 137 | if (np_splitter) { |
| 138 | if (of_address_to_resource(np_splitter, 0, &res_splitter)) { |
| 139 | dev_info(dev, "Missing emac splitter address\n"); |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
Ley Foon Tan | dace1b5 | 2014-08-28 12:59:46 +0800 | [diff] [blame] | 143 | dwmac->splitter_base = devm_ioremap_resource(dev, &res_splitter); |
Wei Yongjun | f19f916 | 2014-09-12 07:12:57 +0800 | [diff] [blame] | 144 | if (IS_ERR(dwmac->splitter_base)) { |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 145 | dev_info(dev, "Failed to mapping emac splitter\n"); |
Wei Yongjun | f19f916 | 2014-09-12 07:12:57 +0800 | [diff] [blame] | 146 | return PTR_ERR(dwmac->splitter_base); |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 150 | np_sgmii_adapter = of_parse_phandle(np, |
| 151 | "altr,gmii-to-sgmii-converter", 0); |
| 152 | if (np_sgmii_adapter) { |
| 153 | index = of_property_match_string(np_sgmii_adapter, "reg-names", |
| 154 | "hps_emac_interface_splitter_avalon_slave"); |
| 155 | |
| 156 | if (index >= 0) { |
| 157 | if (of_address_to_resource(np_sgmii_adapter, index, |
| 158 | &res_splitter)) { |
| 159 | dev_err(dev, |
| 160 | "%s: ERROR: missing emac splitter address\n", |
| 161 | __func__); |
| 162 | return -EINVAL; |
| 163 | } |
| 164 | |
| 165 | dwmac->splitter_base = |
| 166 | devm_ioremap_resource(dev, &res_splitter); |
| 167 | |
| 168 | if (IS_ERR(dwmac->splitter_base)) { |
| 169 | dev_err(dev, |
| 170 | "%s: ERROR: failed mapping emac splitter\n", |
| 171 | __func__); |
| 172 | return PTR_ERR(dwmac->splitter_base); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | index = of_property_match_string(np_sgmii_adapter, "reg-names", |
| 177 | "gmii_to_sgmii_adapter_avalon_slave"); |
| 178 | |
| 179 | if (index >= 0) { |
| 180 | if (of_address_to_resource(np_sgmii_adapter, index, |
| 181 | &res_sgmii_adapter)) { |
| 182 | dev_err(dev, |
| 183 | "%s: ERROR: failed mapping adapter\n", |
| 184 | __func__); |
| 185 | return -EINVAL; |
| 186 | } |
| 187 | |
| 188 | dwmac->pcs.sgmii_adapter_base = |
| 189 | devm_ioremap_resource(dev, &res_sgmii_adapter); |
| 190 | |
| 191 | if (IS_ERR(dwmac->pcs.sgmii_adapter_base)) { |
| 192 | dev_err(dev, "%s: failed to mapping adapter\n", |
| 193 | __func__); |
| 194 | return PTR_ERR(dwmac->pcs.sgmii_adapter_base); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | index = of_property_match_string(np_sgmii_adapter, "reg-names", |
| 199 | "eth_tse_control_port"); |
| 200 | |
| 201 | if (index >= 0) { |
| 202 | if (of_address_to_resource(np_sgmii_adapter, index, |
| 203 | &res_tse_pcs)) { |
| 204 | dev_err(dev, |
| 205 | "%s: ERROR: failed mapping tse control port\n", |
| 206 | __func__); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | dwmac->pcs.tse_pcs_base = |
| 211 | devm_ioremap_resource(dev, &res_tse_pcs); |
| 212 | |
| 213 | if (IS_ERR(dwmac->pcs.tse_pcs_base)) { |
| 214 | dev_err(dev, |
| 215 | "%s: ERROR: failed mapping tse control port\n", |
| 216 | __func__); |
| 217 | return PTR_ERR(dwmac->pcs.sgmii_adapter_base); |
| 218 | } |
| 219 | } |
| 220 | } |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 221 | dwmac->reg_offset = reg_offset; |
| 222 | dwmac->reg_shift = reg_shift; |
| 223 | dwmac->sys_mgr_base_addr = sys_mgr_base_addr; |
| 224 | dwmac->dev = dev; |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
Joachim Eastwood | 0f400a8 | 2016-05-01 22:58:23 +0200 | [diff] [blame] | 229 | static int socfpga_dwmac_set_phy_mode(struct socfpga_dwmac *dwmac) |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 230 | { |
| 231 | struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr; |
| 232 | int phymode = dwmac->interface; |
| 233 | u32 reg_offset = dwmac->reg_offset; |
| 234 | u32 reg_shift = dwmac->reg_shift; |
Phil Reid | 734e00fa | 2016-04-07 15:55:35 +0800 | [diff] [blame] | 235 | u32 ctrl, val, module; |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 236 | |
| 237 | switch (phymode) { |
| 238 | case PHY_INTERFACE_MODE_RGMII: |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 239 | case PHY_INTERFACE_MODE_RGMII_ID: |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 240 | val = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII; |
| 241 | break; |
| 242 | case PHY_INTERFACE_MODE_MII: |
| 243 | case PHY_INTERFACE_MODE_GMII: |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 244 | case PHY_INTERFACE_MODE_SGMII: |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 245 | val = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII; |
| 246 | break; |
| 247 | default: |
| 248 | dev_err(dwmac->dev, "bad phy mode %d\n", phymode); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | |
Ley Foon Tan | b4834c8 | 2014-08-20 14:33:33 +0800 | [diff] [blame] | 252 | /* Overwrite val to GMII if splitter core is enabled. The phymode here |
| 253 | * is the actual phy mode on phy hardware, but phy interface from |
| 254 | * EMAC core is GMII. |
| 255 | */ |
| 256 | if (dwmac->splitter_base) |
| 257 | val = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII; |
| 258 | |
Joachim Eastwood | 70cb136 | 2016-05-01 22:58:21 +0200 | [diff] [blame] | 259 | /* Assert reset to the enet controller before changing the phy mode */ |
| 260 | if (dwmac->stmmac_rst) |
| 261 | reset_control_assert(dwmac->stmmac_rst); |
| 262 | |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 263 | regmap_read(sys_mgr_base_addr, reg_offset, &ctrl); |
| 264 | ctrl &= ~(SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << reg_shift); |
| 265 | ctrl |= val << reg_shift; |
| 266 | |
Phil Reid | 734e00fa | 2016-04-07 15:55:35 +0800 | [diff] [blame] | 267 | if (dwmac->f2h_ptp_ref_clk) { |
Phil Reid | 4356981 | 2015-12-14 11:32:02 +0800 | [diff] [blame] | 268 | ctrl |= SYSMGR_EMACGRP_CTRL_PTP_REF_CLK_MASK << (reg_shift / 2); |
Phil Reid | 734e00fa | 2016-04-07 15:55:35 +0800 | [diff] [blame] | 269 | regmap_read(sys_mgr_base_addr, SYSMGR_FPGAGRP_MODULE_REG, |
| 270 | &module); |
| 271 | module |= (SYSMGR_FPGAGRP_MODULE_EMAC << (reg_shift / 2)); |
| 272 | regmap_write(sys_mgr_base_addr, SYSMGR_FPGAGRP_MODULE_REG, |
| 273 | module); |
| 274 | } else { |
Phil Reid | 4356981 | 2015-12-14 11:32:02 +0800 | [diff] [blame] | 275 | ctrl &= ~(SYSMGR_EMACGRP_CTRL_PTP_REF_CLK_MASK << (reg_shift / 2)); |
Phil Reid | 734e00fa | 2016-04-07 15:55:35 +0800 | [diff] [blame] | 276 | } |
Phil Reid | 4356981 | 2015-12-14 11:32:02 +0800 | [diff] [blame] | 277 | |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 278 | regmap_write(sys_mgr_base_addr, reg_offset, ctrl); |
Phil Reid | 734e00fa | 2016-04-07 15:55:35 +0800 | [diff] [blame] | 279 | |
Joachim Eastwood | 70cb136 | 2016-05-01 22:58:21 +0200 | [diff] [blame] | 280 | /* Deassert reset for the phy configuration to be sampled by |
| 281 | * the enet controller, and operation to start in requested mode |
| 282 | */ |
| 283 | if (dwmac->stmmac_rst) |
| 284 | reset_control_deassert(dwmac->stmmac_rst); |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 285 | if (phymode == PHY_INTERFACE_MODE_SGMII) { |
| 286 | if (tse_pcs_init(dwmac->pcs.tse_pcs_base, &dwmac->pcs) != 0) { |
| 287 | dev_err(dwmac->dev, "Unable to initialize TSE PCS"); |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | } |
Joachim Eastwood | 70cb136 | 2016-05-01 22:58:21 +0200 | [diff] [blame] | 291 | |
Dinh Nguyen | 801d233 | 2014-03-26 22:45:10 -0500 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 295 | static int socfpga_dwmac_probe(struct platform_device *pdev) |
Joachim Eastwood | 8273278 | 2015-07-29 00:08:51 +0200 | [diff] [blame] | 296 | { |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 297 | struct plat_stmmacenet_data *plat_dat; |
| 298 | struct stmmac_resources stmmac_res; |
Joachim Eastwood | 8273278 | 2015-07-29 00:08:51 +0200 | [diff] [blame] | 299 | struct device *dev = &pdev->dev; |
| 300 | int ret; |
| 301 | struct socfpga_dwmac *dwmac; |
| 302 | |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 303 | ret = stmmac_get_platform_resources(pdev, &stmmac_res); |
| 304 | if (ret) |
| 305 | return ret; |
| 306 | |
| 307 | plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac); |
| 308 | if (IS_ERR(plat_dat)) |
| 309 | return PTR_ERR(plat_dat); |
| 310 | |
Joachim Eastwood | 8273278 | 2015-07-29 00:08:51 +0200 | [diff] [blame] | 311 | dwmac = devm_kzalloc(dev, sizeof(*dwmac), GFP_KERNEL); |
| 312 | if (!dwmac) |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 313 | return -ENOMEM; |
Joachim Eastwood | 8273278 | 2015-07-29 00:08:51 +0200 | [diff] [blame] | 314 | |
| 315 | ret = socfpga_dwmac_parse_data(dwmac, dev); |
| 316 | if (ret) { |
| 317 | dev_err(dev, "Unable to parse OF data\n"); |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 318 | return ret; |
Joachim Eastwood | 8273278 | 2015-07-29 00:08:51 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 321 | plat_dat->bsp_priv = dwmac; |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 322 | plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed; |
| 323 | |
Marek Vasut | 3c201b5 | 2016-04-21 14:11:50 +0200 | [diff] [blame] | 324 | ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); |
Tien Hock Loh | fb3bbdb | 2016-07-07 20:23:30 -0700 | [diff] [blame^] | 325 | |
Joachim Eastwood | 70cb136 | 2016-05-01 22:58:21 +0200 | [diff] [blame] | 326 | if (!ret) { |
| 327 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 328 | struct stmmac_priv *stpriv = netdev_priv(ndev); |
| 329 | |
| 330 | /* The socfpga driver needs to control the stmmac reset to |
| 331 | * set the phy mode. Create a copy of the core reset handel |
| 332 | * so it can be used by the driver later. |
| 333 | */ |
| 334 | dwmac->stmmac_rst = stpriv->stmmac_rst; |
| 335 | |
Joachim Eastwood | 0f400a8 | 2016-05-01 22:58:23 +0200 | [diff] [blame] | 336 | ret = socfpga_dwmac_set_phy_mode(dwmac); |
Joachim Eastwood | 70cb136 | 2016-05-01 22:58:21 +0200 | [diff] [blame] | 337 | } |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 338 | |
Marek Vasut | 3c201b5 | 2016-04-21 14:11:50 +0200 | [diff] [blame] | 339 | return ret; |
Joachim Eastwood | 8273278 | 2015-07-29 00:08:51 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Joachim Eastwood | 56868de | 2016-05-01 22:58:20 +0200 | [diff] [blame] | 342 | #ifdef CONFIG_PM_SLEEP |
| 343 | static int socfpga_dwmac_resume(struct device *dev) |
| 344 | { |
Joachim Eastwood | 56868de | 2016-05-01 22:58:20 +0200 | [diff] [blame] | 345 | struct net_device *ndev = dev_get_drvdata(dev); |
| 346 | struct stmmac_priv *priv = netdev_priv(ndev); |
| 347 | |
Joachim Eastwood | 0f400a8 | 2016-05-01 22:58:23 +0200 | [diff] [blame] | 348 | socfpga_dwmac_set_phy_mode(priv->plat->bsp_priv); |
Joachim Eastwood | 56868de | 2016-05-01 22:58:20 +0200 | [diff] [blame] | 349 | |
Joachim Eastwood | 5373724 | 2016-05-01 22:58:22 +0200 | [diff] [blame] | 350 | /* Before the enet controller is suspended, the phy is suspended. |
| 351 | * This causes the phy clock to be gated. The enet controller is |
| 352 | * resumed before the phy, so the clock is still gated "off" when |
| 353 | * the enet controller is resumed. This code makes sure the phy |
| 354 | * is "resumed" before reinitializing the enet controller since |
| 355 | * the enet controller depends on an active phy clock to complete |
| 356 | * a DMA reset. A DMA reset will "time out" if executed |
| 357 | * with no phy clock input on the Synopsys enet controller. |
| 358 | * Verified through Synopsys Case #8000711656. |
| 359 | * |
| 360 | * Note that the phy clock is also gated when the phy is isolated. |
| 361 | * Phy "suspend" and "isolate" controls are located in phy basic |
| 362 | * control register 0, and can be modified by the phy driver |
| 363 | * framework. |
| 364 | */ |
| 365 | if (priv->phydev) |
| 366 | phy_resume(priv->phydev); |
| 367 | |
Joachim Eastwood | 56868de | 2016-05-01 22:58:20 +0200 | [diff] [blame] | 368 | return stmmac_resume(dev); |
| 369 | } |
| 370 | #endif /* CONFIG_PM_SLEEP */ |
| 371 | |
Joachim Eastwood | bfca2eb | 2016-05-08 13:47:23 +0200 | [diff] [blame] | 372 | static SIMPLE_DEV_PM_OPS(socfpga_dwmac_pm_ops, stmmac_suspend, |
| 373 | socfpga_dwmac_resume); |
Joachim Eastwood | 56868de | 2016-05-01 22:58:20 +0200 | [diff] [blame] | 374 | |
Joachim Eastwood | c7c52ae | 2015-05-14 12:11:03 +0200 | [diff] [blame] | 375 | static const struct of_device_id socfpga_dwmac_match[] = { |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 376 | { .compatible = "altr,socfpga-stmmac" }, |
Joachim Eastwood | c7c52ae | 2015-05-14 12:11:03 +0200 | [diff] [blame] | 377 | { } |
| 378 | }; |
| 379 | MODULE_DEVICE_TABLE(of, socfpga_dwmac_match); |
| 380 | |
| 381 | static struct platform_driver socfpga_dwmac_driver = { |
Joachim Eastwood | 8880b6c | 2015-07-29 00:08:52 +0200 | [diff] [blame] | 382 | .probe = socfpga_dwmac_probe, |
Joachim Eastwood | c7c52ae | 2015-05-14 12:11:03 +0200 | [diff] [blame] | 383 | .remove = stmmac_pltfr_remove, |
| 384 | .driver = { |
| 385 | .name = "socfpga-dwmac", |
Joachim Eastwood | 56868de | 2016-05-01 22:58:20 +0200 | [diff] [blame] | 386 | .pm = &socfpga_dwmac_pm_ops, |
Joachim Eastwood | c7c52ae | 2015-05-14 12:11:03 +0200 | [diff] [blame] | 387 | .of_match_table = socfpga_dwmac_match, |
| 388 | }, |
| 389 | }; |
| 390 | module_platform_driver(socfpga_dwmac_driver); |
| 391 | |
| 392 | MODULE_LICENSE("GPL v2"); |