blob: 5153d89e1f0b5f7a1f90da7460dc0029aabf30dd [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 Skeggsbb23f9d2015-08-20 14:54:20 +100025#include "priv.h"
Martin Peresa10220b2012-11-04 01:01:53 +010026
Ben Skeggsa699a852015-08-20 14:54:11 +100027#include <subdev/gpio.h>
28#include <subdev/therm.h>
29
Martin Peresa10220b2012-11-04 01:01:53 +010030static void
Ben Skeggsbb23f9d2015-08-20 14:54:20 +100031nv31_bus_intr(struct nvkm_bus *bus)
Martin Peresa10220b2012-11-04 01:01:53 +010032{
Ben Skeggsbb23f9d2015-08-20 14:54:20 +100033 struct nvkm_subdev *subdev = &bus->subdev;
Ben Skeggsa699a852015-08-20 14:54:11 +100034 struct nvkm_device *device = subdev->device;
Ben Skeggs14caba42015-08-20 14:54:08 +100035 u32 stat = nvkm_rd32(device, 0x001100) & nvkm_rd32(device, 0x001140);
36 u32 gpio = nvkm_rd32(device, 0x001104) & nvkm_rd32(device, 0x001144);
Martin Peresa10220b2012-11-04 01:01:53 +010037
38 if (gpio) {
Ben Skeggsa699a852015-08-20 14:54:11 +100039 struct nvkm_gpio *gpio = device->gpio;
Ben Skeggs6cf813f2015-08-20 14:54:17 +100040 if (gpio)
41 nvkm_subdev_intr(&gpio->subdev);
Martin Peresa10220b2012-11-04 01:01:53 +010042 }
43
Martin Peres9d7175c2012-12-07 02:26:02 +010044 if (stat & 0x00000008) { /* NV41- */
Ben Skeggs14caba42015-08-20 14:54:08 +100045 u32 addr = nvkm_rd32(device, 0x009084);
46 u32 data = nvkm_rd32(device, 0x009088);
Martin Peres9d7175c2012-12-07 02:26:02 +010047
Ben Skeggsa699a852015-08-20 14:54:11 +100048 nvkm_error(subdev, "MMIO %s of %08x FAULT at %06x\n",
49 (addr & 0x00000002) ? "write" : "read", data,
50 (addr & 0x00fffffc));
Martin Peres9d7175c2012-12-07 02:26:02 +010051
Martin Peresa10220b2012-11-04 01:01:53 +010052 stat &= ~0x00000008;
Ben Skeggs14caba42015-08-20 14:54:08 +100053 nvkm_wr32(device, 0x001100, 0x00000008);
Martin Peresa10220b2012-11-04 01:01:53 +010054 }
55
56 if (stat & 0x00070000) {
Ben Skeggsa699a852015-08-20 14:54:11 +100057 struct nvkm_therm *therm = device->therm;
Ben Skeggs6cf813f2015-08-20 14:54:17 +100058 if (therm)
59 nvkm_subdev_intr(&therm->subdev);
Martin Peresa10220b2012-11-04 01:01:53 +010060 stat &= ~0x00070000;
Ben Skeggs14caba42015-08-20 14:54:08 +100061 nvkm_wr32(device, 0x001100, 0x00070000);
Martin Peresa10220b2012-11-04 01:01:53 +010062 }
63
64 if (stat) {
Ben Skeggsa699a852015-08-20 14:54:11 +100065 nvkm_error(subdev, "intr %08x\n", stat);
Ben Skeggs14caba42015-08-20 14:54:08 +100066 nvkm_mask(device, 0x001140, stat, 0x00000000);
Martin Peresa10220b2012-11-04 01:01:53 +010067 }
68}
69
Ben Skeggsbb23f9d2015-08-20 14:54:20 +100070static void
71nv31_bus_init(struct nvkm_bus *bus)
Martin Peresa10220b2012-11-04 01:01:53 +010072{
Ben Skeggs14caba42015-08-20 14:54:08 +100073 struct nvkm_device *device = bus->subdev.device;
Ben Skeggs14caba42015-08-20 14:54:08 +100074 nvkm_wr32(device, 0x001100, 0xffffffff);
75 nvkm_wr32(device, 0x001140, 0x00070008);
Martin Peresa10220b2012-11-04 01:01:53 +010076}
77
Ben Skeggsbb23f9d2015-08-20 14:54:20 +100078static const struct nvkm_bus_func
79nv31_bus = {
80 .init = nv31_bus_init,
Ben Skeggs48ae0b32013-10-24 09:39:05 +100081 .intr = nv31_bus_intr,
Ben Skeggsbb23f9d2015-08-20 14:54:20 +100082};
83
84int
85nv31_bus_new(struct nvkm_device *device, int index, struct nvkm_bus **pbus)
86{
87 return nvkm_bus_new_(&nv31_bus, device, index, pbus);
88}