Revert "USB: ensure parent device is resumed for child's system-resume"

This reverts commit de86e6482897db0006151ae9154f181e75f5ab2c.

Commit 7c8527ce ("PM: Prevent runtime suspend during system resume")
fixes the general issue of a parent device being prematurely
runtime suspended before a child device is resumed. It does so
by moving the pm_runtime_put_sync() call from the device_resume()
stage to device_complete(), which happens to act on the devices
in reverse (children before parent) order.

Thus when usb_resume() is called by device_resume(), we know its
parent will be runtime PM enabled and its usage counter is still
non-zero. This obviates the need to do an additional
pm_runtime_get_sync() before calling usb_resume_both() as the
device and its interfaces now have the opportunity to increment
the parent's power.child_count if necessary without fear of
having a runtime suspended parent.

CRs-fixed: 396041
Change-Id: I793ddfbb9bd88634f45f0c1e570a5d616248e3a8
Signed-off-by: Jack Pham <jackp@codeaurora.org>
usb/core: disable 'usb_hnp_polling_work' function of AU_LINUX_ANDROID_ICS.04.00.04.00.126 (CAF)

The kernel doesn't compile with CONFIG_USB_OTG being enabled otherwise.

I'm too lazy at the moment to fix this function which's
use is currently unknown to me.

It's not part of Linux's 3.4 mainline neither.

Signed-off-by: moddingg33k <moddingg33k@t-online.de>
Enable setting security contexts on rootfs inodes.

rootfs (ramfs) can support setting of security contexts
by userspace due to the vfs fallback behavior of calling
the security module to set the in-core inode state
for security.* attributes when the filesystem does not
provide an xattr handler.  No xattr handler required
as the inodes are pinned in memory and have no backing
store.

This is useful in allowing early userspace to label individual
files within a rootfs while still providing a policy-defined
default via genfs.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Change-Id: I3436cf9ae27ade445e37376d7b9125746b1e506f
config: *update*
ARM: add SCHED_HRTICK config option

As we don't include kernel/Kconfig.hz as this defines HZ values
unsuitable for ARM platforms, add the SCHED_HRTICK to properly configure
the scheduler for hrtimer operation.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
ARM: fault: assume no context when IRQs are disabled during data abort.

Bail out early if IRQs are disabled in do_page_fault or else
  [14415.157266] BUG: sleeping function called from invalid context at arch/arm/mm/fault.c:301

Russell King's idea from
  http://comments.gmane.org/gmane.linux.ports.arm.omap/59256

Signed-off-by: JP Abgrall <jpa@google.com>
cpufreq: fix utilization statistics for sync cpus

If the cpus are using related_cpus policy, then the
current implementaion will overwrite the the calculated
load for every iteration in the for loop. Hence, mpdecision
will read incorrect value, if the cores are using related
cpus policy. With this change mpdecision will read the
sum of the loads of all cpu's, if related cpu policy is
used.

Change-Id: I242c8fe39fd75dc3e48750a5b78a5d218b536ddd
Signed-off-by: Narayanan Gopalakrishnan <nargop@codeaurora.org>
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>
mm: remove compressed copy from zram in-memory

Swap subsystem does lazy swap slot free with expecting the page would be
swapped out again so we can avoid unnecessary write.

But the problem in in-memory swap(ex, zram) is that it consumes memory
space until vm_swap_full(ie, used half of all of swap device) condition
meet.  It could be bad if we use multiple swap device, small in-memory
swap and big storage swap or in-memory swap alone.

This patch makes swap subsystem free swap slot as soon as swap-read is
completed and make the swapcache page dirty so the page should be
written out the swap device to reclaim it.  It means we never lose it.

I tested this patch with kernel compile workload.

1. before

   compile time : 9882.42
   zram max wasted space by fragmentation: 13471881 byte
   memory space consumed by zram: 174227456 byte
   the number of slot free notify: 206684

2. after

   compile time : 9653.90
   zram max wasted space by fragmentation: 11805932 byte
   memory space consumed by zram: 154001408 byte
   the number of slot free notify: 426972

[akpm@linux-foundation.org: tweak comment text]
[artem.savkov@gmail.com: fix BUG due to non-swapcache pages in end_swap_bio_read()]
[akpm@linux-foundation.org: invert unlikely() test, augment comment, 80-col cleanup]
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Artem Savkov <artem.savkov@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Konrad Rzeszutek Wilk <konrad@darnok.org>
Cc: Shaohua Li <shli@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Conflicts:
	mm/page_io.c

Change-Id: I8f11fb7f0391954435002e7f290352f311c907d4
mmc: msm_sdcc: check for pending_resume in SDCC system suspend

If system comes out of suspend, msmsdcc_pm_resume() sets the
host->pending_resume flag if the SDCC wasn't runtime suspended.
Now if the system again goes to suspend without any SDCC activity
then host->pending_resume flag will remain set which may cause the SDCC
resume to happen first and then suspend.

To avoid this unnecessary resume/suspend, make sure that pending_resume
flag is cleared before calling the msmsdcc_runtime_suspend().

CRs-Fixed: 438081
Change-Id: I2b667bec704f938a532d4780dd9b7937e2eb12c7
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
mm: pass readahead info down to the i/o scheduler

Some i/o schedulers (i.e. row-iosched, cfq-iosched) deploy an idling
algorithm in order to be better synced with the readahead algorithm.
Idling is a prediction algorithm for incoming read requests.

In this patch we mark pages which are part of a readahead window, by
setting a newly introduced flag. With this flag, the i/o scheduler can
identify a request which is associated with a readahead page. This
enables the i/o scheduler's idling mechanism to be en-sync with the
readahead mechanism and, in turn, can increase read throughput.

Change-Id: I0654f23315b6d19d71bcc9cc029c6b281a44b196
Signed-off-by: Lee Susman <lsusman@codeaurora.org>
usb: gadget: composite: Fix a bug in delayed status handling

The SET_CONFIGURATION control request's status phase is delayed
till the new config change is handled by the file-storage thread.
If the cable is disconnected or the bus is reset before the
previous config is handled, then composite driver is not notified
about the delayed status.  As a result of which, the delayed_status
field of composite device structure remains non-zero.  The status
phase of next SET_CONFIGURATION control request is not sent.
This makes the gadget unusable.

Calling usb_composite_setup_continue() after the disconnect or reset
does not make any sense.  If the host sends another control request
before the status phase of the previous control request is sent, the
delayed_status must be reset to zero.  This is not straight forward
as the UDC handles some control requests without delegating them to
the composite driver.  A simple fix would be resetting the delayed
status value after the disconnect/reset.

CRs-Fixed: 501527
Change-Id: I67c832afc88c9e7d025247e539b7223fd83644d7
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
msm: pm2: Update SPC LPM stats correctly

Currently StandalonePC stats are updating incorrectly even
for successful cases. After debug found that compiler has
optimized some of the instructions where the return value
from "msm_pm_power_collapse_standalone()" being compared
incorrectly and always log the stats as failed even for
success cases. Change the "exit_stat" variable to "volatile"
to avoid any optimization.

CRs-Fixed: 433578
Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>
(cherry picked from commit f59048d29fd75a30cac8c294e068178d9d489af3)

Change-Id: If1f9313f7968e93f5dcd9fb33426496f5091d14a
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: pm2: Restore interrupt subsystem from sleep.

Change-Id: Id5128e47e1e78688d0b608b64454555f26a65043
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
Signed-off-by: Baji Patthan <bpatth@codeaurora.org>
msm: kgsl: *squashing CAF updates*

msm: kgsl: Lower bounds check the number of power levels

      A misconfigured board file could cause an out-of-bounds
      array access through this value.

msm: kgsl: Protect the mem_entry list during deletion

      Use the spinlock to prevent corruption of the mem_entry list during
      deletion. Otherwise the mem_entry list may be modified by another
      thread at the same time resulting in memory corruption.

msm: kgsl: Always resume the GPU regardless of its state

      Make sure we resume the GPU regardless of its current
      state. If the device is not in suspend state restart the
      device and  print an error message.

msm: kgsl: Do not try to resume the device from INIT state

      If the device is still in INIT state there are no open instances
      of it running.  Resume calls should be no-ops.  Do not attempt
      to start the device at this point.

msm: kgsl: Don't consider active count if not in active state

      Don't consider active_cnt variable if not already in ACTIVE state.
      The active count variable does not necessarily exactly indicate the
      number of open handles to GPU for switching power state. Hence,
      only wait for active count to reach zero before switching to SUSPEND
      state if, the current state is ACTIVE.

msm: kgsl: Check the current interrupt status before power operations

      Sometimes the core will go idle before the interrupt can be handled on
      the GPU. If that happens then we could go to a lower power state before
      cleaning up the pending interrupt and various entities that might be
      waiting for it. Consider the current interrupt status when checking
      for idle.

msm: kgsl: Check for valid pointer before dereferencing

      Check to make sure that there is a valid context pointer before
      dereferencing it when adding commands to the ringbuffer.

msm: kgsl: Always submit an interrupt request to the GPU

      A context does not have to be present to send an internal dummy
      command to the GPU.  Remove BUG() in this case and instead send
      a NULL context which will still cause the interrupt to get submitted
      to the GPU.

msm: kgsl: Add CP_WAIT_FOR_IDLE packet before updating timestamp

      HW workaround to resolve MMU pagefault caused by memory
      freeing early before GPU completes it.

      This is race condition where timestamp is getting updated
      and the event handler runs before the GPU actually got done
      with the timestamp, hence freeing the buffer early while GPU
      still not completed with it.

msm: kgsl: Add cache flush for A20x

      Adding extra cache flush command to make sure that CP block
      gets event from RB all the time to avoid race conditions because of
      clock switches. this is to improve stability on 8x25 target.

msm: kgsl: Turn off the CP_DEBUG dynamic clock

      The CP dynamic clock seems to be glitchy when the CP clocks are turned
      back on after a power event. Turn off said dynamic clock control at
      init time. The impact of leaving the dynamic clock control off is
      negligible since the CP clock is only on when the CP is actually in
      use.

msm: kgsl: Increase REG_RBBM_CNTL value to 0xFFFF for A20X

      Increase number of clocks that RBBM will wait before de-asserting
      the Register Clock Active signal. This fixes kernel panics during
      stability tests on multiple devices.

msm: kgsl: Use the correct units for ADRENO_IDLE_TIMEOUT

      In a few spots the ADRENO_IDLE_TIMEOUT value (measured in milliseconds)
      was used directly for jiffy calculations resulting in timeouts that were
      1000/HZ times longer than they should have been.  Use msecs_to_jiffies
      for these situations.

msm: kgsl: Hold the pm_qos vote at all times when ACTIVE

      The GPU needs access to the L2 cache while running.  If the
      CPU is not also active using the cache can lead to stability
      issues.  Keep the CPU out of idle power collapse at all times
      while the GPU is running.

msm: kgsl: Calculate busy interval considering GPU freq as float

      GPU freq could be non-integral value and treating it as an integer
      to calculate GPU busy insterval leads to higher busy interval
      and more often we see negative idle stats. This change caculates
      busy interval by treating gpu freq to the correct precision.

msm: kgsl: Restore the value of RB_BC_CONTROL on context switch

      On 8x25Q, when GPU footswitch is turned off during TCXO shutdown, the
      RB_BC_CONTROL register value is lost which causes GPU hang after coming
      out of TCXO shutdown. Now the value of RB_BC_CONTROL is preserved properly
      during context save and restore.

msm: kgsl: Set sysfs max clock for devices with no power scale policy

      When the sysfs entry for max clock is updated, set it immediately for the
      devices that has no power scale policy. This prevents the device from
      running with undesired clock.

msm: kgsl: Remove extra interrupts when setting MMU state

      The interrupts added to the ringbuffer on PTFLUSH and TLBUPDATE
      were causing a major increase in the number of interrupts from the GPU.
      This was leading to increase in power and loss of performance. Add a check
      to turn off IOMMU clocks when going to SLEEP.
msm: video: *squashing CAF updates*

msm: msm_fb: remove mmio access through mmap

      Disable access to mm io and add
      appropriate range checks to ensure valid accesses
      through framebuffer mmap. This prevents illegal
      access into memory.

msm_fb: call the backlight control before FB_BLANK_POWERDOWN

      You might see the white line while lcd off. You should turn lcd backlight
      off before lcd off to avoid that issue. So call the notifier for backlight
      before handling of FB_BLANK_POWERDOWN in msm_fb.

msm_fb: Release semaphore when display Unblank fails

      When continuous splash is enabled, the display subsystem will be
      turned on during first pan display after boot up. During this
      process, we acquire a semaphore. Release the semaphore if display
      init fails and the function has to return early.

msm_fb: Handle histogram IRQ cleanly during suspend/resume

      Currently, if the histogram disable IOCTL comes after panel
      is turned off, we early return the IOCTL causing the interrupt
      to be left enabled. This causes IPC issues during suspend. Fix
      this issue by properly enabling/disabling the histogram interrupt
      during suspend/resume scenario.

msm_fb: display: Map framebuffer region in Display Write Domain

      Framebuffer is currently mapped for Display read and rotator source
      domains. For MDP writeback mode, Display write domain requires
      framebuffer region and it is mapped at initialization time.

msm_fb: display: no early suspend for writeback panel

      Writeback panel is not real physical panel and no power consumption
      concern, so it is removed from early suspend registration to avoid
      open fb2 error during suspend/resume.

msm_fb: display: add iommu mapping for mdp cursor buffer address

      The mdp h/w cursor buffer physical address needs to be mapped to an
      iommu virtual address when iommu domain is enabled.

msm: display: fb blend setting via MSMFB_METADATA_SET ioctl

      MSMFB_METADATA_SET ioctl is added for the fb user to pass
      in additional infomation rather than using reserved
      fields.
      User can set pre-multiplied alpha for the frame buffer via this
      ioctl, overlay blend setting will take this into account.

msm_fb: Update backlight level on resume after first pan display

      Use shared workqueue to delay the update of backlight after
      a first valid frame is displayed on the panel. This avoids any
      transients being displayed during resume.

msm: msm_fb: REVERT customizations of Huawei
      (Signed-off-by: moddingg33k <moddingg33k@t-online.de>)

msm_fb: display: Copy splash image to kernel memory

      The bootloader memory from which the splashscreen is shown
      gets reclaimed before frame update happens from framework.
      Hence, copy the splash image to a local buffer as soon as
      display is initialized. This will ensure proper continuous
      splashscreen functionality.

video: msm_fb: Ensure backlight is scaled atomically

      Ensure that when backlight scaling ratio or backlight level is being
      changed that the operation execute atomically. This prevents a backlight
      level change from being overwritten when it interrupts a backlight scale
      update.

msm_fb: dtv: Serve device off in a separate thread

      DTV device should not be powered down until the audio engine has
      shutdown. This change moves dtv audio off sequence to a separate
      thread so that framebuffer close system call does not get blocked.

msm-fb: v4l2: Add user pointer support using ION for mdp3 target

      -Add multi-planar user pointer support in msm v4l2 display driver
      using multiple ION fd's (2 fd's in case of mdp3).
      -Handle multi-buffer use case using memory offset along with ION
      fd to calculate physical address.

msm_fb: Avoid memset of frame buffer during early suspend

      At present, we have backlight disabled before frame buffer
      early suspend and there is mechanism in place to enable backlight
      only after first frame update after display resume. This makes sure
      to avoid panel specific artifacts being visible. Hence,
      remove memset of frame buffer during suspend. This change
      reduces latencies during frame buffer's early suspend.

msm_fb: Use an exclusive semaphore for Vsync IOCTL

      Vsync IOCTL runs in a separate thread context and is independent of the
      other display IOCTLs. Right now, we have the same semaphore shared
      for Vsync IOCTL along with other IOCTLs. This will cause performance
      drop if a Vsync enable/disable IOCTL thread waits to acquire the
      semaphore since composition might be happening through Overlay/Blit
      IOCTL. Hence, use a different semaphore for the Vsync IOCTL.

msm_fb: display: check FB_ACTIVATE_VBL bit only

      FB_ACTIVATE_VBL bit is set to enable TE logic at pan_display
      and unset to disable TE logic at pan_display for smart panel.
      This patch checks for FB_ACTIVATE_VBL bit set only instead of
      value.

msm_fb: Add support for BGRA_8888 as FB format

      Make BGRA_8888 as one of supported frame buffer
      format.

