drm/plane: Make ->atomic_update() mandatory

There is no use-case where it would be useful for drivers not to
implement this function and the transitional plane helpers already
require drivers to provide an implementation.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/plane: Add optional ->atomic_disable() callback

In order to prevent drivers from having to perform the same checks over
and over again, add an optional ->atomic_disable callback which the core
calls under the right circumstances.

v2: pass old state and detect edges to avoid calling ->atomic_disable on
already disabled planes, remove redundant comment (Daniel Vetter)

v3: rename helper to drm_atomic_plane_disabling() to clarify that it is
checking for transitions, move helper to drm_atomic_helper.h, clarify
check for !old_state and its relation to transitional helpers

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/exynos: Update for ->atomic_update change
drm/tegra: Universal planes fixup
drm/tegra: Use tegra_commit_dc() in output drivers

All output drivers have open-coded variants of this function, so export
it to remove some code duplication.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: Stop CRTC at CRTC disable time

Previously output drivers would all stop the display controller in their
disable path. However with the transition to atomic modesetting the
display controller needs to be kept running until all planes have been
disabled so that software can properly determine (using VBLANK counts)
when it is safe to remove the framebuffers associated with the planes.

Moving this code into the display controller's disable path also gets
rid of the duplication of this into all output drivers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: dsi: Registers are 32-bit

Use a sized unsigned 32-bit data type (u32) to store register contents.
The DSI registers are 32 bits wide irrespective of the architecture's
data width.

Signed-off-by: Thierry Reding <treding@nvidia.com>
usb: phy: Restore deferred probing path

Commit 1290a958d48e ("usb: phy: propagate __of_usb_find_phy()'s error on
failure") broke platforms that rely on deferred probing to order probing
of PHY and host controller drivers. The reason is that the commit simply
propagates errors from __of_usb_find_phy(), which returns -ENODEV if no
PHY has been registered yet for a given device tree node. The only case
in which -EPROBE_DEFER would now be returned is if try_module_get() did
fail, which does not make sense.

The correct thing to do is to return -EPROBE_DEFER if a PHY hasn't been
registered yet. The only condition under which it makes sense to return
-ENODEV is if the device tree node representing the PHY has been
disabled (via the status property) because in that case the PHY will
never be registered.

This patch addresses the problem by making __of_usb_find_phy() return an
appropriate error code while keeping in line with the above-mentioned
commit to propagate error codes rather than overwriting them. At the
same time the check for a valid PHY is decoupled from the check for the
try_module_get() call and a separate error code is returned if the
latter fails.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: dsi: Soft-reset controller on ->disable

This reset is necessary to properly clean up the internal state of the
controller.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: dsi: Reset across ->exit()/->init()

This allows a DRM driver unload/reload cycle to completely reset the DSI
controller and may help in situations where it's broken.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: Move tegra_drm_mode_funcs to the core

This structure will be extended using non-framebuffer related callbacks
in subsequent patches, so it should move to a more central location.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: dc: Remove unneeded checks

These checks try to make sure that a page-flip has been successfully
programmed to the display controller before returning the VBLANK event
to userspace. This is problematic because it checks the framebuffer
associated with the primary plane and will therefore break with atomic
modesetting where that framebuffer isn't kept up-to-date. A relatively
simple fix could be to look at the framebuffer in the CRTC's state. It
is somewhat brittle to base the decision about a successful page-flip
merely on the primary plane since eventually a page-flip could involve
overlay planes only.

Instead of trying to be smart, trust the code that performs the page-
flip to do the right thing and assume that the new framebuffer will be
scanned out after the next VBLANK interrupt.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: dc: No longer disable planes at CRTC disable

The DRM core should take care of disabling all unneeded planes, so there
is no need to do this explicitly.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: Convert output midlayer to helpers

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: output: Make ->setup_clock() optional

In order to transition output drivers to using the struct tegra_output
as a helper rather than midlayer, make this callback optional. Instead
drivers should implement the equivalent as part of ->mode_fixup(). For
the conversion to atomic modesetting a new callback ->atomic_check()
should be implemented that updates the display controller's state with
the corresponding parent clock, rate and shift clock divider.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: Add tegra_dc_setup_clock() helper

This is a small helper that performs the basic steps required by all
output drivers to prepare the display controller for use with a given
encoder.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: hdmi: Demidlayer

Implement encoder and connector within the HDMI driver itself using the
Tegra output helpers rather than using the Tegra output as midlayer. By
doing so one level of indirection is removed and output drivers become
more flexible while keeping the majority of the advantages provided by
the common output helpers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: dsi: Demidlayer

Implement encoder and connector within the DSI driver itself using the
Tegra output helpers rather than using the Tegra output as midlayer. By
doing so one level of indirection is removed and output drivers become
more flexible while keeping the majority of the advantages provided by
the common output helpers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
drm/tegra: sor: Demidlayer

Implement encoder and connector within the eDP driver itself using the
Tegra output helpers rather than using the Tegra output as midlayer. By
doing so one level of indirection is removed and output drivers become
more flexible while keeping the majority of the advantages provided by
the common output helpers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
iommu/tegra: Correctly keep track of usage count

The address space usage count needs to be incremented every time a
device is attached to a domain, otherwise the device detachment code
will prematurely free the address space.

Signed-off-by: Thierry Reding <treding@nvidia.com>