ReactOS 0.4.16-dev-319-g6cf4263
xboxi2c.c File Reference
#include <freeldr.h>
Include dependency graph for xboxi2c.c:

Go to the source code of this file.

Macros

#define I2C_IO_BASE   0xc000
 

Functions

static BOOLEAN WriteToSMBus (UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG Data_to_smbus)
 
static BOOLEAN ReadfromSMBus (UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG *Data_to_smbus)
 
BOOLEAN I2CTransmitByteGetReturn (UCHAR bPicAddressI2cFormat, UCHAR bDataToWrite, ULONG *Return)
 
static BOOLEAN I2CTransmitWord (UCHAR bPicAddressI2cFormat, USHORT wDataToWrite)
 
static void I2cSetFrontpanelLed (UCHAR b)
 
void XboxSetLED (PCSTR pattern)
 

Macro Definition Documentation

◆ I2C_IO_BASE

#define I2C_IO_BASE   0xc000

Definition at line 24 of file xboxi2c.c.

Function Documentation

◆ I2cSetFrontpanelLed()

static void I2cSetFrontpanelLed ( UCHAR  b)
static

Definition at line 188 of file xboxi2c.c.

189{
190 I2CTransmitWord( 0x10, 0x800 | b); // sequencing thanks to Jarin the Penguin!
191 I2CTransmitWord( 0x10, 0x701);
192}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static BOOLEAN I2CTransmitWord(UCHAR bPicAddressI2cFormat, USHORT wDataToWrite)
Definition: xboxi2c.c:182

Referenced by XboxSetLED().

◆ I2CTransmitByteGetReturn()

BOOLEAN I2CTransmitByteGetReturn ( UCHAR  bPicAddressI2cFormat,
UCHAR  bDataToWrite,
ULONG Return 
)

Definition at line 175 of file xboxi2c.c.

176{
177 return ReadfromSMBus(bPicAddressI2cFormat, bDataToWrite, 1, Return);
178}
static BOOLEAN ReadfromSMBus(UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG *Data_to_smbus)
Definition: xboxi2c.c:98

◆ I2CTransmitWord()

static BOOLEAN I2CTransmitWord ( UCHAR  bPicAddressI2cFormat,
USHORT  wDataToWrite 
)
static

Definition at line 182 of file xboxi2c.c.

183{
184 return WriteToSMBus(bPicAddressI2cFormat,(wDataToWrite>>8)&0xff,1,(wDataToWrite&0xff));
185}
static BOOLEAN WriteToSMBus(UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG Data_to_smbus)
Definition: xboxi2c.c:27

Referenced by I2cSetFrontpanelLed().

◆ ReadfromSMBus()

static BOOLEAN ReadfromSMBus ( UCHAR  Address,
UCHAR  bRegister,
UCHAR  Size,
ULONG Data_to_smbus 
)
static

Definition at line 98 of file xboxi2c.c.

99{
100 int nRetriesToLive=50;
101
102 while (0 != (READ_PORT_USHORT((PUSHORT) (I2C_IO_BASE + 0)) & 0x0800))
103 {
104 ; /* Franz's spin while bus busy with any master traffic */
105 }
106
107 while (0 != nRetriesToLive--)
108 {
109 UCHAR b;
110 int temp;
111
112 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 4), (Address << 1) | 1);
113 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 8), bRegister);
114
116 WRITE_PORT_USHORT((PUSHORT) (I2C_IO_BASE + 0), temp); /* clear down all preexisting errors */
117
118 switch (Size)
119 {
120 case 4:
121 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 2), 0x0d); /* DWORD modus ? */
122 break;
123 case 2:
124 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 2), 0x0b); /* WORD modus */
125 break;
126 default:
127 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 2), 0x0a); // BYTE
128 break;
129 }
130
131 b = 0;
132
133 while (0 == (b & 0x36))
134 {
136 }
137
138 if (0 != (b & 0x24))
139 {
140 /* printf("I2CTransmitByteGetReturn error %x\n", b); */
141 }
142
143 if(0 == (b & 0x10))
144 {
145 /* printf("I2CTransmitByteGetReturn no complete, retry\n"); */
146 }
147 else
148 {
149 switch (Size)
150 {
151 case 4:
157 break;
158 case 2:
159 *Data_to_smbus = READ_PORT_USHORT((USHORT *) (I2C_IO_BASE + 6));
160 break;
161 default:
162 *Data_to_smbus = READ_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 6));
163 break;
164 }
165
166
167 return TRUE;
168 }
169 }
170
171 return FALSE;
172}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63
#define b
Definition: ke_i.h:79
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
unsigned short USHORT
Definition: pedump.c:61
static WCHAR Address[46]
Definition: ping.c:68
static calc_node_t temp
Definition: rpn_ieee.c:38
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define I2C_IO_BASE
Definition: xboxi2c.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by I2CTransmitByteGetReturn().

◆ WriteToSMBus()

static BOOLEAN WriteToSMBus ( UCHAR  Address,
UCHAR  bRegister,
UCHAR  Size,
ULONG  Data_to_smbus 
)
static

Definition at line 27 of file xboxi2c.c.

28{
29 int nRetriesToLive=50;
30
31 while(READ_PORT_USHORT((PUSHORT) (I2C_IO_BASE+0)) & 0x0800)
32 {
33 ; // Franz's spin while bus busy with any master traffic
34 }
35
36 while(nRetriesToLive--)
37 {
38 UCHAR b;
39 unsigned int temp;
40
41 WRITE_PORT_UCHAR((PUCHAR)(I2C_IO_BASE + 4), (Address << 1) | 0);
42 WRITE_PORT_UCHAR((PUCHAR)(I2C_IO_BASE + 8), bRegister);
43
44 switch (Size)
45 {
46 case 4:
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 );
52 break;
53 case 2:
54 WRITE_PORT_USHORT((PUSHORT) (I2C_IO_BASE + 6), Data_to_smbus&0xffff);
55 break;
56 default: // 1
57 WRITE_PORT_USHORT((PUSHORT) (I2C_IO_BASE + 6), Data_to_smbus&0xff);
58 break;
59 }
60
61
63 WRITE_PORT_USHORT((PUSHORT) (I2C_IO_BASE + 0), temp); // clear down all preexisting errors
64
65 switch (Size)
66 {
67 case 4:
68 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 2), 0x1d); // DWORD modus
69 break;
70 case 2:
71 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 2), 0x1b); // WORD modus
72 break;
73 default: // 1
74 WRITE_PORT_UCHAR((PUCHAR) (I2C_IO_BASE + 2), 0x1a); // BYTE modus
75 break;
76 }
77
78 b = 0;
79
80 while( (b&0x36)==0 )
81 {
83 }
84
85 if ((b&0x10) != 0)
86 {
87 return TRUE;
88 }
89
91 }
92
93 return FALSE;
94}
VOID StallExecutionProcessor(ULONG Microseconds)
Definition: pchw.c:60

Referenced by I2CTransmitWord().

◆ XboxSetLED()

void XboxSetLED ( PCSTR  pattern)

Definition at line 198 of file xboxi2c.c.

198 {
199 const char *x = pattern;
200 int r, g;
201
202 if(strlen(pattern) == 4) {
203 r = g = 0;
204 while (*x) {
205 r *= 2;
206 g *= 2;
207 switch (*x) {
208 case 'r':
209 r++;
210 break;
211 case 'g':
212 g++;
213 break;
214 case 'o':
215 r++;
216 g++;
217 break;
218 }
219 x++;
220 }
221 I2cSetFrontpanelLed(((r<<4) & 0xF0) + (g & 0xF));
222 }
223}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLubyte * pattern
Definition: glext.h:7787
GLboolean GLboolean g
Definition: glext.h:6204
static void I2cSetFrontpanelLed(UCHAR b)
Definition: xboxi2c.c:188

Referenced by MachInit().