# SD card driver support



## cpm@ (May 4, 2012)

Hi people:

Same problem with SD card reader, *I* found this unsolved thread

After this bad news... :\ 



> I abandoned the SDHCI device driver development. Sorry guys!
> Please support the FreeBSD developers on their work on the SDHCI driver.
> http://people.freebsd.org/~mav/sdhci/



UNIX will support FlashMedia driver?


----------



## Deleted member 30996 (May 4, 2012)

I picked up a Targus USB adapter for SD cards at WalMart yesterday for $8. 

It's not the greatest but all my music was stored on SD cards and it beats having to boot into another OS to access it.


----------



## cpm@ (May 5, 2012)

Thanks for your feedback, but I hope someone post other solution.


----------



## cpm@ (May 12, 2012)

Well, someone in this forum has knowledge about the sdhci(4) source driver, or a compatible driver.


----------



## cpm@ (May 12, 2012)

`uname -a`


```
FreeBSD example.FreeBSD.org 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Fri Feb 24 00:47:45 CET 2012     
root@example.FreeBSD.org:/usr/obj/usr/src/sys/MYKERNEL  i386
```

`pciconf -lv` (relevant info print)


```
none1@pci0:7:6:2:       class=0x018000 card=0xff101179 chip=0x803b104c rev=0x00 hdr=0x00
    vendor     = 'Texas Instruments'
    device     = '5-in-1 Multimedia Card Reader (SD/MMC/MS/MS PRO/xD)'
    class      = mass storage
sdhci0@pci0:7:6:3:      class=0x080501 card=0xff101179 chip=0x803c104c rev=0x00 hdr=0x00
    vendor     = 'Texas Instruments'
    device     = 'PCIxx12 SDA Standard Compliant SD Host Controller'
    class      = base peripheral
    subclass   = SD host controller
```

I *kldload* mmc, mmcsd and sdhci

`dmesg | grep sdhci`


```
sdhci0: <Generic SD HCI> mem 0xf0906800-0xf09068ff irq 18 at device 6.3 on pci7
sdhci0: 1 slot(s) allocated
```

Problem: SD reader doesn't work... bump!


----------



## cpm@ (May 12, 2012)

I post /var/log/messages output


```
kernel: pci7: <mass storage> at device 6.2 (no driver attached)
kernel: sdhci0: <Generic SD HCI> mem 0xf0906800-0xf09068ff irq 18 at device 6.3
kernel: sdhci0: 1 slot(s) allocated
```


----------



## cpm@ (May 14, 2012)

After looking at some mailing list I found a workaround



> "SD/MMC control can be at _either_ the flash controller, or the SD host, not both. The control for this is in a PCI register on the
> flash controller called MMC_SD_DIS and is documented as disabling MMC/SD support in the flash media controller... the SD host controller takes over at that point... A register in PCI space needs to be changed. A register that is configured by the eeprom in the laptop".



So how to do it then? First we need to know the current value of the reg. It is in subfunction 3 at offset 4C: 


```
40: 00 00 00 00 01 00 02 7e 00 00 00 00 20 00 00 00 
                                        ^^
```

The bit we want to set is bit 2. So we change the above to 22. 


```
example# lspci -s 07:06.2 -vvvxxx
07:06.2 Mass storage controller: Texas Instruments 5-in-1 Multimedia Card Reader (SD/MMC/MS/MS PRO/xD)
        Subsystem: Toshiba America Info Systems Device ff10
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 128 (1750ns min, 1000ns max), Cache Line Size: 16 bytes
        Interrupt: pin B routed to IRQ 18
        Region 0: Memory at f0904000 (32-bit, non-prefetchable)
        Capabilities: [44] Power Management version 2
                Flags: PMEClk- DSI- D1+ D2+ AuxCurrent=0mA PME(D0+,D1+,D2+,D3hot+,D3cold-)
                Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME-
00: 4c 10 3b 80 06 00 10 02 00 00 80 01 04 80 80 00
10: 00 40 90 f0 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 79 11 10 ff
30: 00 00 00 00 44 00 00 00 00 00 00 00 12 02 07 04
40: 00 00 00 00 01 00 02 7e 00 00 00 00 22 00 00 00
50: 79 11 10 ff 05 01 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
```

