blob: 05b83646c2d573350a850bdec045eb4c54dc92cb [file] [log] [blame]
Sudip Mukherjee81dee672015-03-03 16:21:06 +05301
2#include "ddk750_help.h"
3#include "ddk750_reg.h"
4#include "ddk750_mode.h"
5#include "ddk750_chip.h"
6
Elizabeth Ferdman35e4d8c2016-09-28 14:33:51 -07007/* SM750LE only:
8 * This function takes care extra registers and bit fields required to set
9 * up a mode in SM750LE
10 *
11 * Explanation about Display Control register:
12 * HW only supports 7 predefined pixel clocks, and clock select is
13 * in bit 29:27 of Display Control register.
14 */
Sudip Mukherjee81dee672015-03-03 16:21:06 +053015static unsigned long displayControlAdjust_SM750LE(mode_parameter_t *pModeParam, unsigned long dispControl)
16{
17 unsigned long x, y;
18
19 x = pModeParam->horizontal_display_end;
20 y = pModeParam->vertical_display_end;
21
Juston Li78376532015-07-14 21:14:30 -070022 /* SM750LE has to set up the top-left and bottom-right
Elizabeth Ferdman35e4d8c2016-09-28 14:33:51 -070023 * registers as well.
24 * Note that normal SM750/SM718 only use those two register for
25 * auto-centering mode.
Juston Li78376532015-07-14 21:14:30 -070026 */
Mike Rapoport85943da2016-02-15 19:53:45 +020027 POKE32(CRT_AUTO_CENTERING_TL, 0);
Sudip Mukherjee81dee672015-03-03 16:21:06 +053028
Juston Li78376532015-07-14 21:14:30 -070029 POKE32(CRT_AUTO_CENTERING_BR,
Mike Rapoportaed4b782016-02-15 19:53:46 +020030 (((y - 1) << CRT_AUTO_CENTERING_BR_BOTTOM_SHIFT) &
31 CRT_AUTO_CENTERING_BR_BOTTOM_MASK) |
32 ((x - 1) & CRT_AUTO_CENTERING_BR_RIGHT_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +053033
Juston Li78376532015-07-14 21:14:30 -070034 /* Assume common fields in dispControl have been properly set before
Elizabeth Ferdman35e4d8c2016-09-28 14:33:51 -070035 * calling this function.
36 * This function only sets the extra fields in dispControl.
Juston Li78376532015-07-14 21:14:30 -070037 */
Sudip Mukherjee81dee672015-03-03 16:21:06 +053038
39 /* Clear bit 29:27 of display control register */
Mike Rapoportcdce1f12016-02-10 18:34:19 +020040 dispControl &= ~CRT_DISPLAY_CTRL_CLK_MASK;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053041
42 /* Set bit 29:27 of display control register for the right clock */
Matej Vasekfbb8c962016-01-25 16:02:33 +010043 /* Note that SM750LE only need to supported 7 resolutions. */
Juston Li8332d942015-07-14 21:14:32 -070044 if (x == 800 && y == 600)
Mike Rapoportcdce1f12016-02-10 18:34:19 +020045 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL41;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053046 else if (x == 1024 && y == 768)
Mike Rapoportcdce1f12016-02-10 18:34:19 +020047 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL65;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053048 else if (x == 1152 && y == 864)
Mike Rapoportcdce1f12016-02-10 18:34:19 +020049 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL80;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053050 else if (x == 1280 && y == 768)
Mike Rapoportcdce1f12016-02-10 18:34:19 +020051 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL80;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053052 else if (x == 1280 && y == 720)
Mike Rapoportcdce1f12016-02-10 18:34:19 +020053 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL74;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053054 else if (x == 1280 && y == 960)
Mike Rapoportcdce1f12016-02-10 18:34:19 +020055 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL108;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053056 else if (x == 1280 && y == 1024)
Mike Rapoportcdce1f12016-02-10 18:34:19 +020057 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL108;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053058 else /* default to VGA clock */
Mike Rapoportcdce1f12016-02-10 18:34:19 +020059 dispControl |= CRT_DISPLAY_CTRL_CLK_PLL25;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053060
61 /* Set bit 25:24 of display controller */
Mike Rapoportd8264ed2016-02-10 18:34:18 +020062 dispControl |= (CRT_DISPLAY_CTRL_CRTSELECT | CRT_DISPLAY_CTRL_RGBBIT);
Sudip Mukherjee81dee672015-03-03 16:21:06 +053063
Juston Li78376532015-07-14 21:14:30 -070064 /* Set bit 14 of display controller */
Phil Turnbull992f9612016-09-02 15:35:31 -040065 dispControl |= DISPLAY_CTRL_CLOCK_PHASE;
Sudip Mukherjee81dee672015-03-03 16:21:06 +053066
Juston Li78376532015-07-14 21:14:30 -070067 POKE32(CRT_DISPLAY_CTRL, dispControl);
Sudip Mukherjee81dee672015-03-03 16:21:06 +053068
69 return dispControl;
70}
71
72
73
74/* only timing related registers will be programed */
Greg Donaldeb0f4272015-06-18 15:06:56 -050075static int programModeRegisters(mode_parameter_t *pModeParam, pll_value_t *pll)
Sudip Mukherjee81dee672015-03-03 16:21:06 +053076{
77 int ret = 0;
78 int cnt = 0;
Mike Rapoportc436e6b2016-02-10 18:34:02 +020079 unsigned int tmp, reg;
Juston Li40403c12015-07-14 21:14:48 -070080
Juston Li259fef32015-07-14 21:14:45 -070081 if (pll->clockType == SECONDARY_PLL) {
Sudip Mukherjee81dee672015-03-03 16:21:06 +053082 /* programe secondary pixel clock */
Isaac Assegai195d2b62015-06-02 03:14:29 -070083 POKE32(CRT_PLL_CTRL, formatPllReg(pll));
Juston Li78376532015-07-14 21:14:30 -070084 POKE32(CRT_HORIZONTAL_TOTAL,
Mike Rapoport32849f82016-02-15 19:53:47 +020085 (((pModeParam->horizontal_total - 1) <<
86 CRT_HORIZONTAL_TOTAL_TOTAL_SHIFT) &
87 CRT_HORIZONTAL_TOTAL_TOTAL_MASK) |
88 ((pModeParam->horizontal_display_end - 1) &
89 CRT_HORIZONTAL_TOTAL_DISPLAY_END_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +053090
Juston Li78376532015-07-14 21:14:30 -070091 POKE32(CRT_HORIZONTAL_SYNC,
Mike Rapoport1adb3c22016-02-15 19:53:48 +020092 ((pModeParam->horizontal_sync_width <<
93 CRT_HORIZONTAL_SYNC_WIDTH_SHIFT) &
94 CRT_HORIZONTAL_SYNC_WIDTH_MASK) |
95 ((pModeParam->horizontal_sync_start - 1) &
96 CRT_HORIZONTAL_SYNC_START_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +053097
Juston Li78376532015-07-14 21:14:30 -070098 POKE32(CRT_VERTICAL_TOTAL,
Mike Rapoport3d5158d2016-02-15 19:53:49 +020099 (((pModeParam->vertical_total - 1) <<
100 CRT_VERTICAL_TOTAL_TOTAL_SHIFT) &
101 CRT_VERTICAL_TOTAL_TOTAL_MASK) |
102 ((pModeParam->vertical_display_end - 1) &
103 CRT_VERTICAL_TOTAL_DISPLAY_END_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530104
Juston Li78376532015-07-14 21:14:30 -0700105 POKE32(CRT_VERTICAL_SYNC,
Mike Rapoport620c3912016-02-15 19:53:50 +0200106 ((pModeParam->vertical_sync_height <<
107 CRT_VERTICAL_SYNC_HEIGHT_SHIFT) &
108 CRT_VERTICAL_SYNC_HEIGHT_MASK) |
109 ((pModeParam->vertical_sync_start - 1) &
110 CRT_VERTICAL_SYNC_START_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530111
112
Mike Rapoport6fba39c2016-02-10 18:34:08 +0200113 tmp = DISPLAY_CTRL_TIMING | DISPLAY_CTRL_PLANE;
114 if (pModeParam->vertical_sync_polarity)
115 tmp |= DISPLAY_CTRL_VSYNC_PHASE;
116 if (pModeParam->horizontal_sync_polarity)
117 tmp |= DISPLAY_CTRL_HSYNC_PHASE;
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530118
Moshe Green06a4f422016-09-25 22:58:35 +0300119 if (sm750_get_chip_type() == SM750LE) {
Mike Rapoportc436e6b2016-02-10 18:34:02 +0200120 displayControlAdjust_SM750LE(pModeParam, tmp);
Juston Li6338a7812015-07-14 21:14:36 -0700121 } else {
Mike Rapoport6fba39c2016-02-10 18:34:08 +0200122 reg = PEEK32(CRT_DISPLAY_CTRL) &
123 ~(DISPLAY_CTRL_VSYNC_PHASE |
124 DISPLAY_CTRL_HSYNC_PHASE |
125 DISPLAY_CTRL_TIMING | DISPLAY_CTRL_PLANE);
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530126
Mike Rapoportc436e6b2016-02-10 18:34:02 +0200127 POKE32(CRT_DISPLAY_CTRL, tmp | reg);
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530128 }
129
Juston Li259fef32015-07-14 21:14:45 -0700130 } else if (pll->clockType == PRIMARY_PLL) {
Mike Rapoportc436e6b2016-02-10 18:34:02 +0200131 unsigned int reserved;
Juston Li40403c12015-07-14 21:14:48 -0700132
Isaac Assegai195d2b62015-06-02 03:14:29 -0700133 POKE32(PANEL_PLL_CTRL, formatPllReg(pll));
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530134
Mike Rapoport60112062016-02-10 18:34:22 +0200135 reg = ((pModeParam->horizontal_total - 1) <<
136 PANEL_HORIZONTAL_TOTAL_TOTAL_SHIFT) &
137 PANEL_HORIZONTAL_TOTAL_TOTAL_MASK;
138 reg |= ((pModeParam->horizontal_display_end - 1) &
139 PANEL_HORIZONTAL_TOTAL_DISPLAY_END_MASK);
140 POKE32(PANEL_HORIZONTAL_TOTAL, reg);
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530141
Juston Li78376532015-07-14 21:14:30 -0700142 POKE32(PANEL_HORIZONTAL_SYNC,
Mike Rapoporta6f17bc2016-02-15 19:53:51 +0200143 ((pModeParam->horizontal_sync_width <<
144 PANEL_HORIZONTAL_SYNC_WIDTH_SHIFT) &
145 PANEL_HORIZONTAL_SYNC_WIDTH_MASK) |
146 ((pModeParam->horizontal_sync_start - 1) &
147 PANEL_HORIZONTAL_SYNC_START_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530148
Juston Li78376532015-07-14 21:14:30 -0700149 POKE32(PANEL_VERTICAL_TOTAL,
Mike Rapoport6014a312016-02-15 19:53:52 +0200150 (((pModeParam->vertical_total - 1) <<
151 PANEL_VERTICAL_TOTAL_TOTAL_SHIFT) &
152 PANEL_VERTICAL_TOTAL_TOTAL_MASK) |
153 ((pModeParam->vertical_display_end - 1) &
154 PANEL_VERTICAL_TOTAL_DISPLAY_END_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530155
Juston Li78376532015-07-14 21:14:30 -0700156 POKE32(PANEL_VERTICAL_SYNC,
Mike Rapoport8ffe4612016-02-15 19:53:53 +0200157 ((pModeParam->vertical_sync_height <<
158 PANEL_VERTICAL_SYNC_HEIGHT_SHIFT) &
159 PANEL_VERTICAL_SYNC_HEIGHT_MASK) |
160 ((pModeParam->vertical_sync_start - 1) &
161 PANEL_VERTICAL_SYNC_START_MASK));
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530162
Mike Rapoport6fba39c2016-02-10 18:34:08 +0200163 tmp = DISPLAY_CTRL_TIMING | DISPLAY_CTRL_PLANE;
164 if (pModeParam->vertical_sync_polarity)
165 tmp |= DISPLAY_CTRL_VSYNC_PHASE;
166 if (pModeParam->horizontal_sync_polarity)
167 tmp |= DISPLAY_CTRL_HSYNC_PHASE;
168 if (pModeParam->clock_phase_polarity)
169 tmp |= DISPLAY_CTRL_CLOCK_PHASE;
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530170
Mike Rapoport9bd2c862016-02-10 18:34:05 +0200171 reserved = PANEL_DISPLAY_CTRL_RESERVED_MASK |
Mike Rapoport6fba39c2016-02-10 18:34:08 +0200172 PANEL_DISPLAY_CTRL_VSYNC;
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530173
Mike Rapoport6fba39c2016-02-10 18:34:08 +0200174 reg = (PEEK32(PANEL_DISPLAY_CTRL) & ~reserved) &
175 ~(DISPLAY_CTRL_CLOCK_PHASE | DISPLAY_CTRL_VSYNC_PHASE |
176 DISPLAY_CTRL_HSYNC_PHASE | DISPLAY_CTRL_TIMING |
177 DISPLAY_CTRL_PLANE);
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530178
179 /* May a hardware bug or just my test chip (not confirmed).
180 * PANEL_DISPLAY_CTRL register seems requiring few writes
Carlos E. Garcia69e98df2015-04-24 09:40:42 -0400181 * before a value can be successfully written in.
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530182 * Added some masks to mask out the reserved bits.
183 * Note: This problem happens by design. The hardware will wait for the
184 * next vertical sync to turn on/off the plane.
185 */
186
Mike Rapoportc436e6b2016-02-10 18:34:02 +0200187 POKE32(PANEL_DISPLAY_CTRL, tmp | reg);
Mike Rapoportcfac7d62015-10-22 09:38:39 +0300188
Mike Rapoportc436e6b2016-02-10 18:34:02 +0200189 while ((PEEK32(PANEL_DISPLAY_CTRL) & ~reserved) !=
190 (tmp | reg)) {
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530191 cnt++;
Juston Li9ccc5f42015-07-14 21:14:33 -0700192 if (cnt > 1000)
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530193 break;
Mike Rapoportc436e6b2016-02-10 18:34:02 +0200194 POKE32(PANEL_DISPLAY_CTRL, tmp | reg);
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530195 }
Juston Li259fef32015-07-14 21:14:45 -0700196 } else {
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530197 ret = -1;
198 }
199 return ret;
200}
201
Greg Donaldeb0f4272015-06-18 15:06:56 -0500202int ddk750_setModeTiming(mode_parameter_t *parm, clock_type_t clock)
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530203{
204 pll_value_t pll;
205 unsigned int uiActualPixelClk;
Juston Li40403c12015-07-14 21:14:48 -0700206
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530207 pll.inputFreq = DEFAULT_INPUT_CLOCK;
208 pll.clockType = clock;
209
Isaac Assegai195d2b62015-06-02 03:14:29 -0700210 uiActualPixelClk = calcPllValue(parm->pixel_clock, &pll);
Moshe Green06a4f422016-09-25 22:58:35 +0300211 if (sm750_get_chip_type() == SM750LE) {
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530212 /* set graphic mode via IO method */
Isaac Assegai195d2b62015-06-02 03:14:29 -0700213 outb_p(0x88, 0x3d4);
214 outb_p(0x06, 0x3d5);
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530215 }
Isaac Assegai195d2b62015-06-02 03:14:29 -0700216 programModeRegisters(parm, &pll);
Sudip Mukherjee81dee672015-03-03 16:21:06 +0530217 return 0;
218}
219
220