Skip to content

Commit 966315a

Browse files
author
Josuah Demangeon
committed
move the register tests to init, never re-run
Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 35a18d2 commit 966315a

File tree

1 file changed

+42
-100
lines changed

1 file changed

+42
-100
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 42 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -422,96 +422,6 @@ int dwc2_core_reset(const struct device *dev)
422422
return 0;
423423
}
424424

425-
static inline int dwc2_get_config(const struct device *dev)
426-
{
427-
const struct uhc_dwc2_config *const config = dev->config;
428-
struct usb_dwc2_reg *const dwc2 = config->base;
429-
uint32_t reg;
430-
431-
reg = sys_read32((mem_addr_t)&dwc2->gsnpsid);
432-
if (reg != config->gsnpsid) {
433-
LOG_ERR("Unexpected GSNPSID 0x%08x instead of 0x%08x", reg, config->gsnpsid);
434-
return -ENOTSUP;
435-
}
436-
437-
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg1);
438-
if (reg != config->ghwcfg1) {
439-
LOG_ERR("Unexpected GHWCFG1 0x%08x instead of 0x%08x", reg, config->ghwcfg1);
440-
return -ENOTSUP;
441-
}
442-
443-
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg2);
444-
if (reg != config->ghwcfg2) {
445-
LOG_ERR("Unexpected GHWCFG2 0x%08x instead of 0x%08x", reg, config->ghwcfg2);
446-
return -ENOTSUP;
447-
}
448-
449-
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg3);
450-
if (reg != config->ghwcfg3) {
451-
LOG_ERR("Unexpected GHWCFG3 0x%08x instead of 0x%08x", reg, config->ghwcfg3);
452-
return -ENOTSUP;
453-
}
454-
455-
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg4);
456-
if (reg != config->ghwcfg4) {
457-
LOG_ERR("Unexpected GHWCFG4 0x%08x instead of 0x%08x", reg, config->ghwcfg4);
458-
return -ENOTSUP;
459-
}
460-
461-
if ((config->ghwcfg4 & USB_DWC2_GHWCFG4_DEDFIFOMODE) == 0) {
462-
LOG_ERR("Only dedicated TX FIFO mode is supported");
463-
return -ENOTSUP;
464-
}
465-
466-
/* Buffer DMA is always supported in Internal DMA mode.
467-
* TODO: check and support descriptor DMA if available
468-
*/
469-
470-
if (UHC_DWC2_OTGARCH(config) == USB_DWC2_GHWCFG2_OTGARCH_INTERNALDMA) {
471-
LOG_DBG("Buffer DMA enabled");
472-
}
473-
474-
if (config->ghwcfg2 & USB_DWC2_GHWCFG2_DYNFIFOSIZING) {
475-
LOG_DBG("Dynamic FIFO Sizing is enabled");
476-
/* TODO: support FIFO dynamic sizing */
477-
}
478-
479-
/* TODO: Support hybernation */
480-
481-
LOG_DBG("OTG architecture (OTGARCH) %u, mode (OTGMODE) %u",
482-
usb_dwc2_get_ghwcfg2_otgarch(config->ghwcfg2),
483-
usb_dwc2_get_ghwcfg2_otgmode(config->ghwcfg2));
484-
485-
LOG_DBG("DFIFO depth (DFIFODEPTH) %u bytes", UHC_DWC2_FIFODEPTH(config) * 4);
486-
487-
/* TODO: Support vendor control interface */
488-
LOG_DBG("Vendor Control interface support enabled: %s",
489-
(config->ghwcfg3 & USB_DWC2_GHWCFG3_VNDCTLSUPT) ? "true" : "false");
490-
491-
LOG_DBG("PHY interface type: FSPHYTYPE %u, HSPHYTYPE %u, DATAWIDTH %u",
492-
usb_dwc2_get_ghwcfg2_fsphytype(config->ghwcfg2),
493-
usb_dwc2_get_ghwcfg2_hsphytype(config->ghwcfg2),
494-
usb_dwc2_get_ghwcfg4_phydatawidth(config->ghwcfg4));
495-
496-
/* TODO: Support LPM */
497-
LOG_DBG("LPM mode is %s",
498-
(config->ghwcfg3 & USB_DWC2_GHWCFG3_LPMMODE) ? "enabled" : "disabled");
499-
500-
if (config->ghwcfg3 & USB_DWC2_GHWCFG3_RSTTYPE) {
501-
/* TODO: Support sync reset */
502-
}
503-
504-
/* TODO: Support dedicated FIFO mode */
505-
506-
LOG_DBG("PHY interface type: FSPHYTYPE %u, HSPHYTYPE %u, DATAWIDTH %u",
507-
UHC_DWC2_FSPHYTYPE(config), UHC_DWC2_HSPHYTYPE(config),
508-
UHC_DWC2_PHYDATAWIDTH(config));
509-
510-
LOG_DBG("Number of host channels (NUMHSTCHNL + 1) %u", UHC_DWC2_NUMHSTCHNL(config));
511-
512-
return 0;
513-
}
514-
515425
static void dwc2_channel_configure(const struct device *dev, struct uhc_dwc2_chan *chan)
516426
{
517427
const struct uhc_dwc2_config *const config = dev->config;
@@ -805,16 +715,10 @@ static inline void uhc_dwc2_set_defaults(const struct device *dev)
805715

806716
static int uhc_dwc2_init_controller(const struct device *dev)
807717
{
718+
const struct uhc_dwc2_config *const config = dev->config;
808719
struct uhc_dwc2_data *priv = uhc_get_private(dev);
809720
int ret;
810721

811-
/* Get hardware configuration */
812-
ret = dwc2_get_config(dev);
813-
if (ret) {
814-
LOG_ERR("Failed to get DWC2 core parameters: %d", ret);
815-
return ret;
816-
}
817-
818722
/* Pre-calculate FIFO settings */
819723
uhc_dwc2_config_fifo_fixed_dma(dev);
820724

@@ -1069,7 +973,7 @@ static inline uint16_t calc_packet_count(const uint16_t size, const uint8_t mps)
1069973
}
1070974
}
1071975

