Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jaehoon Chung | 103e83a | 2016-12-15 18:21:10 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Samsung Electronics |
| 4 | * Jaehoon Chung <jh80.chung@samsung.com> |
Jaehoon Chung | 103e83a | 2016-12-15 18:21:10 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Jaehoon Chung | 1a5a05d | 2017-02-02 17:04:09 +0900 | [diff] [blame] | 9 | #include <errno.h> |
Jaehoon Chung | 103e83a | 2016-12-15 18:21:10 +0900 | [diff] [blame] | 10 | #include <i2c.h> |
| 11 | #include <power/pmic.h> |
| 12 | #include <power/max8998_pmic.h> |
Jaehoon Chung | 103e83a | 2016-12-15 18:21:10 +0900 | [diff] [blame] | 13 | |
Jaehoon Chung | 103e83a | 2016-12-15 18:21:10 +0900 | [diff] [blame] | 14 | static int max8998_reg_count(struct udevice *dev) |
| 15 | { |
| 16 | return PMIC_NUM_OF_REGS; |
| 17 | } |
| 18 | |
| 19 | static int max8998_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 20 | int len) |
| 21 | { |
| 22 | int ret; |
| 23 | |
| 24 | ret = dm_i2c_write(dev, reg, buff, len); |
| 25 | if (ret) |
Simon Glass | c83c436 | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 26 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
Jaehoon Chung | 103e83a | 2016-12-15 18:21:10 +0900 | [diff] [blame] | 27 | |
| 28 | return ret; |
| 29 | } |
| 30 | |
| 31 | static int max8998_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 32 | { |
| 33 | int ret; |
| 34 | |
| 35 | ret = dm_i2c_read(dev, reg, buff, len); |
| 36 | if (ret) |
Simon Glass | c83c436 | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 37 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
Jaehoon Chung | 103e83a | 2016-12-15 18:21:10 +0900 | [diff] [blame] | 38 | |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | static struct dm_pmic_ops max8998_ops = { |
| 43 | .reg_count = max8998_reg_count, |
| 44 | .read = max8998_read, |
| 45 | .write = max8998_write, |
| 46 | }; |
| 47 | |
| 48 | static const struct udevice_id max8998_ids[] = { |
| 49 | { .compatible = "maxim,max8998" }, |
| 50 | { } |
| 51 | }; |
| 52 | |
| 53 | U_BOOT_DRIVER(pmic_max8998) = { |
| 54 | .name = "max8998_pmic", |
| 55 | .id = UCLASS_PMIC, |
| 56 | .of_match = max8998_ids, |
| 57 | .ops = &max8998_ops, |
| 58 | }; |