axp18-board.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #include <linux/init.h>
  2. #include <linux/device.h>
  3. #include <linux/platform_device.h>
  4. #include <linux/regulator/machine.h>
  5. #include <linux/i2c.h>
  6. #include <mach/irqs.h>
  7. #include <linux/power_supply.h>
  8. #include <linux/apm_bios.h>
  9. #include <linux/apm-emulation.h>
  10. #include "axp-mfd.h"
  11. #include "axp-cfg.h"
  12. /* Reverse engineered partly from Platformx drivers */
  13. enum axp_regls{
  14. vcc_ldo1,
  15. vcc_ldo2,
  16. vcc_ldo3,
  17. vcc_ldo4,
  18. vcc_ldo5,
  19. vcc_buck1,
  20. vcc_buck2,
  21. vcc_buck3,
  22. vcc_sw1,
  23. vcc_sw2,
  24. };
  25. /* The values of the various regulator constraints are obviously dependent
  26. * on exactly what is wired to each ldo. Unfortunately this information is
  27. * not generally available. More information has been requested from Xbow
  28. * but as of yet they haven't been forthcoming.
  29. *
  30. * Some of these are clearly Stargate 2 related (no way of plugging
  31. * in an lcd on the IM2 for example!).
  32. */
  33. static struct regulator_consumer_supply ldo1_data[] = {
  34. {
  35. .supply = "axp18_rtc",
  36. },
  37. };
  38. static struct regulator_consumer_supply ldo2_data[] = {
  39. {
  40. .supply = "axp18_analog/fm",
  41. },
  42. };
  43. static struct regulator_consumer_supply ldo3_data[] = {
  44. {
  45. .supply = "axp18_flash",
  46. },
  47. };
  48. static struct regulator_consumer_supply ldo4_data[] = {
  49. {
  50. .supply = "axp18_spdif",
  51. },
  52. };
  53. static struct regulator_consumer_supply ldo5_data[] = {
  54. {
  55. .supply = "axp18_others",
  56. },
  57. };
  58. static struct regulator_consumer_supply buck1_data[] = {
  59. {
  60. .supply = "axp18_io",
  61. },{
  62. .supply = "axp18_sw1",
  63. },{
  64. .supply = "axp18_sw2",
  65. },
  66. };
  67. static struct regulator_consumer_supply buck2_data[] = {
  68. {
  69. .supply = "axp18_core",
  70. },
  71. };
  72. static struct regulator_consumer_supply buck3_data[] = {
  73. {
  74. .supply = "axp18_memory",
  75. },
  76. };
  77. static struct regulator_consumer_supply sw1_data[] = {
  78. {
  79. .supply = "axp18_sdram",
  80. },
  81. };
  82. static struct regulator_consumer_supply sw2_data[] = {
  83. {
  84. .supply = "axp18_sdcard",
  85. },
  86. };
  87. static struct regulator_init_data axp_regl_init_data[] = {
  88. [vcc_ldo1] = {
  89. .constraints = { /* board default 1.25V */
  90. .name = "axp18_ldo1",
  91. .min_uV = LDO1MIN * 1000,
  92. .max_uV = LDO1MAX * 1000,
  93. },
  94. .num_consumer_supplies = ARRAY_SIZE(ldo1_data),
  95. .consumer_supplies = ldo1_data,
  96. },
  97. [vcc_ldo2] = {
  98. .constraints = { /* board default 3.0V */
  99. .name = "axp18_ldo2",
  100. .min_uV = 2800000,
  101. .max_uV = 3100000,
  102. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  103. },
  104. .num_consumer_supplies = ARRAY_SIZE(ldo2_data),
  105. .consumer_supplies = ldo2_data,
  106. },
  107. [vcc_ldo3] = {
  108. .constraints = {/* default is 1.8V */
  109. .name = "axp18_ldo3",
  110. .min_uV = LDO3MIN * 1000,
  111. .max_uV = LDO3MAX * 1000,
  112. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  113. },
  114. .num_consumer_supplies = ARRAY_SIZE(ldo3_data),
  115. .consumer_supplies = ldo3_data,
  116. },
  117. [vcc_ldo4] = {
  118. .constraints = {
  119. /* board default is 3.3V */
  120. .name = "axp18_ldo4",
  121. .min_uV = 2700000,
  122. .max_uV = 3300000,
  123. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  124. },
  125. .num_consumer_supplies = ARRAY_SIZE(ldo4_data),
  126. .consumer_supplies = ldo4_data,
  127. },
  128. [vcc_ldo5] = {
  129. .constraints = { /* default 3.3V */
  130. .name = "axp18_ldo5",
  131. .min_uV = 2500000,
  132. .max_uV = 3300000,
  133. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  134. },
  135. .num_consumer_supplies = ARRAY_SIZE(ldo5_data),
  136. .consumer_supplies = ldo5_data,
  137. },
  138. [vcc_buck1] = {
  139. .constraints = { /* default 3.3V */
  140. .name = "axp18_buck1",
  141. .min_uV = 2800000,
  142. .max_uV = 3500000,
  143. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE ,
  144. },
  145. .num_consumer_supplies = ARRAY_SIZE(buck1_data),
  146. .consumer_supplies = buck1_data,
  147. },
  148. [vcc_buck2] = {
  149. .constraints = { /* default 1.24V */
  150. .name = "axp18_buck2",
  151. .min_uV = DCDC2MIN * 1000,
  152. .max_uV = DCDC2MAX * 1000,
  153. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  154. },
  155. .num_consumer_supplies = ARRAY_SIZE(buck2_data),
  156. .consumer_supplies = buck2_data,
  157. },
  158. [vcc_buck3] = {
  159. .constraints = { /* default 2.5V */
  160. .name = "axp18_buck3",
  161. .min_uV = DCDC3MIN * 1000,
  162. .max_uV = DCDC3MAX * 1000,
  163. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  164. },
  165. .num_consumer_supplies = ARRAY_SIZE(buck3_data),
  166. .consumer_supplies = buck3_data,
  167. },
  168. [vcc_sw1] = {
  169. .constraints = { /* default 3.3V */
  170. .name = "axp18_sw1",
  171. .min_uV = 2800000,
  172. .max_uV = 3500000,
  173. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  174. },
  175. .num_consumer_supplies = ARRAY_SIZE(sw1_data),
  176. .consumer_supplies = sw1_data,
  177. },
  178. [vcc_sw2] = {
  179. .constraints = { /* default 3.3V */
  180. .name = "axp18_sw2",
  181. .min_uV = 2800000,
  182. .max_uV = 3500000,
  183. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  184. },
  185. .num_consumer_supplies = ARRAY_SIZE(sw2_data),
  186. .consumer_supplies = sw2_data,
  187. },
  188. };
  189. static struct axp_funcdev_info axp_regldevs[] = {
  190. {
  191. .name = "axp18-regulator",
  192. .id = AXP18_ID_LDO1,
  193. .platform_data = &axp_regl_init_data[vcc_ldo1],
  194. }, {
  195. .name = "axp18-regulator",
  196. .id = AXP18_ID_LDO2,
  197. .platform_data = &axp_regl_init_data[vcc_ldo2],
  198. }, {
  199. .name = "axp18-regulator",
  200. .id = AXP18_ID_LDO3,
  201. .platform_data = &axp_regl_init_data[vcc_ldo3],
  202. }, {
  203. .name = "axp18-regulator",
  204. .id = AXP18_ID_LDO4,
  205. .platform_data = &axp_regl_init_data[vcc_ldo4],
  206. }, {
  207. .name = "axp18-regulator",
  208. .id = AXP18_ID_LDO5,
  209. .platform_data = &axp_regl_init_data[vcc_ldo5],
  210. }, {
  211. .name = "axp18-regulator",
  212. .id = AXP18_ID_BUCK1,
  213. .platform_data = &axp_regl_init_data[vcc_buck1],
  214. }, {
  215. .name = "axp18-regulator",
  216. .id = AXP18_ID_BUCK2,
  217. .platform_data = &axp_regl_init_data[vcc_buck2],
  218. }, {
  219. .name = "axp18-regulator",
  220. .id = AXP18_ID_BUCK3,
  221. .platform_data = &axp_regl_init_data[vcc_buck3],
  222. }, {
  223. .name = "axp18-regulator",
  224. .id = AXP18_ID_SW1,
  225. .platform_data = &axp_regl_init_data[vcc_sw1],
  226. }, {
  227. .name = "axp18-regulator",
  228. .id = AXP18_ID_SW2,
  229. .platform_data = &axp_regl_init_data[vcc_sw2],
  230. },
  231. };
  232. static struct power_supply_info battery_data ={
  233. .name ="axp18-battery",
  234. .technology = POWER_SUPPLY_TECHNOLOGY_LiFe,
  235. .voltage_max_design = 4200000,
  236. .voltage_min_design = 2700000,
  237. .charge_full_design = 1450,
  238. .energy_full_design = 1450,
  239. .use_for_apm = 1,
  240. };
  241. static void axp_battery_low(void)
  242. {
  243. #if defined(CONFIG_APM_EMULATION)
  244. apm_queue_event(APM_LOW_BATTERY);
  245. #endif
  246. }
  247. static void axp_battery_critical(void)
  248. {
  249. #if defined(CONFIG_APM_EMULATION)
  250. apm_queue_event(APM_CRITICAL_SUSPEND);
  251. #endif
  252. }
  253. static struct axp_supply_init_data axp_sply_init_data = {
  254. .battery_info = &battery_data,
  255. .chgcur = 700,
  256. .chgvol = 4200,
  257. .chgend = 70,
  258. .chgen = 1,
  259. .limit_on = 1,
  260. .sample_time = 25,
  261. .chgpretime = 40,
  262. .chgcsttime = 480,
  263. .battery_low = axp_battery_low,
  264. .battery_critical = axp_battery_critical,
  265. };
  266. static struct axp_funcdev_info axp_splydev[]={
  267. { .name = "axp18-supplyer",
  268. .id = AXP18_ID_SUPPLY,
  269. .platform_data = &axp_sply_init_data,
  270. },
  271. };
  272. static struct axp_platform_data axp_pdata = {
  273. .num_regl_devs = ARRAY_SIZE(axp_regldevs),
  274. .num_sply_devs = ARRAY_SIZE(axp_splydev),
  275. .regl_devs = axp_regldevs,
  276. .sply_devs = axp_splydev,
  277. };
  278. static struct i2c_board_info __initdata axp_mfd_i2c_board_info[] = {
  279. {
  280. .type = "axp18_mfd",
  281. .addr = AXP18_ADDR,
  282. .platform_data = &axp_pdata,
  283. .irq = SW_INT_IRQNO_ENMI,
  284. },
  285. };
  286. static int __init axp_board_init(void)
  287. {
  288. return i2c_register_board_info(AXP18_I2CBUS, axp_mfd_i2c_board_info,
  289. ARRAY_SIZE(axp_mfd_i2c_board_info));
  290. }
  291. module_init(axp_board_init);
  292. MODULE_DESCRIPTION("Krosspower axp board");
  293. MODULE_AUTHOR("Donglu Zhang Krosspower");
  294. MODULE_LICENSE("GPL");