1/* $NetBSD: nouveau_subdev_bus_nv04.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $ */
2
3/*
4 * Copyright 2012 Nouveau Community
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Martin Peres <martin.peres@labri.fr>
25 * Ben Skeggs
26 */
27
28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bus_nv04.c,v 1.1.1.1 2014/08/06 12:36:29 riastradh Exp $");
30
31#include "nv04.h"
32
33static void
34nv04_bus_intr(struct nouveau_subdev *subdev)
35{
36 struct nouveau_bus *pbus = nouveau_bus(subdev);
37 u32 stat = nv_rd32(pbus, 0x001100) & nv_rd32(pbus, 0x001140);
38
39 if (stat & 0x00000001) {
40 nv_error(pbus, "BUS ERROR\n");
41 stat &= ~0x00000001;
42 nv_wr32(pbus, 0x001100, 0x00000001);
43 }
44
45 if (stat & 0x00000110) {
46 subdev = nouveau_subdev(subdev, NVDEV_SUBDEV_GPIO);
47 if (subdev && subdev->intr)
48 subdev->intr(subdev);
49 stat &= ~0x00000110;
50 nv_wr32(pbus, 0x001100, 0x00000110);
51 }
52
53 if (stat) {
54 nv_error(pbus, "unknown intr 0x%08x\n", stat);
55 nv_mask(pbus, 0x001140, stat, 0x00000000);
56 }
57}
58
59static int
60nv04_bus_init(struct nouveau_object *object)
61{
62 struct nv04_bus_priv *priv = (void *)object;
63
64 nv_wr32(priv, 0x001100, 0xffffffff);
65 nv_wr32(priv, 0x001140, 0x00000111);
66
67 return nouveau_bus_init(&priv->base);
68}
69
70int
71nv04_bus_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
72 struct nouveau_oclass *oclass, void *data, u32 size,
73 struct nouveau_object **pobject)
74{
75 struct nv04_bus_impl *impl = (void *)oclass;
76 struct nv04_bus_priv *priv;
77 int ret;
78
79 ret = nouveau_bus_create(parent, engine, oclass, &priv);
80 *pobject = nv_object(priv);
81 if (ret)
82 return ret;
83
84 nv_subdev(priv)->intr = impl->intr;
85 priv->base.hwsq_exec = impl->hwsq_exec;
86 priv->base.hwsq_size = impl->hwsq_size;
87 return 0;
88}
89
90struct nouveau_oclass *
91nv04_bus_oclass = &(struct nv04_bus_impl) {
92 .base.handle = NV_SUBDEV(BUS, 0x04),
93 .base.ofuncs = &(struct nouveau_ofuncs) {
94 .ctor = nv04_bus_ctor,
95 .dtor = _nouveau_bus_dtor,
96 .init = nv04_bus_init,
97 .fini = _nouveau_bus_fini,
98 },
99 .intr = nv04_bus_intr,
100}.base;
101