blob: 7208e5b67954b9113dde5fa6026ac049ab5d70a8 [file] [log] [blame]
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +00001/*
2 * Copyright (C) 2012 Samsung Electronics
3 * Rajeshwari Shinde <rajeshwari.s@samsung.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +00006 */
7
8#include <common.h>
Rajeshwari Shinde817cc272013-01-08 21:03:40 +00009#include <fdtdec.h>
10#include <i2c.h>
Rajeshwari Shindefe7c3622012-12-10 01:55:47 +000011#include <power/pmic.h>
12#include <power/max77686_pmic.h>
13#include <errno.h>
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +000014
Rajeshwari Shinde817cc272013-01-08 21:03:40 +000015DECLARE_GLOBAL_DATA_PTR;
16
Rajeshwari Shindefe7c3622012-12-10 01:55:47 +000017int pmic_init(unsigned char bus)
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +000018{
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +000019 static const char name[] = "MAX77686_PMIC";
Rajeshwari Shindefe7c3622012-12-10 01:55:47 +000020 struct pmic *p = pmic_alloc();
21
22 if (!p) {
23 printf("%s: POWER allocation error!\n", __func__);
24 return -ENOMEM;
25 }
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +000026
Rajeshwari Shinde817cc272013-01-08 21:03:40 +000027#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
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +000055 p->name = name;
56 p->interface = PMIC_I2C;
57 p->number_of_regs = PMIC_NUM_OF_REGS;
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +000058 p->hw.i2c.tx_num = 1;
Rajeshwari Shinde817cc272013-01-08 21:03:40 +000059
60 puts("Board PMIC init\n");
Rajeshwari Shindee9e8be82012-08-24 00:39:23 +000061
62 return 0;
63}