History log of /u-boot/drivers/mmc/arm_pl180_mmci.c
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>

# 7938ac65 01-May-2024 Tom Rini <trini@konsulko.com>

mmc: Remove <common.h> and add needed includes

Remove <common.h> from this driver directory and when needed
add missing include files directly.

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

# 1776213d 15-Apr-2024 Maximilian Brune <maximilian.brune@9elements.com>

mmc: arm_pl180: Limit data transfer to U16_MAX

Currently fetching files bigger that cause a data transfer greater than
U16_MAX fails.

The reason is that the specification defines the datalength register
as a 16 bit wide register, but in u-boot it is used as if it is an
32 bit register. Therefore values greater than U16_MAX cause an
infinite loop inside u-boot. U-boot expects to get more data from
interface/hardware then it will ever get and therefore inifintely waits
for more data that will never come.

Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# ee6cee12 08-Feb-2024 Linus Walleij <linus.walleij@linaro.org>

mmc: arm_pl180_mmci: Rely on DM

The PL180/MMCI driver is implied to use CONFIG_DM and the ARM
defconfigs such as configs/vexpress_ca9x4_defconfig will get it
as well.

With a simple oneline to default to not being the v2 variant,
the original ARM MMCI variant works fine with the driver as well.
The IP version actually needs to be read out from a register on
the ARM versions, but we will simply assume we are running on the
original hardware if arm,primecell-periphid is not explicitly
specified in the device tree.

Drop the !CONFIG_DM code and depend on DM_MMC.

Tested on the Versatile Express CA9x4 board.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

# c9309f40 16-Dec-2023 Sean Anderson <seanga2@gmail.com>

treewide: Remove clk_free

This function is a no-op. Remove it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Link: https://lore.kernel.org/r/20231216193843.2463779-3-seanga2@gmail.com

# c95b0297 19-Oct-2021 Usama Arif <usama.arif@arm.com>

mmc: arm_pl180_mmci: Enable HWFC for specific versions of MCI

There are 4 registers (PERIPHID{0-3}) that contain the ID of MCI.
For MMCs' with peripheral id 0x02041180 and 0x03041180, H/W flow control
needs to be enabled for multi block writes (MMC CMD 18).

Signed-off-by: Usama Arif <usama.arif@arm.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# d890f234 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Add configuration for ST-Ericsson Ux500v2

For the eMMC on ST-Ericsson Ux500v2 we need slightly different
configuration values. Use the existing switch statement to match
the peripheral ID of Ux500v2 (0x10480180) and override the necessary
values to make the eMMC work on devices with ST-Ericsson Ux500.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 4daf2ec3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using mmc_of_parse()

Simplify the code a bit by using the common mmc_of_parse() function
instead of duplicating the device tree parsing code. We can still get
a default value for cfg->f_max by assigning it before calling
mmc_of_parse().

Another advantage of this refactoring is that we parse more properties
now, e.g. "non-removable" can be used to disable CD entirely.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19e1da0c 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using dev_read_addr_ptr()

Simplify the code a bit by using dev_read_addr_ptr() instead of
dev_read_addr(). This avoids having to cast explicitly to void*.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 936e9cd3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Don't bind to all arm, primecell devices

The arm,primecell compatible is used for lots of different types
of devices, e.g. I2C, SPI, coresight, ... We really should not bind
the MMC driver to all of them.

Looking through the device trees in U-Boot there seems to be always
a second compatible string for the pl180 device, either arm,pl180
(already listed) or arm,pl18x. Add the "arm,pl18x" compatible to the
list but remove the generic "arm,primecell".

Note that on Linux these compatibles cannot be found in drivers
because AMBA/primecell devices are matched based on their peripheral ID
instead of the compatible.

This fixes the following error messages when booting the ST-Ericsson
U8500 "stemmy" board with the arm_pl180_mmci driver enabled:

MMC: ptm@801ae000 - probe failed: -38
ptm@801af000 - probe failed: -38
funnel@801a6000 - probe failed: -38
tpiu@80190000 - probe failed: -38
etb@801a4000 - probe failed: -38

