Re: [PATCH v2 07/12] drm/sun4i: Add a driver for the display frontend

2018-01-04 Thread Chen-Yu Tsai
On Mon, Dec 18, 2017 at 10:57 PM, Maxime Ripard
 wrote:
> The display frontend is an hardware block that can be used to implement
> some more advanced features like hardware scaling or colorspace
> conversions. It can also be used to implement the output format of the VPU.
>
> Let's create a minimal driver for it that will only enable the hardware
> scaling features.
>
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/gpu/drm/sun4i/Makefile |   3 +-
>  drivers/gpu/drm/sun4i/sun4i_drv.c  |  16 +-
>  drivers/gpu/drm/sun4i/sun4i_drv.h  |   1 +-
>  drivers/gpu/drm/sun4i/sun4i_frontend.c | 392 ++-
>  drivers/gpu/drm/sun4i/sun4i_frontend.h |  96 ++-
>  5 files changed, 503 insertions(+), 5 deletions(-)
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_frontend.c
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_frontend.h
>
> diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
> index 0c2f8c7facae..b660d82011f4 100644
> --- a/drivers/gpu/drm/sun4i/Makefile
> +++ b/drivers/gpu/drm/sun4i/Makefile
> @@ -1,5 +1,6 @@
>  # SPDX-License-Identifier: GPL-2.0
>  sun4i-backend-y+= sun4i_backend.o sun4i_layer.o
> +sun4i-frontend-y   += sun4i_frontend.o
>
>  sun4i-drm-y+= sun4i_drv.o
>  sun4i-drm-y+= sun4i_framebuffer.o
> @@ -21,6 +22,6 @@ obj-$(CONFIG_DRM_SUN4I)   += sun4i-tcon.o
>  obj-$(CONFIG_DRM_SUN4I)+= sun4i_tv.o
>  obj-$(CONFIG_DRM_SUN4I)+= sun6i_drc.o
>
> -obj-$(CONFIG_DRM_SUN4I_BACKEND)+= sun4i-backend.o
> +obj-$(CONFIG_DRM_SUN4I_BACKEND)+= sun4i-backend.o sun4i-frontend.o
>  obj-$(CONFIG_DRM_SUN4I_HDMI)   += sun4i-drm-hdmi.o
>  obj-$(CONFIG_DRM_SUN8I_MIXER)  += sun8i-mixer.o
> diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c 
> b/drivers/gpu/drm/sun4i/sun4i_drv.c
> index 75c76cdd82bc..17bf9bfd98ba 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_drv.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
> @@ -98,6 +98,7 @@ static int sun4i_drv_bind(struct device *dev)
> goto free_drm;
> }
> drm->dev_private = drv;
> +   INIT_LIST_HEAD(>frontend_list);
> INIT_LIST_HEAD(>engine_list);
> INIT_LIST_HEAD(>tcon_list);
>
> @@ -239,9 +240,11 @@ static int sun4i_drv_add_endpoints(struct device *dev,
> int count = 0;
>
> /*
> -* We don't support the frontend for now, so we will never
> -* have a device bound. Just skip over it, but we still want
> -* the rest our pipeline to be added.
> +* The frontend has been disabled in all of our old device

Not quite... I left them enabled in all the ones I did (A10/A20/A31)...

> +* trees. If we find a node that is the frontend and is
> +* disabled, we should just follow through and parse its
> +* child, but without adding it to the component list.
> +* Otherwise, we obviously want to add it to the list.
>  */
> if (!sun4i_drv_node_is_frontend(node) &&
> !of_device_is_available(node))
> @@ -254,7 +257,12 @@ static int sun4i_drv_add_endpoints(struct device *dev,
> if (sun4i_drv_node_is_connector(node))
> return 0;
>
> -   if (!sun4i_drv_node_is_frontend(node)) {
> +   /*
> +* If the device is either just a regular device, or an
> +* enabled frontend, we add it to our component list.
> +*/
> +   if (!sun4i_drv_node_is_frontend(node) ||
> +   (sun4i_drv_node_is_frontend(node) && 
> of_device_is_available(node))) {
> /* Add current component */
> DRM_DEBUG_DRIVER("Adding component %pOF\n", node);
> drm_of_component_match_add(dev, match, compare_of, node);
> diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.h 
> b/drivers/gpu/drm/sun4i/sun4i_drv.h
> index a960c89270cc..9c26a345f85c 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_drv.h
> +++ b/drivers/gpu/drm/sun4i/sun4i_drv.h
> @@ -19,6 +19,7 @@
>
>  struct sun4i_drv {
> struct list_headengine_list;
> +   struct list_headfrontend_list;
> struct list_headtcon_list;
>
> struct drm_fbdev_cma*fbdev;
> diff --git a/drivers/gpu/drm/sun4i/sun4i_frontend.c 
> b/drivers/gpu/drm/sun4i/sun4i_frontend.c
> new file mode 100644
> index ..fb3e96ab57f7
> --- /dev/null
> +++ b/drivers/gpu/drm/sun4i/sun4i_frontend.c
> @@ -0,0 +1,392 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2017 Free Electrons
> + * Maxime Ripard 
> + */
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "sun4i_drv.h"
> +#include "sun4i_frontend.h"
> +
> +static const u32 sun4i_frontend_vert_coef[32] = {
> +   0x4000, 0x000140ff, 0x00033ffe, 

[PATCH v2 07/12] drm/sun4i: Add a driver for the display frontend

2017-12-18 Thread Maxime Ripard
The display frontend is an hardware block that can be used to implement
some more advanced features like hardware scaling or colorspace
conversions. It can also be used to implement the output format of the VPU.

Let's create a minimal driver for it that will only enable the hardware
scaling features.

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/sun4i/Makefile |   3 +-
 drivers/gpu/drm/sun4i/sun4i_drv.c  |  16 +-
 drivers/gpu/drm/sun4i/sun4i_drv.h  |   1 +-
 drivers/gpu/drm/sun4i/sun4i_frontend.c | 392 ++-
 drivers/gpu/drm/sun4i/sun4i_frontend.h |  96 ++-
 5 files changed, 503 insertions(+), 5 deletions(-)
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_frontend.c
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_frontend.h

diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
index 0c2f8c7facae..b660d82011f4 100644
--- a/drivers/gpu/drm/sun4i/Makefile
+++ b/drivers/gpu/drm/sun4i/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 sun4i-backend-y+= sun4i_backend.o sun4i_layer.o
+sun4i-frontend-y   += sun4i_frontend.o
 
 sun4i-drm-y+= sun4i_drv.o
 sun4i-drm-y+= sun4i_framebuffer.o
@@ -21,6 +22,6 @@ obj-$(CONFIG_DRM_SUN4I)   += sun4i-tcon.o
 obj-$(CONFIG_DRM_SUN4I)+= sun4i_tv.o
 obj-$(CONFIG_DRM_SUN4I)+= sun6i_drc.o
 
-obj-$(CONFIG_DRM_SUN4I_BACKEND)+= sun4i-backend.o
+obj-$(CONFIG_DRM_SUN4I_BACKEND)+= sun4i-backend.o sun4i-frontend.o
 obj-$(CONFIG_DRM_SUN4I_HDMI)   += sun4i-drm-hdmi.o
 obj-$(CONFIG_DRM_SUN8I_MIXER)  += sun8i-mixer.o
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c 
b/drivers/gpu/drm/sun4i/sun4i_drv.c
index 75c76cdd82bc..17bf9bfd98ba 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
@@ -98,6 +98,7 @@ static int sun4i_drv_bind(struct device *dev)
goto free_drm;
}
drm->dev_private = drv;
+   INIT_LIST_HEAD(>frontend_list);
INIT_LIST_HEAD(>engine_list);
INIT_LIST_HEAD(>tcon_list);
 
@@ -239,9 +240,11 @@ static int sun4i_drv_add_endpoints(struct device *dev,
int count = 0;
 
/*
-* We don't support the frontend for now, so we will never
-* have a device bound. Just skip over it, but we still want
-* the rest our pipeline to be added.
+* The frontend has been disabled in all of our old device
+* trees. If we find a node that is the frontend and is
+* disabled, we should just follow through and parse its
+* child, but without adding it to the component list.
+* Otherwise, we obviously want to add it to the list.
 */
if (!sun4i_drv_node_is_frontend(node) &&
!of_device_is_available(node))
@@ -254,7 +257,12 @@ static int sun4i_drv_add_endpoints(struct device *dev,
if (sun4i_drv_node_is_connector(node))
return 0;
 
-   if (!sun4i_drv_node_is_frontend(node)) {
+   /*
+* If the device is either just a regular device, or an
+* enabled frontend, we add it to our component list.
+*/
+   if (!sun4i_drv_node_is_frontend(node) ||
+   (sun4i_drv_node_is_frontend(node) && of_device_is_available(node))) 
{
/* Add current component */
DRM_DEBUG_DRIVER("Adding component %pOF\n", node);
drm_of_component_match_add(dev, match, compare_of, node);
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.h 
b/drivers/gpu/drm/sun4i/sun4i_drv.h
index a960c89270cc..9c26a345f85c 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.h
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.h
@@ -19,6 +19,7 @@
 
 struct sun4i_drv {
struct list_headengine_list;
+   struct list_headfrontend_list;
struct list_headtcon_list;
 
struct drm_fbdev_cma*fbdev;
diff --git a/drivers/gpu/drm/sun4i/sun4i_frontend.c 
b/drivers/gpu/drm/sun4i/sun4i_frontend.c
new file mode 100644
index ..fb3e96ab57f7
--- /dev/null
+++ b/drivers/gpu/drm/sun4i/sun4i_frontend.c
@@ -0,0 +1,392 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Free Electrons
+ * Maxime Ripard 
+ */
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sun4i_drv.h"
+#include "sun4i_frontend.h"
+
+static const u32 sun4i_frontend_vert_coef[32] = {
+   0x4000, 0x000140ff, 0x00033ffe, 0x00043ffd,
+   0x00063efc, 0xff083dfc, 0x000a3bfb, 0xff0d39fb,
+   0xff0f37fb, 0xff1136fa, 0xfe1433fb, 0xfe1631fb,
+   0xfd192ffb, 0xfd1c2cfb, 0xfd1f29fb, 0xfc2127fc,
+   0xfc2424fc, 0xfc2721fc, 0xfb291ffd, 0xfb2c1cfd,
+   0xfb2f19fd, 0xfb3116fe, 0xfb3314fe, 0xfa3611ff,
+   0xfb370fff, 0xfb390dff, 0xfb3b0a00, 0xfc3d08ff,
+   0xfc3e0600, 0xfd3f0400, 0xfe3f0300,