aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2016-03-24 13:47:31 +0100
committerGerd Hoffmann <kraxel@redhat.com>2016-03-24 13:47:31 +0100
commitd3a32431b1bd9bfd259c92df66211bff5619628d (patch)
tree93c2d56d60dfe24dcff2e5c4d9d39d3629aa1a9c
parentf280308eea8a25de18568350cde4c232fd728496 (diff)
downloadfbida-d3a32431b1bd9bfd259c92df66211bff5619628d.tar.gz
drm device info
-rw-r--r--drmtools.c92
-rw-r--r--drmtools.h1
-rw-r--r--fbi.c4
-rw-r--r--fbiconfig.c6
-rw-r--r--fbiconfig.h2
5 files changed, 105 insertions, 0 deletions
diff --git a/drmtools.c b/drmtools.c
index 9c8288f..7de221e 100644
--- a/drmtools.c
+++ b/drmtools.c
@@ -33,6 +33,41 @@ static uint8_t *fbmem;
/* ------------------------------------------------------------------ */
+static const char *conn_type[] = {
+ [ DRM_MODE_CONNECTOR_Unknown ] = "unknown",
+ [ DRM_MODE_CONNECTOR_VGA ] = "vga",
+ [ DRM_MODE_CONNECTOR_DVII ] = "dvi-i",
+ [ DRM_MODE_CONNECTOR_DVID ] = "dvi-d",
+ [ DRM_MODE_CONNECTOR_DVIA ] = "dvi-a",
+ [ DRM_MODE_CONNECTOR_Composite ] = "composite",
+ [ DRM_MODE_CONNECTOR_SVIDEO ] = "svideo",
+ [ DRM_MODE_CONNECTOR_LVDS ] = "lvds",
+ [ DRM_MODE_CONNECTOR_Component ] = "component",
+ [ DRM_MODE_CONNECTOR_9PinDIN ] = "9pin-din",
+ [ DRM_MODE_CONNECTOR_DisplayPort ] = "dp",
+ [ DRM_MODE_CONNECTOR_HDMIA ] = "hdmi-a",
+ [ DRM_MODE_CONNECTOR_HDMIB ] = "hdmi-b",
+ [ DRM_MODE_CONNECTOR_TV ] = "tv",
+ [ DRM_MODE_CONNECTOR_eDP ] = "edp",
+ [ DRM_MODE_CONNECTOR_VIRTUAL ] = "virtual",
+ [ DRM_MODE_CONNECTOR_DSI ] = "dsi",
+};
+
+static void drm_conn_name(drmModeConnector *conn, char *dest, int dlen)
+{
+ const char *type;
+
+ if (conn->connector_type_id < sizeof(conn_type)/sizeof(conn_type[0]) &&
+ conn_type[conn->connector_type]) {
+ type = conn_type[conn->connector_type];
+ } else {
+ type = "unknown";
+ }
+ snprintf(dest, dlen, "%s-%d", type, conn->connector_type_id);
+}
+
+/* ------------------------------------------------------------------ */
+
static void drm_cleanup_display(void)
{
/* restore crtc */
@@ -193,3 +228,60 @@ gfxstate *drm_init(const char *device)
gfx->cleanup_display = drm_cleanup_display;
return gfx;
}
+
+void drm_info(const char *device)
+{
+ drmModeConnector *conn;
+ drmModeEncoder *enc;
+ drmModeCrtc *crtc;
+ drmModeRes *res;
+ char name[64];
+ char dev[64];
+ int i;
+
+ if (device) {
+ snprintf(dev, sizeof(dev), "%s", device);
+ } else {
+ snprintf(dev, sizeof(dev), DRM_DEV_NAME, DRM_DIR_NAME, 0);
+ }
+ fd = open(dev, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "drm: open %s: %s\n", dev, strerror(errno));
+ return;
+ }
+ fprintf(stdout, "connectors for %s:\n", dev);
+
+ res = drmModeGetResources(fd);
+ if (res == NULL) {
+ return;
+ }
+
+ for (i = 0; i < res->count_connectors; i++) {
+ conn = drmModeGetConnector(fd, res->connectors[i]);
+ if (!conn)
+ continue;
+ if (!conn->count_encoders)
+ return;
+ drm_conn_name(conn, name, sizeof(name));
+
+ enc = NULL;
+ crtc = NULL;
+ if (conn->encoder_id) {
+ enc = drmModeGetEncoder(fd, conn->encoder_id);
+ if (enc && enc->crtc_id) {
+ crtc = drmModeGetCrtc(fd, enc->crtc_id);
+ }
+ }
+
+ if (conn->connection == DRM_MODE_CONNECTED && crtc) {
+ fprintf(stdout, " %s, connected, %dx%d\n", name,
+ crtc->width, crtc->height);
+ } else {
+ fprintf(stdout, " %s, disconnected\n", name);
+ }
+
+ drmModeFreeCrtc(crtc);
+ drmModeFreeEncoder(enc);
+ drmModeFreeConnector(conn);
+ }
+}
diff --git a/drmtools.h b/drmtools.h
index d778342..0e01ff2 100644
--- a/drmtools.h
+++ b/drmtools.h
@@ -1,2 +1,3 @@
gfxstate *drm_init(const char *dev);
+void drm_info(const char *device);
diff --git a/fbi.c b/fbi.c
index 8315321..c7d84b0 100644
--- a/fbi.c
+++ b/fbi.c
@@ -1466,6 +1466,10 @@ int main(int argc, char *argv[])
version();
exit(0);
}
+ if (GET_DEVICE_INFO()) {
+ drm_info(cfg_get_str(O_DEVICE));
+ exit(0);
+ }
if (GET_WRITECONF())
fbi_write_config();
diff --git a/fbiconfig.c b/fbiconfig.c
index 0f1cb49..8a82331 100644
--- a/fbiconfig.c
+++ b/fbiconfig.c
@@ -23,6 +23,12 @@ struct cfg_cmdline fbi_cmd[] = {
.value = "1",
.desc = "print fbi version number",
},{
+ .letter = 'i',
+ .cmdline = "info",
+ .option = { O_DEVICE_INFO },
+ .value = "1",
+ .desc = "print device info",
+ },{
.cmdline = "store",
.option = { O_WRITECONF },
.value = "1",
diff --git a/fbiconfig.h b/fbiconfig.h
index 9ed7ace..048735b 100644
--- a/fbiconfig.h
+++ b/fbiconfig.h
@@ -9,6 +9,7 @@
#define O_FILE_LIST O_CMDLINE, "file-list"
#define O_TEXT_MODE O_CMDLINE, "text-mode"
#define O_AUTO_ZOOM O_CMDLINE, "auto-zoom"
+#define O_DEVICE_INFO O_CMDLINE, "device-info"
#define O_AUTO_UP O_OPTIONS, "auto-up"
#define O_AUTO_DOWN O_OPTIONS, "auto-down"
@@ -39,6 +40,7 @@
#define GET_WRITECONF() cfg_get_bool(O_WRITECONF, 0)
#define GET_TEXT_MODE() cfg_get_bool(O_TEXT_MODE, 0)
#define GET_AUTO_ZOOM() cfg_get_bool(O_AUTO_ZOOM, 0)
+#define GET_DEVICE_INFO() cfg_get_bool(O_DEVICE_INFO, 0)
#define GET_AUTO_UP() cfg_get_bool(O_AUTO_UP, 0)
#define GET_AUTO_DOWN() cfg_get_bool(O_AUTO_DOWN, 0)