summaryrefslogtreecommitdiffstats
path: root/drivers/mci/sdhci.c
Commit message (Collapse)AuthorAgeFilesLines
* mci: sdhci: replace sdhci_wait_idleSteffen Trumtrar2024-03-181-2/+27
| | | | | | | | | | Linux uses a different sdhci_wait_idle function than what barebox currently does. For HS200 support, the linux version needs to be used. As currently only arasan-sdhci is tested with HS200, keep the old sdhci_wait_idle as sdhci_wait_idle_data and convert all users of it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
* mci: sdhci: add tuning supportSteffen Trumtrar2024-03-181-1/+274
| | | | | | | | | The arasan SDHCI driver doesn't use MMC tuning but SDHCI tuning. Both are not supported yet in barebox. Add SDHCI tuning support from linux v6.7. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* mci: sdhci: wait for idle before stopping clockSascha Hauer2023-11-061-0/+2
| | | | | | | | | We should wait for the controller being idle before stopping the clock. Some SDHCI controllers like the one found on TI AM62x SoCs do not work properly without it. Link: https://lore.barebox.org/20230803105003.4088205-16-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Add common wait for idle functionSascha Hauer2023-11-061-0/+22
| | | | | | | | Waiting for the controller being idle is a common pattern in the different SDHCI drivers we have. Add a common function for it. Link: https://lore.barebox.org/20230803105003.4088205-15-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2023-09-251-0/+10
|\
| * mci: sdhci: don't hang indefinitely waiting for DMA completionAhmad Fatoum2023-08-281-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | barebox was observed to hang on an i.MX8MP while reading ext_csd from a broken eMMC that even bootROM refused to boot from. For PIO, we already have a maximum wait time of 10s. Do the same for DMA. It's unlikely that in that state any further communication with the card will work, but at least, the system isn't stuck and the shell can be reached. The reset is done on the off-chance that the DMA would've completed after the 10s and corrupted memory if not disabled. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20230824135939.1614716-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | mci: sdhci: hardcode SDMA boundary for DMAAhmad Fatoum2023-09-121-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Given that we are not using the feature, there's no reason to compute the boundary when polling for DMA completion. Therefore let's assume the initial default of 512K remains unchanged. The sdhci::sdma_boundary member is still left in place as the i.MX eSDHC driver sets it to zero to affect what sdhci_setup_data_pio() writes into SDHCI_BLOCK_SIZE as the i.MX repurposes doesn't implement the boundary feature and reserves the bits in the SDHCI_BLOCK_SIZE register. Fixes: 88f101358167 ("mci: sdhci: Force DMA update to the next block boundary") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230911121156.2632668-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | mci: sdhci: unmap the DMA buffers actually usedAhmad Fatoum2023-09-121-2/+2
|/ | | | | | | | | | | | | | | | | | | | | At the end of sdhci_transfer_data_dma, sdhci_set_sdma_addr is called to set the next DMA address. Recently, the computation of the next DMA address was changed and instead of storing the next SDMA address into a dedicated local variable as before, it was stored into the existing `dma' variable. The dma variable is passed later though to dma_unmap_single(), so clobbering it results in a loss of cache coherency and thus potential memory corruption. It's worth noting that this next SDMA address is not actually used for DMA: Like Linux, barebox doesn't make use of this feature to chain (?) DMA requests, so we actually invalidated memory buffers that were never used for DMA. Fixes: 76aa243aad95 ("mci: sdhci: Add 64-bit DMA addressing suport for V4 mode") Fixes: 88f101358167 ("mci: sdhci: Force DMA update to the next block boundary") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230911121156.2632668-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Force DMA update to the next block boundaryJules Maselbas2023-08-211-1/+13
| | | | | | Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20230818142244.17157-6-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Add 64-bit DMA addressing suport for V4 modeJules Maselbas2023-08-211-2/+62
| | | | | | Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20230818142244.17157-5-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Add sd host v4 modeJules Maselbas2023-08-211-0/+21
| | | | | | Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20230818142244.17157-4-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Actually return the error code instead of 0Jules Maselbas2023-08-211-1/+1
| | | | | | | | | | The sdhci_transfer_data_dma function always returned 0 even in case of an error, fix this. Fixes: 60b608b271 ("mci: sdhci: Add DMA transfer helpers") Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20230818142244.17157-3-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Set 8-bit host capsJules Maselbas2023-08-211-0/+3
| | | | | | | | Set the mci::host_cap MMC_CAP_8_BIT_DATA if supported by the hardware. Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20230818142244.17157-1-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Add and use common sdhci_wait_for_done()Sascha Hauer2023-04-051-0/+27
| | | | | | | | | | | | | | | | | | | We have different driver specific variants of functions polling for the device ready in the tree. Add a common sdhci_wait_for_done() and use it where appropriate. This fixes a few deficiencies with the driver specific variants. rk_sdhci_wait_for_done() didn't check the SDHCI_INT_TIMEOUT bit and returned -EPERM instead when it ought to return -ETIMEDOUT. The core tries to detect a SD card first and expects a -ETIMEDOUT for the setup command when really a eMMC is connected. Only with a -ETIMEDOUT the core tries to detect a eMMC next. at91_sdhci_wait_for_done() returned the status instead of the expected 0 value for success. Link: https://lore.barebox.org/20230321095056.1333669-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-3/+3
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename device_d::device_node to device_d::of_nodeSascha Hauer2023-01-101-1/+1
| | | | | | | | | | | | | | | | | | | | Linux struct device has the member of_node for the device_node pointer. Rename this in barebox accordingly to minimize the necessary changes when porting Linux code. This was done with the semantic patch: @@ struct device_d E; @@ - E.device_node + E.of_node @@ struct device_d *E; @@ - E->device_node + E->of_node Plus some manual adjustments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: migrate "GPL-2.0" license identifiers to SPDX 2.0Roland Hieber2021-11-221-1/+1
| | | | | | | | | | "GPL-2.0-only" was introduced in SPDX 2.0, and the old identifier "GPL-2.0" is now considered deprecated; see <https://spdx.org/licenses>. Fixes: 28f4a6a4df76f0f1581d (2021-10-30, "drivers: add missing SPDX-License-Identifier") Signed-off-by: Roland Hieber <rhi@pengutronix.de> Link: https://lore.barebox.org/20211117113851.2022669-2-rhi@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: fix big-endian write for blockcount/sizeSteffen Trumtrar2021-10-051-3/+2
| | | | | | | | | | | | | | | | | | | | | | The patch 0a47bce1b03fd236384e904dca005c0870ce8684 mci: imx-esdhc: Use common DMA helpers converted the imx-esdhc driver to use the DMA helpers introduced with 60b608b2714472aa22862a20d04f267cbbac0863 mci: sdhci: Add DMA transfer helpers The common DMA helpers however break support for BE-variants (e.g. Layerscape) as the BLKATTR register seems to be a 32-bit register which internally switches bytes when used with two 16-bit write accesses. As the alignment should also work for LE-SDHCI-variants convert the two 16-bit accesses to one 32-bit access. Signed-off-by: Steffen Trumtrar <str@pengutronix.de> Link: https://lore.barebox.org/20210831064715.8392-1-s.trumtrar@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: Add DMA transfer helpersSascha Hauer2021-06-111-1/+117
| | | | | | | | | | | The SDHCI helpers only use PIO mode so far. This patch implements SDMA mode helpers. The helpers with _pio suffix explicitly do PIO while the DMA helpers have a _dma suffix and first try to do DMA, but fall back to PIO when DMA is not possible. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210610144720.25620-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: port over some common functions from LinuxSascha Hauer2021-06-101-0/+281
| | | | | | | | | | | | | | | | | | | | | | | | This adds some functions useful for SDHCI drivers from Linux: sdhci_calc_clk() sdhci_set_clock() sdhci_enable_clk() sdhci_read_caps() sdhci_set_bus_width() These functions can be used to further unify our different SDHCI drivers. All the new functions assume the also newly introduced sdhci_setup_host() has been called before using them. The functions are moslty the same as their Linux pendants, only sdhci_calc_clk() takes an addional clock rate argument where Linux uses host->max_clk. This is not suitable for the upcoming Rockchip driver which needs to adjust the input clock using clk_set_rate(), so fixed host->max_clk is not accurate for this driver. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210607104411.23071-5-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: sdhci: implement sdhci_reset()Ahmad Fatoum2020-04-271-0/+11
| | | | | | | | SDHCI reset is common between many SDHCI variants. Add a library function, so it can be reused. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: imx-esdhc-pbl: Use sdhci_transfer_data()Andrey Smirnov2019-12-041-0/+13
| | | | | | | | Drop some extra code by converting esdhc_do_data() to use sdhci_transfer_data(). Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mci: Add sdhci helperSascha Hauer2019-11-191-0/+127
We have several SDHCI compatible drivers in the tree. This starts with a set of generic helper functions for these drivers to share some common functionality. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>