summaryrefslogtreecommitdiff
path: root/driver/als_tcs3400.c
Commit message (Collapse)AuthorAgeFilesLines
* drivers/tcs3400: don't apply zero scale.Jongpil Jung2019-12-271-0/+4
| | | | | | | | | | | | | | | | | EC will be broken with scale zero. So, we need to check scale value before we apply value. BUG=b:146868237 TEST=emerge-hatch chromeos-ec and flash ec on device. apply zero scale into rgb sensor. (clear, red, green and blue) echo "0" > /sys/bus/iio/devices/iio\:device6/in_illuminance_calibscale BRANCH=none Change-Id: I716ae805ff1742ddd45dbbdfd956beb1c22d5a6c Signed-off-by: Jongpil Jung <jongpil19.jung@samsung.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1982294 Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Nick Vaccaro <nvaccaro@google.com>
* drivers/tcs3400: don't add offset for LUXNick Vaccaro2019-12-121-2/+23
| | | | | | | | | | | | | | | | When translating RGB to XYZ, don't add in the offset value for LUX. BUG=b:144319657 BRANCH=NONE TEST="make -j BOARD=kohaku", flash EC on kohaku, place kohaku in a dark location and verify it reads 0. Change-Id: I4c6dcc01999ca5e4390f97c31e50b27075ed9ce4 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1959458 Tested-by: Mengqi Guo <mqg@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* drivers/tcs3400: add IR scaling factorNick Vaccaro2019-12-121-8/+14
| | | | | | | | | | | | | | | | | | | | | | | | This change adds a new scaling factor used in IR separation that further improves sensor CCT accuracy. The following restructure of calibration structure was required : - renamed rgb_calibration_t struct to rgb_channel_calibration_t - added new rgb_calibration_t structure definition to include new irt scaling factor to the rgb calibration structure BUG=b:143246741 BRANCH=master TEST=none Cq-Depend: chromium:1879189 Change-Id: Idb3325be828e8ed15747144670230963c369a461 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879188 Tested-by: Mengqi Guo <mqg@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Mengqi Guo <mqg@chromium.org> Reviewed-by: Scott Collyer <scollyer@chromium.org>
* drivers/tcs3400: fix a couple values in lux tableNick Vaccaro2019-09-091-5/+5
| | | | | | | | | | | | | | | | | | | | | | A couple of the values in the lux atime table needed adjusting as they were too aggressive and were causing train-up / saturate / train-down / repeat... pattern cycles. Allow device to upshift in training when we're >= 2.5x from saturation (was >= 3x). Fixed a couple of nits. BUG=b:139749448 BRANCH=master TEST=Walked a flapjack through each lux light level, with a test at the low end of the level and a test at the high end of each level (i.e. for LUX level 1000, tested at 1100 and 1900 LUX), assure the tcs3400 doesn't go into saturation while trying to hit the 90% band. Change-Id: I84c5bf09e072e96d516d91520a176fa35274ce7a Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1767598
* config: Refactor CONFIG_ACCEL_FIFO to enable use of IS_ENABLEDYuval Peress2019-09-031-10/+8
| | | | | | | | | | | | | | | This change allows us to use the IS_ENABLED condition to replace the various ifdef guards around the CONFIG_ACCEL_FIFO BUG=b:137758297,chromium:981990 BRANCH=None TEST=buildall and CTS tests on Arcada Change-Id: I65d36bac19855e51c830a33e6f3812575e8d15d9 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704164 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* common: Move fifo logic out of motion_sense.cYuval Peress2019-08-231-0/+1
| | | | | | | | | | | | | | | | | | | | This change is needed to allow better testing of the fifo behavior. Additionally, motion_sense_fifo.c will only be compiled if CONFIG_ACCEL_FIFO is defined. This behaviour requires a few small changes to several boards and baseboards to make sure that we only define CONFIG_ACCEL_FIFO when the MOTIONSENSE task is present (some times that may be only in one section RW or RO). BUG=b:137758297 BRANCH=None TEST=buildall and ran CTS on arcada Change-Id: I2f7e4e436ba9568a35b7a0b2c8d53a73f198ba73 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704163 Reviewed-by: Alexandru M Stan <amstan@chromium.org> Commit-Queue: Alexandru M Stan <amstan@chromium.org>
* driver/tcs3400: improve efficiency of auto-adjustNick Vaccaro2019-08-201-16/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | Adds an array which holds the number of atime increments needed at various lux levels and again settings to change delta from saturation by 1%. Using this table, the anti-saturation algorithm can get to the 90% band in most cases in a single adjustment vs the 10 to 15 adjustments previously needed when not using this table. Enabling CONFIG_TCS_USE_LUX_TABLES takes up 280 bytes in the ec.obj. BUG=b:124512628 BRANCH=master TEST=Flash and boot flapjack, verify that ALS and RGB sensors are still generating data. I used alslog patch and enabled ALS logging in EC console via "alslog 2047". Verify that under a constant light source, the adjustment mechanism correctly drives the ALS values such that they land in the sweet spot between 90 to <100% of saturation. Change-Id: I7cd0b8242e72233f50ff2751834f7bba367c6706 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1677764 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* driver/tcs3400: add auto-compensation for saturationNick Vaccaro2019-08-201-122/+353
| | | | | | | | | | | | | | | | | | | | | | | | | | Making settings more sensitive makes the SNR better, so this algorithm strives to keep the output level as close to 90% saturation as possible. Adds calibration mode and lux calculation. Removes unused last_value field from the tcs3400_rgb_drv_data_t structure, we use raw_xyz field in motion_sensor_t struct instead. BUG=b:124512628 BRANCH=master TEST=Flash and boot flapjack, verify that ALS and RGB sensors are still generating data. I used alslog patch and enabled ALS logging in EC console via "alslog 1023". Verify that under a constant light source, the adjustment mechanism correctly drives the ALS values such that they land in the sweet spot between 90 to <100% of saturation. Cq-Depend: chromium:1711958,chromium:1702543 Change-Id: Ibf260a990fe285cb54ee94c1ebe8aa85ea10affc Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1633269 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* Remove __7b, __8b and __7bfDenis Brockus2019-07-201-3/+3
| | | | | | | | | | | | | | | | | | | The extentions were added to make the compiler perform most of the verification that the conversion was being done correctly to remove 8bit addressing as the standard I2C/SPI address type. Now that the compiler has verified the code, the extra extentions are being removed BUG=chromium:971296 BRANCH=none TEST=make buildall -j TEST=verify sensor functionality on arcada_ish Change-Id: I36894f8bb9daefb5b31b5e91577708f6f9af2a4f Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704792 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Use 7bit I2C/SPI slave addresses in ECDenis Brockus2019-07-191-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Opt for 7bit slave addresses in EC code. If 8bit is expected by a driver, make it local and show this in the naming. Use __7b, __7bf and __8b as name extensions for i2c/spi addresses used in the EC codebase. __7b indicates a 7bit address by itself. __7bf indicates a 7bit address with optional flags attached. __8b indicates a 8bit address by itself. Allow space for 10bit addresses, even though this is not currently being used by any of our attached devices. These extensions are for verification purposes only and will be removed in the last pass of this ticket. I want to make sure the variable names reflect the type to help eliminate future 7/8/7-flags confusion. BUG=chromium:971296 BRANCH=none TEST=make buildall -j Change-Id: I2fc3d1b52ce76184492b2aaff3060f486ca45f45 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1699893 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* driver/tcs3400: make error message in sensor read less spammy.Ting Shen2019-07-181-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | In EMULATED_IRQ_EVENT mode, we try to estimate the time between a read request and data ready. If the estimated time is shorter, an error message is printed to the console on every retry. On Kukui, this caused ec console spamming one line per second. Change the behavior to print only when returning error. No need to adjust the estimate time because one retry per read is still good enough. BUG=b:137345336 TEST=manually, verify that error message disappeared. BRANCH=None Change-Id: Ie85e8f1a80ea36ca5c50f57a19eba35f3f79f86d Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1697889 Tested-by: Fei Shao <fshao@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Nick Vaccaro <nvaccaro@chromium.org> Reviewed-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* driver: add an option to emulate irq event in TCS3400Ting Shen2019-06-251-6/+30
| | | | | | | | | | | | | | | | | Krane does not reserve an interrupt pin for ALS, so we need another way to trigger the irq handler. Add a new config option CONFIG_ALS_TCS3400_EMULATED_IRQ_EVENT to support this use case. BUG=b:129419982 BRANCH=None TEST=verify that `accelread 3` outputs reasonable data on krane. Change-Id: I960df249d29c0ac21810057e25f14d4bac3e14f5 Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1621449 Reviewed-by: Nick Vaccaro <nvaccaro@google.com> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org>
* driver/tcs3400: disable ADC & oscillator between readsNick Vaccaro2019-06-141-14/+9
| | | | | | | | | | | | | | | | | | | | Disabling ADC and oscillator after servicing the interrupt not only saves power, but it assures the next light sample gathered will be based on a single again and atime setting. Without disabling ADC and oscillator, part of the next sample was getting sampled at one again and atime setting, but part of that sample was getting sampled using a different again or atime setting in cases where the saturation compensation mechanism changed again or atime. BUG=b:134188019 BRANCH=master TEST=Flash and boot flapjack, verify that ALS and RGB sensors are still generating data (I used alslog patch and enabled logging in EC console via "alslog" command). Change-Id: Ie599e03e1e5d8a1956a7006cc944a51dd759e8a6 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1633270
* common: motion_sense: Spread timestamps in motion sense fifoYuval Peress2019-06-061-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes moves the specialized logic for timestamp spreading away from the accelgyro_lsm6dsm and into the main motion_sense loop. The motion_sense_fifo_add_data function was replaced by a stage equivalent, and a commit function was added. Similarly, internal static functions for motion_sense.c were renamed to use the stage terminology. The idea is: When a sensor is read, it might provide more than one measurement though the only known timestamp is the one that caused the interrupt. Staging this data allows us to use the same fifo queue space that the entries would consume eventually anyway without making the entries readable. Upon commit, the timestamp entries are spread if needed. Note that if tight timestamps are disabled, the commit becomes a simple tail move. BUG=chromium:966506 BRANCH=None TEST=Ran CTS on arcada. Change-Id: Ib7d0a75c9c56fc4e275aed794058a5eca58ff47f Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1637416 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* motionsense: Convert in_spoof_mode to a more generic flagsYuval Peress2019-05-231-3/+3
| | | | | | | | | | | | BUG=b:129159505 BRANCH=arcada TEST=I ran `make buildall` since this change isn't used yet it doesn't affect run-time behavior. Change-Id: I01857d679b800f9b53762c659ebd9a018cbf16db Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1612251 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
* tcs3400: rename tcs3400_drv_data_t to als_drv_data_tNick Vaccaro2019-05-091-19/+19
| | | | | | | | | | | | | | | | | | | - rename tsc3400_drv_data_t to als_drv_data_t - change tcs3400 driver to use common als_drv_data_t - change flapjack config to use common als_drv_data_t - rename TSC3400_SCALE() macro to ALS_CHANNEL_SCALE() - create and use new I2C_PORT_ALS definition - fix a couple nits BUG=b:124512628 BRANCH=master TEST=build and flash to flapjack, verify ALS and RGB still work. Change-Id: I9a45d255ff77794ef34026406c9b702a04e09c11 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/1601052 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* driver: add tcs3400 RGB channel sensor driverNick Vaccaro2019-05-071-2/+162
| | | | | | | | | | | | | | | | | | | Implements a MOTIONSENSE_TYPE_LIGHT_RGB sensor using the tcs3400. BUG=b:129419982 BRANCH=master CQ-DEPEND=CL:1541955 TEST=cherry-pick CLs to enable tcs3400 for flapjack and to add alslog, build and flash to flapjack; boot flapjack, from ec console, execute 'sysjump rw', then execute "alslog" to enable logging of als data. Verify als data is generated and logged to ec console. Change-Id: Ia8000d27ff4f9683ceb4c9522bc7f0fed20c2045 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/1551748 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
* driver: add tcs3400 ALS sensor chip driverNick Vaccaro2019-05-061-0/+312
Implements a MOTIONSENSE_TYPE_LIGHT sensor using the clear channel of the tcs3400. BUG=b:124512628 BRANCH=master TEST=cherry-pick CLs to enable tcs3400 for flapjack and to add alslog, build and flash to flapjack; boot flapjack, from ec console, execute 'sysjump rw', then execute "alslog" to enable logging of als data. Verify als data is generated and logged to ec console. Change-Id: I918cbf5513fb5eba20a27705c47545d3c0b3ca91 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/1541955 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>