2 * Copyright 2015 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
24 #include <core/tegra.h>
25 #ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
28 static struct nvkm_device_tegra *
29 nvkm_device_tegra(struct nvkm_device *device)
31 return container_of(device, struct nvkm_device_tegra, device);
34 static struct resource *
35 nvkm_device_tegra_resource(struct nvkm_device *device, unsigned bar)
37 struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
38 return platform_get_resource(tdev->pdev, IORESOURCE_MEM, bar);
41 static resource_size_t
42 nvkm_device_tegra_resource_addr(struct nvkm_device *device, unsigned bar)
44 struct resource *res = nvkm_device_tegra_resource(device, bar);
45 return res ? res->start : 0;
48 static resource_size_t
49 nvkm_device_tegra_resource_size(struct nvkm_device *device, unsigned bar)
51 struct resource *res = nvkm_device_tegra_resource(device, bar);
52 return res ? resource_size(res) : 0;
56 nvkm_device_tegra_intr(int irq, void *arg)
58 struct nvkm_device_tegra *tdev = arg;
59 struct nvkm_mc *mc = tdev->device.mc;
62 nvkm_mc_intr_unarm(mc);
63 nvkm_mc_intr(mc, &handled);
64 nvkm_mc_intr_rearm(mc);
66 return handled ? IRQ_HANDLED : IRQ_NONE;
70 nvkm_device_tegra_fini(struct nvkm_device *device, bool suspend)
72 struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
74 free_irq(tdev->irq, tdev);
80 nvkm_device_tegra_init(struct nvkm_device *device)
82 struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
85 irq = platform_get_irq_byname(tdev->pdev, "stall");
89 ret = request_irq(irq, nvkm_device_tegra_intr,
90 IRQF_SHARED, "nvkm", tdev);
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,
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)
114 struct nvkm_device_tegra *tdev;
116 if (!(tdev = kzalloc(sizeof(*tdev), GFP_KERNEL)))
118 *pdevice = &tdev->device;
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,
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)