4 #include <sys/sockio.h>
16 signed int spicfd
= -1;
18 int sonypi_supported(void)
20 spicfd
= open("/dev/sonypi", O_RDWR
);
27 inline int sonypi_ioctl(int ioctlno
, void *param
)
29 if (ioctl(spicfd
, ioctlno
, param
) < 0)
35 /* Read battery info from sonypi device and shove it into an apm_info
37 int sonypi_read(apm_info
*info
)
43 info
->using_minutes
= info
->battery_flags
= 0;
45 if (!sonypi_ioctl(SONYPI_IOCGBATFLAGS
, &batflags
))
48 info
->ac_line_status
= (batflags
& SONYPI_BFLAGS_AC
) != 0;
49 if (batflags
& SONYPI_BFLAGS_B1
) {
50 if (!sonypi_ioctl(SONYPI_IOCGBAT1CAP
, &cap
))
52 if (!sonypi_ioctl(SONYPI_IOCGBAT1REM
, &rem
))
55 } else if (batflags
& SONYPI_BFLAGS_B2
) {
56 /* Not quite right, if there is a second battery I should
57 * probably merge the two somehow.. */
58 if (!sonypi_ioctl(SONYPI_IOCGBAT2CAP
, &cap
))
60 if (!sonypi_ioctl(SONYPI_IOCGBAT2REM
, &rem
))
64 info
->battery_percentage
= 0;
65 info
->battery_status
= BATTERY_STATUS_ABSENT
;
69 info
->battery_percentage
= 100 * rem
/ cap
;
70 /* Guess at whether the battery is charging. */
71 if (info
->battery_percentage
< 99 && info
->ac_line_status
== 1) {
72 info
->battery_flags
= info
->battery_flags
| BATTERY_FLAGS_CHARGING
;
73 info
->battery_status
= BATTERY_STATUS_CHARGING
;
77 /* Sadly, there is no way to estimate this. */
78 info
->battery_time
= 0;