Commit graph

582 commits

Author SHA1 Message Date
Mahesh Mahadevan f05bbd09be drivers: usb_dc_mcux: Add Pinctrl defines
Add Pinctrl code

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-05-26 17:53:37 -04:00
Mahesh Mahadevan ec5d3b7bff drivers: nxp_usb: Enable USB_DC_HAS_HS_SUPPORT conditionally
Conditionally enable the USB_DC_HAS_HS_SUPPORT as the
USB_DC_NXP_LPCIP3511 controller can have both HS and FS only.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-05-26 17:53:37 -04:00
BJ Chen 215f180296 ITE: drivers/usb/device: Add USB Device Controller Support
Add USB Device Driver (usb_dc) of ITE IT82xx2

TEST=west build -p always -b it82xx2_evb
1. zephyr/sample/subsys/usb/hid
2. zephyr/sample/subsys/usb/hid-mouse

Signed-off-by: BJ Chen <bj.chen@ite.com.tw>
2023-05-26 12:40:18 +02:00
Niek Ilmer b79d65aaca drivers: usb_device: Add USB driver for smartbond
This adds support for the USB interface for the
Renesas Smartbond DA1469x device family.

Co-authored-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>

Signed-off-by: Niek Ilmer <niek.ilmer.aj@renesas.com>
2023-05-26 10:19:15 +02:00
Carlo Caione cb11b2e84b barriers: Move __DSB() to the new API
Remove the arch-specific ARM-centric __DSB() macro and use the new
barrier API instead.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-05-24 13:13:57 -04:00
Carlo Caione 2fa807bcd1 barriers: Move __DMB() to the new API
Remove the arch-specific ARM-centric __DMB() macro and use the new
barrier API instead.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-05-24 13:13:57 -04:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Johann Fischer 1a30cd8f1c drivers: udc: add USB device controller driver skeleton
Add a USB device controller driver skeleton to use as a starting point
for implementing a specific driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-05-17 12:26:48 +02:00
Johann Fischer 0a5b682461 drivers: udc_virtual: fix bus SUSPEND, RESUME, RESET event handling
Only UVB_EVT_REQUEST type passes the pkt argument.
This was overlooked in the last refactoring and
resulted in a zero pointer dereference.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-05-11 15:29:58 +02:00
Johann Fischer fce0b85eca drivers: usb_dc_dw: add support for STM32F4 SoC family
This commit is a draft to support more controller implementations
with these drivers. The goal is also to make it easier to port
this driver to the new UDC API later.
We use compatible, like st,stm24f4-fsotg to support and enable
vendor-specific quirk. The core of the driver remains generic,
and therefore described and enabled by snps,dwc2 compatible.

STM32F4 support requires PINCTRL, even though pinctrl API is
generic, not all platforms implement it, so we have to include
and compile it conditionally.

Now we also switch to use new snps,dwc2 compatible and
explicitly force the controller into device mode,
as we do not support other roles or role changes.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-05-10 20:07:04 +09:00
Johann Fischer 7538c551ff drivers: usb_dc_dw: add definition for GHWCFG1..4 registers
Add definition for GHWCFG1..4 registers to be able to obtain basic
information about PHY, endpoints, and Data FIFO.

Add GGPIO defines for STM32F4 SoC family USB controllers.
This implementation uses GGPIO to enable transceiver, VBUS
detection, and a few other functions.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-05-10 20:07:04 +09:00
Johann Fischer 4d2645a734 drivers: usb_dc_dw: cleanup and reorder register header
Align and sort defines according to the position in memory.
Remove unnecessary parentheses.

Fix USB_DW_DSTS_ENUM_SPD_MASK.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-05-10 20:07:04 +09:00
Johann Fischer 51f8d02294 drivers: usb_dc_dw: cleanup, move USB_DW macros to driver code
Cleanup includes, fix build and missing kernel header include.
Move copyright notice to the top.

USB_DW_* macros are a bit misplaced in register header,
which is supposed to be about registers only.

USB_DW macro is used to point to base of controller register set.
Move it to driver code and add a new variable in driver's configuration
that takes the base address of the instance. This also makes later
porting to UDC API and support multiple instances easier.

