Commit Graph

616 Commits

Author SHA1 Message Date
Scott Collyer
be2c5fa602 tcpci: Change role control setting for auto-toggle enable
In tcpci_tcpc_drp_toggle the role control is being set to
TYPEC_CC_OPEN. This works for the parade tcpci compliant tcpc, but
does not work the anx7447. The tcpci spec has this description for the
role control requirement (4.4.5.2):

If DRP=1b, the only allowed values for CC1/CC2 are Rp/Rp or Rd/Rd.
COMMAND.Look4Connection shall do nothing if CC1/CC2 are not Rp/Rp or
Rd/Rd.

This CL changes the role control setting associated with starting
auto-toggle to be TYPEC_CC_RD.

BUG=b:77544959
BRANCH=NONE
TEST=Verfied that anx7447 does auto toggle between Rd and
Rp. Previously, the TCPC_REG_COMMAND_LOOK4CONNECTION command was being
ignored.

Change-Id: Iea7ce963ebf57c0f3d43005385484913d97774fd
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1005795
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: S Wang <swang@analogix.corp-partner.google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-04-11 14:55:37 -07:00
Jett Rink
00f800dd63 tcpci: add vbus caching back for tcpci except in parade driver
This effectibly reverts CL:993394 except for the parade driver

BRANCH=none
BUG=b:77458917
TEST=yorp p1 still works

Change-Id: I04a57cfcbd19e9f8fdf8165c228a24089c0e1b67
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1005403
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-04-10 19:13:17 -07:00
Scott Collyer
9466bef89b nx20p3483: Fix VBUS OVLO threshold and dead battery mode check
If the board is not powered until VBUS is connected, then that port
will trigger dead battery mode in the PPC. This mode must be exited by
the host (EC) writing to the control register. Until dead battery mode
is exited, VBUS OVLO is fixed at 6.8V. Therefore the regular setting
of this value must be done after exiting dead battery mode.

This CL also changes the check for dead battery mode to use the mode
value in the device status register. The bit in the control register
does not reflect the status, but rather, if dead battery mode exit has
been written by the host. The current check will result in the dead
battery mode section being executed for both ports after every power
up. However, only the port that has VBUS active would succeed because
the HV_SNK mode can't be enabled unless VBUS is present.

Lastly, this CL changes the verification check for the
sink/source_enable functions to rely on the mode in the device status
register instead of the switch state. The reason for this is that the
switch state requires ~15 msec delay before it gets updated following
SNK_EN to the nx20p3484 being set high. However, the mode reports the
correct state without reqiuring a msleep.

BUG=b:77561535
BRANCH=NONE
TEST=Tested both port 0 and 1 and verified that Yorp can power up
without a battery. In addition verified that
nx20p3483_vbus_sink_enable returns EC_SUCCESS for both enable/disable
cases.

Change-Id: I2c993b592cd30e34a39d1c1b7e3c54be9f505844
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1005621
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-04-10 19:12:55 -07:00
Scott Collyer
db8d6edf26 ppc: Add tcpci snk/src control via the COMMAND register
The ANX7447 has a sink/source control lines which can be connected to
a PPC. The NX20P3483 PPC requires this control to set it's sink/source
switch control. The ANX7447 contols these lines via the tcpci COMMAND
register. This CL adds new tcpm_set functions to set either SNK or SRC
control via the COMMAND register.

BUG=b:77583452
BRANCH=NONE
TEST=Tested on port 0 of Yorp with an external charger. Prior to this
CL the PPC would remain in standby state because both snk/src control
remained low. With these changes, verifed that snk_ctrl is driven high
and vbus_sink_enable() function no longer returns an error.

Change-Id: Icbea0d3edb63ad19f3d2c76636208497b6939a72
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/996239
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-04-10 19:12:48 -07:00
Jett Rink
c8814430d6 yorp: add more USB-C power logic
* TCPC reset
* PPC input charging (current/voltage limits)
* PPC output charging
* VBUS presence detection

BRANCH=none
BUG=b:74127309,b:77458917,b:77579760
TEST=yorp C1 can negotiate 20V at 3A

Change-Id: Ifa84071be1617a060a217d00bc102d836edffe95
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/991081
2018-04-10 19:12:47 -07:00
Jett Rink
33e91c211f tcpc: verify that i2c_read for vbus succeeds
If we cannot contact the TCPC, then we need to assume the safer value
of VBus level (i.e. off)

BRANCH=none
BUG=b:77458917
TEST=yorp C1 still works

Change-Id: I1fc1898a7dc554d050cd3612616531cb74de7261
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/995959
Reviewed-by: Divya S Sasidharan <divya.s.sasidharan@intel.com>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-04-10 10:57:38 -07:00
Gwendal Grignou
a796f04b1a FIXUP: driver: lsm6dsm/lsm6dsl: Add FIFO support
Returns an error if the ODR set is less than 13Hz instead of silently
put the sensor in suspend mode.

BUG=b:77601149
BRANCH=None
TEST=Check with accelrate we get an error instead of
"Data rate for sensor 0: 0"

Change-Id: Iead740f4205bbce1cfbccf2407f2a3a0dcf0ddaf
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1000399
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-04-10 10:57:31 -07:00
Jett Rink
d105ac0f77 yorp: fix inverted logic for dead battery mode
BRANCH=none
BUG=b:77561535
TEST=yorp P1 can still boot without battery

Change-Id: Ifa327e2989ac3dfe260b570edbc23add4910e09f
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/998410
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2018-04-06 14:44:14 -07:00
Jett Rink
7e50bfd037 ppc: enter SNK mode before leaving dead battery mode
If we don't enable the SNK mode before leaving dead battery mode
(which does keep the inflow path open), then we will brown out
our only source of power.

BRANCH=none
BUG=b:77561535
TEST=yorp can boot into ec without battery

Change-Id: I095e3cb1ed466fd6497bbc9e7b6851fc92005c75
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/999024
Reviewed-by: Scott Collyer <scollyer@chromium.org>
2018-04-05 22:12:48 -07:00
Mario Tesi
87e769a87e driver: lsm6dsm/lsm6dsl: Add FIFO support
Added FIFO support to Acc and Gyro with
watermark interrupt management.
Watermark is configurable setting macro
CONFIG_ACCEL_FIFO_THRES properly (board.h)

BUG=b:73546254
BRANCH=master
TEST=Pass CTS test cheets_CTS_N.7.1_r15.x86.CtsHardwareTestCases
on meowth.
TEST=Tested on discovery (target stmems) BOARD with LSM6DSM
connected to EC i2c master bus.

Using motion sense console commands is possible to:
 - enable sensor (accelinit 0, accelinit 1 for acc and gyro)
 - set ODR (accelrate 0 x, accelrate 1 y where x, y are mHz)
 - show sensor data (accelinfo on <time> where time is in ms)

Using this procedure is possible to see Green Led of Discovery Board
Blinking each time an interrupt from FIFO arrives. To be sure to
generate interrupt is better to use high ODR and low time in accelinfo.

Change-Id: Icf95b0e889dc806206b8ca50e74636e6a2441a18
Signed-off-by: Mario Tesi <mario.tesi@st.com>
Reviewed-on: https://chromium-review.googlesource.com/467326
Commit-Ready: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2018-04-05 18:41:12 -07:00
Dylan Lai
82a357a385 TCPM: Add TCPM driver for Analogix anx7447 chip
Driver implements TCPC for ANX7447 chip. Enable Type C
port for USB and DP alt mode.

BUG=b:73793947
BRANCH=NONE
TEST=tested compiled binary for pdeval-stm32f072 board with this patch.
Power contract establishment, port role swap, DP alt mode works fine.

Change-Id: Ic11e499fc5fb4aba7732c75e4cb2fee54828c616
Reviewed-on: https://chromium-review.googlesource.com/956790
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Scott Collyer <scollyer@chromium.org>
2018-04-03 21:40:51 -07:00
Jett Rink
228dc8d119 tcpci: remove vbus level caching
On yorp, the PS8751 TCPC resets its event mask when it goes into low
power mode which turns off the VBUS detection event mask. Since the
first interrupts after lower power mode should contain the vbus
changed interrupt we miss it.

We have tried many different permutations of resetting the event mask
on reset without achieving 100% detection success.

The PPC Vbus detection code calls out to the PPC over i2c every time
vbus level is checked; applying that strategy for TPCPs make the
detection much more robust.

BRANCH=none
BUG=b:77458917
TEST=yorp detect vbus on insertion every time with PS8751

