drm: add specific init function for spreadtrum 28/54528/1
authorSangjin Lee <lsj119@samsung.com>
Wed, 16 Dec 2015 04:11:06 +0000 (13:11 +0900)
committerSangjin Lee <lsj119@samsung.com>
Wed, 16 Dec 2015 04:11:06 +0000 (13:11 +0900)
drm-sprd need specific init function.

Change-Id: Ibcc0c3dd1acfb0559146c23e8a96c8055b6913a9
Signed-off-by: Sangjin Lee <lsj119@samsung.com>
configure.ac
packaging/pepper.spec
src/lib/drm/drm-common.c
src/samples/drm-backend.c

index 8720fcb..0f0907b 100644 (file)
@@ -100,6 +100,14 @@ PEPPER_DRM_REQUIRES="libdrm gbm"
 PKG_CHECK_MODULES(PEPPER_DRM, [$PEPPER_DRM_REQUIRES])
 PEPPER_DRM_REQUIRES="$PEPPER_DRM_REQUIRES pepper pepper-render pepper-libinput"
 
+PKG_CHECK_MODULES([DRM_SPRD], [libdrm_sprd], [have_drm_sprd=yes], [have_drm_sprd=no])
+if test x$have_drm_sprd = xyes; then
+   AC_DEFINE([HAVE_DRM_SPRD], [1], [Build the drm_sprd])
+   PEPPER_DRM_REQUIRES="$PEPPER_DRM_REQUIRES libdrm-sprd"
+   PEPPER_DRM_CFLAGS="$PEPPER_DRM_CFLAGS $DRM_SPRD_CFLAGS"
+   PEPPER_DRM_LIBS="$PEPPER_DRM_LIBS $DRM_SPRD_LIBS"
+fi
+
 PEPPER_DRM_DIR="-I\$(top_srcdir)/src/lib/drm"
 PEPPER_DRM_LIB="\$(top_srcdir)/src/lib/drm/libpepper-drm.la"
 
index 67efaf1..27ae021 100644 (file)
@@ -23,6 +23,9 @@ BuildRequires:  pkgconfig(xkbcommon)
 BuildRequires: doxygen
 BuildRequires: pkgconfig(wayland-tbm-client)
 BuildRequires:  pkgconfig(wayland-tbm-server)
+%if ("%{?tizen_target_name}" == "TM1")
+BuildRequires:  pkgconfig(libdrm_sprd)
+%endif
 
 %description
 Pepper is a lightweight and flexible library for developing various types of wayland compositors.
index 1eab579..856878c 100644 (file)
 * DEALINGS IN THE SOFTWARE.
 */
 
+#include <config.h>
 #include <libudev.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include "drm-internal.h"
+#ifdef HAVE_DRM_SPRD
+#include <sprd_drmif.h>
+struct sprd_drm_device *sprd_dev = NULL;
+#endif
 
 static struct udev_device *
 find_primary_gpu(struct udev *udev) /* FIXME: copied from weston */
@@ -82,6 +87,53 @@ find_primary_gpu(struct udev *udev) /* FIXME: copied from weston */
     return drm_device;
 }
 
+#ifdef HAVE_DRM_SPRD
+static void
+drm_sprd_init(int fd)
+{
+    drmVersionPtr drm_info;
+    int drmIRQ = 78;
+    int length = 0;
+
+    if (sprd_dev)
+    {
+        return;
+    }
+
+    drm_info = drmGetVersion(fd);
+    length = drm_info->name_len;
+
+    if (length != 4)
+    {
+        drmFreeVersion(drm_info);
+        return;
+    }
+    if (strncmp("sprd", drm_info->name, 4))
+    {
+        drmFreeVersion(drm_info);
+        return;
+    }
+    drmFreeVersion(drm_info);
+
+    PEPPER_CHECK(!drmCtlInstHandler(fd, drmIRQ), return, "drmCtlInstHandler() failed.\n");
+
+    sprd_dev = sprd_device_create(fd);
+    PEPPER_CHECK(sprd_dev, return, "sprd_device_create() failed.\n");
+
+    return;
+}
+
+static void
+drm_sprd_deinit(void)
+{
+    if (sprd_dev == NULL)
+        return;
+
+    sprd_device_destroy(sprd_dev);
+    sprd_dev = NULL;
+}
+#endif
+
 static int
 handle_drm_event(int fd, uint32_t mask, void *data)
 {
@@ -157,6 +209,11 @@ pepper_drm_create(pepper_compositor_t *compositor, struct udev *udev, const char
     drm->fd = open(filepath, O_RDWR | O_CLOEXEC);
     PEPPER_CHECK(drm->fd != -1, goto error, "open(%s, O_RDWR | O_CLOEXEC) failed.\n", filepath);
 
+#ifdef HAVE_DRM_SPRD
+    /*If drm is sprd, this fuction MUST call before other drm function*/
+    drm_sprd_init(drm->fd);
+#endif
+
     ret = fstat(drm->fd, &s);
     PEPPER_CHECK(ret != -1, goto error, "fstat() failed %s.\n", filepath);
 
@@ -266,6 +323,10 @@ pepper_drm_destroy(pepper_drm_t *drm)
     if (drm->udev_monitor)
         udev_monitor_unref(drm->udev_monitor);
 
+#ifdef HAVE_DRM_SPRD
+    drm_sprd_deinit();
+#endif
+
     if (drm->fd != -1)
         close(drm->fd);
 
index 5c6879a..6863270 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <libudev.h>
 
+#include <config.h>
 #include <pepper.h>
 #include <pepper-libinput.h>
 #include <pepper-drm.h>
@@ -81,13 +82,6 @@ main(int argc, char **argv)
     int                     tty;
     const char             *tty_str;
 
-    {   /* for gdb attach */
-        char cc;
-        int  ret;
-
-        ret = scanf("%c", &cc);
-    }
-
     init_signals();
 
     tty_str = getenv("PEPPER_DRM_TTY");