2 * Copyright (C) 2009 Francisco Jerez.
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:
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.
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.
29 nv10_gpio_sense(struct nvkm_gpio *gpio, int line)
31 struct nvkm_device *device = gpio->subdev.device;
34 line = nvkm_rd32(device, 0x600818) >> line;
35 return !!(line & 0x0100);
38 line = (line - 2) * 4;
39 line = nvkm_rd32(device, 0x60081c) >> line;
40 return !!(line & 0x04);
43 line = (line - 10) * 4;
44 line = nvkm_rd32(device, 0x600850) >> line;
45 return !!(line & 0x04);
52 nv10_gpio_drive(struct nvkm_gpio *gpio, int line, int dir, int out)
54 struct nvkm_device *device = gpio->subdev.device;
61 data = (dir << 4) | out;
64 line = (line - 2) * 4;
67 data = (dir << 1) | out;
70 line = (line - 10) * 4;
73 data = (dir << 1) | out;
78 nvkm_mask(device, reg, mask << line, data << line);
83 nv10_gpio_intr_stat(struct nvkm_gpio *gpio, u32 *hi, u32 *lo)
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);
94 nv10_gpio_intr_mask(struct nvkm_gpio *gpio, u32 type, u32 mask, u32 data)
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);
106 nv10_gpio_oclass = &(struct nvkm_gpio_impl) {
107 .base.handle = NV_SUBDEV(GPIO, 0x10),
108 .base.ofuncs = &(struct nvkm_ofuncs) {
109 .ctor = _nvkm_gpio_ctor,
110 .dtor = _nvkm_gpio_dtor,
111 .init = _nvkm_gpio_init,
112 .fini = _nvkm_gpio_fini,
115 .intr_stat = nv10_gpio_intr_stat,
116 .intr_mask = nv10_gpio_intr_mask,
117 .drive = nv10_gpio_drive,
118 .sense = nv10_gpio_sense,