Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / drivers / i2c / kona_i2c.c
index 9af496bbb1cdbd8454c5fd927bfda5b1bf44b53e..4edcba29110e31fb63b53e13897a8535ec119b42 100644 (file)
@@ -1,12 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2013 Broadcom Corporation.
  *
- * SPDX-License-Identifier:      GPL-2.0+
+ * NOTE: This driver should be converted to driver model before June 2017.
+ * Please see doc/driver-model/i2c-howto.rst for instructions.
  */
 
 #include <common.h>
+#include <log.h>
 #include <asm/io.h>
-#include <asm/errno.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
 #include <asm/arch/sysmap.h>
 #include <asm/kona-common/clk.h>
 #include <i2c.h>
@@ -96,12 +100,6 @@ enum bcm_kona_cmd_t {
        BCM_CMD_STOP,
 };
 
-enum bus_speed_index {
-       BCM_SPD_100K = 0,
-       BCM_SPD_400K,
-       BCM_SPD_1MHZ,
-};
-
 /* Internal divider settings for standard mode, fast mode and fast mode plus */
 struct bus_speed_cfg {
        uint8_t time_m;         /* Number of cycles for setup time */
@@ -113,9 +111,9 @@ struct bus_speed_cfg {
 };
 
 static const struct bus_speed_cfg std_cfg_table[] = {
-       [BCM_SPD_100K] = {0x01, 0x01, 0x03, 0x06, 0x00, 0x02},
-       [BCM_SPD_400K] = {0x05, 0x01, 0x03, 0x05, 0x01, 0x02},
-       [BCM_SPD_1MHZ] = {0x01, 0x01, 0x03, 0x01, 0x01, 0x03},
+       [IC_SPEED_MODE_STANDARD] = {0x01, 0x01, 0x03, 0x06, 0x00, 0x02},
+       [IC_SPEED_MODE_FAST] = {0x05, 0x01, 0x03, 0x05, 0x01, 0x02},
+       [IC_SPEED_MODE_FAST_PLUS] = {0x01, 0x01, 0x03, 0x01, 0x01, 0x03},
 };
 
 struct bcm_kona_i2c_dev {
@@ -125,8 +123,8 @@ struct bcm_kona_i2c_dev {
 };
 
 /* Keep these two defines in sync */
-#define DEF_SPD 100000
-#define DEF_SPD_ENUM BCM_SPD_100K
+#define DEF_SPD I2C_SPEED_STANDARD_RATE
+#define DEF_SPD_ENUM IC_SPEED_MODE_STANDARD
 
 #define DEF_DEVICE(num) \
 {(void *)CONFIG_SYS_I2C_BASE##num, DEF_SPD, &std_cfg_table[DEF_SPD_ENUM]}
@@ -381,7 +379,7 @@ static int bcm_kona_i2c_write_fifo_single(struct bcm_kona_i2c_dev *dev,
                return -EREMOTEIO;
        }
 
-       /* Check if a timeout occured */
+       /* Check if a timeout occurred */
        if (!time_left) {
                printf("completion timed out\n");
                return -EREMOTEIO;
@@ -558,14 +556,14 @@ static uint bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev,
                                          uint speed)
 {
        switch (speed) {
-       case 100000:
-               dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
+       case I2C_SPEED_STANDARD_RATE:
+               dev->std_cfg = &std_cfg_table[IC_SPEED_MODE_STANDARD];
                break;
-       case 400000:
-               dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
+       case I2C_SPEED_FAST_RATE:
+               dev->std_cfg = &std_cfg_table[IC_SPEED_MODE_FAST];
                break;
-       case 1000000:
-               dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
+       case I2C_SPEED_FAST_PLUS_RATE:
+               dev->std_cfg = &std_cfg_table[IC_SPEED_MODE_FAST_PLUS];
                break;
        default:
                printf("%d hz bus speed not supported\n", speed);