Re: [linux-sunxi] [PATCH v2 18/20] drm/sun4i: Add HDMI support

2017-05-12 Thread Chen-Yu Tsai
On Thu, May 4, 2017 at 3:55 PM, Chen-Yu Tsai  wrote:
> On Wed, May 3, 2017 at 7:59 PM, Maxime Ripard
>  wrote:
>> The earlier Allwinner SoCs (A10, A10s, A20, A31) have an embedded HDMI
>> controller.
>>
>> That HDMI controller is able to do audio and CEC, but those have been left
>> out for now.
>>
>> Signed-off-by: Maxime Ripard 
>> ---
>>  drivers/gpu/drm/sun4i/Kconfig   |   9 +-
>>  drivers/gpu/drm/sun4i/Makefile  |   6 +-
>>  drivers/gpu/drm/sun4i/sun4i_hdmi.h  | 157 +++-
>>  drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c  | 127 +-
>>  drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c  | 493 +-
>>  drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c | 225 ++-
>>  6 files changed, 1017 insertions(+), 0 deletions(-)
>>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi.h
>>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c
>>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
>>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c
>>
>> diff --git a/drivers/gpu/drm/sun4i/Kconfig b/drivers/gpu/drm/sun4i/Kconfig
>> index a4b357db8856..35299c4e2594 100644
>> --- a/drivers/gpu/drm/sun4i/Kconfig
>> +++ b/drivers/gpu/drm/sun4i/Kconfig
>> @@ -12,3 +12,12 @@ config DRM_SUN4I
>>   Choose this option if you have an Allwinner SoC with a
>>   Display Engine. If M is selected the module will be called
>>   sun4i-drm.
>> +
>> +if DRM_SUN4I
>> +config DRM_SUN4I_HDMI
>> +   tristate "Allwinner A10 HDMI Controller Support"
>> +   help
>> + Choose this option if you have an Allwinner SoC with an HDMI
>> + controller.
>> +
>> +endif
>> diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
>> index 59b757350a1f..c09bf8093710 100644
>> --- a/drivers/gpu/drm/sun4i/Makefile
>> +++ b/drivers/gpu/drm/sun4i/Makefile
>> @@ -11,3 +11,9 @@ obj-$(CONFIG_DRM_SUN4I)   += sun4i-drm.o 
>> sun4i-tcon.o
>>  obj-$(CONFIG_DRM_SUN4I)+= sun4i_backend.o
>>  obj-$(CONFIG_DRM_SUN4I)+= sun6i_drc.o
>>  obj-$(CONFIG_DRM_SUN4I)+= sun4i_tv.o
>> +
>> +sun4i-drm-hdmi-y += sun4i_hdmi_enc.o
>> +sun4i-drm-hdmi-y += sun4i_hdmi_ddc_clk.o
>> +sun4i-drm-hdmi-y += sun4i_hdmi_tmds_clk.o
>> +
>> +obj-$(CONFIG_DRM_SUN4I_HDMI)   += sun4i-drm-hdmi.o
>> diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi.h 
>> b/drivers/gpu/drm/sun4i/sun4i_hdmi.h
>> new file mode 100644
>> index ..40d57b195b48
>> --- /dev/null
>> +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi.h
>> @@ -0,0 +1,157 @@
>> +/*
>> + * Copyright (C) 2016 Maxime Ripard
>> + *
>> + * Maxime Ripard 
>> + *
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public License as
>> + * published by the Free Software Foundation; either version 2 of
>> + * the License, or (at your option) any later version.
>> + */
>> +
>> +#ifndef _SUN4I_HDMI_H_
>> +#define _SUN4I_HDMI_H_
>> +
>> +#include 
>> +#include 
>> +
>> +#define SUN4I_HDMI_CTRL_REG0x004
>> +#define SUN4I_HDMI_CTRL_ENABLE BIT(31)
>> +
>> +#define SUN4I_HDMI_IRQ_REG 0x008
>> +#define SUN4I_HDMI_IRQ_STA_MASK0x73
>> +#define SUN4I_HDMI_IRQ_STA_FIFO_OF BIT(1)
>> +#define SUN4I_HDMI_IRQ_STA_FIFO_UF BIT(0)
>> +
>> +#define SUN4I_HDMI_HPD_REG 0x00c
>> +#define SUN4I_HDMI_HPD_HIGHBIT(0)
>> +
>> +#define SUN4I_HDMI_VID_CTRL_REG0x010
>> +#define SUN4I_HDMI_VID_CTRL_ENABLE BIT(31)
>> +#define SUN4I_HDMI_VID_CTRL_HDMI_MODE  BIT(30)
>> +
>> +#define SUN4I_HDMI_VID_TIMING_ACT_REG  0x014
>> +#define SUN4I_HDMI_VID_TIMING_BP_REG   0x018
>> +#define SUN4I_HDMI_VID_TIMING_FP_REG   0x01c
>> +#define SUN4I_HDMI_VID_TIMING_SPW_REG  0x020
>> +
>> +#define SUN4I_HDMI_VID_TIMING_X(x) x) - 1) & GENMASK(11, 
>> 0)))
>> +#define SUN4I_HDMI_VID_TIMING_Y(y) y) - 1) & GENMASK(11, 
>> 0)) << 16)
>> +
>> +#define SUN4I_HDMI_VID_TIMING_POL_REG  0x024
>> +#define SUN4I_HDMI_VID_TIMING_POL_TX_CLK(0x3e0 << 16)
>> +#define SUN4I_HDMI_VID_TIMING_POL_VSYNCBIT(1)
>> +#define SUN4I_HDMI_VID_TIMING_POL_HSYNCBIT(0)
>> +
>> +#define SUN4I_HDMI_AVI_INFOFRAME_REG(n)(0x080 + (n))
>> +
>> +#define SUN4I_HDMI_PAD_CTRL0_REG   0x200
>> +#define SUN4I_HDMI_PAD_CTRL0_BIASENBIT(31)
>> +#define SUN4I_HDMI_PAD_CTRL0_LDOCENBIT(30)
>> +#define SUN4I_HDMI_PAD_CTRL0_LDODENBIT(29)
>> +#define SUN4I_HDMI_PAD_CTRL0_PWENC BIT(28)
>> +#define SUN4I_HDMI_PAD_CTRL0_PWEND BIT(27)
>> +#define SUN4I_HDMI_PAD_CTRL0_PWENG BIT(26)
>> +#define SUN4I_HDMI_PAD_CTRL0_CKEN  BIT(25)
>> +#define SUN4I_HDMI_PAD_CTRL0_TXEN   

