net: ethernet: stmmac: dwmac-rk: Add rv1108 gmac support
authorDavid Wu <david.wu@rock-chips.com>
Mon, 21 Aug 2017 10:12:55 +0000 (18:12 +0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 22 Aug 2017 17:30:58 +0000 (10:30 -0700)
It only supports rmii interface. Add constants and callback functions
for the dwmac on rv1108 socs. As can be seen, the base structure is
the same, only registers and the bits in them moved slightly.

Signed-off-by: David Wu <david.wu@rock-chips.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Documentation/devicetree/bindings/net/rockchip-dwmac.txt
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c

index 8f427550720a3ecce2ca4bac3a164f764cc445f4..c1325387632cb31555be0c81bae915a7e2fbad46 100644 (file)
@@ -10,6 +10,7 @@ Required properties:
    "rockchip,rk3366-gmac": found on RK3366 SoCs
    "rockchip,rk3368-gmac": found on RK3368 SoCs
    "rockchip,rk3399-gmac": found on RK3399 SoCs
+   "rockchip,rv1108-gmac": found on RV1108 SoCs
  - reg: addresses and length of the register sets for the device.
  - interrupts: Should contain the GMAC interrupts.
  - interrupt-names: Should contain the interrupt names "macirq".
index 2176403c72d821f878d3f9bd310236982719d5d1..99823f54696a1887ba4ef5f36e5863b12806bc8f 100644 (file)
@@ -787,6 +787,58 @@ static const struct rk_gmac_ops rk3399_ops = {
        .set_rmii_speed = rk3399_set_rmii_speed,
 };
 
+#define RV1108_GRF_GMAC_CON0           0X0900
+
+/* RV1108_GRF_GMAC_CON0 */
+#define RV1108_GMAC_PHY_INTF_SEL_RMII  (GRF_CLR_BIT(4) | GRF_CLR_BIT(5) | \
+                                       GRF_BIT(6))
+#define RV1108_GMAC_FLOW_CTRL          GRF_BIT(3)
+#define RV1108_GMAC_FLOW_CTRL_CLR      GRF_CLR_BIT(3)
+#define RV1108_GMAC_SPEED_10M          GRF_CLR_BIT(2)
+#define RV1108_GMAC_SPEED_100M         GRF_BIT(2)
+#define RV1108_GMAC_RMII_CLK_25M       GRF_BIT(7)
+#define RV1108_GMAC_RMII_CLK_2_5M      GRF_CLR_BIT(7)
+
+static void rv1108_set_to_rmii(struct rk_priv_data *bsp_priv)
+{
+       struct device *dev = &bsp_priv->pdev->dev;
+
+       if (IS_ERR(bsp_priv->grf)) {
+               dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
+               return;
+       }
+
+       regmap_write(bsp_priv->grf, RV1108_GRF_GMAC_CON0,
+                    RV1108_GMAC_PHY_INTF_SEL_RMII);
+}
+
+static void rv1108_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
+{
+       struct device *dev = &bsp_priv->pdev->dev;
+
+       if (IS_ERR(bsp_priv->grf)) {
+               dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
+               return;
+       }
+
+       if (speed == 10) {
+               regmap_write(bsp_priv->grf, RV1108_GRF_GMAC_CON0,
+                            RV1108_GMAC_RMII_CLK_2_5M |
+                            RV1108_GMAC_SPEED_10M);
+       } else if (speed == 100) {
+               regmap_write(bsp_priv->grf, RV1108_GRF_GMAC_CON0,
+                            RV1108_GMAC_RMII_CLK_25M |
+                            RV1108_GMAC_SPEED_100M);
+       } else {
+               dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
+       }
+}
+
+static const struct rk_gmac_ops rv1108_ops = {
+       .set_to_rmii = rv1108_set_to_rmii,
+       .set_rmii_speed = rv1108_set_rmii_speed,
+};
+
 #define RK_GRF_MACPHY_CON0             0xb00
 #define RK_GRF_MACPHY_CON1             0xb04
 #define RK_GRF_MACPHY_CON2             0xb08
@@ -1267,6 +1319,7 @@ static const struct of_device_id rk_gmac_dwmac_match[] = {
        { .compatible = "rockchip,rk3366-gmac", .data = &rk3366_ops },
        { .compatible = "rockchip,rk3368-gmac", .data = &rk3368_ops },
        { .compatible = "rockchip,rk3399-gmac", .data = &rk3399_ops },
+       { .compatible = "rockchip,rv1108-gmac", .data = &rv1108_ops },
        { }
 };
 MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match);