[PATCH] Backlight support for iPaq's with 2.6 kernel
Paul Sokolovsky <[email protected]> Fri, 26 Jan 2007 04:05:52 +0200
| Newsgroups | gmane.comp.handhelds.opie.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello opie-devel, Here's the patch based on older submission by Slavek Banko, http://www.handhelds.org/hypermail/opie-devel/29/2921.html . Slavek Banko's patch tried to provide that support for all devices, which is worthy goal, but I'm afraid, it cannot be said that the patch is too clean. It tries to mix support for 2.4 and 2.6 models in one device file, and that's a bit risky, not saying tangled. So, instead I'd like to submit patch for quite some time present in OE. With it, Slavek's code is applied only to odevice_ipaq.cpp. That's still dirty, but at least we can be sure it doesn't affect other models. As for iPaqs, it's easily reviewable that it preserves support for 2.4 models, and by now well tested on 2.6 models (h3900, h4000, hx4700, etc). I propose this to be committed for 1.2.3. At later time, this stuff should be rewritten in a sane OO manner, using proper class hierarchy based on kernel version. -- Best regards, Paul mailto:[email protected] _______________________________________________ http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex Opie-devel mailing list [email protected] https://handhelds.org/mailman/listinfo/opie-devel
ipaq-2.6-sys-class-backlight-support.patch
(application/octet-stream, 4.4 KB)
Index: libopie2/opiecore/device/odevice_ipaq.cpp
===================================================================
RCS file: /cvs/opie/libopie2/opiecore/device/odevice_ipaq.cpp,v
retrieving revision 1.26
diff -u -r1.26 odevice_ipaq.cpp
--- libopie2/opiecore/device/odevice_ipaq.cpp 2 Aug 2006 19:12:39 -0000 1.26
+++ libopie2/opiecore/device/odevice_ipaq.cpp 11 Oct 2006 00:46:38 -0000
@@ -408,45 +408,19 @@
if ( bright < 0 )
bright = 0;
- QString cmdline;
-
- switch ( model()) {
- case Model_iPAQ_H191x:
- case Model_iPAQ_H4xxx:
- {
- QDir sysClass( "/sys/class/backlight/pxafb/" );
- sysClass.setFilter(QDir::Dirs);
- int fd;
- if ( sysClass.exists() ) {
- QString sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/power" );
- fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
- if ( fd ) {
- char buf[10];
- buf[0] = bright ? 0 : 4;
- buf[1] = '\0';
- res = ( ::write( fd, &buf[0], 2 ) == 0 );
- ::close( fd );
- }
- sysClassPath = sysClass.absFilePath( "/sys/class/backlight/pxafb/brightness" );
- fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
- if ( fd ) {
- char buf[100];
- int len = ::snprintf( &buf[0], sizeof buf, "%d", bright );
- res = ( ::write( fd, &buf[0], len ) == 0 );
- ::close( fd );
- }
- }
- }
- break;
-
- case Model_iPAQ_HX4700:
- cmdline = QString::fromLatin1( "echo %1 > /sys/class/backlight/w100fb/brightness" ).arg( bright );
- // No Global::shellQuote as we gurantee it to be sane
- res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
- break;
-
-
- default:
+ QDir sysClass( "/sys/class/backlight/" );
+ sysClass.setFilter(QDir::Dirs);
+ if ( sysClass.exists() && sysClass.count() > 2 ) {
+ QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/brightness" );
+ int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK );
+ if ( fd ) {
+ char buf[100];
+ int val = bright * displayBrightnessResolution() / 255;
+ int len = ::snprintf( &buf[0], sizeof buf, "%d", val );
+ res = ( ::write( fd, &buf[0], len ) == 0 );
+ ::close( fd );
+ }
+ } else {
if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
FLITE_IN bl;
bl. mode = 1;
@@ -456,11 +430,28 @@
::close ( fd );
}
}
+
return res;
}
int iPAQ::displayBrightnessResolution() const
{
+ int res = 16;
+
+ QDir sysClass( "/sys/class/backlight/" );
+ sysClass.setFilter(QDir::Dirs);
+ if ( sysClass.exists() && sysClass.count() > 2 ) {
+ QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/max_brightness" );
+ int fd = ::open( sysClassPath, O_RDONLY|O_NONBLOCK );
+ if ( fd ) {
+ char buf[100];
+ if ( ::read( fd, &buf[0], sizeof buf ) )
+ ::sscanf( &buf[0], "%d", &res );
+ ::close( fd );
+ }
+ return res;
+ }
+
switch ( model()) {
case Model_iPAQ_H31xx:
case Model_iPAQ_H36xx:
@@ -489,27 +480,22 @@
QString cmdline;
- if ( model() == Model_iPAQ_H191x ) {
- QDir sysClass( "/sys/class/lcd/pxafb/" );
- sysClass.setFilter(QDir::Dirs);
- if ( sysClass.exists() ) {
- QString sysClassPath = sysClass.absFilePath( "/sys/class/lcd/pxafb/power" );
- int fd = ::open( sysClassPath, O_WRONLY | O_NONBLOCK );
- if ( fd ) {
- char buf[10];
- buf[0] = on ? 0 : 4;
- buf[1] = '\0';
- res = ( ::write( fd, &buf[0], 2 ) == 0 );
- ::close( fd );
- }
- }
- return res;
+ QDir sysClass( "/sys/class/lcd/" );
+ sysClass.setFilter(QDir::Dirs);
+ if ( sysClass.exists() && sysClass.count() > 2 ) {
+ QString sysClassPath = sysClass.absFilePath( sysClass[2] + "/power" );
+ int fd = ::open( sysClassPath, O_WRONLY|O_NONBLOCK );
+ if ( fd ) {
+ char buf[10];
+ buf[0] = on ? 0 : 4;
+ buf[1] = '\0';
+ res = ( ::write( fd, &buf[0], 2 ) == 0 );
+ ::close( fd );
+ }
} else {
- return OAbstractMobileDevice::setDisplayStatus(on);
+ res = OAbstractMobileDevice::setDisplayStatus(on);
}
- res = ( ::system( QFile::encodeName(cmdline) ) == 0 );
-
return res;
}
@@ -517,6 +503,7 @@
{
switch (model()) {
case Model_iPAQ_H191x:
+ case Model_iPAQ_H22xx:
case Model_iPAQ_H4xxx:
return false;
default: