summaryrefslogtreecommitdiff
path: root/target/linux/coldfire/patches/088-m547x_8x_i2c_timeout_fix.patch
blob: dbc3c994bbf9adff00380f524c9f2c759dbe251b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
From b9607c9083b767eac26df1d39a030f3cba5d3ae3 Mon Sep 17 00:00:00 2001
From: Kurt Mahan <kmahan@freescale.com>
Date: Fri, 18 Jul 2008 12:40:04 -0600
Subject: [PATCH] Increase timeouts on I2C bus.

LTIBName: m547x-8x-i2c-timeout-fix
Signed-off-by: Shrek Wu <b16972@freescale.com>
---
 drivers/i2c/busses/i2c-mcf548x.c |   40 +++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 9 deletions(-)

--- a/drivers/i2c/busses/i2c-mcf548x.c
+++ b/drivers/i2c/busses/i2c-mcf548x.c
@@ -43,8 +43,8 @@ static struct i2c_adapter i2c_mcf_board_
 	.id = I2C_HW_MPC107,
 	.algo_data = &i2c_mcf_board_data,
 	.class = I2C_CLASS_HWMON,
-	.timeout = 1,
-	.retries = 1
+	.timeout = 100,
+	.retries = 2
 };
 /*
  *  static void i2c_start()
@@ -105,7 +105,7 @@ wait_for_bb(
 	for (i = 0; i < adap->timeout; i++) {
 		if (!(MCF_I2SR & MCF_I2SR_IBB))
 			return 0;
-		udelay(10);
+		udelay(100);
 	}
 	printk(KERN_ERR "%s: timeout", __FUNCTION__);
 	return -ETIMEDOUT;
@@ -124,7 +124,7 @@ wait_for_not_bb(
 	for (i = 0; i < adap->timeout; i++) {
 		if (MCF_I2SR & MCF_I2SR_IBB)
 			return 0;
-		udelay(10);
+		udelay(100);
 	}
 	printk(KERN_ERR "%s: timeout", __FUNCTION__);
 	return -ETIMEDOUT;
@@ -146,7 +146,7 @@ wait_xfer_done(
 			MCF_I2SR &= ~MCF_I2SR_IIF;
 			return 0;
 		}
-		udelay(1);
+		udelay(10);
 	}
 	printk(KERN_ERR "%s: timeout", __FUNCTION__);
 	return -ETIMEDOUT;
@@ -166,7 +166,7 @@ i2c_set_addr(
 ) {
 	unsigned short flags = msg->flags;
 	unsigned char addr;
-
+	MCF_I2CR |= MCF_I2CR_MTX;
 	if ((flags & I2C_M_TEN)) {
 		/* 10 bit address not supported yet */
 		return -EIO;
@@ -269,7 +269,7 @@ mcf_sendbytes(
 		i2c_stop(adap);
 		wait_for_bb(adap);
 	} else {
-		i2c_repstart(adap);
+	/*	i2c_repstart(adap);*/
 	}
 
 	return (i);
@@ -330,7 +330,7 @@ mcf_readbytes(
 		i2c_stop(adap);
 		wait_for_bb(adap);
 	} else {
-		i2c_repstart(adap);
+	/*	i2c_repstart(adap);*/
 	}
 
 	return (i+1);
@@ -380,6 +380,27 @@ mcf_xfer(
 	wait_for_bb(adap);
 
 	for (i = 0; ret >= 0 && i < num; i++) {
+		if (MCF_I2SR & MCF_I2SR_IBB) {
+			MCF_I2ICR = 0x00;
+			MCF_I2CR  = 0x00;
+                	MCF_I2CR  = 0x0A;
+                	timeout = MCF_I2DR;
+                	MCF_I2SR  = 0x00;
+                	MCF_I2CR  = 0x00;
+			MCF_I2ICR = 0x01;
+		}
+		/* setup SCL clock */
+		MCF_I2FDR = get_clock(adap);
+		/* set slave address */
+		MCF_I2AR = get_own(adap);
+		/* enable I2C module */
+		MCF_I2CR = MCF_I2CR_IEN;
+
+		MCF_I2CR |= MCF_I2CR_TXAK;
+
+		/* Check for bus busy */
+		wait_for_bb(adap);
+
 		pmsg = &msgs[i];
 
 		printk(KERN_DEBUG "i2c-algo-mcf: Doing %s %d bytes "
@@ -388,7 +409,7 @@ mcf_xfer(
 			pmsg->len, pmsg->addr, i + 1, num);
 
 		/* Send START */
-		if (i == 0)
+		/*if (i == 0)*/
 			i2c_start(adap);
 
 		/* Wait for Bus Busy */
@@ -440,6 +461,7 @@ mcf_xfer(
 					"%d bytes.\n", ret);
 			}
 		}
+	MCF_I2CR = 0;
 	}
 
 	/* Disable I2C module */