twl6030.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * (C) Copyright 2010
  3. * Texas Instruments, <www.ti.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 <config.h>
  24. #ifdef CONFIG_TWL6030_POWER
  25. #include <twl6030.h>
  26. /* Functions to read and write from TWL6030 */
  27. static inline int twl6030_i2c_write_u8(u8 chip_no, u8 val, u8 reg)
  28. {
  29. return i2c_write(chip_no, reg, 1, &val, 1);
  30. }
  31. static inline int twl6030_i2c_read_u8(u8 chip_no, u8 *val, u8 reg)
  32. {
  33. return i2c_read(chip_no, reg, 1, val, 1);
  34. }
  35. void twl6030_start_usb_charging(void)
  36. {
  37. twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_VICHRG_1500,
  38. CHARGERUSB_VICHRG);
  39. twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_CIN_LIMIT_NONE,
  40. CHARGERUSB_CINLIMIT);
  41. twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, MBAT_TEMP,
  42. CONTROLLER_INT_MASK);
  43. twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, MASK_MCHARGERUSB_THMREG,
  44. CHARGERUSB_INT_MASK);
  45. twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_VOREG_4P0,
  46. CHARGERUSB_VOREG);
  47. twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CHARGERUSB_CTRL2_VITERM_100,
  48. CHARGERUSB_CTRL2);
  49. /* Enable USB charging */
  50. twl6030_i2c_write_u8(TWL6030_CHIP_CHARGER, CONTROLLER_CTRL1_EN_CHARGER,
  51. CONTROLLER_CTRL1);
  52. return;
  53. }
  54. void twl6030_init_battery_charging(void)
  55. {
  56. twl6030_start_usb_charging();
  57. return;
  58. }
  59. void twl6030_usb_device_settings()
  60. {
  61. u8 data = 0;
  62. /* Select APP Group and set state to ON */
  63. twl6030_i2c_write_u8(TWL6030_CHIP_PM, 0x21, VUSB_CFG_STATE);
  64. twl6030_i2c_read_u8(TWL6030_CHIP_PM, &data, MISC2);
  65. data |= 0x10;
  66. /* Select the input supply for VBUS regulator */
  67. twl6030_i2c_write_u8(TWL6030_CHIP_PM, data, MISC2);
  68. }
  69. #endif