Skip to content

Commit 3669621

Browse files
committed
Properly set power state
1 parent 088adf2 commit 3669621

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

uspi/lib/uspios.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@
4949
#define MAIL_TAGS 0x8 // Mailbox Channel 8: Tags (ARM to VC)
5050

5151
#define TAG_GET_BOARD_REVISION 0x00010002 // Hardware: Get Board Revision (Response: Board Revision)
52+
#define TAG_SET_POWER_STATE 0x00028001 // Power: Set Power State (Response: Device ID, State)
53+
54+
#define POWER_STATE_OFF (0 << 0)
55+
#define POWER_STATE_ON (1 << 0)
56+
57+
//
58+
// Power: Unique Device ID's
59+
//
60+
#define PWR_USB_HCD_ID 0x3 // USB HCD
5261

5362
//
5463
// System Timers
@@ -204,13 +213,27 @@ int GetBoardRevision (void)
204213

205214
int SetPowerStateOn (unsigned nDeviceId)
206215
{
207-
mbox_write(0, 0x80);
208-
if(mbox_read(0) != 0x80)
209-
{
210-
return 0;
216+
unsigned int mb_addr = 0x40007000; // 0x7000 in L2 cache coherent mode
217+
volatile unsigned int *mailbuffer = (unsigned int *) mb_addr;
218+
219+
mailbuffer[0] = 8 * 4; // size of this message
220+
mailbuffer[1] = 0; // this is a request
221+
222+
mailbuffer[2] = TAG_SET_POWER_STATE;
223+
mailbuffer[3] = 8; // value buffer size
224+
mailbuffer[4] = 8; // request/response
225+
mailbuffer[5] = PWR_USB_HCD_ID; // device id
226+
mailbuffer[6] = POWER_STATE_ON; // power state
227+
228+
mailbuffer[7] = 0;
229+
mbox_write(MAIL_TAGS, mb_addr);
230+
231+
mbox_read(MAIL_TAGS);
232+
if (mailbuffer[1] == MAIL_FULL) {
233+
return 1;
211234
}
212235

213-
return 1;
236+
return 0;
214237
}
215238

216239
int GetMACAddress (unsigned char Buffer[6])

0 commit comments

Comments
 (0)