blob: 2066d38d12ded0dd5d7db307b6c3134fe3305766 [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
Marcin Slusarzcd897832013-01-27 15:01:55 +010027static void
Ben Skeggs5f8824d2015-01-14 14:40:22 +100028nv04_bus_intr(struct nvkm_subdev *subdev)
Martin Peresa10220b2012-11-04 01:01:53 +010029{
Ben Skeggs01d6b952015-08-20 14:54:06 +100030 struct nvkm_bus *bus = nvkm_bus(subdev);
31 u32 stat = nv_rd32(bus, 0x001100) & nv_rd32(bus, 0x001140);
Martin Peresa10220b2012-11-04 01:01:53 +010032
33 if (stat & 0x00000001) {
Ben Skeggs01d6b952015-08-20 14:54:06 +100034 nv_error(bus, "BUS ERROR\n");
Martin Peresa10220b2012-11-04 01:01:53 +010035 stat &= ~0x00000001;
Ben Skeggs01d6b952015-08-20 14:54:06 +100036 nv_wr32(bus, 0x001100, 0x00000001);
Martin Peresa10220b2012-11-04 01:01:53 +010037 }
38
39 if (stat & 0x00000110) {
Ben Skeggs5f8824d2015-01-14 14:40:22 +100040 subdev = nvkm_subdev(subdev, NVDEV_SUBDEV_GPIO);
Martin Peresa10220b2012-11-04 01:01:53 +010041 if (subdev && subdev->intr)
42 subdev->intr(subdev);
43 stat &= ~0x00000110;
Ben Skeggs01d6b952015-08-20 14:54:06 +100044 nv_wr32(bus, 0x001100, 0x00000110);
Martin Peresa10220b2012-11-04 01:01:53 +010045 }
46
47 if (stat) {
Ben Skeggs01d6b952015-08-20 14:54:06 +100048 nv_error(bus, "unknown intr 0x%08x\n", stat);
49 nv_mask(bus, 0x001140, stat, 0x00000000);
Martin Peresa10220b2012-11-04 01:01:53 +010050 }
51}
52
53static int
Ben Skeggs5f8824d2015-01-14 14:40:22 +100054nv04_bus_init(struct nvkm_object *object)
Martin Peresa10220b2012-11-04 01:01:53 +010055{
Ben Skeggs01d6b952015-08-20 14:54:06 +100056 struct nvkm_bus *bus = (void *)object;
Martin Peresa10220b2012-11-04 01:01:53 +010057
Ben Skeggs01d6b952015-08-20 14:54:06 +100058 nv_wr32(bus, 0x001100, 0xffffffff);
59 nv_wr32(bus, 0x001140, 0x00000111);
Martin Peresa10220b2012-11-04 01:01:53 +010060
Ben Skeggs01d6b952015-08-20 14:54:06 +100061 return nvkm_bus_init(bus);
Martin Peresa10220b2012-11-04 01:01:53 +010062}
63
Ben Skeggs48ae0b32013-10-24 09:39:05 +100064int
Ben Skeggs5f8824d2015-01-14 14:40:22 +100065nv04_bus_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
66 struct nvkm_oclass *oclass, void *data, u32 size,
67 struct nvkm_object **pobject)
Ben Skeggs48ae0b32013-10-24 09:39:05 +100068{
69 struct nv04_bus_impl *impl = (void *)oclass;
Ben Skeggs01d6b952015-08-20 14:54:06 +100070 struct nvkm_bus *bus;
Ben Skeggs48ae0b32013-10-24 09:39:05 +100071 int ret;
72
Ben Skeggs01d6b952015-08-20 14:54:06 +100073 ret = nvkm_bus_create(parent, engine, oclass, &bus);
74 *pobject = nv_object(bus);
Ben Skeggs48ae0b32013-10-24 09:39:05 +100075 if (ret)
76 return ret;
77
Ben Skeggs01d6b952015-08-20 14:54:06 +100078 nv_subdev(bus)->intr = impl->intr;
79 bus->hwsq_exec = impl->hwsq_exec;
80 bus->hwsq_size = impl->hwsq_size;
Ben Skeggs48ae0b32013-10-24 09:39:05 +100081 return 0;
82}
83
Ben Skeggs5f8824d2015-01-14 14:40:22 +100084struct nvkm_oclass *
Ben Skeggs48ae0b32013-10-24 09:39:05 +100085nv04_bus_oclass = &(struct nv04_bus_impl) {
86 .base.handle = NV_SUBDEV(BUS, 0x04),
Ben Skeggs5f8824d2015-01-14 14:40:22 +100087 .base.ofuncs = &(struct nvkm_ofuncs) {
Martin Peresa10220b2012-11-04 01:01:53 +010088 .ctor = nv04_bus_ctor,
Ben Skeggs5f8824d2015-01-14 14:40:22 +100089 .dtor = _nvkm_bus_dtor,
Martin Peresa10220b2012-11-04 01:01:53 +010090 .init = nv04_bus_init,
Ben Skeggs5f8824d2015-01-14 14:40:22 +100091 .fini = _nvkm_bus_fini,
Martin Peresa10220b2012-11-04 01:01:53 +010092 },
Ben Skeggs48ae0b32013-10-24 09:39:05 +100093 .intr = nv04_bus_intr,
94}.base;