2 * Battery and Power Management code for the Sharp SL-C7xx and SL-Cxx00
5 * Copyright (c) 2004-2005 Richard Purdie
7 * Based on code written by Sharp for 2.4 kernels
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/interrupt.h>
21 #include <linux/irq.h>
22 #include <linux/platform_device.h>
23 #include <linux/apm-emulation.h>
25 #include <mach/hardware.h>
26 #include <asm/mach-types.h>
28 #include <mach/pxa-regs.h>
29 #include <mach/pxa2xx-gpio.h>
30 #include <mach/sharpsl.h>
33 struct battery_thresh spitz_battery_levels_acin[] = {
76 struct battery_thresh spitz_battery_levels_noac[] = {
122 extern int max1111_read_channel(int);
124 int sharpsl_pm_pxa_read_max1111(int channel)
126 if (machine_is_tosa()) // Ugly, better move this function into another module
129 /* max1111 accepts channels from 0-3, however,
130 * it is encoded from 0-7 here in the code.
132 return max1111_read_channel(channel >> 1);
135 void sharpsl_pm_pxa_init(void)
137 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
138 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
139 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN);
141 /* Register interrupt handlers */
142 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, IRQF_DISABLED, "AC Input Detect", sharpsl_ac_isr)) {
143 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin));
145 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin),IRQ_TYPE_EDGE_BOTH);
147 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, IRQF_DISABLED, "Battery Cover", sharpsl_fatal_isr)) {
148 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock));
150 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQ_TYPE_EDGE_FALLING);
152 if (sharpsl_pm.machinfo->gpio_fatal) {
153 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED, "Fatal Battery", sharpsl_fatal_isr)) {
154 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal));
156 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQ_TYPE_EDGE_FALLING);
159 if (sharpsl_pm.machinfo->batfull_irq)
161 /* Register interrupt handler. */
162 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED, "CO", sharpsl_chrg_full_isr)) {
163 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull));
165 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQ_TYPE_EDGE_RISING);
169 void sharpsl_pm_pxa_remove(void)
171 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
172 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
174 if (sharpsl_pm.machinfo->gpio_fatal)
175 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr);
177 if (sharpsl_pm.machinfo->batfull_irq)
178 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);