Deleted Added
full compact
mmc.c (331722) mmc.c (338637)
1/*-
2 * Copyright (c) 2006 Bernd Walter. All rights reserved.
3 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
4 * Copyright (c) 2017 Marius Strobl <marius@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 38 unchanged lines hidden (view full) ---

47 * implication, estoppel or otherwise under any patent or other rights of the
48 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
49 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
50 * or the SD Card Association to disclose or distribute any technical
51 * information, know-how or other confidential information to any third party.
52 */
53
54#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 Bernd Walter. All rights reserved.
3 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
4 * Copyright (c) 2017 Marius Strobl <marius@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 38 unchanged lines hidden (view full) ---

47 * implication, estoppel or otherwise under any patent or other rights of the
48 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
49 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
50 * or the SD Card Association to disclose or distribute any technical
51 * information, know-how or other confidential information to any third party.
52 */
53
54#include <sys/cdefs.h>
55__FBSDID("$FreeBSD: stable/11/sys/dev/mmc/mmc.c 331722 2018-03-29 02:50:57Z eadler $");
55__FBSDID("$FreeBSD: stable/11/sys/dev/mmc/mmc.c 338637 2018-09-13 10:18:47Z marius $");
56
57#include <sys/param.h>
58#include <sys/systm.h>
59#include <sys/kernel.h>
60#include <sys/malloc.h>
61#include <sys/lock.h>
62#include <sys/module.h>
63#include <sys/mutex.h>

--- 1518 unchanged lines hidden (view full) ---

