sharpsl_pm.c 4.7 KB

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