Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 1 | #include "ddk750_help.h" |
| 2 | #include "ddk750_reg.h" |
| 3 | #include "ddk750_power.h" |
| 4 | |
| 5 | void ddk750_setDPMS(DPMS_t state) |
| 6 | { |
| 7 | unsigned int value; |
Juston Li | 40403c1 | 2015-07-14 21:14:48 -0700 | [diff] [blame] | 8 | |
Juston Li | 8c11f5a | 2015-07-14 21:14:35 -0700 | [diff] [blame] | 9 | if (getChipType() == SM750LE) { |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 10 | value = PEEK32(CRT_DISPLAY_CTRL); |
Antoine BLIN | 9a2c874 | 2015-07-17 15:04:34 +0200 | [diff] [blame] | 11 | POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(value, CRT_DISPLAY_CTRL, |
| 12 | DPMS, state)); |
Juston Li | 6338a781 | 2015-07-14 21:14:36 -0700 | [diff] [blame] | 13 | } else { |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 14 | value = PEEK32(SYSTEM_CTRL); |
Juston Li | 0d5e63c | 2015-07-14 21:14:41 -0700 | [diff] [blame] | 15 | value = FIELD_VALUE(value, SYSTEM_CTRL, DPMS, state); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 16 | POKE32(SYSTEM_CTRL, value); |
| 17 | } |
| 18 | } |
| 19 | |
Mike Rapoport | 228a4cf8 | 2015-09-30 08:24:58 +0300 | [diff] [blame] | 20 | static unsigned int getPowerMode(void) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 21 | { |
Juston Li | 9ccc5f4 | 2015-07-14 21:14:33 -0700 | [diff] [blame] | 22 | if (getChipType() == SM750LE) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 23 | return 0; |
Aaron Ouellette | 9d7a0ff | 2015-07-16 21:21:16 -0400 | [diff] [blame] | 24 | return FIELD_GET(PEEK32(POWER_MODE_CTRL), POWER_MODE_CTRL, MODE); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * SM50x can operate in one of three modes: 0, 1 or Sleep. |
| 30 | * On hardware reset, power mode 0 is default. |
| 31 | */ |
| 32 | void setPowerMode(unsigned int powerMode) |
| 33 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 34 | unsigned int control_value = 0; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 35 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 36 | control_value = PEEK32(POWER_MODE_CTRL); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 37 | |
Juston Li | 9ccc5f4 | 2015-07-14 21:14:33 -0700 | [diff] [blame] | 38 | if (getChipType() == SM750LE) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 39 | return; |
| 40 | |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 41 | switch (powerMode) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 42 | case POWER_MODE_CTRL_MODE_MODE0: |
Antoine BLIN | 9a2c874 | 2015-07-17 15:04:34 +0200 | [diff] [blame] | 43 | control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, |
| 44 | MODE0); |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 45 | break; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 46 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 47 | case POWER_MODE_CTRL_MODE_MODE1: |
Antoine BLIN | 9a2c874 | 2015-07-17 15:04:34 +0200 | [diff] [blame] | 48 | control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, |
| 49 | MODE1); |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 50 | break; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 51 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 52 | case POWER_MODE_CTRL_MODE_SLEEP: |
Antoine BLIN | 9a2c874 | 2015-07-17 15:04:34 +0200 | [diff] [blame] | 53 | control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, |
| 54 | SLEEP); |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 55 | break; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 56 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 57 | default: |
| 58 | break; |
| 59 | } |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 60 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 61 | /* Set up other fields in Power Control Register */ |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 62 | if (powerMode == POWER_MODE_CTRL_MODE_SLEEP) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 63 | control_value = |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 64 | #ifdef VALIDATION_CHIP |
Juston Li | 7f0ebcc | 2015-07-14 21:14:31 -0700 | [diff] [blame] | 65 | FIELD_SET(control_value, POWER_MODE_CTRL, 336CLK, OFF) | |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 66 | #endif |
Juston Li | 7f0ebcc | 2015-07-14 21:14:31 -0700 | [diff] [blame] | 67 | FIELD_SET(control_value, POWER_MODE_CTRL, OSC_INPUT, OFF); |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 68 | } else { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 69 | control_value = |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 70 | #ifdef VALIDATION_CHIP |
Juston Li | 7f0ebcc | 2015-07-14 21:14:31 -0700 | [diff] [blame] | 71 | FIELD_SET(control_value, POWER_MODE_CTRL, 336CLK, ON) | |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 72 | #endif |
Juston Li | 7f0ebcc | 2015-07-14 21:14:31 -0700 | [diff] [blame] | 73 | FIELD_SET(control_value, POWER_MODE_CTRL, OSC_INPUT, ON); |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 74 | } |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 75 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 76 | /* Program new power mode. */ |
| 77 | POKE32(POWER_MODE_CTRL, control_value); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void setCurrentGate(unsigned int gate) |
| 81 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 82 | unsigned int gate_reg; |
| 83 | unsigned int mode; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 84 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 85 | /* Get current power mode. */ |
| 86 | mode = getPowerMode(); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 87 | |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 88 | switch (mode) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 89 | case POWER_MODE_CTRL_MODE_MODE0: |
| 90 | gate_reg = MODE0_GATE; |
| 91 | break; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 92 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 93 | case POWER_MODE_CTRL_MODE_MODE1: |
| 94 | gate_reg = MODE1_GATE; |
| 95 | break; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 96 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 97 | default: |
| 98 | gate_reg = MODE0_GATE; |
| 99 | break; |
| 100 | } |
| 101 | POKE32(gate_reg, gate); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | |
| 105 | |
| 106 | /* |
| 107 | * This function enable/disable the 2D engine. |
| 108 | */ |
| 109 | void enable2DEngine(unsigned int enable) |
| 110 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 111 | uint32_t gate; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 112 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 113 | gate = PEEK32(CURRENT_GATE); |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 114 | if (enable) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 115 | gate = FIELD_SET(gate, CURRENT_GATE, DE, ON); |
| 116 | gate = FIELD_SET(gate, CURRENT_GATE, CSC, ON); |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 117 | } else { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 118 | gate = FIELD_SET(gate, CURRENT_GATE, DE, OFF); |
| 119 | gate = FIELD_SET(gate, CURRENT_GATE, CSC, OFF); |
| 120 | } |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 121 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 122 | setCurrentGate(gate); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 123 | } |
| 124 | |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 125 | void enableDMA(unsigned int enable) |
| 126 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 127 | uint32_t gate; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 128 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 129 | /* Enable DMA Gate */ |
| 130 | gate = PEEK32(CURRENT_GATE); |
| 131 | if (enable) |
| 132 | gate = FIELD_SET(gate, CURRENT_GATE, DMA, ON); |
| 133 | else |
| 134 | gate = FIELD_SET(gate, CURRENT_GATE, DMA, OFF); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 135 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 136 | setCurrentGate(gate); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* |
| 140 | * This function enable/disable the GPIO Engine |
| 141 | */ |
| 142 | void enableGPIO(unsigned int enable) |
| 143 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 144 | uint32_t gate; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 145 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 146 | /* Enable GPIO Gate */ |
| 147 | gate = PEEK32(CURRENT_GATE); |
| 148 | if (enable) |
| 149 | gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON); |
| 150 | else |
| 151 | gate = FIELD_SET(gate, CURRENT_GATE, GPIO, OFF); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 152 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 153 | setCurrentGate(gate); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 157 | * This function enable/disable the I2C Engine |
| 158 | */ |
| 159 | void enableI2C(unsigned int enable) |
| 160 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 161 | uint32_t gate; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 162 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 163 | /* Enable I2C Gate */ |
| 164 | gate = PEEK32(CURRENT_GATE); |
| 165 | if (enable) |
| 166 | gate = FIELD_SET(gate, CURRENT_GATE, I2C, ON); |
| 167 | else |
| 168 | gate = FIELD_SET(gate, CURRENT_GATE, I2C, OFF); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 169 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 170 | setCurrentGate(gate); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | |