| 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 | #include "ast_post.h" |
| 35 | |
| 36 | /* |
| 37 | * POST |
| 38 | */ |
| 39 | |
| 40 | int ast_2600_post(struct ast_device *ast) |
| 41 | { |
| 42 | ast_2300_set_def_ext_reg(ast); |
| 43 | |
| 44 | if (ast->tx_chip == AST_TX_ASTDP) |
| 45 | return ast_dp_launch(ast); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Device initialization |
| 52 | */ |
| 53 | |
| 54 | static void ast_2600_detect_widescreen(struct ast_device *ast) |
| 55 | { |
| 56 | ast->support_wsxga_p = true; |
| 57 | ast->support_fullhd = true; |
| 58 | if (__ast_2100_detect_wuxga(ast)) |
| 59 | ast->support_wuxga = true; |
| 60 | } |
| 61 | |
| 62 | static const struct ast_device_quirks ast_2600_device_quirks = { |
| 63 | .crtc_mem_req_threshold_low = 160, |
| 64 | .crtc_mem_req_threshold_high = 224, |
| 65 | .crtc_hsync_precatch_needed = true, |
| 66 | .crtc_hsync_add4_needed = true, |
| 67 | }; |
| 68 | |
| 69 | struct drm_device *ast_2600_device_create(struct pci_dev *pdev, |
| 70 | const struct drm_driver *drv, |
| 71 | enum ast_chip chip, |
| 72 | enum ast_config_mode config_mode, |
| 73 | void __iomem *regs, |
| 74 | void __iomem *ioregs, |
| 75 | bool need_post) |
| 76 | { |
| 77 | struct drm_device *dev; |
| 78 | struct ast_device *ast; |
| 79 | int ret; |
| 80 | |
| 81 | ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base); |
| 82 | if (IS_ERR(ptr: ast)) |
| 83 | return ERR_CAST(ptr: ast); |
| 84 | dev = &ast->base; |
| 85 | |
| 86 | ast_device_init(ast, chip, config_mode, regs, ioregs, quirks: &ast_2600_device_quirks); |
| 87 | |
| 88 | ast->dclk_table = ast_2500_dclk_table; |
| 89 | |
| 90 | ast_2300_detect_tx_chip(ast); |
| 91 | |
| 92 | switch (ast->tx_chip) { |
| 93 | case AST_TX_ASTDP: |
| 94 | ret = ast_post_gpu(ast); |
| 95 | break; |
| 96 | default: |
| 97 | ret = 0; |
| 98 | if (need_post) |
| 99 | ret = ast_post_gpu(ast); |
| 100 | break; |
| 101 | } |
| 102 | if (ret) |
| 103 | return ERR_PTR(error: ret); |
| 104 | |
| 105 | ret = ast_mm_init(ast); |
| 106 | if (ret) |
| 107 | return ERR_PTR(error: ret); |
| 108 | |
| 109 | ast_2600_detect_widescreen(ast); |
| 110 | |
| 111 | ret = ast_mode_config_init(ast); |
| 112 | if (ret) |
| 113 | return ERR_PTR(error: ret); |
| 114 | |
| 115 | return dev; |
| 116 | } |
| 117 | |