2019-06-04 15:11:33 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-02-10 19:13:23 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Texas Instruments
|
|
|
|
* Author: Jyri Sarha <jsarha@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/component.h>
|
|
|
|
#include <linux/of_graph.h>
|
2019-07-16 13:42:15 +07:00
|
|
|
|
2019-01-18 04:03:34 +07:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2019-08-26 22:26:29 +07:00
|
|
|
#include <drm/drm_bridge.h>
|
2016-10-19 17:28:27 +07:00
|
|
|
#include <drm/drm_of.h>
|
2015-02-10 19:13:23 +07:00
|
|
|
|
|
|
|
#include "tilcdc_drv.h"
|
|
|
|
#include "tilcdc_external.h"
|
|
|
|
|
|
|
|
static const struct tilcdc_panel_info panel_info_tda998x = {
|
|
|
|
.ac_bias = 255,
|
|
|
|
.ac_bias_intrpt = 0,
|
|
|
|
.dma_burst_sz = 16,
|
|
|
|
.bpp = 16,
|
|
|
|
.fdd = 0x80,
|
|
|
|
.tft_alt_mode = 0,
|
|
|
|
.invert_pxl_clk = 1,
|
|
|
|
.sync_edge = 1,
|
|
|
|
.sync_ctrl = 1,
|
|
|
|
.raster_order = 0,
|
|
|
|
};
|
|
|
|
|
2016-10-31 22:34:22 +07:00
|
|
|
static const struct tilcdc_panel_info panel_info_default = {
|
|
|
|
.ac_bias = 255,
|
|
|
|
.ac_bias_intrpt = 0,
|
|
|
|
.dma_burst_sz = 16,
|
|
|
|
.bpp = 16,
|
|
|
|
.fdd = 0x80,
|
|
|
|
.tft_alt_mode = 0,
|
|
|
|
.sync_edge = 0,
|
|
|
|
.sync_ctrl = 1,
|
|
|
|
.raster_order = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
struct drm_connector *tilcdc_encoder_find_connector(struct drm_device *ddev,
|
|
|
|
struct drm_encoder *encoder)
|
2015-02-10 19:13:23 +07:00
|
|
|
{
|
|
|
|
struct drm_connector *connector;
|
2016-10-31 22:34:22 +07:00
|
|
|
|
2018-06-28 20:13:15 +07:00
|
|
|
list_for_each_entry(connector, &ddev->mode_config.connector_list, head) {
|
|
|
|
if (drm_connector_has_possible_encoder(connector, encoder))
|
|
|
|
return connector;
|
|
|
|
}
|
2016-10-31 22:34:22 +07:00
|
|
|
|
|
|
|
dev_err(ddev->dev, "No connector found for %s encoder (id %d)\n",
|
|
|
|
encoder->name, encoder->base.id);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tilcdc_add_component_encoder(struct drm_device *ddev)
|
|
|
|
{
|
|
|
|
struct tilcdc_drm_private *priv = ddev->dev_private;
|
|
|
|
struct drm_encoder *encoder;
|
|
|
|
|
|
|
|
list_for_each_entry(encoder, &ddev->mode_config.encoder_list, head)
|
|
|
|
if (encoder->possible_crtcs & (1 << priv->crtc->index))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!encoder) {
|
|
|
|
dev_err(ddev->dev, "%s: No suitable encoder found\n", __func__);
|
|
|
|
return -ENODEV;
|
2015-02-10 19:13:23 +07:00
|
|
|
}
|
2016-10-31 22:34:22 +07:00
|
|
|
|
2019-08-02 19:55:22 +07:00
|
|
|
priv->external_connector =
|
|
|
|
tilcdc_encoder_find_connector(ddev, encoder);
|
2016-10-31 22:34:22 +07:00
|
|
|
|
2019-08-02 19:55:22 +07:00
|
|
|
if (!priv->external_connector)
|
2016-10-31 22:34:22 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* Only tda998x is supported at the moment. */
|
|
|
|
tilcdc_crtc_set_simulate_vesa_sync(priv->crtc, true);
|
|
|
|
tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_tda998x);
|
|
|
|
|
2019-08-02 19:55:22 +07:00
|
|
|
return 0;
|
2016-10-31 22:34:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_encoder_funcs tilcdc_external_encoder_funcs = {
|
|
|
|
.destroy = drm_encoder_cleanup,
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge)
|
|
|
|
{
|
|
|
|
struct tilcdc_drm_private *priv = ddev->dev_private;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
priv->external_encoder->possible_crtcs = BIT(0);
|
|
|
|
|
drm/bridge: Extend bridge API to disable connector creation
Most bridge drivers create a DRM connector to model the connector at the
output of the bridge. This model is historical and has worked pretty
well so far, but causes several issues:
- It prevents supporting more complex display pipelines where DRM
connector operations are split over multiple components. For instance a
pipeline with a bridge connected to the DDC signals to read EDID data,
and another one connected to the HPD signal to detect connection and
disconnection, will not be possible to support through this model.
- It requires every bridge driver to implement similar connector
handling code, resulting in code duplication.
- It assumes that a bridge will either be wired to a connector or to
another bridge, but doesn't support bridges that can be used in both
positions very well (although there is some ad-hoc support for this in
the analogix_dp bridge driver).
In order to solve these issues, ownership of the connector should be
moved to the display controller driver (where it can be implemented
using helpers provided by the core).
Extend the bridge API to allow disabling connector creation in bridge
drivers as a first step towards the new model. The new flags argument to
the bridge .attach() operation allows instructing the bridge driver to
skip creating a connector. Unconditionally set the new flags argument to
0 for now to keep the existing behaviour, and modify all existing bridge
drivers to return an error when connector creation is not requested as
they don't support this feature yet.
The change is based on the following semantic patch, with manual review
and edits.
@ rule1 @
identifier funcs;
identifier fn;
@@
struct drm_bridge_funcs funcs = {
...,
.attach = fn
};
@ depends on rule1 @
identifier rule1.fn;
identifier bridge;
statement S, S1;
@@
int fn(
struct drm_bridge *bridge
+ , enum drm_bridge_attach_flags flags
)
{
... when != S
+ if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
+ DRM_ERROR("Fix bridge driver to make connector optional!");
+ return -EINVAL;
+ }
+
S1
...
}
@ depends on rule1 @
identifier rule1.fn;
identifier bridge, flags;
expression E1, E2, E3;
@@
int fn(
struct drm_bridge *bridge,
enum drm_bridge_attach_flags flags
) {
<...
drm_bridge_attach(E1, E2, E3
+ , flags
)
...>
}
@@
expression E1, E2, E3;
@@
drm_bridge_attach(E1, E2, E3
+ , 0
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Tested-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200226112514.12455-10-laurent.pinchart@ideasonboard.com
2020-02-26 18:24:29 +07:00
|
|
|
ret = drm_bridge_attach(priv->external_encoder, bridge, NULL, 0);
|
2016-10-31 22:34:22 +07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(ddev->dev, "drm_bridge_attach() failed %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
tilcdc_crtc_set_panel_info(priv->crtc, &panel_info_default);
|
|
|
|
|
2019-08-02 19:55:22 +07:00
|
|
|
priv->external_connector =
|
|
|
|
tilcdc_encoder_find_connector(ddev, priv->external_encoder);
|
|
|
|
if (!priv->external_connector)
|
2016-10-31 22:34:22 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
2019-08-02 19:55:22 +07:00
|
|
|
return 0;
|
2016-10-31 22:34:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
int tilcdc_attach_external_device(struct drm_device *ddev)
|
|
|
|
{
|
|
|
|
struct tilcdc_drm_private *priv = ddev->dev_private;
|
|
|
|
struct drm_bridge *bridge;
|
2018-02-19 00:48:32 +07:00
|
|
|
struct drm_panel *panel;
|
2016-10-31 22:34:22 +07:00
|
|
|
int ret;
|
|
|
|
|
2018-02-19 00:48:32 +07:00
|
|
|
ret = drm_of_find_panel_or_bridge(ddev->dev->of_node, 0, 0,
|
|
|
|
&panel, &bridge);
|
|
|
|
if (ret == -ENODEV)
|
2016-10-31 22:34:22 +07:00
|
|
|
return 0;
|
2018-02-19 00:48:32 +07:00
|
|
|
else if (ret)
|
|
|
|
return ret;
|
2016-10-31 22:34:22 +07:00
|
|
|
|
|
|
|
priv->external_encoder = devm_kzalloc(ddev->dev,
|
|
|
|
sizeof(*priv->external_encoder),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!priv->external_encoder)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = drm_encoder_init(ddev, priv->external_encoder,
|
|
|
|
&tilcdc_external_encoder_funcs,
|
|
|
|
DRM_MODE_ENCODER_NONE, NULL);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(ddev->dev, "drm_encoder_init() failed %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-19 00:48:32 +07:00
|
|
|
if (panel) {
|
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 20:28:04 +07:00
|
|
|
bridge = devm_drm_panel_bridge_add_typed(ddev->dev, panel,
|
|
|
|
DRM_MODE_CONNECTOR_DPI);
|
2018-02-19 00:48:32 +07:00
|
|
|
if (IS_ERR(bridge)) {
|
|
|
|
ret = PTR_ERR(bridge);
|
|
|
|
goto err_encoder_cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 22:34:22 +07:00
|
|
|
ret = tilcdc_attach_bridge(ddev, bridge);
|
|
|
|
if (ret)
|
2018-02-19 00:48:32 +07:00
|
|
|
goto err_encoder_cleanup;
|
|
|
|
|
|
|
|
return 0;
|
2016-10-31 22:34:22 +07:00
|
|
|
|
2018-02-19 00:48:32 +07:00
|
|
|
err_encoder_cleanup:
|
|
|
|
drm_encoder_cleanup(priv->external_encoder);
|
2016-10-31 22:34:22 +07:00
|
|
|
return ret;
|
2015-02-10 19:13:23 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dev_match_of(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
return dev->of_node == data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tilcdc_get_external_components(struct device *dev,
|
|
|
|
struct component_match **match)
|
|
|
|
{
|
2016-06-06 15:11:35 +07:00
|
|
|
struct device_node *node;
|
2015-02-10 19:13:23 +07:00
|
|
|
|
2017-03-22 20:26:06 +07:00
|
|
|
node = of_graph_get_remote_node(dev->of_node, 0, 0);
|
2016-10-31 22:34:22 +07:00
|
|
|
|
2017-03-22 20:26:06 +07:00
|
|
|
if (!of_device_is_compatible(node, "nxp,tda998x")) {
|
2016-10-31 22:34:22 +07:00
|
|
|
of_node_put(node);
|
2017-03-22 20:26:06 +07:00
|
|
|
return 0;
|
2015-02-10 19:13:23 +07:00
|
|
|
}
|
|
|
|
|
2017-03-22 20:26:06 +07:00
|
|
|
if (match)
|
|
|
|
drm_of_component_match_add(dev, match, dev_match_of, node);
|
|
|
|
of_node_put(node);
|
|
|
|
return 1;
|
2015-02-10 19:13:23 +07:00
|
|
|
}
|