xref: /linux/drivers/gpu/drm/nouveau/nouveau_platform.c (revision face6a3615a649456eb4549f6d474221d877d604)
1 /*
2  * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 #include "nouveau_platform.h"
23 
24 #include <nvkm/subdev/clk/gk20a_devfreq.h>
25 
26 static int nouveau_platform_probe(struct platform_device *pdev)
27 {
28 	const struct nvkm_device_tegra_func *func;
29 	struct nvkm_device *device = NULL;
30 	struct drm_device *drm;
31 
32 	func = of_device_get_match_data(&pdev->dev);
33 
34 	drm = nouveau_platform_device_create(func, pdev, &device);
35 	return PTR_ERR_OR_ZERO(drm);
36 }
37 
38 static void nouveau_platform_remove(struct platform_device *pdev)
39 {
40 	struct nouveau_drm *drm = platform_get_drvdata(pdev);
41 
42 	nouveau_drm_device_remove(drm);
43 }
44 
45 #ifdef CONFIG_PM_SLEEP
46 static int nouveau_platform_suspend(struct device *dev)
47 {
48 	return gk20a_devfreq_suspend(dev);
49 }
50 
51 static int nouveau_platform_resume(struct device *dev)
52 {
53 	return gk20a_devfreq_resume(dev);
54 }
55 
56 static SIMPLE_DEV_PM_OPS(nouveau_pm_ops, nouveau_platform_suspend,
57 			 nouveau_platform_resume);
58 #endif
59 
60 #if IS_ENABLED(CONFIG_OF)
61 static const struct nvkm_device_tegra_func gk20a_platform_data = {
62 	.iommu_bit = 34,
63 	.require_vdd = true,
64 };
65 
66 static const struct nvkm_device_tegra_func gm20b_platform_data = {
67 	.iommu_bit = 34,
68 	.require_vdd = true,
69 	.require_ref_clk = true,
70 };
71 
72 static const struct nvkm_device_tegra_func gp10b_platform_data = {
73 	.iommu_bit = 36,
74 	/* power provided by generic PM domains */
75 	.require_vdd = false,
76 };
77 
78 static const struct of_device_id nouveau_platform_match[] = {
79 	{
80 		.compatible = "nvidia,gk20a",
81 		.data = &gk20a_platform_data,
82 	},
83 	{
84 		.compatible = "nvidia,gm20b",
85 		.data = &gm20b_platform_data,
86 	},
87 	{
88 		.compatible = "nvidia,gp10b",
89 		.data = &gp10b_platform_data,
90 	},
91 	{ }
92 };
93 
94 MODULE_DEVICE_TABLE(of, nouveau_platform_match);
95 #endif
96 
97 struct platform_driver nouveau_platform_driver = {
98 	.driver = {
99 		.name = "nouveau",
100 		.of_match_table = of_match_ptr(nouveau_platform_match),
101 #ifdef CONFIG_PM_SLEEP
102 		.pm = &nouveau_pm_ops,
103 #endif
104 	},
105 	.probe = nouveau_platform_probe,
106 	.remove = nouveau_platform_remove,
107 };
108