Commit graph

427 commits

Author SHA1 Message Date
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