Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "pxa255_PwrClk.h"
  2.  
  3.  
  4. static Boolean pxa255pwrClkPrvCoprocRegXferFunc(struct ArmCpu* cpu, void* userData, Boolean two, Boolean read, UInt8 op1, UInt8 Rx, UInt8 CRn, UInt8 CRm, UInt8 op2){
  5.        
  6.         Pxa255pwrClk* pc = userData;
  7.         UInt32 val = 0;
  8.        
  9.         if(!read) val = cpuGetRegExternal(cpu, Rx);
  10.        
  11.         if(CRm == 0 && op2 == 0 && op1 == 0 && !two){
  12.                
  13.                 switch(CRn){
  14.                        
  15.                         case 6:
  16.                                 if(read) val = 0;
  17.                                 else{
  18.                                         pc->turbo = (val & 1) != 0;
  19.                                         if(val & 2){
  20.                                                
  21.                                                 err_str("Set speed mode");
  22.                                         //      err_str("(CCCR + cp14 reg6) to 0x");
  23.                                         //      err_hex(pc->CCCR);
  24.                                         //      err_str(", 0x");
  25.                                         //      err_hex(val);
  26.                                         //      err_str("\r\n");
  27.                                         }
  28.                                 }
  29.                        
  30.                         case 7:
  31.                                 if(read) val = pc->turbo ? 1 : 0;
  32.                                 else if(val != 0){
  33.                                        
  34.                                 //      fprintf(stderr, "Someone tried to set processor power mode (cp14 reg7) to 0x%08lX\n", val);
  35.                                 }
  36.                                 goto success;
  37.                 }
  38.         }
  39.        
  40.         return false;
  41.  
  42. success:
  43.        
  44.         if(read) cpuSetReg(cpu, Rx, val);
  45.         return true;
  46. }
  47.  
  48. static Boolean pxa255pwrClkPrvClockMgrMemAccessF(void* userData, UInt32 pa, UInt8 size, Boolean write, void* buf){
  49.  
  50.         Pxa255pwrClk* pc = userData;
  51.         UInt32 val = 0;
  52.        
  53.         if(size != 4) {
  54.                 err_str(__FILE__ ": Unexpected ");
  55.         //      err_str(write ? "write" : "read");
  56.         //      err_str(" of ");
  57.         //      err_dec(size);
  58.         //      err_str(" bytes to 0x");
  59.         //      err_hex(pa);
  60.         //      err_str("\r\n");
  61.                 return true;            //we do not support non-word accesses
  62.         }
  63.        
  64.         pa = (pa - PXA255_CLOCK_MANAGER_BASE) >> 2;
  65.        
  66.         if(write) val = *(UInt32*)buf;
  67.        
  68.         switch(pa){
  69.                
  70.                 case 0:         //CCCR
  71.                         if(write) pc->CCCR = val;
  72.                         else val = pc->CCCR;
  73.                         break;
  74.                
  75.                 case 1:         //CKEN
  76.                         if(write) pc->CKEN = val;
  77.                         else val = pc->CKEN;
  78.                         break;
  79.                
  80.                 case 2:         //OSCR
  81.                         if(!write) val = pc->OSCR;
  82.                         //no writing to this register
  83.                         break;
  84.         }
  85.        
  86.         if(!write) *(UInt32*)buf = val;
  87.        
  88.         return true;
  89. }
  90.  
  91. static Boolean pxa255pwrClkPrvPowerMgrMemAccessF(void* userData, UInt32 pa, UInt8 size, Boolean write, void* buf){
  92.  
  93.         Pxa255pwrClk* pc = userData;
  94.         UInt32 val = 0;
  95.        
  96.         if(size != 4) {
  97.                 err_str(__FILE__ ": Unexpected ");
  98.         //      err_str(write ? "write" : "read");
  99.         //      err_str(" of ");
  100.         //      err_dec(size);
  101.         //      err_str(" bytes to 0x");
  102.         //      err_hex(pa);
  103.         //      err_str("\r\n");
  104.                 return true;            //we do not support non-word accesses
  105.         }
  106.        
  107.         pa = (pa - PXA255_POWER_MANAGER_BASE) >> 2;
  108.        
  109.         if(write) val = *(UInt32*)buf;
  110.        
  111.         if(pa < 13){
  112.                
  113.                 if(write) pc->pwrRegs[pa] = val;
  114.                 else val = pc->pwrRegs[pa];    
  115.         }
  116.        
  117.         if(!write) *(UInt32*)buf = val;
  118.        
  119.         return true;
  120. }
  121.  
  122. Boolean pxa255pwrClkInit(Pxa255pwrClk* pc, ArmCpu* cpu, ArmMem* physMem){
  123.        
  124.         ArmCoprocessor cp;
  125.         Boolean ok = true;
  126.        
  127.         __mem_zero(pc, sizeof(Pxa255pwrClk));
  128.        
  129.         pc->cpu = cpu;
  130.         pc->CCCR = 0x00000122UL;        //set CCCR to almost default value (we use mult 32 not 27)
  131.         pc->CKEN = 0x000179EFUL;        //set CKEN to default value
  132.         pc->OSCR = 0x00000003UL;        //32KHz oscillator on and stable
  133.         pc->pwrRegs[1] = 0x20;  //set PSSR
  134.         pc->pwrRegs[3] = 3;     //set PWER
  135.         pc->pwrRegs[4] = 3;     //set PRER
  136.         pc->pwrRegs[5] = 3;     //set PFER
  137.         pc->pwrRegs[12] = 1;    //set RCSR
  138.        
  139.        
  140.         cp.regXfer = pxa255pwrClkPrvCoprocRegXferFunc;
  141.         cp.dataProcessing = NULL;
  142.         cp.memAccess = NULL;
  143.         cp.twoRegF = NULL;
  144.         cp.userData = pc;
  145.        
  146.         cpuCoprocessorRegister(cpu, 14, &cp);
  147.        
  148.         ok = ok && memRegionAdd(physMem, PXA255_CLOCK_MANAGER_BASE, PXA255_CLOCK_MANAGER_SIZE, pxa255pwrClkPrvClockMgrMemAccessF, pc);
  149.         ok = ok && memRegionAdd(physMem, PXA255_POWER_MANAGER_BASE, PXA255_POWER_MANAGER_SIZE, pxa255pwrClkPrvPowerMgrMemAccessF, pc);
  150.        
  151.         return ok;
  152. }
  153.  
  154.  
  155.