gpu: ipu-v3: Add IDMA channel linking support

Adds functions to link and unlink IDMAC source channels to sink
channels.

So far the following links are supported:

IPUV3_CHANNEL_IC_PRP_ENC_MEM -> IPUV3_CHANNEL_MEM_ROT_ENC
PUV3_CHANNEL_IC_PRP_VF_MEM   -> IPUV3_CHANNEL_MEM_ROT_VF
IPUV3_CHANNEL_IC_PP_MEM      -> IPUV3_CHANNEL_MEM_ROT_PP

More links can be added to the idmac_link_info[] array.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
gpu: ipu-cpmem: Support YVU422

Add simple hooks to support YVU422 in cpmem.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
gpu: ipu-cpmem: Add ipu_cpmem_get_burstsize()

Adds ipu_cpmem_get_burstsize().

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: Crtcs moved to device tree

The crtcs are now nodes in the device tree, and the encoder endpoints
fall under the crtc port.

ipu_client_platformdata is no longer needed and is gone. The crtc
retrieves the following required parameters from its node:

- ipu phandle.
- di number.
- the port endpoints.

Optionally, "dual-plane" can be specified to configure the crtc device
with a foreground plane. If not given, the crtc will have only a
single plane.

The DC and IDMAC channels can be inferred from the dual-plane parameter.
In table form, the channel usage is:

                 Background Plane   Foreground Plane     Single Plane
                 ----------------   ----------------     ------------
    Flow Type    IDMAC   DC   DP     IDMAC   DP           IDMAC   DC
    ---------    -----  ---  ---     -----  ---           -----  ---
    Sync          23     5    0       27     1             28     1
    Async         24     6    2       29     3             41     2

Async flows are included in the above table but async displays are
not yet supported by the crtc and plane drivers.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: hdmi: optimize i2c write wait

A wait of around 50 ~ 100 micro seconds seems to be enough to allow
I2C Master PHY done, so instead of wait 1000 usec at each time
of register check, wait 100 usec is more appropriate.

Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: parallel-display: Support RGB666 pixel fmt

Add a clause to imx-pd driver to use 18-bit output if driver is told so.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com>
Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: imx-ldb: Add debug to connector/encoder entry points

Add some debug macros for the important encoder and connector
callbacks.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: imx-ldb: Implement imx_ldb_encoder_dpms()

Implement imx_ldb_encoder_dpms(). Two new functions are created
to share poweroff and poweron code. imx_ldb_poweroff() is called
by encoder dpms, prepare, and disable. imx_ldb_poweron() is called
by encoder dpms and commit.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: parallel-display: Fix typo when setting mode type

Comma expression is used to set mode type
"mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,"
which is a typo, replace it with ";".

Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: ipuv3-plane: Fix planar formats

During a mode set the U/V plane strides and buffer offsets
for planar pixel formats were not being configured in cpmem.
Fix by calling ipu_cpmem_set_yuv_planar() for planar formats.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: ipuv3-plane: Allow YUV space for background plane

A background plane was assuming the framebuffer pixel format was
RGB by passing IPUV3_COLORSPACE_RGB to ipu_dp_setup_channel(). Fix
by passing the actual colorspace of the framebuffer's pixel format.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: ipuv3-plane: Add more supported pixel formats

Report more supported formats to drm core via ipu_plane_formats[].

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: ipuv3-plane: Implement global alpha and colorkey properties

Add support for setting global alpha and colorkey in foreground planes
using plane properties. Background planes can also support these
properties if the background plane is initialized as not private.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: hdmi: rework irq request/free

Rearrange how HDMI driver requests and frees irq. Currently the driver
has two problems:

1) if imx_hdmi_register() fails, irq still can trigger and cause oops
2) irq is enabled too early, before all fields are initialized, so
triggered irq can cause oops.

Fix by moving irq request and activation to very end of imx_hdmi_bind(),
especially after imx_hdmi_register(). Then there's no possible way there
could be a (spurious) interrupt after a failed imx_hdmi_register() but
before the irq is freed.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com>
Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: imx-ldb: Add DDC support

Add support for reading EDID over Display Data Channel. If no DDC
adapter is available, falls back to hardcoded EDID or display-timings
node as before.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: Fix separate primary plane objects

drm_crtc_init() will create a primary plane object, while imx-drm also
creates its own, thus two primary planes are separately created, and
can cause difficult bugs to track down in the future.

Fix by using drm_crtc_init_with_planes() instead of drm_crtc_init(),
so that we can hand drm our own primary plane object, thus crtc->primary
and ipu_crtc->plane[0].base now are the same object.

To do this we need to statically declare the primary and overlay
planes in the crtc driver, to avoid a chicken-before-the-egg problem,
the primary plane must exist when imx_drm_add_crtc() is called but
before ipu_plane_init().

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: Move page flip handling to plane driver

Move page flip handling and associated vblank handling to the
plane driver. This paves the way to allow page flipping in not
just the primary plane but the overlay plane as well.

To do this the primary and overlay planes are assigned a pipe value
suitable for passing to the drm core vblank methods (drm_vblank_get,
put,handle).

We modify imx-drm core slightly to make room for primary and overlay
pipe id's when assigning the crtc pipe. So crtc 0 has a primary pipe
value of 0 and overlay pipe value 1, crtc 1 has primary pipe value 2
and overlay pipe value 3, etc. imx_drm_crtc_id() returns the primary
pipe divided by 2 as an id value to form possible crtc masks.

The drm core vblank sees these planes as additional crtcs (pipes) and
does not need significant changes.

The plane driver implements page flip using idmac double-buffering.
Without double-buffering, a page flip operation changes the idmac
channel buffer base address while the buffer is still active. This
is not recommended according to the reference manual.

With double-buffering, a page-flip can set the base of the inactive
buffer before switching to it using buffer-ready control.

Note that for the synchronous display channels, the buffer ready signal can
be driven either by the ARM core writing to the buffer ready registers,
or by the DI.

When the ARM core does not drive ping-pong buffer ready selection at
every EOF, the DI will drive buffer ready, triggered by a timer located
in the DI. The IPU's FSU unit will quickly settle on a single buffer and
then remain at that buffer, the DI driving buffer ready at that buffer.

If the ARM core (the plane driver) then selects the other (inactive)
buffer, the FSU switches to it and then remains at this buffer, the DI
again taking over buffer ready signalling at the new buffer, until the
ARM core makes the next buffer selection.

So we take advantage of this behaviour and use buffer selection to
switch to the other buffer when we want to flip to another DRM
framebuffer for page-flip.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
imx-drm: Reset ipu unit pointers to NULL on errors

In the crtc and plane drivers it is possible the ipu unit pointers
could be left at error pointer values. Reset them to NULL on errors
to prevent this. Also ipu_put_resources() should reset the units to
NULL after releasing them.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
drm: implement page flipping support for planes

Planes like crtcs would benefit from having page flip event support.
With planes page flip it is now possible to synchronize changing a
framebuffer used by an overlay (or even cursor) plane with vertical
sync events.

A page flip in the primary plane is equivalent to a crtc page flip,
which suggests this ioctl could deprecate the crtc page flip ioctl
at some point in the future.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
Signed-off-by: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com>
imx-drm: ipuv3-plane: Assign page_flip method to drm_plane_funcs

Assign ipu_plane_page_flip to new drm_plane_funcs->page_flip method.
This allows page flip operation in both the primary and overlay planes.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>