sharpsl_pm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 <asm/hardware.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/apm-emulation.h>
  24. #include <asm/arch/pm.h>
  25. #include <asm/arch/pxa-regs.h>
  26. #include <asm/arch/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. return corgi_ssp_max1111_get((channel << MAXCTRL_SEL_SH) | MAXCTRL_PD0 | MAXCTRL_PD1
  127. | MAXCTRL_SGL | MAXCTRL_UNI | MAXCTRL_STR);
  128. }
  129. void sharpsl_pm_pxa_init(void)
  130. {
  131. pxa_gpio_mode(sharpsl_pm.machinfo->gpio_acin | GPIO_IN);
  132. pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batfull | GPIO_IN);
  133. pxa_gpio_mode(sharpsl_pm.machinfo->gpio_batlock | GPIO_IN);
  134. /* Register interrupt handlers */
  135. if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, IRQF_DISABLED, "AC Input Detect", sharpsl_ac_isr)) {
  136. dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin));
  137. }
  138. else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin),IRQT_BOTHEDGE);
  139. if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, IRQF_DISABLED, "Battery Cover", sharpsl_fatal_isr)) {
  140. dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock));
  141. }
  142. else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock),IRQT_FALLING);
  143. if (sharpsl_pm.machinfo->gpio_fatal) {
  144. if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED, "Fatal Battery", sharpsl_fatal_isr)) {
  145. dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal));
  146. }
  147. else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal),IRQT_FALLING);
  148. }
  149. if (sharpsl_pm.machinfo->batfull_irq)
  150. {
  151. /* Register interrupt handler. */
  152. if (request_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED, "CO", sharpsl_chrg_full_isr)) {
  153. dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull));
  154. }
  155. else set_irq_type(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull),IRQT_RISING);
  156. }
  157. }
  158. void sharpsl_pm_pxa_remove(void)
  159. {
  160. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr);
  161. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr);
  162. if (sharpsl_pm.machinfo->gpio_fatal)
  163. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr);
  164. if (sharpsl_pm.machinfo->batfull_irq)
  165. free_irq(IRQ_GPIO(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr);
  166. }