muic_max8997.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/power_chrg.h>
  26. #include <power/max8997_muic.h>
  27. #include <i2c.h>
  28. #include <errno.h>
  29. static int power_chrg_get_type(struct pmic *p)
  30. {
  31. unsigned int val;
  32. unsigned char charge_type, charger;
  33. if (pmic_probe(p))
  34. return CHARGER_NO;
  35. pmic_reg_read(p, MAX8997_MUIC_STATUS2, &val);
  36. charge_type = val & MAX8997_MUIC_CHG_MASK;
  37. switch (charge_type) {
  38. case MAX8997_MUIC_CHG_NO:
  39. charger = CHARGER_NO;
  40. break;
  41. case MAX8997_MUIC_CHG_USB:
  42. case MAX8997_MUIC_CHG_USB_D:
  43. charger = CHARGER_USB;
  44. break;
  45. case MAX8997_MUIC_CHG_TA:
  46. case MAX8997_MUIC_CHG_TA_1A:
  47. charger = CHARGER_TA;
  48. break;
  49. case MAX8997_MUIC_CHG_TA_500:
  50. charger = CHARGER_TA_500;
  51. break;
  52. default:
  53. charger = CHARGER_UNKNOWN;
  54. break;
  55. }
  56. return charger;
  57. }
  58. static struct power_chrg power_chrg_muic_ops = {
  59. .chrg_type = power_chrg_get_type,
  60. };
  61. int power_muic_init(unsigned int bus)
  62. {
  63. static const char name[] = "MAX8997_MUIC";
  64. struct pmic *p = pmic_alloc();
  65. if (!p) {
  66. printf("%s: POWER allocation error!\n", __func__);
  67. return -ENOMEM;
  68. }
  69. debug("Board Micro USB Interface Controller init\n");
  70. p->name = name;
  71. p->interface = PMIC_I2C;
  72. p->number_of_regs = MUIC_NUM_OF_REGS;
  73. p->hw.i2c.addr = MAX8997_MUIC_I2C_ADDR;
  74. p->hw.i2c.tx_num = 1;
  75. p->bus = bus;
  76. p->chrg = &power_chrg_muic_ops;
  77. return 0;
  78. }