Change-Id: I15b5f2ee016f68bac9e4bf4d5d89bbaef323f131
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/993394
Reviewed-by: Scott Collyer <scollyer@chromium.org>
2018-04-03 18:47:09 -07:00
Philip Chen
d3a6a8d82e battery/max17055: Check/Reload the battery profile
When the wrong battery profile is loaded into max17055, we need
to be able to recover it after EC POR by reloading the correct profile.

BUG=b:77491650
BRANCH=scarlet
TEST=First, unplug/replug battery many times until I see
the battery profile loaded is wrong (1/20).
Second, make sure after a hard reset the correct battery profile
is loaded.

Change-Id: Iabb24fc75d31b9ce87bfb835e03549f4726903ed
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/991192
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
2018-04-03 01:29:16 -07:00
Gwendal Grignou
94eaba49b0 driver: lsm6dsm: Fix ODR rate calculation
rate was wrong, but round up was saving us.

BUG=b:73546254
BRANCH=none
TEST=Check register is set correctly even when roundup is 0.

Change-Id: I4cf11291345ccfaacd1fc9942a3f112b460268c1
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/986917
Tested-by: Gwendal Grignou <gwendal@google.com>
Reviewed-by: Gwendal Grignou <gwendal@google.com>
2018-04-02 16:26:46 -07:00
Philip Chen
f319a80975 scarlet: Enable charge termination only when battery is present
If we enable charge termination when booting w/o battery,
charge termination would trigger and cut the power for max17055.

BUG=b:72697658
BRANCH=scarlet
TEST=Read rt946x reg 0x02, confirm charge termination is
disabled when booting w/o battery, and enabled otherwise.

Change-Id: I5780196ad993299ddfb37621bee5e941aa9b0d14
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/989314
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
2018-03-31 01:56:32 -07:00
Philip Chen
1a38513538 battery/max17055: Report BP_NOT_SURE before battery detection finishes
After a POR, max17055 takes ~2.5 seconds to finish the detection
for battery absence.
Let's report BP_NOT_SURE instead of the default BP_YES when the battery
detection result is not settled yet.

BUG=b:72697658
BRANCH=scarlet
TEST=boot scarlet w/o battery and confirm battery_is_present()
never return BP_YES before reporting BP_NO

Change-Id: Ia549b4b78a7403ce2c82802841b78bdd514c6200
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/989313
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
2018-03-31 01:56:30 -07:00
Jett Rink
ffa4054760 usbc: add default I2C addresses
Add hard coded I2C addresses as defined by datasheet.

BRANCH=none
BUG=none
TEST=none

Change-Id: Ia69cc4da7474a9c1f8a994d33db88e0a405f02b7
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/982561
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-03-28 16:40:40 -07:00
Nicolas Boichat
bd49214121 isl923x: Set OTG enable debounce time to 150ms
The default setting is to wait 1.3s from receiving the command, to
enable the OTG output: that's too long, and makes time to active
base very long when running on battery.

BRANCH=none
BUG=b:76396020
TEST=Probe POGO 1/5 and one of the USB lines, check that time from
     connect to active USB is reduced to 580 ms (from 1920 ms).

Change-Id: Iee00fd27978434ccac052e60a94534919dc29f43
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/981853
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-27 20:35:01 -07:00
Wei-Han Chen
9ea406a2f8 driver/touchpad_st.c: implement touchpad fw update
BRANCH=none
BUG=b:70482333
TEST=make BOARD=whiskers
TEST=sudo ./extra/usb_updater/usb_updater2 -d 18d1:5030 -p <file>
Signed-off-by: Wei-Han Chen <stimim@chromium.org>

Change-Id: I6e3e73a01571ae4cf31891edca588c44e5f41194
Reviewed-on: https://chromium-review.googlesource.com/958896
Commit-Ready: Wei-Han Chen <stimim@chromium.org>
Tested-by: Wei-Han Chen <stimim@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-03-27 08:06:03 -07:00
Wei-Han Chen
d8225540d9 ec: add driver/touchpad_st.c
Initial commit for ST touchpad.
This CL will support X/Y mode function.

BRANCH=none
BUG=b:70482333
TEST=make BOARD=whiskers
TEST=manually test touchpad function on whiskers
Signed-off-by: Wei-Han Chen <stimim@chromium.org>

