From patchwork Sat Jun 25 16:50:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9198617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 016FF60752 for ; Sat, 25 Jun 2016 16:50:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6979284EF for ; Sat, 25 Jun 2016 16:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB2EF2851D; Sat, 25 Jun 2016 16:50:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B51B2851C for ; Sat, 25 Jun 2016 16:50:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bGqn8-0004f9-MC; Sat, 25 Jun 2016 16:50:46 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bGqn5-0004cJ-Ge for linux-amlogic@lists.infradead.org; Sat, 25 Jun 2016 16:50:45 +0000 Received: by mail-wm0-x243.google.com with SMTP id 187so13358832wmz.1 for ; Sat, 25 Jun 2016 09:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=E3KuDhArR2qNKloKgT3A4N8pPwR0DJXLdK2OhpvXpW0=; b=hqNMLOtTLskmb1sdfCojkooTOtxXuqXuBvFU1oqMu33YcuhDjy0tZDU8CfSMjv6ie0 M7U3UrJE3BNY2NhYduwuWRrPkaWKRCIUMH0F9UyLQn8XLhbW56T2JxFmlpAf1rG/fdpl BNbtnfO+ejiHpUBoHBpE77RipzhoMrhpdQZbM8izw2F3VG/Zeq54zU52Rw+QeC3Co/7u 5R4cpphADNV3s+4T0IGzsMP0AhMelHTSlj5aq5WdibK0zN60VvwdLz4pXzuyVDSzQYHJ icgoWTjowkuLML0BwfI7LLpXTxLgxGMd0rUDkq8WEVDReG149WI1fRGQ6OpeHu+MVdYC b9Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=E3KuDhArR2qNKloKgT3A4N8pPwR0DJXLdK2OhpvXpW0=; b=LuDveo6Ye5DmB/otnM+Y22Do/vU+j9kC+skviqWlRIMZD7OEJux9fTn7Qjsg5er8fZ YiaCDLIpNUknlwVp8tiPwv8k2JSB0ua7jwY008KEFw8CGPfDvv35Q/cNY2UhNXxK5lp3 hIA3HPWaCj8xWmdzxCz3EsFAU2LDFi1vm778A1zShztpw25yM1/IHMX8dzIWiYMy1j2D fFuHpYEnrFFaheobNlv5X82X1uqAATFYQCSMPd+jGyr2XoeaNXTxHe41ltYZ6q7mfQ0e SjiWG4W46DtcEXmMR5nV4b5U7GK8x2wTPXJfa527GedzhXKI0h5RM+BzSmmNFru9wbjk UAwA== X-Gm-Message-State: ALyK8tIaqzBFJLyeteR1o2+zkiKGKxjhJe7v+5AWFL1I/Yv+8dcl/08LIdpa0DtXcNevAA== X-Received: by 10.28.152.211 with SMTP id a202mr3195958wme.60.1466873424098; Sat, 25 Jun 2016 09:50:24 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD3CD1B04957A13FD6F05B849.dip0.t-ipconnect.de. [2003:dc:d3cd:1b04:957a:13fd:6f05:b849]) by smtp.googlemail.com with ESMTPSA id el4sm3144603wjd.23.2016.06.25.09.50.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Jun 2016 09:50:23 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org Subject: [PATCH RFC 2/3] net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC Date: Sat, 25 Jun 2016 18:50:12 +0200 Message-Id: <20160625165013.15917-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160625165013.15917-1-martin.blumenstingl@googlemail.com> References: <20160625165013.15917-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160625_095043_924588_19F626A5 X-CRM114-Status: GOOD ( 21.17 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, Martin Blumenstingl , khilman@baylibre.com, robh+dt@kernel.org, netdev@vger.kernel.org, carlo@caione.org, peppe.cavallaro@st.com MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 was introduced. Signed-off-by: Martin Blumenstingl --- drivers/net/ethernet/stmicro/stmmac/Makefile | 2 +- .../net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 219 +++++++++++++++++++++ include/dt-bindings/net/amlogic-meson8b-dwmac.h | 33 ++++ 3 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c create mode 100644 include/dt-bindings/net/amlogic-meson8b-dwmac.h diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index 0fb362d..79e5d0c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -9,7 +9,7 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \ obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o obj-$(CONFIG_DWMAC_IPQ806X) += dwmac-ipq806x.o obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o -obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o +obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-socfpga.o obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c new file mode 100644 index 0000000..4c2d1e1 --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c @@ -0,0 +1,219 @@ +/* + * Amlogic Meson S805/S905 DWMAC glue layer + * + * Copyright (C) 20016 Martin Blumenstingl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stmmac_platform.h" + +#define PRG_ETH0 0x0 +#define PRG_ETH0_RGMII_MODE BIT(0) +#define PRG_ETH0_TXDLY_SHIFT 5 /* 2 bits [5-6] */ +#define PRG_ETH0_TXDLY_MASK (0x3 << PRG_ETH0_TXDLY_SHIFT) +#define PRG_ETH0_MP2_CLK_SHIFT 7 /* 3 bits [7-9] */ +#define PRG_ETH0_MP2_CLK_MASK (0x7 << PRG_ETH0_MP2_CLK_SHIFT) +#define PRG_ETH0_GEN_25MHZ_PHY_CLK BIT(10) +#define PRG_ETH0_TX_CLK_SPEED_100 BIT(11) +#define PRG_ETH0_TX_AND_PHY_REF_CLK BIT(12) + +struct meson8b_dwmac { + struct platform_device *pdev; + struct regmap *prg_ethernet; + phy_interface_t phy_mode; + u32 tx_delay; + u32 mp2_clk; + bool enable_25mhz_phy_clk; +}; + +static void meson8b_dwmac_fix_mac_speed(void *priv, unsigned int speed) +{ + struct meson8b_dwmac *dwmac = priv; + + /* MAC speed adjustment is only needed in RMII mode */ + if (dwmac->phy_mode != PHY_INTERFACE_MODE_RMII) + return; + + switch (speed) { + case SPEED_10: + /* 2.5MHz */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_TX_CLK_SPEED_100, 0); + break; + case SPEED_100: + /* 25MHz */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_TX_CLK_SPEED_100, + PRG_ETH0_TX_CLK_SPEED_100); + break; + } +} + +static int meson8b_dwmac_of_parse(struct meson8b_dwmac *dwmac) +{ + struct device *dev = &dwmac->pdev->dev; + struct device_node *np = dev->of_node; + + dwmac->phy_mode = of_get_phy_mode(np); + if (dwmac->phy_mode < 0) { + dev_err(dev, "missing phy-mode property\n"); + return -EINVAL; + } + + /* register map for MAC configuration */ + dwmac->prg_ethernet = syscon_regmap_lookup_by_phandle(np, + "amlogic,prg-ethernet"); + if (IS_ERR(dwmac->prg_ethernet)) { + dev_err(dev, "missing amlogic,prg-ethernet property\n"); + return PTR_ERR(dwmac->prg_ethernet); + } + + if (of_property_read_bool(np, "amlogic,enable-25mhz-phy-clk")) + dwmac->enable_25mhz_phy_clk = true; + + /* TX delay is optional */ + of_property_read_u32(np, "amlogic,tx-delay", &dwmac->tx_delay); + + /* MP2 clock is optional at least in RMII mode */ + of_property_read_u32(np, "amlogic,mp2-clock", &dwmac->mp2_clk); + + return 0; +} + +static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac) +{ + 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: + /* enable RGMII mode */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_RGMII_MODE, + PRG_ETH0_RGMII_MODE); + + /* only relevant for RMII mode -> disable in RGMII mode */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_TX_CLK_SPEED_100, 0); + + /* TX clock delay (ranges from 0 to 3/4 clock cycles) */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_TXDLY_MASK, + dwmac->tx_delay << PRG_ETH0_TXDLY_SHIFT); + break; + + case PHY_INTERFACE_MODE_RMII: + /* disable RGMII mode -> enables RMII mode */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_RGMII_MODE, 0); + + /* default to 100Mbit mode */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_TX_CLK_SPEED_100, + PRG_ETH0_TX_CLK_SPEED_100); + + /* TX clock delay cannot be configured in RMII mode */ + regmap_update_bits(dwmac->prg_ethernet, 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; + } + + /* mp2_clk is the factor for mp2_clk_out, rate = 250MHz * factor */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, PRG_ETH0_MP2_CLK_MASK, + dwmac->mp2_clk << PRG_ETH0_MP2_CLK_SHIFT); + + /* should we generate 25MHz for the PHY? */ + if (dwmac->enable_25mhz_phy_clk) + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_GEN_25MHZ_PHY_CLK, + PRG_ETH0_GEN_25MHZ_PHY_CLK); + else + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_GEN_25MHZ_PHY_CLK, 0); + + /* enable TX_CLK and PHY_REF_CLK generator */ + regmap_update_bits(dwmac->prg_ethernet, PRG_ETH0, + PRG_ETH0_TX_AND_PHY_REF_CLK, + PRG_ETH0_TX_AND_PHY_REF_CLK); + + return 0; +} + +static int meson8b_dwmac_probe(struct platform_device *pdev) +{ + struct plat_stmmacenet_data *plat_dat; + struct stmmac_resources stmmac_res; + struct meson8b_dwmac *dwmac; + int ret; + + ret = stmmac_get_platform_resources(pdev, &stmmac_res); + if (ret) + return ret; + + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac); + if (IS_ERR(plat_dat)) + return PTR_ERR(plat_dat); + + dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + if (!dwmac) + return -ENOMEM; + + dwmac->pdev = pdev; + + ret = meson8b_dwmac_of_parse(dwmac); + if (ret) + return ret; + + ret = meson8b_init_prg_eth(dwmac); + if (ret) + return ret; + + plat_dat->bsp_priv = dwmac; + plat_dat->fix_mac_speed = meson8b_dwmac_fix_mac_speed; + + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); +} + +static const struct of_device_id meson8b_dwmac_match[] = { + { .compatible = "amlogic,meson8b-dwmac" }, + { } +}; +MODULE_DEVICE_TABLE(of, meson8b_dwmac_match); + +static struct platform_driver meson8b_dwmac_driver = { + .probe = meson8b_dwmac_probe, + .remove = stmmac_pltfr_remove, + .driver = { + .name = "meson8b-dwmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = meson8b_dwmac_match, + }, +}; +module_platform_driver(meson8b_dwmac_driver); + +MODULE_AUTHOR("Martin Blumenstingl "); +MODULE_DESCRIPTION("Amlogic Meson S805/S905 DWMAC glue layer"); +MODULE_LICENSE("GPL v2"); diff --git a/include/dt-bindings/net/amlogic-meson8b-dwmac.h b/include/dt-bindings/net/amlogic-meson8b-dwmac.h new file mode 100644 index 0000000..413ef4e --- /dev/null +++ b/include/dt-bindings/net/amlogic-meson8b-dwmac.h @@ -0,0 +1,33 @@ +/* + * Device Tree constants for the Amlogic Meson S805/S905 DWMAC + * + * Copyright (C) 20016 Martin Blumenstingl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _DT_BINDINGS_AMLOGIC_MESON8B_DWMAC_H +#define _DT_BINDINGS_AMLOGIC_MESON8B_DWMAC_H + +/* TX delay settings */ +#define MESON8B_DWMAC_TX_CLK_DELAY_OFF 0x0 +#define MESON8B_DWMAC_TX_CLK_DELAY_QUARTER_CYCLE 0x1 +#define MESON8B_DWMAC_TX_CLK_DELAY_HALF_CYCLE 0x2 +#define MESON8B_DWMAC_TX_CLK_DELAY_THREE_QUARTER_CYCLEs 0x3 + +/* mp2 clock rates */ +#define MESON8B_DWMAC_MP2_CLOCK_DISABLED 0 +#define MESON8B_DWMAC_MP2_CLOCK_250MHZ 1 +#define MESON8B_DWMAC_MP2_CLOCK_500MHZ 2 +#define MESON8B_DWMAC_MP2_CLOCK_750MHZ 3 +#define MESON8B_DWMAC_MP2_CLOCK_1000MHZ 4 +#define MESON8B_DWMAC_MP2_CLOCK_1250MHZ 5 +#define MESON8B_DWMAC_MP2_CLOCK_1500MHZ 6 +#define MESON8B_DWMAC_MP2_CLOCK_1750MHZ 7 + +#endif /* _DT_BINDINGS_AMLOGIC_MESON8B_DWMAC_H */