blob: 419d6495649b238c30e1964ca3ea135b7df962d3 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
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
27#include "drmP.h"
28#include "nouveau_drv.h"
29#include "nouveau_hw.h"
30
Ben Skeggsa0b25632011-11-21 16:41:48 +100031int
32nv10_gpio_sense(struct drm_device *dev, int line)
Ben Skeggs6ee73862009-12-11 19:24:15 +100033{
Ben Skeggsa0b25632011-11-21 16:41:48 +100034 if (line < 2) {
35 line = line * 16;
36 line = NVReadCRTC(dev, 0, NV_PCRTC_GPIO) >> line;
37 return !!(line & 0x0100);
38 } else
39 if (line < 10) {
40 line = (line - 2) * 4;
41 line = NVReadCRTC(dev, 0, NV_PCRTC_GPIO_EXT) >> line;
42 return !!(line & 0x04);
43 } else
44 if (line < 14) {
45 line = (line - 10) * 4;
46 line = NVReadCRTC(dev, 0, NV_PCRTC_850) >> line;
47 return !!(line & 0x04);
Ben Skeggs6ee73862009-12-11 19:24:15 +100048 }
49
Ben Skeggsa0b25632011-11-21 16:41:48 +100050 return -EINVAL;
Ben Skeggs6ee73862009-12-11 19:24:15 +100051}
52
53int
Ben Skeggsa0b25632011-11-21 16:41:48 +100054nv10_gpio_drive(struct drm_device *dev, int line, int dir, int out)
Ben Skeggs6ee73862009-12-11 19:24:15 +100055{
Ben Skeggsa0b25632011-11-21 16:41:48 +100056 u32 reg, mask, data;
Ben Skeggs6ee73862009-12-11 19:24:15 +100057
Ben Skeggsa0b25632011-11-21 16:41:48 +100058 if (line < 2) {
59 line = line * 16;
60 reg = NV_PCRTC_GPIO;
61 mask = 0x00000011;
62 data = (dir << 4) | out;
63 } else
64 if (line < 10) {
65 line = (line - 2) * 4;
66 reg = NV_PCRTC_GPIO_EXT;
67 mask = 0x00000003 << ((line - 2) * 4);
68 data = (dir << 1) | out;
69 } else
70 if (line < 14) {
71 line = (line - 10) * 4;
72 reg = NV_PCRTC_850;
73 mask = 0x00000003;
74 data = (dir << 1) | out;
75 } else {
76 return -EINVAL;
77 }
Ben Skeggs6ee73862009-12-11 19:24:15 +100078
Ben Skeggsa0b25632011-11-21 16:41:48 +100079 mask = NVReadCRTC(dev, 0, reg) & ~(mask << line);
80 NVWriteCRTC(dev, 0, reg, mask | (data << line));
Ben Skeggs6ee73862009-12-11 19:24:15 +100081 return 0;
82}