Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp996427rdb; Sat, 6 Jan 2024 21:36:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGl2Gr4k/+bf8vlFxwhVtAqqwqwZhWCJmiJmz5tDHJwosqXkJ3N8wAYdmDxBGoUe0XYtscE X-Received: by 2002:a05:6214:628:b0:680:c769:f621 with SMTP id a8-20020a056214062800b00680c769f621mr2235321qvx.59.1704605770504; Sat, 06 Jan 2024 21:36:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704605770; cv=none; d=google.com; s=arc-20160816; b=NcmeJ3LfBjBcDLkQcGVth5jFy/qDQCxol5+E88svtyUfo9jKaaMESi6cAPNWX1yDfX C6TJ32D/Z6zIVTlYB1vsqosGYoVNx6F2gyWJ9EY7f+M0J+WAkxbT03VFH+PKlNB5ZHGk PG5FtZTDHQadFf5x2VMcsXzpq0PwwuK1E9u6bOQNDLYaO85F6ICh6ziYbDcgeuhLEtwe kGAzsKJ5JoEzPX3k6qEjU1cgnsxPxCmHlTAc3+4miyXntdJrh44/QcNJPNL72Q144dfl 5czMIXBfZzedkn6ZgJnB2nU4fR+u5zAXk0RHugZwApSNMu6ZvnIKzmuWcuRHKY69Etvi b1OQ== 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=r/6veTlb3b926dnqCGkB7UbG60YqZdxmlPhte48QgzE=; fh=RV+5nlnE/mfkEDo+RaR4UWqJM0xfpxots2QhFlTS3j8=; b=bpQ9OT+qGhUx+Uvl53Wk6jl8wmxLxh/elvOCjirX2dv+S1Z/jYBfeUtSwBcMt0otKU Fgd36+MifPBBHBHj0Hgql/zUr3/1eHZNz+A3o/OZ3facmbkO8lBWsQO5ffBt684YJwc6 8lNzmUOE+LD/WzrYznyHhAfhJ6MreJhzhFlJsUuGcusjWaP++y8O0FPdYhiXFIk+3Iuz YmOB13HB/J1gwt5OxZAXh5+pwF+K59W1JExYeBoSt029apoO/JImZuodUBQhhZq6wt9a EynGCGQ1AaCubPsZ6PA0qTKR5uTwIzxfr1p4TtBzR5FZmohxsI8AVQvk2ARGv9dCeLWa aO6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O3HNTsqB; spf=pass (google.com: domain of linux-kernel+bounces-18786-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id qd7-20020ad44807000000b006801adc03a4si2533968qvb.332.2024.01.06.21.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 21:36:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18786-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O3HNTsqB; spf=pass (google.com: domain of linux-kernel+bounces-18786-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18786-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 389F81C21376 for ; Sun, 7 Jan 2024 05:36:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67AAD125BB; Sun, 7 Jan 2024 05:36:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="O3HNTsqB" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (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 14492882D for ; Sun, 7 Jan 2024 05:35:57 +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-oa1-f42.google.com with SMTP id 586e51a60fabf-2044d093b3fso778881fac.3 for ; Sat, 06 Jan 2024 21:35:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704605757; x=1705210557; 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=r/6veTlb3b926dnqCGkB7UbG60YqZdxmlPhte48QgzE=; b=O3HNTsqBVmOw17byi/3AfjELWYFYqdw3lF9jnXBnlbZkYKz2T9I2gBUZZpRk0IX65+ MRFKgdKA+gxR/gTqjVnVs6gKec0ln3WpREZ3/BfqDtJvUo7N/A7mQ2JqfWTgzUtcB6yF AH71+QX72LoLvaHfiav9T1eMUlxEtQMrghB7Hhhg5KquLoPT3lAJa7LHxiQYSAVwW6f+ do0tIJp1P974GeUd8hB6MZlZyXHpfvG17g2EkM8qqnefd+e8XMGzfUQRwbTi+DpfdgGo ZGVmF1rK/RXhdkKT5oqGMelcgVuhzPc3JF+G/Y3X4tZJ/znPR7pEKuQ9gogsxZpCEQwW /ZHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704605757; x=1705210557; 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=r/6veTlb3b926dnqCGkB7UbG60YqZdxmlPhte48QgzE=; b=KdfOhH6SPZKNcmzt+7kgMq7TtyOFNwTRTwvtJQ/rUmw80ez19c1zi3AtsVwhsjKy73 kTsP2+6P0VEcr9hhylkYid0cLX5CyZ4yVKywxiKwcE5bAIm/WxDT34OSm2yfNTIoWApJ ZtvWvvGfK77fI2UEnoEKR4hsyC7LEr5uQQ3VOCImoztXTldzMhiCSULBqoMJer7ivYq6 ZLznCPcL4ThlyeMekcfazDpagKE6/AYhoQeQYaH+OkFVZ1Z4ZjYArfCnOOOqKGFpibhL l3JWJPS0ysGVEWMusOXV/mLUvZD0tlm9YPmrMw9jp6bG6xnLjAJmSrn23V3QHdfvLoK6 dGRw== X-Gm-Message-State: AOJu0YyoxeMeVBqo6qzEn9zPejnfdY+ah2fNlJ7gHkha3u1DS9ZK+6e/ hBZTcF2+OGTtgPjMOfEKKPYSHrVMg/Fe X-Received: by 2002:a05:6871:7a0e:b0:203:2b71:dad5 with SMTP id pc14-20020a0568717a0e00b002032b71dad5mr2370437oac.8.1704605757126; Sat, 06 Jan 2024 21:35:57 -0800 (PST) Received: from thinkpad ([103.197.115.97]) by smtp.gmail.com with ESMTPSA id p3-20020a056a0026c300b006da19433468sm3833811pfw.61.2024.01.06.21.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 21:35:56 -0800 (PST) Date: Sun, 7 Jan 2024 11:05:48 +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: <20240107053548.GK3416@thinkpad> References: <20231227182727.1747435-1-Frank.Li@nxp.com> <20231227182727.1747435-8-Frank.Li@nxp.com> <20240107051655.GF3416@thinkpad> 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: On Sun, Jan 07, 2024 at 12:32:14AM -0500, Frank Li wrote: > On Sun, Jan 07, 2024 at 10:46:55AM +0530, Manivannan Sadhasivam wrote: > > 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. > > No, iMX95 will change it. > Ok, fine then. - Mani > Frank > > > > > - 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 > > > > > > > -- > > மணிவண்ணன் சதாசிவம் -- மணிவண்ணன் சதாசிவம்