2013-06-19 19:54:11 +08:00
|
|
|
/*
|
2013-06-15 21:02:12 +08:00
|
|
|
* rcar_du_encoder.c -- R-Car Display Unit Encoder
|
2013-06-19 19:54:11 +08:00
|
|
|
*
|
2014-02-07 01:13:52 +08:00
|
|
|
* Copyright (C) 2013-2014 Renesas Electronics Corporation
|
2013-06-19 19:54:11 +08:00
|
|
|
*
|
|
|
|
* Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.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.
|
|
|
|
*/
|
|
|
|
|
2013-06-17 19:48:27 +08:00
|
|
|
#include <linux/export.h>
|
|
|
|
|
2013-06-19 19:54:11 +08:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_crtc.h>
|
|
|
|
#include <drm/drm_crtc_helper.h>
|
2016-11-18 09:22:37 +08:00
|
|
|
#include <drm/drm_panel.h>
|
2013-06-19 19:54:11 +08:00
|
|
|
|
|
|
|
#include "rcar_du_drv.h"
|
2013-06-15 21:02:12 +08:00
|
|
|
#include "rcar_du_encoder.h"
|
2013-06-19 19:54:11 +08:00
|
|
|
#include "rcar_du_kms.h"
|
2013-06-15 20:21:51 +08:00
|
|
|
#include "rcar_du_lvdscon.h"
|
2013-06-17 19:48:27 +08:00
|
|
|
#include "rcar_du_lvdsenc.h"
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2013-06-15 21:02:12 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Encoder
|
|
|
|
*/
|
|
|
|
|
2015-02-20 20:05:21 +08:00
|
|
|
static void rcar_du_encoder_disable(struct drm_encoder *encoder)
|
2013-06-15 21:02:12 +08:00
|
|
|
{
|
2013-06-17 19:48:27 +08:00
|
|
|
struct rcar_du_encoder *renc = to_rcar_encoder(encoder);
|
|
|
|
|
2016-11-18 09:22:37 +08:00
|
|
|
if (renc->connector && renc->connector->panel) {
|
|
|
|
drm_panel_disable(renc->connector->panel);
|
|
|
|
drm_panel_unprepare(renc->connector->panel);
|
|
|
|
}
|
|
|
|
|
2013-06-17 19:48:27 +08:00
|
|
|
if (renc->lvds)
|
2015-02-20 20:05:21 +08:00
|
|
|
rcar_du_lvdsenc_enable(renc->lvds, encoder->crtc, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rcar_du_encoder_enable(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct rcar_du_encoder *renc = to_rcar_encoder(encoder);
|
|
|
|
|
|
|
|
if (renc->lvds)
|
|
|
|
rcar_du_lvdsenc_enable(renc->lvds, encoder->crtc, true);
|
2016-11-18 09:22:37 +08:00
|
|
|
|
|
|
|
if (renc->connector && renc->connector->panel) {
|
|
|
|
drm_panel_prepare(renc->connector->panel);
|
|
|
|
drm_panel_enable(renc->connector->panel);
|
|
|
|
}
|
2015-02-20 20:05:21 +08:00
|
|
|
}
|
|
|
|
|
2015-02-23 03:02:39 +08:00
|
|
|
static int rcar_du_encoder_atomic_check(struct drm_encoder *encoder,
|
|
|
|
struct drm_crtc_state *crtc_state,
|
|
|
|
struct drm_connector_state *conn_state)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
2013-06-17 19:48:27 +08:00
|
|
|
struct rcar_du_encoder *renc = to_rcar_encoder(encoder);
|
2015-02-23 03:02:39 +08:00
|
|
|
struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
|
|
|
|
const struct drm_display_mode *mode = &crtc_state->mode;
|
|
|
|
struct drm_connector *connector = conn_state->connector;
|
2013-06-19 19:54:11 +08:00
|
|
|
struct drm_device *dev = encoder->dev;
|
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
/*
|
|
|
|
* Only panel-related encoder types require validation here, everything
|
|
|
|
* else is handled by the bridge drivers.
|
|
|
|
*/
|
2016-10-07 22:39:21 +08:00
|
|
|
if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
|
2016-10-07 21:01:41 +08:00
|
|
|
const struct drm_display_mode *panel_mode;
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
if (list_empty(&connector->modes)) {
|
|
|
|
dev_dbg(dev->dev, "encoder: empty modes list\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
panel_mode = list_first_entry(&connector->modes,
|
|
|
|
struct drm_display_mode, head);
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
/* We're not allowed to modify the resolution. */
|
|
|
|
if (mode->hdisplay != panel_mode->hdisplay ||
|
|
|
|
mode->vdisplay != panel_mode->vdisplay)
|
|
|
|
return -EINVAL;
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
/*
|
|
|
|
* The flat panel mode is fixed, just copy it to the adjusted
|
|
|
|
* mode.
|
|
|
|
*/
|
|
|
|
drm_mode_copy(adjusted_mode, panel_mode);
|
|
|
|
}
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2013-06-17 19:48:27 +08:00
|
|
|
if (renc->lvds)
|
2015-09-07 20:44:44 +08:00
|
|
|
rcar_du_lvdsenc_atomic_check(renc->lvds, adjusted_mode);
|
2013-06-17 19:48:27 +08:00
|
|
|
|
2015-02-23 03:02:39 +08:00
|
|
|
return 0;
|
2013-06-19 19:54:11 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 21:02:12 +08:00
|
|
|
static void rcar_du_encoder_mode_set(struct drm_encoder *encoder,
|
2016-11-18 21:37:37 +08:00
|
|
|
struct drm_crtc_state *crtc_state,
|
|
|
|
struct drm_connector_state *conn_state)
|
2013-06-15 21:02:12 +08:00
|
|
|
{
|
|
|
|
struct rcar_du_encoder *renc = to_rcar_encoder(encoder);
|
2016-10-03 18:07:02 +08:00
|
|
|
struct drm_display_info *info = &conn_state->connector->display_info;
|
|
|
|
enum rcar_lvds_mode mode;
|
2013-06-15 21:02:12 +08:00
|
|
|
|
2016-11-18 21:37:37 +08:00
|
|
|
rcar_du_crtc_route_output(crtc_state->crtc, renc->output);
|
2016-11-18 09:22:37 +08:00
|
|
|
|
|
|
|
if (!renc->lvds) {
|
|
|
|
/*
|
|
|
|
* The DU driver creates connectors only for the outputs of the
|
|
|
|
* internal LVDS encoders.
|
|
|
|
*/
|
|
|
|
renc->connector = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
renc->connector = to_rcar_connector(conn_state->connector);
|
2016-10-03 18:07:02 +08:00
|
|
|
|
|
|
|
if (!info->num_bus_formats || !info->bus_formats) {
|
|
|
|
dev_err(encoder->dev->dev, "no LVDS bus format reported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info->bus_formats[0]) {
|
|
|
|
case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
|
|
|
|
case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:
|
|
|
|
mode = RCAR_LVDS_MODE_JEIDA;
|
|
|
|
break;
|
|
|
|
case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:
|
|
|
|
mode = RCAR_LVDS_MODE_VESA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(encoder->dev->dev,
|
|
|
|
"unsupported LVDS bus format 0x%04x\n",
|
|
|
|
info->bus_formats[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->bus_flags & DRM_BUS_FLAG_DATA_LSB_TO_MSB)
|
|
|
|
mode |= RCAR_LVDS_MODE_MIRROR;
|
|
|
|
|
|
|
|
rcar_du_lvdsenc_set_mode(renc->lvds, mode);
|
2013-06-15 21:02:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 19:54:11 +08:00
|
|
|
static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
|
2016-11-18 21:37:37 +08:00
|
|
|
.atomic_mode_set = rcar_du_encoder_mode_set,
|
2015-02-20 20:05:21 +08:00
|
|
|
.disable = rcar_du_encoder_disable,
|
|
|
|
.enable = rcar_du_encoder_enable,
|
2015-02-23 03:02:39 +08:00
|
|
|
.atomic_check = rcar_du_encoder_atomic_check,
|
2013-06-19 19:54:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_encoder_funcs encoder_funcs = {
|
|
|
|
.destroy = drm_encoder_cleanup,
|
|
|
|
};
|
|
|
|
|
2013-06-15 21:02:12 +08:00
|
|
|
int rcar_du_encoder_init(struct rcar_du_device *rcdu,
|
2013-06-17 09:13:11 +08:00
|
|
|
enum rcar_du_output output,
|
2014-09-17 19:41:57 +08:00
|
|
|
struct device_node *enc_node,
|
|
|
|
struct device_node *con_node)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
|
|
|
struct rcar_du_encoder *renc;
|
2014-03-31 07:50:16 +08:00
|
|
|
struct drm_encoder *encoder;
|
2016-10-07 21:01:41 +08:00
|
|
|
struct drm_bridge *bridge = NULL;
|
2013-06-19 19:54:11 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
renc = devm_kzalloc(rcdu->dev, sizeof(*renc), GFP_KERNEL);
|
|
|
|
if (renc == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
renc->output = output;
|
2014-03-31 07:50:16 +08:00
|
|
|
encoder = rcar_encoder_to_drm_encoder(renc);
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2013-06-17 19:48:27 +08:00
|
|
|
switch (output) {
|
|
|
|
case RCAR_DU_OUTPUT_LVDS0:
|
|
|
|
renc->lvds = rcdu->lvds[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RCAR_DU_OUTPUT_LVDS1:
|
|
|
|
renc->lvds = rcdu->lvds[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
if (enc_node) {
|
2016-10-07 22:39:21 +08:00
|
|
|
dev_dbg(rcdu->dev, "initializing encoder %s for output %u\n",
|
|
|
|
of_node_full_name(enc_node), output);
|
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
/* Locate the DRM bridge from the encoder DT node. */
|
|
|
|
bridge = of_drm_find_bridge(enc_node);
|
|
|
|
if (!bridge) {
|
|
|
|
ret = -EPROBE_DEFER;
|
|
|
|
goto done;
|
|
|
|
}
|
2016-10-07 22:39:21 +08:00
|
|
|
} else {
|
|
|
|
dev_dbg(rcdu->dev,
|
|
|
|
"initializing internal encoder for output %u\n",
|
|
|
|
output);
|
2013-06-17 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
ret = drm_encoder_init(rcdu->ddev, encoder, &encoder_funcs,
|
2016-10-07 22:39:21 +08:00
|
|
|
DRM_MODE_ENCODER_NONE, NULL);
|
2016-10-07 21:01:41 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
2013-06-15 21:02:12 +08:00
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
drm_encoder_helper_add(encoder, &encoder_helper_funcs);
|
2014-03-31 03:55:38 +08:00
|
|
|
|
2016-10-07 21:01:41 +08:00
|
|
|
if (bridge) {
|
|
|
|
/*
|
|
|
|
* Attach the bridge to the encoder. The bridge will create the
|
|
|
|
* connector.
|
|
|
|
*/
|
|
|
|
ret = drm_bridge_attach(encoder, bridge, NULL);
|
|
|
|
if (ret) {
|
|
|
|
drm_encoder_cleanup(encoder);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* There's no bridge, create the connector manually. */
|
|
|
|
switch (output) {
|
|
|
|
case RCAR_DU_OUTPUT_LVDS0:
|
|
|
|
case RCAR_DU_OUTPUT_LVDS1:
|
|
|
|
ret = rcar_du_lvds_connector_init(rcdu, renc, con_node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2013-06-15 21:02:12 +08:00
|
|
|
}
|
2014-12-11 07:26:04 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (ret < 0) {
|
|
|
|
if (encoder->name)
|
|
|
|
encoder->funcs->destroy(encoder);
|
|
|
|
devm_kfree(rcdu->dev, renc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-06-19 19:54:11 +08:00
|
|
|
}
|