]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/sm750fb/ddk750_power.c
staging: sm750fb: use BIT macro for POWER_MODE_CTRL single-bit fields
[karo-tx-linux.git] / drivers / staging / sm750fb / ddk750_power.c
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;
8
9         if (getChipType() == SM750LE) {
10                 value = PEEK32(CRT_DISPLAY_CTRL);
11                 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(value, CRT_DISPLAY_CTRL,
12                                                      DPMS, state));
13         } else {
14                 value = PEEK32(SYSTEM_CTRL);
15                 value = (value & ~SYSTEM_CTRL_DPMS_MASK) | state;
16                 POKE32(SYSTEM_CTRL, value);
17         }
18 }
19
20 static unsigned int getPowerMode(void)
21 {
22         if (getChipType() == SM750LE)
23                 return 0;
24         return FIELD_GET(PEEK32(POWER_MODE_CTRL), POWER_MODE_CTRL, MODE);
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 {
34         unsigned int control_value = 0;
35
36         control_value = PEEK32(POWER_MODE_CTRL);
37
38         if (getChipType() == SM750LE)
39                 return;
40
41         switch (powerMode) {
42         case POWER_MODE_CTRL_MODE_MODE0:
43                 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE,
44                                           MODE0);
45                 break;
46
47         case POWER_MODE_CTRL_MODE_MODE1:
48                 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE,
49                                           MODE1);
50                 break;
51
52         case POWER_MODE_CTRL_MODE_SLEEP:
53                 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE,
54                                           SLEEP);
55                 break;
56
57         default:
58                 break;
59         }
60
61         /* Set up other fields in Power Control Register */
62         if (powerMode == POWER_MODE_CTRL_MODE_SLEEP) {
63                 control_value &= ~POWER_MODE_CTRL_OSC_INPUT;
64 #ifdef VALIDATION_CHIP
65                 control_value &= ~POWER_MODE_CTRL_336CLK;
66 #endif
67         } else {
68                 control_value |= POWER_MODE_CTRL_OSC_INPUT;
69 #ifdef VALIDATION_CHIP
70                 control_value |= POWER_MODE_CTRL_336CLK;
71 #endif
72         }
73
74         /* Program new power mode. */
75         POKE32(POWER_MODE_CTRL, control_value);
76 }
77
78 void setCurrentGate(unsigned int gate)
79 {
80         unsigned int gate_reg;
81         unsigned int mode;
82
83         /* Get current power mode. */
84         mode = getPowerMode();
85
86         switch (mode) {
87         case POWER_MODE_CTRL_MODE_MODE0:
88                 gate_reg = MODE0_GATE;
89                 break;
90
91         case POWER_MODE_CTRL_MODE_MODE1:
92                 gate_reg = MODE1_GATE;
93                 break;
94
95         default:
96                 gate_reg = MODE0_GATE;
97                 break;
98         }
99         POKE32(gate_reg, gate);
100 }
101
102
103
104 /*
105  * This function enable/disable the 2D engine.
106  */
107 void enable2DEngine(unsigned int enable)
108 {
109         u32 gate;
110
111         gate = PEEK32(CURRENT_GATE);
112         if (enable) {
113                 gate |= (CURRENT_GATE_DE | CURRENT_GATE_CSC);
114         } else {
115                 gate &= ~(CURRENT_GATE_DE | CURRENT_GATE_CSC);
116         }
117
118         setCurrentGate(gate);
119 }
120
121 void enableDMA(unsigned int enable)
122 {
123         u32 gate;
124
125         /* Enable DMA Gate */
126         gate = PEEK32(CURRENT_GATE);
127         if (enable)
128                 gate |= CURRENT_GATE_DMA;
129         else
130                 gate &= ~CURRENT_GATE_DMA;
131
132         setCurrentGate(gate);
133 }
134
135 /*
136  * This function enable/disable the GPIO Engine
137  */
138 void enableGPIO(unsigned int enable)
139 {
140         u32 gate;
141
142         /* Enable GPIO Gate */
143         gate = PEEK32(CURRENT_GATE);
144         if (enable)
145                 gate |= CURRENT_GATE_GPIO;
146         else
147                 gate &= ~CURRENT_GATE_GPIO;
148
149         setCurrentGate(gate);
150 }
151
152 /*
153  * This function enable/disable the I2C Engine
154  */
155 void enableI2C(unsigned int enable)
156 {
157         u32 gate;
158
159         /* Enable I2C Gate */
160         gate = PEEK32(CURRENT_GATE);
161         if (enable)
162                 gate |= CURRENT_GATE_I2C;
163         else
164                 gate &= ~CURRENT_GATE_I2C;
165
166         setCurrentGate(gate);
167 }
168
169