mirror of
https://git.planet-casio.com/Lephenixnoir/gint.git
synced 2025-04-18 17:07:02 +02:00
usb: fix module not being restored after usb_close()
usb_close() would unpower the module and gint_world_switch_out() assumed it was powered, so the context switch would fail.
This commit is contained in:
parent
c37f150600
commit
50cbcd4ac1
2 changed files with 11 additions and 0 deletions
|
@ -104,6 +104,9 @@ void gint_world_switch_out(gint_world_t world_addin, gint_world_t world_os)
|
||||||
gint_driver_t *d = &gint_drivers[i];
|
gint_driver_t *d = &gint_drivers[i];
|
||||||
uint8_t *f = &gint_driver_flags[i];
|
uint8_t *f = &gint_driver_flags[i];
|
||||||
|
|
||||||
|
/* Power the device if it was unpowered previously */
|
||||||
|
if(d->hpowered && !d->hpowered() && d->hpoweron) d->hpoweron();
|
||||||
|
|
||||||
/* For non-shared devices, save previous device state and
|
/* For non-shared devices, save previous device state and
|
||||||
consider restoring the preserved one */
|
consider restoring the preserved one */
|
||||||
if(!(*f & GINT_DRV_SHARED))
|
if(!(*f & GINT_DRV_SHARED))
|
||||||
|
|
|
@ -74,7 +74,11 @@ static void hpoweron(void)
|
||||||
|
|
||||||
SH7305_POWER.MSTPCR2.USB0 = 0;
|
SH7305_POWER.MSTPCR2.USB0 = 0;
|
||||||
SH7305_USB_UPONCR.word = 0x0600;
|
SH7305_USB_UPONCR.word = 0x0600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finish the poweron procedure by enabling writes in the registers */
|
||||||
|
static void hpoweron_write(void)
|
||||||
|
{
|
||||||
/* Turn on SCKE, which activates all other registers. The existing
|
/* Turn on SCKE, which activates all other registers. The existing
|
||||||
BUSWAIT delay might not be high enough, so wait a little bit before
|
BUSWAIT delay might not be high enough, so wait a little bit before
|
||||||
modifying registers; a couple CPU cycles is enough. */
|
modifying registers; a couple CPU cycles is enough. */
|
||||||
|
@ -120,6 +124,7 @@ int usb_open(usb_interface_t const **interfaces, gint_call_t callback)
|
||||||
|
|
||||||
usb_open_callback = callback;
|
usb_open_callback = callback;
|
||||||
if(!hpowered()) hpoweron();
|
if(!hpowered()) hpoweron();
|
||||||
|
hpoweron_write();
|
||||||
|
|
||||||
*(uint16_t volatile *)0xa4d800c2 = 0x0020;
|
*(uint16_t volatile *)0xa4d800c2 = 0x0020;
|
||||||
|
|
||||||
|
@ -283,6 +288,8 @@ void hsave(usb_state_t *s)
|
||||||
|
|
||||||
static void hrestore(usb_state_t const *s)
|
static void hrestore(usb_state_t const *s)
|
||||||
{
|
{
|
||||||
|
hpoweron_write();
|
||||||
|
|
||||||
USB.DVSTCTR.word = s->DVSTCTR;
|
USB.DVSTCTR.word = s->DVSTCTR;
|
||||||
USB.TESTMODE.word = s->TESTMODE;
|
USB.TESTMODE.word = s->TESTMODE;
|
||||||
USB.REG_C2 = s->REG_C2;
|
USB.REG_C2 = s->REG_C2;
|
||||||
|
@ -313,6 +320,7 @@ static void hrestore(usb_state_t const *s)
|
||||||
|
|
||||||
gint_driver_t drv_usb = {
|
gint_driver_t drv_usb = {
|
||||||
.name = "USB",
|
.name = "USB",
|
||||||
|
/* TODO: Wait for remaining transfers in unbind() */
|
||||||
.hpowered = hpowered,
|
.hpowered = hpowered,
|
||||||
.hpoweron = hpoweron,
|
.hpoweron = hpoweron,
|
||||||
.hpoweroff = hpoweroff,
|
.hpoweroff = hpoweroff,
|
||||||
|
|
Loading…
Add table
Reference in a new issue