# Dell laptop integrated card reader won't work after booting

## candamil

Hi, guys, I hope you can help me.

I bought a dell xps 15 L502X laptop. It comes with a JMicron SD Card reader. With the configuration I have right now, I can get it working but only if the SD card is inserted before booting. If I insert it after booting, the SD card reader isn't detected.

I think it's a bus problem. I was trying to solve this problem and I followed these two threads:

https://forums.gentoo.org/viewtopic-p-6932072.html

https://forums.gentoo.org/viewtopic-t-882177-highlight-dell+reader.html

As Yczo says in the second one, if I run "echo 1 > /sys/bus/pci/rescan", the card reader is detected properly (but it would be great for it to be automatic  :Razz: ).

I suppose it's a kernel issue or something like that, but I don't really know what I should configure. This is my configuration right now:

Kernel 3.2.12-gentoo

Bus options

```

  │ │                           [*] PCI support                                                                                  │ │   

  │ │                           [*]   Support mmconfig PCI config space access                                                   │ │   

  │ │                           [*]   PCI Express support                                                                        │ │   

  │ │                           <M>     PCI Express Hotplug driver                                                               │ │   

  │ │                           [ ]     Root Port Advanced Error Reporting support                                               │ │   

  │ │                           -*-     PCI Express ASPM control                                                                 │ │   

  │ │                           [ ]       Debug PCI Express ASPM                                                                 │ │   

  │ │                           -*- Message Signaled Interrupts (MSI and MSI-X)                                                  │ │   

  │ │                           [ ] PCI Debugging                                                                                │ │   

  │ │                           < > PCI Stub driver                                                                              │ │   

  │ │                           [*] Interrupts on hypertransport devices                                                         │ │   

  │ │                           -*- PCI IOV support                                                                              │ │   

  │ │                           [ ] PCI PRI support                                                                              │ │   

  │ │                           [ ] PCI PASID support                                                                            │ │   

  │ │                           < > PCCard (PCMCIA/CardBus) support  --->                                                        │ │   

  │ │                           <*> Support for PCI Hotplug  --->                                                                │ │   

  │ │                           [ ] RapidIO support

```

Device drivers / MMC/SD/blahblah

```

  │ │                           --- MMC/SD/SDIO card support                                                                     │ │   

  │ │                           [ ]   MMC debugging                                                                              │ │   

  │ │                           [ ]   Assume MMC/SD cards are non-removable (DANGEROUS)                                          │ │   

  │ │                           [ ]   MMC host clock gating (EXPERIMENTAL)                                                       │ │   

  │ │                                 *** MMC/SD/SDIO Card Drivers ***                                                           │ │   

  │ │                           <*>   MMC block device driver                                                                    │ │   

  │ │                           (8)     Number of minors per block device                                                        │ │   

  │ │                           [*]     Use bounce buffer for simple hosts                                                       │ │   

  │ │                           <*>   SDIO UART/GPS class support                                                                │ │   

  │ │                           < >   MMC host test driver                                                                       │ │   

  │ │                                 *** MMC/SD/SDIO Host Controller Drivers ***                                                │ │   

  │ │                           <*>   Secure Digital Host Controller Interface support                                           │ │   

  │ │                           <M>   SDHCI support on PCI bus                                                                   │ │   

  │ │                           [*]     Ricoh MMC Controller Disabler  (EXPERIMENTAL)                                            │ │   

  │ │                           < >   SDHCI platform and OF driver helper                                                        │ │   

  │ │                           < >   Winbond W83L51xD SD/MMC Card Interface support                                             │ │   

  │ │                           < >   TI Flash Media MMC/SD Interface support  (EXPERIMENTAL)                                    │ │   

  │ │                           < >   ENE CB710 MMC/SD Interface support                                                         │ │   

  │ │                           < >   VIA SD/MMC Card Reader Driver                                                              │ │   

  │ │                           < >   VUB300 USB to SDIO/SD/MMC Host Controller support                                          │ │   

  │ │                           <*>   USB SD Host Controller (USHC) support 

```

This is the important content of modules:

```

nomada linux # more /etc/conf.d/modules

modules="pciehp"

module_pciehp_args="pciehp_force=1"

modules="scsi_wait_scan"

```

I also tried with this line in grub (the pcie_ports option):

```

kernel /boot/linux-3.2.12-gentoo root=/dev/sda8 vga=791 splash=silent,fadein,theme:emergence console=tty1 pcie_ports=native

```

And this is my hardware:

