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