From patchwork Fri Apr 19 15:35:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josua Mayer X-Patchwork-Id: 13636529 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2095.outbound.protection.outlook.com [40.107.104.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB976130494; Fri, 19 Apr 2024 15:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.95 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713540933; cv=fail; b=S+XGvQP0EzCawBVR/ZCAN1Ld8MSUcK5AF3R1XJQ+FZujF5oT3/h+QfJTV0flkeugER3urSY5C6zsVNIhxnQtk7faWF1AHI98X2LMLj5KisN4+GF5xpIWSmcC7AdRiJ4g0fzDXDeTaBRRwswxmvogcG42VF0ZmfGnliUtoHINBwc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713540933; c=relaxed/simple; bh=4qOEVo/WCBLin0OpN77ESpYNsGu75TdiO3EY2x/Bbas=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=jdz3waK4FAqZ5fOjQ6o4rkP/+Gmgb9LCQw6N/hyPMDfboerPZvUWee/8qDu0rY5m/jCLMzmSQVrkZa0QHt8hAEJk7sMrkW/qy80lpZ79DQQJa3j21K63tF/rsOf6nSmvV8YEmglCM1PqCFRvKy8bN3wgiL7DPa3Jsu3U/WAYc6Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=solid-run.com; spf=pass smtp.mailfrom=solid-run.com; dkim=pass (1024-bit key) header.d=solidrn.onmicrosoft.com header.i=@solidrn.onmicrosoft.com header.b=iUUlN76O; arc=fail smtp.client-ip=40.107.104.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=solid-run.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=solid-run.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=solidrn.onmicrosoft.com header.i=@solidrn.onmicrosoft.com header.b="iUUlN76O" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PU4/Oa3JIhrUs/ZDC0zAybBacpu7EQXyp+c8v+X6bL2vsZTSsxE9oOqhSC+4KfMi9hFPL/ZQGwJjbANoCAmB8acRw+dB7PlSBHbRwtnDfe52puGdW8+nZn1q2mHJkeZmj4TKPtasn5e8xjvtkSTnoyLot1pR2DbM7xh6eD3aQVdXr5k6BeusuS4q/1AW46e7a0zZSZZHapjdCL90P5H0qKWPem+PQZH5/WoSMW+Ao0deZAX7SWeYNnhue+uUnjpAc1KzA80PBq1mE+6lfKdPP8IkdjEO9lGptGbby9Ggop7fzJaxDVE3M9QN9Ji8Qvy5ISDhO1PO5uDPPWqLWrYViA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=48jtsrGhSb43p1yDkWQYR0PZtJP8BSR2tlAJiufzEuY=; b=hG/GMYD3MD1gCwZMgkTuVS+L8Yhd7V9DRmLE8Y5BjDQjYKc3Vhwtjnzi8rwenZT+bxTHISeGRKxclrBgqBmbwjVP3KIjE3LcegHRV0sCw5uApeQFbcUjp/Lr9ZO6n1PxQTueom0i8er9MOqcMq4ShET4gd1nNVhOiIQihtxEKkFjjnG880gx1YMS6rhq0toG1tFb3oUrAMEz/CI+j17jS/13irTycGdBhCIlsBb4oWAOP/eMBTzmlh6/3uFisdSD1bEfHdtYulHwKJ3o2t4gYJqr0kZhqpXka1LKKZS2m9sRSR0hHTu8XWdMMS1yiV9fkLyaYOyhrRtEZspZ4Fnfuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=solid-run.com; dmarc=pass action=none header.from=solid-run.com; dkim=pass header.d=solid-run.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=solidrn.onmicrosoft.com; s=selector1-solidrn-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=48jtsrGhSb43p1yDkWQYR0PZtJP8BSR2tlAJiufzEuY=; b=iUUlN76OWVLnOt0ENJFlfOAoippwhfWaXDL7Q4M7Pc45TuVJClKNFZfvYWaoReW6ZFdIi1+NEPklxzI3ctuKMFp30b1Z5RB3yDN6PsCs2BmqubzqCQIz/ZsU0OPxUzDplMFRTEV7XPp0sAM2uvnMU0H1YCwQ9H/KbXZykT9PMOo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=solid-run.com; Received: from AM9PR04MB7586.eurprd04.prod.outlook.com (2603:10a6:20b:2d5::17) by DB9PR04MB8250.eurprd04.prod.outlook.com (2603:10a6:10:245::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.43; Fri, 19 Apr 2024 15:35:26 +0000 Received: from AM9PR04MB7586.eurprd04.prod.outlook.com ([fe80::c04e:8a97:516c:5529]) by AM9PR04MB7586.eurprd04.prod.outlook.com ([fe80::c04e:8a97:516c:5529%7]) with mapi id 15.20.7472.042; Fri, 19 Apr 2024 15:35:26 +0000 From: Josua Mayer Date: Fri, 19 Apr 2024 17:35:18 +0200 Subject: [PATCH net-next 2/2] net: phy: adin: add support for setting led-, link-status-pin polarity Message-Id: <20240419-adin-pin-polarity-v1-2-eaae8708db8d@solid-run.com> References: <20240419-adin-pin-polarity-v1-0-eaae8708db8d@solid-run.com> In-Reply-To: <20240419-adin-pin-polarity-v1-0-eaae8708db8d@solid-run.com> To: Michael Hennerich , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexandru Tachici , Andrew Lunn , Heiner Kallweit , Russell King Cc: Jon Nettleton , Yazan Shhady , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Josua Mayer X-Mailer: b4 0.12.4 X-ClientProxiedBy: FR3P281CA0122.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:94::6) To AM9PR04MB7586.eurprd04.prod.outlook.com (2603:10a6:20b:2d5::17) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB7586:EE_|DB9PR04MB8250:EE_ X-MS-Office365-Filtering-Correlation-Id: 43097cc6-d8da-4df8-5001-08dc608655c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?utf-8?q?mjHe96Mff38yZW2V4K4wM0We0HlOfuh?= =?utf-8?q?26DCnJgKC8uZVz7wq0iDhW7uERLsDbhFdapNPqxV3z4mQD1LpCfAyhEUZ+EGw2SvC?= =?utf-8?q?pWsxDrcjw3zNzYGTnYP6CdzmmwAC0uekS1pr2dFO5JSAZ1jlasR0ZQ2BSP/RUc+Rw?= =?utf-8?q?d0ZHYJWHTo0l9XHFnI8R5N+GCM56TSzAHgftIiL0ucZawm4Ck5LDAqggeco9CmhHX?= =?utf-8?q?qTNe+gk8RW7gu7n7WYBPmiSZ2lcuULLxsxpg/02OkrvQ1OopiKUbZtJ/0VEA9vh+g?= =?utf-8?q?kXvfMmc1oHKLj/Q3DYoYM/13OK5DF5VFuqvMQdSjuX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= =?utf-8?q?TKFW2ZQYQigD/nevmr3qySTSCAZjn7mYaH+rHc2XNcvy5jxIwVNwjJ3aOgOiUffBV?= =?utf-8?q?rUrQL/wZvl2BIp3GGhO+s2Kd7P/0dbv0NrlBJOsJyO16CAd9yZNDuPbc=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB7586.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(366007)(7416005)(376005)(52116005)(38350700005)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?6Yq9M4Ztb45G/BLpa5x64suIIbWs?= =?utf-8?q?bukYQtUQiZ0fs3uPo7fdv6zP2wC53Q0zrzYPIqGXFzeu7puheAmPwxN2pGlystmMm?= =?utf-8?q?w35gjKnD/hXCARD3eL7a97oRLslqjcKdfiphn120l8YriSgnZ2XoMx2QED/G0innX?= =?utf-8?q?ozkhbbDxiB8FgOfcv1vu/3BOLCfZDW4BLYncmWlikuezLreTCbJ9lm7S3oz7TAswM?= =?utf-8?q?+ykb8q4hnVYIQyd7JSiiC9yAb9OGMTs2DMo9cXPhUxvJnMT1VlkTCSYeN8Qw7EVG/?= =?utf-8?q?gjj/XQy55lyiyg3QXbyoh7kXygzq3EqWnkBuSk5OJNJ9TuV1uyuCYXUufr/DjzceA?= =?utf-8?q?Rtf9a5yjqQ6+bG1COr0wCS/nbbV1NY+vi1Cmr/OjhywrtlL3hD+EGw/fOCqgmCSsZ?= =?utf-8?q?R/KUXSnWzwWHAAuhDeZb2gBpuloMHmT2QnX30EqvG5Ri8qykenStxquxa73HksQ7r?= =?utf-8?q?Jvhwr8/btmMlPgozO+vimscOjzbux7ylrEfAvrLnJ0z/p3l31O+QwRkb8O1P3VEUs?= =?utf-8?q?ckIZv+e/RVLorjPWkrYXFlwLc+ug0Nz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u5LdFnwKfS/l3oFWiHB4InaZK92UGCXG6scjSfz?= =?utf-8?q?uguLQWy8zRxgclul8s8Trd8ba4ZIH1SWmyS1QUH2SVh0DIVjdxmmwa9r/tNxuQjFF?= =?utf-8?q?4twyMXBRijay?= X-OriginatorOrg: solid-run.com X-MS-Exchange-CrossTenant-Network-Message-Id: 43097cc6-d8da-4df8-5001-08dc608655c2 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB7586.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 15:35:26.1235 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a4a8aaf3-fd27-4e27-add2-604707ce5b82 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qOiZNjiG+KHEdiuMIDIYlnCMlganAZO1TD4cqtdBXv5sjaOb3zSHwO3BrgFkJ8E3Su/VjMNFhko3xUn9Mj0kGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8250 X-Patchwork-Delegate: kuba@kernel.org ADIN1300 supports software control over pin polarity for both LED_0 and LINK_ST pins. Configure the polarity during probe based on device-tree properties. Led polarity is only set if specified in device-tree, otherwise the phy can choose either active-low or active-high based on external line voltage. Link-status polarity is set to active-high as default if not specified, which is always the reset-default. Signed-off-by: Josua Mayer --- drivers/net/phy/adin.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c index 2e1a46e121d9..53159dea6381 100644 --- a/drivers/net/phy/adin.c +++ b/drivers/net/phy/adin.c @@ -114,6 +114,9 @@ #define ADIN1300_CDIAG_FLT_DIST(x) (0xba21 + (x)) +#define ADIN1300_LED_A_INV_EN_REG 0xbc01 +#define ADIN1300_LED_A_INV_EN BIT(0) + #define ADIN1300_GE_SOFT_RESET_REG 0xff0c #define ADIN1300_GE_SOFT_RESET BIT(0) @@ -158,6 +161,9 @@ #define ADIN1300_RMII_20_BITS 0x0004 #define ADIN1300_RMII_24_BITS 0x0005 +#define ADIN1300_GE_LNK_STAT_INV_EN_REG 0xff3c +#define ADIN1300_GE_LNK_STAT_INV_EN BIT(0) + /** * struct adin_cfg_reg_map - map a config value to aregister value * @cfg: value in device configuration @@ -522,6 +528,49 @@ static int adin_config_clk_out(struct phy_device *phydev) ADIN1300_GE_CLK_CFG_MASK, sel); } +static int adin_config_pin_polarity(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + int ret; + u32 val; + + /* set led polarity, if property present */ + if (device_property_present(dev, "adi,led-polarity")) { + ret = device_property_read_u32(dev, "adi,led-polarity", &val); + if (ret) { + return ret; + } else if (val > 1) { + phydev_err(phydev, "invalid adi,led-polarity\n"); + return -EINVAL; + } + + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, + ADIN1300_LED_A_INV_EN_REG, + ADIN1300_LED_A_INV_EN, val); + if (ret) + return ret; + } + + /* set link-status polarity, default to active-high (0) */ + if (device_property_present(dev, "adi,link-st-polarity")) { + ret = device_property_read_u32(dev, "adi,link-st-polarity", &val); + if (ret) { + return ret; + } else if (val > 1) { + phydev_err(phydev, "invalid adi,link-st-polarity\n"); + return -EINVAL; + } + } else { + val = 0; + } + + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, + ADIN1300_GE_LNK_STAT_INV_EN_REG, + ADIN1300_GE_LNK_STAT_INV_EN, val); + + return ret; +} + static int adin_config_init(struct phy_device *phydev) { int rc; @@ -548,6 +597,10 @@ static int adin_config_init(struct phy_device *phydev) if (rc < 0) return rc; + rc = adin_config_pin_polarity(phydev); + if (rc < 0) + return rc; + phydev_dbg(phydev, "PHY is using mode '%s'\n", phy_modes(phydev->interface));