Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Samsung Electronics |
| 3 | * Przemyslaw Marczak <p.marczak@samsung.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <fdtdec.h> |
| 10 | #include <errno.h> |
| 11 | #include <dm.h> |
| 12 | #include <i2c.h> |
| 13 | #include <power/pmic.h> |
| 14 | #include <power/s2mps11.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static int s2mps11_reg_count(struct udevice *dev) |
| 19 | { |
| 20 | return S2MPS11_REG_COUNT; |
| 21 | } |
| 22 | |
| 23 | static int s2mps11_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 24 | int len) |
| 25 | { |
| 26 | int ret; |
| 27 | |
| 28 | ret = dm_i2c_write(dev, reg, buff, len); |
| 29 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 30 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 31 | |
| 32 | return ret; |
| 33 | } |
| 34 | |
| 35 | static int s2mps11_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 36 | { |
| 37 | int ret; |
| 38 | |
| 39 | ret = dm_i2c_read(dev, reg, buff, len); |
| 40 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 41 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Przemyslaw Marczak | 9181512 | 2015-10-27 13:07:58 +0100 | [diff] [blame] | 42 | |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | static struct dm_pmic_ops s2mps11_ops = { |
| 47 | .reg_count = s2mps11_reg_count, |
| 48 | .read = s2mps11_read, |
| 49 | .write = s2mps11_write, |
| 50 | }; |
| 51 | |
| 52 | static const struct udevice_id s2mps11_ids[] = { |
| 53 | { .compatible = "samsung,s2mps11-pmic" }, |
| 54 | { } |
| 55 | }; |
| 56 | |
| 57 | U_BOOT_DRIVER(pmic_s2mps11) = { |
| 58 | .name = "s2mps11_pmic", |
| 59 | .id = UCLASS_PMIC, |
| 60 | .of_match = s2mps11_ids, |
| 61 | .ops = &s2mps11_ops, |
| 62 | }; |