blob: c593540ac1380d8d82e40470057a6ef01791f471 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassf48eaf02015-08-03 08:19:24 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glassf48eaf02015-08-03 08:19:24 -06005 */
6
7#include <common.h>
8#include <dm.h>
9#include <cros_ec.h>
10#include <errno.h>
11#include <i2c.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Simon Glassf48eaf02015-08-03 08:19:24 -060013#include <power/tps65090.h>
14
15static int cros_ec_ldo_set_bus_speed(struct udevice *dev, unsigned int speed)
16{
17 return 0;
18}
19
20static int cros_ec_ldo_xfer(struct udevice *dev, struct i2c_msg *msg,
21 int nmsgs)
22{
23 bool is_read = nmsgs > 1;
24 int fet_id, ret;
25
26 /*
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.
29 */
30 if (!nmsgs || !msg->len || (msg->flags & I2C_M_RD)) {
31 debug("%s: Invalid message\n", __func__);
32 goto err;
33 }
34
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);
38 goto err;
39 }
40
41 if (is_read) {
42 uint8_t state;
43
44 ret = cros_ec_get_ldo(dev->parent, fet_id, &state);
45 if (!ret)
46 msg[1].buf[0] = state ?
47 FET_CTRL_ENFET | FET_CTRL_PGFET : 0;
48 } else {
49 bool on = msg->buf[1] & FET_CTRL_ENFET;
50
51 ret = cros_ec_set_ldo(dev->parent, fet_id, on);
52 }
53
54 return ret;
55
56err:
57 /* Indicate that the message is unimplemented */
58 return -ENOSYS;
59}
60
61static 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,
64};
65
66static const struct udevice_id cros_ec_i2c_ids[] = {
67 { .compatible = "google,cros-ec-ldo-tunnel" },
68 { }
69};
70
71U_BOOT_DRIVER(cros_ec_ldo) = {
72 .name = "cros_ec_ldo_tunnel",
73 .id = UCLASS_I2C,
74 .of_match = cros_ec_i2c_ids,
Simon Glassf48eaf02015-08-03 08:19:24 -060075 .ops = &cros_ec_i2c_ops,
76};