mkbp: Fix problems with backslash

The mkbp code (post 3.4) has an issue where it can't deal with two
keys on the keyboard having the same keycode.  When this happens it
will get confused about whether the key is down or up and will cause
some screwy behavior.

We need to have two keys on the keyboard with the same keycode for UK
keyboards.  Specifically:
* On the US keyboard the backslash key (above enter) is r3 c11 and is
  supposed to be reported as BACKSLASH.
* On the UK keyboard the # key (left of enter) is r4 c10 and is
  supposed to be reported as BACKSLASH.
* On the UK keyboard the \ key (left of Z) is r2 c7 and is supposed to
  be reported as KEY_102ND.

The above may be crazy, but that's how it's supposed to work so we
need to handle two KEY_BACKSLASH keycodes.  Luckily this is easy to
handle.

This is posted upstream at:
  https://patchwork.kernel.org/patch/3384681/

BUG=chrome-os-partner:24379
TEST=Ran evtest and validated the above on US and UK keyboards.
TEST=Crazy double inputs of "\" and "|" when pressing shift and
backslash at the same time on US keyboard no longer happens.
TEST=Different repeat behavior when holding backslash and other keys
together on US keyboard no longer happens.

Change-Id: I175f335008fc2e6bb4118e9de013870e769b1df7
Signed-off-by: Doug Anderson <dianders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/180494
(cherry picked from commit 3c56a5a6c1c69306371a4d5f37762044c87e4216)
Reviewed-on: https://chromium-review.googlesource.com/180876
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: mfd: cros_ec: Create sysfs attributes for the ChromeOS EC.

This adds the first few sysfs attributes for the Chrome OS EC. These
controls are made available under /sys/devices/virtual/chromeos/cros_ec

  flashinfo   - display current flash info
  reboot      - tell the EC to reboot in various ways
  version     - information about the EC software and hardware

Future changes will build on this to add additional controls.

BUG=chromium:239205
TEST=manual for now, autotest coming soon (crbug.com/334014)

From a root shell, you should be able to do things like this:

  cd /sys/devices/virtual/chromeos/cros_ec
  cat flashinfo
  cat version
  echo rw > reboot
  cat version
  echo ro > reboot
  cat version
  echo rw > reboot
  cat version
  echo cold > reboot

That last command will reboot the AP too.

Original-Change-Id: I4b16245b855b6a71baa1f9001ef484f6a6115d4f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/176840
Reviewed-by: Olof Johansson <olofj@chromium.org>
(cherry picked from commit 311a3fceab6de8a33e9aa337cbd97123fd3b5be2)
Change-Id: Iddbb0753c7ce489c62eb7aa8fbc5b0e1186690a7
Reviewed-on: https://chromium-review.googlesource.com/183012
CHROMIUM: input: cros_ec_keyb: clear buffer only when not a wake device

According to the comment there, we should clear the EC's key scan buffer
only when it's *not* a wake device.

BUG=none
TEST=suspend/resume test with EC wake up & suspend_stress_test over 3000
interations

Change-Id: Ic657ea24b964e82e5fe6070904442d001fe32a82
Signed-off-by: Joseph Lo <josephl@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/186944
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: mfd: cros_ec: Expose Chrome OS Lightbar to users

This adds some sysfs entries to provide userspace control of the
four-element LED "lightbar" on the Chromebook Pixel. This only instantiates
the lightbar controls if the device actually exists.

To prevent DoS attacks, this interface is limited to 20 accesses/second,
although that rate can be adjusted by a privileged user.

BUG=chromium:239205
BRANCH=none
TEST=manual (autotest coming soon: crbug.com/343270).

On Chromebooks without a lightbar, this should have no effect. On the
Chromebook Pixel, you should be able to do things like this:

    $ cd /sys/devices/virtual/chromeos/cros_ec/lightbar
    $ echo 0x80 > brightness
    $ echo 255 > brightness
    $
    $ cat sequence
    S0
    $ echo konami > sequence
    $ cat sequence
    KONAMI
    $
    $ cat sequence
    S0

