2018-09-29 03:13:25 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-09-21 16:07:48 +08:00
|
|
|
/*
|
|
|
|
* i.MX drm driver - parallel display implementation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Sascha Hauer, Pengutronix
|
|
|
|
*/
|
|
|
|
|
2013-11-03 19:23:34 +08:00
|
|
|
#include <linux/component.h>
|
2012-09-21 16:07:48 +08:00
|
|
|
#include <linux/module.h>
|
2019-07-16 14:42:18 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
|
|
|
|
#include <video/of_display_timing.h>
|
|
|
|
|
2016-07-08 17:40:56 +08:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2019-08-26 23:26:29 +08:00
|
|
|
#include <drm/drm_bridge.h>
|
2012-09-21 16:07:48 +08:00
|
|
|
#include <drm/drm_fb_helper.h>
|
2017-03-30 02:55:46 +08:00
|
|
|
#include <drm/drm_of.h>
|
2014-02-25 18:55:04 +08:00
|
|
|
#include <drm/drm_panel.h>
|
2019-01-18 05:03:34 +08:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2020-03-05 23:59:36 +08:00
|
|
|
#include <drm/drm_simple_kms_helper.h>
|
2012-09-21 16:07:48 +08:00
|
|
|
|
|
|
|
#include "imx-drm.h"
|
|
|
|
|
|
|
|
struct imx_parallel_display {
|
|
|
|
struct drm_connector connector;
|
2016-07-06 20:49:24 +08:00
|
|
|
struct drm_encoder encoder;
|
2020-01-28 21:55:09 +08:00
|
|
|
struct drm_bridge bridge;
|
2012-09-21 16:07:48 +08:00
|
|
|
struct device *dev;
|
|
|
|
void *edid;
|
|
|
|
int edid_len;
|
2016-07-06 20:49:24 +08:00
|
|
|
u32 bus_format;
|
2016-07-12 21:30:03 +08:00
|
|
|
u32 bus_flags;
|
2012-09-21 16:07:48 +08:00
|
|
|
struct drm_display_mode mode;
|
2014-02-25 18:55:04 +08:00
|
|
|
struct drm_panel *panel;
|
2020-01-28 21:55:09 +08:00
|
|
|
struct drm_bridge *next_bridge;
|
2012-09-21 16:07:48 +08:00
|
|
|
};
|
|
|
|
|
2016-07-06 21:47:11 +08:00
|
|
|
static inline struct imx_parallel_display *con_to_imxpd(struct drm_connector *c)
|
|
|
|
{
|
|
|
|
return container_of(c, struct imx_parallel_display, connector);
|
|
|
|
}
|
|
|
|
|
2016-07-06 20:49:24 +08:00
|
|
|
static inline struct imx_parallel_display *enc_to_imxpd(struct drm_encoder *e)
|
|
|
|
{
|
|
|
|
return container_of(e, struct imx_parallel_display, encoder);
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
static inline struct imx_parallel_display *bridge_to_imxpd(struct drm_bridge *b)
|
|
|
|
{
|
|
|
|
return container_of(b, struct imx_parallel_display, bridge);
|
|
|
|
}
|
|
|
|
|
2012-09-21 16:07:48 +08:00
|
|
|
static int imx_pd_connector_get_modes(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
struct imx_parallel_display *imxpd = con_to_imxpd(connector);
|
2013-04-03 23:36:28 +08:00
|
|
|
struct device_node *np = imxpd->dev->of_node;
|
2019-08-05 04:16:25 +08:00
|
|
|
int num_modes;
|
|
|
|
|
2019-12-07 22:03:34 +08:00
|
|
|
num_modes = drm_panel_get_modes(imxpd->panel, connector);
|
2019-08-05 04:16:25 +08:00
|
|
|
if (num_modes > 0)
|
|
|
|
return num_modes;
|
2014-02-25 18:55:04 +08:00
|
|
|
|
2012-09-21 16:07:48 +08:00
|
|
|
if (imxpd->edid) {
|
2018-07-09 16:40:06 +08:00
|
|
|
drm_connector_update_edid_property(connector, imxpd->edid);
|
2012-09-21 16:07:48 +08:00
|
|
|
num_modes = drm_add_edid_modes(connector, imxpd->edid);
|
|
|
|
}
|
|
|
|
|
2013-04-03 23:36:28 +08:00
|
|
|
if (np) {
|
|
|
|
struct drm_display_mode *mode = drm_mode_create(connector->dev);
|
2016-07-12 21:30:01 +08:00
|
|
|
int ret;
|
2014-08-05 03:07:07 +08:00
|
|
|
|
2014-02-27 07:53:42 +08:00
|
|
|
if (!mode)
|
|
|
|
return -EINVAL;
|
2016-07-12 21:30:01 +08:00
|
|
|
|
|
|
|
ret = of_get_drm_display_mode(np, &imxpd->mode,
|
2016-07-12 21:30:03 +08:00
|
|
|
&imxpd->bus_flags,
|
2016-07-12 21:30:01 +08:00
|
|
|
OF_USE_NATIVE_MODE);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2013-04-03 23:36:28 +08:00
|
|
|
drm_mode_copy(mode, &imxpd->mode);
|
|
|
|
mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
|
2012-09-21 16:07:48 +08:00
|
|
|
drm_mode_probed_add(connector, mode);
|
|
|
|
num_modes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_modes;
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
static void imx_pd_bridge_enable(struct drm_bridge *bridge)
|
2012-09-21 16:07:48 +08:00
|
|
|
{
|
2020-01-28 21:55:09 +08:00
|
|
|
struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
|
2014-11-03 22:54:47 +08:00
|
|
|
|
|
|
|
drm_panel_prepare(imxpd->panel);
|
|
|
|
drm_panel_enable(imxpd->panel);
|
2012-09-21 16:07:48 +08:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
static void imx_pd_bridge_disable(struct drm_bridge *bridge)
|
2012-09-21 16:07:48 +08:00
|
|
|
{
|
2020-01-28 21:55:09 +08:00
|
|
|
struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
|
2014-11-03 22:54:47 +08:00
|
|
|
|
|
|
|
drm_panel_disable(imxpd->panel);
|
|
|
|
drm_panel_unprepare(imxpd->panel);
|
2012-09-21 16:07:48 +08:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
static const u32 imx_pd_bus_fmts[] = {
|
|
|
|
MEDIA_BUS_FMT_RGB888_1X24,
|
|
|
|
MEDIA_BUS_FMT_BGR888_1X24,
|
|
|
|
MEDIA_BUS_FMT_GBR888_1X24,
|
|
|
|
MEDIA_BUS_FMT_RGB666_1X18,
|
|
|
|
MEDIA_BUS_FMT_RGB666_1X24_CPADHI,
|
|
|
|
MEDIA_BUS_FMT_RGB565_1X16,
|
|
|
|
};
|
|
|
|
|
|
|
|
static u32 *
|
|
|
|
imx_pd_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge,
|
|
|
|
struct drm_bridge_state *bridge_state,
|
|
|
|
struct drm_crtc_state *crtc_state,
|
|
|
|
struct drm_connector_state *conn_state,
|
|
|
|
unsigned int *num_output_fmts)
|
2016-07-06 20:49:24 +08:00
|
|
|
{
|
|
|
|
struct drm_display_info *di = &conn_state->connector->display_info;
|
2020-01-28 21:55:09 +08:00
|
|
|
struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
|
|
|
|
u32 *output_fmts;
|
2016-07-06 20:49:24 +08:00
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
if (!imxpd->bus_format && !di->num_bus_formats) {
|
|
|
|
*num_output_fmts = ARRAY_SIZE(imx_pd_bus_fmts);
|
|
|
|
return kmemdup(imx_pd_bus_fmts, sizeof(imx_pd_bus_fmts),
|
|
|
|
GFP_KERNEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
*num_output_fmts = 1;
|
|
|
|
output_fmts = kmalloc(sizeof(*output_fmts), GFP_KERNEL);
|
|
|
|
if (!output_fmts)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!imxpd->bus_format && di->num_bus_formats)
|
|
|
|
output_fmts[0] = di->bus_formats[0];
|
|
|
|
else
|
|
|
|
output_fmts[0] = imxpd->bus_format;
|
|
|
|
|
|
|
|
return output_fmts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool imx_pd_format_supported(u32 output_fmt)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(imx_pd_bus_fmts); i++) {
|
|
|
|
if (imx_pd_bus_fmts[i] == output_fmt)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 *
|
|
|
|
imx_pd_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge,
|
|
|
|
struct drm_bridge_state *bridge_state,
|
|
|
|
struct drm_crtc_state *crtc_state,
|
|
|
|
struct drm_connector_state *conn_state,
|
|
|
|
u32 output_fmt,
|
|
|
|
unsigned int *num_input_fmts)
|
|
|
|
{
|
|
|
|
struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
|
|
|
|
u32 *input_fmts;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the next bridge does not support bus format negotiation, let's
|
|
|
|
* use the static bus format definition (imxpd->bus_format) if it's
|
|
|
|
* specified, RGB888 when it's not.
|
|
|
|
*/
|
|
|
|
if (output_fmt == MEDIA_BUS_FMT_FIXED)
|
|
|
|
output_fmt = imxpd->bus_format ? : MEDIA_BUS_FMT_RGB888_1X24;
|
|
|
|
|
|
|
|
/* Now make sure the requested output format is supported. */
|
|
|
|
if ((imxpd->bus_format && imxpd->bus_format != output_fmt) ||
|
|
|
|
!imx_pd_format_supported(output_fmt)) {
|
|
|
|
*num_input_fmts = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*num_input_fmts = 1;
|
|
|
|
input_fmts = kmalloc(sizeof(*input_fmts), GFP_KERNEL);
|
|
|
|
if (!input_fmts)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
input_fmts[0] = output_fmt;
|
|
|
|
return input_fmts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_pd_bridge_atomic_check(struct drm_bridge *bridge,
|
|
|
|
struct drm_bridge_state *bridge_state,
|
|
|
|
struct drm_crtc_state *crtc_state,
|
|
|
|
struct drm_connector_state *conn_state)
|
|
|
|
{
|
|
|
|
struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state);
|
|
|
|
struct drm_display_info *di = &conn_state->connector->display_info;
|
|
|
|
struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
|
|
|
|
struct drm_bridge_state *next_bridge_state = NULL;
|
|
|
|
struct drm_bridge *next_bridge;
|
|
|
|
u32 bus_flags, bus_fmt;
|
|
|
|
|
|
|
|
next_bridge = drm_bridge_get_next_bridge(bridge);
|
|
|
|
if (next_bridge)
|
|
|
|
next_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
|
|
|
|
next_bridge);
|
|
|
|
|
|
|
|
if (next_bridge_state)
|
|
|
|
bus_flags = next_bridge_state->input_bus_cfg.flags;
|
2020-03-10 04:18:33 +08:00
|
|
|
else if (di->num_bus_formats)
|
2020-01-28 21:55:09 +08:00
|
|
|
bus_flags = di->bus_flags;
|
|
|
|
else
|
|
|
|
bus_flags = imxpd->bus_flags;
|
|
|
|
|
|
|
|
bus_fmt = bridge_state->input_bus_cfg.format;
|
|
|
|
if (!imx_pd_format_supported(bus_fmt))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (bus_flags &
|
|
|
|
~(DRM_BUS_FLAG_DE_LOW | DRM_BUS_FLAG_DE_HIGH |
|
|
|
|
DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE |
|
|
|
|
DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE)) {
|
|
|
|
dev_warn(imxpd->dev, "invalid bus_flags (%x)\n", bus_flags);
|
|
|
|
return -EINVAL;
|
2016-07-12 21:30:03 +08:00
|
|
|
}
|
2020-01-28 21:55:09 +08:00
|
|
|
|
|
|
|
bridge_state->output_bus_cfg.flags = bus_flags;
|
|
|
|
bridge_state->input_bus_cfg.flags = bus_flags;
|
|
|
|
imx_crtc_state->bus_flags = bus_flags;
|
|
|
|
imx_crtc_state->bus_format = bridge_state->input_bus_cfg.format;
|
2016-07-06 20:49:24 +08:00
|
|
|
imx_crtc_state->di_hsync_pin = 2;
|
|
|
|
imx_crtc_state->di_vsync_pin = 3;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-15 19:21:09 +08:00
|
|
|
static const struct drm_connector_funcs imx_pd_connector_funcs = {
|
2012-09-21 16:07:48 +08:00
|
|
|
.fill_modes = drm_helper_probe_single_connector_modes,
|
2013-11-03 21:30:48 +08:00
|
|
|
.destroy = imx_drm_connector_destroy,
|
2016-07-08 17:40:56 +08:00
|
|
|
.reset = drm_atomic_helper_connector_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
|
2012-09-21 16:07:48 +08:00
|
|
|
};
|
|
|
|
|
2015-12-15 19:21:09 +08:00
|
|
|
static const struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = {
|
2012-09-21 16:07:48 +08:00
|
|
|
.get_modes = imx_pd_connector_get_modes,
|
|
|
|
};
|
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
static const struct drm_bridge_funcs imx_pd_bridge_funcs = {
|
|
|
|
.enable = imx_pd_bridge_enable,
|
|
|
|
.disable = imx_pd_bridge_disable,
|
|
|
|
.atomic_reset = drm_atomic_helper_bridge_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
|
|
|
|
.atomic_check = imx_pd_bridge_atomic_check,
|
|
|
|
.atomic_get_input_bus_fmts = imx_pd_bridge_atomic_get_input_bus_fmts,
|
|
|
|
.atomic_get_output_bus_fmts = imx_pd_bridge_atomic_get_output_bus_fmts,
|
2012-09-21 16:07:48 +08:00
|
|
|
};
|
|
|
|
|
2013-11-03 21:30:48 +08:00
|
|
|
static int imx_pd_register(struct drm_device *drm,
|
|
|
|
struct imx_parallel_display *imxpd)
|
2012-09-21 16:07:48 +08:00
|
|
|
{
|
2016-07-06 20:49:24 +08:00
|
|
|
struct drm_encoder *encoder = &imxpd->encoder;
|
2012-09-21 16:07:48 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-07-06 20:49:24 +08:00
|
|
|
ret = imx_drm_encoder_parse_of(drm, encoder, imxpd->dev->of_node);
|
2013-11-03 21:30:48 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2014-06-17 21:34:51 +08:00
|
|
|
/* set the connector's dpms to OFF so that
|
|
|
|
* drm_helper_connector_dpms() won't return
|
|
|
|
* immediately since the current state is ON
|
|
|
|
* at this point.
|
|
|
|
*/
|
|
|
|
imxpd->connector.dpms = DRM_MODE_DPMS_OFF;
|
|
|
|
|
2020-03-05 23:59:36 +08:00
|
|
|
drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_NONE);
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
imxpd->bridge.funcs = &imx_pd_bridge_funcs;
|
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
|
|
|
drm_bridge_attach(encoder, &imxpd->bridge, NULL, 0);
|
2020-01-28 21:55:09 +08:00
|
|
|
|
|
|
|
if (!imxpd->next_bridge) {
|
2016-06-27 21:26:31 +08:00
|
|
|
drm_connector_helper_add(&imxpd->connector,
|
|
|
|
&imx_pd_connector_helper_funcs);
|
|
|
|
drm_connector_init(drm, &imxpd->connector,
|
|
|
|
&imx_pd_connector_funcs,
|
2017-08-19 00:34:22 +08:00
|
|
|
DRM_MODE_CONNECTOR_DPI);
|
2016-06-27 21:26:31 +08:00
|
|
|
}
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2020-01-28 21:55:09 +08:00
|
|
|
if (imxpd->next_bridge) {
|
|
|
|
ret = drm_bridge_attach(encoder, imxpd->next_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
|
|
|
&imxpd->bridge, 0);
|
2016-06-27 21:26:31 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(imxpd->dev, "failed to attach bridge: %d\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-09 16:40:07 +08:00
|
|
|
drm_connector_attach_encoder(&imxpd->connector, encoder);
|
2016-06-27 21:26:31 +08:00
|
|
|
}
|
2012-09-21 16:07:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-03 19:23:34 +08:00
|
|
|
static int imx_pd_bind(struct device *dev, struct device *master, void *data)
|
2012-09-21 16:07:48 +08:00
|
|
|
{
|
2013-11-03 21:30:48 +08:00
|
|
|
struct drm_device *drm = data;
|
2013-11-03 19:23:34 +08:00
|
|
|
struct device_node *np = dev->of_node;
|
2012-09-21 16:07:48 +08:00
|
|
|
const u8 *edidp;
|
|
|
|
struct imx_parallel_display *imxpd;
|
|
|
|
int ret;
|
2016-07-08 17:40:58 +08:00
|
|
|
u32 bus_format = 0;
|
2012-09-21 16:07:48 +08:00
|
|
|
const char *fmt;
|
|
|
|
|
2020-06-11 20:43:31 +08:00
|
|
|
imxpd = dev_get_drvdata(dev);
|
|
|
|
memset(imxpd, 0, sizeof(*imxpd));
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2019-11-21 00:54:59 +08:00
|
|
|
/* port@1 is the output port */
|
|
|
|
ret = drm_of_find_panel_or_bridge(np, 1, 0, &imxpd->panel,
|
|
|
|
&imxpd->next_bridge);
|
|
|
|
if (ret && ret != -ENODEV)
|
|
|
|
return ret;
|
2012-09-21 16:07:48 +08:00
|
|
|
|
|
|
|
edidp = of_get_property(np, "edid", &imxpd->edid_len);
|
|
|
|
if (edidp)
|
|
|
|
imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
|
|
|
|
|
|
|
|
ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
|
|
|
|
if (!ret) {
|
|
|
|
if (!strcmp(fmt, "rgb24"))
|
2016-07-08 17:40:58 +08:00
|
|
|
bus_format = MEDIA_BUS_FMT_RGB888_1X24;
|
2012-09-21 16:07:48 +08:00
|
|
|
else if (!strcmp(fmt, "rgb565"))
|
2016-07-08 17:40:58 +08:00
|
|
|
bus_format = MEDIA_BUS_FMT_RGB565_1X16;
|
2013-04-23 05:19:31 +08:00
|
|
|
else if (!strcmp(fmt, "bgr666"))
|
2016-07-08 17:40:58 +08:00
|
|
|
bus_format = MEDIA_BUS_FMT_RGB666_1X18;
|
2014-03-29 20:57:44 +08:00
|
|
|
else if (!strcmp(fmt, "lvds666"))
|
2016-07-08 17:40:58 +08:00
|
|
|
bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
|
2012-09-21 16:07:48 +08:00
|
|
|
}
|
2016-07-06 20:49:24 +08:00
|
|
|
imxpd->bus_format = bus_format;
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2013-11-03 19:23:34 +08:00
|
|
|
imxpd->dev = dev;
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2013-11-03 21:30:48 +08:00
|
|
|
ret = imx_pd_register(drm, imxpd);
|
2012-09-21 16:07:48 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-03 19:23:34 +08:00
|
|
|
static void imx_pd_unbind(struct device *dev, struct device *master,
|
|
|
|
void *data)
|
2012-09-21 16:07:48 +08:00
|
|
|
{
|
2013-11-03 19:23:34 +08:00
|
|
|
struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2013-12-09 05:03:58 +08:00
|
|
|
kfree(imxpd->edid);
|
2013-11-03 19:23:34 +08:00
|
|
|
}
|
2012-09-21 16:07:48 +08:00
|
|
|
|
2013-11-03 19:23:34 +08:00
|
|
|
static const struct component_ops imx_pd_ops = {
|
|
|
|
.bind = imx_pd_bind,
|
|
|
|
.unbind = imx_pd_unbind,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int imx_pd_probe(struct platform_device *pdev)
|
|
|
|
{
|
2020-06-11 20:43:31 +08:00
|
|
|
struct imx_parallel_display *imxpd;
|
|
|
|
|
|
|
|
imxpd = devm_kzalloc(&pdev->dev, sizeof(*imxpd), GFP_KERNEL);
|
|
|
|
if (!imxpd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, imxpd);
|
|
|
|
|
2013-11-03 19:23:34 +08:00
|
|
|
return component_add(&pdev->dev, &imx_pd_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_pd_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
component_del(&pdev->dev, &imx_pd_ops);
|
2013-12-09 05:03:58 +08:00
|
|
|
|
2012-09-21 16:07:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id imx_pd_dt_ids[] = {
|
|
|
|
{ .compatible = "fsl,imx-parallel-display", },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
2013-06-07 17:36:46 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, imx_pd_dt_ids);
|
2012-09-21 16:07:48 +08:00
|
|
|
|
|
|
|
static struct platform_driver imx_pd_driver = {
|
|
|
|
.probe = imx_pd_probe,
|
2012-11-20 02:20:51 +08:00
|
|
|
.remove = imx_pd_remove,
|
2012-09-21 16:07:48 +08:00
|
|
|
.driver = {
|
|
|
|
.of_match_table = imx_pd_dt_ids,
|
|
|
|
.name = "imx-parallel-display",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(imx_pd_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("i.MX parallel display driver");
|
|
|
|
MODULE_AUTHOR("Sascha Hauer, Pengutronix");
|
|
|
|
MODULE_LICENSE("GPL");
|
2013-08-19 08:40:05 +08:00
|
|
|
MODULE_ALIAS("platform:imx-parallel-display");
|