]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/nvkm/subdev/ibus/gk20a.c
Merge branch 'acpi-tools'
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / nvkm / subdev / ibus / gk20a.c
1 /*
2  * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 #include <subdev/ibus.h>
23 #include <subdev/timer.h>
24
25 struct gk20a_ibus_priv {
26         struct nvkm_ibus base;
27 };
28
29 static void
30 gk20a_ibus_init_priv_ring(struct gk20a_ibus_priv *priv)
31 {
32         nv_mask(priv, 0x137250, 0x3f, 0);
33
34         nv_mask(priv, 0x000200, 0x20, 0);
35         usleep_range(20, 30);
36         nv_mask(priv, 0x000200, 0x20, 0x20);
37
38         nv_wr32(priv, 0x12004c, 0x4);
39         nv_wr32(priv, 0x122204, 0x2);
40         nv_rd32(priv, 0x122204);
41
42         /*
43          * Bug: increase clock timeout to avoid operation failure at high
44          * gpcclk rate.
45          */
46         nv_wr32(priv, 0x122354, 0x800);
47         nv_wr32(priv, 0x128328, 0x800);
48         nv_wr32(priv, 0x124320, 0x800);
49 }
50
51 static void
52 gk20a_ibus_intr(struct nvkm_subdev *subdev)
53 {
54         struct gk20a_ibus_priv *priv = (void *)subdev;
55         u32 status0 = nv_rd32(priv, 0x120058);
56
57         if (status0 & 0x7) {
58                 nv_debug(priv, "resetting priv ring\n");
59                 gk20a_ibus_init_priv_ring(priv);
60         }
61
62         /* Acknowledge interrupt */
63         nv_mask(priv, 0x12004c, 0x2, 0x2);
64
65         if (!nv_wait(subdev, 0x12004c, 0x3f, 0x00))
66                 nv_warn(priv, "timeout waiting for ringmaster ack\n");
67 }
68
69 static int
70 gk20a_ibus_init(struct nvkm_object *object)
71 {
72         struct gk20a_ibus_priv *priv = (void *)object;
73         int ret;
74
75         ret = _nvkm_ibus_init(object);
76         if (ret)
77                 return ret;
78
79         gk20a_ibus_init_priv_ring(priv);
80
81         return 0;
82 }
83
84 static int
85 gk20a_ibus_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
86                 struct nvkm_oclass *oclass, void *data, u32 size,
87                 struct nvkm_object **pobject)
88 {
89         struct gk20a_ibus_priv *priv;
90         int ret;
91
92         ret = nvkm_ibus_create(parent, engine, oclass, &priv);
93         *pobject = nv_object(priv);
94         if (ret)
95                 return ret;
96
97         nv_subdev(priv)->intr = gk20a_ibus_intr;
98         return 0;
99 }
100
101 struct nvkm_oclass
102 gk20a_ibus_oclass = {
103         .handle = NV_SUBDEV(IBUS, 0xea),
104         .ofuncs = &(struct nvkm_ofuncs) {
105                 .ctor = gk20a_ibus_ctor,
106                 .dtor = _nvkm_ibus_dtor,
107                 .init = gk20a_ibus_init,
108                 .fini = _nvkm_ibus_fini,
109         },
110 };