Workaround lack of SPMI support in usb.c

M3+ have a new USB power controller and it works over SPMI.
However, the USB ports work (at least within m1n1) if we ignore
this and just init the phys directly.

This detects the case where we are not on an I2C based USB machine,
and initializes the phys directly.

Eventually we should support SPMI properly.

Signed-off-By: Daniel Berlin <dberlin@dberlin.org>
This commit is contained in:
Daniel Berlin 2023-11-30 13:21:13 -05:00 committed by Hector Martin
parent b50b17ceb5
commit 9065c700df

View file

@ -7,6 +7,7 @@
#include "iodev.h" #include "iodev.h"
#include "malloc.h" #include "malloc.h"
#include "pmgr.h" #include "pmgr.h"
#include "string.h"
#include "tps6598x.h" #include "tps6598x.h"
#include "types.h" #include "types.h"
#include "usb_dwc3.h" #include "usb_dwc3.h"
@ -228,6 +229,14 @@ static tps6598x_dev_t *hpm_init(i2c_dev_t *i2c, const char *hpm_path)
return tps; return tps;
} }
void usb_spmi_init(void)
{
for (int idx = 0; idx < USB_IODEV_COUNT; ++idx)
usb_phy_bringup(idx); /* Fails on missing devices, just continue */
usb_is_initialized = true;
}
void usb_init(void) void usb_init(void)
{ {
char hpm_path[sizeof(FMT_HPM_PATH)]; char hpm_path[sizeof(FMT_HPM_PATH)];
@ -235,6 +244,15 @@ void usb_init(void)
if (usb_is_initialized) if (usb_is_initialized)
return; return;
/*
* M3 models do not use i2c, but instead SPMI with a new controller.
* We can get USB going for now by just bringing up the phys.
*/
if (adt_path_offset(adt, "/arm-io/nub-spmi-a0/hpm0") != 0) {
usb_spmi_init();
return;
}
i2c_dev_t *i2c = i2c_init("/arm-io/i2c0"); i2c_dev_t *i2c = i2c_init("/arm-io/i2c0");
if (!i2c) { if (!i2c) {
printf("usb: i2c init failed.\n"); printf("usb: i2c init failed.\n");