From: khilman@baylibre.com (Kevin Hilman)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH 2/3] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC
Date: Fri, 19 Aug 2016 14:40:00 -0700 [thread overview]
Message-ID: <7hshu0780f.fsf@baylibre.com> (raw)
In-Reply-To: <20160815164100.27766-3-martin.blumenstingl@googlemail.com> (Martin Blumenstingl's message of "Mon, 15 Aug 2016 18:40:59 +0200")
Martin Blumenstingl <martin.blumenstingl@googlemail.com> writes:
> The Ethernet controller available in Meson8b and GXBB SoCs is a Synopsys
> DesignWare MAC IP core which is already supported by the stmmac driver.
>
> In addition to the standard stmmac driver some Meson8b / GXBB specific
> registers have to be configured for the PHY clocks. These SoC specific
> registers are called PRG_ETHERNET_ADDR0 and PRG_ETHERNET_ADDR1 in the
> datasheet.
> These registers are not backwards compatible with those on Meson 6b,
> which is why a new glue driver is introduced. This worked for many
> boards because the bootloader programs the PRG_ETHERNET registers
> correctly. Additionally the meson6-dwmac driver only sets bit 1 of
> PRG_ETHERNET_ADDR0 which (according to the datasheet) is only used
> during reset.
>
> Currently all configuration values can be determined automatically,
> based on the configured phy-mode (which is mandatory for the stmmac
> driver). If required the tx-delay and the mux clock (so it supports
> the MPLL2 clock as well) can be made configurable in the future.
>
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
[...]
> +static int meson8b_init_clk(struct meson8b_dwmac *dwmac)
> +{
> + struct clk_init_data init;
> + int i, ret;
> + struct device *dev = &dwmac->pdev->dev;
> + char clk_name[32];
> + const char *clk_div_parents[1];
> + const char *mux_parent_names[MUX_CLK_NUM_PARENTS];
> + unsigned int mux_parent_count = 0;
> + static struct clk_div_table clk_25m_div_table[] = {
> + { .val = 0, .div = 5 },
> + { .val = 1, .div = 10 },
> + { /* sentinel */ },
> + };
> +
> + /* get the mux parents from DT */
> + for (i = 0; i < MUX_CLK_NUM_PARENTS; i++) {
> + char name[16];
> +
> + snprintf(name, sizeof(name), "clkin%d", i);
> + dwmac->m250_mux_parent[i] = devm_clk_get(dev, name);
> + if (IS_ERR(dwmac->m250_mux_parent[i])) {
> + /* NOTE: the second clock (MP2) is unused on all known
nit: multi-line comment style (c.f. Documentation/CodingStyle search
for "multi-line")
> + * boards, thus we're making it optional here.
> + */
> + if (i > 0)
> + continue;
IMO, this is a bit confusing. I think this should either be coded to
deal with an optional "clkin1" (preferred), or it should be coded to
without a mux and clkin0 is directly the parent of the divider. The
current way of always bailing out of this loop early is a bit confusing.
> + ret = PTR_ERR(dwmac->m250_mux_parent[i]);
> + if (ret != -EPROBE_DEFER)
> + dev_err(dev, "Missing clock %s\n", name);
> + dwmac->m250_mux_parent[i] = NULL;
> + return ret;
> + }
> +
> + mux_parent_names[i] =
> + __clk_get_name(dwmac->m250_mux_parent[i]);
> + mux_parent_count++;
> + }
> +
> + /* create the m250_mux */
> + snprintf(clk_name, sizeof(clk_name), "%s#m250_sel", dev_name(dev));
> + init.name = clk_name;
> + init.ops = &clk_mux_ops;
> + init.flags = CLK_IS_BASIC;
> + init.parent_names = mux_parent_names;
> + init.num_parents = mux_parent_count;
> +
> + dwmac->m250_mux.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
> + dwmac->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
> + dwmac->m250_mux.flags = 0;
> + dwmac->m250_mux.table = NULL;
> + dwmac->m250_mux.hw.init = &init;
> +
> + dwmac->m250_mux_clk = devm_clk_register(dev, &dwmac->m250_mux.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m250_mux_clk)))
> + return PTR_ERR(dwmac->m250_mux_clk);
> +
> + /* create the m250_div */
> + snprintf(clk_name, sizeof(clk_name), "%s#m250_div", dev_name(dev));
> + init.name = devm_kstrdup(dev, clk_name, GFP_KERNEL);
> + init.ops = &clk_divider_ops;
> + init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT;
hmm, with CLK_SET_RATE_PARENT that implies that it might switch the mux,
but it's hard-coded above so the mux only ever has one parent, so that
can never happen.
> + clk_div_parents[0] = __clk_get_name(dwmac->m250_mux_clk);
> + init.parent_names = clk_div_parents;
> + init.num_parents = ARRAY_SIZE(clk_div_parents);
> +
> + dwmac->m250_div.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m250_div.shift = PRG_ETH0_CLK_M250_DIV_SHIFT;
> + dwmac->m250_div.width = PRG_ETH0_CLK_M250_DIV_WIDTH;
> + dwmac->m250_div.hw.init = &init;
> + dwmac->m250_div.flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
> +
> + dwmac->m250_div_clk = devm_clk_register(dev, &dwmac->m250_div.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m250_div_clk)))
> + return PTR_ERR(dwmac->m250_div_clk);
> +
> + /* create the m25_div */
> + snprintf(clk_name, sizeof(clk_name), "%s#m25_div", dev_name(dev));
> + init.name = devm_kstrdup(dev, clk_name, GFP_KERNEL);
> + init.ops = &clk_divider_ops;
> + init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT;
> + clk_div_parents[0] = __clk_get_name(dwmac->m250_div_clk);
> + init.parent_names = clk_div_parents;
> + init.num_parents = ARRAY_SIZE(clk_div_parents);
> +
> + dwmac->m25_div.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m25_div.shift = PRG_ETH0_CLK_M25_DIV_SHIFT;
> + dwmac->m25_div.width = PRG_ETH0_CLK_M25_DIV_WIDTH;
> + dwmac->m25_div.table = clk_25m_div_table;
> + dwmac->m25_div.hw.init = &init;
> + dwmac->m25_div.flags = CLK_DIVIDER_ALLOW_ZERO;
> +
> + dwmac->m25_div_clk = devm_clk_register(dev, &dwmac->m25_div.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m25_div_clk)))
> + return PTR_ERR(dwmac->m25_div_clk);
> +
> + return 0;
> +}
> +
> +static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac)
> +{
> + int ret;
> + unsigned long clk_rate;
> +
> + switch (dwmac->phy_mode) {
> + case PHY_INTERFACE_MODE_RGMII:
> + case PHY_INTERFACE_MODE_RGMII_ID:
> + case PHY_INTERFACE_MODE_RGMII_RXID:
> + case PHY_INTERFACE_MODE_RGMII_TXID:
> + /* Generate a 25MHz clock for the PHY */
> + clk_rate = 25 * 1000 * 1000;
> +
> + /* enable RGMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_RGMII_MODE,
> + PRG_ETH0_RGMII_MODE);
> +
> + /* only relevant for RMII mode -> disable in RGMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0,
> + PRG_ETH0_INVERTED_RMII_CLK, 0);
> +
> + /* TX clock delay - all known boards use a 1/4 cycle delay */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK,
> + PRG_ETH0_TXDLY_QUARTER);
> + break;
> +
> + case PHY_INTERFACE_MODE_RMII:
> + /* Use the rate of the mux clock for the internal RMII PHY */
> + clk_rate = clk_get_rate(dwmac->m250_mux_clk);
> +
> + /* disable RGMII mode -> enables RMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_RGMII_MODE,
> + 0);
> +
> + /* invert internal clk_rmii_i to generate 25/2.5 tx_rx_clk */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0,
> + PRG_ETH0_INVERTED_RMII_CLK,
> + PRG_ETH0_INVERTED_RMII_CLK);
> +
> + /* TX clock delay cannot be configured in RMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK,
> + 0);
> +
> + break;
> +
> + default:
> + dev_err(&dwmac->pdev->dev, "unsupported phy-mode %s\n",
> + phy_modes(dwmac->phy_mode));
> + return -EINVAL;
> + }
> +
> + ret = clk_prepare_enable(dwmac->m25_div_clk);
> + if (ret) {
> + dev_err(&dwmac->pdev->dev, "failed to enable the PHY clock\n");
> + return ret;
> + }
> +
> + ret = clk_set_rate(dwmac->m25_div_clk, clk_rate);
> + if (ret) {
> + clk_disable_unprepare(dwmac->m25_div_clk);
> +
> + dev_err(&dwmac->pdev->dev, "failed to set PHY clock\n");
> + return ret;
> + }
In the case of success, the clock is never disabled/unprepared. You
probably need a .remove function which disables the clock and then calls
stmmac_pltfr_remove.
> + /* enable TX_CLK and PHY_REF_CLK generator */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TX_AND_PHY_REF_CLK,
> + PRG_ETH0_TX_AND_PHY_REF_CLK);
> +
> + return 0;
> +}
[...]
Otherwise, this is looking good.
Also, I tested on meson-gxbb-odroidc2 and meson-gxbb-p200 by booting a debian
root filesystem over NFS and all was well.
Tested-by: Kevin Hilman <khilman@baylibre.com>
Kevin
WARNING: multiple messages have this Message-ID (diff)
From: khilman@baylibre.com (Kevin Hilman)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC
Date: Fri, 19 Aug 2016 14:40:00 -0700 [thread overview]
Message-ID: <7hshu0780f.fsf@baylibre.com> (raw)
In-Reply-To: <20160815164100.27766-3-martin.blumenstingl@googlemail.com> (Martin Blumenstingl's message of "Mon, 15 Aug 2016 18:40:59 +0200")
Martin Blumenstingl <martin.blumenstingl@googlemail.com> writes:
> The Ethernet controller available in Meson8b and GXBB SoCs is a Synopsys
> DesignWare MAC IP core which is already supported by the stmmac driver.
>
> In addition to the standard stmmac driver some Meson8b / GXBB specific
> registers have to be configured for the PHY clocks. These SoC specific
> registers are called PRG_ETHERNET_ADDR0 and PRG_ETHERNET_ADDR1 in the
> datasheet.
> These registers are not backwards compatible with those on Meson 6b,
> which is why a new glue driver is introduced. This worked for many
> boards because the bootloader programs the PRG_ETHERNET registers
> correctly. Additionally the meson6-dwmac driver only sets bit 1 of
> PRG_ETHERNET_ADDR0 which (according to the datasheet) is only used
> during reset.
>
> Currently all configuration values can be determined automatically,
> based on the configured phy-mode (which is mandatory for the stmmac
> driver). If required the tx-delay and the mux clock (so it supports
> the MPLL2 clock as well) can be made configurable in the future.
>
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
[...]
> +static int meson8b_init_clk(struct meson8b_dwmac *dwmac)
> +{
> + struct clk_init_data init;
> + int i, ret;
> + struct device *dev = &dwmac->pdev->dev;
> + char clk_name[32];
> + const char *clk_div_parents[1];
> + const char *mux_parent_names[MUX_CLK_NUM_PARENTS];
> + unsigned int mux_parent_count = 0;
> + static struct clk_div_table clk_25m_div_table[] = {
> + { .val = 0, .div = 5 },
> + { .val = 1, .div = 10 },
> + { /* sentinel */ },
> + };
> +
> + /* get the mux parents from DT */
> + for (i = 0; i < MUX_CLK_NUM_PARENTS; i++) {
> + char name[16];
> +
> + snprintf(name, sizeof(name), "clkin%d", i);
> + dwmac->m250_mux_parent[i] = devm_clk_get(dev, name);
> + if (IS_ERR(dwmac->m250_mux_parent[i])) {
> + /* NOTE: the second clock (MP2) is unused on all known
nit: multi-line comment style (c.f. Documentation/CodingStyle search
for "multi-line")
> + * boards, thus we're making it optional here.
> + */
> + if (i > 0)
> + continue;
IMO, this is a bit confusing. I think this should either be coded to
deal with an optional "clkin1" (preferred), or it should be coded to
without a mux and clkin0 is directly the parent of the divider. The
current way of always bailing out of this loop early is a bit confusing.
> + ret = PTR_ERR(dwmac->m250_mux_parent[i]);
> + if (ret != -EPROBE_DEFER)
> + dev_err(dev, "Missing clock %s\n", name);
> + dwmac->m250_mux_parent[i] = NULL;
> + return ret;
> + }
> +
> + mux_parent_names[i] =
> + __clk_get_name(dwmac->m250_mux_parent[i]);
> + mux_parent_count++;
> + }
> +
> + /* create the m250_mux */
> + snprintf(clk_name, sizeof(clk_name), "%s#m250_sel", dev_name(dev));
> + init.name = clk_name;
> + init.ops = &clk_mux_ops;
> + init.flags = CLK_IS_BASIC;
> + init.parent_names = mux_parent_names;
> + init.num_parents = mux_parent_count;
> +
> + dwmac->m250_mux.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
> + dwmac->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
> + dwmac->m250_mux.flags = 0;
> + dwmac->m250_mux.table = NULL;
> + dwmac->m250_mux.hw.init = &init;
> +
> + dwmac->m250_mux_clk = devm_clk_register(dev, &dwmac->m250_mux.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m250_mux_clk)))
> + return PTR_ERR(dwmac->m250_mux_clk);
> +
> + /* create the m250_div */
> + snprintf(clk_name, sizeof(clk_name), "%s#m250_div", dev_name(dev));
> + init.name = devm_kstrdup(dev, clk_name, GFP_KERNEL);
> + init.ops = &clk_divider_ops;
> + init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT;
hmm, with CLK_SET_RATE_PARENT that implies that it might switch the mux,
but it's hard-coded above so the mux only ever has one parent, so that
can never happen.
> + clk_div_parents[0] = __clk_get_name(dwmac->m250_mux_clk);
> + init.parent_names = clk_div_parents;
> + init.num_parents = ARRAY_SIZE(clk_div_parents);
> +
> + dwmac->m250_div.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m250_div.shift = PRG_ETH0_CLK_M250_DIV_SHIFT;
> + dwmac->m250_div.width = PRG_ETH0_CLK_M250_DIV_WIDTH;
> + dwmac->m250_div.hw.init = &init;
> + dwmac->m250_div.flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
> +
> + dwmac->m250_div_clk = devm_clk_register(dev, &dwmac->m250_div.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m250_div_clk)))
> + return PTR_ERR(dwmac->m250_div_clk);
> +
> + /* create the m25_div */
> + snprintf(clk_name, sizeof(clk_name), "%s#m25_div", dev_name(dev));
> + init.name = devm_kstrdup(dev, clk_name, GFP_KERNEL);
> + init.ops = &clk_divider_ops;
> + init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT;
> + clk_div_parents[0] = __clk_get_name(dwmac->m250_div_clk);
> + init.parent_names = clk_div_parents;
> + init.num_parents = ARRAY_SIZE(clk_div_parents);
> +
> + dwmac->m25_div.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m25_div.shift = PRG_ETH0_CLK_M25_DIV_SHIFT;
> + dwmac->m25_div.width = PRG_ETH0_CLK_M25_DIV_WIDTH;
> + dwmac->m25_div.table = clk_25m_div_table;
> + dwmac->m25_div.hw.init = &init;
> + dwmac->m25_div.flags = CLK_DIVIDER_ALLOW_ZERO;
> +
> + dwmac->m25_div_clk = devm_clk_register(dev, &dwmac->m25_div.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m25_div_clk)))
> + return PTR_ERR(dwmac->m25_div_clk);
> +
> + return 0;
> +}
> +
> +static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac)
> +{
> + int ret;
> + unsigned long clk_rate;
> +
> + switch (dwmac->phy_mode) {
> + case PHY_INTERFACE_MODE_RGMII:
> + case PHY_INTERFACE_MODE_RGMII_ID:
> + case PHY_INTERFACE_MODE_RGMII_RXID:
> + case PHY_INTERFACE_MODE_RGMII_TXID:
> + /* Generate a 25MHz clock for the PHY */
> + clk_rate = 25 * 1000 * 1000;
> +
> + /* enable RGMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_RGMII_MODE,
> + PRG_ETH0_RGMII_MODE);
> +
> + /* only relevant for RMII mode -> disable in RGMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0,
> + PRG_ETH0_INVERTED_RMII_CLK, 0);
> +
> + /* TX clock delay - all known boards use a 1/4 cycle delay */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK,
> + PRG_ETH0_TXDLY_QUARTER);
> + break;
> +
> + case PHY_INTERFACE_MODE_RMII:
> + /* Use the rate of the mux clock for the internal RMII PHY */
> + clk_rate = clk_get_rate(dwmac->m250_mux_clk);
> +
> + /* disable RGMII mode -> enables RMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_RGMII_MODE,
> + 0);
> +
> + /* invert internal clk_rmii_i to generate 25/2.5 tx_rx_clk */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0,
> + PRG_ETH0_INVERTED_RMII_CLK,
> + PRG_ETH0_INVERTED_RMII_CLK);
> +
> + /* TX clock delay cannot be configured in RMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK,
> + 0);
> +
> + break;
> +
> + default:
> + dev_err(&dwmac->pdev->dev, "unsupported phy-mode %s\n",
> + phy_modes(dwmac->phy_mode));
> + return -EINVAL;
> + }
> +
> + ret = clk_prepare_enable(dwmac->m25_div_clk);
> + if (ret) {
> + dev_err(&dwmac->pdev->dev, "failed to enable the PHY clock\n");
> + return ret;
> + }
> +
> + ret = clk_set_rate(dwmac->m25_div_clk, clk_rate);
> + if (ret) {
> + clk_disable_unprepare(dwmac->m25_div_clk);
> +
> + dev_err(&dwmac->pdev->dev, "failed to set PHY clock\n");
> + return ret;
> + }
In the case of success, the clock is never disabled/unprepared. You
probably need a .remove function which disables the clock and then calls
stmmac_pltfr_remove.
> + /* enable TX_CLK and PHY_REF_CLK generator */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TX_AND_PHY_REF_CLK,
> + PRG_ETH0_TX_AND_PHY_REF_CLK);
> +
> + return 0;
> +}
[...]
Otherwise, this is looking good.
Also, I tested on meson-gxbb-odroidc2 and meson-gxbb-p200 by booting a debian
root filesystem over NFS and all was well.
Tested-by: Kevin Hilman <khilman@baylibre.com>
Kevin
WARNING: multiple messages have this Message-ID (diff)
From: Kevin Hilman <khilman@baylibre.com>
To: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: linux-amlogic@lists.infradead.org, carlo@caione.org,
mturquette@baylibre.com, peppe.cavallaro@st.com,
alexandre.torgue@st.com, robh+dt@kernel.org,
mark.rutland@arm.com, catalin.marinas@arm.com,
will.deacon@arm.com, netdev@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 2/3] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC
Date: Fri, 19 Aug 2016 14:40:00 -0700 [thread overview]
Message-ID: <7hshu0780f.fsf@baylibre.com> (raw)
In-Reply-To: <20160815164100.27766-3-martin.blumenstingl@googlemail.com> (Martin Blumenstingl's message of "Mon, 15 Aug 2016 18:40:59 +0200")
Martin Blumenstingl <martin.blumenstingl@googlemail.com> writes:
> The Ethernet controller available in Meson8b and GXBB SoCs is a Synopsys
> DesignWare MAC IP core which is already supported by the stmmac driver.
>
> In addition to the standard stmmac driver some Meson8b / GXBB specific
> registers have to be configured for the PHY clocks. These SoC specific
> registers are called PRG_ETHERNET_ADDR0 and PRG_ETHERNET_ADDR1 in the
> datasheet.
> These registers are not backwards compatible with those on Meson 6b,
> which is why a new glue driver is introduced. This worked for many
> boards because the bootloader programs the PRG_ETHERNET registers
> correctly. Additionally the meson6-dwmac driver only sets bit 1 of
> PRG_ETHERNET_ADDR0 which (according to the datasheet) is only used
> during reset.
>
> Currently all configuration values can be determined automatically,
> based on the configured phy-mode (which is mandatory for the stmmac
> driver). If required the tx-delay and the mux clock (so it supports
> the MPLL2 clock as well) can be made configurable in the future.
>
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
[...]
> +static int meson8b_init_clk(struct meson8b_dwmac *dwmac)
> +{
> + struct clk_init_data init;
> + int i, ret;
> + struct device *dev = &dwmac->pdev->dev;
> + char clk_name[32];
> + const char *clk_div_parents[1];
> + const char *mux_parent_names[MUX_CLK_NUM_PARENTS];
> + unsigned int mux_parent_count = 0;
> + static struct clk_div_table clk_25m_div_table[] = {
> + { .val = 0, .div = 5 },
> + { .val = 1, .div = 10 },
> + { /* sentinel */ },
> + };
> +
> + /* get the mux parents from DT */
> + for (i = 0; i < MUX_CLK_NUM_PARENTS; i++) {
> + char name[16];
> +
> + snprintf(name, sizeof(name), "clkin%d", i);
> + dwmac->m250_mux_parent[i] = devm_clk_get(dev, name);
> + if (IS_ERR(dwmac->m250_mux_parent[i])) {
> + /* NOTE: the second clock (MP2) is unused on all known
nit: multi-line comment style (c.f. Documentation/CodingStyle search
for "multi-line")
> + * boards, thus we're making it optional here.
> + */
> + if (i > 0)
> + continue;
IMO, this is a bit confusing. I think this should either be coded to
deal with an optional "clkin1" (preferred), or it should be coded to
without a mux and clkin0 is directly the parent of the divider. The
current way of always bailing out of this loop early is a bit confusing.
> + ret = PTR_ERR(dwmac->m250_mux_parent[i]);
> + if (ret != -EPROBE_DEFER)
> + dev_err(dev, "Missing clock %s\n", name);
> + dwmac->m250_mux_parent[i] = NULL;
> + return ret;
> + }
> +
> + mux_parent_names[i] =
> + __clk_get_name(dwmac->m250_mux_parent[i]);
> + mux_parent_count++;
> + }
> +
> + /* create the m250_mux */
> + snprintf(clk_name, sizeof(clk_name), "%s#m250_sel", dev_name(dev));
> + init.name = clk_name;
> + init.ops = &clk_mux_ops;
> + init.flags = CLK_IS_BASIC;
> + init.parent_names = mux_parent_names;
> + init.num_parents = mux_parent_count;
> +
> + dwmac->m250_mux.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
> + dwmac->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
> + dwmac->m250_mux.flags = 0;
> + dwmac->m250_mux.table = NULL;
> + dwmac->m250_mux.hw.init = &init;
> +
> + dwmac->m250_mux_clk = devm_clk_register(dev, &dwmac->m250_mux.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m250_mux_clk)))
> + return PTR_ERR(dwmac->m250_mux_clk);
> +
> + /* create the m250_div */
> + snprintf(clk_name, sizeof(clk_name), "%s#m250_div", dev_name(dev));
> + init.name = devm_kstrdup(dev, clk_name, GFP_KERNEL);
> + init.ops = &clk_divider_ops;
> + init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT;
hmm, with CLK_SET_RATE_PARENT that implies that it might switch the mux,
but it's hard-coded above so the mux only ever has one parent, so that
can never happen.
> + clk_div_parents[0] = __clk_get_name(dwmac->m250_mux_clk);
> + init.parent_names = clk_div_parents;
> + init.num_parents = ARRAY_SIZE(clk_div_parents);
> +
> + dwmac->m250_div.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m250_div.shift = PRG_ETH0_CLK_M250_DIV_SHIFT;
> + dwmac->m250_div.width = PRG_ETH0_CLK_M250_DIV_WIDTH;
> + dwmac->m250_div.hw.init = &init;
> + dwmac->m250_div.flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
> +
> + dwmac->m250_div_clk = devm_clk_register(dev, &dwmac->m250_div.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m250_div_clk)))
> + return PTR_ERR(dwmac->m250_div_clk);
> +
> + /* create the m25_div */
> + snprintf(clk_name, sizeof(clk_name), "%s#m25_div", dev_name(dev));
> + init.name = devm_kstrdup(dev, clk_name, GFP_KERNEL);
> + init.ops = &clk_divider_ops;
> + init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT;
> + clk_div_parents[0] = __clk_get_name(dwmac->m250_div_clk);
> + init.parent_names = clk_div_parents;
> + init.num_parents = ARRAY_SIZE(clk_div_parents);
> +
> + dwmac->m25_div.reg = dwmac->regs + PRG_ETH0;
> + dwmac->m25_div.shift = PRG_ETH0_CLK_M25_DIV_SHIFT;
> + dwmac->m25_div.width = PRG_ETH0_CLK_M25_DIV_WIDTH;
> + dwmac->m25_div.table = clk_25m_div_table;
> + dwmac->m25_div.hw.init = &init;
> + dwmac->m25_div.flags = CLK_DIVIDER_ALLOW_ZERO;
> +
> + dwmac->m25_div_clk = devm_clk_register(dev, &dwmac->m25_div.hw);
> + if (WARN_ON(PTR_ERR_OR_ZERO(dwmac->m25_div_clk)))
> + return PTR_ERR(dwmac->m25_div_clk);
> +
> + return 0;
> +}
> +
> +static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac)
> +{
> + int ret;
> + unsigned long clk_rate;
> +
> + switch (dwmac->phy_mode) {
> + case PHY_INTERFACE_MODE_RGMII:
> + case PHY_INTERFACE_MODE_RGMII_ID:
> + case PHY_INTERFACE_MODE_RGMII_RXID:
> + case PHY_INTERFACE_MODE_RGMII_TXID:
> + /* Generate a 25MHz clock for the PHY */
> + clk_rate = 25 * 1000 * 1000;
> +
> + /* enable RGMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_RGMII_MODE,
> + PRG_ETH0_RGMII_MODE);
> +
> + /* only relevant for RMII mode -> disable in RGMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0,
> + PRG_ETH0_INVERTED_RMII_CLK, 0);
> +
> + /* TX clock delay - all known boards use a 1/4 cycle delay */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK,
> + PRG_ETH0_TXDLY_QUARTER);
> + break;
> +
> + case PHY_INTERFACE_MODE_RMII:
> + /* Use the rate of the mux clock for the internal RMII PHY */
> + clk_rate = clk_get_rate(dwmac->m250_mux_clk);
> +
> + /* disable RGMII mode -> enables RMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_RGMII_MODE,
> + 0);
> +
> + /* invert internal clk_rmii_i to generate 25/2.5 tx_rx_clk */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0,
> + PRG_ETH0_INVERTED_RMII_CLK,
> + PRG_ETH0_INVERTED_RMII_CLK);
> +
> + /* TX clock delay cannot be configured in RMII mode */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK,
> + 0);
> +
> + break;
> +
> + default:
> + dev_err(&dwmac->pdev->dev, "unsupported phy-mode %s\n",
> + phy_modes(dwmac->phy_mode));
> + return -EINVAL;
> + }
> +
> + ret = clk_prepare_enable(dwmac->m25_div_clk);
> + if (ret) {
> + dev_err(&dwmac->pdev->dev, "failed to enable the PHY clock\n");
> + return ret;
> + }
> +
> + ret = clk_set_rate(dwmac->m25_div_clk, clk_rate);
> + if (ret) {
> + clk_disable_unprepare(dwmac->m25_div_clk);
> +
> + dev_err(&dwmac->pdev->dev, "failed to set PHY clock\n");
> + return ret;
> + }
In the case of success, the clock is never disabled/unprepared. You
probably need a .remove function which disables the clock and then calls
stmmac_pltfr_remove.
> + /* enable TX_CLK and PHY_REF_CLK generator */
> + meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TX_AND_PHY_REF_CLK,
> + PRG_ETH0_TX_AND_PHY_REF_CLK);
> +
> + return 0;
> +}
[...]
Otherwise, this is looking good.
Also, I tested on meson-gxbb-odroidc2 and meson-gxbb-p200 by booting a debian
root filesystem over NFS and all was well.
Tested-by: Kevin Hilman <khilman@baylibre.com>
Kevin
next prev parent reply other threads:[~2016-08-19 21:40 UTC|newest]
Thread overview: 176+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-25 16:50 [RFC] meson: add support for configuring the ethernet clocks Martin Blumenstingl
2016-06-25 16:50 ` Martin Blumenstingl
2016-06-25 16:50 ` [PATCH RFC 1/3] net: dt-bindings: add the amlogic, meson8b-dwmac binding Martin Blumenstingl
2016-06-25 16:50 ` [PATCH RFC 1/3] net: dt-bindings: add the amlogic,meson8b-dwmac binding Martin Blumenstingl
2016-06-25 16:50 ` [PATCH RFC 2/3] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC Martin Blumenstingl
2016-06-25 16:50 ` Martin Blumenstingl
2016-06-25 16:50 ` [PATCH RFC 3/3] ARM64: dts: meson-gxbb: use the new meson8b DWMAC glue Martin Blumenstingl
2016-06-25 16:50 ` Martin Blumenstingl
2016-06-27 9:24 ` Carlo Caione
2016-06-27 9:24 ` Carlo Caione
2016-06-27 10:44 ` Martin Blumenstingl
2016-06-27 10:44 ` Martin Blumenstingl
2016-06-27 11:33 ` Martin Blumenstingl
2016-06-27 11:33 ` Martin Blumenstingl
2016-07-13 21:01 ` Michael Turquette
2016-07-13 21:01 ` Michael Turquette
2016-07-13 21:22 ` Kevin Hilman
2016-07-13 21:22 ` Kevin Hilman
2016-08-15 16:40 ` [PATCH 0/3] ARM64: meson: Meson8b and GXBB DWMAC glue driver Martin Blumenstingl
2016-08-15 16:40 ` Martin Blumenstingl
2016-08-15 16:40 ` Martin Blumenstingl
2016-08-15 16:40 ` [PATCH 1/3] net: dt-bindings: Document the new Meson8b and GXBB DWMAC bindings Martin Blumenstingl
2016-08-15 16:40 ` Martin Blumenstingl
2016-08-15 16:40 ` Martin Blumenstingl
2016-08-16 14:25 ` Rob Herring
2016-08-16 14:25 ` Rob Herring
2016-08-16 14:25 ` Rob Herring
2016-08-15 16:40 ` [PATCH 2/3] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC Martin Blumenstingl
2016-08-15 16:40 ` Martin Blumenstingl
2016-08-15 16:40 ` Martin Blumenstingl
2016-08-19 21:40 ` Kevin Hilman [this message]
2016-08-19 21:40 ` Kevin Hilman
2016-08-19 21:40 ` Kevin Hilman
2016-08-15 16:41 ` [PATCH 3/3] ARM64: dts: meson-gxbb: use the new GXBB DWMAC glue driver Martin Blumenstingl
2016-08-15 16:41 ` Martin Blumenstingl
2016-08-15 16:41 ` Martin Blumenstingl
2016-08-20 9:35 ` [PATCH v2 0/4] meson: Meson8b and " Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 9:35 ` [PATCH v2 1/4] net: dt-bindings: Document the new Meson8b and GXBB DWMAC bindings Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-22 11:55 ` Arnd Bergmann
2016-08-22 11:55 ` Arnd Bergmann
2016-08-22 11:55 ` Arnd Bergmann
2016-08-22 12:04 ` Martin Blumenstingl
2016-08-22 12:04 ` Martin Blumenstingl
2016-08-22 12:04 ` Martin Blumenstingl
2016-08-22 15:25 ` Arnd Bergmann
2016-08-22 15:25 ` Arnd Bergmann
2016-08-22 15:25 ` Arnd Bergmann
2016-08-28 16:15 ` Martin Blumenstingl
2016-08-28 16:15 ` Martin Blumenstingl
2016-08-28 16:15 ` Martin Blumenstingl
2016-08-29 13:31 ` Arnd Bergmann
2016-08-29 13:31 ` Arnd Bergmann
2016-08-29 13:31 ` Arnd Bergmann
2016-08-20 9:35 ` [PATCH v2 2/4] clk: gxbb: expose MPLL2 clock for use by DT Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 9:35 ` [PATCH v2 3/4] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 21:29 ` Joachim Eastwood
2016-08-20 21:29 ` Joachim Eastwood
2016-08-20 21:29 ` Joachim Eastwood
2016-08-21 12:00 ` Martin Blumenstingl
2016-08-21 12:00 ` Martin Blumenstingl
2016-08-21 12:00 ` Martin Blumenstingl
2016-08-20 9:35 ` [PATCH v2 4/4] ARM64: dts: meson-gxbb: use the new GXBB DWMAC glue driver Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-20 9:35 ` Martin Blumenstingl
2016-08-28 16:16 ` [PATCH v3 0/5] meson: Meson8b and " Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` [PATCH v3 1/5] net: dt-bindings: Document the new Meson8b and GXBB DWMAC bindings Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` [PATCH v3 2/5] clk: gxbb: expose MPLL2 clock for use by DT Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` [PATCH v3 3/5] stmmac: introduce get_stmmac_bsp_priv() helper Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` [PATCH v3 4/5] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-30 19:19 ` Stephen Boyd
2016-08-30 19:19 ` Stephen Boyd
2016-08-30 19:19 ` Stephen Boyd
2016-09-04 18:20 ` Martin Blumenstingl
2016-09-04 18:20 ` Martin Blumenstingl
2016-09-04 18:20 ` Martin Blumenstingl
2016-09-05 9:27 ` Arnd Bergmann
2016-09-05 9:27 ` Arnd Bergmann
2016-09-05 9:27 ` Arnd Bergmann
2016-08-28 16:16 ` [PATCH v3 5/5] ARM64: dts: meson-gxbb: use the new GXBB DWMAC glue driver Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-28 16:16 ` Martin Blumenstingl
2016-08-29 3:40 ` [PATCH v3 0/5] meson: Meson8b and " David Miller
2016-08-29 3:40 ` David Miller
2016-08-29 3:40 ` David Miller
2016-08-30 18:49 ` Martin Blumenstingl
2016-08-30 18:49 ` Martin Blumenstingl
2016-08-30 18:49 ` Martin Blumenstingl
2016-08-31 4:57 ` David Miller
2016-08-31 4:57 ` David Miller
2016-08-31 4:57 ` David Miller
2016-09-02 4:23 ` Kevin Hilman
2016-09-02 4:23 ` Kevin Hilman
2016-09-02 4:23 ` Kevin Hilman
2016-09-02 5:37 ` David Miller
2016-09-02 5:37 ` David Miller
2016-09-02 5:37 ` David Miller
2016-09-02 8:50 ` Arnd Bergmann
2016-09-02 8:50 ` Arnd Bergmann
2016-09-02 8:50 ` Arnd Bergmann
2016-09-04 18:23 ` [PATCH v4 " Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` [PATCH v4 1/5] net: dt-bindings: Document the new Meson8b and GXBB DWMAC bindings Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` [PATCH v4 2/5] clk: gxbb: expose MPLL2 clock for use by DT Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` [PATCH v4 3/5] stmmac: introduce get_stmmac_bsp_priv() helper Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` [PATCH v4 4/5] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-05 1:37 ` kbuild test robot
2016-09-05 1:37 ` kbuild test robot
2016-09-05 1:37 ` kbuild test robot
2016-09-05 1:37 ` kbuild test robot
2016-09-05 10:53 ` Arnd Bergmann
2016-09-05 10:53 ` Arnd Bergmann
2016-09-05 10:53 ` Arnd Bergmann
2016-09-05 19:07 ` Martin Blumenstingl
2016-09-05 19:07 ` Martin Blumenstingl
2016-09-05 19:07 ` Martin Blumenstingl
2016-09-06 9:37 ` Arnd Bergmann
2016-09-06 9:37 ` Arnd Bergmann
2016-09-06 9:37 ` Arnd Bergmann
2016-09-05 1:43 ` kbuild test robot
2016-09-05 1:43 ` kbuild test robot
2016-09-05 1:43 ` kbuild test robot
2016-09-05 1:43 ` kbuild test robot
2016-09-04 18:23 ` [PATCH v4 5/5] ARM64: dts: meson-gxbb: use the new GXBB DWMAC glue driver Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-04 18:23 ` Martin Blumenstingl
2016-09-06 21:38 ` [PATCH v5 0/6] meson: Meson8b and " Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` [PATCH v5 1/6] net: dt-bindings: Document the new Meson8b and GXBB DWMAC bindings Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` [PATCH v5 2/6] clk: gxbb: expose MPLL2 clock for use by DT Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-07 21:27 ` Stephen Boyd
2016-09-07 21:27 ` Stephen Boyd
2016-09-07 21:27 ` Stephen Boyd
2016-09-06 21:38 ` [PATCH v5 3/6] stmmac: introduce get_stmmac_bsp_priv() helper Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` [PATCH v5 4/6] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` [PATCH v5 5/6] ARM64: dts: meson-gxbb: use the new GXBB DWMAC glue driver Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` [PATCH v5 6/6] net: stmmac: update the module description of the dwmac-meson driver Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
2016-09-06 21:38 ` Martin Blumenstingl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7hshu0780f.fsf@baylibre.com \
--to=khilman@baylibre.com \
--cc=linus-amlogic@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.