1 /* 2 * Copyright (C) 2012 Samsung Electronics 3 * Rajeshwari Shinde <rajeshwari.s@samsung.com> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <fdtdec.h> 10 #include <i2c.h> 11 #include <power/pmic.h> 12 #include <power/max77686_pmic.h> 13 #include <errno.h> 14 15 DECLARE_GLOBAL_DATA_PTR; 16 17 int pmic_init(unsigned char bus) 18 { 19 static const char name[] = "MAX77686_PMIC"; 20 struct pmic *p = pmic_alloc(); 21 22 if (!p) { 23 printf("%s: POWER allocation error!\n", __func__); 24 return -ENOMEM; 25 } 26 27 #ifdef CONFIG_OF_CONTROL 28 const void *blob = gd->fdt_blob; 29 int node, parent; 30 31 node = fdtdec_next_compatible(blob, 0, COMPAT_MAXIM_MAX77686_PMIC); 32 if (node < 0) { 33 debug("PMIC: No node for PMIC Chip in device tree\n"); 34 debug("node = %d\n", node); 35 return -1; 36 } 37 38 parent = fdt_parent_offset(blob, node); 39 if (parent < 0) { 40 debug("%s: Cannot find node parent\n", __func__); 41 return -1; 42 } 43 44 p->bus = i2c_get_bus_num_fdt(parent); 45 if (p->bus < 0) { 46 debug("%s: Cannot find I2C bus\n", __func__); 47 return -1; 48 } 49 p->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", 9); 50 #else 51 p->bus = bus; 52 p->hw.i2c.addr = MAX77686_I2C_ADDR; 53 #endif 54 55 p->name = name; 56 p->interface = PMIC_I2C; 57 p->number_of_regs = PMIC_NUM_OF_REGS; 58 p->hw.i2c.tx_num = 1; 59 60 puts("Board PMIC init\n"); 61 62 return 0; 63 } 64