xref: /linux/drivers/gpu/drm/ast/ast_2200.c (revision 52e6b198833411564e0b9ce6e96bbd3d72f961e7)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright 2012 Red Hat Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19  * USE OR OTHER DEALINGS IN THE SOFTWARE.
20  *
21  * The above copyright notice and this permission notice (including the
22  * next paragraph) shall be included in all copies or substantial portions
23  * of the Software.
24  */
25 /*
26  * Authors: Dave Airlie <airlied@redhat.com>
27  */
28 
29 #include <linux/pci.h>
30 
31 #include <drm/drm_drv.h>
32 
33 #include "ast_drv.h"
34 
35 static void ast_2200_detect_widescreen(struct ast_device *ast)
36 {
37 	if (__ast_2100_detect_wsxga_p(ast)) {
38 		ast->support_wsxga_p = true;
39 		if (ast->chip == AST2200)
40 			ast->support_fullhd = true;
41 	}
42 	if (__ast_2100_detect_wuxga(ast))
43 		ast->support_wuxga = true;
44 }
45 
46 struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
47 					  const struct drm_driver *drv,
48 					  enum ast_chip chip,
49 					  enum ast_config_mode config_mode,
50 					  void __iomem *regs,
51 					  void __iomem *ioregs,
52 					  bool need_post)
53 {
54 	struct drm_device *dev;
55 	struct ast_device *ast;
56 	int ret;
57 
58 	ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base);
59 	if (IS_ERR(ast))
60 		return ERR_CAST(ast);
61 	dev = &ast->base;
62 
63 	ast_device_init(ast, chip, config_mode, regs, ioregs);
64 
65 	ast_2000_detect_tx_chip(ast, need_post);
66 
67 	if (need_post) {
68 		ret = ast_post_gpu(ast);
69 		if (ret)
70 			return ERR_PTR(ret);
71 	}
72 
73 	ret = ast_mm_init(ast);
74 	if (ret)
75 		return ERR_PTR(ret);
76 
77 	ast_2200_detect_widescreen(ast);
78 
79 	ret = ast_mode_config_init(ast);
80 	if (ret)
81 		return ERR_PTR(ret);
82 
83 	return dev;
84 }
85 
86