Change-Id: I1669286ca764fbbd4a691171193415dd4999673f
Reviewed-on: https://chromium-review.googlesource.com/958894
Commit-Ready: Wei-Han Chen <stimim@chromium.org>
Tested-by: Wei-Han Chen <stimim@chromium.org>
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-03-26 23:33:33 -07:00
Marco Chen
67ee456782 sensor: bmi160/bma2x2: Fix the timeout value of compensation.
CL:957872 introduced "get_time().val + 400" as the deadline to perform
compensation and the comment in bma2x2.c mentioned the deadline should be
400ms. But the unit of val in timestamp_t is microsecond not milisecond
so only 400us is defined not 400ms.

BRANCH=none
BUG=b:76234078
BUG=b:76202592
TEST=test manually on the dut by performing calibrate.

Change-Id: I7a834ef6dcb0772569d2c8d6c507803deb5d2fc1
Signed-off-by: Marco Chen <marcochen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/979512
Commit-Ready: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2018-03-26 14:41:34 -07:00
Philip Chen
f59290878e battery/max17055: Report the raw measured current
BUG=b:74321682
BRANCH=scarlet
TEST=battery command shows current change instantaneously when
AC charger is plugged/unplugged

Change-Id: Ic47efbdfc861355325ee2c69be09fbcfa1394654
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/977022
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-23 17:29:48 -07:00
Jett Rink
ca204befd3 tcpc: rename CONFIG_USB_PD_TCPM_ANX74XX to CONFIG_USB_PD_TCPM_ANX3429
Since all of the uses of CONFIG_USB_PD_TCPM_ANX74XX are actually for
ANX3429, rename the option especially since the ANX7447
driver will not reuse the ANX74XX driver which is being introduced
in CL:956790.

Also adding the CONFIG_USB_PD_TCPM_ANX740X and
CONFIG_USB_PD_TCPM_ANX741X options to advertise which versions of the
ANX chip the anx74xx.c driver applies to.

BRANCH=none
BUG=chromium:824208
TEST=build all

Change-Id: Ib47f4661466e54ff2a0c52d517eb318d3bfd25a2
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/973558
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2018-03-23 14:50:51 -07:00
Divya Sasidharan
b9fbc80fa3 usb_mux: Fix incorrect revision check at init for ps874x
This patch fixes revision check for ps8xxx usb mux and
thereby removing print "Error initializing mux port(x)"
at bootup.
This is just a cosmetic change and should not affect any
functionality.

BUG=none
BRANCH=glkrvp
TEST=On glkrvp: Boot up the system to verify the
     error message setting mux is gone at init.

Change-Id: I0926077d50e818bd93aaa4214106b2f8067d9710
Signed-off-by: Divya Sasidharan <divya.s.sasidharan@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/846291
Commit-Ready: Divya S Sasidharan <divya.s.sasidharan@intel.com>
Tested-by: Divya S Sasidharan <divya.s.sasidharan@intel.com>
Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2018-03-22 18:16:50 -07:00
Philip Chen
9aee2a19e8 battery/max17055: Implement battery_status()
BUG=b:74841068
BRANCH=scarlet
TEST='/sys/class/power_supply/sbs-9-000b/status' shows
discharging/charging/full status correctly

Change-Id: I4216ba2d95ac82a9f600d8685d993cb5b37206d8
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/969747
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-21 13:25:57 -07:00
Scott Collyer
261afe62f3 ppc: Add driver for NX20P3483
The NX20P3483 is a USB PD and Type C high voltage sink/source combo
switch. This CL adds support for this PPC variant. Unlike the TI
SN5S330, the NX20P3483 does not support VCONN and does not need to be
informed of CC polarity by the TCPM. To account for these differences,
2 new PPC config options are added and the driver for the TI SN5S330
was modified to include these new options.

The SNK/SRC switch mode for the NX20P3483 is controlled by 2 GPIO
signals which may be connected the EC or directly to the TCPC. To
handle both cases, the ppc_chips structure was modified with a flags,
snk_gpio, and src_gpio elements.

BUG=b:74206647
BRANCH=none
TEST=make -j buildall and verified there are no build errors.

Change-Id: Ic4415ab7571b80e7661ea673434eaf4cf1f1fd2d
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/966926
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2018-03-20 19:30:17 -07:00
Gwendal Grignou
3d3a009f49 driver: lsm6dsm: fix units
Units must be reported in according to the range.
2g means 1<<15 should be returned when accel is 2g.
Actually accelerometer report units in mg.

