common: Drop linux/delay.h from common header
[oweals/u-boot.git] / drivers / i2c / kona_i2c.c
index 5eab338cfc470fbc57ae1fd4cff2166d122fa536..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]}
@@ -156,7 +154,7 @@ static struct bcm_kona_i2c_dev g_i2c_devs[CONFIG_SYS_MAX_I2C_BUS] = {
 #define I2C_M_RD       0x0001  /* read data */
 #define I2C_M_NOSTART  0x4000  /* no restart between msgs */
 
-struct i2c_msg {
+struct kona_i2c_msg {
        uint16_t addr;
        uint16_t flags;
        uint16_t len;
@@ -297,7 +295,7 @@ static int bcm_kona_i2c_read_fifo_single(struct bcm_kona_i2c_dev *dev,
 
 /* Read any amount of data using the RX FIFO from the i2c bus */
 static int bcm_kona_i2c_read_fifo(struct bcm_kona_i2c_dev *dev,
-                                 struct i2c_msg *msg)
+                                 struct kona_i2c_msg *msg)
 {
        unsigned int bytes_to_read = MAX_RX_FIFO_SIZE;
        unsigned int last_byte_nak = 0;
@@ -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;
@@ -392,7 +390,7 @@ static int bcm_kona_i2c_write_fifo_single(struct bcm_kona_i2c_dev *dev,
 
 /* Write any amount of data using TX FIFO to the i2c bus */
 static int bcm_kona_i2c_write_fifo(struct bcm_kona_i2c_dev *dev,
-                                  struct i2c_msg *msg)
+                                  struct kona_i2c_msg *msg)
 {
        unsigned int bytes_to_write = MAX_TX_FIFO_SIZE;
        unsigned int bytes_written = 0;
@@ -418,7 +416,7 @@ static int bcm_kona_i2c_write_fifo(struct bcm_kona_i2c_dev *dev,
 
 /* Send i2c address */
 static int bcm_kona_i2c_do_addr(struct bcm_kona_i2c_dev *dev,
-                               struct i2c_msg *msg)
+                               struct kona_i2c_msg *msg)
 {
        unsigned char addr;
 
@@ -480,9 +478,9 @@ static void bcm_kona_i2c_config_timing(struct bcm_kona_i2c_dev *dev)
 
 /* Master transfer function */
 static int bcm_kona_i2c_xfer(struct bcm_kona_i2c_dev *dev,
-                            struct i2c_msg msgs[], int num)
+                            struct kona_i2c_msg msgs[], int num)
 {
-       struct i2c_msg *pmsg;
+       struct kona_i2c_msg *pmsg;
        int rc = 0;
        int i;
 
@@ -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);
@@ -635,7 +633,7 @@ static int kona_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr,
                         int alen, uchar *buffer, int len)
 {
        /* msg[0] writes the addr, msg[1] reads the data */
-       struct i2c_msg msg[2];
+       struct kona_i2c_msg msg[2];
        unsigned char msgbuf0[64];
        struct bcm_kona_i2c_dev *dev = kona_get_dev(adap);
 
@@ -663,7 +661,7 @@ static int kona_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr,
 static int kona_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr,
                          int alen, uchar *buffer, int len)
 {
-       struct i2c_msg msg[1];
+       struct kona_i2c_msg msg[1];
        unsigned char msgbuf0[64];
        unsigned int i;
        struct bcm_kona_i2c_dev *dev = kona_get_dev(adap);