sysclk: attempt to fix lite issues
This commit is contained in:
@@ -108,22 +108,17 @@ typedef struct {
|
|||||||
unsigned int PLLD_LDPULSE_ADJ: 3;
|
unsigned int PLLD_LDPULSE_ADJ: 3;
|
||||||
unsigned int reserved: 2;
|
unsigned int reserved: 2;
|
||||||
} PLLD_MISC;
|
} PLLD_MISC;
|
||||||
|
|
||||||
// Configuration structure
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t clkVirtAddr;
|
uintptr_t clkVirtAddr;
|
||||||
uint64_t dsiVirtAddr;
|
uintptr_t dsiVirtAddr;
|
||||||
bool isDocked;
|
bool isDocked;
|
||||||
bool isLite;
|
bool isLite;
|
||||||
bool isRetroSUPER;
|
bool isRetroSUPER;
|
||||||
bool isPossiblySpoofedRetro;
|
bool isPossiblySpoofedRetro;
|
||||||
bool dontForce60InDocked;
|
|
||||||
bool matchLowestDocked;
|
|
||||||
bool displaySync;
|
bool displaySync;
|
||||||
bool displaySyncOutOfFocus60;
|
bool matchLowestDocked;
|
||||||
bool displaySyncDocked;
|
|
||||||
bool displaySyncDockedOutOfFocus60;
|
|
||||||
} DisplayRefreshConfig;
|
} DisplayRefreshConfig;
|
||||||
|
|
||||||
bool DisplayRefresh_Initialize(const DisplayRefreshConfig* config);
|
bool DisplayRefresh_Initialize(const DisplayRefreshConfig* config);
|
||||||
void DisplayRefresh_SetDockedState(bool isDocked);
|
void DisplayRefresh_SetDockedState(bool isDocked);
|
||||||
bool DisplayRefresh_SetRate(uint32_t new_refreshRate);
|
bool DisplayRefresh_SetRate(uint32_t new_refreshRate);
|
||||||
|
|||||||
@@ -213,7 +213,8 @@ static void _getDockedHighestRefreshRate(uint32_t fd_in) {
|
|||||||
uint8_t highestRefreshRate = 60;
|
uint8_t highestRefreshRate = 60;
|
||||||
uint32_t fd = fd_in;
|
uint32_t fd = fd_in;
|
||||||
|
|
||||||
if(!fd) nvOpen(&fd, "/dev/nvdisp-disp1");
|
if (!fd) nvOpen(&fd, "/dev/nvdisp-disp1");
|
||||||
|
|
||||||
NvdcModeDB2 db2 = {0};
|
NvdcModeDB2 db2 = {0};
|
||||||
int rc = nvIoctl(fd, NVDISP_GET_MODE_DB2, &db2);
|
int rc = nvIoctl(fd, NVDISP_GET_MODE_DB2, &db2);
|
||||||
|
|
||||||
@@ -221,11 +222,9 @@ static void _getDockedHighestRefreshRate(uint32_t fd_in) {
|
|||||||
for (size_t i = 0; i < db2.num_modes; i++) {
|
for (size_t i = 0; i < db2.num_modes; i++) {
|
||||||
if (db2.modes[i].hActive < 1920 || db2.modes[i].vActive < 1080)
|
if (db2.modes[i].hActive < 1920 || db2.modes[i].vActive < 1080)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint32_t v_total = db2.modes[i].vActive + db2.modes[i].vSyncWidth + db2.modes[i].vFrontPorch + db2.modes[i].vBackPorch;
|
uint32_t v_total = db2.modes[i].vActive + db2.modes[i].vSyncWidth + db2.modes[i].vFrontPorch + db2.modes[i].vBackPorch;
|
||||||
uint32_t h_total = db2.modes[i].hActive + db2.modes[i].hSyncWidth + db2.modes[i].hFrontPorch + db2.modes[i].hBackPorch;
|
uint32_t h_total = db2.modes[i].hActive + db2.modes[i].hSyncWidth + db2.modes[i].hFrontPorch + db2.modes[i].hBackPorch;
|
||||||
double refreshRate = round((double)(db2.modes[i].pclkKHz * 1000) / (double)(v_total * h_total));
|
double refreshRate = round((double)(db2.modes[i].pclkKHz * 1000) / (double)(v_total * h_total));
|
||||||
|
|
||||||
if (highestRefreshRate < (uint8_t)refreshRate)
|
if (highestRefreshRate < (uint8_t)refreshRate)
|
||||||
highestRefreshRate = (uint8_t)refreshRate;
|
highestRefreshRate = (uint8_t)refreshRate;
|
||||||
}
|
}
|
||||||
@@ -238,17 +237,17 @@ static void _getDockedHighestRefreshRate(uint32_t fd_in) {
|
|||||||
highestRefreshRate = g_dockedRefreshRates[numRates - 1];
|
highestRefreshRate = g_dockedRefreshRates[numRates - 1];
|
||||||
|
|
||||||
NvdcMode2 display_b = {0};
|
NvdcMode2 display_b = {0};
|
||||||
rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
|
nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
|
||||||
|
|
||||||
struct dpaux_read_0x100 {
|
struct {
|
||||||
uint32_t cmd;
|
uint32_t cmd;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
struct {
|
struct {
|
||||||
unsigned char link_rate;
|
unsigned char link_rate;
|
||||||
unsigned int lane_count: 5;
|
unsigned char lane_count: 5;
|
||||||
unsigned int unk1: 2;
|
unsigned char unk1: 2;
|
||||||
unsigned int isFramingEnhanced: 1;
|
unsigned char isFramingEnhanced: 1;
|
||||||
unsigned char downspread;
|
unsigned char downspread;
|
||||||
unsigned char training_pattern;
|
unsigned char training_pattern;
|
||||||
unsigned char lane_pattern[4];
|
unsigned char lane_pattern[4];
|
||||||
@@ -257,11 +256,8 @@ static void _getDockedHighestRefreshRate(uint32_t fd_in) {
|
|||||||
} dpaux = {6, 0x100, 0x10};
|
} dpaux = {6, 0x100, 0x10};
|
||||||
|
|
||||||
rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||||
if (rc == 0) {
|
if (rc == 0)
|
||||||
g_dockedLinkRate = dpaux.set.link_rate;
|
g_dockedLinkRate = dpaux.set.link_rate;
|
||||||
// if (display_b.hActive == 1920 && display_b.vActive == 1080 && highestRefreshRate > 75 && dpaux.set.link_rate < 20 && )
|
|
||||||
// highestRefreshRate = 75;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fd_in) nvClose(fd);
|
if (!fd_in) nvClose(fd);
|
||||||
g_dockedHighestRefreshRate = highestRefreshRate;
|
g_dockedHighestRefreshRate = highestRefreshRate;
|
||||||
@@ -547,30 +543,28 @@ bool DisplayRefresh_SetRate(uint32_t new_refreshRate) {
|
|||||||
|
|
||||||
uint32_t fd = 0;
|
uint32_t fd = 0;
|
||||||
|
|
||||||
if (g_config.isLite && g_config.isPossiblySpoofedRetro) {
|
if (g_config.isLite && g_config.isPossiblySpoofedRetro)
|
||||||
g_config.isRetroSUPER = false; // Would check flag file here in original, but i dont care lol
|
g_config.isRetroSUPER = false;
|
||||||
}
|
|
||||||
|
|
||||||
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
if (g_config.isRetroSUPER && !g_config.isDocked)
|
||||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||||
}
|
|
||||||
|
|
||||||
else if ((!g_config.isRetroSUPER && g_config.isLite) || R_FAILED(nvOpen(&fd, "/dev/nvdisp-disp1"))) {
|
else if ((!g_config.isRetroSUPER && g_config.isLite) || R_FAILED(nvOpen(&fd, "/dev/nvdisp-disp1"))) {
|
||||||
if (_setPLLDHandheldRefreshRate(new_refreshRate) == false)
|
if (_setPLLDHandheldRefreshRate(new_refreshRate) == false)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
struct dpaux_read {
|
struct {
|
||||||
uint32_t cmd;
|
uint32_t cmd;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
struct {
|
struct {
|
||||||
unsigned int rev_minor : 4;
|
unsigned char rev_minor: 4;
|
||||||
unsigned int rev_major : 4;
|
unsigned char rev_major: 4;
|
||||||
unsigned char link_rate;
|
unsigned char link_rate;
|
||||||
unsigned int lane_count: 5;
|
unsigned char lane_count: 5;
|
||||||
unsigned int unk1: 2;
|
unsigned char unk1: 2;
|
||||||
unsigned int isFramingEnhanced: 1;
|
unsigned char isFramingEnhanced: 1;
|
||||||
unsigned char unk2[13];
|
unsigned char unk2[13];
|
||||||
} DPCD;
|
} DPCD;
|
||||||
} dpaux = {6, 0, 0x10};
|
} dpaux = {6, 0, 0x10};
|
||||||
@@ -579,15 +573,14 @@ bool DisplayRefresh_SetRate(uint32_t new_refreshRate) {
|
|||||||
nvClose(fd);
|
nvClose(fd);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
if (!g_config.isRetroSUPER) {
|
if (!g_config.isRetroSUPER)
|
||||||
return _setPLLDHandheldRefreshRate(new_refreshRate);
|
return _setPLLDHandheldRefreshRate(new_refreshRate);
|
||||||
} else {
|
else
|
||||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if(g_config.isDocked)
|
if (g_config.isDocked)
|
||||||
return _setNvDispDockedRefreshRate(new_refreshRate);
|
return _setNvDispDockedRefreshRate(new_refreshRate);
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,6 +589,7 @@ bool DisplayRefresh_SetRate(uint32_t new_refreshRate) {
|
|||||||
|
|
||||||
bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
||||||
if (!out_refreshRate || !g_initialized || !g_config.clkVirtAddr) return false;
|
if (!out_refreshRate || !g_initialized || !g_config.clkVirtAddr) return false;
|
||||||
|
|
||||||
static uint32_t value = 60;
|
static uint32_t value = 60;
|
||||||
|
|
||||||
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
||||||
@@ -633,7 +627,6 @@ bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
|||||||
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
|
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
|
||||||
|
|
||||||
if (value == 0 || value == 80) {
|
if (value == 0 || value == 80) {
|
||||||
// Docked mode
|
|
||||||
if (g_config.isLite) return false;
|
if (g_config.isLite) return false;
|
||||||
|
|
||||||
g_config.isDocked = true;
|
g_config.isDocked = true;
|
||||||
@@ -641,15 +634,15 @@ bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
|||||||
if (!g_canChangeRefreshRateDocked) {
|
if (!g_canChangeRefreshRateDocked) {
|
||||||
uint32_t fd = 0;
|
uint32_t fd = 0;
|
||||||
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||||
struct dpaux_read_0x100 {
|
struct {
|
||||||
uint32_t cmd;
|
uint32_t cmd;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
struct {
|
struct {
|
||||||
unsigned char link_rate;
|
unsigned char link_rate;
|
||||||
unsigned int lane_count: 5;
|
unsigned char lane_count: 5;
|
||||||
unsigned int unk1: 2;
|
unsigned char unk1: 2;
|
||||||
unsigned int isFramingEnhanced: 1;
|
unsigned char isFramingEnhanced: 1;
|
||||||
unsigned char downspread;
|
unsigned char downspread;
|
||||||
unsigned char training_pattern;
|
unsigned char training_pattern;
|
||||||
unsigned char lane_pattern[4];
|
unsigned char lane_pattern[4];
|
||||||
@@ -671,10 +664,7 @@ bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(internal) {
|
|
||||||
*out_refreshRate = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
uint32_t fd = 0;
|
uint32_t fd = 0;
|
||||||
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||||
NvdcMode2 display_b = {0};
|
NvdcMode2 display_b = {0};
|
||||||
@@ -683,12 +673,10 @@ bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
|||||||
nvClose(fd);
|
nvClose(fd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_lastVActive != display_b.vActive) {
|
if (g_lastVActive != display_b.vActive) {
|
||||||
g_lastVActive = display_b.vActive;
|
g_lastVActive = display_b.vActive;
|
||||||
_getDockedHighestRefreshRate(fd);
|
_getDockedHighestRefreshRate(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
|
uint32_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
|
||||||
uint32_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
uint32_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
||||||
uint32_t pixelClock = display_b.pclkKHz * 1000 + 999;
|
uint32_t pixelClock = display_b.pclkKHz * 1000 + 999;
|
||||||
@@ -702,10 +690,8 @@ bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!g_config.isRetroSUPER) {
|
else if (!g_config.isRetroSUPER) {
|
||||||
// Handheld mode
|
|
||||||
g_config.isDocked = false;
|
g_config.isDocked = false;
|
||||||
g_canChangeRefreshRateDocked = false;
|
g_canChangeRefreshRateDocked = false;
|
||||||
|
|
||||||
uint32_t pixelClock = (9375 * ((4096 * ((2 * temp.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * temp.PLLD_DIVM);
|
uint32_t pixelClock = (9375 * ((4096 * ((2 * temp.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * temp.PLLD_DIVM);
|
||||||
value = pixelClock / (DSI_CLOCK_HZ / 60);
|
value = pixelClock / (DSI_CLOCK_HZ / 60);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user