2015-10-29 15:36:23 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Free Electrons
|
|
|
|
* Copyright (C) 2015 NextThing Co
|
|
|
|
*
|
|
|
|
* Maxime Ripard <maxime.ripard@free-electrons.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
|
|
|
#include <drm/drm_crtc.h>
|
|
|
|
#include <drm/drm_modes.h>
|
2019-01-18 04:03:34 +07:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2015-10-29 15:36:23 +07:00
|
|
|
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/of_address.h>
|
2017-02-23 15:05:34 +07:00
|
|
|
#include <linux/of_graph.h>
|
2015-10-29 15:36:23 +07:00
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
|
|
|
|
#include <video/videomode.h>
|
|
|
|
|
2018-01-22 16:25:23 +07:00
|
|
|
#include "sun4i_backend.h"
|
2015-10-29 15:36:23 +07:00
|
|
|
#include "sun4i_crtc.h"
|
|
|
|
#include "sun4i_drv.h"
|
2017-05-17 21:47:17 +07:00
|
|
|
#include "sunxi_engine.h"
|
2015-10-29 15:36:23 +07:00
|
|
|
#include "sun4i_tcon.h"
|
|
|
|
|
drm/sun4i: tcon: Don't rely on encoders to enable the TCON
So far, we've required all the TCON-connected encoders to call the TCON
enable and disable functions.
This was made this way because in the RGB/LVDS case, the TCON is the CRTC
and the encoder. However, in all the other cases (HDMI, TV, DSI, etc.), we
have another encoder down the road that needs to be programmed.
We also needed to know which channel the encoder is connected to, which is
encoder-specific.
The CRTC's enable and disable callbacks can work just fine for our use
case, and we can get the channel to use just by looking at the type of
encoder, since that is fixed. Implement those callbacks, which will
remove some of the encoder boilerplate.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Link: https://patchwork.freedesktop.org/patch/msgid/90b4396e19b3eca61b2ebfdae0672074b88ad74d.1508231063.git-series.maxime.ripard@free-electrons.com
2017-10-17 16:06:12 +07:00
|
|
|
/*
|
|
|
|
* While this isn't really working in the DRM theory, in practice we
|
|
|
|
* can only ever have one encoder per TCON since we have a mux in our
|
|
|
|
* TCON.
|
|
|
|
*/
|
|
|
|
static struct drm_encoder *sun4i_crtc_get_encoder(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct drm_encoder *encoder;
|
|
|
|
|
|
|
|
drm_for_each_encoder(encoder, crtc->dev)
|
|
|
|
if (encoder->crtc == crtc)
|
|
|
|
return encoder;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-01-22 16:25:19 +07:00
|
|
|
static int sun4i_crtc_atomic_check(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state)
|
|
|
|
{
|
|
|
|
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
|
|
|
|
struct sunxi_engine *engine = scrtc->engine;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (engine && engine->ops && engine->ops->atomic_check)
|
|
|
|
ret = engine->ops->atomic_check(engine, state);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-29 15:36:23 +07:00
|
|
|
static void sun4i_crtc_atomic_begin(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *old_state)
|
|
|
|
{
|
|
|
|
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
|
|
|
|
struct drm_device *dev = crtc->dev;
|
2018-01-22 16:25:21 +07:00
|
|
|
struct sunxi_engine *engine = scrtc->engine;
|
2015-10-29 15:36:23 +07:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (crtc->state->event) {
|
|
|
|
WARN_ON(drm_crtc_vblank_get(crtc) != 0);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->event_lock, flags);
|
|
|
|
scrtc->event = crtc->state->event;
|
|
|
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
|
|
|
crtc->state->event = NULL;
|
2018-01-22 16:25:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (engine->ops->atomic_begin)
|
|
|
|
engine->ops->atomic_begin(engine, old_state);
|
2015-10-29 15:36:23 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-06-08 19:18:58 +07:00
|
|
|
struct drm_pending_vblank_event *event = crtc->state->event;
|
2015-10-29 15:36:23 +07:00
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("Committing plane changes\n");
|
|
|
|
|
2017-05-17 21:47:17 +07:00
|
|
|
sunxi_engine_commit(scrtc->engine);
|
2016-06-08 19:18:58 +07:00
|
|
|
|
|
|
|
if (event) {
|
|
|
|
crtc->state->event = NULL;
|
|
|
|
|
|
|
|
spin_lock_irq(&crtc->dev->event_lock);
|
|
|
|
if (drm_crtc_vblank_get(crtc) == 0)
|
|
|
|
drm_crtc_arm_vblank_event(crtc, event);
|
|
|
|
else
|
|
|
|
drm_crtc_send_vblank_event(crtc, event);
|
|
|
|
spin_unlock_irq(&crtc->dev->event_lock);
|
|
|
|
}
|
2015-10-29 15:36:23 +07:00
|
|
|
}
|
|
|
|
|
2017-06-30 16:36:45 +07:00
|
|
|
static void sun4i_crtc_atomic_disable(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *old_state)
|
2015-10-29 15:36:23 +07:00
|
|
|
{
|
drm/sun4i: tcon: Don't rely on encoders to enable the TCON
So far, we've required all the TCON-connected encoders to call the TCON
enable and disable functions.
This was made this way because in the RGB/LVDS case, the TCON is the CRTC
and the encoder. However, in all the other cases (HDMI, TV, DSI, etc.), we
have another encoder down the road that needs to be programmed.
We also needed to know which channel the encoder is connected to, which is
encoder-specific.
The CRTC's enable and disable callbacks can work just fine for our use
case, and we can get the channel to use just by looking at the type of
encoder, since that is fixed. Implement those callbacks, which will
remove some of the encoder boilerplate.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Link: https://patchwork.freedesktop.org/patch/msgid/90b4396e19b3eca61b2ebfdae0672074b88ad74d.1508231063.git-series.maxime.ripard@free-electrons.com
2017-10-17 16:06:12 +07:00
|
|
|
struct drm_encoder *encoder = sun4i_crtc_get_encoder(crtc);
|
2015-10-29 15:36:23 +07:00
|
|
|
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
|
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("Disabling the CRTC\n");
|
|
|
|
|
2018-02-21 19:57:03 +07:00
|
|
|
drm_crtc_vblank_off(crtc);
|
|
|
|
|
drm/sun4i: tcon: Don't rely on encoders to enable the TCON
So far, we've required all the TCON-connected encoders to call the TCON
enable and disable functions.
This was made this way because in the RGB/LVDS case, the TCON is the CRTC
and the encoder. However, in all the other cases (HDMI, TV, DSI, etc.), we
have another encoder down the road that needs to be programmed.
We also needed to know which channel the encoder is connected to, which is
encoder-specific.
The CRTC's enable and disable callbacks can work just fine for our use
case, and we can get the channel to use just by looking at the type of
encoder, since that is fixed. Implement those callbacks, which will
remove some of the encoder boilerplate.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Link: https://patchwork.freedesktop.org/patch/msgid/90b4396e19b3eca61b2ebfdae0672074b88ad74d.1508231063.git-series.maxime.ripard@free-electrons.com
2017-10-17 16:06:12 +07:00
|
|
|
sun4i_tcon_set_status(scrtc->tcon, encoder, false);
|
2016-06-20 17:20:59 +07:00
|
|
|
|
|
|
|
if (crtc->state->event && !crtc->state->active) {
|
|
|
|
spin_lock_irq(&crtc->dev->event_lock);
|
|
|
|
drm_crtc_send_vblank_event(crtc, crtc->state->event);
|
|
|
|
spin_unlock_irq(&crtc->dev->event_lock);
|
|
|
|
|
|
|
|
crtc->state->event = NULL;
|
|
|
|
}
|
2015-10-29 15:36:23 +07:00
|
|
|
}
|
|
|
|
|
2017-06-30 16:36:44 +07:00
|
|
|
static void sun4i_crtc_atomic_enable(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *old_state)
|
2015-10-29 15:36:23 +07:00
|
|
|
{
|
drm/sun4i: tcon: Don't rely on encoders to enable the TCON
So far, we've required all the TCON-connected encoders to call the TCON
enable and disable functions.
This was made this way because in the RGB/LVDS case, the TCON is the CRTC
and the encoder. However, in all the other cases (HDMI, TV, DSI, etc.), we
have another encoder down the road that needs to be programmed.
We also needed to know which channel the encoder is connected to, which is
encoder-specific.
The CRTC's enable and disable callbacks can work just fine for our use
case, and we can get the channel to use just by looking at the type of
encoder, since that is fixed. Implement those callbacks, which will
remove some of the encoder boilerplate.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Link: https://patchwork.freedesktop.org/patch/msgid/90b4396e19b3eca61b2ebfdae0672074b88ad74d.1508231063.git-series.maxime.ripard@free-electrons.com
2017-10-17 16:06:12 +07:00
|
|
|
struct drm_encoder *encoder = sun4i_crtc_get_encoder(crtc);
|
2015-10-29 15:36:23 +07:00
|
|
|
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
|
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("Enabling the CRTC\n");
|
|
|
|
|
drm/sun4i: tcon: Don't rely on encoders to enable the TCON
So far, we've required all the TCON-connected encoders to call the TCON
enable and disable functions.
This was made this way because in the RGB/LVDS case, the TCON is the CRTC
and the encoder. However, in all the other cases (HDMI, TV, DSI, etc.), we
have another encoder down the road that needs to be programmed.
We also needed to know which channel the encoder is connected to, which is
encoder-specific.
The CRTC's enable and disable callbacks can work just fine for our use
case, and we can get the channel to use just by looking at the type of
encoder, since that is fixed. Implement those callbacks, which will
remove some of the encoder boilerplate.
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Link: https://patchwork.freedesktop.org/patch/msgid/90b4396e19b3eca61b2ebfdae0672074b88ad74d.1508231063.git-series.maxime.ripard@free-electrons.com
2017-10-17 16:06:12 +07:00
|
|
|
sun4i_tcon_set_status(scrtc->tcon, encoder, true);
|
2018-02-21 19:57:03 +07:00
|
|
|
|
|
|
|
drm_crtc_vblank_on(crtc);
|
2015-10-29 15:36:23 +07:00
|
|
|
}
|
|
|
|
|
2017-10-17 16:06:13 +07:00
|
|
|
static void sun4i_crtc_mode_set_nofb(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct drm_display_mode *mode = &crtc->state->adjusted_mode;
|
|
|
|
struct drm_encoder *encoder = sun4i_crtc_get_encoder(crtc);
|
|
|
|
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
|
|
|
|
|
|
|
|
sun4i_tcon_mode_set(scrtc->tcon, encoder, mode);
|
|
|
|
}
|
|
|
|
|
2015-10-29 15:36:23 +07:00
|
|
|
static const struct drm_crtc_helper_funcs sun4i_crtc_helper_funcs = {
|
2018-01-22 16:25:19 +07:00
|
|
|
.atomic_check = sun4i_crtc_atomic_check,
|
2015-10-29 15:36:23 +07:00
|
|
|
.atomic_begin = sun4i_crtc_atomic_begin,
|
|
|
|
.atomic_flush = sun4i_crtc_atomic_flush,
|
2017-06-30 16:36:44 +07:00
|
|
|
.atomic_enable = sun4i_crtc_atomic_enable,
|
2017-06-30 16:36:45 +07:00
|
|
|
.atomic_disable = sun4i_crtc_atomic_disable,
|
2017-10-17 16:06:13 +07:00
|
|
|
.mode_set_nofb = sun4i_crtc_mode_set_nofb,
|
2015-10-29 15:36:23 +07:00
|
|
|
};
|
|
|
|
|
2017-02-07 16:16:31 +07:00
|
|
|
static int sun4i_crtc_enable_vblank(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
|
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("Enabling VBLANK on crtc %p\n", crtc);
|
|
|
|
|
2017-02-23 15:05:43 +07:00
|
|
|
sun4i_tcon_enable_vblank(scrtc->tcon, true);
|
2017-02-07 16:16:31 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sun4i_crtc_disable_vblank(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
|
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("Disabling VBLANK on crtc %p\n", crtc);
|
|
|
|
|
2017-02-23 15:05:43 +07:00
|
|
|
sun4i_tcon_enable_vblank(scrtc->tcon, false);
|
2017-02-07 16:16:31 +07:00
|
|
|
}
|
|
|
|
|
2015-10-29 15:36:23 +07:00
|
|
|
static const struct drm_crtc_funcs sun4i_crtc_funcs = {
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
|
|
|
|
.destroy = drm_crtc_cleanup,
|
|
|
|
.page_flip = drm_atomic_helper_page_flip,
|
|
|
|
.reset = drm_atomic_helper_crtc_reset,
|
|
|
|
.set_config = drm_atomic_helper_set_config,
|
2017-02-07 16:16:31 +07:00
|
|
|
.enable_vblank = sun4i_crtc_enable_vblank,
|
|
|
|
.disable_vblank = sun4i_crtc_disable_vblank,
|
2015-10-29 15:36:23 +07:00
|
|
|
};
|
|
|
|
|
2017-03-09 17:05:28 +07:00
|
|
|
struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm,
|
2017-05-17 21:47:17 +07:00
|
|
|
struct sunxi_engine *engine,
|
2017-03-09 17:05:28 +07:00
|
|
|
struct sun4i_tcon *tcon)
|
2015-10-29 15:36:23 +07:00
|
|
|
{
|
|
|
|
struct sun4i_crtc *scrtc;
|
2017-05-14 23:30:36 +07:00
|
|
|
struct drm_plane **planes;
|
2017-02-23 15:05:38 +07:00
|
|
|
struct drm_plane *primary = NULL, *cursor = NULL;
|
|
|
|
int ret, i;
|
2015-10-29 15:36:23 +07:00
|
|
|
|
|
|
|
scrtc = devm_kzalloc(drm->dev, sizeof(*scrtc), GFP_KERNEL);
|
|
|
|
if (!scrtc)
|
2017-02-17 10:13:30 +07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2017-05-17 21:47:17 +07:00
|
|
|
scrtc->engine = engine;
|
2017-03-09 17:05:28 +07:00
|
|
|
scrtc->tcon = tcon;
|
2015-10-29 15:36:23 +07:00
|
|
|
|
2017-02-23 15:05:36 +07:00
|
|
|
/* Create our layers */
|
2017-05-17 21:47:17 +07:00
|
|
|
planes = sunxi_engine_layers_init(drm, engine);
|
2017-05-14 23:30:36 +07:00
|
|
|
if (IS_ERR(planes)) {
|
2017-02-23 15:05:36 +07:00
|
|
|
dev_err(drm->dev, "Couldn't create the planes\n");
|
2017-02-23 15:05:38 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find primary and cursor planes for drm_crtc_init_with_planes */
|
2017-05-14 23:30:36 +07:00
|
|
|
for (i = 0; planes[i]; i++) {
|
|
|
|
struct drm_plane *plane = planes[i];
|
2017-02-23 15:05:38 +07:00
|
|
|
|
2017-05-14 23:30:36 +07:00
|
|
|
switch (plane->type) {
|
2017-02-23 15:05:38 +07:00
|
|
|
case DRM_PLANE_TYPE_PRIMARY:
|
2017-05-14 23:30:36 +07:00
|
|
|
primary = plane;
|
2017-02-23 15:05:38 +07:00
|
|
|
break;
|
|
|
|
case DRM_PLANE_TYPE_CURSOR:
|
2017-05-14 23:30:36 +07:00
|
|
|
cursor = plane;
|
2017-02-23 15:05:38 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-02-23 15:05:36 +07:00
|
|
|
}
|
|
|
|
|
2015-10-29 15:36:23 +07:00
|
|
|
ret = drm_crtc_init_with_planes(drm, &scrtc->crtc,
|
2017-02-23 15:05:38 +07:00
|
|
|
primary,
|
|
|
|
cursor,
|
2015-10-29 15:36:23 +07:00
|
|
|
&sun4i_crtc_funcs,
|
|
|
|
NULL);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(drm->dev, "Couldn't init DRM CRTC\n");
|
2017-02-17 10:13:30 +07:00
|
|
|
return ERR_PTR(ret);
|
2015-10-29 15:36:23 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
drm_crtc_helper_add(&scrtc->crtc, &sun4i_crtc_helper_funcs);
|
|
|
|
|
2017-02-23 15:05:34 +07:00
|
|
|
/* Set crtc.port to output port node of the tcon */
|
2017-03-09 17:05:26 +07:00
|
|
|
scrtc->crtc.port = of_graph_get_port_by_id(scrtc->tcon->dev->of_node,
|
2017-02-23 15:05:34 +07:00
|
|
|
1);
|
|
|
|
|
2017-02-23 15:05:39 +07:00
|
|
|
/* Set possible_crtcs to this crtc for overlay planes */
|
2017-05-14 23:30:36 +07:00
|
|
|
for (i = 0; planes[i]; i++) {
|
2018-06-27 02:47:14 +07:00
|
|
|
uint32_t possible_crtcs = drm_crtc_mask(&scrtc->crtc);
|
2017-05-14 23:30:36 +07:00
|
|
|
struct drm_plane *plane = planes[i];
|
2017-02-23 15:05:39 +07:00
|
|
|
|
2017-05-14 23:30:36 +07:00
|
|
|
if (plane->type == DRM_PLANE_TYPE_OVERLAY)
|
|
|
|
plane->possible_crtcs = possible_crtcs;
|
2017-02-23 15:05:39 +07:00
|
|
|
}
|
|
|
|
|
2015-10-29 15:36:23 +07:00
|
|
|
return scrtc;
|
|
|
|
}
|