UPSTREAM: Bluetooth: btmrvl: wait for HOST_SLEEP_ENABLE event in suspend

After BT_CMD_HOST_SLEEP_ENABLE command finishes, driver should
wait until getting BT_EVENT_HOST_SLEEP_ENABLE event to complete
suspend procedure.
Without this patch the suspend handler would return success
earlier. By the time when the BT_EVENT_HOST_SLEEP_ENABLE event
comes in the controller driver could have already turned off the
bus clock. This causes kernel crash or system reboot eventually.

Cc: <stable@vger.kernel.org> # 3.13+
Signed-off-by: Chin-Ran Lo <crlo@marvell.com>
Signed-off-by: Jeff CF Chen <jeffc@marvell.com>
Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

BUG=chrome-os-partner:29565,chrome-os-partner:28553,chrome-os-partner:25091
TEST=WLAN connected to AP; BT running A2DP; suspend_stress_test.
Unit test passed overnight.
Based on ODM's test result, 10 out of 13 passed 600 iterations.
It used to fail on every unit.
Without this patch, the current in suspend mode was 7.1mA,
deep sleep 2.2mA. With this patch applied, the current in suspend
mode drops to 2.2mA, same as in deep sleep mode.

Change-Id: I0341c5a5bd938b419af68d3f1671f7c137531fd3
Reviewed-on: https://chromium-review.googlesource.com/206341
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Bing Zhao <bzhao@marvell.com>
Commit-Queue: Bing Zhao <bzhao@marvell.com>
CHROMIUM: ARM: dts: blaze: update T-SKIN trip temperature

Update T-skin trip temperature to 45 Celsius.

BUG=chrome-os-partner:29744
TEST=build, download and verified by thermal test

Change-Id: I6eddfd61385160f1b749824e8e31d3a8fbc5ad0f
Signed-off-by: Neil Chen <neilc@nvidia.com>
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/207341
Reviewed-by: Dylan Reid <dgreid@chromium.org>
CHROMIUM: drivers/backlight: Add "choose" method

Add a new backlight method backlight_choose(), for choosing a particular
backlight configuration.  Child driver's implementation of the choose
method is optional.

BUG=chrome-os-partner:29804
BRANCH=nyan*
TEST=emerge-nyan chromeos-kernel-3_10

Change-Id: I5b0f37cc7321d4ef7331c947066452e80112150c
Signed-off-by: Andrew Chew <achew@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/205317
Tested-by: Danny Huang <dahuang@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: pwm-backlight: add alternate brightness tables

Allow the option to specify multiple backlight brightness-levels tables.
The backlight framework's choose method is used to select the particular
brightness-levels table.

BUG=chrome-os-partner:29804
BRANCH=nyan*
TEST=emerge-nyan chromeos-kernel-3_10, hardcode a backlight_choose() call
into tegra dc driver and make sure the proper table is chosen.

Change-Id: I4ce3b01f15deaa6fdcc15283b90bbc4079ac0ac4
Signed-off-by: Andrew Chew <achew@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/205318
Tested-by: Danny Huang <dahuang@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: pwm-backlight: add alternate brightness tables doc

Extend the pwm-backlight bindings documentation with information about
alternate brightness tables.

BUG=chrome-os-partner:29804
BRANCH=nyan*
TEST=none

Change-Id: I32fb15a374c06b33039a5b9e85229dbfa571e7ab
Signed-off-by: Andrew Chew <achew@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/205319
Tested-by: Danny Huang <dahuang@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: ARM: dts: tegra124: add label for backlight

BUG=chrome-os-partner:29804
BRANCH=nyan*
TEST=emerge-nyan chromeos-kernel-3_10

Change-Id: Iad7aeb89030af2a27fe14b659dcdb084094b88b7
Signed-off-by: Andrew Chew <achew@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/205350
Tested-by: Danny Huang <dahuang@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: Input: elan_i2c - Add lid event listener

The patch tries to add a LID input event filter to listen for SW_LID events
to enable/disable touchpad when LID is open/closed.

Signed-off-by: Duson Lin <dusonlin@emc.com.tw>
BUG=chrome-os-partner:29727
TEST=Do the following on device with Elan touchpad.
 * Test normal lid-closed suspend :
  1. log in as guest
  2. close the lid, wait for suspend
  3. open the lid to resume
  4. Check that touchpad is responsive.

 * Test suspend, lid-closed, then lid-open:
  1. log in as guest
  2. wait for the suspend
  3. close the lid
  4. opend the lid to resume
  5. check that touchpad is responsive.

 * Test normal lid-open, suspend, then lid-closed:
  1. log in as guest with external DISPLAY+keyboard connected with lid-open
  2. wait for the suspend
  3. close the lid
  4. wake up the device with external keyboard
  5. ensure no stray touches from touchpad*

 * Test Docked mode, lid close-open, no suspend :
  1. log in as guest
  2. connect external display to extend monitor
  3. close the lid to enter docked mode
  4. ensure no stray touches from touchpad here*
  5. open the lid
  6. Check that touchpad is responsive.

 * Test Docked mode, lid closed, idle suspend :
  1. log in as guest
  2. connect external display and connect USB keyboard.
  3. close the lid to enter docked mode
  4. ensure no stray touches from touchpad here*
  5. from a remote shell (ssh) : powerd_dbus_suspend
  6. strike a key from usb keyboard to resume.
  7. ensure no stray touches from touchpad here*
  8. open the lid
  9. Check that touchpad is responsive.

 * Test normal lid-closed suspend with external mouse, docked mode, lid open:
  1. log in as guest
  2. connect USB keyboard.
  3. close the lid to enter suspend mode
  4. connect external display
  5. strike a key from usb keyboard to resume.
  6. ensure no stray touches from touchpad here*
  7. open the lid
  8. Check that touchpad is responsive.

  *: To check that no stray touches occur:
  a) ssh to dut.
  b) run "evtest" command.
  c) open the lid a little bit(good enough for your finger to touch the pad, but
     make sure it won't trigger lid open event.
  d) a finger touches the pad to verify that touchpad should not be responsive.

Change-Id: Idee243d24ab708eac4bf85e09785e34013f29611
Reviewed-on: https://chromium-review.googlesource.com/205640
Reviewed-by: Chung-yih Wang <cywang@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Tested-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Benson Leung <bleung@chromium.org>
UPSTREAM: drm/i915: Use frame counter for intel_wait_for_vblank() on CTG

Use the same wait_for_vblank code for CTG that we use for ILK+.

Also fix the name of the frame counter register while at it.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
Reviewed-by: Imre Deak <imre.deak@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
(cherry picked from commit 57e22f4add51b0f42b76a6960c4a4daa71e8f832)
Signed-off-by: Kevin Strasser <kevin.strasser@intel.com>

BUG=chrome-os-partner:28200,chrome-os-partner:24085,chrome-os-partner:25575
TEST=Manual: Boot and suspend/resume Rambi with drm.debug=0x06.
Check that there are a reduced number of vblank timeouts.

Change-Id: I066d322e104ed5ad9b6573820e1b9b036c7b7f6e
Reviewed-on: https://chromium-review.googlesource.com/203782
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Kevin Strasser <kevin.strasser@intel.com>
Commit-Queue: Kevin Strasser <kevin.strasser@intel.com>
Tested-by: Kevin Strasser <kevin.strasser@intel.com>
CHROMIUM: thermal: update cdev updated field

Set cdev->updated to false, whatever the target state is same as
current state or not.
Because if a cooling device return an error in set_cur_state
callback, we should give the cooling device a chance in the next
passive check to configure itself to the target state.

BUG=chrome-os-partner:30260
TEST=hack the trip temp of gpu-balanced to 40C and the pid
governor to return the max throttle state, then observe below
on boot:
1. without this change, thermal_cdev_update failed then no retry.
2. while with this change, succeeded after couple retries.

