4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // These functions are used only inside xbox-specific code
22 // thus I didn't include them in header
24 #define I2C_IO_BASE 0xc000
27 WriteToSMBus(UCHAR Address
, UCHAR bRegister
, UCHAR Size
, ULONG Data_to_smbus
)
29 int nRetriesToLive
=50;
31 while(READ_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+0)) & 0x0800)
33 ; // Franz's spin while bus busy with any master traffic
36 while(nRetriesToLive
--)
41 WRITE_PORT_UCHAR((PUCHAR
)(I2C_IO_BASE
+ 4), (Address
<< 1) | 0);
42 WRITE_PORT_UCHAR((PUCHAR
)(I2C_IO_BASE
+ 8), bRegister
);
47 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9), Data_to_smbus
& 0xff);
48 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9), (Data_to_smbus
>> 8) & 0xff );
49 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9), (Data_to_smbus
>> 16) & 0xff );
50 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9), (Data_to_smbus
>> 24) & 0xff );
51 WRITE_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 6), 4);
54 WRITE_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 6), Data_to_smbus
&0xffff);
57 WRITE_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 6), Data_to_smbus
&0xff);
62 temp
= READ_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 0));
63 WRITE_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 0), temp
); // clear down all preexisting errors
68 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x1d); // DWORD modus
71 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x1b); // WORD modus
74 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x1a); // BYTE modus
82 b
=READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 0));
90 StallExecutionProcessor(1);
98 ReadfromSMBus(UCHAR Address
, UCHAR bRegister
, UCHAR Size
, ULONG
*Data_to_smbus
)
100 int nRetriesToLive
=50;
102 while (0 != (READ_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 0)) & 0x0800))
104 ; /* Franz's spin while bus busy with any master traffic */
107 while (0 != nRetriesToLive
--)
112 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 4), (Address
<< 1) | 1);
113 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 8), bRegister
);
115 temp
= READ_PORT_USHORT((USHORT
*) (I2C_IO_BASE
+ 0));
116 WRITE_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 0), temp
); /* clear down all preexisting errors */
121 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x0d); /* DWORD modus ? */
124 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x0b); /* WORD modus */
127 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x0a); // BYTE
133 while (0 == (b
& 0x36))
135 b
= READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 0));
140 /* printf("I2CTransmitByteGetReturn error %x\n", b); */
145 /* printf("I2CTransmitByteGetReturn no complete, retry\n"); */
152 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 6));
153 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
154 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
155 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
156 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
159 *Data_to_smbus
= READ_PORT_USHORT((USHORT
*) (I2C_IO_BASE
+ 6));
162 *Data_to_smbus
= READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 6));
175 I2CTransmitByteGetReturn(UCHAR bPicAddressI2cFormat
, UCHAR bDataToWrite
, ULONG
*Return
)
177 return ReadfromSMBus(bPicAddressI2cFormat
, bDataToWrite
, 1, Return
);
180 // transmit a word, no returned data from I2C device
182 I2CTransmitWord(UCHAR bPicAddressI2cFormat
, USHORT wDataToWrite
)
184 return WriteToSMBus(bPicAddressI2cFormat
,(wDataToWrite
>>8)&0xff,1,(wDataToWrite
&0xff));
188 I2cSetFrontpanelLed(UCHAR b
)
190 I2CTransmitWord( 0x10, 0x800 | b
); // sequencing thanks to Jarin the Penguin!
191 I2CTransmitWord( 0x10, 0x701);
194 // Set the pattern of the LED.
195 // r = Red, g = Green, o = Orange, x = Off
196 // This func is taken from cromwell, all credits goes for them
198 XboxSetLED(PCSTR pattern
) {
199 const char *x
= pattern
;
202 if(strlen(pattern
) == 4) {
221 I2cSetFrontpanelLed(((r
<<4) & 0xF0) + (g
& 0xF));