1#include "ddk750_help.h" 2#include "ddk750_reg.h" 3#include "ddk750_power.h" 4 5void ddk750_setDPMS(DPMS_t state) 6{ 7 unsigned int value; 8 if(getChipType() == SM750LE){ 9 value = PEEK32(CRT_DISPLAY_CTRL); 10 POKE32(CRT_DISPLAY_CTRL,FIELD_VALUE(value,CRT_DISPLAY_CTRL,DPMS,state)); 11 }else{ 12 value = PEEK32(SYSTEM_CTRL); 13 value= FIELD_VALUE(value,SYSTEM_CTRL,DPMS,state); 14 POKE32(SYSTEM_CTRL, value); 15 } 16} 17 18unsigned int getPowerMode(void) 19{ 20 if(getChipType() == SM750LE) 21 return 0; 22 return (FIELD_GET(PEEK32(POWER_MODE_CTRL), POWER_MODE_CTRL, MODE)); 23} 24 25 26/* 27 * SM50x can operate in one of three modes: 0, 1 or Sleep. 28 * On hardware reset, power mode 0 is default. 29 */ 30void setPowerMode(unsigned int powerMode) 31{ 32 unsigned int control_value = 0; 33 34 control_value = PEEK32(POWER_MODE_CTRL); 35 36 if(getChipType() == SM750LE) 37 return; 38 39 switch (powerMode) 40 { 41 case POWER_MODE_CTRL_MODE_MODE0: 42 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, MODE0); 43 break; 44 45 case POWER_MODE_CTRL_MODE_MODE1: 46 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, MODE1); 47 break; 48 49 case POWER_MODE_CTRL_MODE_SLEEP: 50 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, SLEEP); 51 break; 52 53 default: 54 break; 55 } 56 57 /* Set up other fields in Power Control Register */ 58 if (powerMode == POWER_MODE_CTRL_MODE_SLEEP) 59 { 60 control_value = 61#ifdef VALIDATION_CHIP 62 FIELD_SET( control_value, POWER_MODE_CTRL, 336CLK, OFF) | 63#endif 64 FIELD_SET( control_value, POWER_MODE_CTRL, OSC_INPUT, OFF); 65 } 66 else 67 { 68 control_value = 69#ifdef VALIDATION_CHIP 70 FIELD_SET( control_value, POWER_MODE_CTRL, 336CLK, ON) | 71#endif 72 FIELD_SET( control_value, POWER_MODE_CTRL, OSC_INPUT, ON); 73 } 74 75 /* Program new power mode. */ 76 POKE32(POWER_MODE_CTRL, control_value); 77} 78 79void setCurrentGate(unsigned int gate) 80{ 81 unsigned int gate_reg; 82 unsigned int mode; 83 84 /* Get current power mode. */ 85 mode = getPowerMode(); 86 87 switch (mode) 88 { 89 case POWER_MODE_CTRL_MODE_MODE0: 90 gate_reg = MODE0_GATE; 91 break; 92 93 case POWER_MODE_CTRL_MODE_MODE1: 94 gate_reg = MODE1_GATE; 95 break; 96 97 default: 98 gate_reg = MODE0_GATE; 99 break; 100 } 101 POKE32(gate_reg, gate); 102} 103 104 105 106/* 107 * This function enable/disable the 2D engine. 108 */ 109void enable2DEngine(unsigned int enable) 110{ 111 uint32_t gate; 112 113 gate = PEEK32(CURRENT_GATE); 114 if (enable) 115 { 116 gate = FIELD_SET(gate, CURRENT_GATE, DE, ON); 117 gate = FIELD_SET(gate, CURRENT_GATE, CSC, ON); 118 } 119 else 120 { 121 gate = FIELD_SET(gate, CURRENT_GATE, DE, OFF); 122 gate = FIELD_SET(gate, CURRENT_GATE, CSC, OFF); 123 } 124 125 setCurrentGate(gate); 126} 127 128 129/* 130 * This function enable/disable the ZV Port. 131 */ 132void enableZVPort(unsigned int enable) 133{ 134 uint32_t gate; 135 136 /* Enable ZV Port Gate */ 137 gate = PEEK32(CURRENT_GATE); 138 if (enable) 139 { 140 gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, ON); 141#if 1 142 /* Using Software I2C */ 143 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON); 144#else 145 /* Using Hardware I2C */ 146 gate = FIELD_SET(gate, CURRENT_GATE, I2C, ON); 147#endif 148 } 149 else 150 { 151 /* Disable ZV Port Gate. There is no way to know whether the GPIO pins are being used 152 or not. Therefore, do not disable the GPIO gate. */ 153 gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, OFF); 154 } 155 156 setCurrentGate(gate); 157} 158 159 160void enableSSP(unsigned int enable) 161{ 162 uint32_t gate; 163 164 /* Enable SSP Gate */ 165 gate = PEEK32(CURRENT_GATE); 166 if (enable) 167 gate = FIELD_SET(gate, CURRENT_GATE, SSP, ON); 168 else 169 gate = FIELD_SET(gate, CURRENT_GATE, SSP, OFF); 170 171 setCurrentGate(gate); 172} 173 174void enableDMA(unsigned int enable) 175{ 176 uint32_t gate; 177 178 /* Enable DMA Gate */ 179 gate = PEEK32(CURRENT_GATE); 180 if (enable) 181 gate = FIELD_SET(gate, CURRENT_GATE, DMA, ON); 182 else 183 gate = FIELD_SET(gate, CURRENT_GATE, DMA, OFF); 184 185 setCurrentGate(gate); 186} 187 188/* 189 * This function enable/disable the GPIO Engine 190 */ 191void enableGPIO(unsigned int enable) 192{ 193 uint32_t gate; 194 195 /* Enable GPIO Gate */ 196 gate = PEEK32(CURRENT_GATE); 197 if (enable) 198 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON); 199 else 200 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, OFF); 201 202 setCurrentGate(gate); 203} 204 205/* 206 * This function enable/disable the PWM Engine 207 */ 208void enablePWM(unsigned int enable) 209{ 210 uint32_t gate; 211 212 /* Enable PWM Gate */ 213 gate = PEEK32(CURRENT_GATE); 214 if (enable) 215 gate = FIELD_SET(gate, CURRENT_GATE, PWM, ON); 216 else 217 gate = FIELD_SET(gate, CURRENT_GATE, PWM, OFF); 218 219 setCurrentGate(gate); 220} 221 222/* 223 * This function enable/disable the I2C Engine 224 */ 225void enableI2C(unsigned int enable) 226{ 227 uint32_t gate; 228 229 /* Enable I2C Gate */ 230 gate = PEEK32(CURRENT_GATE); 231 if (enable) 232 gate = FIELD_SET(gate, CURRENT_GATE, I2C, ON); 233 else 234 gate = FIELD_SET(gate, CURRENT_GATE, I2C, OFF); 235 236 setCurrentGate(gate); 237} 238 239 240