pmic.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2011-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. #ifndef __CORE_PMIC_H_
  24. #define __CORE_PMIC_H_
  25. #include <common.h>
  26. #include <linux/list.h>
  27. #include <i2c.h>
  28. #include <power/power_chrg.h>
  29. enum { PMIC_I2C, PMIC_SPI, PMIC_NONE};
  30. enum { I2C_PMIC, I2C_NUM, };
  31. enum { PMIC_READ, PMIC_WRITE, };
  32. enum { PMIC_SENSOR_BYTE_ORDER_LITTLE, PMIC_SENSOR_BYTE_ORDER_BIG, };
  33. struct p_i2c {
  34. unsigned char addr;
  35. unsigned char *buf;
  36. unsigned char tx_num;
  37. };
  38. struct p_spi {
  39. unsigned int cs;
  40. unsigned int mode;
  41. unsigned int bitlen;
  42. unsigned int clk;
  43. unsigned int flags;
  44. u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
  45. };
  46. struct pmic;
  47. struct power_fg {
  48. int (*fg_battery_check) (struct pmic *p, struct pmic *bat);
  49. int (*fg_battery_update) (struct pmic *p, struct pmic *bat);
  50. };
  51. struct power_chrg {
  52. int (*chrg_type) (struct pmic *p);
  53. int (*chrg_bat_present) (struct pmic *p);
  54. int (*chrg_state) (struct pmic *p, int state, int current);
  55. };
  56. struct power_battery {
  57. struct battery *bat;
  58. int (*battery_init) (struct pmic *bat, struct pmic *p1,
  59. struct pmic *p2, struct pmic *p3);
  60. int (*battery_charge) (struct pmic *bat);
  61. /* Keep info about power devices involved with battery operation */
  62. struct pmic *chrg, *fg, *muic;
  63. };
  64. struct pmic {
  65. const char *name;
  66. unsigned char bus;
  67. unsigned char interface;
  68. unsigned char sensor_byte_order;
  69. unsigned int number_of_regs;
  70. union hw {
  71. struct p_i2c i2c;
  72. struct p_spi spi;
  73. } hw;
  74. void (*low_power_mode) (void);
  75. struct power_battery *pbat;
  76. struct power_chrg *chrg;
  77. struct power_fg *fg;
  78. struct pmic *parent;
  79. struct list_head list;
  80. };
  81. int pmic_init(unsigned char bus);
  82. int pmic_dialog_init(unsigned char bus);
  83. int check_reg(struct pmic *p, u32 reg);
  84. struct pmic *pmic_alloc(void);
  85. struct pmic *pmic_get(const char *s);
  86. int pmic_probe(struct pmic *p);
  87. int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
  88. int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
  89. int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
  90. #define pmic_i2c_addr (p->hw.i2c.addr)
  91. #define pmic_i2c_tx_num (p->hw.i2c.tx_num)
  92. #define pmic_spi_bitlen (p->hw.spi.bitlen)
  93. #define pmic_spi_flags (p->hw.spi.flags)
  94. #endif /* __CORE_PMIC_H_ */