Received: by 2002:a05:7412:8d08:b0:f9:2d0a:d759 with SMTP id bj8csp233311rdb; Sun, 17 Dec 2023 09:18:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvAzdXD8t7Y0L3OBm6tdyAzj9tzQh8Lh02DCSD2UX+O2VZAZfPkk7C9YhLkrLUhRCnfovX X-Received: by 2002:a17:902:e54e:b0:1d0:70f7:ba02 with SMTP id n14-20020a170902e54e00b001d070f7ba02mr8238462plf.92.1702833524605; Sun, 17 Dec 2023 09:18:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702833524; cv=none; d=google.com; s=arc-20160816; b=p8I8uGVjqug6cET7MTVmEscrsL4/ad5N+xOPXAseDkzusoWfg2+0liRbesGnVp+dQN oKnF5/lPDiE4wX9sT7mal0AjbxihmSCZD7ObCMRfUTLLvCyC5Y2iQ2p0AWAxALXGJOnP K4k9jEtNkWvPdHS3o1jrgF14Y3RHPfb/b5OPKJdRimNfRZn+H9KfElhqVkQoD4SQOqdo QONZFOQa+rAsiijf2d66WsLarVlTcahhgZSh4muiGdkUP+2rZ9dbHlYEwp16l+BhzEuC e462wJtHh3BEeQsUxJNpMLKxZvBXHlppLb8GPnMVK4ohFqp2T/OneVNPKkUkTXmczR8d 9pAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yvzvPPOvURo9eUay1zjag8iF5jEJZnvBduw4ZeL4Nkg=; fh=iWBv4He8s+xpzrJY93iuua2RS8H3PW0G6YXgJrUCrjQ=; b=zi5uqqPNz1Sj9nwy5ldjsdxGW0QxI/YQaYCQ8Rnze963cf0qnub+BC2jBqWzS1Vo/T s43uXstEvaDDZhXZPs+1212MlJUS1YpyEQp2nahl9ZnrsnSwbsJ4rkzhopCje4rD2uuE 1M/6Gm8as4XNoWZcF7KfVWio1xsMAM0/XMu0nnKhTOktYvjbItPipwHgZoKh5etOgmoV 2Uc2I67AGxPrq7k6ErgMIMf1096SJKGemm8VSLidMGewWtqReZdMrMH1uy7FlfDBA2r9 sY7Y1qdiSHLCh9AgDXJQwl+dJr9v5isoW2YWzOIJYCY8N1vleMP6tV3/JgtgYKk7M7VQ eocQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vKaydqxP; spf=pass (google.com: domain of linux-kernel+bounces-2700-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2700-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m10-20020a170902db0a00b001cf8e9e8813si16746208plx.315.2023.12.17.09.18.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 09:18:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2700-linux.lists.archive=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=@linaro.org header.s=google header.b=vKaydqxP; spf=pass (google.com: domain of linux-kernel+bounces-2700-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2700-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 A1191B20E8E for ; Sun, 17 Dec 2023 17:18:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 768AF46441; Sun, 17 Dec 2023 17:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vKaydqxP" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) (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 EDE5845C09 for ; Sun, 17 Dec 2023 17:18:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-7b719f05b11so119071039f.1 for ; Sun, 17 Dec 2023 09:18:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702833501; x=1703438301; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=yvzvPPOvURo9eUay1zjag8iF5jEJZnvBduw4ZeL4Nkg=; b=vKaydqxPH5eN5TDUVUldqnsWrWBSqc7lpcbdJJ3eBCo1mKHv6QBBqd4VE2w9ZmENPS 1yl7wuauPNPCEPxAYfNafFobpMI9Uq8vkA56AOVXKQm+ro9uM59CKKxLTsfStZ7oNqcB cLkOMvp/ITOcBeIObfFBI/KcnylIK0l/QQh9FmA+LR/CTe45cgxf4GDTnWJG40vynpJj iSbfgfVfxUBwXTNApdlMhP+1X2+fgitUZ6vSwuVJgrkuK35seAnO1h5nWYaLIRGfVlOt Sp0z1bWi/gHw9UI8Ar38+4ZYFE3skS0cicrLQUDjOuyQq/BviDszpJ/wl57YN5sYFO+L 35lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702833501; x=1703438301; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yvzvPPOvURo9eUay1zjag8iF5jEJZnvBduw4ZeL4Nkg=; b=TGRDGCn1tXsvv8lVoF5M6oMeSy5MIrY2ci0lYQZMHa0DAYadDVeQm3oWkxGodwd2Wb DFY45sKz4usLGHu6c1YTnyP6PPIZpmQFH+7glr4J6jNlCEfKlgPE+Cg0+No5cKJ/ZZDD Dc2LmgH9Ikk9EPhSxyd5p3d4vRtQS07zgkyGkZTq0cTFGb5C8ByPDmuoeUhlD1zUGBjs +0lTL3cwbpAU6HatSHNN2NVtt7Y1CjCD2C9vmR9XEd7/TS1JfzAZRniL6IQ1v6L4VKWG FvxMDJMV8tibTZ5ufDID+GzVwyrZavMJjxMOO4NsS1HiRI/8uejw5Ah5DrZpMk1wbSG5 qXdw== X-Gm-Message-State: AOJu0Yy2KkBxrkYcE9O0baHaonATU9XppiahhlxRtVYYNJDG1DqZrSXN 81wNvMo9tRDolgQgo4d7rIr3 X-Received: by 2002:a05:6602:4902:b0:7b6:fc2d:6b52 with SMTP id ef2-20020a056602490200b007b6fc2d6b52mr17463986iob.4.1702833501039; Sun, 17 Dec 2023 09:18:21 -0800 (PST) Received: from thinkpad ([103.28.246.178]) by smtp.gmail.com with ESMTPSA id q18-20020a17090311d200b001d3867b6424sm4383852plh.113.2023.12.17.09.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 09:18:20 -0800 (PST) Date: Sun, 17 Dec 2023 22:48:11 +0530 From: Manivannan Sadhasivam To: Frank Li Cc: krzysztof.kozlowski@linaro.org, bhelgaas@google.com, conor+dt@kernel.org, devicetree@vger.kernel.org, festevam@gmail.com, helgaas@kernel.org, hongxing.zhu@nxp.com, imx@lists.linux.dev, kernel@pengutronix.de, krzysztof.kozlowski+dt@linaro.org, kw@linux.com, l.stach@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lpieralisi@kernel.org, robh@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org Subject: Re: [PATCH v4 02/15] PCI: imx6: Simplify phy handling by using by using IMX6_PCIE_FLAG_HAS_PHY Message-ID: <20231217171811.GD6748@thinkpad> References: <20231217051210.754832-1-Frank.Li@nxp.com> <20231217051210.754832-3-Frank.Li@nxp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231217051210.754832-3-Frank.Li@nxp.com> On Sun, Dec 17, 2023 at 12:11:57AM -0500, Frank Li wrote: > Refactors the phy handling logic in the imx6 PCI driver by adding > IMX6_PCIE_FLAG_HAS_PHY bitmask define for drvdata::flags. > > The drvdata::flags and a bitmask ensures a cleaner and more scalable > switch-case structure for handling phy. > > Signed-off-by: Frank Li > --- > > Notes: > Change from v1 to v3: > - none > > drivers/pci/controller/dwc/pci-imx6.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index 2086214345e9a..91ba26a4b4c3d 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -60,6 +60,9 @@ enum imx6_pcie_variants { > #define IMX6_PCIE_FLAG_IMX6_PHY BIT(0) > #define IMX6_PCIE_FLAG_IMX6_SPEED_CHANGE BIT(1) > #define IMX6_PCIE_FLAG_SUPPORTS_SUSPEND BIT(2) > +#define IMX6_PCIE_FLAG_HAS_PHY BIT(3) > + > +#define imx6_check_flag(pci, val) (pci->drvdata->flags & val) > > #define IMX6_PCIE_MAX_CLKS 6 > > @@ -1277,6 +1280,13 @@ static int imx6_pcie_probe(struct platform_device *pdev) > if (ret) > return ret; > > + if (imx6_check_flag(imx6_pcie, IMX6_PCIE_FLAG_HAS_PHY)) { > + imx6_pcie->phy = devm_phy_get(dev, "pcie-phy"); Can't you use devm_phy_optional_get()? This will return NULL if the PHY is not defined in DT. So you can use IS_ERR() to catch error if there are issues in acquiring PHY if defined and NULL can be safely passed to other PHY APIs like phy_init() as well. With this, you won't need a flag in drv_data and can also get rid of the condition around PHY APIs. - Mani > + if (IS_ERR(imx6_pcie->phy)) > + return dev_err_probe(dev, PTR_ERR(imx6_pcie->phy), > + "failed to get pcie phy\n"); > + } > + > switch (imx6_pcie->drvdata->variant) { > case IMX7D: > if (dbi_base->start == IMX8MQ_PCIE2_BASE_ADDR) > @@ -1306,11 +1316,6 @@ static int imx6_pcie_probe(struct platform_device *pdev) > return dev_err_probe(dev, PTR_ERR(imx6_pcie->apps_reset), > "failed to get pcie apps reset control\n"); > > - imx6_pcie->phy = devm_phy_get(dev, "pcie-phy"); > - if (IS_ERR(imx6_pcie->phy)) > - return dev_err_probe(dev, PTR_ERR(imx6_pcie->phy), > - "failed to get pcie phy\n"); > - > break; > default: > break; > @@ -1447,13 +1452,15 @@ static const struct imx6_pcie_drvdata drvdata[] = { > }, > [IMX8MM] = { > .variant = IMX8MM, > - .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND, > + .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND | > + IMX6_PCIE_FLAG_HAS_PHY, > .gpr = "fsl,imx8mm-iomuxc-gpr", > .clk_names = {IMX6_CLKS_COMMON, "pcie_aux"}, > }, > [IMX8MP] = { > .variant = IMX8MP, > - .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND, > + .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND | > + IMX6_PCIE_FLAG_HAS_PHY, > .gpr = "fsl,imx8mp-iomuxc-gpr", > .clk_names = {IMX6_CLKS_COMMON, "pcie_aux"}, > }, > @@ -1465,12 +1472,14 @@ static const struct imx6_pcie_drvdata drvdata[] = { > }, > [IMX8MM_EP] = { > .variant = IMX8MM_EP, > + .flags = IMX6_PCIE_FLAG_HAS_PHY, > .mode = DW_PCIE_EP_TYPE, > .gpr = "fsl,imx8mm-iomuxc-gpr", > .clk_names = {IMX6_CLKS_COMMON, "pcie_aux"}, > }, > [IMX8MP_EP] = { > .variant = IMX8MP_EP, > + .flags = IMX6_PCIE_FLAG_HAS_PHY, > .mode = DW_PCIE_EP_TYPE, > .gpr = "fsl,imx8mp-iomuxc-gpr", > .clk_names = {IMX6_CLKS_COMMON, "pcie_aux"}, > -- > 2.34.1 > -- மணிவண்ணன் சதாசிவம்