BUG=b:73546254
BRANCH=master
TEST=Check with accelinfo with 2g gain Z ~= 1<<14.

Change-Id: I218210ca8305ecbe76a681b535f3d75f3a6bea52
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/924408
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-19 19:21:21 -07:00
Gwendal Grignou
94f5413159 driver: lis2dh: fix gain units
Accelerometer reports accelerating in mg. Fix gain to that full range
(2g, 4g or 8g) returns 2<<15.

BUG=b:73546254
BRANCH=master
TEST=compile

Change-Id: I2873a641985fa800709a2d30b031c2b6e3fcb39e
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/924407
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-19 19:21:21 -07:00
Gwendal Grignou
88613a3aa2 driver: accel_lis2dh: Fix interface
Add support in ectool, expose min/max ODR.

BUG=b:73546254
BRANCH=master
TEST=compile

Change-Id: Ib09c06e17d7d73aaab91680672de4d5267299c7f
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/924405
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-19 19:21:19 -07:00
Gwendal Grignou
47f344713e driver: lsm6dsm/lsm6dsl/lis2dh: Use STM MEMs common functions
LSM6DSM now use STM MEMs common functions already
used by LIS2DH12 device. Added st_raw_read_n_noinc
function to read i2c data not using auto increment
protocol.

BUG=b:73546254
BRANCH=master
TEST=Tested on discovery BOARD with LSM6DSM sensor connected on
I2C master bus interface of target board.
Using motion sense console commands is possible to enable, set data
rate, set full scale and show data from sensor (acc and gyro).
Commons function works properly for LSM6DSM.

Change-Id: I7a987306135a85abcfa9c1d3ba596fb70598fadc
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/465376
2018-03-19 19:21:18 -07:00
Yidi Lin
7640df67aa driver: kionix: Add software reset flow for KX022
Kionix suggests that it is recommended to issue the Software Reset
command after the device was powered. This is effective against
dynamic or non-linear behavior of a power supply or unexpected
noise above normal on the power rail during a power up.

BRANCH=eve
BUG=b:62607555
TEST=kx022:
     1. press power button 10 second to power off.
     2. power on the DUT
     3. refresh + power button to cold reboot the DUT
     4. Check the g-sensor by 'ectool motionsense'
     kxcj9:
     eve: sensor kxcj9 found.

Signed-off-by: Yidi Lin <yidi.lin@mediatek.com>
Reviewed-on: https://chromium-review.googlesource.com/536723
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
(cherry picked from commit 5a52614b8c87ab1de84c461b7bbd0b4a14dc7fdb)
 Conflict in init routine in accel_kionix.c.
 By moving WHOAMI after reset, we expect the test to work the first
 time.)
Change-Id: I362f2af59253519aa35b72cfb6b666c49e425777
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/753969
2018-03-19 17:04:54 -07:00
Gwendal Grignou
c577880b79 Revert "driver: kionix: Add checking whoami value at initialization."
This reverts commit 1d8fcd4fab.
It looks like KXCJ9 may not return proper WHOAMI after powerup
but before reset.

BUG=b:67865186
BRANCH=eve
TEST=compile

Change-Id: Iceaaf3b2a45d920e08db587e1308cec0379e68cf
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/753967
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-19 17:04:52 -07:00
Gwendal Grignou
cf30d5c29d driver: bma2x2: Add perform_calib
Add fast compensation automatic calibration, like bmi160.
Use timestamp_expired for timeout measurement for both perform_calib
functions.
Remove driver offset field, remove private bma2x2 structure.

BUG=b:73205042
BRANCH=master
TEST=echo 1 > calibrate perform calibration.
Reading in_accel_*_calibbias is within range.
Check on Lami for both bma2x2 and bmi160.

Change-Id: I3472865287fa4769a05e6f872b92d7c3f933cb4e
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/957872
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-03-16 13:29:58 -07:00
Gwendal Grignou
e0a2a98b69 driver: sensor: Remove set_resolution when NOOP
set_resolution is only used for few sensors and is not exposed to the AP.
Remove definition when sensors have a fixed resolution.

BUG=none
BRANCH=master
TEST=compile, kevin has enough space for perform_calib.

