xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/subdev/bus/nv31.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs  * Copyright 2012 Nouveau Community
3c39f472eSBen Skeggs  *
4c39f472eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs  * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs  *
11c39f472eSBen Skeggs  * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs  * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs  *
14c39f472eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17c39f472eSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs  *
22c39f472eSBen Skeggs  * Authors: Martin Peres <martin.peres@labri.fr>
23c39f472eSBen Skeggs  *          Ben Skeggs
24c39f472eSBen Skeggs  */
25bb23f9d7SBen Skeggs #include "priv.h"
26c39f472eSBen Skeggs 
27a699a85aSBen Skeggs #include <subdev/gpio.h>
28a699a85aSBen Skeggs #include <subdev/therm.h>
29a699a85aSBen Skeggs 
30c39f472eSBen Skeggs static void
nv31_bus_intr(struct nvkm_bus * bus)31bb23f9d7SBen Skeggs nv31_bus_intr(struct nvkm_bus *bus)
32c39f472eSBen Skeggs {
33bb23f9d7SBen Skeggs 	struct nvkm_subdev *subdev = &bus->subdev;
34a699a85aSBen Skeggs 	struct nvkm_device *device = subdev->device;
3514caba44SBen Skeggs 	u32 stat = nvkm_rd32(device, 0x001100) & nvkm_rd32(device, 0x001140);
3614caba44SBen Skeggs 	u32 gpio = nvkm_rd32(device, 0x001104) & nvkm_rd32(device, 0x001144);
37c39f472eSBen Skeggs 
38c39f472eSBen Skeggs 	if (gpio) {
39a699a85aSBen Skeggs 		struct nvkm_gpio *gpio = device->gpio;
406cf813fbSBen Skeggs 		if (gpio)
416cf813fbSBen Skeggs 			nvkm_subdev_intr(&gpio->subdev);
42c39f472eSBen Skeggs 	}
43c39f472eSBen Skeggs 
44c39f472eSBen Skeggs 	if (stat & 0x00000008) {  /* NV41- */
4514caba44SBen Skeggs 		u32 addr = nvkm_rd32(device, 0x009084);
4614caba44SBen Skeggs 		u32 data = nvkm_rd32(device, 0x009088);
47c39f472eSBen Skeggs 
48*9887bda0SLyude Paul 		nvkm_error_ratelimited(subdev, "MMIO %s of %08x FAULT at %06x\n",
49c39f472eSBen Skeggs 				       (addr & 0x00000002) ? "write" : "read", data,
50c39f472eSBen Skeggs 				       (addr & 0x00fffffc));
51c39f472eSBen Skeggs 
52c39f472eSBen Skeggs 		stat &= ~0x00000008;
5314caba44SBen Skeggs 		nvkm_wr32(device, 0x001100, 0x00000008);
54c39f472eSBen Skeggs 	}
55c39f472eSBen Skeggs 
56c39f472eSBen Skeggs 	if (stat & 0x00070000) {
57a699a85aSBen Skeggs 		struct nvkm_therm *therm = device->therm;
586cf813fbSBen Skeggs 		if (therm)
596cf813fbSBen Skeggs 			nvkm_subdev_intr(&therm->subdev);
60c39f472eSBen Skeggs 		stat &= ~0x00070000;
6114caba44SBen Skeggs 		nvkm_wr32(device, 0x001100, 0x00070000);
62c39f472eSBen Skeggs 	}
63c39f472eSBen Skeggs 
64c39f472eSBen Skeggs 	if (stat) {
65a699a85aSBen Skeggs 		nvkm_error(subdev, "intr %08x\n", stat);
6614caba44SBen Skeggs 		nvkm_mask(device, 0x001140, stat, 0x00000000);
67c39f472eSBen Skeggs 	}
68c39f472eSBen Skeggs }
69c39f472eSBen Skeggs 
70bb23f9d7SBen Skeggs static void
nv31_bus_init(struct nvkm_bus * bus)71bb23f9d7SBen Skeggs nv31_bus_init(struct nvkm_bus *bus)
72c39f472eSBen Skeggs {
7314caba44SBen Skeggs 	struct nvkm_device *device = bus->subdev.device;
7414caba44SBen Skeggs 	nvkm_wr32(device, 0x001100, 0xffffffff);
7514caba44SBen Skeggs 	nvkm_wr32(device, 0x001140, 0x00070008);
76c39f472eSBen Skeggs }
77c39f472eSBen Skeggs 
78bb23f9d7SBen Skeggs static const struct nvkm_bus_func
79bb23f9d7SBen Skeggs nv31_bus = {
80c39f472eSBen Skeggs 	.init = nv31_bus_init,
81c39f472eSBen Skeggs 	.intr = nv31_bus_intr,
82bb23f9d7SBen Skeggs };
83bb23f9d7SBen Skeggs 
84bb23f9d7SBen Skeggs int
nv31_bus_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_bus ** pbus)85d37766e5SBen Skeggs nv31_bus_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
86d37766e5SBen Skeggs 	     struct nvkm_bus **pbus)
87bb23f9d7SBen Skeggs {
88d37766e5SBen Skeggs 	return nvkm_bus_new_(&nv31_bus, device, type, inst, pbus);
89bb23f9d7SBen Skeggs }
90