Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4433773pxu; Wed, 9 Dec 2020 17:42:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFBGUIoXvmmh+c882ZdgG5jvjD8HtgkqadvYhzq3Lt1AgMpW2c8xY5RAnoNggtgUr6s6su X-Received: by 2002:a17:907:2131:: with SMTP id qo17mr4378465ejb.546.1607564562993; Wed, 09 Dec 2020 17:42:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607564562; cv=none; d=google.com; s=arc-20160816; b=qDaCpf4m0WNyaXYj/PerI2HA7y4T513cUs5iRM084QBS4LFPGMG+WvYUkw0MnwW9an BHfbvsbOSEm8nXsiDIkoR56KMwAn4EAZ1HAtMwB6l0CkrJkvoYERljVtYPnuDVu8M8JT 1dH1jWFM/zH9xtbHoUz275l3pdzESL57PEBeNXffmzifk8Fa/e/FSHybdLg0h0jB5nED h0+0NtzWjwfY8Vna99f7IHM5LUlnWe9KfOvdOzg8OgXPVJS170PzeQvGJiqFB/R3vb+D votLs0u67ECC0peSWlTQC0aorSZ89OcnK/1vAUBD8pnSsJ4jc5eiYO2liati37ssd3v2 vInw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3td+CKxBbplPaGbDWTbVMmGG1IaSVF5bkOz1uqYZNdU=; b=Slr8pqfdv2IK0KISKFGDNyN0z1qyFjlxnoIxYaytvYkbHzcLFRJpfUT95yrjtiV87Y I3MXfQkfw8B65GL6J+kvP0kkLMeOf1K/lxqGoqnaBrwP90bTZyWH/g/mhebFYK/s3k5B Y+ISQBjARGZ6E6ho+BzDH4nBeagSRVky3C/OV0mDBXOQkPwWAa9hhxAQQkNt5CAJRnfI ESXqFgNUUy+5i/QG4n+UlS9HyQQq16rgEgJ/P2N3DP3CP6moWDD5vOWBnT2l1wPe1Ah5 j7UBXZVn2b5gnga0Dqd3ymyEGSwpvim9tczVtGJ1/a2VUK4F1xl387SLUa/14UMFLeiz Xhyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yadro.com header.s=mta-01 header.b=XTVlpAfe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yadro.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v26si1613581ejg.723.2020.12.09.17.42.12; Wed, 09 Dec 2020 17:42:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yadro.com header.s=mta-01 header.b=XTVlpAfe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yadro.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732726AbgLIOAh (ORCPT + 99 others); Wed, 9 Dec 2020 09:00:37 -0500 Received: from mta-02.yadro.com ([89.207.88.252]:54196 "EHLO mta-01.yadro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728539AbgLIOAb (ORCPT ); Wed, 9 Dec 2020 09:00:31 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id C13D4412FD; Wed, 9 Dec 2020 13:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1607522386; x=1609336787; bh=Y2xyk/w0d2sgxR9+vPtvXUDmTgLzwzS14XM CrKqQtrQ=; b=XTVlpAfe+OHrW9jLrwC5P06DKFZWD3lM0lgCqsKH9ak5y1S0rCq t64Oaho0utmwaBUrI+UVXCDX8oitDfsFbyOPNvPmFoA2NSpsf/NlVGjGCco1KRFL B1Ll7zpGvFePXacF74AhNHYgvAS4wW+KH5TsGTr8k+1yRzufuhiDjA3w= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZDQk9Osmjuq7; Wed, 9 Dec 2020 16:59:46 +0300 (MSK) Received: from T-EXCH-03.corp.yadro.com (t-exch-03.corp.yadro.com [172.17.100.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 8AC0D41281; Wed, 9 Dec 2020 16:59:45 +0300 (MSK) Received: from localhost.dev.yadro.com (10.199.0.125) by T-EXCH-03.corp.yadro.com (172.17.100.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Wed, 9 Dec 2020 16:59:43 +0300 From: Ivan Mikhaylov To: "David S . Miller" , Jakub Kicinski , Rob Herring , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King CC: Ivan Mikhaylov , , , Subject: [PATCH 1/2] net: phy: micrel: add LED control on KSZ9131 Date: Wed, 9 Dec 2020 17:05:00 +0300 Message-ID: <20201209140501.17415-2-i.mikhaylov@yadro.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20201209140501.17415-1-i.mikhaylov@yadro.com> References: <20201209140501.17415-1-i.mikhaylov@yadro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.199.0.125] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-03.corp.yadro.com (172.17.100.103) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the possibility to read the LED configuration via DTS properties from KSZ9131 PHY node. Add the new proprties and handle for them: micrel,led-mode-behavior micrel,led-mode-select Signed-off-by: Ivan Mikhaylov --- drivers/net/phy/micrel.c | 69 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 3fe552675dd2..117f3a3b9dd6 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -71,6 +71,11 @@ #define MII_KSZPHY_RX_DATA_PAD_SKEW 0x105 #define MII_KSZPHY_TX_DATA_PAD_SKEW 0x106 +/* KSZ9131 LED registers */ +#define MII_KSZPHY_LED_MODE_SELECT 0x16 +#define MII_KSZPHY_LED_BEHAVIOR 0x17 +#define MII_KSZPHY_LED_MODE 0x1a + #define PS_TO_REG 200 struct kszphy_hw_stat { @@ -86,6 +91,8 @@ static struct kszphy_hw_stat kszphy_hw_stats[] = { struct kszphy_type { u32 led_mode_reg; + u32 led_mode_behavior_reg; + u32 led_mode_select_reg; u16 interrupt_level_mask; bool has_broadcast_disable; bool has_nand_tree_disable; @@ -95,6 +102,8 @@ struct kszphy_type { struct kszphy_priv { const struct kszphy_type *type; int led_mode; + int led_mode_behavior; + int led_mode_select; bool rmii_ref_clk_sel; bool rmii_ref_clk_sel_val; u64 stats[ARRAY_SIZE(kszphy_hw_stats)]; @@ -131,6 +140,13 @@ static const struct kszphy_type ksz9021_type = { .interrupt_level_mask = BIT(14), }; +static const struct kszphy_type ksz9131_type = { + .led_mode_reg = MII_KSZPHY_LED_MODE, + .led_mode_behavior_reg = MII_KSZPHY_LED_BEHAVIOR, + .led_mode_select_reg = MII_KSZPHY_LED_MODE_SELECT, + .interrupt_level_mask = BIT(14), +}; + static int kszphy_extended_write(struct phy_device *phydev, u32 regnum, u16 val) { @@ -204,6 +220,7 @@ static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val) switch (reg) { case MII_KSZPHY_CTRL_1: + case MII_KSZPHY_LED_MODE: shift = 14; break; case MII_KSZPHY_CTRL_2: @@ -286,6 +303,26 @@ static int kszphy_config_reset(struct phy_device *phydev) if (priv->led_mode >= 0) kszphy_setup_led(phydev, priv->type->led_mode_reg, priv->led_mode); + if (priv->led_mode_behavior >= 0) { + ret = phy_write(phydev, priv->type->led_mode_behavior_reg, + priv->led_mode_behavior); + if (ret) { + phydev_err(phydev, + "failed to set led mode behavior reg\n"); + return ret; + } + } + + if (priv->led_mode_select >= 0) { + ret = phy_write(phydev, priv->type->led_mode_select_reg, + priv->led_mode_select); + if (ret) { + phydev_err(phydev, + "failed to set led mode select reg\n"); + return ret; + } + } + return 0; } @@ -1122,6 +1159,36 @@ static int kszphy_probe(struct phy_device *phydev) priv->led_mode = -1; } + if (type->led_mode_behavior_reg) { + ret = of_property_read_u32(np, "micrel,led-mode-behavior", + &priv->led_mode_behavior); + if (!ret) { + ret = phy_write(phydev, type->led_mode_behavior_reg, + priv->led_mode_behavior); + if (ret) + phydev_err(phydev, + "invalid led mode behavior: 0x%x\n", + priv->led_mode_behavior); + } + } else { + priv->led_mode_behavior = -1; + } + + if (type->led_mode_select_reg) { + ret = of_property_read_u32(np, "micrel,led-mode-select", + &priv->led_mode_select); + if (!ret) { + ret = phy_write(phydev, type->led_mode_select_reg, + priv->led_mode_select); + if (ret) + phydev_err(phydev, + "invalid led mode select: 0x%x\n", + priv->led_mode_select); + } + } else { + priv->led_mode_select = -1; + } + clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref"); /* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */ if (!IS_ERR_OR_NULL(clk)) { @@ -1319,7 +1386,7 @@ static struct phy_driver ksphy_driver[] = { .phy_id_mask = MICREL_PHY_ID_MASK, .name = "Microchip KSZ9131 Gigabit PHY", /* PHY_GBIT_FEATURES */ - .driver_data = &ksz9021_type, + .driver_data = &ksz9131_type, .probe = kszphy_probe, .config_init = ksz9131_config_init, .read_status = genphy_read_status, -- 2.21.1