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> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 13 | |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | struct cros_ec_i2c_bus { |
| 17 | int remote_bus; |
| 18 | }; |
| 19 | |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 20 | static int cros_ec_i2c_set_bus_speed(struct udevice *dev, unsigned int speed) |
| 21 | { |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | static int cros_ec_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, |
| 26 | int nmsgs) |
| 27 | { |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 28 | 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 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 33 | static int cros_ec_i2c_of_to_plat(struct udevice *dev) |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 34 | { |
| 35 | struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev); |
| 36 | const void *blob = gd->fdt_blob; |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 37 | int node = dev_of_offset(dev); |
Moritz Fischer | 6d1a718 | 2016-09-27 15:42:07 -0700 | [diff] [blame] | 38 | |
| 39 | i2c_bus->remote_bus = fdtdec_get_uint(blob, node, "google,remote-bus", |
| 40 | 0); |
| 41 | |
| 42 | return 0; |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static 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 | |
| 50 | static const struct udevice_id cros_ec_i2c_ids[] = { |
| 51 | { .compatible = "google,cros-ec-i2c-tunnel" }, |
| 52 | { } |
| 53 | }; |
| 54 | |
| 55 | U_BOOT_DRIVER(cros_ec_tunnel) = { |
| 56 | .name = "cros_ec_tunnel", |
| 57 | .id = UCLASS_I2C, |
| 58 | .of_match = cros_ec_i2c_ids, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 59 | .of_to_plat = cros_ec_i2c_of_to_plat, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 60 | .priv_auto = sizeof(struct cros_ec_i2c_bus), |
Simon Glass | cc456bd | 2015-08-03 08:19:23 -0600 | [diff] [blame] | 61 | .ops = &cros_ec_i2c_ops, |
| 62 | }; |