```

nomada linux # lspci  | grep JMicron

05:00.0 System peripheral: JMicron Technology Corp. SD/MMC Host Controller (rev 30)

05:00.2 SD Host controller: JMicron Technology Corp. Standard SD Host Controller (rev 30)

05:00.3 System peripheral: JMicron Technology Corp. MS Host Controller (rev 30)

05:00.4 System peripheral: JMicron Technology Corp. xD Host Controller (rev 30)

```

Any idea about how to solve this problem?

Thank you!

----------

## BillWho

candamil,

I couldn't use my card reader for a while until I stumbled on this - it was previously unset.

```
CONFIG_SCSI_MULTI_LUN=y
```

It was in the listed link https://forums.gentoo.org/viewtopic-p-6932072.html, but maybe you missed it!

Good luck   :Wink: 

----------

## candamil

Unfortuntely that's not the problem:

```

  │ Symbol: SCSI_MULTI_LUN [=y]                                                                                                    │   

  │ Type  : boolean                                                                                                                │   

  │ Prompt: Probe all LUNs on each SCSI device                                                                                     │   

  │   Defined at drivers/scsi/Kconfig:200                                                                                          │   

  │   Depends on: SCSI [=y]                                                                                                        │   

  │   Location:                                                                                                                    │   

  │     -> Device Drivers                                                                                                          │   

  │       -> SCSI device support                                                                                                   │   

```

But thanks for trying  :Wink: 

----------

## candamil

I have just tried to set all these modules embedded in the kernel, but of course it didn't work. I have no idea what else should I try. Any help would be appreciated  :Razz: 

----------

## nicoseb

I used to have this issue because I had forgotten to turn on PCIe hotplug in my kernel. It then worked for a while, but it came back I have been stuck with it almost ever since I am on kernel 3.0... 

I am now on kernel 3.3.0 and still with the issue.

I am decided to go after it, I will let you know if I find anything. Likewise, please let me know if this is fixed for you?!

Thanks

----------

## BillWho

nicoseb,

 Do you get anything from udevadm when you plug the card in? This is my output:

```
root@gentoo-gateway .ssh # udevadm monitor --udev

monitor will print the received events for:

UDEV - the event which udev sends out after rule processing

UDEV  [32305.413482] change   /devices/pci0000:00/0000:00:13.2/usb2/2-3/2-3:1.0/host4/target4:0:0/4:0:0:2/block/sde (block)

UDEV  [32305.507939] change   /devices/pci0000:00/0000:00:13.2/usb2/2-3/2-3:1.0/host4/target4:0:0/4:0:0:2/block/sde (block)

UDEV  [32305.604987] add      /devices/pci0000:00/0000:00:13.2/usb2/2-3/2-3:1.0/host4/target4:0:0/4:0:0:2/block/sde/sde1 (block)

```

and fdisk shows:

```
root@gentoo-gateway .ssh # fdisk -l|grep sde

Disk /dev/sde: 4008 MB, 4008706048 bytes

/dev/sde1            8192     7829503     3910656    b  W95 FAT32

```

----------

## candamil

I have tried the udev command, but it doesn't show any information when I plug the card (and, of course, there isn't any new disk device). Nothing until I run "echo 1 > /sys/bus/pci/rescan".

So it's exactly that the card reader isn't detected if it has not a card while booting. Now I have the pcie hotplug module activated, so that isn't the problem neither.

----------

## nicoseb

Billwho,

Same here, the udev command does not do anything.

I actually booted with the card, mounted it, got my pics off, umounted it and took it out. 

If I plug the card back in, udev does not do anything, the other command "echo 1 > /sys/bus/pci/rescan" does not do anything for me, but I can still mount the card since it was detected at startup.

Note that mounting/unmounting the card does not show anything once or ever in dmesg!

Seems like I am in an even worse place haha.

----------

## BillWho

nicoseb and candamil,

I don't know what suggest next   :Confused: 

There are several posts attributed to udev not detecting devices. It seems odd that they also exhibit the same anomaly - it's detected during boot.  

I'm starting to suspect that the latest udev changes introduced these problems, but of course I can't be sure. Here's what I have from December

```
Sat Dec 10 11:42:39 2011 >>> sys-fs/udev-171-r3

Sun Dec 11 10:17:23 2011 >>> sys-fs/udev-171-r4

Thu Dec 29 15:40:45 2011 >>> sys-fs/udev-171-r5

Sun Mar 18 22:43:28 2012 >>> sys-fs/udev-181

Tue Mar 20 09:52:23 2012 >>> sys-fs/udev-182

Sat Mar 24 09:59:41 2012 >>> sys-fs/udev-182-r2

Sun Apr  1 17:03:23 2012 >>> sys-fs/udev-182-r3

```

Give  

