2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
13 #include <power/tps65090.h>
15 static int cros_ec_ldo_set_bus_speed(struct udevice *dev, unsigned int speed)
20 static int cros_ec_ldo_xfer(struct udevice *dev, struct i2c_msg *msg,
23 bool is_read = nmsgs > 1;
27 * Look for reads and writes of the LDO registers. In either case the
28 * first message is a write with the register number as the first byte.
30 if (!nmsgs || !msg->len || (msg->flags & I2C_M_RD)) {
31 debug("%s: Invalid message\n", __func__);
35 fet_id = msg->buf[0] - REG_FET_BASE;
36 if (fet_id < 1 || fet_id > MAX_FET_NUM) {
37 debug("%s: Invalid FET %d\n", __func__, fet_id);
44 ret = cros_ec_get_ldo(dev->parent, fet_id, &state);
46 msg[1].buf[0] = state ?
47 FET_CTRL_ENFET | FET_CTRL_PGFET : 0;
49 bool on = msg->buf[1] & FET_CTRL_ENFET;
51 ret = cros_ec_set_ldo(dev->parent, fet_id, on);
57 /* Indicate that the message is unimplemented */
61 static const struct dm_i2c_ops cros_ec_i2c_ops = {
62 .xfer = cros_ec_ldo_xfer,
63 .set_bus_speed = cros_ec_ldo_set_bus_speed,
66 static const struct udevice_id cros_ec_i2c_ids[] = {
67 { .compatible = "google,cros-ec-ldo-tunnel" },
71 U_BOOT_DRIVER(cros_ec_ldo) = {
72 .name = "cros_ec_ldo_tunnel",
74 .of_match = cros_ec_i2c_ids,
75 .ops = &cros_ec_i2c_ops,