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 static const struct ast_device_quirks ast_2400_device_quirks = { 48 .crtc_mem_req_threshold_low = 96, 49 .crtc_mem_req_threshold_high = 120, 50 }; 51 52 struct drm_device *ast_2400_device_create(struct pci_dev *pdev, 53 const struct drm_driver *drv, 54 enum ast_chip chip, 55 enum ast_config_mode config_mode, 56 void __iomem *regs, 57 void __iomem *ioregs, 58 bool need_post) 59 { 60 struct drm_device *dev; 61 struct ast_device *ast; 62 int ret; 63 64 ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base); 65 if (IS_ERR(ast)) 66 return ERR_CAST(ast); 67 dev = &ast->base; 68 69 ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2400_device_quirks); 70 71 ast->dclk_table = ast_2000_dclk_table; 72 73 ast_2300_detect_tx_chip(ast); 74 75 if (need_post) { 76 ret = ast_post_gpu(ast); 77 if (ret) 78 return ERR_PTR(ret); 79 } 80 81 ret = ast_mm_init(ast); 82 if (ret) 83 return ERR_PTR(ret); 84 85 /* map reserved buffer */ 86 ast->dp501_fw_buf = NULL; 87 if (ast->vram_size < pci_resource_len(pdev, 0)) { 88 ast->dp501_fw_buf = pci_iomap_range(pdev, 0, ast->vram_size, 0); 89 if (!ast->dp501_fw_buf) 90 drm_info(dev, "failed to map reserved buffer!\n"); 91 } 92 93 ast_2400_detect_widescreen(ast); 94 95 ret = ast_mode_config_init(ast); 96 if (ret) 97 return ERR_PTR(ret); 98 99 return dev; 100 } 101