msm: kgsl: Do not return invalid power stats when the device is off

adreno_power_stats() was returning unitialized data when the device
state was not active. Leave early from the function if the device
is not active and return 0s instead.

Change-Id: Ic0dedbadf6201cadb4472327c4ce7f9d9d32b82d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Prabhat Awasthi <pawasthi@codeaurora.org>
msm: wlan: db.txt: enable mid 5GHz channels of WORLD reg domain

Patch enables the mid 5GHz channels for passive scanning on
WORLD regulatory domain.

Change-Id: I0e5b2a04afaa39b94a05e072ec1979e7d9ca0d14
CRs-Fixed: 614247
Signed-off-by: Manjunathappa Prakash <prakashpm@codeaurora.org>
mmc: queue: do not clean current request when urgent in progress

As a result of following fix: "mmc: core: do not reinsert prepeared
FUA and FLUSH requests in stop flow" REQ_FUA and REQ_FLUSH requests
are not reinserted back into i/o scheduler, but instead started request
execution.

This change will prevent cleaning current request pointer for such
requests.

Change-Id: I25f8706954fb538be62182c87d5fb20354696b7a
CRs-fixed: 600127
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>

Conflicts:
	drivers/mmc/core/core.c
mmc: block: Fix an invalid use of req->cmd_flag in DISCARD operation

When handling a DISCARD operation, the MMC request data structure may be
freed in memory. Therefore, it can't be used to retrieve the cmd_flags
for checking if MMC_REQ_NOREINSERT_MASK is set:
(!(mq->mqrq_cur->req->cmd_flags & MMC_REQ_NOREINSERT_MASK)))).

To prevent the issue we should use the local variable of cmd_flags.

Change-Id: I3b25a0e734325355c50d4d5f5b38e9631ae41dd9
CRs-Fixed: 683957
Signed-off-by: Maya Erez <merez@codeaurora.org>
Signed-off-by: Konstantin Dorfman <kdorfman@codeaurora.org>
qseecom: Fix issue related to retrieving pipe for PFE

Incorrect  parameter is overwritten when reading information
related to what pipe is used for PFE feature.

Change-Id: I6747fa0b8b99d937475d3d12e2f9ed9a723f91bb
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
qseecom: Add support to handle multiple app load & unload

Media server is associated with multiple apps on TZ-side.
Unloading a single app for clean up is not enought. QSEECOM
needs to handle the app load & unload of multiple apps
associated with the client. During app_load & app_unload
along with app_id, app_name should also be checked. Besides,
keymaster will not be unloaded and app search execution
during app unload is optimized.

Change-Id: Ie92e97b9154851b713a8c3394b8ed10fdbdebd2f
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
mmc: block: check for NULL pointer before dereferencing

mmc block data can be NULL. Hence, check for NULL before
dereferencing md.

CRs-Fixed: 562259
Change-Id: I0182c216ec73347cdd2ea464f593839fffd242a9
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
mmc: core: add deferred resume support

This patch enables the deferred resume support which would
prevent initialization of the card each time the system resumes.
With this change, the resume process would only be initiated if
a request is received.

Following scenario can occur:
1. device runtime suspended, system suspend is triggered
   When resumed, the device would not be resumed until a
   request is received.
2. device is runtime active, system suspend is triggered
   When resumed, the device would be marked as BUS_NEEDS_RESUME
   and actual resume would happen, when a request is received.
   At this point, the device may also enter runtime-suspend or
   system suspend may also occur. In both the cases, since the
   device has not been resumed, it won't be suspended again.
   However, the platform device would be runtime suspended
   and resumed as before.
   It can so happen that the card is removed even before a
   request is received. In this case the device would be
   resumed and card would be removed from core layer and
   upper layers would be notified.
In case of SDIO cards, this change would not have any effect
since manual resume would be enabled for devices supporting
a block read/write commands.

CRs-Fixed: 561382
Change-Id: Id39befea109ee24864dfde0898395b972d0a1b3a
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
mmc: block: stop bkops during shutdown

[   42.885198] SysRq : Emergency Remount R/O
[   43.003988] mmc0: mmc_bus_shutdown: invoked ###
[   43.033289] mmc0: mmc_bus_shutdown: done ###
[   43.118486] mmc0: sdhci_request: sending cmd8 after bus shutdown !!!
[   43.147955] [<c0659ca4>] (sdhci_request+0x4c/0x260) from
				[<c063ee24>] (mmc_start_request+0x27c/0x2b0)
[   43.157152] [<c063ee24>] (mmc_start_request+0x27c/0x2b0) from
				[<c063eec4>] (mmc_wait_for_req+0x6c/0x13c)
[   43.166618] [<c063eec4>] (mmc_wait_for_req+0x6c/0x13c) from
				[<c0645ed4>] (mmc_send_cxd_data+0xe0/0x114)
[   43.175991] [<c0645ed4>] (mmc_send_cxd_data+0xe0/0x114) from
				[<c0645f24>] (mmc_send_ext_csd+0x1c/0x20)
[   43.185277] [<c0645f24>] (mmc_send_ext_csd+0x1c/0x20) from
				[<c063df28>] (mmc_read_bkops_status+0x98/0xdc)
[   43.194823] [<c063df28>] (mmc_read_bkops_status+0x98/0xdc) from
				[<c06417ac>] (mmc_start_bkops+0x168/0x324)
[   43.204461] [<c06417ac>] (mmc_start_bkops+0x168/0x324) from
				[<c01a9584>] (process_one_work+0x200/0x400)
[   43.213835] [<c01a9584>] (process_one_work+0x200/0x400) from
				[<c01a9934>] (worker_thread+0x184/0x2a4)
[   43.223039] [<c01a9934>] (worker_thread+0x184/0x2a4) from
				[<c01ae010>] (kthread+0x80/0x90)
[   43.231286] [<c01ae010>] (kthread+0x80/0x90) from
				[<c0106c4c>] (kernel_thread_exit+0x0/0x8)
[   45.648206] wcnss crash shutdown 0
[   45.650599] Rebooting in 5 seconds..

In the above log, it is seen that the bkops thread runs after
mmc_bus_shutdown is completed and sends CMD8. Hence, cancel
bkops work during shutdown to prevent sending commands after
mmc bus is shutdown.

CRs-fixed: 593813
Change-Id: I3e8e9eb228bd03603d04561eb478d60664f50aaa
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
mmc: queue: scale down the max_segs if memory allocation fails

In low memory conditions at runtime, allocation of max_segs may
fail. Retry with a scaled down max_segs until allocation succeeds.

CRs-fixed: 583267
Change-Id: I072724afa44854dacc58654e6329531c1bb11120
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
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

CRs-Fixed: 585481
Change-Id: Ic8d5c98073e8ed3f676eb42fc0ce1f13a11cb40f
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
mmc: core: Hold host resume status while card rescan is in progress

In case if a removable card is hot-plugged when the card and host
are runtime suspended then the mmc_rescan() tries to detect the card
status and removes the bus_ops. During card removal the Linux device
model calls pm_runtime_remove() of the corresponding "card" device,
which not only marks the device as suspended but also notifies the
parent so that it can be suspended if there are no children that are
holding resume. In case if the runtime suspend work of host is scheduled
before bus_ops are marked NULL in mmc_rescan(), the runtime suspend
of host fails with -ENOMEDIUM error. This error makes runtime PM framework
to permanently mark the host device in error and further runtime PM
operations are disallowed even when the card is re-inserted.

CRs-Fixed: 593475
Change-Id: Ie5e09f05ef26098c561b0c64b3954962d9d4c039
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
mmc: core : fix arbitrary read/write to user space

In the MMC card debug_fs the read and write handlers use the strlcat
and sscanf, without checking the pointer given.
Since the pointer is not checked it is possible to write
everywhere (ring 0 or 3).
In order to fix it, an access_ok function is being used to verify
the buffer's pointer supplied by user is valid.

CRs-fixed: 545716
Change-Id: Ia710b6af5a95974fc930ca902e8ff18afa4e17ba
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
mmc: core : fix arbitrary read/write to user space

In the MMC card debug_fs the read and write handlers use the strlcat
and sscanf, without checking the pointer given.
Since the pointer is not checked it is possible to write
everywhere (ring 0 or 3).
In order to fix it, an access_ok function is being used to verify
the buffer's pointer supplied by user is valid.

CRs-fixed: 545716

Change-Id: I13ca736337fefe29ff9b0df6a318e7d92240f8b2
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
mmc: quirks: enable clock gating for AR6004 card

This patch whitelists the AR6004 card for clock-gating.
The controller supports asynchronous interrupt functionality
which enables to receive interrupts from the card when clocks
are off. Hence, clocks can be turned off when idle.

This patch whitelists the card, to let the clock-gating
framework gate the clock during idle time.

CRs-Fixed: 585481
Change-Id: I651f86e42595cc82f99093c06ee220a1d0ec95a9
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
mmc: core: Issue with voltage switch sequence

When a broken UHS-I card is inserted, the voltage switch sequence
fails as expected but the controller is left in bad state due to
which software request timeouts are observed for further commands.
Add mmc_power_cycle() for any failure in voltage switch so it will
also help reset the controller in addition to card.

CRs-fixed: 608192
Change-Id: I332c0717b9310692799b9a4ba6570df67fcf3b6e
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
mmc: msm_sdcc: fix the clock selection logic in DDR mode

MSM SDCC controller requires the internal clock frequency to set be
doubled when running in DDR (Dual Data Rate) mode and existing
clock selection logic used to work fine until the MMC clock scaling
functionality got added. With clock scaling now, clock (ios->clock)
might get scaled down from 50MHz to 25MHz during DDR mode operation
and existing clock frequency selection logic may not change the clock
frequency when we move back from 25MHz to 50MHz.

This patch fixes the above issue and also simplifies the clock frequency
selection logic in DDR mode.

CRs-Fixed: 458926
Change-Id: I60f9ae2d5a7f92031fb46d9b16676c74363e7b9f
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
mmc: sdhci: add asynchronous interrupt support for sdio card

Some controllers can gate the clock to save power
even for SDIO cards. In such cases, an asynchronous
interrupt mechanism is used to receive interrupts
even when clocks are off.

This patch wakes up the sdio thread if interrupts
were received when clocks were off.

CRs-Fixed: 585481
Change-Id: Ifcfafad251dedc992637596b6bb9349cfbca5d8b
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
mmc: sdhci: add sdio wakeup event

This patch adds wakeup event capability for sdio cards.
When a wakeup event is received during suspend, a reference
to the card devices' wakeup source is taken for 300 ms.

It is expected that the function driver would act on the
wakeup event within this time-period.

CRs-Fixed: 585481
Change-Id: I80fe0c450e8d9b3df51aa181d667d94517c961dc
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>
mmc: sdhci: Use right API to read/write host control2 register

The SDHCI host control2 register offset is 0x3E which is not
word aligned and is only 16 bits wide. But we use readl/writel
to read/write to it. Use readw/writew to avoid any alignment
issues.

CRs-Fixed: 585481
Change-Id: Ibaa87ce46f2a2dd97f9e1c7979adb38e426acd5b
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Asutosh Das <asutoshd@codeaurora.org>