2019-06-03 13:44:50 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-01-06 18:13:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Traphandler
|
|
|
|
* Copyright (C) 2014 Free Electrons
|
|
|
|
* Copyright (C) 2014 Atmel
|
|
|
|
*
|
|
|
|
* Author: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
|
|
|
|
* Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
|
|
|
|
*/
|
|
|
|
|
2019-06-30 14:19:03 +08:00
|
|
|
#include <linux/media-bus-format.h>
|
2015-01-06 18:13:28 +08:00
|
|
|
#include <linux/of_graph.h>
|
|
|
|
|
2020-03-05 23:59:30 +08:00
|
|
|
#include <drm/drm_bridge.h>
|
2019-06-30 14:19:03 +08:00
|
|
|
#include <drm/drm_encoder.h>
|
2017-03-30 02:55:46 +08:00
|
|
|
#include <drm/drm_of.h>
|
2020-03-05 23:59:30 +08:00
|
|
|
#include <drm/drm_simple_kms_helper.h>
|
2015-01-06 18:13:28 +08:00
|
|
|
|
|
|
|
#include "atmel_hlcdc_dc.h"
|
|
|
|
|
2018-08-25 16:56:20 +08:00
|
|
|
struct atmel_hlcdc_rgb_output {
|
|
|
|
struct drm_encoder encoder;
|
|
|
|
int bus_fmt;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct atmel_hlcdc_rgb_output *
|
|
|
|
atmel_hlcdc_encoder_to_rgb_output(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
return container_of(encoder, struct atmel_hlcdc_rgb_output, encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
int atmel_hlcdc_encoder_get_bus_fmt(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct atmel_hlcdc_rgb_output *output;
|
|
|
|
|
|
|
|
output = atmel_hlcdc_encoder_to_rgb_output(encoder);
|
|
|
|
|
|
|
|
return output->bus_fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atmel_hlcdc_of_bus_fmt(const struct device_node *ep)
|
|
|
|
{
|
|
|
|
u32 bus_width;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(ep, "bus-width", &bus_width);
|
|
|
|
if (ret == -EINVAL)
|
|
|
|
return 0;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (bus_width) {
|
|
|
|
case 12:
|
|
|
|
return MEDIA_BUS_FMT_RGB444_1X12;
|
|
|
|
case 16:
|
|
|
|
return MEDIA_BUS_FMT_RGB565_1X16;
|
|
|
|
case 18:
|
|
|
|
return MEDIA_BUS_FMT_RGB666_1X18;
|
|
|
|
case 24:
|
|
|
|
return MEDIA_BUS_FMT_RGB888_1X24;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 20:35:21 +08:00
|
|
|
static int atmel_hlcdc_attach_endpoint(struct drm_device *dev, int endpoint)
|
2016-01-06 17:16:32 +08:00
|
|
|
{
|
2018-08-25 16:56:20 +08:00
|
|
|
struct atmel_hlcdc_rgb_output *output;
|
|
|
|
struct device_node *ep;
|
2016-01-06 17:16:32 +08:00
|
|
|
struct drm_panel *panel;
|
|
|
|
struct drm_bridge *bridge;
|
|
|
|
int ret;
|
2015-01-06 18:13:28 +08:00
|
|
|
|
2018-08-25 16:56:20 +08:00
|
|
|
ep = of_graph_get_endpoint_by_regs(dev->dev->of_node, 0, endpoint);
|
|
|
|
if (!ep)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2017-05-18 20:35:21 +08:00
|
|
|
ret = drm_of_find_panel_or_bridge(dev->dev->of_node, 0, endpoint,
|
|
|
|
&panel, &bridge);
|
2018-08-25 16:56:20 +08:00
|
|
|
if (ret) {
|
|
|
|
of_node_put(ep);
|
2017-05-18 20:35:21 +08:00
|
|
|
return ret;
|
2018-08-25 16:56:20 +08:00
|
|
|
}
|
2017-05-18 20:35:21 +08:00
|
|
|
|
2018-08-25 16:56:20 +08:00
|
|
|
output = devm_kzalloc(dev->dev, sizeof(*output), GFP_KERNEL);
|
|
|
|
if (!output) {
|
|
|
|
of_node_put(ep);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->bus_fmt = atmel_hlcdc_of_bus_fmt(ep);
|
|
|
|
of_node_put(ep);
|
|
|
|
if (output->bus_fmt < 0) {
|
|
|
|
dev_err(dev->dev, "endpoint %d: invalid bus width\n", endpoint);
|
2016-01-06 17:16:32 +08:00
|
|
|
return -EINVAL;
|
2018-08-25 16:56:20 +08:00
|
|
|
}
|
2015-01-06 18:13:28 +08:00
|
|
|
|
2020-03-05 23:59:30 +08:00
|
|
|
ret = drm_simple_encoder_init(dev, &output->encoder,
|
|
|
|
DRM_MODE_ENCODER_NONE);
|
2015-01-06 18:13:28 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-08-25 16:56:20 +08:00
|
|
|
output->encoder.possible_crtcs = 0x1;
|
2016-01-06 17:16:32 +08: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 21:28:04 +08:00
|
|
|
bridge = drm_panel_bridge_add_typed(panel,
|
|
|
|
DRM_MODE_CONNECTOR_Unknown);
|
2017-05-12 02:31:28 +08:00
|
|
|
if (IS_ERR(bridge))
|
|
|
|
return PTR_ERR(bridge);
|
2016-01-06 17:16:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bridge) {
|
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 19:24:29 +08:00
|
|
|
ret = drm_bridge_attach(&output->encoder, bridge, NULL, 0);
|
2016-01-06 17:16:32 +08:00
|
|
|
if (!ret)
|
|
|
|
return 0;
|
2017-05-12 02:31:28 +08:00
|
|
|
|
|
|
|
if (panel)
|
|
|
|
drm_panel_bridge_remove(bridge);
|
2016-01-06 17:16:32 +08:00
|
|
|
}
|
2015-01-06 18:13:28 +08:00
|
|
|
|
2018-08-25 16:56:20 +08:00
|
|
|
drm_encoder_cleanup(&output->encoder);
|
2015-01-06 18:13:28 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int atmel_hlcdc_create_outputs(struct drm_device *dev)
|
|
|
|
{
|
2017-05-18 20:35:21 +08:00
|
|
|
int endpoint, ret = 0;
|
2018-08-25 16:56:19 +08:00
|
|
|
int attached = 0;
|
2017-05-18 20:35:21 +08:00
|
|
|
|
2018-08-25 16:56:19 +08:00
|
|
|
/*
|
|
|
|
* Always scan the first few endpoints even if we get -ENODEV,
|
|
|
|
* but keep going after that as long as we keep getting hits.
|
|
|
|
*/
|
|
|
|
for (endpoint = 0; !ret || endpoint < 4; endpoint++) {
|
2017-05-18 20:35:21 +08:00
|
|
|
ret = atmel_hlcdc_attach_endpoint(dev, endpoint);
|
2018-08-25 16:56:19 +08:00
|
|
|
if (ret == -ENODEV)
|
|
|
|
continue;
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
attached++;
|
|
|
|
}
|
2017-05-18 20:35:21 +08:00
|
|
|
|
|
|
|
/* At least one device was successfully attached.*/
|
2018-08-25 16:56:19 +08:00
|
|
|
if (ret == -ENODEV && attached)
|
2017-05-18 20:35:21 +08:00
|
|
|
return 0;
|
2015-01-06 18:13:28 +08:00
|
|
|
|
2017-03-30 02:55:46 +08:00
|
|
|
return ret;
|
2015-01-06 18:13:28 +08:00
|
|
|
}
|