bat_trats.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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(10000000);
  40. puts(".");
  41. bat->fg->fg_battery_update(p_bat->fg, bat);
  42. if (k == 100) {
  43. debug(" %d [V]", battery->voltage_uV);
  44. puts("\n");
  45. k = 0;
  46. }
  47. }
  48. bat->chrg->chrg_state(p_bat->chrg, CHARGER_DISABLE, 0);
  49. return 0;
  50. }
  51. static int power_battery_init_trats(struct pmic *bat_,
  52. struct pmic *fg_,
  53. struct pmic *chrg_,
  54. struct pmic *muic_)
  55. {
  56. bat_->pbat->fg = fg_;
  57. bat_->pbat->chrg = chrg_;
  58. bat_->pbat->muic = muic_;
  59. bat_->fg = fg_->fg;
  60. bat_->chrg = chrg_->chrg;
  61. bat_->chrg->chrg_type = muic_->chrg->chrg_type;
  62. return 0;
  63. }
  64. static struct power_battery power_bat_trats = {
  65. .bat = &battery_trats,
  66. .battery_init = power_battery_init_trats,
  67. .battery_charge = power_battery_charge,
  68. };
  69. int power_bat_init(unsigned char bus)
  70. {
  71. static const char name[] = "BAT_TRATS";
  72. struct pmic *p = pmic_alloc();
  73. if (!p) {
  74. printf("%s: POWER allocation error!\n", __func__);
  75. return -ENOMEM;
  76. }
  77. debug("Board BAT init\n");
  78. p->interface = PMIC_NONE;
  79. p->name = name;
  80. p->bus = bus;
  81. p->pbat = &power_bat_trats;
  82. return 0;
  83. }