• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 #include "ddk750_chip.h"
3 #include "ddk750_reg.h"
4 #include "ddk750_power.h"
5 
ddk750_set_dpms(enum dpms state)6 void ddk750_set_dpms(enum dpms state)
7 {
8 	unsigned int value;
9 
10 	if (sm750_get_chip_type() == SM750LE) {
11 		value = peek32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_DPMS_MASK;
12 		value |= (state << CRT_DISPLAY_CTRL_DPMS_SHIFT);
13 		poke32(CRT_DISPLAY_CTRL, value);
14 	} else {
15 		value = peek32(SYSTEM_CTRL);
16 		value = (value & ~SYSTEM_CTRL_DPMS_MASK) | state;
17 		poke32(SYSTEM_CTRL, value);
18 	}
19 }
20 
get_power_mode(void)21 static unsigned int get_power_mode(void)
22 {
23 	if (sm750_get_chip_type() == SM750LE)
24 		return 0;
25 	return peek32(POWER_MODE_CTRL) & POWER_MODE_CTRL_MODE_MASK;
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  */
sm750_set_power_mode(unsigned int mode)32 void sm750_set_power_mode(unsigned int mode)
33 {
34 	unsigned int ctrl = 0;
35 
36 	ctrl = peek32(POWER_MODE_CTRL) & ~POWER_MODE_CTRL_MODE_MASK;
37 
38 	if (sm750_get_chip_type() == SM750LE)
39 		return;
40 
41 	switch (mode) {
42 	case POWER_MODE_CTRL_MODE_MODE0:
43 		ctrl |= POWER_MODE_CTRL_MODE_MODE0;
44 		break;
45 
46 	case POWER_MODE_CTRL_MODE_MODE1:
47 		ctrl |= POWER_MODE_CTRL_MODE_MODE1;
48 		break;
49 
50 	case POWER_MODE_CTRL_MODE_SLEEP:
51 		ctrl |= POWER_MODE_CTRL_MODE_SLEEP;
52 		break;
53 
54 	default:
55 		break;
56 	}
57 
58 	/* Set up other fields in Power Control Register */
59 	if (mode == POWER_MODE_CTRL_MODE_SLEEP) {
60 		ctrl &= ~POWER_MODE_CTRL_OSC_INPUT;
61 #ifdef VALIDATION_CHIP
62 		ctrl &= ~POWER_MODE_CTRL_336CLK;
63 #endif
64 	} else {
65 		ctrl |= POWER_MODE_CTRL_OSC_INPUT;
66 #ifdef VALIDATION_CHIP
67 		ctrl |= POWER_MODE_CTRL_336CLK;
68 #endif
69 	}
70 
71 	/* Program new power mode. */
72 	poke32(POWER_MODE_CTRL, ctrl);
73 }
74 
sm750_set_current_gate(unsigned int gate)75 void sm750_set_current_gate(unsigned int gate)
76 {
77 	if (get_power_mode() == POWER_MODE_CTRL_MODE_MODE1)
78 		poke32(MODE1_GATE, gate);
79 	else
80 		poke32(MODE0_GATE, gate);
81 }
82 
83 /*
84  * This function enable/disable the 2D engine.
85  */
sm750_enable_2d_engine(unsigned int enable)86 void sm750_enable_2d_engine(unsigned int enable)
87 {
88 	u32 gate;
89 
90 	gate = peek32(CURRENT_GATE);
91 	if (enable)
92 		gate |= (CURRENT_GATE_DE | CURRENT_GATE_CSC);
93 	else
94 		gate &= ~(CURRENT_GATE_DE | CURRENT_GATE_CSC);
95 
96 	sm750_set_current_gate(gate);
97 }
98 
sm750_enable_dma(unsigned int enable)99 void sm750_enable_dma(unsigned int enable)
100 {
101 	u32 gate;
102 
103 	/* Enable DMA Gate */
104 	gate = peek32(CURRENT_GATE);
105 	if (enable)
106 		gate |= CURRENT_GATE_DMA;
107 	else
108 		gate &= ~CURRENT_GATE_DMA;
109 
110 	sm750_set_current_gate(gate);
111 }
112 
113 /*
114  * This function enable/disable the GPIO Engine
115  */
sm750_enable_gpio(unsigned int enable)116 void sm750_enable_gpio(unsigned int enable)
117 {
118 	u32 gate;
119 
120 	/* Enable GPIO Gate */
121 	gate = peek32(CURRENT_GATE);
122 	if (enable)
123 		gate |= CURRENT_GATE_GPIO;
124 	else
125 		gate &= ~CURRENT_GATE_GPIO;
126 
127 	sm750_set_current_gate(gate);
128 }
129 
130 /*
131  * This function enable/disable the I2C Engine
132  */
sm750_enable_i2c(unsigned int enable)133 void sm750_enable_i2c(unsigned int enable)
134 {
135 	u32 gate;
136 
137 	/* Enable I2C Gate */
138 	gate = peek32(CURRENT_GATE);
139 	if (enable)
140 		gate |= CURRENT_GATE_I2C;
141 	else
142 		gate &= ~CURRENT_GATE_I2C;
143 
144 	sm750_set_current_gate(gate);
145 }
146