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/platform_device.h>
23 #include <asm/hardware.h>
24 #include <asm/mach-types.h>
27 #include <asm/arch/pm.h>
28 #include <asm/arch/pxa-regs.h>
29 #include <asm/arch/sharpsl.h>
30 #include <asm/hardware/sharpsl_pm.h>
33 struct battery_thresh spitz_battery_levels_acin[] = {
76 struct battery_thresh spitz_battery_levels_noac[] = {
119 /* MAX1111 Commands */
120 #define MAXCTRL_PD0 1u << 0
121 #define MAXCTRL_PD1 1u << 1
122 #define MAXCTRL_SGL 1u << 2
123 #define MAXCTRL_UNI 1u << 3
124 #define MAXCTRL_SEL_SH 4
125 #define MAXCTRL_STR 1u << 7
130 int sharpsl_pm_pxa_read_max1111(int channel)
132 return corgi_ssp_max1111_get((channel << MAXCTRL_SEL_SH) | MAXCTRL_PD0 | MAXCTRL_PD1
133 | MAXCTRL_SGL | MAXCTRL_UNI | MAXCTRL_STR);
136 void sharpsl_pm_pxa_init(void)
138 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
139 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
140 pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN);
142 /* Register interrupt handlers */
143 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, SA_INTERRUPT, "AC Input Detect", sharpsl_ac_isr)) {
144 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin));
146 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin),IRQT_BOTHEDGE);
148 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, SA_INTERRUPT, "Battery Cover", sharpsl_fatal_isr)) {
149 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock));
151 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQT_FALLING);
153 if (sharpsl_pm.machinfo->gpio_fatal) {
154 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, SA_INTERRUPT, "Fatal Battery", sharpsl_fatal_isr)) {
155 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal));
157 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQT_FALLING);
160 if (!machine_is_corgi())
162 /* Register interrupt handler. */
163 if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, SA_INTERRUPT, "CO", sharpsl_chrg_full_isr)) {
164 dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull));
166 else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQT_RISING);
170 void sharpsl_pm_pxa_remove(void)
172 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
173 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
175 if (sharpsl_pm.machinfo->gpio_fatal)
176 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr);
178 if (!machine_is_corgi())
179 free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);