]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: cros_ec: Convert cros_ec_i2c over to driver model
authorSimon Glass <sjg@chromium.org>
Tue, 27 Jan 2015 03:29:40 +0000 (20:29 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 30 Jan 2015 00:10:01 +0000 (17:10 -0700)
Move this driver to use driver model and update the snow configuration to
match.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/misc/cros_ec_i2c.c
include/configs/snow.h

index 513cdb1cb09808be69ac6a44be2cb651ad9ac347..f9bc9750d4cb2e617eab6fb4f4dd126d64c9e2b5 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <i2c.h>
 #include <cros_ec.h>
 
 #define debug_trace(fmt, b...)
 #endif
 
-int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
-                    const uint8_t *dout, int dout_len,
-                    uint8_t **dinp, int din_len)
+static int cros_ec_i2c_command(struct udevice *udev, uint8_t cmd,
+                              int cmd_version, const uint8_t *dout,
+                              int dout_len, uint8_t **dinp, int din_len)
 {
-       int old_bus = 0;
+       struct cros_ec_dev *dev = udev->uclass_priv;
        /* version8, cmd8, arglen8, out8[dout_len], csum8 */
        int out_bytes = dout_len + 4;
        /* response8, arglen8, in8[din_len], checksum8 */
@@ -37,8 +38,6 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
        uint8_t *in_ptr;
        int len, csum, ret;
 
-       old_bus = i2c_get_bus_num();
-
        /*
         * Sanity-check I/O sizes given transaction overhead in internal
         * buffers.
@@ -86,36 +85,24 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
        *ptr++ = (uint8_t)
                cros_ec_calc_checksum(dev->dout, dout_len + 3);
 
-       /* Set to the proper i2c bus */
-       if (i2c_set_bus_num(dev->bus_num)) {
-               debug("%s: Cannot change to I2C bus %d\n", __func__,
-                       dev->bus_num);
-               return -1;
-       }
-
        /* Send output data */
        cros_ec_dump_data("out", -1, dev->dout, out_bytes);
-       ret = i2c_write(dev->addr, 0, 0, dev->dout, out_bytes);
+       ret = dm_i2c_write(udev, 0, dev->dout, out_bytes);
        if (ret) {
-               debug("%s: Cannot complete I2C write to 0x%x\n",
-                       __func__, dev->addr);
+               debug("%s: Cannot complete I2C write to %s\n", __func__,
+                     udev->name);
                ret = -1;
        }
 
        if (!ret) {
-               ret = i2c_read(dev->addr, 0, 0, in_ptr, in_bytes);
+               ret = dm_i2c_read(udev, 0, in_ptr, in_bytes);
                if (ret) {
-                       debug("%s: Cannot complete I2C read from 0x%x\n",
-                               __func__, dev->addr);
+                       debug("%s: Cannot complete I2C read from %s\n",
+                             __func__, udev->name);
                        ret = -1;
                }
        }
 
-       /* Return to original bus number */
-       i2c_set_bus_num(old_bus);
-       if (ret)
-               return ret;
-
        if (*in_ptr != EC_RES_SUCCESS) {
                debug("%s: Received bad result code %d\n", __func__, *in_ptr);
                return -(int)*in_ptr;
@@ -142,35 +129,24 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
        return din_len;
 }
 
-int cros_ec_i2c_decode_fdt(struct cros_ec_dev *dev, const void *blob)
+static int cros_ec_probe(struct udevice *dev)
 {
-       /* Decode interface-specific FDT params */
-       dev->max_frequency = fdtdec_get_int(blob, dev->node,
-                                           "i2c-max-frequency", 100000);
-       dev->bus_num = i2c_get_bus_num_fdt(dev->parent_node);
-       if (dev->bus_num == -1) {
-               debug("%s: Failed to read bus number\n", __func__);
-               return -1;
-       }
-       dev->addr = fdtdec_get_int(blob, dev->node, "reg", -1);
-       if (dev->addr == -1) {
-               debug("%s: Failed to read device address\n", __func__);
-               return -1;
-       }
-
-       return 0;
+       return cros_ec_register(dev);
 }
 
-/**
- * Initialize I2C protocol.
- *
- * @param dev          CROS_EC device
- * @param blob         Device tree blob
- * @return 0 if ok, -1 on error
- */
-int cros_ec_i2c_init(struct cros_ec_dev *dev, const void *blob)
-{
-       i2c_init(dev->max_frequency, dev->addr);
-
-       return 0;
-}
+static struct dm_cros_ec_ops cros_ec_ops = {
+       .command = cros_ec_i2c_command,
+};
+
+static const struct udevice_id cros_ec_ids[] = {
+       { .compatible = "google,cros-ec" },
+       { }
+};
+
+U_BOOT_DRIVER(cros_ec_i2c) = {
+       .name           = "cros_ec",
+       .id             = UCLASS_CROS_EC,
+       .of_match       = cros_ec_ids,
+       .probe          = cros_ec_probe,
+       .ops            = &cros_ec_ops,
+};
index 7eaa58697e44f6cfeab3d2480eada7afb67aa636..ce6676eae7f71c95a32a98d0681584ba6ca15902 100644 (file)
@@ -22,6 +22,7 @@
 
 #define CONFIG_CROS_EC_I2C             /* Support CROS_EC over I2C */
 #define CONFIG_POWER_TPS65090_I2C
+#define CONFIG_DM_CROS_EC
 
 #define CONFIG_BOARD_COMMON
 #define CONFIG_ARCH_EARLY_INIT_R