Remove redundant DW_USB_IN_EP_NUM and DW_USB_OUT_EP_NUM
macros. Do not limit number of endpoint register in
struct usb_dw_in_ep_reg as it does not reflect common
register mapping of the controller.

Fix build warnings caused by USB_DW_EP_FIFO and use base variable
to calculate data FIFO access register.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-05-10 20:07:04 +09:00
Keith Short d4fef500b2 emul: pi3usb9201: Add charging mode support
Add charging mode support the PI3USB9201 emulator and add a backend API
for connecting/disconnecting a portable device partner.

Signed-off-by: Keith Short <keithshort@google.com>
2023-05-08 09:57:56 +02:00
Keith Short 00733f346b bc12: Add charging mode support
Add chargingg mode support to the BC1.2 API and the PI3USB9201 driver.

Signed-off-by: Keith Short <keithshort@google.com>
2023-05-08 09:57:56 +02:00
Keith Short 86cb55943d bc12: Add charging mode role information to callback
Update the result callback routine to also provide information about the
charging mode role. This permits tests to validate plug/unplug events
detected by the BC1.2 device operating in charging mode.

Signed-off-by: Keith Short <keithshort@google.com>
2023-05-08 09:57:56 +02:00
Tomasz Moń 11b599c708 drivers: usb_dc_nrfx: Enable SOF interrupts only when needed
Do not enable SOF event interrupt when the USB device driver is going to
discard the event anyway. This prevents completely unnecessary interrupt
handler from executing 1000 times a second when device is connected.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2023-05-05 13:37:47 +02:00
Declan Snyder 90570c6b9d drivers: usb_dc_mcux: Fix write performance issues
The MCUX USB device driver currently suffers from
some performance related issues caused by the removal
of the intermediate buffer in commit 4e6f80d37a.
This buffer was essential in the case when some USB
descriptors or data were in a slow access memory,
for example a flash memory accessed over flexspi.
USB DMA as AHB master would try to fetch the data,
but it would be too slow and USB peripheral
could not meet deadlines on the USB bus waiting for it,
and so it would send null packets instead causing errors.

This problem can be fixed by re-introducing an intermediate
buffer in RAM with the data copied from the slow memory by
the core before the USB transfer begins, so that USB DMA
is not responsible for fetching it from flexspi/flash.

Changes to MCUX USB Device Driver:
- Re-add intermediate buffer for USB writes in RAM
- Buffer is not needed for reads, add runtime check
  to avoid copy overhead
- Buffer is not needed for platforms with USB RAM,
  since the USB RAM itself acts as an intermediate buffer.
  Compile with buffer code only when USB RAM is not present on
  the platform, to avoid unecessary copy overhead.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-04-25 12:43:17 -05:00
Gerard Marull-Paretas 4863c5f05b sys/util: extend usage of DIV_ROUND_UP
Many areas of Zephyr divide and round up without using the DIV_ROUND_UP
macro. Make use of it, so that we make use of a tested system macro and
at the same time we make code more readable.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 16:42:29 +02:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Pieter De Gendt 6b532ff43e treewide: Update clock control API usage
Replace all (clock_control_subsys_t *) casts with (clock_control_subsys_t)

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-05 10:55:46 +02:00
Keith Short 9b8c4ee847 emul: pi3usb9201: Create pi3usb9201 emulator
Create an emulator for the pi3usb9201 USB charging detector.

Signed-off-by: Keith Short <keithshort@google.com>
2023-03-30 17:34:36 -04:00
Keith Short e0dd45ba31 bc12: API and 1st driver implementation.
Add portable-device mode to the Diodes PI3USB9201 USB charging detector.

