Commit graph

582 commits

Author SHA1 Message Date
Johann Fischer 00adb2a539 drivers: udc: remove no more required pending state flag
Pending state flag was only used by the UDC nRF USBD driver.
With the introduction of busy state flag it is no longer needed
and can be removed.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-11 17:44:50 +01:00
Johann Fischer a033784c7e drivers: usb: udc_nrf: fix race condition in nRF USBD
Periodic enqeueu of buffers can cause a attempt to start
a new transfer to host even though an IN endpoint is already busy.
Use busy state flags to explicitly mark an endpoint busy.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-11 17:44:50 +01:00
Johann Fischer baef621bed drivers: udc: add helper functions to set/check endpoint busy state
Add helper functions to set and check endpoint busy state.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-11 17:44:50 +01:00
Johann Fischer c1860326d1 drivers: udc: avoid NULL pointer dereferencing if endpoint is invalid
Immediately return NULL if endpoint configuration is not available.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-11 17:44:50 +01:00
Raul Pando cd1d7e4bb8 drivers: usb: make USB VBUS sensing configurable for STM32 devices
Vbus detection is required by self-powered, with external non-USB
supply, devices to have an operational USB peripheral. The voltage
sensing, when enabled, is performed via a designated pin (PA9 is
the most common).

For greater details see section 2.6, ST application note AN4879.

Signed-off-by: Raul Pando <raul.pando@bytegrity.co.uk>
2023-01-09 15:26:21 +00:00
Erwan Gouriou 56d93e3fef drivers: usb: stm32f1: USB clk prescaler config done in clock_controller
Now that USB clock prescaler is done is clock_control driver.
Remove similar part in USB driver.

Note that behavior is different: it is now up to the user to provide
the proper configuration.
Add a warning during the transition period.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-22 14:43:26 +01:00
Erwan Gouriou 66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Erwan Gouriou 11836dd4c1 dts: bindings: usb stm32: Remove deprecated prop 'enable-pin-remap'
Property is deprecated since more than one year.
Remove it and clean up related driver code.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-20 17:05:26 +00:00
Fabio Baltieri 4b48d91cce drivers: usb_dc_stm32: implement usb_dc_wakeup_request
Implement usb_dc_wakeup_request for STM32 USB DC and default to enable
remote wakeup functionality when the drivers is selected.

This allows the device to wake the host up by calling
usb_wakeup_request().

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2022-12-16 14:46:25 +01:00
Johann Fischer e939c1d8ae drivers: uhc: add driver for virtual USB host controller
Add support for virtual USB host controller intended for use
together with virtual bus and virtual device controllers.
This driver is not an emulation of any real host controller.
The driver has initial support for handling control and bulk
transfers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-16 13:21:12 +01:00
Johann Fischer ac649c35fd drivers: udc: add driver for virtual USB device controller
Add support for virtual USB device controller intended for use
by virtual bus and virtual UHC controllers. This driver is not
an emulation of any real host controller.
The driver has initial support for handling control and bulk
transfers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-16 13:21:12 +01:00
Johann Fischer deb637eb8a drivers: usb: add support for virtual USB bus
Add support for virtual USB bus (UVB) intended for use
by virtual UDC and UHC controllers. UVB is not an emulation
of the USB bus or protocol but a simplified service to connect
a virtual host controller to one or more virtual device
controllers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-16 13:21:12 +01:00
Johann Fischer da639954c1 drivers: usb: add common layer of UHC API and MAX3421E driver
Add common layer of UHC API and MAX3421E host controller driver.
This implements the bare minimum necessary to communicate with
one peripheral device.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-16 13:21:12 +01:00
Ryan McClelland 1f489cf03a drivers: usb: stm32: add usb hs ulpi support
Add support for the STM32H7 USB OTG HS and support for the ULPI PHY.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2022-12-15 14:28:00 +00:00
Johann Fischer 95717520bf drivers: udc: do not call driver's dequeue on empty fifo
Do not call driver's dequeue implementation if endpoint fifo
is empty.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-14 12:06:03 +01:00
Johann Fischer 721b8c22d8 drivers: udc_nrf: dequeue instantly when endpoint is not busy
In the case that IN endpoint is not busy there will be
no notification from the HAL driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-14 12:06:03 +01:00
Georgij Cernysiov 581a50e000 drivers: usb: stm32: Simplify Kconfig help message
The USB_DC_STM32 help message started to miss some
STM32 MCU families. Overtime, the message will
get bigger if we continue to list family names.
Removed family names to simplify the message and
avoid periodic modifications.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2022-12-08 09:58:58 +00:00
Francois Ramu 2ed292e1be drivers: stm32: do not enable the HSI48 locally
The HSI48 is enabled by clock control driver.
It is no more done by each driver that requires this clock
However when using rng or sdmmc or bluetooth/ipm or usb,
the HSI48 clock must be present in the DTS.
Add a warning for this particular check but keep the deprecated
HSI48 clock enable : keeping for legacy but to remove later.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-12-07 10:03:11 +00:00
Mark Watson 5381e0b716 drivers: usb: usb_dc_nrfx: add usbd worker thread name.
I added a thread name to the usbd worker thread.

Signed-off-by: Mark Watson <mwatson@prosaris.ca>

Fixes: #43330
2022-12-05 18:03:39 +01:00
Tomasz Moń 22168bd45c drivers: usb_dc_nrfx: Do not uninit on detach
It is possible for nrfx usbd driver to send NRFX_USBBD_EP_ABORTED during
endpoint disable. The event is passed to event handler registered with
nrfx_usbd_init(). The nrfx_usbd_uninit() removes the registered event
handler, replacing it with NULL. If any event is sent after uninit, the
NULL pointer is executed and device crashes.

Do not uninit nrfx usbd driver on detach so it is possible for the
usb_disable() to disable all the endpoints.

Fixes: 460ca86527 ("drivers: usb_dc_nrfx: Always allow endpoint disable")

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-12-05 15:50:43 +01:00
Johann Fischer 1083e61163 drivers: udc: add USBFSOTG UDC driver for Kinetis SoCs
Add USBFSOTG UDC driver for Kinetis SoCs.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-02 12:55:18 +01:00
Johann Fischer 1f11fbc1aa drivers: udc_nrf: do not abuse HAL events for the driver's concerns.
HAL events were also used for the shim driver's concerns
during the prototyping of API. Fix it now and use specific
shim driver events. That also allows new transfers to be
triggered from a single point.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-02 12:55:18 +01:00
Johann Fischer 292951da4b drivers: udc_nrf: implement method to distiguish hal and shim events
Implement method to distiguish hal driver and UDC shim driver events.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-02 12:55:18 +01:00
Johann Fischer 1fa31bbc30 drivers: usb: add new USB device controller API (UDC API)
Add new USB device controller API and nRF USBD controller driver.
The new UDC API brings support for multiple instances and asynchronous
transfer model, transfers use net_buf and store methadata in the
user data area.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-12-02 12:55:18 +01:00
Tomasz Moń 12e244b184 drivers: usb_dc_native_posix: Allow endpoint disable after detach
There is no reason to prevent endpoint disable after detach.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-25 20:02:42 +01:00
Tomasz Moń 460ca86527 drivers: usb_dc_nrfx: Always allow endpoint disable
There is no point in allowing endpoint disable only when device is
attached and ready. Remove the pointless check as it is actually harmful
and prevents endpoints disable on USB stack disable.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-25 20:02:42 +01:00
romain pelletant 8aa4164518 drivers: usb_dc_stm32: implement usb_dc_detach()
Implement support to detach USB device.

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2022-11-15 12:15:54 +00:00
Milind Paranjpe 7a1cd99555 drivers: usb: mcux: mark endpoint unoccupied on disable
In usb_dc_ep_disable() mark an endpoint as unoccupied in addition to
being disabled. This allows the endpoint to get enabled properly
with a subsequent call to usb_dc_ep_enable()

See: zephyrproject-rtos/zephyr#51685

Signed-off-by: Milind Paranjpe <mparanjpe@yahoo.com>
2022-11-11 15:10:26 -06:00
Lukas Gehreke 1bd931ab66 drivers: usb_dc_rpi_pico: fixed buffer status handling
The buf_status register is 32 bit wide but was saved in a
uint8_t. This caused some buffers never to be handled which
results in the pico getting stuck in the interrupt handler.

