11 signed int spicfd
= -1;
13 int sonypi_supported(void)
15 spicfd
= open("/dev/sonypi", O_RDWR
);
22 inline int sonypi_ioctl(int ioctlno
, void *param
)
24 if (ioctl(spicfd
, ioctlno
, param
) < 0)
30 /* Read battery info from sonypi device and shove it into an apm_info
32 int sonypi_read(apm_info
*info
)
38 info
->using_minutes
= info
->battery_flags
= 0;
40 if (!sonypi_ioctl(SONYPI_IOCGBATFLAGS
, &batflags
))
43 info
->ac_line_status
= (batflags
& SONYPI_BFLAGS_AC
) != 0;
44 if (batflags
& SONYPI_BFLAGS_B1
) {
45 if (!sonypi_ioctl(SONYPI_IOCGBAT1CAP
, &cap
))
47 if (!sonypi_ioctl(SONYPI_IOCGBAT1REM
, &rem
))
50 } else if (batflags
& SONYPI_BFLAGS_B2
) {
51 /* Not quite right, if there is a second battery I should
52 * probably merge the two somehow.. */
53 if (!sonypi_ioctl(SONYPI_IOCGBAT2CAP
, &cap
))
55 if (!sonypi_ioctl(SONYPI_IOCGBAT2REM
, &rem
))
59 info
->battery_percentage
= 0;
60 info
->battery_status
= BATTERY_STATUS_ABSENT
;
64 info
->battery_percentage
= 100 * rem
/ cap
;
65 /* Guess at whether the battery is charging. */
66 if (info
->battery_percentage
< 99 && info
->ac_line_status
== 1) {
67 info
->battery_flags
= info
->battery_flags
| BATTERY_FLAGS_CHARGING
;
68 info
->battery_status
= BATTERY_STATUS_CHARGING
;
72 /* Sadly, there is no way to estimate this. */
73 info
->battery_time
= 0;