All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
To: Jitao Shi <jitao.shi@mediatek.com>
Cc: Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@linux.ie>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	devicetree@vger.kernel.org, srv_heupstream@mediatek.com,
	huijuan.xie@mediatek.com, stonea168@163.com,
	cawa.cheng@mediatek.com,
	"moderated list:ARM/Mediatek SoC support" 
	<linux-mediatek@lists.infradead.org>,
	yingjoe.chen@mediatek.com, eddie.huang@mediatek.com,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v5 4/4] drm/mediatek: config mipitx impedance with calibration data
Date: Sat, 11 Apr 2020 00:12:16 +0800	[thread overview]
Message-ID: <CAAOTY_-ZiMKn5wVuhECnL4E6BM_=QoF9goorHB-GK-hRL40gyA@mail.gmail.com> (raw)
In-Reply-To: <20200410043248.114384-5-jitao.shi@mediatek.com>

Hi, Jitao:

Jitao Shi <jitao.shi@mediatek.com> 於 2020年4月10日 週五 下午12:33寫道:
>
> Read calibration data from nvmem, and config mipitx impedance with
> calibration data to make sure their impedance are 100ohm.
>
> Signed-off-by: Jitao Shi <jitao.shi@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.c        | 40 +++++++++++++++++++
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.h        |  3 ++
>  drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c | 21 ++++++++++
>  3 files changed, 64 insertions(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> index e301af64809e..5e91fc2c1318 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> @@ -88,6 +88,44 @@ static const struct phy_ops mtk_mipi_tx_ops = {
>         .owner = THIS_MODULE,
>  };
>
> +static void mtk_mipi_tx_get_calibration_datal(struct mtk_mipi_tx *mipi_tx)
> +{
> +       struct nvmem_cell *cell;
> +       size_t len;
> +       u32 *buf;
> +
> +       memset(mipi_tx->rt_code, 0, sizeof(mipi_tx->rt_code));

You use kzalloc() to allocate mipi_tx, so this is already zero-initialized.

> +       cell = nvmem_cell_get(mipi_tx->dev, "calibration-data");
> +       if (IS_ERR(cell)) {
> +               dev_info(mipi_tx->dev, "can't get nvmem_cell_get, ignore it\n");
> +       } else {

If you return when error, you could get rid of the 'else', so you
could reduce many 'tab' and reduce the probability of one line over 80
character.

> +               buf = (u32 *)nvmem_cell_read(cell, &len);
> +               nvmem_cell_put(cell);
> +
> +               if (IS_ERR(buf)) {
> +                       dev_info(mipi_tx->dev, "can't get data, ignore it\n");
> +               } else {

Ditto.

Regards,
Chun-Kuang.

> +                       if (len < 3 * sizeof(u32)) {
> +                               dev_info(mipi_tx->dev, "invalid calibration data\n");
> +                               kfree(buf);
> +                               return;
> +                       }
> +
> +                       mipi_tx->rt_code[0] = ((buf[0] >> 6 & 0x1f) << 5) |
> +                                              (buf[0] >> 11 & 0x1f);
> +                       mipi_tx->rt_code[1] = ((buf[1] >> 27 & 0x1f) << 5) |
> +                                              (buf[0] >> 1 & 0x1f);
> +                       mipi_tx->rt_code[2] = ((buf[1] >> 17 & 0x1f) << 5) |
> +                                              (buf[1] >> 22 & 0x1f);
> +                       mipi_tx->rt_code[3] = ((buf[1] >> 7 & 0x1f) << 5) |
> +                                              (buf[1] >> 12 & 0x1f);
> +                       mipi_tx->rt_code[4] = ((buf[2] >> 27 & 0x1f) << 5) |
> +                                              (buf[1] >> 2 & 0x1f);
> +                       kfree(buf);
> +               }
> +       }
> +}
> +
>  static int mtk_mipi_tx_probe(struct platform_device *pdev)
>  {
>         struct device *dev = &pdev->dev;
> @@ -174,6 +212,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
>
>         mipi_tx->dev = dev;
>
> +       mtk_mipi_tx_get_calibration_datal(mipi_tx);
> +
>         return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
>                                    mipi_tx->pll);
>  }
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> index eea44327fe9f..c76f07c3fdeb 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> @@ -12,9 +12,11 @@
>  #include <linux/delay.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
>  #include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/phy/phy.h>
> +#include <linux/slab.h>
>
>  struct mtk_mipitx_data {
>         const u32 mppll_preserve;
> @@ -28,6 +30,7 @@ struct mtk_mipi_tx {
>         void __iomem *regs;
>         u32 data_rate;
>         u32 mipitx_drive;
> +       u32 rt_code[5];
>         const struct mtk_mipitx_data *driver_data;
>         struct clk_hw pll_hw;
>         struct clk *pll;
> diff --git a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> index e4cc967750cb..9f3e55aeebb2 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> @@ -28,6 +28,7 @@
>  #define MIPITX_PLL_CON4                0x003c
>  #define RG_DSI_PLL_IBIAS               (3 << 10)
>
> +#define MIPITX_D2P_RTCODE      0x0100
>  #define MIPITX_D2_SW_CTL_EN    0x0144
>  #define MIPITX_D0_SW_CTL_EN    0x0244
>  #define MIPITX_CK_CKMODE_EN    0x0328
> @@ -108,6 +109,24 @@ static const struct clk_ops mtk_mipi_tx_pll_ops = {
>         .recalc_rate = mtk_mipi_tx_pll_recalc_rate,
>  };
>
> +static void mtk_mipi_tx_config_calibration_data(struct mtk_mipi_tx *mipi_tx)
> +{
> +       int i, j;
> +
> +       for (i = 0; i < 5; i++) {
> +               if ((mipi_tx->rt_code[i] & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10;
> +
> +               if ((mipi_tx->rt_code[i] >> 5 & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10 << 5;
> +
> +               for (j = 0; j < 10; j++)
> +                       mtk_mipi_tx_update_bits(mipi_tx,
> +                               MIPITX_D2P_RTCODE * (i + 1) + j * 4,
> +                               1, mipi_tx->rt_code[i] >> j & 1);
> +       }
> +}
> +
>  static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>  {
>         struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
> @@ -130,6 +149,8 @@ static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>                                 RG_DSI_HSTX_LDO_REF_SEL,
>                                 (mipi_tx->mipitx_drive - 3000) / 200 << 6);
>
> +       mtk_mipi_tx_config_calibration_data(mipi_tx);
> +
>         mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_CKMODE_EN, DSI_CK_CKMODE_EN);
>  }
>
> --
> 2.21.0
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
To: Jitao Shi <jitao.shi@mediatek.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, srv_heupstream@mediatek.com,
	David Airlie <airlied@linux.ie>,
	huijuan.xie@mediatek.com, stonea168@163.com,
	linux-kernel <linux-kernel@vger.kernel.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	cawa.cheng@mediatek.com, Rob Herring <robh+dt@kernel.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-mediatek@lists.infradead.org>,
	Daniel Vetter <daniel@ffwll.ch>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	yingjoe.chen@mediatek.com, eddie.huang@mediatek.com,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v5 4/4] drm/mediatek: config mipitx impedance with calibration data
Date: Sat, 11 Apr 2020 00:12:16 +0800	[thread overview]
Message-ID: <CAAOTY_-ZiMKn5wVuhECnL4E6BM_=QoF9goorHB-GK-hRL40gyA@mail.gmail.com> (raw)
In-Reply-To: <20200410043248.114384-5-jitao.shi@mediatek.com>

Hi, Jitao:

Jitao Shi <jitao.shi@mediatek.com> 於 2020年4月10日 週五 下午12:33寫道:
>
> Read calibration data from nvmem, and config mipitx impedance with
> calibration data to make sure their impedance are 100ohm.
>
> Signed-off-by: Jitao Shi <jitao.shi@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.c        | 40 +++++++++++++++++++
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.h        |  3 ++
>  drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c | 21 ++++++++++
>  3 files changed, 64 insertions(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> index e301af64809e..5e91fc2c1318 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> @@ -88,6 +88,44 @@ static const struct phy_ops mtk_mipi_tx_ops = {
>         .owner = THIS_MODULE,
>  };
>
> +static void mtk_mipi_tx_get_calibration_datal(struct mtk_mipi_tx *mipi_tx)
> +{
> +       struct nvmem_cell *cell;
> +       size_t len;
> +       u32 *buf;
> +
> +       memset(mipi_tx->rt_code, 0, sizeof(mipi_tx->rt_code));

You use kzalloc() to allocate mipi_tx, so this is already zero-initialized.

> +       cell = nvmem_cell_get(mipi_tx->dev, "calibration-data");
> +       if (IS_ERR(cell)) {
> +               dev_info(mipi_tx->dev, "can't get nvmem_cell_get, ignore it\n");
> +       } else {

If you return when error, you could get rid of the 'else', so you
could reduce many 'tab' and reduce the probability of one line over 80
character.

> +               buf = (u32 *)nvmem_cell_read(cell, &len);
> +               nvmem_cell_put(cell);
> +
> +               if (IS_ERR(buf)) {
> +                       dev_info(mipi_tx->dev, "can't get data, ignore it\n");
> +               } else {

Ditto.

Regards,
Chun-Kuang.

> +                       if (len < 3 * sizeof(u32)) {
> +                               dev_info(mipi_tx->dev, "invalid calibration data\n");
> +                               kfree(buf);
> +                               return;
> +                       }
> +
> +                       mipi_tx->rt_code[0] = ((buf[0] >> 6 & 0x1f) << 5) |
> +                                              (buf[0] >> 11 & 0x1f);
> +                       mipi_tx->rt_code[1] = ((buf[1] >> 27 & 0x1f) << 5) |
> +                                              (buf[0] >> 1 & 0x1f);
> +                       mipi_tx->rt_code[2] = ((buf[1] >> 17 & 0x1f) << 5) |
> +                                              (buf[1] >> 22 & 0x1f);
> +                       mipi_tx->rt_code[3] = ((buf[1] >> 7 & 0x1f) << 5) |
> +                                              (buf[1] >> 12 & 0x1f);
> +                       mipi_tx->rt_code[4] = ((buf[2] >> 27 & 0x1f) << 5) |
> +                                              (buf[1] >> 2 & 0x1f);
> +                       kfree(buf);
> +               }
> +       }
> +}
> +
>  static int mtk_mipi_tx_probe(struct platform_device *pdev)
>  {
>         struct device *dev = &pdev->dev;
> @@ -174,6 +212,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
>
>         mipi_tx->dev = dev;
>
> +       mtk_mipi_tx_get_calibration_datal(mipi_tx);
> +
>         return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
>                                    mipi_tx->pll);
>  }
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> index eea44327fe9f..c76f07c3fdeb 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> @@ -12,9 +12,11 @@
>  #include <linux/delay.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
>  #include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/phy/phy.h>
> +#include <linux/slab.h>
>
>  struct mtk_mipitx_data {
>         const u32 mppll_preserve;
> @@ -28,6 +30,7 @@ struct mtk_mipi_tx {
>         void __iomem *regs;
>         u32 data_rate;
>         u32 mipitx_drive;
> +       u32 rt_code[5];
>         const struct mtk_mipitx_data *driver_data;
>         struct clk_hw pll_hw;
>         struct clk *pll;
> diff --git a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> index e4cc967750cb..9f3e55aeebb2 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> @@ -28,6 +28,7 @@
>  #define MIPITX_PLL_CON4                0x003c
>  #define RG_DSI_PLL_IBIAS               (3 << 10)
>
> +#define MIPITX_D2P_RTCODE      0x0100
>  #define MIPITX_D2_SW_CTL_EN    0x0144
>  #define MIPITX_D0_SW_CTL_EN    0x0244
>  #define MIPITX_CK_CKMODE_EN    0x0328
> @@ -108,6 +109,24 @@ static const struct clk_ops mtk_mipi_tx_pll_ops = {
>         .recalc_rate = mtk_mipi_tx_pll_recalc_rate,
>  };
>
> +static void mtk_mipi_tx_config_calibration_data(struct mtk_mipi_tx *mipi_tx)
> +{
> +       int i, j;
> +
> +       for (i = 0; i < 5; i++) {
> +               if ((mipi_tx->rt_code[i] & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10;
> +
> +               if ((mipi_tx->rt_code[i] >> 5 & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10 << 5;
> +
> +               for (j = 0; j < 10; j++)
> +                       mtk_mipi_tx_update_bits(mipi_tx,
> +                               MIPITX_D2P_RTCODE * (i + 1) + j * 4,
> +                               1, mipi_tx->rt_code[i] >> j & 1);
> +       }
> +}
> +
>  static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>  {
>         struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
> @@ -130,6 +149,8 @@ static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>                                 RG_DSI_HSTX_LDO_REF_SEL,
>                                 (mipi_tx->mipitx_drive - 3000) / 200 << 6);
>
> +       mtk_mipi_tx_config_calibration_data(mipi_tx);
> +
>         mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_CKMODE_EN, DSI_CK_CKMODE_EN);
>  }
>
> --
> 2.21.0
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
To: Jitao Shi <jitao.shi@mediatek.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, srv_heupstream@mediatek.com,
	David Airlie <airlied@linux.ie>,
	huijuan.xie@mediatek.com, stonea168@163.com,
	linux-kernel <linux-kernel@vger.kernel.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	cawa.cheng@mediatek.com, Rob Herring <robh+dt@kernel.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-mediatek@lists.infradead.org>,
	Daniel Vetter <daniel@ffwll.ch>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	yingjoe.chen@mediatek.com, eddie.huang@mediatek.com,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v5 4/4] drm/mediatek: config mipitx impedance with calibration data
Date: Sat, 11 Apr 2020 00:12:16 +0800	[thread overview]
Message-ID: <CAAOTY_-ZiMKn5wVuhECnL4E6BM_=QoF9goorHB-GK-hRL40gyA@mail.gmail.com> (raw)
In-Reply-To: <20200410043248.114384-5-jitao.shi@mediatek.com>

Hi, Jitao:

Jitao Shi <jitao.shi@mediatek.com> 於 2020年4月10日 週五 下午12:33寫道:
>
> Read calibration data from nvmem, and config mipitx impedance with
> calibration data to make sure their impedance are 100ohm.
>
> Signed-off-by: Jitao Shi <jitao.shi@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.c        | 40 +++++++++++++++++++
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.h        |  3 ++
>  drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c | 21 ++++++++++
>  3 files changed, 64 insertions(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> index e301af64809e..5e91fc2c1318 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> @@ -88,6 +88,44 @@ static const struct phy_ops mtk_mipi_tx_ops = {
>         .owner = THIS_MODULE,
>  };
>
> +static void mtk_mipi_tx_get_calibration_datal(struct mtk_mipi_tx *mipi_tx)
> +{
> +       struct nvmem_cell *cell;
> +       size_t len;
> +       u32 *buf;
> +
> +       memset(mipi_tx->rt_code, 0, sizeof(mipi_tx->rt_code));

You use kzalloc() to allocate mipi_tx, so this is already zero-initialized.

> +       cell = nvmem_cell_get(mipi_tx->dev, "calibration-data");
> +       if (IS_ERR(cell)) {
> +               dev_info(mipi_tx->dev, "can't get nvmem_cell_get, ignore it\n");
> +       } else {

If you return when error, you could get rid of the 'else', so you
could reduce many 'tab' and reduce the probability of one line over 80
character.

> +               buf = (u32 *)nvmem_cell_read(cell, &len);
> +               nvmem_cell_put(cell);
> +
> +               if (IS_ERR(buf)) {
> +                       dev_info(mipi_tx->dev, "can't get data, ignore it\n");
> +               } else {

Ditto.

Regards,
Chun-Kuang.

> +                       if (len < 3 * sizeof(u32)) {
> +                               dev_info(mipi_tx->dev, "invalid calibration data\n");
> +                               kfree(buf);
> +                               return;
> +                       }
> +
> +                       mipi_tx->rt_code[0] = ((buf[0] >> 6 & 0x1f) << 5) |
> +                                              (buf[0] >> 11 & 0x1f);
> +                       mipi_tx->rt_code[1] = ((buf[1] >> 27 & 0x1f) << 5) |
> +                                              (buf[0] >> 1 & 0x1f);
> +                       mipi_tx->rt_code[2] = ((buf[1] >> 17 & 0x1f) << 5) |
> +                                              (buf[1] >> 22 & 0x1f);
> +                       mipi_tx->rt_code[3] = ((buf[1] >> 7 & 0x1f) << 5) |
> +                                              (buf[1] >> 12 & 0x1f);
> +                       mipi_tx->rt_code[4] = ((buf[2] >> 27 & 0x1f) << 5) |
> +                                              (buf[1] >> 2 & 0x1f);
> +                       kfree(buf);
> +               }
> +       }
> +}
> +
>  static int mtk_mipi_tx_probe(struct platform_device *pdev)
>  {
>         struct device *dev = &pdev->dev;
> @@ -174,6 +212,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
>
>         mipi_tx->dev = dev;
>
> +       mtk_mipi_tx_get_calibration_datal(mipi_tx);
> +
>         return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
>                                    mipi_tx->pll);
>  }
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> index eea44327fe9f..c76f07c3fdeb 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> @@ -12,9 +12,11 @@
>  #include <linux/delay.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
>  #include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/phy/phy.h>
> +#include <linux/slab.h>
>
>  struct mtk_mipitx_data {
>         const u32 mppll_preserve;
> @@ -28,6 +30,7 @@ struct mtk_mipi_tx {
>         void __iomem *regs;
>         u32 data_rate;
>         u32 mipitx_drive;
> +       u32 rt_code[5];
>         const struct mtk_mipitx_data *driver_data;
>         struct clk_hw pll_hw;
>         struct clk *pll;
> diff --git a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> index e4cc967750cb..9f3e55aeebb2 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> @@ -28,6 +28,7 @@
>  #define MIPITX_PLL_CON4                0x003c
>  #define RG_DSI_PLL_IBIAS               (3 << 10)
>
> +#define MIPITX_D2P_RTCODE      0x0100
>  #define MIPITX_D2_SW_CTL_EN    0x0144
>  #define MIPITX_D0_SW_CTL_EN    0x0244
>  #define MIPITX_CK_CKMODE_EN    0x0328
> @@ -108,6 +109,24 @@ static const struct clk_ops mtk_mipi_tx_pll_ops = {
>         .recalc_rate = mtk_mipi_tx_pll_recalc_rate,
>  };
>
> +static void mtk_mipi_tx_config_calibration_data(struct mtk_mipi_tx *mipi_tx)
> +{
> +       int i, j;
> +
> +       for (i = 0; i < 5; i++) {
> +               if ((mipi_tx->rt_code[i] & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10;
> +
> +               if ((mipi_tx->rt_code[i] >> 5 & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10 << 5;
> +
> +               for (j = 0; j < 10; j++)
> +                       mtk_mipi_tx_update_bits(mipi_tx,
> +                               MIPITX_D2P_RTCODE * (i + 1) + j * 4,
> +                               1, mipi_tx->rt_code[i] >> j & 1);
> +       }
> +}
> +
>  static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>  {
>         struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
> @@ -130,6 +149,8 @@ static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>                                 RG_DSI_HSTX_LDO_REF_SEL,
>                                 (mipi_tx->mipitx_drive - 3000) / 200 << 6);
>
> +       mtk_mipi_tx_config_calibration_data(mipi_tx);
> +
>         mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_CKMODE_EN, DSI_CK_CKMODE_EN);
>  }
>
> --
> 2.21.0
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
To: Jitao Shi <jitao.shi@mediatek.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, srv_heupstream@mediatek.com,
	David Airlie <airlied@linux.ie>,
	huijuan.xie@mediatek.com, stonea168@163.com,
	linux-kernel <linux-kernel@vger.kernel.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	cawa.cheng@mediatek.com, Rob Herring <robh+dt@kernel.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-mediatek@lists.infradead.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	yingjoe.chen@mediatek.com, eddie.huang@mediatek.com,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v5 4/4] drm/mediatek: config mipitx impedance with calibration data
Date: Sat, 11 Apr 2020 00:12:16 +0800	[thread overview]
Message-ID: <CAAOTY_-ZiMKn5wVuhECnL4E6BM_=QoF9goorHB-GK-hRL40gyA@mail.gmail.com> (raw)
In-Reply-To: <20200410043248.114384-5-jitao.shi@mediatek.com>

Hi, Jitao:

Jitao Shi <jitao.shi@mediatek.com> 於 2020年4月10日 週五 下午12:33寫道:
>
> Read calibration data from nvmem, and config mipitx impedance with
> calibration data to make sure their impedance are 100ohm.
>
> Signed-off-by: Jitao Shi <jitao.shi@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.c        | 40 +++++++++++++++++++
>  drivers/gpu/drm/mediatek/mtk_mipi_tx.h        |  3 ++
>  drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c | 21 ++++++++++
>  3 files changed, 64 insertions(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> index e301af64809e..5e91fc2c1318 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.c
> @@ -88,6 +88,44 @@ static const struct phy_ops mtk_mipi_tx_ops = {
>         .owner = THIS_MODULE,
>  };
>
> +static void mtk_mipi_tx_get_calibration_datal(struct mtk_mipi_tx *mipi_tx)
> +{
> +       struct nvmem_cell *cell;
> +       size_t len;
> +       u32 *buf;
> +
> +       memset(mipi_tx->rt_code, 0, sizeof(mipi_tx->rt_code));

You use kzalloc() to allocate mipi_tx, so this is already zero-initialized.

> +       cell = nvmem_cell_get(mipi_tx->dev, "calibration-data");
> +       if (IS_ERR(cell)) {
> +               dev_info(mipi_tx->dev, "can't get nvmem_cell_get, ignore it\n");
> +       } else {

If you return when error, you could get rid of the 'else', so you
could reduce many 'tab' and reduce the probability of one line over 80
character.

> +               buf = (u32 *)nvmem_cell_read(cell, &len);
> +               nvmem_cell_put(cell);
> +
> +               if (IS_ERR(buf)) {
> +                       dev_info(mipi_tx->dev, "can't get data, ignore it\n");
> +               } else {

Ditto.

Regards,
Chun-Kuang.

> +                       if (len < 3 * sizeof(u32)) {
> +                               dev_info(mipi_tx->dev, "invalid calibration data\n");
> +                               kfree(buf);
> +                               return;
> +                       }
> +
> +                       mipi_tx->rt_code[0] = ((buf[0] >> 6 & 0x1f) << 5) |
> +                                              (buf[0] >> 11 & 0x1f);
> +                       mipi_tx->rt_code[1] = ((buf[1] >> 27 & 0x1f) << 5) |
> +                                              (buf[0] >> 1 & 0x1f);
> +                       mipi_tx->rt_code[2] = ((buf[1] >> 17 & 0x1f) << 5) |
> +                                              (buf[1] >> 22 & 0x1f);
> +                       mipi_tx->rt_code[3] = ((buf[1] >> 7 & 0x1f) << 5) |
> +                                              (buf[1] >> 12 & 0x1f);
> +                       mipi_tx->rt_code[4] = ((buf[2] >> 27 & 0x1f) << 5) |
> +                                              (buf[1] >> 2 & 0x1f);
> +                       kfree(buf);
> +               }
> +       }
> +}
> +
>  static int mtk_mipi_tx_probe(struct platform_device *pdev)
>  {
>         struct device *dev = &pdev->dev;
> @@ -174,6 +212,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
>
>         mipi_tx->dev = dev;
>
> +       mtk_mipi_tx_get_calibration_datal(mipi_tx);
> +
>         return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
>                                    mipi_tx->pll);
>  }
> diff --git a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> index eea44327fe9f..c76f07c3fdeb 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> +++ b/drivers/gpu/drm/mediatek/mtk_mipi_tx.h
> @@ -12,9 +12,11 @@
>  #include <linux/delay.h>
>  #include <linux/io.h>
>  #include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
>  #include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/phy/phy.h>
> +#include <linux/slab.h>
>
>  struct mtk_mipitx_data {
>         const u32 mppll_preserve;
> @@ -28,6 +30,7 @@ struct mtk_mipi_tx {
>         void __iomem *regs;
>         u32 data_rate;
>         u32 mipitx_drive;
> +       u32 rt_code[5];
>         const struct mtk_mipitx_data *driver_data;
>         struct clk_hw pll_hw;
>         struct clk *pll;
> diff --git a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> index e4cc967750cb..9f3e55aeebb2 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mt8183_mipi_tx.c
> @@ -28,6 +28,7 @@
>  #define MIPITX_PLL_CON4                0x003c
>  #define RG_DSI_PLL_IBIAS               (3 << 10)
>
> +#define MIPITX_D2P_RTCODE      0x0100
>  #define MIPITX_D2_SW_CTL_EN    0x0144
>  #define MIPITX_D0_SW_CTL_EN    0x0244
>  #define MIPITX_CK_CKMODE_EN    0x0328
> @@ -108,6 +109,24 @@ static const struct clk_ops mtk_mipi_tx_pll_ops = {
>         .recalc_rate = mtk_mipi_tx_pll_recalc_rate,
>  };
>
> +static void mtk_mipi_tx_config_calibration_data(struct mtk_mipi_tx *mipi_tx)
> +{
> +       int i, j;
> +
> +       for (i = 0; i < 5; i++) {
> +               if ((mipi_tx->rt_code[i] & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10;
> +
> +               if ((mipi_tx->rt_code[i] >> 5 & 0x1f) == 0)
> +                       mipi_tx->rt_code[i] |= 0x10 << 5;
> +
> +               for (j = 0; j < 10; j++)
> +                       mtk_mipi_tx_update_bits(mipi_tx,
> +                               MIPITX_D2P_RTCODE * (i + 1) + j * 4,
> +                               1, mipi_tx->rt_code[i] >> j & 1);
> +       }
> +}
> +
>  static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>  {
>         struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
> @@ -130,6 +149,8 @@ static void mtk_mipi_tx_power_on_signal(struct phy *phy)
>                                 RG_DSI_HSTX_LDO_REF_SEL,
>                                 (mipi_tx->mipitx_drive - 3000) / 200 << 6);
>
> +       mtk_mipi_tx_config_calibration_data(mipi_tx);
> +
>         mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_CKMODE_EN, DSI_CK_CKMODE_EN);
>  }
>
> --
> 2.21.0
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-04-10 16:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10  4:32 [PATCH v5 0/4] Config mipi tx current and impedance Jitao Shi
2020-04-10  4:32 ` Jitao Shi
2020-04-10  4:32 ` Jitao Shi
2020-04-10  4:32 ` Jitao Shi
2020-04-10  4:32 ` [PATCH v5 1/4] dt-bindings: display: mediatek: add property to control mipi tx drive current Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32 ` [PATCH v5 2/4] dt-bindings: display: mediatek: get mipitx calibration data from nvmem Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32 ` [PATCH v5 3/4] drm/mediatek: add the mipitx driving control Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32 ` [PATCH v5 4/4] drm/mediatek: config mipitx impedance with calibration data Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10  4:32   ` Jitao Shi
2020-04-10 16:12   ` Chun-Kuang Hu [this message]
2020-04-10 16:12     ` Chun-Kuang Hu
2020-04-10 16:12     ` Chun-Kuang Hu
2020-04-10 16:12     ` Chun-Kuang Hu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAOTY_-ZiMKn5wVuhECnL4E6BM_=QoF9goorHB-GK-hRL40gyA@mail.gmail.com' \
    --to=chunkuang.hu@kernel.org \
    --cc=airlied@linux.ie \
    --cc=cawa.cheng@mediatek.com \
    --cc=daniel@ffwll.ch \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eddie.huang@mediatek.com \
    --cc=huijuan.xie@mediatek.com \
    --cc=jitao.shi@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=srv_heupstream@mediatek.com \
    --cc=stonea168@163.com \
    --cc=yingjoe.chen@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.