Cc: Patrice Chotard <patrice.chotard@st.com>
Fixes: 6f41d1a17e20 ("mmc: arm_pl180_mmci: Sync compatible with kernel")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# 7938ac65 01-May-2024 Tom Rini <trini@konsulko.com>

mmc: Remove <common.h> and add needed includes

Remove <common.h> from this driver directory and when needed
add missing include files directly.

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

# 1776213d 15-Apr-2024 Maximilian Brune <maximilian.brune@9elements.com>

mmc: arm_pl180: Limit data transfer to U16_MAX

Currently fetching files bigger that cause a data transfer greater than
U16_MAX fails.

The reason is that the specification defines the datalength register
as a 16 bit wide register, but in u-boot it is used as if it is an
32 bit register. Therefore values greater than U16_MAX cause an
infinite loop inside u-boot. U-boot expects to get more data from
interface/hardware then it will ever get and therefore inifintely waits
for more data that will never come.

Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# ee6cee12 08-Feb-2024 Linus Walleij <linus.walleij@linaro.org>

mmc: arm_pl180_mmci: Rely on DM

The PL180/MMCI driver is implied to use CONFIG_DM and the ARM
defconfigs such as configs/vexpress_ca9x4_defconfig will get it
as well.

With a simple oneline to default to not being the v2 variant,
the original ARM MMCI variant works fine with the driver as well.
The IP version actually needs to be read out from a register on
the ARM versions, but we will simply assume we are running on the
original hardware if arm,primecell-periphid is not explicitly
specified in the device tree.

Drop the !CONFIG_DM code and depend on DM_MMC.

Tested on the Versatile Express CA9x4 board.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

# c9309f40 16-Dec-2023 Sean Anderson <seanga2@gmail.com>

treewide: Remove clk_free

This function is a no-op. Remove it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Link: https://lore.kernel.org/r/20231216193843.2463779-3-seanga2@gmail.com

# c95b0297 19-Oct-2021 Usama Arif <usama.arif@arm.com>

mmc: arm_pl180_mmci: Enable HWFC for specific versions of MCI

There are 4 registers (PERIPHID{0-3}) that contain the ID of MCI.
For MMCs' with peripheral id 0x02041180 and 0x03041180, H/W flow control
needs to be enabled for multi block writes (MMC CMD 18).

Signed-off-by: Usama Arif <usama.arif@arm.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# d890f234 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Add configuration for ST-Ericsson Ux500v2

For the eMMC on ST-Ericsson Ux500v2 we need slightly different
configuration values. Use the existing switch statement to match
the peripheral ID of Ux500v2 (0x10480180) and override the necessary
values to make the eMMC work on devices with ST-Ericsson Ux500.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 4daf2ec3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using mmc_of_parse()

Simplify the code a bit by using the common mmc_of_parse() function
instead of duplicating the device tree parsing code. We can still get
a default value for cfg->f_max by assigning it before calling
mmc_of_parse().

Another advantage of this refactoring is that we parse more properties
now, e.g. "non-removable" can be used to disable CD entirely.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19e1da0c 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using dev_read_addr_ptr()

Simplify the code a bit by using dev_read_addr_ptr() instead of
dev_read_addr(). This avoids having to cast explicitly to void*.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 936e9cd3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Don't bind to all arm, primecell devices

The arm,primecell compatible is used for lots of different types
of devices, e.g. I2C, SPI, coresight, ... We really should not bind
the MMC driver to all of them.

Looking through the device trees in U-Boot there seems to be always
a second compatible string for the pl180 device, either arm,pl180
(already listed) or arm,pl18x. Add the "arm,pl18x" compatible to the
list but remove the generic "arm,primecell".

Note that on Linux these compatibles cannot be found in drivers
because AMBA/primecell devices are matched based on their peripheral ID
instead of the compatible.

This fixes the following error messages when booting the ST-Ericsson
U8500 "stemmy" board with the arm_pl180_mmci driver enabled:

MMC: ptm@801ae000 - probe failed: -38
ptm@801af000 - probe failed: -38
funnel@801a6000 - probe failed: -38
tpiu@80190000 - probe failed: -38
etb@801a4000 - probe failed: -38

Cc: Patrice Chotard <patrice.chotard@st.com>
Fixes: 6f41d1a17e20 ("mmc: arm_pl180_mmci: Sync compatible with kernel")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# 1776213d 15-Apr-2024 Maximilian Brune <maximilian.brune@9elements.com>

mmc: arm_pl180: Limit data transfer to U16_MAX

Currently fetching files bigger that cause a data transfer greater than
U16_MAX fails.

The reason is that the specification defines the datalength register
as a 16 bit wide register, but in u-boot it is used as if it is an
32 bit register. Therefore values greater than U16_MAX cause an
infinite loop inside u-boot. U-boot expects to get more data from
interface/hardware then it will ever get and therefore inifintely waits
for more data that will never come.

Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# ee6cee12 08-Feb-2024 Linus Walleij <linus.walleij@linaro.org>

mmc: arm_pl180_mmci: Rely on DM

The PL180/MMCI driver is implied to use CONFIG_DM and the ARM
defconfigs such as configs/vexpress_ca9x4_defconfig will get it
as well.

With a simple oneline to default to not being the v2 variant,
the original ARM MMCI variant works fine with the driver as well.
The IP version actually needs to be read out from a register on
the ARM versions, but we will simply assume we are running on the
original hardware if arm,primecell-periphid is not explicitly
specified in the device tree.

Drop the !CONFIG_DM code and depend on DM_MMC.

Tested on the Versatile Express CA9x4 board.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

# c9309f40 16-Dec-2023 Sean Anderson <seanga2@gmail.com>

treewide: Remove clk_free

This function is a no-op. Remove it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Link: https://lore.kernel.org/r/20231216193843.2463779-3-seanga2@gmail.com

# c95b0297 19-Oct-2021 Usama Arif <usama.arif@arm.com>

mmc: arm_pl180_mmci: Enable HWFC for specific versions of MCI

There are 4 registers (PERIPHID{0-3}) that contain the ID of MCI.
For MMCs' with peripheral id 0x02041180 and 0x03041180, H/W flow control
needs to be enabled for multi block writes (MMC CMD 18).

Signed-off-by: Usama Arif <usama.arif@arm.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# d890f234 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Add configuration for ST-Ericsson Ux500v2

For the eMMC on ST-Ericsson Ux500v2 we need slightly different
configuration values. Use the existing switch statement to match
the peripheral ID of Ux500v2 (0x10480180) and override the necessary
values to make the eMMC work on devices with ST-Ericsson Ux500.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 4daf2ec3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using mmc_of_parse()

Simplify the code a bit by using the common mmc_of_parse() function
instead of duplicating the device tree parsing code. We can still get
a default value for cfg->f_max by assigning it before calling
mmc_of_parse().

Another advantage of this refactoring is that we parse more properties
now, e.g. "non-removable" can be used to disable CD entirely.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19e1da0c 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using dev_read_addr_ptr()

Simplify the code a bit by using dev_read_addr_ptr() instead of
dev_read_addr(). This avoids having to cast explicitly to void*.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 936e9cd3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Don't bind to all arm, primecell devices

The arm,primecell compatible is used for lots of different types
of devices, e.g. I2C, SPI, coresight, ... We really should not bind
the MMC driver to all of them.

Looking through the device trees in U-Boot there seems to be always
a second compatible string for the pl180 device, either arm,pl180
(already listed) or arm,pl18x. Add the "arm,pl18x" compatible to the
list but remove the generic "arm,primecell".

Note that on Linux these compatibles cannot be found in drivers
because AMBA/primecell devices are matched based on their peripheral ID
instead of the compatible.

This fixes the following error messages when booting the ST-Ericsson
U8500 "stemmy" board with the arm_pl180_mmci driver enabled:

MMC: ptm@801ae000 - probe failed: -38
ptm@801af000 - probe failed: -38
funnel@801a6000 - probe failed: -38
tpiu@80190000 - probe failed: -38
etb@801a4000 - probe failed: -38

Cc: Patrice Chotard <patrice.chotard@st.com>
Fixes: 6f41d1a17e20 ("mmc: arm_pl180_mmci: Sync compatible with kernel")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# ee6cee12 08-Feb-2024 Linus Walleij <linus.walleij@linaro.org>

mmc: arm_pl180_mmci: Rely on DM

The PL180/MMCI driver is implied to use CONFIG_DM and the ARM
defconfigs such as configs/vexpress_ca9x4_defconfig will get it
as well.

With a simple oneline to default to not being the v2 variant,
the original ARM MMCI variant works fine with the driver as well.
The IP version actually needs to be read out from a register on
the ARM versions, but we will simply assume we are running on the
original hardware if arm,primecell-periphid is not explicitly
specified in the device tree.

Drop the !CONFIG_DM code and depend on DM_MMC.

Tested on the Versatile Express CA9x4 board.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

# c9309f40 16-Dec-2023 Sean Anderson <seanga2@gmail.com>

treewide: Remove clk_free

This function is a no-op. Remove it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Link: https://lore.kernel.org/r/20231216193843.2463779-3-seanga2@gmail.com

# c95b0297 19-Oct-2021 Usama Arif <usama.arif@arm.com>

mmc: arm_pl180_mmci: Enable HWFC for specific versions of MCI

There are 4 registers (PERIPHID{0-3}) that contain the ID of MCI.
For MMCs' with peripheral id 0x02041180 and 0x03041180, H/W flow control
needs to be enabled for multi block writes (MMC CMD 18).

Signed-off-by: Usama Arif <usama.arif@arm.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# d890f234 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Add configuration for ST-Ericsson Ux500v2

For the eMMC on ST-Ericsson Ux500v2 we need slightly different
configuration values. Use the existing switch statement to match
the peripheral ID of Ux500v2 (0x10480180) and override the necessary
values to make the eMMC work on devices with ST-Ericsson Ux500.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 4daf2ec3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using mmc_of_parse()

Simplify the code a bit by using the common mmc_of_parse() function
instead of duplicating the device tree parsing code. We can still get
a default value for cfg->f_max by assigning it before calling
mmc_of_parse().

Another advantage of this refactoring is that we parse more properties
now, e.g. "non-removable" can be used to disable CD entirely.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19e1da0c 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using dev_read_addr_ptr()

Simplify the code a bit by using dev_read_addr_ptr() instead of
dev_read_addr(). This avoids having to cast explicitly to void*.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 936e9cd3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Don't bind to all arm, primecell devices

The arm,primecell compatible is used for lots of different types
of devices, e.g. I2C, SPI, coresight, ... We really should not bind
the MMC driver to all of them.

Looking through the device trees in U-Boot there seems to be always
a second compatible string for the pl180 device, either arm,pl180
(already listed) or arm,pl18x. Add the "arm,pl18x" compatible to the
list but remove the generic "arm,primecell".

Note that on Linux these compatibles cannot be found in drivers
because AMBA/primecell devices are matched based on their peripheral ID
instead of the compatible.

This fixes the following error messages when booting the ST-Ericsson
U8500 "stemmy" board with the arm_pl180_mmci driver enabled:

MMC: ptm@801ae000 - probe failed: -38
ptm@801af000 - probe failed: -38
funnel@801a6000 - probe failed: -38
tpiu@80190000 - probe failed: -38
etb@801a4000 - probe failed: -38

Cc: Patrice Chotard <patrice.chotard@st.com>
Fixes: 6f41d1a17e20 ("mmc: arm_pl180_mmci: Sync compatible with kernel")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# c9309f40 16-Dec-2023 Sean Anderson <seanga2@gmail.com>

treewide: Remove clk_free

