Author: ian
Date: Sun Jan  8 02:32:53 2017
New Revision: 311660
URL: https://svnweb.freebsd.org/changeset/base/311660

Log:
  Add a new sdhci interface method, get_card_present().
  
  Many embedded SoC controllers that are (more or less) sdhci-compatible don't
  implement card detect, and the related values in the PRESENT_STATE register
  aren't useful.  A bridge driver can now implement get_card_present() to read
  a gpio pin or whatever else is necessary for that system.
  
  The default implementation reads the CARD_PRESENT bit from the PRESENT_STATE
  register, so existing drivers will keep working (or keep not-fully-working,
  since many drivers right now can't detect card insert/remove).

Modified:
  head/sys/dev/sdhci/sdhci.c
  head/sys/dev/sdhci/sdhci.h
  head/sys/dev/sdhci/sdhci_if.m

Modified: head/sys/dev/sdhci/sdhci.c
==============================================================================
--- head/sys/dev/sdhci/sdhci.c  Sat Jan  7 23:42:17 2017        (r311659)
+++ head/sys/dev/sdhci/sdhci.c  Sun Jan  8 02:32:53 2017        (r311660)
@@ -164,8 +164,7 @@ sdhci_reset(struct sdhci_slot *slot, uin
        int timeout;
 
        if (slot->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) {
-               if (!(RD4(slot, SDHCI_PRESENT_STATE) &
-                       SDHCI_CARD_PRESENT))
+               if (!SDHCI_GET_CARD_PRESENT(slot->bus, slot))
                        return;
        }
 
@@ -489,7 +488,7 @@ sdhci_card_task(void *arg, int pending)
        struct sdhci_slot *slot = arg;
 
        SDHCI_LOCK(slot);
-       if (RD4(slot, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT) {
+       if (SDHCI_GET_CARD_PRESENT(slot->bus, slot)) {
                if (slot->dev == NULL) {
                        /* If card is present - attach mmc bus. */
                        slot->dev = device_add_child(slot->bus, "mmc", -1);
@@ -718,6 +717,13 @@ sdhci_generic_min_freq(device_t brdev, s
                return (slot->max_clk / SDHCI_200_MAX_DIVIDER);
 }
 
+bool
+sdhci_generic_get_card_present(device_t brdev, struct sdhci_slot *slot)
+{
+
+       return (RD4(slot, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
+}
+
 int
 sdhci_generic_update_ios(device_t brdev, device_t reqdev)
 {
@@ -834,7 +840,7 @@ sdhci_start_command(struct sdhci_slot *s
        state = RD4(slot, SDHCI_PRESENT_STATE);
        /* Do not issue command if there is no card, clock or power.
         * Controller will not detect timeout without clock active. */
-       if ((state & SDHCI_CARD_PRESENT) == 0 ||
+       if (!SDHCI_GET_CARD_PRESENT(slot->bus, slot) ||
            slot->power == 0 ||
            slot->clock == 0) {
                cmd->error = MMC_ERR_FAILED;
@@ -1323,7 +1329,7 @@ sdhci_generic_intr(struct sdhci_slot *sl
 
        /* Handle card presence interrupts. */
        if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
-               present = RD4(slot, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT;
+               present = SDHCI_GET_CARD_PRESENT(slot->bus, slot);
                slot->intmask &=
                    ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
                slot->intmask |= present ? SDHCI_INT_CARD_REMOVE :

Modified: head/sys/dev/sdhci/sdhci.h
==============================================================================
--- head/sys/dev/sdhci/sdhci.h  Sat Jan  7 23:42:17 2017        (r311659)
+++ head/sys/dev/sdhci/sdhci.h  Sun Jan  8 02:32:53 2017        (r311660)
@@ -322,5 +322,6 @@ int sdhci_generic_acquire_host(device_t 
 int sdhci_generic_release_host(device_t brdev, device_t reqdev);
 void sdhci_generic_intr(struct sdhci_slot *slot);
 uint32_t sdhci_generic_min_freq(device_t brdev, struct sdhci_slot *slot);
+bool sdhci_generic_get_card_present(device_t brdev, struct sdhci_slot *slot);
 
 #endif /* __SDHCI_H__ */

Modified: head/sys/dev/sdhci/sdhci_if.m
==============================================================================
--- head/sys/dev/sdhci/sdhci_if.m       Sat Jan  7 23:42:17 2017        
(r311659)
+++ head/sys/dev/sdhci/sdhci_if.m       Sun Jan  8 02:32:53 2017        
(r311660)
@@ -152,3 +152,9 @@ METHOD uint32_t min_freq {
        device_t                brdev;
        struct sdhci_slot       *slot;
 } DEFAULT sdhci_generic_min_freq;
+
+METHOD bool get_card_present {
+       device_t                brdev;
+       struct sdhci_slot       *slot;
+} DEFAULT sdhci_generic_get_card_present;
+
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to