Philipp Tomsich | b7f57e1 | 2018-11-30 20:00:08 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) 2018 Theobroma Systems Design und Consulting GmbH |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Philipp Tomsich | b7f57e1 | 2018-11-30 20:00:08 +0100 | [diff] [blame] | 9 | #include <dm/device-internal.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <dm/device_compat.h> |
Philipp Tomsich | b7f57e1 | 2018-11-30 20:00:08 +0100 | [diff] [blame] | 11 | #include <dm/lists.h> |
| 12 | #include <i2c.h> |
Vasily Khoruzhick | 43e7b34 | 2019-11-16 11:32:03 -0800 | [diff] [blame] | 13 | #include <power/fan53555.h> |
Philipp Tomsich | b7f57e1 | 2018-11-30 20:00:08 +0100 | [diff] [blame] | 14 | #include <power/pmic.h> |
| 15 | #include <power/regulator.h> |
| 16 | |
| 17 | static int pmic_fan53555_reg_count(struct udevice *dev) |
| 18 | { |
| 19 | return 1; |
| 20 | }; |
| 21 | |
| 22 | static int pmic_fan53555_read(struct udevice *dev, uint reg, |
| 23 | u8 *buff, int len) |
| 24 | { |
| 25 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 26 | pr_err("%s: read error for register: %#x!", dev->name, reg); |
| 27 | return -EIO; |
| 28 | } |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static int pmic_fan53555_write(struct udevice *dev, uint reg, |
| 34 | const u8 *buff, int len) |
| 35 | { |
| 36 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 37 | pr_err("%s: write error for register: %#x!", dev->name, reg); |
| 38 | return -EIO; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int pmic_fan53555_bind(struct udevice *dev) |
| 45 | { |
| 46 | /* |
| 47 | * The FAN53555 has only a single regulator and therefore doesn't |
| 48 | * have a subnode. So we have to rebind a child device (the one |
| 49 | * regulator) here. |
| 50 | */ |
| 51 | |
| 52 | const char *regulator_driver_name = "fan53555_regulator"; |
| 53 | struct udevice *child; |
| 54 | struct driver *drv; |
| 55 | |
| 56 | debug("%s\n", __func__); |
| 57 | |
| 58 | drv = lists_driver_lookup_name(regulator_driver_name); |
| 59 | if (!drv) { |
| 60 | dev_err(dev, "no driver '%s'\n", regulator_driver_name); |
| 61 | return -ENOENT; |
| 62 | } |
| 63 | |
Vasily Khoruzhick | 43e7b34 | 2019-11-16 11:32:03 -0800 | [diff] [blame] | 64 | return device_bind_with_driver_data(dev, drv, "SW", dev->driver_data, |
Philipp Tomsich | b7f57e1 | 2018-11-30 20:00:08 +0100 | [diff] [blame] | 65 | dev_ofnode(dev), &child); |
| 66 | }; |
| 67 | |
| 68 | static struct dm_pmic_ops pmic_fan53555_ops = { |
| 69 | .reg_count = pmic_fan53555_reg_count, |
| 70 | .read = pmic_fan53555_read, |
| 71 | .write = pmic_fan53555_write, |
| 72 | }; |
| 73 | |
| 74 | static const struct udevice_id pmic_fan53555_match[] = { |
Vasily Khoruzhick | 43e7b34 | 2019-11-16 11:32:03 -0800 | [diff] [blame] | 75 | { .compatible = "fcs,fan53555", .data = FAN53555_VENDOR_FAIRCHILD, }, |
| 76 | { .compatible = "silergy,syr827", .data = FAN53555_VENDOR_SILERGY, }, |
| 77 | { .compatible = "silergy,syr828", .data = FAN53555_VENDOR_SILERGY, }, |
Philipp Tomsich | b7f57e1 | 2018-11-30 20:00:08 +0100 | [diff] [blame] | 78 | { }, |
| 79 | }; |
| 80 | |
| 81 | U_BOOT_DRIVER(pmic_fan53555) = { |
| 82 | .name = "pmic_fan53555", |
| 83 | .id = UCLASS_PMIC, |
| 84 | .of_match = pmic_fan53555_match, |
| 85 | .bind = pmic_fan53555_bind, |
| 86 | .ops = &pmic_fan53555_ops, |
| 87 | }; |