sh: hp6xx: Correct APM output.
authorKristoffer Ericson <kristoffer.ericson@gmail.com>
Wed, 5 Mar 2008 07:09:25 +0000 (23:09 -0800)
committerPaul Mundt <lethal@linux-sh.org>
Thu, 6 Mar 2008 02:54:17 +0000 (11:54 +0900)
This patch fixes the old non-verbose hp6xx apm code and enables some
very basic apm output.  We now get percentage (battery) output
and basic time estimate.

Signed-off-by: Kristoffer Ericson <kristoffer.ericson@gmail.com>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/boards/hp6xx/hp6xx_apm.c

index 640ca2a74f163c07ef42ac570e11cb254da76e0f..76b6776235df7b587338c3bae2b17d4a003d3758 100644 (file)
@@ -2,6 +2,7 @@
  * bios-less APM driver for hp680
  *
  * Copyright 2005 (c) Andriy Skulysh <askulysh@gmail.com>
+ * Copyright 2008 (c) Kristoffer Ericson <kristoffer.ericson@gmail.com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License.
 #include <asm/adc.h>
 #include <asm/hp6xx.h>
 
-#define SH7709_PGDR                    0xa400012c
-
+/* percentage values */
 #define APM_CRITICAL                   10
 #define APM_LOW                                30
 
+/* resonably sane values */
 #define HP680_BATTERY_MAX              898
 #define HP680_BATTERY_MIN              486
 #define HP680_BATTERY_AC_ON            1023
@@ -38,17 +39,26 @@ static void hp6x0_apm_get_power_status(struct apm_power_info *info)
        percentage = 100 * (battery - HP680_BATTERY_MIN) /
                           (HP680_BATTERY_MAX - HP680_BATTERY_MIN);
 
+       /* % of full battery */
+       info->battery_life = percentage;
+
+       /* We want our estimates in minutes */
+       info->units = 0;
+
+       /* Extremely(!!) rough estimate, we will replace this with a datalist later on */
+       info->time = (2 * battery);
+
        info->ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
                         APM_AC_ONLINE : APM_AC_OFFLINE;
 
-       pgdr = ctrl_inb(SH7709_PGDR);
+       pgdr = ctrl_inb(PGDR);
        if (pgdr & PGDR_MAIN_BATTERY_OUT) {
                info->battery_status    = APM_BATTERY_STATUS_NOT_PRESENT;
                info->battery_flag      = 0x80;
        } else if (charging < 8) {
                info->battery_status    = APM_BATTERY_STATUS_CHARGING;
                info->battery_flag      = 0x08;
-               info->ac_line_status = 0xff;
+               info->ac_line_status    = 0x01;
        } else if (percentage <= APM_CRITICAL) {
                info->battery_status    = APM_BATTERY_STATUS_CRITICAL;
                info->battery_flag      = 0x04;
@@ -59,8 +69,6 @@ static void hp6x0_apm_get_power_status(struct apm_power_info *info)
                info->battery_status    = APM_BATTERY_STATUS_HIGH;
                info->battery_flag      = 0x01;
        }
-
-       info->units = 0;
 }
 
 static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev)