1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <linux/pci.h>
4 
5 #include <drm/drm_drv.h>
6 
7 #include "mgag200_drv.h"
8 
9 /*
10  * DRM device
11  */
12 
13 static const struct mgag200_device_info mgag200_g200ew3_device_info =
14 	MGAG200_DEVICE_INFO_INIT(2048, 2048, 0, true, 0, 1, false);
15 
16 static resource_size_t mgag200_g200ew3_device_probe_vram(struct mga_device *mdev)
17 {
18 	resource_size_t vram_size = resource_size(mdev->vram_res);
19 
20 	if (vram_size >= 0x1000000)
21 		vram_size = vram_size - 0x400000;
22 	return mgag200_probe_vram(mdev->vram, vram_size);
23 }
24 
25 struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev,
26 						 const struct drm_driver *drv,
27 						 enum mga_type type)
28 {
29 	struct mga_device *mdev;
30 	struct drm_device *dev;
31 	resource_size_t vram_available;
32 	int ret;
33 
34 	mdev = devm_drm_dev_alloc(&pdev->dev, drv, struct mga_device, base);
35 	if (IS_ERR(mdev))
36 		return mdev;
37 	dev = &mdev->base;
38 
39 	pci_set_drvdata(pdev, dev);
40 
41 	ret = mgag200_init_pci_options(pdev, 0x41049120, 0x0000b000);
42 	if (ret)
43 		return ERR_PTR(ret);
44 
45 	ret = mgag200_device_preinit(mdev);
46 	if (ret)
47 		return ERR_PTR(ret);
48 
49 	ret = mgag200_device_init(mdev, type, &mgag200_g200ew3_device_info);
50 	if (ret)
51 		return ERR_PTR(ret);
52 
53 	vram_available = mgag200_g200ew3_device_probe_vram(mdev);
54 
55 	ret = mgag200_modeset_init(mdev, vram_available);
56 	if (ret)
57 		return ERR_PTR(ret);
58 
59 	return mdev;
60 }
61