summaryrefslogtreecommitdiff
path: root/util/comm-i2c.c
Commit message (Collapse)AuthorAgeFilesLines
* util: Add explicit castsTom Hughes2021-05-061-2/+2
| | | | | | | | | | | | | | When compiling with C++, the implicit casting that is performed in C is disallowed. Add casts in preparation for C++ compatibility. BRANCH=none BUG=b:144959033 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I5c25440819428db65225c772c1c5115a735db58a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2864519 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* util/comm-i2c.c: Remove incorrect castTom Hughes2021-05-031-2/+2
| | | | | | | | | | | | | | buf is type "uint8_t *", not "char *". BRANCH=none BUG=b:144959033 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I0e813069f164b08324844009cd64d470b7d35405 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2864516 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* util/comm-i2c: Add switch to specify I2C busHarry Cutts2019-10-041-18/+29
| | | | | | | | | | | | | | | | | | | | Currently, devices running CrOS EC that aren't actually the embedded controller (such as touchpad or fingerprint MCUs) can only be contacted over I2C if they are in the device tree. To avoid having to recompile the Kernel, Coreboot, or `ectool`, the `--i2c_bus` switch allows `ectool` to be used for testing as-is. BRANCH=none BUG=none TEST=Checked various commands (hello, version, inventory...) with `--i2c_bus=7`, connecting to a MAX32660. Verified that a contradictory `--interface` switch is rejected. Checked that invalid bus numbers (≥32) are rejected. Change-Id: I92f3307bbbdf88978b9f8271610a3ae222279767 Signed-off-by: Harry Cutts <hcutts@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1828064 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* util/comm-i2c: return response length from `ec_command`Harry Cutts2019-10-011-1/+1
| | | | | | | | | | | | | | | | | | In my original implementation I returned the response code (possibly because I was confused by `ec_command_servo_spi` returning something like that), but `do_i2c_xfer` (used for all I2C passthrough stuff) breaks in that case. Changing it to return response length (consistent with the `ec_command` doc comment) fixes that problem. BRANCH=none BUG=chromium:1008568 TEST=Use `ectool i2cwrite ...` to write to one of the EC's I2C slaves (should report success instead of "Truncated read response"). Change-Id: I341c3907ac44c6c3d1086ae10b31e81062215f20 Signed-off-by: Harry Cutts <hcutts@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1830099 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* util/comm-i2c: upgrade to host command protocol v3Harry Cutts2019-09-261-104/+133
| | | | | | | | | | | | | | | | | | | | | We can remove the v2 code, as any boards still using it have reached end-of-life, with the exception of Samus's PD, which we only communicate with via the Kernel driver, as far as I can tell. (I verified that an `ectool` built with this change can still be used to communicate with the Samus PD.) BRANCH=none BUG=none TEST=Checked various commands (hello, version, inventory...) with `--interface=i2c` and `comm_init_i2c` modified to hard-code the I2C bus to use (as the board I tested with is not yet in sysfs). The test board is using a MAX32660, so https://crrev.com/c/1716928 was patched in for testing. Change-Id: I1e014c6f747ce29d9bf1541be51c519af98e7f45 Signed-off-by: Harry Cutts <hcutts@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1803977 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* util/comm-i2c: Fix memory leakPatrick Georgi2019-09-041-1/+2
| | | | | | | | | | | | | | | Found by Coverity #58167 BUG=none BRANCH=none TEST=none Change-Id: I434d4b140683b4c3440c30b232fab34d781da9d4 Signed-off-by: Patrick Georgi <pgeorgi@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1781466 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Patrick Georgi <pgeorgi@chromium.org> Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
* LICENSE: remove unnecessary (c) after CopyrightTom Hughes2019-06-191-1/+1
| | | | | | | | | | | | | | | | Ran the following command: git grep -l 'Copyright (c)' | \ xargs sed -i 's/Copyright (c)/Copyright/g' BRANCH=none BUG=none TEST=make buildall -j Change-Id: I6cc4a0f7e8b30d5b5f97d53c031c299f3e164ca7 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1663262 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* util: Fix return value of ec_commandGwendal Grignou2014-11-171-2/+2
| | | | | | | | | | | | | | | | | | | | When ec_command fails because of transport issue, it should returns an error between -1 and -EECRESULT. If the command fails because of the EC, the error should be less than -EECRESULT. Unify all transports to return the error in the same manner. BRANCH=ToT BUG=None TEST=Samus: Check that unsupported command fails with the correct error number over dev transport. Qwarks: Check the same command with a 3.10 kernel (no dev transport, just LPC) fails with the same error code. Change-Id: I2e43d0cb003d75318b0edd3745e534c700d7d7d8 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/228295 Reviewed-by: Alec Berg <alecaberg@chromium.org>
* Fix ec detection for i2c protocolPuthikorn Voravootivat2014-08-181-3/+4
| | | | | | | | | | | | | | | ectool seems to looks at wrong location for ec. This patch fix that BRANCH=none BUG=chromium:402581,chrome-os-partner:30707 TEST=ectool hello runs fine on ryu Change-Id: I7b847b0eaf3fd39a8ba2948a87879b3f8223c582 Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/212483 Reviewed-by: Vic Yang <victoryang@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* samus: add options for device passthru and interfaceRandall Spangler2014-07-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | This allows sending host commands to the PD chip through the EC. The --interface option allows forcing a particular host interface. This is necessary at present because the crosec device driver doesn't support host protocol v3 so only has 8-bit command numbers. BUG=chrome-os-partner:30079 BRANCH=none TEST=from EC console, ectool version -> prints EC version ectool --interface=lpc --dev=0 version -> prints EC version ectool --interface=lpc --dev=1 version -> prints PD version ectool --interface=lpc --dev=2 version -> prints error ectool --interface=i2c version -> can't find EC ectool --interface=dev version -> prints EC version Change-Id: I9dd10578dac77e3e104d19e2f37759814eec6ca2 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/207948
* cleanup: Yes, even more TODO commentsRandall Spangler2013-11-041-1/+2
| | | | | | | | | | | | | Almost done. Comment changes only. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all platforms Change-Id: I974dfc12aa264e2035b3bae35a089c19344e7d45 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/175484 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Move protocol v2 constants to ec_commands.hRandall Spangler2013-07-031-10/+3
| | | | | | | | | | | | | | | | These constants are scattered around the various interface implementations and should be in one place. This will also clean up the u-boot side when ec_commands.h is copied there. BUG=chrome-os-partner:20257 BRANCH=none TEST=build link, spring, pit; test 'ectool hello' Change-Id: Ib1425db00ec8220538d8c5c65107ac9548009516 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/60810 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* Comm interface now provides max I/O sizes and preallocated buffersRandall Spangler2013-07-011-0/+2
| | | | | | | | | | | | | | | | | | | | The maximum packet / param size differs depending on interface and protocol version. Commands can now ask the comm interface what the limits are, and can use preallocated buffers to avoid needless malloc/free. BUG=chrome-os-partner:20571 BRANCH=none TEST=the following all work on link burn_my_ec ectool version ectool chargedump ectool console ectool i2cxfer 5 0x41 2 Change-Id: Ib847994da3f79721e7fb4e347231b9147a3f485f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/60275
* ectool prefers /dev/cros_ec, then falls back to i2c, lpcBill Richardson2013-06-051-108/+43
| | | | | | | | | | | | | | | This is preparation for the common userspace EC interface. If/when that appears, this will be ready. BUG=chromium:239197 BRANCH=all TEST=manual Build, install, run it. Shouldn't be any change. Change-Id: I9fa78515ec5443ba659f10a66bbaadcb7f4802b0 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/56131
* comm-i2c.c upgrades to protocol v2.Louis Yung-Chieh Lo2012-09-051-49/+71
| | | | | | | | | | | | | | | | | | | | | | | | Old i2c code uses protocol v1, which cannot handle veriable-length response (unknown lenght to calculate checksum). So, upgrade to procotol v2 anyway since command v1 needs protocol v2. BUG=chrome-os-partner:11608, Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org> BRANCH=None TEST=on snow, and both command v0/v1 are working on protocol v2. ectool version ectool hello ectool echash ectool flashinfo ectool flashprotect ectool flashwp Change-Id: Id8532fe51359dce18839d37de8a8c8669754041c Reviewed-on: https://gerrit.chromium.org/gerrit/31838 Commit-Ready: Yung-Chieh Lo <yjlou@chromium.org> Reviewed-by: Yung-Chieh Lo <yjlou@chromium.org> Tested-by: Yung-Chieh Lo <yjlou@chromium.org>
* Support new-style LPC command interface in EC, ectoolRandall Spangler2012-07-121-5/+10
| | | | | | | | | | | | | | | | | | Both EC and ectool are still backwards-compatible to the old interface. BUG=chrome-os-partner:11275 TEST=manual From U-boot prompt: mkbp hash // test old host talking to new EC From root shell: ectool echash // test new host talking to new EC You can also update just the OS and use an old EC, and verify that 'ectool echash' still works, which tests a new host talking to an old EC. Change-Id: I2afbb208cb16836f842ba119b74b1ab6a38ce5d5 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/27313
* Add memory-mapped data support for I2C and SPI protocolsRandall Spangler2012-07-071-12/+52
| | | | | | | | | | | | | | | And fix returning memory-mapped string length on LPC as well. BUG=chrome-os-partner:11090 TEST=manual from EC, 'hostevent set 0x40000' from host, 'ectool eventget' --> should print 0x40000 Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: I9edbd0a1468b5d4160ce67c471332226e51fa868 Reviewed-on: https://gerrit.chromium.org/gerrit/26719 Reviewed-by: Simon Glass <sjg@chromium.org>
* Tidy util headers and make ec_commands.h not include other headersRandall Spangler2012-06-291-1/+0
| | | | | | | | | | | | | In preparation for being able to copy ec_commands.h to u-boot, which is itself in preparation for u-boot picking it up from /usr/src/ec/ BUG=none TEST=make link, snow, bds Change-Id: If256434b6722ff0787ce21a8ed4c7035c28024a8 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/26451 Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
* Change ec_command() to return negative values for errorsRandall Spangler2012-06-291-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is more compatible with kernel and u-boot, and will make it easier to share code between the ec project and those. BUG=none TEST=manual: ectool version -> should work normally on ec, do 'hostevent set 0x40000'. Then at root shell ectool queryec EC returned error result code 19 ectool flashread 0x100000 16 foo Reading 16 bytes at offset 1048576... EC returned error result code 2 Read error at offset 0 Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: I5e2a85f96c874d0730c14e1438a533649cd594f8 Reviewed-on: https://gerrit.chromium.org/gerrit/26359 Commit-Ready: Randall Spangler <rspangler@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
* Add I2C host communicationVincent Palatin2012-05-241-0/+210
Allow to use EC tool on ARM based platforms. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=None TEST=On Daisy, ectool version Change-Id: If7f52de827d0bcffb39af0553245cce4e02b9b48