linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2
@ 2017-02-23  8:05 Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 01/11] drm/sun4i: Make sunxi_rgb2yuv_coef constant Chen-Yu Tsai
                   ` (10 more replies)
  0 siblings, 11 replies; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

Hi Maxime,

This is the second bunch of fixes for the sun4i drm driver. This is part
of the cleanup I am doing towards making the driver support multiple
display pipelines.

This part mainly aims to get detection of crtcs working with of_graph,
and moving data structure pointers around for a more layered and
connected approach of associating the various components:

	----------              ---------
	|----------             |---------
  SW:	||        |  included   ||       |
	|| layers | ----------> || crtcs |
	-|        |     in      -|       |
	 ----------              ---------

	      |   \_______________   |
	      |                   \  |
	      v	     maps to      v  v

	------------            ---------
	|------------           |---------
  HW:	||          |   feeds   ||       |
	|| backends | --------> || tcons |
	-|          |           -|       |
	 ------------            ---------

This will make it easier to support multiple display pipelines, as
we only have to deal with indexes at bind time.


Patch 1 makes the table of RGB-to-YUV conversion coefficients constant.

Patch 2 sets the crtc's output port so drm_of_find_possible_crtcs can
work.

Patch 3 adds an empty end of list element to the list of layers returned
from sun4i_layers_init.

Patch 4 moves the list of layers from the main sun4i_drv structure into
the crtc.

Patch 5 initializes the crtc within the tcon's bind function. The crtc
has to be initialized before any encoders downstream of the tcon, so
drm_of_find_possible_crtcs() used within encoder bind functions work.
Previously crtcs were initialized after all hardware components were
bound.

Patch 6 drops the pointer to the primary layer/plane from sun4i_drv.
This pointer was only used for initializing the crtc later on.

Patch 7 drops the hardcoded .possible_crtcs values for the layers.
Instead we iterate through the list of layers and set the value
for overlay layers with the value derived from the crtc that was
just initialized.

Patch 8 makes the tv encoder driver use drm_of_find_possible_crtcs
instead of a hardcoded value.

Patch 9 adds a argument to pass the tcon pointer when initializing
the RGB encoder.

Patch 10 adds a pointer to the underlying backend to sun4i_layer.

Patch 11 adds pointers to the underlying backend and tcon to
sun4i_crtc.


Please have a look. Notably, I do not have hardware to test patch 8,
though I do not expect any problems.

Still to come is the actual work of supporting many display pipelines.

Regards
ChenYu

Chen-Yu Tsai (11):
  drm/sun4i: Make sunxi_rgb2yuv_coef constant
  drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node
  drm/sun4i: Add end of list element for sun4i_layers_init's returned
    list
  drm/sun4i: Move layers from sun4i_drv to sun4i_crtc
  drm/sun4i: Initialize crtc from tcon bind function
  drm/sun4i: Drop primary layer pointer from sun4i_drv
  drm/sun4i: Drop hardcoded .possible_crtcs values from layers
  drm/sun4i: tv: Switch to drm_of_find_possible_crtcs
  drm/sun4i: rgb: Pass tcon pointer when initializing RGB encoder
  drm/sun4i: Add backend pointer to sun4i_layer
  drm/sun4i: Add backend and tcon pointers to sun4i_crtc

 drivers/gpu/drm/sun4i/Makefile        |  4 +--
 drivers/gpu/drm/sun4i/sun4i_backend.c |  2 +-
 drivers/gpu/drm/sun4i/sun4i_crtc.c    | 57 +++++++++++++++++++++++++++++------
 drivers/gpu/drm/sun4i/sun4i_crtc.h    |  4 ++-
 drivers/gpu/drm/sun4i/sun4i_drv.c     | 17 -----------
 drivers/gpu/drm/sun4i/sun4i_drv.h     |  4 ---
 drivers/gpu/drm/sun4i/sun4i_layer.c   | 16 ++++------
 drivers/gpu/drm/sun4i/sun4i_layer.h   |  1 +
 drivers/gpu/drm/sun4i/sun4i_rgb.c     | 30 +++++++-----------
 drivers/gpu/drm/sun4i/sun4i_rgb.h     |  2 +-
 drivers/gpu/drm/sun4i/sun4i_tcon.c    | 12 ++++++--
 drivers/gpu/drm/sun4i/sun4i_tcon.h    |  3 ++
 drivers/gpu/drm/sun4i/sun4i_tv.c      |  8 ++++-
 13 files changed, 91 insertions(+), 69 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 01/11] drm/sun4i: Make sunxi_rgb2yuv_coef constant
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23 18:18   ` Maxime Ripard
  2017-02-23  8:05 ` [PATCH 02/11] drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node Chen-Yu Tsai
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

sunxi_rgb2yuv_coef is a table of RGB-to-YUV conversion coefficients.
They are programmed into the hardware, and can be declared constant.

Reported-by: Priit Laes <plaes@plaes.org>
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c
index 5bf1ea4d92fc..7a61bd330f04 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.c
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
@@ -24,7 +24,7 @@
 #include "sun4i_backend.h"
 #include "sun4i_drv.h"
 
-static u32 sunxi_rgb2yuv_coef[12] = {
+static const u32 sunxi_rgb2yuv_coef[12] = {
 	0x00000107, 0x00000204, 0x00000064, 0x00000108,
 	0x00003f69, 0x00003ed6, 0x000001c1, 0x00000808,
 	0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 02/11] drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 01/11] drm/sun4i: Make sunxi_rgb2yuv_coef constant Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23 18:20   ` Maxime Ripard
  2017-02-23  8:05 ` [PATCH 03/11] drm/sun4i: Add end of list element for sun4i_layers_init's returned list Chen-Yu Tsai
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

The way drm_of_find_possible_crtcs is it tries to match the
remote-endpoint of the given node's various endpoints to all the
crtc's .port field. Thus we need to set drm_crtc.port to the output
port node of the underlying TCON.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_crtc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index 4e2e89c3104f..de6f7da69746 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -19,6 +19,7 @@
 #include <linux/clk-provider.h>
 #include <linux/ioport.h>
 #include <linux/of_address.h>
+#include <linux/of_graph.h>
 #include <linux/of_irq.h>
 #include <linux/regmap.h>
 
@@ -136,5 +137,9 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm)
 
 	drm_crtc_helper_add(&scrtc->crtc, &sun4i_crtc_helper_funcs);
 
+	/* Set crtc.port to output port node of the tcon */
+	scrtc->crtc.port = of_graph_get_port_by_id(drv->tcon->dev->of_node,
+						   1);
+
 	return scrtc;
 }
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 03/11] drm/sun4i: Add end of list element for sun4i_layers_init's returned list
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 01/11] drm/sun4i: Make sunxi_rgb2yuv_coef constant Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 02/11] drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23 18:21   ` Maxime Ripard
  2017-02-23  8:05 ` [PATCH 04/11] drm/sun4i: Move layers from sun4i_drv to sun4i_crtc Chen-Yu Tsai
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

The number of defined planes in sun4i_layer is unknown to other parts
of the sun4i drm driver. Since the return value of sun4i_layers_init
is a list of layers, make it return 1 more empty layer as an end of
list guard value.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_layer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.c b/drivers/gpu/drm/sun4i/sun4i_layer.c
index 41bc0f860f5c..0b703fb02656 100644
--- a/drivers/gpu/drm/sun4i/sun4i_layer.c
+++ b/drivers/gpu/drm/sun4i/sun4i_layer.c
@@ -139,7 +139,7 @@ struct sun4i_layer **sun4i_layers_init(struct drm_device *drm)
 	struct sun4i_layer **layers;
 	int i;
 
-	layers = devm_kcalloc(drm->dev, ARRAY_SIZE(sun4i_backend_planes),
+	layers = devm_kcalloc(drm->dev, ARRAY_SIZE(sun4i_backend_planes) + 1,
 			      sizeof(*layers), GFP_KERNEL);
 	if (!layers)
 		return ERR_PTR(-ENOMEM);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 04/11] drm/sun4i: Move layers from sun4i_drv to sun4i_crtc
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (2 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 03/11] drm/sun4i: Add end of list element for sun4i_layers_init's returned list Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23 18:22   ` Maxime Ripard
  2017-02-23  8:05 ` [PATCH 05/11] drm/sun4i: Initialize crtc from tcon bind function Chen-Yu Tsai
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

This patch moves the sun4i_layers_init call from sun4i_drv_bind to
sun4i_crtc_init, and the layers pointer from struct sun4i_drv to
struct sun4i_crtc.

The layers are bound to a specific crtc, and they are not directly
used once initiated. They are used through their included drm_plane
structures.

Moving the layers into the crtc facilitates binding them to the crtc
explicitly, by setting the corresponding bit in their .possible_crtcs
fields right after the crtc is initialized. This is done in a later
patch.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_crtc.c | 8 ++++++++
 drivers/gpu/drm/sun4i/sun4i_crtc.h | 1 +
 drivers/gpu/drm/sun4i/sun4i_drv.c  | 9 ---------
 drivers/gpu/drm/sun4i/sun4i_drv.h  | 2 --
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index de6f7da69746..1d01667fa45d 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -28,6 +28,7 @@
 #include "sun4i_backend.h"
 #include "sun4i_crtc.h"
 #include "sun4i_drv.h"
+#include "sun4i_layer.h"
 #include "sun4i_tcon.h"
 
 static void sun4i_crtc_atomic_begin(struct drm_crtc *crtc,
@@ -125,6 +126,13 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm)
 		return ERR_PTR(-ENOMEM);
 	scrtc->drv = drv;
 
+	/* Create our layers */
+	scrtc->layers = sun4i_layers_init(drm);
+	if (IS_ERR(scrtc->layers)) {
+		dev_err(drm->dev, "Couldn't create the planes\n");
+		return ERR_CAST(scrtc->layers);
+	}
+
 	ret = drm_crtc_init_with_planes(drm, &scrtc->crtc,
 					drv->primary,
 					NULL,
diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.h b/drivers/gpu/drm/sun4i/sun4i_crtc.h
index dec8ce4d9b25..0a888f73c983 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.h
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.h
@@ -18,6 +18,7 @@ struct sun4i_crtc {
 	struct drm_pending_vblank_event	*event;
 
 	struct sun4i_drv		*drv;
+	struct sun4i_layer		**layers;
 };
 
 static inline struct sun4i_crtc *drm_crtc_to_sun4i_crtc(struct drm_crtc *crtc)
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c
index fc6ef4066c59..87bc0951eba8 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
@@ -23,7 +23,6 @@
 #include "sun4i_crtc.h"
 #include "sun4i_drv.h"
 #include "sun4i_framebuffer.h"
-#include "sun4i_layer.h"
 #include "sun4i_tcon.h"
 
 static int sun4i_drv_enable_vblank(struct drm_device *drm, unsigned int pipe)
@@ -143,14 +142,6 @@ static int sun4i_drv_bind(struct device *dev)
 		goto cleanup_mode_config;
 	}
 
-	/* Create our layers */
-	drv->layers = sun4i_layers_init(drm);
-	if (IS_ERR(drv->layers)) {
-		dev_err(drm->dev, "Couldn't create the planes\n");
-		ret = PTR_ERR(drv->layers);
-		goto cleanup_mode_config;
-	}
-
 	/* Create our CRTC */
 	drv->crtc = sun4i_crtc_init(drm);
 	if (IS_ERR(drv->crtc)) {
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.h b/drivers/gpu/drm/sun4i/sun4i_drv.h
index 597353eab728..e22ee536677e 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.h
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.h
@@ -23,8 +23,6 @@ struct sun4i_drv {
 
 	struct drm_plane	*primary;
 	struct drm_fbdev_cma	*fbdev;
-
-	struct sun4i_layer	**layers;
 };
 
 #endif /* _SUN4I_DRV_H_ */
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 05/11] drm/sun4i: Initialize crtc from tcon bind function
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (3 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 04/11] drm/sun4i: Move layers from sun4i_drv to sun4i_crtc Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23 18:24   ` Maxime Ripard
  2017-02-23  8:05 ` [PATCH 06/11] drm/sun4i: Drop primary layer pointer from sun4i_drv Chen-Yu Tsai
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

The tcon provides part of the functionality of the crtc, and also
provides the device node for the output port of the crtc. To be able
to use drm_of_find_possible_crtcs(), all crtc must be initialized before
any downstream encoders. The other part of the crtc is the display
backend.

The Rockchip DRM driver does this by first binding all vops, which is
their crtc, and this step also creates the crtc objects. Then all
remaining hardware components are bound. With the Allwinner display
pipeline, we have multiple components comprising the crtc, and varying
depths of the display pipeline. Since components are added with a depth
first search of the of_graph, we can initialize the crtc object within
the tcon bind function. Since the backend precedes the tcon, and the
backends cannot be muxed or switched around, we can be sure that the
associated backend is already initialized.

This patch also moves the crtc pointer from the main drm_device data to
the tcon device data. Besides the crtc callbacks, the crtc structure is
only used within the tcon driver to signal vblank events from its
interrupt handler.

As the crtc and layer bits are now called from the tcon bits, we must
move them from the sun4i-drm module to the sun4i-tcon module to avoid
circular dependencies between the two modules. This is because sun4i-drm
also calls into sun4i-tcon.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/Makefile     |  4 ++--
 drivers/gpu/drm/sun4i/sun4i_drv.c  |  8 --------
 drivers/gpu/drm/sun4i/sun4i_drv.h  |  1 -
 drivers/gpu/drm/sun4i/sun4i_tcon.c | 10 ++++++++--
 drivers/gpu/drm/sun4i/sun4i_tcon.h |  3 +++
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
index d625a82a6e5f..59b757350a1f 100644
--- a/drivers/gpu/drm/sun4i/Makefile
+++ b/drivers/gpu/drm/sun4i/Makefile
@@ -1,11 +1,11 @@
-sun4i-drm-y += sun4i_crtc.o
 sun4i-drm-y += sun4i_drv.o
 sun4i-drm-y += sun4i_framebuffer.o
-sun4i-drm-y += sun4i_layer.o
 
 sun4i-tcon-y += sun4i_tcon.o
 sun4i-tcon-y += sun4i_rgb.o
 sun4i-tcon-y += sun4i_dotclock.o
+sun4i-tcon-y += sun4i_crtc.o
+sun4i-tcon-y += sun4i_layer.o
 
 obj-$(CONFIG_DRM_SUN4I)		+= sun4i-drm.o sun4i-tcon.o
 obj-$(CONFIG_DRM_SUN4I)		+= sun4i_backend.o
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c
index 87bc0951eba8..4384c837baa8 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
@@ -20,7 +20,6 @@
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_of.h>
 
-#include "sun4i_crtc.h"
 #include "sun4i_drv.h"
 #include "sun4i_framebuffer.h"
 #include "sun4i_tcon.h"
@@ -142,13 +141,6 @@ static int sun4i_drv_bind(struct device *dev)
 		goto cleanup_mode_config;
 	}
 
-	/* Create our CRTC */
-	drv->crtc = sun4i_crtc_init(drm);
-	if (IS_ERR(drv->crtc)) {
-		dev_err(drm->dev, "Couldn't create the CRTC\n");
-		ret = PTR_ERR(drv->crtc);
-		goto cleanup_mode_config;
-	}
 	drm->irq_enabled = true;
 
 	/* Remove early framebuffers (ie. simplefb) */
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.h b/drivers/gpu/drm/sun4i/sun4i_drv.h
index e22ee536677e..7a3345b7b6d1 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.h
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.h
@@ -18,7 +18,6 @@
 
 struct sun4i_drv {
 	struct sun4i_backend	*backend;
-	struct sun4i_crtc	*crtc;
 	struct sun4i_tcon	*tcon;
 
 	struct drm_plane	*primary;
diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
index ea2906f87cb9..3f3eb3f0b209 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
+++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
@@ -290,8 +290,7 @@ static irqreturn_t sun4i_tcon_handler(int irq, void *private)
 {
 	struct sun4i_tcon *tcon = private;
 	struct drm_device *drm = tcon->drm;
-	struct sun4i_drv *drv = drm->dev_private;
-	struct sun4i_crtc *scrtc = drv->crtc;
+	struct sun4i_crtc *scrtc = tcon->crtc;
 	unsigned int status;
 
 	regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status);
@@ -524,6 +523,13 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master,
 		goto err_free_clocks;
 	}
 
+	tcon->crtc = sun4i_crtc_init(drm);
+	if (IS_ERR(tcon->crtc)) {
+		dev_err(dev, "Couldn't create our CRTC\n");
+		ret = PTR_ERR(tcon->crtc);
+		goto err_free_clocks;
+	}
+
 	ret = sun4i_rgb_init(drm);
 	if (ret < 0)
 		goto err_free_clocks;
diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.h b/drivers/gpu/drm/sun4i/sun4i_tcon.h
index 166064bafe2e..f636343a935d 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tcon.h
+++ b/drivers/gpu/drm/sun4i/sun4i_tcon.h
@@ -169,6 +169,9 @@ struct sun4i_tcon {
 
 	/* Platform adjustments */
 	const struct sun4i_tcon_quirks	*quirks;
+
+	/* Associated crtc */
+	struct sun4i_crtc		*crtc;
 };
 
 struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 06/11] drm/sun4i: Drop primary layer pointer from sun4i_drv
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (4 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 05/11] drm/sun4i: Initialize crtc from tcon bind function Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23 18:26   ` Maxime Ripard
  2017-02-23  8:05 ` [PATCH 07/11] drm/sun4i: Drop hardcoded .possible_crtcs values from layers Chen-Yu Tsai
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

The current layer init code keeps a pointer to the primary plane layer
in sun4i_drv. When we eventually support multiple display pipelines,
this would force us to keep track of primary planes for all crtcs. And
these pointers only get used at bind time.

Instead, have the crtc init code iterate through the returned layers
to find the primary and cursor layers. And drop the pointer from the
sun4i_drv structure.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_crtc.c  | 25 +++++++++++++++++++++----
 drivers/gpu/drm/sun4i/sun4i_drv.h   |  1 -
 drivers/gpu/drm/sun4i/sun4i_layer.c |  3 ---
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index 1d01667fa45d..cb1a901bc389 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -119,7 +119,8 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm)
 {
 	struct sun4i_drv *drv = drm->dev_private;
 	struct sun4i_crtc *scrtc;
-	int ret;
+	struct drm_plane *primary = NULL, *cursor = NULL;
+	int ret, i;
 
 	scrtc = devm_kzalloc(drm->dev, sizeof(*scrtc), GFP_KERNEL);
 	if (!scrtc)
@@ -130,12 +131,28 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm)
 	scrtc->layers = sun4i_layers_init(drm);
 	if (IS_ERR(scrtc->layers)) {
 		dev_err(drm->dev, "Couldn't create the planes\n");
-		return ERR_CAST(scrtc->layers);
+		return NULL;
+	}
+
+	/* find primary and cursor planes for drm_crtc_init_with_planes */
+	for (i = 0; scrtc->layers[i]; i++) {
+		struct sun4i_layer *layer = scrtc->layers[i];
+
+		switch (layer->plane.type) {
+		case DRM_PLANE_TYPE_PRIMARY:
+			primary = &layer->plane;
+			break;
+		case DRM_PLANE_TYPE_CURSOR:
+			cursor = &layer->plane;
+			break;
+		default:
+			break;
+		}
 	}
 
 	ret = drm_crtc_init_with_planes(drm, &scrtc->crtc,
-					drv->primary,
-					NULL,
+					primary,
+					cursor,
 					&sun4i_crtc_funcs,
 					NULL);
 	if (ret) {
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.h b/drivers/gpu/drm/sun4i/sun4i_drv.h
index 7a3345b7b6d1..5df50126ff52 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.h
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.h
@@ -20,7 +20,6 @@ struct sun4i_drv {
 	struct sun4i_backend	*backend;
 	struct sun4i_tcon	*tcon;
 
-	struct drm_plane	*primary;
 	struct drm_fbdev_cma	*fbdev;
 };
 
diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.c b/drivers/gpu/drm/sun4i/sun4i_layer.c
index 0b703fb02656..9c0baee25fae 100644
--- a/drivers/gpu/drm/sun4i/sun4i_layer.c
+++ b/drivers/gpu/drm/sun4i/sun4i_layer.c
@@ -127,9 +127,6 @@ static struct sun4i_layer *sun4i_layer_init_one(struct drm_device *drm,
 			     &sun4i_backend_layer_helper_funcs);
 	layer->drv = drv;
 
-	if (plane->type == DRM_PLANE_TYPE_PRIMARY)
-		drv->primary = &layer->plane;
-
 	return layer;
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 07/11] drm/sun4i: Drop hardcoded .possible_crtcs values from layers
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (5 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 06/11] drm/sun4i: Drop primary layer pointer from sun4i_drv Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 08/11] drm/sun4i: tv: Switch to drm_of_find_possible_crtcs Chen-Yu Tsai
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

To support multiple display pipelines, we would have multiple crtcs,
with one or more planes bound to them. Obviously having hardcoded
values for the drm_plane .possible_crtcs field is not going to work.

For primary and cursor planes, the value is set by
drm_crtc_init_with_planes. We just need to set it for overlay planes.

We also fix the value set for the RGB encoder, by referencing the
crtc set in sun4i_drv.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_crtc.c  | 9 +++++++++
 drivers/gpu/drm/sun4i/sun4i_layer.c | 3 ++-
 drivers/gpu/drm/sun4i/sun4i_rgb.c   | 3 ++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index cb1a901bc389..4a30932643c3 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -166,5 +166,14 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm)
 	scrtc->crtc.port = of_graph_get_port_by_id(drv->tcon->dev->of_node,
 						   1);
 
+	/* Set possible_crtcs to this crtc for overlay planes */
+	for (i = 0; scrtc->layers[i]; i++) {
+		uint32_t possible_crtcs = BIT(drm_crtc_index(&scrtc->crtc));
+		struct sun4i_layer *layer = scrtc->layers[i];
+
+		if (layer->plane.type == DRM_PLANE_TYPE_OVERLAY)
+			layer->plane.possible_crtcs = possible_crtcs;
+	}
+
 	return scrtc;
 }
diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.c b/drivers/gpu/drm/sun4i/sun4i_layer.c
index 9c0baee25fae..431e13362b62 100644
--- a/drivers/gpu/drm/sun4i/sun4i_layer.c
+++ b/drivers/gpu/drm/sun4i/sun4i_layer.c
@@ -114,7 +114,8 @@ static struct sun4i_layer *sun4i_layer_init_one(struct drm_device *drm,
 	if (!layer)
 		return ERR_PTR(-ENOMEM);
 
-	ret = drm_universal_plane_init(drm, &layer->plane, BIT(0),
+	/* possible crtcs are set later */
+	ret = drm_universal_plane_init(drm, &layer->plane, 0,
 				       &sun4i_backend_layer_funcs,
 				       plane->formats, plane->nformats,
 				       plane->type, NULL);
diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.c b/drivers/gpu/drm/sun4i/sun4i_rgb.c
index f5e86fe7750e..fc7f7467d120 100644
--- a/drivers/gpu/drm/sun4i/sun4i_rgb.c
+++ b/drivers/gpu/drm/sun4i/sun4i_rgb.c
@@ -17,6 +17,7 @@
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_panel.h>
 
+#include "sun4i_crtc.h"
 #include "sun4i_drv.h"
 #include "sun4i_tcon.h"
 #include "sun4i_rgb.h"
@@ -237,7 +238,7 @@ int sun4i_rgb_init(struct drm_device *drm)
 	}
 
 	/* The RGB encoder can only work with the TCON channel 0 */
-	rgb->encoder.possible_crtcs = BIT(0);
+	rgb->encoder.possible_crtcs = BIT(drm_crtc_index(&tcon->crtc->crtc));
 
 	if (!IS_ERR(tcon->panel)) {
 		drm_connector_helper_add(&rgb->connector,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 08/11] drm/sun4i: tv: Switch to drm_of_find_possible_crtcs
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (6 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 07/11] drm/sun4i: Drop hardcoded .possible_crtcs values from layers Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 09/11] drm/sun4i: rgb: Pass tcon pointer when initializing RGB encoder Chen-Yu Tsai
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

Now that the crtcs have their .port field set properly, we can use
drm_of_find_possible_crtcs to find the connected crtcs, instead of
hardcoding the first crtc as usable. The new code also defers binding
when the upstream crtc hasn't been registered yet.

This makes it easier to support multiple tcons/crtcs.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_tv.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c b/drivers/gpu/drm/sun4i/sun4i_tv.c
index c6f47222e8fc..32ed5fdf0c4d 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_tv.c
@@ -19,6 +19,7 @@
 #include <drm/drmP.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc_helper.h>
+#include <drm/drm_of.h>
 #include <drm/drm_panel.h>
 
 #include "sun4i_backend.h"
@@ -623,7 +624,12 @@ static int sun4i_tv_bind(struct device *dev, struct device *master,
 		goto err_disable_clk;
 	}
 
-	tv->encoder.possible_crtcs = BIT(0);
+	tv->encoder.possible_crtcs = drm_of_find_possible_crtcs(drm,
+								dev->of_node);
+	if (!tv->encoder.possible_crtcs) {
+		ret = -EPROBE_DEFER;
+		goto err_disable_clk;
+	}
 
 	drm_connector_helper_add(&tv->connector,
 				 &sun4i_tv_comp_connector_helper_funcs);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 09/11] drm/sun4i: rgb: Pass tcon pointer when initializing RGB encoder
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (7 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 08/11] drm/sun4i: tv: Switch to drm_of_find_possible_crtcs Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 10/11] drm/sun4i: Add backend pointer to sun4i_layer Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 11/11] drm/sun4i: Add backend and tcon pointers to sun4i_crtc Chen-Yu Tsai
  10 siblings, 0 replies; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

The RGB encoder represents channel 0 of the TCON. Instead of fetching
the pointer to its TCON from the main sun4i_drv structure, pass it in
as part of the init call, save it, and use it directly in the encoder
and connector callbacks.

We can also drop the otherwise unused sun4i_drv pointer.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_rgb.c  | 27 +++++++++------------------
 drivers/gpu/drm/sun4i/sun4i_rgb.h  |  2 +-
 drivers/gpu/drm/sun4i/sun4i_tcon.c |  2 +-
 3 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.c b/drivers/gpu/drm/sun4i/sun4i_rgb.c
index fc7f7467d120..a244458197e1 100644
--- a/drivers/gpu/drm/sun4i/sun4i_rgb.c
+++ b/drivers/gpu/drm/sun4i/sun4i_rgb.c
@@ -18,7 +18,6 @@
 #include <drm/drm_panel.h>
 
 #include "sun4i_crtc.h"
-#include "sun4i_drv.h"
 #include "sun4i_tcon.h"
 #include "sun4i_rgb.h"
 
@@ -26,7 +25,7 @@ struct sun4i_rgb {
 	struct drm_connector	connector;
 	struct drm_encoder	encoder;
 
-	struct sun4i_drv	*drv;
+	struct sun4i_tcon	*tcon;
 };
 
 static inline struct sun4i_rgb *
@@ -47,8 +46,7 @@ static int sun4i_rgb_get_modes(struct drm_connector *connector)
 {
 	struct sun4i_rgb *rgb =
 		drm_connector_to_sun4i_rgb(connector);
-	struct sun4i_drv *drv = rgb->drv;
-	struct sun4i_tcon *tcon = drv->tcon;
+	struct sun4i_tcon *tcon = rgb->tcon;
 
 	return drm_panel_get_modes(tcon->panel);
 }
@@ -57,8 +55,7 @@ static int sun4i_rgb_mode_valid(struct drm_connector *connector,
 				struct drm_display_mode *mode)
 {
 	struct sun4i_rgb *rgb = drm_connector_to_sun4i_rgb(connector);
-	struct sun4i_drv *drv = rgb->drv;
-	struct sun4i_tcon *tcon = drv->tcon;
+	struct sun4i_tcon *tcon = rgb->tcon;
 	u32 hsync = mode->hsync_end - mode->hsync_start;
 	u32 vsync = mode->vsync_end - mode->vsync_start;
 	unsigned long rate = mode->clock * 1000;
@@ -115,8 +112,7 @@ static void
 sun4i_rgb_connector_destroy(struct drm_connector *connector)
 {
 	struct sun4i_rgb *rgb = drm_connector_to_sun4i_rgb(connector);
-	struct sun4i_drv *drv = rgb->drv;
-	struct sun4i_tcon *tcon = drv->tcon;
+	struct sun4i_tcon *tcon = rgb->tcon;
 
 	drm_panel_detach(tcon->panel);
 	drm_connector_cleanup(connector);
@@ -141,8 +137,7 @@ static int sun4i_rgb_atomic_check(struct drm_encoder *encoder,
 static void sun4i_rgb_encoder_enable(struct drm_encoder *encoder)
 {
 	struct sun4i_rgb *rgb = drm_encoder_to_sun4i_rgb(encoder);
-	struct sun4i_drv *drv = rgb->drv;
-	struct sun4i_tcon *tcon = drv->tcon;
+	struct sun4i_tcon *tcon = rgb->tcon;
 
 	DRM_DEBUG_DRIVER("Enabling RGB output\n");
 
@@ -158,8 +153,7 @@ static void sun4i_rgb_encoder_enable(struct drm_encoder *encoder)
 static void sun4i_rgb_encoder_disable(struct drm_encoder *encoder)
 {
 	struct sun4i_rgb *rgb = drm_encoder_to_sun4i_rgb(encoder);
-	struct sun4i_drv *drv = rgb->drv;
-	struct sun4i_tcon *tcon = drv->tcon;
+	struct sun4i_tcon *tcon = rgb->tcon;
 
 	DRM_DEBUG_DRIVER("Disabling RGB output\n");
 
@@ -177,8 +171,7 @@ static void sun4i_rgb_encoder_mode_set(struct drm_encoder *encoder,
 				       struct drm_display_mode *adjusted_mode)
 {
 	struct sun4i_rgb *rgb = drm_encoder_to_sun4i_rgb(encoder);
-	struct sun4i_drv *drv = rgb->drv;
-	struct sun4i_tcon *tcon = drv->tcon;
+	struct sun4i_tcon *tcon = rgb->tcon;
 
 	sun4i_tcon0_mode_set(tcon, mode);
 
@@ -204,10 +197,8 @@ static struct drm_encoder_funcs sun4i_rgb_enc_funcs = {
 	.destroy	= sun4i_rgb_enc_destroy,
 };
 
-int sun4i_rgb_init(struct drm_device *drm)
+int sun4i_rgb_init(struct drm_device *drm, struct sun4i_tcon *tcon)
 {
-	struct sun4i_drv *drv = drm->dev_private;
-	struct sun4i_tcon *tcon = drv->tcon;
 	struct drm_encoder *encoder;
 	struct sun4i_rgb *rgb;
 	int ret;
@@ -215,7 +206,7 @@ int sun4i_rgb_init(struct drm_device *drm)
 	rgb = devm_kzalloc(drm->dev, sizeof(*rgb), GFP_KERNEL);
 	if (!rgb)
 		return -ENOMEM;
-	rgb->drv = drv;
+	rgb->tcon = tcon;
 	encoder = &rgb->encoder;
 
 	tcon->panel = sun4i_tcon_find_panel(tcon->dev->of_node);
diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.h b/drivers/gpu/drm/sun4i/sun4i_rgb.h
index 7c4da4c8acdd..40c18f4a6c7e 100644
--- a/drivers/gpu/drm/sun4i/sun4i_rgb.h
+++ b/drivers/gpu/drm/sun4i/sun4i_rgb.h
@@ -13,6 +13,6 @@
 #ifndef _SUN4I_RGB_H_
 #define _SUN4I_RGB_H_
 
-int sun4i_rgb_init(struct drm_device *drm);
+int sun4i_rgb_init(struct drm_device *drm, struct sun4i_tcon *tcon);
 
 #endif /* _SUN4I_RGB_H_ */
diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
index 3f3eb3f0b209..505520baa585 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
+++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
@@ -530,7 +530,7 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master,
 		goto err_free_clocks;
 	}
 
-	ret = sun4i_rgb_init(drm);
+	ret = sun4i_rgb_init(drm, tcon);
 	if (ret < 0)
 		goto err_free_clocks;
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 10/11] drm/sun4i: Add backend pointer to sun4i_layer
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (8 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 09/11] drm/sun4i: rgb: Pass tcon pointer when initializing RGB encoder Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23  8:05 ` [PATCH 11/11] drm/sun4i: Add backend and tcon pointers to sun4i_crtc Chen-Yu Tsai
  10 siblings, 0 replies; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