Re: [linux-sunxi] [PATCH v2 18/20] drm/sun4i: Add HDMI support

2017-05-04 Thread Chen-Yu Tsai
On Wed, May 3, 2017 at 7:59 PM, Maxime Ripard
 wrote:
> The earlier Allwinner SoCs (A10, A10s, A20, A31) have an embedded HDMI
> controller.
>
> That HDMI controller is able to do audio and CEC, but those have been left
> out for now.
>
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/gpu/drm/sun4i/Kconfig   |   9 +-
>  drivers/gpu/drm/sun4i/Makefile  |   6 +-
>  drivers/gpu/drm/sun4i/sun4i_hdmi.h  | 157 +++-
>  drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c  | 127 +-
>  drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c  | 493 +-
>  drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c | 225 ++-
>  6 files changed, 1017 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi.h
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c
>
> diff --git a/drivers/gpu/drm/sun4i/Kconfig b/drivers/gpu/drm/sun4i/Kconfig
> index a4b357db8856..35299c4e2594 100644
> --- a/drivers/gpu/drm/sun4i/Kconfig
> +++ b/drivers/gpu/drm/sun4i/Kconfig
> @@ -12,3 +12,12 @@ config DRM_SUN4I
>   Choose this option if you have an Allwinner SoC with a
>   Display Engine. If M is selected the module will be called
>   sun4i-drm.
> +
> +if DRM_SUN4I
> +config DRM_SUN4I_HDMI
> +   tristate "Allwinner A10 HDMI Controller Support"
> +   help
> + Choose this option if you have an Allwinner SoC with an HDMI
> + controller.
> +
> +endif
> diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
> index 59b757350a1f..c09bf8093710 100644
> --- a/drivers/gpu/drm/sun4i/Makefile
> +++ b/drivers/gpu/drm/sun4i/Makefile
> @@ -11,3 +11,9 @@ obj-$(CONFIG_DRM_SUN4I)   += sun4i-drm.o 
> sun4i-tcon.o
>  obj-$(CONFIG_DRM_SUN4I)+= sun4i_backend.o
>  obj-$(CONFIG_DRM_SUN4I)+= sun6i_drc.o
>  obj-$(CONFIG_DRM_SUN4I)+= sun4i_tv.o
> +
> +sun4i-drm-hdmi-y += sun4i_hdmi_enc.o
> +sun4i-drm-hdmi-y += sun4i_hdmi_ddc_clk.o
> +sun4i-drm-hdmi-y += sun4i_hdmi_tmds_clk.o
> +
> +obj-$(CONFIG_DRM_SUN4I_HDMI)   += sun4i-drm-hdmi.o
> diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi.h 
> b/drivers/gpu/drm/sun4i/sun4i_hdmi.h
> new file mode 100644
> index ..40d57b195b48
> --- /dev/null
> +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi.h
> @@ -0,0 +1,157 @@
> +/*
> + * Copyright (C) 2016 Maxime Ripard
> + *
> + * Maxime Ripard 
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + */
> +
> +#ifndef _SUN4I_HDMI_H_
> +#define _SUN4I_HDMI_H_
> +
> +#include 
> +#include 
> +
> +#define SUN4I_HDMI_CTRL_REG0x004
> +#define SUN4I_HDMI_CTRL_ENABLE BIT(31)
> +
> +#define SUN4I_HDMI_IRQ_REG 0x008
> +#define SUN4I_HDMI_IRQ_STA_MASK0x73
> +#define SUN4I_HDMI_IRQ_STA_FIFO_OF BIT(1)
> +#define SUN4I_HDMI_IRQ_STA_FIFO_UF BIT(0)
> +
> +#define SUN4I_HDMI_HPD_REG 0x00c
> +#define SUN4I_HDMI_HPD_HIGHBIT(0)
> +
> +#define SUN4I_HDMI_VID_CTRL_REG0x010
> +#define SUN4I_HDMI_VID_CTRL_ENABLE BIT(31)
> +#define SUN4I_HDMI_VID_CTRL_HDMI_MODE  BIT(30)
> +
> +#define SUN4I_HDMI_VID_TIMING_ACT_REG  0x014
> +#define SUN4I_HDMI_VID_TIMING_BP_REG   0x018
> +#define SUN4I_HDMI_VID_TIMING_FP_REG   0x01c
> +#define SUN4I_HDMI_VID_TIMING_SPW_REG  0x020
> +
> +#define SUN4I_HDMI_VID_TIMING_X(x) x) - 1) & GENMASK(11, 0)))
> +#define SUN4I_HDMI_VID_TIMING_Y(y) y) - 1) & GENMASK(11, 0)) 
> << 16)
> +
> +#define SUN4I_HDMI_VID_TIMING_POL_REG  0x024
> +#define SUN4I_HDMI_VID_TIMING_POL_TX_CLK(0x3e0 << 16)
> +#define SUN4I_HDMI_VID_TIMING_POL_VSYNCBIT(1)
> +#define SUN4I_HDMI_VID_TIMING_POL_HSYNCBIT(0)
> +
> +#define SUN4I_HDMI_AVI_INFOFRAME_REG(n)(0x080 + (n))
> +
> +#define SUN4I_HDMI_PAD_CTRL0_REG   0x200
> +#define SUN4I_HDMI_PAD_CTRL0_BIASENBIT(31)
> +#define SUN4I_HDMI_PAD_CTRL0_LDOCENBIT(30)
> +#define SUN4I_HDMI_PAD_CTRL0_LDODENBIT(29)
> +#define SUN4I_HDMI_PAD_CTRL0_PWENC BIT(28)
> +#define SUN4I_HDMI_PAD_CTRL0_PWEND BIT(27)
> +#define SUN4I_HDMI_PAD_CTRL0_PWENG BIT(26)
> +#define SUN4I_HDMI_PAD_CTRL0_CKEN  BIT(25)
> +#define SUN4I_HDMI_PAD_CTRL0_TXEN  BIT(23)
> +
> +#define SUN4I_HDMI_PAD_CTRL1_REG   0x204
> +#define SUN4I_HDMI_PAD_CTRL1_AMP_OPT   BIT(23)
> +#define SUN4I_HDMI_PAD_CTRL1_AMPCK_OPT BIT(22)
> 

