Commit 3b97210e authored by Radek Polak's avatar Radek Polak

gta02 - 2.6.39 adaptation

parent 8b026e2c
......@@ -85,9 +85,7 @@ bool NeoSuspend::canSuspend() const
static int readChargeNow()
{
QString chargeNowStr =
qReadFile("/sys/class/power_supply/bq27000-battery/charge_now");
return chargeNowStr.toInt();
return qReadSysfsInt("/sys/class/power_supply/bq27000-battery/charge_now");
}
bool NeoSuspend::suspend()
......@@ -126,9 +124,7 @@ bool NeoSuspend::wake()
QString::number(avgCurrent));
// Read and update current_now. It should contain the current in suspend
QString currentNowStr =
qReadFile("/sys/class/power_supply/bq27000-battery/current_now");
int currentNow = currentNowStr.toInt() / 1000;
int currentNow = qReadSysfsInt("/sys/class/power_supply/bq27000-battery/current_now") / 1000;
batteryVso.setAttribute("current_now_in_suspend",
QString::number(currentNow));
......
......@@ -36,16 +36,7 @@
QTOPIABASE_EXPORT int qpe_sysBrightnessSteps()
{
QFile f("/sys/class/backlight/pcf50633-backlight/max_brightness");
if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "qpe_sysBrightnessSteps: " + f.errorString();
return 0;
}
QTextStream in(&f);
QString str;
in >> str;
f.close();
return str.toInt();
return qReadSysfsInt("/sys/class/backlight/pcf50633-backlight/max_brightness");
}
QTOPIABASE_EXPORT void qpe_setBrightness(int b)
......@@ -61,14 +52,8 @@ QTOPIABASE_EXPORT void qpe_setBrightness(int b)
//bright
b = brightessSteps;
}
QFile f("/sys/class/backlight/pcf50633-backlight/brightness");
if(!f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
qWarning() << "qpe_setBrightness: " + f.errorString();
return;
}
QTextStream out(&f);
out << QString::number(b);
f.close();
QByteArray str = QByteArray::number(b);
qWriteFile("/sys/class/backlight/pcf50633-backlight/brightness", str.constData());
}
......@@ -138,15 +138,9 @@ void NeoBattery::updateDumbStatus()
int NeoBattery::getDumbCapacity()
{
qLog(PowerManagement) << __PRETTY_FUNCTION__;
int voltage = 0;
QString inStr;
QFile battvolt("/sys/class/power_supply/battery/voltage_now");
battvolt.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&battvolt);
in >> inStr;
voltage = inStr.toInt();
battvolt.close();
qLog(PowerManagement)<<"voltage"<< inStr;
int voltage = qReadSysfsInt("/sys/class/power_supply/battery/voltage_now");
qLog(PowerManagement)<<"voltage"<< voltage;
// lets use 3400 as empty, for all intensive purposes,
// 2 minutes left of battery life till neo shuts off might
......@@ -190,23 +184,13 @@ void NeoBattery::updateStatus()
\internal */
bool NeoBattery::isCharging()
{
qLog(PowerManagement) << __PRETTY_FUNCTION__;
QString charge;
QFile chargeState("/sys/class/power_supply/battery/status");
chargeState.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&chargeState);
in >> charge;
qLog(PowerManagement) << __PRETTY_FUNCTION__ << charge;
// Charging Discharging Not charging
// ac battery ac/full
chargeState.close();
QByteArray content = qReadFile("/sys/class/power_supply/battery/status");
qLog(PowerManagement) << __PRETTY_FUNCTION__ << content;
// Charging Discharging Not charging
// ac battery ac/full
// JM: Fixed this as it can return Not charging too
if (charge == ("Charging")) {
return true;
}
return false;
return (strcmp(content.constData(), "Charging") == 0);
}
/*!
......@@ -237,14 +221,7 @@ int NeoBattery::getCapacity()
qLog(PowerManagement) << __PRETTY_FUNCTION__;
int capacity = 0;
QFile capacityState("/sys/class/power_supply/battery/capacity");
capacityState.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&capacityState);
in >> capacity;
capacityState.close();
qLog(PowerManagement) << capacity;
int capacity = qReadSysfsInt("/sys/class/power_supply/battery/capacity");
// JM: Removed this test as it will permanently switch to dumb battery which will always return 100%
// might be gta02 with dumb battery
......@@ -264,16 +241,7 @@ int NeoBattery::getTimeToFull()
return 0;
qLog(PowerManagement) << __PRETTY_FUNCTION__;
int time = 0;
QFile timeState("/sys/class/power_supply/battery/time_to_full_now");
timeState.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&timeState);
in >> time;
timeState.close();
qLog(PowerManagement) << time/60;
int time = qReadSysfsInt("/sys/class/power_supply/battery/time_to_full_now");
return time/60;
}
......@@ -286,16 +254,7 @@ int NeoBattery::getTimeRemaining()
return 0;
qLog(PowerManagement) << __PRETTY_FUNCTION__;
int time = 0;
QFile timeState("/sys/class/power_supply/battery/time_to_empty_now");
timeState.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&timeState);
in >> time;
timeState.close();
qLog(PowerManagement) << time/60;
int time = Qtopia::readSysfsInt("/sys/class/power_supply/battery/time_to_empty_now", false, 0);
return time/60;
}
......
......@@ -35,6 +35,7 @@
#include <qbootsourceaccessory.h>
#include <qtopiaipcenvelope.h>
#include <qtopianamespace.h>
#include <qtopiaserverapplication.h>
......@@ -133,15 +134,16 @@ char *value;
if (bytesAvail < readCount)
readCount = bytesAvail;
ueventSocket->read(&buffer[0],readCount);
if(strcmp(buffer,"change@/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc.0/power_supply/usb")==0)
if(strcmp(buffer,"change@/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc/power_supply/usb")==0)
{
qLog(PowerManagement)<<"usb change event";
cableConnected(getCableStatus());
}else if(strcmp(buffer,"change@/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc.0/power_supply/ac")==0)
}else if(strcmp(buffer,"change@/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc/power_supply/ac")==0)
{
qLog(PowerManagement)<<"ac change event";
cableConnected(getCableStatus());
}else if(strcmp(buffer,"change@/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc.0/power_supply/adapter")==0)
}else if(strcmp(buffer,"change@/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc/power_supply/adapter")==0)
{
value=findAttribute(buffer,readCount,"POWER_SUPPLY_ONLINE=");
qLog(PowerManagement)<<"power_supply change event; online="<<value;
......@@ -155,9 +157,7 @@ char *value;
qDebug()<<"headset change event, switch_state="<<value;
}
QString currentNowStr =
qReadFile("/sys/class/power_supply/battery/current_now");
int currentNow = currentNowStr.toInt() / 1000;
int currentNow = qReadSysfsInt("/sys/class/power_supply/battery/current_now") / 1000;
batteryVso.setAttribute("current_now", QString::number(currentNow));
}
......@@ -210,44 +210,19 @@ void NeoHardware::shutdownRequested()
{
qLog(PowerManagement)<< __PRETTY_FUNCTION__;
QFile powerFile("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.1/gta02-pm-gsm.0/power_on");
QFile btPower("/sys/devices/platform/gta02-pm-bt.0/power_on");
if( !powerFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
qWarning()<<"File not opened";
} else {
QTextStream out(&powerFile);
out << "0";
powerFile.close();
}
if( !btPower.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
qWarning()<<"File not opened";
} else {
QTextStream out(&btPower);
out << "0";
powerFile.close();
}
qWriteFile("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio/reg-fixed-voltage.1/gta02-pm-gsm.0/power_on", "0");
qWriteFile("/sys/devices/platform/gta02-pm-bt.0/power_on", "0");
QtopiaServerApplication::instance()->shutdown(QtopiaServerApplication::ShutdownSystem);
}
bool NeoHardware::getCableStatus()
{
// These code from NeoBattery::isCharging()
// Seems better than the origin method
qLog(PowerManagement) << __PRETTY_FUNCTION__;
QString charge;
QFile chargeState("/sys/class/power_supply/battery/status");
chargeState.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&chargeState);
in >> charge;
qLog(PowerManagement) << __PRETTY_FUNCTION__ << charge;
char buf[64];
qReadSysfsStr("/sys/class/power_supply/battery/status", buf);
// Charging Discharging Not charging
// ac battery ac/full
chargeState.close();
return (charge != ("Discharging"));
return strcmp(buf, "Discharging") != 0;
}
#endif // QT_QWS_NEO
......
......@@ -26,7 +26,7 @@
#include <stdlib.h>
#include <QDesktopWidget>
#include <QTimer>
#include <qtopianamespace.h>
#include "systemsuspend.h"
......@@ -77,9 +77,7 @@ bool NeoSuspend::canSuspend() const
static int readChargeNow()
{
QString chargeNowStr =
qReadFile("/sys/class/power_supply/battery/charge_now");
return chargeNowStr.toInt();
return qReadSysfsInt("/sys/class/power_supply/battery/charge_now");
}
bool NeoSuspend::suspend()
......@@ -105,9 +103,7 @@ bool NeoSuspend::wake()
batteryVso.setAttribute("avg_current_in_suspend", QString::number(avgCurrent));
// Actual current_now
QString currentNowStr =
qReadFile("/sys/class/power_supply/battery/current_now");
int currentNow = currentNowStr.toInt() / 1000;
int currentNow = qReadSysfsInt("/sys/class/power_supply/battery/current_now") / 1000;
batteryVso.setAttribute("current_now_in_suspend", QString::number(currentNow));
#ifdef Q_WS_QWS
......@@ -135,6 +131,5 @@ bool NeoSuspend::wake()
/* No waitForFinished after start, because we want the command to complete
in the background */
resumeScript.start("after-resume.sh");
return true;
}
#!/bin/sh
echo 0 > /sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on
echo 0 > /sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio/reg-fixed-voltage.1/gta02-pm-gsm.0/power_on
echo device > /sys/devices/platform/s3c2410-ohci/usb_mode
......@@ -23,6 +23,7 @@
#include <QDebug>
#include <QSettings>
#include <qtopialog.h>
#include <qtopianamespace.h>
#include <QValueSpaceItem>
#include <qgsm0710multiplexer.h>
......@@ -61,17 +62,9 @@ bool NeoMultiplexerPlugin::detect( QSerialIODevice *device )
qLog(Hardware) << __PRETTY_FUNCTION__;
// Power on modem via sysfs
QFile f("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.1/gta02-pm-gsm.0/power_on");
if(f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
f.write("0");
f.close();
}
if(f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
f.write("1");
f.close();
} else {
qWarning() << "Modem power on failed "<< f.errorString();
}
#define POWER_ON_FILE "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio/reg-fixed-voltage.1/gta02-pm-gsm.0/power_on"
qWriteFile(POWER_ON_FILE, "0");
qWriteFile(POWER_ON_FILE, "1");
// The FIC needs a special line discipline set on the device.
QSerialPort *port = qobject_cast<QSerialPort *>( device );
......
......@@ -820,32 +820,12 @@ void NeoVibrateAccessory::setVibrateOnRing( const bool value )
void NeoVibrateAccessory::setVibrateNow( const bool value, int timeoutMs, int strength )
{
qLog(Modem)<<"setVibrateNow "<<value;
QString vibFile("/sys/class/leds/gta02::vibrator");
if ( value ) { //turn on
QFile trigger( vibFile + "/trigger");
trigger.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
QTextStream out(&trigger);
out<<"timer";
trigger.close();
QFile delayOn( vibFile + "/delay_on");
delayOn.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
QTextStream out1(&delayOn);
out1<<"500";
delayOn.close();
QFile delayOff(vibFile + "/delay_off");
delayOff.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
QTextStream out2(&delayOff);
out2<<"1000";
delayOff.close();
qWriteFile("/sys/class/leds/gta02::vibrator/trigger", "timer");
qWriteFile("/sys/class/leds/gta02::vibrator/delay_on", "500");
qWriteFile("/sys/class/leds/gta02::vibrator/delay_off", "1000");
} else { //turn off
QFile trigger( vibFile + "/trigger");
trigger.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
QTextStream out(&trigger);
out<<"none";
trigger.close();
qWriteFile("/sys/class/leds/gta02::vibrator/trigger", "none");
}
QVibrateAccessoryProvider::setVibrateNow( value );
......
......@@ -96,9 +96,20 @@ Step 4
echo g_ether > /media/card/etc/modules
echo ppp_generic >> /media/card/etc/modules
echo lis302dl >> /media/card/etc/modules
echo joydev >> /media/card/etc/modules
echo bq27x00_battery >> /media/card/etc/modules
echo ohci_hcd >> /media/card/etc/modules
echo snd-soc-neo1973-wm8753 >> /media/card/etc/modules
echo ar6000 >> /media/card/etc/modules
echo btusb >> /media/card/etc/modules
echo bluetooth >> /media/card/etc/modules
echo snd-soc-neo1973-wm8753 >> /media/card/etc/modules
echo snd-soc-wm8753 >> /media/card/etc/modules
echo snd-soc-dfbmcs320 >> /media/card/etc/modules
echo snd-soc-neo1973-wm8753 >> /media/card/etc/modules
echo snd_soc_s3c24xx >> /media/card/etc/modules
* Edit /media/card/etc/ppp/options and replace "auth" with "noauth"
......
......@@ -1646,10 +1646,8 @@ int Qtopia::writeFd(int fd, const char *buf, int n, int okRes, int errRes)
for (;;) {
int count = write(fd, buf, n);
if (count <= 0) {
if(errno == EAGAIN) {
usleep(1000);
if(errno == EAGAIN)
continue;
}
return errRes;
}
buf += count;
......@@ -1659,6 +1657,26 @@ int Qtopia::writeFd(int fd, const char *buf, int n, int okRes, int errRes)
}
}
/*!
Reads n bytes to \a buf from file descriptor \a fd. On success returns
number of bytes read, on error return \a errRes. You can check errno in this case.
*/
int Qtopia::readFd(int fd, char *buf, int bufLen, int errRes)
{
int n = 0;
for (;;) {
int count = read(fd, buf + n, bufLen - n);
if (count == -1) {
if(errno == EAGAIN)
continue;
return errRes;
}
n += count;
if (n == bufLen || count == 0)
return n;
}
}
/*!
Writes \a n bytes from \a buf to file specified by \a path. In case of error
if \a warnOnError is true qWarning() is used to print the error message. On
......@@ -1695,6 +1713,56 @@ QByteArray Qtopia::readFile(const char *path)
return content;
}
/*!
Reads contents of file specified by \a path. Returns number of bytes read or \a errRes.
*/
int Qtopia::readFile(const char *path, char *buf, int bufLen, bool warnOnError, int errRes)
{
int fd = open(path, O_RDONLY);
int n;
if (fd >= 0 && (n = readFd(fd, buf, bufLen))) {
close(fd);
return n;
}
if(warnOnError)
qWarning() << "readFile failed " << path << ":" << strerror(errno);
if(fd >= 0)
close(fd);
return errRes;
}
/*!
Reads string from file. Similar to readFile except that it terminates string
in \a buf with 0 and removes trailing newline.
*/
int Qtopia::readSysfsStr(const char *path, char *buf, int bufLen, bool warnOnError, int errRes)
{
int n = readFile(path, buf, bufLen - 1, warnOnError, errRes);
if(n <= 0) {
buf[0] = 0;
return errRes;
}
if(buf[n] == '\n') // remove new line char
buf[n] = 0;
else
buf[n+1] = 0; // terminate string
return n;
}
/*!
Reads ASCII represented integer from file.
*/
int Qtopia::readSysfsInt(const char *path, bool warnOnError, int errRes)
{
char buf[16];
int n = readSysfsStr(path, buf, sizeof(buf), warnOnError, errRes);
if(n <= 0)
return errRes;
return atoi(buf);
}
#endif //QTOPIA_HOST
#include "qtopianamespace_lock.cpp"
......
......@@ -69,11 +69,18 @@ namespace Qtopia
QTOPIABASE_EXPORT int writeFd(int fd, const char *buf, int n, int okRes = 1, int errRes = 0);
QTOPIABASE_EXPORT int writeFile(const char * path, const char * buf, int n, bool warnOnError = true, int okRes = 1, int errRes = 0);
QTOPIABASE_EXPORT QByteArray readFile(const char *path);
QTOPIABASE_EXPORT int readFd(int fd, char *buf, int bufLen, int errRes = 0);
QTOPIABASE_EXPORT int readFile(const char *path, char *buf, int bufLen, bool warnOnError, int errRes);
QTOPIABASE_EXPORT int readSysfsStr(const char *path, char *buf, int bufLen, bool warnOnError = true, int errRes = 0);
QTOPIABASE_EXPORT int readSysfsInt(const char *path, bool warnOnError = true, int errRes = 0);
// Convenient macros (shorter name), writeFile for writing string constant
#define qWriteFile(path, buf) Qtopia::writeFile(path, buf, sizeof(buf) - 1);
#define qReadFile(path) Qtopia::readFile(path);
#define qWriteFile(path, buf) Qtopia::writeFile(path, buf, sizeof(buf) - 1)
#define qReadFile(path) Qtopia::readFile(path)
#define qReadSysfsStr(path, buf) Qtopia::readSysfsStr(path, buf, sizeof(buf))
#define qReadSysfsInt(path) Qtopia::readSysfsInt(path)
QTOPIABASE_EXPORT bool mousePreferred();
QTOPIABASE_EXPORT bool hasKey(int key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment