sharpsl_pm.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #undef DEBUG
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/irq.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/apm-emulation.h>
  22. #include <mach/hardware.h>
  23. #include <asm/mach-types.h>
  24. #include <mach/pm.h>
  25. #include <mach/pxa2xx-gpio.h>
  26. #include <mach/sharpsl.h>
  27. #include "sharpsl.h"
  28. struct battery_thresh spitz_battery_levels_acin[] = {
  29. { 213, 100},
  30. { 212, 98},
  31. { 211, 95},
  32. { 210, 93},
  33. { 209, 90},
  34. { 208, 88},
  35. { 207, 85},
  36. { 206, 83},
  37. { 205, 80},
  38. { 204, 78},
  39. { 203, 75},
  40. { 202, 73},
  41. { 201, 70},
  42. { 200, 68},
  43. { 199, 65},
  44. { 198, 63},
  45. { 197, 60},
  46. { 196, 58},
  47. { 195, 55},
  48. { 194, 53},
  49. { 193, 50},
  50. { 192, 48},
  51. { 192, 45},
  52. { 191, 43},
  53. { 191, 40},
  54. { 190, 38},
  55. { 190, 35},
  56. { 189, 33},
  57. { 188, 30},
  58. { 187, 28},
  59. { 186, 25},
  60. { 185, 23},
  61. { 184, 20},
  62. { 183, 18},
  63. { 182, 15},
  64. { 181, 13},
  65. { 180, 10},
  66. { 179, 8},
  67. { 178, 5},
  68. { 0, 0},
  69. };
  70. struct battery_thresh spitz_battery_levels_noac[] = {
  71. { 213, 100},
  72. { 212, 98},
  73. { 211, 95},
  74. { 210, 93},
  75. { 209, 90},
  76. { 208, 88},
  77. { 207, 85},
  78. { 206, 83},
  79. { 205, 80},
  80. { 204, 78},
  81. { 203, 75},
  82. { 202, 73},
  83. { 201, 70},
  84. { 200, 68},
  85. { 199, 65},
  86. { 198, 63},
  87. { 197, 60},
  88. { 196, 58},
  89. { 195, 55},
  90. { 194, 53},
  91. { 193, 50},
  92. { 192, 48},
  93. { 191, 45},
  94. { 190, 43},
  95. { 189, 40},
  96. { 188, 38},
  97. { 187, 35},
  98. { 186, 33},
  99. { 185, 30},
  100. { 184, 28},
  101. { 183, 25},
  102. { 182, 23},
  103. { 181, 20},
  104. { 180, 18},
  105. { 179, 15},
  106. { 178, 13},
  107. { 177, 10},
  108. { 176, 8},
  109. { 175, 5},
  110. { 0, 0},
  111. };
  112. /* MAX1111 Commands */
  113. #define MAXCTRL_PD0 1u << 0
  114. #define MAXCTRL_PD1 1u << 1
  115. #define MAXCTRL_SGL 1u << 2
  116. #define MAXCTRL_UNI 1u << 3
  117. #define MAXCTRL_SEL_SH 4
  118. #define MAXCTRL_STR 1u << 7
  119. /*
  120. * Read MAX1111 ADC
  121. */
  122. int sharpsl_pm_pxa_read_max1111(int channel)
  123. {
  124. if (machine_is_tosa()) // Ugly, better move this function into another module
  125. return 0;
  126. #ifdef CONFIG_CORGI_SSP_DEPRECATED
  127. return corgi_ssp_max1111_get((channel << MAXCTRL_SEL_SH) | MAXCTRL_PD0 | MAXCTRL_PD1
  128. | MAXCTRL_SGL | MAXCTRL_UNI | MAXCTRL_STR);
  129. #else
  130. extern int max1111_read_channel(int);
  131. /* max1111 accepts channels from 0-3, however,
  132. * it is encoded from 0-7 here in the code.
  133. */
  134. return max1111_read_channel(channel >> 1);
  135. #endif
  136. }
  137. void sharpsl_pm_pxa_init(void)
  138. {
  139. pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
  140. pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
  141. 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, IRQF_DISABLED, "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));
  145. }
  146. 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));
  149. }
  150. else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQ_TYPE_EDGE_FALLING);
  151. if (sharpsl_pm.machinfo->gpio_fatal) {
  152. if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED, "Fatal Battery", sharpsl_fatal_isr)) {
  153. dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal));
  154. }
  155. else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQ_TYPE_EDGE_FALLING);
  156. }
  157. if (sharpsl_pm.machinfo->batfull_irq)
  158. {
  159. /* Register interrupt handler. */
  160. if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED, "CO", sharpsl_chrg_full_isr)) {
  161. dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull));
  162. }
  163. else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQ_TYPE_EDGE_RISING);
  164. }
  165. }
  166. void sharpsl_pm_pxa_remove(void)
  167. {
  168. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
  169. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
  170. if (sharpsl_pm.machinfo->gpio_fatal)
  171. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr);
  172. if (sharpsl_pm.machinfo->batfull_irq)
  173. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);
  174. }