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