Signed-off-by: Lukas Gehreke <lk.gehreke@gmail.com>
2022-11-11 08:50:09 +00:00
Milind Paranjpe 21da8c27bf drivers: usb: mcux: Deinit then Init endpoint HAL during config
The USB device subsystem driver's set_interface() function calls
usb_dc_ep_configure() followed by usb_dc_ep_enable(). When
switching between alternate settings of a configuration's
interface, set_endpoint() can be followed by reset_endpoint() on
an endpoint. Some time later, set_endpoint() can be called again
on the same endpoint. This results in the HAL's
kUSB_DeviceControlEndpointInit function being called twice in a
row, which causes a memory allocation error. A simple solution is
to call the HAL's kUSB_DeviceControlEndpointDeinit function
before calling kUSB_DeviceControlEndpointInit. This overcomes the
memory allocation error.

Signed-off-by: Milind Paranjpe <mparanjpe@yahoo.com>
2022-11-08 09:43:44 +00:00
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Gerson Fernando Budke b3c5dcf1c6 drivers: usb: usb_dc_sam0: Add missing kernel include
Fix warnings and undefined symbols reported by CI.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-10-17 14:38:53 +09:00
Gerard Marull-Paretas 6a0f554ffa include: add missing kernel.h include
Some files make use of Kernel APIs without including kernel.h, fix this
problem.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Gerard Marull-Paretas acc8cb4bc8 include: add missing irq.h include
Some modules use the IRQ API without including the necessary headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Tomasz Moń 8c7eba346a driver: usb_dc_sam_usbhs: Restore EP0 after detach
SAM V71 Xplained Ultra failed to re-enumerate on the bus after device
detach-attach sequence. The device was recognized by the host, but it
was not responding to control transfers, i.e. it was not acknowledging
SETUP data. Make device acknowledge SETUP data by reconfiguring EP0
when necessary.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-09-23 11:52:18 +02:00
Tomasz Moń 37705bc554 driver: usb_dc_sam_usbhs: Actually set detach bit
Device physically detaches when the DETACH bit is set. Fix the
assignment to actually set the bit instead of clearing it.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-09-23 11:52:18 +02:00
Tomasz Moń 0d4aa49766 drivers: usb_dc_nrfx: Do not uninit endpoints on detach
Sometimes it is desired for the USB device to detach and reattach itself
to the host. USB device controller driver interface supports detach with
usb_dc_detach() function. Subsequently the device can be reattached to
the bus by calling usb_dc_attach().

USB device stack sets the control transfer callbacks in usb_enable().
Nordic usb_dc_detach() implementation inadvertedly overwrote registered
callbacks with zeroes by clearing endpoint configuration structure. This
lead to a NULL pointer dereference during enumeration after device has
reattached inself to the host.

Preserve the callbacks by removing the eps_ctx_uninit() function.
Endpoints runtime data is initialized in usb_dc_attach() so this should
pose no problems.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-09-21 12:56:39 +02:00
Steven Slupsky 32f4f8d987 drivers: usb: usb_dc_sam0: fix memory leak
The usb_dc_sam0 driver is leaking memory when the usb device is detached
using usb_disable().

When a device is detached, the driver does not reliably deallocate the
descriptor bank memory. Therefore, upon the next attach and configure,
another block of memory is allocated. After several connect /
disconnect sequences, the usb interface becomes unresponsive.

This commit adds a static function to release all memory allocated
to the ep descriptors when usb_dc_detach() is called.  Since detach is
called from usb_disable(), this releases the memory when the
interface is disabled.

Avoid calling k_free() if buffer pointer is already
set to NULL.

Fixes #49177

Signed-off-by: Steven Slupsky <sslupsky@gmail.com>
2022-09-19 15:20:53 -05:00
Nick Kraus dd1d367f34 driver: usb_dc_sam_usbhs: Initialize Endpoint FIFO
Ensure that the FIFO of each endpoint is initialized during endpoint
configuration, to prevent a NULL FIFO from being encountered during the
first call to usb_dc_ep_write() for a given endpoint.

Signed-off-by: Nick Kraus <nick@nckraus.com>
2022-09-09 16:31:43 -04:00
Mahesh Mahadevan 9966181510 drivers: usb: mcux: Restructure driver for SDK updates
1. Move the defines from usb_dc_mcux.h to usb_device_config.h
   and fsl_os_abstraction.h. These headers are used by
   the SDK USB driver. usb_dc_mcux.h header file is not longer
   needed and hence deleted.
2. Delete the Zephyr implementation of the usb_device_struct
   driver and use the one implemented inside the SDK USB
   driver. This requires updating the references to
   usb_device_struct inside the USB driver
3. Move defines and structures used by the driver
   out of the header file that is included by the SDK and
   into the MCUX USB driver.
4. Use end point defines provided by Zephyr instead of adding
   them locally.
5. Add a Kconfig to set the thread stack size
6. Move code to enable interrupts back to usb_attach function.
   Interrupts should be enabled after the init is successful,
   else we see errors of the ISR getting called before the
   init is complete causing Faults
6. Update west.yml to update the NXP HAL to get the updated
   SDK USB driver.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2022-09-09 09:44:46 -05:00
Mahesh Mahadevan c5f44f94f8 drivers: usb: Update MCUX controller identification
Use device tree to identify the controller type

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2022-09-09 09:44:46 -05:00
Marcin Niestroj cf4578bdda drivers: usb_dc_rpi: set thread name
Thread name is useful when debugging or using shell with
CONFIG_THREAD_NAME=y.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-09-02 11:00:48 +00:00
Marcin Niestroj 966738db2c drivers: usb_dc_mcux: set thread name
Thread name is useful when debugging or using shell with
CONFIG_THREAD_NAME=y.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-09-02 11:00:48 +00:00
Marcin Niestroj de36a7d7f4 drivers: usb_dc_kinetis: set thread name
Thread name is useful when debugging or using shell with
CONFIG_THREAD_NAME=y.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-09-02 11:00:48 +00:00
Marcin Niestroj 1e982fffd2 drivers: usb_dc_rpi: create thread and connect IRQ during init
So far thread was created as part of usb_dc_attach() by k_thread_create().
This means that if following function were executed:

 * usb_enable()
 * usb_disable()
 * usb_enable()

then k_thread_create() was called second time. This results in undefined
behavior.

Fix above issue by moving k_thread_create() invocation to function called
during system initialization.

While at it, move IRQ_CONNECT() and irq_enable() invocations to init as
well.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-09-02 11:00:48 +00:00
Marcin Niestroj e4480d6ab6 drivers: usb_dc_mcux: create thread and connect IRQ during init
So far thread was created as part of usb_dc_attach() by k_thread_create().
This means that if following function were executed:

 * usb_enable()
 * usb_disable()
 * usb_enable()

then k_thread_create() was called second time. This results in undefined
behavior.

Fix above issue by moving k_thread_create() invocation to function called
during system initialization.

While at it, move IRQ_CONNECT() and irq_enable() invocations to init as
well.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-09-02 11:00:48 +00:00
Marcin Niestroj 9de245a588 drivers: usb_dc_kinetis: create thread and connect IRQ during init
So far thread was created as part of usb_dc_attach() by k_thread_create().
This means that if following function were executed:

 * usb_enable()
 * usb_disable()
 * usb_enable()

then k_thread_create() was called second time. This results in undefined
behavior.

Fix above issue by moving k_thread_create() invocation to function called
during system initialization.

While at it, move IRQ_CONNECT() and irq_enable() invocations to init as
well.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-09-02 11:00:48 +00:00
Kumar Gala 2ac45e09db drivers: usb: device: Update drivers to use devicetree Kconfig symbol
Update usb device drivers to use DT_HAS_<compat>_ENABLED Kconfig symbol
to expose the driver and enable it by default based on devicetree.

We remove 'depend on' Kconfig for symbols that would be implied by
the devicetree node existing.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-08-25 08:05:54 -05:00
Gerard Marull-Paretas a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Henrik Brix Andersen 5a61e664b7 drivers: usb: check if clock device is ready before accessing
Add check for device_is_ready() before accessing clock control devices.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-09 17:16:16 +02:00
David Jablonski 855a489a1c usb_dc_stm32: fix init on soft reset
Soft resetting a STM32 device currently does not reset the USB
connection, which causes a few problems: The endpoints do not respond
anymore, and within zephyr any kind of status information like
CDC_SET_CONTROL_LINE_STATE is also missing as they are not
re-negotiated.

This is fixed by stopping the USB device from zephyr side, right after
initialising the USB device.

Signed-off-by: David Jablonski <dayjaby@gmail.com>
2022-08-01 18:03:42 +02:00
Simon Hein d0921018fc drivers: Fix coding guidelines MISRAC:2012 Rule 14.4 do-whiles/Zero checks
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)

Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.

The commit is a subset of the original auditable-branch commit:
5d02614e34a86b549c7707d3d9f0984bc3a5f22a

Signed-off-by: Simon Hein <SHein@baumer.com>
2022-07-26 15:30:24 -04:00
Chris Collins 3a0f8a3d45 drivers: usb: device: stm32: Use macros for frequencies
Rather than explicitly setting out the frequnecy in full, use the MHZ()
macro.

Signed-off-by: Chris Collins <chris@realsimgear.com>
2022-07-04 18:07:06 +02:00
Chris Collins f1e4d7bbef drivers: usb: device: stm32: Configure USB Prescaler for F103
- If the HAL headers expose the USBPRE flag, then we're probably
  dealing with a F103 - using the same fundamental logic as the
  code for the OTG models, set-up the USB Prescaler correctly.

- Fixes #47146

Signed-off-by: Chris Collins <chris@realsimgear.com>
2022-07-04 18:07:06 +02:00
Kumar Gala 75f44cf991 drivers: usb: usb_dc_stm32: Update driver to use gpio_dt_spec
Move driver to use gpio_dt_spec for GPIO access.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-04 09:49:29 +02:00
Aurelien Jarno b2f969e562 drivers: usb: device: stm32: only disable the ULPI clock for USB FS
On SoCs with two USB controller, Zephyr selects the FS one, and in that
case the ULPI clock needs to be disabled in sleep mode for the
controller to work.

On SoCs with a single USB HS controller, this operation is not needed.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno e19be674fc drivers: usb: device: stm32: fix disabling the ULPI clock on STM32H7X
The ULPI clock uses slightly different names on STM32H7X as those
SoC can have more than one USB controller.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno a9f044e0d2 drivers: usb: device: stm32: fix a wrong comment STM32H7X and ULPI clock
On STM32H7X SoCs, both USB controllers are HS capable, however it is not
possible to connect an ULPI PHY to the USB2 one, which limit it to FS.
Therefore the ULPI clock in sleep mode has to be disabled for USB2 in
all cases. The ULPI clock for USB1 is already disabled when needed in
the usb_dc_stm32_clock_enable() function like for other SoCs.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno 58674926a9 drivers: usb: device: stm32: do not manually enable the clock on STM32H7
Do not manually enable the USB clock on STM32H7, as it is already done
in usb_dc_stm32_clock_enable() using the values in the device tree.

This partially fixes the build for STM32H7 devices with a single USB
controller.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno 278bf9883f drivers: usb: device: stm32: do not disable ULPI clock in run mode
The ULPI clock is disabled by default in run mode, there is no need to
disable it again. It is however enabled by default in sleep/low power
mode, so it needs to be disabled.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Fabio Baltieri e24314f10f include: add more missing zephyr/ prefixes
Adds few missing zephyr/ prefixes to leftover #include statements that
either got added recently or were using double quote format.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-05-27 15:20:27 -07:00
Chris Collins ce84c782dc drivers: usb: device: stm32: fix disconnect-gpios configuration.
For some reason, rather than testing for the presence of
disconnect-gpios in the devicetree, the STM32 USB Device driver was
relying on a hidden Kconfig flag to be set.

This patch removes the Kconfig option completely and simply tests for
the DT property - if it's set, you obviously know what you're doing and
obviously need the pull-up GPIO behaviour.

Signed-off-by: Chris Collins <chris@realsimgear.com>
2022-05-19 11:28:38 -07:00
Peter Johanson 43b77a2191 drivers: usb: Add RP2040 USB device support.
Add USB device driver for Rasberry Pico family of controllers.

Signed-off-by: Peter Johanson <peter@peterjohanson.com>
2022-05-13 16:28:27 +02:00
Esteban Valverde 03ec46889b drivers: usb: Adding support to GIC_V1 in dc_dw USB driver
Adding support for the GIC_V1 to the dc_dw USB driver
to be used by Cyclone V SoC FPGA Development Kit

Signed-off-by: Esteban Valverde <esteban.valverde.vega@intel.com>
2022-05-10 13:29:47 -04:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Gerson Fernando Budke 8961172e6d drivers: usb: Add sam0 support to pinctrl
This add support to pinctrl at Atmel sam0 usb dc driver. It updates
all boards with new pinctrl groups format and drop pinmux entries.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-03-24 15:45:37 -07:00
Gerson Fernando Budke 3c4a9ef47d drivers: usb: Update sam usb drivers to use pinctrl
This update Atmel sam usb drivers to use pinctrl driver and API. It
updates all boards with new pinctrl groups format.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-03-24 15:45:37 -07:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Daniel DeGrasse 4f792714a8 drivers: usb_dc_mcux: Enable second USB EHCI
Enable second usb EHCI if usb2 node has status="okay" Note that this
driver is still an single instance driver, this change simply enables
the driver to work with the usb2 peripheral if that one is enabled, and
usb1 is disabled.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-03-11 14:50:11 -08:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Daniel DeGrasse 2ac1b42952 drivers: usb_dc_mcux: Move mcux callback handler out of ISR context
MCUX usb ISR was making usb callbacks directly, which caused assertion
failures when a callback attempted to lock a mutex. Move USB callback
handler to separate thread, and make ISR notify thread via message
queue.

Fixes #40638

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-01-28 10:05:47 +01:00
Gerard Marull-Paretas 5dc6ed3ce3 pinctrl: require ; after PINCTRL_DT_(INST_)DEFINE macros
The PINCTRL_DT_(INST_)DEFINE macros already defined the trailing ;,
making its usage inconsistent with other macros such as
DEVICE_DT_DEFINE.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-01 07:39:08 -05:00
Johann Fischer 64751220bd drivers: usb: allow to disable option USB_DEVICE_REMOTE_WAKEUP
This flag may cause host to more ambitious power saving behavior,
not all Zephyr USB classes or applications may be ready for this
now. Allow to disable option USB_DEVICE_REMOTE_WAKEUP.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-12-14 09:08:58 -05:00
Erwan Gouriou 90b0e92540 drivers/usb/device: stm32: use new pinctrl API
Use the new pinctrl API to configure pins.

Additionally, rename usb_pinctrl to usb_pcfg to better fit
new pinctrl API.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-11-26 11:36:42 +01:00
Raúl Sánchez Siles f35cdfc1e4 drivers: usb_dc_native_posix fill in data amount
Fill in received bytes in USBIP_RET_SUBMIT packet

Currently this field is unconditionally set to 0 and therefore not
filled in conveniently. This may mislead the USB host which is correctly
acknowledged that the transaction was sucessful but it cannot check the
actual received bytes.

Test application:

```python
import usb

data = (0xFF, 0xFF)
print("Opening loopback device")
device = usb.core.find(idVendor=0x2FE3, idProduct=0x0009)
print("Writing test data", data)
written = device.write(0x1, data)
print("Written", written, "bytes")
```

Before:
```
$ ./test_loopback.py
Opening loopback device
Writing test data (255, 255)
Written 0 bytes
```

After:
```
$ ./test_loopback.py
Opening loopback device
Writing test data (255, 255)
Written 2 bytes
```

Signed-off-by: Raúl Sánchez Siles <rsanchezs@k-lagan.com>
2021-11-24 17:55:04 +01:00
Johann Fischer 48362df588 drivers: usb_dc_sam_usbhs: default to full-speed
Use DT_INST_ENUM_IDX_OR and always default to full-speed
if CONFIG_USB_DC_HAS_HS_SUPPORT is not set or maximum-speed
property is not defined.
Remove low-speed setting since device stack does not support it.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-24 12:28:02 +01:00
Johann Fischer cf8d7764da usb: fix bulk endpoint configuration for high-speed capable device
In the current USB device support, the sizes of bulk endpoint
are mostly configure through Kconfig and do not care if a device
is high-speed capable. The information if a USB device controller
supports high-speed comes from devicetree. Add a Kconfig option to
map this information and configure bulk endpoint sizes
accordingly.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-24 12:28:02 +01:00
Johann Fischer f2e45d75a7 drivers: usb_dc_native_posix: check return value from recv()
Check return value from recv() passed by usbip_recv().

