Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4444169pxb; Mon, 21 Feb 2022 21:49:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXuFxVVKcaOXy2frP7p+k+ND2pmFMO4HnF/hzfI+sVLr+yt0cGPUtapWG1YYqHDuM76Q9V X-Received: by 2002:a17:902:a405:b0:14f:b5ee:cc59 with SMTP id p5-20020a170902a40500b0014fb5eecc59mr8326864plq.95.1645508949012; Mon, 21 Feb 2022 21:49:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645508949; cv=none; d=google.com; s=arc-20160816; b=mvZMbtGX5DOZ8KMsMFXX943OaOeT4nElvIPBZpU8t4u8zJM1ZynPWL0bnrZLEYP/Hk bweE9898xyCyxiCNmltNFRYpFjJtJxTXbyyyqIfCtnhGI7YC+vvK5lMAOW2GUBsslbnT SxVZ+BTiCa5Hzv/DkKTc4rhAeHHKQOpCVv34dFXcMZX3p2E/vMzw/6X5YwR7w0UapkrD zca32VitRxkAWCHjfsLcNI2H05ndQuVZ9TYX3MoYF4UsVpZIXpZn6704waAebevt3aPx MYuMpAeM0DPxbfpmGRG6TM0bT8wlNzBBzwEU4Gp9NyCNlowc3rkKdTJS1hn6j6RdsIGp ZWsA== 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=IwJT7O+ycIIE2B/+I0PXXUOt4c+jLoAf67OAg4gFgvc=; b=bpo64NaP4b+sfTa6jWbLeDdQrDi05uTK/jhU1mK5k0hJ0Z6JTo0pGzcQCBavzMwXCf ZgodaUepB3TeKCvtWpusKebSqKNnOltKFqd/+0mG136tuAOz9iSuVn24Y4aeDt85AOGo SFBqIhPRNF7oN5lTSLgRe5jrW+/XKRfC0PqhHUHqmJIBJJHRMbT8Au/hdo/w4NkMVIH0 NNt5sM5CWYwUQft4N8RQ/80dgROSJ9rji1hGYsUBsSaL+a+dlNXAWZUnY2S+UbkQrn7R Og6yVoxlZ7Yn2KG/VIWrpDIIjrf+aVdks1UHNL6gH+1EcKqf+B3zl0hMHCGQ2mhRR6JD nrQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Qwo8YWwL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e12si5205185pgm.874.2022.02.21.21.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:49:08 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Qwo8YWwL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C1C2DB85E; Mon, 21 Feb 2022 21:13:05 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380858AbiBUQjj (ORCPT + 99 others); Mon, 21 Feb 2022 11:39:39 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380805AbiBUQjL (ORCPT ); Mon, 21 Feb 2022 11:39:11 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A5492408D; Mon, 21 Feb 2022 08:38:40 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::229]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 62B7AD26C6; Mon, 21 Feb 2022 16:30:05 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B2FF4FF813; Mon, 21 Feb 2022 16:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IwJT7O+ycIIE2B/+I0PXXUOt4c+jLoAf67OAg4gFgvc=; b=Qwo8YWwLdfMsmfiY94ufBkAM9expN513dX5+VcMfJhaEjDPz+QL9DhWi7HCxyANoNo9jG5 hfyRmusIiVsECh+6ve4bNOHBeq2T1FvaCx2xjaUJGSajuNXSa2XwCnyBDcAzxnCYfSlZXN 56BGKVKQCkkfVh/LcJQyH51f0UXsl3K4juxlDsbotEDEn+DlP/tXwwrUQ/hObDQxyx9Bht qyV5m92oGiKLiJyY/FZFO7G5PRflHWEMe6+Cs5aK61Rtuj9cefSnIlkza1rb5xgt0kpQqh iLXH73CPxNLS9rVBejg0uYUDYO+utSOHCPl8t6Za764WxXqH/M7tebae7L2kXw== From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= Subject: [RFC 10/10] net: sfp: add support for fwnode Date: Mon, 21 Feb 2022 17:26:52 +0100 Message-Id: <20220221162652.103834-11-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code. Signed-off-by: Clément Léger --- drivers/net/phy/sfp.c | 44 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 4720b24ca51b..9d9e3d209408 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -2499,43 +2499,25 @@ static int sfp_probe(struct platform_device *pdev) return err; sff = sfp->type = &sfp_data; + if (dev_fwnode(&pdev->dev)) { + struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev); + struct fwnode_handle *np; - if (pdev->dev.of_node) { - struct device_node *node = pdev->dev.of_node; - const struct of_device_id *id; - struct device_node *np; + if (!is_acpi_device_node(fwnode)) { + sff = device_get_match_data(&pdev->dev); + if (WARN_ON(!sff)) + return -EINVAL; - id = of_match_node(sfp_of_match, node); - if (WARN_ON(!id)) - return -EINVAL; - - sff = sfp->type = id->data; - - np = of_parse_phandle(node, "i2c-bus", 0); - if (!np) { - dev_err(sfp->dev, "missing 'i2c-bus' property\n"); - return -ENODEV; + sfp->type = sff; } - i2c = of_find_i2c_adapter_by_node(np); - of_node_put(np); - } else if (has_acpi_companion(&pdev->dev)) { - struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); - struct fwnode_handle *fw = acpi_fwnode_handle(adev); - struct fwnode_reference_args args; - struct acpi_handle *acpi_handle; - int ret; - - ret = acpi_node_get_property_reference(fw, "i2c-bus", 0, &args); - if (ret || !is_acpi_device_node(args.fwnode)) { - dev_err(&pdev->dev, "missing 'i2c-bus' property\n"); + np = fwnode_find_reference(fwnode, "i2c-bus", 0); + if (!np) { + dev_err(&pdev->dev, "Cannot parse i2c-bus\n"); return -ENODEV; } - - acpi_handle = ACPI_HANDLE_FWNODE(args.fwnode); - i2c = i2c_acpi_find_adapter_by_handle(acpi_handle); - } else { - return -EINVAL; + i2c = fwnode_find_i2c_adapter_by_node(np); + fwnode_handle_put(np); } if (!i2c) -- 2.34.1