summaryrefslogtreecommitdiff
path: root/chip/stm32/usb.c
Commit message (Collapse)AuthorAgeFilesLines
* chip/stm32: Factor family specific clock logic out of usb.cJes B. Klinke2021-09-081-21/+3
| | | | | | | | | | | | | | | | | | | | | | | The register for enabling USB register clock appears to have been identical across F0, F3, and G4 families, but for L5 it is different. Rather than having #ifdef in usb.c (as I recently committed), this CL will move the clock logic into clock_enable_module() where it arguably belonged all the time. Additionally: Some of the chip families make use of a clock_mask in their implementation of clock_enable_module(), but since the module_id enum has more than 32 value, until now, some values (among those MODULE_USB) would result in overflow, causing new_mask to be identical to clock_mask, and the USB case could have never been reached. BUG=b:192262089 TEST=Compile servo_v4 without linker errors BRANCH=none Signed-off-by: Jes Bodi Klinke <jbk@chromium.org> Change-Id: I7c29339f45eb513e3e78f662797a70543912c8c7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3130733 Reviewed-by: Scott Collyer <scollyer@chromium.org>
* chip/stm32: Add initial support for STM32L5xx seriesJes B. Klinke2021-08-251-0/+17
| | | | | | | | | | | | | | | | Introduce L5xx mostly as copy of L4xx, though registers-stm32l5.c is extensively modified. BUG=b:192262089 TEST=Compile and upload board/hyperdebug to Nucleo board BRANCH=none Signed-off-by: Jes B. Klinke <jbk@opentitan.org> Change-Id: Iccc7b05e4f2dfa732559b8099cf856882401e31c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3086362 Tested-by: Jes Klinke <jbk@chromium.org> Reviewed-by: Scott Collyer <scollyer@chromium.org> Commit-Queue: Jes Klinke <jbk@chromium.org>
* usb-ep: Add config option to define VIDScott Collyer2021-05-021-1/+1
| | | | | | | | | | | | | | | | | This value was previously hardcoded to Google's VID. However, some products with USB-EP support may require a different VID to correctly support fwupd. BUG=b:181920029 BRANCH=quiche TEST=verified that fwupd works on baklava Signed-off-by: Scott Collyer <scollyer@google.com> Change-Id: I23c36507a90428ab46cd5efde7d79581207bde74 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2848424 Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org>
* atomic: rename atomic_read_clear to atomic_clearDawid Niedzwiecki2020-11-021-1/+1
| | | | | | | | | | | | | | | | | Rename atomic_read_clear to atomic_clear to be consistent with the rest of the atomic functions, which return the previous value of the variable. BUG=b:169151160 BRANCH=none TEST=buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I2588971bd7687879a28ec637cf5f6c3d27d393f4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2505143 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* tree: Use new atomic_* implementationDawid Niedzwiecki2020-10-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | It is done as a part of porting to Zephyr. Since the implementation of atomic functions is done for all architectures use atomic_* instead of deprecated_atomic_*. Sometimes there was a compilation error "discards 'volatile' qualifier" due to dropping "volatile" in the argument of the functions, thus some pointers casts need to be made. It shouldn't cause any issues, because we are sure about generated asm (store operation will be performed). BUG=b:169151160 BRANCH=none TEST=buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I98f590c323c3af52035e62825e8acfa358e0805a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2478949 Tested-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* tree: rename atomic_* functions to deprecated_atomic_*Jack Rosenthal2020-09-291-1/+1
| | | | | | | | | | | | | | | | We will move to an API compatible with Zephyr's API. See the bug for complete rationale and plan. BUG=b:169151160 BRANCH=none TEST=buildall Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Id611f663446abf00b24298a669f2ae47fef7f632 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2427507 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* Servo: Adds persistent storage of MAC addressBrian J. Nemec2020-02-211-0/+58
| | | | | | | | | | | | | | | | | | | | | | | Adds a field to the persistent storage to store the MAC address of the device. This is enabled on ServoV4 in order to store the MAC address for the integrated ethernet port. Added a console command to set and load this value. BUG=b:149506580 TEST=Verified setting and loading the MAC address using: 'macaddr set 12:34:56:78:90:ab' and 'macaddr' or 'macaddr load' Verified that MAC addresses over 19 characters long return an error response and not update the MAC. Verified no set serial number will return the uninitialized string. Verified that the MAC address can be updated independently of serialno Verified that the persist_state fields restore during firmware updates Change-Id: I8425ce9e13322e99a4f59df444ea0dc73821aa6b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2063330 Tested-by: Brian Nemec <bnemec@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@google.com> Commit-Queue: Brian Nemec <bnemec@chromium.org>
* chip/stm32/usb: Detect SOF when resume state is not expectedNicolas Boichat2020-02-041-5/+27
| | | | | | | | | | | | | | | | | | | | | | | When the resume interrupt handler is called, but the state is not the expected 0 or 1, let's detect if we receive any SOF from the host. If we do, this means that the link is active and that we shouldn't go back to sleep (which would put us in an infinite loop). BRANCH=kukui BUG=b:144808697 TEST=Type usbresume in console (with other HACK CL), see that we can recover whether or not the interface is autosuspended. TEST=With device autosuspended, short D+/D- on the base, that generates a spurious resume event (similar to what we observed doing ESD testing on Soraka), and check that in that can we don't get an SOF and we go back to sleep. Change-Id: Ibd5c5f7e5f5c324622df5169bb317afa118edc45 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2035436 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Eric Yilun Lin <yllin@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>
* common: replace 1 << digits, with BIT(digits)Gwendal Grignou2019-03-261-3/+3
| | | | | | | | | | | | | | | | Requested for linux integration, use BIT instead of 1 << First step replace bit operation with operand containing only digits. Fix an error in motion_lid try to set bit 31 of a signed integer. BUG=None BRANCH=None TEST=compile Change-Id: Ie843611f2f68e241f0f40d4067f7ade726951d29 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518659 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* stm32: convert to CONFIG_CHIP_MEMORY_REGIONSVincent Palatin2018-03-051-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the former special case for USB RAM Add additional RAM regions for STM32H7. For USB RAM, add an explicit alignment directive to ensure we always meet the 8-byte boundary hardware constraint for the BTABLE. This was already true because we put the .usb_ram.btable section first. I keep this property by alpha-sorting the sections but makes it more explicit by adding a 2-digit numeric prefix: e.g. 00_firstsection, 99_lastsection. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=b:67081508 TEST=on ZerbleBarn, along with the following CLs, run the firmware with large arrays in special AHB memory regions. TEST=build all targets with and without the patch and verify that all smap files are identical. Change-Id: I9ee7f519a13cb14ba9997220f22180028f9c0175 Reviewed-on: https://chromium-review.googlesource.com/946369 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
* stm32/usb: Add HOOK_USB_PM_CHANGE, called when USB is resumed/suspendedNicolas Boichat2018-02-021-1/+22
| | | | | | | | | | | | | | | | | | In particular, this will allow touchpad driver and keyboard matrix scanning to be powered off/disabled when the USB interface is disabled without setting the remote wake feature (USB_REQ_FEATURE_DEVICE_REMOTE_WAKEUP), as events would be ignored anyway. BRANCH=none BUG=b:72683995 TEST=With next CLs, touchpad and keyboard matrix scanning are disabled when lid is closed. Change-Id: I3750bfaf8c31cde075adf9da4fef39753b8981c5 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/897067 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32/usb: Add logic to detect stuck controller in usb_wakeNicolas Boichat2018-01-181-1/+28
| | | | | | | | | | | | | | | | | | | | | | When we tried to go back to sleep immediately after receiving a spurious USB resume event, the controller would get stuck in an unrecoverable state. Hopefully we fixed the resume logic, but this code would catch other cases, and recover the base. BRANCH=none BUG=b:35775088 BUG=b:67766202 BUG=b:71688150 TEST=With badly implemented resume logic (e.g. call usb_resume_deferred directly from usb_resume), with USB autosuspend enabled on soraka, short D+/D- lines. Next wake event from staff shows "USB stuck", and then USB interface recovers. Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Change-Id: I7463a37682723be195bd6a72ea5d76c21bb6cb9a Reviewed-on: https://chromium-review.googlesource.com/868094 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32/usb: Handle spurious wakes in usb_resumeNicolas Boichat2018-01-181-7/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes, usb_resume gets called, but the D+/D- lines do not indicate an actual resume event (e.g. during ESD discharge). Reference manual tells we should go back to sleep if state is 10 or 11. However, setting FSUSP and LP_MODE in this interrupt routine seems to lock the USB controller (see b/35775088 and b/71688150). Instead, we do it in a deferred routine. The host must assert the reset condition for 20ms, so reading D+/D- after ~3ms should be safe (there is no chance we end up sampling during a bus transaction). BRANCH=none BUG=b:35775088 BUG=b:67766202 BUG=b:71688150 TEST=On staff, with USB autosuspend enabled on soraka, short D+/D- lines, which causes a spurious wake event. After that remote wake-up still works. TEST=Repeat test with ESD discharge. TEST=Repeat test with plugging/unplugging of USB-C monitor. Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Change-Id: I0f2697d1fa5b68356fd8a4fc16eaab5eadad9086 Reviewed-on: https://chromium-review.googlesource.com/868093 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32/usb: usb_wake: Update STM32_USB_CNTR with interrupts offNicolas Boichat2018-01-171-1/+5
| | | | | | | | | | | | | | | | | STM32_USB_CNTR may be written from both interrupt context, and usb_wake (not necessarily in interrupt context). Let's disable interrupts to make sure the operation is atomic. BRANCH=none BUG=b:35775088 BUG=b:67766202 BUG=b:71688150 TEST=Flash hammer, hammer can wake from USB autosuspend Change-Id: I9c2a3259902ecb759a6d0d89c7746c7aa72ae73d Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/744282 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32/usb: Patching framework for USB descriptorsNicolas Boichat2017-12-121-1/+35
| | | | | | | | | | | | | | | | | | In some cases, we want to be able to dynamically modify a few bytes in the USB descriptor (in our case, length of referenced items), but it could also be other things like flags. These 2 new functions allow to keep all the USB descriptor in flash, and modify these few bytes before writing them in the USB buffer. BRANCH=none BUG=b:37447752 TEST=Flash hammer, USB descriptors are valid. Change-Id: I8624255fa43f52a0aaa21d20e963f3974f236912 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/771057 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32: update USB version for BOS descriptorsVincent Palatin2017-11-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | Bump the USB version (aka bcdUSB) for BOS descriptors to 2.1 (rather than 2.01) to be compatible with Chrome implementation. The CL 664813 was intending to do this, but I screw up and only changed it for chip/g and let chip/stm32 unchanged : https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/664813 Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=twinkie BUG=none TEST=manual, plug an updated Twinkie and see the WebUSB pop-up on Chrome. Change-Id: Ia81fa91b6d7790af6f6683c0da7ca1d794b4e4df Reviewed-on: https://chromium-review.googlesource.com/789934 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Todd Broch <tbroch@chromium.org>
* Add WebUSB descriptor supportVincent Palatin2017-09-221-19/+40
| | | | | | | | | | | | | | | | | | | | | | | | | The WebUSB specification defines a specific Platform Descriptor in the Binary Object Store: https://wicg.github.io/webusb/#webusb-platform-capability-descriptor This descriptor provides a special 'Landing page' URL to the host browser and associated privileges for it. Bump the USB version for BOS descriptors to 2.1 to be compatible with Chrome implementation. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=none BRANCH=twinkie TEST=manual: on Twinkie (chip/stm32) and HG proto2 (chip/g), enumerate WebUSB descriptors with lsusb and connect to a WebUSB page in Chrome R61+. Change-Id: I7211ab554f4a6c156c1e8e79a3d9f0d6644217c6 Reviewed-on: https://chromium-review.googlesource.com/664813 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* chip/stm32/usb: Replace reset handler by generic event handlerNicolas Boichat2017-08-161-3/+11
| | | | | | | | | | | | | | | | | | | Some USB interface handlers need to know when USB has been successfully resumed after a wake event. For example, this is useful so that HID keyboard can send the events at the right time. BRANCH=none BUG=b:35775048 TEST=Using USB HID keyboard patches to queue keys in a FIFO: After USB autosuspends, press a single key and hold it. Without this patch the endpoint data only gets reloaded on the _next_ event. TEST=On hammer, I2C passthrough still works. Change-Id: I9b52b9de16767c8a66c702a5ae70369334a3d590 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/569547 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* chip/stm32/usb: Split usb wake handler as a different functionNicolas Boichat2017-08-151-43/+49
| | | | | | | | | | | | | | Indentation is growing out of control, let's move to a separate function so that we can return early. BRANCH=none BUG=b:35775048 TEST=Flash hammer, usb_wake works. Change-Id: I9abf99ff55b3977dfc307fc99aac6f1ab7dd1f6a Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/612922 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* chip/stm32/usb: Increase resume timeout to 3 secondsNicolas Boichat2017-08-061-1/+1
| | | | | | | | | | | | | | | | | | | When resuming from S3, it may take a while for the bus to become alive again, so let's increase the timeout. 3 seconds is probably a bit too long, but should work for our purpose: we just do not want to be stuck in that state forever. BRANCH=none BUG=b:35587173 TEST=Use powerd_dbus_suspend to put poppy in S3. Press key, see that hosts sometimes takes ~90ms, but sometimes up to 1.5s to resume. Change-Id: Ic800481b2b500fb68a8d1de16b11cbe77a4013d4 Reviewed-on: https://chromium-review.googlesource.com/569523 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* chip/stm32/usb: Fix resume handler in usb_wakeNicolas Boichat2017-08-061-11/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the previous version of the code, we were counting ESOF (every ms) to figure out when to clear the resume bit, and then using ESOF counts again to wait for the USB interface to resume. This missed the fact that ESOF (expected SOF) interrupts are not triggered when SOF are actually received. Somehow, this worked fine in most cases, except that sometimes the last ESOF would race with the RXDP/RXDM going to state 2, and we would not know that the resume completed successfully. Let's also count SOF interrupts, and also take a received SOF as an indicator of a successful resume. While we're at it, trim down USB debugging messages, and add a line when resume is successful. BRANCH=none BUG=b:35587173 TEST=Connect hammer, force autosuspend using: DEVICE=$(dirname $(grep 5022 /sys/bus/usb/devices/*/idProduct)) echo 500 > $DEVICE/power/autosuspend_delay_ms echo auto > $DEVICE/power/control Add debugging in hammer code, make sure that usb_wake_done goes back to 1 after resume succeeds. Change-Id: I206c9c6b3066a3a337b6bd2370c9d0c6a9e2396c Reviewed-on: https://chromium-review.googlesource.com/569522 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Add OTP supportGwendal Grignou2017-07-281-12/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | One Time Programmable memory can be used to store permanent data like serial numbers. Reorganize the code to support writing serial number to OTP, in addition to pstate (if using its own memory bank) or autogenerate from unique id (hammer). + Add CONFIG_OTP to enable OTP code + Add CONFIG_SERIALNO_LEN to indicate the size of the serial number string. Currently set to 28, when USB serial number is needed. + Expose flash_read|write_pstate_serial and add otp_read|write_serail, remove more generic flash_read|write_serial. + Make board_read|write_serial generic, declared outside of USB subsystem. Priority order to read|write serial string: - board definition (like hammer) - pstate location, if stored in its private memory bank - otp area If none of these methods are available, a compilation error is raised. BUG=chromium:746471 BRANCH=none TEST=compile Change-Id: I3d16125a6c0f424fb30e38123e63cf074b3cb2d3 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/580289 Reviewed-by: Nick Sanders <nsanders@chromium.org>
* stm32/usb: Add support for board-specific serial numberNicolas Boichat2017-06-131-1/+8
| | | | | | | | | | | | | | | | | | | By default, read USB serial number from flash, but provide a way for boards to override the function (e.g., to read serial number from unique chip id). BRANCH=none BUG=b:62280271 TEST=Flash hammer lsusb -d 18d1:5022 -v -v | grep iSerial shows different chip IDs on different boards. Change-Id: I0917752bb8e04c1eff4dffc0b3714f63dcd942b0 Reviewed-on: https://chromium-review.googlesource.com/523045 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Nick Sanders <nsanders@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* hammer: Pulse detection pin on USB wake eventNicolas Boichat2017-05-021-0/+9
| | | | | | | | | | | | | | | | | | When usb_wake is called (key press, trackpad event), pulse detection pin for 100us. This allows Lid EC to wake the AP even when it is in deep S3 mode, where normal wake using USB lines does not work. BRANCH=none BUG=b:35775062 TEST=Flash hammer, looks at poppy console: base power is not disconnected, but events appear in the console. Change-Id: I7b8ee407046d4caa1ce75190c30d693b71b00d2e Reviewed-on: https://chromium-review.googlesource.com/448380 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* chip/stm32/usb: More reliable implementation of usb_wakeNicolas Boichat2017-05-021-6/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | Current usb_wake was sleeping between setting and clearing RESUME bit, which is unprecise. Instead, we count ESOF interrupts in usb_interrupt to detect when to clear RESUME. It is also important that usb_wake does not block, as the calling task (e.g. keyboard scanning) must continue to service events while the USB device is resuming. BRANCH=none BUG=b:35587173 TEST=Connect hammer, force autosuspend using: DEVICE=$(dirname $(grep 5022 /sys/bus/usb/devices/*/idProduct)) echo 500 > $DEVICE/power/autosuspend_delay_ms echo auto > $DEVICE/power/control Wait a second, type something quickly, verify that no keys are lost. Change-Id: I53b46cce5a4adb0ee4c4a7e9f935c00f7f321636 Reviewed-on: https://chromium-review.googlesource.com/490129 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* usb: Cleanup headersNicolas Boichat2017-03-161-0/+2
| | | | | | | | | | | | | | | | | | | Let's split the usb headers in 3 different parts, instead of having usb_descriptor.h pull in usb_hw.h and usb_api.h. - usb_api.h: EC functions related to usb (e.g. connect/disconnect) - usb_descriptor.h: common USB names and structures - usb_hw.h: Functions required for interactive with EC's USB HW BRANCH=none BUG=b:35587171 TEST=make buildall -j Change-Id: I37ead61e3be5e7ae464f1c9137cf02eaab0ff92e Reviewed-on: https://chromium-review.googlesource.com/454861 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* chip/stm32/usb: Add support for USB SET_FEATURE control requestsNicolas Boichat2017-03-081-5/+30
| | | | | | | | | | | | | | | | | | | | This is required so that the kernel can enable/disable remote wake-up capabilities, and in particular for the kernel to enable autosuspend. Also, properly implement GET_STATUS. BRANCH=none BUG=b:35579996 TEST=echo auto > /sys/bus/usb/drivers/usb/X-Y/power/control, device autosuspends after 2 seconds, and wakes on keypress. Note that this introduces other bugs, where keys are missing, repeated, see b/35775048. Change-Id: I7ddd257ac3877d27fb2da813f20583a614a0169b Reviewed-on: https://chromium-review.googlesource.com/450826 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32/usb: Add support for remote wake-upNicolas Boichat2017-03-011-9/+23
| | | | | | | | | | | | | | | | | | | | USB uses a special mode the trigger remote wake-up during host suspend, by setting the K-state on the data differential pair, and setting a bit in the USB config descriptor attributes field. Let's enable that so that hammer can wake up host from S3. BRANCH=none BUG=chrome-os-partner:62325 TEST=Connect hammer to chell, put chell in S3. Press a key (or use ("kb 3 3 1; kb 3 3 0" in console), or touch trackpad => host wakes. Change-Id: Ib7b1e9047e01869f07ddd771c9c9bc640eef10d6 Reviewed-on: https://chromium-review.googlesource.com/446240 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32/usb: Add support for USB suspendNicolas Boichat2017-03-011-2/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | This follows the basics of what is decribed in RM0091 Reference Manual 30.5.5 Suspend/Resume events . We call enable/disable_sleep at suspend/resume, to make sure the EC stays awake when USB is connected and active. We also call clock_enable/disable_module, which is stubbed on stm32f0, but can be used on other devices in the family. This also fixes interrupt handling in usb_interrupt, by only clearing interrupt bits that were handled instead of resetting them all, which is racy, and can potentially lead to issues if reset comes soon after a resume event. BRANCH=none BUG=chrome-os-partner:62325 TEST=build and flash hammer, connect to chell, suspend/resume, and see that hammer prints USB suspend and USB resume lines. Change-Id: Ie9d02fd4a114add3ebc98dc9393680bc9a64a522 Reviewed-on: https://chromium-review.googlesource.com/446239 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32/usb: Add useful register macros instead of hardcoding valuesNicolas Boichat2017-02-231-6/+9
| | | | | | | | | | | | | | | Hopefully makes the code a little easier to understand, and will be useful for future features. BRANCH=none BUG=chrome-os-partner:62325 TEST=build and flash hammer Change-Id: I2b562740794c165da4e6611be371926e737f3887 Reviewed-on: https://chromium-review.googlesource.com/446238 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* chip/stm32/usb: Allow interface handler to reply with more than 64 bytesNicolas Boichat2016-11-221-5/+25
| | | | | | | | | | | | | | | | For example, when a HID descriptor is longer than 64 bytes, we need to split it in multiple packets. BRANCH=none BUG=chrome-os-partner:59083 TEST=make buildall -j TEST=make BOARD=hammer -j && util/flash_ec --board=hammer Change-Id: I25a05eabaf9413e332fe3cd70695a0d53639713d Reviewed-on: https://chromium-review.googlesource.com/409316 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Fix various misspellings in commentsMartin Roth2016-11-151-1/+1
| | | | | | | | | | | | | No functional changes. BUG=none BRANCH=none TEST=make buildall passes Change-Id: Ie852feb8e3951975d99dce5a49c17f5f0e8bc791 Signed-off-by: Martin Roth <martinroth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/403417 Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
* cleanup: DECLARE_CONSOLE_COMMAND only needs 4 argsBill Richardson2016-08-241-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Since pretty much always, we've declared console commands to take a "longhelp" argument with detailed explanations of what the command does. But since almost as long, we've never actually used that argument for anything - we just silently throw it away in the macro. There's only one command (usbchargemode) that even thinks it defines that argument. We're never going to use this, let's just get rid of it. BUG=none BRANCH=none CQ-DEPEND=CL:*279060 CQ-DEPEND=CL:*279158 CQ-DEPEND=CL:*279037 TEST=make buildall; tested on Cr50 hardware Everything builds. Since we never used this arg anyway, there had better not be any difference in the result. Change-Id: Id3f71a53d02e3dc625cfcc12aa71ecb50e35eb9f Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/374163 Reviewed-by: Myles Watson <mylesgw@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* servo_v4: servo_micro: cr50: fix usb power declarationNick Sanders2016-08-081-2/+10
| | | | | | | | | | | | | | | | | | | | | | | Servo_micro sets usb config maxpower to 100mA. Servo_v4 is set to self powered as it's powered by a shared vbus and not be the bub it's connected to. cr50 is self powered as no power is transmitted as part of CCD. * Add CONFIG_USB_MAXPOWER_MA to define USB maximum power draw requested per board. * Add CONFIG_USB_SELF_POWERED to indicate that a device is not powered by allocated USB power. BUG=chromium:631302 TEST=lsusb reports 100mA bMaxPower (micro), Self powered (v4) BRANCH=None Change-Id: I79b8ce46f32d94f16104a4a8080104e30dce7f2c Signed-off-by: Nick Sanders <nsanders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/363153 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* servo_micro: add programmable serial numberNick Sanders2016-05-261-2/+110
| | | | | | | | | | | | | | | | This change provides a console command for setting, and loading a usb serial number from flash. This feature adds CONFIG_USB_SERIALNO, and currently only has a useful implementation when PSTATE is present. BUG=chromium:571477 TEST=serialno set abcdef; serialno load; reboot BRANCH=none Change-Id: I3b24cfa2d52d54118bc3fd54b276e3d95412d245 Signed-off-by: Nick Sanders <nsanders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/337359 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cleanup: Rename usb.h to usb_descriptor.hShawn Nematbakhsh2015-11-081-1/+1
| | | | | | | | | | | | | | | | Rename usb.h to usb_descriptor.h to prevent conflict with a commonly-used libusb header. BUG=chromium:552006 BRANCH=None TEST=`make buildall -j` Change-Id: I6145ce120e1fda41bc5c4d4da0313272e76839c7 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/311429 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
* USB: Fix memcpy routinesAnton Staaf2015-04-131-21/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The memcpy like routines for moving to and from usb packet RAM couldn't deal with all unaligned uses, this fixes their behavior. In particular, a previous caller might assume that the packet RAM addresses were contiguous and attempt to break up a call into two separate chunks (as the queue insertion/removal code does). But this can lead to invalid pointers passed to these memcpy routines. A much cleaner solution is to make the packet RAM address space contiguous. To do so the memcpy routines take packet RAM addresses instead of AHB address space mapped addresses and __usb_ram_start needed to change to be of type usb_uint so that pointer arithmatic on it worked correctly on all platforms, this also allowed the usb_sram_addr macro to be simplified. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Verify that USB still works on Ryu and discovery-stm32f072 Change-Id: I479461f07a3203f1e6e0cf9705f512a5a43c4646 Reviewed-on: https://chromium-review.googlesource.com/264764 Trybot-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
* USB: fix memcpy_to_usbramAnton Staaf2015-02-171-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | A change to the toolchain or environment surfaced an issue where the writes to packet RAM were being split into two 16-bit writes. This was interacting poorly with the AHB2APB bridge. Marking the packet RAM destination pointer volatile forces the compiler to use full 32-bit writes. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Check that Ryu's console is accessible over USB Change-Id: I0c3db08c704389a627570b90ef97bce81ab553fa Reviewed-on: https://chromium-review.googlesource.com/248840 Trybot-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vic Yang <victoryang@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
* usb: fix sysjumpVincent Palatin2015-01-081-0/+2
| | | | | | | | | | | | | | | | | | | | Ensure that we can re-etablish a proper USB communication after a sysjump by properly disabling the USB stack before jumping. So the host sees a USB disconnection and can properly re-initialize the device when it re-appears. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=samus BUG=none TEST=On Twinkie, use the "sysjump RW" command on the USB console and see the prompt coming back after a few seconds. Change-Id: Iaf4498333eb4e7a1dda0f51ee8be19a0c9f10349 Reviewed-on: https://chromium-review.googlesource.com/239227 Reviewed-by: Anton Staaf <robotboy@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
* USB: Add memcpy_from_usbram and update existing memcpyAnton Staaf2015-01-081-3/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously there was just a memcpy_usbram that copied to USB packet memory, and no routine to copy out. This adds the "from" version and renames and improves to "to" version. The improvement is that the new "to" version correctly handles unaligned beginning and endings of the region to be copied. These need to be read/modify/write accesses since the USB packet ram has to be manipulated in 16-bit chunks. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Verify that discovery-stm32f072 still enumerates and communicates correctly over USB. Change-Id: I94353e66ad0248d4e674abb29f9a88e979767655 Reviewed-on: https://chromium-review.googlesource.com/238764 Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vic Yang <victoryang@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Trybot-Ready: Anton Staaf <robotboy@chromium.org>
* USB: Add setup packet struct and parsing routineAnton Staaf2014-12-081-0/+9
| | | | | | | | | | | | | | | | | | | This can be used by interface specific EP0 setup packet callbacks. The USB-SPI bridge will use this to handle enabling and disabling the bridge. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Change-Id: I3f3db65934707243f54bed9e093f376b6978d271 Reviewed-on: https://chromium-review.googlesource.com/232367 Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Trybot-Ready: Anton Staaf <robotboy@chromium.org>
* USB: Interface callbacks now return an error codeAnton Staaf2014-12-021-2/+3
| | | | | | | | | | | | | | | | | | | | A non-zero error code returned by the callback causes EP0 to STALL. This is the common mechanism used in USB to indicate an error while processing a control request. This simplifies the implementation of interface callbacks. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Change-Id: I89ceb4892f9f810fcaf6e975e6982fc5b2ae447b Reviewed-on: https://chromium-review.googlesource.com/232368 Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* stm32: Do not wait for USB host if USB is disabledVic Yang2014-11-211-0/+5
| | | | | | | | | | | | | | | | | | For USB console, we wait for USB host to grab the data before writing the next chunk of characters. However, if the USB peripheral is disabled, the current implementation is confused as to whether the host has grabbed the previous chunk of data. Fix this by explicitly checking for USB peripheral enabled. BRANCH=ryu BUG=None TEST=Boot on Ryu and check console isn't slow. Signed-off-by: Vic Yang <victoryang@chromium.org> Change-Id: I438c95835e56707b7ca1796734f2e47062799f44 Reviewed-on: https://chromium-review.googlesource.com/231115 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* USB: Enable finer grain control over init processAnton Staaf2014-11-131-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously enabling USB would automatically (using an init hook) initialize the USB peripheral. This would take over the GPIO lines assigned to the USB module. This is not OK on Ryu for Case Closed Debug because it interferes with the AP's access to the USB 2.0 lines even when not in Case Close Debug mode. This change adds a configuration option to inhibit this default initialization of the USB peripheral. It also renames the existing CONFIG_USB_INHIBIT to CONFIG_USB_INHIBIT_CONNECT now that there are two possible inhibitions. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Enable console on ryu_p2 and discovery-stm32f072 board Verify that it works on both Change-Id: I6734357131b4356e3d4164349d6c74deac196ce5 Reviewed-on: https://chromium-review.googlesource.com/229138 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org>
* USB: Add support for board specific connect/disconnectAnton Staaf2014-11-111-31/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously the usb driver used #ifs to select a mechanism to enable and disable the DP pullup. This doesn't scale well, especially when the knowledge of how to do this is not known to the chip specific code, but instead is board specific (as it is with the STM32F373). This change uses the build systems ability to build chip family specific files per build to select the appropriate behavior. And on the STM32F3 family of parts it just calls out to a board specific pair of connect/disconnect functions. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Enable console on ryu_p2 and discovery-stm32f072 board Verify that it works on both Change-Id: I976e02fbc7acbb0f85817d7295b26ee9ecab0711 Reviewed-on: https://chromium-review.googlesource.com/229040 Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
* USB: Remove special case for iVersion string descriptorAnton Staaf2014-11-041-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously the version string was special cased in the USB stack because the build system prevented the inclusion of ec_version.h in any file other than common/version.c. This lead to common/version.c being the only place that the USB version string could be computed and thus the special case of filling in the version string descriptor at run time. This made the USB stack more complex, and lead to the common/version.c file including usb.h, which is actually STM32 specific. Now, the portion of ec_version.h that is deterministic is only updated when something in the tree actually changes (by way of a conditional in the makefile), and ec_version.h no longer has to depend on all object files (other than the special version.o). This allows anyone to include ec_version.h as needed. In particular, each board that wants to define a USB version string can directly include ec_version.h and do so. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j touch files and verify rebuilds happen correctly Change-Id: Ic84d0b9da90f82ebb4630fb550ec841071e25a49 Reviewed-on: https://chromium-review.googlesource.com/227211 Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
* pd: dingdong/hoho: Include product VDO in discovery identity.Todd Broch2014-10-311-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Per table 6-24 of USB PD spec an alternate mode adapter (AMA) should include both product & AMA VDOs. BRANCH=samus BUG=chrome-os-partner:31192,chrome-os-partner:31193 TEST=manual, Connect hoho/dingdong to fpie/samus and see product VDO proceed the AMA VDO in DFP_U console output: Product VDO -----------------------------v |------| SVDM/5 [1] ff008041 340018d1 00000000 50100001 1100000b Note, hoho's PID == 0x5010 And dingdong (0x5011) SVDM/5 [1] ff008041 340018d1 00000000 50110001 1100000b Also see bcdDevice field in descriptor match above data. $ lsusb -v -d 18d1: | egrep -i "idproduct|bcddev" idProduct 0x5011 bcdDevice 0.01 Change-Id: I4d898816a45c68c7ff75a54fd348fc11be408ae0 Signed-off-by: Todd Broch <tbroch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226125 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* pd: dingdong/hoho: inhibit USB Billboard.Todd Broch2014-10-311-8/+25
| | | | | | | | | | | | | | | | | | | | | | | USB Billboard class can be used to advertise an alternate mode capable device that hasn't entered a mode. Additionally it can remain after mode entry providing its Billboard capabilities descriptor is updated. This CL postpones enumeration which previously occurred after boot until tAMETimeout has passed and alternate mode has NOT been entered. Future CL could choose to also (re)enumerate with mode capabilities although this is not required by the USB PD specification. BRANCH=none BUG=chrome-os-partner:31192,chrome-os-partner:31193 TEST=manual, With DFP_U which does not enter mode see Billboard class enumerate else it does not. Change-Id: I59a0815cd0ea551ba9a878907c0184df4ba9480c Signed-off-by: Todd Broch <tbroch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/224663 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* ryu_p2: Set alternate function for USB D+/D- pinsVic Yang2014-10-221-0/+6
| | | | | | | | | | | | | | | Unlike STM32F0, we need to configure alternate function for USB module on STM32F373. Adds the pin configuration for ryu_p2 and also adds the proper configuration step in USB module. BRANCH=None BUG=chrome-os-partner:32660 TEST=With changes to enable USB on ryu_p2, see the device enumerated Change-Id: I5e2cb7cfc44a1bb88bae69804021c783c8d17968 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/224789 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>