From patchwork Thu Mar 14 14:01:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 10852905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B65641669 for ; Thu, 14 Mar 2019 14:02:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99F1C2A524 for ; Thu, 14 Mar 2019 14:02:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 976602A4B2; Thu, 14 Mar 2019 14:02:12 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1A0FE2A4B2 for ; Thu, 14 Mar 2019 14:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4jdjxf3NYTbX41ZROk2GpwZjK5TM9xiDkGzXjT3YCW4=; b=UascvoystEInwG mdeBGKzfdLcDCf4fNuLFVlHMkD0R6Pg7IyF2OO24EoeUD5DG/DZjQt/xFBbGYdHgCsC2+0rBLgELH wOYFY/uxz2e8sjiEZPzRapylpJ4rGPjcBcG+ZSEoJqwopPyU6poG14zjk1ijkwbOCHhwCsqjURl/X 9LIhJS3rq62+w8nKuHqbgpRBHy0f9ulotowxYHGjP6G/Tjpeu+dKlAM68cAhCYWrSBFA73BXReYPm FCR6Td3s4uZVk25D2BU3Ho7J8IptRpKyrb3Lo3zlrPeuHGqORlV1+Y/X8d3Bg2/CmNXk65Cclq0PJ CsGMtIyQ7HqWF6P0EzvA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Qvy-0000NT-E0; Thu, 14 Mar 2019 14:02:10 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Qvk-0000Gi-9d for linux-amlogic@lists.infradead.org; Thu, 14 Mar 2019 14:02:07 +0000 Received: by mail-wm1-x342.google.com with SMTP id e74so3104187wmg.3 for ; Thu, 14 Mar 2019 07:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VrIM0LIaAeyRnbtzdYl720Pekr4qj64JGsc6swg1oRE=; b=h12UH4uN+TK+CWagvg7xGzLUqGLu4PZVoiVJpeT4y/1h7Iq1fV58Wm9UTL0VMB85J5 xixzDy/ousy7RYw7epz+obveAK4Njoxz4uhAtAEMX5J1Frme5pEgrhukvX9JCfP0zLjm Ro4PQ+Kpq9SQW0EHZE7ATa9nwM17DgjsfpP6TG9UUWYE4DhO8S10eStLrOQn3I3JHgqb nFqYfJlA3dSJeDjxUN0ghhivQBL/77X2DZKVMSycDjTwa1usSaEH5xpBvwVoPc3mp9F0 MUhi/RoBtC1oOrdxwrgVBGhn4N01ELMCVDFLhW6yK3XhnxeRrAscucOzTDdGmJtVaC4K tauQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VrIM0LIaAeyRnbtzdYl720Pekr4qj64JGsc6swg1oRE=; b=c/WuYToleCfNE+yOFHc70o0UCpkmP73UiuC173vgQflBwd72Knm3J6AhXM9vQSwg8L 5kEtZF2A+5MvOCx6g95u0pegWOlEDNDfceakkOWD6KlT/Q/a8OQJa3CfCYOIdl3r9okE 41pBI1hlNo3/SdZqkhFJiYQ9uR/hff5CddJWuyc02Mc8Nsyx9LwGeK2g+xIbM8Y2brC0 yUyXkgAfGxlpWDjjj/E+W1xK9ZXNyBnfI0WngGKRHvNEDFYmSHqRjGe/K83EXN1oPSDf mqVepwiv3hm5YKVlGEddetLy/OFcnUNZhnoDmzkiyP7YAjrL8c96l+htbkM6xKH/oe/6 /l+Q== X-Gm-Message-State: APjAAAXbD0h5BXNjc3Y5hGe+SjL+eKnHSpjo/AtajAljyJVKZqXnKKoV fKF05RD7o4y5LVNink4pT3YWdw== X-Google-Smtp-Source: APXvYqx30dID+exeDffHkGRxAS6tGiz1CiwGspdI2h6soSmi9WPVymySTu2maYUw9cnBmRw6gtuXBg== X-Received: by 2002:a1c:9693:: with SMTP id y141mr2805320wmd.33.1552572114872; Thu, 14 Mar 2019 07:01:54 -0700 (PDT) Received: from boomer.local ([2a01:e34:eeb6:4690:106b:bae3:31ed:7561]) by smtp.googlemail.com with ESMTPSA id y7sm2661051wmi.34.2019.03.14.07.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 07:01:54 -0700 (PDT) From: Jerome Brunet To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , "David S. Miller" , Kevin Hilman Subject: [PATCH net-next 1/3] dt-bindings: net: phy: add g12a mdio mux documentation Date: Thu, 14 Mar 2019 15:01:33 +0100 Message-Id: <20190314140135.19184-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190314140135.19184-1-jbrunet@baylibre.com> References: <20190314140135.19184-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_070156_367010_990A5165 X-CRM114-Status: GOOD ( 11.44 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jerome Brunet Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add documentation for the device tree bindings of the MDIO mux of Amlogic g12a SoC family Signed-off-by: Jerome Brunet Reviewed-by: Rob Herring --- .../bindings/net/mdio-mux-meson-g12a.txt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mdio-mux-meson-g12a.txt diff --git a/Documentation/devicetree/bindings/net/mdio-mux-meson-g12a.txt b/Documentation/devicetree/bindings/net/mdio-mux-meson-g12a.txt new file mode 100644 index 000000000000..e738bba6a9de --- /dev/null +++ b/Documentation/devicetree/bindings/net/mdio-mux-meson-g12a.txt @@ -0,0 +1,48 @@ +Properties for the MDIO bus multiplexer/glue of Amlogic G12a SoC family. + +This is a special case of a MDIO bus multiplexer. It allows to choose between +the internal mdio bus leading to the embedded 10/100 PHY or the external +MDIO bus. + +Required properties in addition to the generic multiplexer properties: +- compatible : amlogic,g12a-mdio-mux +- reg: physical address and length of the multiplexer/glue registers +- clocks: list of clock phandle, one for each entry clock-names. +- clock-names: should contain the following: + * "pclk" : peripheral clock. + * "clkin0" : platform crytal + * "clkin1" : SoC 50MHz MPLL + +Example : + +mdio-mux: mdio-multiplexer@4c000 { + compatible = "amlogic,g12a-mdio-mux"; + reg = <0x0 0x4c000 0x0 0xa4>; + clocks = <&clkc CLKID_ETH_PHY>, + <&xtal>, + <&clkc CLKID_MPLL_5OM>; + clock-names = "pclk", "clkin0", "clkin1"; + mdio-parent-bus = <&mdio0>; + #address-cells = <1>; + #size-cells = <0>; + + ext_mdio: mdio@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + }; + + int_mdio: mdio@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + internal_ephy: ethernet_phy@8 { + compatible = "ethernet-phy-id0180.3301", + "ethernet-phy-ieee802.3-c22"; + interrupts = ; + reg = <8>; + max-speed = <100>; + }; + }; +}; From patchwork Thu Mar 14 14:01:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 10852907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5880F139A for ; Thu, 14 Mar 2019 14:02:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BF0D2A523 for ; Thu, 14 Mar 2019 14:02:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39BD62A558; Thu, 14 Mar 2019 14:02:15 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 41EBF2A523 for ; Thu, 14 Mar 2019 14:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Z43w4cWlLuYfvvmx3bmpOeryuLptSdwFwLUkVsvo2wE=; b=WAuxIlkl0IoTBp 2TpBS38p0OHGzf7Ck1Kx5OUbeQIZVGU2Yl7iPRuPEh5+sT1E77FnO5k3zV5x75ZN/Pl2R5Ar36HCN eVbZ+FuTOElbegL5WNf2ArzW8LKbBR/yRm0KBgKZ+FXnY0Wf/OrXg0vBORZ7ZhYQoV7DSHu2X7hwA 15M+LpYT+Q/Hz/yu5H87ZiPN/eprKc7lcZPH6GR5pEme40cUXrb+zsCXB/OhDZ2qPj7zFqa5n2ShC QZGKraM8cWWThsGnvUVXyJktVu0Egon5WRdnjf+0JXczKAtHfXgyDQwpkieC9MVFDijIhwIHdwt9b 6Ca+llP2yzVRSlA5zMDQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Qw1-0000QY-Dy; Thu, 14 Mar 2019 14:02:13 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Qvn-0000Hu-2a for linux-amlogic@lists.infradead.org; Thu, 14 Mar 2019 14:02:10 +0000 Received: by mail-wm1-x341.google.com with SMTP id t124so2818496wma.4 for ; Thu, 14 Mar 2019 07:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o8hkwStb4arPJdoRuGRS4yit7i2bvsVJxinFa9oo8k4=; b=UE6Fs1bMujjiKWH/OsWrchpDUI5PVjkSqQ9EzCprdG+dP6l8W+qyRzYu2xbbymlKmT BSAed8ieNayIy8wOVss3wR6YYb211Dvbtp4Q7AnadVFqlc0qMGR4A6BATUoDlvzteSPE /kcP+I9z4CV/0+aVkHaKWPZgvuIhCpu9QQNHUIApUCPXdhklBY8TPKsHy+WlAVF1SvW0 Scl8Y+rJtZv0ajs9IHrE4t10OzUsDr+sy/bi28jdm8R1slk7MpsFVfRBr4TAEgqRD6Lx EhRWrS+f8SToaXTkJcdAry1JK8RLXE6MAPRrzzTqI7q+xkoVrKaGupOkUc7IChgAVxfG cZ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o8hkwStb4arPJdoRuGRS4yit7i2bvsVJxinFa9oo8k4=; b=dr86m8+9ePQhoN2xJhjz3Tc6XJ1KwD0puwZceWolAxUtpWNB6S2tyfnHK33pz9hckw wo/HULfSIM9SLkXK9DbrgKQY0k7HiEPM871mrg6CP8vIvEOUYe4ISqHr6AL4iEEIK/8C 0EtReQ/HIaPJ9Fl+tisfaD8hzf9llZ7B4eCs9OjrTVmBSlqDu5nU6KLeG/jAbP7kzglE 1i6WBLYO0g+OKaN9tRvtcl6Ip7WYxw2y1sUg40gFJvC6TPQAGJv2lmAREsGWUPQdvL9h gNMwtioDt/Vw7bz8E0NmJAcxOrD5TtI7rHGDhIEJLFqvtcKX4JxR80m95qEPwhCW9qKB BMPA== X-Gm-Message-State: APjAAAWlfLHt8IpeaEWLRcVA+BrsFYLDYs4ZsBve55tNzJQePtgDKh6W qw/qNxkWIUOOeNAfFGXc96WOeg== X-Google-Smtp-Source: APXvYqxLZv4CRlP9PraVeEcVMUrNCJxQTkbshoQBMnpSEasIqDoMiIhoqRNTOPvNB0Y0ZgiI8Md9zg== X-Received: by 2002:a1c:c60e:: with SMTP id w14mr2670501wmf.146.1552572116925; Thu, 14 Mar 2019 07:01:56 -0700 (PDT) Received: from boomer.local ([2a01:e34:eeb6:4690:106b:bae3:31ed:7561]) by smtp.googlemail.com with ESMTPSA id y7sm2661051wmi.34.2019.03.14.07.01.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 07:01:56 -0700 (PDT) From: Jerome Brunet To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , "David S. Miller" , Kevin Hilman Subject: [PATCH net-next 2/3] net: phy: add amlogic g12a mdio mux support Date: Thu, 14 Mar 2019 15:01:34 +0100 Message-Id: <20190314140135.19184-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190314140135.19184-1-jbrunet@baylibre.com> References: <20190314140135.19184-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_070159_234542_FC879A62 X-CRM114-Status: GOOD ( 21.41 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jerome Brunet Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for the mdio mux and internal phy glue of the g12a SoC family Signed-off-by: Jerome Brunet Reviewed-by: Neil Armstrong --- drivers/net/phy/Kconfig | 10 + drivers/net/phy/Makefile | 1 + drivers/net/phy/mdio-mux-meson-g12a.c | 371 ++++++++++++++++++++++++++ 3 files changed, 382 insertions(+) create mode 100644 drivers/net/phy/mdio-mux-meson-g12a.c diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 071869db44cf..831aa350b1cb 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -74,6 +74,16 @@ config MDIO_BUS_MUX_GPIO several child MDIO busses to a parent bus. Child bus selection is under the control of GPIO lines. +config MDIO_BUS_MUX_MESON_G12A + tristate "Amlogic G12a based MDIO bus multiplexer" + depends on ARCH_MESON || COMPILE_TEST + depends on OF_MDIO && HAS_IOMEM + select MDIO_BUS_MUX + help + This module provides a driver for the MDIO multiplexer/glue of + the amlogic g12a SoC. The multiplexers connects either the external + or the internal MDIO bus to the parent bus. + config MDIO_BUS_MUX_MMIOREG tristate "MMIO device-controlled MDIO bus multiplexers" depends on OF_MDIO && HAS_IOMEM diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index ece5dae67174..27d7f9f3b0de 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o obj-$(CONFIG_MDIO_BUS_MUX) += mdio-mux.o obj-$(CONFIG_MDIO_BUS_MUX_BCM_IPROC) += mdio-mux-bcm-iproc.o obj-$(CONFIG_MDIO_BUS_MUX_GPIO) += mdio-mux-gpio.o +obj-$(CONFIG_MDIO_BUS_MUX_MESON_G12A) += mdio-mux-meson-g12a.o obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o obj-$(CONFIG_MDIO_BUS_MUX_MULTIPLEXER) += mdio-mux-multiplexer.o obj-$(CONFIG_MDIO_CAVIUM) += mdio-cavium.o diff --git a/drivers/net/phy/mdio-mux-meson-g12a.c b/drivers/net/phy/mdio-mux-meson-g12a.c new file mode 100644 index 000000000000..9da681cce7cd --- /dev/null +++ b/drivers/net/phy/mdio-mux-meson-g12a.c @@ -0,0 +1,371 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2019 Baylibre, SAS. + * Author: Jerome Brunet + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ETH_PLL_STS 0x40 +#define ETH_PLL_CTL0 0x44 +#define PLL_CTL0_LOCK_DIG BIT(30) +#define PLL_CTL0_RST BIT(29) +#define PLL_CTL0_EN BIT(28) +#define PLL_CTL0_SEL BIT(23) +#define PLL_CTL0_N GENMASK(14, 10) +#define PLL_CTL0_M GENMASK(8, 0) +#define PLL_LOCK_TIMEOUT 1000000 +#define PLL_MUX_NUM_PARENT 2 +#define ETH_PLL_CTL1 0x48 +#define ETH_PLL_CTL2 0x4c +#define ETH_PLL_CTL3 0x50 +#define ETH_PLL_CTL4 0x54 +#define ETH_PLL_CTL5 0x58 +#define ETH_PLL_CTL6 0x5c +#define ETH_PLL_CTL7 0x60 + +#define ETH_PHY_CNTL0 0x80 +#define EPHY_G12A_ID 0x33000180 +#define ETH_PHY_CNTL1 0x84 +#define PHY_CNTL1_ST_MODE GENMASK(2, 0) +#define PHY_CNTL1_ST_PHYADD GENMASK(7, 3) +#define EPHY_DFLT_ADD 8 +#define PHY_CNTL1_MII_MODE GENMASK(15, 14) +#define EPHY_MODE_RMII 0x1 +#define PHY_CNTL1_CLK_EN BIT(16) +#define PHY_CNTL1_CLKFREQ BIT(17) +#define PHY_CNTL1_PHY_ENB BIT(18) +#define ETH_PHY_CNTL2 0x88 +#define PHY_CNTL2_USE_INTERNAL BIT(5) +#define PHY_CNTL2_SMI_SRC_MAC BIT(6) +#define PHY_CNTL2_RX_CLK_EPHY BIT(9) + +#define MESON_G12A_MDIO_EXTERNAL_ID 0 +#define MESON_G12A_MDIO_INTERNAL_ID 1 + +struct g12a_mdio_mux { + void __iomem *regs; + struct clk *pclk; + struct clk *pll; + bool pll_is_enabled; + void *mux_handle; +}; + +struct g12a_ephy_pll { + struct clk_hw hw; + void __iomem *base; +}; + +#define g12a_ephy_pll_to_dev(_hw) \ + container_of(_hw, struct g12a_ephy_pll, hw) \ + +static unsigned long g12a_ephy_pll_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw); + u32 val, m, n; + + val = readl(pll->base + ETH_PLL_CTL0); + m = FIELD_GET(PLL_CTL0_M, val); + n = FIELD_GET(PLL_CTL0_N, val); + + return parent_rate * m / n; +} + +static int g12a_ephy_pll_enable(struct clk_hw *hw) +{ + struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw); + u32 val = readl(pll->base + ETH_PLL_CTL0); + + /* Apply both enable an reset */ + val |= PLL_CTL0_RST | PLL_CTL0_EN; + writel(val, pll->base + ETH_PLL_CTL0); + + /* Clear the reset to let PLL lock */ + val &= ~PLL_CTL0_RST; + writel(val, pll->base + ETH_PLL_CTL0); + + /* Poll on the digital lock instead of the usual analog lock + * This is done because bit 31 is unreliable on some SoC. Bit + * 31 may indicate that the PLL is not lock eventhough the clock + * is actually running + */ + return readl_poll_timeout(pll->base + ETH_PLL_CTL0, val, + val & PLL_CTL0_LOCK_DIG, 0, PLL_LOCK_TIMEOUT); +} + +static void g12a_ephy_pll_disable(struct clk_hw *hw) +{ + struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw); + u32 val; + + val = readl(pll->base + ETH_PLL_CTL0); + val &= ~PLL_CTL0_EN; + val |= PLL_CTL0_RST; + writel(val, pll->base + ETH_PLL_CTL0); +} + +static int g12a_ephy_pll_is_enabled(struct clk_hw *hw) +{ + struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw); + unsigned int val; + + val = readl(pll->base + ETH_PLL_CTL0); + + return (val & PLL_CTL0_LOCK_DIG) ? 1 : 0; +} + +static void g12a_ephy_pll_init(struct clk_hw *hw) +{ + struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw); + + /* Apply PLL HW settings */ + writel(0x29c0040a, pll->base + ETH_PLL_CTL0); + writel(0x927e0000, pll->base + ETH_PLL_CTL1); + writel(0xac5f49e5, pll->base + ETH_PLL_CTL2); + writel(0x00000000, pll->base + ETH_PLL_CTL3); + writel(0x00000000, pll->base + ETH_PLL_CTL4); + writel(0x20200000, pll->base + ETH_PLL_CTL5); + writel(0x0000c002, pll->base + ETH_PLL_CTL6); + writel(0x00000023, pll->base + ETH_PLL_CTL7); +} + +static const struct clk_ops g12a_ephy_pll_ops = { + .recalc_rate = g12a_ephy_pll_recalc_rate, + .is_enabled = g12a_ephy_pll_is_enabled, + .enable = g12a_ephy_pll_enable, + .disable = g12a_ephy_pll_disable, + .init = g12a_ephy_pll_init, +}; + +static int _g12a_enable_internal_mdio(struct g12a_mdio_mux *priv) +{ + int ret; + + /* Enable the phy clock */ + if (!priv->pll_is_enabled) { + ret = clk_prepare_enable(priv->pll); + if (ret) + return ret; + } + + priv->pll_is_enabled = true; + + /* Initialize ephy control */ + writel(EPHY_G12A_ID, priv->regs + ETH_PHY_CNTL0); + writel(FIELD_PREP(PHY_CNTL1_ST_MODE, 3) | + FIELD_PREP(PHY_CNTL1_ST_PHYADD, EPHY_DFLT_ADD) | + FIELD_PREP(PHY_CNTL1_MII_MODE, EPHY_MODE_RMII) | + PHY_CNTL1_CLK_EN | + PHY_CNTL1_CLKFREQ | + PHY_CNTL1_PHY_ENB, + priv->regs + ETH_PHY_CNTL1); + writel(PHY_CNTL2_USE_INTERNAL | + PHY_CNTL2_SMI_SRC_MAC | + PHY_CNTL2_RX_CLK_EPHY, + priv->regs + ETH_PHY_CNTL2); + + return 0; +} + +static int _g12a_enable_external_mdio(struct g12a_mdio_mux *priv) +{ + /* Reset the mdio bus mux */ + writel_relaxed(0x0, priv->regs + ETH_PHY_CNTL2); + + /* Disable the phy clock if enabled */ + if (priv->pll_is_enabled) { + clk_disable_unprepare(priv->pll); + priv->pll_is_enabled = false; + } + + return 0; +} + +static int g12a_mdio_switch_fn(int current_child, int desired_child, + void *data) +{ + struct device *dev = data; + struct g12a_mdio_mux *priv = dev_get_drvdata(dev); + + if (current_child == desired_child) + return 0; + + switch (desired_child) { + case MESON_G12A_MDIO_EXTERNAL_ID: + return _g12a_enable_external_mdio(priv); + case MESON_G12A_MDIO_INTERNAL_ID: + return _g12a_enable_internal_mdio(priv); + default: + return -EINVAL; + } +} + +static const struct of_device_id g12a_mdio_mux_match[] = { + { .compatible = "amlogic,g12a-mdio-mux", }, + {}, +}; +MODULE_DEVICE_TABLE(of, g12a_mdio_mux_match); + +static int g12a_ephy_glue_clk_register(struct device *dev) +{ + struct g12a_mdio_mux *priv = dev_get_drvdata(dev); + const char *parent_names[PLL_MUX_NUM_PARENT]; + struct clk_init_data init; + struct clk_mux *mux; + struct g12a_ephy_pll *pll; + struct clk *clk; + char *name; + int i; + + /* get the mux parents */ + for (i = 0; i < PLL_MUX_NUM_PARENT; i++) { + char in_name[8]; + + snprintf(in_name, sizeof(in_name), "clkin%d", i); + clk = devm_clk_get(dev, in_name); + if (IS_ERR(clk)) { + if (PTR_ERR(clk) != -EPROBE_DEFER) + dev_err(dev, "Missing clock %s\n", in_name); + return PTR_ERR(clk); + } + + parent_names[i] = __clk_get_name(clk); + } + + /* create the input mux */ + mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + if (!mux) + return -ENOMEM; + + name = kasprintf(GFP_KERNEL, "%s#mux", dev_name(dev)); + if (!name) + return -ENOMEM; + + init.name = name; + init.ops = &clk_mux_ro_ops; + init.flags = 0; + init.parent_names = parent_names; + init.num_parents = PLL_MUX_NUM_PARENT; + + mux->reg = priv->regs + ETH_PLL_CTL0; + mux->shift = __ffs(PLL_CTL0_SEL); + mux->mask = PLL_CTL0_SEL >> mux->shift; + mux->hw.init = &init; + + clk = devm_clk_register(dev, &mux->hw); + kfree(name); + if (IS_ERR(clk)) { + dev_err(dev, "failed to register input mux\n"); + return PTR_ERR(clk); + } + + /* create the pll */ + pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); + if (!pll) + return -ENOMEM; + + name = kasprintf(GFP_KERNEL, "%s#pll", dev_name(dev)); + if (!name) + return -ENOMEM; + + init.name = name; + init.ops = &g12a_ephy_pll_ops; + init.flags = 0; + parent_names[0] = __clk_get_name(clk); + init.parent_names = parent_names; + init.num_parents = 1; + + pll->base = priv->regs; + pll->hw.init = &init; + + clk = devm_clk_register(dev, &pll->hw); + kfree(name); + if (IS_ERR(clk)) { + dev_err(dev, "failed to register input mux\n"); + return PTR_ERR(clk); + } + + priv->pll = clk; + + return 0; +} + +static int g12a_mdio_mux_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + struct g12a_mdio_mux *priv; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + platform_set_drvdata(pdev, priv); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + priv->regs = devm_ioremap_resource(dev, res); + if (IS_ERR(priv->regs)) + return PTR_ERR(priv->regs); + + priv->pclk = devm_clk_get(dev, "pclk"); + if (IS_ERR(priv->pclk)) { + ret = PTR_ERR(priv->pclk); + if (ret != -EPROBE_DEFER) + dev_err(dev, "failed to get peripheral clock\n"); + return ret; + } + + /* Make sure the device registers are clocked */ + ret = clk_prepare_enable(priv->pclk); + if (ret) { + dev_err(dev, "failed to enable peripheral clock"); + return ret; + } + + /* Register PLL in CCF */ + ret = g12a_ephy_glue_clk_register(dev); + if (ret) + return ret; + + return mdio_mux_init(dev, dev->of_node, g12a_mdio_switch_fn, + &priv->mux_handle, dev, NULL); +} + +static int g12a_mdio_mux_remove(struct platform_device *pdev) +{ + struct g12a_mdio_mux *priv = platform_get_drvdata(pdev); + + mdio_mux_uninit(priv->mux_handle); + + if (priv->pll_is_enabled) + clk_disable_unprepare(priv->pll); + + clk_disable_unprepare(priv->pclk); + + return 0; +} + +static struct platform_driver g12a_mdio_mux_driver = { + .probe = g12a_mdio_mux_probe, + .remove = g12a_mdio_mux_remove, + .driver = { + .name = "g12a-mdio_mux", + .of_match_table = g12a_mdio_mux_match, + }, +}; +module_platform_driver(g12a_mdio_mux_driver); + +MODULE_DESCRIPTION("Amlogic G12a MDIO multiplexer driver"); +MODULE_AUTHOR("Jerome Brunet "); +MODULE_LICENSE("GPL v2"); From patchwork Thu Mar 14 14:01:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 10852909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A704F139A for ; Thu, 14 Mar 2019 14:02:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 870EC2A507 for ; Thu, 14 Mar 2019 14:02:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84F5A2A4BD; Thu, 14 Mar 2019 14:02:16 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 330132A4F9 for ; Thu, 14 Mar 2019 14:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jH26sUyFVhyit98W++HSWpnEXS38LsUxo59X4CvIPXM=; b=uMpkyI9WhbAZzE CE/OWhyJqlJOGaIp8mzs9/Ix+sEJUYw4B/crJUZ1GpKItTZO/T9JAygBGKrt4Gzd+ZTNLHOdc5oor OWV1mo5oAKgx0mp1bMeXCB2PdoxIJxhdayuMvepCQSiqEYEMWm2LrLUSovLyVtuWROlpSBBFwy2tN 4+NjGgUMEHvA8IHFHQ4m3TVqWcc/dDNozL7cZoiQuDvWVLrtYrlrj8gv+LfPnkqfakS1K+gmgw4tM IikzkwKWejltzGg5w682xutADarYP19lWT+ZRAKpZlS89pLkDOE3LwuMYGGCUzdxDYGwGRn6hHSWD 9TjT8TKEbFBr+VoSnsKw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Qw3-0000T7-P8; Thu, 14 Mar 2019 14:02:15 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Qw1-0000PM-Et for linux-amlogic@bombadil.infradead.org; Thu, 14 Mar 2019 14:02:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gSe5MubfDDFMdYdBkB1bnX6EGj1Asq+NDs4nOR6+nzA=; b=lYzzHowu9JIzFhpqMymIfplEha 7HDxSvMZp1BU/TMaP+Bo3qL9d1wHAtshsl/mADJN6f/2xASSfrWDDZnQMRyTpC95kv0qgXFOmdzdD ak0Sb57cw/L3yeCcVvPubpfTiI1FrRyYuC7hvTyq64SqSsHHieqnaNlg8bHHj050dVWA6Vg53GNYr k6gTebOtBfWVZVdN9crmjY36fUVG6v0MFGIT4zjZ484WeuWMUaPIDVQ/XI2bx3poEBtqRMDYxjgVy ICr7Tam3JjrlupV5J2Cnm9byuX9hokZvCQFJbS+8NtpOsHn6NLi+cGhY9n8GA4lr41T0e0cr5IYz2 T+TpE6kQ==; Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4Qvv-0006AO-Da for linux-amlogic@lists.infradead.org; Thu, 14 Mar 2019 14:02:11 +0000 Received: by mail-wr1-x442.google.com with SMTP id t5so5994415wri.7 for ; Thu, 14 Mar 2019 07:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gSe5MubfDDFMdYdBkB1bnX6EGj1Asq+NDs4nOR6+nzA=; b=I179FTGHDGQnhvAAcTCZkjupEZ7SeeRUFFIjl6S2EabiorJXAHBhtgYjdMKF/Z5rmp +eWJv3f1JZOpJ9f45HNffGXG8X+oyHLYOj1bOtC46hQ1T/8i3FQ/EXF5xCAafTv892Zb aIGfJbXtUX4BIPDBhDKp1Io7klF4yRWMhQSevipssy8AxjuDySSX4COz4R8YUeR+mn/S sOV/YGgukfZt9pBZojGeFlsmty93cBUxtBL8JM8CXumeV8/JV/CuJ7ZoP0D/0vuOrKgc KjSXaMWM9GmqT7p0SzzciTSXWpun9T+2+mclRiLftICwDmQWna3JcVjNZV+s6zMh2I2D mSuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gSe5MubfDDFMdYdBkB1bnX6EGj1Asq+NDs4nOR6+nzA=; b=UPzX0LrEoOk8Isb5EJ9OM4XvKjEMGDdM94JwIsRnDiZufUxPYQgb5e8B9LjbUP5Y2U t79v5JBG2f1oc+5tvaJ0xo3O9mRYkOuF/nlT+TEmiXTOofzddnkhEn1QrGH0jfKkIXd2 XbI51BzSiWXr+Z/wo0LPc4+iadX/ABV8NHxwnVIux6nwjx/zTqFpWocz6eWV6tsqBets 2DBaM2nIzqtT4MZg6WMcKdzCp5BOEugwecXiCeWQSkmpPttAest+M/wxu9lxXd5HzowR zXpgrh4YOfUO4vziVVnOzoiaQ0u7rVSiMYij27CtjxIkVZCK5KKsi++tTIpDoFVE5cT5 rwYQ== X-Gm-Message-State: APjAAAWrlkpWmRppGUvv6bDOIwZajF8H+rIrjD8Vs32PyrKA3C8ZoBiw /FB24p7l1Rk7O56eKz2YI/x8cg== X-Google-Smtp-Source: APXvYqxOsW0L02QZtLWq3QISHge5mO3XVz+uW+KzndOm8Q1A9D4vhbaWTD5xPJI/b38LcjKpcEsIkw== X-Received: by 2002:adf:ba84:: with SMTP id p4mr31965743wrg.156.1552572118395; Thu, 14 Mar 2019 07:01:58 -0700 (PDT) Received: from boomer.local ([2a01:e34:eeb6:4690:106b:bae3:31ed:7561]) by smtp.googlemail.com with ESMTPSA id y7sm2661051wmi.34.2019.03.14.07.01.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 07:01:57 -0700 (PDT) From: Jerome Brunet To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , "David S. Miller" , Kevin Hilman Subject: [PATCH net-next 3/3] net: phy: meson-gxl: add g12a support Date: Thu, 14 Mar 2019 15:01:35 +0100 Message-Id: <20190314140135.19184-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190314140135.19184-1-jbrunet@baylibre.com> References: <20190314140135.19184-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_100207_487284_D65778E2 X-CRM114-Status: GOOD ( 11.71 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jerome Brunet Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The g12a SoC family uses the type of internal PHY that was used on the gxl family. The quirks of gxl family, like the LPA register corruption, appear to have been resolved on this new SoC generation. Signed-off-by: Jerome Brunet --- drivers/net/phy/meson-gxl.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/phy/meson-gxl.c b/drivers/net/phy/meson-gxl.c index 0eec2913c289..49cad0f4c79b 100644 --- a/drivers/net/phy/meson-gxl.c +++ b/drivers/net/phy/meson-gxl.c @@ -237,11 +237,25 @@ static struct phy_driver meson_gxl_phy[] = { .config_intr = meson_gxl_config_intr, .suspend = genphy_suspend, .resume = genphy_resume, + }, { + .phy_id = 0x01803301, + .phy_id_mask = 0xffffffff, + .name = "Meson G12A Internal PHY", + .features = PHY_BASIC_FEATURES, + .flags = PHY_IS_INTERNAL, + .soft_reset = genphy_soft_reset, + .aneg_done = genphy_aneg_done, + .read_status = genphy_read_status, + .ack_interrupt = meson_gxl_ack_interrupt, + .config_intr = meson_gxl_config_intr, + .suspend = genphy_suspend, + .resume = genphy_resume, }, }; static struct mdio_device_id __maybe_unused meson_gxl_tbl[] = { { 0x01814400, 0xfffffff0 }, + { 0x01803301, 0xffffffff }, { } };