Signed-off-by: Keith Short <keithshort@google.com>
2023-03-30 17:34:36 -04:00
Henrik Brix Andersen c41dd36de2 drivers: kconfig: unify menuconfig title strings
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".

Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 15:06:06 +02:00
Johann Fischer 9d91333a43 drivers: udc: simplify udc_submit_event()
Since we have a dedicated function for UDC_EVT_EP_REQUEST type
events, we can now simplify udc_submit_event() and remove
buf parameter.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-03-23 10:08:03 +01:00
Johann Fischer ad81b3b797 drivers: udc: move transfer status to buffer info structure
This allows us to get the result of synchronous transfer without
any hacks, just from the net_buf structure.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-03-23 10:08:03 +01:00
Johann Fischer 39218112ab drivers: udc_nrf: do not use UDC_EVT_EP_REQUEST without net_buf pointer
Do not use UDC_EVT_EP_REQUEST event without a valid pointer
to a request buffer. No changes needed in the upper layer because
it requires valid buffer pointer for this type of event anyway.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-03-23 10:08:03 +01:00
Johann Fischer 4a53645448 drivers: udc: add helper function to send UDC endpoint event
Add helper function to send UDC endpoint event to a higher level
that takes fewer arguments.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-03-23 10:08:03 +01:00
Gerson Fernando Budke 5522e65581 drivers: usb: sam: Update to use clock control
This update Atmel SAM usbhs driver to use clock control driver.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2023-03-21 14:12:25 -07:00
Purdea Andrei f4e0f9004f drivers: usb_dc_rpi_pico: implement remote wakeup support
This change implements the following, necessary for remote wakeup to be
supported:

- implement usb_dc_wakeup_request() call to trigger remote wakeup
- implement interrupts to detect supsended/resumed state
- implement extra logic to simulate resumed state when the resume
  is a result of remote wakeup. In this case the rp2040 chip doesn't
  send a USB_INTR_DEV_RESUME_FROM_HOST interrupt, or any other
  interrupts when the resume condition is detected to be extended
  by the upstream port, so we need to simulate this event when we
  see activity on the bus.

Signed-off-by: Purdea Andrei <andrei@purdea.ro>
2023-03-06 21:18:38 +01:00
Purdea Andrei 73a800f7dd drivers: usb_dc_rpi_pico: fix stability issue related to control transfers
Description of the bad behaviour before this change:

The arming of the control EP0_OUT endpoint was not kept under
control. It could happen that the EP0_OUT endpoint was left
armed, after the completion of a complete control transfer.

It is clear that the intention was to NOT keep EP0_OUT constantly
armed while idle, because usb_dc_ep_enable() doesn't arm it,
and the intention was for when usb_dc_ep_read() is called to
collect the Setup-Stage 8-byte data, that is when EP0_OUT is armed,
and before this call is performed, the host will keep getting NAKs
for the Data-Stage of the to_device control transfer.

This happens correctly on the first to_device control transfer with
wLength > 0. However, because usb_dc_ep_read_continue() indiscriminately
re-arms all OUT endpoints, in the case of to_device control transfers
with wLength > 0, on the Data-Stage, the endpoint is also re-armed,
which is wrong, because then the endpoint will be left armed after
the control transfer is over.

In this case when a new to_device control transfer starts, the
Data-Stage will be accepted on the first try. This would still
have worked without a failure if the Setup-Stage would have been
processed immediately, but because we process everything in a work
queue at a later time, when the Setup-Stage associated 8-byte data
buffer is read both the Setup-Stage and Data-Stage have arrived.
At the end of handling the Setup-Stage we try to re-arm the EP0_OUT,
which already contains data, thereby corrupting the received length
portion of the buf_ctl register. (Obviously other fields are changed
too, but the length field is the one that first causes chaos, cause
it's written to the maximum, which is 64.) The above mentioned Data-Stage
already has a message in its workqueue for it to be processed, but
it is picked up only after the length field has been corrupted.
Because of this usb_dc_ep_read() thinks there is more data in the buffer
than there really is, and everything becomes de-synchronized, with
later reads accessing uninitialized parts of the buffer.

This sounds like a fundamental failure, that should make it impossible
to operate USB, however the reason this behaviour doesn't make it
impossible to enumerate the device is that this only affects
to_device control transfers with wLength > 0, and during enumeration
there are not many of those happening.
When enumerating a HID keyboard, there is only _one_ of those
happening, and it is the initial setting of the lock light led status.
And that first one succeeds because it's the first one. (However, later
lock light setting control transfers can cause problems, which is how
this problem was encountered.)

The solution in this commit is to keep better control over when EP0_OUT
is armed. This forces the Data-Stage to arrive later (the host will keep
re-trying), and that way the corruption of the buffer control register
is avoided.

