summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_simpad.cpp87
1 files changed, 68 insertions, 19 deletions
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp
index 2d0160d..fd46b95 100644
--- a/libopie2/opiecore/device/odevice_simpad.cpp
+++ b/libopie2/opiecore/device/odevice_simpad.cpp
@@ -187,24 +187,85 @@ void SIMpad::initButtons()
187#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave 187#define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave
188#define SIMPAD_RS232_ON 0x0400 188#define SIMPAD_RS232_ON 0x0400
189#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave 189#define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave
190#define SIMPAD_LED2_ON 0x1000 190#define SIMPAD_LED2_ON 0x1000
191#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode 191#define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode
192#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit 192#define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit
193#define SIMPAD_RESET_SIMCARD 0x8000 193#define SIMPAD_RESET_SIMCARD 0x8000
194 194
195//SIMpad touchscreen backlight strength control 195//SIMpad touchscreen backlight strength control
196#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL" 196#define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL"
197#define SIMPAD_BACKLIGHT_MASK 0x00a10044 197#define SIMPAD_BACKLIGHT_MASK 0x00a10044
198 198
199
200/*
201 * The SIMpad exposes ChipSelect3 to userspace
202 * via a proc filesystem file. Using this register
203 * one can toggle power of serial, irda, dect circuits
204 * change the video driver and display status and
205 * many more things.
206 * To not lose the current setting we read the current
207 * cs3 setting and toggle the necessary bits and then
208 * write it.
209 */
210static bool setCS3Bit( bool bitset, int bit ) {
211 int cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_RDONLY );
212
213 if ( cs3_fd < 0 )
214 return false;
215
216 static char line[32];
217 int val = 0;
218 bool ok = false;
219
220 /*
221 * try to read and parse the Chipselect3 status
222 * be paranoid and make sure line[31] is null
223 * terminated
224 */
225 while( !ok && ::read(cs3_fd, &line, sizeof(line)) > 0 ) {
226 line[31] = '\0';
227 if (::sscanf(line, "Chipselect3 : %x", &val ))
228 ok = true;
229 }
230
231 ::close(cs3_fd);
232
233 /*
234 * we were not able to find the current value
235 * and as a result we won't set it
236 */
237 if ( !ok )
238 return false;
239
240 /*
241 * change the value
242 */
243 val = bitset ? (val | bit) : (val & ~bit);
244
245 /*
246 * write it back
247 */
248 cs3_fd = ::open( SIMPAD_BOARDCONTROL, O_WRONLY );
249 if ( cs3_fd < 0 )
250 return false;
251
252 ::snprintf(line, sizeof(line), "0x%04x\n", val);
253 ::write(cs3_fd, line, strlen(line));
254 ::close(cs3_fd);
255
256 return true;
257}
258
259
199QValueList <OLed> SIMpad::ledList() const 260QValueList <OLed> SIMpad::ledList() const
200{ 261{
201 QValueList <OLed> vl; 262 QValueList <OLed> vl;
202 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? 263 vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one?
203 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway 264 //vl << Led_Mail; //TODO find out if LED1 is accessible anyway
204 return vl; 265 return vl;
205} 266}
206 267
207QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const 268QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const
208{ 269{
209 QValueList <OLedState> vl; 270 QValueList <OLedState> vl;
210 271
@@ -220,39 +281,30 @@ OLedState SIMpad::ledState ( OLed l ) const
220 switch ( l ) { 281 switch ( l ) {
221 case Led_Power: 282 case Led_Power:
222 return m_leds [0]; 283 return m_leds [0];
223 //case Led_Mail: 284 //case Led_Mail:
224 // return m_leds [1]; 285 // return m_leds [1];
225 default: 286 default:
226 return Led_Off; 287 return Led_Off;
227 } 288 }
228} 289}
229 290
230bool SIMpad::setLedState ( OLed l, OLedState st ) 291bool SIMpad::setLedState ( OLed l, OLedState st )
231{ 292{
232#if 0 293 if ( l == Led_Power ) {
233 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); 294 m_leds [0] = st;
234 295 setCS3Bit(st == Led_On, SIMPAD_LED2_ON);
235 /*TODO Implement this like that: 296 return true;
236 read from cs3 297 }
237 && with SIMPAD_LED2_ON 298
238 write to cs3 */
239 m_leds [0] = st;
240 return true;
241 // }
242// }
243#else
244 Q_UNUSED( l )
245 Q_UNUSED( st )
246#endif
247 return false; 299 return false;
248} 300}
249 301
250 302
251bool SIMpad::filter ( int /*unicode*/, int /*keycode*/, int /*modifiers*/, bool /*isPress*/, bool /*autoRepeat*/ ) 303bool SIMpad::filter ( int /*unicode*/, int /*keycode*/, int /*modifiers*/, bool /*isPress*/, bool /*autoRepeat*/ )
252{ 304{
253 //TODO 305 //TODO
254 return false; 306 return false;
255} 307}
256 308
257void SIMpad::timerEvent ( QTimerEvent * ) 309void SIMpad::timerEvent ( QTimerEvent * )
258{ 310{
@@ -301,28 +353,25 @@ bool SIMpad::suspend() // Must override because SIMpad does NOT have apm
301 353
302bool SIMpad::setSoftSuspend ( bool soft ) 354bool SIMpad::setSoftSuspend ( bool soft )
303{ 355{
304 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" ); 356 qDebug( "ODevice for SIMpad: UNHANDLED setSoftSuspend(%s)", soft? "on" : "off" );
305 return false; 357 return false;
306} 358}
307 359
308 360
309bool SIMpad::setDisplayStatus ( bool on ) 361bool SIMpad::setDisplayStatus ( bool on )
310{ 362{
311 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); 363 qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" );
312 364
313 365 return setCS3Bit(on, SIMPAD_DISPLAY_ON);
314 QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :)
315
316 return ( ::system( (const char*) cmdline ) == 0 );
317} 366}
318 367
319 368
320bool SIMpad::setDisplayBrightness ( int bright ) 369bool SIMpad::setDisplayBrightness ( int bright )
321{ 370{
322 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright ); 371 qDebug( "ODevice for SIMpad: setDisplayBrightness( %d )", bright );
323 bool res = false; 372 bool res = false;
324 int fd; 373 int fd;
325 374
326 if ( bright > 255 ) 375 if ( bright > 255 )
327 bright = 255; 376 bright = 255;
328 if ( bright < 1 ) 377 if ( bright < 1 )