sun4i_layer only controls the backend hardware block of the display
pipeline. Instead of getting a pointer to the underlying backend
through the drm_device structure, leave one in itself.

Also drop the drm_device pointer, since it is no longer needed.

The next step forward would be to pass the pointer in through
sun4i_layers_init as a parameter. This would make it easier to support
multiple display pipelines layer on.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_layer.c | 8 +++-----
 drivers/gpu/drm/sun4i/sun4i_layer.h | 1 +
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.c b/drivers/gpu/drm/sun4i/sun4i_layer.c
index 431e13362b62..6feaf85a5942 100644
--- a/drivers/gpu/drm/sun4i/sun4i_layer.c
+++ b/drivers/gpu/drm/sun4i/sun4i_layer.c
@@ -36,8 +36,7 @@ static void sun4i_backend_layer_atomic_disable(struct drm_plane *plane,
 					       struct drm_plane_state *old_state)
 {
 	struct sun4i_layer *layer = plane_to_sun4i_layer(plane);
-	struct sun4i_drv *drv = layer->drv;
-	struct sun4i_backend *backend = drv->backend;
+	struct sun4i_backend *backend = layer->backend;
 
 	sun4i_backend_layer_enable(backend, layer->id, false);
 }
@@ -46,8 +45,7 @@ static void sun4i_backend_layer_atomic_update(struct drm_plane *plane,
 					      struct drm_plane_state *old_state)
 {
 	struct sun4i_layer *layer = plane_to_sun4i_layer(plane);
-	struct sun4i_drv *drv = layer->drv;
-	struct sun4i_backend *backend = drv->backend;
+	struct sun4i_backend *backend = layer->backend;
 
 	sun4i_backend_update_layer_coord(backend, layer->id, plane);
 	sun4i_backend_update_layer_formats(backend, layer->id, plane);
@@ -126,7 +124,7 @@ static struct sun4i_layer *sun4i_layer_init_one(struct drm_device *drm,
 
 	drm_plane_helper_add(&layer->plane,
 			     &sun4i_backend_layer_helper_funcs);
-	layer->drv = drv;
+	layer->backend = drv->backend;
 
 	return layer;
 }
diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.h b/drivers/gpu/drm/sun4i/sun4i_layer.h
index a2f65d7a3f4e..a97e376bae17 100644
--- a/drivers/gpu/drm/sun4i/sun4i_layer.h
+++ b/drivers/gpu/drm/sun4i/sun4i_layer.h
@@ -16,6 +16,7 @@
 struct sun4i_layer {
 	struct drm_plane	plane;
 	struct sun4i_drv	*drv;
+	struct sun4i_backend	*backend;
 	int			id;
 };
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 11/11] drm/sun4i: Add backend and tcon pointers to sun4i_crtc
  2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
                   ` (9 preceding siblings ...)
  2017-02-23  8:05 ` [PATCH 10/11] drm/sun4i: Add backend pointer to sun4i_layer Chen-Yu Tsai