Fixes: #39849
Fixes: #39869
Coverity-CID: 240221
Coverity-CID: 240244

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-22 09:11:41 +01:00
Gerard Marull-Paretas c759a35d08 drivers: use DT_INST_ENUM_IDX(_OR) macros
Replace `DT_ENUM_IDX(_OR)(DT_DRV_INST(...),` pattern with
`DT_INST_ENUM_IDX(_OR)(...,`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-18 19:12:07 -05:00
Johann Fischer 02c32d4474 usb: move USB_DEVICE_REMOTE_WAKEUP option to drivers
Kconfig USB_DEVICE_REMOTE_WAKEUP option depends only on
USB device controller capability, but is not controlled
by the USB device controller drivers configuration.
Move USB_DEVICE_REMOTE_WAKEUP option to drivers and
make it promptless.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-08 17:01:32 +01:00
Francois Ramu 2ebf885ab0 drivers: usb device driver for the stm32u5 soc family
This commit enables the HSI48 clock for the stm32U5 soc family
to use the USB device peripheral.
Enable the VDD USB voltage supply.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-11-04 10:25:17 -05:00
Erwan Gouriou aa144ca3f0 drivers/usb: stm23: Fix deprecated macro declaration
Use of '__DEPRECATED_MACRO' was not compatible with the way macro
is used later in this driver.
Remove it and keep the warning as vector for deprecation information.

Additionally, replace DT_NODE_HAS_PROP with DT_INST_PROP as
using the former is not recommended with boolean properties.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-10-21 05:53:52 -05:00
Andrzej Głąbek 40329881bf soc: nrf52: Add Kconfig option for enabling REG0 DC/DC converter
Add a Kconfig option, similar to the one that is already available
for nRF5340, that allows enabling the REG0 (VDDH) DC/DC converter
in nRF52840. Make use of this option in Nordic boards: nRF52840 DK
and nRF52840 Dongle.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2021-10-17 11:49:26 -04:00
Luc Viala a94c2bc78b usb: stm32l5: add configuration to enable HSI48 clock
Add configuration to enable HSI48 clock when using USB from STM32L5
board

Signed-off-by: Luc Viala <luc.viala19@gmail.com>
2021-10-13 06:15:58 -04:00
Erwan Gouriou 19a40a15b6 drivers/usb: stm32: Deprecate 'enable-pin-remap'
'enable-pin-remap' is deprecated in favor of 'remap-pa11-pa12' from
'st-stm32-pinctrl'.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-10-07 15:38:53 -04:00
Daniel Leung 89ddd0bfd2 usb: usb_dc_mcux: use K_HEAP_DEFINE_NOCACHE()
This changes "__nocache K_HEAP_DEFINE()" to use the new
K_HEAP_DEFINE_NOCACHE() macro. This fixes a build error
as K_HEAP_DEFINE() is specifying its own linker section
so that it is no longer possible to specify another
linker section.

Fixes #38108

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-31 16:29:11 -04:00
Johann Fischer 010b448454 drivers: usb_dc_nrfx: add logging for NRFX_USBD_EP_ABORTED event
Add logging for NRFX_USBD_EP_ABORTED event inside
control transfer events handling, otherwise "Unexpected event"
error message in this regard confuses the users.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-30 13:37:14 -04:00
Gerson Fernando Budke 1c43138333 drivers: usb: dc: sam: Add full driver fsm
Add sam4l full finite state machine based on Atmel Software Framework.
This allows driver detect protocol errors and sync all requests.  This
version is compliance with Linux USB tests.

Note: Tests are timing sensitive and log may affect results.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2021-08-26 14:03:44 -04:00
Gerson Fernando Budke 670c067563 drivers: usb: dc: sam: Add atmel USBC controller
Add atmel USBC device controller.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2021-08-26 14:03:44 -04:00
Yong Cong Sin cf3b18bec0 drivers: usb: device: Add support for USB on STM32G0X
Patches to support USB_DRD_FS on STM32G0 series.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-08-23 08:24:46 -04:00
Mahesh Mahadevan e3a14d9cb9 drivers: usb: Rename NXP EHCI driver
Rename to usb_dc_mcux as this driver is used for both
EHCI and LPC USB controllers

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2021-08-19 17:19:11 -04:00
Mahesh Mahadevan 3982708359 drivers: usb: Add support for NXP LPC USB controller
1. Add support for NXP LPC USB controller
2. Do not check the return value from the
   kUSB_DeviceControlRun command as not all SDK drivers
   return a value
3. Use the kUSB_DeviceControlPreSetDeviceAddress
   command to set device address

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2021-08-19 17:19:11 -04:00
Daniel Leung 25b47290bd drivers: usb: build as static library
Instead of putting object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-17 06:06:03 -04:00
Mahesh Mahadevan a69bd75bd8 modules: hal_nxp: Move NXP USB file to modules folder
Move USB file to from modules/hal_nxp to zephyr/modules
folder

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2021-08-13 12:51:46 -04:00
Johann Fischer ae074e81d4 usb: remove Kconfig option CONFIG_USB
The USB configuration option is actually a global switch
to enable USB drivers in general, but currently only
the device controller drivers are meant.

USB device controller drivers also have USB_DEVICE_DRIVER option.
Thus the option USB is actually redundant and can be replaced
by the self-explanatory option USB_DEVICE_DRIVER.
The name USB itself is not unique and should not be used as an
configuration option.

With these changes the option USB_DEVICE_DRIVER generally
enables USB device controller drivers. The option USB_DEVICE_STACK
enables USB device support. It is sufficient to enable only option
USB_DEVICE_STACK because it selects USB_DEVICE_DRIVER.

CONFIG_USB Kconfig option is temporary added to subsys/usb/Kconfig.
This is necessary to pass CI and will be removed again
when the USB configuration has been adapted in modules.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:00:12 -04:00
Johann Fischer 6954554284 drivers: usb: use new USB framework header
Use macros and types from usb/usb_ch9.h header where it
is possible. This patch also adds local macros, USB_REQTYPE_GET_DIR
and USB_REQTYPE_GET_TYPE, which is an intermediate solution and
these will be removed later.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 13:20:07 +02:00
Johann Fischer 0500ec214c drivers: usb_dc_mcux_ehci: use K_NO_WAIT in k_heap_alloc()
This is called in ISR context and timeout must be set
to K_NO_WAIT.

Reported-by: Pieter De Gendt <pieter.degendt@basalte.be>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-07-14 13:05:18 -05:00
Johann Fischer 8eeec634ea drivers: usb_dc_mcux_ehci: fix style
Fix style, two lines are indented too far.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-07-14 13:05:18 -05:00
Gerson Fernando Budke 0ff3616bdf drivers: usb: device: Rename usb_dc_sam to usb_dc_sam_usbhs
The SoC driver name is 'USB High-Speed Interface (USBHS)'. This rename
from usb_dc_sam to usb_dc_sam_usbhs allowing add others SoC drivers
like 'USB Device Port (UDP)' that is found at SAM4S/E variations.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2021-07-14 07:23:38 -04:00
Erwan Gouriou fcc3177509 drivers/pinmux: stm32: Move stm32 driver from stm32/
Since we removed various series headers, move stm32 driver
under main driver/pinmux folder.
Take this change into account into various drivers.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-06-11 08:04:39 -05:00
Johann Fischer 26f2e33227 drivers: usb_dc_nrfx: add attached event delay
Add configurable attached event delay. Delay can be used to give
USB Charging Controller time for initialization.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-04-29 09:55:28 -04:00
Erwan Gouriou 2691541ad2 drivers/clock_controller: stm32: Prepare for dts based configuration
To allow transition to device tree based clock configuration on
stm32 targets, rework clock_control driver to use intermediate
STM32_ macros initially defined as the equivalent Kconfig macros
for now.
Propagate the change in all code using these macros.

The reason to introduce these new macros instead of configuring
Kconfig flags using dt kconfigfunctions is that we'll need
to be able to inform users that Kconfig flags are deprecated
once the whole family conversion is done, to encourage
out of tree users to adopt this new configuration scheme.

Note: For now STM32H7 series and code is excluded.
This is the same for some series specific code such as
PLL mul/div for L0/L1 and XTRE prescaler on F1 series.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-04-27 11:53:37 +02:00
Johann Fischer 583334b606 drivers: usb_dc_nrfx: clear endpoint flags during ep_disable()
If a loaded endpoint was disabled and then reconfigured,
it is not possible to start an IN transfer and
usb_dc_ep_write() returns -EAGAIN.

