Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics |
| 3 | * Rajeshwari Shinde <rajeshwari.s@samsung.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Rajeshwari Shinde | 817cc27 | 2013-01-08 21:03:40 +0000 | [diff] [blame] | 9 | #include <fdtdec.h> |
| 10 | #include <i2c.h> |
Rajeshwari Shinde | fe7c362 | 2012-12-10 01:55:47 +0000 | [diff] [blame] | 11 | #include <power/pmic.h> |
| 12 | #include <power/max77686_pmic.h> |
| 13 | #include <errno.h> |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 14 | |
Rajeshwari Shinde | 817cc27 | 2013-01-08 21:03:40 +0000 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Rajeshwari Shinde | fe7c362 | 2012-12-10 01:55:47 +0000 | [diff] [blame] | 17 | int pmic_init(unsigned char bus) |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 18 | { |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 19 | static const char name[] = "MAX77686_PMIC"; |
Rajeshwari Shinde | fe7c362 | 2012-12-10 01:55:47 +0000 | [diff] [blame] | 20 | struct pmic *p = pmic_alloc(); |
| 21 | |
| 22 | if (!p) { |
| 23 | printf("%s: POWER allocation error!\n", __func__); |
| 24 | return -ENOMEM; |
| 25 | } |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 26 | |
Rajeshwari Shinde | 817cc27 | 2013-01-08 21:03:40 +0000 | [diff] [blame] | 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 | |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 55 | p->name = name; |
| 56 | p->interface = PMIC_I2C; |
| 57 | p->number_of_regs = PMIC_NUM_OF_REGS; |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 58 | p->hw.i2c.tx_num = 1; |
Rajeshwari Shinde | 817cc27 | 2013-01-08 21:03:40 +0000 | [diff] [blame] | 59 | |
| 60 | puts("Board PMIC init\n"); |
Rajeshwari Shinde | e9e8be8 | 2012-08-24 00:39:23 +0000 | [diff] [blame] | 61 | |
| 62 | return 0; |
| 63 | } |