diff mbox

[v2,0/2] Improve drm_of_component_probe() and move rockchip to use it

Message ID 20151223103906.2aae53595345240d57d57b41@free.fr (mailing list archive)
State New, archived
Headers show

Commit Message

Jean-Francois Moine Dec. 23, 2015, 9:39 a.m. UTC
On Tue, 22 Dec 2015 17:38:00 +0000
Liviu Dudau <Liviu.Dudau@arm.com> wrote:

> On Fri, Nov 20, 2015 at 02:22:03PM +0000, Liviu Dudau wrote:
> > Hello,
> > 
> > This is v2 of the patchset trying to make drm_of_component_probe() cope with finding
> > both local crtc ports and remote encoder ones. Heiko Stübner was nice enough to test
> > an earlier version that was patched following Russell's suggestions on rk3288, but
> > I haven't seen any reports from iMX or Armada users.
> > 
> > Changelog:
> >  v2: Updated the drm_of_component_probe() comment to explain why the reference count
> >      is not dropped. Fixed the compare_port() function for rockchip as described by
> >      Russell.
> >  v1: Original submission. http://lists.freedesktop.org/archives/dri-devel/2015-November/094546.html
> 
> Gentle ping, this has now been tested by Rockchip people and fixes the earlier version
> that had to be reverted in mainline. Can it be included in the -next somewhere?

Hi Liviu,

Sorry for being a bit late.

I wanted to use drm_of_component_probe() for a new DRM driver, but I
could not find any way to do it: you add the "ports" nodes as
components while, usually, the components are the device nodes
themselves.

With this simple patch:

everything is easy, my DT being like:

	de_controller {
		...
		ports = <&lcd0_p>;
	};

	lcd_controller {
		...
		lcd0_p: port {
			lcd0_ep: endpoint {
				remote-endpoint = <&hdmi_ep>;
			};
		};
	};

What was the reason to keep the "ports" node instead of the device?

Comments

Liviu Dudau Dec. 23, 2015, 10:05 a.m. UTC | #1
On Wed, Dec 23, 2015 at 10:39:06AM +0100, Jean-Francois Moine wrote:
> On Tue, 22 Dec 2015 17:38:00 +0000
> Liviu Dudau <Liviu.Dudau@arm.com> wrote:
> 
> > On Fri, Nov 20, 2015 at 02:22:03PM +0000, Liviu Dudau wrote:
> > > Hello,
> > > 
> > > This is v2 of the patchset trying to make drm_of_component_probe() cope with finding
> > > both local crtc ports and remote encoder ones. Heiko Stübner was nice enough to test
> > > an earlier version that was patched following Russell's suggestions on rk3288, but
> > > I haven't seen any reports from iMX or Armada users.
> > > 
> > > Changelog:
> > >  v2: Updated the drm_of_component_probe() comment to explain why the reference count
> > >      is not dropped. Fixed the compare_port() function for rockchip as described by
> > >      Russell.
> > >  v1: Original submission. http://lists.freedesktop.org/archives/dri-devel/2015-November/094546.html
> > 
> > Gentle ping, this has now been tested by Rockchip people and fixes the earlier version
> > that had to be reverted in mainline. Can it be included in the -next somewhere?
> 
> Hi Liviu,
> 
> Sorry for being a bit late.
> 
> I wanted to use drm_of_component_probe() for a new DRM driver, but I
> could not find any way to do it: you add the "ports" nodes as
> components while, usually, the components are the device nodes
> themselves.
> 
> With this simple patch:
> 
> diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
> index 493c05c..dbd2921 100644
> --- a/drivers/gpu/drm/drm_of.c
> +++ b/drivers/gpu/drm/drm_of.c
> @@ -101,7 +101,7 @@ int drm_of_component_probe(struct device *dev,
>  			continue;
>  		}
>  
> -		component_match_add(dev, &match, compare_of, port);
> +		component_match_add(dev, &match, compare_of, port->parent);
>  		of_node_put(port);
>  	}
>  
> everything is easy, my DT being like:
> 
> 	de_controller {
> 		...
> 		ports = <&lcd0_p>;
> 	};
> 
> 	lcd_controller {
> 		...
> 		lcd0_p: port {
> 			lcd0_ep: endpoint {
> 				remote-endpoint = <&hdmi_ep>;
> 			};
> 		};
> 	};
> 
> What was the reason to keep the "ports" node instead of the device?

The function is an extract of common code sprinkled through a few DRM drivers,
they all used port rather than port->parent.

Have a look at my v2 where I've introduced two compare functions and also
modified the Rockchip compare_port() to use port->parent in the comparison. I
guess that should solve your problem.

Best regards,
Liviu

> 
> -- 
> Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
> Jef		|		http://moinejf.free.fr/
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
Jean-Francois Moine Dec. 23, 2015, 5:20 p.m. UTC | #2
On Wed, 23 Dec 2015 10:05:34 +0000
Liviu Dudau <Liviu.Dudau@arm.com> wrote:

> > What was the reason to keep the "ports" node instead of the device?
> 
> The function is an extract of common code sprinkled through a few DRM drivers,
> they all used port rather than port->parent.

Sorry for I could find such drivers. May you give me any pointer?

> Have a look at my v2 where I've introduced two compare functions and also
> modified the Rockchip compare_port() to use port->parent in the comparison. I
> guess that should solve your problem.

Keeping the port instead of the parent asks for more code, but,
especially, it also asks for changes in the component drivers because,
at bind time, in 'data', they get a port instead of the device.

You might say that this could be interesting for components with many
different masters (video and audio), but this could be solved adding
intermediate device nodes in the DT (ports).
Russell King - ARM Linux Dec. 23, 2015, 6:59 p.m. UTC | #3
On Wed, Dec 23, 2015 at 06:20:33PM +0100, Jean-Francois Moine wrote:
> On Wed, 23 Dec 2015 10:05:34 +0000
> Liviu Dudau <Liviu.Dudau@arm.com> wrote:
> 
> > > What was the reason to keep the "ports" node instead of the device?
> > 
> > The function is an extract of common code sprinkled through a few DRM drivers,
> > they all used port rather than port->parent.
> 
> Sorry for I could find such drivers. May you give me any pointer?

imx-drm probably.

> > Have a look at my v2 where I've introduced two compare functions and also
> > modified the Rockchip compare_port() to use port->parent in the comparison. I
> > guess that should solve your problem.
> 
> Keeping the port instead of the parent asks for more code, but,
> especially, it also asks for changes in the component drivers because,
> at bind time, in 'data', they get a port instead of the device.

Sorry, this doesn't make sense.  You have far too many sub-clauses
which mean nothing at all.  Please rephrase.
Jean-Francois Moine Dec. 24, 2015, 8:15 a.m. UTC | #4
On Wed, 23 Dec 2015 18:59:48 +0000
Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:

> > > Have a look at my v2 where I've introduced two compare functions and also
> > > modified the Rockchip compare_port() to use port->parent in the comparison. I
> > > guess that should solve your problem.
> > 
> > Keeping the port instead of the parent asks for more code, but,
> > especially, it also asks for changes in the component drivers because,
> > at bind time, in 'data', they get a port instead of the device.
> 
> Sorry, this doesn't make sense.  You have far too many sub-clauses
> which mean nothing at all.  Please rephrase.

Well, two topics:

- adding a second 'of_compare' function complexifies the code
  and people may wonder why such a function is needed and what
  they have to put inside.

- usually, the component drivers just do a component_add() of the device
  at probe time.
  Now, as the bind() function of the components of the first level
  returns the port in 'data', some work has to be done for retrieving
  the device.
  This can (should?) be done in the bind() function.
  In drm/imx/ipuv3-crtc.c, this is done by a hack, changing the device
  node reference before calling component_add()!

I looked at the imx-drm and the associated DTs, and I think that,
without the v2 patch and keeping the port parent as the component
(previous mail), the code could be simplified adding an intermediate
device node in the DT.

For example, in imx6qdl.dtsi:

	ipu1: ipu@02400000 {
		...
		ports@2 {			/* di<x> device */
			ipu1_di0: port {
				...
				ipu1_di0_hdmi: endpoint@1 {
					remote-endpoint = <&hdmi_mux_0>;
				};
				...
			};
		};
	}

In the code, the ipu driver searches the 'ports' and adds them as components.
After binding, the devices are the 'ports'.
Russell King - ARM Linux Dec. 24, 2015, 10:52 a.m. UTC | #5
On Thu, Dec 24, 2015 at 09:15:28AM +0100, Jean-Francois Moine wrote:
> On Wed, 23 Dec 2015 18:59:48 +0000
> Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> 
> > > > Have a look at my v2 where I've introduced two compare functions and also
> > > > modified the Rockchip compare_port() to use port->parent in the comparison. I
> > > > guess that should solve your problem.
> > > 
> > > Keeping the port instead of the parent asks for more code, but,
> > > especially, it also asks for changes in the component drivers because,
> > > at bind time, in 'data', they get a port instead of the device.
> > 
> > Sorry, this doesn't make sense.  You have far too many sub-clauses
> > which mean nothing at all.  Please rephrase.
> 
> Well, two topics:
> 
> - adding a second 'of_compare' function complexifies the code
>   and people may wonder why such a function is needed and what
>   they have to put inside.
> 
> - usually, the component drivers just do a component_add() of the device
>   at probe time.

... which is exactly what does happen throughout imx-drm.

>   Now, as the bind() function of the components of the first level
>   returns the port in 'data', some work has to be done for retrieving
>   the device.
>   This can (should?) be done in the bind() function.

Sorry, this still makes zero sense to me.  "retrieving the device"
is all done by the core component code and has nothing to do with
the drivers themselves.

>   In drm/imx/ipuv3-crtc.c, this is done by a hack, changing the device
>   node reference before calling component_add()!

What hack?

static int ipu_drm_probe(struct platform_device *pdev)
{
        struct device *dev = &pdev->dev;
        int ret;

        if (!dev->platform_data)
                return -EINVAL;

        ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
        if (ret)
                return ret;

        return component_add(dev, &ipu_crtc_ops);
}

There's no hack there.  I see nothing changing dev->of_node there.

> I looked at the imx-drm and the associated DTs, and I think that,
> without the v2 patch and keeping the port parent as the component
> (previous mail), the code could be simplified adding an intermediate
> device node in the DT.

Not going to happen, because that's going to break compatibility with
existing DTs.

Let me explain instead what's going on, and why imx-drm is different.

The iMX DT files describe the hardware, which is a very complex block.
The IPU as a whole in DT, with its external interfaces.  The IPU driver
lives in drivers/gpu/ipu-v3/.

The hardware is a single controller (aka IPU - image processing unit)
which consists of many sub-blocks of hardware.  Two of these blocks
are display controllers with associated display interfaces.  These
_can_ be programmed to behave as a CRTC, but they're essentially just
waveform generators.  There's other blocks, including camera interfaces.

We _choose_ in Linux to have the IPU driver create several different
platform devices, one for each of its ports, whether it's a camera
interface or a display interface.  These platform devices are bound
to the IPU's port DT nodes.

Some iMX chips have two IPUs.  This means there can be a total of four
display outputs.

On the display bridge side, display bridges can be configured via
muxes to be connected to any of these display outputs.  Several
display bridges can even be connected to a single display output,
though this is not done in practise.

DT fully describes these links between the display outputs and
display bridges using the OF graph support.  From the DT point of
view, this is all very elegant and correct to the hardware structure.

However, when we come to the Linux implementation, things get sticky
because we need to select the correct platform device corresponding
with the IPU's port.  This can only be done using the 'port' node
and not port->parent.

port->parent would be the IPU device node itself.  If we were to
introduce the additional ports {} node, that doesn't help, because
now port->parent points at the ports {} node instead, not the actual
port - and we need the port itself to identify which of the IPU's
own created platform devices to select.

So, modifying DT doesn't help in any way, even if you ignore the fact
that we need to maintain backwards compatibility.
Jean-Francois Moine Dec. 24, 2015, 12:27 p.m. UTC | #6
On Thu, 24 Dec 2015 10:52:07 +0000
Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:

> On Thu, Dec 24, 2015 at 09:15:28AM +0100, Jean-Francois Moine wrote:
> > Well, two topics:
> > 
> > - adding a second 'of_compare' function complexifies the code
> >   and people may wonder why such a function is needed and what
> >   they have to put inside.
> > 
> > - usually, the component drivers just do a component_add() of the device
> >   at probe time.
> 
> ... which is exactly what does happen throughout imx-drm.
> 
> >   Now, as the bind() function of the components of the first level
> >   returns the port in 'data', some work has to be done for retrieving
> >   the device.
> >   This can (should?) be done in the bind() function.
> 
> Sorry, this still makes zero sense to me.  "retrieving the device"
> is all done by the core component code and has nothing to do with
> the drivers themselves.

