15#ifdef BUILDING_XPADMAN
43static u8 sio2_in_buffer[256];
44static u8 sio2_out_buffer[256];
45static s32 change_slot_buffer[8];
47static int transferCount;
49#ifndef BUILDING_XPADMAN
50static int pd_set_change_slot_buffer(s32 *status)
54 for (i = 0; i < 4; i++, status++) {
55 if ((*status + 1) < 2)
69 if(
id == 0)
id = PAD_ID_DIGITAL;
71 return (PAD_ID_LO(
id)*2)+3;
74u32 pdGetOutSize(u8
id)
76 if(
id == 0)
id = PAD_ID_DIGITAL;
78 return (PAD_ID_LO(
id)*2)+3;
81u32 pdGetRegData(u32
id)
85 ret1 = pdGetInSize((u8)
id);
87 ret2 = pdGetOutSize((u8)
id);
89 return ((ret2 & 0x1FF) << 18) | ((ret1 & 0x1FF) << 8) | 0x40;
92u32 pdSetRegData(u32 port, u32 slot, u32 reg_data)
96 padData[port][slot].reg_data = reg_data;
104u32 setupReadData(u32 port, u32 slot, u32 val)
109 res = sio2CmdGetPortCtrl1(0, val, 0);
111 pdSetCtrl1(port, slot, res);
113 res = sio2CmdGetPortCtrl2(0, val);
115 pdSetCtrl2(port, slot, res);
118 res = pdGetRegData(0);
120 pdSetRegData(port, slot, res);
123 res = pdGetInSize(0);
125 pdSetInSize(port, slot, res);
127 res = pdGetOutSize(0);
129 pdSetOutSize(port, slot, res);
131 sio2CmdSetReadData(0, buf);
133 pdSetInBuffer(port, slot, 0, buf);
138u32 pdSetActive(u32 port, u32 slot, u32 active)
140 u32 res = padData[port][slot].active;
142 padData[port][slot].active = active;
147u32 pdIsActive(u32 port, u32 slot)
149 return padData[port][slot].active;
152static u32 mtapChangeSlot(u32 slot)
154 change_slot_buffer[0] = -1;
155 change_slot_buffer[1] = -1;
156 change_slot_buffer[2] = -1;
157 change_slot_buffer[3] = -1;
159 if( (padData[0][slot].active == 0) && (padData[1][slot].active == 0) )
162 if(padData[0][slot].active == 1)
163 change_slot_buffer[0] = slot;
165 if(padData[1][slot].active == 1)
166 change_slot_buffer[1] = slot;
168#ifdef BUILDING_XPADMAN
169 sio2_mtap_change_slot(change_slot_buffer);
171 pd_set_change_slot_buffer(change_slot_buffer);
177u32 pdSetStat70bit(u32 port, u32 slot, u32 val)
179 u32 ret = padData[port][slot].stat70bit;
181 padData[port][slot].stat70bit = val;
186static u32 setupTransferData(u32 index, u32 port, u32 slot)
189 if(padData[port][slot].in_size > 0)
193 for(i=0; (u32)i < padData[port][slot].in_size; i++)
195 sio2_td.in[sio2_td.in_size] = padData[port][slot].in_buffer[i];
200 sio2_td.out_size += padData[port][slot].out_size;
202 sio2_td.port_ctrl1[port] = padData[port][slot].port_ctrl1;
203 sio2_td.port_ctrl2[port] = padData[port][slot].port_ctrl2;
204 sio2_td.regdata[index] = (padData[port][slot].reg_data & 0xFFFFFFFC) | (port & 0x3);
206 sio2_td.regdata[index+1] = 0;
213 return( (td->stat6c & (0x00010000 << bit)) != 0);
216u32 readSio2OutBuffer(u32 bit, u32 port, u32 slot)
218 if(((sio2_td.stat6c >> 13) & 0x1) == 1)
220 padData[port][slot].error = 1;
225 if(readStat6cBit(bit, &sio2_td) == 1)
227 padData[port][slot].error = 1;
232 padData[port][slot].error = 0;
234 if( padData[port][slot].out_size > 0)
238 for(i=0; (u32)i < padData[port][slot].out_size; i++)
240 padData[port][slot].out_buffer[i] = sio2_td.out[sio2_td.out_size];
250u32 padTransfer(u32 slot)
253 u32 trans_count = 0, port0_start = 0, port1_start = 0;
258 sio2_td.out_size = 0;
259 sio2_td.in_dma.addr = 0;
260 sio2_td.out_dma.addr = 0;
262 stat70 = sio2_stat70_get();
264 pdSetStat70bit(0, slot, (stat70 >> 4) & 1);
265 pdSetStat70bit(1, slot, (stat70 >> 5) & 1);
267 if( padData[0][slot].active == 1 )
269 if(change_slot_buffer[4] == 1)
273 trans_count = setupTransferData(0, 0, slot);
277 if( padData[1][slot].active == 1 )
279 if(change_slot_buffer[5] == 1)
282 port1_start = trans_count;
283 trans_count = setupTransferData(trans_count, 1, slot);
289 if(padData[0][slot].active == 1)
291 if(change_slot_buffer[4] != 1)
292 padData[0][slot].error = 0xA;
295 if(padData[1][slot].active == 1)
297 if(change_slot_buffer[5] != 1)
298 padData[1][slot].error = 0xA;
303#ifndef BUILDING_XPADMAN
304 sio2_pad_transfer_init();
307#ifdef BUILDING_XPADMAN
308 sio2_transfer2( &sio2_td );
310 sio2_transfer( &sio2_td );
313 sio2_td.out_size = 0;
317 readSio2OutBuffer(port0_start, 0, slot);
318 sio2_td.out_size = padData[0][slot].out_size;
323 readSio2OutBuffer(port1_start, 1, slot);
324 sio2_td.out_size = padData[1][slot].out_size;
337#ifdef BUILDING_XPADMAN
338 sio2_pad_transfer_init();
343 for(slot=0; slot < 4; slot++)
345 if( (padData[0][slot].active == 1) || (padData[1][slot].active == 1) )
347 if(slot > 0) mtapChangeSlot(slot);
355#ifdef BUILDING_XPADMAN
356 sio2_transfer_reset2();
360u32 pdGetStat70bit(u32 port, u32 slot)
362 return padData[port][slot].stat70bit;
373 padData[i][j].active = 0;
374 padData[i][j].stat70bit = 0;
380 sio2_td.in = sio2_in_buffer;
381 sio2_td.out = sio2_out_buffer;
385static u32 SlotCheckConnection(u32 port, u32 slot)
390 sio2_td.out_size = 0;
391 sio2_td.out_dma.addr = 0;
392 sio2_td.in_dma.addr = 0;
394 if(change_slot_buffer[4+port] == 1)
396#ifndef BUILDING_XPADMAN
397 sio2_pad_transfer_init();
401 stat70 = sio2_stat70_get();
407 pdSetStat70bit(0, slot, (stat70 >> 4) & 0x1);
410 pdSetStat70bit(1, slot, (stat70 >> 5) & 0x1);
415 setupTransferData(0, port, slot);
418#ifdef BUILDING_XPADMAN
419 sio2_transfer2( &sio2_td );
421 sio2_transfer( &sio2_td );
424 sio2_td.out_size = 0;
427 readSio2OutBuffer(0, port, slot);
428 sio2_td.out_size = padData[port][slot].out_size;
431 if(change_slot_buffer[4+port] != 1)
432 padData[port][slot].error = 0xA;
440u32 pdCheckConnection(u32 port, u32 slot)
445#ifndef BUILDING_XPADMAN
452#ifdef BUILDING_XPADMAN
453 sio2_pad_transfer_init();
456 change_slot_buffer[0] = slot;
457 change_slot_buffer[1] = slot;
458 change_slot_buffer[2] = -1;
459 change_slot_buffer[3] = -1;
461#ifdef BUILDING_XPADMAN
462 sio2_mtap_change_slot(change_slot_buffer);
464 pd_set_change_slot_buffer(change_slot_buffer);
467 res = pdGetStat70bit(0, slot);
468 setupReadData(0, slot, res);
470 res = pdGetStat70bit(1, slot);
471 setupReadData(1, slot, res);
474 if(SlotCheckConnection(port, slot) == 1)
476 if( padData[port][slot].error == 0 )
480 change_slot_buffer[0] = 0;
481 change_slot_buffer[1] = 0;
482 change_slot_buffer[2] = -1;
483 change_slot_buffer[3] = -1;
485#ifdef BUILDING_XPADMAN
486 sio2_mtap_change_slot(change_slot_buffer);
488 pd_set_change_slot_buffer(change_slot_buffer);
491#ifdef BUILDING_XPADMAN
492 sio2_transfer_reset2();
498s32 pdGetError(u32 port, u32 slot)
501 return padData[port][slot].error;
506u32 pdSetCtrl1(u32 port, u32 slot, u32 ctrl)
510 padData[port][slot].port_ctrl1 = ctrl;
517u32 pdSetCtrl2(u32 port, u32 slot, u32 ctrl)
521 padData[port][slot].port_ctrl2 = ctrl;
529u32 pdSetInSize(u32 port, u32 slot, u32 size)
533 padData[port][slot].in_size = size;
540u32 pdSetOutSize(u32 port, u32 slot, u32 size)
544 padData[port][slot].out_size = size;
552u32 pdSetInBuffer(u32 port, u32 slot, u32 size,
const u8 *buf)
556 if(size == 0) size = padData[port][slot].in_size;
562 for(i=0; (u32)i < size; i++)
563 padData[port][slot].in_buffer[i] = buf[i];
572u32 pdGetOutBuffer(u32 port, u32 slot, u32 size, u8 *buf)
576 if(size == 0) size = padData[port][slot].out_size;
582 for(i=0; (u32)i < size; i++)
583 buf[i] = padData[port][slot].out_buffer[i];