power_supply: add change the scope property

The scope property indicates the operating mode of the system. This
property could be used to switch to and from usb host mode.

Add a helper api to update this property.

CRs-fixed: 373365 368475
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 59d890ff84c431d1cf56118ba0c5892b7d9b7a06)

Change-Id: I3ed91574dddedc795fd6bdce7abb729c3116221a
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
power: pm8921-charger: support dc charging while in usb host mode

The current code disables charging when the usb is operating in host
mode. This unnecessarily stops charging from the DC path. The board
layout (the ovp fet and otg path) is assumed to support host mode and
charging from dc path.

Also make the usb driver change the power supply framework's scope
property instead of calling 8921 charger apis directly.

CRs-fixed: 373365 368475
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 5e96aaa4c667b34b354a100cbe7b0c3da01cc3d4)

Conflicts:

	drivers/power/pm8921-charger.c

Change-Id: I852fbee9f1fec6d9f55b8f5583023f029cb6ec63
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
power_supply: add SCOPE attribute to power supplies

This adds a "scope" attribute to a power_supply, which indicates how
much of the system it powers.  It appears in sysfs as "scope" or in
the uevent file as POWER_SUPPLY_SCOPE=.  There are presently three
possible values:
	Unknown - unknown power topology
	System - the power supply powers the whole system
	Device - it powers a specific device, or tree of devices

A power supply which doesn't have a "scope" attribute should be assumed to
have "System" scope.

In general, usermode should assume that loss of all System-scoped power
supplies will power off the whole system, but any single one is sufficient
to power the system.

Change-Id: Ib0d844dc7f0c175ee0ccb5307df7f85bf8797658
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Richard Hughes <richard@hughsie.com>
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

Conflicts:
	include/linux/power_supply.h
Bluetooth: Update Local COD to bluez userspace on write complete.

Class of device information is required to the bluez userspace
to write to persistant storage and also update upper layers on
request. So update the local CoD info to bluez once the hci write
is successful.

CRs-fixed: 375304
Signed-off-by: Srinivas Krovvidi <skrovvid@codeaurora.org>
(cherry picked from commit 58562d8177e97893c27d04a378867e714029e620)

Change-Id: I88355cbf128f8e5f9b85f2a4bcfcdea4ab3b0f78
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

Conflicts:
	net/bluetooth/mgmt.c
msm-fb: display: lm2 writeback support on mpq platfroms

lm2 writeback has broken on mpq platfroms as lm1 and lm2 are
selecting the same axi writeback path. It adds the support
to select the right axi writeback path based the availability
of the write master

CRs-fixed: 375340
Signed-off-by: Nagamalleswararao Ganji <nganji@codeaurora.org>
(cherry picked from commit b411a253ea37acbe8cc817bf004ae08d877d9bd1)

Change-Id: I06917794b08fa4dadb5ecf0ec6867b26cba106c5
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
diag: Add missing SSID range

OEMs use SSID in a specific range. Recently DIAG changed the mask
update algorithm and this range was missed as its not used internally.
This change adds it back.

CRs-fixed: 359379
Change-Id: Ib7249f157e4e37294b6da6580fcf19995afeef8f
Signed-off-by: Shalabh Jain <shalabhj@codeaurora.org>
(cherry picked from commit 44b79b7bb5aeeaa2c956ce0fd1e605d840c55a73)

Conflicts:

	include/linux/diagchar.h

Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
msm: bam_dmux: Add locking around platform device calls

The channel state is used to determine if a platform device has been
registered on a particular channel.  In the case of a subsystem restart
while a channel is being opened, the subsystem restart can occur between
the channel state being set to opened and the platform device being
added.  This will result in the subsystem restart code seeing that the
channel is open and attempting to remove a platform device that has been
added.

This change adds mutex protection around the channel state updates and
the platform device add/remove calls to handle any race conditions.

CRs-fixed: 378060
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
(cherry picked from commit a623da8bda62e95acf5991905af2847e8e326e09)

Change-Id: I8eef024141a2c81552439856aa9c77fc491354a3
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
hwmon: pm8xxx-adc: Update pa_therm mapping table

Inaccurate temperature readings are reported for
pa_therm when read from the apps. This is because
an inaccurate B constant was used while calculating
the voltage to temperature mapping table. Fix it
by generating the table using the correct B constant
for the thermistor.

CRs-fixed: 374589
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
(cherry picked from commit 9ae3efba35a5291df925bc645662dd2c5fbd4efb)