[linux-sunxi] [PATCH v2 18/20] drm/sun4i: Add HDMI support

2017-05-03 Thread Maxime Ripard
The earlier Allwinner SoCs (A10, A10s, A20, A31) have an embedded HDMI
controller.

That HDMI controller is able to do audio and CEC, but those have been left
out for now.

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/sun4i/Kconfig   |   9 +-
 drivers/gpu/drm/sun4i/Makefile  |   6 +-
 drivers/gpu/drm/sun4i/sun4i_hdmi.h  | 157 +++-
 drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c  | 127 +-
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c  | 493 +-
 drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c | 225 ++-
 6 files changed, 1017 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi.h
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c

diff --git a/drivers/gpu/drm/sun4i/Kconfig b/drivers/gpu/drm/sun4i/Kconfig
index a4b357db8856..35299c4e2594 100644
--- a/drivers/gpu/drm/sun4i/Kconfig
+++ b/drivers/gpu/drm/sun4i/Kconfig
@@ -12,3 +12,12 @@ config DRM_SUN4I
  Choose this option if you have an Allwinner SoC with a
  Display Engine. If M is selected the module will be called
  sun4i-drm.
+
+if DRM_SUN4I
+config DRM_SUN4I_HDMI
+   tristate "Allwinner A10 HDMI Controller Support"
+   help
+ Choose this option if you have an Allwinner SoC with an HDMI
+ controller.
+
+endif
diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
index 59b757350a1f..c09bf8093710 100644
--- a/drivers/gpu/drm/sun4i/Makefile
+++ b/drivers/gpu/drm/sun4i/Makefile
@@ -11,3 +11,9 @@ obj-$(CONFIG_DRM_SUN4I)   += sun4i-drm.o 
sun4i-tcon.o
 obj-$(CONFIG_DRM_SUN4I)+= sun4i_backend.o
 obj-$(CONFIG_DRM_SUN4I)+= sun6i_drc.o
 obj-$(CONFIG_DRM_SUN4I)+= sun4i_tv.o
+
+sun4i-drm-hdmi-y += sun4i_hdmi_enc.o
+sun4i-drm-hdmi-y += sun4i_hdmi_ddc_clk.o
+sun4i-drm-hdmi-y += sun4i_hdmi_tmds_clk.o
+
+obj-$(CONFIG_DRM_SUN4I_HDMI)   += sun4i-drm-hdmi.o
diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi.h 
b/drivers/gpu/drm/sun4i/sun4i_hdmi.h
new file mode 100644
index ..40d57b195b48
--- /dev/null
+++ b/drivers/gpu/drm/sun4i/sun4i_hdmi.h
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2016 Maxime Ripard
+ *
+ * Maxime Ripard 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ */
+
+#ifndef _SUN4I_HDMI_H_
+#define _SUN4I_HDMI_H_
+
+#include 
+#include 
+
+#define SUN4I_HDMI_CTRL_REG0x004
+#define SUN4I_HDMI_CTRL_ENABLE BIT(31)
+
+#define SUN4I_HDMI_IRQ_REG 0x008
+#define SUN4I_HDMI_IRQ_STA_MASK0x73
+#define SUN4I_HDMI_IRQ_STA_FIFO_OF BIT(1)
+#define SUN4I_HDMI_IRQ_STA_FIFO_UF BIT(0)
+
+#define SUN4I_HDMI_HPD_REG 0x00c
+#define SUN4I_HDMI_HPD_HIGHBIT(0)
+
+#define SUN4I_HDMI_VID_CTRL_REG0x010
+#define SUN4I_HDMI_VID_CTRL_ENABLE BIT(31)
+#define SUN4I_HDMI_VID_CTRL_HDMI_MODE  BIT(30)
+
+#define SUN4I_HDMI_VID_TIMING_ACT_REG  0x014
+#define SUN4I_HDMI_VID_TIMING_BP_REG   0x018
+#define SUN4I_HDMI_VID_TIMING_FP_REG   0x01c
+#define SUN4I_HDMI_VID_TIMING_SPW_REG  0x020
+
+#define SUN4I_HDMI_VID_TIMING_X(x) x) - 1) & GENMASK(11, 0)))
+#define SUN4I_HDMI_VID_TIMING_Y(y) y) - 1) & GENMASK(11, 0)) 
<< 16)
+
+#define SUN4I_HDMI_VID_TIMING_POL_REG  0x024
+#define SUN4I_HDMI_VID_TIMING_POL_TX_CLK(0x3e0 << 16)
+#define SUN4I_HDMI_VID_TIMING_POL_VSYNCBIT(1)
+#define SUN4I_HDMI_VID_TIMING_POL_HSYNCBIT(0)
+
+#define SUN4I_HDMI_AVI_INFOFRAME_REG(n)(0x080 + (n))
+
+#define SUN4I_HDMI_PAD_CTRL0_REG   0x200
+#define SUN4I_HDMI_PAD_CTRL0_BIASENBIT(31)
+#define SUN4I_HDMI_PAD_CTRL0_LDOCENBIT(30)
+#define SUN4I_HDMI_PAD_CTRL0_LDODENBIT(29)
+#define SUN4I_HDMI_PAD_CTRL0_PWENC BIT(28)
+#define SUN4I_HDMI_PAD_CTRL0_PWEND BIT(27)
+#define SUN4I_HDMI_PAD_CTRL0_PWENG BIT(26)
+#define SUN4I_HDMI_PAD_CTRL0_CKEN  BIT(25)
+#define SUN4I_HDMI_PAD_CTRL0_TXEN  BIT(23)
+
+#define SUN4I_HDMI_PAD_CTRL1_REG   0x204
+#define SUN4I_HDMI_PAD_CTRL1_AMP_OPT   BIT(23)
+#define SUN4I_HDMI_PAD_CTRL1_AMPCK_OPT BIT(22)
+#define SUN4I_HDMI_PAD_CTRL1_EMP_OPT   BIT(20)
+#define SUN4I_HDMI_PAD_CTRL1_EMPCK_OPT BIT(19)
+#define SUN4I_HDMI_PAD_CTRL1_REG_DEN   BIT(15)
+#define SUN4I_HDMI_PAD_CTRL1_REG_DENCK BIT(14)
+#define SUN4I_HDMI_PAD_CTRL1_REG_EMP(n)(((n) & 7) << 10)
+#define