```
udevadm trigger --action=change --verbose --dry-run --subsystem-match=block
```

a try after plugging in the card. My output is below. It shows sde even though nothing is plugged in it at the moment:

```
/sys/devices/pci0000:00/0000:00:13.2/usb2/2-3/2-3:1.0/host4/target4:0:0/4:0:0:0/block/sdc

/sys/devices/pci0000:00/0000:00:13.2/usb2/2-3/2-3:1.0/host4/target4:0:0/4:0:0:1/block/sdd

/sys/devices/pci0000:00/0000:00:13.2/usb2/2-3/2-3:1.0/host4/target4:0:0/4:0:0:2/block/sde

/sys/devices/pci0000:00/0000:00:13.2/usb2/2-3/2-3:1.0/host4/target4:0:0/4:0:0:3/block/sdf
```

----------

## nicoseb

No change before or after putting the card in...

```

/sys/devices/pci0000:00/0000:00:11.0/ata1/host0/target0:0:0/0:0:0:0/block/sda

/sys/devices/pci0000:00/0000:00:11.0/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1

/sys/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host6/target6:0:0/6:0:0:0/block/sr0

/sys/devices/pci0000:00/0000:00:13.2/usb2/2-2/2-2:1.0/block/uba

/sys/devices/pci0000:00/0000:00:15.2/0000:04:00.0/usb9/9-1/9-1:1.0/block/ubb

/sys/devices/pci0000:00/0000:00:15.2/0000:04:00.0/usb9/9-1/9-1:1.0/block/ubb/ubb1

/sys/devices/virtual/block/loop0

/sys/devices/virtual/block/loop1

/sys/devices/virtual/block/loop2

/sys/devices/virtual/block/loop3

/sys/devices/virtual/block/loop4

/sys/devices/virtual/block/loop5

/sys/devices/virtual/block/loop6

/sys/devices/virtual/block/loop7

/sys/devices/virtual/block/ram0

/sys/devices/virtual/block/ram1

/sys/devices/virtual/block/ram10

/sys/devices/virtual/block/ram11

/sys/devices/virtual/block/ram12

/sys/devices/virtual/block/ram13

/sys/devices/virtual/block/ram14

/sys/devices/virtual/block/ram15

/sys/devices/virtual/block/ram2

/sys/devices/virtual/block/ram3

/sys/devices/virtual/block/ram4

/sys/devices/virtual/block/ram5

/sys/devices/virtual/block/ram6

/sys/devices/virtual/block/ram7

/sys/devices/virtual/block/ram8

/sys/devices/virtual/block/ram9

```

What I find confusing is why the behavior was exactly the same when I forgot the hotplug in the kernel. These might be completely unrelated, but "funny" coincidence...

I have not seen much more about the subkect online.. most people report the issue of ALL_SCSI_LUN=y and PCIe hotplug=y ... 

Anyway, I appreciate your help on this... 

it used to work, so eventually there must be a way to find the solution  :Smile: 

----------

## candamil

Sorry for the delay, these days I am a little bit busy. Same problem for me, no changes after plugging the card:

```

nomada candamil # udevadm trigger --action=change --verbose --dry-run --subsystem-match=block

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda2

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda3

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8

/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9

/sys/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0

/sys/devices/virtual/block/loop0

/sys/devices/virtual/block/loop1

/sys/devices/virtual/block/loop2

/sys/devices/virtual/block/loop3

/sys/devices/virtual/block/loop4

/sys/devices/virtual/block/loop5

/sys/devices/virtual/block/loop6

/sys/devices/virtual/block/loop7

/sys/devices/virtual/block/nbd0

/sys/devices/virtual/block/nbd1

/sys/devices/virtual/block/nbd10

/sys/devices/virtual/block/nbd11

/sys/devices/virtual/block/nbd12

/sys/devices/virtual/block/nbd13

/sys/devices/virtual/block/nbd14

/sys/devices/virtual/block/nbd15

/sys/devices/virtual/block/nbd2

/sys/devices/virtual/block/nbd3

/sys/devices/virtual/block/nbd4

/sys/devices/virtual/block/nbd5

/sys/devices/virtual/block/nbd6

/sys/devices/virtual/block/nbd7

/sys/devices/virtual/block/nbd8

/sys/devices/virtual/block/nbd9

```

It seems we need to keep thinking of possible problems, but I don't know what else can be...

----------

## candamil

I have found a temporary soution that could work for the moment. As I said in the first post, if I use the command "echo 1 > /sys/bus/pci/rescan", the SD card is detected. What I have just discovered is that the SD card doesn't need to be plugged. I can use that command and THEN plug the SD card, so it's enough if you write a script with that command and run it while system boot.

