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->dclk_table = ast_2000_dclk_table; 67 68 ast_2300_detect_tx_chip(ast); 69 70 if (need_post) { 71 ret = ast_post_gpu(ast); 72 if (ret) 73 return ERR_PTR(ret); 74 } 75 76 ret = ast_mm_init(ast); 77 if (ret) 78 return ERR_PTR(ret); 79 80 /* map reserved buffer */ 81 ast->dp501_fw_buf = NULL; 82 if (ast->vram_size < pci_resource_len(pdev, 0)) { 83 ast->dp501_fw_buf = pci_iomap_range(pdev, 0, ast->vram_size, 0); 84 if (!ast->dp501_fw_buf) 85 drm_info(dev, "failed to map reserved buffer!\n"); 86 } 87 88 ast_2400_detect_widescreen(ast); 89 90 ret = ast_mode_config_init(ast); 91 if (ret) 92 return ERR_PTR(ret); 93 94 return dev; 95 } 96