History log of /u-boot/include/mmc.h
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# d678a59d 18-May-2024 Tom Rini <trini@konsulko.com>

Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""

When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d42223cbb8c86280a083cc3c93e6426, reversing
changes made to 2ee6f3a5f7550de3599faef9704e166e5dcace35.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 2143a11e 01-May-2024 Tom Rini <trini@konsulko.com>

mmc: Migrate MMC_SUPPORTS_TUNING to Kconfig

The constraints on the MMC_SUPPORTS_TUNING symbol can easily be
expressed in Kconfig (with the addition of SPL_MMC_SUPPORTS_TUNING).
Furthermore, in order to remove <common.h> from the MMC subsystem, the
way this symbol is used today needs to be changed in order to continue
functioning.

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8c220897 24-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Add generic tuning flag

Set generic mmc->tuning flag when performing tuning to indicate
this condition to drivers. Drivers may use this to bypass various
checks during tuning.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d1343522 24-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Convert hs400_tuning flag from u8 to bool

This hs400_tuning is a flag, make it bool. No functional change.
This will be useful in the following patch, which adds another
more generic flag, where the compiler can better use the space
now reserved for the u8 to store more flags in it.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a3b27866 20-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Drop unused mmc_send_tuning() cmd_error parameter

The cmd_error parameter is not used, remove it.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# d06e4899 27-Jan-2024 Jonas Karlman <jonas@kwiboo.se>

mmc: Add SPL_MMC_PWRSEQ to fix link issue when building SPL

With MMC_PWRSEQ enabled the following link issue may happen when
building SPL and SPL_PWRSEQ is not enabled.

aarch64-linux-gnu-ld.bfd: drivers/mmc/meson_gx_mmc.o: in function `meson_mmc_probe':
drivers/mmc/meson_gx_mmc.c:295: undefined reference to `pwrseq_set_power'

Fix this by adding a SPL_MMC_PWRSEQ Kconfig option used to enable mmc
pwrseq support in SPL.

Also add depends on DM_GPIO to fix following link issue:

aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.o: in function `mmc_pwrseq_set_power':
drivers/mmc/mmc-pwrseq.c:26: undefined reference to `gpio_request_by_name'
aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.c:29: undefined reference to `dm_gpio_set_value'
aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.c:31: undefined reference to `dm_gpio_set_value'

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Acked-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>

# 0ac2cca3 19-Jun-2023 Hai Pham <hai.pham.ud@renesas.com>

mmc: Introduce mmc_send_stop_transmission()

If a tuning command times out, the card could still be processing it,
which will cause problems for recovery. The eMMC specification section
6.6 Data transfer mode (cont’d) claims that CMD12 can be used to stop
CMD21:
"
The relationship between the various data transfer modes is summarized (see Figure 27):
- All data read commands can be aborted any time by the stop command (CMD12).
The data transfer will terminate and the Device will return to the Transfer State.
The read commands are: ... send tuning block (CMD21) ....
"
Add a function that does that.

Based on Linux commit [1] and [2].

