/* * Copyright (c) 2013 Yasushi Oshima, All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY YASUSHI OSHIMA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. */ #include #include #include #include #include #include #include #include #include #include #include #include "crtmod.h" #include "crtmodfunc.h" static SetRegs modes[20] = { { 91, 9, 17, 81, 567, 5, 40, 552, 27, 0x415 }, /* 512*512*4 in 1024*1024/Hi */ { 75, 3, 5, 69, 259, 2, 16, 256, 44, 0x405 }, /* 512*512*4 in 1024*1024/Lo */ { 45, 4, 6, 38, 567, 5, 40, 552, 27, 0x410 }, /* 256*256*4 in 1024*1024/Hi */ { 37, 1, 0, 32, 259, 2, 16, 256, 36, 0x400 }, /* 256*256*4 in 1024*1024/Lo */ { 91, 9, 17, 81, 567, 5, 40, 552, 27, 0x15 }, /* 512*512*4 in 512*512/Hi */ { 75, 3, 5, 69, 259, 2, 16, 256, 44, 0x05 }, /* 512*512*4 in 512*512/Lo */ { 45, 4, 6, 38, 567, 5, 40, 552, 27, 0x10 }, /* 256*256*4 in 512*512/Hi */ { 37, 1, 0, 32, 259, 2, 16, 256, 36, 0x00 }, /* 256*256*4 in 512*512/Lo */ { 91, 9, 17, 81, 567, 5, 40, 552, 27, 0x115 }, /* 512*512*8 in 512*512/Hi */ { 75, 3, 5, 69, 259, 2, 16, 256, 44, 0x105 }, /* 512*512*8 in 512*512/Lo */ { 45, 4, 6, 38, 567, 5, 40, 552, 27, 0x110 }, /* 256*256*8 in 512*512/Hi */ { 37, 1, 0, 32, 259, 2, 16, 256, 36, 0x100 }, /* 256*256*8 in 512*512/Lo */ { 91, 9, 17, 81, 567, 5, 40, 552, 27, 0x315 }, /* 512*512*16 in 512*512/Hi */ { 75, 3, 5, 69, 259, 2, 16, 256, 44, 0x305 }, /* 512*512*16 in 512*512/Lo */ { 45, 4, 6, 38, 567, 5, 40, 552, 27, 0x310 }, /* 256*256*16 in 512*512/Hi */ { 37, 1, 0, 32, 259, 2, 16, 256, 36, 0x300 }, /* 256*256*16 in 512*512/Lo */ {137, 14, 28,124, 567, 5, 40, 552, 27, 0x416 }, /* 768*512*4 in 1024*1024/Hi */ {137, 14, 28,124, 567, 5, 40, 552, 27, 0x416 }, /* XXX: 1024*400*4 in 1024*1024/Mi */ {137, 14, 28,124, 567, 5, 40, 552, 27, 0x416 }, /* XXX: 1024*800*4 in 1024*1024/Mi */ { 99, 11, 13, 93, 524, 1, 33, 513, 27, 0x417 } /* 640*480*4 in 1024*1024/VGA */ }; int setCrtmode(int n) { int grfdev; FbReg *regs; struct grfinfo gfi; SetRegs *sr; int ret; if ((grfdev = open ("/dev/grf1", O_RDWR, 0)) < 0 ) { return -1; } if (ioctl(grfdev, GRFIOCGINFO, &gfi) == -1 ) { close(grfdev); return -1; } if ( (regs = (FbReg *) mmap (0, sizeof(FbReg), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, grfdev, 0) ) == (FbReg *)-1 ) { close(grfdev); return -1; } if ( n < 20 ) { sr = &(modes[n]); regs->crtc.r00 = sr->r00; regs->crtc.r01 = sr->r01; regs->crtc.r02 = sr->r02; regs->crtc.r03 = sr->r03; regs->crtc.r04 = sr->r04; regs->crtc.r05 = sr->r05; regs->crtc.r06= sr->r06; regs->crtc.r07= sr->r07; regs->crtc.r08= sr->r08; regs->crtc.r20 = sr->r20; regs->videoc.r0 = ((sr->r20)>>8)&7; ret = 0; } else { ret = -1; } munmap(regs, sizeof(FbReg)); close(grfdev); return ret; }