SD card driver

Source: Internet
Author: User
Hardware resources ms_wp, sd_wp, and SD card write protection: gpi_09. The write protection switch for the driver to read the SD card is used for different operations. ms_cd, sd_cd, and plug-in card Detection: gpi_04. (Ms_cd and ms_wp on the left of the schematic diagram are reversed, and the network number shall prevail.) ms_pwr, sd_pwr, power control pin, gpo_01, and 2sj355 are controlled. The driver write protection detects that gpi_09 is a single function that only inputs pins and reads the pin status, registers: p3_inp_state [9]. Code: 103 u32 TMP; 104105 TMP = _ raw_readl (gpio_p3_inp_state (gpio_iobase) & inp_state_gpi_09; by default, Codes Without MMC write protection need to be added. For mmc_platform_data data structure definitions, see :. /ARCH/ARM/include/ASM/Mach/MMC. before writing protection, the plug-in card displays the following prompt: mmc0: host does not support reading read-only switch. assuming write-enable. information from drivers/MMC/CORE/SD. print the c file. The SD card write protection status is read by the host-> OPS-> get_ro function. The following file seems to implement the get_ro function: [chenxibing @ localhost linux-2.6.27.8] $ grep mmc_host_ops-r Drivers/MMC/host/imxmmc. c: static const struct mmc_host_ops imxmci_ops = {Drivers/MMC/host/wbsd. c: static const struct mmc_host_ops wbsd_ops = {Drivers/MMC/host/tifm_sd.c: static const struct mmc_host_ops tifm_sd_ops = {Drivers/MMC/host/sdricoh_cs.c: static struct mmc_host_ops sdricoh_ops = {Drivers/MMC/host/OMA P. c: static const struct mmc_host_ops mmc_omap_ops = {Drivers/MMC/host/pxamci. c: static const struct mmc_host_ops pxamci_ops = {Drivers/MMC/host/at91_mci.c: static const struct mmc_host_ops at91_mci_ops = {Drivers/MMC/host/cloudmci. c: static struct mmc_host_ops s3mci_ops = {Drivers/MMC/host/mmci. c: static const struct mmc_host_ops mmci_ops = {Drivers/MMC/host/atmel-mci.c: static struct mmc_host_ops atmci _ Ops = {Drivers/MMC/host/sdhci. c: static const struct mmc_host_ops sdhci_ops = {Drivers/MMC/host/tmio_mmc.c: static struct mmc_host_ops tmio_mmc_ops = {Drivers/MMC/host/au1xmmc. c: static const struct mmc_host_ops au1xmmc_ops = {Drivers/MMC/host/mmc_spi.c: * beginning of an mmc_host_ops.request until the end. so bewaredrivers/MMC/host/mmc_spi.c: static const struct mmc_host_ops mmc_spi_ops = {mm of omap1 C: 84 static struct omap_mmc_platform_data h3_mmc_data = {85. nr_slots = 1,86. switch_slot = NULL, 87. init = h3_mmc_late_init, 88. cleanup = h3_mmc_cleanup, 89. slots [0] = {90. set_power = h3_mmc_set_power, 91. set_bus_mode = h3_mmc_set_bus_mode, 92. get_ro = NULL, 93. get_cover_state = h3_mmc_get_cover_state, 94. ocr_mask = mmc_vdd_28_29 | mmc_vdd_30_31 | 95 mmc_vdd_32_33 | mmc_vdd_33_34, 96. name = "MMC BLK ", 97}, 98}; omap_mmc_platform_data is defined in the arch/ARM/Plat-OMAP/include/Mach/mmc. h file. 22 struct omap_mmc_platform_data {23 struct omap_mmc_conf conf; 2425/* number of slots on board */26 unsigned nr_slots: 2; 2728/* set if your board has components or wiring that limits the29 * maximum frequency on the MMC bus */30 unsigned int max_freq; 3132/* switch the bus to a new slot */33 int (* switch_slot) (struct device * Dev, int slot); 34/* initialize board-specific MMC functionality, can be Null if35 * not supported */36 int (* init) (struct device * Dev); 37 void (* cleanup) (struct device * Dev); 38 void (* shutdown) (struct device * Dev); 3940/* to handle Board related suspend/resume functionality for MMC */41 int (* suspend) (struct device * Dev, int slot ); 42 int (* resume) (struct device * Dev, int slot); 4344 struct omap_mmc_slot_data {45 int (* set_bus_mode) (struct device * Dev, int slot, in T bus_mode); 46 int (* set_power) (struct device * Dev, int slot, int power_on, int VDD); 47 int (* get_ro) (struct device * Dev, int slot); 4849/* return MMC cover switch state, can be null if not supported.50 * 51 * possible return values: 52*0-open53*1-closed54 */55 int (* get_cover_state) (struct device * Dev, int slot); 5657 const char * Name; 58 u32 ocr_mask; 5960/* card detection irqs */61 int C Ard_detect_irq; 62 int (* card_detect) (int irq); 6364 unsigned int ban_openended: 1; 6566} slots [blocks]; 67}; the SD/MMC of lpc3250 adopts the abma_device structure description: 475 struct amba_device mmc_device = {476. dev ={ 477. coherent_dma_mask = ~ 0,478. bus_id = "Dev: 31", 479. platform_data = & lpc32xx_plat_data, 480}, 481. res = {482. start = SDK, 483. end = (sd_base + sz_4k-1), 484. flags = ioresource_mem, 485}, 486. dma_mask = ~ 0,487. IRQ = {irq_sd0, irq_sd1}, 488}; The amba_device structure is in. /include/Linux/AMBA/bus. the H file is defined as follows: 16 stuct amba_device {17 struct device dev; 18 struct resource res; 19 u64 dma_mask; 20 unsigned int periphid; 21 int IRQ [amba_nr_irqs]; 22 }; the host of the lpc3250 instance does not support get_ro and cannot detect whether the SD card is write-protected. Write protection implementation because the host of the lpc3250 does not support get_ro, we have to adopt a more direct method to directly modify Drivers/MMC/CORE/SD. in the c file, modify the function to check whether the SD card is write-protected: 499/* 500 * Check if read-only switch is active.501 */502 if (! Oldcard) {503 # If defined (bytes) 504 u32 TMP; 505 506 TMP = _ raw_readl (gpio_p3_inp_state (gpio_iobase) & inp_state_gpi_09; 507 if (TMP = 0) {508 printk (kern_warning "% s: In read-write mode \ n", mmc_hostname (host); 509} else {510 mmc_card_set_readonly (card ); 511} 512 # else513 if (! Host-> OPS-> get_ro | host-> OPS-> get_ro (host) <0) {514 printk (kern_warning "% s: host does not "515" support reading read-only "516" switch. assuming write-enable. \ n ", 517 mmc_hostname (host); 518} else {519 if (host-> OPS-> get_ro (host)> 0) 520 mmc_card_set_readonly (card ); 521} 522 # endif523} Of course, you need to add some necessary header files: 25 # If defined (config_mach_smartarm3250) 26 # include <Mach/lpc32xx_gpio.h> 27 # include "http :/ /Www.cnblogs.com/./arch/arm/mach-lpc32xx/sys-lpc32xx.h "28 # include <Mach/hardware. h> 29 # endif plug-in card detection gpi_04 is a single function that only inputs pins, registers p3_inp_state [4 Code :__ raw_readl (gpio_p3_inp_state (gpio_iobase) & inp_state_gpi_04; Power Control gpo_01 is a single function that only outputs pins, registers p3_outp_set [1] and p3_outp_clr [1]. Code: 144 _ raw_writel (outp_state_gpo (1), callback (gpio_iobase); 148 _ raw_writel (outp_state_gpo (1), callback (gpio_iobase); insert the operation information after write protection, create a directory after mounting: [root @ NXP root] # mmc0: New SD card at address e624mmcblk0: mmc0: e624 sd01g 992000kib (RO) mmcblk0: [root @ NXP root] # Mount-T vfat/dev/mmcblk0/mnt/[root @ NXP root] # mkdir/mnt/abing8mkdir: cannot create directory '/mnt/abing8': Read-Only file system [root @ NXP root] # umount/mnt/[root @ NXP root] # unplug the card and Remove write protection, insert again, mount and create the Directory: mmc0: Card e624 removedmmc0: In read-write modemmc0: New SD card at address e624mmcblk0: mmc0: e624 sd01g 992000kibmmcblk0: [root @ NXP root] # Mount-T vfat/dev/mmcblk0/mnt/[root @ NXP root] # mkdir/mnt/abing8 [root @ NXP root] # umount/mnt /view again: [root @ NXP root] # Mount-T vfat/dev/mmcblk0/mnt/[root @ NXP root] # ls/mnt/3250serial.exe abing8 2.bin

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.