5 * Copyright (C) 2010-2011 Scott Smith
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 CSystem::CSystem() : CBase()
27 #if defined(GP2X) || defined(WIZ) || defined(CAANOO)
28 memdev = open( "/dev/mem", O_RDWR );
31 Log( "Could not open /dev/mem\n" );
35 memregs = (uint32_t*)mmap( 0, MMAP_ADDRESS, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000 );
37 if (memregs == MAP_FAILED)
39 Log( "Could not mmap hardware registers!\n" );
48 #if defined(GP2X) || defined(WIZ) || defined(CAANOO)
57 void CSystem::SetCPUClock( uint16_t& mhz )
60 if (mhz == 0 || mhz > CPU_CLOCK_MAX)
62 Log( "CPU mhz out of range, resetting to default. Value is now %d and allowed values should be between 0 and %d Mhz.\n", mhz, CPU_CLOCK_MAX );
67 string command = "/usr/bin/sudo cpuset " + i_to_a(mhz);
68 execlp( command.c_str(), command.c_str(), NULL, NULL, NULL );
70 #elif defined(WIZ) || defined(CAANOO)
71 if (memdev != 0 && memregs != 0)
73 volatile uint32_t *memregl = static_cast<volatile uint32_t*>((volatile void*)memregs);
74 uint32_t mdiv, pdiv = 9, sdiv = 0;
77 mdiv = (mhz * pdiv) / SYS_CLK_FREQ;
78 if (mdiv & ~0x3ff) return;
79 v = pdiv<<18 | mdiv<<8 | sdiv;
83 for (int i = 0; (PWRMODE & 0x8000) && i < 0x100000; i++);
87 if (memdev != 0 && memregs != 0)
90 uint32_t mdiv, pdiv=3, scale=0;
93 mdiv = (mhz * pdiv) / SYS_CLK_FREQ;
94 mdiv = ((mdiv-8)<<8) & 0xff00;
95 pdiv = ((pdiv-2)<<2) & 0xfc;
97 v = mdiv | pdiv | scale;
98 MEM_REG[0x910>>1] = v;
102 Log( "Setting CPU Clock not supported on this machine.\n" );