Write your own SD/MMC host driver (i): Register

Source: Internet
Author: User

There are many articles on the internet that have been written about the driver of Linux SD/MMC, especially in the Samsung series, and it's not too much to describe with an immense amount. I can only say that I wrote the eVB board based on CBP SD/MMC controller driver, this driver does not use DMA, although that is what I am best at. The use of PIO mode, is actually CPU read and write, but unexpectedly also did not use Tasklet, there is no interruption of the upper and lower half of the argument, should not be a very good habit, although Tasklet is actually to start a kernel run queue, to run Pio's reading and writing, etc. There is no big difference in nature, but no use is not used, just to be realistic.

So let's talk about the Linux SD/MMC-driven work process:

First, in accordance with the platform drive, register the probe function, and then the system will call the probe function, specific methods and principles please refer to my writing and reproduced Plateform article, will not repeat.

In probe, a mmc_host structure is assigned first, and when Linux initiates various operations, the parameters are passed through this structure.

Mmc=mmc_alloc_host (sizeof (struct cbpmci_host), &pdev->dev);

Mmc_alloc_host This function is more interesting, where the first parameter passed is a length, which is an additional continuous allocation of data after mmc_hos, which I mean is followed by mmc_host assigned a cbpmci_host structure, see MMC The definition of _host is as follows:

struct Mmc_host {

struct device *parent;

......... Omit several lines ...........

unsigned long private[0] ____cacheline_aligned;

};


In fact, Cbpmci_host's position is private[0] position, ingenious Bar. Often look at Linux code can learn a lot of Linux Daniel's method. This allows you to get the private data you brought in from the Mmc_host by using this function:

static inline void *mmc_priv (struct mmc_host *host)

{

return (void *) host->private;

}

According to Linux-driven practice, this time should register SD/MMC operation function, SD/MMC operation function is probably the least Linux driver of one of the following, only a few:

struct Mmc_host_ops {

Int (*enable) (struct mmc_host *host);

Int (*disable) (struct mmc_host *host, int lazy);

void (*request) (struct mmc_host *host, struct mmc_request);

void (*set_ios) (struct mmc_host *host, struct mmc_ios);

Int (*get_ro) (struct mmc_host *host);

Int (*GET_CD) (struct mmc_host *host);

void (*ENABLE_SDIO_IRQ) (struct mmc_host *host, int enable);

};

My definition:

static struct Mmc_host_ops Cbpmci_ops = {

. Request = Cbpmci_request,

. Set_ios = Cbpmci_set_ios,

. Get_ro = Cbpmci_get_ro,

. GET_CD = Cbpmci_card_present,

. ENABLE_SDIO_IRQ = Cbpmci_enable_sdio_irq,

};

Assign the Cbpmci_ops to Mmc->ops

Mmc->ops = &cbpmci_ops;

Why not even read and write, because he is through the request inside the parameters to identify. Request function mainly deal with Linux sent to the driver of the command request, including with data and no data, with data is generally read/write, in fact, such as ext CSD is also done by reading.

The Set_ios is to set some control parameters, such as clock frequency, power on/off, bus width and so on.

Get_ro is to obtain SD/MMC write protection flag, is the SD card on the small switch state, if the return of 0 is writable, otherwise read-only.

GET_CD is to obtain the insert state of the card, return 0 has a card, or return 1.

Then of course to apply for the corresponding SD interrupt, in the interrupt function will handle the completion of the command, CRC errors and so on interrupt.

And then initialize some of the mmc_host parameters OK, such as the maximum minimum frequency, bus width, the largest block count, and so on. Then call Mmc_add_host to join the host driver.

ret = mmc_add_host (MMC);

If the driver joins without errors, the system will call the corresponding initialization process, as if it is a bit long, or let's it.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.