2018-07-26 10:37:32 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
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)
|
|
|
|
*/
|
|
|
|
|
2013-06-17 19:48:27 +08:00
|
|
|
#include <linux/export.h>
|
2020-12-03 21:09:22 +08:00
|
|
|
#include <linux/slab.h>
|
2013-06-17 19:48:27 +08:00
|
|
|
|
2019-08-26 23:26:29 +08:00
|
|
|
#include <drm/drm_bridge.h>
|
2020-05-25 11:18:01 +08:00
|
|
|
#include <drm/drm_bridge_connector.h>
|
2013-06-19 19:54:11 +08:00
|
|
|
#include <drm/drm_crtc.h>
|
2020-12-03 21:09:22 +08:00
|
|
|
#include <drm/drm_managed.h>
|
2019-01-18 05:03:34 +08:00
|
|
|
#include <drm/drm_modeset_helper_vtables.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"
|
2019-03-05 06:10:28 +08:00
|
|
|
#include "rcar_lvds.h"
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2013-06-15 21:02:12 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Encoder
|
|
|
|
*/
|
|
|
|
|
2019-03-03 00:13:04 +08:00
|
|
|
static unsigned int rcar_du_encoder_count_ports(struct device_node *node)
|
|
|
|
{
|
|
|
|
struct device_node *ports;
|
|
|
|
struct device_node *port;
|
|
|
|
unsigned int num_ports = 0;
|
|
|
|
|
|
|
|
ports = of_get_child_by_name(node, "ports");
|
|
|
|
if (!ports)
|
|
|
|
ports = of_node_get(node);
|
|
|
|
|
|
|
|
for_each_child_of_node(ports, port) {
|
|
|
|
if (of_node_name_eq(port, "port"))
|
|
|
|
num_ports++;
|
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(ports);
|
|
|
|
|
|
|
|
return num_ports;
|
|
|
|
}
|
|
|
|
|
2020-12-03 21:09:22 +08:00
|
|
|
static const struct drm_encoder_funcs rcar_du_encoder_funcs = {
|
|
|
|
};
|
|
|
|
|
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,
|
2019-01-17 06:40:49 +08:00
|
|
|
struct device_node *enc_node)
|
2013-06-19 19:54:11 +08:00
|
|
|
{
|
|
|
|
struct rcar_du_encoder *renc;
|
2020-05-25 11:18:01 +08:00
|
|
|
struct drm_connector *connector;
|
2019-03-03 00:13:04 +08:00
|
|
|
struct drm_bridge *bridge;
|
2020-05-25 11:18:01 +08:00
|
|
|
int ret;
|
2013-06-19 19:54:11 +08:00
|
|
|
|
2019-03-03 00:13:04 +08:00
|
|
|
/*
|
|
|
|
* Locate the DRM bridge from the DT node. For the DPAD outputs, if the
|
|
|
|
* DT node has a single port, assume that it describes a panel and
|
|
|
|
* create a panel bridge.
|
|
|
|
*/
|
|
|
|
if ((output == RCAR_DU_OUTPUT_DPAD0 ||
|
|
|
|
output == RCAR_DU_OUTPUT_DPAD1) &&
|
|
|
|
rcar_du_encoder_count_ports(enc_node) == 1) {
|
|
|
|
struct drm_panel *panel = of_drm_find_panel(enc_node);
|
|
|
|
|
2020-12-04 00:21:55 +08:00
|
|
|
if (IS_ERR(panel))
|
|
|
|
return PTR_ERR(panel);
|
2019-03-03 00:13:04 +08:00
|
|
|
|
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 21:28:04 +08:00
|
|
|
bridge = devm_drm_panel_bridge_add_typed(rcdu->dev, panel,
|
|
|
|
DRM_MODE_CONNECTOR_DPI);
|
2020-12-04 00:21:55 +08:00
|
|
|
if (IS_ERR(bridge))
|
|
|
|
return PTR_ERR(bridge);
|
2019-03-03 00:13:04 +08:00
|
|
|
} else {
|
|
|
|
bridge = of_drm_find_bridge(enc_node);
|
2020-12-04 00:21:55 +08:00
|
|
|
if (!bridge)
|
|
|
|
return -EPROBE_DEFER;
|
2020-12-04 19:43:58 +08:00
|
|
|
|
|
|
|
if (output == RCAR_DU_OUTPUT_LVDS0 ||
|
|
|
|
output == RCAR_DU_OUTPUT_LVDS1)
|
|
|
|
rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] = bridge;
|
2013-06-17 09:13:11 +08:00
|
|
|
}
|
|
|
|
|
2019-03-05 06:10:28 +08:00
|
|
|
/*
|
2020-12-04 00:21:55 +08:00
|
|
|
* Create and initialize the encoder. On Gen3 skip the LVDS1 output if
|
|
|
|
* the LVDS1 encoder is used as a companion for LVDS0 in dual-link
|
|
|
|
* mode.
|
2019-03-05 06:10:28 +08:00
|
|
|
*/
|
|
|
|
if (rcdu->info->gen >= 3 && output == RCAR_DU_OUTPUT_LVDS1) {
|
2020-12-04 00:21:55 +08:00
|
|
|
if (rcar_lvds_dual_link(bridge))
|
|
|
|
return -ENOLINK;
|
2019-03-05 06:10:28 +08:00
|
|
|
}
|
|
|
|
|
2020-12-04 00:21:55 +08:00
|
|
|
dev_dbg(rcdu->dev, "initializing encoder %pOF for output %u\n",
|
|
|
|
enc_node, output);
|
|
|
|
|
2021-01-14 01:02:53 +08:00
|
|
|
renc = drmm_encoder_alloc(&rcdu->ddev, struct rcar_du_encoder, base,
|
|
|
|
&rcar_du_encoder_funcs, DRM_MODE_ENCODER_NONE,
|
|
|
|
NULL);
|
|
|
|
if (!renc)
|
|
|
|
return -ENOMEM;
|
2020-12-03 21:09:22 +08:00
|
|
|
|
2021-01-14 01:02:53 +08:00
|
|
|
renc->output = output;
|
2013-06-15 21:02:12 +08:00
|
|
|
|
2020-05-25 11:18:01 +08:00
|
|
|
/* Attach the bridge to the encoder. */
|
|
|
|
ret = drm_bridge_attach(&renc->base, bridge, NULL,
|
|
|
|
DRM_BRIDGE_ATTACH_NO_CONNECTOR);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(rcdu->dev, "failed to attach bridge for output %u\n",
|
|
|
|
output);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the connector for the chain of bridges. */
|
|
|
|
connector = drm_bridge_connector_init(&rcdu->ddev, &renc->base);
|
|
|
|
if (IS_ERR(connector)) {
|
|
|
|
dev_err(rcdu->dev,
|
|
|
|
"failed to created connector for output %u\n", output);
|
|
|
|
return PTR_ERR(connector);
|
|
|
|
}
|
|
|
|
|
|
|
|
return drm_connector_attach_encoder(connector, &renc->base);
|
2013-06-19 19:54:11 +08:00
|
|
|
}
|