Re: [PATCH v3 07/11] PCI: imx6: Simplify bit operations in PHY functions

From: Lucas Stach
Date: Fri Apr 12 2019 - 11:59:14 EST


Am Sonntag, den 31.03.2019, 21:25 -0700 schrieb Andrey Smirnov:
> Simplify the code by incorporating left shifts into constant
> defnitions as well as using FIELD_PREP/GENMASK. No functional change
> intended.
>
> > Cc: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>
> > Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
> > Cc: Fabio Estevam <fabio.estevam@xxxxxxx>
> > Cc: Chris Healy <cphealy@xxxxxxxxx>
> > Cc: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> > Cc: Leonard Crestez <leonard.crestez@xxxxxxx>
> > Cc: "A.s. Dong" <aisheng.dong@xxxxxxx>
> > Cc: Richard Zhu <hongxing.zhu@xxxxxxx>
> Cc: linux-imx@xxxxxxx
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Cc: linux-pci@xxxxxxxxxxxxxxx
> Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>

Reviewed-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>

> ---
> Âdrivers/pci/controller/dwc/pci-imx6.c | 28 +++++++++++++--------------
> Â1 file changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index b1f30b94fb30..a49e5e491e12 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -105,11 +105,11 @@ struct imx6_pcie {
> Â#define PL_OFFSET 0x700
> Â
> Â#define PCIE_PHY_CTRL (PL_OFFSET + 0x114)
> -#define PCIE_PHY_CTRL_DATA_LOC 0
> -#define PCIE_PHY_CTRL_CAP_ADR_LOC 16
> -#define PCIE_PHY_CTRL_CAP_DAT_LOC 17
> -#define PCIE_PHY_CTRL_WR_LOC 18
> -#define PCIE_PHY_CTRL_RD_LOC 19
> > +#define PCIE_PHY_CTRL_DATA(x) FIELD_PREP(GENMASK(15, 0), (x))
> > +#define PCIE_PHY_CTRL_CAP_ADR BIT(16)
> > +#define PCIE_PHY_CTRL_CAP_DAT BIT(17)
> > +#define PCIE_PHY_CTRL_WR BIT(18)
> > +#define PCIE_PHY_CTRL_RD BIT(19)
> Â
> Â#define PCIE_PHY_STAT (PL_OFFSET + 0x110)
> Â#define PCIE_PHY_STAT_ACK_LOC 16
> @@ -178,17 +178,17 @@ static int pcie_phy_wait_ack(struct imx6_pcie *imx6_pcie, int addr)
> > Â u32 val;
> > Â int ret;
> Â
> > - val = addr << PCIE_PHY_CTRL_DATA_LOC;
> > + val = PCIE_PHY_CTRL_DATA(addr);
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val);
> Â
> > - val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC);
> > + val |= PCIE_PHY_CTRL_CAP_ADR;
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val);
> Â
> > Â ret = pcie_phy_poll_ack(imx6_pcie, 1);
> > Â if (ret)
> > Â return ret;
> Â
> > - val = addr << PCIE_PHY_CTRL_DATA_LOC;
> > + val = PCIE_PHY_CTRL_DATA(addr);
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val);
> Â
> > Â return pcie_phy_poll_ack(imx6_pcie, 0);
> @@ -206,7 +206,7 @@ static int pcie_phy_read(struct imx6_pcie *imx6_pcie, int addr, int *data)
> > Â return ret;
> Â
> > Â /* assert Read signal */
> > - phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
> > + phy_ctl = PCIE_PHY_CTRL_RD;
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, phy_ctl);
> Â
> > Â ret = pcie_phy_poll_ack(imx6_pcie, 1);
> @@ -234,11 +234,11 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data)
> > Â if (ret)
> > Â return ret;
> Â
> > - var = data << PCIE_PHY_CTRL_DATA_LOC;
> > + var = PCIE_PHY_CTRL_DATA(data);
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
> Â
> > Â /* capture data */
> > - var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
> > + var |= PCIE_PHY_CTRL_CAP_DAT;
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
> Â
> > Â ret = pcie_phy_poll_ack(imx6_pcie, 1);
> @@ -246,7 +246,7 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data)
> > Â return ret;
> Â
> > Â /* deassert cap data */
> > - var = data << PCIE_PHY_CTRL_DATA_LOC;
> > + var = PCIE_PHY_CTRL_DATA(data);
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
> Â
> > Â /* wait for ack de-assertion */
> @@ -255,7 +255,7 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data)
> > Â return ret;
> Â
> > Â /* assert wr signal */
> > - var = 0x1 << PCIE_PHY_CTRL_WR_LOC;
> > + var = PCIE_PHY_CTRL_WR;
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
> Â
> > Â /* wait for ack */
> @@ -264,7 +264,7 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data)
> > Â return ret;
> Â
> > Â /* deassert wr signal */
> > - var = data << PCIE_PHY_CTRL_DATA_LOC;
> > + var = PCIE_PHY_CTRL_DATA(data);
> > Â dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
> Â
> > Â /* wait for ack de-assertion */