Call ep_ctx_reset() to clear endpoint operations flags
and reset buffer after endpoint is disabled.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-04-20 15:04:47 +02:00
Peter Bigot 2ac596b91a usb: conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Be aware that this does not address architectural errors in the use
of the work API.

Fixes #34092

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-04-15 12:29:34 -04:00
Jeremy Wood 5164d65269 drivers: usb: device: Add support for USB FS on STM32H7.
* Assumes that the USB2_OTG peripheral is being used in FS mode, as on
  the NUCLEO-H743/753.
* Disable ULPI on USB2_OTFG, enable FS clk.
* Enable USB voltage detect and disable USB reg, per STM app notes.

Signed-off-by: Jeremy Wood <jeremy@bcdevices.com>
2021-03-29 13:42:46 -04:00
Johann Fischer 63ca48a7a9 drivers: usb_dc_native_posix: use ep_dir and ep_idx in usbip_send_common
Use ep_idx in usbip_send_common() instead of endpoint address
and get direction from endpoint address.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-24 15:02:49 +01:00
Johann Fischer 735ba17cad drivers: usb_dc_native_posix: read setup packet as part of submit struct
USB setup packet is a part of USBIP_CMD_SUBMIT, but missing
in struct usbip_submit. This patch fixes it and removes
usbip_skip_setup() and adds an additional integrity check
in handle_usb_control().

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-24 15:02:49 +01:00
Johann Fischer 6c214f796e drivers: usb_dc_native_posix: rework how OUT endpoint data is passed
The transfer length is not stored and processed properly.
Use struct usb_ep_ctrl_prv, which we already have, to store
the transfer length and data. Move usbip_recv() to
handle_usb_control() and handle_usb_data(),
and explicitly copy USB setup packet.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-24 15:02:49 +01:00
Johann Fischer 77c2c1230b drivers: usb_dc_native_posix: do not use IN callback without reason
Call the IN callback only if data in usb_dc_ep_write()
is actually written to the intermediate buffer and sent.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-24 15:02:49 +01:00
Johann Fischer 16cd3be690 drivers: usb_dc_native_posix: rework handle_usb_control/handle_usb_data
Use pointer to struct usb_ep_ctrl_prv, which allows to remove
a few variables and simplifies subsequent improvements.

Use consistently ep_idx in handle_usb_control() instead of
ntohl(hdr->common.ep).

Revise logging so that it is clearer what event is being processed.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-03-24 15:02:49 +01:00
Johann Fischer 627c04f962 drivers: usb_dc_stm32: remove confusing comments
The comments at the beginning of the file are not quite correct
and instructions regarding configuration are not necessary at all.
Also remove the redundant first line.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-02-24 12:01:50 +01:00
Kumar Gala b275fec8c4 soc: stm32: convert to use DEVICE_DT_GET for clocks
Convert from device_get_binding to DEVICE_DT_GET.  In doing this we
no longer need the label in the devicetree node so we remove that.

Removed all __ASSERT_NO_MSG(clk) since we'll get a build error if
DEVICE_DT_GET cant be satisfied, and the clock control api's will
handle reporting if the device_is_ready.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-16 17:01:37 -06:00
Jacob Siverskog 6e0ef1cdd9 drivers: usb: stm32: fix potential null pointer dereference
perform null pointer check before dereferencing.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2021-02-16 15:27:59 +03:00
Aurelien Jarno 35adb6e2c4 drivers: usb_dc_sam: get the maximum speed from DT as enum
For historical reasons, the maximum speed of the Atmel SAM USB
controller is done by comparing the maximum-speed property string from
the DT using strncmp at runtime.

Now that the DT_ENUM_IDX macro exists, we can use it to get the
maximum-speed property at build time and without string comparison.
Unsupported speed can also be reported at build time.

Note that the default speed in case the optional maximum-speed property
isn't present in the DT is changed from full-speed to high-speed to
match the property description. This is a no-op in practice as this
properties is defined at the soc level.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-01-10 18:11:37 -05:00
Attie Grande 78627a5feb usb: stm32: added support for USB Device mode on STM32F105xx parts
The STM32F105xx USB clock goes through a prescaler either PLL1 x2 /2
or PLL1 x2 /3, the output of this must be 48 MHz. As such, the output
of PLL1 must be 48 MHz or 72 MHz.

NOTE: This requires that the system is running from PLL1 (PLLCLK).
      Support for running from PLL2 will be implemented in the future.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2021-01-10 12:42:40 -05:00
Marek Pieta f5a38cb5be drivers: usb_dc_nrfx: Use mem_slab for fifo elements
mem_slab can be used instead of heap, because all allocated
elements have the same size.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2021-01-04 16:26:02 +01:00
Marek Pieta 5dbca81f1a drivers: usb_dc_nrfx: Use static memory for out endpoints
Change switches to using static memory for out endpoints. Using
heap is not necessary, because number of out endpoints is defined
in DTS.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2021-01-04 16:26:02 +01:00
Andy Ross fcd392f6ce kernel: subsys: lib: drivers: Use k_heap instead of z_mem_pool wrappers
Use the core k_heap API pervasively within our tree instead of the
z_mem_pool wrapper that provided compatibility with the older mempool
implementation.

Almost all of this is straightforward swapping of one alloc/free call
for another.  In a few cases where code was holding onto an old-style
"mem_block" a local compatibility struct with a single field has been
swapped in to keep the invasiveness of the changes down.

Note that not all the relevant changes in this patch have in-tree test
coverage, though I validated that it all builds.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross 6965cf526d kernel: Deprecate k_mem_pool APIs
Mark all k_mem_pool APIs deprecated for future code.  Remaining
internal usage now uses equivalent "z_mem_pool" symbols instead.

Fixes #24358

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Martin Jäger 0636b42c81 drivers: usb: stm32: use generic LL headers
Use generic LL headers instead of depending on soc.h.

Signed-off-by: Martin Jäger <martin@libre.solar>
2020-11-30 15:50:03 +01:00
Johann Fischer 5cd66c69c6 drivers: usb_dc_nrfx: remove k_mem_pool_free for IN endpoints
Usage of mem_pool for all IN endpoints was removed in
commit b3c63425a0 ("usb: driver: Reduce Endpoint buffer pool.")
Remove also k_mem_pool_free for all IN endpoints.

Fixes: #30213

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2020-11-25 14:23:48 +02:00
Emil Obalski 773f02e6e9 usb: drivers: Fix ZLP handling for Nordic driver.
ZLP - zero length packet is used to indicate that the device
has no more data to send. If the Host asks for more data that the
device can provide and the data size is mutliplication of Endpoint
wMaxPacketSize then the device must terminate the data transfer
with ZLP.

Until this patch Nordic device driver controller was not aware of
the requested data length and could not determine when the ZLP was
required.

This patch introduces a fix that prevents the driver from starting
setup stage before the ZLP is being send.

For consistance with the Zephyr USB stack sending ZLP must be
issued from the stack level. Making trans_zlp flag true results
in blocking the driver from starting setup stage without required
ZLP.

After the data transfer finishes the driver will be prepared for ZLP
and will call back the stack to start writing ZLP. After the ZLP
is being send the driver will automatically start status stage and
end the Control Transfer.

This patch also removes CONFIG_USB_DEVICE_DISABLE_ZLP_EPIN_HANDLING
and aligns Nordic driver with others.

Without this patch the issue could occur when handling get requests.
Typical case is string descriptor of length equal to wMaxPacketSize.
Hosts usually asks for wLength = 255 Bytes when string descriptors
are being requested. In that case to successfully finish the data
stage of the Control transfer the device must send wMacPacketSize
Bytes of actual string descriptor and then ZLP to indicate that no
more data are present. After ZLP the status stage may start and the
request is finished successfully.

Without this patch the driver will not send ZLP making it unable
to end the Control Request successful - this may lead to failing
'Device Descriptor Test' from USB3CV test tool.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-11-17 18:06:26 +01:00
Emil Obalski 2eb2bc325e usb: drivers: Save setup packet in the driver structure.
This patch adds setup packet copy in the Nordic device
controller driver (ubs_dc_nrfx.c). This patch is required
for subsequent patch that fixes isssues with ZLP handling.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-11-17 18:06:26 +01:00
Emil Obalski b3c63425a0 usb: driver: Reduce Endpoint buffer pool.
IN Endpoints does not require to have initialized internal
buffer. The data send are not copied to the internal buffer
anymore. This patch reduces memory usage for IN Endpoints.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-11-17 18:06:26 +01:00
Emil Obalski 8dacb99e5e usb: drivers: Do not fragment IN transfers for Nordic.
Nordic device driver controller (usb_dc_nrfx.c) was fragmenting
IN transfers longer than wMaxPacketSize long using its
internal buffers. Buffers were reserved for each endpoint.
Because the Low level driver (nrfx) is capable of handling
fragmentation, there is no need to do it at the driver
controller level. Data pointer is used directly to create
the nrfx transfer. Endpoint buffers are not required anymore
and could be dropped.

