Jaehoon Chung | 1a5a05d | 2017-02-02 17:04:09 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Samsung Electronics |
| 3 | * Jaehoon Chung <jh80.chung@samsung.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <i2c.h> |
| 11 | #include <power/pmic.h> |
| 12 | #include <power/max8997_pmic.h> |
| 13 | #include <errno.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | static int max8997_reg_count(struct udevice *dev) |
| 18 | { |
| 19 | return PMIC_NUM_OF_REGS; |
| 20 | } |
| 21 | |
| 22 | static int max8997_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 23 | int len) |
| 24 | { |
| 25 | int ret; |
| 26 | |
| 27 | ret = dm_i2c_write(dev, reg, buff, len); |
| 28 | if (ret) |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 29 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Jaehoon Chung | 1a5a05d | 2017-02-02 17:04:09 +0900 | [diff] [blame] | 30 | |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | static int max8997_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 35 | { |
| 36 | int ret; |
| 37 | |
| 38 | ret = dm_i2c_read(dev, reg, buff, len); |
| 39 | if (ret) |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 40 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Jaehoon Chung | 1a5a05d | 2017-02-02 17:04:09 +0900 | [diff] [blame] | 41 | |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | static struct dm_pmic_ops max8997_ops = { |
| 46 | .reg_count = max8997_reg_count, |
| 47 | .read = max8997_read, |
| 48 | .write = max8997_write, |
| 49 | }; |
| 50 | |
| 51 | static const struct udevice_id max8997_ids[] = { |
| 52 | { .compatible = "maxim,max8997" }, |
| 53 | { }, |
| 54 | }; |
| 55 | |
| 56 | U_BOOT_DRIVER(pmic_max8997) = { |
| 57 | .name = "max8997_pmic", |
| 58 | .id = UCLASS_PMIC, |
| 59 | .of_match = max8997_ids, |
| 60 | .ops = &max8997_ops, |
| 61 | }; |