blob: 3b57f50db4dec1e3af36636eeec4dcba21220903 [file] [log] [blame]
Martin Peresa10220b2012-11-04 01:01:53 +01001/*
2 * Copyright 2012 Nouveau Community
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: Martin Peres <martin.peres@labri.fr>
23 * Ben Skeggs
24 */
Ben Skeggs48ae0b32013-10-24 09:39:05 +100025#include "nv04.h"
Martin Peresa10220b2012-11-04 01:01:53 +010026
Ben Skeggsa699a852015-08-20 14:54:11 +100027#include <subdev/gpio.h>
28
Marcin Slusarzcd897832013-01-27 15:01:55 +010029static void
Ben Skeggs5f8824d2015-01-14 14:40:22 +100030nv04_bus_intr(struct nvkm_subdev *subdev)
Martin Peresa10220b2012-11-04 01:01:53 +010031{
Ben Skeggsa699a852015-08-20 14:54:11 +100032 struct nvkm_device *device = subdev->device;
Ben Skeggs14caba42015-08-20 14:54:08 +100033 u32 stat = nvkm_rd32(device, 0x001100) & nvkm_rd32(device, 0x001140);
Martin Peresa10220b2012-11-04 01:01:53 +010034
35 if (stat & 0x00000001) {
Ben Skeggsa699a852015-08-20 14:54:11 +100036 nvkm_error(subdev, "BUS ERROR\n");
Martin Peresa10220b2012-11-04 01:01:53 +010037 stat &= ~0x00000001;
Ben Skeggs14caba42015-08-20 14:54:08 +100038 nvkm_wr32(device, 0x001100, 0x00000001);
Martin Peresa10220b2012-11-04 01:01:53 +010039 }
40
41 if (stat & 0x00000110) {
Ben Skeggsa699a852015-08-20 14:54:11 +100042 struct nvkm_gpio *gpio = device->gpio;
43 if (gpio && gpio->subdev.intr)
44 gpio->subdev.intr(&gpio->subdev);
Martin Peresa10220b2012-11-04 01:01:53 +010045 stat &= ~0x00000110;
Ben Skeggs14caba42015-08-20 14:54:08 +100046 nvkm_wr32(device, 0x001100, 0x00000110);
Martin Peresa10220b2012-11-04 01:01:53 +010047 }
48
49 if (stat) {
Ben Skeggsa699a852015-08-20 14:54:11 +100050 nvkm_error(subdev, "intr %08x\n", stat);
Ben Skeggs14caba42015-08-20 14:54:08 +100051 nvkm_mask(device, 0x001140, stat, 0x00000000);
Martin Peresa10220b2012-11-04 01:01:53 +010052 }
53}
54
55static int
Ben Skeggs5f8824d2015-01-14 14:40:22 +100056nv04_bus_init(struct nvkm_object *object)
Martin Peresa10220b2012-11-04 01:01:53 +010057{
Ben Skeggs01d6b952015-08-20 14:54:06 +100058 struct nvkm_bus *bus = (void *)object;
Ben Skeggs14caba42015-08-20 14:54:08 +100059 struct nvkm_device *device = bus->subdev.device;
Martin Peresa10220b2012-11-04 01:01:53 +010060
Ben Skeggs14caba42015-08-20 14:54:08 +100061 nvkm_wr32(device, 0x001100, 0xffffffff);
62 nvkm_wr32(device, 0x001140, 0x00000111);
Martin Peresa10220b2012-11-04 01:01:53 +010063
Ben Skeggs01d6b952015-08-20 14:54:06 +100064 return nvkm_bus_init(bus);
Martin Peresa10220b2012-11-04 01:01:53 +010065}
66
Ben Skeggs48ae0b32013-10-24 09:39:05 +100067int
Ben Skeggs5f8824d2015-01-14 14:40:22 +100068nv04_bus_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
69 struct nvkm_oclass *oclass, void *data, u32 size,
70 struct nvkm_object **pobject)
Ben Skeggs48ae0b32013-10-24 09:39:05 +100071{
72 struct nv04_bus_impl *impl = (void *)oclass;
Ben Skeggs01d6b952015-08-20 14:54:06 +100073 struct nvkm_bus *bus;
Ben Skeggs48ae0b32013-10-24 09:39:05 +100074 int ret;
75
Ben Skeggs01d6b952015-08-20 14:54:06 +100076 ret = nvkm_bus_create(parent, engine, oclass, &bus);
77 *pobject = nv_object(bus);
Ben Skeggs48ae0b32013-10-24 09:39:05 +100078 if (ret)
79 return ret;
80
Ben Skeggs01d6b952015-08-20 14:54:06 +100081 nv_subdev(bus)->intr = impl->intr;
82 bus->hwsq_exec = impl->hwsq_exec;
83 bus->hwsq_size = impl->hwsq_size;
Ben Skeggs48ae0b32013-10-24 09:39:05 +100084 return 0;
85}
86
Ben Skeggs5f8824d2015-01-14 14:40:22 +100087struct nvkm_oclass *
Ben Skeggs48ae0b32013-10-24 09:39:05 +100088nv04_bus_oclass = &(struct nv04_bus_impl) {
89 .base.handle = NV_SUBDEV(BUS, 0x04),
Ben Skeggs5f8824d2015-01-14 14:40:22 +100090 .base.ofuncs = &(struct nvkm_ofuncs) {
Martin Peresa10220b2012-11-04 01:01:53 +010091 .ctor = nv04_bus_ctor,
Ben Skeggs5f8824d2015-01-14 14:40:22 +100092 .dtor = _nvkm_bus_dtor,
Martin Peresa10220b2012-11-04 01:01:53 +010093 .init = nv04_bus_init,
Ben Skeggs5f8824d2015-01-14 14:40:22 +100094 .fini = _nvkm_bus_fini,
Martin Peresa10220b2012-11-04 01:01:53 +010095 },
Ben Skeggs48ae0b32013-10-24 09:39:05 +100096 .intr = nv04_bus_intr,
97}.base;