Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 1 | /* |
Scott Jiang | fea9b69 | 2014-11-13 15:30:53 +0800 | [diff] [blame] | 2 | * i2c.c - driver for ADI TWI/I2C |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 3 | * |
Scott Jiang | fea9b69 | 2014-11-13 15:30:53 +0800 | [diff] [blame] | 4 | * Copyright (c) 2006-2014 Analog Devices Inc. |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the GPL-2 or later. |
Simon Glass | 2852709 | 2016-11-23 06:34:44 -0700 | [diff] [blame] | 7 | * |
| 8 | * NOTE: This driver should be converted to driver model before June 2017. |
| 9 | * Please see doc/driver-model/i2c-howto.txt for instructions. |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 13 | #include <console.h> |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 14 | #include <i2c.h> |
| 15 | |
Sonic Zhang | d6a320d | 2014-01-28 13:53:34 +0800 | [diff] [blame] | 16 | #include <asm/clock.h> |
Scott Jiang | fea9b69 | 2014-11-13 15:30:53 +0800 | [diff] [blame] | 17 | #include <asm/twi.h> |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 18 | #include <asm/io.h> |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 19 | |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 20 | static struct twi_regs *i2c_get_base(struct i2c_adapter *adap); |
| 21 | |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 22 | /* Every register is 32bit aligned, but only 16bits in size */ |
| 23 | #define ureg(name) u16 name; u16 __pad_##name; |
| 24 | struct twi_regs { |
| 25 | ureg(clkdiv); |
| 26 | ureg(control); |
| 27 | ureg(slave_ctl); |
| 28 | ureg(slave_stat); |
| 29 | ureg(slave_addr); |
| 30 | ureg(master_ctl); |
| 31 | ureg(master_stat); |
| 32 | ureg(master_addr); |
| 33 | ureg(int_stat); |
| 34 | ureg(int_mask); |
| 35 | ureg(fifo_ctl); |
| 36 | ureg(fifo_stat); |
| 37 | char __pad[0x50]; |
| 38 | ureg(xmt_data8); |
| 39 | ureg(xmt_data16); |
| 40 | ureg(rcv_data8); |
| 41 | ureg(rcv_data16); |
| 42 | }; |
| 43 | #undef ureg |
| 44 | |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 45 | #ifdef TWI_CLKDIV |
| 46 | #define TWI0_CLKDIV TWI_CLKDIV |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 47 | # ifdef CONFIG_SYS_MAX_I2C_BUS |
| 48 | # undef CONFIG_SYS_MAX_I2C_BUS |
| 49 | # endif |
| 50 | #define CONFIG_SYS_MAX_I2C_BUS 1 |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 51 | #endif |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * The way speed is changed into duty often results in integer truncation |
| 55 | * with 50% duty, so we'll force rounding up to the next duty by adding 1 |
| 56 | * to the max. In practice this will get us a speed of something like |
| 57 | * 385 KHz. The other limit is easy to handle as it is only 8 bits. |
| 58 | */ |
| 59 | #define I2C_SPEED_MAX 400000 |
| 60 | #define I2C_SPEED_TO_DUTY(speed) (5000000 / (speed)) |
| 61 | #define I2C_DUTY_MAX (I2C_SPEED_TO_DUTY(I2C_SPEED_MAX) + 1) |
| 62 | #define I2C_DUTY_MIN 0xff /* 8 bit limited */ |
| 63 | #define SYS_I2C_DUTY I2C_SPEED_TO_DUTY(CONFIG_SYS_I2C_SPEED) |
| 64 | /* Note: duty is inverse of speed, so the comparisons below are correct */ |
| 65 | #if SYS_I2C_DUTY < I2C_DUTY_MAX || SYS_I2C_DUTY > I2C_DUTY_MIN |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 66 | # error "The I2C hardware can only operate 20KHz - 400KHz" |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 67 | #endif |
| 68 | |
| 69 | /* All transfers are described by this data structure */ |
Simon Glass | fffff72 | 2015-02-05 21:41:33 -0700 | [diff] [blame] | 70 | struct adi_i2c_msg { |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 71 | u8 flags; |
| 72 | #define I2C_M_COMBO 0x4 |
| 73 | #define I2C_M_STOP 0x2 |
| 74 | #define I2C_M_READ 0x1 |
| 75 | int len; /* msg length */ |
| 76 | u8 *buf; /* pointer to msg data */ |
| 77 | int alen; /* addr length */ |
| 78 | u8 *abuf; /* addr buffer */ |
| 79 | }; |
| 80 | |
Mike Frysinger | 3814ea4 | 2009-10-14 19:27:26 -0400 | [diff] [blame] | 81 | /* Allow msec timeout per ~byte transfer */ |
| 82 | #define I2C_TIMEOUT 10 |
| 83 | |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 84 | /** |
| 85 | * wait_for_completion - manage the actual i2c transfer |
| 86 | * @msg: the i2c msg |
| 87 | */ |
Simon Glass | fffff72 | 2015-02-05 21:41:33 -0700 | [diff] [blame] | 88 | static int wait_for_completion(struct twi_regs *twi, struct adi_i2c_msg *msg) |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 89 | { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 90 | u16 int_stat, ctl; |
Mike Frysinger | 3814ea4 | 2009-10-14 19:27:26 -0400 | [diff] [blame] | 91 | ulong timebase = get_timer(0); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 92 | |
Mike Frysinger | 3814ea4 | 2009-10-14 19:27:26 -0400 | [diff] [blame] | 93 | do { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 94 | int_stat = readw(&twi->int_stat); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 95 | |
| 96 | if (int_stat & XMTSERV) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 97 | writew(XMTSERV, &twi->int_stat); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 98 | if (msg->alen) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 99 | writew(*(msg->abuf++), &twi->xmt_data8); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 100 | --msg->alen; |
| 101 | } else if (!(msg->flags & I2C_M_COMBO) && msg->len) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 102 | writew(*(msg->buf++), &twi->xmt_data8); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 103 | --msg->len; |
| 104 | } else { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 105 | ctl = readw(&twi->master_ctl); |
| 106 | if (msg->flags & I2C_M_COMBO) |
| 107 | writew(ctl | RSTART | MDIR, |
| 108 | &twi->master_ctl); |
| 109 | else |
| 110 | writew(ctl | STOP, &twi->master_ctl); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | if (int_stat & RCVSERV) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 114 | writew(RCVSERV, &twi->int_stat); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 115 | if (msg->len) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 116 | *(msg->buf++) = readw(&twi->rcv_data8); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 117 | --msg->len; |
| 118 | } else if (msg->flags & I2C_M_STOP) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 119 | ctl = readw(&twi->master_ctl); |
| 120 | writew(ctl | STOP, &twi->master_ctl); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | if (int_stat & MERR) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 124 | writew(MERR, &twi->int_stat); |
Mike Frysinger | 3814ea4 | 2009-10-14 19:27:26 -0400 | [diff] [blame] | 125 | return msg->len; |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 126 | } |
| 127 | if (int_stat & MCOMP) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 128 | writew(MCOMP, &twi->int_stat); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 129 | if (msg->flags & I2C_M_COMBO && msg->len) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 130 | ctl = readw(&twi->master_ctl); |
| 131 | ctl = (ctl & ~RSTART) | |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 132 | (min(msg->len, 0xff) << 6) | MEN | MDIR; |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 133 | writew(ctl, &twi->master_ctl); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 134 | } else |
| 135 | break; |
| 136 | } |
Mike Frysinger | 3814ea4 | 2009-10-14 19:27:26 -0400 | [diff] [blame] | 137 | |
| 138 | /* If we were able to do something, reset timeout */ |
| 139 | if (int_stat) |
| 140 | timebase = get_timer(0); |
| 141 | |
| 142 | } while (get_timer(timebase) < I2C_TIMEOUT); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 143 | |
| 144 | return msg->len; |
| 145 | } |
| 146 | |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 147 | static int i2c_transfer(struct i2c_adapter *adap, uint8_t chip, uint addr, |
| 148 | int alen, uint8_t *buffer, int len, uint8_t flags) |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 149 | { |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 150 | struct twi_regs *twi = i2c_get_base(adap); |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 151 | int ret; |
| 152 | u16 ctl; |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 153 | uchar addr_buffer[] = { |
| 154 | (addr >> 0), |
| 155 | (addr >> 8), |
| 156 | (addr >> 16), |
| 157 | }; |
Simon Glass | fffff72 | 2015-02-05 21:41:33 -0700 | [diff] [blame] | 158 | struct adi_i2c_msg msg = { |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 159 | .flags = flags | (len >= 0xff ? I2C_M_STOP : 0), |
| 160 | .buf = buffer, |
| 161 | .len = len, |
| 162 | .abuf = addr_buffer, |
| 163 | .alen = alen, |
| 164 | }; |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 165 | |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 166 | /* wait for things to settle */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 167 | while (readw(&twi->master_stat) & BUSBUSY) |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 168 | if (ctrlc()) |
| 169 | return 1; |
| 170 | |
| 171 | /* Set Transmit device address */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 172 | writew(chip, &twi->master_addr); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 173 | |
| 174 | /* Clear the FIFO before starting things */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 175 | writew(XMTFLUSH | RCVFLUSH, &twi->fifo_ctl); |
| 176 | writew(0, &twi->fifo_ctl); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 177 | |
| 178 | /* prime the pump */ |
| 179 | if (msg.alen) { |
Peter Meerwald | 98ab14e | 2009-06-29 15:48:33 -0400 | [diff] [blame] | 180 | len = (msg.flags & I2C_M_COMBO) ? msg.alen : msg.alen + len; |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 181 | writew(*(msg.abuf++), &twi->xmt_data8); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 182 | --msg.alen; |
| 183 | } else if (!(msg.flags & I2C_M_READ) && msg.len) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 184 | writew(*(msg.buf++), &twi->xmt_data8); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 185 | --msg.len; |
| 186 | } |
| 187 | |
| 188 | /* clear int stat */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 189 | writew(-1, &twi->master_stat); |
| 190 | writew(-1, &twi->int_stat); |
| 191 | writew(0, &twi->int_mask); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 192 | |
| 193 | /* Master enable */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 194 | ctl = readw(&twi->master_ctl); |
| 195 | ctl = (ctl & FAST) | (min(len, 0xff) << 6) | MEN | |
| 196 | ((msg.flags & I2C_M_READ) ? MDIR : 0); |
| 197 | writew(ctl, &twi->master_ctl); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 198 | |
| 199 | /* process the rest */ |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 200 | ret = wait_for_completion(twi, &msg); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 201 | |
| 202 | if (ret) { |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 203 | ctl = readw(&twi->master_ctl) & ~MEN; |
| 204 | writew(ctl, &twi->master_ctl); |
| 205 | ctl = readw(&twi->control) & ~TWI_ENA; |
| 206 | writew(ctl, &twi->control); |
| 207 | ctl = readw(&twi->control) | TWI_ENA; |
| 208 | writew(ctl, &twi->control); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | return ret; |
| 212 | } |
| 213 | |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 214 | static uint adi_i2c_setspeed(struct i2c_adapter *adap, uint speed) |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 215 | { |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 216 | struct twi_regs *twi = i2c_get_base(adap); |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 217 | u16 clkdiv = I2C_SPEED_TO_DUTY(speed); |
| 218 | |
| 219 | /* Set TWI interface clock */ |
| 220 | if (clkdiv < I2C_DUTY_MAX || clkdiv > I2C_DUTY_MIN) |
| 221 | return -1; |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 222 | clkdiv = (clkdiv << 8) | (clkdiv & 0xff); |
| 223 | writew(clkdiv, &twi->clkdiv); |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 224 | |
| 225 | /* Don't turn it on */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 226 | writew(speed > 100000 ? FAST : 0, &twi->master_ctl); |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 231 | static void adi_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr) |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 232 | { |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 233 | struct twi_regs *twi = i2c_get_base(adap); |
| 234 | u16 prescale = ((get_i2c_clk() / 1000 / 1000 + 5) / 10) & 0x7F; |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 235 | |
| 236 | /* Set TWI internal clock as 10MHz */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 237 | writew(prescale, &twi->control); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 238 | |
| 239 | /* Set TWI interface clock as specified */ |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 240 | i2c_set_bus_speed(speed); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 241 | |
Mike Frysinger | 08a1c62 | 2009-10-14 19:27:27 -0400 | [diff] [blame] | 242 | /* Enable it */ |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 243 | writew(TWI_ENA | prescale, &twi->control); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 246 | static int adi_i2c_read(struct i2c_adapter *adap, uint8_t chip, |
| 247 | uint addr, int alen, uint8_t *buffer, int len) |
| 248 | { |
| 249 | return i2c_transfer(adap, chip, addr, alen, buffer, |
| 250 | len, alen ? I2C_M_COMBO : I2C_M_READ); |
| 251 | } |
| 252 | |
| 253 | static int adi_i2c_write(struct i2c_adapter *adap, uint8_t chip, |
| 254 | uint addr, int alen, uint8_t *buffer, int len) |
| 255 | { |
| 256 | return i2c_transfer(adap, chip, addr, alen, buffer, len, 0); |
| 257 | } |
| 258 | |
| 259 | static int adi_i2c_probe(struct i2c_adapter *adap, uint8_t chip) |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 260 | { |
| 261 | u8 byte; |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 262 | return adi_i2c_read(adap, chip, 0, 0, &byte, 1); |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 263 | } |
| 264 | |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 265 | static struct twi_regs *i2c_get_base(struct i2c_adapter *adap) |
Mike Frysinger | be853bf | 2008-10-06 04:16:47 -0400 | [diff] [blame] | 266 | { |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 267 | switch (adap->hwadapnr) { |
| 268 | #if CONFIG_SYS_MAX_I2C_BUS > 2 |
| 269 | case 2: |
| 270 | return (struct twi_regs *)TWI2_CLKDIV; |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 271 | #endif |
| 272 | #if CONFIG_SYS_MAX_I2C_BUS > 1 |
Scott Jiang | a6be70f | 2014-11-13 15:30:54 +0800 | [diff] [blame] | 273 | case 1: |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 274 | return (struct twi_regs *)TWI1_CLKDIV; |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 275 | #endif |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 276 | case 0: |
| 277 | return (struct twi_regs *)TWI0_CLKDIV; |
| 278 | |
| 279 | default: |
| 280 | printf("wrong hwadapnr: %d\n", adap->hwadapnr); |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 281 | } |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 282 | |
| 283 | return NULL; |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 284 | } |
| 285 | |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 286 | U_BOOT_I2C_ADAP_COMPLETE(adi_i2c0, adi_i2c_init, adi_i2c_probe, |
| 287 | adi_i2c_read, adi_i2c_write, |
| 288 | adi_i2c_setspeed, |
| 289 | CONFIG_SYS_I2C_SPEED, |
| 290 | 0, |
| 291 | 0) |
| 292 | |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 293 | #if CONFIG_SYS_MAX_I2C_BUS > 1 |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 294 | U_BOOT_I2C_ADAP_COMPLETE(adi_i2c1, adi_i2c_init, adi_i2c_probe, |
| 295 | adi_i2c_read, adi_i2c_write, |
| 296 | adi_i2c_setspeed, |
| 297 | CONFIG_SYS_I2C_SPEED, |
| 298 | 0, |
| 299 | 1) |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 300 | #endif |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 301 | |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 302 | #if CONFIG_SYS_MAX_I2C_BUS > 2 |
Scott Jiang | c469703 | 2014-11-13 15:30:55 +0800 | [diff] [blame] | 303 | U_BOOT_I2C_ADAP_COMPLETE(adi_i2c2, adi_i2c_init, adi_i2c_probe, |
| 304 | adi_i2c_read, adi_i2c_write, |
| 305 | adi_i2c_setspeed, |
| 306 | CONFIG_SYS_I2C_SPEED, |
| 307 | 0, |
| 308 | 2) |
Mike Frysinger | b5cebb4 | 2010-05-05 03:20:30 -0400 | [diff] [blame] | 309 | #endif |