How to write SD card driver for my own OS kernel?

I am working on a toy OS kernel very much like xv6, but with more features and it runs over OpenSBI. Now I am using a ramdisk due to the lack of a disk driver. My question is, how can I get a SD card / MMC driver and integrate it in my kernel?

As far as I know, the MMC is SPI based, so I should write and read the memory-mapped address to access the MMC? What more should I know? Does it have anything to do with GPIO and DMA?

Since U-boot and Linux are also on the SD card and runnning without a problem, so definitely I can check their source code about mmc/spi, but they seem really complicated. Is there a easier way, or some documents out there I can follow?