Change-Id: I8482387e135356467edaee44da3a0e47cf1db524
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/961222
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-15 21:23:30 -07:00
Gwendal Grignou
9e95ac3e0a driver: kionix: Use base accelgyro structure
Unify get_range/get_datarate by using accelgyro_saved_data_t
structure.

BUG=none
BRANCH=none
TEST=compile

Change-Id: I0bfa2f06c5dd2021a5af9e6499c97e65988167ce
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/961221
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-15 17:58:02 -07:00
Gwendal Grignou
7ce651d4ca driver: bma2x2: Remove tables for range/frequency
To save space, instead of using tables, use macros to convert
range/frequencies into register values.

BUG=b:73205042
BRANCH=none
TEST=Check we save space on Kevin. (184 bytes looking at __image_size in
kevin.RO.map).
Check on nami that range/bandwidth are set properly.

Change-Id: I193768be1f2e7325b986e8ccff25a7809bfb4096
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/959388
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-03-15 17:58:01 -07:00
Philip Chen
ccea4b67f2 battery/max17055: Fix the unit of cycle count
The cycle counts we get from battery_cycle_count()
is in the unit of 1%.
But we should convert it to absolute count to match
the behavior of a smart battery.

BUG=b:74576000
BRANCH=scarlet
TEST='ectool battery' shows reasonable cycle counts

Change-Id: I9d351f8766c90e0addb72a088917ddadfa6c840a
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/961303
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-14 04:07:09 -07:00
Aseda Aboagye
e325981c7d driver: OPT3001: Re-order application of scale.
This commit simply reorders the application of scale in order to
preserve the sensor precision.

BUG=b:72985601
BRANCH=stabilize-meowth-10444.B
TEST=Flash meowth; Set scale to 1000; Verify that more significant
digits are present compared to before.

Change-Id: Ibf46e574fccdde50ceb5f8174f9b4a29e60bfbfe
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/955967
Commit-Ready: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2018-03-14 04:07:08 -07:00
Alexandru M Stan
4a1d2e3daf sensors: Add driver for SYNC
Useful for recording the exact time a gpio interrupt happened in the
context of sensors.

Adding it for camera vsync purposes.

BUG=b:67743747
TEST=With next patch see it work on scarlet.
BRANCH=master

Change-Id: Ic8e8fb444e08200e5d8daded8b4a5920b13431ac
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/850580
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2018-03-14 04:06:53 -07:00
Alexandru M Stan
b63595258d motion: Lower jitter of Sensor->EC timestamp
Instead getting the time for each sample in the task code, we should be
getting it as soon as the sensor reported it added it to its fifo (so
sensor just finished integration).

Because of that each sensor should provide the time when it provides a
sample, ideally from an accurate spot like an interrupt.

Deprecate motion_sense_fifo_add_unit (without a timestamp) in favour of
motion_sense_fifo_add_data (which adds the timestamps). Update all
relevant sensors to use the new api.

Note: for now I focused on the BMI160, where I actually made it get the
time in the interrupt. The other sensors were made to use the new api,
but still don't record the time in the right place (though it's not any
worse than before).

BUG=b:67743747
TEST=In the kernel, fifo_info->info.timestamp still has sane values.
TEST=CTS should still pass
BRANCH=master

Change-Id: I9829343f8702e00cc19f9c88134fa1f258c9e1e9
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/807331
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2018-03-14 04:06:52 -07:00
Gwendal Grignou
8e8d5a63e6 driver: bma2x2: indent register definition
BUG=none
BRANCH=none
TEST=compile

Change-Id: I9507cbe760f886acaa4c6b432cfd8482faeb4618
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/959387
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2018-03-12 20:57:08 -07:00
Philip Chen
b8423e0669 charger/rt946x: Enable charge current termination
BUG=b:74373538
BRANCH=scarlet
TEST=confirm charge current drops to 0mA right after
it hits 400mA, when battery is nearly fully charged

Change-Id: Icd4a7886bf68f3bd4ed91d2b8e705cb62f6e4fb8
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/958295
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-by: David Schneider <dnschneid@chromium.org>
2018-03-12 20:57:02 -07:00
Philip Chen
a4621c5e64 charger/rt946x: Limit ADC timeout to 50ms
In practice, ADC conversion rarely takes more than 35ms.
However, according to the datasheet, ADC conversion may take
up to 200ms. But we can't wait for that long, otherwise
host command would time out. So here we set ADC timeout as
50ms. If ADC times out, we just return the last read vbus_mv.

BUG=b:70641844, chromium:780364
BRANCH=scarlet
TEST=test 'ectool usbpdpower' for 50k cycles
w/o seeing host command timeout

Change-Id: I09c3abf729e96b113f7a0f64a67cd35906da9e3e
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/956900
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
2018-03-09 20:05:18 -08:00
Jett Rink
b593d1c05b bc12: add support for active low/high on all gpio signals
yorp inverts both bc12 signals and the bc12 driver needs to handle
the inverted logic

BRANCH=none
BUG=b:74127309
TEST=none

Change-Id: I6848375fc652251aecb553c3f53d62a5f775bec4
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/956321
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2018-03-09 20:05:12 -08:00
Gwendal Grignou
bc766130be motion: remove load_fifo
To prevent invalid timestamping, call load_fifo only when we get a FIFO
interrupt.
In consequence, remove load_fifo entry point and only process fifo
inside the IRQ.

Add helper function to know when we are in forced mode (the EC needs to
periodically read sensor data or interrupt driven).

BUG=b:73557414
BRANCH=master
TEST=compile

Change-Id: I959e476f3f7215be95424c07223f7421e8b13da1
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/938146
Commit-Ready: Alexandru M Stan <amstan@chromium.org>
Tested-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
2018-03-09 20:05:06 -08:00
Alexandru M Stan
f31dcc649a sensor: bmi160: Don't batch data on the sensor
Set the sensor side fifo watermark to interrupt the EC as soon as
there's any data in there, that way we get more frequent accelerometer
interrupts (which is handy when you want to mark down the time of each
sample accuratelly).

BUG=b:67743747
TEST=Sensor should still be working normally, the ec will probably start
recieving sensor interrupts (before this was probably not the case).
BRANCH=master

Change-Id: I726550e68447a74bbfed88b703d2f68b6967ac93
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/956626
Commit-Ready: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
2018-03-09 20:05:05 -08:00
Nicolas Boichat
49f76d0c86 isl923x: Round up requested OTG current
Without this patch, requesting 100mA or output current would be
rounded down to zero.

This would also cause other issues when doing base/lid and lid/base
power transfers on lux/wand, as the input current has a much finer
grain control, which could lead the input charger to brown out
the output charger.

BRANCH=none
BUG=b:67920792
TEST=Flash lux/wand, lux can provide as little as 100mA of current
     successfully.

Change-Id: Ibf170a6ee3c2dfbdbbc03948c3b0e6ab878eee47
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/956660
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-03-09 07:17:50 -08:00
Philip Chen
b14b974ee4 tcpm/fusb302: Update VBUS supplier when VBUS level changes
To enable USB charging on boards where fusb302 takes care of VBUS detection

BUG=b:65446459
BRANCH=none
TEST=on Scarlet rev3, verify VBUS supplier is updated based on
whether VBUS is present - plug/unplug USB2 charger, boot with USB2
charger plugged.

Change-Id: I50177d40b0eb0490634ad2f103306e0079633fbe
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/905401
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-03-08 14:04:40 -08:00
Philip Chen
9896e428f7 Introduce CONFIG_USB_PD_5V_CHARGER_CTRL
Add a new config for the boards using charger (e.g. rt946x)
to report if VBUS source is enabled instead of using GPIO.

BUG=b:65446459
BRANCH=none
TEST=Charge Scarlet rev3 with SDP and DCP.

Change-Id: Id0a07945f0f888b6a36c422c596b56c5aa5065c0
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/905400
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-03-05 00:21:22 -08:00
Elmo_Lan
6790a884a4 Nami: add keyboard backlight function
Base on LM3509 chip. Add file LM3509.C and LM3509.H
to control keyboard backlight when S0/LidOpen is turn on,
others is turn off.

BUG=b:73055990
BRANCH=none
TEST=Verify keyboard backlight function in resume and suspend.
S0/LidOpen is turn on; S4/S5/G3/LidClose is turn off.

Change-Id: Ief9e385f969c9dfc9e8f0d4e47ea7803cee747aa
Signed-off-by: Elmo_Lan <elmo_lan@compal.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/881081
Commit-Ready: Raymond Chou <raymond_chou@compal.corp-partner.google.com>
Tested-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com>
2018-03-02 22:22:34 -08:00