Skip to content

Commit 7b0e450

Browse files
tmon-nordiccarlescufi
authored andcommitted
[nrf fromtree] drivers: usb: dwc2: nrf: Set PHY.CONFIG value
Generate PHY.CONFIG based on devicetree and assign it before PHY power-on reset is released. Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no> (cherry picked from commit 21b3ac8)
1 parent d114f75 commit 7b0e450

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/** @cond INTERNAL_HIDDEN */
8+
9+
#ifndef NRF_USBHS_PHY_CONFIG_H__
10+
#define NRF_USBHS_PHY_CONFIG_H__
11+
12+
/* This macro works for both types, because differences between Type1 and Type2
13+
* are covered by devicetree bindings having different enum values and defaults.
14+
*/
15+
#define PHY_CONFIG_VALUE(node) \
16+
(0 << USBHS_PHY_CONFIG_PLLITUNE_Pos) |\
17+
(0xC << USBHS_PHY_CONFIG_PLLPTUNE_Pos) |\
18+
(DT_ENUM_IDX(node, compdistune) << USBHS_PHY_CONFIG_COMPDISTUNE0_Pos) |\
19+
(DT_ENUM_IDX(node, sqrxtune) << USBHS_PHY_CONFIG_SQRXTUNE0_Pos) |\
20+
(DT_ENUM_IDX(node, vdatreftune) << USBHS_PHY_CONFIG_VDATREFTUNE0_Pos) |\
21+
((1 + DT_ENUM_IDX(node, txhsxvtune)) << USBHS_PHY_CONFIG_TXHSXVTUNE0_Pos) |\
22+
(BIT_MASK(DT_ENUM_IDX(node, txfslstune)) << USBHS_PHY_CONFIG_TXFSLSTUNE0_Pos) |\
23+
(DT_ENUM_IDX(node, txvreftune) << USBHS_PHY_CONFIG_TXVREFTUNE0_Pos) |\
24+
(DT_ENUM_IDX(node, txrisetune) << USBHS_PHY_CONFIG_TXRISETUNE0_Pos) |\
25+
(DT_ENUM_IDX(node, txrestune) << USBHS_PHY_CONFIG_TXRESTUNE0_Pos) |\
26+
(DT_ENUM_IDX(node, txpreempamptune) << USBHS_PHY_CONFIG_TXPREEMPAMPTUNE0_Pos) |\
27+
(DT_ENUM_IDX(node, txpreemppulsetune) << USBHS_PHY_CONFIG_TXPREEMPPULSETUNE0_Pos)
28+
29+
#define PHY_CONFIG(node) \
30+
COND_CASE_1(DT_NODE_HAS_COMPAT(node, nordic_nrf_usbhs_phy_type1), (PHY_CONFIG_VALUE(node)),\
31+
DT_NODE_HAS_COMPAT(node, nordic_nrf_usbhs_phy_type2), (PHY_CONFIG_VALUE(node)),\
32+
(ZERO_OR_COMPILE_ERROR(0)))
33+
34+
#endif /* NRF_USBHS_PHY_CONFIG_H__ */
35+
36+
/** @endcond */

‎drivers/usb/common/nordic/nrf_usbhs_wrapper.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/device.h>
1010
#include <zephyr/devicetree.h>
1111
#include <zephyr/drivers/regulator.h>
12+
#include <nrf_usbhs_phy_config.h>
1213
#include <nrf_usbhs_wrapper.h>
1314

1415
#include <zephyr/logging/log.h>
@@ -42,6 +43,7 @@ static const char *const bc12_state_str[] = {
4243
struct usbhs_wrapper_config {
4344
NRF_USBHS_Type *base;
4445
const struct device *vregusb_dev;
46+
uint32_t phy_config;
4547
};
4648

4749
struct nrf_usbhs_wrapper_data {
@@ -134,6 +136,9 @@ static void wrapper_enable_core_internal(const struct device *dev)
134136
/* Power up peripheral */
135137
wrapper->ENABLE = USBHS_ENABLE_CORE_Msk;
136138

139+
/* Set PHY strapping options */
140+
wrapper->PHY.CONFIG = config->phy_config;
141+
137142
/* Set role to Device, force D+ pull-up off by overriding VBUS valid signal */
138143
wrapper->PHY.OVERRIDEVALUES = USBHS_PHY_OVERRIDEVALUES_ID_Msk;
139144
wrapper->PHY.INPUTOVERRIDE = USBHS_PHY_INPUTOVERRIDE_ID_Msk |
@@ -483,6 +488,7 @@ static int usbhs_wrapper_init(const struct device *dev)
483488
static const struct usbhs_wrapper_config usbhs_wrapper_config_##n = { \
484489
.base = (void *)(DT_INST_REG_ADDR(n)), \
485490
.vregusb_dev = DEVICE_DT_GET(DT_INST_PHANDLE(n, regulator)), \
491+
.phy_config = PHY_CONFIG(DT_INST_PHANDLE(n, phy)), \
486492
}; \
487493
\
488494
static struct nrf_usbhs_wrapper_data usbhs_wrapper_data_##n; \

‎drivers/usb/udc/udc_dwc2_nrf_usbhs.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/logging/log.h>
1010
#include <nrfs_backend_ipc_service.h>
1111
#include <nrfs_usb.h>
12+
#include "../common/nordic/nrf_usbhs_phy_config.h"
1213

1314
#define USBHS_DT_WRAPPER_REG_ADDR(n) UINT_TO_POINTER(DT_INST_REG_ADDR_BY_NAME(n, wrapper))
1415

@@ -22,6 +23,8 @@
2223
static K_EVENT_DEFINE(usbhs_events);
2324
#define USBHS_VBUS_READY BIT(0)
2425

26+
const static uint32_t phy_config = PHY_CONFIG(DT_INST_PROP(0, phy));
27+
2528
static void usbhs_vbus_handler(nrfs_usb_evt_t const *p_evt, void *const context)
2629
{
2730
LOG_MODULE_DECLARE(udc_dwc2, CONFIG_UDC_DRIVER_LOG_LEVEL);
@@ -96,6 +99,13 @@ static inline int usbhs_enable_core(const struct device *dev)
9699
}
97100
}
98101

102+
/* Power up peripheral */
103+
wrapper->ENABLE = USBHS_ENABLE_CORE_Msk;
104+
105+
/* Set PHY strapping options */
106+
wrapper->PHY.CONFIG = phy_config;
107+
108+
/* Release PHY power-on reset */
99109
wrapper->ENABLE = USBHS_ENABLE_PHY_Msk | USBHS_ENABLE_CORE_Msk;
100110

101111
/* Wait for PHY clock to start */

0 commit comments

Comments
 (0)