bat_trats.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. * Lukasz Majewski <l.majewski@samsung.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <power/pmic.h>
  25. #include <power/battery.h>
  26. #include <power/max8997_pmic.h>
  27. #include <errno.h>
  28. static struct battery battery_trats;
  29. static int power_battery_charge(struct pmic *bat)
  30. {
  31. struct power_battery *p_bat = bat->pbat;
  32. struct battery *battery = p_bat->bat;
  33. int k;
  34. if (bat->chrg->chrg_state(p_bat->chrg, CHARGER_ENABLE, 450))
  35. return -1;
  36. for (k = 0; bat->chrg->chrg_bat_present(p_bat->chrg) &&
  37. bat->chrg->chrg_type(p_bat->muic) &&
  38. battery->state_of_chrg < 100; k++) {
  39. udelay(2000000);
  40. if (!(k % 5))
  41. puts(".");
  42. bat->fg->fg_battery_update(p_bat->fg, bat);
  43. if (k == 200) {
  44. debug(" %d [V]", battery->voltage_uV);
  45. puts("\n");
  46. k = 0;
  47. }
  48. if (ctrlc()) {
  49. printf("\nCharging disabled on request.\n");
  50. goto exit;
  51. }
  52. }
  53. exit:
  54. bat->chrg->chrg_state(p_bat->chrg, CHARGER_DISABLE, 0);
  55. return 0;
  56. }
  57. static int power_battery_init_trats(struct pmic *bat_,
  58. struct pmic *fg_,
  59. struct pmic *chrg_,
  60. struct pmic *muic_)
  61. {
  62. bat_->pbat->fg = fg_;
  63. bat_->pbat->chrg = chrg_;
  64. bat_->pbat->muic = muic_;
  65. bat_->fg = fg_->fg;
  66. bat_->chrg = chrg_->chrg;
  67. bat_->chrg->chrg_type = muic_->chrg->chrg_type;
  68. return 0;
  69. }
  70. static struct power_battery power_bat_trats = {
  71. .bat = &battery_trats,
  72. .battery_init = power_battery_init_trats,
  73. .battery_charge = power_battery_charge,
  74. };
  75. int power_bat_init(unsigned char bus)
  76. {
  77. static const char name[] = "BAT_TRATS";
  78. struct pmic *p = pmic_alloc();
  79. if (!p) {
  80. printf("%s: POWER allocation error!\n", __func__);
  81. return -ENOMEM;
  82. }
  83. debug("Board BAT init\n");
  84. p->interface = PMIC_NONE;
  85. p->name = name;
  86. p->bus = bus;
  87. p->pbat = &power_bat_trats;
  88. return 0;
  89. }