This patch removes fragmentation of in transfers and omits
usage of internal endpoint buffers. Buffer could be later
freed by subsequent patches.

Nordic low level usbd driver is also capable of adding ZLP
if required however for consistance with the Zephyr USB device
stack ZLP must be triggered from stack level.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-11-17 18:06:26 +01:00
Emil Obalski 1ebe1573da usb: nordic: Clear STALL when Endpoint is enabled.
Endpoint STALL should be cleared when Endpoint is enabled.
In particular when the HOST performs SetInterface requests
and Endpoints associated with that Interface are enabled
STALL should be cleared.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-11-12 08:59:08 -06:00
Emil Obalski 33fdaac74d drivers: usb: Start Nordic driver workqueue at USB init.
This patch makes the initialization of workqueue earlier
for Nordic driver. Without this change Nordic devices
will fail tests/subsys/usb/device test as it is resetting
USB and by that will try to start already started workqueue
thread. This may lead to Zephyr fatal error.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-10-28 17:02:22 +01:00
Erwan Gouriou a1cb59398b drivers/usb: stm32: Add support for pinctrl configuration
Enable configuration of USB signals in stm32 driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-22 10:34:14 -05:00
Erwan Gouriou 5a9eff1e1a drivers/usb: stm32: Clean up related to DT api usage
Few adjustments made to make the code a bit more readable.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-22 10:34:14 -05:00
Andrzej Głąbek a97611a399 drivers: usb_dc_nrfx: Correct the nrfx_power driver configuration
The initial configuration provided for the nrfx_power driver cannot
contain just default values, as that mean that DC/DC converters are
to be disabled, while those converters may be (and they actually are
by default for many boards) enabled through Kconfig.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-10-22 14:08:13 +02:00
Emil Obalski dc79b37167 usb: nrf: Do not allow to clear STALL or dtoggle for ISO ep.
Isochronous transactions do not support handshake phase
so in particular the ISO endpoint cannot be STALLed.
Isochronous transactions do no support data toggle sequencing
and should only send DATA0 PID.

Taking into consideration those requirements do not try to
clear dtoggle or STALL an ISO Endpoint in nRF USBD driver.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-09-15 10:15:20 +02:00
Emil Obalski 613726728f usb: clock_control: Fix symbol when getting mgr for HFCLK
When getting a hfxo manager for USB sybsystem incorrect symbol
was checked. This lead to always enabling HFCLK, even for nRF5340
which needs HFCLK192M.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-09-07 16:47:02 +02:00
Johann Fischer 362d8b27a7 drivers: usb_dc_mcux_ehci: fix endpoints index assignment
MCUX EHCI USB device controller supports a specific
number of bidirectional endpoints. Bidirectional means
that an endpoint object is represented to the outside
as an OUT and an IN Eindpoint with its own buffers
and control structures.

ep_abs_idx index refers to the corresponding control
structure, for example:

 EP addr | ep_idx | ep_abs_idx
-------------------------------
 0x00    | 0x00   | 0x00
 0x80    | 0x00   | 0x01
 0x01    | 0x01   | 0x02
 0x81    | 0x01   | 0x03
 ....    | ....   | ....

The NUM_OF_EP_MAX (and number of s_ep_ctrl) should be double
of num_bidir_endpoints. There is also no need to reserve
endpoint addresses for this controller type.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-09-05 10:49:37 -05:00
Krzysztof Chruscinski 8f2754e027 drivers: usb: device: nrf: Add support for hf192m clock
Added support for nrf53 where hf192m clock must be used.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-09-04 16:36:05 +02:00
Andrzej Głąbek 460a97d378 drivers: usb_dc_nrfx: Enable and properly initialize nrfx POWER driver
This is a follow-up to commit 701e9befe4.

The NRFX_POWER Kconfig option should be enabled together with USB_NRFX,
not with CLOCK_CONTROL_NRF, as the USB driver is the actual user of
the nrfx POWER driver.

This patch adds also missing initialization of the nrfx POWER driver
and refactors a bit the usb_init() function introduced in the commit
mentioned above, so that it does not redefine the DT_DRV_COMPAT macro
and uses for conditional compilation the same Kconfig option that is
the dependency of NRFX_USBREG.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-09-03 21:52:52 +02:00
Alexandre Bourdiol 5deb8ffe0c drivers: STM32: Rework CLK48 HSEM protection
Due to HSEM implementation #24862, USB CLK48 lock implementation
#25850 should be reworked.
And by the way, implement the same in entropy which is using the
same clock.

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-09-02 14:13:49 +02:00
Tomasz Bursztyka 4dcfb5531c isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs

This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.

Note that only the ISR passed to IRQ_CONNECT are of interest here.

In order to do so, the script fix_isr.py below is necessary:

from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os

cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
(
 const struct device *D = (const struct device *)P;
|
 const struct device *D = P;
)
 ...
}

@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
 const struct device *D;
 ...
(
 D = (const struct device *)P;
|
 D = P;
)
 ...
}

@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
 ...
}

@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);

@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
 ...
}

