8000 MMC · embox/embox Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Deryugin edited this page Oct 29, 2019 · 1 revision

User API

MMC devices are presented as a regular block devices, so they can be accessed via devfs (/dev/mmcX). Generally there's no specific API if you just work with MMC/SD card as a data storage.

Driver API

MMC and SD specifications allows to use a lot of common code for various storage devices, so you don't need to implement whole set of block device read()/write()/ioctl() functions.

It's recommended to place new MMC/SD drivers into src/drivers/mmc/host/ directory (check out existing drivers for examples).

The general idea is following:

  1. You need to implement struct host_ops with .request handler, which should send command and transfer data correctly.

Example (assume we implement driver for foobar MMC controller):

src/drivers/mmc/host/foobar/foobar.c

static void foobar_mmc_request(struct mmc_host *host, struct mmc_request *req) {
	int cmd_idx = req->cmd.opcode;
	int cmd_arg = req->cmd.arg;
	int flags = req->cmd.flags;
	/* cmd_idx, cmd_arg and flags correspond to MMC/SD specification */

	bool do_read = flags & MMC_DATA_READ;
	bool do_write = flags & MMC_DATA_WRITE;

	uintptr_t data_transfer_addr = req->data.addr;
	
	/* Do something meaningful ... */
}

const struct mmc_host_ops foobar_mmc_ops = {
	.request = foobar_mmc_request,
};

  1. Register MMC device in system if it is present.
src/drivers/mmc/host/foobar/foobar.c

#include <drivers/mmc/mmc_core.h>
#include <drivers/mmc/mmc_host.h>
#include <framework/mod/options.h>

EMBOX_UNIT_INIT(pl181_init); /* Tells the system to run this function on boot */
static int pl181_init(void) {
	/* First you need to figure out 
	 * if device is present */
	bool is_present = ...;

	if (is_present) {
		struct mmc_host *mmc = mmc_host_alloc();
		mmc->ops = &foobar_mmc_ops;

		/* This function will reset card and read 
		 * identification registers */
		mmc_sw_reset(mmc);
	}

	return 0;
}

Overview

GSoC

Demos

Supported platforms

Examples

Development

Libraries

Subsystems

Misc

Mybuild - build system

Contributing

Clone this wiki locally
0