summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/kernel-x1000.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-02-27 22:08:58 +0000
committerAidan MacDonald <amachronic@protonmail.com>2021-03-28 00:01:37 +0000
commit3ec66893e377b088c1284d2d23adb2aeea6d7965 (patch)
treeb647717f83ad56b15dc42cfdef5d04d68cd9bd6b /firmware/target/mips/ingenic_x1000/kernel-x1000.c
parent83fcbedc65f4b9ae7e491ecf6f07c0af4b245f74 (diff)
downloadrockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.tar.gz
rockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.zip
New port: FiiO M3K on bare metal
Change-Id: I7517e7d5459e129dcfc9465c6fbd708619888fbe
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/kernel-x1000.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/kernel-x1000.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/kernel-x1000.c b/firmware/target/mips/ingenic_x1000/kernel-x1000.c
new file mode 100644
index 0000000000..c8105a3446
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/kernel-x1000.c
@@ -0,0 +1,74 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "kernel.h"
23#include "system.h"
24#include "x1000/ost.h"
25
26/* TODO: implement a CPU frequency switching policy based on CPU utilization
27 *
28 * The basic assumption is that the workload consumes a fixed number of CPU
29 * cycles per second on average (= utilization), so we can set the frequency
30 * based on that value. Audio playback should fit this usage pattern well, so
31 * it's a good fit for Rockbox.
32 *
33 * It's easier to understand in terms of fluid flow -- we need to keep
34 * a reservoir of water topped up, CPU frequency is the inflow rate, and
35 * CPU utilization is the outflow rate. The goal is to avoid running dry
36 * and minimize the inflow rate.
37 *
38 * The only tricky part here is handing usage spikes -- CPU frequency has to
39 * increase faster than utilization or there's a risk of audio dropouts.
40 *
41 * Rockbox CPU boost could be used as a hint to scale up frequency faster.
42 * If that's not necessary to get good results, HAVE_ADJUSTABLE_CPU_FREQ can
43 * be disabled entirely.
44 */
45
46#define CPU_IDLE_SAMPLES 100
47
48void tick_start(unsigned interval_in_ms)
49{
50 jz_writef(OST_CTRL, PRESCALE1_V(BY_16));
51 jz_write(OST_1DFR, interval_in_ms*(X1000_EXCLK_FREQ/16000));
52 jz_write(OST_1CNT, 0);
53 jz_write(OST_1FLG, 0);
54 jz_write(OST_1MSK, 0);
55 jz_setf(OST_ENABLE, OST1);
56}
57
58void OST(void)
59{
60 /* CPU idle time accounting */
61 uint32_t now = __ost_read32();
62 uint32_t div = now - __cpu_idle_reftick;
63 if(div != 0) {
64 uint32_t fraction = 1000 * __cpu_idle_ticks / div;
65 __cpu_idle_avg += fraction - __cpu_idle_avg / CPU_IDLE_SAMPLES;
66 __cpu_idle_cur = __cpu_idle_avg / CPU_IDLE_SAMPLES;
67 __cpu_idle_ticks = 0;
68 __cpu_idle_reftick = now;
69 }
70
71 /* Call regular kernel tick */
72 jz_write(OST_1FLG, 0);
73 call_tick_tasks();
74}