@ 2017-02-23  8:05 ` Chen-Yu Tsai
  2017-02-23 18:30   ` Maxime Ripard
  10 siblings, 1 reply; 19+ messages in thread
From: Chen-Yu Tsai @ 2017-02-23  8:05 UTC (permalink / raw)
  To: Maxime Ripard, David Airlie
  Cc: Chen-Yu Tsai, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

sun4i_crtc controls the backend and tcon hardware blocks of the display
pipeline. Instead of doing so through the master drm structure, leave
pointers to the corresponding backend and tcon in itself.

Also drop the drm_device pointer, since it is no longer needed.

The next step forward would be to pass the pointers in through
sun4i_crtc_init as parameters. This would make it easier to support
multiple display pipelines layer on.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_crtc.c | 12 +++++-------
 drivers/gpu/drm/sun4i/sun4i_crtc.h |  3 ++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index 4a30932643c3..018239870a0b 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -52,12 +52,11 @@ static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc,
 				    struct drm_crtc_state *old_state)
 {
 	struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
-	struct sun4i_drv *drv = scrtc->drv;
 	struct drm_pending_vblank_event *event = crtc->state->event;
 
 	DRM_DEBUG_DRIVER("Committing plane changes\n");
 
-	sun4i_backend_commit(drv->backend);
+	sun4i_backend_commit(scrtc->backend);
 
 	if (event) {
 		crtc->state->event = NULL;
@@ -74,11 +73,10 @@ static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc,
 static void sun4i_crtc_disable(struct drm_crtc *crtc)
 {
 	struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
-	struct sun4i_drv *drv = scrtc->drv;
 
 	DRM_DEBUG_DRIVER("Disabling the CRTC\n");
 
-	sun4i_tcon_disable(drv->tcon);
+	sun4i_tcon_disable(scrtc->tcon);
 
 	if (crtc->state->event && !crtc->state->active) {
 		spin_lock_irq(&crtc->dev->event_lock);
@@ -92,11 +90,10 @@ static void sun4i_crtc_disable(struct drm_crtc *crtc)
 static void sun4i_crtc_enable(struct drm_crtc *crtc)
 {
 	struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
-	struct sun4i_drv *drv = scrtc->drv;
 
 	DRM_DEBUG_DRIVER("Enabling the CRTC\n");
 
-	sun4i_tcon_enable(drv->tcon);
+	sun4i_tcon_enable(scrtc->tcon);
 }
 
 static const struct drm_crtc_helper_funcs sun4i_crtc_helper_funcs = {
@@ -125,7 +122,8 @@ struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm)
 	scrtc = devm_kzalloc(drm->dev, sizeof(*scrtc), GFP_KERNEL);
 	if (!scrtc)
 		return ERR_PTR(-ENOMEM);
-	scrtc->drv = drv;
+	scrtc->backend = drv->backend;
+	scrtc->tcon = drv->tcon;
 
 	/* Create our layers */
 	scrtc->layers = sun4i_layers_init(drm);
diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.h b/drivers/gpu/drm/sun4i/sun4i_crtc.h
index 0a888f73c983..cd0e633cce3a 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.h
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.h
@@ -17,7 +17,8 @@ struct sun4i_crtc {
 	struct drm_crtc			crtc;
 	struct drm_pending_vblank_event	*event;
 
-	struct sun4i_drv		*drv;
+	struct sun4i_backend		*backend;
+	struct sun4i_tcon		*tcon;
 	struct sun4i_layer		**layers;
 };
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 01/11] drm/sun4i: Make sunxi_rgb2yuv_coef constant
  2017-02-23  8:05 ` [PATCH 01/11] drm/sun4i: Make sunxi_rgb2yuv_coef constant Chen-Yu Tsai
@ 2017-02-23 18:18   ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2017-02-23 18:18 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: David Airlie, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 435 bytes --]

On Thu, Feb 23, 2017 at 04:05:33PM +0800, Chen-Yu Tsai wrote:
> sunxi_rgb2yuv_coef is a table of RGB-to-YUV conversion coefficients.
> They are programmed into the hardware, and can be declared constant.
> 
> Reported-by: Priit Laes <plaes@plaes.org>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 02/11] drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node
  2017-02-23  8:05 ` [PATCH 02/11] drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node Chen-Yu Tsai
@ 2017-02-23 18:20   ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2017-02-23 18:20 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: David Airlie, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 534 bytes --]

On Thu, Feb 23, 2017 at 04:05:34PM +0800, Chen-Yu Tsai wrote:
> The way drm_of_find_possible_crtcs is it tries to match the

Aren't you missing "works" here     ^

> remote-endpoint of the given node's various endpoints to all the
> crtc's .port field. Thus we need to set drm_crtc.port to the output
> port node of the underlying TCON.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Added it, and applied.
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 03/11] drm/sun4i: Add end of list element for sun4i_layers_init's returned list
  2017-02-23  8:05 ` [PATCH 03/11] drm/sun4i: Add end of list element for sun4i_layers_init's returned list Chen-Yu Tsai
@ 2017-02-23 18:21   ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2017-02-23 18:21 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: David Airlie, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1341 bytes --]

On Thu, Feb 23, 2017 at 04:05:35PM +0800, Chen-Yu Tsai wrote:
> The number of defined planes in sun4i_layer is unknown to other parts
> of the sun4i drm driver. Since the return value of sun4i_layers_init
> is a list of layers, make it return 1 more empty layer as an end of
> list guard value.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied. Thanks!

I guess you could also add a comment about what it returns, just so
it's obvious that it's a NULL terminated list of items

Maxime

> ---
>  drivers/gpu/drm/sun4i/sun4i_layer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.c b/drivers/gpu/drm/sun4i/sun4i_layer.c
> index 41bc0f860f5c..0b703fb02656 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_layer.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_layer.c
> @@ -139,7 +139,7 @@ struct sun4i_layer **sun4i_layers_init(struct drm_device *drm)
>  	struct sun4i_layer **layers;
>  	int i;
>  
> -	layers = devm_kcalloc(drm->dev, ARRAY_SIZE(sun4i_backend_planes),
> +	layers = devm_kcalloc(drm->dev, ARRAY_SIZE(sun4i_backend_planes) + 1,
>  			      sizeof(*layers), GFP_KERNEL);
>  	if (!layers)
>  		return ERR_PTR(-ENOMEM);
> -- 
> 2.11.0
> 

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 04/11] drm/sun4i: Move layers from sun4i_drv to sun4i_crtc
  2017-02-23  8:05 ` [PATCH 04/11] drm/sun4i: Move layers from sun4i_drv to sun4i_crtc Chen-Yu Tsai
@ 2017-02-23 18:22   ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2017-02-23 18:22 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: David Airlie, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

On Thu, Feb 23, 2017 at 04:05:36PM +0800, Chen-Yu Tsai wrote:
> This patch moves the sun4i_layers_init call from sun4i_drv_bind to
> sun4i_crtc_init, and the layers pointer from struct sun4i_drv to
> struct sun4i_crtc.
> 
> The layers are bound to a specific crtc, and they are not directly
> used once initiated. They are used through their included drm_plane
> structures.
> 
> Moving the layers into the crtc facilitates binding them to the crtc
> explicitly, by setting the corresponding bit in their .possible_crtcs
> fields right after the crtc is initialized. This is done in a later
> patch.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thanks!
Maxime
-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 05/11] drm/sun4i: Initialize crtc from tcon bind function
  2017-02-23  8:05 ` [PATCH 05/11] drm/sun4i: Initialize crtc from tcon bind function Chen-Yu Tsai
@ 2017-02-23 18:24   ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2017-02-23 18:24 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: David Airlie, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1677 bytes --]

On Thu, Feb 23, 2017 at 04:05:37PM +0800, Chen-Yu Tsai wrote:
> The tcon provides part of the functionality of the crtc, and also
> provides the device node for the output port of the crtc. To be able
> to use drm_of_find_possible_crtcs(), all crtc must be initialized before
> any downstream encoders. The other part of the crtc is the display
> backend.
> 
> The Rockchip DRM driver does this by first binding all vops, which is
> their crtc, and this step also creates the crtc objects. Then all
> remaining hardware components are bound. With the Allwinner display
> pipeline, we have multiple components comprising the crtc, and varying
> depths of the display pipeline. Since components are added with a depth
> first search of the of_graph, we can initialize the crtc object within
> the tcon bind function. Since the backend precedes the tcon, and the
> backends cannot be muxed or switched around, we can be sure that the
> associated backend is already initialized.
> 
> This patch also moves the crtc pointer from the main drm_device data to
> the tcon device data. Besides the crtc callbacks, the crtc structure is
> only used within the tcon driver to signal vblank events from its
> interrupt handler.
> 
> As the crtc and layer bits are now called from the tcon bits, we must
> move them from the sun4i-drm module to the sun4i-tcon module to avoid
> circular dependencies between the two modules. This is because sun4i-drm
> also calls into sun4i-tcon.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 06/11] drm/sun4i: Drop primary layer pointer from sun4i_drv
  2017-02-23  8:05 ` [PATCH 06/11] drm/sun4i: Drop primary layer pointer from sun4i_drv Chen-Yu Tsai