@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
 ...
}
"""

def find_isr(fn):
    db = []
    data = None
    start = 0

    try:
        with open(fn, 'r+') as f:
            data = str(mmap.mmap(f.fileno(), 0).read())
    except Exception as e:
        return db

    while True:
        isr = ""
        irq = data.find('IRQ_CONNECT', start)
        while irq > -1:
            p = 1
            arg = 1
            p_o = data.find('(', irq)
            if p_o < 0:
                irq = -1
                break;

            pos = p_o + 1

            while p > 0:
                if data[pos] == ')':
                    p -= 1
                elif data[pos] == '(':
                    p += 1
                elif data[pos] == ',' and p == 1:
                    arg += 1

                if arg == 3:
                    isr += data[pos]

                pos += 1

            isr = isr.strip(',\\n\\t ')
            if isr not in db and len(isr) > 0:
                db.append(isr)

            start = pos
            break

        if irq < 0:
            break

    return db

def patch_isr(fn, isr_list):
    if len(isr_list) <= 0:
        return

    for isr in isr_list:
        tmplt = cocci_template.replace('<!fn!>', isr)
        with open('/tmp/isr_fix.cocci', 'w') as f:
            f.write(tmplt)

        cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]

        subprocess.run(cmd)

def process_files(path):
    if path.is_file() and path.suffix in ['.h', '.c']:
        p = str(path.parent) + '/' + path.name
        isr_list = find_isr(p)
        patch_isr(p, isr_list)
    elif path.is_dir():
        for p in path.iterdir():
            process_files(p)

if len(sys.argv) < 2:
    print("You need to provide a dir/file path")
    sys.exit(1)

process_files(Path(sys.argv[1]))

And is run: ./fix_isr.py <zephyr root directory>

Finally, some files needed manual fixes such.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Krzysztof Chruscinski 701e9befe4 drivers: clock_control: nrf: Move USB part to the USB driver
Removed all nrf_power/USB related stuff from clock control
driver to USB driver.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-08-31 12:40:47 +02:00
Emil Obalski 0042e1e95f usb: nrf: Fix for remote wake up request.
Short explanation of remote wake up:

The device has a possibility to wake up the HOST by sending
the wake up request. The request must be previously
explicitly enabled by the HOST just before the SUSPEND.

The HOST enables the remote wake up functionality by sending
SET_FEATURE request with remote wake up flag set to 1.
This ususally happens just before the device is suspended.

About this PR:
When the device decides to wake up the HOST it sends proper request.
Nordic USB HW is creating an event when the request has been sent.

The Zephyr USB device stack must proerly react to this event and
change the state of the device from SUSPENDED. For example if the
device was previously in CONFIGURED state it will remain CONFIGURED.
For state changes refer to Chapter 9.1.1 form USB 2.0 specification.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-08-17 13:41:35 -04:00
Andrew Boie 7d920ba39b drivers: use K_KERNEL_STACK macros
None of these threads run in user mode and we can save some
memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-04 12:16:43 -04:00
Krzysztof Chruscinski 9e546fdf7e drivers: usb: device: nrf: Adapt to control clock using onoff
Change to use onoff service when controlling HFXO.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-07-20 16:22:21 +02:00
Johann Fischer 6d76bd8a9f drivers: usb_dc_sam0: rename ep_num to common ep_idx
ep_idx is common used designator for endpoint index,
rename ep_num to ep_idx in usb_dc_sam0 driver.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-07-10 11:45:46 +02:00
Johann Fischer b95558dd9f drivers: usb: unify endpoint helper macros
Unify endpoint index and direction helper macros
across all usb device drivers.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-07-10 11:45:46 +02:00
Michael Hope dcf64c93e3 drivers: usb: switch the SAM0 driver from a custom allocator to the heap
Also automatically enable the heap if the USB device is selected.

Part of #23178

Signed-off-by: Michael Hope <mlhx@google.com>
2020-07-06 09:58:20 -04:00
Michael Hope ad7ea0d498 drivers: usb: fix usb_dc_ep_mps() for the SAM0 for IN endpoints
The driver was returning zero due to accessing the, say, 0x81'th
endpoint instead of the 0x01'th endpoint.

Signed-off-by: Michael Hope <mlhx@google.com>
2020-06-24 21:00:59 +02:00
Michael Hope 18d3499dba drivers: usb: fix a buffer overflow in usb_sam0.c
The driver currently blindly copies all of the outgoing bytes into the
endpoint.  Instead, calculate the endpoint size and copy up to that
amount instead.

Signed-off-by: Michael Hope <mlhx@google.com>
2020-06-15 16:56:05 +02:00
Michael Hope fe35269d12 drivers: usb: handle a null output arg on SAM0
The output parameter `ret_bytes` is optional and may be NULL.

Signed-off-by: Michael Hope <mlhx@google.com>
2020-06-15 16:55:52 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Pete Johanson f525a4b25a usb: stm32wb: Properly lock Sem5 before initializing USB.
* AN5289 notes that Sem5 should be held before configuring
  CLK48 for USB timing.

Signed-off-by: Pete Johanson <peter@peterjohanson.com>
2020-06-02 20:11:30 +02:00
Emil Obalski 19f6ed02b8 usb: driver: Fix Nordic driver for fragmented control OUT transfers.
Nordic driver must allow read from control OUT endpoint by
itself. For data stage transactions with length > MPS (64Bytes)
this must be performed for each 64B + Residue data packet.

Residue - data packet with len < 64B.

The exact length of data transfer is known from wLength field
form setup packet in setup stage. Until now driver was incorrectly
initializing the length of the data stage and at some point will
not allow for next data stage.

This commit addresses the issue #23980.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-05-22 12:50:35 +02:00
Emil Obalski 2a2d92f9c2 usb: driver: nordic: Unlock mutex in case of error.
Mutex that was previously locked must be unlocked in case
of an error.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-05-21 11:02:02 +02:00
Marek Pieta 6da15634bf drivers: usb_dc_nrfx: Abort write on ep_ctx_reset
Change adds abort of ongoing write operation in ep_ctx_reset. This is
required to keep the state of Zephyr driver consistent with state of
nrfx driver. This fixes a bug where nrfx_usbd was stuck in busy state.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-05-14 13:28:46 +02:00
Johann Fischer 5a3d44256e drivers: usb_dc_sam: free endpoint memory on End of Reset event
Free endpoint memory on End of Reset event (EORST).

Fixes: #24626

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-05-13 11:13:36 +02:00
Johann Fischer 29d95ba1d4 drivers: usb_dc_sam: tweak logging for enable, disable, configure
Tweak logging for enable, disable, configure.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-05-13 11:13:36 +02:00
Martí Bolívar 7e0eed9235 devicetree: allow access to all nodes
Usually, we want to operate only on "available" device
nodes ("available" means "status is okay and a matching binding is
found"), but that's not true in all cases.

Sometimes we want to operate on special nodes without matching
bindings, such as those describing memory.

To handle the distinction, change various additional devicetree APIs
making it clear that they operate only on available device nodes,
adjusting gen_defines and devicetree.h implementation details
accordingly:

- emit macros for all existing nodes in gen_defines.py, regardless
  of status or matching binding
- rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY
- rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY
- rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY
- rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY
- rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS
- resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS
- remove DT_COMPAT_ON_BUS as a public API
- use the new default_prop_types edtlib parameter

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-08 19:37:18 -05:00
Emil Obalski 38aea280e7 usb: Sync receiving data from ISO OUT endpoint with SOF
This commit adds support for receiveing data from ISO OUT endpoint
for NRF devices. NRF USB IP core does not generate IRQ when
data are received on ISO OUT endpoint and it must be synchronized
with SOF event.

Enable SOF handling by default if usb audio is configured
with NRF devices.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-05-08 15:12:27 +02:00
Emil Obalski 9e998d108a drivers: usb: Correct naming for endpoint Transfer Type
This commit updates definitions to better match usb 2.0 spec.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-05-08 15:12:27 +02:00
Emil Obalski 79704fac5a usb: ISO endpoint size may not be power of 2.
By this commit exception for ISO endpoints is made when it comes
to its size. ISO endpoint buffer size for nrf devices is 1023 and
may be configured with variable length size. NRFX checks is size
is chosen accordingly and it is no reason to do it in SHIM.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-05-08 15:12:27 +02:00
Pete Johanson 91d6139338 boards: arm: nucleo_wb55rg: Enable USB for stm32wb.
* Define USB driver for base stm32wb device.
* Enable USB for the nucleo_wb55rg board.
* Properly initialize USB power + clock for the platform.

Signed-off-by: Pete Johanson <peter@peterjohanson.com>
2020-05-06 10:46:23 -05:00
Kumar Gala 1ce133d0fe drivers: usb: usb_dc_stm32: Rename defines to remove DT_ prefix
We want to limit DT_ prefix to macros from devicetree.h and generation.
So rename DT_USB* to just USB*.

Also fixup how USB_MAXIMUM_SPEED was defined.  We should only define it
if the property exists.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-01 07:49:00 -05:00
Kumar Gala 085747e5fb drivers: usb: usb_dc_sam: Convert to DT_INST macros
Convert driver to use new DT_INST macros throughout.  We also remove
defines in dts_fixup.h as they are no longer needed.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 06:10:07 -05:00
Kumar Gala 22a41e4eb7 drivers: usb: usb_dc_stm32: Convert DT_COMPAT_ define usage to new macros
Convert driver from using DT_COMPAT_ST_STM32_* to new macro
DT_HAS_COMPAT(st_stm32_*).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 05:58:17 -05:00
Martí Bolívar 18c9c8cf27 drivers: usb_dc_nrfx: move to new DT API
Close out the existing partial conversion to the new DT API.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-21 13:34:22 -05:00
Kumar Gala af5515e2e0 drivers: usb: device: kinetis: Convert driver to DT_INST macro
Convert from using dts_fixup.h based macros to DT_INST macro.  This
lets us remove the dependancy on dts_fixup.h for this driver.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-20 15:40:44 +02:00
Kumar Gala 1d605684ce drivers: usb: device: mcux_ehci: Convert driver to DT_INST macro
Convert from using dts_fixup.h based macros to DT_INST macro.  This lets
us remove the dependancy on dts_fixup.h for this driver.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-17 11:27:30 -05:00
Kumar Gala 8b56e7a63c drivers: usb_dc_nrfx: Convert driver to new DT_INST macros
Convert to using DT_LABEL(DT_INST()) to get label of the
nordic,nrf-clock device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-14 10:37:34 -05:00
Kumar Gala e6e5d868e1 drivers: usb: usb_dw: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-30 08:29:30 -05:00
Kumar Gala 28870e7a32 drivers: atmel sam0: Convert atmel sam0 drivers to new DT_INST macros
Convert older DT_INST_ macro use in atmel sam0 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-27 11:02:57 -05:00
Kumar Gala 989484b4bf drivers: stm32: Convert STM32 drivers to new DT_INST macros
Convert older DT_INST_ macro use in STM32 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 12:22:12 -05:00
Stephanos Ioannidis c4479d0643 drivers: usb_dc_sam: Use mode-specific interrupt register fields
The new Atmel DFP USBHS component headers provide mode-specific
interrupt register field definitions that replace the generic
definitions (e.g. `USBHS_DEVEPTISR_RXSTPI` for a control endpoint is
now `USBHS_DEVEPTISR_CTRL_RXSTPI`).

This commit updates the Zephyr SAM USBHS driver to use the new
mode-specific interrupt register field definitions.

In addition, it maps the generic definitions to the mode-specific
definitions, as the revision A variant headers (e.g. same70a) in the
latest DFPs, at the time of writing, still provide only the generic
definitions.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-26 09:23:48 -05:00
Erwan Gouriou 9367c6ad3f drivers/usb: usb_dc_stm32: Convert to DT_INST
Convert usb_stm32 driver to use of DT_INST macros.

Since driver is compatible with 3 different dt compatibles and
compatible string is included in DT_INST macros, I've kept the
DT_USB_ compatible agnostic macros based on DT_INST ones, which
allowed to remove fixup definitions.
Use of DT_USB symbols is now limited to usb_dc_stm32.

Additionally, compatible "st,stm32-otgfs" is removed from list
of compatibles for usbotg_hs ips.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-03-17 11:03:10 -06:00
Kumar Gala 0c7a5fdf1c drivers: usb: usb_dw: convert to DT_INST defines
Convert driver to use DT_INST_ defines.  The preferred defines for
drivers are DT_INST_.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-11 07:59:38 -06:00
Josh Gao b9d2028590 usb_dc_stm32: improve struct layout.
Put the one-byte sized fields next to each other to reduce padding.

Signed-off-by: Josh Gao <josh@jmgao.dev>
2020-03-10 18:32:47 +02:00
Josh Gao c4a7d96c04 usb_dc_stm32: reuse PMA buffer when possible.
Previously, endpoint configuration would reserve memory in the packet
memory area which would never be reclaimed. After this patch, endpoints
will reuse previously allocated memory when possible. We still leak
memory when reconfiguration increases the max packet size for a given
endpoint number, but this fixes the common case.

Bug: https://github.com/zephyrproject-rtos/zephyr/issues/23178
Signed-off-by: Josh Gao <josh@jmgao.dev>
2020-03-10 18:32:47 +02:00
Johann Fischer 085e58faf8 drivers: usb_dc_mcux_ehci: re-enable reception after clear stall
Re-enable reception after clear an endpoint stall.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer e0b2227c39 drivers: usb_dc_mcux_ehci: add checks for valid endpoint
Add checks for valid endpoint.
Fix controllerHandle check in usb_dc_detach().

Fixes: #19763

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer e9a35dd6f1 drivers: usb_dc_mcux_ehci: rework USB_DeviceNotificationTrigger()
Rework USB_DeviceNotificationTrigger(). Fix style.

Drop messages from USB_DeviceEhciCancel().
MCUX EHCI driver notifies about canceled transfers,
but there is no specific code for this event in
usb_device_callback_message_struct_t, the only way to
recognize it is to check the length value.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer c2d45640c2 drivers: usb_dc_mcux_ehci: rework ep_write/ep_read
Rework ep_write/ep_read. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 0958667125 drivers: usb_dc_mcux_ehci: rework endpoint enable/disable
Rework endpoint enable/disable. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 031d744b9a drivers: usb_dc_mcux_ehci: rework set/clear stall
Rework set/clear stall. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 4bbd5ae438 drivers: usb_dc_mcux_ehci: do not reconfigure active endpoint
Do not reconfigure active endpoint. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer adf8cfdf3f drivers: usb_dc_mcux_ehci: fix style, rework usb_dc_detach()
Fix style, rework usb_dc_detach().

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 6116a0388b drivers: usb_dc_mcux_ehci: fix style, rework usb_dc_attach
Fix style, rework usb_dc_attach.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer a6207db0f7 drivers: usb_dc_mcux_ehci: remove unnecessary cast
Remove unnecessary cast, fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer b04715b3b9 drivers: usb_dc_mcux_ehci: fix style, variables name
Fix style, variables name, defines.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 4253280525 drivers: usb_dc_nrfx: always reset data toggle in usb_dc_ep_enable
Data toggle should be reset after SetConfiguration or
SetInterface request.
Always reset data toggle in usb_dc_ep_enable.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 14:54:29 +02:00
Audun Korneliussen 388c6ea01f drivers: usb_dc_nrfx: Reset dtoggle when stall is cleared
USB Host expects dtoggle to be cleared after ClearFeature(Halt):

"[...] clearing the Halt feature via a ClearFeature(ENDPOINT_HALT)
request results in the endpoint no longer returning a STALL.
For endpoints using data toggle, regardless of whether an endpoint
has the Halt feature set, a ClearFeature(ENDPOINT_HALT) request always
results in the data toggle being reinitialized to DATA0."
- Subsection 9.4.5 of usb 2.0 spec (usb_20.pdf)

Signed-off-by: Audun Korneliussen <audun.korneliussen@nordicsemi.no>
2020-03-10 14:54:29 +02:00
Erwan Gouriou 557d263354 dts: stm32f3: Remap USB IRQ to avoid conflict with CAN
On stm32f302/3 series, USB and CAN_1 share same IRQ lines.
To use USB and CAN_1 together, USB IRQ could be remap to other
line numbers, on which there is no conflict.
Remap the USB IRQ lines by default:
-Assign remap number in matching dtsi files
-Perform remap before usb driver init

Additionally, fix compilation issue in usb driver.

Fixes #22343

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-02-18 18:44:42 +02:00
Emil Obalski 3ed9dc3a24 usb: Fix for set/reset endpoints
setting/resetting endpoints is required when switching to alternate
interfaces. This is a common operation for usb audio class.

When audio device is enumerated host invokes set_interface request
to alternate with 0 endpoints associated. That operation lead to
disable never enabled endpoints. With previous solution error message
will appear.

This commit limits error messages to be present only if endpoint
was configured/enabled before and there was a problem when trying
to configure/enable it for the first time.

* Kinetis driver was updated with return error value when ep was
already configured/enabled.

* nxp driver updated with return error value when ep was already
enabled

* sam0 driver updated with return codes instead of magic numbers.

This is fix patch to  #21741

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-02-12 14:40:40 +02:00
Yannis Damigos ee351328a4 usb_dc_stm32: Convert usb disconnect gpio to new gpio api
Convert usb disconnect gpio to new gpio api.
Updates device tree for the olimexino_stm32.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2020-02-05 12:00:36 +01:00
Gerson Fernando Budke 17ccd9ee1b drivers: usb: sam: Add support to samv71 soc
Add depends on SOC_SERIES_SAMV71 to enable usb driver for samv71 soc.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-02-04 14:02:59 -05:00
Anas Nashif 0358d707b0 usb: dw: fix undefined callback variable
Add missing declaration of variables for callbacks.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-01-31 14:51:37 -05:00
Tomasz Bursztyka b8e14b5b9d drivers/usb: Switching to DTS based configuration for DW driver
And applying the changes to intel_s1000_crb board as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-01-28 18:18:18 -05:00
Tomasz Bursztyka 2161c91f0b drivers/usb: Fixing style issues in DW driver
Lots of style mess in this driver:
- 80 chars limit not followed
- variable allocation and if condition on it should be coalesced
- etc...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-01-28 18:18:18 -05:00
Peter Bigot 84497d0e49 treewide: use full path to usb/usb_dc.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Peter Bigot 0b0d2e640b treewide: use full path to clock_control/stm32_clock_control.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Erwan Gouriou 136d92de33 drivers/usb/device: stm32: Update due to API change on F0/F3/L0
Following update of STM32Cube packages for series F0/L0/F3,
a new file ll_usb.h is now available for these series.
As a consequence, specific hanlding is no more requested for this
series is stm32 usb_device driver.

Fixes #21962

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-01-16 10:09:58 -05:00
Krzysztof Chruscinski 00156ad80a drivers: clock_control: nrf: Switch to single clock device
Low frequency and high frequency clocks had separate devices
while they are actually handled by single peripheral with single
interrupt. The split was done probably because opaque subsys
argument in the API was used for other purposes and there was
no way to pass the information which clock should be controlled.
Implementation changes some time ago and subsys parameter was
no longer used. It now can be used to indicate which clock should
be controlled.

Change become necessary when nrf5340 is taken into account where
there are more clocks and current approach would lead to create
multiple devices - mess.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-12-17 14:38:19 +01:00
Ulf Magnusson 984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00