Skip to content

Commit e9e0569

Browse files
author
Laurent Pinchart
committed
drm: rcar-du: lvds: Convert to DRM panel bridge helper
Replace the manual panel handling with usage of the DRM panel bridge helper. This simplifies the driver, and brings support for DRM_BRIDGE_ATTACH_NO_CONNECTOR as an added bonus. Signed-off-by: Laurent Pinchart <[email protected]> Tested-by: Kieran Bingham <[email protected]> # On V3U Reviewed-by: Kieran Bingham <[email protected]>
1 parent 5bcc483 commit e9e0569

File tree

1 file changed

+12
-108
lines changed

1 file changed

+12
-108
lines changed

drivers/gpu/drm/rcar-du/rcar_lvds.c

Lines changed: 12 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ struct rcar_lvds {
6363
struct drm_bridge bridge;
6464

6565
struct drm_bridge *next_bridge;
66-
struct drm_connector connector;
6766
struct drm_panel *panel;
6867

6968
void __iomem *mmio;
@@ -80,73 +79,11 @@ struct rcar_lvds {
8079
#define bridge_to_rcar_lvds(b) \
8180
container_of(b, struct rcar_lvds, bridge)
8281

83-
#define connector_to_rcar_lvds(c) \
84-
container_of(c, struct rcar_lvds, connector)
85-
8682
static void rcar_lvds_write(struct rcar_lvds *lvds, u32 reg, u32 data)
8783
{
8884
iowrite32(data, lvds->mmio + reg);
8985
}
9086

91-
/* -----------------------------------------------------------------------------
92-
* Connector & Panel
93-
*/
94-
95-
static int rcar_lvds_connector_get_modes(struct drm_connector *connector)
96-
{
97-
struct rcar_lvds *lvds = connector_to_rcar_lvds(connector);
98-
99-
return drm_panel_get_modes(lvds->panel, connector);
100-
}
101-
102-
static int rcar_lvds_connector_atomic_check(struct drm_connector *connector,
103-
struct drm_atomic_state *state)
104-
{
105-
struct rcar_lvds *lvds = connector_to_rcar_lvds(connector);
106-
const struct drm_display_mode *panel_mode;
107-
struct drm_connector_state *conn_state;
108-
struct drm_crtc_state *crtc_state;
109-
110-
conn_state = drm_atomic_get_new_connector_state(state, connector);
111-
if (!conn_state->crtc)
112-
return 0;
113-
114-
if (list_empty(&connector->modes)) {
115-
dev_dbg(lvds->dev, "connector: empty modes list\n");
116-
return -EINVAL;
117-
}
118-
119-
panel_mode = list_first_entry(&connector->modes,
120-
struct drm_display_mode, head);
121-
122-
/* We're not allowed to modify the resolution. */
123-
crtc_state = drm_atomic_get_crtc_state(state, conn_state->crtc);
124-
if (IS_ERR(crtc_state))
125-
return PTR_ERR(crtc_state);
126-
127-
if (crtc_state->mode.hdisplay != panel_mode->hdisplay ||
128-
crtc_state->mode.vdisplay != panel_mode->vdisplay)
129-
return -EINVAL;
130-
131-
/* The flat panel mode is fixed, just copy it to the adjusted mode. */
132-
drm_mode_copy(&crtc_state->adjusted_mode, panel_mode);
133-
134-
return 0;
135-
}
136-
137-
static const struct drm_connector_helper_funcs rcar_lvds_conn_helper_funcs = {
138-
.get_modes = rcar_lvds_connector_get_modes,
139-
.atomic_check = rcar_lvds_connector_atomic_check,
140-
};
141-
142-
static const struct drm_connector_funcs rcar_lvds_conn_funcs = {
143-
.reset = drm_atomic_helper_connector_reset,
144-
.fill_modes = drm_helper_probe_single_connector_modes,
145-
.destroy = drm_connector_cleanup,
146-
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
147-
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
148-
};
149-
15087
/* -----------------------------------------------------------------------------
15188
* PLL Setup
15289
*/
@@ -583,11 +520,6 @@ static void __rcar_lvds_atomic_enable(struct drm_bridge *bridge,
583520
/* Turn the output on. */
584521
lvdcr0 |= LVDCR0_LVRES;
585522
rcar_lvds_write(lvds, LVDCR0, lvdcr0);
586-
587-
if (lvds->panel) {
588-
drm_panel_prepare(lvds->panel);
589-
drm_panel_enable(lvds->panel);
590-
}
591523
}
592524

593525
static void rcar_lvds_atomic_enable(struct drm_bridge *bridge,
@@ -609,11 +541,6 @@ static void rcar_lvds_atomic_disable(struct drm_bridge *bridge,
609541
{
610542
struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge);
611543

612-
if (lvds->panel) {
613-
drm_panel_disable(lvds->panel);
614-
drm_panel_unprepare(lvds->panel);
615-
}
616-
617544
rcar_lvds_write(lvds, LVDCR0, 0);
618545
rcar_lvds_write(lvds, LVDCR1, 0);
619546
rcar_lvds_write(lvds, LVDPLLCR, 0);
@@ -648,45 +575,13 @@ static int rcar_lvds_attach(struct drm_bridge *bridge,
648575
enum drm_bridge_attach_flags flags)
649576
{
650577
struct rcar_lvds *lvds = bridge_to_rcar_lvds(bridge);
651-
struct drm_connector *connector = &lvds->connector;
652-
struct drm_encoder *encoder = bridge->encoder;
653-
int ret;
654-
655-
/* If we have a next bridge just attach it. */
656-
if (lvds->next_bridge)
657-
return drm_bridge_attach(bridge->encoder, lvds->next_bridge,
658-
bridge, flags);
659-
660-
if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
661-
DRM_ERROR("Fix bridge driver to make connector optional!");
662-
return -EINVAL;
663-
}
664-
665-
/* Otherwise if we have a panel, create a connector. */
666-
if (!lvds->panel)
667-
return 0;
668-
669-
ret = drm_connector_init(bridge->dev, connector, &rcar_lvds_conn_funcs,
670-
DRM_MODE_CONNECTOR_LVDS);
671-
if (ret < 0)
672-
return ret;
673-
674-
drm_connector_helper_add(connector, &rcar_lvds_conn_helper_funcs);
675-
676-
ret = drm_connector_attach_encoder(connector, encoder);
677-
if (ret < 0)
678-
return ret;
679-
680-
return 0;
681-
}
682578

683-
static void rcar_lvds_detach(struct drm_bridge *bridge)
684-
{
579+
return drm_bridge_attach(bridge->encoder, lvds->next_bridge, bridge,
580+
flags);
685581
}
686582

687583
static const struct drm_bridge_funcs rcar_lvds_bridge_ops = {
688584
.attach = rcar_lvds_attach,
689-
.detach = rcar_lvds_detach,
690585
.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
691586
.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
692587
.atomic_reset = drm_atomic_helper_bridge_reset,
@@ -759,7 +654,7 @@ static int rcar_lvds_parse_dt_companion(struct rcar_lvds *lvds)
759654
* that we are expected to generate even pixels from the primary
760655
* encoder, and odd pixels from the companion encoder.
761656
*/
762-
if (lvds->next_bridge && lvds->next_bridge->timings &&
657+
if (lvds->next_bridge->timings &&
763658
lvds->next_bridge->timings->dual_link)
764659
lvds->link_type = RCAR_LVDS_DUAL_LINK_EVEN_ODD_PIXELS;
765660
else
@@ -811,6 +706,15 @@ static int rcar_lvds_parse_dt(struct rcar_lvds *lvds)
811706
if (ret)
812707
goto done;
813708

709+
if (lvds->panel) {
710+
lvds->next_bridge = devm_drm_panel_bridge_add(lvds->dev,
711+
lvds->panel);
712+
if (IS_ERR_OR_NULL(lvds->next_bridge)) {
713+
ret = -EINVAL;
714+
goto done;
715+
}
716+
}
717+
814718
if (lvds->info->quirks & RCAR_LVDS_QUIRK_DUAL_LINK)
815719
ret = rcar_lvds_parse_dt_companion(lvds);
816720

0 commit comments

Comments
 (0)