In CQ mode, the legacy commands will be sent after CQ is put in
halt state. But when deferred resume is enabled, the resume
happens in mmc_wait_for_req(), which will enable CQ again
overiding the caller's state. This causes legacy commands to fail.
Fix this by moving the deferred resume from all the places to
mmc_rpm_hold() which is always the first step done in both
CQ/legacy commands and thus avoids the above issue scneario.
Fix: fbb7cbf8ea (mmc: core: Add deferred resume for command queue mode)
Change-Id: I97fb9d654968b294dc1fb6986b8b9431e22233c0
Signed-off-by: Veerabhadrarao Badiganti <vbadigan@codeaurora.org>
MMC_PM_WAKE_SDIO_IRQ flag is used by platform driver(sdhci-msm
here) to determine if SDIO wakeup IRQ needs to be enabled
or not. If this flag is not removed in every mmc_resume_host,
then while suspend, platform driver will configure the sdio
wakeup IRQ even though wlan is disabled from UI.
This flag can be enabled by wlan driver before entring into suspend.
In this case since Wlan is not enable and thus not entering WoW mode,
pull up present on this SDIO GPIO line will pull the line high (which
otherwise is pulled low by wlan firmware in WoW mode and triggers
interrupt by pulling it high in WoW mode) which eventually will
trigger a false SDIO wakeup interrupt thus breaking the suspend
everytime.
Hence disable the flag everytime in mmc_resume_host and let
wlan driver enables it (-by sdio_set_host_pm_flags)
before entering into suspend if needed
for sdio wakeup part.
Change-Id: Iecf9eef4d91a741116bc8b8bb59c49ae7f2891fd
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
Power supply to card QCA9377 & QCA6574 is used for wlan and
bluetooth as well.
Now if SDIO card is switched to 1.8V signaling voltage, it will not
switch back to 3.3V without a power cycle. CMD0 will not make SD (SDIO)
card enter 3.3V signalling voltage. Since the power supply
for mentioned card is also used to power bluetooth along with
wlan, so card cannot be power cycled for wlan alone from such mmc
host
This patch adds a capability for such host which cannot power cycle
the card. Thus during resume of sdio (mmc_sdio_resume), it checks
if host has MMC_CAP2_BROKEN_PWR_CYCLE capability set. In case if this
capability is set we do mmc_sdio_power_restore.
This patch also fixes the resume path that if there is an oldcard
present and it's an UHS card then CMD11 may give no response. In that
case we need to switch only host signal voltage to 1.8V as card is
already in 1.8V.
Without this patch software assumes that card is switched to 3.3V on
power cycle and tries voltage switch sequence which fails
(because host driver will not control this power supply and thus
card will never enter into 3.3V supply). Thus UHS mode is not entered.
Change-Id: I1fae116fd3c5b3854761ac09da1ffec7f6ddfec9
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
During the suspend of class device (mmc_host), it is
legal for the suspend to fail. For e.g in case of SDIO
the wlan may refuse to suspend at that point of time.
In such a scenario the device should not be marked as
suspended. Its state should be restored to resumed.
Otherwise, the device never enters suspend again.
write mem to /sys/power/state -> suspend is triggered
[0: ksdioirqd/mmc2:25044] HIFsuspendwow TODO
wma_suspend_fw: wow suspend successful
system_server: 1226] vfsspi_regulator_onoff: off
kworker/u16:2:23854] mmc2: mmc_host_suspend: start
wma_check_scan_in_progress: scan in progress on interface
hifDeviceSuspend: Scan in progress. Aborting suspend
kworker/u16:2:23854] wlan suspend failed error=-1
Wlan refuses to suspend above
mmc2: mmc_host_suspend: failed: ret: -1 .
mmc2: mmc_host_suspend: end -->
dpm_run_callback(): mmc_host_suspend+0x0/0x2d8 returns -1
PM: Device mmc2 failed to suspend async: error -1
PM: Some devices failed to suspend
Since wlan refuses to suspend, SDIO doesn't suspend too.
But the class device is still marked to be suspended
[state: 2] incorrectly.
It should be marked as resumed, since suspend had failed.
After this, the device never suspends:
!@suspend_thread_func: write mem to /sys/power/state
PM: suspend entry 2016-03-29 10:52:42.456889406 UTC
mmc2: sdio_irq_thread: 130: acquired wlock: state: 2 ->
incorrectly marked as suspended.
mmc2: sdio_irq_thread: 130: acquired wlock: state: 2
PM: Syncing filesystems ... done.
active wakeup source: mmc2:0001->wakeup event by mmc2
CRs-fixed: 997876
Change-Id: Ib08a72b2ab21c4d4a76bac8e65d06c13ccbd1482
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Do not resume the eMMC device as part of the system resume.
Only resume it when there's a request to be processed.
CRs-fixed: 972118
Change-Id: Ia4b3fcafb3fb5eabaad9d32bd776a03f45d4ab40
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Pavan Anamula <pavana@codeaurora.org>
Currently ios->timing mode for HS400 mode is missing
from debugfs and thus taken as invalid.
Fix this by adding HS400 timing mode info in
mmc_ios_show.
Change-Id: I49d1e93862d97de6e2f0e2fa5da2b1be03ee60b1
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
To remove bus vote we expect clk-gating to kick in. But when SDcard is not
inserted, we are never turning the clocks on and hence gating will never
kick in. Thus bus voting will be always put to true.
Fix this by notifying the sdhci_msm about the pm_status only when card
is present(if host->bus_ops is NOT NULL) and remove bus vote in case of
error in mmc_suspend_host/mmc_resume_host.
Change-Id: I1f244e312f0716f99cdc53c991d37b102d40b8bc
Signed-off-by: Sayali Lokhande <sayalil@codeaurora.org>
Following eMMC JEDEC JESD84-B51 standard, an ehannced form of
rpmb is supported. What this enhanced mode supports is in
addition to be able to write one rpmb or two rpmb frames at a
time,32 frames can be written at a time.
Expose this information present in ext csd field so that the
user space application that wants to make use of this can do
so.
Change-Id: I53fd962fd7e04b5d2d7804c289d7865c2c5618d5
Signed-off-by: Krishna Konda <kkonda@codeaurora.org>
Signed-off-by: Pavan Anamula <pavana@codeaurora.org>
This patch does following-
This adds an API(mmc_cmdq_hw_reset), for RESET_ALL
of SDHCI, power cycle mmc card and
reintialize it, which enables cmdq as well(if supported).
This acquires claim_host before calling mmc_power_restore.
mmc_power_restore should be called with claim_host acquired,
since this function is required from non-claim-host context in
cmdq error handling.
Change-Id: I31c4449dead1d4ad4e10a4822cce2298ec5fb4b6
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
Call mmc_/cmdq_post_req with tag number instead of
mrq. This is needed in error handling as part of multiple
request error handling.
Change-Id: I175432639d28378ec74669e31deb4d1667c49bb8
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
This is to ensure that clock scaling work is either cancelled
or completely done if it is already running before the MMC/SD
suspend is started. Otherwise, the system suspend may fail
unnecessarily if it cannot claim the host due to pending
clock scaling work.
Change-Id: Icc465a607451b29d51e27b733e506060ca9f9dc0
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
After reading ext_csd, the host is not claimed while
doing unhalt if the card is in CQ mode. This may race
with RPMB context which tries to halt and disable CQ
in the card. This may unhalt the controller while RPMB
is still going on, resulting in software request timeout
for RPMB commands that are supposed to be sent in
legacy mode with controller in halt state.
Fix this by claiming the host till the unhalt is done
in mmc_ext_csd_open() so as to prevent race with RPMB
context.
Change-Id: I6d2738b21c3cd44c8fb6c99f63291059d5b18ee1
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
This reverts commit 5df1d211b6.
This is because it breaks the existing shutdown for eMMC and SD
card.
Change-Id: Id78b8bfd0f4ad29a13e006fa1ce866b36f180011
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
This change reverts the following gerrits as they break the
existing shutdown functionality for eMMC and SD card.
8635767 "mmc: core: Extend shutdown sequence to handle bus operations"
b4f9379 "mmc: core: Add shutdown callback for (e)MMC bus_ops"
e3126b8 "mmc: core: Add shutdown callback for SD bus_ops"
Change-Id: I3d34404e653600d52015afe851ae55b7e60e07dd
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
During system suspend mmc_host_suspend halts CQE and then
disables it. At the same time, if any req is pulled by
mmc_cmdq_thread and acquires mmc_claim_host.
mmc_suspend_host -> will return -EBUSY then but currently
we dont re-nable the CQE state if mmc_suspend_host returns an
error. This causes all request to timeout.
Fix this by try to claim host before calling mmc_suspend_host
(in case of CQ) & enbling CQE back and unhalting it in case
mmc_suspend_host fails (for both runtime/system suspend)
Change-Id: Ieb8e094ec216679dc6c9d5f9b4f870da9ff6963f
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
Fix the timeout issue with mmc_cmdq_halt() that happens in the
below scenario -
1. Let us say an RPMB request is processed just before the
runtime suspend. The RPMB request will put the controller in HALT
state and will put the card in legacy mode.
2. So during runtime suspend, the SW will check for card's state and
since it is in legacy mode, it won't call CQ disable host->op.
But CQ HW will get reset due to SW reset that gets issued during suspend.
3. If we get another RPMB request, we try to do the runtime resume.
But since SW did not invoke CQ disable host->op, it thinks that CQ is still
enabled and returns here without enabling CQ.
4. Now the RPMB request tries to put the controller in HALT state but
timesout since CQ is still not enabled.
Fix this issue by checking for host->card->cmdq_init to determine
if the controller is initialized in CQ mode instead of checking for
card's state in runtime suspend. This will ensure CQ will be disabled
as part of runtime suspend and will be enabled again during
runtime resume.
Change-Id: I26bf97962d31522a9cb25009c6a048dfff6e4535
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Earlier we disabled the cache during suspend, which meant a flush was
internally at the eMMC performed as well.
To simplify code we can make use of the mmc_flush_cache(), during mmc
suspend, which makes the mmc_cache_ctrl() redundant so then we can
remove it.
Change-Id: I80c6cbf9ad3e81943aee4b844c267c8e4f360257
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Seungwon Jeon <tgih.jun@samsung.com>
Signed-off-by: Chris Ball <chris@printf.net>
Git-commit: 1a6fd1533dfa409e48f377db1d92ef1cc6b0c4ce
Git-repo: https://android.googlesource.com/kernel/common.git
[kaushalk@codeaurora.org: Resolved context conflicts]
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
Commit "mmc: core: Handle card shutdown from mmc_bus" introduced an
Oops in the shutdown sequence for SDIO.
The drv pointer, does not exist for SDIO since the probing of the SDIO
card from the mmc_bus perspective is expected to fail by returning
-ENODEV.
This patch adds the proper check for the pointer before calling it.
Change-Id: I31b014f9c6600683e79738e161fcb946a1f4948b
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reported-by: Stephen Warren <swarren@wwwdotorg.org>
Reported-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
Tested-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: b807de244fa78d579fa7283b37fc21b3c13eddab
Git-repo: https://android.googlesource.com/kernel/common.git
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
The DT-binding for MMC_CAP2_FULL_PWR_CYCLE, is used to indicate whether
it is possible to perform a full power cycle of the card.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: 823b9ed01bbcb01d5119f822142f8620cc897571
Git-repo: https://android.googlesource.com/kernel/common.git
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
MMC_CAP2_FULL_PWR_CYCLE shall be set by host drivers which are able to
do a complete power cycle of the card. In the eMMC case that includes
both vcc and vccq.
This CAP is providing the protocol layer with important information,
needed to take optimized decisions during card initialization and in
the suspend/resume sequence.
MMC_CAP2_POWEROFF_NOTIFY is replaced by MMC_CAP2_FULL_PWR_CYCLE, since
it makes sense to use a wider scope for it.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: 211f8b40b27a83c8513bcade87188ab168aece90
Git-repo: https://android.googlesource.com/kernel/common.git
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
In suspend mode it is important to save power. If the host is able to
cut buth vcc and vccq, the MMC_CAP2_POWEROFF_NOTIFY shall be set. It
will mean the card will be completely powered down at suspend and the
power off notification cmd will be sent prior power down.
It seems common not being able to cut both vcc and vccq for a host. In
this situation we issue the sleep cmd in favor of the power off
notification cmd, to save more power.
While maintainng the above policy, we also want to make use of the
power off notification in the shutdown sequence, even in the case were
the host has not set MMC_CAP2_POWEROFF_NOTIFY, since we know vcc and
vccq will regardless be cut.
We accomplish this by always enabling the power off notification byte
in the EXT_CSD and issue the power off notification when either
MMC_CAP2_POWEROFF_NOTIFY is set or we are executing a shutdown.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: 020586d24e5dce45b0738d9340636c9f1688237f
Git-repo: https://android.googlesource.com/kernel/common.git
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
The shutdown sequence of an (e)MMC is very similar to a suspend. We
re-use the suspend function and tell it we are not in suspend context.
Change-Id: Id81922dce7227759f84c24e864d0c24c8aee0fb1
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: eb91ee02bce94d96560b670508f64a86544f2ecc
Git-repo: https://android.googlesource.com/kernel/common.git
[kaushalk@codeaurora.org: Resolved context conflicts]
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
Depending on the context of the operation while powering down the card,
either POWER_OFF_NOTIFY_SHORT or POWER_OFF_NOTIFY_LONG will be used. In
suspend context a short timeout is preferred while a long timeout would
be acceptable in a shutdown/hibernation context.
We add a new parameter to the mmc_suspend function so we can provide an
indication of what notification type to use.
Change-Id: I4a1db618d8b41dc7851e4cc95f801e3585b665e8
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: bb09907fdbc4451448e9efb9009f0ef538e52861
Git-repo: https://android.googlesource.com/kernel/common.git
[kaushalk@codeaurora.org: Resolved context conflicts]
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
For the SD .shutdown callback we re-use the SD suspend function since
it performs the relevant actions.
Change-Id: Ibbc3dbdf9fa368c16d590ccdd7c62333c11ad50d
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: 2a68a68a88ce0fac7b69792776355ff5bdd69962
Git-repo: https://android.googlesource.com/kernel/common.git
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
By adding an optional .shutdown callback to the bus_ops struct we
provide the possibility to let each bus type handle it's shutdown
requirements.
Change-Id: Ie746b03c24f1e6b3b54aaefb09fa15cc10a731b3
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: c53cd1c90652a7109da51238a92f8075f86902ec
Git-repo: https://android.googlesource.com/kernel/common.git
[kaushalk@codeaurora.org: Resolved context conflicts]
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
Considering shutdown of the card, the responsibility to initate this
sequence shall be driven from the mmc_bus.
This patch enables the mmc_bus to handle this sequence properly. A new
.shutdown callback is added in the mmc_driver struct which is used to
shutdown the blk device.
Change-Id: I2327f396b2cf01f30f31b46b025a1867ccf7d92a
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <cjb@laptop.org>
Git-commit: feaf40b94634f3ae497465b023c56fbda1d1877e
Git-repo: https://android.googlesource.com/kernel/common.git
[kaushalk@codeaurora.org: Resolved context conflicts]
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
Read the firmware version from ext_csd register and print it
for debugging purpose.
Change-Id: I4c1fefd5bff753915c9858fb35c958335986c778
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Read the firmware version from ext_csd register and print it
for debugging purpose.
Change-Id: I4c1fefd5bff753915c9858fb35c958335986c778
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
This adds support in mmc host layer to notify LLD
with mmc suspend/resume state.
This information is needed by LLD for optimizing
suspend/resume latency.
Change-Id: Ib8d8f63b4b228079f0e7ef79164e243a55eb2559
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
Add support to use the DDR52 bus speed mode during eMMC clock
scaling, if the host supports it. This patch currently adds
support only for scaling up/down from HS400<->DDR52.
Change-Id: I21282c3dcef4605584ed7b1817165cc85b2de034
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
There is no action taken if the card is runtime suspended by the time
system suspend is triggered. During system resume, the card remains
runtime suspended and also no action taken.
However, when the card in system suspend was not runtime suspended and
the suspend sequence was executed as part of the system suspend
sequence, on system resume there is resume sequence to execute. For
command queueing mode, before suspending the card the CQE was halted,
therefore after resuming the card during system resume the CQE un-halt
must be executed.
This change executes CQE un-halt sequence only in case the card resume
sequence was done.
Change-Id: I41eaa9fe050bbba22cf4a9e118268579f08a1e3c
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
Timeout handler executed on softirq context. cmdq dumpstate() api resumes
platform device and it can't be executed on softirq context. Request
completion callback schedules error handler work in case of timeout error.
This change moves CQE registers dump to the error handler callback.
Change-Id: Iea26ca5240f6031218dcf374cafcf2708df1f125
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
Some eMMC vendors violate eMMC 5.0 spec and set REL_WR_SEC_C
register to 0x10 to indicate the ability of RPMB throughput
improvement thus lead to failure when TZ module write data to
RPMB partition. This change will check bit[4] of EXT_CSD[166]
and if it is not set then change value of REL_WR_SEC_C to 0x1
directly ignoring value of EXT_CSD[222].
CRs-Fixed: 866059
Change-Id: Ibd12c94ad691eca1fa3ea2049b750a6e98178678
Signed-off-by: xiaonian <xiaonian@codeaurora.org>
Currently getting status/ext_csd using debugfs or IOCTL
calls in cmdq mode is not working.
Fix it by halting the cmdq engine and making sure that
card queue is empty before issuing these cmds.
Change-Id: Idb89def9ff5c2fee6866759b9a8c652049552933
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
When CONFIG_MMC_BLOCK_DEFERRED_RESUME was enabled,
if sleep and wake up the phone, then remove SD card,
the removal event will not be detected. This change
will ensure removal detection of SD card even if it
has not been resumed if the card is removed after
waking up the phone.
Change-Id: Ib99d1915b6fc150979c77dc3fbf6af79e5558db6
Signed-off-by: xiaonian <xiaonian@codeaurora.org>
During system suspend CQE halted by queue suspend even before mmc host
suspend. When mmc host suspend calls halt helper, CQE is already halted.
This change ignores error value of halt helper.
Change-Id: I2d1456333f1d04f0e7a77485443b80a0ccaa3b4e
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
mmc_host_clk_hold/release pair should be added for relevant
cmdq_ops. Since it enables host->clock which is needed
for register access as well (apart from
MCLK).
Change-Id: I6d9d15a421225c5b4179cb19e467a17d01ad176f
Signed-off-by: Ritesh Harjani <riteshh@codeaurora.org>
As per eMMC specification, the PON (Power Off Notification)
must be sent by host to the card before turning off the power.
This will allow card to prepare itself for the power off and
may even reduce the initialization of eMMC upon next boot-up.
Send long PON during system power off and send short PON during
system reboot to reduce the reboot latency.
Change-Id: If4188b8b80aaa0e6c4e00e1807aa9589d5e7efdb
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Need to cancel clock scaling work only when scaling was enabled and
the card is in the legacy (non-cq mode).
Change-Id: Ibfe00e54c495e249d0937345ffc6e6335940d21e
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
Add trace events to capture mmc runtime suspend-resume latencies.
This would be useful to capture latencies for variety of MMC/SD cards
and decide on best possible runtime PM timeout.
Usage -
cd /sys/d/tracing
echo 1 > events/mmc/mmc_host_runtime_suspend/enable
echo 1 > events/mmc/mmc_host_runtime_resume/enable
Change-Id: Ia5dbb175c16f3e697d1239cb1faa5764ffeb5414
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
This change is needed bacause mmc_rpm_release() api is used in softirq
context, when usage counter goes to zero, it will trigger pm core runtime
suspend callback.
Change-Id: I18b1d193952a83336d6539c495509091c24e7d41
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>