Change-Id: I879f6281efe6afed8ff5a3037ca34d2988d231a5
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
msm_fb: Check for Histogram NULL while queuing work

Don't queue the work if the user hasn't requested for the
histogram data

CRs-Fixed: 365729 363763
Signed-off-by: Jeevan Shriram <jshriram@codeaurora.org>
(cherry picked from commit ff42a9a426ab9a76d75a29464412807dd72ceb13)

Change-Id: If5e6a5ad525e895ff7c2f27666cc7a445c485cb4
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
video: msm: Always queue histogram work

Always queue histogram read worker in order to gain concurrency protection
from the histogram management mutex (move previous checks/calls into worker
itself).

CRs-fixed: 363763
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
(cherry picked from commit c0d815c2a4118d1ba51e316c6cb59bee4d68eb9b)

Change-Id: I8970021ff300c08131bdc1fbf3efdc74623bdb90
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
video: msm: Always queue histogram work & lock histogram calls

Always queue histogram read worker in order to gain concurrency protection
from the histogram management mutex (move previous checks/calls into worker
itself).

Lock the mdp_histogram_start and mdp_histogram_stop calls with the same
lock used currently by mdp_do_histogram to maintain that every do_histogram
called between a start and stop will be completed.

Add a timeout to do_histogram wait_for_completion so that it will unlock
and yield to other histogram calls if it waits for longer than 33 msec.

CRs-fixed: 363763
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
(cherry picked from commit 56a123baaab84af584fbbf5cbb29955ec5c92f39)

Change-Id: I803b6457523d1af13cc83e459a8b0fe2829badf8
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm_fb: Handle multiple histogram reader errors during suspend/resume

If a histogram reader waits for completion in the do_histogram ioctl
and during this time the device is suspended, the complete for this
gets called from mdp_histogram_ctrl_all() in the panel_next_off()
sequence. This results in mgmt->hist not set to NULL. The subsequent
do_histogram ioctls after device resume fail due to multiple reader
failure condition since the histogram irq will be enabled now from
the same mdp_histogram_ctrl_all() during panel_next_on() sequence and
this by-passes mgmt->hist getting set to NULL that is present in
histogram_start() ioctl. Handle this scenario.

CRs-fixed: 363763
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
(cherry picked from commit a43f44b44ee221df11ad84b8536c1c8d5373cbaf)

Change-Id: If0a45a8215a969bf6f137e19f2536d6d4abce156
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
video: msm: Fix corner cases of "read twice" error

Fix several cases where histogram's completion structure is completed
multiple times which causes the next histogram read to force the histogram
software state machine into believing that the histogram is always being
read by someone.

When the timeout in mdp_do_histogram times out and then soon after the work
that was being waited on completes, the next do_histogram call that is
processed will not wait (and thus will not have its hist field set to
NULL). This will cause all subsequent do_histograms to think that the
histogram is currently being read, and will cause the "read twice" message
to flood the kernel logs.

This error is fixed by always initializing the completion structure before
waiting for the histogram to complete. That way if the completion happens
after the timeout, instead of causing the error, the completion's internal
counter is reset to zero, which prevents the next histogram read from
completing without waiting.

CRs-fixed: 363763
Signed-off-by: Padmanabhan Komanduru <pkomandu@codeaurora.org>
Signed-off-by: Carl Vanderlip <carlv@codeaurora.org>
(cherry picked from commit 3d297368b8199b07bda815915e94ecb5761561b0)

Change-Id: Ibb47ceae75fdd7347b1c3474cb16a394eff40446
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: camera: Send camif error notification to user.

In case of CAMIF errors, notify the user so that it
can cleanup resources and exit gracefully.

CRs-Fixed: 371688
Change-Id: I8340627931ce07788abc1418100826f1ac94ef6c
Signed-off-by: Kiran Kumar H N <hurlisal@codeaurora.org>
msm: kgsl: Add TLB flush for each submit in case of 8x25/7x2xa

Add TLB flush for each submit to prevent target freeze
in case of 8x25/7x27a/7x25a targets.

CRs-fixed: 379991
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
(cherry picked from commit 22a06d18c6eb100419616ddf7a2c4ac403420a9e)

Change-Id: I7c34660128c791c9329b41246af39879625d64d3
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno.c
Bluetooth : Ignore incomming events when the hci device is down

In error conditions Adapter state machine via Bluez tries to reset
the hci device, during that in some rare scenario if some pending event
comes from riva, the command complete apis tries to access some already
freed memory in reset sequence.

