Commit graph

208 commits

Author SHA1 Message Date
Pavan Anamula
0b56648089 mmc: host: add support to allow SANITIZE operation
SANITIZE is an operation performed by the storage device and its purpose
is to delete its unmap memory regions.
This change adds support for the SANITIZE capability.

Change-Id: I58b647fb576c694aaa16c1e827d0784d4a5b4456
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
Signed-off-by: Pavan Anamula <pavana@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:27:17 -07:00
Gilad Broner
9bc36b07a2 mmc: core: kick block queue after unhalting cmdq
If request has to be requeued due to cmdq being halted and if we change
the task status to interruptible before going to sleep then cmdq thread
may not wakeup again. Note that blk_requeue_request() doesn't trigger
->request_fn() again to wakeup the cmdq thread.

Fix this issue by kicking the queue once cmdq state machine is unhalted.

Change-Id: Icbfb3b6560285fa0a0ce7e83eee66b651d4594a0
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:27:15 -07:00
Dov Levenglick
8ee51daf1c mmc: schci: add support for MMC_PM_KEEP_POWER in eMMC
There are eMMC cards that should not be powered off
during suspend/resume cycles.
This patch adds support for such cards and avoids powering
the card off during suspend or powering it back on
during resume when MMC_PM_KEEP_POWER is set.

Change-Id: Iec1a0aac80ee41dff56f192e7253c2bd00c15694
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
2016-05-31 15:27:04 -07:00
Dov Levenglick
348a140b51 mmc: host: add detect vops chain
Add call from sdio to host_ops to sdhci_ops
in order to indicate when a sdio card is detected.
This will be used by hosts that require special
handling for card detection.

Change-Id: I65ec6ee464d658cd938d9254a0a748e6137f9223
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:27:03 -07:00
Talel Shenhar
2941d9d5bd mmc: sdhci: cmdq: add notification for cmdq halt
During halted CMDQ mode, HW expects descriptors sizes
same as used in CMDQ mode.
Our SW uses the legacy path (SDHCI) in case CMDQ is halted,
thus, we need to update legacy path of the fact that we
are in Halted CMDQ state so it can adjust the descriptors
size accordingly.
This change adds a notification mechanism for that purpose.

Change-Id: Iabb473696fb11827dfcce9b137c26b2c5a5a879d
Signed-off-by: Talel Shenhar <tatias@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts & compilation
errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:52 -07:00
Talel Shenhar
a9c940c044 mmc: cmdq: add clock scaling for CMDQ mode
This change adds clock scaling ability to command-queueing
mode, it does so by adding next logic:

* Statistics collection for CMDQ data path
* Empty the queue and Halt it before frequency change
* Scale from data path in case host claiming is not possible

Change-Id: I53a323b55df4d7c27e3ee3426ee4e856e533522c
Signed-off-by: Talel Shenhar <tatias@codeaurora.org>
2016-05-31 15:26:51 -07:00
Dov Levenglick
fda56078bb mmc: add support for bkops
Add support for manual and auto bkops for
legacy (not command-queue) mode.

Change-Id: I1333e1d4330393e446ba48a9474c83295744c050
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
[subhashj@codeaurora.org: fixed merge conflicts and compilation
errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:49 -07:00
Venkat Gopalakrishnan
506b393bf6 mmc: Add host ops for enhanced strobe
Some hosts may need additional steps to get HS400 functional in
enhanced strobe mode. Add host ops to facilitate that.

Change-Id: I9663830e7ccedf8bf7970d0724a4c7ce212073fd
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:46 -07:00
Asutosh Das
eb2587ce53 mmc: queue: add timeout capability to requests
Individual requests can have timeouts defined. The default
timeout is set to 120 seconds. On a timeout, the block layer
notifies the driver and error can be handled thereafter.

Change-Id: Ifcd690411770ab266c12a01bb0993f92b0f18bc6
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
2016-05-31 15:26:33 -07:00
Asutosh Das
444223d884 mmc: block: Add error handling to command queue host
On error, the CMDQ engine stops processing requests. It is then
halted and error handled.
The error have been categorized as below:
1. Command error
	a. time-out
		- invalidate all pending tags & requeue
		- reset both card & controller
	b. crc
		- end the error mrq
		- tune
		- unhalt
2. Data error
	a. time-out
		- invalidate all pending tags & requeue
		- reset both card and controller
	b. crc
		- end the error mrq
		- tune
		- unhalt
3. RED error
	This is device specific error and is not recoverable.
	The card and controller are reset in this case and all
	pending tags are invalidated and requeued.

Change-Id: I791d05f6b31d8f9b35a56fe85007b320c14e8b46
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:32 -07:00
Asutosh Das
44a464b93c mmc: core: Add halt support
Halt is a controller feature that can change the controller mode
from command-queue to legacy. This feature is very helpful in
error cases.

Change-Id: I7f1465b609afed68886256bd605d4019716964f4
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
2016-05-31 15:26:29 -07:00
Venkat Gopalakrishnan
c811ac5993 mmc: cmdq: support for command queue enabled host
This patch adds CMDQ support for command-queue compatible
hosts.

Command queue is added in eMMC-5.1 specification. This
enables the controller to process upto 32 requests at
a time.

Change-Id: I0486495ef57c64bf8427e917daeb184c69b8dc73
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:28 -07:00
Asutosh Das
89ada7fc6d mmc: core: add flush request support to command queue
Adds flush request support to command-queue. This uses DCMD
feature of the controller for sending commands in
command-queue mode. DCMD is a direct command feature that uses
a pre-configured slot for sending commands other than Class 11.

Change-Id: Iebf6b74173dc91b0dc7230d1e87c65983d15148e
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:28 -07:00
Venkat Gopalakrishnan
fc4b531dfd mmc: card: add read/write support in command queue mode
Command queueing is defined in eMMC-5.1. It is designed for
higher performance by ensuring upto 32 requests to be serviced
at a time.

Adds read/write support for CMDQ enabled devices.

Change-Id: I136ddea8e5ca57eb4f85ca6e72c60001a7e24f78
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:27 -07:00
Asutosh Das
ee66ddaa07 mmc: core: Add command queue initialzation support
Command Queueing (CQ) feature is introduced to eMMC
standard in revision 5.1. CQ includes new commands
for issuing tasks to the device, for ordering the
execution of previously issued tasks and for
additional task management functions.

This patch adds initialization and enabling of command
queue in the card and controller. If the card and the
controller support CQ, then it is enabled.

Change-Id: I92d893d1503396d4b00848813cc546fc263e77fd
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:27 -07:00
Asutosh Das
6d1be7e42b mmc: queue: initialization of command queue
Command Queueing (CQ) feature is introduced to eMMC
standard in revision 5.1. CQ includes new commands
for issuing tasks to the device, for ordering the
execution of previously issued tasks and for
additional task management functions.

The idea is to keep the legacy and CQ code as discrete
as possible. Hence, a separate queue is created for CQ.
The issuing path is non-blocking since several requests
(max. 32) can be queued at a time.

Change-Id: I5b48d1b3ed17585b907ec70ff7c8d583003ec9e1
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts & compilation
error]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:26 -07:00
Talel Shenhar
ae479fa29f mmc: core: devfreq: migrate to devfreq based clock scaling
This change adds the use of devfreq to MMC.
Both eMMC and SD card will use it.
For some workloads, such as video playback, it isn't
necessary for these cards to run at high speed.
Running at lower frequency, for example 52MHz, in such
cases can still meet the deadlines for data transfers.
Scaling down the clock frequency dynamically has power
savings not only because the bus is running at lower frequency
but also has an advantage of scaling down the system core
voltage, if supported.
Provide an ondemand clock scaling support similar to the
cpufreq ondemand governor having two thresholds,
up_threshold and down_threshold to decide whether to
increase the frequency or scale it down respectively.
The sampling interval is in the order of milliseconds.
If sampling interval is too low, frequent switching of
frequencies can lead to high power consumption and if
sampling interval is too high, the clock scaling logic
would take long time to realize that the underlying
hardware (controller and card) is busy and scale up
the clocks.

Change-Id: I58ddbd93648ded82b304411956e035fb353cd97e
Signed-off-by: Talel Shenhar <tatias@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts & compilation
errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:23 -07:00
Dov Levenglick
ed9551c160 mmc: add support for scheduling mmcqd on idle CPU
In order to boost mmc performance on various platforms,
add support for configuring whether set_wake_up_idle()
should be called on the mmc queue thread (mmcqd).
The decision will be set in each individual platform's
dts file.

CRs-Fixed: 787554
Change-Id: I3989d3f5b8228785e6d3bc49c7eb01ebf2fa2f38
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:22 -07:00
Venkat Gopalakrishnan
58821ee5f6 mmc: core: Add workaround for hosts that need addtional tuning for HS400
Add a capability to identify hosts that need additional tuning for HS400
and perform a post tuning process that maybe needed for proper HS400
functionality.

Change-Id: I3895aabddce4dbecb208e3c522957e656f37e30d
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:26:02 -07:00
Sujit Reddy Thumma
3332d5a9e4 mmc: core: Fix clock frequency transitions during invalid states
eMMC and SD card specifications restrict the usage of a class of
commands while commands in other class are in progress. For example,
during erase operations the SD/eMMC spec. allows only CMD35, CMD36,
CMD38. If clock scaling is enabled and decide to scale up the clocks
it may be possible that CMD19/21 tuning commands are sent in between
erase commands, which is illegal as per specification.

Fix such illegal transactions to the card and also make clock scaling
statistics accountable only for read/write commands instead of time
consuming commands, like CMD38 erase, where transactions are independent
of bus frequency.

Change-Id: Iffba175787837e7f95bde8970f19d0f0f9d7d67d
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[merez@codeaurora.org: fix conflicts as mmc_update_clk_scaling is missing on 3.14]
Signed-off-by: Maya Erez <merez@codeaurora.org>
2016-05-31 15:25:58 -07:00
Asutosh Das
3c0c23354a mmc: core: add wakeup functionality to sdio cards
This patch initializes wakeup source if the detected card
is a sdio card and enables the wakeup capability.

Platform drivers would have to invoke:
 * pm_wakeup_event on this card device to signal a wakeup
 * corresponding pm_relax have to be invoked

Change-Id: Ic8d5c98073e8ed3f676eb42fc0ce1f13a11cb40f
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
[merez@codeaurora.org: fix conflicts due to different PM in 3.14]
Signed-off-by: Maya Erez <merez@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:51 -07:00
Subhash Jadavani
83d95c50fb mmc: sdio: enable asynchronous interrupt support in 4-bit mode
SDIO 3.0 specification has added the support for asynchronous interrupt
period during which card allows the clock to be gated off. Host needs
to first read the "Support Asynchronous Interrupt" bit in CCCR register
space to check if the card supports the feature or not. If yes and if
the host wants to enable the feature, host needs to write '1' to
"Enable Asynchronous Interrupt" bit in CCCR register space.

This change allows the host controller driver to control whether to enable
the asynchronous interrupt in card or not and if the asynchronous interrupt
is enabled then clock gating feature would be enabled for such cards.

Change-Id: I678cffb63af6a2013640a5eafa6ce9bfad8a51d6
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[merez@codeaurora.org: fix CAPS2 index]
Signed-off-by: Maya Erez <merez@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:48 -07:00
Sujit Reddy Thumma
2023cd8d36 mmc: core: Add support for notifying host driver while scaling clocks
Host drivers can participate in clock scaling by registering
->notify_load host operation, which allows host driver to carry out
platform specific operations for further power savings or increasing
throughput based on whether load is LOW or HIGH respectively. This
can be applicable to non-ultra high speed cards as well so remove
the check for ultra high speed cards to initialize clock scaling.

Change-Id: Icaab9520135e384f5470db68b2f25c5cdce5663a
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[merez:codeaurora@org: fix conflicts due to removal of stop transmission]
Signed-off-by: Maya Erez <merez@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:48 -07:00
Sujit Reddy Thumma
b4b98fb480 mmc: core: Log MMC clock frequency transitions
Use kernel's ftrace support to capture MMC clock frequency
transitions which can be useful for debugging issues related
to power consumption.

Usage:
mount -t debugfs none /sys/kernel/debug
echo 1 > /sys/kernel/debug/tracing/events/mmc/mmc_clk/enable
cat /sys/kernel/debug/tracing/trace_pipe

Change-Id: I25c4ee39dcbe30e7665902a9f723a5a421b55ca3
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
2016-05-31 15:25:47 -07:00
Sujit Reddy Thumma
baf82d92c5 mmc: core: Add load based clock scaling support
The SD3.0/eMMC4.5/SDIO3.0 cards can support clock rates upto
200MHz (SDR104 or HS200 bus speed modes). For some workloads
like video playback it isn't necessary for these cards to run
at such high speed. Running at lower frequency, say 50MHz, in
such cases can still meet the deadlines for data transfers.
Scaling down the clock frequency dynamically has huge power
savings not only because the bus is running at lower frequency
but also has an advantage of scaling down the system core
voltage, if supported.