This function is a no-op. Remove it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Link: https://lore.kernel.org/r/20231216193843.2463779-3-seanga2@gmail.com

# c95b0297 19-Oct-2021 Usama Arif <usama.arif@arm.com>

mmc: arm_pl180_mmci: Enable HWFC for specific versions of MCI

There are 4 registers (PERIPHID{0-3}) that contain the ID of MCI.
For MMCs' with peripheral id 0x02041180 and 0x03041180, H/W flow control
needs to be enabled for multi block writes (MMC CMD 18).

Signed-off-by: Usama Arif <usama.arif@arm.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# d890f234 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Add configuration for ST-Ericsson Ux500v2

For the eMMC on ST-Ericsson Ux500v2 we need slightly different
configuration values. Use the existing switch statement to match
the peripheral ID of Ux500v2 (0x10480180) and override the necessary
values to make the eMMC work on devices with ST-Ericsson Ux500.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 4daf2ec3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using mmc_of_parse()

Simplify the code a bit by using the common mmc_of_parse() function
instead of duplicating the device tree parsing code. We can still get
a default value for cfg->f_max by assigning it before calling
mmc_of_parse().

Another advantage of this refactoring is that we parse more properties
now, e.g. "non-removable" can be used to disable CD entirely.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19e1da0c 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using dev_read_addr_ptr()

Simplify the code a bit by using dev_read_addr_ptr() instead of
dev_read_addr(). This avoids having to cast explicitly to void*.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 936e9cd3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Don't bind to all arm, primecell devices

The arm,primecell compatible is used for lots of different types
of devices, e.g. I2C, SPI, coresight, ... We really should not bind
the MMC driver to all of them.

Looking through the device trees in U-Boot there seems to be always
a second compatible string for the pl180 device, either arm,pl180
(already listed) or arm,pl18x. Add the "arm,pl18x" compatible to the
list but remove the generic "arm,primecell".

Note that on Linux these compatibles cannot be found in drivers
because AMBA/primecell devices are matched based on their peripheral ID
instead of the compatible.

This fixes the following error messages when booting the ST-Ericsson
U8500 "stemmy" board with the arm_pl180_mmci driver enabled:

MMC: ptm@801ae000 - probe failed: -38
ptm@801af000 - probe failed: -38
funnel@801a6000 - probe failed: -38
tpiu@80190000 - probe failed: -38
etb@801a4000 - probe failed: -38

Cc: Patrice Chotard <patrice.chotard@st.com>
Fixes: 6f41d1a17e20 ("mmc: arm_pl180_mmci: Sync compatible with kernel")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# c95b0297 19-Oct-2021 Usama Arif <usama.arif@arm.com>

mmc: arm_pl180_mmci: Enable HWFC for specific versions of MCI

There are 4 registers (PERIPHID{0-3}) that contain the ID of MCI.
For MMCs' with peripheral id 0x02041180 and 0x03041180, H/W flow control
needs to be enabled for multi block writes (MMC CMD 18).

Signed-off-by: Usama Arif <usama.arif@arm.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

# d890f234 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Add configuration for ST-Ericsson Ux500v2

For the eMMC on ST-Ericsson Ux500v2 we need slightly different
configuration values. Use the existing switch statement to match
the peripheral ID of Ux500v2 (0x10480180) and override the necessary
values to make the eMMC work on devices with ST-Ericsson Ux500.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 4daf2ec3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using mmc_of_parse()

Simplify the code a bit by using the common mmc_of_parse() function
instead of duplicating the device tree parsing code. We can still get
a default value for cfg->f_max by assigning it before calling
mmc_of_parse().

Another advantage of this refactoring is that we parse more properties
now, e.g. "non-removable" can be used to disable CD entirely.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19e1da0c 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using dev_read_addr_ptr()

Simplify the code a bit by using dev_read_addr_ptr() instead of
dev_read_addr(). This avoids having to cast explicitly to void*.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 936e9cd3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Don't bind to all arm, primecell devices

