Commit db474322 authored by Dave Airlie's avatar Dave Airlie

Merge branch 'drm-next-tilcdc-atomic' of https://github.com/jsarha/linux into drm-next

Please pull tilcdc atomic modeset support and some non critical fixes.

* 'drm-next-tilcdc-atomic' of https://github.com/jsarha/linux: (29 commits)
  drm/tilcdc: Change tilcdc_crtc_page_flip() to tilcdc_crtc_update_fb()
  drm/tilcdc: Remove unnecessary pm_runtime_get() and *_put() calls
  drm/tilcdc: Get rid of legacy dpms mechanism
  drm/tilcdc: Use drm_atomic_helper_resume/suspend()
  drm/tilcdc: Enable and disable interrupts in crtc start() and stop()
  drm/tilcdc: tfp410: Add atomic modeset helpers to connector funcs
  drm/tilcdc: tfp410: Set crtc panel info at init phase
  drm/tilcdc: panel: Add atomic modeset helpers to connector funcs
  drm/tilcdc: panel: Set crtc panel info at init phase
  drm/tilcdc: Remove tilcdc_verify_fb()
  drm/tilcdc: Remove obsolete crtc helper functions
  drm/tilcdc: Set DRIVER_ATOMIC and use atomic crtc helpers
  drm/tilcdc: Add drm_mode_config_reset() call to tilcdc_load()
  drm/tilcdc: Add atomic mode config funcs
  drm/tilcdc: Add tilcdc_crtc_atomic_check()
  drm/tilcdc: Add tilcdc_crtc_mode_set_nofb()
  drm/tilcdc: Initialize dummy primary plane from crtc init
  drm/tilcdc: Add dummy primary plane implementation
  drm/tilcdc: Make tilcdc_crtc_page_flip() work if crtc is not yet on
  drm/tilcdc: Make tilcdc_crtc_page_flip() public
  ...
