[RFC PATCH 08/11] mci: Add sunxi-mmc driver

Ahmad Fatoum a.fatoum at pengutronix.de
Thu May 18 23:51:39 PDT 2023


On 19.05.23 07:51, Sascha Hauer wrote:
> On Thu, May 18, 2023 at 09:26:56PM +0200, Ahmad Fatoum wrote:
>> On 11.05.23 01:37, Jules Maselbas wrote:
>>> This driver is adapted from different sources: Linux, u-boot and p-boot.
>>> The latter, p-boot (forked from u-boot), is a bootloader for pinephones.
>>>
>>> It currently only support PIO xfer but could be further improved to also
>>> support DMA xfer. This driver is split in three source file so it can be
>>> used by PBL and barebox proper.
>>> ---
>>>  drivers/mci/Kconfig            |   6 +
>>>  drivers/mci/Makefile           |   2 +
>>>  drivers/mci/sunxi-mmc-common.c | 259 +++++++++++++++++++++++++++++++++
>>>  drivers/mci/sunxi-mmc-pbl.c    |  81 +++++++++++
>>>  drivers/mci/sunxi-mmc.c        | 173 ++++++++++++++++++++++
>>>  drivers/mci/sunxi-mmc.h        | 225 ++++++++++++++++++++++++++++
>>>  include/mach/sunxi/xload.h     |  12 ++
>>>  7 files changed, 758 insertions(+)
>>>  create mode 100644 drivers/mci/sunxi-mmc-common.c
>>>  create mode 100644 drivers/mci/sunxi-mmc-pbl.c
>>>  create mode 100644 drivers/mci/sunxi-mmc.c
>>>  create mode 100644 drivers/mci/sunxi-mmc.h
>>>  create mode 100644 include/mach/sunxi/xload.h
>>>
>>> diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
>>> index bbdca67e9d..c1903b6c90 100644
>>> --- a/drivers/mci/Kconfig
>>> +++ b/drivers/mci/Kconfig
>>> @@ -72,6 +72,12 @@ config MCI_DW_PIO
>>>  	help
>>>  	  Use PIO mode (instead of IDMAC) in DW MMC driver.
>>>  
>>> +config MCI_SUNXI_SMHC
>>> +	bool "Allwinner SD-MMC Memory Card Host Controller"
>>> +	help
>>> +	  Enable support for the Allwinner SD-MMC Memory Card Host Controller,
>>> +	  his provides host support for SD and MMC interfaces, in PIO mode.
>>
>> This
>>
>>> +
>>>  config MCI_MXS
>>>  	bool "i.MX23/i.MX28"
>>>  	depends on ARCH_MXS
>>> diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile
>>> index e3dc5ad8ae..c17cd41db1 100644
>>> --- a/drivers/mci/Makefile
>>> +++ b/drivers/mci/Makefile
>>> @@ -20,4 +20,6 @@ obj-$(CONFIG_MCI_SPI)		+= mci_spi.o
>>>  obj-$(CONFIG_MCI_DW)		+= dw_mmc.o
>>>  obj-$(CONFIG_MCI_MMCI)		+= mmci.o
>>>  obj-$(CONFIG_MCI_STM32_SDMMC2)	+= stm32_sdmmc2.o
>>> +obj-$(CONFIG_MCI_SUNXI_SMHC)	+= sunxi-mmc.o
>>> +pbl-$(CONFIG_MCI_SUNXI_SMHC)	+= sunxi-mmc-pbl.o
>>>  obj-pbl-$(CONFIG_MCI_SDHCI)	+= sdhci.o
>>> diff --git a/drivers/mci/sunxi-mmc-common.c b/drivers/mci/sunxi-mmc-common.c
>>> new file mode 100644
>>> index 0000000000..845078805b
>>> --- /dev/null
>>> +++ b/drivers/mci/sunxi-mmc-common.c
>>> @@ -0,0 +1,259 @@
>>> +#include "sunxi-mmc.h"
>>> +
>>> +static int sdxc_read_data_pio(struct sunxi_mmc_host *host, struct mci_data *data);
>>> +static int sdxc_write_data_pio(struct sunxi_mmc_host *host, struct mci_data *data);
>>> +static int sunxi_mmc_send_cmd(struct sunxi_mmc_host *host, struct mci_cmd *cmd, struct mci_data *data, const char **why);
>>> +static int sunxi_mmc_set_ios(struct sunxi_mmc_host *host, struct mci_ios *ios);
>>> +static void sunxi_mmc_init(struct sunxi_mmc_host *host);
>>> +
>>> +static int sdxc_read_data_pio(struct sunxi_mmc_host *host, struct mci_data *data)
>>> +{
>>> +	size_t i, len = data->blocks * data->blocksize;
>>> +	u8 *dst = data->dest;
>>> +	u32 reg;
>>> +
>>> +	sdxc_writel(host, SDXC_REG_GCTRL, SDXC_GCTRL_ACCESS_BY_AHB);
>>> +
>>> +	for (i = 0; i < len; i += 4) {
>>> +		if (wait_on_timeout(2000 * MSECOND, !sdxc_is_fifo_empty(host)))
>>
>> This can add up to 8 seconds. Just use is_timeout directly?
>>
>>> +			return -ETIMEDOUT;
> 
> It will return -ETIMEDOUT after two seconds at maximum.

Thanks. I misread and thought the loop was from 0 to 4 and wondered if
we shouldn't use a timeout for the whole loop runtime instead of iteration.

Thanks,
Ahmad

> 
> Sascha
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




More information about the barebox mailing list