PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
iLink_PHY.c
1/* iLink_PHY.c
2 * Purpose: Contains the functions that are used for writing/reading values from the PHY.
3 *
4 * Last Updated: 2012/02/20
5 * Programmer: SP193
6 */
7
8#include <thbase.h>
9
10#include "iLinkman.h"
11#include "iLink_internal.h"
12
13extern struct ILINKMemMap *ILINKRegisterBase;
14
15#define RdPhy 0x80000000
16#define WrPhy 0x40000000
17
18static void iLinkPhySync(void)
19{
20 while (ILINKRegisterBase->PHYAccess & (RdPhy | WrPhy)) {};
21}
22
23unsigned char iLinkReadPhy(unsigned char address)
24{
25 ILINKRegisterBase->PHYAccess = (((unsigned int)address) << 24) | RdPhy;
26 iLinkPhySync();
27
28 while (!(ILINKRegisterBase->intr0 & iLink_INTR0_PhyRRx)) {};
29 ILINKRegisterBase->intr0 = iLink_INTR0_PhyRRx;
30
31 return (ILINKRegisterBase->PHYAccess & 0xFF);
32}
33
34void iLinkWritePhy(unsigned char address, unsigned char data)
35{
36 ILINKRegisterBase->PHYAccess = (((unsigned int)address) << 24) | (((unsigned int)data) << 16) | WrPhy;
37 iLinkPhySync();
38}
39
40void iLinkPHY_SetRootBit(int isRoot)
41{
42 unsigned short int Register01value;
43
44 Register01value = iLinkReadPhy(1);
45 if (isRoot)
46 Register01value |= REG01_RHB;
47 else
48 Register01value &= (~REG01_RHB);
49
50 iLinkWritePhy(1, Register01value);
51}
52
53void iLinkPHY_SetGapCount(unsigned char GapCount)
54{
55 iLinkWritePhy(1, (iLinkReadPhy(1) & 0xC0) | GapCount);
56}
57
58void iLinkPHY_SetLCTRL(int LCTRL_status)
59{
60 unsigned short int Register04value;
61
62 Register04value = iLinkReadPhy(4);
63 if (LCTRL_status)
64 Register04value |= REG04_LCTRL;
65 else
66 Register04value &= (~REG04_LCTRL);
67
68 iLinkWritePhy(4, Register04value);
69}
70
71void iLinkPHYBusReset(void)
72{
73 iLinkWritePhy(5, iLinkReadPhy(5) | REG05_ISBR);
74}