1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
5 * Author: Vinay Simha <vinaysimha@inforcecomputing.com>
10 struct mdp4_lvds_connector
{
11 struct drm_connector base
;
12 struct drm_encoder
*encoder
;
13 struct device_node
*panel_node
;
14 struct drm_panel
*panel
;
16 #define to_mdp4_lvds_connector(x) container_of(x, struct mdp4_lvds_connector, base)
18 static enum drm_connector_status
mdp4_lvds_connector_detect(
19 struct drm_connector
*connector
, bool force
)
21 struct mdp4_lvds_connector
*mdp4_lvds_connector
=
22 to_mdp4_lvds_connector(connector
);
24 if (!mdp4_lvds_connector
->panel
) {
25 mdp4_lvds_connector
->panel
=
26 of_drm_find_panel(mdp4_lvds_connector
->panel_node
);
27 if (IS_ERR(mdp4_lvds_connector
->panel
))
28 mdp4_lvds_connector
->panel
= NULL
;
31 return mdp4_lvds_connector
->panel
?
32 connector_status_connected
:
33 connector_status_disconnected
;
36 static void mdp4_lvds_connector_destroy(struct drm_connector
*connector
)
38 struct mdp4_lvds_connector
*mdp4_lvds_connector
=
39 to_mdp4_lvds_connector(connector
);
41 drm_connector_cleanup(connector
);
43 kfree(mdp4_lvds_connector
);
46 static int mdp4_lvds_connector_get_modes(struct drm_connector
*connector
)
48 struct mdp4_lvds_connector
*mdp4_lvds_connector
=
49 to_mdp4_lvds_connector(connector
);
50 struct drm_panel
*panel
= mdp4_lvds_connector
->panel
;
54 ret
= drm_panel_get_modes(panel
, connector
);
59 static int mdp4_lvds_connector_mode_valid(struct drm_connector
*connector
,
60 struct drm_display_mode
*mode
)
62 struct mdp4_lvds_connector
*mdp4_lvds_connector
=
63 to_mdp4_lvds_connector(connector
);
64 struct drm_encoder
*encoder
= mdp4_lvds_connector
->encoder
;
65 long actual
, requested
;
67 requested
= 1000 * mode
->clock
;
68 actual
= mdp4_lcdc_round_pixclk(encoder
, requested
);
70 DBG("requested=%ld, actual=%ld", requested
, actual
);
72 if (actual
!= requested
)
73 return MODE_CLOCK_RANGE
;
78 static const struct drm_connector_funcs mdp4_lvds_connector_funcs
= {
79 .detect
= mdp4_lvds_connector_detect
,
80 .fill_modes
= drm_helper_probe_single_connector_modes
,
81 .destroy
= mdp4_lvds_connector_destroy
,
82 .reset
= drm_atomic_helper_connector_reset
,
83 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
84 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
87 static const struct drm_connector_helper_funcs mdp4_lvds_connector_helper_funcs
= {
88 .get_modes
= mdp4_lvds_connector_get_modes
,
89 .mode_valid
= mdp4_lvds_connector_mode_valid
,
92 /* initialize connector */
93 struct drm_connector
*mdp4_lvds_connector_init(struct drm_device
*dev
,
94 struct device_node
*panel_node
, struct drm_encoder
*encoder
)
96 struct drm_connector
*connector
= NULL
;
97 struct mdp4_lvds_connector
*mdp4_lvds_connector
;
99 mdp4_lvds_connector
= kzalloc(sizeof(*mdp4_lvds_connector
), GFP_KERNEL
);
100 if (!mdp4_lvds_connector
)
101 return ERR_PTR(-ENOMEM
);
103 mdp4_lvds_connector
->encoder
= encoder
;
104 mdp4_lvds_connector
->panel_node
= panel_node
;
106 connector
= &mdp4_lvds_connector
->base
;
108 drm_connector_init(dev
, connector
, &mdp4_lvds_connector_funcs
,
109 DRM_MODE_CONNECTOR_LVDS
);
110 drm_connector_helper_add(connector
, &mdp4_lvds_connector_helper_funcs
);
112 connector
->polled
= 0;
114 connector
->interlace_allowed
= 0;
115 connector
->doublescan_allowed
= 0;
117 drm_connector_attach_encoder(connector
, encoder
);