Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000 |
| 4 | * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it |
| 5 | * |
| 6 | * (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2003 Pengutronix e.K. |
| 10 | * Robert Schwebel <r.schwebel@pengutronix.de> |
| 11 | * |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 12 | * (C) Copyright 2011 Marvell Inc. |
| 13 | * Lei Wen <leiwen@marvell.com> |
| 14 | * |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 15 | * Back ported to the 8xx platform (from the 8260 platform) by |
| 16 | * Murray.Jensen@cmst.csiro.au, 27-Jan-01. |
| 17 | */ |
| 18 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 19 | #include <common.h> |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 20 | #include <dm.h> |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 21 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 22 | #include <log.h> |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 23 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 24 | #include <linux/delay.h> |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 25 | #include "mv_i2c.h" |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 26 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 27 | /* All transfers are described by this data structure */ |
Simon Glass | d5ff0b9 | 2015-02-05 21:41:33 -0700 | [diff] [blame] | 28 | struct mv_i2c_msg { |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 29 | u8 condition; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 30 | u8 acknack; |
| 31 | u8 direction; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 32 | u8 data; |
| 33 | }; |
| 34 | |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 35 | #ifdef CONFIG_ARMADA_3700 |
| 36 | /* Armada 3700 has no padding between the registers */ |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 37 | struct mv_i2c { |
| 38 | u32 ibmr; |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 39 | u32 idbr; |
| 40 | u32 icr; |
| 41 | u32 isr; |
| 42 | u32 isar; |
| 43 | }; |
| 44 | #else |
| 45 | struct mv_i2c { |
| 46 | u32 ibmr; |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 47 | u32 pad0; |
| 48 | u32 idbr; |
| 49 | u32 pad1; |
| 50 | u32 icr; |
| 51 | u32 pad2; |
| 52 | u32 isr; |
| 53 | u32 pad3; |
| 54 | u32 isar; |
| 55 | }; |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 56 | #endif |
| 57 | |
| 58 | /* |
| 59 | * Dummy implementation that can be overwritten by a board |
| 60 | * specific function |
| 61 | */ |
| 62 | __weak void i2c_clk_enable(void) |
| 63 | { |
| 64 | } |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 65 | |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 66 | /* |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 67 | * i2c_reset: - reset the host controller |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 68 | * |
| 69 | */ |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 70 | static void i2c_reset(struct mv_i2c *base) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 71 | { |
Stefan Roese | 2b9a838 | 2016-09-16 15:07:53 +0200 | [diff] [blame] | 72 | u32 icr_mode; |
| 73 | |
| 74 | /* Save bus mode (standard or fast speed) for later use */ |
| 75 | icr_mode = readl(&base->icr) & ICR_MODE_MASK; |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 76 | writel(readl(&base->icr) & ~ICR_IUE, &base->icr); /* disable unit */ |
| 77 | writel(readl(&base->icr) | ICR_UR, &base->icr); /* reset the unit */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 78 | udelay(100); |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 79 | writel(readl(&base->icr) & ~ICR_IUE, &base->icr); /* disable unit */ |
| 80 | |
| 81 | i2c_clk_enable(); |
| 82 | |
| 83 | writel(CONFIG_SYS_I2C_SLAVE, &base->isar); /* set our slave address */ |
Stefan Roese | 2b9a838 | 2016-09-16 15:07:53 +0200 | [diff] [blame] | 84 | /* set control reg values */ |
| 85 | writel(I2C_ICR_INIT | icr_mode, &base->icr); |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 86 | writel(I2C_ISR_INIT, &base->isr); /* set clear interrupt bits */ |
| 87 | writel(readl(&base->icr) | ICR_IUE, &base->icr); /* enable unit */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 88 | udelay(100); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 91 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 92 | * i2c_isr_set_cleared: - wait until certain bits of the I2C status register |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 93 | * are set and cleared |
| 94 | * |
Markus Klotzbuecher | 7cf18be | 2006-03-24 12:23:27 +0100 | [diff] [blame] | 95 | * @return: 1 in case of success, 0 means timeout (no match within 10 ms). |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 96 | */ |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 97 | static int i2c_isr_set_cleared(struct mv_i2c *base, unsigned long set_mask, |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 98 | unsigned long cleared_mask) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 99 | { |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 100 | int timeout = 1000, isr; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 101 | |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 102 | do { |
| 103 | isr = readl(&base->isr); |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 104 | udelay(10); |
| 105 | if (timeout-- < 0) |
| 106 | return 0; |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 107 | } while (((isr & set_mask) != set_mask) |
| 108 | || ((isr & cleared_mask) != 0)); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 109 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 110 | return 1; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 113 | /* |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 114 | * i2c_transfer: - Transfer one byte over the i2c bus |
| 115 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 116 | * This function can tranfer a byte over the i2c bus in both directions. |
| 117 | * It is used by the public API functions. |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 118 | * |
| 119 | * @return: 0: transfer successful |
| 120 | * -1: message is empty |
| 121 | * -2: transmit timeout |
| 122 | * -3: ACK missing |
| 123 | * -4: receive timeout |
| 124 | * -5: illegal parameters |
| 125 | * -6: bus is busy and couldn't be aquired |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 126 | */ |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 127 | static int i2c_transfer(struct mv_i2c *base, struct mv_i2c_msg *msg) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 128 | { |
| 129 | int ret; |
| 130 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 131 | if (!msg) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 132 | goto transfer_error_msg_empty; |
| 133 | |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 134 | switch (msg->direction) { |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 135 | case I2C_WRITE: |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 136 | /* check if bus is not busy */ |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 137 | if (!i2c_isr_set_cleared(base, 0, ISR_IBB)) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 138 | goto transfer_error_bus_busy; |
| 139 | |
| 140 | /* start transmission */ |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 141 | writel(readl(&base->icr) & ~ICR_START, &base->icr); |
| 142 | writel(readl(&base->icr) & ~ICR_STOP, &base->icr); |
| 143 | writel(msg->data, &base->idbr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 144 | if (msg->condition == I2C_COND_START) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 145 | writel(readl(&base->icr) | ICR_START, &base->icr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 146 | if (msg->condition == I2C_COND_STOP) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 147 | writel(readl(&base->icr) | ICR_STOP, &base->icr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 148 | if (msg->acknack == I2C_ACKNAK_SENDNAK) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 149 | writel(readl(&base->icr) | ICR_ACKNAK, &base->icr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 150 | if (msg->acknack == I2C_ACKNAK_SENDACK) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 151 | writel(readl(&base->icr) & ~ICR_ACKNAK, &base->icr); |
| 152 | writel(readl(&base->icr) & ~ICR_ALDIE, &base->icr); |
| 153 | writel(readl(&base->icr) | ICR_TB, &base->icr); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 154 | |
| 155 | /* transmit register empty? */ |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 156 | if (!i2c_isr_set_cleared(base, ISR_ITE, 0)) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 157 | goto transfer_error_transmit_timeout; |
| 158 | |
| 159 | /* clear 'transmit empty' state */ |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 160 | writel(readl(&base->isr) | ISR_ITE, &base->isr); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 161 | |
| 162 | /* wait for ACK from slave */ |
| 163 | if (msg->acknack == I2C_ACKNAK_WAITACK) |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 164 | if (!i2c_isr_set_cleared(base, 0, ISR_ACKNAK)) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 165 | goto transfer_error_ack_missing; |
| 166 | break; |
| 167 | |
| 168 | case I2C_READ: |
| 169 | |
| 170 | /* check if bus is not busy */ |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 171 | if (!i2c_isr_set_cleared(base, 0, ISR_IBB)) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 172 | goto transfer_error_bus_busy; |
| 173 | |
| 174 | /* start receive */ |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 175 | writel(readl(&base->icr) & ~ICR_START, &base->icr); |
| 176 | writel(readl(&base->icr) & ~ICR_STOP, &base->icr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 177 | if (msg->condition == I2C_COND_START) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 178 | writel(readl(&base->icr) | ICR_START, &base->icr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 179 | if (msg->condition == I2C_COND_STOP) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 180 | writel(readl(&base->icr) | ICR_STOP, &base->icr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 181 | if (msg->acknack == I2C_ACKNAK_SENDNAK) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 182 | writel(readl(&base->icr) | ICR_ACKNAK, &base->icr); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 183 | if (msg->acknack == I2C_ACKNAK_SENDACK) |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 184 | writel(readl(&base->icr) & ~ICR_ACKNAK, &base->icr); |
| 185 | writel(readl(&base->icr) & ~ICR_ALDIE, &base->icr); |
| 186 | writel(readl(&base->icr) | ICR_TB, &base->icr); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 187 | |
| 188 | /* receive register full? */ |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 189 | if (!i2c_isr_set_cleared(base, ISR_IRF, 0)) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 190 | goto transfer_error_receive_timeout; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 191 | |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 192 | msg->data = readl(&base->idbr); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 193 | |
| 194 | /* clear 'receive empty' state */ |
Lei Wen | a41374b4 | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 195 | writel(readl(&base->isr) | ISR_IRF, &base->isr); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 196 | break; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 197 | default: |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 198 | goto transfer_error_illegal_param; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 199 | } |
| 200 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 201 | return 0; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 202 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 203 | transfer_error_msg_empty: |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 204 | debug("i2c_transfer: error: 'msg' is empty\n"); |
| 205 | ret = -1; |
| 206 | goto i2c_transfer_finish; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 207 | |
| 208 | transfer_error_transmit_timeout: |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 209 | debug("i2c_transfer: error: transmit timeout\n"); |
| 210 | ret = -2; |
| 211 | goto i2c_transfer_finish; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 212 | |
| 213 | transfer_error_ack_missing: |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 214 | debug("i2c_transfer: error: ACK missing\n"); |
| 215 | ret = -3; |
| 216 | goto i2c_transfer_finish; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 217 | |
| 218 | transfer_error_receive_timeout: |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 219 | debug("i2c_transfer: error: receive timeout\n"); |
| 220 | ret = -4; |
| 221 | goto i2c_transfer_finish; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 222 | |
| 223 | transfer_error_illegal_param: |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 224 | debug("i2c_transfer: error: illegal parameters\n"); |
| 225 | ret = -5; |
| 226 | goto i2c_transfer_finish; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 227 | |
| 228 | transfer_error_bus_busy: |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 229 | debug("i2c_transfer: error: bus is busy\n"); |
| 230 | ret = -6; |
| 231 | goto i2c_transfer_finish; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 232 | |
| 233 | i2c_transfer_finish: |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 234 | debug("i2c_transfer: ISR: 0x%04x\n", readl(&base->isr)); |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 235 | i2c_reset(base); |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 236 | return ret; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 239 | static int __i2c_read(struct mv_i2c *base, uchar chip, u8 *addr, int alen, |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 240 | uchar *buffer, int len) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 241 | { |
Simon Glass | d5ff0b9 | 2015-02-05 21:41:33 -0700 | [diff] [blame] | 242 | struct mv_i2c_msg msg; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 243 | |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 244 | debug("i2c_read(chip=0x%02x, addr=0x%02x, alen=0x%02x, " |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 245 | "len=0x%02x)\n", chip, *addr, alen, len); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 246 | |
jinghua | 2bbee3e | 2016-09-16 15:07:54 +0200 | [diff] [blame] | 247 | if (len == 0) { |
| 248 | printf("reading zero byte is invalid\n"); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 252 | i2c_reset(base); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 253 | |
| 254 | /* dummy chip address write */ |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 255 | debug("i2c_read: dummy chip address write\n"); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 256 | msg.condition = I2C_COND_START; |
| 257 | msg.acknack = I2C_ACKNAK_WAITACK; |
| 258 | msg.direction = I2C_WRITE; |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 259 | msg.data = (chip << 1); |
| 260 | msg.data &= 0xFE; |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 261 | if (i2c_transfer(base, &msg)) |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 262 | return -1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 263 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 264 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 265 | * send memory address bytes; |
| 266 | * alen defines how much bytes we have to send. |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 267 | */ |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 268 | while (--alen >= 0) { |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 269 | debug("i2c_read: send address byte %02x (alen=%d)\n", |
| 270 | *addr, alen); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 271 | msg.condition = I2C_COND_NORMAL; |
| 272 | msg.acknack = I2C_ACKNAK_WAITACK; |
| 273 | msg.direction = I2C_WRITE; |
Bradley Bolen | 36c4a7c | 2016-12-13 12:49:53 -0500 | [diff] [blame] | 274 | msg.data = addr[alen]; |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 275 | if (i2c_transfer(base, &msg)) |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 276 | return -1; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 277 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 278 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 279 | /* start read sequence */ |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 280 | debug("i2c_read: start read sequence\n"); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 281 | msg.condition = I2C_COND_START; |
| 282 | msg.acknack = I2C_ACKNAK_WAITACK; |
| 283 | msg.direction = I2C_WRITE; |
| 284 | msg.data = (chip << 1); |
| 285 | msg.data |= 0x01; |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 286 | if (i2c_transfer(base, &msg)) |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 287 | return -1; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 288 | |
| 289 | /* read bytes; send NACK at last byte */ |
| 290 | while (len--) { |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 291 | if (len == 0) { |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 292 | msg.condition = I2C_COND_STOP; |
| 293 | msg.acknack = I2C_ACKNAK_SENDNAK; |
| 294 | } else { |
| 295 | msg.condition = I2C_COND_NORMAL; |
| 296 | msg.acknack = I2C_ACKNAK_SENDACK; |
| 297 | } |
| 298 | |
| 299 | msg.direction = I2C_READ; |
| 300 | msg.data = 0x00; |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 301 | if (i2c_transfer(base, &msg)) |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 302 | return -1; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 303 | |
Markus Klotzbuecher | 7cf18be | 2006-03-24 12:23:27 +0100 | [diff] [blame] | 304 | *buffer = msg.data; |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 305 | debug("i2c_read: reading byte (%p)=0x%02x\n", |
| 306 | buffer, *buffer); |
Markus Klotzbuecher | 7cf18be | 2006-03-24 12:23:27 +0100 | [diff] [blame] | 307 | buffer++; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 310 | i2c_reset(base); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 315 | static int __i2c_write(struct mv_i2c *base, uchar chip, u8 *addr, int alen, |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 316 | uchar *buffer, int len) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 317 | { |
Simon Glass | d5ff0b9 | 2015-02-05 21:41:33 -0700 | [diff] [blame] | 318 | struct mv_i2c_msg msg; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 319 | |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 320 | debug("i2c_write(chip=0x%02x, addr=0x%02x, alen=0x%02x, " |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 321 | "len=0x%02x)\n", chip, *addr, alen, len); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 322 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 323 | i2c_reset(base); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 324 | |
| 325 | /* chip address write */ |
Stefan Roese | 5196855 | 2016-09-16 15:07:49 +0200 | [diff] [blame] | 326 | debug("i2c_write: chip address write\n"); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 327 | msg.condition = I2C_COND_START; |
| 328 | msg.acknack = I2C_ACKNAK_WAITACK; |
| 329 | msg.direction = I2C_WRITE; |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 330 | msg.data = (chip << 1); |
| 331 | msg.data &= 0xFE; |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 332 | if (i2c_transfer(base, &msg)) |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 333 | return -1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 334 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 335 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 336 | * send memory address bytes; |
| 337 | * alen defines how much bytes we have to send. |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 338 | */ |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 339 | while (--alen >= 0) { |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 340 | debug("i2c_read: send address byte %02x (alen=%d)\n", |
| 341 | *addr, alen); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 342 | msg.condition = I2C_COND_NORMAL; |
| 343 | msg.acknack = I2C_ACKNAK_WAITACK; |
| 344 | msg.direction = I2C_WRITE; |
Bradley Bolen | 36c4a7c | 2016-12-13 12:49:53 -0500 | [diff] [blame] | 345 | msg.data = addr[alen]; |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 346 | if (i2c_transfer(base, &msg)) |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 347 | return -1; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 348 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 349 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 350 | /* write bytes; send NACK at last byte */ |
| 351 | while (len--) { |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 352 | debug("i2c_write: writing byte (%p)=0x%02x\n", |
| 353 | buffer, *buffer); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 354 | |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 355 | if (len == 0) |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 356 | msg.condition = I2C_COND_STOP; |
| 357 | else |
| 358 | msg.condition = I2C_COND_NORMAL; |
| 359 | |
| 360 | msg.acknack = I2C_ACKNAK_WAITACK; |
| 361 | msg.direction = I2C_WRITE; |
| 362 | msg.data = *(buffer++); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 363 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 364 | if (i2c_transfer(base, &msg)) |
Lei Wen | d3ae17b | 2011-04-13 23:48:16 +0530 | [diff] [blame] | 365 | return -1; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 368 | i2c_reset(base); |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 369 | |
| 370 | return 0; |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 371 | } |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 372 | |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 373 | #ifndef CONFIG_DM_I2C |
| 374 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 375 | static struct mv_i2c *base_glob; |
| 376 | |
| 377 | static void i2c_board_init(struct mv_i2c *base) |
| 378 | { |
| 379 | #ifdef CONFIG_SYS_I2C_INIT_BOARD |
| 380 | u32 icr; |
| 381 | /* |
| 382 | * call board specific i2c bus reset routine before accessing the |
| 383 | * environment, which might be in a chip on that bus. For details |
| 384 | * about this problem see doc/I2C_Edge_Conditions. |
| 385 | * |
| 386 | * disable I2C controller first, otherwhise it thinks we want to |
| 387 | * talk to the slave port... |
| 388 | */ |
| 389 | icr = readl(&base->icr); |
| 390 | writel(readl(&base->icr) & ~(ICR_SCLE | ICR_IUE), &base->icr); |
| 391 | |
| 392 | i2c_init_board(); |
| 393 | |
| 394 | writel(icr, &base->icr); |
| 395 | #endif |
| 396 | } |
| 397 | |
| 398 | #ifdef CONFIG_I2C_MULTI_BUS |
| 399 | static unsigned long i2c_regs[CONFIG_MV_I2C_NUM] = CONFIG_MV_I2C_REG; |
| 400 | static unsigned int bus_initialized[CONFIG_MV_I2C_NUM]; |
| 401 | static unsigned int current_bus; |
| 402 | |
| 403 | int i2c_set_bus_num(unsigned int bus) |
| 404 | { |
| 405 | if ((bus < 0) || (bus >= CONFIG_MV_I2C_NUM)) { |
| 406 | printf("Bad bus: %d\n", bus); |
| 407 | return -1; |
| 408 | } |
| 409 | |
| 410 | base_glob = (struct mv_i2c *)i2c_regs[bus]; |
| 411 | current_bus = bus; |
| 412 | |
| 413 | if (!bus_initialized[current_bus]) { |
| 414 | i2c_board_init(base_glob); |
| 415 | bus_initialized[current_bus] = 1; |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | unsigned int i2c_get_bus_num(void) |
| 422 | { |
| 423 | return current_bus; |
| 424 | } |
| 425 | #endif |
| 426 | |
| 427 | /* API Functions */ |
| 428 | void i2c_init(int speed, int slaveaddr) |
| 429 | { |
Stefan Roese | 2b9a838 | 2016-09-16 15:07:53 +0200 | [diff] [blame] | 430 | u32 val; |
| 431 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 432 | #ifdef CONFIG_I2C_MULTI_BUS |
| 433 | current_bus = 0; |
| 434 | base_glob = (struct mv_i2c *)i2c_regs[current_bus]; |
| 435 | #else |
| 436 | base_glob = (struct mv_i2c *)CONFIG_MV_I2C_REG; |
| 437 | #endif |
| 438 | |
Simon Glass | f0c99c5 | 2020-01-23 11:48:22 -0700 | [diff] [blame] | 439 | if (speed > I2C_SPEED_STANDARD_RATE) |
Stefan Roese | 2b9a838 | 2016-09-16 15:07:53 +0200 | [diff] [blame] | 440 | val = ICR_FM; |
| 441 | else |
| 442 | val = ICR_SM; |
| 443 | clrsetbits_le32(&base_glob->icr, ICR_MODE_MASK, val); |
| 444 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 445 | i2c_board_init(base_glob); |
| 446 | } |
| 447 | |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 448 | static int __i2c_probe_chip(struct mv_i2c *base, uchar chip) |
| 449 | { |
| 450 | struct mv_i2c_msg msg; |
| 451 | |
| 452 | i2c_reset(base); |
| 453 | |
| 454 | msg.condition = I2C_COND_START; |
| 455 | msg.acknack = I2C_ACKNAK_WAITACK; |
| 456 | msg.direction = I2C_WRITE; |
| 457 | msg.data = (chip << 1) + 1; |
| 458 | if (i2c_transfer(base, &msg)) |
| 459 | return -1; |
| 460 | |
| 461 | msg.condition = I2C_COND_STOP; |
| 462 | msg.acknack = I2C_ACKNAK_SENDNAK; |
| 463 | msg.direction = I2C_READ; |
| 464 | msg.data = 0x00; |
| 465 | if (i2c_transfer(base, &msg)) |
| 466 | return -1; |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 471 | /* |
| 472 | * i2c_probe: - Test if a chip answers for a given i2c address |
| 473 | * |
| 474 | * @chip: address of the chip which is searched for |
| 475 | * @return: 0 if a chip was found, -1 otherwhise |
| 476 | */ |
| 477 | int i2c_probe(uchar chip) |
| 478 | { |
| 479 | return __i2c_probe_chip(base_glob, chip); |
| 480 | } |
| 481 | |
| 482 | /* |
| 483 | * i2c_read: - Read multiple bytes from an i2c device |
| 484 | * |
| 485 | * The higher level routines take into account that this function is only |
| 486 | * called with len < page length of the device (see configuration file) |
| 487 | * |
| 488 | * @chip: address of the chip which is to be read |
| 489 | * @addr: i2c data address within the chip |
| 490 | * @alen: length of the i2c data address (1..2 bytes) |
| 491 | * @buffer: where to write the data |
| 492 | * @len: how much byte do we want to read |
| 493 | * @return: 0 in case of success |
| 494 | */ |
| 495 | int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) |
| 496 | { |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 497 | u8 addr_bytes[4]; |
| 498 | |
| 499 | addr_bytes[0] = (addr >> 0) & 0xFF; |
| 500 | addr_bytes[1] = (addr >> 8) & 0xFF; |
| 501 | addr_bytes[2] = (addr >> 16) & 0xFF; |
| 502 | addr_bytes[3] = (addr >> 24) & 0xFF; |
| 503 | |
| 504 | return __i2c_read(base_glob, chip, addr_bytes, alen, buffer, len); |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* |
| 508 | * i2c_write: - Write multiple bytes to an i2c device |
| 509 | * |
| 510 | * The higher level routines take into account that this function is only |
| 511 | * called with len < page length of the device (see configuration file) |
| 512 | * |
| 513 | * @chip: address of the chip which is to be written |
| 514 | * @addr: i2c data address within the chip |
| 515 | * @alen: length of the i2c data address (1..2 bytes) |
| 516 | * @buffer: where to find the data to be written |
| 517 | * @len: how much byte do we want to read |
| 518 | * @return: 0 in case of success |
| 519 | */ |
| 520 | int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) |
| 521 | { |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 522 | u8 addr_bytes[4]; |
| 523 | |
| 524 | addr_bytes[0] = (addr >> 0) & 0xFF; |
| 525 | addr_bytes[1] = (addr >> 8) & 0xFF; |
| 526 | addr_bytes[2] = (addr >> 16) & 0xFF; |
| 527 | addr_bytes[3] = (addr >> 24) & 0xFF; |
| 528 | |
| 529 | return __i2c_write(base_glob, chip, addr_bytes, alen, buffer, len); |
| 530 | } |
| 531 | |
| 532 | #else /* CONFIG_DM_I2C */ |
| 533 | |
| 534 | struct mv_i2c_priv { |
| 535 | struct mv_i2c *base; |
| 536 | }; |
| 537 | |
| 538 | static int mv_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs) |
| 539 | { |
| 540 | struct mv_i2c_priv *i2c = dev_get_priv(bus); |
| 541 | struct i2c_msg *dmsg, *omsg, dummy; |
| 542 | |
| 543 | memset(&dummy, 0, sizeof(struct i2c_msg)); |
| 544 | |
| 545 | /* |
| 546 | * We expect either two messages (one with an offset and one with the |
| 547 | * actual data) or one message (just data or offset/data combined) |
| 548 | */ |
| 549 | if (nmsgs > 2 || nmsgs == 0) { |
| 550 | debug("%s: Only one or two messages are supported.", __func__); |
| 551 | return -1; |
| 552 | } |
| 553 | |
| 554 | omsg = nmsgs == 1 ? &dummy : msg; |
| 555 | dmsg = nmsgs == 1 ? msg : msg + 1; |
| 556 | |
| 557 | if (dmsg->flags & I2C_M_RD) |
| 558 | return __i2c_read(i2c->base, dmsg->addr, omsg->buf, |
| 559 | omsg->len, dmsg->buf, dmsg->len); |
| 560 | else |
| 561 | return __i2c_write(i2c->base, dmsg->addr, omsg->buf, |
| 562 | omsg->len, dmsg->buf, dmsg->len); |
Stefan Roese | 90ddbb9 | 2016-09-16 15:07:51 +0200 | [diff] [blame] | 563 | } |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 564 | |
Stefan Roese | 2b9a838 | 2016-09-16 15:07:53 +0200 | [diff] [blame] | 565 | static int mv_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) |
| 566 | { |
| 567 | struct mv_i2c_priv *priv = dev_get_priv(bus); |
| 568 | u32 val; |
| 569 | |
Simon Glass | f0c99c5 | 2020-01-23 11:48:22 -0700 | [diff] [blame] | 570 | if (speed > I2C_SPEED_STANDARD_RATE) |
Stefan Roese | 2b9a838 | 2016-09-16 15:07:53 +0200 | [diff] [blame] | 571 | val = ICR_FM; |
| 572 | else |
| 573 | val = ICR_SM; |
| 574 | clrsetbits_le32(&priv->base->icr, ICR_MODE_MASK, val); |
| 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 579 | static int mv_i2c_probe(struct udevice *bus) |
| 580 | { |
| 581 | struct mv_i2c_priv *priv = dev_get_priv(bus); |
| 582 | |
Masahiro Yamada | 32822d0 | 2020-08-04 14:14:43 +0900 | [diff] [blame] | 583 | priv->base = dev_read_addr_ptr(bus); |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 584 | |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static const struct dm_i2c_ops mv_i2c_ops = { |
| 589 | .xfer = mv_i2c_xfer, |
Stefan Roese | 2b9a838 | 2016-09-16 15:07:53 +0200 | [diff] [blame] | 590 | .set_bus_speed = mv_i2c_set_bus_speed, |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 591 | }; |
| 592 | |
| 593 | static const struct udevice_id mv_i2c_ids[] = { |
| 594 | { .compatible = "marvell,armada-3700-i2c" }, |
| 595 | { } |
| 596 | }; |
| 597 | |
| 598 | U_BOOT_DRIVER(i2c_mv) = { |
| 599 | .name = "i2c_mv", |
| 600 | .id = UCLASS_I2C, |
| 601 | .of_match = mv_i2c_ids, |
| 602 | .probe = mv_i2c_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 603 | .priv_auto = sizeof(struct mv_i2c_priv), |
Stefan Roese | 8c3ba15 | 2016-09-16 15:07:52 +0200 | [diff] [blame] | 604 | .ops = &mv_i2c_ops, |
| 605 | }; |
| 606 | #endif /* CONFIG_DM_I2C */ |