.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /** |
---|
2 | | - * dwmac-rk.c - Rockchip RK3288 DWMAC specific glue layer |
---|
| 3 | + * DOC: dwmac-rk.c - Rockchip RK3288 DWMAC specific glue layer |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2014 Chen-Zhi (Roger Chen) |
---|
5 | 6 | * |
---|
6 | 7 | * Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, |
---|
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | | - * GNU General Public License for more details. |
---|
17 | 8 | */ |
---|
18 | 9 | |
---|
19 | 10 | #include <linux/stmmac.h> |
---|
.. | .. |
---|
48 | 39 | void (*set_to_qsgmii)(struct rk_priv_data *bsp_priv); |
---|
49 | 40 | void (*set_rgmii_speed)(struct rk_priv_data *bsp_priv, int speed); |
---|
50 | 41 | void (*set_rmii_speed)(struct rk_priv_data *bsp_priv, int speed); |
---|
51 | | - void (*set_sgmii_speed)(struct rk_priv_data *bsp_priv, int speed); |
---|
52 | 42 | void (*set_clock_selection)(struct rk_priv_data *bsp_priv, bool input, |
---|
53 | 43 | bool enable); |
---|
54 | 44 | void (*integrated_phy_power)(struct rk_priv_data *bsp_priv, bool up); |
---|
.. | .. |
---|
56 | 46 | |
---|
57 | 47 | struct rk_priv_data { |
---|
58 | 48 | struct platform_device *pdev; |
---|
59 | | - int phy_iface; |
---|
| 49 | + phy_interface_t phy_iface; |
---|
60 | 50 | int bus_id; |
---|
61 | 51 | struct regulator *regulator; |
---|
62 | 52 | bool suspended; |
---|
.. | .. |
---|
65 | 55 | bool clk_enabled; |
---|
66 | 56 | bool clock_input; |
---|
67 | 57 | bool integrated_phy; |
---|
68 | | - struct phy *comphy; |
---|
69 | 58 | |
---|
70 | 59 | struct clk *clk_mac; |
---|
71 | 60 | struct clk *gmac_clkin; |
---|
.. | .. |
---|
86 | 75 | int rx_delay; |
---|
87 | 76 | |
---|
88 | 77 | struct regmap *grf; |
---|
| 78 | + struct regmap *php_grf; |
---|
89 | 79 | struct regmap *xpcs; |
---|
90 | 80 | |
---|
91 | 81 | unsigned char otp_data; |
---|
| 82 | + unsigned int bgs_increment; |
---|
92 | 83 | }; |
---|
93 | 84 | |
---|
94 | 85 | /* XPCS */ |
---|
.. | .. |
---|
173 | 164 | int ret, i, id = bsp_priv->bus_id; |
---|
174 | 165 | u32 val; |
---|
175 | 166 | |
---|
176 | | - if (mode == PHY_INTERFACE_MODE_QSGMII && !id) |
---|
| 167 | + if (mode == PHY_INTERFACE_MODE_QSGMII && id > 0) |
---|
177 | 168 | return 0; |
---|
178 | 169 | |
---|
179 | | - ret = xpcs_soft_reset(bsp_priv, 0); |
---|
| 170 | + ret = xpcs_soft_reset(bsp_priv, id); |
---|
180 | 171 | if (ret) { |
---|
181 | 172 | dev_err(&bsp_priv->pdev->dev, "xpcs_soft_reset fail %d\n", ret); |
---|
182 | 173 | return ret; |
---|
.. | .. |
---|
203 | 194 | SR_MII_CTRL_AN_ENABLE); |
---|
204 | 195 | } |
---|
205 | 196 | } else { |
---|
206 | | - val = xpcs_read(bsp_priv, SR_MII_OFFSET(0) + VR_MII_DIG_CTRL1); |
---|
207 | | - xpcs_write(bsp_priv, SR_MII_OFFSET(0) + VR_MII_DIG_CTRL1, |
---|
| 197 | + val = xpcs_read(bsp_priv, SR_MII_OFFSET(id) + VR_MII_DIG_CTRL1); |
---|
| 198 | + xpcs_write(bsp_priv, SR_MII_OFFSET(id) + VR_MII_DIG_CTRL1, |
---|
208 | 199 | val | MII_MAC_AUTO_SW); |
---|
209 | | - xpcs_write(bsp_priv, SR_MII_OFFSET(0) + MII_BMCR, |
---|
| 200 | + xpcs_write(bsp_priv, SR_MII_OFFSET(id) + MII_BMCR, |
---|
210 | 201 | SR_MII_CTRL_AN_ENABLE); |
---|
211 | 202 | } |
---|
212 | 203 | |
---|
.. | .. |
---|
223 | 214 | ((((tx) >= 0) ? soc##_GMAC_TXCLK_DLY_ENABLE : soc##_GMAC_TXCLK_DLY_DISABLE) | \ |
---|
224 | 215 | (((rx) >= 0) ? soc##_GMAC_RXCLK_DLY_ENABLE : soc##_GMAC_RXCLK_DLY_DISABLE)) |
---|
225 | 216 | |
---|
| 217 | +#define DELAY_ENABLE_BY_ID(soc, tx, rx, id) \ |
---|
| 218 | + ((((tx) >= 0) ? soc##_GMAC_TXCLK_DLY_ENABLE(id) : soc##_GMAC_TXCLK_DLY_DISABLE(id)) | \ |
---|
| 219 | + (((rx) >= 0) ? soc##_GMAC_RXCLK_DLY_ENABLE(id) : soc##_GMAC_RXCLK_DLY_DISABLE(id))) |
---|
| 220 | + |
---|
226 | 221 | #define DELAY_VALUE(soc, tx, rx) \ |
---|
227 | 222 | ((((tx) >= 0) ? soc##_GMAC_CLK_TX_DL_CFG(tx) : 0) | \ |
---|
228 | 223 | (((rx) >= 0) ? soc##_GMAC_CLK_RX_DL_CFG(rx) : 0)) |
---|
| 224 | + |
---|
| 225 | +#define GMAC_RGMII_CLK_DIV_BY_ID(soc, id, div) \ |
---|
| 226 | + (soc##_GMAC##id##_CLK_RGMII_DIV##div) |
---|
| 227 | + |
---|
| 228 | +#define GMAC_RMII_CLK_DIV_BY_ID(soc, id, div) \ |
---|
| 229 | + (soc##_GMAC##id##_CLK_RMII_DIV##div) |
---|
229 | 230 | |
---|
230 | 231 | /* Integrated EPHY */ |
---|
231 | 232 | |
---|
.. | .. |
---|
268 | 269 | regmap_write(priv->grf, RK_GRF_MACPHY_CON0, RK_MACPHY_DISABLE); |
---|
269 | 270 | if (priv->phy_reset) |
---|
270 | 271 | reset_control_assert(priv->phy_reset); |
---|
| 272 | +} |
---|
| 273 | + |
---|
| 274 | +/* Integrated FEPHY */ |
---|
| 275 | +#define RK_FEPHY_SHUTDOWN GRF_BIT(1) |
---|
| 276 | +#define RK_FEPHY_POWERUP GRF_CLR_BIT(1) |
---|
| 277 | +#define RK_FEPHY_INTERNAL_RMII_SEL GRF_BIT(6) |
---|
| 278 | +#define RK_FEPHY_24M_CLK_SEL (GRF_BIT(8) | GRF_BIT(9)) |
---|
| 279 | +#define RK_FEPHY_PHY_ID GRF_BIT(11) |
---|
| 280 | + |
---|
| 281 | +#define RK_FEPHY_BGS HIWORD_UPDATE(0x0, 0xf, 0) |
---|
| 282 | + |
---|
| 283 | +#define RK_FEPHY_BGS_MAX 7 |
---|
| 284 | + |
---|
| 285 | +static void rk_gmac_integrated_fephy_power(struct rk_priv_data *priv, |
---|
| 286 | + unsigned int ctrl_offset, |
---|
| 287 | + unsigned int bgs_offset, |
---|
| 288 | + bool up) |
---|
| 289 | +{ |
---|
| 290 | + struct device *dev = &priv->pdev->dev; |
---|
| 291 | + |
---|
| 292 | + if (IS_ERR(priv->grf) || !priv->phy_reset) { |
---|
| 293 | + dev_err(dev, "%s: Missing rockchip,grf or phy_reset property\n", |
---|
| 294 | + __func__); |
---|
| 295 | + return; |
---|
| 296 | + } |
---|
| 297 | + |
---|
| 298 | + if (up) { |
---|
| 299 | + unsigned int bgs = priv->otp_data; |
---|
| 300 | + |
---|
| 301 | + reset_control_assert(priv->phy_reset); |
---|
| 302 | + udelay(20); |
---|
| 303 | + regmap_write(priv->grf, ctrl_offset, |
---|
| 304 | + RK_FEPHY_POWERUP | |
---|
| 305 | + RK_FEPHY_INTERNAL_RMII_SEL | |
---|
| 306 | + RK_FEPHY_24M_CLK_SEL | |
---|
| 307 | + RK_FEPHY_PHY_ID); |
---|
| 308 | + |
---|
| 309 | + if (bgs > (RK_FEPHY_BGS_MAX - priv->bgs_increment) && |
---|
| 310 | + bgs <= RK_FEPHY_BGS_MAX) { |
---|
| 311 | + bgs = HIWORD_UPDATE(RK_FEPHY_BGS_MAX, 0xf, 0); |
---|
| 312 | + } else { |
---|
| 313 | + bgs += priv->bgs_increment; |
---|
| 314 | + bgs &= 0xf; |
---|
| 315 | + bgs = HIWORD_UPDATE(bgs, 0xf, 0); |
---|
| 316 | + } |
---|
| 317 | + |
---|
| 318 | + regmap_write(priv->grf, bgs_offset, bgs); |
---|
| 319 | + usleep_range(10 * 1000, 12 * 1000); |
---|
| 320 | + reset_control_deassert(priv->phy_reset); |
---|
| 321 | + usleep_range(50 * 1000, 60 * 1000); |
---|
| 322 | + } else { |
---|
| 323 | + regmap_write(priv->grf, ctrl_offset, |
---|
| 324 | + RK_FEPHY_SHUTDOWN); |
---|
| 325 | + } |
---|
271 | 326 | } |
---|
272 | 327 | |
---|
273 | 328 | #define PX30_GRF_GMAC_CON1 0x0904 |
---|
.. | .. |
---|
688 | 743 | .set_to_rmii = rk3228_set_to_rmii, |
---|
689 | 744 | .set_rgmii_speed = rk3228_set_rgmii_speed, |
---|
690 | 745 | .set_rmii_speed = rk3228_set_rmii_speed, |
---|
691 | | - .integrated_phy_power = rk3228_integrated_phy_power, |
---|
| 746 | + .integrated_phy_power = rk3228_integrated_phy_power, |
---|
692 | 747 | }; |
---|
693 | 748 | |
---|
694 | 749 | #define RK3288_GRF_SOC_CON1 0x0248 |
---|
.. | .. |
---|
993 | 1048 | .set_to_rmii = rk3328_set_to_rmii, |
---|
994 | 1049 | .set_rgmii_speed = rk3328_set_rgmii_speed, |
---|
995 | 1050 | .set_rmii_speed = rk3328_set_rmii_speed, |
---|
996 | | - .integrated_phy_power = rk3328_integrated_phy_power, |
---|
| 1051 | + .integrated_phy_power = rk3328_integrated_phy_power, |
---|
997 | 1052 | }; |
---|
998 | 1053 | |
---|
999 | 1054 | #define RK3366_GRF_SOC_CON6 0x0418 |
---|
.. | .. |
---|
1365 | 1420 | #define RK3528_VO_GRF_MACPHY_CON0 0X6001c |
---|
1366 | 1421 | #define RK3528_VO_GRF_MACPHY_CON1 0X60020 |
---|
1367 | 1422 | |
---|
1368 | | -#define RK3528_VO_GRF_MACPHY_SHUTDOWN GRF_BIT(1) |
---|
1369 | | -#define RK3528_VO_GRF_MACPHY_POWERUP GRF_CLR_BIT(1) |
---|
1370 | | -#define RK3528_VO_GRF_MACPHY_INTERNAL_RMII_SEL GRF_BIT(6) |
---|
1371 | | -#define RK3528_VO_GRF_MACPHY_24M_CLK_SEL (GRF_BIT(8) | GRF_BIT(9)) |
---|
1372 | | -#define RK3528_VO_GRF_MACPHY_PHY_ID GRF_BIT(11) |
---|
1373 | | - |
---|
1374 | | -#define RK3528_VO_GRF_MACPHY_BGS HIWORD_UPDATE(0x0, 0xf, 0) |
---|
1375 | | - |
---|
1376 | 1423 | static void rk3528_set_to_rgmii(struct rk_priv_data *bsp_priv, |
---|
1377 | 1424 | int tx_delay, int rx_delay) |
---|
1378 | 1425 | { |
---|
.. | .. |
---|
1408 | 1455 | RK3528_GMAC1_PHY_INTF_SEL_RMII); |
---|
1409 | 1456 | else |
---|
1410 | 1457 | regmap_write(bsp_priv->grf, RK3528_VO_GRF_GMAC_CON, |
---|
1411 | | - RK3528_GMAC0_PHY_INTF_SEL_RMII); |
---|
| 1458 | + RK3528_GMAC0_PHY_INTF_SEL_RMII | |
---|
| 1459 | + RK3528_GMAC0_CLK_RMII_DIV2); |
---|
1412 | 1460 | } |
---|
1413 | 1461 | |
---|
1414 | 1462 | static void rk3528_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) |
---|
.. | .. |
---|
1482 | 1530 | |
---|
1483 | 1531 | static void rk3528_integrated_sphy_power(struct rk_priv_data *priv, bool up) |
---|
1484 | 1532 | { |
---|
1485 | | - struct device *dev = &priv->pdev->dev; |
---|
1486 | | - unsigned int id = priv->bus_id; |
---|
1487 | | - |
---|
1488 | | - /* Only GMAC0 support integrated phy */ |
---|
1489 | | - if (id > 0) |
---|
1490 | | - return; |
---|
1491 | | - |
---|
1492 | | - if (IS_ERR(priv->grf) || !priv->phy_reset) { |
---|
1493 | | - dev_err(dev, "%s: Missing rockchip,grf or phy_reset property\n", |
---|
1494 | | - __func__); |
---|
1495 | | - return; |
---|
1496 | | - } |
---|
1497 | | - |
---|
1498 | | - if (up) { |
---|
1499 | | - unsigned int bgs = RK3528_VO_GRF_MACPHY_BGS; |
---|
1500 | | - |
---|
1501 | | - reset_control_assert(priv->phy_reset); |
---|
1502 | | - udelay(20); |
---|
1503 | | - regmap_write(priv->grf, RK3528_VO_GRF_MACPHY_CON0, |
---|
1504 | | - RK3528_VO_GRF_MACPHY_POWERUP | |
---|
1505 | | - RK3528_VO_GRF_MACPHY_INTERNAL_RMII_SEL | |
---|
1506 | | - RK3528_VO_GRF_MACPHY_24M_CLK_SEL | |
---|
1507 | | - RK3528_VO_GRF_MACPHY_PHY_ID); |
---|
1508 | | - |
---|
1509 | | - if (priv->otp_data > 0) |
---|
1510 | | - bgs = HIWORD_UPDATE(priv->otp_data, 0xf, 0); |
---|
1511 | | - |
---|
1512 | | - regmap_write(priv->grf, RK3528_VO_GRF_MACPHY_CON1, bgs); |
---|
1513 | | - usleep_range(10 * 1000, 12 * 1000); |
---|
1514 | | - reset_control_deassert(priv->phy_reset); |
---|
1515 | | - usleep_range(50 * 1000, 60 * 1000); |
---|
1516 | | - } else { |
---|
1517 | | - regmap_write(priv->grf, RK3528_VO_GRF_MACPHY_CON0, |
---|
1518 | | - RK3528_VO_GRF_MACPHY_SHUTDOWN); |
---|
1519 | | - } |
---|
| 1533 | + rk_gmac_integrated_fephy_power(priv, RK3528_VO_GRF_MACPHY_CON0, |
---|
| 1534 | + RK3528_VO_GRF_MACPHY_CON1, up); |
---|
1520 | 1535 | } |
---|
1521 | 1536 | |
---|
1522 | 1537 | static const struct rk_gmac_ops rk3528_ops = { |
---|
.. | .. |
---|
1526 | 1541 | .set_rmii_speed = rk3528_set_rmii_speed, |
---|
1527 | 1542 | .set_clock_selection = rk3528_set_clock_selection, |
---|
1528 | 1543 | .integrated_phy_power = rk3528_integrated_sphy_power, |
---|
| 1544 | +}; |
---|
| 1545 | + |
---|
| 1546 | +/* sys_grf */ |
---|
| 1547 | +#define RK3562_GRF_SYS_SOC_CON0 0X0400 |
---|
| 1548 | +#define RK3562_GRF_SYS_SOC_CON1 0X0404 |
---|
| 1549 | + |
---|
| 1550 | +#define RK3562_GMAC0_CLK_RMII_MODE GRF_BIT(5) |
---|
| 1551 | +#define RK3562_GMAC0_CLK_RGMII_MODE GRF_CLR_BIT(5) |
---|
| 1552 | + |
---|
| 1553 | +#define RK3562_GMAC0_CLK_RMII_GATE GRF_BIT(6) |
---|
| 1554 | +#define RK3562_GMAC0_CLK_RMII_NOGATE GRF_CLR_BIT(6) |
---|
| 1555 | + |
---|
| 1556 | +#define RK3562_GMAC0_CLK_RMII_DIV2 GRF_BIT(7) |
---|
| 1557 | +#define RK3562_GMAC0_CLK_RMII_DIV20 GRF_CLR_BIT(7) |
---|
| 1558 | + |
---|
| 1559 | +#define RK3562_GMAC0_CLK_RGMII_DIV1 \ |
---|
| 1560 | + (GRF_CLR_BIT(7) | GRF_CLR_BIT(8)) |
---|
| 1561 | +#define RK3562_GMAC0_CLK_RGMII_DIV5 \ |
---|
| 1562 | + (GRF_BIT(7) | GRF_BIT(8)) |
---|
| 1563 | +#define RK3562_GMAC0_CLK_RGMII_DIV50 \ |
---|
| 1564 | + (GRF_CLR_BIT(7) | GRF_BIT(8)) |
---|
| 1565 | + |
---|
| 1566 | +#define RK3562_GMAC0_CLK_RMII_DIV2 GRF_BIT(7) |
---|
| 1567 | +#define RK3562_GMAC0_CLK_RMII_DIV20 GRF_CLR_BIT(7) |
---|
| 1568 | + |
---|
| 1569 | +#define RK3562_GMAC0_CLK_SELET_CRU GRF_CLR_BIT(9) |
---|
| 1570 | +#define RK3562_GMAC0_CLK_SELET_IO GRF_BIT(9) |
---|
| 1571 | + |
---|
| 1572 | +#define RK3562_GMAC1_CLK_RMII_GATE GRF_BIT(12) |
---|
| 1573 | +#define RK3562_GMAC1_CLK_RMII_NOGATE GRF_CLR_BIT(12) |
---|
| 1574 | + |
---|
| 1575 | +#define RK3562_GMAC1_CLK_RMII_DIV2 GRF_BIT(13) |
---|
| 1576 | +#define RK3562_GMAC1_CLK_RMII_DIV20 GRF_CLR_BIT(13) |
---|
| 1577 | + |
---|
| 1578 | +#define RK3562_GMAC1_RMII_SPEED100 GRF_BIT(11) |
---|
| 1579 | +#define RK3562_GMAC1_RMII_SPEED10 GRF_CLR_BIT(11) |
---|
| 1580 | + |
---|
| 1581 | +#define RK3562_GMAC1_CLK_SELET_CRU GRF_CLR_BIT(15) |
---|
| 1582 | +#define RK3562_GMAC1_CLK_SELET_IO GRF_BIT(15) |
---|
| 1583 | + |
---|
| 1584 | +/* ioc_grf */ |
---|
| 1585 | +#define RK3562_GRF_IOC_GMAC_IOFUNC0_CON0 0X10400 |
---|
| 1586 | +#define RK3562_GRF_IOC_GMAC_IOFUNC0_CON1 0X10404 |
---|
| 1587 | +#define RK3562_GRF_IOC_GMAC_IOFUNC1_CON0 0X00400 |
---|
| 1588 | +#define RK3562_GRF_IOC_GMAC_IOFUNC1_CON1 0X00404 |
---|
| 1589 | + |
---|
| 1590 | +#define RK3562_GMAC_RXCLK_DLY_ENABLE GRF_BIT(1) |
---|
| 1591 | +#define RK3562_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(1) |
---|
| 1592 | +#define RK3562_GMAC_TXCLK_DLY_ENABLE GRF_BIT(0) |
---|
| 1593 | +#define RK3562_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(0) |
---|
| 1594 | + |
---|
| 1595 | +#define RK3562_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0xFF, 8) |
---|
| 1596 | +#define RK3562_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0xFF, 0) |
---|
| 1597 | + |
---|
| 1598 | +#define RK3562_GMAC0_IO_EXTCLK_SELET_CRU GRF_CLR_BIT(2) |
---|
| 1599 | +#define RK3562_GMAC0_IO_EXTCLK_SELET_IO GRF_BIT(2) |
---|
| 1600 | + |
---|
| 1601 | +#define RK3562_GMAC1_IO_EXTCLK_SELET_CRU GRF_CLR_BIT(3) |
---|
| 1602 | +#define RK3562_GMAC1_IO_EXTCLK_SELET_IO GRF_BIT(3) |
---|
| 1603 | + |
---|
| 1604 | +static void rk3562_set_to_rgmii(struct rk_priv_data *bsp_priv, |
---|
| 1605 | + int tx_delay, int rx_delay) |
---|
| 1606 | +{ |
---|
| 1607 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 1608 | + |
---|
| 1609 | + if (IS_ERR(bsp_priv->grf) || IS_ERR(bsp_priv->php_grf)) { |
---|
| 1610 | + dev_err(dev, "Missing rockchip,grf or rockchip,php_grf property\n"); |
---|
| 1611 | + return; |
---|
| 1612 | + } |
---|
| 1613 | + |
---|
| 1614 | + if (bsp_priv->bus_id > 0) |
---|
| 1615 | + return; |
---|
| 1616 | + |
---|
| 1617 | + regmap_write(bsp_priv->grf, RK3562_GRF_SYS_SOC_CON0, |
---|
| 1618 | + RK3562_GMAC0_CLK_RGMII_MODE); |
---|
| 1619 | + |
---|
| 1620 | + regmap_write(bsp_priv->php_grf, RK3562_GRF_IOC_GMAC_IOFUNC0_CON1, |
---|
| 1621 | + DELAY_ENABLE(RK3562, tx_delay, rx_delay)); |
---|
| 1622 | + regmap_write(bsp_priv->php_grf, RK3562_GRF_IOC_GMAC_IOFUNC0_CON0, |
---|
| 1623 | + DELAY_VALUE(RK3562, tx_delay, rx_delay)); |
---|
| 1624 | + |
---|
| 1625 | + regmap_write(bsp_priv->php_grf, RK3562_GRF_IOC_GMAC_IOFUNC1_CON1, |
---|
| 1626 | + DELAY_ENABLE(RK3562, tx_delay, rx_delay)); |
---|
| 1627 | + regmap_write(bsp_priv->php_grf, RK3562_GRF_IOC_GMAC_IOFUNC1_CON0, |
---|
| 1628 | + DELAY_VALUE(RK3562, tx_delay, rx_delay)); |
---|
| 1629 | +} |
---|
| 1630 | + |
---|
| 1631 | +static void rk3562_set_to_rmii(struct rk_priv_data *bsp_priv) |
---|
| 1632 | +{ |
---|
| 1633 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 1634 | + |
---|
| 1635 | + if (IS_ERR(bsp_priv->grf)) { |
---|
| 1636 | + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); |
---|
| 1637 | + return; |
---|
| 1638 | + } |
---|
| 1639 | + |
---|
| 1640 | + if (!bsp_priv->bus_id) |
---|
| 1641 | + regmap_write(bsp_priv->grf, RK3562_GRF_SYS_SOC_CON0, |
---|
| 1642 | + RK3562_GMAC0_CLK_RMII_MODE); |
---|
| 1643 | +} |
---|
| 1644 | + |
---|
| 1645 | +static void rk3562_set_gmac_speed(struct rk_priv_data *bsp_priv, int speed) |
---|
| 1646 | +{ |
---|
| 1647 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 1648 | + unsigned int val = 0, offset, id = bsp_priv->bus_id; |
---|
| 1649 | + |
---|
| 1650 | + switch (speed) { |
---|
| 1651 | + case 10: |
---|
| 1652 | + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) { |
---|
| 1653 | + if (id > 0) { |
---|
| 1654 | + val = GMAC_RMII_CLK_DIV_BY_ID(RK3562, 1, 20); |
---|
| 1655 | + regmap_write(bsp_priv->grf, RK3562_GRF_SYS_SOC_CON0, |
---|
| 1656 | + RK3562_GMAC1_RMII_SPEED10); |
---|
| 1657 | + } else { |
---|
| 1658 | + val = GMAC_RMII_CLK_DIV_BY_ID(RK3562, 0, 20); |
---|
| 1659 | + } |
---|
| 1660 | + } else { |
---|
| 1661 | + val = GMAC_RGMII_CLK_DIV_BY_ID(RK3562, 0, 50); |
---|
| 1662 | + } |
---|
| 1663 | + break; |
---|
| 1664 | + case 100: |
---|
| 1665 | + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) { |
---|
| 1666 | + if (id > 0) { |
---|
| 1667 | + val = GMAC_RMII_CLK_DIV_BY_ID(RK3562, 1, 2); |
---|
| 1668 | + regmap_write(bsp_priv->grf, RK3562_GRF_SYS_SOC_CON0, |
---|
| 1669 | + RK3562_GMAC1_RMII_SPEED100); |
---|
| 1670 | + } else { |
---|
| 1671 | + val = GMAC_RMII_CLK_DIV_BY_ID(RK3562, 0, 2); |
---|
| 1672 | + } |
---|
| 1673 | + } else { |
---|
| 1674 | + val = GMAC_RGMII_CLK_DIV_BY_ID(RK3562, 0, 5); |
---|
| 1675 | + } |
---|
| 1676 | + break; |
---|
| 1677 | + case 1000: |
---|
| 1678 | + if (bsp_priv->phy_iface != PHY_INTERFACE_MODE_RMII) |
---|
| 1679 | + val = GMAC_RGMII_CLK_DIV_BY_ID(RK3562, 0, 1); |
---|
| 1680 | + else |
---|
| 1681 | + goto err; |
---|
| 1682 | + break; |
---|
| 1683 | + default: |
---|
| 1684 | + goto err; |
---|
| 1685 | + } |
---|
| 1686 | + |
---|
| 1687 | + offset = (bsp_priv->bus_id > 0) ? RK3562_GRF_SYS_SOC_CON1 : |
---|
| 1688 | + RK3562_GRF_SYS_SOC_CON0; |
---|
| 1689 | + regmap_write(bsp_priv->grf, offset, val); |
---|
| 1690 | + |
---|
| 1691 | + return; |
---|
| 1692 | +err: |
---|
| 1693 | + dev_err(dev, "unknown speed value for GMAC speed=%d", speed); |
---|
| 1694 | +} |
---|
| 1695 | + |
---|
| 1696 | +static void rk3562_set_clock_selection(struct rk_priv_data *bsp_priv, bool input, |
---|
| 1697 | + bool enable) |
---|
| 1698 | +{ |
---|
| 1699 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 1700 | + unsigned int value; |
---|
| 1701 | + |
---|
| 1702 | + if (IS_ERR(bsp_priv->grf) || IS_ERR(bsp_priv->php_grf)) { |
---|
| 1703 | + dev_err(dev, "Missing rockchip,grf or rockchip,php_grf property\n"); |
---|
| 1704 | + return; |
---|
| 1705 | + } |
---|
| 1706 | + |
---|
| 1707 | + if (!bsp_priv->bus_id) { |
---|
| 1708 | + value = input ? RK3562_GMAC0_CLK_SELET_IO : |
---|
| 1709 | + RK3562_GMAC0_CLK_SELET_CRU; |
---|
| 1710 | + value |= enable ? RK3562_GMAC0_CLK_RMII_NOGATE : |
---|
| 1711 | + RK3562_GMAC0_CLK_RMII_GATE; |
---|
| 1712 | + regmap_write(bsp_priv->grf, RK3562_GRF_SYS_SOC_CON0, value); |
---|
| 1713 | + |
---|
| 1714 | + value = input ? RK3562_GMAC0_IO_EXTCLK_SELET_IO : |
---|
| 1715 | + RK3562_GMAC0_IO_EXTCLK_SELET_CRU; |
---|
| 1716 | + regmap_write(bsp_priv->php_grf, RK3562_GRF_IOC_GMAC_IOFUNC0_CON1, value); |
---|
| 1717 | + regmap_write(bsp_priv->php_grf, RK3562_GRF_IOC_GMAC_IOFUNC1_CON1, value); |
---|
| 1718 | + } else { |
---|
| 1719 | + value = input ? RK3562_GMAC1_CLK_SELET_IO : |
---|
| 1720 | + RK3562_GMAC1_CLK_SELET_CRU; |
---|
| 1721 | + value |= enable ? RK3562_GMAC1_CLK_RMII_NOGATE : |
---|
| 1722 | + RK3562_GMAC1_CLK_RMII_GATE; |
---|
| 1723 | + regmap_write(bsp_priv->grf, RK3562_GRF_SYS_SOC_CON1, value); |
---|
| 1724 | + |
---|
| 1725 | + value = input ? RK3562_GMAC1_IO_EXTCLK_SELET_IO : |
---|
| 1726 | + RK3562_GMAC1_IO_EXTCLK_SELET_CRU; |
---|
| 1727 | + regmap_write(bsp_priv->php_grf, RK3562_GRF_IOC_GMAC_IOFUNC1_CON1, value); |
---|
| 1728 | + } |
---|
| 1729 | +} |
---|
| 1730 | + |
---|
| 1731 | +static const struct rk_gmac_ops rk3562_ops = { |
---|
| 1732 | + .set_to_rgmii = rk3562_set_to_rgmii, |
---|
| 1733 | + .set_to_rmii = rk3562_set_to_rmii, |
---|
| 1734 | + .set_rgmii_speed = rk3562_set_gmac_speed, |
---|
| 1735 | + .set_rmii_speed = rk3562_set_gmac_speed, |
---|
| 1736 | + .set_clock_selection = rk3562_set_clock_selection, |
---|
1529 | 1737 | }; |
---|
1530 | 1738 | |
---|
1531 | 1739 | #define RK3568_GRF_GMAC0_CON0 0X0380 |
---|
.. | .. |
---|
1657 | 1865 | __func__, rate, ret); |
---|
1658 | 1866 | } |
---|
1659 | 1867 | |
---|
1660 | | -static void rk3568_set_gmac_sgmii_speed(struct rk_priv_data *bsp_priv, int speed) |
---|
1661 | | -{ |
---|
1662 | | - struct device *dev = &bsp_priv->pdev->dev; |
---|
1663 | | - unsigned int ctrl; |
---|
1664 | | - |
---|
1665 | | - /* Only gmac1 set the speed for port1 */ |
---|
1666 | | - if (!bsp_priv->bus_id) |
---|
1667 | | - return; |
---|
1668 | | - |
---|
1669 | | - switch (speed) { |
---|
1670 | | - case 10: |
---|
1671 | | - ctrl = BMCR_SPEED10; |
---|
1672 | | - break; |
---|
1673 | | - case 100: |
---|
1674 | | - ctrl = BMCR_SPEED100; |
---|
1675 | | - break; |
---|
1676 | | - case 1000: |
---|
1677 | | - ctrl = BMCR_SPEED1000; |
---|
1678 | | - break; |
---|
1679 | | - default: |
---|
1680 | | - dev_err(dev, "unknown speed value for GMAC speed=%d", speed); |
---|
1681 | | - return; |
---|
1682 | | - } |
---|
1683 | | - |
---|
1684 | | - xpcs_write(bsp_priv, SR_MII_OFFSET(bsp_priv->bus_id) + MII_BMCR, |
---|
1685 | | - ctrl | BMCR_FULLDPLX); |
---|
1686 | | -} |
---|
1687 | | - |
---|
1688 | 1868 | static const struct rk_gmac_ops rk3568_ops = { |
---|
1689 | 1869 | .set_to_rgmii = rk3568_set_to_rgmii, |
---|
1690 | 1870 | .set_to_rmii = rk3568_set_to_rmii, |
---|
.. | .. |
---|
1692 | 1872 | .set_to_qsgmii = rk3568_set_to_qsgmii, |
---|
1693 | 1873 | .set_rgmii_speed = rk3568_set_gmac_speed, |
---|
1694 | 1874 | .set_rmii_speed = rk3568_set_gmac_speed, |
---|
1695 | | - .set_sgmii_speed = rk3568_set_gmac_sgmii_speed, |
---|
| 1875 | +}; |
---|
| 1876 | + |
---|
| 1877 | +/* sys_grf */ |
---|
| 1878 | +#define RK3588_GRF_GMAC_CON7 0X031c |
---|
| 1879 | +#define RK3588_GRF_GMAC_CON8 0X0320 |
---|
| 1880 | +#define RK3588_GRF_GMAC_CON9 0X0324 |
---|
| 1881 | + |
---|
| 1882 | +#define RK3588_GMAC_RXCLK_DLY_ENABLE(id) GRF_BIT(2 * (id) + 3) |
---|
| 1883 | +#define RK3588_GMAC_RXCLK_DLY_DISABLE(id) GRF_CLR_BIT(2 * (id) + 3) |
---|
| 1884 | +#define RK3588_GMAC_TXCLK_DLY_ENABLE(id) GRF_BIT(2 * (id) + 2) |
---|
| 1885 | +#define RK3588_GMAC_TXCLK_DLY_DISABLE(id) GRF_CLR_BIT(2 * (id) + 2) |
---|
| 1886 | + |
---|
| 1887 | +#define RK3588_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0xFF, 8) |
---|
| 1888 | +#define RK3588_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0xFF, 0) |
---|
| 1889 | + |
---|
| 1890 | +/* php_grf */ |
---|
| 1891 | +#define RK3588_GRF_GMAC_CON0 0X0008 |
---|
| 1892 | +#define RK3588_GRF_CLK_CON1 0X0070 |
---|
| 1893 | + |
---|
| 1894 | +#define RK3588_GMAC_PHY_INTF_SEL_RGMII(id) \ |
---|
| 1895 | + (GRF_BIT(3 + (id) * 6) | GRF_CLR_BIT(4 + (id) * 6) | GRF_CLR_BIT(5 + (id) * 6)) |
---|
| 1896 | +#define RK3588_GMAC_PHY_INTF_SEL_RMII(id) \ |
---|
| 1897 | + (GRF_CLR_BIT(3 + (id) * 6) | GRF_CLR_BIT(4 + (id) * 6) | GRF_BIT(5 + (id) * 6)) |
---|
| 1898 | + |
---|
| 1899 | +#define RK3588_GMAC_CLK_RMII_MODE(id) GRF_BIT(5 * (id)) |
---|
| 1900 | +#define RK3588_GMAC_CLK_RGMII_MODE(id) GRF_CLR_BIT(5 * (id)) |
---|
| 1901 | + |
---|
| 1902 | +#define RK3588_GMAC_CLK_SELET_CRU(id) GRF_BIT(5 * (id) + 4) |
---|
| 1903 | +#define RK3588_GMAC_CLK_SELET_IO(id) GRF_CLR_BIT(5 * (id) + 4) |
---|
| 1904 | + |
---|
| 1905 | +#define RK3588_GMA_CLK_RMII_DIV2(id) GRF_BIT(5 * (id) + 2) |
---|
| 1906 | +#define RK3588_GMA_CLK_RMII_DIV20(id) GRF_CLR_BIT(5 * (id) + 2) |
---|
| 1907 | + |
---|
| 1908 | +#define RK3588_GMAC_CLK_RGMII_DIV1(id) \ |
---|
| 1909 | + (GRF_CLR_BIT(5 * (id) + 2) | GRF_CLR_BIT(5 * (id) + 3)) |
---|
| 1910 | +#define RK3588_GMAC_CLK_RGMII_DIV5(id) \ |
---|
| 1911 | + (GRF_BIT(5 * (id) + 2) | GRF_BIT(5 * (id) + 3)) |
---|
| 1912 | +#define RK3588_GMAC_CLK_RGMII_DIV50(id) \ |
---|
| 1913 | + (GRF_CLR_BIT(5 * (id) + 2) | GRF_BIT(5 * (id) + 3)) |
---|
| 1914 | + |
---|
| 1915 | +#define RK3588_GMAC_CLK_RMII_GATE(id) GRF_BIT(5 * (id) + 1) |
---|
| 1916 | +#define RK3588_GMAC_CLK_RMII_NOGATE(id) GRF_CLR_BIT(5 * (id) + 1) |
---|
| 1917 | + |
---|
| 1918 | +static void rk3588_set_to_rgmii(struct rk_priv_data *bsp_priv, |
---|
| 1919 | + int tx_delay, int rx_delay) |
---|
| 1920 | +{ |
---|
| 1921 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 1922 | + u32 offset_con, id = bsp_priv->bus_id; |
---|
| 1923 | + |
---|
| 1924 | + if (IS_ERR(bsp_priv->grf) || IS_ERR(bsp_priv->php_grf)) { |
---|
| 1925 | + dev_err(dev, "Missing rockchip,grf or rockchip,php_grf property\n"); |
---|
| 1926 | + return; |
---|
| 1927 | + } |
---|
| 1928 | + |
---|
| 1929 | + offset_con = bsp_priv->bus_id == 1 ? RK3588_GRF_GMAC_CON9 : |
---|
| 1930 | + RK3588_GRF_GMAC_CON8; |
---|
| 1931 | + |
---|
| 1932 | + regmap_write(bsp_priv->php_grf, RK3588_GRF_GMAC_CON0, |
---|
| 1933 | + RK3588_GMAC_PHY_INTF_SEL_RGMII(id)); |
---|
| 1934 | + |
---|
| 1935 | + regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, |
---|
| 1936 | + RK3588_GMAC_CLK_RGMII_MODE(id)); |
---|
| 1937 | + |
---|
| 1938 | + regmap_write(bsp_priv->grf, RK3588_GRF_GMAC_CON7, |
---|
| 1939 | + DELAY_ENABLE_BY_ID(RK3588, tx_delay, rx_delay, id)); |
---|
| 1940 | + |
---|
| 1941 | + regmap_write(bsp_priv->grf, offset_con, |
---|
| 1942 | + DELAY_VALUE(RK3588, tx_delay, rx_delay)); |
---|
| 1943 | +} |
---|
| 1944 | + |
---|
| 1945 | +static void rk3588_set_to_rmii(struct rk_priv_data *bsp_priv) |
---|
| 1946 | +{ |
---|
| 1947 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 1948 | + |
---|
| 1949 | + if (IS_ERR(bsp_priv->php_grf)) { |
---|
| 1950 | + dev_err(dev, "%s: Missing rockchip,php_grf property\n", __func__); |
---|
| 1951 | + return; |
---|
| 1952 | + } |
---|
| 1953 | + |
---|
| 1954 | + regmap_write(bsp_priv->php_grf, RK3588_GRF_GMAC_CON0, |
---|
| 1955 | + RK3588_GMAC_PHY_INTF_SEL_RMII(bsp_priv->bus_id)); |
---|
| 1956 | + |
---|
| 1957 | + regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, |
---|
| 1958 | + RK3588_GMAC_CLK_RMII_MODE(bsp_priv->bus_id)); |
---|
| 1959 | +} |
---|
| 1960 | + |
---|
| 1961 | +static void rk3588_set_gmac_speed(struct rk_priv_data *bsp_priv, int speed) |
---|
| 1962 | +{ |
---|
| 1963 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 1964 | + unsigned int val = 0, id = bsp_priv->bus_id; |
---|
| 1965 | + |
---|
| 1966 | + switch (speed) { |
---|
| 1967 | + case 10: |
---|
| 1968 | + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) |
---|
| 1969 | + val = RK3588_GMA_CLK_RMII_DIV20(id); |
---|
| 1970 | + else |
---|
| 1971 | + val = RK3588_GMAC_CLK_RGMII_DIV50(id); |
---|
| 1972 | + break; |
---|
| 1973 | + case 100: |
---|
| 1974 | + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) |
---|
| 1975 | + val = RK3588_GMA_CLK_RMII_DIV2(id); |
---|
| 1976 | + else |
---|
| 1977 | + val = RK3588_GMAC_CLK_RGMII_DIV5(id); |
---|
| 1978 | + break; |
---|
| 1979 | + case 1000: |
---|
| 1980 | + if (bsp_priv->phy_iface != PHY_INTERFACE_MODE_RMII) |
---|
| 1981 | + val = RK3588_GMAC_CLK_RGMII_DIV1(id); |
---|
| 1982 | + else |
---|
| 1983 | + goto err; |
---|
| 1984 | + break; |
---|
| 1985 | + default: |
---|
| 1986 | + goto err; |
---|
| 1987 | + } |
---|
| 1988 | + |
---|
| 1989 | + regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, val); |
---|
| 1990 | + |
---|
| 1991 | + return; |
---|
| 1992 | +err: |
---|
| 1993 | + dev_err(dev, "unknown speed value for GMAC speed=%d", speed); |
---|
| 1994 | +} |
---|
| 1995 | + |
---|
| 1996 | +static void rk3588_set_clock_selection(struct rk_priv_data *bsp_priv, bool input, |
---|
| 1997 | + bool enable) |
---|
| 1998 | +{ |
---|
| 1999 | + unsigned int val = input ? RK3588_GMAC_CLK_SELET_IO(bsp_priv->bus_id) : |
---|
| 2000 | + RK3588_GMAC_CLK_SELET_CRU(bsp_priv->bus_id); |
---|
| 2001 | + |
---|
| 2002 | + val |= enable ? RK3588_GMAC_CLK_RMII_NOGATE(bsp_priv->bus_id) : |
---|
| 2003 | + RK3588_GMAC_CLK_RMII_GATE(bsp_priv->bus_id); |
---|
| 2004 | + |
---|
| 2005 | + regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, val); |
---|
| 2006 | +} |
---|
| 2007 | + |
---|
| 2008 | +static const struct rk_gmac_ops rk3588_ops = { |
---|
| 2009 | + .set_to_rgmii = rk3588_set_to_rgmii, |
---|
| 2010 | + .set_to_rmii = rk3588_set_to_rmii, |
---|
| 2011 | + .set_rgmii_speed = rk3588_set_gmac_speed, |
---|
| 2012 | + .set_rmii_speed = rk3588_set_gmac_speed, |
---|
| 2013 | + .set_clock_selection = rk3588_set_clock_selection, |
---|
| 2014 | +}; |
---|
| 2015 | + |
---|
| 2016 | +#define RV1106_VOGRF_GMAC_CLK_CON 0X60004 |
---|
| 2017 | + |
---|
| 2018 | +#define RV1106_VOGRF_MACPHY_RMII_MODE GRF_BIT(0) |
---|
| 2019 | +#define RV1106_VOGRF_GMAC_CLK_RMII_DIV2 GRF_BIT(2) |
---|
| 2020 | +#define RV1106_VOGRF_GMAC_CLK_RMII_DIV20 GRF_CLR_BIT(2) |
---|
| 2021 | + |
---|
| 2022 | +#define RV1106_VOGRF_MACPHY_CON0 0X60028 |
---|
| 2023 | +#define RV1106_VOGRF_MACPHY_CON1 0X6002C |
---|
| 2024 | + |
---|
| 2025 | +static void rv1106_set_to_rmii(struct rk_priv_data *bsp_priv) |
---|
| 2026 | +{ |
---|
| 2027 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 2028 | + |
---|
| 2029 | + if (IS_ERR(bsp_priv->grf)) { |
---|
| 2030 | + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); |
---|
| 2031 | + return; |
---|
| 2032 | + } |
---|
| 2033 | + |
---|
| 2034 | + regmap_write(bsp_priv->grf, RV1106_VOGRF_GMAC_CLK_CON, |
---|
| 2035 | + RV1106_VOGRF_MACPHY_RMII_MODE | |
---|
| 2036 | + RV1106_VOGRF_GMAC_CLK_RMII_DIV2); |
---|
| 2037 | +} |
---|
| 2038 | + |
---|
| 2039 | +static void rv1106_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) |
---|
| 2040 | +{ |
---|
| 2041 | + struct device *dev = &bsp_priv->pdev->dev; |
---|
| 2042 | + unsigned int val = 0; |
---|
| 2043 | + |
---|
| 2044 | + if (IS_ERR(bsp_priv->grf)) { |
---|
| 2045 | + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); |
---|
| 2046 | + return; |
---|
| 2047 | + } |
---|
| 2048 | + |
---|
| 2049 | + if (speed == 10) { |
---|
| 2050 | + val = RV1106_VOGRF_GMAC_CLK_RMII_DIV20; |
---|
| 2051 | + } else if (speed == 100) { |
---|
| 2052 | + val = RV1106_VOGRF_GMAC_CLK_RMII_DIV2; |
---|
| 2053 | + } else { |
---|
| 2054 | + dev_err(dev, "unknown speed value for RMII! speed=%d", speed); |
---|
| 2055 | + return; |
---|
| 2056 | + } |
---|
| 2057 | + |
---|
| 2058 | + regmap_write(bsp_priv->grf, RV1106_VOGRF_GMAC_CLK_CON, val); |
---|
| 2059 | +} |
---|
| 2060 | + |
---|
| 2061 | +static void rv1106_integrated_sphy_power(struct rk_priv_data *priv, bool up) |
---|
| 2062 | +{ |
---|
| 2063 | + rk_gmac_integrated_fephy_power(priv, RV1106_VOGRF_MACPHY_CON0, |
---|
| 2064 | + RV1106_VOGRF_MACPHY_CON1, up); |
---|
| 2065 | +} |
---|
| 2066 | + |
---|
| 2067 | +static const struct rk_gmac_ops rv1106_ops = { |
---|
| 2068 | + .set_to_rmii = rv1106_set_to_rmii, |
---|
| 2069 | + .set_rmii_speed = rv1106_set_rmii_speed, |
---|
| 2070 | + .integrated_phy_power = rv1106_integrated_sphy_power, |
---|
1696 | 2071 | }; |
---|
1697 | 2072 | |
---|
1698 | 2073 | #define RV1108_GRF_GMAC_CON0 0X0900 |
---|
.. | .. |
---|
1989 | 2364 | clk_prepare_enable(bsp_priv->clk_xpcs_eee); |
---|
1990 | 2365 | |
---|
1991 | 2366 | if (bsp_priv->ops && bsp_priv->ops->set_clock_selection) |
---|
1992 | | - bsp_priv->ops->set_clock_selection(bsp_priv, bsp_priv->clock_input, |
---|
1993 | | - true); |
---|
| 2367 | + bsp_priv->ops->set_clock_selection(bsp_priv, |
---|
| 2368 | + bsp_priv->clock_input, true); |
---|
1994 | 2369 | |
---|
1995 | 2370 | /** |
---|
1996 | 2371 | * if (!IS_ERR(bsp_priv->clk_mac)) |
---|
.. | .. |
---|
2002 | 2377 | } else { |
---|
2003 | 2378 | if (bsp_priv->clk_enabled) { |
---|
2004 | 2379 | if (bsp_priv->ops && bsp_priv->ops->set_clock_selection) |
---|
2005 | | - bsp_priv->ops->set_clock_selection(bsp_priv, bsp_priv->clock_input, |
---|
2006 | | - false); |
---|
| 2380 | + bsp_priv->ops->set_clock_selection(bsp_priv, |
---|
| 2381 | + bsp_priv->clock_input, false); |
---|
2007 | 2382 | |
---|
2008 | 2383 | if (phy_iface == PHY_INTERFACE_MODE_RMII) { |
---|
2009 | 2384 | clk_disable_unprepare(bsp_priv->mac_clk_rx); |
---|
.. | .. |
---|
2074 | 2449 | if (!bsp_priv) |
---|
2075 | 2450 | return ERR_PTR(-ENOMEM); |
---|
2076 | 2451 | |
---|
2077 | | - bsp_priv->phy_iface = of_get_phy_mode(dev->of_node); |
---|
| 2452 | + of_get_phy_mode(dev->of_node, &bsp_priv->phy_iface); |
---|
2078 | 2453 | bsp_priv->ops = ops; |
---|
2079 | 2454 | bsp_priv->bus_id = plat->bus_id; |
---|
2080 | 2455 | |
---|
.. | .. |
---|
2125 | 2500 | |
---|
2126 | 2501 | bsp_priv->grf = syscon_regmap_lookup_by_phandle(dev->of_node, |
---|
2127 | 2502 | "rockchip,grf"); |
---|
| 2503 | + bsp_priv->php_grf = syscon_regmap_lookup_by_phandle(dev->of_node, |
---|
| 2504 | + "rockchip,php_grf"); |
---|
2128 | 2505 | bsp_priv->xpcs = syscon_regmap_lookup_by_phandle(dev->of_node, |
---|
2129 | 2506 | "rockchip,xpcs"); |
---|
2130 | 2507 | if (!IS_ERR(bsp_priv->xpcs)) { |
---|
2131 | | - bsp_priv->comphy = devm_of_phy_get(&pdev->dev, dev->of_node, NULL); |
---|
2132 | | - if (IS_ERR(bsp_priv->comphy)) { |
---|
2133 | | - bsp_priv->comphy = NULL; |
---|
| 2508 | + struct phy *comphy; |
---|
| 2509 | + |
---|
| 2510 | + comphy = devm_of_phy_get(&pdev->dev, dev->of_node, NULL); |
---|
| 2511 | + if (IS_ERR(comphy)) |
---|
2134 | 2512 | dev_err(dev, "devm_of_phy_get error\n"); |
---|
2135 | | - } |
---|
| 2513 | + ret = phy_init(comphy); |
---|
| 2514 | + if (ret) |
---|
| 2515 | + dev_err(dev, "phy_init error\n"); |
---|
2136 | 2516 | } |
---|
2137 | 2517 | |
---|
2138 | 2518 | if (plat->phy_node) { |
---|
.. | .. |
---|
2147 | 2527 | if (IS_ERR(bsp_priv->phy_reset)) { |
---|
2148 | 2528 | dev_err(&pdev->dev, "No PHY reset control found.\n"); |
---|
2149 | 2529 | bsp_priv->phy_reset = NULL; |
---|
| 2530 | + } |
---|
| 2531 | + |
---|
| 2532 | + if (of_property_read_u32(plat->phy_node, "bgs,increment", |
---|
| 2533 | + &bsp_priv->bgs_increment)) { |
---|
| 2534 | + bsp_priv->bgs_increment = 0; |
---|
| 2535 | + } else { |
---|
| 2536 | + if (bsp_priv->bgs_increment > RK_FEPHY_BGS_MAX) { |
---|
| 2537 | + dev_err(dev, "%s: error bgs increment: %d\n", |
---|
| 2538 | + __func__, bsp_priv->bgs_increment); |
---|
| 2539 | + bsp_priv->bgs_increment = RK_FEPHY_BGS_MAX; |
---|
| 2540 | + } |
---|
2150 | 2541 | } |
---|
2151 | 2542 | |
---|
2152 | 2543 | /* Read bgs from OTP if it exists */ |
---|
.. | .. |
---|
2217 | 2608 | break; |
---|
2218 | 2609 | case PHY_INTERFACE_MODE_SGMII: |
---|
2219 | 2610 | dev_info(dev, "init for SGMII\n"); |
---|
2220 | | - ret = phy_init(bsp_priv->comphy); |
---|
2221 | | - if (ret) { |
---|
2222 | | - dev_err(dev, "phy_init error: %d\n", ret); |
---|
2223 | | - return ret; |
---|
2224 | | - } |
---|
2225 | | - |
---|
2226 | 2611 | if (bsp_priv->ops && bsp_priv->ops->set_to_sgmii) |
---|
2227 | 2612 | bsp_priv->ops->set_to_sgmii(bsp_priv); |
---|
2228 | 2613 | break; |
---|
2229 | 2614 | case PHY_INTERFACE_MODE_QSGMII: |
---|
2230 | 2615 | dev_info(dev, "init for QSGMII\n"); |
---|
2231 | | - ret = phy_init(bsp_priv->comphy); |
---|
2232 | | - if (ret) { |
---|
2233 | | - dev_err(dev, "phy_init error: %d\n", ret); |
---|
2234 | | - return ret; |
---|
2235 | | - } |
---|
2236 | | - |
---|
2237 | 2616 | if (bsp_priv->ops && bsp_priv->ops->set_to_qsgmii) |
---|
2238 | 2617 | bsp_priv->ops->set_to_qsgmii(bsp_priv); |
---|
2239 | 2618 | break; |
---|
.. | .. |
---|
2247 | 2626 | return ret; |
---|
2248 | 2627 | } |
---|
2249 | 2628 | |
---|
2250 | | - pm_runtime_enable(dev); |
---|
2251 | 2629 | pm_runtime_get_sync(dev); |
---|
2252 | 2630 | |
---|
2253 | 2631 | return 0; |
---|
.. | .. |
---|
2255 | 2633 | |
---|
2256 | 2634 | static void rk_gmac_powerdown(struct rk_priv_data *gmac) |
---|
2257 | 2635 | { |
---|
2258 | | - struct device *dev = &gmac->pdev->dev; |
---|
2259 | | - |
---|
2260 | | - if (gmac->phy_iface == PHY_INTERFACE_MODE_SGMII || |
---|
2261 | | - gmac->phy_iface == PHY_INTERFACE_MODE_QSGMII) |
---|
2262 | | - phy_exit(gmac->comphy); |
---|
2263 | | - |
---|
2264 | | - pm_runtime_put_sync(dev); |
---|
2265 | | - pm_runtime_disable(dev); |
---|
| 2636 | + pm_runtime_put_sync(&gmac->pdev->dev); |
---|
2266 | 2637 | |
---|
2267 | 2638 | rk_gmac_phy_power_on(gmac, false); |
---|
2268 | 2639 | gmac_clk_enable(gmac, false); |
---|
.. | .. |
---|
2286 | 2657 | bsp_priv->ops->set_rmii_speed(bsp_priv, speed); |
---|
2287 | 2658 | break; |
---|
2288 | 2659 | case PHY_INTERFACE_MODE_SGMII: |
---|
2289 | | - if (bsp_priv->ops && bsp_priv->ops->set_sgmii_speed) |
---|
2290 | | - bsp_priv->ops->set_sgmii_speed(bsp_priv, speed); |
---|
2291 | 2660 | case PHY_INTERFACE_MODE_QSGMII: |
---|
2292 | 2661 | break; |
---|
2293 | 2662 | default: |
---|
.. | .. |
---|
2342 | 2711 | } |
---|
2343 | 2712 | EXPORT_SYMBOL(dwmac_rk_get_phy_interface); |
---|
2344 | 2713 | |
---|
2345 | | -void __weak rk_devinfo_get_eth_mac(u8 *mac) |
---|
2346 | | -{ |
---|
2347 | | -} |
---|
2348 | | - |
---|
2349 | | -void rk_get_eth_addr(void *priv, unsigned char *addr) |
---|
| 2714 | +static unsigned char macaddr[6]; |
---|
| 2715 | +extern ssize_t at24_mac_read(unsigned char* addr); |
---|
| 2716 | +static void rk_get_eth_addr(void *priv, unsigned char *addr) |
---|
2350 | 2717 | { |
---|
2351 | 2718 | struct rk_priv_data *bsp_priv = priv; |
---|
2352 | 2719 | struct device *dev = &bsp_priv->pdev->dev; |
---|
2353 | | - unsigned char ethaddr[ETH_ALEN * MAX_ETH] = {0}; |
---|
| 2720 | + //unsigned char ethaddr[ETH_ALEN * MAX_ETH] = {0}; |
---|
2354 | 2721 | int ret, id = bsp_priv->bus_id; |
---|
| 2722 | + //int i; |
---|
2355 | 2723 | |
---|
2356 | | - rk_devinfo_get_eth_mac(addr); |
---|
| 2724 | + printk("hw-debug:enter rk_get_eth_addr.. \n"); |
---|
| 2725 | +#if 0 |
---|
2357 | 2726 | if (is_valid_ether_addr(addr)) |
---|
2358 | 2727 | goto out; |
---|
2359 | 2728 | |
---|
.. | .. |
---|
2383 | 2752 | } else { |
---|
2384 | 2753 | memcpy(addr, ðaddr[id * ETH_ALEN], ETH_ALEN); |
---|
2385 | 2754 | } |
---|
| 2755 | +#endif |
---|
| 2756 | + |
---|
2386 | 2757 | |
---|
| 2758 | + //eeprom |
---|
| 2759 | + ret = at24_mac_read(macaddr); |
---|
| 2760 | + if (ret > 0) |
---|
| 2761 | + { |
---|
| 2762 | + printk("ben %s: at24_mac_read Success!! \n", __func__); |
---|
| 2763 | + memcpy(addr, macaddr, 6); |
---|
| 2764 | + |
---|
| 2765 | + if ((addr[0] == 0x68) && (addr[1] == 0xed)) |
---|
| 2766 | + { |
---|
| 2767 | + printk("at24_eeprom mac is valid \n", __func__); |
---|
| 2768 | + goto out; |
---|
| 2769 | + } |
---|
| 2770 | + else |
---|
| 2771 | + { |
---|
| 2772 | + printk("at24_eeprom mac is invalid \n", __func__); |
---|
| 2773 | + addr[0] = 0x68; |
---|
| 2774 | + addr[1] = 0xed; |
---|
| 2775 | + addr[2] = 0x01; |
---|
| 2776 | + addr[3] = 0x02; |
---|
| 2777 | + addr[4] = 0x03; |
---|
| 2778 | + addr[5] = 0x04; |
---|
| 2779 | + } |
---|
| 2780 | + } |
---|
2387 | 2781 | out: |
---|
2388 | 2782 | dev_err(dev, "%s: mac address: %pM\n", __func__, addr); |
---|
2389 | 2783 | } |
---|
.. | .. |
---|
2412 | 2806 | if (!of_device_is_compatible(pdev->dev.of_node, "snps,dwmac-4.20a")) |
---|
2413 | 2807 | plat_dat->has_gmac = true; |
---|
2414 | 2808 | |
---|
| 2809 | + plat_dat->sph_disable = true; |
---|
2415 | 2810 | plat_dat->fix_mac_speed = rk_fix_speed; |
---|
2416 | 2811 | plat_dat->get_eth_addr = rk_get_eth_addr; |
---|
2417 | 2812 | plat_dat->integrated_phy_power = rk_integrated_phy_power; |
---|
.. | .. |
---|
2524 | 2919 | #ifdef CONFIG_CPU_RK3528 |
---|
2525 | 2920 | { .compatible = "rockchip,rk3528-gmac", .data = &rk3528_ops }, |
---|
2526 | 2921 | #endif |
---|
| 2922 | +#ifdef CONFIG_CPU_RK3562 |
---|
| 2923 | + { .compatible = "rockchip,rk3562-gmac", .data = &rk3562_ops }, |
---|
| 2924 | +#endif |
---|
2527 | 2925 | #ifdef CONFIG_CPU_RK3568 |
---|
2528 | 2926 | { .compatible = "rockchip,rk3568-gmac", .data = &rk3568_ops }, |
---|
2529 | 2927 | #endif |
---|
2530 | | -#ifdef CONFIG_CPU_RV110X |
---|
| 2928 | +#ifdef CONFIG_CPU_RK3588 |
---|
| 2929 | + { .compatible = "rockchip,rk3588-gmac", .data = &rk3588_ops }, |
---|
| 2930 | +#endif |
---|
| 2931 | +#ifdef CONFIG_CPU_RV1106 |
---|
| 2932 | + { .compatible = "rockchip,rv1106-gmac", .data = &rv1106_ops }, |
---|
| 2933 | +#endif |
---|
| 2934 | +#ifdef CONFIG_CPU_RV1108 |
---|
2531 | 2935 | { .compatible = "rockchip,rv1108-gmac", .data = &rv1108_ops }, |
---|
2532 | 2936 | #endif |
---|
2533 | 2937 | #ifdef CONFIG_CPU_RV1126 |
---|
.. | .. |
---|
2546 | 2950 | .of_match_table = rk_gmac_dwmac_match, |
---|
2547 | 2951 | }, |
---|
2548 | 2952 | }; |
---|
2549 | | -module_platform_driver(rk_gmac_dwmac_driver); |
---|
| 2953 | +//module_platform_driver(rk_gmac_dwmac_driver); |
---|
| 2954 | +module_platform_driver1(rk_gmac_dwmac_driver); |
---|
2550 | 2955 | |
---|
2551 | 2956 | MODULE_AUTHOR("Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>"); |
---|
2552 | 2957 | MODULE_DESCRIPTION("Rockchip RK3288 DWMAC specific glue layer"); |
---|