From patchwork Tue Aug 13 19:11:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 1146609 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="WyIrrUoU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 467Mlk2dSZz9sNx for ; Wed, 14 Aug 2019 05:12:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbfHMTL6 (ORCPT ); Tue, 13 Aug 2019 15:11:58 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36588 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbfHMTL5 (ORCPT ); Tue, 13 Aug 2019 15:11:57 -0400 Received: by mail-pg1-f195.google.com with SMTP id l21so51738484pgm.3 for ; Tue, 13 Aug 2019 12:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F5AyXCx/QmI9rH4K6aLYamGqeaWZ1S6PDC5Nf41bKkw=; b=WyIrrUoUSkNtHBI9z7wgaA6fP/WFma1wFLGLMPg/xMvcK91Ci0rniw350VSEV3p88K 4VORSA1Wn7T06D+JBLhklkIUi+3LXgvFSSQwpyrLsm22zykF/i1Fj5tEupn+EQc6Vq86 DOCPK8lgV8FgIsSan0/coGwMLEFlFO8ohJAkA= 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=F5AyXCx/QmI9rH4K6aLYamGqeaWZ1S6PDC5Nf41bKkw=; b=G0Kl4O/KbiHu9GOHS8yj3K0PisYSBdIo+uP6xfSYbKBAc+9wRgqtZ4uIcZcRZuzeaq gh7160lU2/n9V3rhp5QY/Ky2IIm35V/NYnJSQtv5WuyHCW3N/81MC39G65SwJE9tREpW 0oXf+5eWQHjHNNpotua58qOS9xUpUJzLxSf2JGVR6k/+enp8SzfbQMAp/hS8BtZZje/X m45KbG07pNC/8XI3PO7xj+UJcp52TaLRBOZ0gdfHb0XYs9d5KtQ1qXAou/MN3ctEuYV+ xabscNXqVg4a5q5tGVM5MeYWKOFq0i3RC6v+YKXuvcLxMvfINeL8AThRs6OdbyfXxUJU pWyg== X-Gm-Message-State: APjAAAXdthnSDdr3AKOHzvILPKWHlxz0Hli64UsCRP6Y0JaHBuSdv6da UGoMpT7zdNExd6SXOZqLNHwOcw== X-Google-Smtp-Source: APXvYqwePoQk7GtsasNE2CHPI7WEOyjvLAhhK8sOQJR6FcIy5NGuw+eiY4/p+PQAE7XhzEHVCHYlwg== X-Received: by 2002:a62:cec4:: with SMTP id y187mr42137245pfg.84.1565723516634; Tue, 13 Aug 2019 12:11:56 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id e13sm2836023pff.181.2019.08.13.12.11.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Aug 2019 12:11:56 -0700 (PDT) From: Matthias Kaehlcke To: "David S . Miller" , Rob Herring , Mark Rutland , Andrew Lunn , Florian Fainelli , Heiner Kallweit Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Douglas Anderson , Matthias Kaehlcke Subject: [PATCH v6 1/4] dt-bindings: net: phy: Add subnode for LED configuration Date: Tue, 13 Aug 2019 12:11:44 -0700 Message-Id: <20190813191147.19936-2-mka@chromium.org> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog In-Reply-To: <20190813191147.19936-1-mka@chromium.org> References: <20190813191147.19936-1-mka@chromium.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The LED behavior of some Ethernet PHYs is configurable. Add an optional 'leds' subnode with a child node for each LED to be configured. The binding aims to be compatible with the common LED binding (see devicetree/bindings/leds/common.txt). A LED can be configured to be: - 'on' when a link is active, some PHYs allow configuration for certain link speeds speeds - 'off' - blink on RX/TX activity, some PHYs allow configuration for certain link speeds For the configuration to be effective it needs to be supported by the hardware and the corresponding PHY driver. Suggested-by: Andrew Lunn Signed-off-by: Matthias Kaehlcke Reviewed-by: Andrew Lunn --- Changes in v6: - none Changes in v5: - renamed triggers from 'phy_link__active' to 'phy-link-' - added entries for 'phy-link--activity' - added 'phy-link' and 'phy-link-activity' for triggers with any link speed - added entry for trigger 'none' Changes in v4: - patch added to the series --- .../devicetree/bindings/net/ethernet-phy.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Documentation/devicetree/bindings/net/ethernet-phy.yaml index f70f18ff821f..98ba320f828b 100644 --- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml @@ -153,6 +153,50 @@ properties: Delay after the reset was deasserted in microseconds. If this property is missing the delay will be skipped. +patternProperties: + "^leds$": + type: object + description: + Subnode with configuration of the PHY LEDs. + + patternProperties: + "^led@[0-9]+$": + type: object + description: + Subnode with the configuration of a single PHY LED. + + properties: + reg: + description: + The ID number of the LED, typically corresponds to a hardware ID. + $ref: "/schemas/types.yaml#/definitions/uint32" + + linux,default-trigger: + description: + This parameter, if present, is a string specifying the trigger + assigned to the LED. Supported triggers are: + "none" - LED will be solid off + "phy-link" - LED will be solid on when a link is active + "phy-link-10m" - LED will be solid on when a 10Mb/s link is active + "phy-link-100m" - LED will be solid on when a 100Mb/s link is active + "phy-link-1g" - LED will be solid on when a 1Gb/s link is active + "phy-link-10g" - LED will be solid on when a 10Gb/s link is active + "phy-link-activity" - LED will be on when link is active and blink + off with activity. + "phy-link-10m-activity" - LED will be on when 10Mb/s link is active + and blink off with activity. + "phy-link-100m-activity" - LED will be on when 100Mb/s link is + active and blink off with activity. + "phy-link-1g-activity" - LED will be on when 1Gb/s link is active + and blink off with activity. + "phy-link-10g-activity" - LED will be on when 10Gb/s link is active + and blink off with activity. + + $ref: "/schemas/types.yaml#/definitions/string" + + required: + - reg + required: - reg @@ -173,5 +217,20 @@ examples: reset-gpios = <&gpio1 4 1>; reset-assert-us = <1000>; reset-deassert-us = <2000>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + linux,default-trigger = "phy-link-1g"; + }; + + led@1 { + reg = <1>; + linux,default-trigger = "phy-link-100m-activity"; + }; + }; }; }; From patchwork Tue Aug 13 19:11:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 1146610 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="W2aKmxcS"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 467Mlq2KKYz9sNy for ; Wed, 14 Aug 2019 05:12:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726751AbfHMTMD (ORCPT ); Tue, 13 Aug 2019 15:12:03 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33271 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbfHMTL6 (ORCPT ); Tue, 13 Aug 2019 15:11:58 -0400 Received: by mail-pl1-f193.google.com with SMTP id c14so49570997plo.0 for ; Tue, 13 Aug 2019 12:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xf+xGPCkE88V8f+N3LFOWyEFFd8oY99DHKFNSz59Vzc=; b=W2aKmxcSCRDgnJ5yif0VeFy5UM0A2nMLW8Ww4W+za6uQAEK6a6ecgN6WtgatGIHIuK fS0RqyQOCTSKVi3s01NkESYy5JI/R/drXDnVwVHmONwTD/jRtYjmHd4dP3ZrxZzy6T8z ui5KNy/2buIYOx4CJm1A2CPuWWpJKlLcIDmW0= 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=Xf+xGPCkE88V8f+N3LFOWyEFFd8oY99DHKFNSz59Vzc=; b=taab9mi1lfU2v1UW/9gRyu3WHNUfSd2UlkTNhK/ZnT/KdE/DQqjPX0WEjcI+Nlu1eB r8eWEkzLtMk0Z7bpKdYXbIJNU1L+ZD203yOOMg5sNKb0pwg96IN4UFUMyqOKgRtNRHKZ nkTQAhcDJFMIsUulyABoQGAZenhmY5Ko74Y6LXVr0+23G6J0BqYjtiaPtrcvO78TdCn2 7tv8vk+xLMQpUvb/tOpIyzu7R4aG5RI5x8EjKXc+wNnHLMaRkm9P7tUNfrb1Ji0Jq3je ychCsGyv/x5NOw5h5lFP04k2vW5kTkDZZUl7KcE1Fv/KiS/RK+Kk/RLOkm5GPa+p+g1Y V55g== X-Gm-Message-State: APjAAAVubJi3CcJOyg8kRZpkZKb7vdfEiHY+Wgd+adibIMJtilYRs0RB VPsJgwSvmZT/VvlJ9EmEDizXMg== X-Google-Smtp-Source: APXvYqyV3re8AhD0pKkRI8gLv84rBCbOMKsMXNv3ANRPsZAt47VPftjglh04U0u15HLfgoW5U0dIUw== X-Received: by 2002:a17:902:b090:: with SMTP id p16mr17834984plr.93.1565723518007; Tue, 13 Aug 2019 12:11:58 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id p8sm10245846pfq.129.2019.08.13.12.11.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Aug 2019 12:11:57 -0700 (PDT) From: Matthias Kaehlcke To: "David S . Miller" , Rob Herring , Mark Rutland , Andrew Lunn , Florian Fainelli , Heiner Kallweit Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Douglas Anderson , Matthias Kaehlcke Subject: [PATCH v6 2/4] net: phy: Add support for generic LED configuration through the DT Date: Tue, 13 Aug 2019 12:11:45 -0700 Message-Id: <20190813191147.19936-3-mka@chromium.org> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog In-Reply-To: <20190813191147.19936-1-mka@chromium.org> References: <20190813191147.19936-1-mka@chromium.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For PHYs with a device tree node look for LED trigger configuration using the generic binding, if it exists try to apply it via the new driver hook .config_led. Signed-off-by: Matthias Kaehlcke Reviewed-by: Andrew Lunn --- Changes in v6: - delete unnecessary of_node_put() inside for_each_child_of_node() loop - use continue instead of goto in of_phy_config_leds() - check return value of ->config_led() and print a warning if !0 Changes in v5: - add callback to configure a LED to the PHY driver, instead of having the driver retrieve the DT data - use new trigger names - added support for trigger 'none' - release DT nodes after use - renamed 'PHY_LED_LINK_*' to 'PHY_LED_TRIGGER_LINK_*' - added anonymous struct to struct phy_led_config to track 'activity' in a separate flag. this could be changed to 'flags' if needed/desired. - updated commit message (previous subject was 'net: phy: Add function to retrieve LED configuration from the DT') Changes in v4: - patch added to the series --- drivers/net/phy/phy_device.c | 72 ++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 22 +++++++++++ 2 files changed, 94 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 6b5cb87f3866..80315777ae67 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -29,6 +29,7 @@ #include #include #include +#include #include MODULE_DESCRIPTION("PHY library"); @@ -1064,6 +1065,75 @@ static int phy_poll_reset(struct phy_device *phydev) return 0; } +static void of_phy_config_leds(struct phy_device *phydev) +{ + struct device_node *np, *child; + struct phy_led_config cfg; + const char *trigger; + int ret; + + if (!IS_ENABLED(CONFIG_OF_MDIO) || !phydev->drv->config_led) + return; + + np = of_find_node_by_name(phydev->mdio.dev.of_node, "leds"); + if (!np) + return; + + for_each_child_of_node(np, child) { + u32 led; + + if (of_property_read_u32(child, "reg", &led)) + continue; + + ret = of_property_read_string(child, "linux,default-trigger", + &trigger); + if (ret) + trigger = "none"; + + memset(&cfg, 0, sizeof(cfg)); + + if (!strcmp(trigger, "none")) { + cfg.trigger.t = PHY_LED_TRIGGER_NONE; + } else if (!strcmp(trigger, "phy-link")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK; + } else if (!strcmp(trigger, "phy-link-10m")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_10M; + } else if (!strcmp(trigger, "phy-link-100m")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_100M; + } else if (!strcmp(trigger, "phy-link-1g")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_1G; + } else if (!strcmp(trigger, "phy-link-10g")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_10G; + } else if (!strcmp(trigger, "phy-link-activity")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK; + cfg.trigger.activity = true; + } else if (!strcmp(trigger, "phy-link-10m-activity")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_10M; + cfg.trigger.activity = true; + } else if (!strcmp(trigger, "phy-link-100m-activity")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_100M; + cfg.trigger.activity = true; + } else if (!strcmp(trigger, "phy-link-1g-activity")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_1G; + cfg.trigger.activity = true; + } else if (!strcmp(trigger, "phy-link-10g-activity")) { + cfg.trigger.t = PHY_LED_TRIGGER_LINK_10G; + cfg.trigger.activity = true; + } else { + phydev_warn(phydev, "trigger '%s' for LED%d is invalid\n", + trigger, led); + continue; + } + + ret = phydev->drv->config_led(phydev, led, &cfg); + if (ret) + phydev_warn(phydev, "trigger '%s' for LED%d not supported\n", + trigger, led); + } + + of_node_put(np); +} + int phy_init_hw(struct phy_device *phydev) { int ret = 0; @@ -1087,6 +1157,8 @@ int phy_init_hw(struct phy_device *phydev) if (phydev->drv->config_init) ret = phydev->drv->config_init(phydev); + of_phy_config_leds(phydev); + return ret; } EXPORT_SYMBOL(phy_init_hw); diff --git a/include/linux/phy.h b/include/linux/phy.h index 462b90b73f93..3a07390fc5e9 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -325,6 +325,24 @@ struct phy_c45_device_ids { u32 device_ids[8]; }; +/* Triggers for PHY LEDs */ +enum phy_led_trigger { + PHY_LED_TRIGGER_NONE, + PHY_LED_TRIGGER_LINK, + PHY_LED_TRIGGER_LINK_10M, + PHY_LED_TRIGGER_LINK_100M, + PHY_LED_TRIGGER_LINK_1G, + PHY_LED_TRIGGER_LINK_10G, +}; + +/* Configuration of a single PHY LED */ +struct phy_led_config { + struct { + enum phy_led_trigger t; + bool activity; + } trigger; +}; + /* phy_device: An instance of a PHY * * drv: Pointer to the driver for this PHY instance @@ -626,6 +644,10 @@ struct phy_driver { struct ethtool_tunable *tuna, const void *data); int (*set_loopback)(struct phy_device *dev, bool enable); + + /* Configure a PHY LED */ + int (*config_led)(struct phy_device *dev, int led, + struct phy_led_config *cfg); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv) From patchwork Tue Aug 13 19:11:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 1146611 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="BwfIYO4z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 467Mlw1W9Bz9sP8 for ; Wed, 14 Aug 2019 05:12:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbfHMTML (ORCPT ); Tue, 13 Aug 2019 15:12:11 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42248 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbfHMTMA (ORCPT ); Tue, 13 Aug 2019 15:12:00 -0400 Received: by mail-pg1-f194.google.com with SMTP id p3so1440283pgb.9 for ; Tue, 13 Aug 2019 12:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A5T2awAbmTODH86MSd7SOI9tSGo/wo5wEB+/mqImgxg=; b=BwfIYO4zc4aWUmrI9UD8lz5ygEX8EVRpdxerDlRtdyz2XP4BYiNkSSfDBHqFlUXw9k 0F+e02hsK+86/zfo8/RjjGW7tujQkUySggNYtSSDPsUsCvU6uqjiBl4GLE5BBc+ZSRfC SnhmjxzUhp+LGmyn7K6Dg1+FJL4ieXqYUcDN0= 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=A5T2awAbmTODH86MSd7SOI9tSGo/wo5wEB+/mqImgxg=; b=L/AcxxOing/MFo5xBOPnVG2gnpP6hUZ+D4bJr1eS9glA0lvYtu0SOFk5bbtJCvbSWx 0fAiNsioox3Qw5Ou1JpkbjjYs5yjzrlE81Jde52S4t7pK+pfDgjuQFXKUJqLXsVllVTK MwqbSvb3fnXbf8hwWkq9IOZM8zeIa+9kQyCidPnTJfBGOmHZmvrf8aXbunZWyCKhj0Eu m0txUPBSDM/fbgg8ZjVLJ67e3hLrzwse5hRPJZGrJjyHyxKmt1KEN0fVhh49ZySvIw2i 2wEQBpsUXvcymVEd5tA0wzz058puOD9t6ij2+Ueg8v9jRCIkDLMnTYj6+Ls3I5INtzpm 1Z/g== X-Gm-Message-State: APjAAAXN44E+g1em/zGIgujDDFqvojlQL1vgcI53Yj0jYsmCy4gF3IvI uuCLWyoHNAmLfVAa52Iyjw4mcOgexMU= X-Google-Smtp-Source: APXvYqw9ePu/VxnJMlXN5kUdq67hALwKfkwbmoCzjB0VdgjhNfAO9qJZ0Sp3c1dphks1gDrVbpqZyQ== X-Received: by 2002:a65:684c:: with SMTP id q12mr33364685pgt.405.1565723519347; Tue, 13 Aug 2019 12:11:59 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id p10sm6806603pff.132.2019.08.13.12.11.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Aug 2019 12:11:58 -0700 (PDT) From: Matthias Kaehlcke To: "David S . Miller" , Rob Herring , Mark Rutland , Andrew Lunn , Florian Fainelli , Heiner Kallweit Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Douglas Anderson , Matthias Kaehlcke Subject: [PATCH v6 3/4] net: phy: realtek: Add helpers for accessing RTL8211x extension pages Date: Tue, 13 Aug 2019 12:11:46 -0700 Message-Id: <20190813191147.19936-4-mka@chromium.org> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog In-Reply-To: <20190813191147.19936-1-mka@chromium.org> References: <20190813191147.19936-1-mka@chromium.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some RTL8211x PHYs have extension pages, which can be accessed after selecting a page through a custom method. Add a function to modify bits in a register of an extension page and a helper for selecting an ext page. Use rtl8211x_modify_ext_paged() in rtl8211e_config_init() instead of doing things 'manually'. Signed-off-by: Matthias Kaehlcke Reviewed-by: Andrew Lunn --- Changes in v6: - none Changes in v5: - renamed 'rtl8211e__ext_page' to 'rtl8211x__ext_page' - updated commit message Changes in v4: - don't add constant RTL8211E_EXT_PAGE, it's only used once, use a literal instead - pass 'oldpage' to phy_restore_page() in rtl8211e_select_ext_page(), not 'page' - return 'oldpage' in rtl8211e_select_ext_page() - use __phy_modify() in rtl8211e_modify_ext_paged() instead of reimplementing __phy_modify_changed() - in rtl8211e_modify_ext_paged() return directly when rtl8211e_select_ext_page() fails Changes in v3: - use the new function in rtl8211e_config_init() instead of doing things 'manually' - use existing RTL8211E_EXT_PAGE instead of adding a new define - updated commit message Changes in v2: - use phy_select_page() and phy_restore_page(), get rid of rtl8211e_restore_page() - s/rtl821e_select_ext_page/rtl8211e_select_ext_page/ - updated commit message --- drivers/net/phy/realtek.c | 47 +++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index a669945eb829..a5b3708dc4d8 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -53,6 +53,36 @@ static int rtl821x_write_page(struct phy_device *phydev, int page) return __phy_write(phydev, RTL821x_PAGE_SELECT, page); } +static int rtl8211x_select_ext_page(struct phy_device *phydev, int page) +{ + int ret, oldpage; + + oldpage = phy_select_page(phydev, 7); + if (oldpage < 0) + return oldpage; + + ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, page); + if (ret) + return phy_restore_page(phydev, oldpage, ret); + + return oldpage; +} + +static int rtl8211x_modify_ext_paged(struct phy_device *phydev, int page, + u32 regnum, u16 mask, u16 set) +{ + int ret = 0; + int oldpage; + + oldpage = rtl8211x_select_ext_page(phydev, page); + if (oldpage < 0) + return oldpage; + + ret = __phy_modify(phydev, regnum, mask, set); + + return phy_restore_page(phydev, oldpage, ret); +} + static int rtl8201_ack_interrupt(struct phy_device *phydev) { int err; @@ -184,7 +214,6 @@ static int rtl8211f_config_init(struct phy_device *phydev) static int rtl8211e_config_init(struct phy_device *phydev) { - int ret = 0, oldpage; u16 val; /* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */ @@ -213,19 +242,9 @@ static int rtl8211e_config_init(struct phy_device *phydev) * 2 = RX Delay, 1 = TX Delay, 0 = SELRGV (see original PHY datasheet * for details). */ - oldpage = phy_select_page(phydev, 0x7); - if (oldpage < 0) - goto err_restore_page; - - ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, 0xa4); - if (ret) - goto err_restore_page; - - ret = __phy_modify(phydev, 0x1c, RTL8211E_TX_DELAY | RTL8211E_RX_DELAY, - val); - -err_restore_page: - return phy_restore_page(phydev, oldpage, ret); + return rtl8211x_modify_ext_paged(phydev, 0xa4, 0x1c, + RTL8211E_TX_DELAY | RTL8211E_RX_DELAY, + val); } static int rtl8211b_suspend(struct phy_device *phydev) From patchwork Tue Aug 13 19:11:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 1146612 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="mDnp/9Im"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 467Mm116jzz9sNx for ; Wed, 14 Aug 2019 05:12:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726800AbfHMTMK (ORCPT ); Tue, 13 Aug 2019 15:12:10 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:46848 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726717AbfHMTMB (ORCPT ); Tue, 13 Aug 2019 15:12:01 -0400 Received: by mail-pf1-f195.google.com with SMTP id q139so3847677pfc.13 for ; Tue, 13 Aug 2019 12:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kx7hXRRKFHX0BuedwQZzNXNcuv3a7cFx9ZeS3n0LxTk=; b=mDnp/9ImreJem/DrAUC6vZR7sY5twl97eb3aIFbCe7gHNvE6cr3+oYO9MQLf9GTQG6 VF5dZeGYH1ifQL3L9/O80vK/i8cBDleeSzjkHm/lfoe1TanfayBU+isCuOxCLkCN2JO2 zKtKsKSPv+l8C8h7x+tB8KAK8vp7huycnHXt8= 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=kx7hXRRKFHX0BuedwQZzNXNcuv3a7cFx9ZeS3n0LxTk=; b=obocbjq/HatL0Dla268P5wB0IHP+M30lXZsXDQssGPfzWMDgEouRox0BWZeKaPxCIK 4+OyDE9lvAm/LrxhFlmkuU0ibVb5PL/9oFJyXIr04GijguqMZGL94fXq+jqLuXMKJjps oWY56NMk9hmg3pJDByk9izS0uFZb/nP/eNAtyn5AbRq71dnTQKqH3Ev67fo4vQB1M65/ c0ZwCzLM+jdgzTRVuVD8uHbLbeGKrCwlYc3/0dX9SsPAMSAwGmnNuUJpSaX/SIIbd8/r sITDRTeV+nLYEW+TF6vajzzQmbxpDbVaigiy8Norxmr4Uq4aAWyoWOXLpm/CytMykORi EHgw== X-Gm-Message-State: APjAAAUhdg3DBarg2T9LQq4nicvR6oY4tagQYRyHDBPDQ/jFliNraUyL l4vEwr3DiYNU/Oh8jXRTFaqLmFIjuvI= X-Google-Smtp-Source: APXvYqw7qIZJ5iHbSUcNoDmoCgiwtG+7dNb/PeZ/XL9Sbk5C42ZSFE1/DUtV8id/CG0U/tJ3UC5fpg== X-Received: by 2002:a62:1bd5:: with SMTP id b204mr3752057pfb.14.1565723520778; Tue, 13 Aug 2019 12:12:00 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id t7sm4408176pgp.68.2019.08.13.12.11.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Aug 2019 12:12:00 -0700 (PDT) From: Matthias Kaehlcke To: "David S . Miller" , Rob Herring , Mark Rutland , Andrew Lunn , Florian Fainelli , Heiner Kallweit Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Douglas Anderson , Matthias Kaehlcke Subject: [PATCH v6 4/4] net: phy: realtek: Add LED configuration support for RTL8211E Date: Tue, 13 Aug 2019 12:11:47 -0700 Message-Id: <20190813191147.19936-5-mka@chromium.org> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog In-Reply-To: <20190813191147.19936-1-mka@chromium.org> References: <20190813191147.19936-1-mka@chromium.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add a .config_led hook which is called by the PHY core when configuration data for a PHY LED is available. Each LED can be configured to be solid 'off, solid 'on' for certain (or all) link speeds or to blink on RX/TX activity. Signed-off-by: Matthias Kaehlcke --- Changes in v6: - return -EOPNOTSUPP if trigger is not supported, don't log warning - don't log errors if MDIO ops fail, this is rare and the phy_device will log a warning - added parentheses around macro argument used in arithmetics to avoid possible operator precedence issues - minor formatting changes Changes in v5: - use 'config_leds' driver callback instead of requesting the DT configuration - added support for trigger 'none' - always disable EEE LED mode when a LED is configured. We have no device data struct to keep track of its state, the number of LEDs is limited, so the overhead of disabling it multiple times (once for each LED that is configured) during initialization is negligible - print warning when disabling EEE LED mode fails - updated commit message (previous subject was 'net: phy: realtek: configure RTL8211E LEDs') Changes in v4: - use the generic PHY LED binding - keep default/current configuration if none is specified - added rtl8211e_disable_eee_led_mode() - was previously in separate patch, however since we always want to disable EEE LED mode when a LED configuration is specified it makes sense to just add the function here. - don't call phy_restore_page() in rtl8211e_config_leds() if selection of the extended page failed. - use phydev_warn() instead of phydev_err() if LED configuration fails since we don't bail out - use hex number to specify page for consistency - add hex number to comment about ext page 44 to facilitate searching Changes in v3: - sanity check led-modes values - set LACR bits in a more readable way - use phydev_err() instead of dev_err() - log an error if LED configuration fails Changes in v2: - patch added to the series --- drivers/net/phy/realtek.c | 90 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index a5b3708dc4d8..2bca3b91d43d 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -9,8 +9,9 @@ * Copyright (c) 2004 Freescale Semiconductor, Inc. */ #include -#include +#include #include +#include #define RTL821x_PHYSR 0x11 #define RTL821x_PHYSR_DUPLEX BIT(13) @@ -26,6 +27,19 @@ #define RTL821x_EXT_PAGE_SELECT 0x1e #define RTL821x_PAGE_SELECT 0x1f +/* RTL8211E page 5 */ +#define RTL8211E_EEE_LED_MODE1 0x05 +#define RTL8211E_EEE_LED_MODE2 0x06 + +/* RTL8211E extension page 44 (0x2c) */ +#define RTL8211E_LACR 0x1a +#define RLT8211E_LACR_LEDACTCTRL_SHIFT 4 +#define RTL8211E_LCR 0x1c + +#define LACR_MASK(led) BIT(4 + (led)) +#define LCR_MASK(led) GENMASK(((led) * 4) + 2,\ + (led) * 4) + #define RTL8211F_INSR 0x1d #define RTL8211F_TX_DELAY BIT(8) @@ -83,6 +97,79 @@ static int rtl8211x_modify_ext_paged(struct phy_device *phydev, int page, return phy_restore_page(phydev, oldpage, ret); } +static void rtl8211e_disable_eee_led_mode(struct phy_device *phydev) +{ + int oldpage; + int err = 0; + + oldpage = phy_select_page(phydev, 5); + if (oldpage < 0) + goto out; + + /* write magic values to disable EEE LED mode */ + err = __phy_write(phydev, RTL8211E_EEE_LED_MODE1, 0x8b82); + if (err) + goto out; + + err = __phy_write(phydev, RTL8211E_EEE_LED_MODE2, 0x052b); + +out: + if (err) + phydev_warn(phydev, "failed to disable EEE LED mode: %d\n", + err); + + phy_restore_page(phydev, oldpage, err); +} + +static int rtl8211e_config_led(struct phy_device *phydev, int led, + struct phy_led_config *cfg) +{ + u16 lacr_bits = 0, lcr_bits = 0; + int oldpage, ret; + + switch (cfg->trigger.t) { + case PHY_LED_TRIGGER_LINK: + lcr_bits = 7 << (led * 4); + break; + + case PHY_LED_TRIGGER_LINK_10M: + lcr_bits = 1 << (led * 4); + break; + + case PHY_LED_TRIGGER_LINK_100M: + lcr_bits = 2 << (led * 4); + break; + + case PHY_LED_TRIGGER_LINK_1G: + lcr_bits |= 4 << (led * 4); + break; + + case PHY_LED_TRIGGER_NONE: + break; + + default: + return -EOPNOTSUPP; + } + + if (cfg->trigger.activity) + lacr_bits = BIT(RLT8211E_LACR_LEDACTCTRL_SHIFT + led); + + rtl8211e_disable_eee_led_mode(phydev); + + oldpage = rtl8211x_select_ext_page(phydev, 0x2c); + if (oldpage < 0) + return oldpage; + + ret = __phy_modify(phydev, RTL8211E_LACR, LACR_MASK(led), lacr_bits); + if (ret) + goto err; + + ret = __phy_modify(phydev, RTL8211E_LCR, LCR_MASK(led), lcr_bits); + +err: + return phy_restore_page(phydev, oldpage, ret); +} + static int rtl8201_ack_interrupt(struct phy_device *phydev) { int err; @@ -330,6 +417,7 @@ static struct phy_driver realtek_drvs[] = { .config_init = &rtl8211e_config_init, .ack_interrupt = &rtl821x_ack_interrupt, .config_intr = &rtl8211e_config_intr, + .config_led = &rtl8211e_config_led, .suspend = genphy_suspend, .resume = genphy_resume, .read_page = rtl821x_read_page,