blob: a630817352ec2bef91f04860d6331b6e35237e05 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass9ad07af2015-08-03 08:19:23 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass9ad07af2015-08-03 08:19:23 -06005 */
6
7#include <common.h>
8#include <dm.h>
9#include <cros_ec.h>
10#include <errno.h>
11#include <i2c.h>
12
Moritz Fischer6cddc602016-09-27 15:42:07 -070013DECLARE_GLOBAL_DATA_PTR;
14
15struct cros_ec_i2c_bus {
16 int remote_bus;
17};
18
Simon Glass9ad07af2015-08-03 08:19:23 -060019static int cros_ec_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
20{
21 return 0;
22}
23
24static int cros_ec_i2c_xfer(struct udevice *dev, struct i2c_msg *msg,
25 int nmsgs)
26{
Moritz Fischer6cddc602016-09-27 15:42:07 -070027 struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
28
29 return cros_ec_i2c_tunnel(dev->parent, i2c_bus->remote_bus, msg, nmsgs);
30}
31
32static int cros_ec_i2c_ofdata_to_platdata(struct udevice *dev)
33{
34 struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
35 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -070036 int node = dev_of_offset(dev);
Moritz Fischer6cddc602016-09-27 15:42:07 -070037
38 i2c_bus->remote_bus = fdtdec_get_uint(blob, node, "google,remote-bus",
39 0);
40
41 return 0;
Simon Glass9ad07af2015-08-03 08:19:23 -060042}
43
44static const struct dm_i2c_ops cros_ec_i2c_ops = {
45 .xfer = cros_ec_i2c_xfer,
46 .set_bus_speed = cros_ec_i2c_set_bus_speed,
47};
48
49static const struct udevice_id cros_ec_i2c_ids[] = {
50 { .compatible = "google,cros-ec-i2c-tunnel" },
51 { }
52};
53
54U_BOOT_DRIVER(cros_ec_tunnel) = {
55 .name = "cros_ec_tunnel",
56 .id = UCLASS_I2C,
57 .of_match = cros_ec_i2c_ids,
Moritz Fischer6cddc602016-09-27 15:42:07 -070058 .ofdata_to_platdata = cros_ec_i2c_ofdata_to_platdata,
59 .priv_auto_alloc_size = sizeof(struct cros_ec_i2c_bus),
Simon Glass9ad07af2015-08-03 08:19:23 -060060 .ops = &cros_ec_i2c_ops,
61};