xref: /linux/drivers/gpu/drm/ast/ast_post.c (revision 4b99990cdf9560e8a071640baf19f312e6ae02f4)
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18  * USE OR OTHER DEALINGS IN THE SOFTWARE.
19  *
20  * The above copyright notice and this permission notice (including the
21  * next paragraph) shall be included in all copies or substantial portions
22  * of the Software.
23  *
24  */
25 /*
26  * Authors: Dave Airlie <airlied@redhat.com>
27  */
28 
29 #include <linux/delay.h>
30 #include <linux/pci.h>
31 
32 #include <drm/drm_print.h>
33 
34 #include "ast_drv.h"
35 #include "ast_post.h"
36 
37 int ast_post_gpu(struct ast_device *ast)
38 {
39 	int ret;
40 
41 	if (AST_GEN(ast) >= 7) {
42 		ret = ast_2600_post(ast);
43 		if (ret)
44 			return ret;
45 	} else if (AST_GEN(ast) >= 6) {
46 		ret = ast_2500_post(ast);
47 		if (ret)
48 			return ret;
49 	} else if (AST_GEN(ast) >= 4) {
50 		ret = ast_2300_post(ast);
51 		if (ret)
52 			return ret;
53 	} else  if (AST_GEN(ast) >= 2) {
54 		ret = ast_2100_post(ast);
55 		if (ret)
56 			return ret;
57 	} else  {
58 		ret = ast_2000_post(ast);
59 		if (ret)
60 			return ret;
61 	}
62 
63 	return 0;
64 }
65 
66 #define TIMEOUT              5000000
67 
68 bool mmc_test(struct ast_device *ast, u32 datagen, u8 test_ctl)
69 {
70 	u32 data, timeout;
71 
72 	ast_moutdwm(ast, AST_REG_MCR70, 0x00000000);
73 	ast_moutdwm(ast, AST_REG_MCR70, (datagen << 3) | test_ctl);
74 	timeout = 0;
75 	do {
76 		data = ast_mindwm(ast, AST_REG_MCR70) & 0x3000;
77 		if (data & 0x2000)
78 			return false;
79 		if (++timeout > TIMEOUT) {
80 			ast_moutdwm(ast, AST_REG_MCR70, 0x00000000);
81 			return false;
82 		}
83 	} while (!data);
84 	ast_moutdwm(ast, AST_REG_MCR70, 0x0);
85 	return true;
86 }
87 
88 bool mmc_test_burst(struct ast_device *ast, u32 datagen)
89 {
90 	return mmc_test(ast, datagen, 0xc1);
91 }
92