Commit Graph

311 Commits

Author SHA1 Message Date
wanggang26 23c39f9dab mmcsd: add multi partitions support
include boot0,boot1,gp1,gp2,gp3,gp4,rpmb

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-16 16:58:37 +08:00
zhanghu5 32717ae353 sdio_probe: set voltage use CMD5
reference doc: https://www.infineon.com/dgdl/Infineon-SDIO_platform_support_guide-UserManual-v01_00-EN.pdf?fileId=8ac78c8c8c3de074018c8ba3a9973619

Signed-off-by: zhanghu5 <zhanghu5@xiaomi.com>
2024-10-15 21:04:28 +08:00
wanggang26 9ee4566b4d mmcsd:add reset card to idle state (CMD0) support
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-15 03:15:24 +08:00
wanggang26 243148241a mmcsd:add STATUS_SEND (CMD13) support
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-15 01:09:16 +08:00
wanggang26 955a3838f7 mmcsd: refine emmc capacity calculate
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-09 22:24:18 +08:00
wanggang26 ecc2d473e3 mmcsd: add multi partitions prototype implementation
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-09 13:57:07 +08:00
wanggang26 e16c785e8c mmcsd: move block driver register to probe stage in order to read ext_csd reg
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-10-05 09:17:25 +08:00
Xiang Xiao 73f0c7c51d drivers/mmcsd: Rename mmcsd_read_csd to mmcsd_read_extcsd
since it really read extcsd register not csd register
and remove the temp buffer inside it.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-09-30 21:17:27 +08:00
wanggang26 ce1d047845 mmcsd: fix cmd6 timeout error when repeat calling
If CMD6 is sent again before last transmission is complete, a timeout
error will be encountered.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-27 10:25:51 +08:00
Jukka Laitinen 5238c3bb25 drivers/mmcsd/mmcsd_sdio.c: Fix setting SDIO_WIDEBUS for SD cards
This corrects the setting widebus for SD cards, which was recently broken in 4f7f751d2a.

