pmic_max77686.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. * Rajeshwari Shinde <rajeshwari.s@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 <fdtdec.h>
  25. #include <i2c.h>
  26. #include <power/pmic.h>
  27. #include <power/max77686_pmic.h>
  28. #include <errno.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. int pmic_init(unsigned char bus)
  31. {
  32. static const char name[] = "MAX77686_PMIC";
  33. struct pmic *p = pmic_alloc();
  34. if (!p) {
  35. printf("%s: POWER allocation error!\n", __func__);
  36. return -ENOMEM;
  37. }
  38. #ifdef CONFIG_OF_CONTROL
  39. const void *blob = gd->fdt_blob;
  40. int node, parent;
  41. node = fdtdec_next_compatible(blob, 0, COMPAT_MAXIM_MAX77686_PMIC);
  42. if (node < 0) {
  43. debug("PMIC: No node for PMIC Chip in device tree\n");
  44. debug("node = %d\n", node);
  45. return -1;
  46. }
  47. parent = fdt_parent_offset(blob, node);
  48. if (parent < 0) {
  49. debug("%s: Cannot find node parent\n", __func__);
  50. return -1;
  51. }
  52. p->bus = i2c_get_bus_num_fdt(parent);
  53. if (p->bus < 0) {
  54. debug("%s: Cannot find I2C bus\n", __func__);
  55. return -1;
  56. }
  57. p->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", 9);
  58. #else
  59. p->bus = bus;
  60. p->hw.i2c.addr = MAX77686_I2C_ADDR;
  61. #endif
  62. p->name = name;
  63. p->interface = PMIC_I2C;
  64. p->number_of_regs = PMIC_NUM_OF_REGS;
  65. p->hw.i2c.tx_num = 1;
  66. puts("Board PMIC init\n");
  67. return 0;
  68. }