----------

## BillWho

candamil,

Good find   :Exclamation: 

Coincident with your discovery, I happened upon this in  cat -n Documentation/feature-removal-schedule.txt

 272	What:	fakephp and associated sysfs files in /sys/bus/pci/slots/

   273	When:	2011

   274	Why:	In 2.6.27, the semantics of /sys/bus/pci/slots was redefined to

   275		represent a machine's physical PCI slots. The change in semantics

   276		had userspace implications, as the hotplug core no longer allowed

   277		drivers to create multiple sysfs files per physical slot (required

   278		for multi-function devices, e.g.). fakephp was seen as a developer's

   279		tool only, and its interface changed. Too late, we learned that

   280		there were some users of the fakephp interface.

   281	

   282		In 2.6.30, the original fakephp interface was restored. At the same

   283		time, the PCI core gained the ability that fakephp provided, namely

   284		function-level hot-remove and hot-add.

   285	

   286		Since the PCI core now provides the same functionality, exposed in:

   287	

   288			/sys/bus/pci/rescan

   289			/sys/bus/pci/devices/.../remove

   290			/sys/bus/pci/devices/.../rescan

   291	

   292		there is no functional reason to maintain fakephp as well.

   293	

   294		We will keep the existing module so that 'modprobe fakephp' will

   295		present the old /sys/bus/pci/slots/... interface for compatibility,

   296		but users are urged to migrate their applications to the API above.

   297	

   298		After a reasonable transition period, we will remove the legacy

   299		fakephp interface.

   300	Who:	Alex Chiang <achiang@hp.com>

Myabe setting CONFIG_HOTPLUG_PCI_FAKE=m would provide the functionally   :Question: 

----------

## candamil

Hi there. I have tried it, as an embedded module and as a module, both cases with and without the ACPI hotplug module, but with no results. It seems we need to keep searching...

----------

## candamil

Another little hint.

I was trying to find a way to solve this problem automatically, so I created a service that runs at startup. Here it is:

```

nomada candamil # more /etc/init.d/sdmounter

#!/sbin/runscript

depend()

{

}

start()

{

        ebegin "Starting SDCard mounter (JMB389)"                               

        /bin/echo 1 > /sys/bus/pci/rescan

        /bin/echo "test" > /home/ficherotest

        eend $?

}

```

You just need to save it in /etc/init.d, give it execution permissions and add it to rc.

PROBLEM: added just like that, it doesn't work. I tried to wait until kdm starts, then login into terminal and run it, and this way, it DOES work. I suppose I need to wait for a service and run this after that, maybe udev or dbus, but I'm not sure. I tried with xdm, but it doesn't work.

Ideas?

EDIT: OK, I tried to run it after dbus and udev, but it doesn't work. It seems that the command must be run from an open session. Not it's time to figure how to run a superuser command ONCE at startup of a normal user session (A solution would be using cron, but I don't want to have the same command running every 5 minutres, it's quite messy).

----------

## BillWho

candamil,

I applaud your efforts trying to figure this thing out   :Smile: 

Since mine works and others don't I was giving some thought to rc.conf settings.

As far as I recall the only change I made a long time ago was setting rc_sys="uml".

I thought maybe rc_hotplug would affect it, but mine is commented #rc_hotplug="*"

Have you changed anything in this file  :Question: 

----------

## Gusar

It seems you should learn about the wonders of openrc, in particular /etc/local.d

----------

## candamil

@BillWho

I tried with rc.conf, but with no results. It seems the hotplug section is just for services, not for hardware (in fact, when I activated it, it tries to load ALL my services, even which are not in the booting and default profiles), and with the rc_sys there was no result at all.

@Gusar

With /etc/local.d the problem is the same than I said in the previous post. With that, the services run at boot time (actually, when the "local" service is started) and the results are the same as with the service I created. The command needs to be run as superuser but just once the user session has started. Something like the ".kde4/Autostart" directory. The problem with that directory is that it runs as a normal user, and I need it to be run as a superuser.

Time to keep thinking, guys. Thank you again.

----------

## Gusar

 *candamil wrote:*   

> The command needs to be run as superuser but just once the user session has started.

 

That sound really, really weird to me. But anyway, you could write a pci_rescan.sh script, configure sudoers so that a user can launch the script without password, then from ".kde4/Autostart" you do "sudo pci_rescan.sh"

----------

## candamil

In fact, yes, it is very weird. I have just created a script with the command and configured sudo so it allows me to run it as superuser without password. The thing is that if I run it manually, it works, but if I add it to .kde4/Autostart, it doesn't. Very very strange.