The if checking the priv->caps, priv->buswidth and IS_MMC has been wrong for
some time. The proper logic is that for MMC only the priv->caps is checked.
For SD card, both priv->caps and priv->buswidth need to be checked.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-09-25 21:10:26 +08:00
wanggang26 f6c1d88931 mmcsd: fix a build error
Error: mmcsd/mmcsd_sdio.c:1419:12: error: 'mmcsd_setblockcount' defined
but not used [-Werror=unused-function]
1172 1419 | static int mmcsd_setblockcount(FAR struct mmcsd_state_s
*priv,

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-19 15:44:59 +08:00
wanggang26 1a6e8b9c99 mmcsd: fix a logic error
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-19 07:29:33 +02:00
wanggang26 ff0194fb74 mmcsd: make a compatibility change for cmd12 and cmd23
For some sd cards don't support cmd23 or support cmd23 indicated by
bit33 in scr

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-19 03:17:48 +08:00
chenrun1 44351959ee mmcsd_sdio:Limit the use of sleep in mmcsd.
reference:https://github.com/apache/nuttx/pull/12971

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-06 12:25:55 +08:00
chenrun1 0e13ea9ed1 mmcsd_sdio:Fix performing read and write in irq
In some usage scenarios, read and write tasks will be performed during interruptions. If sleep is used at this time, it will cause a timeout crash. Therefore, a macro is added to determine whether it is currently interrupted to select sleep/delay.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-06 12:25:55 +08:00
wanggang26 dfffaee706 mmcsd: add write ext csd reg support
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-08-26 17:45:43 -04:00
Petro Karashchenko d499ac9d58 nuttx: fix multiple 'FAR', 'CODE' and style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
Petro Karashchenko d252b6229f nuttx: use sizeof instead of define or number in snprintf
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
wanggang26 a2662bd369 mmcsd: add support of getting ext_csd reg data
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-08-21 02:53:54 +08:00
Windrow14 5c8adefc67 drivers/mmcsd/Kconfig|mmcsd_sdio.c: check ready without sleep
If per tick is set to 10ms, it will cause nxsig_usleep(1000) in the
sdio driver to sleep for 19ms, which is much longer than the
expected 1ms, resulting in very low write performance. Add option to
reduce CPU hogging by using sched_yield(), though it may also affect
write performance when the CPU is busy.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
2024-08-19 19:52:39 +08:00
Windrow14 c96a33a12f drivers/mmcsd/mmcsd_sdio.c: enable clock before issue CMD0
In mmcsd_cardidentify(), the clock is not enabled before issuing
CMD0, and the clock has been disabled in mmcsd_removed(). It makes
no sense to enable the clock after issuing CMD0, because when CMD0
is issued, it will exit with error due to the clock is not enabled.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
2024-08-19 19:52:39 +08:00
Windrow14 d07e73e684 drivers/mmcsd/mmcsd_sdio.c: show eMMC information after initialization is completed
Prompts for capacity, speed mode and bus width after eMMC
initialization is completed.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
2024-08-19 19:52:39 +08:00
Windrow14 49cbcfb5e6 drivers/mmcsd/mmcsd.h|mmcsd_sdio.c|mmcsd_sdio.h: support MMC high speed SDR mode
According to the eMMC specification, in Backwards Compatibility
with legacy MMC card mode, the frequency of the SD clock must be
0-26 MHZ; in high speed SDR mode, it must be 0-52MHZ. So we should
switch to high speed SDR mode if the clock frequency is higher than
26MHZ.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
2024-08-19 19:52:39 +08:00
Windrow14 08ce36d292 drivers/mmcsd/mmcsd_sdio.c|h: optimize macros for setting EXT_CSD
CMD6 can use these macros to set any writable EXT_CSD field, not
just the bus width, so optimize these macro definitions to make
them general.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
2024-08-19 19:52:39 +08:00
Windrow14 4f7f751d2a drivers/mmcsd/mmcsd_sdio.c: fix unable to switch eMMC device to 4-bit bus width mode
All eMMC devices support 4-bit bus width, so we should mark the
device as supporting 4-bit bus width after detecting that the
device type is eMMC.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
2024-08-19 19:52:39 +08:00
Jani Paalijarvi 975d99c3f6 drivers/mmcsd/mmcsd_sdio.c: Fix SD card 4-bit support
Fix a bug which causes that 1-bit mode is always selected.
This happens even if the driver sets SDIO_CAPS_4BIT capability
in case of the card and the host support 1- and 4-bit wide bus.

Signed-off-by: Jani Paalijarvi <jani.paalijarvi@unikie.com>
2024-05-10 19:43:08 +08:00
yinshengkai 9852428953 fs: procfs add poll support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-12-26 19:23:13 -08:00
Xiang Xiao 673cb18a7a drivers/mmcsd: mmcsd_sdinitialize should save csd register into priv->csd
just like what mmcsd_mmcinitialize do

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-11-19 20:24:30 +01:00
Xiang Xiao f02ad03124 Fix error: 'mmcsd_general_cmd_read' defined but not used
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-26 00:45:50 +03:00
wanggang26 50cad1536d emmc: add get emmc cid register interface.
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-25 23:29:34 +08:00
wanggang26 203b558ec9 mmcsd: fix a typo
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-24 19:34:14 -04:00
Xiang Xiao 723d721098 Fix mmcsd/mmcsd_debug.c:110:9: error: format '%d' expects argument of type 'int', but argument 3 has type 'long unsigned int'
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-25 01:10:00 +03:00
wanggang26 db2f204cc4 mmcsd: support dump cid and csd with mmc-utils
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-21 22:40:39 +08:00
wanggang26 fa744e24a3 mmcsd: update cid reg layout
refer spec: https://www.jedec.org/sites/default/files/docs/JESD84-B51.pdf

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-20 00:42:30 +08:00
Eero Nurkkala db13d5e24c drivers/mmcsd: fix regression causing emmcsd not working
Commit 50a8ec6 broke many mmc devices.  Only if the flag
priv->caps & SDIO_CAPS_4BIT_ONLY was set, it migth work.
Without the flag, the mmc clock is never set (mmcsd_widebus()
call is terminated early stopping the clock).  This flag
is probably not very generic because most mmc hw support
1, 4 and 8 bit modes.

JEDEC specifies a bus width selection procedure, but it's
not implemented in this mmcsd_sdio.c driver.  Thus, it's
not known whether the hw supports 1, 4 anf 8 bit modes or
a combination of them.

However, with priv->caps & SDIO_CAPS_4BIT_ONLY the driver
suddenly assigns priv->buswidth = MMCSD_SCR_BUSWIDTH_4BIT
making it the only way to have the driver working.

Fix this by relaxing the above mentioned restrictions.

Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
2023-08-30 14:33:32 +08:00
chao an b60f01a55b inode/i_private: remove all unnecessary cast for i_private
Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-29 08:58:07 +02:00
chao an 7aa45305b7 fs/inode: remove all unnecessary check for filep/inode
Since VFS layer already contains sanity checks, so remove unnecessary lower half checks

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-29 09:47:11 +08:00
zhanghu5 a69b6846e6 fix byte_block_count error in byte mode
Signed-off-by: zhanghu5 <zhanghu5@xiaomi.com>
2023-08-11 13:15:57 +08:00
dongjiuzhu1 37fc0a0208 drivers/mmcsd_sdio: config timout to write one data block
Some hardware needs to config this delay to write one data block, because
the hardware needs more time to wear leveling and bad block manage.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-28 05:01:36 -07:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Xiang Xiao 7990f90915 Indent the define statement by two spaces
follow the code style convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-21 09:52:08 -03:00
Petro Karashchenko 8254b374dd drivers/mmcsd: fix style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Radek Pesina 50a8ec62c4 Add eMMC driver support
- Fix DMA addressing issues within litex_sendsetup/litex_recvsetup
- Extend with handling specific to eMMC commands during init & use.
- Cleanup of 4-bit BUS handling for SD and eMMC
- For eMMC, Send CMD0 during init as per JEDEC v4.41 for pre-idle
2023-04-26 00:34:36 -04:00
chao an 4e3480554d mmcsd/sdio: enlarge cmd53 timeout to 1s
cmd53 need a longer tolerance on some slow devices

Signed-off-by: chao an <anchao@xiaomi.com>
2023-03-22 17:26:52 -03:00
chao an 1b46484849 mmcsd/sdio: fix potential race condition in sdio
sdio driver should ensure the thread safety

Signed-off-by: chao an <anchao@xiaomi.com>
2023-03-21 14:40:44 -03:00
Michal Lenc 0797b03c08 mmcsd: add nxsig_usleep delay after MMC_CMD1 command
MMC_CMD1 command is used to check whether card is MMC type (checked if
CONFIG_MMCSD_MMCSUPPORT is enabled). This commit inserts nxsig_usleep
wait if this check fails. This is to ensure the communication recovers
from invalid response as this may take some time on some platforms (
samv7 for example). Following command for SDHC check may fail if sleep
is not used.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2023-03-13 22:22:54 +02:00
David Sidrane 9d0e712347 mmcsd_sdio:Release CPU during wait for Write Completion 2023-02-17 15:26:19 +08:00
David Sidrane d570a93945 mmcsd_sdio:Insure a error exiting via mmcsd_removed will not Hang system.
mmcsd_removed will be called if the card is in invalid state.
   This can happen if the card is bad, or vibrations causes a power
   loss.

   mmcsd_removed resets:
     priv->capacity     = 0; /* Capacity=0 sometimes means no media */
     priv->blocksize    = 0;
     priv->probed       = false;
     priv->mediachanged = false;
     priv->wrbusy       = false;
     priv->type         = MMCSD_CARDTYPE_UNKNOWN;
     priv->rca          = 0;
     priv->selblocklen  = 0;
     priv->widebus      = false;

  If blocksize is set to 0 will cause the log2 to result
  in an infinate loop in some drivers.

  IS_EMPTY will check for priv->type = MMCSD_CARDTYPE_UNKNOWN
  and return ENODEV.
2023-02-17 15:26:19 +08:00
chao an d1162ac58f mmcsd/mmcsd_spi: remove redundant mmcsd_unlock()
Assertion on lm3s6965-ek/qemu-flat if enable CONFIG_DEBUG_ASSERTIONS:

_assert: Current Version: NuttX  12.0.0 666b224c35 Feb  3 2023 19:36:38 arm
_assert: Assertion failed : at file: misc/lib_mutex.c:336 task: nsh_main 0xb385

Backtrace:
nuttx/libs/libc/sched/sched_dumpstack.c:69
nuttx/sched/misc/assert.c:494
nuttx/libs/libc/assert/lib_assert.c:36
nuttx/libs/libc/misc/lib_mutex.c:336
nuttx/drivers/mmcsd/mmcsd_spi.c:421
nuttx/drivers/mmcsd/mmcsd_spi.c:2072
nuttx/boards/arm/tiva/lm3s6965-ek/src/lm_bringup.c:119 (discriminator 3)
nuttx/boards/boardctl.c:335
apps/nshlib/nsh_init.c:144
apps/system/nsh/nsh_main.c:68
nuttx/libs/libc/sched/task_startup.c:70 (discriminator 2)
nuttx/sched/task/task_start.c:134

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-03 16:34:04 +02:00
Xiang Xiao 9f027208d4 fs: Add model field to geometry and mtd_geometry_s
the model is very useful to track the device info

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-31 11:50:28 -03:00