msm: Remove all references to CONFIG_ANDROID_PMEM

      CONFIG_ANDROID_PMEM is completely deprecated. Remove all
      references to it.

msm: display: reset vsync state when display is turned on

In the case that vsync ctrl is unbalanced, vsync IRQ is cleared
in suspend,  vsync cannot be enabled after resume.
Clear the status when display is turned on

CRs-fixed: 449155
Change-Id: I5ecf23053b60d1fbd91f042758d67d39c83ab444
Signed-off-by: Ken Zhang <kenz@codeaurora.org>

video: msm: *squashing CAF updates*

video: msm: Do not use disable_irq in the spin_lock_irqsave context

      Both mdp_isr() and mdp_histogram_disable() uses the same
      spin lock mdp_spin_lock variable.  One core waits for disabling
      mdp_isr after acquiring mdp_spin_lock and other core in mdp_isr()
      waits for spin lock mdp_spin_lock and dead lock between two cores.

video: msm: Send ETIMEDOUT on update-notify timeout

      Send the ETIMEDOUT errno when the update-notify wait_for_completion times
      out. This is required to be able to properly handle the different failure
      cases in the functions that use the update notify ioctl.

video: msm: Enable mdp clock for histogram and histLUT

      Enable the mdp clock for histogram and histogram LUT to ensure that the
      clock remains enabled when they are being accessed.

video: msm: Clear previous histogram data on next startup

      Clear the pointer to the userspace histogram struct when histogram is
      started. Previously, when the histogram was stopped while a histogram read
      was in progress, the pointer was not cleared, causing the next histogram
      read to think that someone was already using the histogram.

msm_fb: Keep LCDC timing generator enabled during boot up

      Keep the LCDC timing generator enabled during boot up on
      MDP 3.03 targets if continuous splash screen feature is enabled.

video: msm: Ensure idle state before enabling histogram

      Disable interrupt, set state flags to false, cancel histogram collection,
      and clear the workqueue before attempting to enable the histogram. This
      guarantees that this is the only configuration of the histogram running.

msm_fb: Fix display corruption with continuous splash screen feature

      During boot up, we observe random lines on screen between the
      splash_screen image and the android animation. MDP clocks
      were turned off during bootup. Fix this issue by enabling
      the clocks when this feature is enabled.

      Add check to see that the video mode engine is not busy before
      turning off the dsi controller to avoid any underruns.

msm_fb: Correctly setup splash screen flag in MDP probe

      The continuous splash screen flag was sometimes not correctly setup
      during MDP probe causing corrupted grey screen on resets.

msm_fb: display: add mdp bandwidth runtime calculation

      Currently mdp bandwidth request logic is based on source image size
      and number of layers. This logic can not support complicated mdp
      usecases and it is not power efficient. The logic is improved by
      calculating mdp bandwidth request at runtime from all pipes and mixers.

msm_fb: display: add sysfs and clock control to smart panel

      This patch allows both vsync enable and disable are controlled
      by framework. Driver reports vsync event to framework via sysfs.
      Meanwhile, mdp related clocks are enabled by framework at vsync
      enabled request and disabled by driver if there is no any display
      update within specifid vsync period.

msm_fb: display: add video mode dcs cmdlist support

      Add video mode dcs command list support. This patch
      make sure dcs commands committed while dsi video engine
      is busy so that dcs command will be transmitted at beginning
      of next BLLP.

msm_fb: display: fix dsi_busy_wait race condition

      After pipe_commit() released mutex and before kickoff happens,
      There has possibility that dcs command may start transmitted.
      This patch add dsi_mdp_busy flag to fix this race condition.

msm_fb: display: delete dsi clock control from cmdlist_commit

      cmdlist_commit perform dsi clock control which turns off
      dsi clock unexpectly when dsi controller is configured as
      command mode during booting up. This cause display panel
      can not be lit up. This patch drop clock control mechanism
      from cmdlist_commit and move dsi clock control mechanism to
      caller.

msm_fb: display: Removing extra disable irq in cmds_rx API's

      Disable IRQ for DSI_CMD_TERM was already called in the isr.
      Removing the extra call present in the cmds_rx API's.