----------

## BillWho

candamil,

I don't know if you have sys-fs/lsscsi installed or not, but I'm curious what the output would be on yours. Mine returns:

```
root@gentoo-gateway bill # lsscsi

[0:0:0:0]    disk    ATA      WDC WD6400AAKS-2 01.0  /dev/sda 

[1:0:0:0]    cd/dvd  HL-DT-ST DVDRAM GH40F     MG01  /dev/sr0 

[2:0:0:0]    disk    ATA      WDC WD1001FALS-0 05.0  /dev/sdb 

[6:0:0:0]    disk    IOI CF/M icroDrive Disk.. 1.09  /dev/sdc 

[6:0:0:1]    disk    IOI SM/x D-Picture Disk.. 1.09  /dev/sdd 

[6:0:0:2]    disk    IOI SD/M MC Disk ...      1.09  /dev/sde 

[6:0:0:3]    disk    IOI MS/M sPro Disk ...    1.09  /dev/sdf 

```

Notice my /dev/sde. 

Also, take a look at the man page for other options. There's a mention of the sg driver being loaded if it's a module. I grepped for sg and got this:

```
root@gentoo-gateway bill # grep -i sg /usr/src/linux/.config

CONFIG_NEED_SG_DMA_LENGTH=y

CONFIG_BLK_DEV_BSG=y

# CONFIG_BLK_DEV_BSGLIB is not set

CONFIG_SGI_PARTITION=y

# CONFIG_SGI_IOC4 is not set

CONFIG_CHR_DEV_SG=y

CONFIG_SND_DMA_SGBUF=y

# Rpmsg drivers (EXPERIMENTAL)

# CONFIG_DEBUG_SG is not set

# CONFIG_SECURITY_DMESG_RESTRICT is not set

```

Again for lack of any other brilliant ideas   :Sad: 

----------

## candamil

In my case, before executing the holy command, this is what I get:

```

nomada candamil # lsscsi 

[0:0:0:0]    disk    ATA      WDC WD7500BPKT-7 01.0  /dev/sda 

[1:0:0:0]    cd/dvd  PLDS     DVD+-RW DS-8A8SH KD11  /dev/sr0 

```

Just the DVD and the HDD. After doing it the output is just the same, it seems it isn't detected as a SCSI device. In fact, the devices are:

```

nomada candamil # ls -al /dev/mm*

brw-rw---- 1 root disk 179, 0 abr 10 17:24 /dev/mmcblk0

brw-rw---- 1 root disk 179, 1 abr 10 17:24 /dev/mmcblk0p1

```

I have been trying with scripts, automatic stuff and shit, and nothing works, only the command executed from an opened session, so the easiest way I found was to add the command to a script and add that script to the sudoers file so it doesn't ask for a superuser password, but anyway, you need to execute that command manually. Other way would be to add it to the crontab, but as I already said, I don't want to have that command executing itself each 5 minutes, it's a waste of resources.

----------

## BillWho

candamil,

Have you tried to see if the card is detected in a live cd environment like ubuntu or mint or even systemrescue   :Question: 

Again for lack of any other brilliant ideas   :Sad: 

----------

## candamil

Hum... I'll try it as soon as I can. I'm testing my battery right now (1:40 remaining :p)

----------

## keenblade

İf you run this as root, does it work?

```

setpci -s 05:00.2 4c.b=0x02

```

You should change the "05:00.2" for your Multimedia Card Reader. Find it with lspci command. for me it gives this output (07:06.2) and adjust yours accordingly:

```

lspci

07:06.2 Mass storage controller: Texas Instruments 5-in-1 Multimedia Card Reader (SD/MMC/MS/MS PRO/xD)

```

If it does work, you can put this in your /etc/local.d/local.start file. 

It works that way for me.

----------

## candamil

@keenblade

As it is not detected, the setpci command doesn't work:

```

nomada candamil # setpci -s 05:00.2 4c.b=0x02

setpci: Warning: No devices selected for "4c.b=0x02".

```

(It's the same device than in your example)

@BillWho

I have tried with ubuntu, mint, wifiway and systemrescue, but with no results in any of them. 

This is a little pain in the ass  :Razz: 

----------

## luis6674

I had the same problem with a Dell XPS 15 and I always had to insert the card, then remove it, then execute the command "echo 1 > /sys/bus/pci/rescan". Then insert the card again and it worked. A pain, but it worked.

Now it stopped working. I don't know exactly when, probably when upgrading to kernel 3.6. Anyone else has this problem?

(I don't use Gentoo, but Arch Linux, I just happend to find this thread here).

----------

