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>
24 #include <asm/hardware.h>
25 #include <asm/mach-types.h>
27 #include <asm/arch/pm.h>
28 #include <asm/arch/pxa-regs.h>
29 #include <asm/arch/sharpsl.h>
32 struct battery_thresh spitz_battery_levels_acin[] = {
75 struct battery_thresh spitz_battery_levels_noac[] = {
118 /* MAX1111 Commands */
119 #define MAXCTRL_PD0 1u << 0
120 #define MAXCTRL_PD1 1u << 1
121 #define MAXCTRL_SGL 1u << 2
122 #define MAXCTRL_UNI 1u << 3
123 #define MAXCTRL_SEL_SH 4
124 #define MAXCTRL_STR 1u << 7
129 int sharpsl_pm_pxa_read_max1111(int channel)
131 if (machine_is_tosa()) // Ugly, better move this function into another module
134 return corgi_ssp_max1111_get((channel << MAXCTRL_SEL_SH) | MAXCTRL_PD0 | MAXCTRL_PD1
135 | MAXCTRL_SGL | MAXCTRL_UNI | MAXCTRL_STR);
138 void sharpsl_pm_pxa_init(void)
140 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
141 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
142 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN);
144 /* Register interrupt handlers */
145 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, IRQF_DISABLED, "AC Input Detect", sharpsl_ac_isr)) {
146 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin));
148 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin),IRQT_BOTHEDGE);
150 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, IRQF_DISABLED, "Battery Cover", sharpsl_fatal_isr)) {
151 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock));
153 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQT_FALLING);
155 if (sharpsl_pm.machinfo->gpio_fatal) {
156 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED, "Fatal Battery", sharpsl_fatal_isr)) {
157 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal));
159 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQT_FALLING);
162 if (sharpsl_pm.machinfo->batfull_irq)
164 /* Register interrupt handler. */
165 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED, "CO", sharpsl_chrg_full_isr)) {
166 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull));
168 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQT_RISING);
172 void sharpsl_pm_pxa_remove(void)
174 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
175 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
177 if (sharpsl_pm.machinfo->gpio_fatal)
178 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr);
180 if (sharpsl_pm.machinfo->batfull_irq)
181 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);