From owner-svn-src-head@freebsd.org Sun Jan 8 02:32:54 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ACC7CC99D3B; Sun, 8 Jan 2017 02:32:54 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 870FD131D; Sun, 8 Jan 2017 02:32:54 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v082Wrpk028929; Sun, 8 Jan 2017 02:32:53 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v082WruG028927; Sun, 8 Jan 2017 02:32:53 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201701080232.v082WruG028927@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 8 Jan 2017 02:32:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r311660 - head/sys/dev/sdhci X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jan 2017 02:32:54 -0000 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; +