===== SDIO =====
===== Introduction =====
SDIO is an interface designed as an extension for the existing SD card standard, to allow connecting different peripherals to the host with the standard SD controller.
Nowadays it's extensively used to connect WiFi/Bluetooth chips on ARM boards, like [[arm/imx6|Wandboard]], Raspberry Pi 3/4 or Banana Pi. %%GlobalScale%% %%DreamPlug%% has an internal SDIO slot with the Marvell WLAN/Bluetooth module.
===== Status =====
%%FreeBSD%% 13 gained SDIO support in [[https://svnweb.freebsd.org/base?view=revision&revision=348805|r348805]] and is now able to talk to the peripheral devices behind SDIO. Work is ongoing to create a WiFi driver for the Broadcom chips.
Earlier version used %%DreamPlug%% hardware, which has Marvell SD8787 chip (WiFi, BT and FM).
In order to use the SDIO bus one has to compile the kernel with the MMC stack using the CAM framework, which allows to handle interrupts generated by SDIO cards and hopefully fix several other issues with the old stack.
===== SDIO Wireless Chipsets =====
The first version of MMCCAM stack was committed to %%FreeBSD%% 12 in r320844, minimum FreeBSD_version is 1200038.
This means that it's now possible to work on drivers for the WiFi devices sitting on the SDIO bus.
| Board | Device | Linux driver | More Info | Contact |
| Wandboard | Broadcom BCM4339 802.11 a/b/g/n/ac | [[https://github.com/torvalds/linux/tree/master/drivers/net/wireless/broadcom/brcm80211/brcmfmac|brcmfmac]] | [[https://wireless.wiki.kernel.org/en/users/Drivers/brcm80211|Linux Wireless]] | |
| Raspberry Pi 3/4 | Broadcom BCM43438, etc. | [[https://github.com/torvalds/linux/tree/master/drivers/net/wireless/broadcom/brcm80211/brcmfmac|brcmfmac]] | [[https://wireless.wiki.kernel.org/en/users/Drivers/brcm80211|Linux Wireless]] | BjoernZeeb |
| Banana Pro | AMPAK AP6181 (Broadcom BCM43362) | [[https://github.com/torvalds/linux/tree/master/drivers/net/wireless/broadcom/brcm80211/brcmfmac|brcmfmac]] | wikidevi | |
| Beaglebone Black Wireless and Green Wireless | TI WL1835MOD | [[https://github.com/torvalds/linux/tree/master/drivers/net/wireless/ti/wl18xx|wl18xx]] | [[https://www.ti.com/product/WL1835MOD|Texas Instruments: WL1835MOD Product Page]] | |
So, basically the Broadcom driver is the most important to get as it's used in IMX6-based boards and RPi3/4.
===== Get hands dirty =====
Prerequisites: working Beaglebone Black / IMX6-based board (Wandboard, Hummingboard,...) / Raspberry Pi, serial console access.
* Get %%FreeBSD%%-CURRENT
* If you have Wandboard rev C, apply [[https://github.com/kibab/freebsd/commit/686272e37118a7fbef84b649fd1963f55d734aa8|this patch]] so that the second SDHC controller, where SDIO WiFi sits, is probed;
* Build world for armv7 (armv6 in case of older Rpi) and for arm64.
* Build kernel using kernel config file named GENERIC-MMCCAM;
* Run ''%%camcontrol devlist%%''
You should see something like this (this is on Beaglebone Black with MMC card inserted into the uSD slot using adapter) (TODO: updated output for rpi with sdiob):
# camcontrol devlist
at scbus0 target 0 lun 0 (pass1,sdda1)
at scbus1 target 0 lun 0 (sdda0,pass0)
Or, in case of Wandboard:
camcontrol devlist -v
scbus0 on sdhci_slot0 bus 0:
scbus1 on sdhci_slot1 bus 0:
at scbus1 target 0 lun 0 (pass0)
<> at scbus1 target 0 lun 1 ()
<> at scbus1 target 0 lun 2 ()
scbus2 on sdhci_slot2 bus 0:
at scbus2 target 0 lun 0 (pass1,sdda0)
scbus-1 on xpt0 bus 0:
<> at scbus-1 target -1 lun ffffffff (xpt0)
Here, "SDIO card" on pass0 is built-in WiFi module with lun 1 and 2 representing SDIO functions 1 and 2; SDHC card on pass1 is a SDHC card inserted into the internal uSD slot.
You can try getting controller information:
# camcontrol mmcsdcmd pass1 -I
Host controller information
Host OCR: 0x60000
Min frequency: 375 KHz
Max frequency: 96 MHz
Supported bus width: 4 bit
Current settings:
Bus width: 4 bit
Freq: 24.000 MHz(high-speed timing)
In general, ''%%camcontrol mmcsdcmd%%'' can be used to send MMC commands directly to the card from the userland.
There is also **usr.bin/sdiotool** that is a highly experimental way of prototyping the SDIO device drivers in userland. Currently it's possible to get chip revision for Broadcom-based SDIO devices.
===== More Information =====
* [[https://github.com/kibab/freebsd/tree/kibab-dplug|GitHub Repository: Old source code]]
* [[https://github.com/kibab/freebsd/tree/mmccam-current|GitHub Repository: Version of MMC stack based on CAM framework]]
* [[https://en.wikipedia.org/wiki/Secure_Digital#SDIO|Wikipedia: Article about SD and SDIO]]
* [[https://www.sdcard.org/developers/overview/sdio/index.html|sdcard.org: SDIO Specification]]
* {{sdio/sdio_bsdcam.pdf?linkonly|BSDCam 2017: SDIO Status Report Slides}}
----
{{tag>Stale}}