summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Sliwa <dominik.sliwa@toradex.com>2016-12-15 14:22:05 +0100
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>2017-01-11 12:03:36 +0100
commit74a74be23feb5d44121f059e1ab96787be4b7532 (patch)
treefece7a2f7713323611ee79af38a34b98b8fd6446
parent66898c40b3772c19d8d076c4fac6324379e72629 (diff)
apalis-tk1: Mainline kernel machine
This patch adds mainline linux based Apalis TK1 machine. It includes compatible recipes for libdrm, mesa, Xorg, and weston. Signed-off-by: Dominik Sliwa <dominik.sliwa@toradex.com> Acked-by: Max Krummenacher <max.krummenacher@toradex.com>
-rw-r--r--conf/machine/apalis-tk1-mainline.conf50
-rw-r--r--recipes-bsp/u-boot/files/tegra124m/fw_env.config15
-rw-r--r--recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch82
-rw-r--r--recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch51
-rw-r--r--recipes-graphics/drm/libdrm_%.bbappend16
-rw-r--r--recipes-graphics/mesa/mesa_%.bbappend6
-rw-r--r--recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch181
-rw-r--r--recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch195
-rw-r--r--recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch48
-rw-r--r--recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch73
-rw-r--r--recipes-graphics/wayland/weston_%.bbappend12
-rw-r--r--recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch145
-rw-r--r--recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch72
-rw-r--r--recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend20
-rw-r--r--recipes-kernel/linux-firmware/linux-firmware_%.bbappend10
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis-tk1-remove-spurious-new-lines.patch113
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis_t30-tk1-fix-pcie-clock-and-reset-not-conformi.patch147
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0001-toradex_apalis_tk1_t30-customize-defconfig.patch181
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0002-apalis-tk1-temp-alert-pull-up.patch34
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0002-igb-integrate-tools-only-device-support.patch74
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis-tk1-optional-displayport-hot-plug-detect.patch29
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch136
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch114
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch52
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch37
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline-4.9/0006-apalis-tk1-update-compatibility-comment.patch30
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline.inc110
-rw-r--r--recipes-kernel/linux/linux-toradex-mainline_4.9.bb58
28 files changed, 2090 insertions, 1 deletions
diff --git a/conf/machine/apalis-tk1-mainline.conf b/conf/machine/apalis-tk1-mainline.conf
new file mode 100644
index 0000000..1b8cddf
--- /dev/null
+++ b/conf/machine/apalis-tk1-mainline.conf
@@ -0,0 +1,50 @@
+#@TYPE: Machine
+#@NAME: apalis-tk1-mainline
+#@DESCRIPTION: Toradex Apalis TK1 Mainline
+
+#require conf/machine/include/tegra-base.inc
+require conf/machine/include/soc-family.inc
+
+SOC_FAMILY = "tegra124m"
+
+PREFERRED_PROVIDER_virtual/kernel = "linux-toradex-mainline"
+
+KERNEL_IMAGETYPE = "uImage"
+KERNEL_DEFCONFIG = "tegra_defconfig"
+KERNEL_DEVICETREE += "tegra124-apalis-eval.dtb"
+
+PREFERRED_PROVIDER_u-boot = "u-boot-toradex"
+PREFERRED_PROVIDER_virtual/bootloader = "u-boot-toradex"
+UBOOT_MACHINE = "apalis-tk1_defconfig"
+UBOOT_ENTRYPOINT = "0x80008000"
+UBOOT_LOADADDRESS = "${UBOOT_ENTRYPOINT}"
+
+PREFERRED_PROVIDER_lxde-icon-theme_apalis-tk1-mainline = "lxde-icon-theme"
+PREFERRED_PROVIDER_lxsession-lite_apalis-tk1-mainline = "lxsession"
+PREFERRED_PROVIDER_virtual/psplash = "psplash-angstrom"
+PREFERRED_PROVIDER_psplash-support = "psplash-angstrom"
+
+PREFERRED_PROVIDER_virtual/xserver ?= "xserver-xorg"
+PREFERRED_VERSION_xserver-xorg_tegra124m = "99:1.18%"
+PREFERRED_PROVIDER_virtual/mesa ?= "mesa"
+PREFERRED_PROVIDER_virtual/libgl ?= "mesa"
+
+GALLIUMDRIVERS_append_armv7a =",nouveau"
+XSERVER ?= "xserver-xorg \
+ mesa-driver-nouveau \
+ xf86-input-evdev \
+ xf86-input-keyboard \
+ xf86-input-mouse \
+ xf86-video-modesetting \
+ "
+
+MACHINE_FEATURES = "screen usbgadget usbhost vfat ext2 alsa touchscreen wifi bluetooth 3g pci "
+MACHINE_EXTRA_RDEPENDS = "linux-firmware-nvidia"
+EXTRA_IMAGEDEPENDS += "u-boot"
+
+# used by sysvinit_2
+SERIAL_CONSOLE = "115200 ttyS0"
+IMAGE_FSTYPES ?= "tar.bz2"
+
+DEFAULTTUNE = "cortexa15hf-neon"
+require conf/machine/include/tune-cortexa15.inc
diff --git a/recipes-bsp/u-boot/files/tegra124m/fw_env.config b/recipes-bsp/u-boot/files/tegra124m/fw_env.config
new file mode 100644
index 0000000..5941da2
--- /dev/null
+++ b/recipes-bsp/u-boot/files/tegra124m/fw_env.config
@@ -0,0 +1,15 @@
+# Configuration file for fw_(printenv/setenv) utility.
+# Up to two entries are valid, in this case the redundant
+# environment sector is assumed present.
+# Device offset must be prefixed with 0x to be parsed as a hexadecimal value.
+# On a block device a negative offset is treated as a backwards offset from the
+# end of the device/partition, rather than a forwards offset from the start.
+
+# Apalis TK1
+# U-Boot environment is stored at the end of the first eMMC boot partition
+# hence use a negative value. The environment is just in front of the config
+# block which occupies the last sector (hence -0x200)
+
+# Block device name Device offset Env. size
+/dev/mmcblk0boot0 -0x2200 0x2000
+
diff --git a/recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch b/recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch
new file mode 100644
index 0000000..36cc8e2
--- /dev/null
+++ b/recipes-graphics/drm/files/0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch
@@ -0,0 +1,82 @@
+From abfa680dbdfa4600105d904f4903c047d453cdb5 Mon Sep 17 00:00:00 2001
+From: "Kristian H. Kristensen" <hoegsberg@chromium.org>
+Date: Thu, 8 Sep 2016 13:08:59 -0700
+Subject: [PATCH] Add drmModeAddFB2WithModifiers() which takes format modifiers
+
+The only other user of this feature open codes the ioctl. Let's add an
+entry point for this to libdrm.
+
+Signed-off-by: Kristian H. Kristensen <hoegsberg@chromium.org>
+Reviewed-by: Rob Clark <robdclark@gmail.com>
+---
+ xf86drmMode.c | 21 +++++++++++++++++----
+ xf86drmMode.h | 7 +++++++
+ 2 files changed, 24 insertions(+), 4 deletions(-)
+
+diff --git a/xf86drmMode.c b/xf86drmMode.c
+index f7b5948..228c6e4 100644
+--- a/xf86drmMode.c
++++ b/xf86drmMode.c
+@@ -270,10 +270,10 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
+ return 0;
+ }
+
+-int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+- uint32_t pixel_format, uint32_t bo_handles[4],
+- uint32_t pitches[4], uint32_t offsets[4],
+- uint32_t *buf_id, uint32_t flags)
++int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height,
++ uint32_t pixel_format, uint32_t bo_handles[4],
++ uint32_t pitches[4], uint32_t offsets[4],
++ uint64_t modifier[4], uint32_t *buf_id, uint32_t flags)
+ {
+ struct drm_mode_fb_cmd2 f;
+ int ret;
+@@ -286,6 +286,8 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+ memcpy(f.handles, bo_handles, 4 * sizeof(bo_handles[0]));
+ memcpy(f.pitches, pitches, 4 * sizeof(pitches[0]));
+ memcpy(f.offsets, offsets, 4 * sizeof(offsets[0]));
++ if (modifier)
++ memcpy(f.modifier, modifier, 4 * sizeof(modifier[0]));
+
+ if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
+ return ret;
+@@ -294,6 +296,17 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+ return 0;
+ }
+
++int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
++ uint32_t pixel_format, uint32_t bo_handles[4],
++ uint32_t pitches[4], uint32_t offsets[4],
++ uint32_t *buf_id, uint32_t flags)
++{
++ return drmModeAddFB2WithModifiers(fd, width, height,
++ pixel_format, bo_handles,
++ pitches, offsets, NULL,
++ buf_id, flags);
++}
++
+ int drmModeRmFB(int fd, uint32_t bufferId)
+ {
+ return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
+diff --git a/xf86drmMode.h b/xf86drmMode.h
+index 4de7bbb..1a02fed 100644
+--- a/xf86drmMode.h
++++ b/xf86drmMode.h
+@@ -369,6 +369,13 @@ extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
+ uint32_t pixel_format, uint32_t bo_handles[4],
+ uint32_t pitches[4], uint32_t offsets[4],
+ uint32_t *buf_id, uint32_t flags);
++
++/* ...with format modifiers */
++int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height,
++ uint32_t pixel_format, uint32_t bo_handles[4],
++ uint32_t pitches[4], uint32_t offsets[4],
++ uint64_t modifier[4], uint32_t *buf_id, uint32_t flags);
++
+ /**
+ * Destroies the given framebuffer.
+ */
+--
+2.9.3
+
diff --git a/recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch b/recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch
new file mode 100644
index 0000000..19e69aa
--- /dev/null
+++ b/recipes-graphics/drm/files/0001-sync-kernel-UAPI.patch
@@ -0,0 +1,51 @@
+From 9bfdb183a7c50266caa97e5fcbabeaf54db6c2a1 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Tue, 20 Sep 2016 11:33:51 +0900
+Subject: [PATCH] sync kernel UAPI
+
+---
+ include/drm/drm_fourcc.h | 23 +++++++++++++++++++++++
+ 1 file changed, 23 insertions(+)
+
+diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
+index 4d8da69..7fed8a2 100644
+--- a/include/drm/drm_fourcc.h
++++ b/include/drm/drm_fourcc.h
+@@ -26,6 +26,10 @@
+
+ #include "drm.h"
+
++#if defined(__cplusplus)
++extern "C" {
++#endif
++
+ #define fourcc_code(a, b, c, d) ((__u32)(a) | ((__u32)(b) << 8) | \
+ ((__u32)(c) << 16) | ((__u32)(d) << 24))
+
+@@ -229,4 +233,23 @@
+ */
+ #define DRM_FORMAT_MOD_SAMSUNG_64_32_TILE fourcc_mod_code(SAMSUNG, 1)
+
++
++/* NVIDIA Frame buffer modifiers */
++
++#define NV_FORMAT_MOD_TEGRA_SHIFT 32
++
++#define NV_FORMAT_MOD_TEGRA_TILED \
++ fourcc_mod_code(NV, 1ULL << NV_FORMAT_MOD_TEGRA_SHIFT)
++
++#define NV_FORMAT_MOD_TEGRA_BLOCK_MASK \
++ fourcc_mod_code(NV, 2ULL << NV_FORMAT_MOD_TEGRA_SHIFT)
++#define NV_FORMAT_MOD_TEGRA_BLOCK_VALUE(m) \
++ (m & ((1ULL << NV_FORMAT_MOD_TEGRA_SHIFT) - 1))
++#define NV_FORMAT_MOD_TEGRA_BLOCK(v) \
++ (NV_FORMAT_MOD_TEGRA_BLOCK_MASK | NV_FORMAT_MOD_TEGRA_BLOCK_VALUE(v))
++
++#if defined(__cplusplus)
++}
++#endif
++
+ #endif /* DRM_FOURCC_H */
+--
+2.9.3
+
diff --git a/recipes-graphics/drm/libdrm_%.bbappend b/recipes-graphics/drm/libdrm_%.bbappend
new file mode 100644
index 0000000..c035f18
--- /dev/null
+++ b/recipes-graphics/drm/libdrm_%.bbappend
@@ -0,0 +1,16 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
+
+SRC_URI += "\
+ file://0001-Add-drmModeAddFB2WithModifiers-which-takes-format-mo.patch \
+ file://0001-sync-kernel-UAPI.patch \
+ "
+PACKAGES += "\
+ ${PN}-tegra \
+ \
+ "
+FILES_${PN}-tegra = "${libdir}/libdrm_tegra.so.*"
+
+EXTRA_OECONF_append += "\
+ --enable-tegra-experimental-api \
+ "
+
diff --git a/recipes-graphics/mesa/mesa_%.bbappend b/recipes-graphics/mesa/mesa_%.bbappend
index b63e8f2..52b9e33 100644
--- a/recipes-graphics/mesa/mesa_%.bbappend
+++ b/recipes-graphics/mesa/mesa_%.bbappend
@@ -20,8 +20,12 @@ DEPENDS_REMOVE = "linux-driver-package"
DEPENDS_REMOVE_tegra124 = ""
DEPENDS_remove = "${DEPENDS_REMOVE}"
+#####
+## Tegra TK1 mainline kernel
+
+PACKAGECONFIG_append_tegra124m = "dri3 egl gles gallium "
# until meta-jetson-tk1 adds it through its bbappend:
DEPENDS_append_tegra124= " linux-driver-package "
-SRC_URI_append_tegra123 = " tegra-path-add.patch" \ No newline at end of file
+SRC_URI_append_tegra123 = " tegra-path-add.patch"
diff --git a/recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch b/recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch
new file mode 100644
index 0000000..cbd2cd5
--- /dev/null
+++ b/recipes-graphics/wayland/files/0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch
@@ -0,0 +1,181 @@
+From 0719ed96aa2c41afe342f4c3c19e4ca91f270be2 Mon Sep 17 00:00:00 2001
+From: James Thomas <james.thomas@codethink.co.uk>
+Date: Fri, 20 Jun 2014 12:12:26 +0100
+Subject: [PATCH 1/6] compositor-drm: Add new gbm struct to allow for a
+ separate gbm device
+
+This is needed for devices like tegra jetson where the gbm device is not
+the same as the drm device
+---
+ src/compositor-drm.c | 48 +++++++++++++++++++++++++++---------------------
+ 1 file changed, 27 insertions(+), 21 deletions(-)
+
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 893877d..5db86dc 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -90,8 +90,11 @@ struct drm_backend {
+ int fd;
+ char *filename;
+ } drm;
+- struct gbm_device *gbm;
+- uint32_t *crtcs;
++ struct {
++ int fd;
++ char *filename;
++ } gbm;
++ struct gbm_device *gbm_device; uint32_t *crtcs;
+ int num_crtcs;
+ uint32_t crtc_allocator;
+ uint32_t connector_allocator;
+@@ -478,7 +481,7 @@ drm_output_prepare_scanout_view(struct drm_output *output,
+
+ if (ev->geometry.x != output->base.x ||
+ ev->geometry.y != output->base.y ||
+- buffer == NULL || b->gbm == NULL ||
++ buffer == NULL || b->gbm_device == NULL ||
+ buffer->width != output->base.current_mode->width ||
+ buffer->height != output->base.current_mode->height ||
+ output->base.transform != viewport->buffer.transform ||
+@@ -488,7 +491,7 @@ drm_output_prepare_scanout_view(struct drm_output *output,
+ if (ev->geometry.scissor_enabled)
+ return NULL;
+
+- bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
++ bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_WL_BUFFER,
+ buffer->resource, GBM_BO_USE_SCANOUT);
+
+ /* Unable to use the buffer for scanout */
+@@ -923,7 +926,7 @@ drm_output_prepare_overlay_view(struct drm_output *output,
+ uint32_t format;
+ wl_fixed_t sx1, sy1, sx2, sy2;
+
+- if (b->gbm == NULL)
++ if (b->gbm_device == NULL)
+ return NULL;
+
+ if (viewport->buffer.transform != output->base.transform)
+@@ -985,13 +988,13 @@ drm_output_prepare_overlay_view(struct drm_output *output,
+ if (dmabuf->attributes.n_planes != 1 || dmabuf->attributes.offset[0] != 0)
+ return NULL;
+
+- bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_FD, &gbm_dmabuf,
++ bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_FD, &gbm_dmabuf,
+ GBM_BO_USE_SCANOUT);
+ #else
+ return NULL;
+ #endif
+ } else {
+- bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
++ bo = gbm_bo_import(b->gbm_device, GBM_BO_IMPORT_WL_BUFFER,
+ buffer_resource, GBM_BO_USE_SCANOUT);
+ }
+ if (!bo)
+@@ -1091,7 +1094,7 @@ drm_output_prepare_cursor_view(struct drm_output *output,
+ if (ev->transform.enabled &&
+ (ev->transform.matrix.type > WESTON_MATRIX_TRANSFORM_TRANSLATE))
+ return NULL;
+- if (b->gbm == NULL)
++ if (b->gbm_device == NULL)
+ return NULL;
+ if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
+ return NULL;
+@@ -1493,6 +1496,9 @@ init_drm(struct drm_backend *b, struct udev_device *device)
+ b->drm.fd = fd;
+ b->drm.filename = strdup(filename);
+
++ b->gbm.fd = fd;
++ b->gbm.filename = b->drm.filename;
++
+ ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
+ if (ret == 0 && cap == 1)
+ clk_id = CLOCK_MONOTONIC;
+@@ -1579,7 +1585,7 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
+ n_formats = 3;
+ if (gl_renderer->create(b->compositor,
+ EGL_PLATFORM_GBM_KHR,
+- (void *)b->gbm,
++ (void *)b->gbm_device,
+ gl_renderer->opaque_attribs,
+ format,
+ n_formats) < 0) {
+@@ -1592,13 +1598,13 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
+ static int
+ init_egl(struct drm_backend *b)
+ {
+- b->gbm = create_gbm_device(b->drm.fd);
++ b->gbm_device = create_gbm_device(b->gbm.fd);
+
+- if (!b->gbm)
++ if (!b->gbm_device)
+ return -1;
+
+ if (drm_backend_create_gl_renderer(b) < 0) {
+- gbm_device_destroy(b->gbm);
++ gbm_device_destroy(b->gbm_device);
+ return -1;
+ }
+
+@@ -1831,7 +1837,7 @@ drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
+ };
+ int i, flags, n_formats = 1;
+
+- output->gbm_surface = gbm_surface_create(b->gbm,
++ output->gbm_surface = gbm_surface_create(b->gbm_device,
+ output->base.current_mode->width,
+ output->base.current_mode->height,
+ format[0],
+@@ -1862,7 +1868,7 @@ drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
+ continue;
+
+ output->gbm_cursor_bo[i] =
+- gbm_bo_create(b->gbm, b->cursor_width, b->cursor_height,
++ gbm_bo_create(b->gbm_device, b->cursor_width, b->cursor_height,
+ GBM_FORMAT_ARGB8888, flags);
+ }
+
+@@ -2703,8 +2709,8 @@ drm_destroy(struct weston_compositor *ec)
+
+ weston_compositor_shutdown(ec);
+
+- if (b->gbm)
+- gbm_device_destroy(b->gbm);
++ if (b->gbm_device)
++ gbm_device_destroy(b->gbm_device);
+
+ weston_launcher_destroy(ec->launcher);
+
+@@ -2989,8 +2995,8 @@ switch_to_gl_renderer(struct drm_backend *b)
+
+ weston_log("Switching to GL renderer\n");
+
+- b->gbm = create_gbm_device(b->drm.fd);
+- if (!b->gbm) {
++ b->gbm_device = create_gbm_device(b->drm.fd);
++ if (!b->gbm_device) {
+ weston_log("Failed to create gbm device. "
+ "Aborting renderer switch\n");
+ return;
+@@ -3002,7 +3008,7 @@ switch_to_gl_renderer(struct drm_backend *b)
+ b->compositor->renderer->destroy(b->compositor);
+
+ if (drm_backend_create_gl_renderer(b) < 0) {
+- gbm_device_destroy(b->gbm);
++ gbm_device_destroy(b->gbm_device);
+ weston_log("Failed to create GL renderer. Quitting.\n");
+ /* FIXME: we need a function to shutdown cleanly */
+ assert(0);
+@@ -3191,8 +3197,8 @@ err_drm_source:
+ err_udev_input:
+ udev_input_destroy(&b->input);
+ err_sprite:
+- if (b->gbm)
+- gbm_device_destroy(b->gbm);
++ if (b->gbm_device)
++ gbm_device_destroy(b->gbm_device);
+ destroy_sprites(b);
+ err_udev_dev:
+ udev_device_unref(drm_device);
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch b/recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch
new file mode 100644
index 0000000..83aafe7
--- /dev/null
+++ b/recipes-graphics/wayland/files/0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch
@@ -0,0 +1,195 @@
+From 22cbce65feeb49f547f412ab77a9430773b692b8 Mon Sep 17 00:00:00 2001
+From: James Thomas <james.thomas@codethink.co.uk>
+Date: Fri, 20 Jun 2014 12:42:32 +0000
+Subject: [PATCH 2/6] compositor-drm: Add support for Tegra Jetson TK1
+
+Update configure.ac to add check for libdrm_tegra
+---
+ configure.ac | 18 ++++++++++
+ src/compositor-drm.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++--
+ 2 files changed, 109 insertions(+), 3 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 97a7769..fbb2c8c 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -133,6 +133,23 @@ fi
+ PKG_CHECK_MODULES(LIBDRM, [libdrm],
+ [AC_DEFINE(HAVE_LIBDRM, 1, [Define if libdrm is available]) have_libdrm=yes], have_libdrm=no)
+
++AC_ARG_ENABLE(libdrm-tegra,
++ AS_HELP_STRING([--disable-libdrm-tegra],
++ [do not build support for nvidia Jetson TK1]),,
++ enable_libdrm_tegra=auto)
++
++if test "x$enable_libdrm_tegra" != "xno"; then
++ PKG_CHECK_MODULES(LIBDRM_TEGRA,
++ libdrm_tegra,
++ have_libdrm_tegra=yes,
++ have_libdrm_tegra=no)
++ if test "x$have_libdrm_tegra" = "xno" -a "x$enable_libdrm_tegra" = "xyes"; then
++ AC_MSG_ERROR([Tegra support explicitly requested, but libdrm_tegra not found])
++ fi
++ AS_IF([test "x$have_libdrm_tegra" = "xyes"],
++ AC_DEFINE([HAVE_DRM_TEGRA], [1], [Enable tegra support in drm backend]))
++fi
++
+ AC_ARG_ENABLE(x11-compositor, [ --enable-x11-compositor],,
+ enable_x11_compositor=yes)
+ AM_CONDITIONAL(ENABLE_X11_COMPOSITOR, test x$enable_x11_compositor = xyes)
+@@ -699,4 +716,5 @@ AC_MSG_RESULT([
+ libwebp Support ${have_webp}
+ libunwind Support ${have_libunwind}
+ VA H.264 encoding Support ${have_libva}
++ Tegra DRM Support ${have_libdrm_tegra}
+ ])
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 5db86dc..90cae10 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -45,6 +45,9 @@
+
+ #include <gbm.h>
+ #include <libudev.h>
++#ifdef HAVE_DRM_TEGRA
++#include <tegra_drm.h>
++#endif
+
+ #include "compositor.h"
+ #include "compositor-drm.h"
+@@ -226,6 +229,32 @@ static struct gl_renderer_interface *gl_renderer;
+
+ static const char default_seat[] = "seat0";
+
++static int
++drm_tegra_import(int fd, uint32_t handle)
++{
++ #ifdef HAVE_DRM_TEGRA
++ struct drm_tegra_gem_set_tiling args;
++ int err;
++
++ memset(&args, 0, sizeof(args));
++ args.handle = handle;
++ args.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
++ args.value = 4;
++
++ err = ioctl(fd, DRM_IOCTL_TEGRA_GEM_SET_TILING, &args);
++ if (err < 0) {
++ weston_log("failed to set tiling parameters: %m\n");
++ return -errno;
++ }
++ return 0;
++ #else
++ weston_log("DRM device is a tegra but weston compiled without "
++ "libdrm tegra");
++
++ return -1;
++ #endif
++}
++
+ static void
+ drm_output_set_cursor(struct drm_output *output);
+
+@@ -368,6 +397,32 @@ drm_fb_get_from_bo(struct gbm_bo *bo,
+ fb->size = fb->stride * height;
+ fb->fd = backend->drm.fd;
+
++ if (backend->drm.fd != backend->gbm.fd) {
++ int fd;
++
++ ret = drmPrimeHandleToFD(backend->gbm.fd, fb->handle, 0,
++ &fd);
++ if (ret) {
++ weston_log("failed to export bo: %m\n");
++ goto err_free;
++ }
++
++ ret = drmPrimeFDToHandle(backend->drm.fd, fd, &fb->handle);
++ if (ret) {
++ weston_log("failed to import bo: %m\n");
++ goto err_free;
++ }
++
++ close(fd);
++
++ ret = drm_tegra_import(backend->drm.fd, fb->handle);
++ if (ret < 0) {
++ weston_log("failed to import handle: %s\n",
++ strerror(-ret));
++ goto err_free;
++ }
++ }
++
+ if (backend->min_width > width || width > backend->max_width ||
+ backend->min_height > height ||
+ height > backend->max_height) {
+@@ -1496,8 +1551,14 @@ init_drm(struct drm_backend *b, struct udev_device *device)
+ b->drm.fd = fd;
+ b->drm.filename = strdup(filename);
+
+- b->gbm.fd = fd;
+- b->gbm.filename = b->drm.filename;
++ if (b->gbm.filename) {
++ fd = weston_launcher_open(b->compositor->launcher, b->gbm.filename,
++ O_RDWR);
++ b->gbm.fd = fd;
++ } else {
++ b->gbm.fd = fd;
++ b->gbm.filename = b->drm.filename;
++ }
+
+ ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
+ if (ret == 0 && cap == 1)
+@@ -2808,7 +2869,7 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ struct udev_enumerate *e;
+ struct udev_list_entry *entry;
+ const char *path, *device_seat, *id;
+- struct udev_device *device, *drm_device, *pci;
++ struct udev_device *device, *drm_device, *pci, *soc = NULL;
+
+ e = udev_enumerate_new(b->udev);
+ udev_enumerate_add_match_subsystem(e, "drm");
+@@ -2818,6 +2879,7 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ drm_device = NULL;
+ udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+ path = udev_list_entry_get_name(entry);
++ weston_log("udev path = %s\n", path);
+ device = udev_device_new_from_syspath(b->udev, path);
+ if (!device)
+ continue;
+@@ -2839,6 +2901,32 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ drm_device = device;
+ break;
+ }
++ } else {
++ soc = udev_device_get_parent_with_subsystem_devtype(
++ device,
++ "soc",
++ NULL);
++ if (soc) {
++ id = udev_device_get_sysattr_value(soc,
++ "family");
++ if (id && !strcmp(id, "Tegra")) {
++ if (drm_device) {
++ /* Previously have found the
++ * drm device, use this device
++ * as the GBM device
++ */
++ if (udev_device_get_devnode(
++ device)) {
++ b->gbm.filename = strdup(
++ udev_device_get_devnode(device));
++ break;
++ }
++ continue;
++ }
++ drm_device = device;
++ continue;
++ }
++ }
+ }
+
+ if (!drm_device)
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch b/recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch
new file mode 100644
index 0000000..c7426a4
--- /dev/null
+++ b/recipes-graphics/wayland/files/0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch
@@ -0,0 +1,48 @@
+From 412880dfeb9951f9e807ed36e293805bc97beb32 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Thu, 24 Sep 2015 13:19:02 +0900
+Subject: [PATCH 3/6] Add glFinish to DRM backend to avoid tearing
+
+---
+ Makefile.am | 3 ++-
+ src/compositor-drm.c | 2 ++
+ 2 files changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index 00b74e5..071d540 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -281,8 +281,9 @@ drm_backend_la_LIBADD = \
+ $(COMPOSITOR_LIBS) \
+ $(DRM_COMPOSITOR_LIBS) \
+ $(INPUT_BACKEND_LIBS) \
+- libshared.la \
+ $(CLOCK_GETTIME_LIBS) \
++ $(SIMPLE_EGL_CLIENT_LIBS) \
++ libshared.la -lrt \
+ libsession-helper.la
+ drm_backend_la_CFLAGS = \
+ $(COMPOSITOR_CFLAGS) \
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 90cae10..17ba640 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -715,6 +715,7 @@ drm_output_repaint(struct weston_output *output_base,
+ output_base->set_dpms(output_base, WESTON_DPMS_ON);
+ }
+
++ glFinish();
+ if (drmModePageFlip(backend->drm.fd, output->crtc_id,
+ output->next->fb_id,
+ DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
+@@ -838,6 +839,7 @@ drm_output_start_repaint_loop(struct weston_output *output_base)
+ */
+ fb_id = output->current->fb_id;
+
++ glFinish();
+ if (drmModePageFlip(backend->drm.fd, output->crtc_id, fb_id,
+ DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
+ weston_log("queueing pageflip failed: %m\n");
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch b/recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch
new file mode 100644
index 0000000..a5969ab
--- /dev/null
+++ b/recipes-graphics/wayland/files/0004-use-name-based-detection-of-display-and-render-nodes.patch
@@ -0,0 +1,73 @@
+From 6c8d3da72fabd2a915e18dbf9fb65b7c1134d65d Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Fri, 9 Sep 2016 15:06:27 +0900
+Subject: [PATCH 4/6] use name-based detection of display and render nodes
+
+The previous detection scheme assumed that the graphics nodes were under
+"soc0". This is no longer true for Jetson TX1. Instead, assume that
+card0 is the display node, and card1 the render one.
+---
+ src/compositor-drm.c | 39 ++++++++-------------------------------
+ 1 file changed, 8 insertions(+), 31 deletions(-)
+
+diff --git a/src/compositor-drm.c b/src/compositor-drm.c
+index 17ba640..214fc41 100644
+--- a/src/compositor-drm.c
++++ b/src/compositor-drm.c
+@@ -2871,7 +2871,7 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ struct udev_enumerate *e;
+ struct udev_list_entry *entry;
+ const char *path, *device_seat, *id;
+- struct udev_device *device, *drm_device, *pci, *soc = NULL;
++ struct udev_device *device, *drm_device, *pci;
+
+ e = udev_enumerate_new(b->udev);
+ udev_enumerate_add_match_subsystem(e, "drm");
+@@ -2904,37 +2904,14 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
+ break;
+ }
+ } else {
+- soc = udev_device_get_parent_with_subsystem_devtype(
+- device,
+- "soc",
+- NULL);
+- if (soc) {
+- id = udev_device_get_sysattr_value(soc,
+- "family");
+- if (id && !strcmp(id, "Tegra")) {
+- if (drm_device) {
+- /* Previously have found the
+- * drm device, use this device
+- * as the GBM device
+- */
+- if (udev_device_get_devnode(
+- device)) {
+- b->gbm.filename = strdup(
+- udev_device_get_devnode(device));
+- break;
+- }
+- continue;
+- }
+- drm_device = device;
+- continue;
+- }
+- }
++ id = udev_device_get_sysname(device);
++ if (!strcmp(id, "card0"))
++ drm_device = device;
++ else if (!strcmp(id, "card1"))
++ b->gbm.filename = strdup(udev_device_get_devnode(device));
++ else
++ udev_device_unref(device);
+ }
+-
+- if (!drm_device)
+- drm_device = device;
+- else
+- udev_device_unref(device);
+ }
+
+ udev_enumerate_unref(e);
+--
+2.9.3
+
diff --git a/recipes-graphics/wayland/weston_%.bbappend b/recipes-graphics/wayland/weston_%.bbappend
new file mode 100644
index 0000000..cb57c9b
--- /dev/null
+++ b/recipes-graphics/wayland/weston_%.bbappend
@@ -0,0 +1,12 @@
+FILESEXTRAPATHS_prepend_tegra124m := "${THISDIR}/files:"
+
+PACKAGE_ARCH_tegra124m = "${MACHINE_ARCH}"
+
+COMPATIBLE_MACHINE_tegra124m = "(apalis-tk1-mainline)"
+
+SRC_URI_append_tegra124m = "\
+ file://0001-compositor-drm-Add-new-gbm-struct-to-allow-for-a-sep.patch \
+ file://0002-compositor-drm-Add-support-for-Tegra-Jetson-TK1.patch \
+ file://0003-Add-glFinish-to-DRM-backend-to-avoid-tearing.patch \
+ file://0004-use-name-based-detection-of-display-and-render-nodes.patch \
+ "
diff --git a/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch
new file mode 100644
index 0000000..39b92e8
--- /dev/null
+++ b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0001-HACK-use-render-nodes-and-tegra-tiling-format.patch
@@ -0,0 +1,145 @@
+From c9ba24058a5cae32c8d8431911485fba7c6d3a14 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Thu, 24 Sep 2015 18:23:51 +0900
+Subject: [PATCH 1/7] [HACK] use render nodes and tegra tiling format
+
+---
+ glamor/glamor_egl.c | 5 +++
+ hw/xfree86/drivers/modesetting/drmmode_display.c | 56 ++++++++++++++++++++++--
+ hw/xfree86/drivers/modesetting/drmmode_display.h | 1 +
+ 3 files changed, 58 insertions(+), 4 deletions(-)
+
+diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
+index 5aacbed..b6941f2 100644
+--- a/glamor/glamor_egl.c
++++ b/glamor/glamor_egl.c
+@@ -809,6 +809,11 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
+ xf86GlamorEGLPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
+
+ scrn->privates[xf86GlamorEGLPrivateIndex].ptr = glamor_egl;
++
++
++ fd = open("/dev/dri/renderD128", O_RDWR);
++ xf86Msg(X_INFO, "Opening render node: %d\n", fd);
++
+ glamor_egl->fd = fd;
+ #ifdef GLAMOR_HAS_GBM
+ glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
+diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
+index 9c54310..9c9fa27 100644
+--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
++++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
+@@ -50,6 +50,8 @@
+
+ #include "driver.h"
+
++#include <tegra_drm.h>
++
+ static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
+
+ static Bool
+@@ -160,15 +162,61 @@ drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo)
+ }
+
+ static Bool
++drmmode_tegra_import(drmmode_ptr drmmode, drmmode_bo *bo)
++{
++ struct drm_tegra_gem_set_tiling args;
++ int err;
++
++ memset(&args, 0, sizeof(args));
++ args.handle = bo->drm_handle;
++ args.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
++ args.value = 4;
++
++ err = ioctl(drmmode->fd, DRM_IOCTL_TEGRA_GEM_SET_TILING, &args);
++ if (err < 0) {
++ xf86Msg(X_ERROR, "failed to set tiling parameters\n");
++ return FALSE;
++ }
++
++ return TRUE;
++}
++
++static Bool
+ drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
+ unsigned width, unsigned height, unsigned bpp)
+ {
+ #ifdef GLAMOR_HAS_GBM
++ uint32_t handle;
++ int fd;
++ int ret;
++
+ if (drmmode->glamor) {
+ bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
+ GBM_FORMAT_ARGB8888,
+ GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+- return bo->gbm != NULL;
++
++ if (bo->gbm == NULL)
++ return FALSE;
++
++ handle = gbm_bo_get_handle(bo->gbm).u32;
++
++ ret = drmPrimeHandleToFD(gbm_device_get_fd(drmmode->gbm), handle, 0, &fd);
++ if (ret) {
++ xf86Msg(X_ERROR, "failed to export bo\n");
++ return FALSE;
++ }
++
++ ret = drmPrimeFDToHandle(drmmode->fd, fd, &handle);
++ if (ret) {
++ xf86Msg(X_ERROR, "failed to import bo\n");
++ close(fd);
++ return FALSE;
++ }
++
++ close(fd);
++ bo->drm_handle = handle;
++
++ return drmmode_tegra_import(drmmode, bo);
+ }
+ #endif
+
+@@ -410,7 +458,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
+ pScrn->virtualX, pScrn->virtualY,
+ pScrn->depth, drmmode->kbpp,
+ drmmode_bo_get_pitch(&drmmode->front_bo),
+- drmmode_bo_get_handle(&drmmode->front_bo),
++ drmmode->front_bo.drm_handle,
+ &drmmode->fb_id);
+ if (ret < 0) {
+ ErrorF("failed to add fb %d\n", ret);
+@@ -712,7 +760,7 @@ drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
+ ret = drmModeAddFB(drmmode->fd, width, height, crtc->scrn->depth,
+ drmmode->kbpp,
+ drmmode_bo_get_pitch(&drmmode_crtc->rotate_bo),
+- drmmode_bo_get_handle(&drmmode_crtc->rotate_bo),
++ drmmode_crtc->rotate_bo.drm_handle,
+ &drmmode_crtc->rotate_fb_id);
+
+ if (ret) {
+@@ -1700,7 +1748,7 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
+
+ ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
+ scrn->bitsPerPixel, pitch,
+- drmmode_bo_get_handle(&drmmode->front_bo),
++ drmmode->front_bo.drm_handle,
+ &drmmode->fb_id);
+ if (ret)
+ goto fail;
+diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
+index 9139ed4..547fd0d 100644
+--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
++++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
+@@ -41,6 +41,7 @@ typedef struct {
+ #ifdef GLAMOR_HAS_GBM
+ struct gbm_bo *gbm;
+ #endif
++ uint32_t drm_handle;
+ } drmmode_bo;
+
+ typedef struct {
+--
+2.9.3
+
diff --git a/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch
new file mode 100644
index 0000000..f27c2a9
--- /dev/null
+++ b/recipes-graphics/xorg-xserver/xserver-xorg-1.18.4/0002-HACK-enable-GLX-with-DRI3.patch
@@ -0,0 +1,72 @@
+From 1baf53e2b345ae7d883d4fa6c74f09188ea53b51 Mon Sep 17 00:00:00 2001
+From: Alexandre Courbot <acourbot@nvidia.com>
+Date: Fri, 25 Sep 2015 14:37:01 +0900
+Subject: [PATCH 2/7] [HACK] enable GLX with DRI3
+
+---
+ glamor/glamor_egl.c | 5 ++++-
+ hw/xfree86/dri2/dri2.c | 5 ++++-
+ hw/xfree86/drivers/modesetting/dri2.c | 5 +++--
+ 3 files changed, 11 insertions(+), 4 deletions(-)
+
+diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
+index b6941f2..8d25171 100644
+--- a/glamor/glamor_egl.c
++++ b/glamor/glamor_egl.c
+@@ -724,6 +724,7 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
+ glamor_ctx->make_current = glamor_egl_make_current;
+
+ #ifdef DRI3
++ xf86Msg(X_INFO, "DRI3 capable: %d\n", glamor_egl->dri3_capable);
+ if (glamor_egl->dri3_capable) {
+ glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+ /* Tell the core that we have the interfaces for import/export
+@@ -740,7 +741,9 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
+ /* To do DRI3 device FD generation, we need to open a new fd
+ * to the same device we were handed in originally.
+ */
+- glamor_egl->device_path = drmGetDeviceNameFromFd(glamor_egl->fd);
++ //glamor_egl->device_path = drmGetDeviceNameFromFd(glamor_egl->fd);
++ glamor_egl->device_path = "/dev/dri/renderD128";
++ xf86Msg(X_INFO, "DRI3 device name: %s %d\n", glamor_egl->device_path, glamor_egl->fd);
+
+ if (!dri3_screen_init(screen, &glamor_dri3_info)) {
+ xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
+index d55be19..00c5c61 100644
+--- a/hw/xfree86/dri2/dri2.c
++++ b/hw/xfree86/dri2/dri2.c
+@@ -1334,9 +1334,12 @@ DRI2Connect(ClientPtr client, ScreenPtr pScreen,
+ return FALSE;
+
+ *driverName = ds->driverNames[driver_id];
+- *deviceName = ds->deviceName;
++ //*deviceName = ds->deviceName;
++ *deviceName = "/dev/dri/renderD128";
+ *fd = ds->fd;
+
++ xf86Msg(X_INFO, "%s: %s %s %d\n", __func__, *driverName, *deviceName, *fd);
++
+ if (client) {
+ DRI2ClientPtr dri2_client;
+ dri2_client = dri2ClientPrivate(client);
+diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
+index 83cb3e0..3834a01 100644
+--- a/hw/xfree86/drivers/modesetting/dri2.c
++++ b/hw/xfree86/drivers/modesetting/dri2.c
+@@ -831,9 +831,10 @@ ms_dri2_screen_init(ScreenPtr screen)
+ }
+
+ memset(&info, '\0', sizeof(info));
+- info.fd = ms->fd;
++ info.fd = gbm_device_get_fd(ms->drmmode.gbm);
++ //info.fd = ms->fd;
+ info.driverName = NULL; /* Compat field, unused. */
+- info.deviceName = drmGetDeviceNameFromFd(ms->fd);
++ info.deviceName = drmGetDeviceNameFromFd(info.fd);
+
+ info.version = 4;
+ info.CreateBuffer = ms_dri2_create_buffer;
+--
+2.9.3
+
diff --git a/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend b/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend
new file mode 100644
index 0000000..746f367
--- /dev/null
+++ b/recipes-graphics/xorg-xserver/xserver-xorg_1.18.4.bbappend
@@ -0,0 +1,20 @@
+# always latest and greatest.
+PE_tegra124m = "99"
+
+FILESEXTRAPATHS_prepend := "${THISDIR}/xserver-xorg-${PV}:"
+
+SRC_URI_append_tegra124m = "\
+ file://0001-HACK-use-render-nodes-and-tegra-tiling-format.patch \
+ file://0002-HACK-enable-GLX-with-DRI3.patch \
+ "
+PACKAGE_ARCH_tegra124m = "${MACHINE_ARCH}"
+
+COMPATIBLE_MACHINE_tegra124m = "(apalis-tk1-mainline)"
+
+# provided by xf86-input-evdev_2.10.0
+do_install_append () {
+ rm -f ${D}/usr/share/X11/xorg.conf.d/10-evdev.conf
+}
+
+PACKAGECONFIG_tegra124m ?= "dri2 dri3 xshmfence glamor xwayland udev ${XORG_CRYPTO} "
+
diff --git a/recipes-kernel/linux-firmware/linux-firmware_%.bbappend b/recipes-kernel/linux-firmware/linux-firmware_%.bbappend
new file mode 100644
index 0000000..6e91ec3
--- /dev/null
+++ b/recipes-kernel/linux-firmware/linux-firmware_%.bbappend
@@ -0,0 +1,10 @@
+LICENSE_${PN}-nvidia = "Firmware-nvidia"
+LICENSE_${PN}-nvidia-license = "Firmware-nvidia"
+
+PACKAGES_prepend = "\
+ ${PN}-nvidia-license ${PN}-nvidia \
+ "
+FILES_${PN}-nvidia-license = "/lib/firmware/LICENCE.nvidia"
+FILES_${PN}-nvidia = "/lib/firmware/nvidia"
+RDEPENDS_${PN}-nvidia += "${PN}-nvidia-license"
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis-tk1-remove-spurious-new-lines.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis-tk1-remove-spurious-new-lines.patch
new file mode 100644
index 0000000..d6615e9
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis-tk1-remove-spurious-new-lines.patch
@@ -0,0 +1,113 @@
+From 9986ed08d8135318f19a2f5906427bd816bace93 Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Tue, 22 Nov 2016 00:56:25 +0100
+Subject: [RESEND PATCH 1/6] apalis-tk1: remove spurious new lines
+
+Remove some spurious new lines.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+---
+
+ arch/arm/boot/dts/tegra124-apalis-eval.dts | 1 -
+ arch/arm/boot/dts/tegra124-apalis.dtsi | 12 ------------
+ 2 files changed, 13 deletions(-)
+
+diff --git a/arch/arm/boot/dts/tegra124-apalis-eval.dts b/arch/arm/boot/dts/tegra124-apalis-eval.dts
+index 653044a..2b5a0f3 100644
+--- a/arch/arm/boot/dts/tegra124-apalis-eval.dts
++++ b/arch/arm/boot/dts/tegra124-apalis-eval.dts
+@@ -232,7 +232,6 @@
+
+ backlight: backlight {
+ compatible = "pwm-backlight";
+-
+ /* BKL1_PWM */
+ pwms = <&pwm 3 5000000>;
+ brightness-levels = <255 231 223 207 191 159 127 0>;
+diff --git a/arch/arm/boot/dts/tegra124-apalis.dtsi b/arch/arm/boot/dts/tegra124-apalis.dtsi
+index 0819721..6aa4952 100644
+--- a/arch/arm/boot/dts/tegra124-apalis.dtsi
++++ b/arch/arm/boot/dts/tegra124-apalis.dtsi
+@@ -56,7 +56,6 @@
+
+ pcie-controller@01003000 {
+ status = "okay";
+-
+ avddio-pex-supply = <&vdd_1v05>;
+ avdd-pex-pll-supply = <&vdd_1v05>;
+ avdd-pll-erefe-supply = <&avdd_1v05>;
+@@ -85,7 +84,6 @@
+ hdmi@54280000 {
+ pll-supply = <&reg_1v05_avdd_hdmi_pll>;
+ vdd-supply = <&reg_3v3_avdd_hdmi>;
+-
+ nvidia,ddc-i2c-bus = <&hdmi_ddc>;
+ nvidia,hpd-gpio =
+ <&gpio TEGRA_GPIO(N, 7) GPIO_ACTIVE_HIGH>;
+@@ -1607,15 +1605,11 @@
+ compatible = "ams,as3722";
+ reg = <0x40>;
+ interrupts = <0 86 IRQ_TYPE_LEVEL_HIGH>;
+-
+ ams,system-power-controller;
+-
+ #interrupt-cells = <2>;
+ interrupt-controller;
+-
+ gpio-controller;
+ #gpio-cells = <2>;
+-
+ pinctrl-names = "default";
+ pinctrl-0 = <&as3722_default>;
+
+@@ -1790,7 +1784,6 @@
+ reg = <0x4c>;
+ interrupt-parent = <&gpio>;
+ interrupts = <TEGRA_GPIO(I, 6) IRQ_TYPE_LEVEL_LOW>;
+-
+ #thermal-sensor-cells = <1>;
+ };
+ };
+@@ -1823,7 +1816,6 @@
+ sata@70020000 {
+ phys = <&{/padctl@7009f000/pads/sata/lanes/sata-0}>;
+ phy-names = "sata-0";
+-
+ avdd-supply = <&vdd_1v05>;
+ hvdd-supply = <&reg_3v3>;
+ vddio-supply = <&vdd_1v05>;
+@@ -1837,7 +1829,6 @@
+ <&{/padctl@7009f000/pads/usb2/lanes/usb2-2}>,
+ <&{/padctl@7009f000/pads/pcie/lanes/pcie-0}>;
+ phy-names = "usb2-0", "usb3-1", "usb2-1", "usb2-2", "usb3-0";
+-
+ avddio-pex-supply = <&vdd_1v05>;
+ avdd-pll-erefe-supply = <&avdd_1v05>;
+ avdd-pll-utmip-supply = <&vddio_1v8>;
+@@ -1919,7 +1910,6 @@
+ usb2-0 {
+ status = "okay";
+ mode = "otg";
+-
+ vbus-supply = <&reg_usbo1_vbus>;
+ };
+
+@@ -1927,7 +1917,6 @@
+ usb2-1 {
+ status = "okay";
+ mode = "host";
+-
+ vbus-supply = <&reg_usbh_vbus>;
+ };
+
+@@ -1935,7 +1924,6 @@
+ usb2-2 {
+ status = "okay";
+ mode = "host";
+-
+ vbus-supply = <&reg_usbh_vbus>;
+ };
+
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis_t30-tk1-fix-pcie-clock-and-reset-not-conformi.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis_t30-tk1-fix-pcie-clock-and-reset-not-conformi.patch
new file mode 100644
index 0000000..c958ff6
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis_t30-tk1-fix-pcie-clock-and-reset-not-conformi.patch
@@ -0,0 +1,147 @@
+From a2286569bb02b2ef881302eedbd944f8482beabe Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Thu, 15 Dec 2016 10:24:58 +0100
+Subject: [PATCH 1/4] apalis_t30/tk1: fix pcie clock and reset not conforming
+ to specification
+
+Fix PCIe clock and reset not conforming to specification by moving PCIe
+reset handling including the PLX PEX 8605 errata 5 workaround from the
+board platform data into the right places timing wise in the PCIe driver
+itself.
+
+Also add a kernel command line argument to allow using the Apalis GPIO7
+as a regular GPIO rather than for above mentioned PLX PEX 8605
+workaround:
+
+pex_perst=0
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Acked-by: Dominik Sliwa <dominik.sliwa@toradex.com>
+(cherry picked from toradex_tk1_l4t_r21.5 commit
+3e2259b04c2e2c029f742e9dda06a3a2739977d4)
+(cherry picked from tegra commit
+a2f63805703b43d55d91ae17f10d0049bf0f625e)
+
+---
+
+ drivers/pci/host/pci-tegra.c | 83 ++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 83 insertions(+)
+
+diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
+index 8dfccf7..1452fe4 100644
+--- a/drivers/pci/host/pci-tegra.c
++++ b/drivers/pci/host/pci-tegra.c
+@@ -55,6 +55,34 @@
+ #include <asm/mach/map.h>
+ #include <asm/mach/pci.h>
+
++//#define CONFIG_MACH_APALIS_T30
++#define CONFIG_MACH_APALIS_TK1
++#if defined(CONFIG_MACH_APALIS_T30) || defined(CONFIG_MACH_APALIS_TK1)
++#include <linux/gpio.h>
++
++#include "../../../arch/arm/boot/dts/include/dt-bindings/gpio/tegra-gpio.h"
++
++#ifdef CONFIG_MACH_APALIS_T30
++#define APALIS_GPIO7 TEGRA_GPIO(S, 7)
++
++#define LAN_RESET_N -1
++
++#define PEX_PERST_N APALIS_GPIO7
++
++#define RESET_MOCI_N TEGRA_GPIO(I, 4)
++#endif
++
++#ifdef CONFIG_MACH_APALIS_TK1
++#define APALIS_GPIO7 TEGRA_GPIO(DD, 1)
++
++#define LAN_RESET_N TEGRA_GPIO(S, 2)
++
++#define PEX_PERST_N APALIS_GPIO7
++
++#define RESET_MOCI_N TEGRA_GPIO(U, 4)
++#endif
++#endif
++
+ #define INT_PCI_MSI_NR (8 * 32)
+
+ /* register definitions */
+@@ -322,6 +350,21 @@ struct tegra_pcie_bus {
+ unsigned int nr;
+ };
+
++#if defined(CONFIG_MACH_APALIS_T30) || defined(CONFIG_MACH_APALIS_TK1)
++/* To disable the PCIe switch reset errata workaround */
++int g_pex_perst = 1;
++
++/* To disable the PCIe switch reset errata workaround */
++static int __init disable_pex_perst(char *s)
++{
++ if (!(*s) || !strcmp(s, "0"))
++ g_pex_perst = 0;
++
++ return 0;
++}
++__setup("pex_perst=", disable_pex_perst);
++#endif /* CONFIG_MACH_APALIS_T30 || CONFIG_MACH_APALIS_TK1 */
++
+ static inline struct tegra_pcie *sys_to_pcie(struct pci_sys_data *sys)
+ {
+ return sys->private_data;
+@@ -528,6 +571,27 @@ static void tegra_pcie_port_reset(struct tegra_pcie_port *port)
+ unsigned long ctrl = tegra_pcie_port_get_pex_ctrl(port);
+ unsigned long value;
+
++#if defined(CONFIG_MACH_APALIS_T30) || defined(CONFIG_MACH_APALIS_TK1)
++ /*
++ * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on Apalis Evaluation
++ * Board
++ */
++ if (g_pex_perst)
++ gpio_request(PEX_PERST_N, "PEX_PERST_N");
++ gpio_request(RESET_MOCI_N, "RESET_MOCI_N");
++ if (g_pex_perst)
++ gpio_direction_output(PEX_PERST_N, 0);
++ gpio_direction_output(RESET_MOCI_N, 0);
++
++#ifdef CONFIG_MACH_APALIS_TK1
++ /* Reset I210 Gigabit Ethernet Controller */
++ if (LAN_RESET_N) {
++ gpio_request(LAN_RESET_N, "LAN_RESET_N");
++ gpio_direction_output(LAN_RESET_N, 0);
++ }
++#endif /* CONFIG_MACH_APALIS_TK1 */
++#endif /* CONFIG_MACH_APALIS_T30 || CONFIG_MACH_APALIS_TK1 */
++
+ /* pulse reset signal */
+ value = afi_readl(port->pcie, ctrl);
+ value &= ~AFI_PEX_CTRL_RST;
+@@ -538,6 +602,25 @@ static void tegra_pcie_port_reset(struct tegra_pcie_port *port)
+ value = afi_readl(port->pcie, ctrl);
+ value |= AFI_PEX_CTRL_RST;
+ afi_writel(port->pcie, value, ctrl);
++
++#if defined(CONFIG_MACH_APALIS_T30) || defined(CONFIG_MACH_APALIS_TK1)
++ /* Must be asserted for 100 ms after power and clocks are stable */
++ if (g_pex_perst)
++ gpio_set_value(PEX_PERST_N, 1);
++ /*
++ * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not Guaranteed Until
++ * 900 us After PEX_PERST# De-assertion
++ */
++ if (g_pex_perst)
++ mdelay(1);
++ gpio_set_value(RESET_MOCI_N, 1);
++
++#ifdef CONFIG_MACH_APALIS_TK1
++ /* Release I210 Gigabit Ethernet Controller Reset */
++ if (LAN_RESET_N)
++ gpio_set_value(LAN_RESET_N, 1);
++#endif /* CONFIG_MACH_APALIS_TK1 */
++#endif /* CONFIG_MACH_APALIS_T30 || CONFIG_MACH_APALIS_TK1 */
+ }
+
+ static void tegra_pcie_port_enable(struct tegra_pcie_port *port)
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-toradex_apalis_tk1_t30-customize-defconfig.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-toradex_apalis_tk1_t30-customize-defconfig.patch
new file mode 100644
index 0000000..6f1a010
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-toradex_apalis_tk1_t30-customize-defconfig.patch
@@ -0,0 +1,181 @@
+From dbb1d8b04577f892dbaa0a5d086a0ec2c08dc00f Mon Sep 17 00:00:00 2001
+From: Dominik Sliwa <dominik.sliwa@toradex.com>
+Date: Thu, 15 Dec 2016 10:40:06 +0100
+Subject: [PATCH] toradex_apalis_tk1_t30: customize defconfig
+
+---
+ arch/arm/configs/tegra_defconfig | 45 ++++++++++++++++++++++++----------------
+ 1 file changed, 27 insertions(+), 18 deletions(-)
+
+diff --git a/arch/arm/configs/tegra_defconfig b/arch/arm/configs/tegra_defconfig
+index 6012a1e..48f87cd 100644
+--- a/arch/arm/configs/tegra_defconfig
++++ b/arch/arm/configs/tegra_defconfig
+@@ -1,16 +1,15 @@
+ CONFIG_SYSVIPC=y
+-CONFIG_FHANDLE=y
+ CONFIG_IRQ_DOMAIN_DEBUG=y
+ CONFIG_NO_HZ=y
+ CONFIG_HIGH_RES_TIMERS=y
+ CONFIG_IKCONFIG=y
+ CONFIG_IKCONFIG_PROC=y
+ CONFIG_CGROUPS=y
+-CONFIG_CGROUP_DEBUG=y
+-CONFIG_CGROUP_FREEZER=y
+-CONFIG_CGROUP_CPUACCT=y
+ CONFIG_CGROUP_SCHED=y
+ CONFIG_RT_GROUP_SCHED=y
++CONFIG_CGROUP_FREEZER=y
++CONFIG_CGROUP_CPUACCT=y
++CONFIG_CGROUP_DEBUG=y
+ CONFIG_BLK_DEV_INITRD=y
+ # CONFIG_ELF_CORE is not set
+ CONFIG_EMBEDDED=y
+@@ -24,14 +23,10 @@ CONFIG_PARTITION_ADVANCED=y
+ # CONFIG_IOSCHED_DEADLINE is not set
+ # CONFIG_IOSCHED_CFQ is not set
+ CONFIG_ARCH_TEGRA=y
+-CONFIG_ARCH_TEGRA_2x_SOC=y
+-CONFIG_ARCH_TEGRA_3x_SOC=y
+-CONFIG_ARCH_TEGRA_114_SOC=y
+-CONFIG_ARCH_TEGRA_124_SOC=y
+ CONFIG_PCI=y
++CONFIG_PCIEPORTBUS=y
+ CONFIG_PCI_MSI=y
+ CONFIG_PCI_TEGRA=y
+-CONFIG_PCIEPORTBUS=y
+ CONFIG_SMP=y
+ CONFIG_PREEMPT=y
+ CONFIG_AEABI=y
+@@ -41,7 +36,6 @@ CONFIG_ZBOOT_ROM_TEXT=0x0
+ CONFIG_ZBOOT_ROM_BSS=0x0
+ CONFIG_KEXEC=y
+ CONFIG_CPU_FREQ=y
+-CONFIG_CPU_FREQ_STAT_DETAILS=y
+ CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
+ CONFIG_CPUFREQ_DT=y
+ CONFIG_CPU_IDLE=y
+@@ -59,7 +53,6 @@ CONFIG_IP_PNP_RARP=y
+ CONFIG_INET_ESP=y
+ # CONFIG_INET_XFRM_MODE_TUNNEL is not set
+ # CONFIG_INET_XFRM_MODE_BEET is not set
+-# CONFIG_INET_LRO is not set
+ # CONFIG_INET_DIAG is not set
+ CONFIG_IPV6_ROUTER_PREF=y
+ CONFIG_IPV6_OPTIMISTIC_DAD=y
+@@ -110,9 +103,21 @@ CONFIG_USB_PEGASUS=y
+ CONFIG_USB_USBNET=y
+ CONFIG_USB_NET_SMSC75XX=y
+ CONFIG_USB_NET_SMSC95XX=y
++CONFIG_ATH9K=m
++CONFIG_ATH9K_CHANNEL_CONTEXT=y
++CONFIG_ATH9K_HTC=m
++CONFIG_ATH10K=m
++CONFIG_ATH10K_PCI=m
++# CONFIG_WLAN_VENDOR_ATMEL is not set
+ CONFIG_BRCMFMAC=m
++CONFIG_IWLWIFI=m
++CONFIG_IWLDVM=m
++CONFIG_IWLMVM=m
+ CONFIG_RT2X00=y
+ CONFIG_RT2800USB=m
++CONFIG_RTL_CARDS=m
++CONFIG_RTL8192CU=m
++CONFIG_RSI_91X=m
+ CONFIG_INPUT_JOYDEV=y
+ CONFIG_INPUT_EVDEV=y
+ CONFIG_KEYBOARD_GPIO=y
+@@ -131,8 +136,8 @@ CONFIG_INPUT_MPU3050=y
+ # CONFIG_DEVKMEM is not set
+ CONFIG_SERIAL_8250=y
+ CONFIG_SERIAL_8250_CONSOLE=y
+-CONFIG_SERIAL_TEGRA=y
+ CONFIG_SERIAL_OF_PLATFORM=y
++CONFIG_SERIAL_TEGRA=y
+ # CONFIG_HW_RANDOM is not set
+ # CONFIG_I2C_COMPAT is not set
+ CONFIG_I2C_CHARDEV=y
+@@ -151,11 +156,11 @@ CONFIG_GPIO_PCA953X_IRQ=y
+ CONFIG_GPIO_PALMAS=y
+ CONFIG_GPIO_TPS6586X=y
+ CONFIG_GPIO_TPS65910=y
+-CONFIG_BATTERY_SBS=y
+-CONFIG_CHARGER_TPS65090=y
+ CONFIG_POWER_RESET=y
+ CONFIG_POWER_RESET_AS3722=y
+ CONFIG_POWER_RESET_GPIO=y
++CONFIG_BATTERY_SBS=y
++CONFIG_CHARGER_TPS65090=y
+ CONFIG_SENSORS_LM90=y
+ CONFIG_SENSORS_LM95245=y
+ CONFIG_WATCHDOG=y
+@@ -188,6 +193,7 @@ CONFIG_USB_GSPCA=y
+ CONFIG_DRM=y
+ CONFIG_DRM_NOUVEAU=m
+ CONFIG_DRM_TEGRA=y
++CONFIG_DRM_TEGRA_STAGING=y
+ CONFIG_DRM_PANEL_SIMPLE=y
+ # CONFIG_LCD_CLASS_DEVICE is not set
+ # CONFIG_BACKLIGHT_GENERIC is not set
+@@ -216,9 +222,10 @@ CONFIG_SND_SOC_TEGRA_WM9712=y
+ CONFIG_SND_SOC_TEGRA_TRIMSLICE=y
+ CONFIG_SND_SOC_TEGRA_ALC5632=y
+ CONFIG_SND_SOC_TEGRA_MAX98090=y
++CONFIG_SND_SOC_TEGRA_SGTL5000=y
+ CONFIG_USB=y
+ CONFIG_USB_XHCI_HCD=y
+-CONFIG_USB_XHCI_TEGRA=y
++CONFIG_USB_XHCI_TEGRA=m
+ CONFIG_USB_EHCI_HCD=y
+ CONFIG_USB_EHCI_TEGRA=y
+ CONFIG_USB_ACM=y
+@@ -229,11 +236,9 @@ CONFIG_MMC_BLOCK_MINORS=16
+ CONFIG_MMC_SDHCI=y
+ CONFIG_MMC_SDHCI_PLTFM=y
+ CONFIG_MMC_SDHCI_TEGRA=y
+-CONFIG_NEW_LEDS=y
+ CONFIG_LEDS_CLASS=y
+ CONFIG_LEDS_GPIO=y
+ CONFIG_LEDS_PWM=y
+-CONFIG_LEDS_TRIGGERS=y
+ CONFIG_LEDS_TRIGGER_TIMER=y
+ CONFIG_LEDS_TRIGGER_ONESHOT=y
+ CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+@@ -253,6 +258,7 @@ CONFIG_RTC_DRV_TEGRA=y
+ CONFIG_DMADEVICES=y
+ CONFIG_TEGRA20_APB_DMA=y
+ CONFIG_STAGING=y
++CONFIG_R8188EU=m
+ CONFIG_SENSORS_ISL29018=y
+ CONFIG_SENSORS_ISL29028=y
+ CONFIG_MFD_NVEC=y
+@@ -262,6 +268,10 @@ CONFIG_NVEC_POWER=y
+ CONFIG_NVEC_PAZ00=y
+ CONFIG_TEGRA_IOMMU_GART=y
+ CONFIG_TEGRA_IOMMU_SMMU=y
++CONFIG_ARCH_TEGRA_2x_SOC=y
++CONFIG_ARCH_TEGRA_3x_SOC=y
++CONFIG_ARCH_TEGRA_114_SOC=y
++CONFIG_ARCH_TEGRA_124_SOC=y
+ CONFIG_MEMORY=y
+ CONFIG_IIO=y
+ CONFIG_AK8975=y
+@@ -286,6 +286,7 @@ CONFIG_EXT3_FS=y
+ CONFIG_EXT3_FS_POSIX_ACL=y
+ CONFIG_EXT3_FS_SECURITY=y
+ # CONFIG_DNOTIFY is not set
++CONFIG_AUTOFS4_FS=y
+ CONFIG_VFAT_FS=y
+ CONFIG_TMPFS=y
+ CONFIG_TMPFS_POSIX_ACL=y
+@@ -289,7 +299,6 @@ CONFIG_NLS_CODEPAGE_437=y
+ CONFIG_NLS_ISO8859_1=y
+ CONFIG_PRINTK_TIME=y
+ CONFIG_DEBUG_INFO=y
+-CONFIG_DEBUG_FS=y
+ CONFIG_MAGIC_SYSRQ=y
+ CONFIG_DEBUG_SLAB=y
+ CONFIG_DEBUG_VM=y
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-apalis-tk1-temp-alert-pull-up.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-apalis-tk1-temp-alert-pull-up.patch
new file mode 100644
index 0000000..be59f28
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-apalis-tk1-temp-alert-pull-up.patch
@@ -0,0 +1,34 @@
+From 34ef168249df6e467ecdb0333eef7f95f87ab195 Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Tue, 22 Nov 2016 00:57:47 +0100
+Subject: [RESEND PATCH 2/6] apalis-tk1: temp alert pull-up
+
+Pull-up GPIO_PI6 connected to TMP451's ALERT#/THERM2#.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+---
+
+ arch/arm/boot/dts/tegra124-apalis.dtsi | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/arch/arm/boot/dts/tegra124-apalis.dtsi b/arch/arm/boot/dts/tegra124-apalis.dtsi
+index 6aa4952..0534601 100644
+--- a/arch/arm/boot/dts/tegra124-apalis.dtsi
++++ b/arch/arm/boot/dts/tegra124-apalis.dtsi
+@@ -1151,11 +1151,11 @@
+ nvidia,enable-input = <TEGRA_PIN_DISABLE>;
+ };
+
+- /* GPIO_PI6 aka TEMP_ALERT_L */
++ /* GPIO_PI6 aka TMP451 ALERT#/THERM2# */
+ pi6 {
+ nvidia,pins = "pi6";
+ nvidia,function = "rsvd1";
+- nvidia,pull = <TEGRA_PIN_PULL_NONE>;
++ nvidia,pull = <TEGRA_PIN_PULL_UP>;
+ nvidia,tristate = <TEGRA_PIN_ENABLE>;
+ nvidia,enable-input = <TEGRA_PIN_ENABLE>;
+ };
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-igb-integrate-tools-only-device-support.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-igb-integrate-tools-only-device-support.patch
new file mode 100644
index 0000000..f4e85db
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-igb-integrate-tools-only-device-support.patch
@@ -0,0 +1,74 @@
+From 11901a29054e437c9f9241382512faf276f08df4 Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Thu, 15 Dec 2016 10:55:11 +0100
+Subject: [PATCH 2/4] igb: integrate tools only device support
+
+Springville/i211 with a blank Flash/iNVM use different PCI IDs. Extend
+the driver to load despite i210/i211 data sheets claiming tools only,
+not for driver.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Acked-by: Dominik Sliwa <dominik.sliwa@toradex.com>
+
+(cherry picked from toradex_tk1_l4t_r21.5 commit
+783780c43fd4e1473fb64790c8b9e0adb2be04a3)
+(cherry picked from tegra commit
+2c7123458270c9b3ec9b5ed668f9d55a7f8dbad9)
+
+---
+
+ drivers/net/ethernet/intel/igb/e1000_82575.c | 2 ++
+ drivers/net/ethernet/intel/igb/e1000_hw.h | 2 ++
+ drivers/net/ethernet/intel/igb/igb_main.c | 2 ++
+ 3 files changed, 6 insertions(+)
+
+diff --git a/drivers/net/ethernet/intel/igb/e1000_82575.c b/drivers/net/ethernet/intel/igb/e1000_82575.c
+index a61447f..53d9ae7 100644
+--- a/drivers/net/ethernet/intel/igb/e1000_82575.c
++++ b/drivers/net/ethernet/intel/igb/e1000_82575.c
+@@ -610,6 +610,7 @@ static s32 igb_get_invariants_82575(struct e1000_hw *hw)
+ case E1000_DEV_ID_I350_SGMII:
+ mac->type = e1000_i350;
+ break;
++ case E1000_DEV_ID_I210_TOOLS_ONLY:
+ case E1000_DEV_ID_I210_COPPER:
+ case E1000_DEV_ID_I210_FIBER:
+ case E1000_DEV_ID_I210_SERDES:
+@@ -618,6 +619,7 @@ static s32 igb_get_invariants_82575(struct e1000_hw *hw)
+ case E1000_DEV_ID_I210_SERDES_FLASHLESS:
+ mac->type = e1000_i210;
+ break;
++ case E1000_DEV_ID_I211_TOOLS_ONLY:
+ case E1000_DEV_ID_I211_COPPER:
+ mac->type = e1000_i211;
+ break;
+diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
+index 2fb2213..69ebb81 100644
+--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
++++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
+@@ -58,6 +58,8 @@ struct e1000_hw;
+ #define E1000_DEV_ID_I350_FIBER 0x1522
+ #define E1000_DEV_ID_I350_SERDES 0x1523
+ #define E1000_DEV_ID_I350_SGMII 0x1524
++#define E1000_DEV_ID_I210_TOOLS_ONLY 0x1531
++#define E1000_DEV_ID_I211_TOOLS_ONLY 0x1532
+ #define E1000_DEV_ID_I210_COPPER 0x1533
+ #define E1000_DEV_ID_I210_FIBER 0x1536
+ #define E1000_DEV_ID_I210_SERDES 0x1537
+diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
+index a761001..680abcd 100644
+--- a/drivers/net/ethernet/intel/igb/igb_main.c
++++ b/drivers/net/ethernet/intel/igb/igb_main.c
+@@ -77,7 +77,9 @@ static const struct pci_device_id igb_pci_tbl[] = {
+ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
+ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_SGMII) },
+ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
++ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_TOOLS_ONLY), board_82575 },
+ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_COPPER), board_82575 },
++ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_TOOLS_ONLY), board_82575 },
+ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER), board_82575 },
+ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_FIBER), board_82575 },
+ { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES), board_82575 },
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis-tk1-optional-displayport-hot-plug-detect.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis-tk1-optional-displayport-hot-plug-detect.patch
new file mode 100644
index 0000000..7adc524
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis-tk1-optional-displayport-hot-plug-detect.patch
@@ -0,0 +1,29 @@
+From 9172020334268e0e49478afd8a520554df3c612c Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Tue, 22 Nov 2016 00:58:26 +0100
+Subject: [RESEND PATCH 3/6] apalis-tk1: optional displayport hot-plug detect
+
+Configure DP_HPD_PFF0 pin as optional DisplayPort hot-plug detect.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+---
+
+ arch/arm/boot/dts/tegra124-apalis.dtsi | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/arch/arm/boot/dts/tegra124-apalis.dtsi b/arch/arm/boot/dts/tegra124-apalis.dtsi
+index 0534601..747ce81 100644
+--- a/arch/arm/boot/dts/tegra124-apalis.dtsi
++++ b/arch/arm/boot/dts/tegra124-apalis.dtsi
+@@ -255,7 +255,7 @@
+ };
+ dp_hpd_pff0 {
+ nvidia,pins = "dp_hpd_pff0";
+- nvidia,function = "rsvd2";
++ nvidia,function = "dp";
+ nvidia,pull = <TEGRA_PIN_PULL_NONE>;
+ nvidia,tristate = <TEGRA_PIN_DISABLE>;
+ nvidia,enable-input = <TEGRA_PIN_ENABLE>;
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch
new file mode 100644
index 0000000..cd53bc6
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch
@@ -0,0 +1,136 @@
+From 259b864ce38d18f7de945f957ee2e11ea4429812 Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Thu, 15 Dec 2016 10:55:54 +0100
+Subject: [PATCH 3/4] apalis_t30/tk1: igb: no nvm and Ethernet MAC address
+ handling
+
+Only warn rather than fail on NVM validation failures on Apalis T30 and
+Apalis TK1.
+
+Revise Ethernet MAC address assignment: should now handle up to two
+instances of custom user MACs (2nd one with a 0x100000 offset). This
+way customer does not have to worry about NVM on a secondary Ethernet
+on the carrier board and still gets a valid official MAC address from
+us (e.g. analogous to how we did it on our Protea carrier board).
+
+Use the Toradex OUI as default MAC address if no valid one is
+encountered.
+
+Tested on samples of Apalis T30 2GB V1.0B, V1.0C, V1.1A, Apalis T30 1GB
+V1.0A, V1.1A and Apalis T30 1GB IT V1.1A both with blank NVMs as well
+as iNVMs programmed with Intel's defaults.
+
+Tested on samples of Apalis TK1 2GB V1.0A, V1.0B and V1.1A both with
+blank NVMs as well as iNVMs programmed with Intel's defaults.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Acked-by: Dominik Sliwa <dominik.sliwa@toradex.com>
+
+(cherry picked from toradex_tk1_l4t_r21.5 commit
+70efa60d96c9f05d91d8875eee97446df7f9e877)
+(cherry picked from tegra commit
+c4c3c7449bdb15c53bfebb0a29c73b24ea810d23)
+
+---
+
+ drivers/net/ethernet/intel/igb/igb_main.c | 60 +++++++++++++++++++++++++++++--
+ 1 file changed, 57 insertions(+), 3 deletions(-)
+
+diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
+index 680abcd..3df0e4e 100644
+--- a/drivers/net/ethernet/intel/igb/igb_main.c
++++ b/drivers/net/ethernet/intel/igb/igb_main.c
+@@ -55,6 +55,7 @@
+ #include <linux/dca.h>
+ #endif
+ #include <linux/i2c.h>
++#include <linux/ctype.h>
+ #include "igb.h"
+
+ #define MAJ 5
+@@ -69,6 +70,9 @@ static const char igb_driver_string[] =
+ static const char igb_copyright[] =
+ "Copyright (c) 2007-2014 Intel Corporation.";
+
++static char g_mac_addr[ETH_ALEN];
++static int g_usr_mac = 0;
++
+ static const struct e1000_info *igb_info_tbl[] = {
+ [board_82575] = &e1000_82575_info,
+ };
+@@ -258,6 +262,37 @@ static int debug = -1;
+ module_param(debug, int, 0);
+ MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
+
++/* Retrieve user set MAC address */
++static int __init setup_igb_mac(char *macstr)
++{
++ int i, j;
++ unsigned char result, value;
++
++ for (i = 0; i < ETH_ALEN; i++) {
++ result = 0;
++
++ if (i != 5 && *(macstr + 2) != ':')
++ return -1;
++
++ for (j = 0; j < 2; j++) {
++ if (isxdigit(*macstr) && (value = isdigit(*macstr) ?
++ *macstr - '0' : toupper(*macstr) - 'A' + 10) < 16) {
++ result = result * 16 + value;
++ macstr++;
++ } else
++ return -1;
++ }
++
++ macstr++;
++ g_mac_addr[i] = result;
++ }
++
++ g_usr_mac = 1;
++
++ return 0;
++}
++__setup("igb_mac=", setup_igb_mac);
++
+ struct igb_reg_info {
+ u32 ofs;
+ char *name;
+@@ -2511,12 +2546,31 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+ dev_err(&pdev->dev, "NVM Read Error\n");
+ }
+
++ if (g_usr_mac && (g_usr_mac < 3)) {
++ /* Get user set MAC address */
++ if (g_usr_mac == 2) {
++ /* 0x100000 offset for 2nd Ethernet MAC */
++ g_mac_addr[3] += 0x10;
++ if (g_mac_addr[3] < 0x10)
++ dev_warn(&pdev->dev,
++ "MAC addr byte 3 (0x%02x) wrap around"
++ "\n",
++ g_mac_addr[3]);
++ }
++ memcpy(hw->mac.addr, g_mac_addr, ETH_ALEN);
++ g_usr_mac++;
++ }
++
+ memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
+
+ if (!is_valid_ether_addr(netdev->dev_addr)) {
+- dev_err(&pdev->dev, "Invalid MAC Address\n");
+- err = -EIO;
+- goto err_eeprom;
++ /* Use Toradex OUI as default */
++ char default_mac_addr[ETH_ALEN] = {
++ 0x0, 0x14, 0x2d, 0x0, 0x0, 0x0
++ };
++ dev_warn(&pdev->dev, "using Toradex OUI as default igb MAC\n");
++ memcpy(hw->mac.addr, default_mac_addr, ETH_ALEN);
++ memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
+ }
+
+ /* get firmware version for ethtool -i */
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch
new file mode 100644
index 0000000..6841716
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch
@@ -0,0 +1,114 @@
+From 8c753a8354ae5927667b2a450eab2f49ceaac36b Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Tue, 22 Nov 2016 00:59:43 +0100
+Subject: [RESEND PATCH 4/6] apalis-tk1: adjust pin muxing for v1.1 hw
+
+Configure Apalis MMC1 D6 GPIO on SDMMC3_CLK_LB_IN as reserved function
+without any pull-up/down.
+
+Configure GPIO_PV2 as SD1_CD# according to latest V1.1 HW.
+
+Leave SDMMC3_CLK_LB_OUT muxed as SDMMC3 with output driver enabled aka
+not tristated and input driver enabled as well as it features some
+magic properties even though the external loopback is disabled and the
+internal loopback used as per SDMMC_VENDOR_MISC_CNTRL_0 register's
+SDMMC_SPARE1 bits being set to 0xfffd according to the TRM! This pin is
+now a not-connect on V1.1 HW in order to avoid any interference.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+---
+
+ arch/arm/boot/dts/tegra124-apalis.dtsi | 53 +++++++++++++++-------------------
+ 1 file changed, 23 insertions(+), 30 deletions(-)
+
+diff --git a/arch/arm/boot/dts/tegra124-apalis.dtsi b/arch/arm/boot/dts/tegra124-apalis.dtsi
+index 747ce81..2bfc579 100644
+--- a/arch/arm/boot/dts/tegra124-apalis.dtsi
++++ b/arch/arm/boot/dts/tegra124-apalis.dtsi
+@@ -414,18 +414,10 @@
+ nvidia,tristate = <TEGRA_PIN_DISABLE>;
+ nvidia,enable-input = <TEGRA_PIN_ENABLE>;
+ };
+- /*
+- * Don't use MMC1_D6 aka SDMMC3_CLK_LB_IN for now as it
+- * features some magic properties even though the
+- * external loopback is disabled and the internal
+- * loopback used as per SDMMC_VENDOR_MISC_CNTRL_0
+- * register's SDMMC_SPARE1 bits being set to 0xfffd
+- * according to the TRM!
+- */
+ sdmmc3_clk_lb_in_pee5 { /* D6 GPIO */
+ nvidia,pins = "sdmmc3_clk_lb_in_pee5";
+- nvidia,function = "sdmmc3";
+- nvidia,pull = <TEGRA_PIN_PULL_UP>;
++ nvidia,function = "rsvd2";
++ nvidia,pull = <TEGRA_PIN_PULL_NONE>;
+ nvidia,tristate = <TEGRA_PIN_DISABLE>;
+ nvidia,enable-input = <TEGRA_PIN_ENABLE>;
+ };
+@@ -520,20 +512,12 @@
+ nvidia,tristate = <TEGRA_PIN_DISABLE>;
+ nvidia,enable-input = <TEGRA_PIN_ENABLE>;
+ };
+- /*
+- * Don't use SD1_CD# aka SDMMC3_CLK_LB_OUT for now as it
+- * features some magic properties even though the
+- * external loopback is disabled and the internal
+- * loopback used as per SDMMC_VENDOR_MISC_CNTRL_0
+- * register's SDMMC_SPARE1 bits being set to 0xfffd
+- * according to the TRM!
+- */
+- sdmmc3_clk_lb_out_pee4 { /* CD# GPIO */
+- nvidia,pins = "sdmmc3_clk_lb_out_pee4";
+- nvidia,function = "rsvd2";
+- nvidia,pull = <TEGRA_PIN_PULL_NONE>;
++ sdmmc3_cd_n_pv2 { /* CD# GPIO */
++ nvidia,pins = "sdmmc3_cd_n_pv2";
++ nvidia,function = "rsvd3";
++ nvidia,pull = <TEGRA_PIN_PULL_UP>;
+ nvidia,tristate = <TEGRA_PIN_ENABLE>;
+- nvidia,enable-input = <TEGRA_PIN_DISABLE>;
++ nvidia,enable-input = <TEGRA_PIN_ENABLE>;
+ };
+
+ /* Apalis SPDIF */
+@@ -1512,13 +1496,6 @@
+ nvidia,tristate = <TEGRA_PIN_ENABLE>;
+ nvidia,enable-input = <TEGRA_PIN_DISABLE>;
+ };
+- sdmmc3_cd_n_pv2 { /* NC */
+- nvidia,pins = "sdmmc3_cd_n_pv2";
+- nvidia,function = "rsvd3";
+- nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
+- nvidia,tristate = <TEGRA_PIN_ENABLE>;
+- nvidia,enable-input = <TEGRA_PIN_DISABLE>;
+- };
+ gpio_x1_aud_px1 { /* NC */
+ nvidia,pins = "gpio_x1_aud_px1";
+ nvidia,function = "rsvd2";
+@@ -1568,6 +1545,22 @@
+ nvidia,tristate = <TEGRA_PIN_ENABLE>;
+ nvidia,enable-input = <TEGRA_PIN_DISABLE>;
+ };
++ /*
++ * Leave SDMMC3_CLK_LB_OUT muxed as SDMMC3 with output
++ * driver enabled aka not tristated and input driver
++ * enabled as well as it features some magic properties
++ * even though the external loopback is disabled and the
++ * internal loopback used as per
++ * SDMMC_VENDOR_MISC_CNTRL_0 register's SDMMC_SPARE1
++ * bits being set to 0xfffd according to the TRM!
++ */
++ sdmmc3_clk_lb_out_pee4 { /* NC */
++ nvidia,pins = "sdmmc3_clk_lb_out_pee4";
++ nvidia,function = "sdmmc3";
++ nvidia,pull = <TEGRA_PIN_PULL_NONE>;
++ nvidia,tristate = <TEGRA_PIN_DISABLE>;
++ nvidia,enable-input = <TEGRA_PIN_ENABLE>;
++ };
+ };
+ };
+
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch
new file mode 100644
index 0000000..9426107
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch
@@ -0,0 +1,52 @@
+From 3012bd5c49b1f0ce750767194f76e556fbe7e6e6 Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Thu, 15 Dec 2016 10:56:26 +0100
+Subject: [PATCH 4/4] mmc: tegra: apalis-tk1: hack to make sd1 functional
+
+Disable the external loopback and use the internal loopback as per
+SDMMC_VENDOR_MISC_CNTRL_0 register's SDMMC_SPARE1 bits being set to
+0xfffd according to the TRM.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Acked-by: Dominik Sliwa <dominik.sliwa@toradex.com>
+
+(cherry picked from toradex_tk1_l4t_r21.5 commit
+fc14b7601e5ca587afd97936ef3fd599f4e9281c)
+
+---
+
+ drivers/mmc/host/sdhci-tegra.c | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
+index 20b6ff5..6c84334 100644
+--- a/drivers/mmc/host/sdhci-tegra.c
++++ b/drivers/mmc/host/sdhci-tegra.c
+@@ -42,6 +42,7 @@
+ #define SDHCI_MISC_CTRL_ENABLE_SDR50 0x10
+ #define SDHCI_MISC_CTRL_ENABLE_SDHCI_SPEC_300 0x20
+ #define SDHCI_MISC_CTRL_ENABLE_DDR50 0x200
++#define SDHCI_MISC_CTRL_ENABLE_EXT_LOOPBACK 0x20000
+
+ #define SDHCI_TEGRA_AUTO_CAL_CONFIG 0x1e4
+ #define SDHCI_AUTO_CAL_START BIT(31)
+@@ -178,6 +179,16 @@ static void tegra_sdhci_reset(struct sdhci_host *host, u8 mask)
+ clk_ctrl |= SDHCI_CLOCK_CTRL_SDR50_TUNING_OVERRIDE;
+ }
+
++#define CONFIG_MACH_APALIS_TK1
++#ifdef CONFIG_MACH_APALIS_TK1
++ /*
++ * Disable the external loopback and use the internal loopback as per
++ * SDMMC_VENDOR_MISC_CNTRL_0 register's SDMMC_SPARE1 bits being set to
++ * 0xfffd according to the TRM.
++ */
++ misc_ctrl &= ~SDHCI_MISC_CTRL_ENABLE_EXT_LOOPBACK;
++#endif /* CONFIG_MACH_APALIS_TK1 */
++
+ sdhci_writel(host, misc_ctrl, SDHCI_TEGRA_VENDOR_MISC_CTRL);
+ sdhci_writel(host, clk_ctrl, SDHCI_TEGRA_VENDOR_CLOCK_CTRL);
+
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch
new file mode 100644
index 0000000..1a091dd
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch
@@ -0,0 +1,37 @@
+From 042f3f04daed2a1163a5b35b47ab8c9a8e6bf29d Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Tue, 22 Nov 2016 01:00:50 +0100
+Subject: [RESEND PATCH 5/6] apalis-tk1: working sd card detect on v1.1 hw
+
+Add sd card detect SD1_CD# applicable for V1.1 modules using GPIO_PV2.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+---
+
+ arch/arm/boot/dts/tegra124-apalis-eval.dts | 10 ++--------
+ 1 file changed, 2 insertions(+), 8 deletions(-)
+
+diff --git a/arch/arm/boot/dts/tegra124-apalis-eval.dts b/arch/arm/boot/dts/tegra124-apalis-eval.dts
+index 2b5a0f3..2715692 100644
+--- a/arch/arm/boot/dts/tegra124-apalis-eval.dts
++++ b/arch/arm/boot/dts/tegra124-apalis-eval.dts
+@@ -187,14 +187,8 @@
+ /* Apalis SD1 */
+ sdhci@700b0400 {
+ status = "okay";
+- /*
+- * Don't use SD1_CD# aka SDMMC3_CLK_LB_OUT for now as it
+- * features some magic properties even though the external
+- * loopback is disabled and the internal loopback used as per
+- * SDMMC_VENDOR_MISC_CNTRL_0 register's SDMMC_SPARE1 bits being
+- * set to 0xfffd according to the TRM!
+- * cd-gpios = <&gpio TEGRA_GPIO(EE, 4) GPIO_ACTIVE_LOW>;
+- */
++ /* SD1_CD# */
++ cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_LOW>;
+ bus-width = <4>;
+ vqmmc-supply = <&vddio_sdmmc3>;
+ };
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline-4.9/0006-apalis-tk1-update-compatibility-comment.patch b/recipes-kernel/linux/linux-toradex-mainline-4.9/0006-apalis-tk1-update-compatibility-comment.patch
new file mode 100644
index 0000000..71743aa
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline-4.9/0006-apalis-tk1-update-compatibility-comment.patch
@@ -0,0 +1,30 @@
+From e73b61059b07d263d76a887f0354cbdb108a47b8 Mon Sep 17 00:00:00 2001
+From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+Date: Thu, 24 Nov 2016 01:35:48 +0100
+Subject: [RESEND PATCH 6/6] apalis-tk1: update compatibility comment
+
+Now with the new V1.1A HW card detect being implemented update resp.
+compatibility information.
+
+Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
+---
+
+ arch/arm/boot/dts/tegra124-apalis.dtsi | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/arch/arm/boot/dts/tegra124-apalis.dtsi b/arch/arm/boot/dts/tegra124-apalis.dtsi
+index 2bfc579..2276073 100644
+--- a/arch/arm/boot/dts/tegra124-apalis.dtsi
++++ b/arch/arm/boot/dts/tegra124-apalis.dtsi
+@@ -44,7 +44,7 @@
+
+ /*
+ * Toradex Apalis TK1 Module Device Tree
+- * Compatible for Revisions 2GB: V1.0A
++ * Compatible for Revisions 2GB: V1.0A, V1.0B, V1.1A
+ */
+ / {
+ model = "Toradex Apalis TK1";
+--
+2.9.3
+
diff --git a/recipes-kernel/linux/linux-toradex-mainline.inc b/recipes-kernel/linux/linux-toradex-mainline.inc
new file mode 100644
index 0000000..47ee82e
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline.inc
@@ -0,0 +1,110 @@
+SUMMARY = "Linux Kernel for Toradex Tegra based modules"
+SECTION = "kernel"
+LICENSE = "GPLv2"
+
+LIC_FILES_CHKSUM = "file://COPYING;md5=d7810fab7487fb0aad327b76f1be7cd7"
+
+inherit kernel siteinfo
+
+# Try to build & install perf
+#require recipes-kernel/linux/linux-tools.inc
+
+RPSRC = "http://www.rpsys.net/openzaurus/patches/archive"
+
+# Enable OABI compat for people stuck with obsolete userspace
+# ARM_KEEP_OABI ?= "1"
+
+# Quirk for udev greater or equal 141
+UDEV_GE_141 ?= "0"
+
+# Kernel bootlogo is distro-specific (default is OE logo).
+# Logo resolution (qvga, vga, ...) is machine-specific.
+LOGO_SIZE ?= "."
+
+# Support for binary device tree generation
+
+FILES_kernel-devicetree = "/boot/devicetree*"
+
+#KERNEL_DEVICETREE to be specified from machine configuration
+
+KERNEL_DEVICETREE_FLAGS = "-R 8 -S 0x3000"
+
+CORTEXA8FIXUP ?= "yes"
+
+python __anonymous () {
+
+ import bb
+
+ devicetree = bb.data.getVar('KERNEL_DEVICETREE', d, 1) or ''
+ if devicetree:
+ depends = bb.data.getVar("DEPENDS", d, 1)
+ bb.data.setVar("DEPENDS", "%s dtc-native" % depends, d)
+ packages = bb.data.getVar("PACKAGES", d, 1)
+ bb.data.setVar("PACKAGES", "%s kernel-devicetree" % packages, d)
+}
+
+do_configure_append() {
+ if test -e scripts/Makefile.fwinst ; then
+ sed -i -e "s:-m0644:-m 0644:g" scripts/Makefile.fwinst
+ fi
+}
+
+# bitbake.conf only prepends PARALLEL make in tasks called do_compile, which isn't the case for compile_modules
+# So explicitly enable it for that in here
+EXTRA_OEMAKE = "${PARALLEL_MAKE} "
+
+do_uboot_mkimage_prepend() {
+ mkdir arch/${ARCH}/boot/ || true
+}
+
+do_install_append() {
+ oe_runmake headers_install INSTALL_HDR_PATH=${D}${exec_prefix}/src/linux-${KERNEL_VERSION} ARCH=$ARCH
+}
+
+PACKAGES =+ "kernel-headers"
+FILES_kernel-headers = "${exec_prefix}/src/linux*"
+
+do_devicetree_image() {
+ if test -n "${KERNEL_DEVICETREE}" ; then
+ dtc -I dts -O dtb ${KERNEL_DEVICETREE_FLAGS} -o devicetree ${KERNEL_DEVICETREE}
+ install -d ${D}/boot
+ install -m 0644 devicetree ${D}/boot/devicetree-${KERNEL_VERSION}
+ install -d ${DEPLOY_DIR_IMAGE}
+ install -m 0644 devicetree ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGE_BASE_NAME}.dtb
+ package_stagefile_shell ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGE_BASE_NAME}.dtb
+ cd ${DEPLOY_DIR_IMAGE}
+ rm -f ${KERNEL_IMAGE_SYMLINK_NAME}.dtb
+ ln -sf ${KERNEL_IMAGE_BASE_NAME}.dtb ${KERNEL_IMAGE_SYMLINK_NAME}.dtb
+ package_stagefile_shell ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGE_SYMLINK_NAME}.dtb
+ fi
+}
+
+do_devicetree_image_tegra124() {
+}
+
+addtask devicetree_image after do_install before do_package do_deploy
+
+pkg_postinst_kernel-devicetree () {
+ cd /${KERNEL_IMAGEDEST}; update-alternatives --install /${KERNEL_IMAGEDEST}/devicetree devicetree devicetree-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true
+}
+
+pkg_postrm_kernel-devicetree () {
+ cd /${KERNEL_IMAGEDEST}; update-alternatives --remove devicetree devicetree-${KERNEL_VERSION} || true
+}
+
+# Automatically depend on lzop-native if CONFIG_KERNEL_LZO is enabled
+python () {
+ try:
+ defconfig = bb.fetch2.localpath('file://defconfig', d)
+ except bb.fetch2.FetchError:
+ return
+
+ try:
+ configfile = open(defconfig)
+ except IOError:
+ return
+
+ if 'CONFIG_KERNEL_LZO=y\n' in configfile.readlines():
+ depends = d.getVar('DEPENDS', False)
+ d.setVar('DEPENDS', depends + ' lzop-native')
+}
diff --git a/recipes-kernel/linux/linux-toradex-mainline_4.9.bb b/recipes-kernel/linux/linux-toradex-mainline_4.9.bb
new file mode 100644
index 0000000..b7face6
--- /dev/null
+++ b/recipes-kernel/linux/linux-toradex-mainline_4.9.bb
@@ -0,0 +1,58 @@
+SUMMARY = "Linux Kernel for Toradex Apalis Tegra based modules"
+SECTION = "kernel"
+LICENSE = "GPLv2"
+
+LIC_FILES_CHKSUM = "file://COPYING;md5=d7810fab7487fb0aad327b76f1be7cd7"
+
+inherit kernel siteinfo
+require recipes-kernel/linux/linux-dtb.inc
+
+LINUX_VERSION ?= "4.9"
+
+LOCALVERSION = "-${PR}"
+PR = "V2.6.2b1"
+
+PV = "${LINUX_VERSION}"
+S = "${WORKDIR}/linux-${PV}"
+SRC_URI[md5sum] = "0a68ef3615c64bd5ee54a3320e46667d"
+SRC_URI = "https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${PV}.tar.xz \
+ file://0001-toradex_apalis_tk1_t30-customize-defconfig.patch \
+ file://0001-apalis-tk1-remove-spurious-new-lines.patch \
+ file://0002-apalis-tk1-temp-alert-pull-up.patch \
+ file://0003-apalis-tk1-optional-displayport-hot-plug-detect.patch \
+ file://0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch \
+ file://0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch \
+ file://0006-apalis-tk1-update-compatibility-comment.patch\
+ file://0001-apalis_t30-tk1-fix-pcie-clock-and-reset-not-conformi.patch \
+ file://0002-igb-integrate-tools-only-device-support.patch \
+ file://0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch \
+ file://0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch \
+ "
+
+COMPATIBLE_MACHINE = "(apalis-tk1-mainline|apalis-t30-mainline)"
+KERNEL_EXTRA_ARGS = " LOADADDR=0x80008000 "
+
+# One possibiltiy for changes to the defconfig:
+config_script () {
+ echo "dummy" > /dev/null
+}
+
+do_configure_prepend () {
+ pushd ${S}
+ export KBUILD_OUTPUT=${B}
+ oe_runmake ${KERNEL_DEFCONFIG}
+
+ #maybe change some configuration
+ config_script
+
+ #Add Toradex BSP Version as LOCALVERSION
+ sed -i -e /CONFIG_LOCALVERSION/d ${B}/.config
+ echo "CONFIG_LOCALVERSION=\"${LOCALVERSION}\"" >> ${B}/.config
+
+ popd
+}
+
+do_uboot_mkimage_prepend() {
+ cd ${B}
+}
+