2 * (C) Copyright 2009-2010
3 * Nokia Siemens Networks, michael.lawnick.ext@nsn.com
5 * Portions Copyright (C) 2010 - 2016 Cavium, Inc.
7 * This file contains the shared part of the driver for the i2c adapter in
8 * Cavium Networks' OCTEON processors and ThunderX SOCs.
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
15 #include <linux/delay.h>
16 #include <linux/i2c.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include "i2c-octeon-core.h"
23 /* interrupt service routine */
24 irqreturn_t
octeon_i2c_isr(int irq
, void *dev_id
)
26 struct octeon_i2c
*i2c
= dev_id
;
28 i2c
->int_disable(i2c
);
34 static bool octeon_i2c_test_iflg(struct octeon_i2c
*i2c
)
36 return (octeon_i2c_ctl_read(i2c
) & TWSI_CTL_IFLG
);
40 * octeon_i2c_wait - wait for the IFLG to be set
41 * @i2c: The struct octeon_i2c
43 * Returns 0 on success, otherwise a negative errno.
45 static int octeon_i2c_wait(struct octeon_i2c
*i2c
)
50 * Some chip revisions don't assert the irq in the interrupt
51 * controller. So we must poll for the IFLG change.
53 if (i2c
->broken_irq_mode
) {
54 u64 end
= get_jiffies_64() + i2c
->adap
.timeout
;
56 while (!octeon_i2c_test_iflg(i2c
) &&
57 time_before64(get_jiffies_64(), end
))
58 usleep_range(I2C_OCTEON_EVENT_WAIT
/ 2, I2C_OCTEON_EVENT_WAIT
);
60 return octeon_i2c_test_iflg(i2c
) ? 0 : -ETIMEDOUT
;
64 time_left
= wait_event_timeout(i2c
->queue
, octeon_i2c_test_iflg(i2c
),
66 i2c
->int_disable(i2c
);
68 if (i2c
->broken_irq_check
&& !time_left
&&
69 octeon_i2c_test_iflg(i2c
)) {
70 dev_err(i2c
->dev
, "broken irq connection detected, switching to polling mode.\n");
71 i2c
->broken_irq_mode
= true;
81 static bool octeon_i2c_hlc_test_valid(struct octeon_i2c
*i2c
)
83 return (__raw_readq(i2c
->twsi_base
+ SW_TWSI(i2c
)) & SW_TWSI_V
) == 0;
86 static void octeon_i2c_hlc_int_clear(struct octeon_i2c
*i2c
)
88 /* clear ST/TS events, listen for neither */
89 octeon_i2c_write_int(i2c
, TWSI_INT_ST_INT
| TWSI_INT_TS_INT
);
93 * Cleanup low-level state & enable high-level controller.
95 static void octeon_i2c_hlc_enable(struct octeon_i2c
*i2c
)
100 if (i2c
->hlc_enabled
)
102 i2c
->hlc_enabled
= true;
105 val
= octeon_i2c_ctl_read(i2c
);
106 if (!(val
& (TWSI_CTL_STA
| TWSI_CTL_STP
)))
109 /* clear IFLG event */
110 if (val
& TWSI_CTL_IFLG
)
111 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
);
114 pr_err("%s: giving up\n", __func__
);
118 /* spin until any start/stop has finished */
121 octeon_i2c_ctl_write(i2c
, TWSI_CTL_CE
| TWSI_CTL_AAK
| TWSI_CTL_ENAB
);
124 static void octeon_i2c_hlc_disable(struct octeon_i2c
*i2c
)
126 if (!i2c
->hlc_enabled
)
129 i2c
->hlc_enabled
= false;
130 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
);
134 * octeon_i2c_hlc_wait - wait for an HLC operation to complete
135 * @i2c: The struct octeon_i2c
137 * Returns 0 on success, otherwise -ETIMEDOUT.
139 static int octeon_i2c_hlc_wait(struct octeon_i2c
*i2c
)
144 * Some cn38xx boards don't assert the irq in the interrupt
145 * controller. So we must poll for the valid bit change.
147 if (i2c
->broken_irq_mode
) {
148 u64 end
= get_jiffies_64() + i2c
->adap
.timeout
;
150 while (!octeon_i2c_hlc_test_valid(i2c
) &&
151 time_before64(get_jiffies_64(), end
))
152 usleep_range(I2C_OCTEON_EVENT_WAIT
/ 2, I2C_OCTEON_EVENT_WAIT
);
154 return octeon_i2c_hlc_test_valid(i2c
) ? 0 : -ETIMEDOUT
;
157 i2c
->hlc_int_enable(i2c
);
158 time_left
= wait_event_timeout(i2c
->queue
,
159 octeon_i2c_hlc_test_valid(i2c
),
161 i2c
->hlc_int_disable(i2c
);
163 octeon_i2c_hlc_int_clear(i2c
);
165 if (i2c
->broken_irq_check
&& !time_left
&&
166 octeon_i2c_hlc_test_valid(i2c
)) {
167 dev_err(i2c
->dev
, "broken irq connection detected, switching to polling mode.\n");
168 i2c
->broken_irq_mode
= true;
177 static int octeon_i2c_check_status(struct octeon_i2c
*i2c
, int final_read
)
182 * This is ugly... in HLC mode the status is not in the status register
183 * but in the lower 8 bits of SW_TWSI.
185 if (i2c
->hlc_enabled
)
186 stat
= __raw_readq(i2c
->twsi_base
+ SW_TWSI(i2c
));
188 stat
= octeon_i2c_stat_read(i2c
);
191 /* Everything is fine */
194 case STAT_RXADDR_ACK
:
195 case STAT_TXADDR_ACK
:
196 case STAT_TXDATA_ACK
:
199 /* ACK allowed on pre-terminal bytes only */
200 case STAT_RXDATA_ACK
:
205 /* NAK allowed on terminal byte only */
206 case STAT_RXDATA_NAK
:
211 /* Arbitration lost */
212 case STAT_LOST_ARB_38
:
213 case STAT_LOST_ARB_68
:
214 case STAT_LOST_ARB_78
:
215 case STAT_LOST_ARB_B0
:
218 /* Being addressed as slave, should back off & listen */
221 case STAT_GENDATA_ACK
:
222 case STAT_GENDATA_NAK
:
225 /* Core busy as slave */
230 case STAT_SLAVE_LOST
:
235 case STAT_TXDATA_NAK
:
237 case STAT_TXADDR_NAK
:
238 case STAT_RXADDR_NAK
:
242 dev_err(i2c
->dev
, "unhandled state: %d\n", stat
);
247 static int octeon_i2c_recovery(struct octeon_i2c
*i2c
)
251 ret
= i2c_recover_bus(&i2c
->adap
);
253 /* recover failed, try hardware re-init */
254 ret
= octeon_i2c_init_lowlevel(i2c
);
259 * octeon_i2c_start - send START to the bus
260 * @i2c: The struct octeon_i2c
262 * Returns 0 on success, otherwise a negative errno.
264 static int octeon_i2c_start(struct octeon_i2c
*i2c
)
269 octeon_i2c_hlc_disable(i2c
);
271 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
| TWSI_CTL_STA
);
272 ret
= octeon_i2c_wait(i2c
);
276 stat
= octeon_i2c_stat_read(i2c
);
277 if (stat
== STAT_START
|| stat
== STAT_REP_START
)
278 /* START successful, bail out */
282 /* START failed, try to recover */
283 ret
= octeon_i2c_recovery(i2c
);
284 return (ret
) ? ret
: -EAGAIN
;
287 /* send STOP to the bus */
288 static void octeon_i2c_stop(struct octeon_i2c
*i2c
)
290 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
| TWSI_CTL_STP
);
294 * octeon_i2c_read - receive data from the bus via low-level controller
295 * @i2c: The struct octeon_i2c
296 * @target: Target address
297 * @data: Pointer to the location to store the data
298 * @rlength: Length of the data
299 * @recv_len: flag for length byte
301 * The address is sent over the bus, then the data is read.
303 * Returns 0 on success, otherwise a negative errno.
305 static int octeon_i2c_read(struct octeon_i2c
*i2c
, int target
,
306 u8
*data
, u16
*rlength
, bool recv_len
)
308 int i
, result
, length
= *rlength
;
309 bool final_read
= false;
311 octeon_i2c_data_write(i2c
, (target
<< 1) | 1);
312 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
);
314 result
= octeon_i2c_wait(i2c
);
319 result
= octeon_i2c_check_status(i2c
, false);
323 for (i
= 0; i
< length
; i
++) {
325 * For the last byte to receive TWSI_CTL_AAK must not be set.
327 * A special case is I2C_M_RECV_LEN where we don't know the
328 * additional length yet. If recv_len is set we assume we're
329 * not reading the final byte and therefore need to set
332 if ((i
+ 1 == length
) && !(recv_len
&& i
== 0))
335 /* clear iflg to allow next event */
337 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
);
339 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
| TWSI_CTL_AAK
);
341 result
= octeon_i2c_wait(i2c
);
345 data
[i
] = octeon_i2c_data_read(i2c
, &result
);
348 if (recv_len
&& i
== 0) {
349 if (data
[i
] > I2C_SMBUS_BLOCK_MAX
+ 1)
354 result
= octeon_i2c_check_status(i2c
, final_read
);
363 * octeon_i2c_write - send data to the bus via low-level controller
364 * @i2c: The struct octeon_i2c
365 * @target: Target address
366 * @data: Pointer to the data to be sent
367 * @length: Length of the data
369 * The address is sent over the bus, then the data.
371 * Returns 0 on success, otherwise a negative errno.
373 static int octeon_i2c_write(struct octeon_i2c
*i2c
, int target
,
374 const u8
*data
, int length
)
378 octeon_i2c_data_write(i2c
, target
<< 1);
379 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
);
381 result
= octeon_i2c_wait(i2c
);
385 for (i
= 0; i
< length
; i
++) {
386 result
= octeon_i2c_check_status(i2c
, false);
390 octeon_i2c_data_write(i2c
, data
[i
]);
391 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
);
393 result
= octeon_i2c_wait(i2c
);
401 /* high-level-controller pure read of up to 8 bytes */
402 static int octeon_i2c_hlc_read(struct octeon_i2c
*i2c
, struct i2c_msg
*msgs
)
407 octeon_i2c_hlc_enable(i2c
);
408 octeon_i2c_hlc_int_clear(i2c
);
410 cmd
= SW_TWSI_V
| SW_TWSI_R
| SW_TWSI_SOVR
;
412 cmd
|= (u64
)(msgs
[0].len
- 1) << SW_TWSI_SIZE_SHIFT
;
414 cmd
|= (u64
)(msgs
[0].addr
& 0x7full
) << SW_TWSI_ADDR_SHIFT
;
416 if (msgs
[0].flags
& I2C_M_TEN
)
417 cmd
|= SW_TWSI_OP_10
;
421 octeon_i2c_writeq_flush(cmd
, i2c
->twsi_base
+ SW_TWSI(i2c
));
422 ret
= octeon_i2c_hlc_wait(i2c
);
426 cmd
= __raw_readq(i2c
->twsi_base
+ SW_TWSI(i2c
));
427 if ((cmd
& SW_TWSI_R
) == 0)
428 return octeon_i2c_check_status(i2c
, false);
430 for (i
= 0, j
= msgs
[0].len
- 1; i
< msgs
[0].len
&& i
< 4; i
++, j
--)
431 msgs
[0].buf
[j
] = (cmd
>> (8 * i
)) & 0xff;
433 if (msgs
[0].len
> 4) {
434 cmd
= __raw_readq(i2c
->twsi_base
+ SW_TWSI_EXT(i2c
));
435 for (i
= 0; i
< msgs
[0].len
- 4 && i
< 4; i
++, j
--)
436 msgs
[0].buf
[j
] = (cmd
>> (8 * i
)) & 0xff;
443 /* high-level-controller pure write of up to 8 bytes */
444 static int octeon_i2c_hlc_write(struct octeon_i2c
*i2c
, struct i2c_msg
*msgs
)
449 octeon_i2c_hlc_enable(i2c
);
450 octeon_i2c_hlc_int_clear(i2c
);
452 cmd
= SW_TWSI_V
| SW_TWSI_SOVR
;
454 cmd
|= (u64
)(msgs
[0].len
- 1) << SW_TWSI_SIZE_SHIFT
;
456 cmd
|= (u64
)(msgs
[0].addr
& 0x7full
) << SW_TWSI_ADDR_SHIFT
;
458 if (msgs
[0].flags
& I2C_M_TEN
)
459 cmd
|= SW_TWSI_OP_10
;
463 for (i
= 0, j
= msgs
[0].len
- 1; i
< msgs
[0].len
&& i
< 4; i
++, j
--)
464 cmd
|= (u64
)msgs
[0].buf
[j
] << (8 * i
);
466 if (msgs
[0].len
> 4) {
469 for (i
= 0; i
< msgs
[0].len
- 4 && i
< 4; i
++, j
--)
470 ext
|= (u64
)msgs
[0].buf
[j
] << (8 * i
);
471 octeon_i2c_writeq_flush(ext
, i2c
->twsi_base
+ SW_TWSI_EXT(i2c
));
474 octeon_i2c_writeq_flush(cmd
, i2c
->twsi_base
+ SW_TWSI(i2c
));
475 ret
= octeon_i2c_hlc_wait(i2c
);
479 cmd
= __raw_readq(i2c
->twsi_base
+ SW_TWSI(i2c
));
480 if ((cmd
& SW_TWSI_R
) == 0)
481 return octeon_i2c_check_status(i2c
, false);
487 /* high-level-controller composite write+read, msg0=addr, msg1=data */
488 static int octeon_i2c_hlc_comp_read(struct octeon_i2c
*i2c
, struct i2c_msg
*msgs
)
493 octeon_i2c_hlc_enable(i2c
);
495 cmd
= SW_TWSI_V
| SW_TWSI_R
| SW_TWSI_SOVR
;
497 cmd
|= (u64
)(msgs
[1].len
- 1) << SW_TWSI_SIZE_SHIFT
;
499 cmd
|= (u64
)(msgs
[0].addr
& 0x7full
) << SW_TWSI_ADDR_SHIFT
;
501 if (msgs
[0].flags
& I2C_M_TEN
)
502 cmd
|= SW_TWSI_OP_10_IA
;
504 cmd
|= SW_TWSI_OP_7_IA
;
506 if (msgs
[0].len
== 2) {
510 ext
= (u64
)msgs
[0].buf
[0] << SW_TWSI_IA_SHIFT
;
511 cmd
|= (u64
)msgs
[0].buf
[1] << SW_TWSI_IA_SHIFT
;
512 octeon_i2c_writeq_flush(ext
, i2c
->twsi_base
+ SW_TWSI_EXT(i2c
));
514 cmd
|= (u64
)msgs
[0].buf
[0] << SW_TWSI_IA_SHIFT
;
517 octeon_i2c_hlc_int_clear(i2c
);
518 octeon_i2c_writeq_flush(cmd
, i2c
->twsi_base
+ SW_TWSI(i2c
));
520 ret
= octeon_i2c_hlc_wait(i2c
);
524 cmd
= __raw_readq(i2c
->twsi_base
+ SW_TWSI(i2c
));
525 if ((cmd
& SW_TWSI_R
) == 0)
526 return octeon_i2c_check_status(i2c
, false);
528 for (i
= 0, j
= msgs
[1].len
- 1; i
< msgs
[1].len
&& i
< 4; i
++, j
--)
529 msgs
[1].buf
[j
] = (cmd
>> (8 * i
)) & 0xff;
531 if (msgs
[1].len
> 4) {
532 cmd
= __raw_readq(i2c
->twsi_base
+ SW_TWSI_EXT(i2c
));
533 for (i
= 0; i
< msgs
[1].len
- 4 && i
< 4; i
++, j
--)
534 msgs
[1].buf
[j
] = (cmd
>> (8 * i
)) & 0xff;
541 /* high-level-controller composite write+write, m[0]len<=2, m[1]len<=8 */
542 static int octeon_i2c_hlc_comp_write(struct octeon_i2c
*i2c
, struct i2c_msg
*msgs
)
544 bool set_ext
= false;
548 octeon_i2c_hlc_enable(i2c
);
550 cmd
= SW_TWSI_V
| SW_TWSI_SOVR
;
552 cmd
|= (u64
)(msgs
[1].len
- 1) << SW_TWSI_SIZE_SHIFT
;
554 cmd
|= (u64
)(msgs
[0].addr
& 0x7full
) << SW_TWSI_ADDR_SHIFT
;
556 if (msgs
[0].flags
& I2C_M_TEN
)
557 cmd
|= SW_TWSI_OP_10_IA
;
559 cmd
|= SW_TWSI_OP_7_IA
;
561 if (msgs
[0].len
== 2) {
563 ext
|= (u64
)msgs
[0].buf
[0] << SW_TWSI_IA_SHIFT
;
565 cmd
|= (u64
)msgs
[0].buf
[1] << SW_TWSI_IA_SHIFT
;
567 cmd
|= (u64
)msgs
[0].buf
[0] << SW_TWSI_IA_SHIFT
;
570 for (i
= 0, j
= msgs
[1].len
- 1; i
< msgs
[1].len
&& i
< 4; i
++, j
--)
571 cmd
|= (u64
)msgs
[1].buf
[j
] << (8 * i
);
573 if (msgs
[1].len
> 4) {
574 for (i
= 0; i
< msgs
[1].len
- 4 && i
< 4; i
++, j
--)
575 ext
|= (u64
)msgs
[1].buf
[j
] << (8 * i
);
579 octeon_i2c_writeq_flush(ext
, i2c
->twsi_base
+ SW_TWSI_EXT(i2c
));
581 octeon_i2c_hlc_int_clear(i2c
);
582 octeon_i2c_writeq_flush(cmd
, i2c
->twsi_base
+ SW_TWSI(i2c
));
584 ret
= octeon_i2c_hlc_wait(i2c
);
588 cmd
= __raw_readq(i2c
->twsi_base
+ SW_TWSI(i2c
));
589 if ((cmd
& SW_TWSI_R
) == 0)
590 return octeon_i2c_check_status(i2c
, false);
597 * octeon_i2c_xfer - The driver's master_xfer function
598 * @adap: Pointer to the i2c_adapter structure
599 * @msgs: Pointer to the messages to be processed
600 * @num: Length of the MSGS array
602 * Returns the number of messages processed, or a negative errno on failure.
604 int octeon_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msgs
, int num
)
606 struct octeon_i2c
*i2c
= i2c_get_adapdata(adap
);
610 if (msgs
[0].len
> 0 && msgs
[0].len
<= 8) {
611 if (msgs
[0].flags
& I2C_M_RD
)
612 ret
= octeon_i2c_hlc_read(i2c
, msgs
);
614 ret
= octeon_i2c_hlc_write(i2c
, msgs
);
617 } else if (num
== 2) {
618 if ((msgs
[0].flags
& I2C_M_RD
) == 0 &&
619 (msgs
[1].flags
& I2C_M_RECV_LEN
) == 0 &&
620 msgs
[0].len
> 0 && msgs
[0].len
<= 2 &&
621 msgs
[1].len
> 0 && msgs
[1].len
<= 8 &&
622 msgs
[0].addr
== msgs
[1].addr
) {
623 if (msgs
[1].flags
& I2C_M_RD
)
624 ret
= octeon_i2c_hlc_comp_read(i2c
, msgs
);
626 ret
= octeon_i2c_hlc_comp_write(i2c
, msgs
);
631 for (i
= 0; ret
== 0 && i
< num
; i
++) {
632 struct i2c_msg
*pmsg
= &msgs
[i
];
634 /* zero-length messages are not supported */
640 ret
= octeon_i2c_start(i2c
);
644 if (pmsg
->flags
& I2C_M_RD
)
645 ret
= octeon_i2c_read(i2c
, pmsg
->addr
, pmsg
->buf
,
646 &pmsg
->len
, pmsg
->flags
& I2C_M_RECV_LEN
);
648 ret
= octeon_i2c_write(i2c
, pmsg
->addr
, pmsg
->buf
,
651 octeon_i2c_stop(i2c
);
653 return (ret
!= 0) ? ret
: num
;
656 /* calculate and set clock divisors */
657 void octeon_i2c_set_clock(struct octeon_i2c
*i2c
)
659 int tclk
, thp_base
, inc
, thp_idx
, mdiv_idx
, ndiv_idx
, foscl
, diff
;
660 int thp
= 0x18, mdiv
= 2, ndiv
= 0, delta_hz
= 1000000;
662 for (ndiv_idx
= 0; ndiv_idx
< 8 && delta_hz
!= 0; ndiv_idx
++) {
664 * An mdiv value of less than 2 seems to not work well
665 * with ds1337 RTCs, so we constrain it to larger values.
667 for (mdiv_idx
= 15; mdiv_idx
>= 2 && delta_hz
!= 0; mdiv_idx
--) {
669 * For given ndiv and mdiv values check the
670 * two closest thp values.
672 tclk
= i2c
->twsi_freq
* (mdiv_idx
+ 1) * 10;
673 tclk
*= (1 << ndiv_idx
);
674 thp_base
= (i2c
->sys_freq
/ (tclk
* 2)) - 1;
676 for (inc
= 0; inc
<= 1; inc
++) {
677 thp_idx
= thp_base
+ inc
;
678 if (thp_idx
< 5 || thp_idx
> 0xff)
681 foscl
= i2c
->sys_freq
/ (2 * (thp_idx
+ 1));
682 foscl
= foscl
/ (1 << ndiv_idx
);
683 foscl
= foscl
/ (mdiv_idx
+ 1) / 10;
684 diff
= abs(foscl
- i2c
->twsi_freq
);
685 if (diff
< delta_hz
) {
694 octeon_i2c_reg_write(i2c
, SW_TWSI_OP_TWSI_CLK
, thp
);
695 octeon_i2c_reg_write(i2c
, SW_TWSI_EOP_TWSI_CLKCTL
, (mdiv
<< 3) | ndiv
);
698 int octeon_i2c_init_lowlevel(struct octeon_i2c
*i2c
)
703 /* reset controller */
704 octeon_i2c_reg_write(i2c
, SW_TWSI_EOP_TWSI_RST
, 0);
706 for (tries
= 10; tries
&& status
!= STAT_IDLE
; tries
--) {
708 status
= octeon_i2c_stat_read(i2c
);
709 if (status
== STAT_IDLE
)
713 if (status
!= STAT_IDLE
) {
714 dev_err(i2c
->dev
, "%s: TWSI_RST failed! (0x%x)\n",
719 /* toggle twice to force both teardowns */
720 octeon_i2c_hlc_enable(i2c
);
721 octeon_i2c_hlc_disable(i2c
);
725 static int octeon_i2c_get_scl(struct i2c_adapter
*adap
)
727 struct octeon_i2c
*i2c
= i2c_get_adapdata(adap
);
730 state
= octeon_i2c_read_int(i2c
);
731 return state
& TWSI_INT_SCL
;
734 static void octeon_i2c_set_scl(struct i2c_adapter
*adap
, int val
)
736 struct octeon_i2c
*i2c
= i2c_get_adapdata(adap
);
738 octeon_i2c_write_int(i2c
, val
? 0 : TWSI_INT_SCL_OVR
);
741 static int octeon_i2c_get_sda(struct i2c_adapter
*adap
)
743 struct octeon_i2c
*i2c
= i2c_get_adapdata(adap
);
746 state
= octeon_i2c_read_int(i2c
);
747 return state
& TWSI_INT_SDA
;
750 static void octeon_i2c_prepare_recovery(struct i2c_adapter
*adap
)
752 struct octeon_i2c
*i2c
= i2c_get_adapdata(adap
);
754 octeon_i2c_hlc_disable(i2c
);
755 octeon_i2c_reg_write(i2c
, SW_TWSI_EOP_TWSI_RST
, 0);
756 /* wait for software reset to settle */
760 * Bring control register to a good state regardless
763 octeon_i2c_ctl_write(i2c
, TWSI_CTL_ENAB
);
765 octeon_i2c_write_int(i2c
, 0);
768 static void octeon_i2c_unprepare_recovery(struct i2c_adapter
*adap
)
770 struct octeon_i2c
*i2c
= i2c_get_adapdata(adap
);
773 * Generate STOP to finish the unfinished transaction.
774 * Can't generate STOP via the TWSI CTL register
775 * since it could bring the TWSI controller into an inoperable state.
777 octeon_i2c_write_int(i2c
, TWSI_INT_SDA_OVR
| TWSI_INT_SCL_OVR
);
779 octeon_i2c_write_int(i2c
, TWSI_INT_SDA_OVR
);
781 octeon_i2c_write_int(i2c
, 0);
784 struct i2c_bus_recovery_info octeon_i2c_recovery_info
= {
785 .recover_bus
= i2c_generic_scl_recovery
,
786 .get_scl
= octeon_i2c_get_scl
,
787 .set_scl
= octeon_i2c_set_scl
,
788 .get_sda
= octeon_i2c_get_sda
,
789 .prepare_recovery
= octeon_i2c_prepare_recovery
,
790 .unprepare_recovery
= octeon_i2c_unprepare_recovery
,