Change-Id: I1999b5840b8a85837f4303fae2992bfecba40a82
Signed-off-by: Ken Chang <kenc@nvidia.com>
Signed-off-by: Wei Ni <wni@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/207501
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
CHROMIUM: thermal: tegra: return gpu throttling result

If update state failed, it would not change the cur_state.
And return the actual result for set_cur_state and let
the user space decide what to do next.

BUG=chrome-os-partner:30260
TEST=Ran WebGl Aquarium to let the GPU temp hit 60C
then hack the trip temp of gpu-balanced to 40C then reboot
the unit.
Observed tegra_gpu_set_speed_cap() failed on some
throttling states then succeeded in the next target state
which is set by the governor policy or the next passive retry.

Change-Id: I99fd71bde7a5b745ff27ecc720e0bf45afd32463
Signed-off-by: Vince Hsu <vinceh@nvidia.com>
Signed-off-by: Wei Ni <wni@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/207299
Reviewed-by: Ken Chang <kenc@nvidia.com>
Tested-by: Ken Chang <kenc@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: video: tegra: dc: choose brightness table based on EDID

Use a string based on the EDID's manufacturer id, model, and serial to
choose a backlight table.

BUG=chrome-os-partner:29804
TEST=emerge-nyan chromeos-kernel-3_10 after adding an alternate backlight
brightness-levels table for T124 Norrin using "CMN-1132-0", and make sure
the proper backlight table is chosen.

Change-Id: I08f2f9dcd2b62f68a0ce136f0ac6bd810a569053
Signed-off-by: Andrew Chew <achew@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/205351
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: video: tegra: check driver initialization before access

The tegra throttling driver might access the gk20a clk driver
before clk is initialized due to overheating when booting.
So we have to check the driver's readiness first.

BUG=chrome-os-partner:30260
TEST=None

Change-Id: I0b9461ca4e395e6428b7b2a86e676bb8c923415f
Signed-off-by: Vince Hsu <vinceh@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/207320
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Ken Chang <kenc@nvidia.com>
Tested-by: Ken Chang <kenc@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: Bluetooth: btmrvl: avoid sending data to firmware after hs_activated

We should suspend hci device and purge remaining data in tx queue
before enabling host sleep in firmware. If any data is sent to
firmware after host sleep is activated, firmware may end up
sending a TX_DONE interrupt to driver. If this interrupt gets
delivered to host while the SDIO host controller is suspending,
it may crash the system.

Conversely, in resume handler, we should resume hci device after
host sleep is de-activated.

Signed-off-by: Chin-Ran Lo <crlo@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>

BUG=chrome-os-partner:28553
TEST=WLAN connected to AP; BT running A2DP; suspend_stress_test.

Change-Id: Ie9ed19bd0da917cff08c3f70f282336587e7b28b
Reviewed-on: https://chromium-review.googlesource.com/207218
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Bing Zhao <bzhao@marvell.com>
Commit-Queue: Bing Zhao <bzhao@marvell.com>
UPSTREAM: HID: Add some missing HUT mappings

Add mapping for "AL Next Task/Application", "AL Previous Task/Application"
and "AL File Browser" buttons, as found on the Microsoft Office keyboard.

Note that there already is a mapping for "AL Local Machine Browser" to
KEY_FILE. Unless we ever encounter a device with both that should not be
a problem.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

(cherry picked from commit 5820e4d4ae17c0994c93d0537bd1a184267f3cae)
BUG=chromium:389558
TEST=none

Change-Id: Ibe3dd29efd7e2d520c58baf1a6d5beff24b7f5e9
Reviewed-by: Nestor Lopez Casado <nlopezcasad@logitech.com>
Commit-Queue: Nestor Lopez Casado <nlopezcasad@logitech.com>
Tested-by: Nestor Lopez Casado <nlopezcasad@logitech.com>
Reviewed-on: https://chromium-review.googlesource.com/207530
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Tested-by: Andrew de los Reyes <adlr@chromium.org>
UPSTREAM: HID: add missing hid usages

