This source file includes following definitions.
- nv10_gpio_sense
- nv10_gpio_drive
- nv10_gpio_intr_stat
- nv10_gpio_intr_mask
- nv10_gpio_new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include "priv.h"
27
28 static int
29 nv10_gpio_sense(struct nvkm_gpio *gpio, int line)
30 {
31 struct nvkm_device *device = gpio->subdev.device;
32 if (line < 2) {
33 line = line * 16;
34 line = nvkm_rd32(device, 0x600818) >> line;
35 return !!(line & 0x0100);
36 } else
37 if (line < 10) {
38 line = (line - 2) * 4;
39 line = nvkm_rd32(device, 0x60081c) >> line;
40 return !!(line & 0x04);
41 } else
42 if (line < 14) {
43 line = (line - 10) * 4;
44 line = nvkm_rd32(device, 0x600850) >> line;
45 return !!(line & 0x04);
46 }
47
48 return -EINVAL;
49 }
50
51 static int
52 nv10_gpio_drive(struct nvkm_gpio *gpio, int line, int dir, int out)
53 {
54 struct nvkm_device *device = gpio->subdev.device;
55 u32 reg, mask, data;
56
57 if (line < 2) {
58 line = line * 16;
59 reg = 0x600818;
60 mask = 0x00000011;
61 data = (dir << 4) | out;
62 } else
63 if (line < 10) {
64 line = (line - 2) * 4;
65 reg = 0x60081c;
66 mask = 0x00000003;
67 data = (dir << 1) | out;
68 } else
69 if (line < 14) {
70 line = (line - 10) * 4;
71 reg = 0x600850;
72 mask = 0x00000003;
73 data = (dir << 1) | out;
74 } else {
75 return -EINVAL;
76 }
77
78 nvkm_mask(device, reg, mask << line, data << line);
79 return 0;
80 }
81
82 static void
83 nv10_gpio_intr_stat(struct nvkm_gpio *gpio, u32 *hi, u32 *lo)
84 {
85 struct nvkm_device *device = gpio->subdev.device;
86 u32 intr = nvkm_rd32(device, 0x001104);
87 u32 stat = nvkm_rd32(device, 0x001144) & intr;
88 *lo = (stat & 0xffff0000) >> 16;
89 *hi = (stat & 0x0000ffff);
90 nvkm_wr32(device, 0x001104, intr);
91 }
92
93 static void
94 nv10_gpio_intr_mask(struct nvkm_gpio *gpio, u32 type, u32 mask, u32 data)
95 {
96 struct nvkm_device *device = gpio->subdev.device;
97 u32 inte = nvkm_rd32(device, 0x001144);
98 if (type & NVKM_GPIO_LO)
99 inte = (inte & ~(mask << 16)) | (data << 16);
100 if (type & NVKM_GPIO_HI)
101 inte = (inte & ~mask) | data;
102 nvkm_wr32(device, 0x001144, inte);
103 }
104
105 static const struct nvkm_gpio_func
106 nv10_gpio = {
107 .lines = 16,
108 .intr_stat = nv10_gpio_intr_stat,
109 .intr_mask = nv10_gpio_intr_mask,
110 .drive = nv10_gpio_drive,
111 .sense = nv10_gpio_sense,
112 };
113
114 int
115 nv10_gpio_new(struct nvkm_device *device, int index, struct nvkm_gpio **pgpio)
116 {
117 return nvkm_gpio_new_(&nv10_gpio, device, index, pgpio);
118 }