xref: /linux/drivers/gpu/drm/ast/ast_2400.c (revision 6200442de089468ff283becb81382d6ac23c25e9)
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 /*
27  * Authors: Dave Airlie <airlied@redhat.com>
28  */
29 
30 #include <linux/pci.h>
31 
32 #include <drm/drm_drv.h>
33 #include <drm/drm_print.h>
34 
35 #include "ast_drv.h"
36 
37 static void ast_2400_detect_widescreen(struct ast_device *ast)
38 {
39 	if (__ast_2100_detect_wsxga_p(ast) || ast->chip == AST1400) {
40 		ast->support_wsxga_p = true;
41 		ast->support_fullhd = true;
42 	}
43 	if (__ast_2100_detect_wuxga(ast))
44 		ast->support_wuxga = true;
45 }
46 
47 struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
48 					  const struct drm_driver *drv,
49 					  enum ast_chip chip,
50 					  enum ast_config_mode config_mode,
51 					  void __iomem *regs,
52 					  void __iomem *ioregs,
53 					  bool need_post)
54 {
55 	struct drm_device *dev;
56 	struct ast_device *ast;
57 	int ret;
58 
59 	ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base);
60 	if (IS_ERR(ast))
61 		return ERR_CAST(ast);
62 	dev = &ast->base;
63 
64 	ast_device_init(ast, chip, config_mode, regs, ioregs);
65 
66 	ast_2300_detect_tx_chip(ast);
67 
68 	if (need_post) {
69 		ret = ast_post_gpu(ast);
70 		if (ret)
71 			return ERR_PTR(ret);
72 	}
73 
74 	ret = ast_mm_init(ast);
75 	if (ret)
76 		return ERR_PTR(ret);
77 
78 	/* map reserved buffer */
79 	ast->dp501_fw_buf = NULL;
80 	if (ast->vram_size < pci_resource_len(pdev, 0)) {
81 		ast->dp501_fw_buf = pci_iomap_range(pdev, 0, ast->vram_size, 0);
82 		if (!ast->dp501_fw_buf)
83 			drm_info(dev, "failed to map reserved buffer!\n");
84 	}
85 
86 	ast_2400_detect_widescreen(ast);
87 
88 	ret = ast_mode_config_init(ast);
89 	if (ret)
90 		return ERR_PTR(ret);
91 
92 	return dev;
93 }
94