SD / MMC one subsystem - the card detection

A, SDHCI drive controller

  SDHC: Secure Digital (SD) Host Controller, it refers to a set of design criteria sd host controller, and the significance of which has a certain offset registers specification, and provides a corresponding driver, host controller to facilitate the development vendor.
  After the host controller manufacturers to design in accordance with this standard, can be used directly sdhci driver is implemented using a host controller, (qcom and samsung are used in this standard). The vendor only needs to implement the relevant part of the platform, such as clock, pinctrl, power, and so parts can be.
  About this standard, refer to "SDHC_Ver3.00_Final_110225".
  Note to emphasize that this is a mmc host controller design standards, which essentially still belong mmc host. In addition, it is compatible mmc type card, rather than that can only be used for sd type card.

  SDHCI: Secure Digital (SD) Host Controller Interface, is for the SDHC standard driver interface.

  The common interfaces such as:

    sdhci_pltfm_init : SDHCI platform device initialization, mainly allocated to set sdhci_host, ultimately linked to the device platform_device

    sdhci_alloc_host : distribution sdhci_host

      mmc_alloc_host : distribution provided (scan job queue card detection) mmc_host

    sdhci_add_host : Set sdhci_host, linked to mmc_host, and registered mmc_host

      sdhci_setup_host : Set sdhci_host  

Second, the card initialization detection:

  Custom SDHC driver initialization call platform_driver_register platform for registered users platform_driver.

  Which custom SDHC driven probe will be allocated sdhci_host, sdhci_pltfm_host memory, and set sdhci_host

  Then associate mmc_host, sdhci_host, sdhci_pltfm_host.

  Then call SDHCI interfaces sdhci_add_host , resulting in sdhci_host registered to sdhci core.

  SDHCI Interface sdhci_add_host sets sdhci_host, and calling the subordinate __sdhci_add_host.

  SDHCI Interface __sdhci_add_host :

    Upon completion of the call setup request processing task queue handler sdhci_tasklet_finish

    Setting the current request in response to the timing command handler sdhci_timeout_timer

    The current data set interactive response timing sdhci_timeout_data_timer

    Set waiting queue buffer read ready interrupt

    Set sdhci_host

    Set external interrupt

    Registration LE lights

    Call mmc_add_host

    Enable card detection sdhci_enable_card_detection

  Which mmc_add_host will add the device class , call mmc_start_host open host power management notification and registration.

  Which mmc_claim_host declare exclusive host, set the power, using host-> slot.handler_priv-> cd_gpio registered threaded interrupt, performs a card detection _mmc_detect_change .

Second, the card detection execution:

  Because when you start the host will perform card detection, but this will not necessarily detect succeed, because there may be no card.

  In addition to the SDHC driver, but also to prepare a drive controller, such as Hass himci.

  Custom controller driver initialization call platform_driver_register platform registered users platform_driver.

  Wherein SDHC custom probe drive is assigned is provided custom host attributes, wherein the card detection function is used in three cases:

  1) Custom properties mmc_host_ops host function of get_cd

  2) the custom properties host function card_status

  3) Custom Host Properties timer

  Wherein the card detector is usually detected by the timer handler, the processing flow of the timer function is:

  1) detected by the register or the IO card, SD card 5 continuously checks the state of the same continues, otherwise, repeated 100 times. (Times are Custom)

  2) If it is determined whether five identical value to be inserted, if it is inserted into the soft reset, the host initializes the custom attribute, MMC calls the API subsystem mmc_detect_change .

  mmc_detect_change call _mmc_detect_change , the difference between the two is whether power management wake-up events have default

  _mmc_detect_change will determine if the device is configured to wake up, we will prevent new sleep for 5 seconds, in order to provide space for the user using the event.

  Then set mmc_host-> detect_change 1, detect changes

  Then call mmc_schedule_delayed_work scheduling work queue

  mmc_schedule_delayed_work calls queue_delayed_work execution system_freezable_wq work queue, which has two reasons for using system_freezable_wq of:

  1) It allows the simultaneous execution of multiple work (work items are not the same).

  2) When the user freezes the space during system PM, the queue will freeze.

  INIT_DELAYED_WORK (& host-> detect, mmc_rescan) and the task here is to set the mmc_alloc_host;

  So, here jump to mmc_rescan

  mmc_rescan:

    According mmc_host-> rescan_disable determine whether to allow the scan, if it is true is not allowed to exit.

    Depending on whether mmc_host-> cap determined as non-registered mobile card scan only once or can continue scanning.

    Provided mmc_host-> rescan_entered = 1, that enter the scan

    Bus operation count is incremented call mmc_bus_get

    Call mmc_rescan_try_freq, in four frequency initialize SDIO SD EMMC

  mmc_rescan_try_freq

    Provided mmc_host-> f_init, according mmc_recan frequency parameter passed in the function, generally mmc / sd / sdio initialization clock uses 400kHZ.

    Call mmc_power_up , carried out on power. When mmc_add_host, calls mmc_start_host, but first there is the host down, so the power here.

    Call mmc_hw_reset_for_init , some emmc (VCCQ always open) may not be reset after power, so if possible, may be a hardware reset.

    Do different operations depending on the card:

    1) pure SD card, the target card does not answer, the general register host host will complain, but this does not matter, you can ignore it.

    2) pure SDIO card, this is reset SDIO card, done by sending commands CMD52.

    . 3) of the SD card and combination card SDIO card, the need to send CMD52 to reset the SDIO card, SD card and then reset, as in the first CMD52 CMD0 transmission.

    Call mmc_go_idle , send CMD0, reset the SD card into the IDLE mode

    Call mmc_send_if_cond , if the SD card, then sends the voltage value for support of CMD8

    Do different depending on card detection operation card:

    1) SDIO card, call mmc_attach_sdio

    2) SD card, call mmc_attach_sd

    3) MMC card, call mmc_attach_mmc

    4) are true, then the next call mmc_power_off electrical

  Here an SD card, so just look mmc_attach_sd

    

Guess you like

Origin www.cnblogs.com/pokerface/p/11059611.html