// SPDX-License-Identifier: MIT1/*2* Copyright 2012 Red Hat Inc.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the6* "Software"), to deal in the Software without restriction, including7* without limitation the rights to use, copy, modify, merge, publish,8* distribute, sub license, and/or sell copies of the Software, and to9* permit persons to whom the Software is furnished to do so, subject to10* the following conditions:11*12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL15* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,16* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR17* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE18* USE OR OTHER DEALINGS IN THE SOFTWARE.19*20* The above copyright notice and this permission notice (including the21* next paragraph) shall be included in all copies or substantial portions22* of the Software.23*24*/25/*26* Authors: Dave Airlie <[email protected]>27*/2829#include <linux/pci.h>3031#include <drm/drm_drv.h>32#include <drm/drm_print.h>3334#include "ast_drv.h"3536static void ast_2400_detect_widescreen(struct ast_device *ast)37{38if (__ast_2100_detect_wsxga_p(ast) || ast->chip == AST1400) {39ast->support_wsxga_p = true;40ast->support_fullhd = true;41}42if (__ast_2100_detect_wuxga(ast))43ast->support_wuxga = true;44}4546static const struct ast_device_quirks ast_2400_device_quirks = {47.crtc_mem_req_threshold_low = 96,48.crtc_mem_req_threshold_high = 120,49};5051struct drm_device *ast_2400_device_create(struct pci_dev *pdev,52const struct drm_driver *drv,53enum ast_chip chip,54enum ast_config_mode config_mode,55void __iomem *regs,56void __iomem *ioregs,57bool need_post)58{59struct drm_device *dev;60struct ast_device *ast;61int ret;6263ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base);64if (IS_ERR(ast))65return ERR_CAST(ast);66dev = &ast->base;6768ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2400_device_quirks);6970ast->dclk_table = ast_2000_dclk_table;7172ast_2300_detect_tx_chip(ast);7374if (need_post) {75ret = ast_post_gpu(ast);76if (ret)77return ERR_PTR(ret);78}7980ret = ast_mm_init(ast);81if (ret)82return ERR_PTR(ret);8384/* map reserved buffer */85ast->dp501_fw_buf = NULL;86if (ast->vram_size < pci_resource_len(pdev, 0)) {87ast->dp501_fw_buf = pci_iomap_range(pdev, 0, ast->vram_size, 0);88if (!ast->dp501_fw_buf)89drm_info(dev, "failed to map reserved buffer!\n");90}9192ast_2400_detect_widescreen(ast);9394ret = ast_mode_config_init(ast);95if (ret)96return ERR_PTR(ret);9798return dev;99}100101102