Summary of the changes:
 - Rework the logic around deciding wether to re-arm the out endpoint
   after a read. For non-0 endpoint the previous behaviour is kept,
   however for EP0 it is only re-armed if more OUT transactions are
   expected for that SETUP transfer (be it data-stage or status-stage)
 - Force un-arm the EP0_OUT endpoint in case a stall condition is observed.
 - When a setup transfer is received check if EP0_OUT is already armed.
   If armed then log a warning message, and force-disarm it.
 - When a setup req interrupt fires, don't immediately force the next
   read to get it, instead, it will be read only after a setup message
   is extracted from the message queue.
 - When a setup packet is received abort any unfinished previous control
   transfers:
    - cancel any data buffers given to the EP0_IN endpoint
    - drop any new ep0_in writes that are attempted before this newest
      setup packet's associated message is extracted from the message
      queue.
 - In the ISR, check buffer interrupts before setup req interrupts.
   This is to make sure that the final 0-length status message from the
   previous setup packet is consumed before the new setup packet.
   (this is the only case now when both interrupts could be seen as
   having fired by the time the interrupt handler routine executes.

Signed-off-by: Purdea Andrei <andrei@purdea.ro>
Co-authored-by: Johann Fischer
2023-03-02 12:58:24 +01:00
Andrei Emeltchenko 8e84d840b5 usb: Fix build for 64 bit platforms
Use proper format for size_t type eliminating warnings of type:

...
error: format '%u' expects argument of type 'unsigned int', but
argument 2 has type 'size_t' {aka 'long unsigned int'}
[-Werror=format=]
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-02-23 17:51:31 +01:00
Andrei Emeltchenko ddf9854bfb usb: udc_virtual: Adapt to updated API
Commit 00adb2a539 ("drivers: udc: remove no more required pending
state flag") removed state parameter from udc_buf_peek and udc_buf_get.
Adapt udc virtual driver so the code compiles.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-02-23 17:51:31 +01:00
Gerard Marull-Paretas 86a0f80c57 drivers: usb: udc: nrf: fix declaration after label
C language does not allow declarations after labels, only statements are
allowed. Add {} around the `NRFX_USBD_EVT_SETUP` case to fix build
issues (`error: a label can only be part of a statement and a
declaration is not a statement`)

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-02-20 13:22:02 +01:00
Purdea Andrei 158ee9139c drivers: usb_dc_rpi_pico: cleanup incorrect comment and condition
I believe this comment and condition may have found its way into the
rp2040 driver from other drivers where it makes more sense. For
example for the stm32 driver performing a read on the EP0_IN endpoint
turns it silently into a read on the EP0_OUT endpoint. As far as I can
tell, this really was only used to consume 0-length Status-Stages of
to_host control transfer in the other drivers.

Note that usb_dc_ep_start_read() is never called in an IN endpoint
in the rp2040 driver, and furthermore, even if it would have been
called like that, the current implementation would not do the silent
change into actually performing a read on the EP0_OUT endpoint instead,
so the condition and comment is just wrong.

Note that 0-length Status-Stage of to_host control transfers is
currently consumed in this driver by usb_dc_ep_read_continue().

Signed-off-by: Purdea Andrei <andrei@purdea.ro>
2023-02-11 08:23:03 +09:00
Purdea Andrei 4fcbba2fb1 drivers: usb_dc_rpi_pico: fix toggle data1/0 on to_device control transfers
The data stage of Control transfers that are sent from Host to Device, can
be made out of multiple OUT transactions, if the amount of data to be
transmitted is larger than the endpoint size. When this happens, the DATA
pid should be toggling. The USB Device driver of the pico must correctly
prime the EP0_OUT buffer with the correct data PID, otherwise the hardware
will reject the received transaction.

Before this change the driver used to always prime EP0_OUT with a DATA1
pid.
After this change the driver only uses DATA1 pid after a setup transaction,
and then toggles the pid for each transaction.

Signed-off-by: Purdea Andrei <andrei@purdea.ro>
2023-02-11 08:00:43 +09:00
Purdea Andrei 9a7f9ec0ba drivers: usb_dc_rpi_pico: avoid infinite unhandled irq retriggers
This driver enables a number of interrupts it does not attempt to handle.
This results in "unhandled IRQ: 0x...." messages being printed, and the
interrupt handler retriggers immediately again, and this happens again
and again forver, because nothing ends up clearing the interrupt.

This change implements very limited handling of these interrupts. A custom
warning is logged, and the interrupt is cleared.

This change does not imply that doing this is sufficient. More changes may
need to be implemented to more gracefully re-start transactions or
re-arm some endpoints, but this is one step in the right direction,
and at least the OS doesn't freeze up.

Signed-off-by: Purdea Andrei <andrei@purdea.ro>
2023-02-06 22:07:03 +09:00
Mahesh Mahadevan 4e6f80d37a drivers: usb: mcux: Fix the write operation
1. Do not copy over the data to the local buffer,
it can be directly sent to the controller. The
cache is flushed before calling the HAL send
function. Also do not allocate a buffer from
the heap pool for the write operation.
2. Remove a length check as this is handled by
the HAL driver.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-01-30 10:07:07 +00:00
Mahesh Mahadevan 9bef7d07e7 drivers: usb: mcux: Remove unnecessary while loop
The while loop is changed to an if check.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-01-30 10:07:07 +00:00
Mahesh Mahadevan 17da2015bc drivers: usb: Cleanup MCUX driver
1. Remove unused ep_type structure member
2. Add more direction checks

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-01-30 10:07:07 +00:00
Johann Fischer 2f310dc424 drivers: udc: add capability for MPS of control endpoint
New capability is to be used by the stack to adjust the corresponding
field in the device descriptor.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-27 16:11:20 +01:00
Johann Fischer 373d660d96 drivers: udc: remove unused and unsupported udc_ep_flush()
udc_ep_flush() is not implemented by the driver and is not
used by the USB device stack. Remove it for less confusion
when porting drivers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-27 16:11:20 +01:00
Johann Fischer e60a4efbb0 drivers: udc: do not update MPS for isochronous endpoints
Zero data payload size for isochronous endpoints is a
is a valid setting for default interface.
Also do not update MPS of control endpoint since it is
set by the driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-27 00:57:22 +09:00
Mahesh Mahadevan 3b7e7575a9 drivers: usb: Enable High speed Kconfig for NXP controllers
Enable the USB_DC_HAS_HS_SUPPORT Kconfig for NXP controllers
that support High speed.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2023-01-23 19:40:44 -08:00
Erwan Gouriou 419adeaeed drivers: usb: stm32: Replace static clock check by a runtime check.
In order to clean up clock related code, replace static build time
clock configuration code by a runtime check.
Since I'm not able to guarantee this check will provide a correct
verdict in 100% of the cases (I'm thinking to ULPI or exotic configurations
like F7 OTG-HS), add a config option to disable it if needed.
It also doesn't apply on F1/F3 series. Keep the build time check for now.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Erwan Gouriou 4899c104e0 drivers: usb: stm32: Configure domain clock using device tree
This change doesn't consider STM32F1 series.

There are 5 categories of STM32 regarding USB domain clock:
A] USB domain clocks directly driven by CK48 clocks
B] USB domain clocks which can select either CK48 or an alternative clock
C] USB domain clocks which can select between MSI or PLL
D] USB domain clocks relying statically on a PLL output
E] USB domain clocks which can be set on 2 different PLL ouputs

For case A], there is nothing to be done. Clk48 was already configured
in a previous change (51c7643295b02ba26ddcd0fd915484114db7101c).
For case B] and C] USB domain clocks will need to be configured in
each board.
For case D] and E] relying on existing dts configuration. Though
there is no easy build time chekc that can be done.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Erwan Gouriou cbc44075b7 drivers: usb: stm32: Store dt clock information into an array
Use STM32_DT_INST_CLOCKS() to access usb device clock information.
This will help accessing domain clock information from dt nodes.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Erwan Gouriou fccf4c95c0 drivers: usb: stm32: Remove HSI48 activation related code
Remove this code to clean up the driver.
Clock activation is done from device tree configuration in clock_control
driver.
Users are informed by warning about missing configuration.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Johann Fischer b5bfd3b12c drivers: udc: fixup parameter endpoint description
The description was still from the early stages of development.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-01-11 17:44:50 +01:00
Johann Fischer 2cab3a8243 drivers: usb: udc_kinetis: fix race condition in Kinetis USBFSOTG
Periodic enqeueu of buffers can cause a attempt to start
a new transfer even though an endpoint is already busy.

Split usbfsotg_xfer_start() into two function, one to start
next transfer and another to continue the transfers, and 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 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