Add some missing hid usages from consumer page, add
some display brightness control usages from approved hid usage
table request HUTTR41:
http://www.usb.org/developers/hidpage/HUTRR41.pdf
and add voice command usage from approved request HUTTR45:
http://www.usb.org/developers/hidpage/Voice_Command_Usage.pdf

[jkosina@suse.cz: removed KEY_BRIGHTNESS_TOGGLE / KEY_DISPLAYTOGGLE
 conflict from hid-debug.c]

Signed-off-by: Olivier Gay <ogay@logitech.com>
Signed-off-by: Mathieu Meisser <mmeisser@logitech.com>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

(cherry-picked from commit f362e690e5530dd8ace289da991bda558731678e)
BUG=chromium:389558
TEST=compiles

Change-Id: Icebd88bd95b83eb976deb361ef20cff6912e7e52
Reviewed-by: Nestor Lopez Casado <nlopezcasad@logitech.com>
Commit-Queue: Nestor Lopez Casado <nlopezcasad@logitech.com>
Tested-by: Nestor Lopez Casado <nlopezcasad@logitech.com>
Reviewed-on: https://chromium-review.googlesource.com/207531
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Tested-by: Andrew de los Reyes <adlr@chromium.org>
UPSTREAM: mwifiex: fix ext_capab IE structure definition

EXT_CAPAB_IE format involves IEEE header followed by bytestream of
capabilities. Current structure has incorrect member u8 for data;
fix it by defining it as u8[0].

BUG=chrome-os-partner:24153
TEST=With all patches in this series applied on Clapper, test TDLS functionality.
1. run wpa_cli on peer device
2. Discover TDLS peer by command
tdls_discover <Clapper WLAN mac address>
3. Setup TDLS link with clapper
tdls_setup <Clapper WLAN mac address>
4. Teardown existing TDLS link
tdls_teardown <Clapper WLAN mac address>
From Clapper, DBus command can be used to setup TDLS link as follows:
dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \
/fi/w1/wpa_supplicant1/Interfaces/0 \
fi.w1.wpa_supplicant1.Interface.TDLSSetup string:<peer-mac-address>

Change-Id: I35358e8556007e69b15c212df526b41cf48f132d
Signed-off-by: Avinash Patil <patila@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Tested-by: Xinmin hu <huxm@marvell.com>
Tested-by: Avinash Patil <patila@marvell.com>
Reviewed-on: https://chromium-review.googlesource.com/202841
Reviewed-by: Paul Stewart <pstew@chromium.org>
UPSTREAM: mwifiex: rename pkt_count to ba_pkt_count in mwifiex_ra_list_tbl struct

pkt_count is used to determine if BA can be formed on this RA list
by comparing it with randomly generated BA threshold. The pkt_count
variable name here is ambiguous and does not reflect its usage
correctly. Rename it to ba_pkt_count.

BUG=chrome-os-partner:24153
TEST=With all patches in this series applied on Clapper, test TDLS functionality.
1. run wpa_cli on peer device
2. Discover TDLS peer by command
tdls_discover <Clapper WLAN mac address>
3. Setup TDLS link with clapper
tdls_setup <Clapper WLAN mac address>
4. Teardown existing TDLS link
tdls_teardown <Clapper WLAN mac address>
From Clapper, DBus command can be used to setup TDLS link as follows:
dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \
/fi/w1/wpa_supplicant1/Interfaces/0 \
fi.w1.wpa_supplicant1.Interface.TDLSSetup string:<peer-mac-address>

Change-Id: Ia76f91bd532e0c1fd75ebd61d0a8c9072092c83d
Signed-off-by: Avinash Patil <patila@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Tested-by: Xinmin hu <huxm@marvell.com>
Tested-by: Avinash Patil <patila@marvell.com>
Reviewed-on: https://chromium-review.googlesource.com/202842
Reviewed-by: Paul Stewart <pstew@chromium.org>
UPSTREAM: mwifiex: maintain outstanding packet count for RA list instead of packet size

