#if defined (LINUX) #include "../../include/adl_sdk.h" #include "../../include/customer/oem_structures.h" #include <dlfcn.h> //dyopen, dlsym, dlclose #include <stdlib.h> #include <string.h> //memeset #include <unistd.h> //sleep #else #include <windows.h> #include <tchar.h> #include "..\..\include\adl_sdk.h" #include "..\..\include\customer\oem_structures.h" #endif #include <stdio.h> // Definitions of the used function pointers. Add more if you use other ADL APIs typedef int ( *ADL_MAIN_CONTROL_CREATE )(ADL_MAIN_MALLOC_CALLBACK, int ); typedef int ( *ADL_MAIN_CONTROL_DESTROY )(); typedef int ( *ADL_ADAPTER_NUMBEROFADAPTERS_GET ) ( int* ); typedef int ( *ADL_ADAPTER_ADAPTERINFO_GET ) ( LPAdapterInfo, int ); typedef int ( *ADL_DISPLAY_COLORCAPS_GET ) ( int, int, int *, int * ); typedef int ( *ADL_DISPLAY_COLOR_GET ) ( int, int, int, int *, int *, int *, int *, int * ); typedef int ( *ADL_DISPLAY_COLOR_SET ) ( int, int, int, int ); typedef int ( *ADL_DISPLAY_DISPLAYINFO_GET ) ( int, int *, ADLDisplayInfo **, int ); typedef int ( *ADL_DISPLAY_NATIVEAUXCHANNEL_ACCESS)(int, int, ADLDisplayNativeAUXChannelData*); // Memory allocation function void* __stdcall ADL_Main_Memory_Alloc ( int iSize ) { void* lpBuffer = malloc ( iSize ); return lpBuffer; } // Optional Memory de-allocation function void __stdcall ADL_Main_Memory_Free ( void** lpBuffer ) { if ( NULL != *lpBuffer ) { free ( *lpBuffer ); *lpBuffer = NULL; } } #if defined (LINUX) // equivalent functions in linux void * GetProcAddress( void * pLibrary, const char * name) { return dlsym( pLibrary, name); } void Sleep( int time) { usleep(time*1000); } #endif int main (int argc, char** argv) { #if defined (LINUX) void *hDLL; // Handle to .so library #else HINSTANCE hDLL; // Handle to DLL #endif ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create; ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy; ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get; ADL_ADAPTER_ADAPTERINFO_GET ADL_Adapter_AdapterInfo_Get; ADL_DISPLAY_DISPLAYINFO_GET ADL_Display_DisplayInfo_Get; ADL_DISPLAY_NATIVEAUXCHANNEL_ACCESS ADL_Display_NativeAUXChannel_Access; LPAdapterInfo lpAdapterInfo = NULL; LPADLDisplayInfo lpAdlDisplayInfo = NULL; int i, j, m; int ADL_Err; int iNumberAdapters; int iAdapterIndex; int iDisplayIndex; int iNumDisplays; ADLDisplayNativeAUXChannelData data = {0}; unsigned char isDirectAux = 0; /* if 1, then access 1st downstream device (could be MST hub) */ for(i = 1; i < argc; i++) { if(stricmp(argv[i], "-directAux") == 0) { printf(_T("Enabling directAux option...\n")); isDirectAux = 1; } } #if defined (LINUX) hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL); #else hDLL = LoadLibrary("atiadlxx.dll"); if (hDLL == NULL) // A 32 bit calling application on 64 bit OS will fail to LoadLIbrary. // Try to load the 32 bit library (atiadlxy.dll) instead hDLL = LoadLibrary("atiadlxy.dll"); #endif if (NULL == hDLL) { printf("ADL library not found!\n"); return 0; } ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) GetProcAddress(hDLL,"ADL_Main_Control_Create"); ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) GetProcAddress(hDLL,"ADL_Main_Control_Destroy"); ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) GetProcAddress(hDLL,"ADL_Adapter_NumberOfAdapters_Get"); ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) GetProcAddress(hDLL,"ADL_Adapter_AdapterInfo_Get"); ADL_Display_DisplayInfo_Get = (ADL_DISPLAY_DISPLAYINFO_GET) GetProcAddress(hDLL,"ADL_Display_DisplayInfo_Get"); if ( NULL == ADL_Main_Control_Create || NULL == ADL_Main_Control_Destroy || NULL == ADL_Adapter_NumberOfAdapters_Get || NULL == ADL_Adapter_AdapterInfo_Get || NULL == ADL_Display_DisplayInfo_Get ) { printf("ADL's API is missing!\n"); return 0; } ADL_Display_NativeAUXChannel_Access = (ADL_DISPLAY_NATIVEAUXCHANNEL_ACCESS) GetProcAddress(hDLL,"ADL_Display_NativeAUXChannel_Access"); if ( NULL == ADL_Display_NativeAUXChannel_Access ) { printf("ADL_Display_NativeAUXChannel_Access API is missing!\n"); return 0; } // Initialize ADL. The second parameter is 1, which means: // retrieve adapter information only for adapters that are physically present and enabled in the system if ( ADL_OK != ADL_Main_Control_Create (ADL_Main_Memory_Alloc, 1) ) { printf("ADL Initialization Error!\n"); return 0; } // Obtain the number of adapters for the system if ( ADL_OK != ADL_Adapter_NumberOfAdapters_Get ( &iNumberAdapters ) ) { printf("Cannot get the number of adapters!\n"); return 0; } if ( 0 < iNumberAdapters ) { lpAdapterInfo = (LPAdapterInfo)malloc(sizeof(AdapterInfo)* iNumberAdapters); memset ( lpAdapterInfo,'\0', sizeof (AdapterInfo) * iNumberAdapters ); // Get the AdapterInfo structure for all adapters in the system ADL_Adapter_AdapterInfo_Get (lpAdapterInfo, sizeof (AdapterInfo) * iNumberAdapters); } // Repeat for all available adapters in the system for ( i = 0; i < iNumberAdapters; i++ ) { iAdapterIndex = lpAdapterInfo[ i ].iAdapterIndex; ADL_Main_Memory_Free ((void**)&lpAdlDisplayInfo ); if (ADL_OK != ADL_Display_DisplayInfo_Get (lpAdapterInfo[i].iAdapterIndex, &iNumDisplays, &lpAdlDisplayInfo, 0)) continue; for ( j = 0; j < iNumDisplays; j++ ) { // For each display, check its status. Use the display only if it's connected AND mapped (iDisplayInfoValue: bit 0 and 1 ) if ( ( ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED | ADL_DISPLAY_DISPLAYINFO_DISPLAYMAPPED ) != ( ADL_DISPLAY_DISPLAYINFO_DISPLAYCONNECTED | ADL_DISPLAY_DISPLAYINFO_DISPLAYMAPPED & lpAdlDisplayInfo[ j ].iDisplayInfoValue ) ) continue; // Skip the not connected or non-active displays // Is the display mapped to this adapter? This test is too restrictive and may not be needed. if ( iAdapterIndex != lpAdlDisplayInfo[ j ].displayID.iDisplayLogicalAdapterIndex ) continue; iDisplayIndex = lpAdlDisplayInfo[ j ].displayID.iDisplayLogicalIndex; data.iSize = sizeof(ADLDisplayNativeAUXChannelData); /* DPCD_REV = 0x0000 DPCD_ADDR_LANE0_1_STATUS = 0x0202, read = 0; DPCD_ADDR_LANE_ALIGN_STATUS_UPDATED = 0x0204, read = 0x81 */ printf(_T("Read.\n")); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_READ : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_READ); data.iAddress = 0x0000; data.iDataSize = 1; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x%04X, size = 1, data[0] = 0x%x (Minor Ver: 0x%02X / Major Ver: 0x%02X).\n"), ADL_Err, data.iAuxStatus, data.iAddress, (unsigned char)data.cData[0], data.cData[0] & 0x0F, data.cData[0] & 0xF0); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_READ : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_READ); data.iAddress = 0x0202; data.iDataSize = 1; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0202, size = 1, data[0] = 0x%x.\n"), ADL_Err, data.iAuxStatus, (unsigned char)data.cData[0]); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_READ : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_READ); data.iAddress = 0x0204; data.iDataSize = 1; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0204, size = 1, data[0] = 0x%x.\n"), ADL_Err, data.iAuxStatus, (unsigned char)data.cData[0]); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_READ : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_READ); data.iAddress = 0x0204; data.iDataSize = 16; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0204, size = 16.\n"), ADL_Err, data.iAuxStatus); for( m= 0; m < 16; m++) { printf(_T(" data.cData[%d]= 0x%x.\n"), m, (unsigned char)data.cData[m]); } /* DPCD_ADDR_POWER_STATE = 0x0600, write = 2 ( DP_POWER_STATE_D0 = 1, DP_POWER_STATE_D3 = 2) DPCD_ADDR_POWER_STATE = 0x0600, write = 1 ( DP_POWER_STATE_D0 = 1, DP_POWER_STATE_D3 = 2) */ printf(_T("Write.\n")); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_WRITE : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_WRITE); data.iAddress = 0x0600; data.iDataSize = 1; data.cData[0] = 2; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0600, size = 1, data[0] = 0x%x.\n"), ADL_Err, data.iAuxStatus, (unsigned char)data.cData[0]); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_READ : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_READ); data.iAddress = 0x0600; data.iDataSize = 1; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0600, size = 1, data[0] = 0x%x.\n"), ADL_Err, data.iAuxStatus, (unsigned char)data.cData[0]); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_WRITE : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_WRITE); data.iAddress = 0x0600; data.iDataSize = 1; data.cData[0] = 1; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0600, size = 1, data[0] = 0x%x.\n"), ADL_Err, data.iAuxStatus, (unsigned char)data.cData[0]); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_READ : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_READ); data.iAddress = 0x0600; data.iDataSize = 1; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0600, size = 1, data[0] = 0x%x.\n"), ADL_Err, data.iAuxStatus, (unsigned char)data.cData[0]); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_WRITE : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_WRITE); data.iAddress = 0x0600; data.iDataSize = 16; memset(data.cData, 0, 16); data.cData[0] = 1; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0600, size = 16, data[0] = 0x%x.\n"), ADL_Err, data.iAuxStatus, (unsigned char)data.cData[0]); data.iCommand = (isDirectAux == 0 ? ADL_AUX_CHANNEL_READ : ADL_AUX_CHANNEL_IMMEDIATEDEVICE_READ); data.iAddress = 0x0600; data.iDataSize = 16; ADL_Err = ADL_Display_NativeAUXChannel_Access(iAdapterIndex, iDisplayIndex, &data); printf(_T("ADL_Err = %d, iAuxStatus = %d, iAddress = 0x0600, size = 16.\n"), ADL_Err, data.iAuxStatus); for( m= 0; m < 16; m++) { printf(_T(" data.cData[%d]= 0x%x.\n"), m, data.iAuxStatus, (unsigned char)data.cData[m]); } } } ADL_Main_Memory_Free ((void**)&lpAdapterInfo ); ADL_Main_Memory_Free ((void**)&lpAdlDisplayInfo ); ADL_Main_Control_Destroy (); #if defined (LINUX) dlclose(hDLL); #else FreeLibrary(hDLL); #endif return 0; }