i2c: mxc_i2c: Document how non-DM functions work
[platform/kernel/u-boot.git] / drivers / i2c / cros_ec_tunnel.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2015 Google, Inc
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <cros_ec.h>
10 #include <errno.h>
11 #include <i2c.h>
12
13 DECLARE_GLOBAL_DATA_PTR;
14
15 struct cros_ec_i2c_bus {
16         int remote_bus;
17 };
18
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 {
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;
36         int node = dev_of_offset(dev);
37
38         i2c_bus->remote_bus = fdtdec_get_uint(blob, node, "google,remote-bus",
39                                               0);
40
41         return 0;
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,
58         .ofdata_to_platdata = cros_ec_i2c_ofdata_to_platdata,
59         .priv_auto_alloc_size = sizeof(struct cros_ec_i2c_bus),
60         .ops    = &cros_ec_i2c_ops,
61 };