Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <cros_ec.h> |
| 10 | #include <errno.h> |
| 11 | #include <i2c.h> |
| 12 | |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
| 15 | struct cros_ec_i2c_bus { |
| 16 | int remote_bus; |
| 17 | }; |
| 18 | |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 19 | static int cros_ec_i2c_set_bus_speed(struct udevice *dev, unsigned int speed) |
| 20 | { |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | static int cros_ec_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, |
| 25 | int nmsgs) |
| 26 | { |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 27 | 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 | |
| 32 | static 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 Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 36 | int node = dev_of_offset(dev); |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 37 | |
| 38 | i2c_bus->remote_bus = fdtdec_get_uint(blob, node, "google,remote-bus", |
| 39 | 0); |
| 40 | |
| 41 | return 0; |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static 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 | |
| 49 | static const struct udevice_id cros_ec_i2c_ids[] = { |
| 50 | { .compatible = "google,cros-ec-i2c-tunnel" }, |
| 51 | { } |
| 52 | }; |
| 53 | |
| 54 | U_BOOT_DRIVER(cros_ec_tunnel) = { |
| 55 | .name = "cros_ec_tunnel", |
| 56 | .id = UCLASS_I2C, |
| 57 | .of_match = cros_ec_i2c_ids, |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 58 | .ofdata_to_platdata = cros_ec_i2c_ofdata_to_platdata, |
| 59 | .priv_auto_alloc_size = sizeof(struct cros_ec_i2c_bus), |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 60 | .ops = &cros_ec_i2c_ops, |
| 61 | }; |