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
ast_2200_detect_widescreen(struct ast_device * ast)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 static const struct ast_device_quirks ast_2200_device_quirks = {
47 .crtc_mem_req_threshold_low = 47,
48 .crtc_mem_req_threshold_high = 63,
49 };
50
ast_2200_device_create(struct pci_dev * pdev,const struct drm_driver * drv,enum ast_chip chip,enum ast_config_mode config_mode,void __iomem * regs,void __iomem * ioregs,bool need_post)51 struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
52 const struct drm_driver *drv,
53 enum ast_chip chip,
54 enum ast_config_mode config_mode,
55 void __iomem *regs,
56 void __iomem *ioregs,
57 bool need_post)
58 {
59 struct drm_device *dev;
60 struct ast_device *ast;
61 int ret;
62
63 ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base);
64 if (IS_ERR(ast))
65 return ERR_CAST(ast);
66 dev = &ast->base;
67
68 ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2200_device_quirks);
69
70 ast->dclk_table = ast_2000_dclk_table;
71
72 ast_2000_detect_tx_chip(ast, need_post);
73
74 if (need_post) {
75 ret = ast_post_gpu(ast);
76 if (ret)
77 return ERR_PTR(ret);
78 }
79
80 ret = ast_mm_init(ast);
81 if (ret)
82 return ERR_PTR(ret);
83
84 ast_2200_detect_widescreen(ast);
85
86 ret = ast_mode_config_init(ast);
87 if (ret)
88 return ERR_PTR(ret);
89
90 return dev;
91 }
92
93