[1] e711f0309109 ("mmc: mmc: Introduce mmc_abort_tuning()")
[2] 21adc2e45f4e ("mmc: Improve function name when aborting a tuning
cmd")

Reviewed-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Hai Pham <hai.pham.ud@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
[Marek: Update commit message, quote relevant part of the specification.
Rename to mmc_send_stop_transmission().
Remove tuning opcode check, this is controller driver specific.
Deduplicate part of mmc_read_blocks() using this function.]
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# eeb739a6 26-Jan-2023 Loic Poulain <loic.poulain@linaro.org>

mmc: Check support for TRIM operations

When secure/insecure TRIM operations are supported.
When used as erase command argument it applies the
erase operation to write blocks instead of erase
groups.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# cf1f7355 05-Jan-2023 Marek Vasut <marex@denx.de>

cmd: mmc: Expand bkops handling

Add more capable "bkops" command which allows enabling and disabling both
manual and automatic bkops. The existing 'mmc bkops-enable' subcommand is
poorly named to cover all the possibilities, hence the new-ish subcommand.
Note that both commands are wrappers around the same common code.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 75fc79e5 28-Oct-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_MMC_MAX_BLK_COUNT to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_MMC_MAX_BLK_COUNT

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 This contributor prefers not to receive mails <noreply@example.com>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@amd.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 2143a11e 01-May-2024 Tom Rini <trini@konsulko.com>

mmc: Migrate MMC_SUPPORTS_TUNING to Kconfig

The constraints on the MMC_SUPPORTS_TUNING symbol can easily be
expressed in Kconfig (with the addition of SPL_MMC_SUPPORTS_TUNING).
Furthermore, in order to remove <common.h> from the MMC subsystem, the
way this symbol is used today needs to be changed in order to continue
functioning.

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8c220897 24-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Add generic tuning flag

Set generic mmc->tuning flag when performing tuning to indicate
this condition to drivers. Drivers may use this to bypass various
checks during tuning.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d1343522 24-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Convert hs400_tuning flag from u8 to bool

This hs400_tuning is a flag, make it bool. No functional change.
This will be useful in the following patch, which adds another
more generic flag, where the compiler can better use the space
now reserved for the u8 to store more flags in it.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a3b27866 20-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Drop unused mmc_send_tuning() cmd_error parameter

The cmd_error parameter is not used, remove it.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# d06e4899 27-Jan-2024 Jonas Karlman <jonas@kwiboo.se>

mmc: Add SPL_MMC_PWRSEQ to fix link issue when building SPL

With MMC_PWRSEQ enabled the following link issue may happen when
building SPL and SPL_PWRSEQ is not enabled.

aarch64-linux-gnu-ld.bfd: drivers/mmc/meson_gx_mmc.o: in function `meson_mmc_probe':
drivers/mmc/meson_gx_mmc.c:295: undefined reference to `pwrseq_set_power'

Fix this by adding a SPL_MMC_PWRSEQ Kconfig option used to enable mmc
pwrseq support in SPL.

Also add depends on DM_GPIO to fix following link issue:

aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.o: in function `mmc_pwrseq_set_power':
drivers/mmc/mmc-pwrseq.c:26: undefined reference to `gpio_request_by_name'
aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.c:29: undefined reference to `dm_gpio_set_value'
aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.c:31: undefined reference to `dm_gpio_set_value'

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Acked-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>

# 0ac2cca3 19-Jun-2023 Hai Pham <hai.pham.ud@renesas.com>

mmc: Introduce mmc_send_stop_transmission()

If a tuning command times out, the card could still be processing it,
which will cause problems for recovery. The eMMC specification section
6.6 Data transfer mode (cont’d) claims that CMD12 can be used to stop
CMD21:
"
The relationship between the various data transfer modes is summarized (see Figure 27):
- All data read commands can be aborted any time by the stop command (CMD12).
The data transfer will terminate and the Device will return to the Transfer State.
The read commands are: ... send tuning block (CMD21) ....
"
Add a function that does that.

Based on Linux commit [1] and [2].

[1] e711f0309109 ("mmc: mmc: Introduce mmc_abort_tuning()")
[2] 21adc2e45f4e ("mmc: Improve function name when aborting a tuning
cmd")

Reviewed-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Hai Pham <hai.pham.ud@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
[Marek: Update commit message, quote relevant part of the specification.
Rename to mmc_send_stop_transmission().
Remove tuning opcode check, this is controller driver specific.
Deduplicate part of mmc_read_blocks() using this function.]
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# eeb739a6 26-Jan-2023 Loic Poulain <loic.poulain@linaro.org>

mmc: Check support for TRIM operations

When secure/insecure TRIM operations are supported.
When used as erase command argument it applies the
erase operation to write blocks instead of erase
groups.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# cf1f7355 05-Jan-2023 Marek Vasut <marex@denx.de>

cmd: mmc: Expand bkops handling

Add more capable "bkops" command which allows enabling and disabling both
manual and automatic bkops. The existing 'mmc bkops-enable' subcommand is
poorly named to cover all the possibilities, hence the new-ish subcommand.
Note that both commands are wrappers around the same common code.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 75fc79e5 28-Oct-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_MMC_MAX_BLK_COUNT to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_MMC_MAX_BLK_COUNT

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 This contributor prefers not to receive mails <noreply@example.com>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@amd.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 8c220897 24-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Add generic tuning flag

Set generic mmc->tuning flag when performing tuning to indicate
this condition to drivers. Drivers may use this to bypass various
checks during tuning.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d1343522 24-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Convert hs400_tuning flag from u8 to bool

This hs400_tuning is a flag, make it bool. No functional change.
This will be useful in the following patch, which adds another
more generic flag, where the compiler can better use the space
now reserved for the u8 to store more flags in it.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a3b27866 20-Feb-2024 Marek Vasut <marek.vasut+renesas@mailbox.org>

mmc: Drop unused mmc_send_tuning() cmd_error parameter

The cmd_error parameter is not used, remove it.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

# d06e4899 27-Jan-2024 Jonas Karlman <jonas@kwiboo.se>

mmc: Add SPL_MMC_PWRSEQ to fix link issue when building SPL

With MMC_PWRSEQ enabled the following link issue may happen when
building SPL and SPL_PWRSEQ is not enabled.

aarch64-linux-gnu-ld.bfd: drivers/mmc/meson_gx_mmc.o: in function `meson_mmc_probe':
drivers/mmc/meson_gx_mmc.c:295: undefined reference to `pwrseq_set_power'

Fix this by adding a SPL_MMC_PWRSEQ Kconfig option used to enable mmc
pwrseq support in SPL.

Also add depends on DM_GPIO to fix following link issue:

aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.o: in function `mmc_pwrseq_set_power':
drivers/mmc/mmc-pwrseq.c:26: undefined reference to `gpio_request_by_name'
aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.c:29: undefined reference to `dm_gpio_set_value'
aarch64-linux-gnu-ld.bfd: drivers/mmc/mmc-pwrseq.c:31: undefined reference to `dm_gpio_set_value'

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Acked-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>

# 0ac2cca3 19-Jun-2023 Hai Pham <hai.pham.ud@renesas.com>

mmc: Introduce mmc_send_stop_transmission()

If a tuning command times out, the card could still be processing it,
which will cause problems for recovery. The eMMC specification section
6.6 Data transfer mode (cont’d) claims that CMD12 can be used to stop
CMD21:
"
The relationship between the various data transfer modes is summarized (see Figure 27):
- All data read commands can be aborted any time by the stop command (CMD12).
The data transfer will terminate and the Device will return to the Transfer State.
The read commands are: ... send tuning block (CMD21) ....
"
Add a function that does that.

Based on Linux commit [1] and [2].

[1] e711f0309109 ("mmc: mmc: Introduce mmc_abort_tuning()")
[2] 21adc2e45f4e ("mmc: Improve function name when aborting a tuning
cmd")

Reviewed-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Hai Pham <hai.pham.ud@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
[Marek: Update commit message, quote relevant part of the specification.
Rename to mmc_send_stop_transmission().
Remove tuning opcode check, this is controller driver specific.
Deduplicate part of mmc_read_blocks() using this function.]
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# eeb739a6 26-Jan-2023 Loic Poulain <loic.poulain@linaro.org>

mmc: Check support for TRIM operations

When secure/insecure TRIM operations are supported.
When used as erase command argument it applies the
erase operation to write blocks instead of erase
groups.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# cf1f7355 05-Jan-2023 Marek Vasut <marex@denx.de>

cmd: mmc: Expand bkops handling

Add more capable "bkops" command which allows enabling and disabling both
manual and automatic bkops. The existing 'mmc bkops-enable' subcommand is
poorly named to cover all the possibilities, hence the new-ish subcommand.
Note that both commands are wrappers around the same common code.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 75fc79e5 28-Oct-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_MMC_MAX_BLK_COUNT to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_MMC_MAX_BLK_COUNT

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 This contributor prefers not to receive mails <noreply@example.com>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@amd.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 0ac2cca3 19-Jun-2023 Hai Pham <hai.pham.ud@renesas.com>

mmc: Introduce mmc_send_stop_transmission()

If a tuning command times out, the card could still be processing it,
which will cause problems for recovery. The eMMC specification section
6.6 Data transfer mode (cont’d) claims that CMD12 can be used to stop
CMD21:
"
The relationship between the various data transfer modes is summarized (see Figure 27):
- All data read commands can be aborted any time by the stop command (CMD12).
The data transfer will terminate and the Device will return to the Transfer State.
The read commands are: ... send tuning block (CMD21) ....
"
Add a function that does that.

Based on Linux commit [1] and [2].

[1] e711f0309109 ("mmc: mmc: Introduce mmc_abort_tuning()")
[2] 21adc2e45f4e ("mmc: Improve function name when aborting a tuning
cmd")

Reviewed-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Hai Pham <hai.pham.ud@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
[Marek: Update commit message, quote relevant part of the specification.
Rename to mmc_send_stop_transmission().
Remove tuning opcode check, this is controller driver specific.
Deduplicate part of mmc_read_blocks() using this function.]
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# eeb739a6 26-Jan-2023 Loic Poulain <loic.poulain@linaro.org>

mmc: Check support for TRIM operations

When secure/insecure TRIM operations are supported.
When used as erase command argument it applies the
erase operation to write blocks instead of erase
groups.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# cf1f7355 05-Jan-2023 Marek Vasut <marex@denx.de>

cmd: mmc: Expand bkops handling

Add more capable "bkops" command which allows enabling and disabling both
manual and automatic bkops. The existing 'mmc bkops-enable' subcommand is
poorly named to cover all the possibilities, hence the new-ish subcommand.
Note that both commands are wrappers around the same common code.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 75fc79e5 28-Oct-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_MMC_MAX_BLK_COUNT to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_MMC_MAX_BLK_COUNT

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@amd.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# eeb739a6 26-Jan-2023 Loic Poulain <loic.poulain@linaro.org>

mmc: Check support for TRIM operations

When secure/insecure TRIM operations are supported.
When used as erase command argument it applies the
erase operation to write blocks instead of erase
groups.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# cf1f7355 05-Jan-2023 Marek Vasut <marex@denx.de>

cmd: mmc: Expand bkops handling

Add more capable "bkops" command which allows enabling and disabling both
manual and automatic bkops. The existing 'mmc bkops-enable' subcommand is
poorly named to cover all the possibilities, hence the new-ish subcommand.
Note that both commands are wrappers around the same common code.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 75fc79e5 28-Oct-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_MMC_MAX_BLK_COUNT to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_MMC_MAX_BLK_COUNT

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# cf1f7355 05-Jan-2023 Marek Vasut <marex@denx.de>

cmd: mmc: Expand bkops handling

Add more capable "bkops" command which allows enabling and disabling both
manual and automatic bkops. The existing 'mmc bkops-enable' subcommand is
poorly named to cover all the possibilities, hence the new-ish subcommand.
Note that both commands are wrappers around the same common code.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 75fc79e5 28-Oct-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_MMC_MAX_BLK_COUNT to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_MMC_MAX_BLK_COUNT

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 75fc79e5 28-Oct-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_SYS_MMC_MAX_BLK_COUNT to Kconfig

This converts the following to Kconfig:
CONFIG_SYS_MMC_MAX_BLK_COUNT

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# e33a5c6b 11-Aug-2022 Simon Glass <sjg@chromium.org>

blk: Switch over to using uclass IDs

We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.

Drop the if_type values and use the uclass ones instead.

Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 19a29ff3 25-Apr-2022 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>

drivers: mmc: write protect single boot area

Add features to write protect single boot area rather than all boot
areas.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# d6ad5a0a 26-May-2022 Loic Poulain <loic.poulain@linaro.org>

mmc: Add support for wait_dat0 callback

There is no wait_dat0 mmc ops, causing operations waiting for data
line state change (e.g mmc_switch_voltage) to fallback to a 250ms
active delay. mmc_ops still used when DM_MMC is not enabled, which
is often the case for SPL. The result can be unexpectly long SPL
boot time.

This change adds support for wait_dat0() mmc operation.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# b8aa463e 24-Apr-2022 Simon Glass <sjg@chromium.org>

bootstd: mmc: Add a bootdev driver

Add a bootdev driver for MMC. It mostly just calls the bootdev helper
function.

Add a function to obtain the block device for an MMC controller.

Fix up the comment for mmc_get_blk_desc() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marex@denx.de>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marex@denx.de>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@konsulko.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@konsulko.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@konsulko.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@konsulko.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wd@denx.de>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# a15b2e6b 18-Dec-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: unconditionally define mmc_deinit()

We want to replace '#ifdef' by 'if (IS_ENABLED(CONFIG_...))' in our code.
Therefore functions should be defined unconditionally even if they are not
implemented.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenz@kernel.org>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <anup@brainfault.org>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 19f7a34a 13-Aug-2021 Aswath Govindraju <a-govindraju@ti.com>

mmc: Add support for enumerating MMC card in a given mode using mmc command

Add support for enumerating MMC card in a given mode using mmc rescan and
mmc dev commands. The speed mode is provided as the last argument in these
commands and is indicated using the index from enum bus_mode in
include/mmc.h. A speed mode can be set only if it has already been enabled
in the device tree.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# a4c577f9 14-Jul-2021 Pali Rohár <pali@kernel.org>

mmc: mmc_get_op_cond: Allow quiet detection of eMMC

Add a new 'quiet' argument to mmc_get_op_cond() function which avoids
printing error message when SD/eMMC card is not detected.

Espressobin and mx6cuboxi boards use this function for detecting presence
of eMMC and therefore it is expected and normal that eMMC does not have to
be connected. So error message "Card did not respond to voltage select!"
should be skipped in this case as it is not an error.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# d77d61ea 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: mmc-uclass: change to static about dm function

Change to static about dm function.
They can be used with wrapper functions.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 2da2335a 30-May-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: fsl_esdhc_imx: use mmc_send_cmd instead of dm_mmc_send_cmd

Use mmc_send_cmd instead of dm_mmc_send_cmd.
It doesn't need to distinguish this function.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# caee38ae 15-Feb-2021 Jaehoon Chung <jh80.chung@samsung.com>

mmc: pwrseq: add mmc-pwrseq file to provide a generic interface

Add mmc-pwrseq file to provide a generic interface.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8e2b0af7 23-Jan-2021 Stefan Bosch <stefan_b@posteo.net>

mmc: fix response timeout after switch command

After issuing the switch command: Wait until 'current state' of the card
status becomes 'tran'. This prevents from response timeout at the next
command because of 'current state' = 'data'.

Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# c89c96d3 12-Jan-2021 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

mmc: Introduce mmc_phys_to_bus()/mmc_bus_to_phys()

This will allow us to use DM variants of phys_to_bus()/bus_to_phys()
when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 17a42abb 23-Oct-2020 Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

mmc: Define timing macro's

Define timing macro's for all the available speeds of mmc. This is
done similar to linux. Replace speed macro's used with these new timing
macro's wherever applicable.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# d271e105 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a mmc_hs400_prepare_ddr() interface

Add a mmc_hs400_prepare_ddr() interface for controllers
which needs preparation before switching to DDR mode for
HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 8c968808 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a hs400_tuning flag

Some controllers may have difference between HS200 tuning
and HS400 tuning, such as different registers setting,
different procedure, or different errata.

This patch is to add a hs400_tuning flag to identify the
tuning for HS400 mode.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>

# 390f9bdd 01-Sep-2020 Yangbo Lu <yangbo.lu@nxp.com>

mmc: add a reinit() API

For DM_MMC, the controller re-initialization is needed to
clear old configuration for mmc rescan.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 68fd6026 15-Sep-2020 Sean Anderson <seanga2@gmail.com>

mmc: Add mmc_dev()

This macro is necessary for arasan_zynqmp_dll_reset to compile.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Patrick Delaunay <patrick.delaunay@st.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 3a905cd2 08-Apr-2020 Simon Glass <sjg@chromium.org>

dm: mmc: Update mmc_get_mmc_dev() to use const *

This function does not modify the device to change it to use const *, so
that callers with a const udevice * can call it without a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 145429aa 03-Apr-2020 Marek Vasut <marek.vasut@gmail.com>

mmc: Add option to adjust b_max before long read

Add getter function which permits adjusting the maximum number of
blocks that could be read in a single sustained read transfer based
on the location of the source/target buffer and length, before such
transfer starts.

This is mainly useful on systems which have various DMA restrictions
for different memory locations, e.g. DMA limited to 32bit addresses,
and where a bounce buffer is used to work around such restrictions.
Since the U-Boot bounce buffer is mallocated, it's size is limited
by the malloc area size, and the read transfer to such a buffer must
also be limited. However, as not all areas are limited equally, the
b_max should be adjusted accordinly as needed to avoid degrading
performance unnecessarily.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>

# 0469d846 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: mmc: provide boot area protection command

Provide command 'mmc wp' to power on write protect boot areas on eMMC
devices.

The B_PWR_WP_EN bit in the extended CSD register BOOT_WP is set. The boot
area are write protected until the next power cycle occurs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 1601ea21 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: export mmc_send_ext_csd()

Export function mmc_send_ext_csd() for reading the extended CSD register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9abfe33d 29-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

mmc: EXT_CSD registers for write protection

Add the EXT_CSD register definition related to write protection.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# e8d5dde4 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Merge SD_LEGACY and MMC_LEGACY bus modes

MMC_LEGACY & SD_LEGACY are not differentiated timings in the spec and
don't have any meaningful differences. Therefore, get rid of all
references to SD_LEGACY and use MMC_LEGACY to mean both of them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# 32860bdb 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a deferred_probe() API

Add a deferred_probe() API for platforms that want to do some
configurations just before starting to enumerate the device.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 0d3c8584 26-Feb-2020 Faiz Abbas <faiz_abbas@ti.com>

mmc: Add a saved_clock member

Add a saved_clock member to struct mmc to store the previous clock speed
in the clock needs to be stopped for some time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

# bd602c53 24-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

mmc: make <mmc.h> self-contained

This header uses bd_t without including its definition.

Change it to (struct bd_info), and add the forward declaration
to specify it as a structure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# a7b2b6cc 14-Feb-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

mmc: add mmc_get_dma_dir() helper

Copied from Linux kernel.
include/linux/mmc/host.h

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# d4a5fa31 11-Jan-2020 Joel Johnson <mrjoel@lixil.net>

mmc: add additional quirk for APP_CMD retry

It was observed (on ClearFog Base) that sending MMC APP_CMD returned
an error on the first attempt. The issue appears to be timing related
since even inserting a puts() short debug entry before the execution
added sufficient delay to receive success on first attempt.

Follow the existing quirks pattern to retry if initial issuance
failed so as to not introduce any delay unless needed.

Signed-off-by: Joel Johnson <mrjoel@lixil.net>

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@mips.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 Wolfgang Denk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 3602a56a 19-Sep-2019 Yann Gautier <yann.gautier@st.com>

mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>

# 80f02019 09-Sep-2019 Lokesh Vutla <lokeshvutla@ti.com>

spl: dm_mmc: Initialize only the required mmc device

In SPL, all the available mmc devices gets initialized during boot.
This might not work in cases where clocks are not available for
certain mmc devices(other than boot device) and the support for
enabling device might not be ready.

Texas Instruments' K3 J721E device having a central system controller
(dmsc) is one such example falling in this category. Below is the
sequence for the failing scenario:
- ROM comes up in SD mode and loads SPL by just initialing SD card.
- SPL loads dmsc firmware from SD Card.
Since ROM has enabled SD, SPL need not enable the SD, just need
to re initialize the card. But SPL is trying to initialize other MMC
instances which are in disabled state. Since dmsc firmware is not yet
available, devices cannot be enabled. So in SPL, initialize only the
mmc device that is needed.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@imgtec.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 wdenk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 6cf8a903 14-Aug-2019 Sam Protsenko <semen.protsenko@linaro.org>

mmc: Rename timeout parameters for clarification

It's quite hard to figure out time units for various function that have
timeout parameters. This leads to possible errors when one forgets to
convert ms to us, for example. Let's rename those parameters
correspondingly to 'timeout_us' and 'timeout_ms' to prevent such issues
further.

While at it, add time units info as comments to struct mmc fields.

This commit doesn't change the behavior, only renames parameters names.
Buildman should report no changes at all.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>

# 44acd492 10-Jul-2019 Peng Fan <peng.fan@nxp.com>

mmc: support hs400 enhanced strobe mode

eMMC 5.1+ supports HS400 Enhances Strobe mode without the need for
tuning procedure.
The flow is as following:
- set HS_TIMIMG (Highspeed)
- Host change freq to <= 52Mhz
- set the bus width to Enhanced strobe and DDR8Bit(CMD6),
EXT_CSD[183] = 0x86 instead of 0x80
- set HS_TIMING to 0x3 (HS400)
- Host change freq to <= 200Mhz
- Host select HS400 enhanced strobe complete

Signed-off-by: Peng Fan <peng.fan@nxp.com>

# a897269c 07-Jul-2019 Anup Patel <Anup.Patel@wdc.com>

cmd: Remove mmc_spi command

The mmc_spi command was added to manually setup MMC over SPI bus
using command. This was required by the legacy non-DM MMC_SPI driver.

With DM based MMC_SPI driver in-place, we can now use all general
storge commands and mmc command for MMC over SPI bus hence we remove
the mmc_spi command all it's references.

Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 513e00b6 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: When switching partition, use the timeout specified in the ext_csd

The e-MMC spec allows the e-MMC to specify a timeout for the partition
switch command. It can take up to 2550 ms. There is no lower limit to this
value in the spec, but do as the the linux driver does and force it to be
at least 300ms.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 39320c53 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the generic timeout for cmd6 (SWITCH) provided in the ext_csd

Starting with rev 4.5, the eMMC can define a generic timeout for the
SWITCH command.

Following Linux Kernel code, the timeout also changed from 1000 -> 500

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# cd0b80ec 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: if possible, poll the busy state using DAT0

Using the DAT0 line as a rdy/busy line is an alternative to reading the
status register of the card. It especially useful in situation where the
bus is not in a good shape, like when modes are switched.
This is also how the linux driver behaves.

Note of warning: As per the specification, while polling on DAT0 the CLK
must not turned off: "[...] Without a clock edge the Device (unless
previously disconnected by a deselect command (CMD7)) will force the DAT0
line down, forever. [...]"

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c5bda375 02-Jul-2019 Jean-Jacques Hiblot <jjhiblot@ti.com>

Revert "mmc: Add a new callback function to perform the 74 clocks cycle sequence"

This reverts commit 318a7a576bc49aa8b4207e694d3fbd48c663d6ac.

The last and only user of this callback had been the omap_hsmmc driver.
It is not used anymore. Removing the callback.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 86a94e7b 25-Jun-2019 T Karthik Reddy <t.karthik.reddy@xilinx.com>

mmc: Read sd card detect properties from DT

This patch reads card detect properties from device tree &
added mmc capability macros in mmc.h.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>

# fceea992 28-Jan-2019 Marek Vasut <marek.vasut+renesas@gmail.com>

mmc: Downgrade SD/MMC from UHS/HS200/HS400 modes before boot

Older kernel versions or systems which do not connect eMMC reset line
properly may not be able to handle situations where either the eMMC
is left in HS200/HS400 mode or SD card in UHS modes by the bootloader
and may misbehave. Downgrade the eMMC to HS/HS52 mode and/or SD card
to non-UHS mode before booting the kernel to allow such older kernels
to work with modern U-Boot.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

# 43d17c48 12-Jan-2019 Rajesh Bhagat <rajesh.bhagat@nxp.com>

env: fix allow to build multiple environments

Patch fixes build error when enabling CONFIG_ENV_IS_IN_SPI_FLAS
and CONFIG_ENV_IS_IN_MMC at the same time mentioned issue in
below link:

Refer: https://lists.denx.de/pipermail/u-boot/2018-February/319565.html

build error when enabling CONFIG_ENV_IS_IN_SPI_FLASH and
CONFIG_ENV_IS_IN_MMC at the same time.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>

# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>

# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>

# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>

# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>

# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 07d77838 01-Aug-2017 Tom Rini <trini@konsulko.com>

Merge git://git.denx.de/u-boot-x86


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>

# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>

# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>

# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>

# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>

# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>

# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>

# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# b9cb6482 02-Mar-2015 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>

# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>

# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>

# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

# cc49da24 02-Jun-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>

# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>

# 519fdde9 08-Apr-2014 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot/master' into 'u-boot-arm/master'

Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>

# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1ad6364e 04-Mar-2014 Stefano Babic <sbabic@denx.de>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@imgtec.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 348e47f7 22-Jun-2013 Tom Rini <trini@ti.com>

Merge branch 'master' of git://git.denx.de/u-boot-arm


# 69f14dc2 18-Jun-2013 Albert ARIBAUD <albert.u.boot@aribaud.net>

Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master'

Conflicts:
spl/Makefile


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>

# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>

# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>

# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>

# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>

# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>

# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>

# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>

# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>

# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>

# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>

# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>

# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>

# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>

# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>

# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>

# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>

# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>

# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>

# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>

# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>

# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

# 71f95118 15-Jun-2003 wdenk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board

# 4853ad3e 25-Sep-2018 Jens Wiklander <jens.wiklander@linaro.org>

mmc: rpmb: add mmc_rpmb_route_frames()

Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an
external entity.

Tested-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 3dd2626f 10-Aug-2018 Peng Fan <peng.fan@nxp.com>

mmc: add HS400 support

Add HS400 support.
Selecting HS400 needs first select HS200 according to spec, so use
a dedicated function for HS400.
Add HS400 related macros.
Remove the restriction of only using the low 6 bits of
EXT_CSD_CARD_TYPE, using all the 8 bits.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Jean-Jacques Hiblot <jjhiblot@ti.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Faiz Abbas <faiz_abbas@ti.com>
Cc: Marek Vasut <marex@denx.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>


# 6c09eba5 11-Jun-2018 Jon Nettleton <jon@solid-run.com>

mmc: break out get_op_cond code to its own function

This code is useful for testing the existance of devices that
do not have card detect capabilities. This breaks out the core
functionality and leaves the actual init logic and error reporting
in mmc_start_init().

Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Stefano Babic <sbabic@denx.de>


# 31d95004 11-Jun-2018 Baruch Siach <baruch@tkos.co.il>

mmc: drop mention of IN_PROGRESS status

The IN_PROGRESS macro has been removed in commit bd47c13583f (mmc: Fix
splitting device initialization). Remove it from the mmc_start_init()
function description.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>


# 65117182 26-Jan-2018 Jaehoon Chung <jh80.chung@samsung.com>

mmc: add the MMC_CLK_ENABLE/DISABLE macro in mmc.h

mmc_set_clock() function has the disable argument as bool type.
When mmc_set_clock is called, it might be passed to "true" or "false".
But it's too confusion whether clock is enabled or disabled with only
"true" and "false".
To prevent the confusion, replace to MMC_CLK_ENABLE/DISABLE macro from
true/false.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>


# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>


# ace1bed3 08-Feb-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: fix bug in mmc_startup_v4()

The correspondence between mmc versions as used in u-boot and the version
numbers reported in register EXT_CSD_REV is wrong for versions above and
including MMC_VERSION_4_41. All those versions were shifted by one:
real 4.5 hardware appeared to be MMC_VERSION_5_0.

Fix this by adding the missing version in the correspondence table.

Reported-by: eil Eilmsteiner Heribert <eil@keba.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>


# b7a6e2c9 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: remove hc_wp_grp_size from struct mmc if not needed

hc_wp_grp_size is needed only if hardware partitionning is used.
On ARM removing it saves about 30 bytes of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 173c06df 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: don't read the size of eMMC enhanced user data area in SPL

This information is only used by the "mmc info" command.
On ARM removing this information from SPL saves about 140 of code space.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# e6fa5a54 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: compile out erase and write mmc commands if write operations are not enabled

Also remove erase_grp_size and write_bl_len from struct mmc as they are
not used anymore. On ARM, removing them saves about 100 bytes of code
space in SPL.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 5b2e72f3 04-Jan-2018 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: read ssr only if MMC write support is enabled

The content of ssr is useful only for erase operations.
on ARM, removing sd_read_ssr() saves around 300 bytes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# f99c2efe 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make UHS and HS200 optional

Supporting USH and HS200 increases the code size as it brings in IO voltage
control, tuning and fatter data structures.
Use Kconfig configuration to select which of those features should be
built in.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 7abff2c3 30-Nov-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

dm: mmc: update mmc_of_parse()

* convert to livetree API
* don't fail because of an invalid bus-width, instead default to 1-bit.
* recognize 1.2v DDR and 1.2v HS200 flags

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 9215ef5e 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

dm: mmc: Add a library function to parse generic dt binding

Add a new function to parse host controller dt node and
set mmc_config. This function can be used by mmc controller
drivers to set the generic mmc_config.
This function can be extended to set other UHS mode caps
once UHS mode support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 9815e3ba 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: add a library function to send tuning command

HS200/SDR104 requires tuning command to be sent to the card.
Add a simple function to send tuning command and to read and
compare the received data with the tuning block pattern.
This function can be used by platform driver to perform DLL
tuning.
This patch is similar to
commit 996903de92f0 ("mmc: core: add core-level function for
sending tuning commands") added in linux kernel.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# bc1e3272 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: use the right voltage level for MMC DDR and HS200 modes

HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v
or 1.2v signal voltages.
Select the lowest voltage available when using those modes.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 83dc4227 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Retry some MMC cmds on failure

With certain SD cards like Kingston 8GB/16GB UHS card, it is seen that
MMC_CMD_ALL_SEND_CID cmd fails on first attempt, but succeeds
subsequently. Therefore, retry MMC_CMD_ALL_SEND_CID cmd a few time
as done in Linux kernel.
Similarly, it is seen that MMC_CMD_SET_BLOCKLEN may fail on first
attempt, therefore retry this cmd a few times as done in kernel.

To make it clear that those are optionnal workarounds, a new Kconfig
option 'MMC_QUIRKS' is added (enabled by default).

Signed-off-by: Vignesh R <vigneshr@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 01298da3 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Change mode when switching to a boot partition

Boot partitions do not support HS200. Changing to a lower performance mode
is required to access them.
mmc_select_mode_and_width() and sd_select_mode_and_width() are modified to
make it easier to call them outside of the initialization context.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 04a2ea24 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: disable UHS modes if Vcc cannot be switched on and off

If a power cycle cannot be done on Vcc, it is safer not to try the UHS
modes because we wouldn't be able to recover from an error occurring
during the UHS initialization.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# c10b85d6 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add support for UHS modes

Add UHS modes to the list of supported modes, get the UHS capabilites of
the SDcard and implement the procedure to switch the voltage (UHS modes
use 1v8 IO lines)
During the voltage switch procedure, DAT0 is used by the card to signal
when it's ready. The optional card_busy() callback can be used to get this
information from the host driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 634d4849 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add HS200 support in MMC core

Add HS200 to the list of supported modes and introduce tuning in the MMC
startup process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# ec841209 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Add a execute_tuning() callback to the mmc operations.

Tuning is a mandatory step in the initialization of SDR104 and HS200 modes.
This callback execute the tuning process.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 35f67820 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: add a new mmc parameter to disable mmc clock

mmc clock has to be disabled in certain cases like during
the voltage switch sequence. Modify mmc_set_clock function
to take disable as an argument that signifies if the
clock has to be enabled or disabled.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 318a7a57 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a new callback function to perform the 74 clocks cycle sequence

Add a new callback function *send_init_stream* which start a sequence of
at least 74 clock cycles.
The mmc core uses *mmc_send_init_stream* in order to invoke the callback
function. This will be used during power cycle where the specification
requires such a sequence after power up.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# aff5d3c8 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: Enable signal voltage to be selected from mmc core

Add a new function *mmc_set_signal_voltage* in mmc core
which can be used during mmc initialization to select the
signal voltage. Platform driver should use the set_ios
callback function to select the signal voltage.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 2a4d212f 21-Sep-2017 Kishon Vijay Abraham I <kishon@ti.com>

mmc: make mmc_set_ios() return status

set_ios callback has a return value of 'int' but the mmc_set_ios()
function ignore this. Modify mmc_set_ios() and the callers of mmc_set_ios() to
to return the error status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 3862b854 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor MMC startup to make it easier to support new modes

The MMC startup process currently handles 4 modes. To make it easier to
add support for more modes, let's make the process more generic and use a
list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# d0c221fe 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: refactor SD startup to make it easier to support new modes

The SDcard startup process currently handles only 2 modes. To make it
easier to add support for more modes, let's make the process more generic
and use a list of the modes to try.
The major functional change is that when a mode fails we try the next one.
Not all modes are tried, only those supported by the card and the host.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 4c9d2aaa 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: Add a function to dump the mmc capabilities

This adds a simple helper function to display information (bus width and
mode) based on a capability mask. Useful for debug.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# 35f9e196 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: introduce mmc modes

no functionnal changes.
In order to add the support for the high speed SD and MMC modes, it is
useful to track this information.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# dfda9d88 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: make ext_csd part of struct mmc

The ext csd is used for comparison many times. Keep a reference content
of the ext csd in the struct mmc to avoid reading multiple times

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 06ec045f 21-Sep-2017 Jean-Jacques Hiblot <jjhiblot@ti.com>

mmc: dm: get the IO-line and main voltage regulators from the dts

Get a reference to the regulator devices from the dts and store them
in the struct mmc for later use.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>


# bdb60996 01-Aug-2017 Angelo Dureghello <angelo@sysam.it>

cmd: mmc: add mmc partconf read capability

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>


# e7881d85 29-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Drop CONFIG_DM_MMC_OPS

All boards which use DM_MMC have now been converted to use DM_MMC_OPS.
Drop the option and good riddance.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b7c6baef 30-Jul-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove DM_MMC from edison_defconfig]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>


# c4d660d4 04-Jul-2017 Simon Glass <sjg@chromium.org>

dm: mmc: Allow disabling driver model in SPL

At present if U-Boot proper uses driver model for MMC, then SPL has to
also. While this is desirable, it places a significant barrier to moving
to driver model in some cases. For example, with a space-constrained SPL
it may be necessary to enable CONFIG_SPL_OF_PLATDATA which involves
adjusting some drivers.

Add new SPL versions of the options for DM_MMC, DM_MMC_OPS and BLK. By
default these follow their non-SPL versions, but this can be changed by
boards which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>


# da2364cc 26-Jun-2017 Bin Meng <bmeng.cn@gmail.com>

Revert "x86: Convert MMC to driver model"

This reverts commit ddb3ac3c716f56cead695444e65a7ba7b0946555.

With MMC converted to driver model, SCSI driver is broken due to
zero address access at (ops->read) in block_dread() function.

The fix (SCSI driver converted to DM) is ready in u-boot-dm branch,
but it is too late for this relese to get that in.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 7ca0d3dd 10-May-2017 Tom Rini <trini@konsulko.com>

mmc: Change 'part_config' to be a u8 not char.

In some places we check if part_config is set to MMCPART_NOAVAILABLE
(0xff). With part_config being a char this is always false. We should
be using a u8 to store this value instead, after a quick consultation
with the Linux Kernel. Reported by clang-3.8.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@konsulko.com>


# ddb3ac3c 09-Apr-2017 Simon Glass <sjg@chromium.org>

x86: Convert MMC to driver model

Convert the pci_mmc driver over to driver model and migrate all x86 boards
that use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>


# 07b0b9c0 29-Dec-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: change the set_ios return type from void to int

To maintain consistency, set_ios type of legacy mmc_ops changed to int.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>


# b5b838f1 30-Nov-2016 Marek Vasut <marex@denx.de>

mmc: Tinification of the mmc code

Add new configuration option CONFIG_MMC_TINY which strips away all
memory allocation within the MMC code and code for handling multiple
cards. This allows extremely space-constrained SPL code use the MMC
framework.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>


# cd3d4880 25-Nov-2016 Tomas Melin <tomas.melin@vaisala.com>

mmc: add bkops-enable command

Add new command that provides possibility to enable the
background operations handshake functionality
(BKOPS_EN, EXT_CSD byte [163]) on eMMC devices.

This is an optional feature of eMMCs, the setting is write-once.
The command must be explicitly taken into use with
CONFIG_CMD_BKOPS_ENABLE.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>


# 3697e599 31-Aug-2016 Peng Fan <van.freenix@gmail.com>

mmc: sd: extracting erase related information from sd status

Add function to read SD_STATUS information.
According to the information, get erase_timeout/erase_size/erase_offset.
Add a structure sd_ssr to include the erase related information.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>


# 915ffa52 19-Jul-2016 Jaehoon Chung <jh80.chung@samsung.com>

mmc: use the generic error number

Use the generic error number instead of specific error number.
If use the generic error number, it can debug more easier.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Minkyu Kang <mk7.kang@samsung.com>


# 46683f3d 22-Jul-2016 Kever Yang <kever.yang@rock-chips.com>

mmc-uclass: correct the device number

Not like the mmc-legacy which the devnum starts from 1, it starts from 0
in mmc-uclass, so the device number should be (devnum + 1) in get_mmc_num().

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Acked-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>


# 8ca51e51 12-Jun-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to use driver model for MMC operations

The driver model conversion for MMC has moved in small steps. The first step
was to have an MMC device (CONFIG_DM_MMC). The second was to use a child
block device (CONFIG_BLK). The final one is to use driver model for MMC
operations (CONFIG_DM_MMC_OP). Add support for this.

The immediate priority is to make all boards that use DM_MMC also use those
other two options. This will allow them to be removed.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 1a3619cf 16-Jun-2016 Stefan Wahren <stefan.wahren@i2se.com>

mmc: add MMC_VERSION_5_1

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>


# 9cf7b1a7 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop dead mmc code for non-generic MMC

All boards that use MMC define CONFIG_GENERIC_MMC now, so we can drop this
old code.

Signed-off-by: Simon Glass <sjg@chromium.org>


# e98dd20c 14-May-2016 Simon Glass <sjg@chromium.org>

mmc: Drop mmc_register()

This function is no longer used.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 33fb211d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add support for driver-model block devices

Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.

Signed-off-by: Simon Glass <sjg@chromium.org>


# ad27dd5e 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a way to bind MMC devices with driver model

Binding an MMC device when CONFIG_BLK is enabled requires that a block
device be bound as a child of the MMC device. Add a function to do this.
The mmc_create() method will be used only when DM_BLK is disabled.

Add an unbind method also.

Signed-off-by: Simon Glass <sjg@chromium.org>


# cffe5d86 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Set up the device pointer when using the MMC uclass

Update the existing drivers to set up this new pointer. This will be required
by the MMC uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 69f45cd5 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Use the new select_hwpart() API

Avoid calling directly into the MMC code - use the new API call instead.

Signed-off-by: Simon Glass <sjg@chromium.org>


# cb5ec33d 01-May-2016 Simon Glass <sjg@chromium.org>

dm: mmc: Add a function to obtain the block device

The MMC block device is contained within struct mmc. But with driver model
this will not be the case. Add a function to obtain the block device. We
can later implement this for CONFIG_BLK.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 4101f687 29-Feb-2016 Simon Glass <sjg@chromium.org>

dm: Drop the block_dev_desc_t typedef

Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>


# aa844fe1 26-Jan-2016 Clemens Gruber <clemens.gruber@pqgruber.com>

mmc: add missing prototype for mmc_get_env_dev

This is a follow-up patch to e92029c0f4 and adds a prototype for
the weak mmc_get_env_dev function.

Cc: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>


# 873cc1d7 07-Dec-2015 Stephen Warren <swarren@nvidia.com>

mmc: store hwpart in the block device

This will allow us to have multiple block device structs each referring
to the same eMMC device, yet different HW partitions.

For now, there is still a single block device per eMMC device. As before,
this block device always accesses whichever HW partition was most recently
selected. Clients wishing to make use of multiple block devices referring
to different HW partitions can simply take a copy of this block device
once it points at the correct HW partition, and use each one as they wish.
This feature will be used by the next patch.

In the future, perhaps get_device() could be enhanced to return a
dynamically allocated block device struct, to avoid the client needing to
copy it in order to maintain multiple block devices. However, this would
require all users to be updated to free those block device structs at some
point, which is rather a large change.

Most callers of mmc_switch_part() wish to permanently switch the default
MMC block device's HW partition. Enhance mmc_switch_part() so that it does
this. This removes the need for callers to do this. However,
common/env_mmc.c needs to save and restore the current HW partition. Make
it do this more explicitly.

Replace use of mmc_switch_part() with mmc_select_hwpart() in order to
remove duplicate code that skips the call if that HW partition is already
selected.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>


# 4abe8e40 29-Nov-2015 Simon Glass <sjg@chromium.org>

dm: Convert PCI MMC over to use DM PCI API

At present pci_mmc_init() does not correctly use the PCI function since the
list it passes is not terminated. The array size passed to pci_mmc_init() is
actually not used correctly. Fix this and adjust the pci_mmc_init() to scan
all available MMC devices.

Adjust this code to use the new driver model PCI API.

This should move over to the new MMC uclass at some point.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>


# 1aa2d074 07-Dec-2015 Eric Nelson <eric@nelint.com>

mmc: update MMC_ERASE argument to match Linux kernel.

Table 41 of the JEDEC standard for eMMC says that bit 31 of
the command argument is obsolete when issuing the ERASE
command (CMD38) on page 115 of this document:
http://www.jedec.org/sites/default/files/docs/jesd84-B45.pdf

The SD Card Association Physical Layer Simplified Specification also
makes no mention of the use of bit 31.
https://www.sdcard.org/downloads/pls/part1_410.pdf

The Linux kernel distinguishes between secure (bit 31 set) and
non-secure erase, and this patch copies the macro names from
include/linux/mmc/core.h.

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Eric Nelson <eric@nelint.com>
Tested-by: Hector Palacios <hector.palacios@digi.com>


# e7ecf7cb 23-Jun-2015 Simon Glass <sjg@chromium.org>

dm: mmc: Add an MMC uclass

Add basic support for MMC, providing a uclass which can set up an MMC
device. This allows MMC drivers to move to using driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 5a20397b 23-Mar-2015 Rob Herring <robh@kernel.org>

mmc: remove the MMC_MODE_HC flag

High capacity support is not a host capability, but a device capability
that is queried via the OCR. The flag in the operating conditions
request argument can just be set unconditionally. This matches the Linux
implementation.

[panto] Hand merged and renumbering MMC_MODE_DDR_52MHz.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>


# bd47c135 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix splitting device initialization

Starting part of device initialization sets the init_in_progress flag
only if the MMC card did not yet come to ready state and needs to continue
polling. If the card is SD or if the MMC card became ready quickly,
the flag is not set and (if using pre-initialization) the starting
phase will be re-executed from mmc_init function.

Set the init_in_progress flag in all non-error cases. Also, move flags
setting statements around so that the flags are not set in error paths.
Also, IN_PROGRESS return status becomes unnecessary, so get rid of it.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>


# a626c8d4 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Avoid extra duplicate entry in mmc device structure

The 'op_cond_response' field in mmc structure contains the response
from the last SEND_OP_COND MMC command while making iterational
polling of the card. Later it is copied to 'ocr' field, designed
to contain the OCR register value, which is actually the same
response from the same command. So, these fields have actually
the same data, just in different time periods. It's easier to use
the same 'ocr' field in both cases at once, without temporary using
of the 'op_cond_response' field.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>


# 3f2da751 19-Mar-2015 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix typo in MMC type checking macro

The version flag constant name used in IS_MMC macro is incorrect/undefined.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>


# 4b7cee53 22-Jan-2015 Pantelis Antoniou <pantelis.antoniou@konsulko.com>

mmc: Implement SD/MMC versioning properly

The SD/MMC version scheme was buggy when dealing with standard
major.minor.change cases. Fix it by using something similar to
the linux's kernel versioning method.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Reported-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>


# f022d36e 17-Feb-2015 Otavio Salvador <otavio@ossystems.com.br>

mmc: fsl_esdhc: Add CMD11 support to switch to 1.8V

This adds support to switch to 1.8V in case CMD11 succeeds.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Reviewed-by: Marek Vasut <marex@denx.de>


# 91785f70 27-Jan-2015 Simon Glass <sjg@chromium.org>

x86: mmc: Move common FSP functions into a common file

Since these board functions seem to be the same for all boards which use
FSP, move them into a common file. We can adjust this later if future FSPs
need more flexibility.

This creates a generic PCI MMC device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>


# 9e41a00b 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo output to show partition write reliability settings

This extends the mmcinfo hardware partition info output to show
partitions with write reliability enabled with the "WRREL" string.
If the partition does not have write reliability enabled the "WRREL"
string is omitted; this is analogous to the ehhanced attribute.

Example output:

Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
Erase Group Size: 8 MiB
HC WP Group Size: 16 MiB
User Capacity: 13.8 GiB ENH WRREL
User Enhanced Start: 0 Bytes
User Enhanced Size: 512 MiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH WRREL
GP2 Capacity: 64 MiB ENH WRREL

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>


# 8dda5b0e 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend the mmc hardware partitioning API with write reliability

The eMMC partition write reliability settings are to be set while
partitioning a device, as per the eMMC spec, so changes to these
attributes needs to be done in the hardware partitioning API.
This commit adds such support.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>


# ac9da0e0 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: add API to do eMMC hardware partitioning

This adds an API to do hardware partitioning on eMMC devices. The
new mmc_hwpart_config() function does the partitioning in one go.
As the different attributes and partitioning options on eMMC may
be interdependent validation has to be done based on the complete
partitioning configuration. The function accepts three modes:

- MMC_HWPART_CONF_CHECK: just validates that the configuration
is valid.
- MMC_HWPART_CONF_SET: validates and sets all the fields in
EXT_CSD but without setting the "partitioning completed" bit,
and thus is reversible.
- MMC_HWPART_CONF_COMPLETE: does everything and is thus not
reversible.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>


# 037dc0ab 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the high capacity WP group size for eMMC

Read the eMMC high capacity write protect group size at mmc device
initialization. This is useful to correctly partition an eMMC device,
as partitions need to be aligned to this size.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>


# a4ff9f83 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: fix erase_grp_size computation with high-capacity size definition

The erase_grp_size in struct mmc is to be a size in 512-byte sectors
but the code used to compute it for eMMC when EXT_CSD_ERASE_GROUP_DEF is
enabled computed it as bytes, leading to erase sizes and alignment
much larger than what is actually required by the mmc device.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>


# a7f852b6 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: read the size of eMMC enhanced user data area

This modification reads the size of the eMMC enhanced user data area
upon initialization of an mmc device, it will be used later by
mmcinfo.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>


# c3dbb4f9 23-Dec-2014 Diego Santa Cruz <Diego.SantaCruz@spinetix.com>

mmc: extend mmcinfo to show enhanced partition attribute

This extends the mmcinfo command's output to show which eMMC partitions
have the enhanced attribute set. Note that the eMMC spec says that
if the enhanced attribute is supported then the boot and RPMB
partitions are of the enhanced type.

The output of mmcinfo becomes:
Device: OMAP SD/MMC
Manufacturer ID: fe
OEM: 14e
Name: MMC16
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.41
High Capacity: Yes
Capacity: 13.8 GiB
Bus Width: 4-bit
User Capacity: 13.8 GiB ENH
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 64 MiB ENH
GP2 Capacity: 64 MiB ENH

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>


# 786e8f81 01-Dec-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Fix handling of bus widths and DDR card capabilities

If the MMC_MODE_DDR_52MHz flag is set in card capabilities bitmask,
it is never cleared, even if switching to DDR mode fails, and if
the controller driver uses this flag to check the DDR mode, it can
take incorrect actions.

Also, DDR related checks in mmc_startup() incorrectly handle the case
when the host controller does not support some bus widths (e.g. can't
support 8 bits), since the host_caps is checked for DDR bit, but not
bus width bits.

This fix clearly separates using of card_caps bitmask, having there
the flags for the capabilities, that the card can support, and actual
operation mode, described outside of card_caps (i.e. bus_width and
ddr_mode fields in mmc structure). Separate host controller drivers
may need to be updated to use the actual flags. Respectively,
the capabilities checks in mmc_startup are made more correct and clear.

Also, some clean up is made with errors handling and code syntax layout.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>


# edab723b 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: add MMC_VERSION_5_0

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>


# d7b29129 18-Nov-2014 Markus Niebel <Markus.Niebel@tq-group.com>

MMC: fix user capacity for partitioned eMMC card

if the card claims to be high capacity and the card
is partitioned the capacity shall still be read from
ext_csd SEC_COUNT even if the resulting capacity is
smaller than 2 GiB

Signed-off-by: Markus Niebel <Markus.Niebel@tq-group.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>


# 95de9ab2 08-Nov-2014 Paul Kocialkowski <contact@paulk.fr>

mmc: Board-specific MMC power initializations

Some devices may use non-standard combinations of regulators to power MMC:
this allows these devices to provide a board-specific MMC power init function
to set everything up in their own way.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@ti.com>


# aeb80555 08-Oct-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: add prototype for mmc_get_env_addr

Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>


# 750121c3 12-Jul-2014 Jeroen Hofstee <jeroen@myspectrum.nl>

mmc: prevent some warnings with make W=1

Add missing prototypes for global functions and
make local functions static.

cc: panto@antoniou-consulting.com
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>


# 91fdabc6 24-Apr-2014 Pierre Aubert <p.aubert@staubli.com>

eMMC: add support for operations in RPMB partition

This patch adds functions for read, write and authentication
key programming for the Replay Protected Memory Block partition
in the eMMC.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Pierre Aubert <p.aubert@staubli.com>


# 6b2221b0 03-Apr-2014 Andrew Gabbasov <andrew_gabbasov@mentor.com>

mmc: Handle switch error status bit in MMC card status

MMC switch command for unsupported feature (e.g. bus width) sets a switch
error bit in card status. This bit should be checked, and, if it's set,
no access with new controller settings should be performed.

Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>


# d22e3d46 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the DDR mode for eMMC

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>


# 8caf46d1 15-May-2014 Jaehoon Chung <jh80.chung@samsung.com>

mmc: remove the unnecessary define and fix the wrong bit control

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Lukasz Majeski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>


# 07a2d42c 30-Apr-2014 Mateusz Zalega <m.zalega@samsung.com>

mmc: mmc header fix

Structure definition used type block_dev_desc_t, defined in part.h, which
wasn't included in mmc.h. It worked only in circumstances when common.h,
or another header using part.h was incuded in implementation files.

Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>


# 33ace362 07-Feb-2014 Tom Rini <trini@ti.com>

mmc: Add 'mmc rst-function' sub-command

Some eMMC chips may need the RST_n_FUNCTION bit set to a non-zero value
in order for warm reset of the system to work. Details on this being
required will be part of the eMMC datasheet. Also add using this
command to the dra7xx README.

* Whitespace fix by panto

Signed-off-by: Tom Rini <trini@ti.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# 0b2da7e2 28-Mar-2014 Tom Rini <trini@ti.com>

blackfin: mmc: Correct mmc_host_is_spi and bfin_sdh.c

In the recent mmc cleanup, the mmc_host_is_spi macro was broken and
bfin_sdh.c had mmc->bus_width turned into mmc_bus_width(mmc), both of
which were incorrect.

Signed-off-by: Tom Rini <trini@ti.com>


# 93bfd616 11-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Split mmc struct, rework mmc initialization (v2)

The way that struct mmc was implemented was a bit of a mess;
configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads
to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

struct mmc *mmc = malloc(sizeof(struct mmc));
memset(mmc, 0, sizeof(struct mmc);
/* fill in fields of mmc struct */
/* store private data pointer */
mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct
and an optional private data pointer like this:

struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect
mmc_register to go away before long.

Changes since v1:

* Use calloc instead of manually calling memset.
* Mark mmc_register as deprecated.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# 22cb7d33 10-Mar-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Convert mmc struct's name array to a pointer

Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# ab769f22 26-Feb-2014 Pantelis Antoniou <panto@antoniou-consulting.com>

mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with
a constant pointer to it.

This makes the mmc structure smaller as well as conserving
code space (in theory).

All in-tree drivers are converted as well; this is done in a
single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was
not set.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# 3c7ca967 15-Feb-2014 Fabio Estevam <fabio.estevam@freescale.com>

mmc: Add a prototype for board_mmc_init()

Fixes the following sparse warning:

wandboard.c:137:5: warning: symbol 'board_mmc_init' was not declared. Should it be static?

Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>


# 614b2bf1 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Drop open/close mmc sub-commands

The open and close mmc sub-commands implement a hard-coded set of values
specific to the SMDK5250 platform. Remove these commands as what they
did can be done instead with a series of mmc dev / bootpart / bootbus
commands instead now.

Cc: Amar <amarendra.xt@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# 5a99b9de 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add bootbus mmc sub-command

Add a bootbus sub-command to the mmc command to allow for setting
the boot_bus_width, reset_boot_bus_width and boot_mode fields of
BOOT_BUS_WIDTH (EXT_CSD[177]).

Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# 792970b0 05-Feb-2014 Tom Rini <trini@ti.com>

cmd_mmc.c: Add 'partconf' command to mmc

Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]). Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Tom Rini <trini@ti.com>
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# ab71188c 16-Dec-2013 Markus Niebel <Markus.Niebel@tqs.de>

mmc: add setdsr support

The eMMC and the SD-Card specifications describe the optional SET_DSR command.
During measurements at our lab we found that some cards implementing this feature
having really strong driver strengts per default. This can lead to voltage peaks
above the specification of the host on signal edges for data sent from a card to
the host.

Since availability of a given card type may be shorter than the time a certain
hardware will be produced it is useful to have support for this command (Alternative
would be changing termination resistors and adapting the driver strength of the
host to the used card.)

Following proposal for an implementation:

- new field that reflects CSD field DSR_IMP in struct mmc
- new field for design specific DSR value in struct mmc
- board code can set DSR value in mmc struct just after registering an controller
- mmc_startup sends the the stored DSR value before selecting a card, if DSR_IMP is set

Additionally the mmc command is extended to make is possible to play around with different
DSR values.

The concept was tested on a i.MX53 based platform using a Micron eMMC card where the default
DSR is 0x0400 (12mA) but in our design 0x0100 (0x0100) were enough. To use this feature for
instance on a mx53loco one have to add a call to mmc_set_dsr() in board_mmc_init() after
calling fsl_esdhc_initialize() for the eMMC.

Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# dae6c6ba 02-Dec-2013 Lad, Prabhakar <prabhakar.csengg@gmail.com>

include/mmc.h: Remove declaration for spl_mmc_load()

The spl_mmc_load() was removed while converting to
CONFIG_SPL_FRAMEWORK usage the definition was removed
but the declaration was missed. This patch removes this
declaration.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# 1937e5aa 01-Oct-2013 Oliver Metz <oliver@freetz.org>

mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>


# 8687d5c8 04-Sep-2013 Paul Burton <paul.burton@imgtec.com>

mmc: size optimization when !CONFIG_MMC_SPI

When CONFIG_MMC_SPI is not enabled, the MMC_MODE_SPI capability can
never be set. However there is code in mmc.c which uses the
mmc_host_is_spi macro to check that capability & act accordingly. If we
expand that macro to 0 when CONFIG_MMC_SPI is not set (since it will
always be 0 at runtime anyway) then the compiler can optimize away the
SPI-specific code paths in mmc.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>


# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>


# f866a46d 11-Jun-2013 Stephen Warren <swarren@nvidia.com>

mmc: report capacity for the selected partition

Enhance the MMC core to calculate the size of each MMC partition, and
update mmc->capacity whenever a partition is selected. This causes:

mmc dev 0 1 ; mmcinfo

... to report the size of the currently selected partition, rather than
always reporting the size of the user partition.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# 3690d6d6 27-Apr-2013 Amar <amarendra.xt@samsung.com>

MMC: APIs to support resize of EMMC boot partition

This patch adds APIs to access(open / close) and to resize boot partiton of EMMC.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>


# e9550449 28-Nov-2012 Che-Liang Chiou <clchiou@chromium.org>

mmc: Split device init to decouple OCR-polling delay

Most of time that MMC driver spends on initializing a device is polling
OCR (operation conditions register). To decouple this polling loop,
device init is split into two parts: The first part fires the OCR query
command, and the second part polls the result. So the caller is now no
longer bound to the OCR-polling delay; he may fire the query, go
somewhere and then come back later for the result.

To use this, call mmc_set_preinit() on any device which needs this.

This can save significant amounts of time on boot (e.g. 200ms) by
hiding the MMC init time behind other init.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# 8bfa195e 03-Apr-2013 Simon Glass <sjg@chromium.org>

mmc: Define a constant for the maximum block size

The number 512 appears quite a bit in the mmc code. Add a constant for this
so that it can be used here and in other parts of the code (e.g. SPL code
which loads from mmc).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>


# 1741c64d 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: check the revision for sd3.0

Support to check whether the SD3.0 or not.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Rommel Custodio <sessyargc@gmail.com>


# 64f4a619 29-Jan-2013 Jaehoon Chung <jh80.chung@samsung.com>

mmc: support the correct card version for eMMC

eMMC vesrion is supported up to v4.5.
But bootloader isn't saw the exact eMMC version.
After applied this patch,
if use the mmcinfo command, then can see the exactly mmc version.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Rommel Custodio <sessyargc@gmail.com>


# d23d8d7e 02-Dec-2012 Nikita Kiryanov <nikita@compulab.co.il>

mmc: add support for write protection

Add generic mmc write protection functionality.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>


# 29159057 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Tom Warren <twarren@nvidia.com>


# 8948ea83 30-Jul-2012 Stephen Warren <swarren@nvidia.com>

mmc: detect boot sectors using EXT_CSD_BOOT_MULT too

Some eMMC devices contain boot partitions, but do not set the PART_SUPPORT
bit in EXT_CSD_PARTITIONING_SUPPORT. Allow partition selection on such
devices, by enabling partition switching when EXT_CSD_BOOT_MULT is set.

Note that the Linux kernel enables access to boot partitions solely based
on the value of EXT_CSD_BOOT_MULT; EXT_CSD_PARTITIONING_SUPPORT only
influences access to "general" partitions.

eMMC devices affected by this issue exist on various NVIDIA Tegra
platforms (and presumably many others too), such as Harmony (plug-in eMMC),
Seaboard, Springbank, and Whistler (plug-in eMMC).

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# 67cbbf25 30-May-2012 Kaspter Ju <nigh0st3018@gmail.com>

mmc: Remove unused item flags in struct mmc_cmd

Signed-off-by: Kaspter Ju <nigh0st3018@gmail.com>


# 0d986e61 24-Jun-2012 Lad, Prabhakar <prabhakar.lad@ti.com>

da850/omap-l138: Add support to read u-boot image from MMC/SD

DA850/OMAP-L138 does not support strict MMC/SD boot mode. SPL will
be in SPI flash and U-Boot image will be in MMC/SD card. SPL will
do the low level initialization and then loads the u-boot image
from MMC/SD card.

Define CONFIG_SPL_MMC_LOAD macro in the DA850/OMAP-L138
configuration file to enable this feature.

Tested-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
Signed-off-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Signed-off-by: Hadli, Manjunath <manjunath.hadli@ti.com>


# ffdea5da 19-Mar-2012 Andreas Bießmann <biessmann@corscience.de>

include/mmc.h: remove struct mmc_csd

The outdated struct mmc_csd was only used by old atmel_mci driver which was
removed in c9abb4260c30fbfd51bb2cd551e7426e2ae15b66.

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Andy Fleming <afleming@freescale.com>


# 62722036 12-Mar-2012 Łukasz Majewski <l.majewski@samsung.com>

mmc:fix: Set mmc width according to MMC host capabilities

This patch sets the MMC width according to the MMC host capabilities.
It turned out, that there are some targets (e.g. GONI), which are able
to read data from SPI only at 4 bit mode.
This patch restricts the width number according to the MMC host.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Andy Fleming <afleming@gmail.com>


# 72fa4679 21-Oct-2011 Sven Schnelle <svens@stackframe.org>

ATMEL: use generic mmc framework

gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an those boards.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>


# d617c426 05-Feb-2012 Jan Kloetzke <jan.kloetzke@dspg.com>

mmc: make mmc_send_status() more reliable

Align the card status polling with the Linux kernel and retry the
command at least five times. Also some cards apparently mishandle the
status bits, so make sure to check the card state too.

Signed-off-by: Jan Kloetzke <jan.kloetzke@dspg.com>
Cc: Andy Fleming <afleming@gmail.com>


# 48972d90 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Implement card detection.

Check for card detect each time an MMC/SD device is initialized. If card
detection is not implemented, this code behaves as before and continues
assuming a card is present. If no card is detected, has_init is reset
for the MMC/SD device (to force initialization next time) and an error
is returned.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>


# 314284b1 01-Jan-2012 Thierry Reding <thierry.reding@avionic-design.de>

mmc: Change board_mmc_getcd() function prototype.

The new API no longer uses the extra cd parameter that was used to store
the card presence state. Instead, this information is returned via the
function's return value. board_mmc_getcd() returns -1 to indicate that
no card-detection mechanism is implemented; 0 indicates that no card is
present and 1 is returned if it was detected that a card is present.

The rationale for this change can be found in the following email
thread:

http://lists.denx.de/pipermail/u-boot/2011-November/110180.html

In summary, the old API was not consistent with the rest of the MMC API
which always passes a struct mmc as the first parameter. Furthermore the
cd parameter was used to mean "card absence" in some implementations and
"card presence" in others.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Tested-by: Jason Liu <jason.hui@linaro.org>


# 0560db18 03-Oct-2011 Lei Wen <leiwen@marvell.com>

mmc: change magic number to macro define

Previous magic number is hard to parse its meaning, change it to
respective macro definition

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: WOlfgang Denk <wd@denx.de>


# b1f1e821 04-Jul-2011 Łukasz Majewski <l.majewski@samsung.com>

mmc: Access mode validation for eMMC cards > 2 GiB

This patch provides handling of the two way handshake when SEND_OP_COND
(CMD1) is send to mmc card. It is necessary to inform eMMC card if the
host can work with high capacity cards (Jedec JESD84-A441, point 7.4.3).

The extra flag MMC_MODE_HC (high capacity) is added to indicate if the
host is capable of handling the high capacity eMMC cards.

Since this change is added to the generic mmc framework, then it requires
other boards to indicate if their mmc controllers can handle high capacity
cards. As it is now - the old behaviour of the framework is preserved.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# e6f99a56 22-Jun-2011 Lei Wen <leiwen@marvell.com>

MMC: add erase function to both mmc and sd

Erase is a very basic function since the begin of sd specification is
announced. Although we could write a bulk of full 0xff memory to the
range to take place of erase, it is more convenient and safe to
implement the erase function itself.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Signed-off-by: Andy Fleming <afleming@freescale.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# bc897b1d 02-May-2011 Lei Wen <leiwen@marvell.com>

mmc: enable partition switch function for emmc

For emmc, it may have up to 7 partitions: two boot partitions, one
user partition, one RPMB partition and four general purpose partitions.
(Refer to JESD84-A44.pdf/page 154)

As bootloader may need to read out or reflashing images on those

different partitions, it is better to enable the partition switch with
console command support.

Also for partition would be restore to user partition(part 0) when CMD0
is used, so change mmc_init routine to perform normal initialization
only once for each slot, unless use the rescan command to force init
again.

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>


# ea6ebe21 02-May-2011 Lei Wen <leiwen@marvell.com>

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...

Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>


# ed018b21 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc_spi: generate response for send status command

A "send status" command is added with the commit "mmc: checking
status after commands with R1b response". But the status register
returned from send status command of SPI protocol is different from
that of MMC/SD protocol. We do a simple test and generate a response
in stead of full bit-by-bit translation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>


# abe2c93f 18-Apr-2011 Thomas Chou <thomas@wytron.com.tw>

mmc: coding style fix and tabify of mmc.h

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>


# 8feafcc4 17-Apr-2011 John Rigby <john.rigby@linaro.org>

MMC: make b_max unconditional

Make existing field b_max field in struct mmc unconditional
and use it instead of CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_bread
and mmc_bwrite.

Initialize b_max to CONFIG_SYS_MMC_MAX_BLK_COUNT in mmc_register
if it has not been initialized by the hw driver.

Initialize b_max to 0 in all callers to mmc_register.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# 31cacbab 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: SEND_OP_COND considers card capabilities (voltage)

The first SEND_OP_COND (CMD1) command added is used to ask card capabilities.
After it an AND operation is done between card capabilities and host
capabilities (at the moment only for the voltage field).
Finally the correct value is sent to the MMC, waiting that the card
exits from busy state.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# 5d4fc8d9 10-Mar-2011 Raffaele Recalcati <raffaele.recalcati@bticino.it>

mmc: checking status after commands with R1b response

It is recommended to check card status after these kind of commands.
This is done using CMD13 (SEND_STATUS) JEDEC command until
the card is ready.
In case of error the card status field is displayed.

Signed-off-by: Raffaele Recalcati <raffaele.recalcati@bticino.it>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# d52ebf10 24-Dec-2010 Thomas Chou <thomas@wytron.com.tw>

mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on
the generic mmc framework. It works with SDHC and supports multi
blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Andy Fleming <afleming@freescale.com>


# 57418d21 20-Dec-2010 Sandeep Paulraj <s-paulraj@ti.com>

Davinci MMCSD Support

Added support for MMC/SD cards for Davinci. This feature is enabled by
CONFIG_DAVINCI_MMC and is dependant on CONFIG_MMC and CONFIG_GENERIC_MMC
options. This is tested on DM355 and DM365 EVMs with both the available mmc
controllers.

Signed-off-by: Alagu Sankar <alagusankar@embwise.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>


# 4a6ee172 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>


# 94c08a20 25-Nov-2010 Jerry Huang <Chang-Ming.Huang@freescale.com>

fsl_esdhc: Use mmc_set_clock to set initial speed

After booting the u-boot, and first using some SD card (such as Sandisk 2G SD
card), because the field 'clock' of struct mmc is zero, this will cause
the read transfer is always active and SDHC DATA line is always active,
therefore, driver can't handle the next command.

Therefore, we use mmc_set_clock to setup both the data structure and HW
to the initial clock speed of 400000Hz.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Tested-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>


# 1592ef85 13-Aug-2010 Reinhard Meyer <u-boot@emk-elektronik.de>

AT91: MCI: add SD/MMC driver using mmc framework

Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>


# 89716964 01-Jul-2010 Steve Sakoman <steve@sakoman.com>

mmc: add function prototype for mmc_set_dev in mmc.h

this eliminates compiler warnings when cmd_mmc.c is built with CONFIG_SYS_MMC_SET_DEV

the mmc_set_dev implementation in omap3_mmc.c is also tweaked to match
the new prototype in parameter naming and type

Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>


# 11fdade2 05-Feb-2010 Stefano Babic <sbabic@denx.de>

MMC: add weak function to detect MMC/SD card

Most controllers can check if there is a card in the slot.
However, they require pins that could be not available because
required by other functions and the detection of a card must
be performed in another way. This patch adds a weak function
that a board can implement to add its internal custom way
to check the presence of a MMC/SD card.

Signed-off-by: Stefano Babic <sbabic@denx.de>


# 79b91de9 22-Aug-2009 Albin Tonnerre <albin.tonnerre@free-electrons.com>

include/mmc.h: Fix typo in IS_SD() macro

Signed-off-by: Albin Tonnerre <albin.tonnerre@free-electrons.com>


# 0b453ffe 05-Apr-2009 Rabin Vincent <rabin@rab.in>

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>


# 272cc70b 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Add MMC Framework

Here's a new framework (based roughly off the linux one) for managing
MMC controllers. It handles all of the standard SD/MMC transactions,
leaving the host drivers to implement only what is necessary to
deal with their specific hardware.

This also hooks the infrastructure into the PowerPC board code
(similar to how the ethernet infrastructure now hooks in)

Some of this code was contributed by Dave Liu <daveliu@freescale.com>

Signed-off-by: Andy Fleming <afleming@freescale.com>


# 1de97f98 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminated arch-specific mmc header requirement

The current MMC infrastructure relies on the existence of an
arch-specific header file. This isn't necessary, and a couple
drivers were forced to implement dummy files to meet this requirement.
Instead, we move the stuff in those header files into a more appropriate
place, and eliminate the stubs and the #include of asm/arch/mmc.h

Signed-off-by: Andy Fleming <afleming@freescale.com>


# abb5466c 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Convert mmc_init to mmc_legacy_init

This is to get it out of the way of incoming MMC framework

Signed-off-by: Andy Fleming <afleming@freescale.com>


# b2e2ed02 30-Oct-2008 Andy Fleming <afleming@freescale.com>

Eliminate support for using MMC as memory

MMC cards are not memory, so we stop treating them that way.

Signed-off-by: Andy Fleming <afleming@freescale.com>


# 341188b9 22-May-2008 Haavard Skinnemoen <haavard.skinnemoen@atmel.com>

MMC: Consolidate MMC/SD command definitions

This moves the MMC and SD Card command definitions from
include/asm/arch/mmc.h into include/mmc.h. These definitions are
given by the MMC and SD Card standards, not by any particular
architecture.

There's a lot more room for consolidation in the MMC drivers which
I'm hoping to get done eventually, but this patch is a start.

Compile-tested for all avr32 boards as well as lpc2292sodimm and
lubbock. This should cover all three mmc drivers in the tree.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>


# 71f95118 15-Jun-2003 wdenk <wdenk>

* Fix CONFIG_NET_MULTI support in include/net.h

* Patches by Kyle Harris, 13 Mar 2003:
- Add FAT partition support
- Add command support for FAT
- Add command support for MMC
----
- Add Intel PXA support for video
- Add Intel PXA support for MMC
----
- Enable MMC and FAT for lubbock board
- Other misc changes for lubbock board