xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/subdev/bus/nv04.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
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"
26bb23f9d7SBen Skeggs 
27bb23f9d7SBen Skeggs #include <subdev/gpio.h>
28c39f472eSBen Skeggs 
29c39f472eSBen Skeggs static void
nv04_bus_intr(struct nvkm_bus * bus)30bb23f9d7SBen Skeggs nv04_bus_intr(struct nvkm_bus *bus)
31c39f472eSBen Skeggs {
32bb23f9d7SBen Skeggs 	struct nvkm_subdev *subdev = &bus->subdev;
33a699a85aSBen Skeggs 	struct nvkm_device *device = subdev->device;
3414caba44SBen Skeggs 	u32 stat = nvkm_rd32(device, 0x001100) & nvkm_rd32(device, 0x001140);
35c39f472eSBen Skeggs 
36c39f472eSBen Skeggs 	if (stat & 0x00000001) {
37a699a85aSBen Skeggs 		nvkm_error(subdev, "BUS ERROR\n");
38c39f472eSBen Skeggs 		stat &= ~0x00000001;
3914caba44SBen Skeggs 		nvkm_wr32(device, 0x001100, 0x00000001);
40c39f472eSBen Skeggs 	}
41c39f472eSBen Skeggs 
42c39f472eSBen Skeggs 	if (stat & 0x00000110) {
43a699a85aSBen Skeggs 		struct nvkm_gpio *gpio = device->gpio;
446cf813fbSBen Skeggs 		if (gpio)
456cf813fbSBen Skeggs 			nvkm_subdev_intr(&gpio->subdev);
46c39f472eSBen Skeggs 		stat &= ~0x00000110;
4714caba44SBen Skeggs 		nvkm_wr32(device, 0x001100, 0x00000110);
48c39f472eSBen Skeggs 	}
49c39f472eSBen Skeggs 
50c39f472eSBen Skeggs 	if (stat) {
51a699a85aSBen Skeggs 		nvkm_error(subdev, "intr %08x\n", stat);
5214caba44SBen Skeggs 		nvkm_mask(device, 0x001140, stat, 0x00000000);
53c39f472eSBen Skeggs 	}
54c39f472eSBen Skeggs }
55c39f472eSBen Skeggs 
56bb23f9d7SBen Skeggs static void
nv04_bus_init(struct nvkm_bus * bus)57bb23f9d7SBen Skeggs nv04_bus_init(struct nvkm_bus *bus)
58c39f472eSBen Skeggs {
5914caba44SBen Skeggs 	struct nvkm_device *device = bus->subdev.device;
6014caba44SBen Skeggs 	nvkm_wr32(device, 0x001100, 0xffffffff);
6114caba44SBen Skeggs 	nvkm_wr32(device, 0x001140, 0x00000111);
62c39f472eSBen Skeggs }
63c39f472eSBen Skeggs 
64bb23f9d7SBen Skeggs static const struct nvkm_bus_func
65bb23f9d7SBen Skeggs nv04_bus = {
66bb23f9d7SBen Skeggs 	.init = nv04_bus_init,
67bb23f9d7SBen Skeggs 	.intr = nv04_bus_intr,
68bb23f9d7SBen Skeggs };
69bb23f9d7SBen Skeggs 
70c39f472eSBen Skeggs int
nv04_bus_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_bus ** pbus)71*d37766e5SBen Skeggs nv04_bus_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
72*d37766e5SBen Skeggs 	     struct nvkm_bus **pbus)
73c39f472eSBen Skeggs {
74*d37766e5SBen Skeggs 	return nvkm_bus_new_(&nv04_bus, device, type, inst, pbus);
75c39f472eSBen Skeggs }
76