Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How-to: patch, compile and install a working kernel for the Surface Pro 3 #8

Open
Vistaus opened this issue Nov 23, 2014 · 0 comments

Comments

Projects
None yet
1 participant
@Vistaus
Copy link
Owner

commented Nov 23, 2014

**NOTE: if you're using kernel 3.19 or higher, then you only need to apply the camera patch if you want the cameras working. DON'T apply the Type Cover 3 patch if you're on 3.19 or higher as the Type Cover 3 is supported out-of-the-box.

_First off: what's important here is that I've based it off of my experience on Antergos. Antergos uses sudo by default. Pure Arch doesn't use sudo by default so you have to change to the root user. That means that the commands I'm giving in this how-to need to be copy and pasted w/o the sudo part if you're not on Antergos or haven't set up sudo on pure Arch. Also, this howto is as generic as possible so that you can use it for the foreseeable future._

1 Downloading the kernel
First, start by getting the kernel sources. You can do so by downloading the appropriate kernel from the kernel.org website: https://www.kernel.org/
Always choose the newest stable one (or rc one if you're a tad more adventurous). You can also choose the newest longterm one as long as it has a version number higher than 3.16
Unpack the folder in the archive to a folder of your liking where you can easily reach it.

2 Patching it up
In the kernel source folder, create a new typecover3.patch file with the following content:

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 73bd9e2..e94afcc 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -702,6 +702,11 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
    if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
        type == HID_COLLECTION_PHYSICAL)
        hid->group = HID_GROUP_SENSOR_HUB;
+
+   if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
+       hid->product == USB_DEVICE_ID_MS_TYPE_COVER_3 &&
+       hid->group == HID_GROUP_MULTITOUCH)
+       hid->group = HID_GROUP_GENERIC;
 }

 static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
@@ -1861,6 +1866,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
    { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
    { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
    { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) },
+   { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3) },
    { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
    { HID_USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) },
    { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index e23ab8b..15f32c2 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -648,6 +648,7 @@
 #define USB_DEVICE_ID_MS_SURFACE_PRO_2   0x0799
 #define USB_DEVICE_ID_MS_TOUCH_COVER_2   0x07a7
 #define USB_DEVICE_ID_MS_TYPE_COVER_2    0x07a9
+#define USB_DEVICE_ID_MS_TYPE_COVER_3    0x07dc

 #define USB_VENDOR_ID_MOJO     0x8282
 #define USB_DEVICE_ID_RETRO_ADAPTER    0x3201
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index 8ba17a9..cacda43 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -274,6 +274,8 @@ static const struct hid_device_id ms_devices[] = {
        .driver_data = MS_NOGET },
    { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500),
        .driver_data = MS_DUPLICATE_USAGES },
+   { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3),
+       .driver_data = MS_HIDINPUT },

    { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
        .driver_data = MS_PRESENTER },
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 5014bb5..cebfaf2 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -77,6 +77,7 @@ static const struct hid_blacklist {
    { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS },
    { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET },
    { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET },
+   { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3, HID_QUIRK_NO_INIT_REPORTS },
    { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS },
    { USB_VENDOR_ID_NEXIO, USB_DEVICE_ID_NEXIO_MULTITOUCH_PTI0750, HID_QUIRK_NO_INIT_REPORTS },
    { USB_VENDOR_ID_NOVATEK, USB_DEVICE_ID_NOVATEK_MOUSE, HID_QUIRK_NO_INIT_REPORTS },
-- 
2.1.0

Still in the kernel source folder, open up the following file to add in support for the Surface Pro 3 cameras (rear and front):

drivers/media/usb/uvc/uvc_driver.c

Somewhere in between the listed products, for example at line 2342, add the following:

     /* Microsoft Surface Pro 3 Front */
     { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
                             | USB_DEVICE_ID_MATCH_INT_INFO,
       .idVendor             = 0x045e,
       .idProduct            = 0x07be,
       .bInterfaceClass      = USB_CLASS_VIDEO,
       .bInterfaceSubClass   = 1,
       .bInterfaceProtocol   = 1 },
     /* Microsoft Surface Pro 3 Rear */
     { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
                             | USB_DEVICE_ID_MATCH_INT_INFO,
       .idVendor             = 0x045e,
       .idProduct            = 0x07bf,
       .bInterfaceClass      = USB_CLASS_VIDEO,
       .bInterfaceSubClass   = 1,
       .bInterfaceProtocol   = 1 },

Save the file.

Now open up a terminal window and change to the kernel source directory using the cd command.

Now apply the Type Cover 3 patch using the following command:

patch -p1 --ignore-whitespace -i typecover3.patch

(on the 3.18 kernel, you might get a small error after doing that, you can ignore that)

3 The actual compiling

Now issue the following command to copy over the current kernel config to the one you're about to compile:

zcat /proc/config.gz > .config

Then:

make menuconfig

If you're not an advanced user like me, just leave everything as it is and save the file using the corresponding button, then use the exit button to exit out of this.

Now that we've done this, the actual compiling can begin. This can take up to an hour so be patient. Issue the command for this:

make -j3

Now that that's done, let's install the modules:

sudo make modules_install

When that's done, do:

make bzImage

followed by:

sudo make install

Now, everything should be in place. Check this by issuing:

cd /boot

followed by:

ls

Note the name of the kernel there. The name of the kernel is the name minus the vmlinuz part. So for example, if you've compiled the 3.18 rc5 kernel, you'll see vmlinuz-3.18.0-rc5-ARCH - _3.18.0-rc5-ARCH_ is the name of the kernel then.

4 Generating the RAM Disk image file

Don't question what it is, just do the following ;-)

mkinitcpio -k FullKernelName -c /etc/mkinitcpio.conf -g /boot/initramfs-YourKernelName.img```

In both places in the command, replace fullkernelname with the name you just noted from the /boot folder.

5 Finishing it up
To finish it up, issue the following command:

sudo update-initramfs

followed by the last command (to inform GRUB of the changes - if you use LILO as your bootloader (at least Antergos uses GRUB by default), you don't have to issue this command):

sudo grub-mkconfig -o /boot/grub/grub.cfg

Now reboot and you should be able to choose the kernel in your bootloader. It might take a couple of reboots after compiling before the Type Cover 3 starts working. I don't know why that is, seems like something kernel-related is a bit finicky.

In case the trackpad isn't working (correctly) after rebooting into the patched kernel, add the following to /etc/X11/xorg.conf:

Section "InputClass"
        Identifier "Surface Pro 3 cover"
        MatchIsPointer "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
        Option "vendor" "045e"
        Option "product" "07dc"
        Option "IgnoreAbsoluteAxes" "True"
EndSection

and reboot.

@Vistaus Vistaus added the enhancement label Nov 23, 2014

@Vistaus Vistaus changed the title How-to: Surface Pro 3 patched kernel compiling How-to: patch, compile and install a working kernel for the Surface Pro 3 Nov 23, 2014

@Vistaus Vistaus added how-to and removed enhancement labels Nov 24, 2014

danielquinn added a commit to danielquinn/Gentoo-Surface-Pro-3 that referenced this issue Jan 24, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.