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