axp20-board.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. int pmu_used;
  13. int pmu_twi_id;
  14. int pmu_irq_id;
  15. int pmu_twi_addr;
  16. int pmu_battery_rdc;
  17. int pmu_battery_cap;
  18. int pmu_init_chgcur;
  19. int pmu_suspend_chgcur;
  20. int pmu_resume_chgcur;
  21. int pmu_shutdown_chgcur;
  22. int pmu_init_chgvol;
  23. int pmu_init_chgend_rate;
  24. int pmu_init_chg_enabled;
  25. int pmu_init_adc_freq;
  26. int pmu_init_adc_freqc;
  27. int pmu_init_chg_pretime;
  28. int pmu_init_chg_csttime;
  29. int pmu_bat_para1;
  30. int pmu_bat_para2;
  31. int pmu_bat_para3;
  32. int pmu_bat_para4;
  33. int pmu_bat_para5;
  34. int pmu_bat_para6;
  35. int pmu_bat_para7;
  36. int pmu_bat_para8;
  37. int pmu_bat_para9;
  38. int pmu_bat_para10;
  39. int pmu_bat_para11;
  40. int pmu_bat_para12;
  41. int pmu_bat_para13;
  42. int pmu_bat_para14;
  43. int pmu_bat_para15;
  44. int pmu_bat_para16;
  45. int pmu_usbvol_limit;
  46. int pmu_usbvol;
  47. int pmu_usbcur_limit;
  48. int pmu_usbcur;
  49. int pmu_pwroff_vol;
  50. int pmu_pwron_vol;
  51. int dcdc2_vol;
  52. int dcdc3_vol;
  53. int ldo2_vol;
  54. int ldo3_vol;
  55. int ldo4_vol;
  56. int pmu_pekoff_time;
  57. int pmu_pekoff_en;
  58. int pmu_peklong_time;
  59. int pmu_pekon_time;
  60. int pmu_pwrok_time;
  61. int pmu_pwrnoe_time;
  62. int pmu_intotp_en;
  63. /* Reverse engineered partly from Platformx drivers */
  64. enum axp_regls{
  65. vcc_ldo1,
  66. vcc_ldo2,
  67. vcc_ldo3,
  68. vcc_ldo4,
  69. vcc_ldo5,
  70. vcc_buck2,
  71. vcc_buck3,
  72. vcc_ldoio0,
  73. };
  74. /* The values of the various regulator constraints are obviously dependent
  75. * on exactly what is wired to each ldo. Unfortunately this information is
  76. * not generally available. More information has been requested from Xbow
  77. * but as of yet they haven't been forthcoming.
  78. *
  79. * Some of these are clearly Stargate 2 related (no way of plugging
  80. * in an lcd on the IM2 for example!).
  81. */
  82. static struct regulator_consumer_supply ldo1_data[] = {
  83. {
  84. .supply = "axp20_rtc",
  85. },
  86. };
  87. static struct regulator_consumer_supply ldo2_data[] = {
  88. {
  89. .supply = "axp20_analog/fm",
  90. },
  91. };
  92. static struct regulator_consumer_supply ldo3_data[] = {
  93. {
  94. .supply = "axp20_pll",
  95. },
  96. };
  97. static struct regulator_consumer_supply ldo4_data[] = {
  98. {
  99. .supply = "axp20_hdmi",
  100. },
  101. };
  102. static struct regulator_consumer_supply ldoio0_data[] = {
  103. {
  104. .supply = "axp20_mic",
  105. },
  106. };
  107. static struct regulator_consumer_supply buck2_data[] = {
  108. {
  109. .supply = "axp20_core",
  110. },
  111. };
  112. static struct regulator_consumer_supply buck3_data[] = {
  113. {
  114. .supply = "axp20_ddr",
  115. },
  116. };
  117. static struct regulator_init_data axp_regl_init_data[] = {
  118. [vcc_ldo1] = {
  119. .constraints = { /* board default 1.25V */
  120. .name = "axp20_ldo1",
  121. .min_uV = AXP20LDO1 * 1000,
  122. .max_uV = AXP20LDO1 * 1000,
  123. },
  124. .num_consumer_supplies = ARRAY_SIZE(ldo1_data),
  125. .consumer_supplies = ldo1_data,
  126. },
  127. [vcc_ldo2] = {
  128. .constraints = { /* board default 3.0V */
  129. .name = "axp20_ldo2",
  130. .min_uV = 1800000,
  131. .max_uV = 3300000,
  132. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  133. .initial_state = PM_SUSPEND_STANDBY,
  134. .state_standby = {
  135. //.uV = ldo2_vol * 1000,
  136. .enabled = 1,
  137. }
  138. },
  139. .num_consumer_supplies = ARRAY_SIZE(ldo2_data),
  140. .consumer_supplies = ldo2_data,
  141. },
  142. [vcc_ldo3] = {
  143. .constraints = {/* default is 1.8V */
  144. .name = "axp20_ldo3",
  145. .min_uV = 700 * 1000,
  146. .max_uV = 3500* 1000,
  147. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  148. .initial_state = PM_SUSPEND_STANDBY,
  149. .state_standby = {
  150. //.uV = ldo3_vol * 1000,
  151. .enabled = 1,
  152. }
  153. },
  154. .num_consumer_supplies = ARRAY_SIZE(ldo3_data),
  155. .consumer_supplies = ldo3_data,
  156. },
  157. [vcc_ldo4] = {
  158. .constraints = {
  159. /* board default is 3.3V */
  160. .name = "axp20_ldo4",
  161. .min_uV = 1250000,
  162. .max_uV = 3300000,
  163. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  164. .initial_state = PM_SUSPEND_STANDBY,
  165. .state_standby = {
  166. //.uV = ldo4_vol * 1000,
  167. .enabled = 1,
  168. }
  169. },
  170. .num_consumer_supplies = ARRAY_SIZE(ldo4_data),
  171. .consumer_supplies = ldo4_data,
  172. },
  173. [vcc_buck2] = {
  174. .constraints = { /* default 1.24V */
  175. .name = "axp20_buck2",
  176. .min_uV = 700 * 1000,
  177. .max_uV = 2275 * 1000,
  178. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  179. .initial_state = PM_SUSPEND_STANDBY,
  180. .state_standby = {
  181. //.uV = dcdc2_vol * 1000,
  182. .enabled = 1,
  183. }
  184. },
  185. .num_consumer_supplies = ARRAY_SIZE(buck2_data),
  186. .consumer_supplies = buck2_data,
  187. },
  188. [vcc_buck3] = {
  189. .constraints = { /* default 2.5V */
  190. .name = "axp20_buck3",
  191. .min_uV = 700 * 1000,
  192. .max_uV = 3500 * 1000,
  193. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  194. .initial_state = PM_SUSPEND_STANDBY,
  195. .state_standby = {
  196. //.uV = dcdc3_vol * 1000,
  197. .enabled = 1,
  198. }
  199. },
  200. .num_consumer_supplies = ARRAY_SIZE(buck3_data),
  201. .consumer_supplies = buck3_data,
  202. },
  203. [vcc_ldoio0] = {
  204. .constraints = { /* default 2.5V */
  205. .name = "axp20_ldoio0",
  206. .min_uV = 1800 * 1000,
  207. .max_uV = 3300 * 1000,
  208. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
  209. },
  210. .num_consumer_supplies = ARRAY_SIZE(ldoio0_data),
  211. .consumer_supplies = ldoio0_data,
  212. },
  213. };
  214. static struct axp_funcdev_info axp_regldevs[] = {
  215. {
  216. .name = "axp20-regulator",
  217. .id = AXP20_ID_LDO1,
  218. .platform_data = &axp_regl_init_data[vcc_ldo1],
  219. }, {
  220. .name = "axp20-regulator",
  221. .id = AXP20_ID_LDO2,
  222. .platform_data = &axp_regl_init_data[vcc_ldo2],
  223. }, {
  224. .name = "axp20-regulator",
  225. .id = AXP20_ID_LDO3,
  226. .platform_data = &axp_regl_init_data[vcc_ldo3],
  227. }, {
  228. .name = "axp20-regulator",
  229. .id = AXP20_ID_LDO4,
  230. .platform_data = &axp_regl_init_data[vcc_ldo4],
  231. }, {
  232. .name = "axp20-regulator",
  233. .id = AXP20_ID_BUCK2,
  234. .platform_data = &axp_regl_init_data[vcc_buck2],
  235. }, {
  236. .name = "axp20-regulator",
  237. .id = AXP20_ID_BUCK3,
  238. .platform_data = &axp_regl_init_data[vcc_buck3],
  239. }, {
  240. .name = "axp20-regulator",
  241. .id = AXP20_ID_LDOIO0,
  242. .platform_data = &axp_regl_init_data[vcc_ldoio0],
  243. },
  244. };
  245. static struct power_supply_info battery_data ={
  246. .name ="PTI PL336078",
  247. .technology = POWER_SUPPLY_TECHNOLOGY_LiFe,
  248. //.voltage_max_design = pmu_init_chgvol,
  249. //.voltage_min_design = pmu_pwroff_vol,
  250. //.energy_full_design = pmu_battery_cap,
  251. .use_for_apm = 1,
  252. };
  253. static struct axp_supply_init_data axp_sply_init_data = {
  254. .battery_info = &battery_data,
  255. //.chgcur = pmu_init_chgcur,
  256. //.chgvol = pmu_init_chgvol,
  257. //.chgend = pmu_init_chgend_rate,
  258. //.chgen = pmu_init_chg_enabled,
  259. //.sample_time = pmu_init_adc_freq,
  260. //.chgpretime = pmu_init_chg_pretime,
  261. //.chgcsttime = pmu_init_chg_csttime,
  262. };
  263. static struct axp_funcdev_info axp_splydev[]={
  264. {
  265. .name = "axp20-supplyer",
  266. .id = AXP20_ID_SUPPLY,
  267. .platform_data = &axp_sply_init_data,
  268. },
  269. };
  270. static struct axp_funcdev_info axp_gpiodev[]={
  271. { .name = "axp20-gpio",
  272. .id = AXP20_ID_GPIO,
  273. },
  274. };
  275. static struct axp_platform_data axp_pdata = {
  276. .num_regl_devs = ARRAY_SIZE(axp_regldevs),
  277. .num_sply_devs = ARRAY_SIZE(axp_splydev),
  278. .num_gpio_devs = ARRAY_SIZE(axp_gpiodev),
  279. .regl_devs = axp_regldevs,
  280. .sply_devs = axp_splydev,
  281. .gpio_devs = axp_gpiodev,
  282. .gpio_base = 0,
  283. };
  284. static struct i2c_board_info __initdata axp_mfd_i2c_board_info[] = {
  285. {
  286. .type = "axp20_mfd",
  287. //.addr = pmu_twi_addr,
  288. .platform_data = &axp_pdata,
  289. //.irq = pmu_irq_id,
  290. },
  291. };
  292. static int __init axp_board_init(void)
  293. {
  294. int ret;
  295. struct i2c_adapter *adapter;
  296. pmu_twi_id = AXP20_I2CBUS;
  297. pmu_irq_id = AXP20_IRQNO;
  298. pmu_twi_addr = AXP20_ADDR;
  299. pmu_battery_rdc = BATRDC;
  300. pmu_battery_cap = BATTERYCAP;
  301. pmu_init_chgcur = INTCHGCUR ;
  302. pmu_suspend_chgcur = SUSCHGCUR ;
  303. pmu_resume_chgcur = RESCHGCUR ;
  304. pmu_shutdown_chgcur = CLSCHGCUR ;
  305. pmu_init_chgvol = INTCHGVOL ;
  306. pmu_init_chgend_rate = INTCHGENDRATE;
  307. pmu_init_chg_enabled = INTCHGENABLED;
  308. pmu_init_adc_freq = INTADCFREQ;
  309. pmu_init_adc_freq = INTADCFREQC;
  310. pmu_init_chg_pretime = INTCHGPRETIME;
  311. pmu_init_chg_csttime = INTCHGCSTTIME;
  312. pmu_bat_para1 = OCVREG0;
  313. pmu_bat_para2 = OCVREG1;
  314. pmu_bat_para3 = OCVREG2;
  315. pmu_bat_para4 = OCVREG3;
  316. pmu_bat_para5 = OCVREG4;
  317. pmu_bat_para6 = OCVREG5;
  318. pmu_bat_para7 = OCVREG6;
  319. pmu_bat_para8 = OCVREG7;
  320. pmu_bat_para9 = OCVREG8;
  321. pmu_bat_para10 = OCVREG9;
  322. pmu_bat_para11 = OCVREGA;
  323. pmu_bat_para12 = OCVREGB;
  324. pmu_bat_para13 = OCVREGC;
  325. pmu_bat_para14 = OCVREGD;
  326. pmu_bat_para15 = OCVREGE;
  327. pmu_bat_para16 = OCVREGF;
  328. pmu_usbvol_limit = 1;
  329. pmu_usbvol = 4000;
  330. pmu_usbcur_limit = 0;
  331. pmu_usbcur = 900;
  332. pmu_pwroff_vol = 2600;
  333. pmu_pwron_vol = 2600;
  334. dcdc2_vol = 1520;//1400;
  335. dcdc3_vol = 1220;//1250;
  336. ldo2_vol = 3000;
  337. ldo3_vol = 2800;
  338. ldo4_vol = 2800;
  339. pmu_pekoff_time = 6000;
  340. pmu_pekoff_en = 1;
  341. pmu_peklong_time = 1500;
  342. pmu_pwrok_time = 64;
  343. pmu_pwrnoe_time = 2000;
  344. pmu_intotp_en = 1;
  345. pmu_pekon_time = 1000;
  346. //axp_regl_init_data[1].constraints.state_standby.uV = ldo2_vol * 1000;
  347. //axp_regl_init_data[2].constraints.state_standby.uV = ldo3_vol * 1000;
  348. //axp_regl_init_data[3].constraints.state_standby.uV = ldo4_vol * 1000;
  349. axp_regl_init_data[5].constraints.state_standby.uV = dcdc2_vol * 1000;
  350. axp_regl_init_data[6].constraints.state_standby.uV = dcdc3_vol * 1000;
  351. battery_data.voltage_max_design = pmu_init_chgvol;
  352. battery_data.voltage_min_design = pmu_pwroff_vol * 1000;
  353. battery_data.energy_full_design = pmu_battery_cap;
  354. axp_sply_init_data.chgcur = pmu_init_chgcur;
  355. axp_sply_init_data.chgvol = pmu_init_chgvol;
  356. axp_sply_init_data.chgend = pmu_init_chgend_rate;
  357. axp_sply_init_data.chgen = pmu_init_chg_enabled;
  358. axp_sply_init_data.sample_time = pmu_init_adc_freq;
  359. axp_sply_init_data.chgpretime = pmu_init_chg_pretime;
  360. axp_sply_init_data.chgcsttime = pmu_init_chg_csttime;
  361. axp_mfd_i2c_board_info[0].addr = pmu_twi_addr;
  362. axp_mfd_i2c_board_info[0].irq = pmu_irq_id;
  363. /*
  364. return i2c_register_board_info(pmu_twi_id, axp_mfd_i2c_board_info,
  365. ARRAY_SIZE(axp_mfd_i2c_board_info));
  366. */
  367. adapter = i2c_get_adapter(pmu_twi_id);
  368. i2c_new_device(adapter, axp_mfd_i2c_board_info);
  369. return 0;
  370. }
  371. arch_initcall(axp_board_init);
  372. MODULE_DESCRIPTION("Krosspower axp board");
  373. MODULE_AUTHOR("Donglu Zhang Krosspower");
  374. MODULE_LICENSE("GPL");