Right, sorry, I wrote 'data' while thinking 'dev'.

> >   In drm/imx/ipuv3-crtc.c, this is done by a hack, changing the device
> >   node reference before calling component_add()!
> 
> What hack?
	[snip]
> There's no hack there.  I see nothing changing dev->of_node there.

Right again, I was looking in 4.4-rc1.

> > I looked at the imx-drm and the associated DTs, and I think that,
> > without the v2 patch and keeping the port parent as the component
> > (previous mail), the code could be simplified adding an intermediate
> > device node in the DT.
> 
> Not going to happen, because that's going to break compatibility with
> existing DTs.

OK, I cannot discuss against that!

> Let me explain instead what's going on, and why imx-drm is different.

Already understood.

	[snip]
> However, when we come to the Linux implementation, things get sticky
> because we need to select the correct platform device corresponding
> with the IPU's port.  This can only be done using the 'port' node
> and not port->parent.
> 
> port->parent would be the IPU device node itself.  If we were to
> introduce the additional ports {} node, that doesn't help, because
> now port->parent points at the ports {} node instead, not the actual
> port - and we need the port itself to identify which of the IPU's
> own created platform devices to select.
> 
> So, modifying DT doesn't help in any way, even if you ignore the fact
> that we need to maintain backwards compatibility.

The ports {} node is just a container, and so is the (unique) port {}
node which is inside:

	ipu1: ipu@02400000 {
		...
		ports@2 {			/* di0 device */
			ipu1_di0: port {
				...
				ipu1_di0_hdmi: endpoint@1 {
					remote-endpoint = <&hdmi_mux_0>;
				};
				ipu1_di0_mipi: endpoint@2 {
					remote-endpoint = <&mipi_mux_0>;
				};
				...
			};
		};
		ports@3 {			/* di1 device */
			ipu1_di1: port {
				...
				ipu1_di1_hdmi: endpoint@1 {  
					remote-endpoint = <&hdmi_mux_1>;
				};
				ipu1_di1_mipi: endpoint@2 {
					remote-endpoint = <&mipi_mux_1>;
				};
				...
			};
		};
	};
Russell King - ARM Linux Dec. 24, 2015, 12:36 p.m. UTC | #7
On Thu, Dec 24, 2015 at 01:27:08PM +0100, Jean-Francois Moine wrote:
> On Thu, 24 Dec 2015 10:52:07 +0000
> Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> > However, when we come to the Linux implementation, things get sticky
> > because we need to select the correct platform device corresponding
> > with the IPU's port.  This can only be done using the 'port' node
> > and not port->parent.
> > 
> > port->parent would be the IPU device node itself.  If we were to
> > introduce the additional ports {} node, that doesn't help, because
> > now port->parent points at the ports {} node instead, not the actual
> > port - and we need the port itself to identify which of the IPU's
> > own created platform devices to select.
> > 
> > So, modifying DT doesn't help in any way, even if you ignore the fact
> > that we need to maintain backwards compatibility.
> 
> The ports {} node is just a container, and so is the (unique) port {}
> node which is inside:
> 
> 	ipu1: ipu@02400000 {
> 		...
> 		ports@2 {			/* di0 device */
> 			ipu1_di0: port {
> 				...
> 				ipu1_di0_hdmi: endpoint@1 {
> 					remote-endpoint = <&hdmi_mux_0>;
> 				};
> 				ipu1_di0_mipi: endpoint@2 {
> 					remote-endpoint = <&mipi_mux_0>;
> 				};
> 				...
> 			};
> 		};
> 		ports@3 {			/* di1 device */
> 			ipu1_di1: port {
> 				...
> 				ipu1_di1_hdmi: endpoint@1 {  
> 					remote-endpoint = <&hdmi_mux_1>;
> 				};
> 				ipu1_di1_mipi: endpoint@2 {
> 					remote-endpoint = <&mipi_mux_1>;
> 				};
> 				...
> 			};
> 		};
> 	};