CRs-fixed: 369658
Signed-off-by: Bhasker Neti <bneti@codeaurora.org>
(cherry picked from commit 6f4ceb1f8588aec11b4d9380cd328d0008c8d167)

Change-Id: I7d72cc12ef98f15cc21bd5954c5ba9c810246716
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
cpufreq: Fix sysfs deadlock with concurrent hotplug/frequency switch

Running one program that continuously hotplugs and replugs a cpu
concurrently with another program that continuously writes to the
scaling_set_speed node eventually deadlocks with:

=============================================
[ INFO: possible recursive locking detected ]
3.4.0 #37 Tainted: G        W
---------------------------------------------
filemonkey/122 is trying to acquire lock:
 (s_active#13){++++.+}, at: [<c01a3d28>] sysfs_remove_dir+0x9c/0xb4

but task is already holding lock:
 (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(s_active#13);
  lock(s_active#13);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

2 locks held by filemonkey/122:
 #0:  (&buffer->mutex){+.+.+.}, at: [<c01a2230>] sysfs_write_file+0x28/0x140
 #1:  (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

stack backtrace:
[<c0014fcc>] (unwind_backtrace+0x0/0x120) from [<c00ca600>] (validate_chain+0x6f8/0x1054)
[<c00ca600>] (validate_chain+0x6f8/0x1054) from [<c00cb778>] (__lock_acquire+0x81c/0x8d8)
[<c00cb778>] (__lock_acquire+0x81c/0x8d8) from [<c00cb9c0>] (lock_acquire+0x18c/0x1e8)
[<c00cb9c0>] (lock_acquire+0x18c/0x1e8) from [<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180)
[<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180) from [<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4)
[<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4) from [<c02d0e5c>] (kobject_del+0x10/0x38)
[<c02d0e5c>] (kobject_del+0x10/0x38) from [<c02d0f74>] (kobject_release+0xf0/0x194)
[<c02d0f74>] (kobject_release+0xf0/0x194) from [<c0565a98>] (cpufreq_cpu_put+0xc/0x24)
[<c0565a98>] (cpufreq_cpu_put+0xc/0x24) from [<c05683f0>] (store+0x6c/0x74)
[<c05683f0>] (store+0x6c/0x74) from [<c01a2314>] (sysfs_write_file+0x10c/0x140)
[<c01a2314>] (sysfs_write_file+0x10c/0x140) from [<c014af44>] (vfs_write+0xb0/0x128)
[<c014af44>] (vfs_write+0xb0/0x128) from [<c014b06c>] (sys_write+0x3c/0x68)
[<c014b06c>] (sys_write+0x3c/0x68) from [<c000e0e0>] (ret_fast_syscall+0x0/0x3c)

This is because store() in cpufreq.c indirectly grabs a kobject
with kobject_get() and is the last one to call kobject_put()
indirectly via cpufreq_cpu_put().

Fix this deadlock by introducing two new functions,
cpufreq_cpu_get_sysfs() and cpufreq_cpu_put_sysfs() which do the
same thing as cpufreq_cpu_{get,put}() but don't grab the kobject.

CRs-fixed: 366560
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
(cherry picked from commit f82ef51be26b44b83d86afa56b3cd9c743023470)

Change-Id: Ia692e64dc3ce40f0ff3e209025a346f7d9b569da
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
msm_fb: display: Add pre-multiplied alpha support for MDP4.

MDP4 blend logic differs from GPU blend implementation as MDP4
does not differentiate between layers with pre-multiplied alpha
with that to non pre-multiplied alpha layers. Check layers for
pre-multiplied alpha and change blend logic accordingly.

CRs-Fixed: 355755
CRs-Fixed: 361729
CRs-Fixed: 366441
Change-Id: Idf3fef57bc3cc31a221b83027f5f3fa64dee5ae7
Signed-off-by: Mayank Chopra <makchopra@codeaurora.org>
Revert "msm: bam_dmux: Add locking around platform device calls"

This reverts commit 4dae83360bae84c6df12c53c995f772cb068eedb.

Change-Id: Ida541fefa769cd0a1692d3357c58f0556ee754e0
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
USB: ci13xxx_udc: Flush ep0IN and ep0OUT endpoint from ep_dequeue

Flush control endpoints from ep_dequeue and set request completion
to NULL once calling completion handler of function driver. This will
make sure that all control endpoint requests are flushed in disconnect.

CRs-Fixed: 373672
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
(cherry picked from commit 0c1b8b2174f85c4437a197c2e58350bd6f6c3d02)

Change-Id: I3fef1c2b464db6a8ef283c0a02a87b5b48ab26ad
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>