Skip to content
Newer
Older
100644 142 lines (115 sloc) 3.46 KB
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored May 29, 2010
1 /*
2 * Copyright 2010 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 "nouveau_drv.h"
26 #include "nouveau_hw.h"
27
28 static int
29 nv50_gpio_location(struct dcb_gpio_entry *gpio, uint32_t *reg, uint32_t *shift)
30 {
31 const uint32_t nv50_gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 };
32
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored Aug 2, 2010
33 if (gpio->line >= 32)
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored May 29, 2010
34 return -EINVAL;
35
36 *reg = nv50_gpio_reg[gpio->line >> 3];
37 *shift = (gpio->line & 7) << 2;
38 return 0;
39 }
40
41 int
42 nv50_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag)
43 {
44 struct dcb_gpio_entry *gpio;
45 uint32_t r, s, v;
46
47 gpio = nouveau_bios_gpio_entry(dev, tag);
48 if (!gpio)
49 return -ENOENT;
50
51 if (nv50_gpio_location(gpio, &r, &s))
52 return -EINVAL;
53
54 v = nv_rd32(dev, r) >> (s + 2);
55 return ((v & 1) == (gpio->state[1] & 1));
56 }
57
58 int
59 nv50_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state)
60 {
61 struct dcb_gpio_entry *gpio;
62 uint32_t r, s, v;
63
64 gpio = nouveau_bios_gpio_entry(dev, tag);
65 if (!gpio)
66 return -ENOENT;
67
68 if (nv50_gpio_location(gpio, &r, &s))
69 return -EINVAL;
70
71 v = nv_rd32(dev, r) & ~(0x3 << s);
72 v |= (gpio->state[state] ^ 2) << s;
73 nv_wr32(dev, r, v);
74 return 0;
75 }
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored Aug 2, 2010
76
327ca9a @mlankhorst add nvd0 gpio based on darktamas commit
mlankhorst authored Apr 10, 2012
77 int
78 nvd0_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag)
79 {
80 struct dcb_gpio_entry *gpio;
81 u32 v;
82
83 gpio = nouveau_bios_gpio_entry(dev, tag);
84 if (!gpio)
85 return -ENOENT;
86
87 v = nv_rd32(dev, 0x00d610 + (gpio->line * 4));
88 v &= 0x00004000;
89 return (!!v == (gpio->state[1] & 1));
90 }
91
92 int
93 nvd0_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state)
94 {
95 struct dcb_gpio_entry *gpio;
96 u32 v;
97
98 gpio = nouveau_bios_gpio_entry(dev, tag);
99 if (!gpio)
100 return -ENOENT;
101
102 v = gpio->state[state] ^ 2;
103
104 nv_mask(dev, 0x00d610 + (gpio->line * 4), 0x00003000, v << 12);
105 return 0;
106 }
107
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored Aug 2, 2010
108 void
109 nv50_gpio_irq_enable(struct drm_device *dev, enum dcb_gpio_tag tag, bool on)
110 {
111 struct dcb_gpio_entry *gpio;
112 u32 reg, mask;
113
114 gpio = nouveau_bios_gpio_entry(dev, tag);
115 if (!gpio) {
116 NV_ERROR(dev, "gpio tag 0x%02x not found\n", tag);
117 return;
118 }
119
120 reg = gpio->line < 16 ? 0xe050 : 0xe070;
121 mask = 0x00010001 << (gpio->line & 0xf);
122
123 nv_wr32(dev, reg + 4, mask);
124 nv_mask(dev, reg + 0, mask, on ? mask : 0);
125 }
126
127 int
128 nv50_gpio_init(struct drm_device *dev)
129 {
130 struct drm_nouveau_private *dev_priv = dev->dev_private;
131
132 /* disable, and ack any pending gpio interrupts */
133 nv_wr32(dev, 0xe050, 0x00000000);
134 nv_wr32(dev, 0xe054, 0xffffffff);
135 if (dev_priv->chipset >= 0x90) {
136 nv_wr32(dev, 0xe070, 0x00000000);
137 nv_wr32(dev, 0xe074, 0xffffffff);
138 }
139
140 return 0;
141 }
Something went wrong with that request. Please try again.