1072-
static inline bool _buffer_check_done(struct uhc_dwc2_chan *chan)
976+
static inline bool _buffer_is_done(struct uhc_dwc2_chan *chan)
1073977
{
1074978
/* Only control transfers need to be continued */
1075979
if (chan->type != UHC_DWC2_XFER_TYPE_CTRL) {
@@ -1254,7 +1158,7 @@ static enum uhc_dwc2_chan_event uhc_dwc2_decode_chan(const struct device *dev,
12541158
break;
12551159
}
12561160
case DWC2_CHAN_EVENT_CPLT: {
1257-
if (!_buffer_check_done(chan)) {
1161+
if (!_buffer_is_done(chan)) {
12581162
_buffer_exec_proceed(dev, chan);
12591163
break;
12601164
}
@@ -2014,6 +1918,9 @@ static int uhc_dwc2_preinit(const struct device *dev)
20141918

20151919
static int uhc_dwc2_init(const struct device *dev)
20161920
{
1921+
const struct uhc_dwc2_config *const config = dev->config;
1922+
struct usb_dwc2_reg *const dwc2 = config->base;
1923+
uint32_t reg;
20171924
int ret;
20181925

20191926
ret = uhc_dwc2_quirk_init(dev);
@@ -2022,9 +1929,44 @@ static int uhc_dwc2_init(const struct device *dev)
20221929
return ret;
20231930
}
20241931

1932+
reg = sys_read32((mem_addr_t)&dwc2->gsnpsid);
1933+
if (reg != config->gsnpsid) {
1934+
LOG_ERR("Unexpected GSNPSID 0x%08x instead of 0x%08x", reg, config->gsnpsid);
1935+
return -ENOTSUP;
1936+
}
1937+
1938+
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg1);
1939+
if (reg != config->ghwcfg1) {
1940+
LOG_ERR("Unexpected GHWCFG1 0x%08x instead of 0x%08x", reg, config->ghwcfg1);
1941+
return -ENOTSUP;
1942+
}
1943+
1944+
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg2);
1945+
if (reg != config->ghwcfg2) {
1946+
LOG_ERR("Unexpected GHWCFG2 0x%08x instead of 0x%08x", reg, config->ghwcfg2);
1947+
return -ENOTSUP;
1948+
}
1949+
1950+
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg3);
1951+
if (reg != config->ghwcfg3) {
1952+
LOG_ERR("Unexpected GHWCFG3 0x%08x instead of 0x%08x", reg, config->ghwcfg3);
1953+
return -ENOTSUP;
1954+
}
1955+
1956+
reg = sys_read32((mem_addr_t)&dwc2->ghwcfg4);
1957+
if (reg != config->ghwcfg4) {
1958+
LOG_ERR("Unexpected GHWCFG4 0x%08x instead of 0x%08x", reg, config->ghwcfg4);
1959+
return -ENOTSUP;
1960+
}
1961+
1962+
if ((config->ghwcfg4 & USB_DWC2_GHWCFG4_DEDFIFOMODE) == 0) {
1963+
LOG_ERR("Only dedicated TX FIFO mode is supported");
1964+
return -ENOTSUP;
1965+
}
1966+
20251967
ret = uhc_dwc2_init_controller(dev);
20261968
if (ret) {
2027-
LOG_ERR("Failed to nitialize the USB controller");
1969+
LOG_ERR("Failed to initialize the USB controller");
20281970
return ret;
20291971
}
20301972

0 commit comments

Comments
 (0)