Recently I bought an HP Envy d001nl and I’m very happy with it, but yesterday I realized that the Realtek SD Reader was not working properly under Ubuntu 15.10 Wily. Not good, since I badly need the SD Card reader for copying photos from my Pentax K-30… Let’see what can be done.
First of all, it could be useful to exclude an hardware problem: I still have Windows 10 in my PC, barely used, but this time it proves to be useful, since it shows that the card reader is properly working. Using device manager I can find a few more details on this piece of hardware.
It is a Realtke PCIE CardReader with device ID 522A.
Back to Ubuntu, I verify this info with:
[email protected]:~$ lspci
02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. Device 522a (rev 01)
A quick check on the Internet shows that the Realtek SD Reader is supported in the kernel since version 4.4, but unfortunately my Kubuntu version has kernel
[email protected]:~$ uname -r
The cleanest way to solve the problem is to build an updated kernel version, with the support for the card reader: there are a ton of pages that explain how to do that, so I won’t cover this kind of solution.
But suppose that you don’t want to change the kernel, there is still some chance to have the SD card reader properly working.
Disclaimer: I am not responsible of the damages you can do to your PC following this tutorial. Do it at your own risk.
That said, there should really be no problem if you take a bit of care.
The first step is downloading the kernel sources and the kernel headers:
[email protected]:~$ apt-get source linux
[email protected]:~$ sudo apt-get install linux-headers-generic
Four files are involved in the working of the Realtek SD reader:
include/linux/mfd/rtsx_pci.h drivers/mfd/rtsx_pcr.h drivers/mfd/rtsx_pcr.c drivers/mfd/rts5227.c
The right way to proceed would be to backport the changes related to the device identified by the id 522A (to avoid problems due to the different kernel versions), but luckily the driver seems not to be changed much between versions 4.2 and 4.4. This means that we can use the files of the 4.4 (or more recent) kernel version straight away.
For my PC I choose to use the driver source code files found in kernel 4.5; they can be downloaded from the github kernel repository:
Once downloaded, go to the root of the kernel sources
[email protected]:~$ cd linux-4.2.0
and copy respectively the above files in
rtsx_pci.h in include/linux/mfd/
rtsx_pcr.h in drivers/mfd/
rtsx_pcr.c in drivers/mfd/
rts5227.c in drivers/mfd/
Now it’s time to build the driver; copy your kernel configuration in the .config file to be used for kernel building
[email protected]:~/linux-4.2.0$ cp -vi /boot/config-`uname -r` .config
Copy the Module.symvers from the kernel headers package (more info related to the Module.symvers file here)
[email protected]:~/linux-4.2.0$ cp /lib/modules/$(uname -r)/build/Module.symvers ./
Build the modules:
[email protected]:~/linux-4.2.0$ make prepare [email protected]:~/linux-4.2.0$ make modules_prepare [email protected]:~/linux-4.2.0$ make SUBDIRS=drivers/mfd/
If all is fine, using the following command
[email protected]:~/linux-4.2.0$ ls drivers/mfd/*.ko | grep pci
you should see the line
Remove the old driver (if loaded)
[email protected]:~/linux-4.2.0$ sudo rmmod rtsx_pci
Make a backup copy of the old driver
[email protected]:~/linux-4.2.0$ sudo mv /lib/modules/$(uname -r)/kernel/drivers/mfd/rtsx_pci.ko /lib/modules/$(uname -r)/kernel/drivers/mfd/rtsx_pci.ko_ORIGINAL
Copy the new driver and regenerates the module dependencies
[email protected]:~/linux-4.2.0$ sudo cp drivers/mfd/rtsx_pci.ko /lib/modules/$(uname -r)/kernel/drivers/mfd/ [email protected]:~/linux-4.2.0$ sudo depmod -a
Finally, load the driver
[email protected]:~/linux-4.2.0$ sudo modprobe rtsx_pci
If the operations has been successful, once a SD card is inserted, you should see in the kernel log something like:
[ 4248.349559] rtsx_pci 0000:02:00.0: rtsx_pci_acquire_irq: pcr->msi_en = 1, pci->irq = 280 [ 4251.305275] mmc0: cannot verify signal voltage switch [ 4251.433049] mmc0: new ultra high speed SDR50 SDHC card at address aaaa [ 4251.447625] mmcblk0: mmc0:aaaa SU32G 29.7 GiB [ 4251.466839] mmcblk0: p1
and if you are using a desktop manager you should see the device: