Commit | Line | Data |
---|---|---|
078abcf9 RP |
1 | /* |
2 | * Battery and Power Management code for the Sharp SL-C7xx and SL-Cxx00 | |
3 | * series of PDAs | |
4 | * | |
5 | * Copyright (c) 2004-2005 Richard Purdie | |
6 | * | |
7 | * Based on code written by Sharp for 2.4 kernels | |
8 | * | |
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. | |
12 | * | |
13 | */ | |
14 | ||
15 | #undef DEBUG | |
16 | ||
17 | #include <linux/module.h> | |
078abcf9 RP |
18 | #include <linux/init.h> |
19 | #include <linux/kernel.h> | |
078abcf9 | 20 | #include <linux/interrupt.h> |
1623dee8 | 21 | #include <linux/irq.h> |
c5e1ae97 | 22 | #include <linux/platform_device.h> |
61fde514 | 23 | #include <linux/apm-emulation.h> |
078abcf9 | 24 | |
a09e64fb | 25 | #include <mach/hardware.h> |
078abcf9 | 26 | #include <asm/mach-types.h> |
a09e64fb RK |
27 | #include <mach/pm.h> |
28 | #include <mach/pxa-regs.h> | |
29 | #include <mach/pxa2xx-gpio.h> | |
30 | #include <mach/sharpsl.h> | |
078abcf9 RP |
31 | #include "sharpsl.h" |
32 | ||
078abcf9 RP |
33 | struct battery_thresh spitz_battery_levels_acin[] = { |
34 | { 213, 100}, | |
35 | { 212, 98}, | |
36 | { 211, 95}, | |
37 | { 210, 93}, | |
38 | { 209, 90}, | |
39 | { 208, 88}, | |
40 | { 207, 85}, | |
41 | { 206, 83}, | |
42 | { 205, 80}, | |
43 | { 204, 78}, | |
44 | { 203, 75}, | |
45 | { 202, 73}, | |
46 | { 201, 70}, | |
47 | { 200, 68}, | |
48 | { 199, 65}, | |
49 | { 198, 63}, | |
50 | { 197, 60}, | |
51 | { 196, 58}, | |
52 | { 195, 55}, | |
53 | { 194, 53}, | |
54 | { 193, 50}, | |
55 | { 192, 48}, | |
56 | { 192, 45}, | |
57 | { 191, 43}, | |
58 | { 191, 40}, | |
59 | { 190, 38}, | |
60 | { 190, 35}, | |
61 | { 189, 33}, | |
62 | { 188, 30}, | |
63 | { 187, 28}, | |
64 | { 186, 25}, | |
65 | { 185, 23}, | |
66 | { 184, 20}, | |
67 | { 183, 18}, | |
68 | { 182, 15}, | |
69 | { 181, 13}, | |
70 | { 180, 10}, | |
71 | { 179, 8}, | |
72 | { 178, 5}, | |
73 | { 0, 0}, | |
74 | }; | |
75 | ||
76 | struct battery_thresh spitz_battery_levels_noac[] = { | |
77 | { 213, 100}, | |
78 | { 212, 98}, | |
79 | { 211, 95}, | |
80 | { 210, 93}, | |
81 | { 209, 90}, | |
82 | { 208, 88}, | |
83 | { 207, 85}, | |
84 | { 206, 83}, | |
85 | { 205, 80}, | |
86 | { 204, 78}, | |
87 | { 203, 75}, | |
88 | { 202, 73}, | |
89 | { 201, 70}, | |
90 | { 200, 68}, | |
91 | { 199, 65}, | |
92 | { 198, 63}, | |
93 | { 197, 60}, | |
94 | { 196, 58}, | |
95 | { 195, 55}, | |
96 | { 194, 53}, | |
97 | { 193, 50}, | |
98 | { 192, 48}, | |
99 | { 191, 45}, | |
100 | { 190, 43}, | |
101 | { 189, 40}, | |
102 | { 188, 38}, | |
103 | { 187, 35}, | |
104 | { 186, 33}, | |
105 | { 185, 30}, | |
106 | { 184, 28}, | |
107 | { 183, 25}, | |
108 | { 182, 23}, | |
109 | { 181, 20}, | |
110 | { 180, 18}, | |
111 | { 179, 15}, | |
112 | { 178, 13}, | |
113 | { 177, 10}, | |
114 | { 176, 8}, | |
115 | { 175, 5}, | |
116 | { 0, 0}, | |
117 | }; | |
118 | ||
078abcf9 RP |
119 | /* |
120 | * Read MAX1111 ADC | |
121 | */ | |
68677ab3 EM |
122 | extern int max1111_read_channel(int); |
123 | ||
b7557de4 | 124 | int sharpsl_pm_pxa_read_max1111(int channel) |
078abcf9 | 125 | { |
f8703dc8 RP |
126 | if (machine_is_tosa()) // Ugly, better move this function into another module |
127 | return 0; | |
128 | ||
f16177c2 EM |
129 | /* max1111 accepts channels from 0-3, however, |
130 | * it is encoded from 0-7 here in the code. | |
131 | */ | |
132 | return max1111_read_channel(channel >> 1); | |
078abcf9 RP |
133 | } |
134 | ||
b7557de4 | 135 | void sharpsl_pm_pxa_init(void) |
078abcf9 | 136 | { |
078abcf9 RP |
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); | |
140 | ||
141 | /* Register interrupt handlers */ | |
52e405ea | 142 | if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, IRQF_DISABLED, "AC Input Detect", sharpsl_ac_isr)) { |
078abcf9 RP |
143 | dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin)); |
144 | } | |
6cab4860 | 145 | else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin),IRQ_TYPE_EDGE_BOTH); |
078abcf9 | 146 | |
52e405ea | 147 | if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, IRQF_DISABLED, "Battery Cover", sharpsl_fatal_isr)) { |
078abcf9 RP |
148 | dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock)); |
149 | } | |
6cab4860 | 150 | else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQ_TYPE_EDGE_FALLING); |
078abcf9 RP |
151 | |
152 | if (sharpsl_pm.machinfo->gpio_fatal) { | |
52e405ea | 153 | if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED, "Fatal Battery", sharpsl_fatal_isr)) { |
078abcf9 RP |
154 | dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal)); |
155 | } | |
6cab4860 | 156 | else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQ_TYPE_EDGE_FALLING); |
078abcf9 RP |
157 | } |
158 | ||
f8703dc8 | 159 | if (sharpsl_pm.machinfo->batfull_irq) |
078abcf9 RP |
160 | { |
161 | /* Register interrupt handler. */ | |
52e405ea | 162 | if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED, "CO", sharpsl_chrg_full_isr)) { |
078abcf9 RP |
163 | dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull)); |
164 | } | |
6cab4860 | 165 | else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQ_TYPE_EDGE_RISING); |
078abcf9 | 166 | } |
078abcf9 RP |
167 | } |
168 | ||
b7557de4 | 169 | void sharpsl_pm_pxa_remove(void) |
078abcf9 | 170 | { |
078abcf9 RP |
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); | |
173 | ||
174 | if (sharpsl_pm.machinfo->gpio_fatal) | |
175 | free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr); | |
176 | ||
f8703dc8 | 177 | if (sharpsl_pm.machinfo->batfull_irq) |
078abcf9 | 178 | free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr); |
078abcf9 | 179 | } |