Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp992313rdb; Sat, 6 Jan 2024 21:17:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7u7G489b8YTDgkNaqCbITjH0T7yOfC8BdsnHljcmQ5crqa7jGJmEUX06mB8cERSfHeWpF X-Received: by 2002:a05:6e02:184e:b0:35f:b01c:3446 with SMTP id b14-20020a056e02184e00b0035fb01c3446mr3751398ilv.33.1704604636213; Sat, 06 Jan 2024 21:17:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704604636; cv=none; d=google.com; s=arc-20160816; b=n4gIMulWPDIb4X82mcg1OS6PRPo9rwCCOqlqlh0cqXRY42tDCLXKFTER/Bbl5F/T/x WRuREzwg3KrHjkHMP6b6bEdoMUnyU7MG1R70mQ8VV9Mnn+xOk77mlf8EL+QhcpHJvXpE bjKxgDk6OIvI678KHrQuAK8wEZZOyAsGb6l1fiYdOoOtZdJVRRnpTq8PxD3bczCNjz5j 5hHLQxOWOmzB6stD9dpANm8z9ilqPmM+Jvq0wABn0/GOSXX1rRmYaC1X5oBOha2lMzN5 to5O7U/OrjQCUSbGiefq/YTfNva8GV82PUplkrnPcmsHlWmSnl1g94pqTk0egqsPug5J WaWw== 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=NWyB8TfZzCqz702pXUBpDot48wicywENtsPUdumX/6U=; fh=iWBv4He8s+xpzrJY93iuua2RS8H3PW0G6YXgJrUCrjQ=; b=B8sl7WyN8StChAn9tmtHIZ7gUv3loGGpgIGiDW9aNsdLuZRQAWG6OwgeDxS2NkSZ8U /3KMWNhtjxQbZoQVc+edax51rRQCWI2sjcy6YcXLZFoD13WTq+k2L3SqnOClwdW0V5gt nOnOeEQkVSdtVv4KnYW69cjV/uG2j6pBW0xl0GeJyMeOkJrP1D3MsNDOvrixSv9ERguS /q/+RMLM7mrU8hYQ67gDx46orDLO5Ct2jztKO5AZjLi4Vim6pmGki6Un8nSmebSWOXHp YcScuap6t2vvMABcwcHaN3P+HIk07kPx09RdeTptIhrlt/liSfhT8LWUgZjLvyV0uzcC X0iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J6HCespu; spf=pass (google.com: domain of linux-kernel+bounces-18780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jj7-20020a170903048700b001d3f2ff59b3si3987986plb.279.2024.01.06.21.17.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 21:17:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J6HCespu; spf=pass (google.com: domain of linux-kernel+bounces-18780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18780-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D0F05282A4D for ; Sun, 7 Jan 2024 05:17:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AD72125B0; Sun, 7 Jan 2024 05:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="J6HCespu" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 321BE11CB7 for ; Sun, 7 Jan 2024 05:17:05 +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-pj1-f44.google.com with SMTP id 98e67ed59e1d1-28d2be70358so139965a91.0 for ; Sat, 06 Jan 2024 21:17:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704604625; x=1705209425; 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=NWyB8TfZzCqz702pXUBpDot48wicywENtsPUdumX/6U=; b=J6HCespuuQFvhxAJGb7kE7Xlfd9cdLvEsHm3jDco93avnFRCzQE+sqyxJXPG6gD0VG ggDxQ+yk/YAmgQ6q0gqBwWyeDPHrbeRo5CgPk1+q21c4prMxIk7yTDG761adgfx2QyrA Loh5yeLg8KhjVAcuDZCl76oPUE3QYhWJQ013LI5noWQ2rEVXihHjqk345G/TaMIuLCqr zyzcSXg4/m1hklPVOnLfB6wcbUcZuUhb0jdIqBm3gepc+jA7bPsSPQNc9jPWlrAZK0is 02w9iS6mNRdaDsIlNGE6pHrybIq3j2rf0AMadtYYTCXdgTQ4VNxxsIMlJB5NoHlw05Qn 3ZRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704604625; x=1705209425; 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=NWyB8TfZzCqz702pXUBpDot48wicywENtsPUdumX/6U=; b=tQA166hg6+VO5nFBHTKblw6IoG7a/PDMK3wCNdYxTIez5yAeMyN/5wggB4DAuPPySt NvvTmUeC9TU8gGZgmtsXYPG1syJ5hqt4+sWtbJY0Kd+I5exObIqf3v4RAoGtSJpYyoOv lXNNRe12ThM5af7rKnOhfZwZlYCL5VTrn/iX+sIt79KdTnD5Ra4KZ+A06hm7Oyj979Te mLWlKXMz8OdpDgZjh4JsdJWTuelMSiSKxs/utde2Tn6BCa6jh068N84agqcxExnh/32d mDXKragKk5F/r3PW6FLWDVcqw/mbIjEv6A0nMp4L/F0K8zS1uyHW5RLHp+fYpnDI9ZiO 4dDw== X-Gm-Message-State: AOJu0YykGwFj+TAKQ05pHz3W9QS+Jr8YNxD7u6pzINBPtkJ9WTPTvBsO D/rqsaLaqrixq1jAPvUuz8h7dKjcqXEo X-Received: by 2002:a05:6a20:3252:b0:18f:97c:8267 with SMTP id hm18-20020a056a20325200b0018f097c8267mr467006pzc.113.1704604625435; Sat, 06 Jan 2024 21:17:05 -0800 (PST) Received: from thinkpad ([103.197.115.97]) by smtp.gmail.com with ESMTPSA id q15-20020a170902dacf00b001d337b8c0b2sm3852056plx.7.2024.01.06.21.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 21:17:05 -0800 (PST) Date: Sun, 7 Jan 2024 10:46:55 +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 v7 07/16] PCI: imx6: Simplify configure_type() by using mode_off and mode_mask Message-ID: <20240107051655.GF3416@thinkpad> References: <20231227182727.1747435-1-Frank.Li@nxp.com> <20231227182727.1747435-8-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: <20231227182727.1747435-8-Frank.Li@nxp.com> On Wed, Dec 27, 2023 at 01:27:18PM -0500, Frank Li wrote: > Add drvdata::mode_off and drvdata::mode_mask to simple simplify > imx6_pcie_configure_type() logic. > > Signed-off-by: Frank Li Couple of comments below. > --- > > Notes: > Change from v2 to v3 > - none > Change from v1 to v2 > - use ffs() to fixe build error. > > drivers/pci/controller/dwc/pci-imx6.c | 60 ++++++++++++++++++--------- > 1 file changed, 40 insertions(+), 20 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index 588bfb616260e..717e8fa030deb 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -68,6 +68,7 @@ enum imx6_pcie_variants { > > #define IMX6_PCIE_MAX_CLKS 6 > > +#define IMX6_PCIE_MAX_INSTANCES 2 > struct imx6_pcie_drvdata { > enum imx6_pcie_variants variant; > enum dw_pcie_device_mode mode; > @@ -77,6 +78,8 @@ struct imx6_pcie_drvdata { > const char *clk_names[IMX6_PCIE_MAX_CLKS]; > const u32 ltssm_off; > const u32 ltssm_mask; > + const u32 mode_off[IMX6_PCIE_MAX_INSTANCES]; > + const u32 mode_mask[IMX6_PCIE_MAX_INSTANCES]; > }; > > struct imx6_pcie { > @@ -174,32 +177,25 @@ static unsigned int imx6_pcie_grp_offset(const struct imx6_pcie *imx6_pcie) > > static void imx6_pcie_configure_type(struct imx6_pcie *imx6_pcie) > { > - unsigned int mask, val, mode; > + const struct imx6_pcie_drvdata *drvdata = imx6_pcie->drvdata; > + unsigned int mask, val, mode, id; > > - if (imx6_pcie->drvdata->mode == DW_PCIE_EP_TYPE) > + if (drvdata->mode == DW_PCIE_EP_TYPE) > mode = PCI_EXP_TYPE_ENDPOINT; > else > mode = PCI_EXP_TYPE_ROOT_PORT; > > - switch (imx6_pcie->drvdata->variant) { > - case IMX8MQ: > - case IMX8MQ_EP: > - if (imx6_pcie->controller_id == 1) { > - mask = IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE; > - val = FIELD_PREP(IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE, > - mode); > - } else { > - mask = IMX6Q_GPR12_DEVICE_TYPE; > - val = FIELD_PREP(IMX6Q_GPR12_DEVICE_TYPE, mode); > - } > - break; > - default: > - mask = IMX6Q_GPR12_DEVICE_TYPE; > - val = FIELD_PREP(IMX6Q_GPR12_DEVICE_TYPE, mode); > - break; > - } > + id = imx6_pcie->controller_id; > + > + /* If mode_mask[id] is zero, means each controller have its individual gpr */ > + if (!drvdata->mode_mask[id]) > + id = 0; > + > + mask = drvdata->mode_mask[id]; > + /* FIELD_PREP mask have been constant */ No need of this comment. > + val = mode << (ffs(mask) - 1); > > - regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, mask, val); > + regmap_update_bits(imx6_pcie->iomuxc_gpr, drvdata->mode_off[id], mask, val); > } > > static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, bool exp_val) > @@ -1376,6 +1372,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > .clk_names = {"pcie_bus", "pcie", "pcie_phy"}, > .ltssm_off = IOMUXC_GPR12, > .ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > [IMX6SX] = { > .variant = IMX6SX, > @@ -1386,6 +1384,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > .clk_names = {"pcie_bus", "pcie", "pcie_phy", "pcie_inbound_axi"}, > .ltssm_off = IOMUXC_GPR12, > .ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > [IMX6QP] = { > .variant = IMX6QP, > @@ -1397,6 +1397,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > .clk_names = {"pcie_bus", "pcie", "pcie_phy"}, > .ltssm_off = IOMUXC_GPR12, > .ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > [IMX7D] = { > .variant = IMX7D, > @@ -1405,6 +1407,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > IMX6_PCIE_FLAG_HAS_PHY_RESET, > .gpr = "fsl,imx7d-iomuxc-gpr", > .clk_names = {"pcie_bus", "pcie", "pcie_phy"}, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > [IMX8MQ] = { > .variant = IMX8MQ, > @@ -1412,6 +1416,10 @@ static const struct imx6_pcie_drvdata drvdata[] = { > IMX6_PCIE_FLAG_HAS_PHY_RESET, > .gpr = "fsl,imx8mq-iomuxc-gpr", > .clk_names = {"pcie_bus", "pcie", "pcie_phy", "pcie_aux"}, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > + .mode_off[1] = IOMUXC_GPR12, > + .mode_mask[1] = IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE, Is the mode_mask differ between SoCs or fixed based on instances? I mean, if there is a guarantee that it is going to be IMX6Q_GPR12_DEVICE_TYPE for instance 1 and IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE for instance 2 etc... Then we can avoid these SoC specific config and simplify the code further. - Mani > }, > [IMX8MM] = { > .variant = IMX8MM, > @@ -1420,6 +1428,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > IMX6_PCIE_FLAG_HAS_APP_RESET, > .gpr = "fsl,imx8mm-iomuxc-gpr", > .clk_names = {"pcie_bus", "pcie", "pcie_aux"}, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > [IMX8MP] = { > .variant = IMX8MP, > @@ -1428,6 +1438,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > IMX6_PCIE_FLAG_HAS_APP_RESET, > .gpr = "fsl,imx8mp-iomuxc-gpr", > .clk_names = {"pcie_bus", "pcie", "pcie_aux"}, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > [IMX8MQ_EP] = { > .variant = IMX8MQ_EP, > @@ -1436,6 +1448,10 @@ static const struct imx6_pcie_drvdata drvdata[] = { > .mode = DW_PCIE_EP_TYPE, > .gpr = "fsl,imx8mq-iomuxc-gpr", > .clk_names = {"pcie_bus", "pcie", "pcie_phy", "pcie_aux"}, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > + .mode_off[1] = IOMUXC_GPR12, > + .mode_mask[1] = IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE, > }, > [IMX8MM_EP] = { > .variant = IMX8MM_EP, > @@ -1443,6 +1459,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > .mode = DW_PCIE_EP_TYPE, > .gpr = "fsl,imx8mm-iomuxc-gpr", > .clk_names = {"pcie_bus", "pcie", "pcie_aux"}, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > [IMX8MP_EP] = { > .variant = IMX8MP_EP, > @@ -1450,6 +1468,8 @@ static const struct imx6_pcie_drvdata drvdata[] = { > .mode = DW_PCIE_EP_TYPE, > .gpr = "fsl,imx8mp-iomuxc-gpr", > .clk_names = {"pcie_bus", "pcie", "pcie_aux"}, > + .mode_off[0] = IOMUXC_GPR12, > + .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > }, > }; > > -- > 2.34.1 > -- மணிவண்ணன் சதாசிவம்