Skip to content

Commit 225a8d0

Browse files
committed
drm/ast: Implement polling for VGA and SIL164 connectors
Implement polling for VGA and SIL164 connectors. Set the flag DRM_CONNECTOR_POLL_DISCONNECT for each to detect the removal of the monitor cable. Implement struct drm_connector_helper_funcs.detect_ctx for each type of connector by testing for EDID data. The helper drm_connector_helper_detect_ctx() implements .detect_ctx() on top of the connector's DDC channel. The function can be used by other drivers as companion to drm_connector_helper_get_modes(). v6: - change helper name to drm_connector_helper_detec_from_ddc() (Maxime, Sui) v5: - share implementation in drm_connector_helper_detect_ctx() (Maxime) - test for DDC presence with drm_probe_ddc() (Maxime, Jani) Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com> Acked-by: Sui Jingfeng <sui.jingfeng@linux.dev> Acked-by: Maxime Ripard <mripard@kernel.org> Link: https://patchwork.freedesktop.org/patch/msgid/20240325200855.21150-13-tzimmermann@suse.de
1 parent 90170b1 commit 225a8d0

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

drivers/gpu/drm/ast/ast_mode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ static int ast_crtc_init(struct drm_device *dev)
13461346

13471347
static const struct drm_connector_helper_funcs ast_vga_connector_helper_funcs = {
13481348
.get_modes = drm_connector_helper_get_modes,
1349+
.detect_ctx = drm_connector_helper_detect_from_ddc,
13491350
};
13501351

13511352
static const struct drm_connector_funcs ast_vga_connector_funcs = {
@@ -1379,7 +1380,7 @@ static int ast_vga_connector_init(struct drm_device *dev, struct drm_connector *
13791380
connector->interlace_allowed = 0;
13801381
connector->doublescan_allowed = 0;
13811382

1382-
connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1383+
connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
13831384

13841385
return 0;
13851386
}
@@ -1414,6 +1415,7 @@ static int ast_vga_output_init(struct ast_device *ast)
14141415

14151416
static const struct drm_connector_helper_funcs ast_sil164_connector_helper_funcs = {
14161417
.get_modes = drm_connector_helper_get_modes,
1418+
.detect_ctx = drm_connector_helper_detect_from_ddc,
14171419
};
14181420

14191421
static const struct drm_connector_funcs ast_sil164_connector_funcs = {
@@ -1447,7 +1449,7 @@ static int ast_sil164_connector_init(struct drm_device *dev, struct drm_connecto
14471449
connector->interlace_allowed = 0;
14481450
connector->doublescan_allowed = 0;
14491451

1450-
connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1452+
connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
14511453

14521454
return 0;
14531455
}

drivers/gpu/drm/drm_probe_helper.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,32 @@ int drm_connector_helper_tv_get_modes(struct drm_connector *connector)
12791279
return i;
12801280
}
12811281
EXPORT_SYMBOL(drm_connector_helper_tv_get_modes);
1282+
1283+
/**
1284+
* drm_connector_helper_detect_from_ddc - Read EDID and detect connector status.
1285+
* @connector: The connector
1286+
* @ctx: Acquire context
1287+
* @force: Perform screen-destructive operations, if necessary
1288+
*
1289+
* Detects the connector status by reading the EDID using drm_probe_ddc(),
1290+
* which requires connector->ddc to be set. Returns connector_status_connected
1291+
* on success or connector_status_disconnected on failure.
1292+
*
1293+
* Returns:
1294+
* The connector status as defined by enum drm_connector_status.
1295+
*/
1296+
int drm_connector_helper_detect_from_ddc(struct drm_connector *connector,
1297+
struct drm_modeset_acquire_ctx *ctx,
1298+
bool force)
1299+
{
1300+
struct i2c_adapter *ddc = connector->ddc;
1301+
1302+
if (!ddc)
1303+
return connector_status_unknown;
1304+
1305+
if (drm_probe_ddc(ddc))
1306+
return connector_status_connected;
1307+
1308+
return connector_status_disconnected;
1309+
}
1310+
EXPORT_SYMBOL(drm_connector_helper_detect_from_ddc);

include/drm/drm_probe_helper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ int drm_connector_helper_get_modes_fixed(struct drm_connector *connector,
3737
int drm_connector_helper_get_modes(struct drm_connector *connector);
3838
int drm_connector_helper_tv_get_modes(struct drm_connector *connector);
3939

40+
int drm_connector_helper_detect_from_ddc(struct drm_connector *connector,
41+
struct drm_modeset_acquire_ctx *ctx,
42+
bool force);
43+
4044
#endif

0 commit comments

Comments
 (0)