Maintain total outstanding packet count for RA list instead of total
outstanding size as packet count metric seems more reasonable for
checking threshold etc.

BUG=chrome-os-partner:24153
TEST=With all patches in this series applied on Clapper, test TDLS functionality.
1. run wpa_cli on peer device
2. Discover TDLS peer by command
tdls_discover <Clapper WLAN mac address>
3. Setup TDLS link with clapper
tdls_setup <Clapper WLAN mac address>
4. Teardown existing TDLS link
tdls_teardown <Clapper WLAN mac address>
From Clapper, DBus command can be used to setup TDLS link as follows:
dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \
/fi/w1/wpa_supplicant1/Interfaces/0 \
fi.w1.wpa_supplicant1.Interface.TDLSSetup string:<peer-mac-address>

Change-Id: I3d967fd194072520e9dad062ece54cbaa4803d3a
Signed-off-by: Avinash Patil <patila@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Tested-by: Xinmin hu <huxm@marvell.com>
Tested-by: Avinash Patil <patila@marvell.com>
Reviewed-on: https://chromium-review.googlesource.com/202843
Reviewed-by: Paul Stewart <pstew@chromium.org>
UPSTREAM: mwifiex: handle AMPDU supported check for AP interface

This patch fixes a bug where we were checking for AP's AMPDU param
setting even when transmitting traffic to associated station.
Patch adds provision to pass additional parameter ra_list pointer
to function which checks if AMPDU is allowed. If current BSS type is
AP, we check station's AMPDU params else we check AP's AMPDU params.

BUG=chrome-os-partner:24153
TEST=With all patches in this series applied on Clapper, test TDLS functionality.
1. run wpa_cli on peer device
2. Discover TDLS peer by command
tdls_discover <Clapper WLAN mac address>
3. Setup TDLS link with clapper
tdls_setup <Clapper WLAN mac address>
4. Teardown existing TDLS link
tdls_teardown <Clapper WLAN mac address>
From Clapper, DBus command can be used to setup TDLS link as follows:
dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \
/fi/w1/wpa_supplicant1/Interfaces/0 \
fi.w1.wpa_supplicant1.Interface.TDLSSetup string:<peer-mac-address>

Change-Id: I6ffc560f008c00249466a1af2daaaa1aebe1ce9c
Signed-off-by: Avinash Patil <patila@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Tested-by: Xinmin hu <huxm@marvell.com>
Tested-by: Avinash Patil <patila@marvell.com>
Reviewed-on: https://chromium-review.googlesource.com/202844
Reviewed-by: Paul Stewart <pstew@chromium.org>
UPSTREAM: mwifiex: make tos_to_tid_inv part of mwifiex_private structure

tos_to_tid_inv values are needed even during TDLS operations.
Currently tos_to_tid_inv is part of wmm.c and declared static.
Make it part of private structure so that it can be used in
other files as well.

BUG=chrome-os-partner:24153
TEST=With all patches in this series applied on Clapper, test TDLS functionality.
1. run wpa_cli on peer device
2. Discover TDLS peer by command
tdls_discover <Clapper WLAN mac address>
3. Setup TDLS link with clapper
tdls_setup <Clapper WLAN mac address>
4. Teardown existing TDLS link
tdls_teardown <Clapper WLAN mac address>
From Clapper, DBus command can be used to setup TDLS link as follows:
dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \
/fi/w1/wpa_supplicant1/Interfaces/0 \
fi.w1.wpa_supplicant1.Interface.TDLSSetup string:<peer-mac-address>

Change-Id: Ibc1b021b7eaabe989448699b8a01287877dee57d
Signed-off-by: Avinash Patil <patila@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Tested-by: Xinmin hu <huxm@marvell.com>
Tested-by: Avinash Patil <patila@marvell.com>
Reviewed-on: https://chromium-review.googlesource.com/202845
Reviewed-by: Paul Stewart <pstew@chromium.org>