Commit c932ced6 authored by Aradhya Bhatia's avatar Aradhya Bhatia Committed by Javier Martinez Canillas

drm/tidss: Update encoder/bridge chain connect model

With the new encoder/bridge chain model, the display controller driver
is required to create a drm_connector entity instead of asking the
bridge to do so during drm_bridge_attach. Moreover, the controller
driver should create a drm_bridge entity to negotiate bus formats and a
'simple' drm_encoder entity to expose it to userspace.

Update the encoder/bridge initialization sequence in tidss as per the
new model.
Signed-off-by: default avatarAradhya Bhatia <a-bhatia1@ti.com>
Reviewed-by: default avatarTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230606082142.23760-8-a-bhatia1@ti.com
parent b1c08ffc
...@@ -6,91 +6,125 @@ ...@@ -6,91 +6,125 @@
#include <linux/export.h> #include <linux/export.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_bridge_connector.h>
#include <drm/drm_crtc.h> #include <drm/drm_crtc.h>
#include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_modeset_helper_vtables.h>
#include <drm/drm_panel.h> #include <drm/drm_panel.h>
#include <drm/drm_of.h> #include <drm/drm_of.h>
#include <drm/drm_simple_kms_helper.h>
#include "tidss_crtc.h" #include "tidss_crtc.h"
#include "tidss_drv.h" #include "tidss_drv.h"
#include "tidss_encoder.h" #include "tidss_encoder.h"
static int tidss_encoder_atomic_check(struct drm_encoder *encoder, struct tidss_encoder {
struct drm_crtc_state *crtc_state, struct drm_bridge bridge;
struct drm_connector_state *conn_state) struct drm_encoder encoder;
struct drm_connector *connector;
struct drm_bridge *next_bridge;
struct tidss_device *tidss;
};
static inline struct tidss_encoder
*bridge_to_tidss_encoder(struct drm_bridge *b)
{
return container_of(b, struct tidss_encoder, bridge);
}
static int tidss_bridge_attach(struct drm_bridge *bridge,
enum drm_bridge_attach_flags flags)
{
struct tidss_encoder *t_enc = bridge_to_tidss_encoder(bridge);
return drm_bridge_attach(bridge->encoder, t_enc->next_bridge,
bridge, flags);
}
static int tidss_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 drm_device *ddev = encoder->dev; struct tidss_encoder *t_enc = bridge_to_tidss_encoder(bridge);
struct tidss_device *tidss = t_enc->tidss;
struct tidss_crtc_state *tcrtc_state = to_tidss_crtc_state(crtc_state); struct tidss_crtc_state *tcrtc_state = to_tidss_crtc_state(crtc_state);
struct drm_display_info *di = &conn_state->connector->display_info; struct drm_display_info *di = &conn_state->connector->display_info;
struct drm_bridge *bridge; struct drm_bridge_state *next_bridge_state = NULL;
bool bus_flags_set = false;
if (t_enc->next_bridge)
dev_dbg(ddev->dev, "%s\n", __func__); next_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
t_enc->next_bridge);
/*
* Take the bus_flags from the first bridge that defines
* bridge timings, or from the connector's display_info if no
* bridge defines the timings.
*/
drm_for_each_bridge_in_chain(encoder, bridge) {
if (!bridge->timings)
continue;
tcrtc_state->bus_flags = bridge->timings->input_bus_flags;
bus_flags_set = true;
break;
}
if (!di->bus_formats || di->num_bus_formats == 0) { if (next_bridge_state) {
dev_err(ddev->dev, "%s: No bus_formats in connected display\n", tcrtc_state->bus_flags = next_bridge_state->input_bus_cfg.flags;
tcrtc_state->bus_format = next_bridge_state->input_bus_cfg.format;
} else if (di->num_bus_formats) {
tcrtc_state->bus_format = di->bus_formats[0];
tcrtc_state->bus_flags = di->bus_flags;
} else {
dev_err(tidss->dev, "%s: No bus_formats in connected display\n",
__func__); __func__);
return -EINVAL; return -EINVAL;
} }
// XXX any cleaner way to set bus format and flags?
tcrtc_state->bus_format = di->bus_formats[0];
if (!bus_flags_set)
tcrtc_state->bus_flags = di->bus_flags;
return 0; return 0;
} }
static void tidss_encoder_destroy(struct drm_encoder *encoder) static const struct drm_bridge_funcs tidss_bridge_funcs = {
{ .attach = tidss_bridge_attach,
drm_encoder_cleanup(encoder); .atomic_check = tidss_bridge_atomic_check,
kfree(encoder); .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,
static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
.atomic_check = tidss_encoder_atomic_check,
};
static const struct drm_encoder_funcs encoder_funcs = {
.destroy = tidss_encoder_destroy,
}; };
struct drm_encoder *tidss_encoder_create(struct tidss_device *tidss, int tidss_encoder_create(struct tidss_device *tidss,
u32 encoder_type, u32 possible_crtcs) struct drm_bridge *next_bridge,
u32 encoder_type, u32 possible_crtcs)
{ {
struct tidss_encoder *t_enc;
struct drm_encoder *enc; struct drm_encoder *enc;
struct drm_connector *connector;
int ret; int ret;
enc = kzalloc(sizeof(*enc), GFP_KERNEL); t_enc = drmm_simple_encoder_alloc(&tidss->ddev, struct tidss_encoder,
if (!enc) encoder, encoder_type);
return ERR_PTR(-ENOMEM); if (IS_ERR(t_enc))
return PTR_ERR(t_enc);
t_enc->tidss = tidss;
t_enc->next_bridge = next_bridge;
t_enc->bridge.funcs = &tidss_bridge_funcs;
enc = &t_enc->encoder;
enc->possible_crtcs = possible_crtcs; enc->possible_crtcs = possible_crtcs;
ret = drm_encoder_init(&tidss->ddev, enc, &encoder_funcs, /* Attaching first bridge to the encoder */
encoder_type, NULL); ret = drm_bridge_attach(enc, &t_enc->bridge, NULL,
if (ret < 0) { DRM_BRIDGE_ATTACH_NO_CONNECTOR);
kfree(enc); if (ret) {
return ERR_PTR(ret); dev_err(tidss->dev, "bridge attach failed: %d\n", ret);
return ret;
}
/* Initializing the connector at the end of bridge-chain */
connector = drm_bridge_connector_init(&tidss->ddev, enc);
if (IS_ERR(connector)) {
dev_err(tidss->dev, "bridge_connector create failed\n");
return PTR_ERR(connector);
}
ret = drm_connector_attach_encoder(connector, enc);
if (ret) {
dev_err(tidss->dev, "attaching encoder to connector failed\n");
return ret;
} }
drm_encoder_helper_add(enc, &encoder_helper_funcs); t_enc->connector = connector;
dev_dbg(tidss->dev, "Encoder create done\n"); dev_dbg(tidss->dev, "Encoder create done\n");
return enc; return ret;
} }
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
struct tidss_device; struct tidss_device;
struct drm_encoder *tidss_encoder_create(struct tidss_device *tidss, int tidss_encoder_create(struct tidss_device *tidss,
u32 encoder_type, u32 possible_crtcs); struct drm_bridge *next_bridge,
u32 encoder_type, u32 possible_crtcs);
#endif #endif
...@@ -193,7 +193,6 @@ static int tidss_dispc_modeset_init(struct tidss_device *tidss) ...@@ -193,7 +193,6 @@ static int tidss_dispc_modeset_init(struct tidss_device *tidss)
for (i = 0; i < num_pipes; ++i) { for (i = 0; i < num_pipes; ++i) {
struct tidss_plane *tplane; struct tidss_plane *tplane;
struct tidss_crtc *tcrtc; struct tidss_crtc *tcrtc;
struct drm_encoder *enc;
u32 hw_plane_id = feat->vid_order[tidss->num_planes]; u32 hw_plane_id = feat->vid_order[tidss->num_planes];
int ret; int ret;
...@@ -216,16 +215,13 @@ static int tidss_dispc_modeset_init(struct tidss_device *tidss) ...@@ -216,16 +215,13 @@ static int tidss_dispc_modeset_init(struct tidss_device *tidss)
tidss->crtcs[tidss->num_crtcs++] = &tcrtc->crtc; tidss->crtcs[tidss->num_crtcs++] = &tcrtc->crtc;
enc = tidss_encoder_create(tidss, pipes[i].enc_type, ret = tidss_encoder_create(tidss, pipes[i].bridge,
pipes[i].enc_type,
1 << tcrtc->crtc.index); 1 << tcrtc->crtc.index);
if (IS_ERR(enc)) { if (ret) {
dev_err(tidss->dev, "encoder create failed\n"); dev_err(tidss->dev, "encoder create failed\n");
return PTR_ERR(enc);
}
ret = drm_bridge_attach(enc, pipes[i].bridge, NULL, 0);
if (ret)
return ret; return ret;
}
} }
/* create overlay planes of the leftover planes */ /* create overlay planes of the leftover planes */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment