drm and dumb backends use the same DPMS code so share it.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
.get_width = uterm_drm_mode_get_width,
.get_height = uterm_drm_mode_get_height,
};
+
+int uterm_drm_set_dpms(int fd, uint32_t conn_id, int state)
+{
+ int i, ret, set;
+ drmModeConnector *conn;
+ drmModePropertyRes *prop;
+
+ switch (state) {
+ case UTERM_DPMS_ON:
+ set = DRM_MODE_DPMS_ON;
+ break;
+ case UTERM_DPMS_STANDBY:
+ set = DRM_MODE_DPMS_STANDBY;
+ break;
+ case UTERM_DPMS_SUSPEND:
+ set = DRM_MODE_DPMS_SUSPEND;
+ break;
+ case UTERM_DPMS_OFF:
+ set = DRM_MODE_DPMS_OFF;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ conn = drmModeGetConnector(fd, conn_id);
+ if (!conn) {
+ log_err("cannot get display connector");
+ return -EFAULT;
+ }
+
+ ret = state;
+ for (i = 0; i < conn->count_props; ++i) {
+ prop = drmModeGetProperty(fd, conn->props[i]);
+ if (!prop) {
+ log_error("cannot get DRM property (%d): %m", errno);
+ continue;
+ }
+
+ if (!strcmp(prop->name, "DPMS")) {
+ ret = drmModeConnectorSetProperty(fd, conn_id,
+ prop->prop_id, set);
+ if (ret) {
+ log_info("cannot set DPMS");
+ ret = -EFAULT;
+ }
+ drmModeFreeProperty(prop);
+ break;
+ }
+ drmModeFreeProperty(prop);
+ }
+
+ if (i == conn->count_props) {
+ log_warn("display does not support DPMS");
+ ret = UTERM_DPMS_UNKNOWN;
+ }
+
+ drmModeFreeConnector(conn);
+ return ret;
+}
+
+int uterm_drm_get_dpms(int fd, drmModeConnector *conn)
+{
+ int i, ret;
+ drmModePropertyRes *prop;
+
+ for (i = 0; i < conn->count_props; ++i) {
+ prop = drmModeGetProperty(fd, conn->props[i]);
+ if (!prop) {
+ log_error("cannot get DRM property (%d): %m", errno);
+ continue;
+ }
+
+ if (!strcmp(prop->name, "DPMS")) {
+ switch (conn->prop_values[i]) {
+ case DRM_MODE_DPMS_ON:
+ ret = UTERM_DPMS_ON;
+ break;
+ case DRM_MODE_DPMS_STANDBY:
+ ret = UTERM_DPMS_STANDBY;
+ break;
+ case DRM_MODE_DPMS_SUSPEND:
+ ret = UTERM_DPMS_SUSPEND;
+ break;
+ case DRM_MODE_DPMS_OFF:
+ default:
+ ret = UTERM_DPMS_OFF;
+ }
+
+ drmModeFreeProperty(prop);
+ return ret;
+ }
+ drmModeFreeProperty(prop);
+ }
+
+ if (i == conn->count_props)
+ log_warn("display does not support DPMS");
+ return UTERM_DPMS_UNKNOWN;
+}
#include "uterm_video.h"
#include "uterm_video_internal.h"
+/* drm mode */
+
struct uterm_drm_mode {
drmModeModeInfo info;
};
extern const struct mode_ops uterm_drm_mode_ops;
+/* drm dpms */
+
+int uterm_drm_set_dpms(int fd, uint32_t conn_id, int state);
+int uterm_drm_get_dpms(int fd, drmModeConnector *conn);
+
#endif /* UTERM_DRM_SHARED_INTERNAL_H */
static int display_set_dpms(struct uterm_display *disp, int state)
{
- int i, ret, set;
- drmModeConnector *conn;
- drmModePropertyRes *prop;
+ int ret;
if (!display_is_conn(disp) || !video_is_awake(disp->video))
return -EINVAL;
- switch (state) {
- case UTERM_DPMS_ON:
- set = DRM_MODE_DPMS_ON;
- break;
- case UTERM_DPMS_STANDBY:
- set = DRM_MODE_DPMS_STANDBY;
- break;
- case UTERM_DPMS_SUSPEND:
- set = DRM_MODE_DPMS_SUSPEND;
- break;
- case UTERM_DPMS_OFF:
- set = DRM_MODE_DPMS_OFF;
- break;
- default:
- return -EINVAL;
- }
-
log_info("setting DPMS of display %p to %s", disp,
- uterm_dpms_to_name(state));
-
- conn = drmModeGetConnector(disp->video->drm.fd, disp->drm.conn_id);
- if (!conn) {
- log_err("cannot get display connector");
- return -EFAULT;
- }
+ uterm_dpms_to_name(state));
- ret = 0;
- for (i = 0; i < conn->count_props; ++i) {
- prop = drmModeGetProperty(disp->video->drm.fd, conn->props[i]);
- if (!prop) {
- log_error("cannot get DRM property (%d): %m", errno);
- continue;
- }
-
- if (!strcmp(prop->name, "DPMS")) {
- ret = drmModeConnectorSetProperty(disp->video->drm.fd,
- disp->drm.conn_id, prop->prop_id, set);
- if (ret) {
- log_info("cannot set DPMS");
- ret = -EFAULT;
- }
- drmModeFreeProperty(prop);
- break;
- }
- drmModeFreeProperty(prop);
- }
-
- if (i == conn->count_props) {
- ret = 0;
- log_warn("display does not support DPMS");
- state = UTERM_DPMS_UNKNOWN;
- }
+ ret = uterm_drm_set_dpms(disp->video->drm.fd, disp->drm.conn_id,
+ state);
+ if (ret < 0)
+ return ret;
- drmModeFreeConnector(conn);
- disp->dpms = state;
- return ret;
+ disp->dpms = ret;
+ return 0;
}
static int display_use(struct uterm_display *disp)
}
}
-static int get_dpms(struct uterm_display *disp, drmModeConnector *conn)
-{
- int i, ret;
- drmModePropertyRes *prop;
-
- for (i = 0; i < conn->count_props; ++i) {
- prop = drmModeGetProperty(disp->video->drm.fd, conn->props[i]);
- if (!prop) {
- log_error("cannot get DRM property (%d): %m", errno);
- continue;
- }
-
- if (!strcmp(prop->name, "DPMS")) {
- switch (conn->prop_values[i]) {
- case DRM_MODE_DPMS_ON:
- ret = UTERM_DPMS_ON;
- break;
- case DRM_MODE_DPMS_STANDBY:
- ret = UTERM_DPMS_STANDBY;
- break;
- case DRM_MODE_DPMS_SUSPEND:
- ret = UTERM_DPMS_SUSPEND;
- break;
- case DRM_MODE_DPMS_OFF:
- default:
- ret = UTERM_DPMS_OFF;
- }
-
- drmModeFreeProperty(prop);
- return ret;
- }
- drmModeFreeProperty(prop);
- }
-
- if (i == conn->count_props)
- log_warn("display does not support DPMS");
- return UTERM_DPMS_UNKNOWN;
-}
-
static void bind_display(struct uterm_video *video, drmModeRes *res,
drmModeConnector *conn)
{
disp->flags |= DISPLAY_AVAILABLE;
disp->next = video->displays;
video->displays = disp;
- disp->dpms = get_dpms(disp, conn);
+ disp->dpms = uterm_drm_get_dpms(disp->video->drm.fd, conn);
log_info("display %p DPMS is %s", disp,
uterm_dpms_to_name(disp->dpms));
VIDEO_CB(video, disp, UTERM_NEW);
static int display_set_dpms(struct uterm_display *disp, int state)
{
- int i, ret, set;
- drmModeConnector *conn;
- drmModePropertyRes *prop;
+ int ret;
if (!display_is_conn(disp) || !video_is_awake(disp->video))
return -EINVAL;
- switch (state) {
- case UTERM_DPMS_ON:
- set = DRM_MODE_DPMS_ON;
- break;
- case UTERM_DPMS_STANDBY:
- set = DRM_MODE_DPMS_STANDBY;
- break;
- case UTERM_DPMS_SUSPEND:
- set = DRM_MODE_DPMS_SUSPEND;
- break;
- case UTERM_DPMS_OFF:
- set = DRM_MODE_DPMS_OFF;
- break;
- default:
- return -EINVAL;
- }
-
log_info("setting DPMS of display %p to %s", disp,
- uterm_dpms_to_name(state));
-
- conn = drmModeGetConnector(disp->video->dumb.fd, disp->dumb.conn_id);
- if (!conn) {
- log_err("cannot get display connector");
- return -EFAULT;
- }
-
- ret = 0;
- for (i = 0; i < conn->count_props; ++i) {
- prop = drmModeGetProperty(disp->video->dumb.fd, conn->props[i]);
- if (!prop) {
- log_error("cannot get DRM property (%d): %m", errno);
- continue;
- }
-
- if (!strcmp(prop->name, "DPMS")) {
- ret = drmModeConnectorSetProperty(disp->video->dumb.fd,
- disp->dumb.conn_id, prop->prop_id, set);
- if (ret) {
- log_info("cannot set DPMS");
- ret = -EFAULT;
- }
- drmModeFreeProperty(prop);
- break;
- }
- drmModeFreeProperty(prop);
- }
+ uterm_dpms_to_name(state));
- if (i == conn->count_props) {
- ret = 0;
- log_warn("display does not support DPMS");
- state = UTERM_DPMS_UNKNOWN;
- }
+ ret = uterm_drm_set_dpms(disp->video->dumb.fd, disp->dumb.conn_id,
+ state);
+ if (ret < 0)
+ return ret;
- drmModeFreeConnector(conn);
- disp->dpms = state;
- return ret;
+ disp->dpms = ret;
+ return 0;
}
static int display_swap(struct uterm_display *disp)
}
}
-static int get_dpms(struct uterm_display *disp, drmModeConnector *conn)
-{
- int i, ret;
- drmModePropertyRes *prop;
-
- for (i = 0; i < conn->count_props; ++i) {
- prop = drmModeGetProperty(disp->video->dumb.fd, conn->props[i]);
- if (!prop) {
- log_error("cannot get DRM property (%d): %m", errno);
- continue;
- }
-
- if (!strcmp(prop->name, "DPMS")) {
- switch (conn->prop_values[i]) {
- case DRM_MODE_DPMS_ON:
- ret = UTERM_DPMS_ON;
- break;
- case DRM_MODE_DPMS_STANDBY:
- ret = UTERM_DPMS_STANDBY;
- break;
- case DRM_MODE_DPMS_SUSPEND:
- ret = UTERM_DPMS_SUSPEND;
- break;
- case DRM_MODE_DPMS_OFF:
- default:
- ret = UTERM_DPMS_OFF;
- }
-
- drmModeFreeProperty(prop);
- return ret;
- }
- drmModeFreeProperty(prop);
- }
-
- if (i == conn->count_props)
- log_warn("display does not support DPMS");
- return UTERM_DPMS_UNKNOWN;
-}
-
static void bind_display(struct uterm_video *video, drmModeRes *res,
drmModeConnector *conn)
{
disp->flags |= DISPLAY_AVAILABLE;
disp->next = video->displays;
video->displays = disp;
- disp->dpms = get_dpms(disp, conn);
+ disp->dpms = uterm_drm_get_dpms(disp->video->dumb.fd, conn);
log_info("display %p DPMS is %s", disp,
uterm_dpms_to_name(disp->dpms));
VIDEO_CB(video, disp, UTERM_NEW);