1582
1583static void
1584mmc_discover_cards(struct mmc_softc *sc)
1585{
1586 u_char switch_res[64];
1587 uint32_t raw_cid[4];
1588 struct mmc_ivars *ivar = NULL;
1589 const struct mmc_quirk *quirk;
56
57#include <sys/param.h>
58#include <sys/systm.h>
59#include <sys/kernel.h>
60#include <sys/malloc.h>
61#include <sys/lock.h>
62#include <sys/module.h>
63#include <sys/mutex.h>

--- 1518 unchanged lines hidden (view full) ---

1582
1583static void
1584mmc_discover_cards(struct mmc_softc *sc)
1585{
1586 u_char switch_res[64];
1587 uint32_t raw_cid[4];
1588 struct mmc_ivars *ivar = NULL;
1589 const struct mmc_quirk *quirk;
1590 const uint8_t *ext_csd;
1590 device_t child;
1591 int err, host_caps, i, newcard;
1592 uint32_t resp, sec_count, status;
1593 uint16_t rca = 2;
1591 device_t child;
1592 int err, host_caps, i, newcard;
1593 uint32_t resp, sec_count, status;
1594 uint16_t rca = 2;
1595 int16_t rev;
1596 uint8_t card_type;
1594
1595 host_caps = mmcbr_get_caps(sc->dev);
1596 if (bootverbose || mmc_debug)
1597 device_printf(sc->dev, "Probing cards\n");
1598 while (1) {
1599 child = NULL;
1600 sc->squelched++; /* Errors are expected, squelch reporting. */
1601 err = mmc_all_send_cid(sc, raw_cid);

--- 171 unchanged lines hidden (view full) ---

1773
1774 err = mmc_select_card(sc, ivar->rca);
1775 if (err != MMC_ERR_NONE) {
1776 device_printf(sc->dev, "Error selecting card %d\n",
1777 err);
1778 goto free_ivar;
1779 }
1780
1597
1598 host_caps = mmcbr_get_caps(sc->dev);
1599 if (bootverbose || mmc_debug)
1600 device_printf(sc->dev, "Probing cards\n");
1601 while (1) {
1602 child = NULL;
1603 sc->squelched++; /* Errors are expected, squelch reporting. */
1604 err = mmc_all_send_cid(sc, raw_cid);

--- 171 unchanged lines hidden (view full) ---

1776
1777 err = mmc_select_card(sc, ivar->rca);
1778 if (err != MMC_ERR_NONE) {
1779 device_printf(sc->dev, "Error selecting card %d\n",
1780 err);
1781 goto free_ivar;
1782 }
1783
1784 rev = -1;
1781 /* Only MMC >= 4.x devices support EXT_CSD. */
1782 if (ivar->csd.spec_vers >= 4) {
1783 err = mmc_send_ext_csd(sc->dev, sc->dev,
1784 ivar->raw_ext_csd);
1785 if (err != MMC_ERR_NONE) {
1786 device_printf(sc->dev,
1787 "Error reading EXT_CSD %d\n", err);
1788 goto free_ivar;
1789 }
1785 /* Only MMC >= 4.x devices support EXT_CSD. */
1786 if (ivar->csd.spec_vers >= 4) {
1787 err = mmc_send_ext_csd(sc->dev, sc->dev,
1788 ivar->raw_ext_csd);
1789 if (err != MMC_ERR_NONE) {
1790 device_printf(sc->dev,
1791 "Error reading EXT_CSD %d\n", err);
1792 goto free_ivar;
1793 }
1794 ext_csd = ivar->raw_ext_csd;
1795 rev = ext_csd[EXT_CSD_REV];
1790 /* Handle extended capacity from EXT_CSD */
1796 /* Handle extended capacity from EXT_CSD */
1791 sec_count = ivar->raw_ext_csd[EXT_CSD_SEC_CNT] +
1792 (ivar->raw_ext_csd[EXT_CSD_SEC_CNT + 1] << 8) +
1793 (ivar->raw_ext_csd[EXT_CSD_SEC_CNT + 2] << 16) +
1794 (ivar->raw_ext_csd[EXT_CSD_SEC_CNT + 3] << 24);
1797 sec_count = le32dec(&ext_csd[EXT_CSD_SEC_CNT]);
1795 if (sec_count != 0) {
1796 ivar->sec_count = sec_count;
1797 ivar->high_cap = 1;
1798 }
1799 /* Find maximum supported bus width. */
1800 ivar->bus_width = mmc_test_bus_width(sc);
1801 /* Get device speeds beyond normal mode. */
1798 if (sec_count != 0) {
1799 ivar->sec_count = sec_count;
1800 ivar->high_cap = 1;
1801 }
1802 /* Find maximum supported bus width. */
1803 ivar->bus_width = mmc_test_bus_width(sc);
1804 /* Get device speeds beyond normal mode. */
1802 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1803 EXT_CSD_CARD_TYPE_HS_52) != 0) {
1805 card_type = ext_csd[EXT_CSD_CARD_TYPE];
1806 if ((card_type & EXT_CSD_CARD_TYPE_HS_52) != 0) {
1804 setbit(&ivar->timings, bus_timing_hs);
1805 ivar->hs_tran_speed = MMC_TYPE_HS_52_MAX;
1807 setbit(&ivar->timings, bus_timing_hs);
1808 ivar->hs_tran_speed = MMC_TYPE_HS_52_MAX;
1806 } else if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1807 EXT_CSD_CARD_TYPE_HS_26) != 0) {
1809 } else if ((card_type & EXT_CSD_CARD_TYPE_HS_26) != 0) {
1808 setbit(&ivar->timings, bus_timing_hs);
1809 ivar->hs_tran_speed = MMC_TYPE_HS_26_MAX;
1810 }
1810 setbit(&ivar->timings, bus_timing_hs);
1811 ivar->hs_tran_speed = MMC_TYPE_HS_26_MAX;
1812 }
1811 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1812 EXT_CSD_CARD_TYPE_DDR_52_1_2V) != 0 &&
1813 if ((card_type & EXT_CSD_CARD_TYPE_DDR_52_1_2V) != 0 &&
1813 (host_caps & MMC_CAP_SIGNALING_120) != 0) {
1814 setbit(&ivar->timings, bus_timing_mmc_ddr52);
1815 setbit(&ivar->vccq_120, bus_timing_mmc_ddr52);
1816 }
1814 (host_caps & MMC_CAP_SIGNALING_120) != 0) {
1815 setbit(&ivar->timings, bus_timing_mmc_ddr52);
1816 setbit(&ivar->vccq_120, bus_timing_mmc_ddr52);
1817 }
1817 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1818 EXT_CSD_CARD_TYPE_DDR_52_1_8V) != 0 &&
1818 if ((card_type & EXT_CSD_CARD_TYPE_DDR_52_1_8V) != 0 &&
1819 (host_caps & MMC_CAP_SIGNALING_180) != 0) {
1820 setbit(&ivar->timings, bus_timing_mmc_ddr52);
1821 setbit(&ivar->vccq_180, bus_timing_mmc_ddr52);
1822 }
1819 (host_caps & MMC_CAP_SIGNALING_180) != 0) {
1820 setbit(&ivar->timings, bus_timing_mmc_ddr52);
1821 setbit(&ivar->vccq_180, bus_timing_mmc_ddr52);
1822 }
1823 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1824 EXT_CSD_CARD_TYPE_HS200_1_2V) != 0 &&
1823 if ((card_type & EXT_CSD_CARD_TYPE_HS200_1_2V) != 0 &&
1825 (host_caps & MMC_CAP_SIGNALING_120) != 0) {
1826 setbit(&ivar->timings, bus_timing_mmc_hs200);
1827 setbit(&ivar->vccq_120, bus_timing_mmc_hs200);
1828 }
1824 (host_caps & MMC_CAP_SIGNALING_120) != 0) {
1825 setbit(&ivar->timings, bus_timing_mmc_hs200);
1826 setbit(&ivar->vccq_120, bus_timing_mmc_hs200);
1827 }
1829 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1830 EXT_CSD_CARD_TYPE_HS200_1_8V) != 0 &&
1828 if ((card_type & EXT_CSD_CARD_TYPE_HS200_1_8V) != 0 &&
1831 (host_caps & MMC_CAP_SIGNALING_180) != 0) {
1832 setbit(&ivar->timings, bus_timing_mmc_hs200);
1833 setbit(&ivar->vccq_180, bus_timing_mmc_hs200);
1834 }
1829 (host_caps & MMC_CAP_SIGNALING_180) != 0) {
1830 setbit(&ivar->timings, bus_timing_mmc_hs200);
1831 setbit(&ivar->vccq_180, bus_timing_mmc_hs200);
1832 }
1835 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1836 EXT_CSD_CARD_TYPE_HS400_1_2V) != 0 &&
1833 if ((card_type & EXT_CSD_CARD_TYPE_HS400_1_2V) != 0 &&
1837 (host_caps & MMC_CAP_SIGNALING_120) != 0 &&
1838 ivar->bus_width == bus_width_8) {
1839 setbit(&ivar->timings, bus_timing_mmc_hs400);
1840 setbit(&ivar->vccq_120, bus_timing_mmc_hs400);
1841 }
1834 (host_caps & MMC_CAP_SIGNALING_120) != 0 &&
1835 ivar->bus_width == bus_width_8) {
1836 setbit(&ivar->timings, bus_timing_mmc_hs400);
1837 setbit(&ivar->vccq_120, bus_timing_mmc_hs400);
1838 }
1842 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1843 EXT_CSD_CARD_TYPE_HS400_1_8V) != 0 &&
1839 if ((card_type & EXT_CSD_CARD_TYPE_HS400_1_8V) != 0 &&
1844 (host_caps & MMC_CAP_SIGNALING_180) != 0 &&
1845 ivar->bus_width == bus_width_8) {
1846 setbit(&ivar->timings, bus_timing_mmc_hs400);
1847 setbit(&ivar->vccq_180, bus_timing_mmc_hs400);
1848 }
1840 (host_caps & MMC_CAP_SIGNALING_180) != 0 &&
1841 ivar->bus_width == bus_width_8) {
1842 setbit(&ivar->timings, bus_timing_mmc_hs400);
1843 setbit(&ivar->vccq_180, bus_timing_mmc_hs400);
1844 }
1849 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1850 EXT_CSD_CARD_TYPE_HS400_1_2V) != 0 &&
1851 (ivar->raw_ext_csd[EXT_CSD_STROBE_SUPPORT] &
1845 if ((card_type & EXT_CSD_CARD_TYPE_HS400_1_2V) != 0 &&
1846 (ext_csd[EXT_CSD_STROBE_SUPPORT] &
1852 EXT_CSD_STROBE_SUPPORT_EN) != 0 &&
1853 (host_caps & MMC_CAP_SIGNALING_120) != 0 &&
1854 ivar->bus_width == bus_width_8) {
1855 setbit(&ivar->timings, bus_timing_mmc_hs400es);
1856 setbit(&ivar->vccq_120, bus_timing_mmc_hs400es);
1857 }
1847 EXT_CSD_STROBE_SUPPORT_EN) != 0 &&
1848 (host_caps & MMC_CAP_SIGNALING_120) != 0 &&
1849 ivar->bus_width == bus_width_8) {
1850 setbit(&ivar->timings, bus_timing_mmc_hs400es);
1851 setbit(&ivar->vccq_120, bus_timing_mmc_hs400es);
1852 }
1858 if ((ivar->raw_ext_csd[EXT_CSD_CARD_TYPE] &
1859 EXT_CSD_CARD_TYPE_HS400_1_8V) != 0 &&
1860 (ivar->raw_ext_csd[EXT_CSD_STROBE_SUPPORT] &
1853 if ((card_type & EXT_CSD_CARD_TYPE_HS400_1_8V) != 0 &&
1854 (ext_csd[EXT_CSD_STROBE_SUPPORT] &
1861 EXT_CSD_STROBE_SUPPORT_EN) != 0 &&
1862 (host_caps & MMC_CAP_SIGNALING_180) != 0 &&
1863 ivar->bus_width == bus_width_8) {
1864 setbit(&ivar->timings, bus_timing_mmc_hs400es);
1865 setbit(&ivar->vccq_180, bus_timing_mmc_hs400es);
1866 }
1867 /*
1868 * Determine generic switch timeout (provided in
1869 * units of 10 ms), defaulting to 500 ms.
1870 */
1871 ivar->cmd6_time = 500 * 1000;
1855 EXT_CSD_STROBE_SUPPORT_EN) != 0 &&
1856 (host_caps & MMC_CAP_SIGNALING_180) != 0 &&
1857 ivar->bus_width == bus_width_8) {
1858 setbit(&ivar->timings, bus_timing_mmc_hs400es);
1859 setbit(&ivar->vccq_180, bus_timing_mmc_hs400es);
1860 }
1861 /*
1862 * Determine generic switch timeout (provided in
1863 * units of 10 ms), defaulting to 500 ms.
1864 */
1865 ivar->cmd6_time = 500 * 1000;
1872 if (ivar->raw_ext_csd[EXT_CSD_REV] >= 6)
1866 if (rev >= 6)
1873 ivar->cmd6_time = 10 *
1867 ivar->cmd6_time = 10 *
1874 ivar->raw_ext_csd[EXT_CSD_GEN_CMD6_TIME];
1868 ext_csd[EXT_CSD_GEN_CMD6_TIME];
1875 /* Handle HC erase sector size. */
1869 /* Handle HC erase sector size. */
1876 if (ivar->raw_ext_csd[EXT_CSD_ERASE_GRP_SIZE] != 0) {
1870 if (ext_csd[EXT_CSD_ERASE_GRP_SIZE] != 0) {
1877 ivar->erase_sector = 1024 *
1871 ivar->erase_sector = 1024 *
1878 ivar->raw_ext_csd[EXT_CSD_ERASE_GRP_SIZE];
1872 ext_csd[EXT_CSD_ERASE_GRP_SIZE];
1879 err = mmc_switch(sc->dev, sc->dev, ivar->rca,
1880 EXT_CSD_CMD_SET_NORMAL,
1881 EXT_CSD_ERASE_GRP_DEF,
1882 EXT_CSD_ERASE_GRP_DEF_EN,
1883 ivar->cmd6_time, true);
1884 if (err != MMC_ERR_NONE) {
1885 device_printf(sc->dev,
1886 "Error setting erase group %d\n",
1887 err);
1888 goto free_ivar;
1889 }
1890 }
1891 }
1892
1873 err = mmc_switch(sc->dev, sc->dev, ivar->rca,
1874 EXT_CSD_CMD_SET_NORMAL,
1875 EXT_CSD_ERASE_GRP_DEF,
1876 EXT_CSD_ERASE_GRP_DEF_EN,
1877 ivar->cmd6_time, true);
1878 if (err != MMC_ERR_NONE) {
1879 device_printf(sc->dev,
1880 "Error setting erase group %d\n",
1881 err);
1882 goto free_ivar;
1883 }
1884 }
1885 }
1886
1893 mmc_decode_cid_mmc(ivar->raw_cid, &ivar->cid,
1894 ivar->raw_ext_csd[EXT_CSD_REV] >= 5);
1887 mmc_decode_cid_mmc(ivar->raw_cid, &ivar->cid, rev >= 5);
1895
1896child_common:
1897 for (quirk = &mmc_quirks[0]; quirk->mid != 0x0; quirk++) {
1898 if ((quirk->mid == MMC_QUIRK_MID_ANY ||
1899 quirk->mid == ivar->cid.mid) &&
1900 (quirk->oid == MMC_QUIRK_OID_ANY ||
1901 quirk->oid == ivar->cid.oid) &&
1902 strncmp(quirk->pnm, ivar->cid.pnm,

--- 682 unchanged lines hidden ---
1888
1889child_common:
1890 for (quirk = &mmc_quirks[0]; quirk->mid != 0x0; quirk++) {
1891 if ((quirk->mid == MMC_QUIRK_MID_ANY ||
1892 quirk->mid == ivar->cid.mid) &&
1893 (quirk->oid == MMC_QUIRK_OID_ANY ||
1894 quirk->oid == ivar->cid.oid) &&
1895 strncmp(quirk->pnm, ivar->cid.pnm,

--- 682 unchanged lines hidden ---