@ 2017-02-23 18:26   ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2017-02-23 18:26 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: David Airlie, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

On Thu, Feb 23, 2017 at 04:05:38PM +0800, Chen-Yu Tsai wrote:
> The current layer init code keeps a pointer to the primary plane layer
> in sun4i_drv. When we eventually support multiple display pipelines,
> this would force us to keep track of primary planes for all crtcs. And
> these pointers only get used at bind time.
> 
> Instead, have the crtc init code iterate through the returned layers
> to find the primary and cursor layers. And drop the pointer from the
> sun4i_drv structure.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 11/11] drm/sun4i: Add backend and tcon pointers to sun4i_crtc
  2017-02-23  8:05 ` [PATCH 11/11] drm/sun4i: Add backend and tcon pointers to sun4i_crtc Chen-Yu Tsai
@ 2017-02-23 18:30   ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2017-02-23 18:30 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: David Airlie, dri-devel, linux-sunxi, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

On Thu, Feb 23, 2017 at 04:05:43PM +0800, Chen-Yu Tsai wrote:
> sun4i_crtc controls the backend and tcon hardware blocks of the display
> pipeline. Instead of doing so through the master drm structure, leave
> pointers to the corresponding backend and tcon in itself.
> 
> Also drop the drm_device pointer, since it is no longer needed.
> 
> The next step forward would be to pass the pointers in through
> sun4i_crtc_init as parameters. This would make it easier to support
> multiple display pipelines layer on.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied all the previous patches, and this one

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-02-23 18:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-23  8:05 [PATCH 00/11] drm/sun4i: Various fixes and cleanups part 2 Chen-Yu Tsai
2017-02-23  8:05 ` [PATCH 01/11] drm/sun4i: Make sunxi_rgb2yuv_coef constant Chen-Yu Tsai
2017-02-23 18:18   ` Maxime Ripard
2017-02-23  8:05 ` [PATCH 02/11] drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node Chen-Yu Tsai
2017-02-23 18:20   ` Maxime Ripard
2017-02-23  8:05 ` [PATCH 03/11] drm/sun4i: Add end of list element for sun4i_layers_init's returned list Chen-Yu Tsai
2017-02-23 18:21   ` Maxime Ripard
2017-02-23  8:05 ` [PATCH 04/11] drm/sun4i: Move layers from sun4i_drv to sun4i_crtc Chen-Yu Tsai
2017-02-23 18:22   ` Maxime Ripard
2017-02-23  8:05 ` [PATCH 05/11] drm/sun4i: Initialize crtc from tcon bind function Chen-Yu Tsai
2017-02-23 18:24   ` Maxime Ripard
2017-02-23  8:05 ` [PATCH 06/11] drm/sun4i: Drop primary layer pointer from sun4i_drv Chen-Yu Tsai
2017-02-23 18:26   ` Maxime Ripard
2017-02-23  8:05 ` [PATCH 07/11] drm/sun4i: Drop hardcoded .possible_crtcs values from layers Chen-Yu Tsai
2017-02-23  8:05 ` [PATCH 08/11] drm/sun4i: tv: Switch to drm_of_find_possible_crtcs Chen-Yu Tsai
2017-02-23  8:05 ` [PATCH 09/11] drm/sun4i: rgb: Pass tcon pointer when initializing RGB encoder Chen-Yu Tsai
2017-02-23  8:05 ` [PATCH 10/11] drm/sun4i: Add backend pointer to sun4i_layer Chen-Yu Tsai
2017-02-23  8:05 ` [PATCH 11/11] drm/sun4i: Add backend and tcon pointers to sun4i_crtc Chen-Yu Tsai
2017-02-23 18:30   ` Maxime Ripard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).