Provide an ondemand clock scaling support similar to cpufreq
ondemand governor having two thresholds, up_threshold and
down_threshold to decide whether to increase the frequency or
scale it down respectively. The sampling interval is in the
order of milliseconds and should be chosen by host drivers that
enable MMC_CAP2_CLK_SCALE capability to take advantage of clock
scaling. The sampling interval mainly depends on the the clock
switching delays and hence a host driver decision. If sampling
interval is too low frequent switching of frequencies can lead
to high power consumption and if sampling interval is too high,
the clock scaling logic would take long time to realize that the
underlying hardware (controller and card) is busy and scale up
the clocks.

Change-Id: I22a5054beec41b0b66b3bf030ddfcf284de448b3
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[merez@codeaurora.org: fixed conflicts due to changes in 3.14]
Signed-off-by: Maya Erez <merez@codeaurora.org>
[venkatg@codeaurora.org: runtime pm related changes to
accommodate pm framework from 3.14 kernel]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed merge conflicts and fixed compilation
errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:39 -07:00
Tatyana Brokhman
86dc987a4f mmc: block: Add write packing control
The write packing control will ensure that read requests latency is
not increased due to long write packed commands.

The trigger for enabling the write packing is managing to pack several
write requests. The number of potential packed requests that will trigger
the packing can be configured via sysfs by writing the required value to:
/sys/block/<block_dev_name>/num_wr_reqs_to_start_packing.
The trigger for disabling the write packing is fetching a read request.

Change-Id: I22e8ab04cd9aca220678784c39306068a0996790
Signed-off-by: Maya Erez <merez@codeaurora.org>
Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org>
[merez@codeaurora.org: fixed trivial conflicts]
Signed-off-by: Maya Erez <merez@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:34 -07:00
Subhash Jadavani
357f7f515e mmc: host: remove mmcq performance numbers statistics
mmcq performance numbers are not captured since asynchronous
MMC request support got added in MMC block driver. So printing
out these numbers (which are all zeros) just adds confusion.
This patch removes the printing of mmcq performance numbers
statistics.

CRs-Fixed: 364206
Change-Id: I7213b11c8e9e055894c9902af7e975de3be1c519
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:32 -07:00
Subhash Jadavani
9a09218381 mmc: core: capture performance numbers only when asked
Currently performance numbers are captured for each SDCC
transfers unconditionally which may add the overhead and
could reduce the SDCC read/write throughput numbers.

This change adds additional control for enabling/disabling the
capturing of performance numbers at runtime. We already have sysfs
entry named "perf" for msm sdcc devices. Currently setting this
entry to 0 clears the performance statistics. But now we are
changing the definition of this entry as mentioned below:

Disable performance capturing and clear the performance statistics:
	"echo 0 > /sys/devices/platform/msm_sdcc.<n>/perf"

Enable performance capturing:
	"echo 1 > /sys/devices/platform/msm_sdcc.<n>/perf"

CRs-fixed: 345170
Change-Id: I3ab9288fd87cc8a8ada6c0c3d066cac4f68d79b7
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:30 -07:00
Aparna Mallavarapu
0f618d04ba mmc: Add profiling code to measure performance at MMC layers.
Profiling code is added to measure read, write times for
the MMC requests at various MMC layers. Profiling is done
at the MMC queue and at the driver level. This information
can be viewed through a sysfs entry called perf.

Change-Id: I7c65bfe25a1f7774e3a9abf1f9539e690b3718ec
Signed-off-by: Aparna Mallavarapu <aparnam@codeaurora.org>
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflict]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:25:30 -07:00
Sujith Reddy Thumma
6b2e9c4ce0 mmc: core: Fix race between runtime PM suspend and block requests
There is a possible race with mmc_claim_host() in mmc_sd_suspend()/
mmc_suspend() and mmc_claim_host() in mmc_blk_issue_rq() when runtime
pm is enabled. Fix this by blocking processing of requests until the
previous runtime suspend is processed and then resume as part of
msmsdcc_enable(). Previous fix has card detection failure as a side effect
during resume.

Change-Id: I9cb31269638d9db4e630eb22b973a5335af1bda4
Signed-off-by: Sujith Reddy Thumma <sthumma@codeaurora.org>
[sboyd: Dropped msm driver change]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
[subhashj@codeaurora.org: fixed trivial merge conflict]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:20:51 -07:00
Sahitya Tummala
40c3ea6a0c mmc: core: Fix MMC clock scaling in case of tuning failure
When the clock scaling state is changed from MMC_LOAD_LOW to
MMC_LOAD_HIGH, the clocks are first scaled up and then tuning
is performed. But in case of tuning failure, the current code
does nothing but still retain the previous clock scale stats
(state and curr_freq within struct clk_scaling). Hence, correct
it to scale down the clocks in case of tuning failure so that
clock scaling stats reflect the correct status. This also helps
proceed with data transfers at lower clock rate in such cases.

Change-Id: I7e9379d1e3ddc863132af31019604c22a42f8d59
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
[subhashj@codeaurora.org: fixed compilation error]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-31 15:20:50 -07:00
Subhash Jadavani
03dbfc78cf mmc: core: export mmc_host_may_gate_card function
MMC Host driver might want to use the mmc_host_may_gate_card() API
to know whether the clock can be gated to the card or not hence
export this function for usage outside its current scope.

Change-Id: I9ec4173063e2505eca179161cdf8cda033a3fd4b
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[merez@codeaurora.org: fix trivial conflicts]
Signed-off-by: Maya Erez <merez@codeaurora.org>
2016-05-31 15:20:48 -07:00
Guoping Yu
eef1739c44 mmc: sdhci: add support nonhotplug
With some devices, SD card could not support hotplug as there is
no cd-gpio, and also could not use polling way due to power
comsumption. So add nonhotplug to meet such requirement and when
SD card lost or removed manually, device will not crash until
next reboot process to detect SD card.

Change-Id: Ie8ea8ec57015f36689a119249003eeaa48391393
Signed-off-by: Guoping Yu <guopingy@codeaurora.org>
[subhashj@codeaurora.org: fixed minor merge conflict]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-27 10:29:11 -07:00
Sahitya Tummala
c2037aa944 mmc: sdhci-msm: Fix issue with 1.8v switch sequence in 3.10 kernel
The SD3.0 voltage switch sequence to 1.8v would involve stopping the
SDCLK before changing the voltage level and with recent changes in 3.10
kernel, the peripheral clocks are also getting disabled instead of
just stopping the clock to the card. This patch makes sure this doesn't
happen by marking the flag card_clock_off in struct mmc_host before
starting the voltage switch sequence and checking it in host controller
driver.

Change-Id: If62378ba1dd369e69524365a4421d57317c22ca2
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
2016-05-27 10:28:53 -07:00
Sujit Reddy Thumma
0c196acfcb mmc: sdhci: Defer release of CPU DMA PM QoS vote in high load cases
PM QoS vote of default value mean that the CPU is allowed to move
into deepest low power mode whenever possible. Currently, if there
are back-to-back MMC requests, with a short delay, the PM QoS vote
to default value is done immediately which cause the immediate
request to have high latency as the CPU might have idle'd and moved
to deepest low power mode. To avoid this defer the PM QoS vote till
a defined timeout (pm_qos_timeout_us), so that back-to-back requests
may not suffer from additional latencies.

In addition, if the load on MMC is low, the additional latency may be
sustainable. Hence, aggressively release the vote in order to achieve
additional power savings.

CRs-Fixed: 501712
Change-Id: I82166b0ce9416eb0d519f7da26e5a96956093cb2
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[subhashj@codeaurora.org: fixed minor merge conflict and fixed
compilation errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-27 10:28:44 -07:00
Subhash Jadavani
9df78479e4 Revert "mmc: core: Remove the ->enable|disable() callbacks"
This reverts commit 4043326733 as
MSM platforms still needs ->enable/disable() callbacks.

Conflicts:
	drivers/mmc/core/core.c

Change-Id: Ifd986825c10f1475bfcdac37ea1f3b99e5f6daaf
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-27 10:28:27 -07:00
Subhash Jadavani
7cc9ec9f2a Revert "mmc: core: Remove MMC_CLKGATE"
This reverts commit 9eadcc0581.

Clock gating is needed for Qualcomm Platforms hence reverting this
upstream patch.

Change-Id: I96ac0c1c7627e8e5c2d18782e2fc08608f0a7f91
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
2016-05-19 18:35:30 -07:00
San Mehat
707392fd2c mmc: Add concept of an 'embedded' SDIO device.
This is required to support chips which use SDIO for signaling/
communication but do not implement the various card enumeration registers
as required for full SD / SDIO cards.

mmc: sdio: Fix bug where we're freeing the CIS tables we never allocated when using EMBEDDED_SDIO
mmc: Add max_blksize to embedded SDIO data

Change-Id: Ibff2e3e991e5522f55ec8c6edc25ed09f2553736
Signed-off-by: San Mehat <san@google.com>
2016-02-16 13:51:04 -08:00
Douglas Anderson
2086f801cb mmc: core: Add mmc_regulator_set_vqmmc()
This adds logic to the MMC core to set VQMMC.  This is expected to be
called by MMC drivers like dw_mmc as part of (or instead of) their
start_signal_voltage_switch() callback.

A few notes:

* When setting the signal voltage to 3.3V we do our best to make VQMMC
  and VMMC match.  It's been reported that this makes some old cards
  happy since they were tested back in the day before UHS when VQMMC
  and VMMC were provided by the same regulator.  A nice side effect of
  this is that we don't end up on the hairy edge of VQMMC (2.7V),
  which some EEs claim is a little too close to the minimum for
  comfort.
  This is done in two steps. At first we try to find a VQMMC within
  a 0.3V tolerance of VMMC and if this is not supported by the
  supplying regulator we try to find a suitable voltage within the
  whole 2.7V-3.6V area of the spec.

* The two step approach is currently necessary, as the used
  regulator_set_voltage_triplet(min, target, max) uses a simple
  implementation that just tries two basic steps:
	regulator_set_voltage(target, max);
	regulator_set_voltage(min, target);
  So with only one step with 2.7-3.6V borders, if a suitable voltage
  is a bit below VMMC, we would directly get the lowest 2.7V
  which some boards (like Rockchips) don't like at all.

* When setting the signal voltage to 1.8V or 1.2V we aim for that
  specific voltage instead of picking the lowest one in the range.

* We very purposely don't print errors in mmc_regulator_set_vqmmc().
  There are cases where the MMC core will try several different
  voltages and we don't want to pollute the logs.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-10-26 16:00:10 +01:00
Ulf Hansson
9eadcc0581 mmc: core: Remove MMC_CLKGATE
MMC_CLKGATE was once invented to save power by gating the bus clock at
request inactivity. At that time it served its purpose. The modern way to
deal with power saving for these scenarios, is by using runtime PM.

Nowadays, several host drivers have deployed runtime PM, but for those
that haven't and which still cares power saving at request inactivity,
it's certainly time to deploy runtime PM as it has been around for several
years now.

To simplify code to mmc core and thus decrease maintenance efforts, this
patch removes all code related to MMC_CLKGATE.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2015-10-26 16:00:09 +01:00
Yangbo Lu
f13e5b9f3c mmc: sdio: avoid using NULL sdio_irq_thread pointer
For Freescale QorIQ LS1021AQDS board, there is a SDIO interrupt
in the process of resume without inserting SD adapter because of
some unknown issue. But the driver doesn't assign sdio_irq_thread
pointer. This will block the resume of kernel. This patch is used
to avoid using NULL sdio_irq_thread pointer.

Signed-off-by: Yangbo Lu <yangbo.lu@freescale.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-08-17 11:32:46 +02:00
Adrian Hunter
f168359efb mmc: core: Add 'card' to drive strength selection callback
In preparation for supporting also eMMC drive strength,
add the 'card' as a parameter so that the callback can
distinguish different types of cards if necessary.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-06-01 09:07:12 +02:00
Adrian Hunter
b4f30a174e mmc: core: Allow card drive strength to be different to host
Initialization of UHS-I modes for SD and SDIO cards
employs a callback to allow the host driver to
choose a drive strength value. Currently that
assumes the card drive strength and host driver
type must be the same value. Change to let the
callback make that decision and return both the
card drive strength and host driver type.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-06-01 09:07:11 +02:00
Lars-Peter Clausen
9f6e0bff2a mmc: Add support for disabling write-protect detection
It is not uncommon to see systems where there is no physical write-protect
signal (e.g. when using eMMC or microSD card slots). For some controllers,
which have a dedicated write-protection detection logic (like SDHCI
controllers), the get_ro() callback can return bogus data in such a case.

Instead of handling this on a per controller basis this patch adds a new
capability flag to the MMC core that can be set to specify that the result
of get_ro() is invalid. When the flag is set the core will not call
get_ro() and assume that the card is always read-write.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-06-01 09:06:59 +02:00
Adrian Hunter
dfa13ebbe3 mmc: host: Add facility to support re-tuning
Currently, there is core support for tuning during
initialization. There can also be a need to re-tune
periodically (e.g. sdhci) or to re-tune after the
host controller is powered off (e.g. after PM
runtime suspend / resume) or to re-tune in response
to CRC errors.

The main requirements for re-tuning are:
  - ability to enable / disable re-tuning
  - ability to flag that re-tuning is needed
  - ability to re-tune before any request
  - ability to hold off re-tuning if the card is busy
  - ability to hold off re-tuning if re-tuning is in
  progress
  - ability to run a re-tuning timer

To support those requirements 7 members are added to struct
mmc_host:

  unsigned int		can_retune:1;	/* re-tuning can be used */
  unsigned int		doing_retune:1;	/* re-tuning in progress */
  unsigned int		retune_now:1;   /* do re-tuning at next req */
  int			need_retune;	/* re-tuning is needed */
  int			hold_retune;	/* hold off re-tuning */
  unsigned int		retune_period;  /* re-tuning period in secs */
  struct timer_list	retune_timer;	/* for periodic re-tuning */

need_retune is an integer so it can be set without needing
synchronization. hold_retune is a integer to allow nesting.

Various simple functions are provided to set / clear those
variables.

Subsequent patches take those functions into use.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-06-01 09:06:53 +02:00
NeilBrown
4043326733 mmc: core: Remove the ->enable|disable() callbacks
These callbacks have been set to deprecated for some time. The last
user (omap_hsmmc) has moved away from using them, which thus enables
us to completely remove them.

Signed-off-by: NeilBrown <neil@brown.name>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-03-27 10:57:55 +01:00
Ulf Hansson
3aa8793f75 mmc: core: Initial support for MMC power sequences
System on chip designs may specify a specific MMC power sequence. To
successfully detect an (e)MMC/SD/SDIO card, that power sequence must
be followed while initializing the card.

To be able to handle these SOC specific power sequences, let's add a
MMC power sequence interface. It provides the following functions to
help the mmc core to deal with these power sequences.

mmc_pwrseq_alloc() - Invoked from mmc_of_parse(), to initialize data.
mmc_pwrseq_pre_power_on()- Invoked in the beginning of mmc_power_up().
mmc_pwrseq_post_power_on()- Invoked at the end in mmc_power_up().
mmc_pwrseq_power_off()- Invoked from mmc_power_off().
mmc_pwrseq_free() - Invoked from mmc_free_host(), to free data.

Each MMC power sequence provider will be responsible to implement a set
of callbacks. These callbacks mirrors the functions above.

This patch adds the skeleton, following patches will extend the core of
the MMC power sequence and add support for a specific simple MMC power
sequence.

Do note, since the mmc_pwrseq_alloc() is invoked from mmc_of_parse(),
host drivers needs to make use of this API to enable the support for
MMC power sequences. Moreover the MMC power sequence support depends on
CONFIG_OF.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Reviewed-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
2015-01-28 12:31:12 +01:00
Ulf Hansson
df8aca162e mmc: slot-gpio: Rework how to handle allocation of slot-gpio data
By moving the allocation of the slot-gpio data into mmc_alloc_host(),
we can remove the slot-gpio internal calls to mmc_gpio_alloc().

This means mmc_gpio_alloc() has now only one caller left, which
consequence allow us to simplify and remove some of the slot-gpio code.

Additionally, this makes the slot-gpio mutex redundant, so let's remove
it.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-01-19 09:56:18 +01:00
Adrian Hunter
549c0b1848 mmc: sdhci: Clear also HS400 1.2V capability if 1.2V is not supported
1.2V HS200 mode capability is cleared if there is not a voltage
regulator that supports 1.2V.  Do the same for 1.2V HS400 mode.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2014-11-26 14:30:51 +01:00
Roger Tseng
8af465db96 mmc: core: Add new power_mode MMC_POWER_UNDEFINED
Add MMC_POWER_UNDEFINED for power_mode in struct mmc_ios and use it as
the initial value of host->ios.power_mode.

For hosts with MMC_CAP2_NO_PRESCAN_POWERUP, this makes the later
mmc_power_off() do real power-off things instead of NOP, and further
prevents state messed up in cards that was already initialized (eg. by
BIOS of UEFI driver).

Signed-off-by: Roger Tseng <rogerable@realtek.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2014-09-24 11:20:04 +02:00