That's against the binding documentation for graphs:

All 'port' nodes can be grouped under an optional 'ports' node, which
allows to specify #address-cells, #size-cells properties for the 'port'
nodes independently from any other child device nodes a device might
have.

It says "All 'port' nodes" not "Some" or similar.  The DT code requires
this.  To change this would mean changing the DT binding and the code
parsing that binding, adding much more complexity there.

You earlier argued against adding (what would be less) complexity to
the DRM OF helper, now you seem to be wanting more complexity elsewhere
to save what would be trivial complexity elsewhere - all the functions
which iterate over the port nodes would need to be updated to find
all the "ports" nodes, and end up needing an additional level of looping
and complexity to jump from one port node in a ports { } block to the
first port node in the next ports { } block.

Also it makes the API more difficult because we end up with the ports@n
nodes needing a reg= property (as per ePAPR requirements) and it becomes
unclear what that would represent at the hardware level.

It seems that you're trying to work around a limitation in Linux by
modifying the hardware representation...
Jean-Francois Moine Dec. 25, 2015, 9:38 a.m. UTC | #8
On Thu, 24 Dec 2015 12:36:10 +0000
Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:

> It seems that you're trying to work around a limitation in Linux by
> modifying the hardware representation...

Sorry to come back to this topic, but I think you are wrong.

Looking at the imx6 DTs, the problem comes from the display-subsystem
node which is a pure Linux specific software entity.

If you want to describe only the hardware in the DT, everything is
simple.

A IPU is a image controller with its sub-devices. Seen from the system, it
is like a 'board' with its devices (LCDs, camera...).

When 2 IPUs, there are 2 independant boards.

Here is what could be a pure hardware DT:

/* no display-subsystem */

	ipu1: ipu@02400000 {		/* image controller / board 1 */
		compatible = "fsl,imx6q-ipu";
		...
		ports = <&ipu1_di0>, <&ipu1_di1>;
	};
	ipu1_di0: di@0 {		/* display interface / crtc 1 */
		compatible = "fsl,imx6q-di";
		...
		ipu1_di0_hdmi: endpoint@1 {
			remote-endpoint = <&hdmi_mux_0>;
		};
		ipu1_di0_mipi: endpoint@2 {
			remote-endpoint = <&mipi_mux_0>;
		}
		...
	};
	ipu1_di1: di@1 {		/* display interface / crtc 2 */
		compatible = "fsl,imx6q-di";
		...
		ipu1_di1_hdmi: endpoint@1 {
			remote-endpoint = <&hdmi_mux_1>;
		};
		ipu1_di1_mipi: endpoint@2 {
			remote-endpoint = <&mipi_mux_1>;
		}
		...
	};

	ipu2: ipu@02800000 {		/* image controller / board 2 */
		compatible = "fsl,imx6q-ipu";
		...
		ports = <&ipu2_di0>, <&ipu2_di1>;
	};
	ipu2_di0: di@0 {		/* display interface / crtc 1 */
		compatible = "fsl,imx6q-di";
		...
		ipu2_di0_hdmi: endpoint@1 {
			remote-endpoint = <&hdmi_mux_2>;
		};
		ipu2_di0_mipi: endpoint@2 {
			remote-endpoint = <&mipi_mux_2>;
		}
		...
	};
	ipu2_di1: di@1 {		/* display interface / crtc 2 */
		compatible = "fsl,imx6q-di";
		...
		ipu2_di1_hdmi: endpoint@1 {
			remote-endpoint = <&hdmi_mux_3>;
		};
		ipu2_di1_mipi: endpoint@2 {
			remote-endpoint = <&mipi_mux_3>;
		}
		...
	};

Then, a standard component binding (port->parent) works fine...

(you may note that the same problem exists with audio: the
'simple-card' is also a pure Linux specific software entity)
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
index 493c05c..dbd2921 100644
--- a/drivers/gpu/drm/drm_of.c
+++ b/drivers/gpu/drm/drm_of.c
@@ -101,7 +101,7 @@  int drm_of_component_probe(struct device *dev,
 			continue;
 		}
 
-		component_match_add(dev, &match, compare_of, port);
+		component_match_add(dev, &match, compare_of, port->parent);
 		of_node_put(port);
 	}