Bug 203385

Summary: [patch] Add support for BCM57765 Card Reader
Product: Base System Reporter: Landon Fuller <landon>
Component: kernAssignee: Adrian Chadd <adrian>
Status: Closed FIXED    
Severity: Affects Many People CC: adrian
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
BCM57765 support patch none

Description Landon Fuller 2015-09-26 22:10:54 UTC
Created attachment 161446 [details]
BCM57765 support patch

This patch adds support for the BCM57765[2] card reader function included in Broadcom's BCM57766 ethernet/sd3.0 controller. This controller is commonly found in laptops and Apple hardware (MBP, iMac, etc).

The BCM57765 chipset is almost fully compatible with the SD3.0 spec, but does not support deriving a frequency below 781KHz from its default base clock via the standard SD3.0-configured 10-bit clock divisor.

If such a divisor is set, card identification (which requires a 400KHz clock frequency) will time out[1].

As a work-around, I've made use of an undocumented device-specific clock control register to switch the controller to a 63MHz clock source when targeting clock speeds below 781KHz; the clock source is likewise switched back to the 200MHz clock when targeting speeds greater than 781KHz.

Additionally, this patch fixes a small sdhci_pci bug; the sdhci_pci_softc->quirks flag was not copied to the sdhci_slot, resulting in `quirk` behavior not being applied by sdhci.c.

[1] A number of Linux/FreeBSD users have noted that bringing up the chipsets' associated ethernet interface will allow SD cards to enumerate (slowly). This is a controller implementation side-effect triggered by the ethernet driver's reading of the hardware statistics registers.

[2] This may also fix card detection when using the BCM57785 chipset, but I don't have access to the BCM57785 chipset and can't verify.
Comment 1 Landon Fuller 2015-10-14 17:39:19 UTC
I actually snagged some BCM57785 hardware recently (2012 Retina MacBook Pro) and can confirm that this also fixes card enumeration with the BCM57785 chipset; with the patch, I can boot off of the internal sdcard reader.
Comment 2 commit-hook freebsd_committer freebsd_triage 2015-10-15 04:23:27 UTC
A commit references this bug:

Author: adrian
Date: Thu Oct 15 04:22:56 UTC 2015
New revision: 289359
URL: https://svnweb.freebsd.org/changeset/base/289359

Log:
  Add support for the BCM57765 card reader.

  This patch adds support for the BCM57765[2] card reader function included in
  Broadcom's BCM57766 ethernet/sd3.0 controller. This controller is commonly
  found in laptops and Apple hardware (MBP, iMac, etc).

  The BCM57765 chipset is almost fully compatible with the SD3.0 spec, but
  does not support deriving a frequency below 781KHz from its default base
  clock via the standard SD3.0-configured 10-bit clock divisor.

  If such a divisor is set, card identification (which requires a 400KHz
  clock frequency) will time out[1].

  As a work-around, I've made use of an undocumented device-specific clock
  control register to switch the controller to a 63MHz clock source when
  targeting clock speeds below 781KHz; the clock source is likewise switched
  back to the 200MHz clock when targeting speeds greater than 781KHz.

  Additionally, this patch fixes a small sdhci_pci bug; the
  sdhci_pci_softc->quirks flag was not copied to the sdhci_slot, resulting in
  `quirk` behavior not being applied by sdhci.c.

  [1] A number of Linux/FreeBSD users have noted that bringing up the chipsets'
  associated ethernet interface will allow SD cards to enumerate (slowly).
  This is a controller implementation side-effect triggered by the ethernet
  driver's reading of the hardware statistics registers.

  [2] This may also fix card detection when using the BCM57785 chipset, but I
  don't have access to the BCM57785 chipset and can't verify.

  I actually snagged some BCM57785 hardware recently (2012 Retina MacBook Pro)
  and can confirm that this also fixes card enumeration with the BCM57785
  chipset; with the patch, I can boot off of the internal sdcard reader.

  PR:		kern/203385
  Submitted by:	Landon Fuller <landon@landonf.org>

Changes:
  head/sys/dev/sdhci/sdhci.c
  head/sys/dev/sdhci/sdhci.h
  head/sys/dev/sdhci/sdhci_pci.c
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2017-06-26 15:33:07 UTC
Committed back in 2015.