From patchwork Thu Aug 27 20:21:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_Gonz=C3=A1lez_Cabanelas?= X-Patchwork-Id: 1352900 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=bBkqCH4P; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rm41vsLE; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BcvQt3K7Xz9sT6 for ; Fri, 28 Aug 2020 06:27:02 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=81qqRU7KDVoV9xvFMTFN+LBR4ixtAfierhXSTLnVXSc=; b=bBkqCH4PyP4786fdbK6B55IIr3 qE3Y438f6ucTn3w2Qnl75gBuupT8RFnpVGjhkDwlBb7AsOPZ7jURhrn43ZbqXxnw9CtaSy7hv5f5Y z1rOuAyBoR5EN89XYZT2ZBD3CsRSav1udQLN6Efzi4dQNqeYT3wrLc8Fvy33+YQMIlCVs4i0PNmt3 SIPV3GnwT2qYrZI+2qJby6H4H8JjVOXUDv8wj1CsYWnsITU1crmoo0NhKjiLUMoRWsE+RlH1MHFAb 00Bln+K2XmYnSA9yLFD7tSx0uAGKpsh7TTSVw1c450EXJwLCvDgKqDZ0X/p4F5SNPY11g6Mq4zg6A TnjkWq5A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBOSC-0007cF-DS; Thu, 27 Aug 2020 20:25:00 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBOS9-0007bE-34 for openwrt-devel@lists.openwrt.org; Thu, 27 Aug 2020 20:24:57 +0000 Received: by mail-wm1-x343.google.com with SMTP id k20so6205420wmi.5 for ; Thu, 27 Aug 2020 13:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=sAj1T1ZLq6tpxye0lzBzM4muCbWFt+TaW26Y5yryvdo=; b=rm41vsLEMBt+G4snd8fCBPM6M/snI0PJs93hLXMWJoDFz5EskqdtixwGfJm4fH3kGc c8XaJSouL3qjEgLHpUlU8E3IjO+NG4XFM5x6/sRfZlaf5ln3PcZDBYf/JaOWuYqq5d5i MPbQ79VpFwcXZgYeB6y42rh6XKCYB0dEdsILzL7xXIjT2LoitWLypKp1wyDMhcm0L8G5 EwMBOm+kT/nlZSW0rNOqq31zVs2Q4cMArbFs37brY3hDxqbvK1w3p4X2Xq1KhZTH9gR2 gEEHRf+moKM/r7MqEhFbDxNtxO/gXnhOX2kXdq0v0LEqIHYTsRwV66EM2KGlUA4k7vqg EsDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=sAj1T1ZLq6tpxye0lzBzM4muCbWFt+TaW26Y5yryvdo=; b=kZofjzaVWep3De1/0s5VPW3dgYKNKHbHFW74Z8msjcHiXdn1VmZquDAhOV6IEW18+J L0AsSoHVMgBxfU8eLqD1Wt4tEJ43vt42rZDp5iFZQPANOC8+/D+LkZ0hTB6C7uUuJ2NF YVYyan4uiOX+1+QF4wu06H0MHf2PrqrmpEvT0atzqYieS2yCFcXwNyzBd55Hka/BJyyI a+jloMEXPpay+trWfytQXeseHNo9O7Tl/VtPTvYW3B6Xcu3FqN9G6vXkXQbzsyX8Nr/m Mc6r4x/Ic0UtUxem2FAZ+L8vVX2gydf7NuVFlYZCouBc/IoJG1rahrFzNZfwVfgdZ5xZ KhbA== X-Gm-Message-State: AOAM532aV2Ou4XSn/WJIopTs7mkK5vS+SL4+DrlT+ETkw24ou8kPW9v5 7hY8J8S6q1X4Da6x3I31zImTwGQMANc= X-Google-Smtp-Source: ABdhPJz378uICEQqjDKiiko/q6EhGKxw4QOf2fyedVfT7xHAgQzqxezTSzBm7faj5O3JLId1B5ICxQ== X-Received: by 2002:a7b:cbd8:: with SMTP id n24mr513242wmi.47.1598559894091; Thu, 27 Aug 2020 13:24:54 -0700 (PDT) Received: from tool.localnet ([213.177.193.103]) by smtp.gmail.com with ESMTPSA id h5sm8536865wrc.97.2020.08.27.13.24.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 13:24:53 -0700 (PDT) From: Daniel =?iso-8859-1?q?Gonz=E1lez?= Cabanelas To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/2] mvebu: backport linkstation-poweroff upstream driver Date: Thu, 27 Aug 2020 22:21:14 +0200 Message-ID: <1828686.9elolEQQZP@tool> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200827_162457_147623_0282FE66 X-CRM114-Status: GOOD ( 17.21 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [dgcbueu[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Backport the Linkstation poweroff driver from the kernel upstream (commit a7f79f99541ef) This driver is required by the Buffalo LinkStation LS421DE for a correct power off operation. It also allows to use the WoL feature. Signed-off-by: Daniel González Cabanelas --- package/kernel/linux/modules/other.mk | 21 +++ .../030-linkstation-poweroff.patch | 177 ++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 target/linux/mvebu/patches-5.4/030-linkstation-poweroff.patch diff --git a/package/kernel/linux/modules/other.mk b/package/kernel/linux/modules/other.mk index 6eb9404837..683d539be4 100644 --- a/package/kernel/linux/modules/other.mk +++ b/package/kernel/linux/modules/other.mk @@ -329,6 +329,27 @@ endef $(eval $(call KernelPackage,gpio-amd-fch)) +define KernelPackage/linkstation-poweroff + SUBMENU:=$(OTHER_MENU) + DEPENDS:=@TARGET_mvebu + TITLE:=Buffalo LinkStation power off driver + KCONFIG:= \ + CONFIG_POWER_RESET=y \ + CONFIG_POWER_RESET_LINKSTATION \ + CONFIG_POWER_RESET_QNAP=n + + FILES:=$(LINUX_DIR)/drivers/power/reset/linkstation-poweroff.ko + AUTOLOAD:=$(call AutoLoad,31,linkstation-poweroff,1) +endef + +define KernelPackage/linkstation-poweroff/description + This driver supports turning off some Buffalo LinkStations by + setting an output pin at the ethernet PHY to the correct state. + It also makes the device compatible with the WoL function. + Say Y here if you have a Buffalo LinkStation LS421D/E. +endef + +$(eval $(call KernelPackage,linkstation-poweroff)) define KernelPackage/ppdev SUBMENU:=$(OTHER_MENU) diff --git a/target/linux/mvebu/patches-5.4/030-linkstation-poweroff.patch b/target/linux/mvebu/patches-5.4/030-linkstation-poweroff.patch new file mode 100644 index 0000000000..983b1de918 --- /dev/null +++ b/target/linux/mvebu/patches-5.4/030-linkstation-poweroff.patch @@ -0,0 +1,177 @@ +--- a/drivers/power/reset/Kconfig ++++ b/drivers/power/reset/Kconfig +@@ -99,6 +99,17 @@ + help + Reboot support for Hisilicon boards. + ++config POWER_RESET_LINKSTATION ++ tristate "Buffalo LinkStation power-off driver" ++ depends on ARCH_MVEBU || COMPILE_TEST ++ depends on OF_MDIO && PHYLIB ++ help ++ This driver supports turning off some Buffalo LinkStations by ++ setting an output pin at the ethernet PHY to the correct state. ++ It also makes the device compatible with the WoL function. ++ ++ Say Y here if you have a Buffalo LinkStation LS421D/E. ++ + config POWER_RESET_MSM + bool "Qualcomm MSM power-off driver" + depends on ARCH_QCOM +--- a/drivers/power/reset/Makefile ++++ b/drivers/power/reset/Makefile +@@ -10,6 +10,7 @@ + obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o + obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o + obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o ++obj-${CONFIG_POWER_RESET_LINKSTATION} += linkstation-poweroff.o + obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o + obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o + obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o +--- a/dev/null ++++ b/drivers/power/reset/linkstation-poweroff.c +@@ -0,0 +1,144 @@ ++// SPDX-License-Identifier: GPL-2.0 ++/* ++ * LinkStation power off restart driver ++ * Copyright (C) 2020 Daniel González Cabanelas ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++/* Defines from the eth phy Marvell driver */ ++#define MII_MARVELL_COPPER_PAGE 0 ++#define MII_MARVELL_LED_PAGE 3 ++#define MII_MARVELL_WOL_PAGE 17 ++#define MII_MARVELL_PHY_PAGE 22 ++ ++#define MII_PHY_LED_CTRL 16 ++#define MII_88E1318S_PHY_LED_TCR 18 ++#define MII_88E1318S_PHY_WOL_CTRL 16 ++#define MII_M1011_IEVENT 19 ++ ++#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7) ++#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15) ++#define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12) ++#define LED2_FORCE_ON (0x8 << 8) ++#define LEDMASK GENMASK(11,8) ++ ++static struct phy_device *phydev; ++ ++static void mvphy_reg_intn(u16 data) ++{ ++ int rc = 0, saved_page; ++ ++ saved_page = phy_select_page(phydev, MII_MARVELL_LED_PAGE); ++ if (saved_page < 0) ++ goto err; ++ ++ /* Force manual LED2 control to let INTn work */ ++ __phy_modify(phydev, MII_PHY_LED_CTRL, LEDMASK, LED2_FORCE_ON); ++ ++ /* Set the LED[2]/INTn pin to the required state */ ++ __phy_modify(phydev, MII_88E1318S_PHY_LED_TCR, ++ MII_88E1318S_PHY_LED_TCR_FORCE_INT, ++ MII_88E1318S_PHY_LED_TCR_INTn_ENABLE | data); ++ ++ if (!data) { ++ /* Clear interrupts to ensure INTn won't be holded in high state */ ++ __phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_MARVELL_COPPER_PAGE); ++ __phy_read(phydev, MII_M1011_IEVENT); ++ ++ /* If WOL was enabled and a magic packet was received before powering ++ * off, we won't be able to wake up by sending another magic packet. ++ * Clear WOL status. ++ */ ++ __phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_MARVELL_WOL_PAGE); ++ __phy_set_bits(phydev, MII_88E1318S_PHY_WOL_CTRL, ++ MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS); ++ } ++err: ++ rc = phy_restore_page(phydev, saved_page, rc); ++ if (rc < 0) ++ dev_err(&phydev->mdio.dev, "Write register failed, %d\n", rc); ++ ++ if (!data) { ++ /* Slow down the PHY to save energy */ ++ rc= phy_speed_down(phydev, false); ++ if (rc < 0) ++ dev_err(&phydev->mdio.dev, "PHY speed down failed, %d\n", rc); ++ } ++} ++ ++static int linkstation_reboot_notifier(struct notifier_block *nb, ++ unsigned long action, void *unused) ++{ ++ if (action == SYS_RESTART) ++ mvphy_reg_intn(MII_88E1318S_PHY_LED_TCR_FORCE_INT); ++ ++ return NOTIFY_DONE; ++} ++ ++static struct notifier_block linkstation_reboot_nb = { ++ .notifier_call = linkstation_reboot_notifier, ++}; ++ ++static void linkstation_poweroff(void) ++{ ++ unregister_reboot_notifier(&linkstation_reboot_nb); ++ mvphy_reg_intn(0); ++ ++ kernel_restart("Power off"); ++} ++ ++static const struct of_device_id ls_poweroff_of_match[] = { ++ { .compatible = "buffalo,ls421d" }, ++ { .compatible = "buffalo,ls421de" }, ++ { }, ++}; ++ ++static int __init linkstation_poweroff_init(void) ++{ ++ struct mii_bus *bus; ++ struct device_node *dn; ++ ++ dn = of_find_matching_node(NULL, ls_poweroff_of_match); ++ if (!dn) ++ return -ENODEV; ++ of_node_put(dn); ++ ++ dn = of_find_node_by_name(NULL, "mdio"); ++ if (!dn) ++ return -ENODEV; ++ ++ bus = of_mdio_find_bus(dn); ++ of_node_put(dn); ++ if (!bus) ++ return -EPROBE_DEFER; ++ ++ phydev = phy_find_first(bus); ++ if (!phydev) ++ return -EPROBE_DEFER; ++ ++ register_reboot_notifier(&linkstation_reboot_nb); ++ pm_power_off = linkstation_poweroff; ++ ++ pr_info("LinkStation power off driver registered\n"); ++ return 0; ++} ++ ++static void __exit linkstation_poweroff_exit(void) ++{ ++ pm_power_off = NULL; ++ unregister_reboot_notifier(&linkstation_reboot_nb); ++} ++ ++module_init(linkstation_poweroff_init); ++module_exit(linkstation_poweroff_exit); ++ ++MODULE_AUTHOR("Daniel González Cabanelas "); ++MODULE_DESCRIPTION("LinkStation power off driver"); ++MODULE_LICENSE("GPL v2");