Jaehoon Chung | 4997f6e | 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 | |
Jaehoon Chung | 4997f6e | 2017-02-02 17:04:09 +0900 | [diff] [blame] | 15 | static int max8997_reg_count(struct udevice *dev) |
| 16 | { |
| 17 | return PMIC_NUM_OF_REGS; |
| 18 | } |
| 19 | |
| 20 | static int max8997_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 21 | int len) |
| 22 | { |
| 23 | int ret; |
| 24 | |
| 25 | ret = dm_i2c_write(dev, reg, buff, len); |
| 26 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 27 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Jaehoon Chung | 4997f6e | 2017-02-02 17:04:09 +0900 | [diff] [blame] | 28 | |
| 29 | return ret; |
| 30 | } |
| 31 | |
| 32 | static int max8997_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 33 | { |
| 34 | int ret; |
| 35 | |
| 36 | ret = dm_i2c_read(dev, reg, buff, len); |
| 37 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 38 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Jaehoon Chung | 4997f6e | 2017-02-02 17:04:09 +0900 | [diff] [blame] | 39 | |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | static struct dm_pmic_ops max8997_ops = { |
| 44 | .reg_count = max8997_reg_count, |
| 45 | .read = max8997_read, |
| 46 | .write = max8997_write, |
| 47 | }; |
| 48 | |
| 49 | static const struct udevice_id max8997_ids[] = { |
| 50 | { .compatible = "maxim,max8997" }, |
| 51 | { }, |
| 52 | }; |
| 53 | |
| 54 | U_BOOT_DRIVER(pmic_max8997) = { |
| 55 | .name = "max8997_pmic", |
| 56 | .id = UCLASS_PMIC, |
| 57 | .of_match = max8997_ids, |
| 58 | .ops = &max8997_ops, |
| 59 | }; |