Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | b084ddd | 2016-10-05 15:27:09 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Toradex AG |
| 4 | * Stefan Agner <stefan.agner@toradex.com> |
Stefan Agner | b084ddd | 2016-10-05 15:27:09 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Stefan Agner | b084ddd | 2016-10-05 15:27:09 -0700 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <errno.h> |
| 9 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 11 | #include <linux/libfdt.h> |
Stefan Agner | b084ddd | 2016-10-05 15:27:09 -0700 | [diff] [blame] | 12 | #include <power/rn5t567_pmic.h> |
| 13 | #include <power/pmic.h> |
| 14 | |
| 15 | static int rn5t567_reg_count(struct udevice *dev) |
| 16 | { |
| 17 | return RN5T567_NUM_OF_REGS; |
| 18 | } |
| 19 | |
| 20 | static int rn5t567_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) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 27 | debug("write error to device: %p register: %#x!\n", dev, reg); |
Stefan Agner | b084ddd | 2016-10-05 15:27:09 -0700 | [diff] [blame] | 28 | return ret; |
| 29 | } |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int rn5t567_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) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 40 | debug("read error from device: %p register: %#x!\n", dev, reg); |
Stefan Agner | b084ddd | 2016-10-05 15:27:09 -0700 | [diff] [blame] | 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static struct dm_pmic_ops rn5t567_ops = { |
| 48 | .reg_count = rn5t567_reg_count, |
| 49 | .read = rn5t567_read, |
| 50 | .write = rn5t567_write, |
| 51 | }; |
| 52 | |
| 53 | static const struct udevice_id rn5t567_ids[] = { |
| 54 | { .compatible = "ricoh,rn5t567" }, |
Martyn Welch | e32d036 | 2022-10-25 10:55:00 +0100 | [diff] [blame] | 55 | { .compatible = "ricoh,rn5t568" }, |
Stefan Agner | b084ddd | 2016-10-05 15:27:09 -0700 | [diff] [blame] | 56 | { } |
| 57 | }; |
| 58 | |
| 59 | U_BOOT_DRIVER(pmic_rn5t567) = { |
| 60 | .name = "rn5t567 pmic", |
| 61 | .id = UCLASS_PMIC, |
| 62 | .of_match = rn5t567_ids, |
| 63 | .ops = &rn5t567_ops, |
| 64 | }; |