1/* Copyright (c) 2006 Advanced Micro Devices, Inc. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * of this software and associated documentation files (the "Software"), to 5 * deal in the Software without restriction, including without limitation the 6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 * sell copies of the Software, and to permit persons to whom the Software is 8 * furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 * IN THE SOFTWARE. 20 * 21 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its 22 * contributors may be used to endorse or promote products derived from this 23 * software without specific prior written permission. 24 * */ 25 26#ifdef HAVE_CONFIG_H 27#include "config.h" 28#endif 29 30#include "xorg-server.h" 31 32/* Includes that are used by all drivers */ 33#include <xf86.h> 34#include <xf86Modes.h> 35#include <xf86_OSproc.h> 36#include <compiler.h> 37 38#include "geode.h" 39#include <unistd.h> 40#include <fcntl.h> 41 42#define DCON_SLEEP_FILE "/sys/devices/platform/dcon/sleep" 43#define DCON_FREEZE_FILE "/sys/devices/platform/dcon/freeze" 44 45static Bool 46dcon_present(void) 47{ 48 static int _dval = -1; 49 50 if (_dval == -1) 51 _dval = (access("/sys/class/power_supply/olpc-ac", F_OK) == 0); 52 53 return (Bool) _dval; 54} 55 56int 57DCONDPMSSet(ScrnInfoPtr pScrni, int mode) 58{ 59 static int failed = -1; 60 ssize_t ret; 61 int fd; 62 char value[1]; 63 64 if (failed == -1) 65 failed = !dcon_present(); 66 67 if (failed) 68 return 0; 69 70 /* If the DCON is frozen, don't power it down, it was probably frozen 71 * for a reason and powering it down would corrupt the display. 72 * This is needed to avoid losing OLPC's frozen boot image during X 73 * startup, where DPMS is used to power down and up the display. 74 * When geode uses KMS this will not be needed as the system realises 75 * that no mode change is needed and the display power is untouched. */ 76 fd = open(DCON_FREEZE_FILE, O_RDONLY); 77 if (fd < 0) { 78 failed = 1; 79 return 0; 80 } 81 82 ret = read(fd, value, 1); 83 close(fd); 84 if (ret == 1) { 85 if (value[0] == '1') 86 return 0; 87 } 88 89 fd = open(DCON_SLEEP_FILE, O_WRONLY); 90 91 if (fd < 0) { 92 failed = 1; 93 return 0; 94 } 95 96 switch (mode) { 97 case DPMSModeOn: 98 value[0] = '0'; 99 break; 100 case DPMSModeStandby: 101 case DPMSModeSuspend: 102 case DPMSModeOff: 103 value[0] = '1'; 104 break; 105 } 106 107 ret = write(fd, value, sizeof(value)); 108 close(fd); 109 110 if (ret < 0) { 111 failed = 1; 112 return 0; 113 } 114 115 return 1; 116} 117 118Bool 119dcon_init(ScrnInfoPtr pScrni) 120{ 121 GeodeRec *pGeode = GEODEPTR(pScrni); 122 123 pGeode->mm_width = 0; 124 pGeode->mm_height = 0; 125 126 if (!dcon_present()) { 127 xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT, "No DCON is present\n"); 128 return FALSE; 129 } 130 131 pGeode->panelMode = xnfcalloc(1, sizeof(DisplayModeRec)); 132 if (pGeode->panelMode == NULL) 133 return FALSE; 134 135 /* Set up the panel mode structure automagically */ 136 137 pGeode->panelMode->type = M_T_DRIVER | M_T_PREFERRED; 138 pGeode->panelMode->Clock = 57275; 139 pGeode->panelMode->HDisplay = 1200; 140 pGeode->panelMode->HSyncStart = 1208; 141 pGeode->panelMode->HSyncEnd = 1216; 142 pGeode->panelMode->HTotal = 1240; 143 pGeode->panelMode->VDisplay = 900; 144 pGeode->panelMode->VSyncStart = 905; 145 pGeode->panelMode->VSyncEnd = 908; 146 pGeode->panelMode->VTotal = 912; 147 pGeode->panelMode->Flags = V_NHSYNC | V_NVSYNC; 148 149 pGeode->mm_width = 152; 150 pGeode->mm_height = 114; 151 152 xf86SetModeDefaultName(pGeode->panelMode); 153 154 /* TODO: Print board revision once sysfs exports it. */ 155 xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT, "DCON detected.\n"); 156 157 return TRUE; 158} 159