parents 694d0d0b e0e344e6
......@@ -24,6 +24,10 @@ Optional nodes:
binding follows Documentation/devicetree/bindings/graph.txt and
suppors a single port with a single endpoint.
- See also Documentation/devicetree/bindings/display/tilcdc/panel.txt and
Documentation/devicetree/bindings/display/tilcdc/tfp410.txt for connecting
tfp410 DVI encoder or lcd panel to lcdc
Example:
fb: fb@4830e000 {
......
......@@ -7,6 +7,7 @@ obj-$(CONFIG_DRM_TILCDC_SLAVE_COMPAT) += tilcdc_slave_compat.o \
tilcdc_slave_compat.dtb.o
tilcdc-y := \
tilcdc_plane.o \
tilcdc_crtc.o \
tilcdc_tfp410.o \
tilcdc_panel.o \
......
This diff is collapsed.
......@@ -20,6 +20,8 @@
#include <linux/component.h>
#include <linux/pinctrl/consumer.h>
#include <linux/suspend.h>
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include "tilcdc_drv.h"
#include "tilcdc_regs.h"
......@@ -59,9 +61,84 @@ static void tilcdc_fb_output_poll_changed(struct drm_device *dev)
drm_fbdev_cma_hotplug_event(priv->fbdev);
}
int tilcdc_atomic_check(struct drm_device *dev,
struct drm_atomic_state *state)
{
int ret;
ret = drm_atomic_helper_check_modeset(dev, state);
if (ret)
return ret;
ret = drm_atomic_helper_check_planes(dev, state);
if (ret)
return ret;
/*
* tilcdc ->atomic_check can update ->mode_changed if pixel format
* changes, hence will we check modeset changes again.
*/
ret = drm_atomic_helper_check_modeset(dev, state);
if (ret)
return ret;
return ret;
}
static int tilcdc_commit(struct drm_device *dev,
struct drm_atomic_state *state,
bool async)
{
int ret;
ret = drm_atomic_helper_prepare_planes(dev, state);
if (ret)
return ret;
drm_atomic_helper_swap_state(state, true);
/*
* Everything below can be run asynchronously without the need to grab
* any modeset locks at all under one condition: It must be guaranteed
* that the asynchronous work has either been cancelled (if the driver
* supports it, which at least requires that the framebuffers get
* cleaned up with drm_atomic_helper_cleanup_planes()) or completed
* before the new state gets committed on the software side with
* drm_atomic_helper_swap_state().
*
* This scheme allows new atomic state updates to be prepared and
* checked in parallel to the asynchronous completion of the previous
* update. Which is important since compositors need to figure out the
* composition of the next frame right after having submitted the
* current layout.
*/
/* Keep HW on while we commit the state. */
pm_runtime_get_sync(dev->dev);
drm_atomic_helper_commit_modeset_disables(dev, state);
drm_atomic_helper_commit_planes(dev, state, false);
drm_atomic_helper_commit_modeset_enables(dev, state);
/* Now HW should remain on if need becase the crtc is enabled */
pm_runtime_put_sync(dev->dev);
drm_atomic_helper_wait_for_vblanks(dev, state);
drm_atomic_helper_cleanup_planes(dev, state);
drm_atomic_state_free(state);
return 0;
}
static const struct drm_mode_config_funcs mode_config_funcs = {
.fb_create = tilcdc_fb_create,
.output_poll_changed = tilcdc_fb_output_poll_changed,
.atomic_check = tilcdc_atomic_check,
.atomic_commit = tilcdc_commit,
};
static int modeset_init(struct drm_device *dev)
......@@ -112,7 +189,7 @@ static int tilcdc_unload(struct drm_device *dev)
{
struct tilcdc_drm_private *priv = dev->dev_private;
tilcdc_crtc_dpms(priv->crtc, DRM_MODE_DPMS_OFF);
tilcdc_crtc_disable(priv->crtc);
tilcdc_remove_external_encoders(dev);
......@@ -121,9 +198,7 @@ static int tilcdc_unload(struct drm_device *dev)
drm_mode_config_cleanup(dev);
drm_vblank_cleanup(dev);
pm_runtime_get_sync(dev->dev);
drm_irq_uninstall(dev);
pm_runtime_put_sync(dev->dev);
#ifdef CONFIG_CPU_FREQ
cpufreq_unregister_notifier(&priv->freq_transition,
......@@ -146,8 +221,6 @@ static int tilcdc_unload(struct drm_device *dev)
return 0;
}
static size_t tilcdc_num_regs(void);
static int tilcdc_load(struct drm_device *dev, unsigned long flags)
{
struct platform_device *pdev = dev->platformdev;
......@@ -159,11 +232,7 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
int ret;
priv = devm_kzalloc(dev->dev, sizeof(*priv), GFP_KERNEL);
if (priv)
priv->saved_register =
devm_kcalloc(dev->dev, tilcdc_num_regs(),
sizeof(*priv->saved_register), GFP_KERNEL);
if (!priv || !priv->saved_register) {
if (!priv) {
dev_err(dev->dev, "failed to allocate private data\n");
return -ENOMEM;
}
......@@ -279,9 +348,7 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
goto fail_external_cleanup;
}
pm_runtime_get_sync(dev->dev);
ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0));
pm_runtime_put_sync(dev->dev);
if (ret < 0) {
dev_err(dev->dev, "failed to install IRQ handler\n");
goto fail_vblank_cleanup;
......@@ -295,6 +362,9 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
}
drm_helper_disable_unused_functions(dev);
drm_mode_config_reset(dev);
priv->fbdev = drm_fbdev_cma_init(dev, bpp,
dev->mode_config.num_crtc,
dev->mode_config.num_connector);
......@@ -308,9 +378,7 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
return 0;
fail_irq_uninstall:
pm_runtime_get_sync(dev->dev);
drm_irq_uninstall(dev);
pm_runtime_put_sync(dev->dev);
fail_vblank_cleanup:
drm_vblank_cleanup(dev);
......@@ -361,45 +429,6 @@ static irqreturn_t tilcdc_irq(int irq, void *arg)
return tilcdc_crtc_irq(priv->crtc);
}
static void tilcdc_irq_preinstall(struct drm_device *dev)
{
tilcdc_clear_irqstatus(dev, 0xffffffff);
}
static int tilcdc_irq_postinstall(struct drm_device *dev)
{
struct tilcdc_drm_private *priv = dev->dev_private;
/* enable FIFO underflow irq: */
if (priv->rev == 1) {
tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_V1_UNDERFLOW_INT_ENA);
} else {
tilcdc_write(dev, LCDC_INT_ENABLE_SET_REG,
LCDC_V2_UNDERFLOW_INT_ENA |
LCDC_V2_END_OF_FRAME0_INT_ENA |
LCDC_FRAME_DONE | LCDC_SYNC_LOST);
}
return 0;
}
static void tilcdc_irq_uninstall(struct drm_device *dev)
{
struct tilcdc_drm_private *priv = dev->dev_private;
/* disable irqs that we might have enabled: */
if (priv->rev == 1) {
tilcdc_clear(dev, LCDC_RASTER_CTRL_REG,
LCDC_V1_UNDERFLOW_INT_ENA | LCDC_V1_PL_INT_ENA);
tilcdc_clear(dev, LCDC_DMA_CTRL_REG, LCDC_V1_END_OF_FRAME_INT_ENA);
} else {
tilcdc_write(dev, LCDC_INT_ENABLE_CLR_REG,
LCDC_V2_UNDERFLOW_INT_ENA | LCDC_V2_PL_INT_ENA |
LCDC_V2_END_OF_FRAME0_INT_ENA |
LCDC_FRAME_DONE | LCDC_SYNC_LOST);
}
}
static int tilcdc_enable_vblank(struct drm_device *dev, unsigned int pipe)
{
return 0;
......@@ -410,7 +439,7 @@ static void tilcdc_disable_vblank(struct drm_device *dev, unsigned int pipe)
return;
}
#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_PM_SLEEP)
#if defined(CONFIG_DEBUG_FS)
static const struct {
const char *name;
uint8_t rev;
......@@ -441,15 +470,6 @@ static const struct {
#undef REG
};
static size_t tilcdc_num_regs(void)
{
return ARRAY_SIZE(registers);
}
#else
static size_t tilcdc_num_regs(void)
{
return 0;
}
#endif
#ifdef CONFIG_DEBUG_FS
......@@ -537,14 +557,11 @@ static const struct file_operations fops = {
static struct drm_driver tilcdc_driver = {
.driver_features = (DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET |
DRIVER_PRIME),
DRIVER_PRIME | DRIVER_ATOMIC),
.load = tilcdc_load,
.unload = tilcdc_unload,
.lastclose = tilcdc_lastclose,
.irq_handler = tilcdc_irq,
.irq_preinstall = tilcdc_irq_preinstall,
.irq_postinstall = tilcdc_irq_postinstall,
.irq_uninstall = tilcdc_irq_uninstall,
.get_vblank_counter = drm_vblank_no_hw_counter,
.enable_vblank = tilcdc_enable_vblank,
.disable_vblank = tilcdc_disable_vblank,
......@@ -584,28 +601,12 @@ static int tilcdc_pm_suspend(struct device *dev)
{
struct drm_device *ddev = dev_get_drvdata(dev);
struct tilcdc_drm_private *priv = ddev->dev_private;
unsigned i, n = 0;
drm_kms_helper_poll_disable(ddev);
priv->saved_state = drm_atomic_helper_suspend(ddev);
/* Select sleep pin state */
pinctrl_pm_select_sleep_state(dev);
if (pm_runtime_suspended(dev)) {
priv->ctx_valid = false;
return 0;
}
/* Disable the LCDC controller, to avoid locking up the PRCM */
tilcdc_crtc_dpms(priv->crtc, DRM_MODE_DPMS_OFF);
/* Save register state: */
for (i = 0; i < ARRAY_SIZE(registers); i++)
if (registers[i].save && (priv->rev >= registers[i].rev))
priv->saved_register[n++] = tilcdc_read(ddev, registers[i].reg);
priv->ctx_valid = true;
return 0;
}
......@@ -613,23 +614,15 @@ static int tilcdc_pm_resume(struct device *dev)
{
struct drm_device *ddev = dev_get_drvdata(dev);
struct tilcdc_drm_private *priv = ddev->dev_private;
unsigned i, n = 0;
int ret = 0;
/* Select default pin state */
pinctrl_pm_select_default_state(dev);
if (priv->ctx_valid == true) {
/* Restore register state: */
for (i = 0; i < ARRAY_SIZE(registers); i++)
if (registers[i].save &&
(priv->rev >= registers[i].rev))
tilcdc_write(ddev, registers[i].reg,
priv->saved_register[n++]);
}
drm_kms_helper_poll_enable(ddev);
if (priv->saved_state)
ret = drm_atomic_helper_resume(ddev, priv->saved_state);
return 0;
return ret;
}
#endif
......@@ -648,6 +641,12 @@ static int tilcdc_bind(struct device *dev)
static void tilcdc_unbind(struct device *dev)
{
struct drm_device *ddev = dev_get_drvdata(dev);
/* Check if a subcomponent has already triggered the unloading. */
if (!ddev->dev_private)
return;
drm_put_dev(dev_get_drvdata(dev));
}
......@@ -680,17 +679,15 @@ static int tilcdc_pdev_probe(struct platform_device *pdev)
static int tilcdc_pdev_remove(struct platform_device *pdev)
{
struct drm_device *ddev = dev_get_drvdata(&pdev->dev);
struct tilcdc_drm_private *priv = ddev->dev_private;
/* Check if a subcomponent has already triggered the unloading. */
if (!priv)
return 0;
int ret;
if (priv->is_componentized)
component_master_del(&pdev->dev, &tilcdc_comp_ops);
else
ret = tilcdc_get_external_components(&pdev->dev, NULL);
if (ret < 0)
return ret;
else if (ret == 0)
drm_put_dev(platform_get_drvdata(pdev));
else
component_master_del(&pdev->dev, &tilcdc_comp_ops);
return 0;
}
......
......@@ -65,9 +65,8 @@ struct tilcdc_drm_private {
*/
uint32_t max_width;
/* register contents saved across suspend/resume: */
u32 *saved_register;
bool ctx_valid;
/* The context for pm susped/resume cycle is stored here */
struct drm_atomic_state *saved_state;
#ifdef CONFIG_CPU_FREQ
struct notifier_block freq_transition;
......@@ -171,6 +170,11 @@ void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc,
bool simulate_vesa_sync);
int tilcdc_crtc_mode_valid(struct drm_crtc *crtc, struct drm_display_mode *mode);
int tilcdc_crtc_max_width(struct drm_crtc *crtc);
void tilcdc_crtc_dpms(struct drm_crtc *crtc, int mode);
void tilcdc_crtc_disable(struct drm_crtc *crtc);
int tilcdc_crtc_update_fb(struct drm_crtc *crtc,
struct drm_framebuffer *fb,
struct drm_pending_vblank_event *event);
int tilcdc_plane_init(struct drm_device *dev, struct drm_plane *plane);
#endif /* __TILCDC_DRV_H__ */
......@@ -138,12 +138,21 @@ static int dev_match_of(struct device *dev, void *data)
int tilcdc_get_external_components(struct device *dev,
struct component_match **match)
{
struct device_node *node;
struct device_node *ep = NULL;
int count = 0;
while ((ep = of_graph_get_next_endpoint(dev->of_node, ep))) {
struct device_node *node;
/* Avoid error print by of_graph_get_next_endpoint() if there
* is no ports present.
*/
node = of_get_child_by_name(dev->of_node, "ports");
if (!node)
node = of_get_child_by_name(dev->of_node, "port");
if (!node)
return 0;
of_node_put(node);
while ((ep = of_graph_get_next_endpoint(dev->of_node, ep))) {
node = of_graph_get_remote_port_parent(ep);
if (!node && !of_device_is_available(node)) {
of_node_put(node);
......
......@@ -22,6 +22,7 @@
#include <video/display_timing.h>
#include <video/of_display_timing.h>
#include <video/videomode.h>
#include <drm/drm_atomic_helper.h>
#include "tilcdc_drv.h"
......@@ -64,9 +65,7 @@ static void panel_encoder_dpms(struct drm_encoder *encoder, int mode)
static void panel_encoder_prepare(struct drm_encoder *encoder)
{
struct panel_encoder *panel_encoder = to_panel_encoder(encoder);
panel_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
tilcdc_crtc_set_panel_info(encoder->crtc, panel_encoder->mod->info);
}
static void panel_encoder_commit(struct drm_encoder *encoder)
......@@ -196,9 +195,12 @@ static struct drm_encoder *panel_connector_best_encoder(
static const struct drm_connector_funcs panel_connector_funcs = {
.destroy = panel_connector_destroy,
.dpms = drm_helper_connector_dpms,
.dpms = drm_atomic_helper_connector_dpms,
.detect = panel_connector_detect,
.fill_modes = drm_helper_probe_single_connector_modes,
.reset = drm_atomic_helper_connector_reset,
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
};
static const struct drm_connector_helper_funcs panel_connector_helper_funcs = {
......@@ -268,6 +270,9 @@ static int panel_modeset_init(struct tilcdc_module *mod, struct drm_device *dev)
priv->encoders[priv->num_encoders++] = encoder;
priv->connectors[priv->num_connectors++] = connector;
tilcdc_crtc_set_panel_info(priv->crtc,
to_panel_encoder(encoder)->mod->info);
return 0;
}
......
/*
* Copyright (C) 2015 Texas Instruments
* Author: Jyri Sarha <jsarha@ti.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <drm/drmP.h>
#include <drm/drm_atomic.h>
#include <drm/drm_plane_helper.h>
#include <drm/drm_atomic_helper.h>
#include <uapi/drm/drm_fourcc.h>
#include "tilcdc_drv.h"
static const u32 tilcdc_formats[] = { DRM_FORMAT_RGB565,
DRM_FORMAT_RGB888,
DRM_FORMAT_XRGB8888 };
static struct drm_plane_funcs tilcdc_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
.destroy = drm_plane_cleanup,
.set_property = drm_atomic_helper_plane_set_property,
.reset = drm_atomic_helper_plane_reset,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
};
static int tilcdc_plane_atomic_check(struct drm_plane *plane,
struct drm_plane_state *state)
{
struct drm_crtc_state *crtc_state;
struct drm_plane_state *old_state = plane->state;
unsigned int depth, bpp;
if (!state->crtc)
return 0;
if (WARN_ON(!state->fb))
return -EINVAL;
if (state->crtc_x || state->crtc_y) {
dev_err(plane->dev->dev, "%s: crtc position must be zero.",
__func__);
return -EINVAL;
}
crtc_state = drm_atomic_get_existing_crtc_state(state->state,
state->crtc);
/* we should have a crtc state if the plane is attached to a crtc */
if (WARN_ON(!crtc_state))
return 0;
if (crtc_state->mode.hdisplay != state->crtc_w ||
crtc_state->mode.vdisplay != state->crtc_h) {
dev_err(plane->dev->dev,
"%s: Size must match mode (%dx%d == %dx%d)", __func__,
crtc_state->mode.hdisplay, crtc_state->mode.vdisplay,
state->crtc_w, state->crtc_h);
return -EINVAL;
}
drm_fb_get_bpp_depth(state->fb->pixel_format, &depth, &bpp);
if (state->fb->pitches[0] != crtc_state->mode.hdisplay * bpp / 8) {
dev_err(plane->dev->dev,
"Invalid pitch: fb and crtc widths must be the same");
return -EINVAL;
}
if (state->fb && old_state->fb &&
state->fb->pixel_format != old_state->fb->pixel_format) {
dev_dbg(plane->dev->dev,
"%s(): pixel format change requires mode_change\n",
__func__);
crtc_state->mode_changed = true;
}
return 0;
}
static void tilcdc_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
{
struct drm_plane_state *state = plane->state;
if (!state->crtc)
return;
if (WARN_ON(!state->fb || !state->crtc->state))
return;
tilcdc_crtc_update_fb(state->crtc,
state->fb,
state->crtc->state->event);
}
static const struct drm_plane_helper_funcs plane_helper_funcs = {
.atomic_check = tilcdc_plane_atomic_check,
.atomic_update = tilcdc_plane_atomic_update,
};
int tilcdc_plane_init(struct drm_device *dev,
struct drm_plane *plane)
{
int ret;
ret = drm_plane_init(dev, plane, 1,
&tilcdc_plane_funcs,
tilcdc_formats,
ARRAY_SIZE(tilcdc_formats),
true);
if (ret) {
dev_err(dev->dev, "Failed to initialize plane: %d\n", ret);
return ret;
}
drm_plane_helper_add(plane, &plane_helper_funcs);
return 0;
}
......@@ -20,6 +20,7 @@
#include <linux/of_gpio.h>
#include <linux/pinctrl/pinmux.h>
#include <linux/pinctrl/consumer.h>
#include <drm/drm_atomic_helper.h>
#include "tilcdc_drv.h"
......@@ -75,7 +76,6 @@ static void tfp410_encoder_dpms(struct drm_encoder *encoder, int mode)
static void tfp410_encoder_prepare(struct drm_encoder *encoder)
{
tfp410_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
tilcdc_crtc_set_panel_info(encoder->crtc, &dvi_info);
}
static void tfp410_encoder_commit(struct drm_encoder *encoder)
......@@ -201,9 +201,12 @@ static struct drm_encoder *tfp410_connector_best_encoder(
static const struct drm_connector_funcs tfp410_connector_funcs = {
.destroy = tfp410_connector_destroy,
.dpms = drm_helper_connector_dpms,
.dpms = drm_atomic_helper_connector_dpms,
.detect = tfp410_connector_detect,
.fill_modes = drm_helper_probe_single_connector_modes,
.reset = drm_atomic_helper_connector_reset,
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
};
static const struct drm_connector_helper_funcs tfp410_connector_helper_funcs = {
......@@ -276,6 +279,7 @@ static int tfp410_modeset_init(struct tilcdc_module *mod, struct drm_device *dev
priv->encoders[priv->num_encoders++] = encoder;
priv->connectors[priv->num_connectors++] = connector;
tilcdc_crtc_set_panel_info(priv->crtc, &dvi_info);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment