aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/ast/ast_main.c')
-rw-r--r--drivers/gpu/drm/ast/ast_main.c171
1 files changed, 119 insertions, 52 deletions
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 9b8f0b975ca6..498a94069e6b 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -62,13 +62,84 @@ uint8_t ast_get_index_reg_mask(struct ast_private *ast,
62 return ret; 62 return ret;
63} 63}
64 64
65static void ast_detect_config_mode(struct drm_device *dev, u32 *scu_rev)
66{
67 struct device_node *np = dev->pdev->dev.of_node;
68 struct ast_private *ast = dev->dev_private;
69 uint32_t data, jregd0, jregd1;
70
71 /* Defaults */
72 ast->config_mode = ast_use_defaults;
73 *scu_rev = 0xffffffff;
74
75 /* Check if we have device-tree properties */
76 if (np && !of_property_read_u32(np, "aspeed,scu-revision-id",
77 scu_rev)) {
78 /* We do, disable P2A access */
79 ast->config_mode = ast_use_dt;
80 DRM_INFO("Using device-tree for configuration\n");
81 return;
82 }
83
84 /* Not all families have a P2A bridge */
85 if (dev->pdev->device != PCI_CHIP_AST2000)
86 return;
87
88 /*
89 * The BMC will set SCU 0x40 D[12] to 1 if the P2 bridge
90 * is disabled. We force using P2A if VGA only mode bit
91 * is set D[7]
92 */
93 jregd0 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
94 jregd1 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff);
95 if (!(jregd0 & 0x80) || !(jregd1 & 0x10)) {
96 /* Double check it's actually working */
97 data = ast_read32(ast, 0xf004);
98 if (data != 0xFFFFFFFF) {
99 /* P2A works, grab silicon revision */
100 ast->config_mode = ast_use_p2a;
101
102 DRM_INFO("Using P2A bridge for configuration\n");
103
104 /* Read SCU7c (silicon revision register) */
105 ast_write32(ast, 0xf004, 0x1e6e0000);
106 ast_write32(ast, 0xf000, 0x1);
107 *scu_rev = ast_read32(ast, 0x1207c);
108 return;
109 }
110 }
111
112 /* We have a P2A bridge but it's disabled */
113 DRM_INFO("P2A bridge disabled, using default configuration\n");
114}
65 115
66static int ast_detect_chip(struct drm_device *dev, bool *need_post) 116static int ast_detect_chip(struct drm_device *dev, bool *need_post)
67{ 117{
68 struct ast_private *ast = dev->dev_private; 118 struct ast_private *ast = dev->dev_private;
69 uint32_t data, jreg; 119 uint32_t jreg, scu_rev;
120
121 /*
122 * If VGA isn't enabled, we need to enable now or subsequent
123 * access to the scratch registers will fail. We also inform
124 * our caller that it needs to POST the chip
125 * (Assumption: VGA not enabled -> need to POST)
126 */
127 if (!ast_is_vga_enabled(dev)) {
128 ast_enable_vga(dev);
129 DRM_INFO("VGA not enabled on entry, requesting chip POST\n");
130 *need_post = true;
131 } else
132 *need_post = false;
133
134
135 /* Enable extended register access */
136 ast_enable_mmio(dev);
70 ast_open_key(ast); 137 ast_open_key(ast);
71 138
139 /* Find out whether P2A works or whether to use device-tree */
140 ast_detect_config_mode(dev, &scu_rev);
141
142 /* Identify chipset */
72 if (dev->pdev->device == PCI_CHIP_AST1180) { 143 if (dev->pdev->device == PCI_CHIP_AST1180) {
73 ast->chip = AST1100; 144 ast->chip = AST1100;
74 DRM_INFO("AST 1180 detected\n"); 145 DRM_INFO("AST 1180 detected\n");
@@ -80,12 +151,7 @@ static int ast_detect_chip(struct drm_device *dev, bool *need_post)
80 ast->chip = AST2300; 151 ast->chip = AST2300;
81 DRM_INFO("AST 2300 detected\n"); 152 DRM_INFO("AST 2300 detected\n");
82 } else if (dev->pdev->revision >= 0x10) { 153 } else if (dev->pdev->revision >= 0x10) {
83 uint32_t data; 154 switch (scu_rev & 0x0300) {
84 ast_write32(ast, 0xf004, 0x1e6e0000);
85 ast_write32(ast, 0xf000, 0x1);
86
87 data = ast_read32(ast, 0x1207c);
88 switch (data & 0x0300) {
89 case 0x0200: 155 case 0x0200:
90 ast->chip = AST1100; 156 ast->chip = AST1100;
91 DRM_INFO("AST 1100 detected\n"); 157 DRM_INFO("AST 1100 detected\n");
@@ -110,20 +176,6 @@ static int ast_detect_chip(struct drm_device *dev, bool *need_post)
110 } 176 }
111 } 177 }
112 178
113 /*
114 * If VGA isn't enabled, we need to enable now or subsequent
115 * access to the scratch registers will fail. We also inform
116 * our caller that it needs to POST the chip
117 * (Assumption: VGA not enabled -> need to POST)
118 */
119 if (!ast_is_vga_enabled(dev)) {
120 ast_enable_vga(dev);
121 ast_enable_mmio(dev);
122 DRM_INFO("VGA not enabled on entry, requesting chip POST\n");
123 *need_post = true;
124 } else
125 *need_post = false;
126
127 /* Check if we support wide screen */ 179 /* Check if we support wide screen */
128 switch (ast->chip) { 180 switch (ast->chip) {
129 case AST1180: 181 case AST1180:
@@ -140,14 +192,11 @@ static int ast_detect_chip(struct drm_device *dev, bool *need_post)
140 ast->support_wide_screen = true; 192 ast->support_wide_screen = true;
141 else { 193 else {
142 ast->support_wide_screen = false; 194 ast->support_wide_screen = false;
143 /* Read SCU7c (silicon revision register) */ 195 if (ast->chip == AST2300 &&
144 ast_write32(ast, 0xf004, 0x1e6e0000); 196 (scu_rev & 0x300) == 0x0) /* ast1300 */
145 ast_write32(ast, 0xf000, 0x1);
146 data = ast_read32(ast, 0x1207c);
147 data &= 0x300;
148 if (ast->chip == AST2300 && data == 0x0) /* ast1300 */
149 ast->support_wide_screen = true; 197 ast->support_wide_screen = true;
150 if (ast->chip == AST2400 && data == 0x100) /* ast1400 */ 198 if (ast->chip == AST2400 &&
199 (scu_rev & 0x300) == 0x100) /* ast1400 */
151 ast->support_wide_screen = true; 200 ast->support_wide_screen = true;
152 } 201 }
153 break; 202 break;
@@ -212,29 +261,49 @@ static int ast_detect_chip(struct drm_device *dev, bool *need_post)
212 261
213static int ast_get_dram_info(struct drm_device *dev) 262static int ast_get_dram_info(struct drm_device *dev)
214{ 263{
264 struct device_node *np = dev->pdev->dev.of_node;
215 struct ast_private *ast = dev->dev_private; 265 struct ast_private *ast = dev->dev_private;
216 uint32_t data, data2; 266 uint32_t mcr_cfg, mcr_scu_mpll, mcr_scu_strap;
217 uint32_t denum, num, div, ref_pll; 267 uint32_t denum, num, div, ref_pll, dsel;
218
219 ast_write32(ast, 0xf004, 0x1e6e0000);
220 ast_write32(ast, 0xf000, 0x1);
221
222
223 ast_write32(ast, 0x10000, 0xfc600309);
224 268
225 do { 269 switch (ast->config_mode) {
226 if (pci_channel_offline(dev->pdev)) 270 case ast_use_dt:
227 return -EIO; 271 /*
228 } while (ast_read32(ast, 0x10000) != 0x01); 272 * If some properties are missing, use reasonable
229 data = ast_read32(ast, 0x10004); 273 * defaults for AST2400
274 */
275 if (of_property_read_u32(np, "aspeed,mcr-configuration",
276 &mcr_cfg))
277 mcr_cfg = 0x00000577;
278 if (of_property_read_u32(np, "aspeed,mcr-scu-mpll",
279 &mcr_scu_mpll))
280 mcr_scu_mpll = 0x000050C0;
281 if (of_property_read_u32(np, "aspeed,mcr-scu-strap",
282 &mcr_scu_strap))
283 mcr_scu_strap = 0;
284 break;
285 case ast_use_p2a:
286 ast_write32(ast, 0xf004, 0x1e6e0000);
287 ast_write32(ast, 0xf000, 0x1);
288 mcr_cfg = ast_read32(ast, 0x10004);
289 mcr_scu_mpll = ast_read32(ast, 0x10120);
290 mcr_scu_strap = ast_read32(ast, 0x10170);
291 break;
292 case ast_use_defaults:
293 default:
294 ast->dram_bus_width = 16;
295 ast->dram_type = AST_DRAM_1Gx16;
296 ast->mclk = 396;
297 return 0;
298 }
230 299
231 if (data & 0x40) 300 if (mcr_cfg & 0x40)
232 ast->dram_bus_width = 16; 301 ast->dram_bus_width = 16;
233 else 302 else
234 ast->dram_bus_width = 32; 303 ast->dram_bus_width = 32;
235 304
236 if (ast->chip == AST2300 || ast->chip == AST2400) { 305 if (ast->chip == AST2300 || ast->chip == AST2400) {
237 switch (data & 0x03) { 306 switch (mcr_cfg & 0x03) {
238 case 0: 307 case 0:
239 ast->dram_type = AST_DRAM_512Mx16; 308 ast->dram_type = AST_DRAM_512Mx16;
240 break; 309 break;
@@ -250,13 +319,13 @@ static int ast_get_dram_info(struct drm_device *dev)
250 break; 319 break;
251 } 320 }
252 } else { 321 } else {
253 switch (data & 0x0c) { 322 switch (mcr_cfg & 0x0c) {
254 case 0: 323 case 0:
255 case 4: 324 case 4:
256 ast->dram_type = AST_DRAM_512Mx16; 325 ast->dram_type = AST_DRAM_512Mx16;
257 break; 326 break;
258 case 8: 327 case 8:
259 if (data & 0x40) 328 if (mcr_cfg & 0x40)
260 ast->dram_type = AST_DRAM_1Gx16; 329 ast->dram_type = AST_DRAM_1Gx16;
261 else 330 else
262 ast->dram_type = AST_DRAM_512Mx32; 331 ast->dram_type = AST_DRAM_512Mx32;
@@ -267,17 +336,15 @@ static int ast_get_dram_info(struct drm_device *dev)
267 } 336 }
268 } 337 }
269 338
270 data = ast_read32(ast, 0x10120); 339 if (mcr_scu_strap & 0x2000)
271 data2 = ast_read32(ast, 0x10170);
272 if (data2 & 0x2000)
273 ref_pll = 14318; 340 ref_pll = 14318;
274 else 341 else
275 ref_pll = 12000; 342 ref_pll = 12000;
276 343
277 denum = data & 0x1f; 344 denum = mcr_scu_mpll & 0x1f;
278 num = (data & 0x3fe0) >> 5; 345 num = (mcr_scu_mpll & 0x3fe0) >> 5;
279 data = (data & 0xc000) >> 14; 346 dsel = (mcr_scu_mpll & 0xc000) >> 14;
280 switch (data) { 347 switch (dsel) {
281 case 3: 348 case 3:
282 div = 0x4; 349 div = 0x4;
283 break; 350 break;