[PATCH] Staging: android: binder: More offset validation.

Make sure offsets don't point to overlapping flat_binder_object
structs.

Change-Id: I425ab0c46fbe2b00ed679c5becf9e8140395eb40
Signed-off-by: Arve HjÃ¸nnevÃ¥g <arve@android.com>
[PATCH] netlink: add signed types

Signed types might be needed in NL communication from time to time
(I need s32 in team driver), so add them.

Change-Id: Icc6c8286a1d55313fcc7993d8b02267fe1ef2bdc
CRs-Fixed: 677858
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
USB: msm_otg: Fix race between PM resume and charger detection

When device is in system suspend and USB charger is disconnected,
then due to VBUS clear IRQ from PMIC, the device will be PM resumed.
Now shortly if PMIC driver detects valid VBUS it will handle VBUS
set condition,notifies to msm_otg and msm_otg will kick in charger
detection mechanism. During PM resume, in dmp_complete() it will
call a pm_runtime_put_sync(), which will immediately kick off the
PM runtime idle and suspend routines.
dpm_complete()
  ->device_complete()
    ->pm_runtime_put_sync()
      ->rpm_idle()
        ->rpm_suspend()

The PM resume also runs in a separate worker queue, so it is not
guaranteed that it will finish executing before we finish the charger
detection stage. During this case there is a race if dpm_complete()
returns before charger detection starts. Return of dmp_cpmplete()
before charger detection will make USB to enter LPM. As USB will be
in LPM now and if charger detection starts then it will lead to
unclocked access.

Fixing the issue by handling the pm usage count using the variable
pm_done in msm_otg. When USB charger is disconnected and msm_otg
processes the disconnect event it marks the pm_done to true. Later
when USB charger is connected , mark the pm_done to false in
msm_otg_runtime_resume(). If pm_done is true increment the pm counter
using pm_runtime_get_sync. This handles the race case when PM resume
thread returns before the charger detection starts.

CRs-Fixed: 599143
Change-Id: I6de19fe850e24efa03ea71c7d14e388c15cf2f97
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: Clear pm_done flag to false in msm_otg_sm_work

As part of USB disconnect event, msm_otg_suspend() executes and USB
enters into low power mode and pm_done flag is set to true. In the
scenario in which before the msm_otg_suspend() finished executing,
then USB connect event came in, in this case msm_otg_suspend() returns
-EBUSY. And later USB connect event is processed. As device is already
in resumed state, hence pm_done flag is never set to false. So on
next USB connect pm usage counter gets incremented in msm_otg_sm_work()
and device cannot enter into sleep state.

Fix the issue by clearing pm_done flag to false as part of usb connect
in msm_otg_sm_work().

CRs-fixed: 649434
Change-Id: Ibc36221b2f8b781322fa741b1b6639dd813c0810
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: msm_otg: Process HOST disconnect only after system RESUME

If Host Cable (ID_GND) is disconnected in system suspend then
it results in race between device removal and device pm_resume.
PM core does't handle this correctly and sometimes frees up
parent device before children are resumed. To avoid this race
make sure that system has resumed completely before handling
ID_FLOAT (or host cable disconnect) event.

CRs-fixed: 652870, 651561
Change-Id: Id0956a9677d819d3fa3f17f54965cae38f2ee31d
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: msm_otg: Print warning message when not able to turn USB CLKs

This change prints warning message failures with call stack when
not able to turn ON USB core_clk and pclk in msm_otg_resume() and
msm_otg_link_clk_reset()

CRs-Fixed: 612896
Change-Id: I9f53751b9ff0254205231656e01ed84302067bef
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: Set power supply online status to false after cable disconnect

During bootup, power supply online status is set to true in
qpnp_charger_probe() as soon as usb cable insert is detected by
PMIC without waiting for notification from USB driver.
Later when usb cable is disconnected before charger detection
mechanism starts, online status is not set to false by USB.
As part of cable disconnect, USB checks in msm_otg_notify_charger()
whether the cur_power is same as requested mA, if both are same
then USB does not call power_supply_set_online() to set it to false.

Fix the issue by setting power supply online status to false for
the scenario when usb cable is disconected during bootup before
charger detection mechanism is completed.

CRs-fixed: 634183
Change-Id: Ibd57a40c7364e13bb10870e9e6343224e01171d7
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: Fix bug in ext_chg_active flag handling

The ext_chg_active flag is set to true when the external charger
processing is pending. It is set to true when DCP is detected and
set to false when the user space notifies that it is done with
the charger detection. The user space may unblock the low power mode
any time to access the hardware to request a new voltage setting.
The current code does not set ext_chg_active flag in this case due to
which USB enters low power mode while external charger processing
is pending. This results in unclocked register access.
Fix the issue by setting ext_chg_active to true every time the
userspace calls the block LPM.

CRs-Fixed: 663301
Change-Id: If18f762d7fc0b4eaba297e27bbd7382b161fbcde
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
usb: msm_otg: Fix timeout during usb disconnect with hvdcp charger

Once DCP is detected, ext_chg_active is set to true and DCP uevent
reached to user space. The hvdcp main thread mark dcp_connected to
true and wakesup the detector thread to do hvdcp detection. But before
the detector thread gets a chance to run, DCP is removed. The disconnect
uevent reached the user space and the hvdcp main thread marks the
dcp_connected to false and it will not call any ioctl call. As
ext_chg_active is still set to true, it is waiting for 3 seconds while
processing usb disconnect.

Also it is possible that DCP uevent is reached to the user space much
before ext_chg_active flag is set to true in otg state machine work which
later leads to timeout of 3 seconds later while processing usb disconnect.

Fix these issues by maintaining different states for ext_chg_active. Upon
DCP disconnect, if the ext_chg_active value is still default, mark it to
inactive. This avoid the 3 seconds wait timeout while processing the usb
disconnect.

CRs-Fixed: 671181
Change-Id: Ic4aa6745e994a007bd6bd2e75d4f44fb8f7ac9c1
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: phy-msm-usb: Disable charger detection block on DISCONNECT

VBUS LOW (or DISCONNECT) may happen any time during charger detection
phase. If it happens before charger detection is complete then there
is a possibility of leaving IDP_SRC or VDP_SRC enabled which can
affect charger detection on next cable connect.

Change-Id: Ifde35112aeae294b1979255b9757d5e4fc62c8b0
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: ChandanaKishori Chiluveru <cchilu@codeaurora.org>
USB: msm_otg: Implement VOLTAGE_NOW property for usb power supply

Implement VOLTAGE_NOW property for power supply so that usb_in
value can be read at any time through this sysfs entry by
userspace.

To read usb_in value,
	cat /sys/class/power_supply/usb/voltage_now

CRs-Fixed: 599547
Change-Id: I8f9bf4077282fbe32304b667793dab8009e68243
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
usb: msm_otg: Fix bug with hvdcp connect and disconnect processing

The HVDCP charger is detected as a DCP charger by the USB driver. When a
DCP is detected, ext_chg_active flag is set to true and low power mode is
deferred by 3 seconds. When the user space receives the DCP connect uevent,
it kicks the charger detection algorithm. The charger detection procedure
involves reading and writing to the USB hardware registers and it makes an
ioctl call to block the low power mode by incrementing the pmruntime usage
counter. The user space calls the ioctl to unblock low power mode once
hvdcp detection is done by decrementing the pmruntime usage counter .

Consider the scenario where DCP detection is done and userspace makes
ioctl call to block low power mode. Next usb cable is disconnected and then
userspace makes ioctl call to unblock the low power mode by decrementing
the pmruntime usage counter. Due to this runtime suspend gets called and
USB clocks are turned off which later leads to unclocked access in
disconnnect processing. As part of USB disconnect, phy reset is done which
also involves ulpi register access. As clocks are turned off, it leads to
crash.

Fix the issue by making sure otg_sm work for usb disconnect is processed
first followed by decrementing the pmruntime usage counter in the ioctl
call made by userspace for unblocking the low power mode.

CRs-Fixed: 668648
Change-Id: I91db5f2e1084ae8f65dd8ec51c4314acc764c9c5
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: msm_otg: Add support for new ioctl for voltage request

Add support for new ioctls for userspace to let kernel driver
know about new voltage request being negogiated and also result
whether the request is successful or not, when HVDCP charger is
connected.

Change-Id: Ie7271cc2dea082ceb33d67f0b4d2959ed977b618
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3-msm: Add support for new ioctl for voltage request

Add support for new ioctls for userspace to let kernel driver
know about new voltage request being negogiated and also result
whether the request is successful or not, when HVDCP charger is
connected.

Change-Id: I9f36949fc7888274171aa1724da45a11704b7fec
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: msm: Add support for MSM_USB_EXT_CHG_TYPE ioctl

Add support for MSM_USB_EXT_CHG_TYPE ioctl in driver for userspace to
notify kernel whether charger connected is external charger or not.

CRs-Fixed: 652965
Change-Id: I13095b4183efe3cfc690b7a9cb4f3c2d3cb4ee73
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3: otg: Fix stop endpoint command timeout issue

Currently HSPHY SUSP bit is set while starting host mode and
it is not cleared till stopping host mode. As part of urb dequeue,
xhci stack will queue stop endpoint command for flushing endpoint
which is getting timedout due to this HSPHY SUSP bit. Hence clear
this bit before queuing stop endpoint command and set it back after
stop endpoint command completion. Otherwise xhci stack treats this
timeout as fatal error and halts host controller.

Crs-Fixed: 580268
Change-Id: I784407386e6f87bcabd8569fcbae4e3af167144d
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
usb: dwc3_otg: Turn on VBUS before starting host

Currently the VBUS regulator is enabled only after initializing
the xHCI host stack, which can result in enumeration failures
for certain devices. This is likely due to VBUS having a
finite rise time when it is turned on, especially when a load
is already attached. Mitigate this by enabling VBUS first before
starting the host stack.

CRs-Fixed: 599498
Change-Id: I9785ae4682d0a2dfbcec921b869fc03550e0db82
Signed-off-by: Jack Pham <jackp@codeaurora.org>
msm: msm-krait-l2-accessors: Add RTB logging

Accesses to indirect CP15 registers are important system events that
are worth recording in the RTB logs. The logs may aid in debugging
issues seen following operations that use these APIs, like CPU clock
source selection changes.

Change-Id: Ibc98ba2d58ab809a9e22bab4b6fcadd1e00e5f70
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
ARM: gic: Add support for logging interrupts in RTB

To help with the debug of interrupt storms and problems during IRQ
handling, log the IRQ number in RTB for each interrupt that fires.

Change-Id: I479f8cc032b269f3d43d939419e346528d4f909e
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
ARM: gic: Use _no_log variants while accessing some registers

Some GIC register accesses happens more frequently flooding the
RTB logs. Since they're not that useful for debugging purposes,
use _no_log variants while accessing those registers.

Change-Id: Idfb48c668eb90a3187fa3afdd7df5cd64062559d
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>