Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 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 Skeggs | a0b2563 | 2011-11-21 16:41:48 +1000 | [diff] [blame^] | 31 | int |
| 32 | nv10_gpio_sense(struct drm_device *dev, int line) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 33 | { |
Ben Skeggs | a0b2563 | 2011-11-21 16:41:48 +1000 | [diff] [blame^] | 34 | 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 Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 48 | } |
| 49 | |
Ben Skeggs | a0b2563 | 2011-11-21 16:41:48 +1000 | [diff] [blame^] | 50 | return -EINVAL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | int |
Ben Skeggs | a0b2563 | 2011-11-21 16:41:48 +1000 | [diff] [blame^] | 54 | nv10_gpio_drive(struct drm_device *dev, int line, int dir, int out) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 55 | { |
Ben Skeggs | a0b2563 | 2011-11-21 16:41:48 +1000 | [diff] [blame^] | 56 | u32 reg, mask, data; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 57 | |
Ben Skeggs | a0b2563 | 2011-11-21 16:41:48 +1000 | [diff] [blame^] | 58 | 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 Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 78 | |
Ben Skeggs | a0b2563 | 2011-11-21 16:41:48 +1000 | [diff] [blame^] | 79 | mask = NVReadCRTC(dev, 0, reg) & ~(mask << line); |
| 80 | NVWriteCRTC(dev, 0, reg, mask | (data << line)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 81 | return 0; |
| 82 | } |