• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Red Hat Inc.
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: Ben Skeggs
23  */
24 
25 #include "priv.h"
26 
27 struct nve0_gpio_priv {
28 	struct nouveau_gpio base;
29 };
30 
31 void
nve0_gpio_intr(struct nouveau_subdev * subdev)32 nve0_gpio_intr(struct nouveau_subdev *subdev)
33 {
34 	struct nve0_gpio_priv *priv = (void *)subdev;
35 	u32 intr0 = nv_rd32(priv, 0xdc00) & nv_rd32(priv, 0xdc08);
36 	u32 intr1 = nv_rd32(priv, 0xdc80) & nv_rd32(priv, 0xdc88);
37 	u32 hi = (intr0 & 0x0000ffff) | (intr1 << 16);
38 	u32 lo = (intr0 >> 16) | (intr1 & 0xffff0000);
39 	int i;
40 
41 	for (i = 0; (hi | lo) && i < 32; i++) {
42 		if ((hi | lo) & (1 << i))
43 			nouveau_event_trigger(priv->base.events, i);
44 	}
45 
46 	nv_wr32(priv, 0xdc00, intr0);
47 	nv_wr32(priv, 0xdc88, intr1);
48 }
49 
50 void
nve0_gpio_intr_enable(struct nouveau_event * event,int line)51 nve0_gpio_intr_enable(struct nouveau_event *event, int line)
52 {
53 	const u32 addr = line < 16 ? 0xdc00 : 0xdc80;
54 	const u32 mask = 0x00010001 << (line & 0xf);
55 	nv_wr32(event->priv, addr + 0x08, mask);
56 	nv_mask(event->priv, addr + 0x00, mask, mask);
57 }
58 
59 void
nve0_gpio_intr_disable(struct nouveau_event * event,int line)60 nve0_gpio_intr_disable(struct nouveau_event *event, int line)
61 {
62 	const u32 addr = line < 16 ? 0xdc00 : 0xdc80;
63 	const u32 mask = 0x00010001 << (line & 0xf);
64 	nv_wr32(event->priv, addr + 0x08, mask);
65 	nv_mask(event->priv, addr + 0x00, mask, 0x00000000);
66 }
67 
68 int
nve0_gpio_fini(struct nouveau_object * object,bool suspend)69 nve0_gpio_fini(struct nouveau_object *object, bool suspend)
70 {
71 	struct nve0_gpio_priv *priv = (void *)object;
72 	nv_wr32(priv, 0xdc08, 0x00000000);
73 	nv_wr32(priv, 0xdc88, 0x00000000);
74 	return nouveau_gpio_fini(&priv->base, suspend);
75 }
76 
77 int
nve0_gpio_init(struct nouveau_object * object)78 nve0_gpio_init(struct nouveau_object *object)
79 {
80 	struct nve0_gpio_priv *priv = (void *)object;
81 	int ret;
82 
83 	ret = nouveau_gpio_init(&priv->base);
84 	if (ret)
85 		return ret;
86 
87 	nv_wr32(priv, 0xdc00, 0xffffffff);
88 	nv_wr32(priv, 0xdc80, 0xffffffff);
89 	return 0;
90 }
91 
92 void
nve0_gpio_dtor(struct nouveau_object * object)93 nve0_gpio_dtor(struct nouveau_object *object)
94 {
95 	struct nve0_gpio_priv *priv = (void *)object;
96 	nouveau_gpio_destroy(&priv->base);
97 }
98 
99 static int
nve0_gpio_ctor(struct nouveau_object * parent,struct nouveau_object * engine,struct nouveau_oclass * oclass,void * data,u32 size,struct nouveau_object ** pobject)100 nve0_gpio_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
101 	       struct nouveau_oclass *oclass, void *data, u32 size,
102 	       struct nouveau_object **pobject)
103 {
104 	struct nve0_gpio_priv *priv;
105 	int ret;
106 
107 	ret = nouveau_gpio_create(parent, engine, oclass, 32, &priv);
108 	*pobject = nv_object(priv);
109 	if (ret)
110 		return ret;
111 
112 	priv->base.reset = nvd0_gpio_reset;
113 	priv->base.drive = nvd0_gpio_drive;
114 	priv->base.sense = nvd0_gpio_sense;
115 	priv->base.events->priv = priv;
116 	priv->base.events->enable = nve0_gpio_intr_enable;
117 	priv->base.events->disable = nve0_gpio_intr_disable;
118 	nv_subdev(priv)->intr = nve0_gpio_intr;
119 	return 0;
120 }
121 
122 struct nouveau_oclass
123 nve0_gpio_oclass = {
124 	.handle = NV_SUBDEV(GPIO, 0xe0),
125 	.ofuncs = &(struct nouveau_ofuncs) {
126 		.ctor = nve0_gpio_ctor,
127 		.dtor = nv50_gpio_dtor,
128 		.init = nve0_gpio_init,
129 		.fini = nve0_gpio_fini,
130 	},
131 };
132