From patchwork Thu Jan 25 20:36:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 192297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp242292dyb; Thu, 25 Jan 2024 12:40:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnlVZfE5bJI2O7ciXvuO+Ntw9ZJSdVcO4Y+RTl8MlWzGod12mqRpDxlE3gJi3R7GSVFtXB X-Received: by 2002:a05:6a00:b4a:b0:6d9:955a:d3bb with SMTP id p10-20020a056a000b4a00b006d9955ad3bbmr162757pfo.10.1706215256154; Thu, 25 Jan 2024 12:40:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706215256; cv=pass; d=google.com; s=arc-20160816; b=N6onN7S/ofwEohcqfZYxR54DlopwpnuQxY58791GuF+nmhitQhjBkGqH62kdBwMctO 5IuV+Q7S25LuMyqYUhJoDceBvp2LPSZFlLwMHIvQDwQXAVooCwosH4/RT+39UL93eZA+ XkCSXYlDEzBrxq0PPDofNM1Q4uPP9EWvQpkZCHH4bf9CLyjbPQc085fgjz5eIMTq+Vbv ClZKIiyaDS/jav5Nr9ih9fvZl/zO4fl5oP0X3fviiMwb2d+N/bYnitCLeKoEgeawM5As EzwWhq6m3q8bOAElJTB63XuF5ZlbuiZLd9TeD4TknsWhksCmiIoG/at1Za3YXFF+cU/o FRmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=jYZjI2Tknpmm3tYZbjPO9Pae0r5NRRsVcbrpdnsJuFs=; fh=t/rEUYZBrjIVtJtvItkK7O2t2zLyO6TH9UCXgO6Lsag=; b=AXf0pWjC0/CI4ZwjaVvAIT07bJrK0v2N89GyRbgYD0Ffia1fWEY5r66XXFMJEaAjFr UFeK3XKitf+41fMr7l0VpTx+HbxVi/Y3rXDftjcQ19dc68OMCDYKfIP+QR6UE5F2jpCB 6z87gLYKjv5pU4JA1CNfcbEanmcupyPBlprzAS+GVz0TheiD4jkaHoeLksxqdIRe0xe0 sk/N+9PGe36rILD0YjaRDwAaeaphxZAdJlQj0Da+D9dlW1gNv7Cs4Qfh1HxcmzQw9bpr fCiu0zWYyiabnR4vhgnQP20rf/NyGxJ+CYXlZ+jCGNYSyLxEcw+GQ2nFlGVQkTyQD7sU kRkQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KEVS9VG6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-39253-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39253-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id lm20-20020a056a003c9400b006dddd4a34dbsi818130pfb.139.2024.01.25.12.40.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 12:40:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39253-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KEVS9VG6; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-39253-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39253-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9C816B22A5F for ; Thu, 25 Jan 2024 20:39:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9FA613B7B5; Thu, 25 Jan 2024 20:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KEVS9VG6" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A52BC1386D5; Thu, 25 Jan 2024 20:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706215046; cv=none; b=SLvd2YjsGqAgTLFlnSh9vu3uwqTV0RBwDzNgxh1TnxUGz1Gl5xa4ep51Q0fs3Xeld15lTW5bMyVl23BP7YHg/cslVt9OctVTwdBgnMrd6RGKS73KbF6KnaQumQFXBiw7J3ivhYt1iZfI+LKF4OvFfr6xR8EWBRDcVXPqwfYJcaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706215046; c=relaxed/simple; bh=OY/CIaPBCKIjFDNlNL1iTCqE6gW8vC8FhQ1KzxBDIR0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ksBvZb/aKW3fmZtJcMYD41C0XBlXyPHvvcQAvWfQbiEhXT/zL9v1u4KwSTjwepCepcU4930M3zCZsBzeq2KXAErOclptyT016UAsQ0vw60ZWd6SohlUPWBeKmHDNHkM+J8BT4nFUZFwprEHSwuHrlIRhE+jjg6s4eb2IwPAoJgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KEVS9VG6; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40ed2333c8fso12029065e9.0; Thu, 25 Jan 2024 12:37:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706215043; x=1706819843; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jYZjI2Tknpmm3tYZbjPO9Pae0r5NRRsVcbrpdnsJuFs=; b=KEVS9VG6ssFWWcbM/S/QJ/zuHtPN+x9+gEOcvYcs6wOZLWv3S1D5DryIuzzn5mj0IG SDzudM8svdkxX1GcYifBZSBMoPm8Np5xC/mdesnQAQ5BH/akyrZ8TKLk9jntyD8RLJkP /TkmsuFsoIfKpLvMhSxOFBPXzRq09l2lAOYbhfbk7P2gMma6NSv0MfY2AYuLDkVFmDxF k6F+8ObAuMKqGaqaB2rsawi+KBIxRJJWw4C55yci8zL1bQ2dijbeqRySL+M3HtVMMajR 98QEsscQjJx5BOdRPrgF8OWOmYr+aKqQNhG6LJSmJieBBBwCfZTmUpdmy2ISQ2BYAra1 rh8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706215043; x=1706819843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jYZjI2Tknpmm3tYZbjPO9Pae0r5NRRsVcbrpdnsJuFs=; b=Jgep+sU9KXHjopA67IyCMp872woJ/l377pWH/PfcOVgeAbW89NnkYpXQordN6Agtk/ zDhFFo7ogAK8E+oRZmAjxm//2Ps2xr4KL9VME9DGeOtx41coz/6Ev+wSn+CypOcyqpMZ w8VL1Be4kcuc3YZiZ8A67rfWc2lI5ZRcMcj1TrRnznwDmvmenJiP+hHz50wtk5lQO+4l zoRCBB9NweV0KOvobYMaQ6quSr6gpk76S0rF1BFsd3taBpsaXqjmjwMpv0vqia/3qAbm iXM11EJfMM/wkbCKct/Y1DZeTB8PeRGsYdj/ilJTbYIfR5L0Z0gCW3MsVrq7KAdS16Hi PWWg== X-Gm-Message-State: AOJu0YzRz/7aNA6OExh+q3pjmCN/jNQQ4AsqdePg6Hb+cFj4lD5KD1N5 HHRWhb0LFejrsFhtxu4+VuUKtOD9TCMuzRUh6wxpmqY5Gx4ydAv+ X-Received: by 2002:a05:600c:2112:b0:40e:4b49:9b0f with SMTP id u18-20020a05600c211200b0040e4b499b0fmr152473wml.239.1706215042819; Thu, 25 Jan 2024 12:37:22 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id j32-20020a05600c1c2000b0040e813f1f31sm3817700wms.25.2024.01.25.12.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 12:37:22 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , William Zhang , Anand Gore , Kursad Oney , Florian Fainelli , =?utf-8?b?UmFmYcWCIE1p?= =?utf-8?b?xYJlY2tp?= , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Jacek Anaszewski , =?utf-8?q?Fern=C3=A1ndez_Roj?= =?utf-8?q?as?= , Sven Schwermer , Christian Marangi , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Subject: [net-next PATCH v10 3/5] net: phy: add support for PHY LEDs polarity modes Date: Thu, 25 Jan 2024 21:36:59 +0100 Message-ID: <20240125203702.4552-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240125203702.4552-1-ansuelsmth@gmail.com> References: <20240125203702.4552-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789096368474656860 X-GMAIL-MSGID: 1789096368474656860 Add support for PHY LEDs polarity modes. Some PHY require LED to be set to active low to be turned ON. Adds support for this by declaring active-low property in DT. PHY driver needs to declare .led_polarity_set() to configure LED polarity modes. Function will pass the index with the LED index and a bitmap with all the required modes to set. Current supported modes are: - active-low with the flag PHY_LED_ACTIVE_LOW. LED is set to active-low to turn it ON. - inactive-high-impedance with the flag PHY_LED_INACTIVE_HIGH_IMPEDANCE. LED is set to high impedance to turn it OFF. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- Changes v10: - Add Review tag Changes v9: - Make LED probe fail if modes asked but not supported - Fix wrong function description Changes v5: - Rework to LED modes bitmap Changes v4: - Drop for global active-low - Rework to polarity option (for marvell10g series support) Changes v3: - Out of RFC Changes v2: - Add this patch drivers/net/phy/phy_device.c | 16 ++++++++++++++++ include/linux/phy.h | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3611ea64875e..dd778c7fde1d 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3097,6 +3097,7 @@ static int of_phy_led(struct phy_device *phydev, struct device *dev = &phydev->mdio.dev; struct led_init_data init_data = {}; struct led_classdev *cdev; + unsigned long modes = 0; struct phy_led *phyled; u32 index; int err; @@ -3114,6 +3115,21 @@ static int of_phy_led(struct phy_device *phydev, if (index > U8_MAX) return -EINVAL; + if (of_property_read_bool(led, "active-low")) + set_bit(PHY_LED_ACTIVE_LOW, &modes); + if (of_property_read_bool(led, "inactive-high-impedance")) + set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &modes); + + if (modes) { + /* Return error if asked to set polarity modes but not supported */ + if (!phydev->drv->led_polarity_set) + return -EINVAL; + + err = phydev->drv->led_polarity_set(phydev, index, modes); + if (err) + return err; + } + phyled->index = index; if (phydev->drv->led_brightness_set) cdev->brightness_set_blocking = phy_led_set_brightness; diff --git a/include/linux/phy.h b/include/linux/phy.h index 684efaeca07c..c9994a59ca2e 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -852,6 +852,15 @@ struct phy_plca_status { bool pst; }; +/* Modes for PHY LED configuration */ +enum phy_led_modes { + PHY_LED_ACTIVE_LOW = 0, + PHY_LED_INACTIVE_HIGH_IMPEDANCE = 1, + + /* keep it last */ + __PHY_LED_MODES_NUM, +}; + /** * struct phy_led: An LED driven by the PHY * @@ -1145,6 +1154,19 @@ struct phy_driver { int (*led_hw_control_get)(struct phy_device *dev, u8 index, unsigned long *rules); + /** + * @led_polarity_set: Set the LED polarity modes + * @dev: PHY device which has the LED + * @index: Which LED of the PHY device + * @modes: bitmap of LED polarity modes + * + * Configure LED with all the required polarity modes in @modes + * to make it correctly turn ON or OFF. + * + * Returns 0, or an error code. + */ + int (*led_polarity_set)(struct phy_device *dev, int index, + unsigned long modes); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv)