OSDN Git Service

net: dsa: sja1105: skip CGU configuration if it's unnecessary
authorVladimir Oltean <vladimir.oltean@nxp.com>
Mon, 24 May 2021 13:14:17 +0000 (16:14 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 24 May 2021 20:59:03 +0000 (13:59 -0700)
There are two distinct code paths which enter sja1105_clocking.c, one
through sja1105_clocking_setup() and the other through
sja1105_clocking_setup_port():

sja1105_static_config_reload      sja1105_setup
              |                         |
              |      +------------------+
              |      |
              v      v
   sja1105_clocking_setup               sja1105_adjust_port_config
                 |                                   |
                 v                                   |
      sja1105_clocking_setup_port <------------------+

As opposed to SJA1105, the SJA1110 does not need any configuration of
the Clock Generation Unit in order for xMII ports to work. Just RGMII
internal delays need to be configured, and that is done inside
sja1105_clocking_setup_port for the RGMII ports.

So this patch introduces the concept of a "reserved address", which the
CGU configuration functions from sja1105_clocking.c must check before
proceeding to do anything. The SJA1110 will have reserved addresses for
the CGU PLLs for MII/RMII/RGMII.

Additionally, make sja1105_clocking_setup() a function pointer so it can
be overridden by the SJA1110. Even though nothing port-related needs to
be done in the CGU, there are some operations such as disabling the
watchdog clock which are unique to the SJA1110.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/sja1105/sja1105.h
drivers/net/dsa/sja1105/sja1105_clocking.c
drivers/net/dsa/sja1105/sja1105_main.c
drivers/net/dsa/sja1105/sja1105_spi.c
drivers/net/dsa/sja1105/sja1105_static_config.h

index 3737a3b..47cad24 100644 (file)
@@ -109,6 +109,7 @@ struct sja1105_info {
                           const unsigned char *addr, u16 vid);
        void (*ptp_cmd_packing)(u8 *buf, struct sja1105_ptp_cmd *cmd,
                                enum packing_op op);
+       int (*clocking_setup)(struct sja1105_private *priv);
        const char *name;
 };
 
