OSDN Git Service

drm/nouveau/device: remove pci/platform_device from common struct
[uclinux-h8/linux.git] / drivers / gpu / drm / nouveau / nvkm / engine / device / tegra.c
1 /*
2  * Copyright 2015 Red Hat Inc.
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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs <bskeggs@redhat.com>
23  */
24 #include <core/tegra.h>
25 #ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
26 #include "priv.h"
27
28 static struct nvkm_device_tegra *
29 nvkm_device_tegra(struct nvkm_device *device)
30 {
31         return container_of(device, struct nvkm_device_tegra, device);
32 }
33
34 static struct resource *
35 nvkm_device_tegra_resource(struct nvkm_device *device, unsigned bar)
36 {
37         struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
38         return platform_get_resource(tdev->pdev, IORESOURCE_MEM, bar);
39 }
40
41 static resource_size_t
42 nvkm_device_tegra_resource_addr(struct nvkm_device *device, unsigned bar)
43 {
44         struct resource *res = nvkm_device_tegra_resource(device, bar);
45         return res ? res->start : 0;
46 }
47
48 static resource_size_t
49 nvkm_device_tegra_resource_size(struct nvkm_device *device, unsigned bar)
50 {
51         struct resource *res = nvkm_device_tegra_resource(device, bar);
52         return res ? resource_size(res) : 0;
53 }
54
55 static irqreturn_t
56 nvkm_device_tegra_intr(int irq, void *arg)
57 {
58         struct nvkm_device_tegra *tdev = arg;
59         struct nvkm_mc *mc = tdev->device.mc;
60         bool handled = false;
61         if (likely(mc)) {
62                 nvkm_mc_intr_unarm(mc);
63                 nvkm_mc_intr(mc, &handled);
64                 nvkm_mc_intr_rearm(mc);
65         }
66         return handled ? IRQ_HANDLED : IRQ_NONE;
67 }
68
69 static void
70 nvkm_device_tegra_fini(struct nvkm_device *device, bool suspend)
71 {
72         struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
73         if (tdev->irq) {
74                 free_irq(tdev->irq, tdev);
75                 tdev->irq = 0;
76         };
77 }
78
79 static int
80 nvkm_device_tegra_init(struct nvkm_device *device)
81 {
82         struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
83         int irq, ret;
84
85         irq = platform_get_irq_byname(tdev->pdev, "stall");
86         if (irq < 0)
87                 return irq;
88
89         ret = request_irq(irq, nvkm_device_tegra_intr,
90                           IRQF_SHARED, "nvkm", tdev);
91         if (ret)
92                 return ret;
93
94         tdev->irq = irq;
95         return 0;
96 }
97
98 static const struct nvkm_device_func
99 nvkm_device_tegra_func = {
100         .tegra = nvkm_device_tegra,
101         .init = nvkm_device_tegra_init,
102         .fini = nvkm_device_tegra_fini,
103         .resource_addr = nvkm_device_tegra_resource_addr,
104         .resource_size = nvkm_device_tegra_resource_size,
105         .cpu_coherent = false,
106 };
107
108 int
109 nvkm_device_tegra_new(struct platform_device *pdev,
110                       const char *cfg, const char *dbg,
111                       bool detect, bool mmio, u64 subdev_mask,
112                       struct nvkm_device **pdevice)
113 {
114         struct nvkm_device_tegra *tdev;
115
116         if (!(tdev = kzalloc(sizeof(*tdev), GFP_KERNEL)))
117                 return -ENOMEM;
118         *pdevice = &tdev->device;
119         tdev->pdev = pdev;
120         tdev->irq = -1;
121
122         return nvkm_device_ctor(&nvkm_device_tegra_func, NULL, &pdev->dev,
123                                 NVKM_DEVICE_TEGRA, pdev->id, NULL,
124                                 cfg, dbg, detect, mmio, subdev_mask,
125                                 &tdev->device);
126 }
127 #else
128 int
129 nvkm_device_tegra_new(struct platform_device *pdev,
130                       const char *cfg, const char *dbg,
131                       bool detect, bool mmio, u64 subdev_mask,
132                       struct nvkm_device **pdevice)
133 {
134         return -ENOSYS;
135 }
136 #endif