Convert CONFIG_SYS_I2C_LEGACY to Kconfig and add CONFIG_[ST]PL_SYS_I2C_LEGACY
[platform/kernel/u-boot.git] / drivers / i2c / lpc32xx_i2c.c
index 661d031..774129a 100644 (file)
@@ -1,13 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * LPC32xx I2C interface driver
  *
  * (C) Copyright 2014-2015  DENX Software Engineering GmbH
  * Written-by: Albert ARIBAUD - 3ADEV <albert.aribaud@3adev.fr>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <log.h>
 #include <asm/io.h>
 #include <i2c.h>
 #include <linux/errno.h>
 /* Status register values */
 #define LPC32XX_I2C_STAT_TFF           0x00000400
 #define LPC32XX_I2C_STAT_RFE           0x00000200
-#define LPC32XX_I2C_STAT_DRMI          0x00000008
 #define LPC32XX_I2C_STAT_NAI           0x00000004
 #define LPC32XX_I2C_STAT_TDI           0x00000001
 
-#ifndef CONFIG_DM_I2C
+#if !CONFIG_IS_ENABLED(DM_I2C)
 static struct lpc32xx_i2c_base *lpc32xx_i2c[] = {
        (struct lpc32xx_i2c_base *)I2C1_BASE,
        (struct lpc32xx_i2c_base *)I2C2_BASE,
@@ -224,7 +223,7 @@ static int __i2c_write(struct lpc32xx_i2c_base *base, u8 dev, uint addr,
        return 0;
 }
 
-#ifndef CONFIG_DM_I2C
+#if !CONFIG_IS_ENABLED(DM_I2C)
 static void lpc32xx_i2c_init(struct i2c_adapter *adap,
                             int requested_speed, int slaveadd)
 {
@@ -281,9 +280,9 @@ U_BOOT_I2C_ADAP_COMPLETE(lpc32xx_2, lpc32xx_i2c_init, NULL,
 #else /* CONFIG_DM_I2C */
 static int lpc32xx_i2c_probe(struct udevice *bus)
 {
-       struct lpc32xx_i2c_dev *dev = dev_get_platdata(bus);
-       bus->seq = dev->index;
+       struct lpc32xx_i2c_dev *dev = dev_get_plat(bus);
 
+       dev->base = dev_read_addr_ptr(bus);
        __i2c_init(dev->base, dev->speed, 0, dev->index);
        return 0;
 }
@@ -291,14 +290,14 @@ static int lpc32xx_i2c_probe(struct udevice *bus)
 static int lpc32xx_i2c_probe_chip(struct udevice *bus, u32 chip_addr,
                                  u32 chip_flags)
 {
-       struct lpc32xx_i2c_dev *dev = dev_get_platdata(bus);
+       struct lpc32xx_i2c_dev *dev = dev_get_plat(bus);
        return __i2c_probe_chip(dev->base, chip_addr);
 }
 
 static int lpc32xx_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
                int nmsgs)
 {
-       struct lpc32xx_i2c_dev *dev = dev_get_platdata(bus);
+       struct lpc32xx_i2c_dev *dev = dev_get_plat(bus);
        struct i2c_msg *dmsg, *omsg, dummy;
        uint i = 0, address = 0;
 
@@ -330,13 +329,13 @@ static int lpc32xx_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
 
 static int lpc32xx_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
 {
-       struct lpc32xx_i2c_dev *dev = dev_get_platdata(bus);
+       struct lpc32xx_i2c_dev *dev = dev_get_plat(bus);
        return __i2c_set_bus_speed(dev->base, speed, dev->index);
 }
 
 static int lpc32xx_i2c_reset(struct udevice *bus)
 {
-       struct lpc32xx_i2c_dev *dev = dev_get_platdata(bus);
+       struct lpc32xx_i2c_dev *dev = dev_get_plat(bus);
 
        __i2c_init(dev->base, dev->speed, 0, dev->index);
        return 0;
@@ -349,9 +348,15 @@ static const struct dm_i2c_ops lpc32xx_i2c_ops = {
        .set_bus_speed = lpc32xx_i2c_set_bus_speed,
 };
 
+static const struct udevice_id lpc32xx_i2c_ids[] = {
+       { .compatible = "nxp,pnx-i2c" },
+       { }
+};
+
 U_BOOT_DRIVER(i2c_lpc32xx) = {
-       .id                   = UCLASS_I2C,
        .name                 = "i2c_lpc32xx",
+       .id                   = UCLASS_I2C,
+       .of_match             = lpc32xx_i2c_ids,
        .probe                = lpc32xx_i2c_probe,
        .ops                  = &lpc32xx_i2c_ops,
 };