pciconf(8) does the trick


```
example# pciconf -w pci0:7:6:2 76 34
```

dmesg output


```
mmc0: <MMC/SD bus> on sdhci0
```

But I can't see mmcsd0 device in /dev and mount the file system on it.


----------



## cpm@ (May 14, 2012)

If I set hw.mmc.debug=1 and hw.sdhci.debug=1 I see following in dmesg:


```
sdhci0: <Generic SD HCI> mem 0xf0906800-0xf09068ff irq 18 at device 6.3 on pci7
sdhci0-slot0: 48MHz 4bits 3.3V DMA
sdhci0-slot0: ============== REGISTER DUMP ==============
sdhci0-slot0: Sys addr: 0x00000000 | Version:  0x00008900
sdhci0-slot0: Blk size: 0x00000000 | Blk cnt:  0x00000000
sdhci0-slot0: Argument: 0x00000000 | Trn mode: 0x00000000
sdhci0-slot0: Present:  0x000a0000 | Host ctl: 0x00000000
sdhci0-slot0: Power:    0x00000000 | Blk gap:  0x00000000
sdhci0-slot0: Wake-up:  0x00000000 | Clock:    0x00000000
sdhci0-slot0: Timeout:  0x00000000 | Int stat: 0x00000000
sdhci0-slot0: Int enab: 0x01ff00fb | Sig enab: 0x01ff00fb
sdhci0-slot0: AC12 err: 0x00000000 | Slot int: 0x00000000
sdhci0-slot0: Caps:     0x01c030b0 | Max curr: 0x00000000
sdhci0-slot0: ===========================================
sdhci0: 1 slot(s) allocated
sdhci0-slot0: Card inserted
mmc0: <MMC/SD bus> on sdhci0
```


----------



## cpm@ (Jul 15, 2012)

UPDATE:

After read PCIXXX21, PCIXXX11 Implementation Guide (Rev. A)



> *Disabling SD/MMC Support*
> 
> If SD/MMC support is not required, then the MMC_SD_DIS bit in the general control register must be set (PCI Function 0 offset 4Ch, bit 1). If this bit is set, then all of the SD_SUPPORT bits in the socket enumeration register are 0s. When this bit is set, the SD_IF_SEL bit in the socket control register is read-only 1. This bit is set by default.



I try tune PCI configuration register referred, but result is not as expected, nothing happens when I insert a card.

New considerations are welcome.


----------



## un_x (Feb 22, 2013)

*Targus Micro SD Card Reader*



			
				Trihexagonal said:
			
		

> I picked up a Targus USB adapter for SD cards at WalMart yesterday for $8.
> 
> It's not the greatest but all my music was stored on SD cards and it beats having to boot into another OS to access it.



This is exactly what I have.  I hope you are still around, because it is not working with my 9.1 kernel.  I don't have X going and can't copy/paste (don't know about moused), but am a little (lot) desperate to access this device, and I would like to know if you, or any other person has this working with FreeBSD 9.1.

`#  mount -t msdosfs /dev/da0 /mnt`
 gives 

```
mount_msdosfs: /dev/da0: Invalid argument
```
 error.
The install CD kernel gave a lot of camcontrol-type warnings about it after detection (trying, retrying, etc), but the installed kernel doesn't complain about it at boot-time.
`#  camcontrol devlist` finds it and lists it just fine. Any help on the next steps I should take would be very much appreciated because this is more serious than just a computer problem for me.

I have not had time to study and build a new kernel, so I am using the default installation kernel (upgrading from 4.11, where the device worked flawlessly). Thanks.


----------

