net: mscc: ocelot: filter out ocelot SoC specific PCS config from common path
authorClaudiu Manoil <claudiu.manoil@nxp.com>
Thu, 14 Nov 2019 15:03:21 +0000 (17:03 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 15 Nov 2019 20:32:16 +0000 (12:32 -0800)
The adjust_link routine should be generic enough to be (re)used by
any SoC that integrates a switch core compatible with the Ocelot
core switch driver.  Currently all configurations are generic except
for the PCS settings that are SoC specific.  Move these out to the
Ocelot SoC/board instance.

Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mscc/ocelot.c
drivers/net/ethernet/mscc/ocelot.h
drivers/net/ethernet/mscc/ocelot_board.c
drivers/net/ethernet/mscc/ocelot_regs.c

index 3e7a2796c37d1be138c7c1eef945d9c0b863c627..2b6792ab0eda6fa5c75b33173208d599eb9b9655 100644 (file)
@@ -455,23 +455,8 @@ static void ocelot_adjust_link(struct ocelot *ocelot, int port,
        ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
                           DEV_MAC_HDX_CFG);
 
-       /* Disable HDX fast control */
-       ocelot_port_writel(ocelot_port, DEV_PORT_MISC_HDX_FAST_DIS,
-                          DEV_PORT_MISC);
-
-       /* SGMII only for now */
-       ocelot_port_writel(ocelot_port, PCS1G_MODE_CFG_SGMII_MODE_ENA,
-                          PCS1G_MODE_CFG);
-       ocelot_port_writel(ocelot_port, PCS1G_SD_CFG_SD_SEL, PCS1G_SD_CFG);
-
-       /* Enable PCS */
-       ocelot_port_writel(ocelot_port, PCS1G_CFG_PCS_ENA, PCS1G_CFG);
-
-       /* No aneg on SGMII */
-       ocelot_port_writel(ocelot_port, 0, PCS1G_ANEG_CFG);
-
-       /* No loopback */
-       ocelot_port_writel(ocelot_port, 0, PCS1G_LB_CFG);
+       if (ocelot->ops->pcs_init)
+               ocelot->ops->pcs_init(ocelot, port);
 
        /* Set Max Length and maximum tags allowed */
        ocelot_port_writel(ocelot_port, VLAN_ETH_FRAME_LEN,
index b5802cea7cc47df5914aeec18e8b26c1c484b1d1..7e28434c22c102999ceb0e6358a7ffc554aeb47f 100644 (file)
@@ -435,13 +435,19 @@ enum ocelot_tag_prefix {
 };
 
 struct ocelot_port;
+struct ocelot;
 
 struct ocelot_stat_layout {
        u32 offset;
        char name[ETH_GSTRING_LEN];
 };
 
+struct ocelot_ops {
+       void (*pcs_init)(struct ocelot *ocelot, int port);
+};
+
 struct ocelot {
+       const struct ocelot_ops *ops;
        struct device *dev;
 
        struct regmap *targets[TARGET_MAX];
@@ -553,7 +559,7 @@ struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
 
 int ocelot_init(struct ocelot *ocelot);
 void ocelot_deinit(struct ocelot *ocelot);
-int ocelot_chip_init(struct ocelot *ocelot);
+int ocelot_chip_init(struct ocelot *ocelot, const struct ocelot_ops *ops);
 int ocelot_probe_port(struct ocelot *ocelot, u8 port,
                      void __iomem *regs,
                      struct phy_device *phy);
index ddb34f17fa5234dcdb3df44b6c710a36f47c1d2b..de2da6d33d4333eeb49c2c264a893f3ebe832eec 100644 (file)
@@ -254,6 +254,33 @@ static const struct of_device_id mscc_ocelot_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mscc_ocelot_match);
 
+static void ocelot_port_pcs_init(struct ocelot *ocelot, int port)
+{
+       struct ocelot_port *ocelot_port = ocelot->ports[port];
+
+       /* Disable HDX fast control */
+       ocelot_port_writel(ocelot_port, DEV_PORT_MISC_HDX_FAST_DIS,
+                          DEV_PORT_MISC);
+
+       /* SGMII only for now */
+       ocelot_port_writel(ocelot_port, PCS1G_MODE_CFG_SGMII_MODE_ENA,
+                          PCS1G_MODE_CFG);
+       ocelot_port_writel(ocelot_port, PCS1G_SD_CFG_SD_SEL, PCS1G_SD_CFG);
+
+       /* Enable PCS */
+       ocelot_port_writel(ocelot_port, PCS1G_CFG_PCS_ENA, PCS1G_CFG);
+
+       /* No aneg on SGMII */
+       ocelot_port_writel(ocelot_port, 0, PCS1G_ANEG_CFG);
+
+       /* No loopback */
+       ocelot_port_writel(ocelot_port, 0, PCS1G_LB_CFG);
+}
+
+static const struct ocelot_ops ocelot_ops = {
+       .pcs_init               = ocelot_port_pcs_init,
+};
+
 static int mscc_ocelot_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
@@ -315,7 +342,7 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 
        ocelot->targets[HSIO] = hsio;
 
-       err = ocelot_chip_init(ocelot);
+       err = ocelot_chip_init(ocelot, &ocelot_ops);
        if (err)
                return err;
 
index e59977d204005321a38268764759add03a7aff5b..b88b5899b22736fdc44f4dc7da04453282012d95 100644 (file)
@@ -423,7 +423,7 @@ static void ocelot_pll5_init(struct ocelot *ocelot)
                     HSIO_PLL5G_CFG2_AMPC_SEL(0x10));
 }
 
-int ocelot_chip_init(struct ocelot *ocelot)
+int ocelot_chip_init(struct ocelot *ocelot, const struct ocelot_ops *ops)
 {
        int ret;
 
@@ -431,6 +431,7 @@ int ocelot_chip_init(struct ocelot *ocelot)
        ocelot->stats_layout = ocelot_stats_layout;
        ocelot->num_stats = ARRAY_SIZE(ocelot_stats_layout);
        ocelot->shared_queue_sz = 224 * 1024;
+       ocelot->ops = ops;
 
        ret = ocelot_regfields_init(ocelot, ocelot_regfields);
        if (ret)