2 * Copyright (C) 2009-2010 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 internal const string SYSFS_RESUME_REASON_PATH = "/class/i2c-adapter/i2c-0/0-0073/neo1973-resume.0/resume_reason";
25 internal const string SYSFS_RESUME_SUBREASON_PATH = "/class/i2c-adapter/i2c-0/0-0073/resume_reason";
27 class LowLevel.Openmoko : FsoUsage.LowLevel, FsoFramework.AbstractObject
29 private HashTable<string,uint> intmap1;
30 private HashTable<string,uint> intmap2;
34 logger.info( "Registering openmoko low level suspend/resume handling" );
36 var sysfs_root = config.stringValue( "cornucopia", "sysfs_root", "/sys" );
37 sys_power_state = Path.build_filename( sysfs_root, "power", "state" );
38 sys_resume_reason = Path.build_filename( sysfs_root, SYSFS_RESUME_REASON_PATH );
39 sys_resume_subreason = Path.build_filename( sysfs_root, SYSFS_RESUME_SUBREASON_PATH );
41 intmap1 = new HashTable<string,uint>( str_hash, str_equal );
42 intmap1.insert( "EINT00_ACCEL1", ResumeReason.Accelerometer );
43 intmap1.insert( "EINT01_GSM", ResumeReason.GSM );
44 intmap1.insert( "EINT02_BLUETOOTH", ResumeReason.Bluetooth );
45 intmap1.insert( "EINT03_DEBUGBRD", ResumeReason.Debug );
46 intmap1.insert( "EINT04_JACK", ResumeReason.Headphone );
47 intmap1.insert( "EINT05_WLAN", ResumeReason.WiFi );
48 intmap1.insert( "EINT06_AUXKEY", ResumeReason.AuxKey );
49 intmap1.insert( "EINT07_HOLDKEY", ResumeReason.Headphone );
50 intmap1.insert( "EINT08_ACCEL2", ResumeReason.Accelerometer );
51 intmap1.insert( "EINT09_PMU", ResumeReason.PMU );
52 intmap1.insert( "EINT10_NULL", ResumeReason.Invalid );
53 intmap1.insert( "EINT11_NULL", ResumeReason.Invalid );
54 intmap1.insert( "EINT12_GLAMO", ResumeReason.GFX );
55 intmap1.insert( "EINT13_NULL", ResumeReason.Invalid );
56 intmap1.insert( "EINT14_NULL", ResumeReason.Invalid );
57 intmap1.insert( "EINT15_NULL", ResumeReason.Invalid );
59 intmap2 = new HashTable<string,uint>( str_hash, str_equal );
60 intmap2.insert( "0000000200", ResumeReason.LowBattery );
61 intmap2.insert( "0002000000", ResumeReason.PowerKey );
64 public override string repr()
71 FsoFramework.FileHandling.write( "mem\n", sys_power_state );
74 public ResumeReason resume()
76 var reasons = FsoFramework.FileHandling.read( sys_resume_reason ).split( "\n" );
77 var reasonkey = "unknown";
78 foreach ( var line in reasons )
80 if ( line.has_prefix( "*" ) )
82 reasonkey = line.substring( 2 );
86 var reasonvalue = intmap1.lookup( reasonkey );
87 if ( reasonvalue == 0 )
89 logger.info( "No resume reason marked in %s".printf( sys_resume_reason ) );
90 return ResumeReason.Unknown;
93 if ( reasonvalue == ResumeReason.PMU )
95 logger.debug( "PMU resume reason marked in %s".printf( sys_resume_reason ) );
97 var subreasonkey = FsoFramework.FileHandling.read( sys_resume_subreason );
98 var subreasonvalue = intmap2.lookup( subreasonkey );
99 if ( subreasonvalue == 0 )
101 logger.debug( "Unknown subreason %s for PMU resume, please fix me!".printf( subreasonkey ) );
102 return ResumeReason.PMU;
104 return (ResumeReason)subreasonvalue;
106 return (ResumeReason)reasonvalue;
110 string sys_power_state;
111 string sys_resume_reason;
112 string sys_resume_subreason;
115 * This function gets called on plugin initialization time.
116 * @return the name of your plugin here
117 * @note that it needs to be a name in the format <subsystem>.<plugin>
118 * else your module will be unloaded immediately.
120 public static string fso_factory_function( FsoFramework.Subsystem subsystem ) throws Error
122 FsoFramework.theLogger.debug( "lowlevel_openmoko fso_factory_function" );
123 return "fsousage.lowlevel_openmoko";
127 public static void fso_register_function( TypeModule module )
129 // do not remove this function