drm/nouveau/gpio: split g92 class from nv50
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / subdev / gpio / nv10.c
CommitLineData
6ee73861
BS
1/*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
fa531bc8 27#include "priv.h"
6ee73861 28
e0996aea
BS
29struct nv10_gpio_priv {
30 struct nouveau_gpio base;
31};
32
33static int
34nv10_gpio_sense(struct nouveau_gpio *gpio, int line)
6ee73861 35{
a0b25635
BS
36 if (line < 2) {
37 line = line * 16;
e0996aea 38 line = nv_rd32(gpio, 0x600818) >> line;
a0b25635
BS
39 return !!(line & 0x0100);
40 } else
41 if (line < 10) {
42 line = (line - 2) * 4;
e0996aea 43 line = nv_rd32(gpio, 0x60081c) >> line;
a0b25635
BS
44 return !!(line & 0x04);
45 } else
46 if (line < 14) {
47 line = (line - 10) * 4;
e0996aea 48 line = nv_rd32(gpio, 0x600850) >> line;
a0b25635
BS
49 return !!(line & 0x04);
50 }
6ee73861 51
a0b25635 52 return -EINVAL;
6ee73861
BS
53}
54
e0996aea
BS
55static int
56nv10_gpio_drive(struct nouveau_gpio *gpio, int line, int dir, int out)
6ee73861 57{
a0b25635
BS
58 u32 reg, mask, data;
59
60 if (line < 2) {
61 line = line * 16;
e0996aea 62 reg = 0x600818;
a0b25635
BS
63 mask = 0x00000011;
64 data = (dir << 4) | out;
65 } else
66 if (line < 10) {
67 line = (line - 2) * 4;
e0996aea 68 reg = 0x60081c;
b99da31e 69 mask = 0x00000003;
a0b25635
BS
70 data = (dir << 1) | out;
71 } else
72 if (line < 14) {
73 line = (line - 10) * 4;
e0996aea 74 reg = 0x600850;
a0b25635
BS
75 mask = 0x00000003;
76 data = (dir << 1) | out;
77 } else {
78 return -EINVAL;
79 }
6ee73861 80
e0996aea 81 nv_mask(gpio, reg, mask << line, data << line);
6ee73861
BS
82 return 0;
83}
47e5d5cb 84
47e5d5cb 85static void
e0996aea 86nv10_gpio_intr(struct nouveau_subdev *subdev)
47e5d5cb 87{
e0996aea
BS
88 struct nv10_gpio_priv *priv = (void *)subdev;
89 u32 intr = nv_rd32(priv, 0x001104);
47e5d5cb
BS
90 u32 hi = (intr & 0x0000ffff) >> 0;
91 u32 lo = (intr & 0xffff0000) >> 16;
4f47643d 92 int i;
47e5d5cb 93
4f47643d
BS
94 for (i = 0; (hi | lo) && i < 32; i++) {
95 if ((hi | lo) & (1 << i))
8e8832e8 96 nouveau_event_trigger(priv->base.events, 1, i);
4f47643d 97 }
47e5d5cb 98
e0996aea 99 nv_wr32(priv, 0x001104, intr);
47e5d5cb
BS
100}
101
4f47643d
BS
102static void
103nv10_gpio_intr_enable(struct nouveau_event *event, int line)
104{
105 nv_wr32(event->priv, 0x001104, 0x00010001 << line);
106 nv_mask(event->priv, 0x001144, 0x00010001 << line, 0x00010001 << line);
107}
108
109static void
110nv10_gpio_intr_disable(struct nouveau_event *event, int line)
111{
112 nv_wr32(event->priv, 0x001104, 0x00010001 << line);
113 nv_mask(event->priv, 0x001144, 0x00010001 << line, 0x00000000);
114}
115
e0996aea
BS
116static int
117nv10_gpio_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
118 struct nouveau_oclass *oclass, void *data, u32 size,
119 struct nouveau_object **pobject)
47e5d5cb 120{
e0996aea
BS
121 struct nv10_gpio_priv *priv;
122 int ret;
123
7356859a 124 ret = nouveau_gpio_create(parent, engine, oclass, &priv);
e0996aea
BS
125 *pobject = nv_object(priv);
126 if (ret)
127 return ret;
128
129 priv->base.drive = nv10_gpio_drive;
130 priv->base.sense = nv10_gpio_sense;
4f47643d
BS
131 priv->base.events->priv = priv;
132 priv->base.events->enable = nv10_gpio_intr_enable;
133 priv->base.events->disable = nv10_gpio_intr_disable;
e0996aea 134 nv_subdev(priv)->intr = nv10_gpio_intr;
47e5d5cb
BS
135 return 0;
136}
137
e0996aea
BS
138static void
139nv10_gpio_dtor(struct nouveau_object *object)
47e5d5cb 140{
e0996aea
BS
141 struct nv10_gpio_priv *priv = (void *)object;
142 nouveau_gpio_destroy(&priv->base);
47e5d5cb 143}
e0996aea
BS
144
145static int
146nv10_gpio_init(struct nouveau_object *object)
147{
148 struct nv10_gpio_priv *priv = (void *)object;
149 int ret;
150
151 ret = nouveau_gpio_init(&priv->base);
152 if (ret)
153 return ret;
154
e0996aea
BS
155 nv_wr32(priv, 0x001144, 0x00000000);
156 nv_wr32(priv, 0x001104, 0xffffffff);
157 return 0;
158}
159
160static int
161nv10_gpio_fini(struct nouveau_object *object, bool suspend)
162{
163 struct nv10_gpio_priv *priv = (void *)object;
e0996aea
BS
164 nv_wr32(priv, 0x001144, 0x00000000);
165 return nouveau_gpio_fini(&priv->base, suspend);
166}
167
d93174ec 168struct nouveau_oclass *
7356859a
BS
169nv10_gpio_oclass = &(struct nouveau_gpio_impl) {
170 .base.handle = NV_SUBDEV(GPIO, 0x10),
171 .base.ofuncs = &(struct nouveau_ofuncs) {
e0996aea
BS
172 .ctor = nv10_gpio_ctor,
173 .dtor = nv10_gpio_dtor,
174 .init = nv10_gpio_init,
175 .fini = nv10_gpio_fini,
176 },
7356859a
BS
177 .lines = 16,
178}.base;
This page took 0.369809 seconds and 5 git commands to generate.