From 6c535bf7dfaf662083fec498d8cf338a2b0e76d6 Mon Sep 17 00:00:00 2001 From: Lephe Date: Mon, 20 Jul 2020 17:10:47 +0200 Subject: [PATCH] cpg: add spread spectrum control Disables spread spectrum by default so that the frequency estimations of the CPG driver (notably used by the timer driver and libprof) are more accurate. --- TODO | 7 +------ include/gint/mpu/cpg.h | 9 +++++++-- src/cpg/cpg.c | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index aa2b81e..e4f9be6 100644 --- a/TODO +++ b/TODO @@ -3,17 +3,11 @@ For the 2.1.0 release: * project: remove the compat branch * project: remove the gray aliases -Issues: -* #10 support fx-CG 20 - Extensions on existing code: * tmu: make interrupt handlers more elegant * bopti: try to display fullscreen images with TLB access + DMA on fxcg50 -* topti: support unicode fonts * dma: fx9860g support (need to switch it on and update the Makefile) * core: try to leave add-in without reset in case of panic -* hardware: fill in the HWMEM_FITTLB flag -* cpg: spread spectrum on fxcg50 * core: use cmp/str for memchr() * r61524: brightness control and clean the file * core: review forgotten globals and MPU addresses not in @@ -21,6 +15,7 @@ Extensions on existing code: * core: run destructors when a task-switch results in leaving the app * core: invoke main menu instead of returning after main() ends * core rtc: use qdiv10 to massively improve division performance +* topti: let the font specify letter and word spacing Future directions. * A complete file system abstraction diff --git a/include/gint/mpu/cpg.h b/include/gint/mpu/cpg.h index 665bbce..cba1083 100644 --- a/include/gint/mpu/cpg.h +++ b/include/gint/mpu/cpg.h @@ -65,8 +65,13 @@ typedef volatile struct uint32_t CKOFF :1; /* CKO Output Stop */ uint32_t :1; ); - /* TODO: CPG: Add the SSCGCR register */ - pad(0x28); + + pad(0x1c); + lword_union(SSCGCR, + uint32_t SSEN :1; /* Spread Spectrum Enable */ + uint32_t :31; + ); + pad(0x8); lword_union(FLLFRQ, uint32_t :16; diff --git a/src/cpg/cpg.c b/src/cpg/cpg.c index 929f8bf..9ed33cf 100644 --- a/src/cpg/cpg.c +++ b/src/cpg/cpg.c @@ -113,11 +113,17 @@ static void sh7305_probe(void) #undef CPG //--- -// Other driver stuff +// Initialization, contexts and driver metadata //--- static void init(void) { + /* Disable spread spectrum in SSGSCR */ + if(isSH4()) + { + SH7305_CPG.SSCGCR.SSEN = 0; + } + /* This avoids warnings about sh7705_probe() being undefined when building for fxcg50 */ #if defined(FX9860G) || (!defined(FX9860G) && !defined(FXCG50)) @@ -126,9 +132,31 @@ static void init(void) sh7305_probe(); } +typedef struct { + uint32_t SSCGCR; +} ctx_t; + +static ctx_t sys_ctx, gint_ctx; + +static void ctx_save(void *ctx) +{ + ctx_t *c = ctx; + if(isSH4()) c->SSCGCR = SH7305_CPG.SSCGCR.lword; +} + +static void ctx_restore(void *ctx) +{ + ctx_t *c = ctx; + if(isSH4()) SH7305_CPG.SSCGCR.lword = c->SSCGCR; +} + gint_driver_t drv_cpg = { - .name = "CPG", - .init = init, + .name = "CPG", + .init = init, + .sys_ctx = &sys_ctx, + .gint_ctx = &gint_ctx, + .ctx_save = ctx_save, + .ctx_restore = ctx_restore, }; GINT_DECLARE_DRIVER(1, drv_cpg);