And

    $ cd /sys/devices/virtual/chromeos/cros_ec/lightbar
    $ echo stop > sequence
    $ echo "4 255 255 255" > led_rgb
    $ echo "0 255 0 0  1 0 255 0  2 0 0 255  3 255 255 0" > led_rgb
    $ echo run  > sequence

Test the DoS prevention with this:

    $ cd /sys/devices/virtual/chromeos/cros_ec/lightbar
    $ echo 500 > interval_msec
    $ time (cat version version version version version version version)

It should take about three seconds. An autotest is coming soon
(crbug.com/343270).

Combining two commits from the 3.8 branch into one (first, plus bug fix):

Original-Change-Id: I68133f212962e382ccf9b6605e2126b39f6e491f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/183140
Reviewed-by: Olof Johansson <olofj@chromium.org>
(cherry picked from commit 6142f30455f19ec826a415d29fab1df011174c55)
Original-Change-Id: I606dc59c0095c0122a3b7706eae495dc1de04021
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/186363
Tested-by: Doug Anderson <dianders@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
(cherry picked from commit 0e90742902650946a695f0f6318668212b53c562)

Change-Id: Ie6b2dadf144a9896be90ba0d54ab180f8587b327
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187680
Reviewed-by: Benson Leung <bleung@chromium.org>
CHROMIUM: cros_ec: Expose EC accelerometer data through sysfs

Adding iio driver to expose EC accelerometer up through sysfs.
You can manually read each accelerometer channel, or you can set
up a sysfs trigger to trigger collection of multiple channels at
once and stuff it into a buffer which can be read as a char
device.

Also added to cros_ec a function to read from EC shared memory.

The cros-ec-accel and iio-trig-sysfs modules are automatically
loaded if while register cros-ec we detect that the EC has
accelerometers

BUG=chrome-os-partner:26027
TEST=manual

On chromebook with accelerometer:

$ cd /sys/bus/iio/devices
$ echo 0 > iio_sysfs_trigger/add_trigger
$ cd iio:device0
$ echo "sysfstrig0" > trigger/current_trigger
$ echo 1 > scan_elements/in_angl_en
$ echo 1 > buffer/enable

And trigger a capture with:

$ cd /sys/bus/iio/devices
$ echo 1 > trigger0/trigger_now

Then, read from the char device to make sure we are getting lid angle and timestamp:

$ od -x /dev/iio:device0

Change-Id: I39e61539c3377ed20b95eafa133305cb62b6e48b
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/186307
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
CHROMIUM: cros_ec: Add host commands to cros_ec_accel driver

Added ability to modify accelerometer parameters to the cros_ec_accel driver
by sending host commands to EC. This adds four new sysfs files:
sampling_frequency for the rate at which the EC samples all motion sensors (in ms),
peak_scale is the max range setting of the sensor (in +/- G's), frequency
is the setting for output data rate (ODR) of the accelerometer, and lid angle
offset is the lid angle threshold for the EC to be in tablet mode in which
the keyboard is not used as a wake source in S3.

BUG=chrome-os-partner:27321
TEST=manual
On chromebook with accelerometer, tested that I can read/write to sampling
frequency, accelerometer frequency (ODR), and peak scale (sensor range).
Each of these require a host command to the EC. Note that when writing to
the peak scale and frequency, the EC rounds the input arg up to the nearest
valid value.

$ cd /sys/bus/iio/devices/iio:device0
$ cat in_accel_lid_sampling_frequency
10
$ echo "150" > in_accel_lid_sampling_frequency
$ cat in_accel_lid_sampling_frequency
150

$ cat in_accel_lid_peak_scale
2
$ echo "5" > in_accel_lid_peak_scale
$ cat in_accel_lid_peak_scale
8

$ cat in_accel_lid_frequency
100000
$ echo "25000" > in_accel_lid_frequency
$ cat in_accel_lid_frequency
50000

$ cat in_angl_offset
180
$ echo "210" > in_angl_offset
$ cat in_angl_offset
210

Change-Id: Ic6b384e9bf3f974c854edb094c1f9a7cd9a26763
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/192722
Reviewed-by: Olof Johansson <olofj@chromium.org>