Commit 0a9b0db1 authored by Paul Mundt's avatar Paul Mundt Committed by Ralf Baechle

[APM] SH: Convert to use shared APM emulation.

Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 2116245e
...@@ -48,6 +48,9 @@ config GENERIC_IOMAP ...@@ -48,6 +48,9 @@ config GENERIC_IOMAP
config GENERIC_TIME config GENERIC_TIME
def_bool n def_bool n
config SYS_SUPPORTS_APM_EMULATION
bool
config ARCH_MAY_HAVE_PC_FDC config ARCH_MAY_HAVE_PC_FDC
bool bool
...@@ -126,6 +129,7 @@ config SH_7751_SYSTEMH ...@@ -126,6 +129,7 @@ config SH_7751_SYSTEMH
config SH_HP6XX config SH_HP6XX
bool "HP6XX" bool "HP6XX"
select SYS_SUPPORTS_APM_EMULATION
help help
Select HP6XX if configuring for a HP jornada HP6xx. Select HP6XX if configuring for a HP jornada HP6xx.
More information (hardware only) at More information (hardware only) at
...@@ -694,9 +698,6 @@ depends on EXPERIMENTAL ...@@ -694,9 +698,6 @@ depends on EXPERIMENTAL
source kernel/power/Kconfig source kernel/power/Kconfig
config APM
bool "Advanced Power Management Emulation"
depends on PM
endmenu endmenu
source "net/Kconfig" source "net/Kconfig"
......
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
* modify it under the terms of the GNU General Public License. * modify it under the terms of the GNU General Public License.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/apm_bios.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <asm/io.h> #include <linux/apm-emulation.h>
#include <asm/apm.h> #include <linux/io.h>
#include <asm/adc.h> #include <asm/adc.h>
#include <asm/hp6xx.h> #include <asm/hp6xx.h>
...@@ -27,60 +26,41 @@ ...@@ -27,60 +26,41 @@
#define MODNAME "hp6x0_apm" #define MODNAME "hp6x0_apm"
static int hp6x0_apm_get_info(char *buf, char **start, off_t fpos, int length) static void hp6x0_apm_get_power_status(struct apm_power_info *info)
{ {
int battery, backup, charging, percentage;
u8 pgdr; u8 pgdr;
char *p;
int battery_status;
int battery_flag;
int ac_line_status;
int time_units = APM_BATTERY_LIFE_UNKNOWN;
int battery = adc_single(ADC_CHANNEL_BATTERY); battery = adc_single(ADC_CHANNEL_BATTERY);
int backup = adc_single(ADC_CHANNEL_BACKUP); backup = adc_single(ADC_CHANNEL_BACKUP);
int charging = adc_single(ADC_CHANNEL_CHARGE); charging = adc_single(ADC_CHANNEL_CHARGE);
int percentage;
percentage = 100 * (battery - HP680_BATTERY_MIN) / percentage = 100 * (battery - HP680_BATTERY_MIN) /
(HP680_BATTERY_MAX - HP680_BATTERY_MIN); (HP680_BATTERY_MAX - HP680_BATTERY_MIN);
ac_line_status = (battery > HP680_BATTERY_AC_ON) ? info->ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
APM_AC_ONLINE : APM_AC_OFFLINE; APM_AC_ONLINE : APM_AC_OFFLINE;
p = buf;
pgdr = ctrl_inb(SH7709_PGDR); pgdr = ctrl_inb(SH7709_PGDR);
if (pgdr & PGDR_MAIN_BATTERY_OUT) { if (pgdr & PGDR_MAIN_BATTERY_OUT) {
battery_status = APM_BATTERY_STATUS_NOT_PRESENT; info->battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
battery_flag = 0x80; info->battery_flag = 0x80;
percentage = -1; } else if (charging < 8) {
} else if (charging < 8 ) { info->battery_status = APM_BATTERY_STATUS_CHARGING;
battery_status = APM_BATTERY_STATUS_CHARGING; info->battery_flag = 0x08;
battery_flag = 0x08; info->ac_line_status = 0xff;
ac_line_status = 0xff;
} else if (percentage <= APM_CRITICAL) { } else if (percentage <= APM_CRITICAL) {
battery_status = APM_BATTERY_STATUS_CRITICAL; info->battery_status = APM_BATTERY_STATUS_CRITICAL;
battery_flag = 0x04; info->battery_flag = 0x04;
} else if (percentage <= APM_LOW) { } else if (percentage <= APM_LOW) {
battery_status = APM_BATTERY_STATUS_LOW; info->battery_status = APM_BATTERY_STATUS_LOW;
battery_flag = 0x02; info->battery_flag = 0x02;
} else { } else {
battery_status = APM_BATTERY_STATUS_HIGH; info->battery_status = APM_BATTERY_STATUS_HIGH;
battery_flag = 0x01; info->battery_flag = 0x01;
} }
p += sprintf(p, "1.0 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n", info->units = 0;
APM_32_BIT_SUPPORT,
ac_line_status,
battery_status,
battery_flag,
percentage,
time_units,
"min");
p += sprintf(p, "bat=%d backup=%d charge=%d\n",
battery, backup, charging);
return p - buf;
} }
static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev) static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev)
...@@ -96,14 +76,14 @@ static int __init hp6x0_apm_init(void) ...@@ -96,14 +76,14 @@ static int __init hp6x0_apm_init(void)
int ret; int ret;
ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt, ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt,
IRQF_DISABLED, MODNAME, 0); IRQF_DISABLED, MODNAME, NULL);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {
printk(KERN_ERR MODNAME ": IRQ %d request failed\n", printk(KERN_ERR MODNAME ": IRQ %d request failed\n",
HP680_BTN_IRQ); HP680_BTN_IRQ);
return ret; return ret;
} }
apm_get_info = hp6x0_apm_get_info; apm_get_power_status = hp6x0_apm_get_power_status;
return ret; return ret;
} }
...@@ -111,7 +91,7 @@ static int __init hp6x0_apm_init(void) ...@@ -111,7 +91,7 @@ static int __init hp6x0_apm_init(void)
static void __exit hp6x0_apm_exit(void) static void __exit hp6x0_apm_exit(void)
{ {
free_irq(HP680_BTN_IRQ, 0); free_irq(HP680_BTN_IRQ, 0);
apm_get_info = 0; apm_get_info = NULL;
} }
module_init(hp6x0_apm_init); module_init(hp6x0_apm_init);
......
...@@ -19,6 +19,5 @@ obj-$(CONFIG_SH_CPU_FREQ) += cpufreq.o ...@@ -19,6 +19,5 @@ obj-$(CONFIG_SH_CPU_FREQ) += cpufreq.o
obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
obj-$(CONFIG_APM) += apm.o
obj-$(CONFIG_PM) += pm.o obj-$(CONFIG_PM) += pm.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_STACKTRACE) += stacktrace.o
This diff is collapsed.
/*
* Copyright 2006 (c) Andriy Skulysh <askulysh@gmail.com>
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
*/
#ifndef __ASM_SH_APM_H
#define __ASM_SH_APM_H
#define APM_AC_OFFLINE 0
#define APM_AC_ONLINE 1
#define APM_AC_BACKUP 2
#define APM_AC_UNKNOWN 0xff
#define APM_BATTERY_STATUS_HIGH 0
#define APM_BATTERY_STATUS_LOW 1
#define APM_BATTERY_STATUS_CRITICAL 2
#define APM_BATTERY_STATUS_CHARGING 3
#define APM_BATTERY_STATUS_NOT_PRESENT 4
#define APM_BATTERY_STATUS_UNKNOWN 0xff
#define APM_BATTERY_LIFE_UNKNOWN 0xFFFF
#define APM_BATTERY_LIFE_MINUTES 0x8000
#define APM_BATTERY_LIFE_VALUE_MASK 0x7FFF
#define APM_BATTERY_FLAG_HIGH (1 << 0)
#define APM_BATTERY_FLAG_LOW (1 << 1)
#define APM_BATTERY_FLAG_CRITICAL (1 << 2)
#define APM_BATTERY_FLAG_CHARGING (1 << 3)
#define APM_BATTERY_FLAG_NOT_PRESENT (1 << 7)
#define APM_BATTERY_FLAG_UNKNOWN 0xff
#define APM_UNITS_MINS 0
#define APM_UNITS_SECS 1
#define APM_UNITS_UNKNOWN -1
extern int (*apm_get_info)(char *buf, char **start, off_t fpos, int length);
extern int apm_suspended;
void apm_queue_event(apm_event_t event);
#endif
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