summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-04-15 14:03:44 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-04-15 14:03:44 +0200
commita6c1a29d7346b44582247c7597cef3c1f82d576b (patch)
treea98e0fd79bb9ced0c47b9bd1cb810e7da9e582da
parent8e5f4360503003b740a90da0423a746d2af85745 (diff)
DPMS/Power Mode support
-rw-r--r--src/wfdapi.c19
-rw-r--r--src/wfdport.c75
-rw-r--r--src/wfdport.h6
3 files changed, 96 insertions, 4 deletions
diff --git a/src/wfdapi.c b/src/wfdapi.c
index 1c32fad..f2198b5 100644
--- a/src/wfdapi.c
+++ b/src/wfdapi.c
@@ -613,11 +613,26 @@ wfdGetPortAttribfv(WFDDevice device,
WFD_API_CALL void WFD_APIENTRY
-wfdSetPortAttribi(WFDDevice device,
- WFDPort port,
+wfdSetPortAttribi(WFDDevice device_handle,
+ WFDPort port_handle,
WFDPortConfigAttrib attrib,
WFDint value) WFD_APIEXIT
{
+ struct wfd_device *device;
+ struct wfd_port *port;
+
+ device = wf_handle_get_object(device_handle, DEVICE_HANDLE);
+ if (device == NULL)
+ return 0;
+ wfd_device_set_error(device, WFD_ERROR_NONE);
+
+ port = wf_handle_get_object(port_handle, PORT_HANDLE);
+ if (port == NULL) {
+ wfd_device_set_error(device, WFD_ERROR_BAD_HANDLE);
+ return 0;
+ }
+
+ wfd_port_set_attribi(device, port, attrib, value);
}
diff --git a/src/wfdport.c b/src/wfdport.c
index efba6d2..147e03a 100644
--- a/src/wfdport.c
+++ b/src/wfdport.c
@@ -21,6 +21,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
@@ -47,6 +48,8 @@ struct wfd_port {
uint32_t choosen_pipeline;
+ uint32_t dpms_enum_id;
+ WFDint power_mode;
};
WFDint
@@ -132,13 +135,16 @@ wfd_port_create(struct wfd_device *device,
{
struct wfd_port *port;
int drm_fd = wfd_device_get_fd(device);
- drmModeEncoder *encoder;
+ drmModeEncoderPtr encoder;
+ drmModePropertyPtr prop;
int i;
port = calloc(1, sizeof *port);
if (port == NULL)
return NULL;
+ port->power_mode = WFD_POWER_MODE_OFF;
+
port->connector = drmModeGetConnector(drm_fd, port_id);
if (port->connector == NULL) {
free(port);
@@ -163,6 +169,22 @@ wfd_port_create(struct wfd_device *device,
drmModeFreeEncoder(encoder);
}
+ port->dpms_enum_id = 0;
+ for (i = 0; i < port->connector->count_props; ++i) {
+ prop = drmModeGetProperty(drm_fd, port->connector->props[i]);
+ if (!prop)
+ continue;
+
+ if (prop->flags && DRM_MODE_PROP_ENUM &&
+ strcmp(prop->name, "DPMS") == 0) {
+ port->dpms_enum_id = port->connector->props[i];
+ drmModeFreeProperty(prop);
+ break;
+ }
+
+ drmModeFreeProperty(prop);
+ }
+
port->mode = NULL;
return port;
@@ -245,6 +267,30 @@ wfd_port_get_attribiv(struct wfd_device *device,
}
}
+void
+wfd_port_set_attribi(struct wfd_device *device,
+ struct wfd_port *port,
+ WFDPortConfigAttrib attribute,
+ WFDint value)
+{
+ switch (attribute) {
+ case WFD_PORT_POWER_MODE:
+ switch (value) {
+ case WFD_POWER_MODE_ON:
+ case WFD_POWER_MODE_LIMITED_USE:
+ case WFD_POWER_MODE_SUSPEND:
+ case WFD_POWER_MODE_OFF:
+ break;
+ default:
+ return;
+ }
+ port->power_mode = value;
+ break;
+ default:
+ break;
+ }
+}
+
WFDint
wfd_port_get_modes(struct wfd_device *device,
struct wfd_port *port,
@@ -334,8 +380,33 @@ wfd_port_commit(struct wfd_device *device,
&port->connector->connector_id, 1,
port->mode);
- if (ret)
+ if (ret) {
fprintf(stderr, "drmModeSetCrtc: %d %m\n", ret);
+ return ret;
+ }
+
+ uint64_t power_mode;
+ switch (port->power_mode) {
+ case WFD_POWER_MODE_ON:
+ power_mode = DRM_MODE_DPMS_ON;
+ break;
+ case WFD_POWER_MODE_LIMITED_USE:
+ power_mode = DRM_MODE_DPMS_STANDBY;
+ break;
+ case WFD_POWER_MODE_SUSPEND:
+ power_mode = DRM_MODE_DPMS_SUSPEND;
+ break;
+ case WFD_POWER_MODE_OFF:
+ power_mode = DRM_MODE_DPMS_OFF;
+ break;
+ }
+
+ ret = drmModeConnectorSetProperty(fd, port->connector->connector_id,
+ port->dpms_enum_id, power_mode);
+ if (ret) {
+ fprintf(stderr, "drmModeconnectorSetProperty: %d %m\n", ret);
+ return ret;
+ }
return ret;
}
diff --git a/src/wfdport.h b/src/wfdport.h
index 08bbef5..0276cca 100644
--- a/src/wfdport.h
+++ b/src/wfdport.h
@@ -55,6 +55,12 @@ wfd_port_get_attribiv(struct wfd_device *device,
WFDint count,
WFDint *value);
+void
+wfd_port_set_attribi(struct wfd_device *device,
+ struct wfd_port *port,
+ WFDPortConfigAttrib attribute,
+ WFDint value);
+
WFDint
wfd_port_get_modes(struct wfd_device *device,
struct wfd_port *port,