mmc: Fix size calculation for sector addressed MMC version 4
authorMarek Vasut <marex@denx.de>
Wed, 29 Jan 2025 11:15:54 +0000 (12:15 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 24 Feb 2025 20:16:28 +0000 (14:16 -0600)
commitdbb9e136b8c01de581a08113ae6124f484b29362
tree45ec64a67c311bbed19d29bab86d44d951bfd3eb
parent59fd62d71c6a04b3ab9db848414a7c386cfd2cfb
mmc: Fix size calculation for sector addressed MMC version 4

For eMMC v4 and newer that is smaller than 2 GiB, the JEDEC JESD84-B51
section 6.2.4 Configure partitions indicates that EXT_CSD SEC_COUNT
should not be used to determine device size, and instead device size
should be calculated from C_SIZE and C_SIZE_MULT.

This is not exactly accurate, the 2 GiB limit is not a hard line,
there are eMMC devices which are smaller than 2 GiB and still
require device size to be determined from EXT_CSD SEC_COUNT. The
hard line is instead OCR HCS bit, which indicates whether the device
is byte or sector addressed, the former applies to most devices
below 2 GiB, and the later applies mostly to devices above 2 GiB.

However, there are a couple of devices which are smaller than 2 GiB
and still set the OCR HCS bit to indicate they are sector addressed,
and therefore the size calculation for those devices should also
use EXT_CSD SEC_COUNT . Use mmc->high_capacity flag to discern the
devices instead of arbitrary 2 GiB limit. The mmc->high_capacity flag
reflects the OCR HCS bit state.

Fixes: 639b7827d1ca ("mmc: fix the condition for MMC version 4")
Signed-off-by: Marek Vasut <marex@denx.de>
drivers/mmc/mmc.c