The arm,primecell compatible is used for lots of different types
of devices, e.g. I2C, SPI, coresight, ... We really should not bind
the MMC driver to all of them.

Looking through the device trees in U-Boot there seems to be always
a second compatible string for the pl180 device, either arm,pl180
(already listed) or arm,pl18x. Add the "arm,pl18x" compatible to the
list but remove the generic "arm,primecell".

Note that on Linux these compatibles cannot be found in drivers
because AMBA/primecell devices are matched based on their peripheral ID
instead of the compatible.

This fixes the following error messages when booting the ST-Ericsson
U8500 "stemmy" board with the arm_pl180_mmci driver enabled:

MMC: ptm@801ae000 - probe failed: -38
ptm@801af000 - probe failed: -38
funnel@801a6000 - probe failed: -38
tpiu@80190000 - probe failed: -38
etb@801a4000 - probe failed: -38

Cc: Patrice Chotard <patrice.chotard@st.com>
Fixes: 6f41d1a17e20 ("mmc: arm_pl180_mmci: Sync compatible with kernel")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# d890f234 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Add configuration for ST-Ericsson Ux500v2

For the eMMC on ST-Ericsson Ux500v2 we need slightly different
configuration values. Use the existing switch statement to match
the peripheral ID of Ux500v2 (0x10480180) and override the necessary
values to make the eMMC work on devices with ST-Ericsson Ux500.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 4daf2ec3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using mmc_of_parse()

Simplify the code a bit by using the common mmc_of_parse() function
instead of duplicating the device tree parsing code. We can still get
a default value for cfg->f_max by assigning it before calling
mmc_of_parse().

Another advantage of this refactoring is that we parse more properties
now, e.g. "non-removable" can be used to disable CD entirely.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 19e1da0c 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Simplify code using dev_read_addr_ptr()

Simplify the code a bit by using dev_read_addr_ptr() instead of
dev_read_addr(). This avoids having to cast explicitly to void*.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 936e9cd3 06-Jul-2021 Stephan Gerhold <stephan@gerhold.net>

mmc: arm_pl180_mmci: Don't bind to all arm, primecell devices

The arm,primecell compatible is used for lots of different types
of devices, e.g. I2C, SPI, coresight, ... We really should not bind
the MMC driver to all of them.

Looking through the device trees in U-Boot there seems to be always
a second compatible string for the pl180 device, either arm,pl180
(already listed) or arm,pl18x. Add the "arm,pl18x" compatible to the
list but remove the generic "arm,primecell".

Note that on Linux these compatibles cannot be found in drivers
because AMBA/primecell devices are matched based on their peripheral ID
instead of the compatible.

This fixes the following error messages when booting the ST-Ericsson
U8500 "stemmy" board with the arm_pl180_mmci driver enabled:

MMC: ptm@801ae000 - probe failed: -38
ptm@801af000 - probe failed: -38
funnel@801a6000 - probe failed: -38
tpiu@80190000 - probe failed: -38
etb@801a4000 - probe failed: -38

Cc: Patrice Chotard <patrice.chotard@st.com>
Fixes: 6f41d1a17e20 ("mmc: arm_pl180_mmci: Sync compatible with kernel")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com> on stm32f769-disco
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# 0fd3d911 22-Dec-2020 Simon Glass <sjg@chromium.org>

dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

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

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

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

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

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

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

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

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@foss.st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

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

common: Drop linux/delay.h from common header

Move this uncommon header out of the common header.

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

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

common: Drop log.h from common header

Move this header out of the common header.

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

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# 336d4615 03-Feb-2020 Simon Glass <sjg@chromium.org>

dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

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

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# 6f41d1a1 05-Dec-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Sync compatible with kernel

Initially the compatible string was wrongly set to "st,stm32f4xx-sdio".
Use compatible string used by kernel instead and identify mmci variant
using "arm,primecell-periphid" property.

Currently, the DM part of mmci driver is only used by STM32 SoCs,
that's why the switch case gets only one entry. It will be populated
easily with new variant in the future.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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

# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>

# 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>

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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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

