geode_dcon.c revision f29dbc25
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/* Includes that are used by all drivers */ 31#include <xf86.h> 32#include <xf86_OSproc.h> 33#include <compiler.h> 34 35#include "geode.h" 36#include <unistd.h> 37#include <fcntl.h> 38 39#define DCON_SLEEP_FILE "/sys/devices/platform/dcon/sleep" 40 41static Bool 42dcon_present(void) 43{ 44 static int _dval = -1; 45 46 if (_dval == -1) 47 _dval = (access("/sys/class/power_supply/olpc-ac", F_OK) == 0); 48 49 return (Bool) _dval; 50} 51 52int 53DCONDPMSSet(ScrnInfoPtr pScrni, int mode) 54{ 55 static int failed = -1; 56 int fd; 57 char value[1]; 58 59 if (failed == -1) 60 failed = !dcon_present(); 61 62 if (failed) 63 return 0; 64 65 fd = open(DCON_SLEEP_FILE, O_WRONLY); 66 67 if (fd < 0) { 68 failed = 1; 69 return 0; 70 } 71 72 switch (mode) { 73 case DPMSModeOn: 74 value[0] = '0'; 75 break; 76 case DPMSModeStandby: 77 case DPMSModeSuspend: 78 case DPMSModeOff: 79 value[0] = '1'; 80 break; 81 } 82 83 write(fd, value, sizeof(value)); 84 close(fd); 85 86 return 1; 87} 88 89Bool 90dcon_init(ScrnInfoPtr pScrni) 91{ 92 GeodeRec *pGeode = GEODEPTR(pScrni); 93 94 pGeode->mm_width = 0; 95 pGeode->mm_height = 0; 96 97 if (!dcon_present()) { 98 xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT, "No DCON is present\n"); 99 return FALSE; 100 } 101 102 pGeode->panelMode = xnfcalloc(1, sizeof(DisplayModeRec)); 103 if (pGeode->panelMode == NULL) 104 return FALSE; 105 106 /* Set up the panel mode structure automagically */ 107 108 pGeode->panelMode->type = M_T_DRIVER|M_T_PREFERRED; 109 pGeode->panelMode->Clock = 57275; 110 pGeode->panelMode->HDisplay = 1200; 111 pGeode->panelMode->HSyncStart = 1208; 112 pGeode->panelMode->HSyncEnd = 1216; 113 pGeode->panelMode->HTotal = 1240; 114 pGeode->panelMode->VDisplay = 900; 115 pGeode->panelMode->VSyncStart = 905; 116 pGeode->panelMode->VSyncEnd = 908; 117 pGeode->panelMode->VTotal = 912; 118 pGeode->panelMode->Flags = V_NHSYNC | V_NVSYNC; 119 120 pGeode->mm_width = 152; 121 pGeode->mm_height = 114; 122 123 xf86SetModeDefaultName(pGeode->panelMode); 124 125 /* TODO: Print board revision once sysfs exports it. */ 126 xf86DrvMsg(pScrni->scrnIndex, X_DEFAULT, "DCON detected.\n"); 127 128 return TRUE; 129} 130