2018-07-26 02:37:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-06-19 13:54:11 +02:00
|
|
|
/*
|
2022-04-24 23:44:35 +03:00
|
|
|
* R-Car Display Unit Encoder
|
2013-06-19 13:54:11 +02:00
|
|
|
*
|
2014-02-06 18:13:52 +01:00
|
|
|
* Copyright (C) 2013-2014 Renesas Electronics Corporation
|
2013-06-19 13:54:11 +02:00
|
|
|
*
|
|
|
|
* Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
|
|
|
|
*/
|
|
|
|
|
2013-06-17 13:48:27 +02:00
|
|
|
#include <linux/export.h>
|
2022-06-30 22:51:12 +03:00
|
|
|
#include <linux/of.h>
|
2013-06-17 13:48:27 +02:00
|
|
|
|
2019-08-26 17:26:29 +02:00
|
|
|
#include <drm/drm_bridge.h>
|
2020-05-25 06:18:01 +03:00
|
|
|
#include <drm/drm_bridge_connector.h>
|
2016-11-18 03:22:37 +02:00
|
|
|
#include <drm/drm_panel.h>
|
2013-06-19 13:54:11 +02:00
|
|
|
|
|
|
|
#include "rcar_du_drv.h"
|
2013-06-15 15:02:12 +02:00
|
|
|
#include "rcar_du_encoder.h"
|
2019-03-05 00:10:28 +02:00
|
|
|
#include "rcar_lvds.h"
|
2013-06-19 13:54:11 +02:00
|
|
|
|
2013-06-15 15:02:12 +02:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Encoder
|
|
|
|
*/
|
|
|
|
|
2019-03-02 18:13:04 +02: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 15:09:22 +02:00
|
|
|
static const struct drm_encoder_funcs rcar_du_encoder_funcs = {
|
|
|
|
};
|
|
|
|
|
2013-06-15 15:02:12 +02:00
|
|
|
int rcar_du_encoder_init(struct rcar_du_device *rcdu,
|
2013-06-17 03:13:11 +02:00
|
|
|
enum rcar_du_output output,
|
2019-01-17 00:40:49 +02:00
|
|
|
struct device_node *enc_node)
|
2013-06-19 13:54:11 +02:00
|
|
|
{
|
|
|
|
struct rcar_du_encoder *renc;
|
2020-05-25 06:18:01 +03:00
|
|
|
struct drm_connector *connector;
|
2019-03-02 18:13:04 +02:00
|
|
|
struct drm_bridge *bridge;
|
2020-05-25 06:18:01 +03:00
|
|
|
int ret;
|
2013-06-19 13:54:11 +02:00
|
|
|
|
2019-03-02 18:13:04 +02: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-03 18:21:55 +02:00
|
|
|
if (IS_ERR(panel))
|
|
|
|
return PTR_ERR(panel);
|
2019-03-02 18:13:04 +02: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 16:28:04 +03:00
|
|
|
bridge = devm_drm_panel_bridge_add_typed(rcdu->dev, panel,
|
|
|
|
DRM_MODE_CONNECTOR_DPI);
|
2020-12-03 18:21:55 +02:00
|
|
|
if (IS_ERR(bridge))
|
|
|
|
return PTR_ERR(bridge);
|
2019-03-02 18:13:04 +02:00
|
|
|
} else {
|
|
|
|
bridge = of_drm_find_bridge(enc_node);
|
2020-12-03 18:21:55 +02:00
|
|
|
if (!bridge)
|
|
|
|
return -EPROBE_DEFER;
|
2020-12-04 13:43:58 +02:00
|
|
|
|
|
|
|
if (output == RCAR_DU_OUTPUT_LVDS0 ||
|
|
|
|
output == RCAR_DU_OUTPUT_LVDS1)
|
|
|
|
rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] = bridge;
|
2022-08-24 15:47:25 +03:00
|
|
|
|
|
|
|
if (output == RCAR_DU_OUTPUT_DSI0 ||
|
|
|
|
output == RCAR_DU_OUTPUT_DSI1)
|
|
|
|
rcdu->dsi[output - RCAR_DU_OUTPUT_DSI0] = bridge;
|
2013-06-17 03:13:11 +02:00
|
|
|
}
|
|
|
|
|
2019-03-05 00:10:28 +02:00
|
|
|
/*
|
2021-08-22 02:44:27 +03:00
|
|
|
* Create and initialize the encoder. On Gen3, skip the LVDS1 output if
|
2020-12-03 18:21:55 +02:00
|
|
|
* the LVDS1 encoder is used as a companion for LVDS0 in dual-link
|
2021-08-22 02:44:27 +03:00
|
|
|
* mode, or any LVDS output if it isn't connected. The latter may happen
|
|
|
|
* on D3 or E3 as the LVDS encoders are needed to provide the pixel
|
|
|
|
* clock to the DU, even when the LVDS outputs are not used.
|
2019-03-05 00:10:28 +02:00
|
|
|
*/
|
2021-08-22 02:44:27 +03:00
|
|
|
if (rcdu->info->gen >= 3) {
|
|
|
|
if (output == RCAR_DU_OUTPUT_LVDS1 &&
|
|
|
|
rcar_lvds_dual_link(bridge))
|
|
|
|
return -ENOLINK;
|
|
|
|
|
|
|
|
if ((output == RCAR_DU_OUTPUT_LVDS0 ||
|
|
|
|
output == RCAR_DU_OUTPUT_LVDS1) &&
|
|
|
|
!rcar_lvds_is_connected(bridge))
|
2020-12-03 18:21:55 +02:00
|
|
|
return -ENOLINK;
|
2019-03-05 00:10:28 +02:00
|
|
|
}
|
|
|
|
|
2021-08-22 02:44:27 +03:00
|
|
|
dev_dbg(rcdu->dev, "initializing encoder %pOF for output %s\n",
|
|
|
|
enc_node, rcar_du_output_name(output));
|
2020-12-03 18:21:55 +02:00
|
|
|
|
2021-01-13 17:02:53 +00:00
|
|
|
renc = drmm_encoder_alloc(&rcdu->ddev, struct rcar_du_encoder, base,
|
|
|
|
&rcar_du_encoder_funcs, DRM_MODE_ENCODER_NONE,
|
|
|
|
NULL);
|
2023-02-27 13:06:59 +03:00
|
|
|
if (IS_ERR(renc))
|
|
|
|
return PTR_ERR(renc);
|
2020-12-03 15:09:22 +02:00
|
|
|
|
2021-01-13 17:02:53 +00:00
|
|
|
renc->output = output;
|
2013-06-15 15:02:12 +02:00
|
|
|
|
2020-05-25 06:18:01 +03:00
|
|
|
/* Attach the bridge to the encoder. */
|
|
|
|
ret = drm_bridge_attach(&renc->base, bridge, NULL,
|
|
|
|
DRM_BRIDGE_ATTACH_NO_CONNECTOR);
|
|
|
|
if (ret) {
|
2021-08-22 02:44:27 +03:00
|
|
|
dev_err(rcdu->dev,
|
|
|
|
"failed to attach bridge %pOF for output %s (%d)\n",
|
|
|
|
bridge->of_node, rcar_du_output_name(output), ret);
|
2020-05-25 06:18:01 +03:00
|
|
|
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,
|
2021-08-22 02:44:27 +03:00
|
|
|
"failed to created connector for output %s (%ld)\n",
|
|
|
|
rcar_du_output_name(output), PTR_ERR(connector));
|
2020-05-25 06:18:01 +03:00
|
|
|
return PTR_ERR(connector);
|
|
|
|
}
|
|
|
|
|
|
|
|
return drm_connector_attach_encoder(connector, &renc->base);
|
2013-06-19 13:54:11 +02:00
|
|
|
}
|