# 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>

# 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>

# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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

# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>

# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>

# 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>

# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>

# fa911561 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Remove cd_inverted host's struct field

As platform uses GPIOs for card detection, it's
simpler and more readable to use GPIO_ACTIVE_(LOW|HIGH)
in the gpio flags instead of using the cd-inverted
property.

Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>


# 43d36a0b 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Add missing clk_free

Add missing clk_free() call in case of failure
when enabling the clock.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# 80150938 25-Jul-2018 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: Update to support CONFIG_BLK

Config flag CONFIG_BLK becomes mandatory, update arm_pl180_mmci
to support this config.

This driver is used by STM32Fx and by Vexpress platforms.
Only STM32Fx are DM ready. No DM code is isolated and will be
removed easily when wexpress will be converted to DM.

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>


# d024236e 18-Apr-2018 Tom Rini <trini@konsulko.com>

Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR

We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

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


# 5829fe2d 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>


# 5f256fe7 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add clock support

Allow to get and enable MMC related clock

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>


# 9035bb74 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: add bus_width DT property support

Allow to get "bus-width" property from device tree

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>


# 3c0dbed2 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: adapt driver to DM usage

Convert this driver to driver model.
This driver is also used by VEXPRESS platforms which doesn't
use driver model.

Tested on STM32F746 and STM32F769 platforms.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>


# cb0060e8 23-Oct-2017 Patrice Chotard <patrice.chotard@st.com>

mmc: arm_pl180_mmci: update arm_pl180_mmci_init() prototype

Update arm_pl180_mmci_init() prototype by adding struct mmc**
param. This is needed before converting this driver to driver model
in order to use arm_pl180_mmci_init() in driver model and in none
driver model implementation

Signed-off-by: Patrice Chotard <patrice.chotard@st.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>


# 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>


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

dm: block: Rename device number member dev to devnum

This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

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


# 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>


# 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>


# 95b01c47 06-Sep-2012 Andy Fleming <afleming@freescale.com>

mmc: Remove incorrect cmd->flags usage

There were a couple of drivers that were actually using the flags
field of the cmd structure, despite the fact that no one ever
*set* that field. When we removed the field, those drivers failed
to compile. Replaced the references with the correct usage of
resp_type.

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


# 10ed93dc 31-Jul-2012 John Rigby <john.rigby@linaro.org>

u8500: Separating mmc config parameters from driver

Configuration in vexpress and u8500.v1 is different from what
is needed in u8500.v2. As such, card configuration specifics need
to reside in the board file rather than the driver.

Signed-off-by: John Rigby <john.rigby@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tom Rini <trini@ti.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>


# 0612fcbc 03-Nov-2011 Jon Medhurst (Tixy) <jon.medhurst@linaro.org>

MMC: PL180: Fix infinite loop with VExpress extended fifo implementation

The new IO FPGA implementation for Versatile Express contains an MMCI
(PL180) cell with the FIFO extended to 128 words. This causes the
read_bytes() function to go into an infinite loop; as it will wait for
for the half-full signal (SDI_STA_RXFIFOBR) if there are more than 8
words remaining (SDI_FIFO_BURST_SIZE), but it won't receive this signal
once there are fewer than 64 words left to transfer.

One possible fix is to add some build time configuration to change
SDI_FIFO_BURST_SIZE for the new implementation. However, the problematic
code only seems to exist as a small performance optimisation, so the
solution implemented by this patch is to simply remove it. The error
checking following the loop is also removed as this will be handled by
code further down the function.

Cc: Andy Fleming <afleming@gmail.com>
Signed-off-by: Jon Medhurst <jon.medhurst@linaro.org>


# 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>


# 23b93e1d 16-Apr-2011 Matt Waddel <matt.waddel@linaro.org>

MMC: Add support for PL180 ARM mmc device

Add support for the ARM PrimeCell MultiMedia Interface - PL180.
Ported from original device driver written by ST-Ericsson.

Signed-off-by: Matt Waddel <matt.waddel@linaro.org>