Skip to content

Instantly share code, notes, and snippets.

@eggman
Last active May 10, 2023 01:09
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eggman/40612fdeb6d081a9a7d1a63ddef647f1 to your computer and use it in GitHub Desktop.
Save eggman/40612fdeb6d081a9a7d1a63ddef647f1 to your computer and use it in GitHub Desktop.

RaspberryPi SDIO

Spec

  • BCM2835 ha two sdhost controllers.
  • 1 sdhci : Arasan sdhci controller (SD / SDIO)
  • 2 sdhost : custom sdhost controller (SD only, but better performance)
  • RPi1 use sdhci for SD slot.
  • RPi3 use sdhost for SD slot. RPi3 use sdhci for Wi-Fi.

pin

  • pin 48 - 53 (0x30 - 0x35): SD slot
  • pin 34 - 39 (0x22 - 0x27): wi-fi module

sdhci pin

  • alt-0

sdhost pin

  • alt-3

sdhci Registers

sdhost Registers

  • BASE : 0x20202000
  • 00 SDCMD : command and flags
  • 04 SDARG : command argument
  • 08 SDTOUT : timeout counter
  • 0C SDCDIV : clock divider
  • 10 SDRSP0
  • 14 SDRSP1
  • 18 SDRSP2
  • 1C SDRSP3
  • 20 SDHSTS : sdhost status
  • 30 SDVDD : voltage setting
  • 34 SDEDM : for debug
  • 38 SDHCFG : sdhost config
  • 3C SDHBCT : block size
  • 40 ? : data port
  • 50 ? : block count

interrupt

interrupt number

  • sdhci IRQ62
  • sdhost IRQ56

interrupt register

sdhci

  • 30 Normal interrupt status
  • 32 Error interrupt status
  • 34 Normal interrupt status enable
  • 36 Error interrupt status enable

sdhost

  • 20 SDHSTS : R/W : enalbe and status
  • 0400 SDHSTS_BUSY_IRPT
  • 0200 SDHSTS_BLOCK_IRPT
  • 0100 SDHSTS_SDIO_IRPT
  • 0001 SDHSTS_DATA_FLAG

power setting

clock setting

sdhci initialize

add_sdhci()

  • get capabilities (read SDHCI_CAPABILITIES)
  • reset all (write SDHCI_SOFTWARE_RESET)
  • wait (read SDHCI_SOFTWARE_RESET)

sdhci_init()

  • assign dma buffer
  • set voltage setting (write SDHCI_POWER_CONTROL)
  • int enable (write SDHCI_INT_ENABLE)
  • signal enable (write SDHCI_SIGNAL_ENABLE)

Driver Source Code

u-boot

Linux kernel raspberrypi tree (rpi-3.6.y branch)

Linux kernel raspberrypi tree (rpi-3.19.y branch)

Linux kernel raspberrypi tree (rpi-4.0.y branch)

Linux kernel mainline (deprecated)

Linux kernel mainline

FreeBSD

NetBSD

Emulator source code

QEMU

link

@Hongqin-Li
Copy link

Hongqin-Li commented Mar 22, 2021

I'm developing an operating system on raspberry pi 3, this post helps me a lot, thanks!

@patryk4815
Copy link

sdhci pin
alt-0

sdhost pin
alt-3

I think sdhci use alt-3? And sdhost use alt-0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment