[PATCH v13 04/14] drm/mediatek: Add DPI sub driver

2016-03-15 Thread Philipp Zabel
Hi Daniel,

Am Mittwoch, den 09.03.2016, 22:23 +0800 schrieb Daniel Kurtz:
> Hi Philipp, Jie,
> 
> Some small comments.
> Nothing that can't be fixed after merging if you prefer.
>
> On Tue, Mar 8, 2016 at 9:27 PM, Philipp Zabel  
> wrote:
[...]
> > +static int mtk_dpi_power_on(struct mtk_dpi *dpi, enum mtk_dpi_power_ctl 
> > pctl)
> > +{
> > +   int ret;
> > +
> > +   dpi->power_ctl |= pctl;
> > +
> > +   if (!(dpi->power_ctl & DPI_POWER_START) &&
> > +   !((dpi->power_ctl & DPI_POWER_ENABLE) &&
> > + ((dpi->power_ctl & DPI_POWER_RESUME
> 
> There one too many () on the POWER_RESUME clause.

I'll try to remove the suspend ops and this with them.

[...]
> > +static SIMPLE_DEV_PM_OPS(mtk_dpi_pm_ops, mtk_dpi_suspend, mtk_dpi_resume);
> 
> Like hdmi & dsi, I think we can remove these PM routines.
> And maybe then we can remove the "DPI_POWER_RESUME" logic (which I
> don't grok yet)?

Right, also we probably should use drm_atomic_helper_suspend/resume in
mtk_drm_sys_suspend/resume.

[...]
> > diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.h 
> > b/drivers/gpu/drm/mediatek/mtk_dpi.h
> > new file mode 100644
> > index 000..4fa4114
> > --- /dev/null
> > +++ b/drivers/gpu/drm/mediatek/mtk_dpi.h
> 
> All of this can be moved to mtk_dpi.c.

Ok, I'll merge this into mtk_dpi.c.

regards
Philipp



[PATCH v13 04/14] drm/mediatek: Add DPI sub driver

2016-03-09 Thread Daniel Kurtz
Hi Philipp, Jie,

Some small comments.
Nothing that can't be fixed after merging if you prefer.

On Tue, Mar 8, 2016 at 9:27 PM, Philipp Zabel  wrote:
> From: Jie Qiu 
>
> Add DPI connector/encoder to support HDMI output via the
> attached HDMI bridge.
>
> Signed-off-by: Jie Qiu 
> Signed-off-by: Philipp Zabel 
> ---
>  drivers/gpu/drm/mediatek/Makefile   |   3 +-
>  drivers/gpu/drm/mediatek/mtk_dpi.c  | 757 
> 
>  drivers/gpu/drm/mediatek/mtk_dpi.h  |  85 
>  drivers/gpu/drm/mediatek/mtk_dpi_regs.h | 228 ++
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c  |   1 +
>  drivers/gpu/drm/mediatek/mtk_drm_drv.h  |   1 +
>  6 files changed, 1074 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/mediatek/mtk_dpi.c
>  create mode 100644 drivers/gpu/drm/mediatek/mtk_dpi.h
>  create mode 100644 drivers/gpu/drm/mediatek/mtk_dpi_regs.h
>
> diff --git a/drivers/gpu/drm/mediatek/Makefile 
> b/drivers/gpu/drm/mediatek/Makefile
> index e781db5a..5fcf58e 100644
> --- a/drivers/gpu/drm/mediatek/Makefile
> +++ b/drivers/gpu/drm/mediatek/Makefile
> @@ -8,6 +8,7 @@ mediatek-drm-y := mtk_disp_ovl.o \
>   mtk_drm_gem.o \
>   mtk_drm_plane.o \
>   mtk_dsi.o \
> - mtk_mipi_tx.o
> + mtk_mipi_tx.o \
> + mtk_dpi.o
>
>  obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
> diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c 
> b/drivers/gpu/drm/mediatek/mtk_dpi.c
> new file mode 100644
> index 000..ae81906
> --- /dev/null
> +++ b/drivers/gpu/drm/mediatek/mtk_dpi.c
> @@ -0,0 +1,757 @@
> +/*
> + * Copyright (c) 2014 MediaTek Inc.
> + * Author: Jie Qiu 
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "mtk_dpi.h"
> +#include "mtk_dpi_regs.h"
> +
> +enum mtk_dpi_polarity {
> +   MTK_DPI_POLARITY_RISING,
> +   MTK_DPI_POLARITY_FALLING,
> +};
> +
> +enum mtk_dpi_power_ctl {
> +   DPI_POWER_START = BIT(0),
> +   DPI_POWER_ENABLE = BIT(1),
> +   DPI_POWER_RESUME = BIT(2),
> +};
> +
> +struct mtk_dpi_polarities {
> +   enum mtk_dpi_polarity de_pol;
> +   enum mtk_dpi_polarity ck_pol;
> +   enum mtk_dpi_polarity hsync_pol;
> +   enum mtk_dpi_polarity vsync_pol;
> +};
> +
> +struct mtk_dpi_sync_param {
> +   u32 sync_width;
> +   u32 front_porch;
> +   u32 back_porch;
> +   bool shift_half_line;
> +};
> +
> +struct mtk_dpi_yc_limit {
> +   u16 y_top;
> +   u16 y_bottom;
> +   u16 c_top;
> +   u16 c_bottom;
> +};
> +
> +static void mtk_dpi_mask(struct mtk_dpi *dpi, u32 offset, u32 val, u32 mask)
> +{
> +   u32 tmp = readl(dpi->regs + offset) & ~mask;
> +
> +   tmp |= (val & mask);
> +   writel(tmp, dpi->regs + offset);
> +}
> +
> +static void mtk_dpi_sw_reset(struct mtk_dpi *dpi, bool reset)
> +{
> +   mtk_dpi_mask(dpi, DPI_RET, reset ? RST : 0, RST);
> +}
> +
> +static void mtk_dpi_enable(struct mtk_dpi *dpi)
> +{
> +   mtk_dpi_mask(dpi, DPI_EN, EN, EN);
> +}
> +
> +static void mtk_dpi_disable(struct mtk_dpi *dpi)
> +{
> +   mtk_dpi_mask(dpi, DPI_EN, 0, EN);
> +}
> +
> +static void mtk_dpi_config_hsync(struct mtk_dpi *dpi,
> +struct mtk_dpi_sync_param *sync)
> +{
> +   mtk_dpi_mask(dpi, DPI_TGEN_HWIDTH,
> +sync->sync_width << HPW, HPW_MASK);
> +   mtk_dpi_mask(dpi, DPI_TGEN_HPORCH,
> +sync->back_porch << HBP, HBP_MASK);
> +   mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, sync->front_porch << HFP,
> +HFP_MASK);
> +}
> +
> +static void mtk_dpi_config_vsync(struct mtk_dpi *dpi,
> +struct mtk_dpi_sync_param *sync,
> +u32 width_addr, u32 porch_addr)
> +{
> +   mtk_dpi_mask(dpi, width_addr,
> +sync->sync_width << VSYNC_WIDTH_SHIFT,
> +VSYNC_WIDTH_MASK);
> +   mtk_dpi_mask(dpi, width_addr,
> +sync->shift_half_line << VSYNC_HALF_LINE_SHIFT,
> +VSYNC_HALF_LINE_MASK);
> +   mtk_dpi_mask(dpi, porch_addr,
> +sync->back_porch << VSYNC_BACK_PORCH_SHIFT,
> +VSYNC_BACK_PORCH_MASK);
> +   mtk_dpi_mask(dpi, porch_addr,
> +sync->front_porch << VSYNC_FRONT_PORCH_SHIFT,
> +VSYNC_FRONT_PORCH_MASK);
> +}
> +
> +static void 

[PATCH v13 04/14] drm/mediatek: Add DPI sub driver

2016-03-08 Thread Philipp Zabel
From: Jie Qiu 

Add DPI connector/encoder to support HDMI output via the
attached HDMI bridge.

Signed-off-by: Jie Qiu 
Signed-off-by: Philipp Zabel 
---
 drivers/gpu/drm/mediatek/Makefile   |   3 +-
 drivers/gpu/drm/mediatek/mtk_dpi.c  | 757 
 drivers/gpu/drm/mediatek/mtk_dpi.h  |  85 
 drivers/gpu/drm/mediatek/mtk_dpi_regs.h | 228 ++
 drivers/gpu/drm/mediatek/mtk_drm_drv.c  |   1 +
 drivers/gpu/drm/mediatek/mtk_drm_drv.h  |   1 +
 6 files changed, 1074 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dpi.c
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dpi.h
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dpi_regs.h

diff --git a/drivers/gpu/drm/mediatek/Makefile 
b/drivers/gpu/drm/mediatek/Makefile
index e781db5a..5fcf58e 100644
--- a/drivers/gpu/drm/mediatek/Makefile
+++ b/drivers/gpu/drm/mediatek/Makefile
@@ -8,6 +8,7 @@ mediatek-drm-y := mtk_disp_ovl.o \
  mtk_drm_gem.o \
  mtk_drm_plane.o \
  mtk_dsi.o \
- mtk_mipi_tx.o
+ mtk_mipi_tx.o \
+ mtk_dpi.o

 obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c 
b/drivers/gpu/drm/mediatek/mtk_dpi.c
new file mode 100644
index 000..ae81906
--- /dev/null
+++ b/drivers/gpu/drm/mediatek/mtk_dpi.c
@@ -0,0 +1,757 @@
+/*
+ * Copyright (c) 2014 MediaTek Inc.
+ * Author: Jie Qiu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mtk_dpi.h"
+#include "mtk_dpi_regs.h"
+
+enum mtk_dpi_polarity {
+   MTK_DPI_POLARITY_RISING,
+   MTK_DPI_POLARITY_FALLING,
+};
+
+enum mtk_dpi_power_ctl {
+   DPI_POWER_START = BIT(0),
+   DPI_POWER_ENABLE = BIT(1),
+   DPI_POWER_RESUME = BIT(2),
+};
+
+struct mtk_dpi_polarities {
+   enum mtk_dpi_polarity de_pol;
+   enum mtk_dpi_polarity ck_pol;
+   enum mtk_dpi_polarity hsync_pol;
+   enum mtk_dpi_polarity vsync_pol;
+};
+
+struct mtk_dpi_sync_param {
+   u32 sync_width;
+   u32 front_porch;
+   u32 back_porch;
+   bool shift_half_line;
+};
+
+struct mtk_dpi_yc_limit {
+   u16 y_top;
+   u16 y_bottom;
+   u16 c_top;
+   u16 c_bottom;
+};
+
+static void mtk_dpi_mask(struct mtk_dpi *dpi, u32 offset, u32 val, u32 mask)
+{
+   u32 tmp = readl(dpi->regs + offset) & ~mask;
+
+   tmp |= (val & mask);
+   writel(tmp, dpi->regs + offset);
+}
+
+static void mtk_dpi_sw_reset(struct mtk_dpi *dpi, bool reset)
+{
+   mtk_dpi_mask(dpi, DPI_RET, reset ? RST : 0, RST);
+}
+
+static void mtk_dpi_enable(struct mtk_dpi *dpi)
+{
+   mtk_dpi_mask(dpi, DPI_EN, EN, EN);
+}
+
+static void mtk_dpi_disable(struct mtk_dpi *dpi)
+{
+   mtk_dpi_mask(dpi, DPI_EN, 0, EN);
+}
+
+static void mtk_dpi_config_hsync(struct mtk_dpi *dpi,
+struct mtk_dpi_sync_param *sync)
+{
+   mtk_dpi_mask(dpi, DPI_TGEN_HWIDTH,
+sync->sync_width << HPW, HPW_MASK);
+   mtk_dpi_mask(dpi, DPI_TGEN_HPORCH,
+sync->back_porch << HBP, HBP_MASK);
+   mtk_dpi_mask(dpi, DPI_TGEN_HPORCH, sync->front_porch << HFP,
+HFP_MASK);
+}
+
+static void mtk_dpi_config_vsync(struct mtk_dpi *dpi,
+struct mtk_dpi_sync_param *sync,
+u32 width_addr, u32 porch_addr)
+{
+   mtk_dpi_mask(dpi, width_addr,
+sync->sync_width << VSYNC_WIDTH_SHIFT,
+VSYNC_WIDTH_MASK);
+   mtk_dpi_mask(dpi, width_addr,
+sync->shift_half_line << VSYNC_HALF_LINE_SHIFT,
+VSYNC_HALF_LINE_MASK);
+   mtk_dpi_mask(dpi, porch_addr,
+sync->back_porch << VSYNC_BACK_PORCH_SHIFT,
+VSYNC_BACK_PORCH_MASK);
+   mtk_dpi_mask(dpi, porch_addr,
+sync->front_porch << VSYNC_FRONT_PORCH_SHIFT,
+VSYNC_FRONT_PORCH_MASK);
+}
+
+static void mtk_dpi_config_vsync_lodd(struct mtk_dpi *dpi,
+ struct mtk_dpi_sync_param *sync)
+{
+   mtk_dpi_config_vsync(dpi, sync, DPI_TGEN_VWIDTH, DPI_TGEN_VPORCH);
+}
+
+static void mtk_dpi_config_vsync_leven(struct mtk_dpi *dpi,
+  struct mtk_dpi_sync_param *sync)
+{
+   mtk_dpi_config_vsync(dpi, sync, DPI_TGEN_VWIDTH_LEVEN,
+