blob: 9cf8e7dec0f8861b44f5316e7196ce59e6ecf2ba [file] [log] [blame]
Simon Glasscc456bd2015-08-03 08:19:23 -06001/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <cros_ec.h>
11#include <errno.h>
12#include <i2c.h>
13
Moritz Fischer6d1a7182016-09-27 15:42:07 -070014DECLARE_GLOBAL_DATA_PTR;
15
16struct cros_ec_i2c_bus {
17 int remote_bus;
18};
19
Simon Glasscc456bd2015-08-03 08:19:23 -060020static int cros_ec_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
21{
22 return 0;
23}
24
25static int cros_ec_i2c_xfer(struct udevice *dev, struct i2c_msg *msg,
26 int nmsgs)
27{
Moritz Fischer6d1a7182016-09-27 15:42:07 -070028 struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
29
30 return cros_ec_i2c_tunnel(dev->parent, i2c_bus->remote_bus, msg, nmsgs);
31}
32
33static int cros_ec_i2c_ofdata_to_platdata(struct udevice *dev)
34{
35 struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
36 const void *blob = gd->fdt_blob;
37 int node = dev->of_offset;
38
39 i2c_bus->remote_bus = fdtdec_get_uint(blob, node, "google,remote-bus",
40 0);
41
42 return 0;
Simon Glasscc456bd2015-08-03 08:19:23 -060043}
44
45static const struct dm_i2c_ops cros_ec_i2c_ops = {
46 .xfer = cros_ec_i2c_xfer,
47 .set_bus_speed = cros_ec_i2c_set_bus_speed,
48};
49
50static const struct udevice_id cros_ec_i2c_ids[] = {
51 { .compatible = "google,cros-ec-i2c-tunnel" },
52 { }
53};
54
55U_BOOT_DRIVER(cros_ec_tunnel) = {
56 .name = "cros_ec_tunnel",
57 .id = UCLASS_I2C,
58 .of_match = cros_ec_i2c_ids,
Moritz Fischer6d1a7182016-09-27 15:42:07 -070059 .ofdata_to_platdata = cros_ec_i2c_ofdata_to_platdata,
60 .priv_auto_alloc_size = sizeof(struct cros_ec_i2c_bus),
Simon Glasscc456bd2015-08-03 08:19:23 -060061 .ops = &cros_ec_i2c_ops,
62};