index f54b4d0..4697ac0 100644 (file)
@@ -110,6 +110,9 @@ static int sja1105_cgu_idiv_config(struct sja1105_private *priv, int port,
        struct sja1105_cgu_idiv idiv;
        u8 packed_buf[SJA1105_SIZE_CGU_CMD] = {0};
 
+       if (regs->cgu_idiv[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        if (enabled && factor != 1 && factor != 10) {
                dev_err(dev, "idiv factor must be 1 or 10\n");
                return -ERANGE;
@@ -159,6 +162,9 @@ static int sja1105_cgu_mii_tx_clk_config(struct sja1105_private *priv,
        u8 packed_buf[SJA1105_SIZE_CGU_CMD] = {0};
        int clksrc;
 
+       if (regs->mii_tx_clk[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        if (role == XMII_MAC)
                clksrc = mac_clk_sources[port];
        else
@@ -188,6 +194,9 @@ sja1105_cgu_mii_rx_clk_config(struct sja1105_private *priv, int port)
                CLKSRC_MII4_RX_CLK,
        };
 
+       if (regs->mii_rx_clk[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        /* Payload for packed_buf */
        mii_rx_clk.clksrc    = clk_sources[port];
        mii_rx_clk.autoblock = 1;  /* Autoblock clk while changing clksrc */
@@ -212,6 +221,9 @@ sja1105_cgu_mii_ext_tx_clk_config(struct sja1105_private *priv, int port)
                CLKSRC_IDIV4,
        };
 
+       if (regs->mii_ext_tx_clk[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        /* Payload for packed_buf */
        mii_ext_tx_clk.clksrc    = clk_sources[port];
        mii_ext_tx_clk.autoblock = 1; /* Autoblock clk while changing clksrc */
@@ -236,6 +248,9 @@ sja1105_cgu_mii_ext_rx_clk_config(struct sja1105_private *priv, int port)
                CLKSRC_IDIV4,
        };
 
+       if (regs->mii_ext_rx_clk[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        /* Payload for packed_buf */
        mii_ext_rx_clk.clksrc    = clk_sources[port];
        mii_ext_rx_clk.autoblock = 1; /* Autoblock clk while changing clksrc */
@@ -320,6 +335,9 @@ static int sja1105_cgu_rgmii_tx_clk_config(struct sja1105_private *priv,
        u8 packed_buf[SJA1105_SIZE_CGU_CMD] = {0};
        int clksrc;
 
+       if (regs->rgmii_tx_clk[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        if (speed == SJA1105_SPEED_1000MBPS) {
                clksrc = CLKSRC_PLL0;
        } else {
@@ -368,6 +386,9 @@ static int sja1105_rgmii_cfg_pad_tx_config(struct sja1105_private *priv,
        struct sja1105_cfg_pad_mii pad_mii_tx = {0};
        u8 packed_buf[SJA1105_SIZE_CGU_CMD] = {0};
 
+       if (regs->pad_mii_tx[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        /* Payload */
        pad_mii_tx.d32_os    = 3; /* TXD[3:2] output stage: */
                                  /*          high noise/high speed */
@@ -394,6 +415,9 @@ static int sja1105_cfg_pad_rx_config(struct sja1105_private *priv, int port)
        struct sja1105_cfg_pad_mii pad_mii_rx = {0};
        u8 packed_buf[SJA1105_SIZE_CGU_CMD] = {0};
 
+       if (regs->pad_mii_rx[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        /* Payload */
        pad_mii_rx.d32_ih    = 0; /* RXD[3:2] input stage hysteresis: */
                                  /*          non-Schmitt (default) */
@@ -572,6 +596,9 @@ static int sja1105_cgu_rmii_ref_clk_config(struct sja1105_private *priv,
                CLKSRC_MII4_TX_CLK,
        };
 
+       if (regs->rmii_ref_clk[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        /* Payload for packed_buf */
        ref_clk.clksrc    = clk_sources[port];
        ref_clk.autoblock = 1;      /* Autoblock clk while changing clksrc */
@@ -589,6 +616,9 @@ sja1105_cgu_rmii_ext_tx_clk_config(struct sja1105_private *priv, int port)
        struct sja1105_cgu_mii_ctrl ext_tx_clk;
        u8 packed_buf[SJA1105_SIZE_CGU_CMD] = {0};
 
+       if (regs->rmii_ext_tx_clk[port] == SJA1105_RSV_ADDR)
+               return 0;
+
        /* Payload for packed_buf */
        ext_tx_clk.clksrc    = CLKSRC_PLL1;
        ext_tx_clk.autoblock = 1;   /* Autoblock clk while changing clksrc */
@@ -607,6 +637,9 @@ static int sja1105_cgu_rmii_pll_config(struct sja1105_private *priv)
        struct device *dev = priv->ds->dev;
        int rc;
 
+       if (regs->rmii_pll1 == SJA1105_RSV_ADDR)
+               return 0;
+
        /* PLL1 must be enabled and output 50 Mhz.
         * This is done by writing first 0x0A010941 to
         * the PLL_1_C register and then deasserting
index 409e059..be48e45 100644 (file)
@@ -1936,7 +1936,7 @@ out_unlock_ptp:
         * For these interfaces there is no dynamic configuration
         * needed, since PLLs have same settings at all speeds.
         */
-       rc = sja1105_clocking_setup(priv);
+       rc = priv->info->clocking_setup(priv);
        if (rc < 0)
                goto out;
 
@@ -3015,7 +3015,7 @@ static int sja1105_setup(struct dsa_switch *ds)
                return rc;
        }
        /* Configure the CGU (PHY link modes and speeds) */
-       rc = sja1105_clocking_setup(priv);
+       rc = priv->info->clocking_setup(priv);
        if (rc < 0) {
                dev_err(ds->dev, "Failed to configure MII clocking: %d\n", rc);
                return rc;
index f22340e..c08aa6f 100644 (file)
@@ -489,6 +489,7 @@ const struct sja1105_info sja1105e_info = {
        .fdb_add_cmd            = sja1105et_fdb_add,
        .fdb_del_cmd            = sja1105et_fdb_del,
        .ptp_cmd_packing        = sja1105et_ptp_cmd_packing,
+       .clocking_setup         = sja1105_clocking_setup,
        .regs                   = &sja1105et_regs,
        .name                   = "SJA1105E",
 };
@@ -507,6 +508,7 @@ const struct sja1105_info sja1105t_info = {
        .fdb_add_cmd            = sja1105et_fdb_add,
        .fdb_del_cmd            = sja1105et_fdb_del,
        .ptp_cmd_packing        = sja1105et_ptp_cmd_packing,
+       .clocking_setup         = sja1105_clocking_setup,
        .regs                   = &sja1105et_regs,
        .name                   = "SJA1105T",
 };
@@ -526,6 +528,7 @@ const struct sja1105_info sja1105p_info = {
        .fdb_add_cmd            = sja1105pqrs_fdb_add,
        .fdb_del_cmd            = sja1105pqrs_fdb_del,
        .ptp_cmd_packing        = sja1105pqrs_ptp_cmd_packing,
+       .clocking_setup         = sja1105_clocking_setup,
        .regs                   = &sja1105pqrs_regs,
        .name                   = "SJA1105P",
 };
@@ -545,6 +548,7 @@ const struct sja1105_info sja1105q_info = {
        .fdb_add_cmd            = sja1105pqrs_fdb_add,
        .fdb_del_cmd            = sja1105pqrs_fdb_del,
        .ptp_cmd_packing        = sja1105pqrs_ptp_cmd_packing,
+       .clocking_setup         = sja1105_clocking_setup,
        .regs                   = &sja1105pqrs_regs,
        .name                   = "SJA1105Q",
 };
@@ -564,6 +568,7 @@ const struct sja1105_info sja1105r_info = {
        .fdb_add_cmd            = sja1105pqrs_fdb_add,
        .fdb_del_cmd            = sja1105pqrs_fdb_del,
        .ptp_cmd_packing        = sja1105pqrs_ptp_cmd_packing,
+       .clocking_setup         = sja1105_clocking_setup,
        .regs                   = &sja1105pqrs_regs,
        .name                   = "SJA1105R",
 };
@@ -584,5 +589,6 @@ const struct sja1105_info sja1105s_info = {
        .fdb_add_cmd            = sja1105pqrs_fdb_add,
        .fdb_del_cmd            = sja1105pqrs_fdb_del,
        .ptp_cmd_packing        = sja1105pqrs_ptp_cmd_packing,
+       .clocking_setup         = sja1105_clocking_setup,
        .name                   = "SJA1105S",
 };
index 779eb68..9bc783a 100644 (file)
@@ -129,6 +129,8 @@ enum sja1105_blk_idx {
 #define SJA1105R_PART_NO                               0x9A86
 #define SJA1105S_PART_NO                               0x9A87
 
+#define SJA1105_RSV_ADDR               0xffffffffffffffffull
+
 struct sja1105_schedule_entry {
        u64 winstindex;
        u64 winend;