From owner-svn-src-head@FreeBSD.ORG  Thu Feb 13 03:45:34 2014
Return-Path: <owner-svn-src-head@FreeBSD.ORG>
Delivered-To: svn-src-head@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id 775FFAF8;
 Thu, 13 Feb 2014 03:45:34 +0000 (UTC)
Received: from svn.freebsd.org (svn.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id 49143125E;
 Thu, 13 Feb 2014 03:45:34 +0000 (UTC)
Received: from svn.freebsd.org ([127.0.1.70])
 by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s1D3jYQ1047094;
 Thu, 13 Feb 2014 03:45:34 GMT (envelope-from ian@svn.freebsd.org)
Received: (from ian@localhost)
 by svn.freebsd.org (8.14.8/8.14.8/Submit) id s1D3jYic047093;
 Thu, 13 Feb 2014 03:45:34 GMT (envelope-from ian@svn.freebsd.org)
Message-Id: <201402130345.s1D3jYic047093@svn.freebsd.org>
From: Ian Lepore <ian@FreeBSD.org>
Date: Thu, 13 Feb 2014 03:45:34 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-head@freebsd.org
Subject: svn commit: r261817 - head/sys/arm/freescale/imx
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.17
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
 <svn-src-head.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/>
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 13 Feb 2014 03:45:34 -0000

Author: ian
Date: Thu Feb 13 03:45:33 2014
New Revision: 261817
URL: http://svnweb.freebsd.org/changeset/base/261817

Log:
  Add handling of standard "non-removable" property, and also some workaround
  code so that if card detect is wired to a gpio pin, for now we just treat
  it the same as non-removable (because there isn't a gpio driver yet).

Modified:
  head/sys/arm/freescale/imx/imx_sdhci.c

Modified: head/sys/arm/freescale/imx/imx_sdhci.c
==============================================================================
--- head/sys/arm/freescale/imx/imx_sdhci.c	Thu Feb 13 03:41:00 2014	(r261816)
+++ head/sys/arm/freescale/imx/imx_sdhci.c	Thu Feb 13 03:45:33 2014	(r261817)
@@ -71,6 +71,7 @@ struct imx_sdhci_softc {
 	uint32_t		r1bfix_intmask;
 	uint8_t			r1bfix_type;
 	uint8_t			hwtype;
+	boolean_t		force_card_present;
 };
 
 #define	R1BFIX_NONE	0	/* No fix needed at next interrupt. */
@@ -323,6 +324,8 @@ imx_sdhci_read_4(device_t dev, struct sd
 		val32 &= 0x000F0F07;
 		val32 |= (wrk32 >> 4) & SDHCI_STATE_DAT_MASK;
 		val32 |= (wrk32 >> 9) & SDHCI_RETUNE_REQUEST;
+		if (sc->force_card_present)
+			val32 |= SDHCI_CARD_PRESENT;
 		return (val32);
 	}
 
@@ -591,6 +594,7 @@ imx_sdhci_attach(device_t dev)
 {
 	struct imx_sdhci_softc *sc = device_get_softc(dev);
 	int rid, err;
+	phandle_t node;
 
 	sc->dev = dev;
 
@@ -657,6 +661,25 @@ imx_sdhci_attach(device_t dev)
 
 	sdhci_init_slot(dev, &sc->slot, 0);
 
+	/*
+	 * If the slot is flagged with the non-removable property, set our flag
+	 * to always force the SDHCI_CARD_PRESENT bit on.
+	 *
+	 * XXX Workaround for gpio-based card detect...
+	 *
+	 * We don't have gpio support yet.  If there's a cd-gpios property just
+	 * force the SDHCI_CARD_PRESENT bit on for now.  If there isn't really a
+	 * card there it will fail to probe at the mmc layer and nothing bad
+	 * happens except instantiating a /dev/mmcN device for an empty slot.
+	 */
+	node = ofw_bus_get_node(dev);
+	if (OF_hasprop(node, "non-removable"))
+		sc->force_card_present = true;
+	else if (OF_hasprop(node, "cd-gpios")) {
+		/* XXX put real gpio hookup here. */
+		sc->force_card_present = true;
+	}
+
 	bus_generic_probe(dev);
 	bus_generic_attach(dev);