Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Feb 2015 19:28:26 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r278778 - stable/10/sys/arm/broadcom/bcm2835
Message-ID:  <201502141928.t1EJSQS7030632@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: loos
Date: Sat Feb 14 19:28:26 2015
New Revision: 278778
URL: https://svnweb.freebsd.org/changeset/base/278778

Log:
  MFC: r273264, r274409, r278212, r278213:
  
  Add a workaround needed to fix a bug of Arasan Host Controller where it may
  lose the contents of consecutive writes (that happens within two SD card
  clock cycles).
  
  This fixes the causes of instability during the SD card detection and
  identification on Raspberry Pi (which happens at 400 kHz and so was much
  more vulnerable to this issue).
  
  Remove the previous workaround which clearly can't provide the same effect.
  
  Remove stale comments about the issues with HS mode.
  
  Remove a previous workaround to limit the minimum sdhci frequency that
  isn't needed anymore.
  
  Remove some duplicate calls to bus_release_resource() and destroy the mutex
  on error cases.
  
  While here remove unnecessary includes.

Modified:
  stable/10/sys/arm/broadcom/bcm2835/bcm2835_sdhci.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/arm/broadcom/bcm2835/bcm2835_sdhci.c
==============================================================================
--- stable/10/sys/arm/broadcom/bcm2835/bcm2835_sdhci.c	Sat Feb 14 19:24:38 2015	(r278777)
+++ stable/10/sys/arm/broadcom/bcm2835/bcm2835_sdhci.c	Sat Feb 14 19:28:26 2015	(r278778)
@@ -29,32 +29,17 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/bio.h>
 #include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/endian.h>
 #include <sys/kernel.h>
-#include <sys/kthread.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
-#include <sys/queue.h>
-#include <sys/resource.h>
 #include <sys/rman.h>
 #include <sys/sysctl.h>
 #include <sys/taskqueue.h>
-#include <sys/time.h>
-#include <sys/timetc.h>
-#include <sys/watchdog.h>
-
-#include <sys/kdb.h>
 
 #include <machine/bus.h>
-#include <machine/cpu.h>
-#include <machine/cpufunc.h>
-#include <machine/resource.h>
-#include <machine/intr.h>
 
 #include <dev/fdt/fdt_common.h>
 #include <dev/ofw/ofw_bus.h>
@@ -82,16 +67,9 @@ __FBSDID("$FreeBSD$");
 #define dprintf(fmt, args...)
 #endif
 
-/* 
- * Arasan HC seems to have problem with Data CRC on lower frequencies.
- * Use this tunable to cap initialization sequence frequency at higher
- * value. Default is standard 400kHz
- */
-static int bcm2835_sdhci_min_freq = 400000;
 static int bcm2835_sdhci_hs = 1;
 static int bcm2835_sdhci_pio_mode = 0;
 
-TUNABLE_INT("hw.bcm2835.sdhci.min_freq", &bcm2835_sdhci_min_freq);
 TUNABLE_INT("hw.bcm2835.sdhci.hs", &bcm2835_sdhci_hs);
 TUNABLE_INT("hw.bcm2835.sdhci.pio_mode", &bcm2835_sdhci_pio_mode);
 
@@ -208,16 +186,12 @@ bcm_sdhci_attach(device_t dev)
 	    RF_ACTIVE);
 	if (!sc->sc_irq_res) {
 		device_printf(dev, "cannot allocate interrupt\n");
-		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
 		err = ENXIO;
 		goto fail;
 	}
 
 	if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-	    NULL, bcm_sdhci_intr, sc, &sc->sc_intrhand))
-	{
-		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
-		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
+	    NULL, bcm_sdhci_intr, sc, &sc->sc_intrhand)) {
 		device_printf(dev, "cannot setup interrupt handler\n");
 		err = ENXIO;
 		goto fail;
@@ -283,6 +257,7 @@ fail:
 		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
 	if (sc->sc_mem_res)
 		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
+	mtx_destroy(&sc->sc_mtx);
 
 	return (err);
 }
@@ -319,21 +294,15 @@ RD4(struct bcm_sdhci_softc *sc, bus_size
 static inline void
 WR4(struct bcm_sdhci_softc *sc, bus_size_t off, uint32_t val)
 {
-	bus_space_write_4(sc->sc_bst, sc->sc_bsh, off, val);
 
-	if ((off != SDHCI_BUFFER && off != SDHCI_INT_STATUS && off != SDHCI_CLOCK_CONTROL))
-	{
-		int timeout = 100000;
-		while (val != bus_space_read_4(sc->sc_bst, sc->sc_bsh, off) 
-		    && --timeout > 0)
-			continue;
-
-		if (timeout <= 0)
-			printf("sdhci_brcm: writing 0x%X to reg 0x%X "
-				"always gives 0x%X\n",
-				val, (uint32_t)off, 
-				bus_space_read_4(sc->sc_bst, sc->sc_bsh, off));
-	}
+	bus_space_write_4(sc->sc_bst, sc->sc_bsh, off, val);
+	/*
+	 * The Arasan HC has a bug where it may lose the content of
+	 * consecutive writes to registers that are within two SD-card
+	 * clock cycles of each other (a clock domain crossing problem). 
+	 */
+	if (sc->sc_slot.clock > 0)
+		DELAY(((2 * 1000000) / sc->sc_slot.clock) + 1);
 }
 
 static uint8_t
@@ -425,13 +394,6 @@ bcm_sdhci_write_multi_4(device_t dev, st
 	bus_space_write_multi_4(sc->sc_bst, sc->sc_bsh, off, data, count);
 }
 
-static uint32_t
-bcm_sdhci_min_freq(device_t dev, struct sdhci_slot *slot)
-{
-
-	return bcm2835_sdhci_min_freq;
-}
-
 static void
 bcm_sdhci_start_dma_seg(struct bcm_sdhci_softc *sc)
 {
@@ -684,7 +646,6 @@ static device_method_t bcm_sdhci_methods
 	DEVMETHOD(mmcbr_acquire_host,	sdhci_generic_acquire_host),
 	DEVMETHOD(mmcbr_release_host,	sdhci_generic_release_host),
 
-	DEVMETHOD(sdhci_min_freq,	bcm_sdhci_min_freq),
 	/* Platform transfer methods */
 	DEVMETHOD(sdhci_platform_will_handle,		bcm_sdhci_will_handle_transfer),
 	DEVMETHOD(sdhci_platform_start_transfer,	bcm_sdhci_start_transfer),



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502141928.t1EJSQS7030632>