@@ -60,29 +60,29 @@ static void pca9665_reset(void *pd)
6060 *
6161 * returns after the start condition has occurred
6262 */
63- static void pca_start (struct i2c_algo_pca_data * adap )
63+ static int pca_start (struct i2c_algo_pca_data * adap )
6464{
6565 int sta = pca_get_con (adap );
6666 DEB2 ("=== START\n" );
6767 sta |= I2C_PCA_CON_STA ;
6868 sta &= ~(I2C_PCA_CON_STO |I2C_PCA_CON_SI );
6969 pca_set_con (adap , sta );
70- pca_wait (adap );
70+ return pca_wait (adap );
7171}
7272
7373/*
7474 * Generate a repeated start condition on the i2c bus
7575 *
7676 * return after the repeated start condition has occurred
7777 */
78- static void pca_repeated_start (struct i2c_algo_pca_data * adap )
78+ static int pca_repeated_start (struct i2c_algo_pca_data * adap )
7979{
8080 int sta = pca_get_con (adap );
8181 DEB2 ("=== REPEATED START\n" );
8282 sta |= I2C_PCA_CON_STA ;
8383 sta &= ~(I2C_PCA_CON_STO |I2C_PCA_CON_SI );
8484 pca_set_con (adap , sta );
85- pca_wait (adap );
85+ return pca_wait (adap );
8686}
8787
8888/*
@@ -108,7 +108,7 @@ static void pca_stop(struct i2c_algo_pca_data *adap)
108108 *
109109 * returns after the address has been sent
110110 */
111- static void pca_address (struct i2c_algo_pca_data * adap ,
111+ static int pca_address (struct i2c_algo_pca_data * adap ,
112112 struct i2c_msg * msg )
113113{
114114 int sta = pca_get_con (adap );
@@ -125,15 +125,15 @@ static void pca_address(struct i2c_algo_pca_data *adap,
125125 sta &= ~(I2C_PCA_CON_STO |I2C_PCA_CON_STA |I2C_PCA_CON_SI );
126126 pca_set_con (adap , sta );
127127
128- pca_wait (adap );
128+ return pca_wait (adap );
129129}
130130
131131/*
132132 * Transmit a byte.
133133 *
134134 * Returns after the byte has been transmitted
135135 */
136- static void pca_tx_byte (struct i2c_algo_pca_data * adap ,
136+ static int pca_tx_byte (struct i2c_algo_pca_data * adap ,
137137 __u8 b )
138138{
139139 int sta = pca_get_con (adap );
@@ -143,7 +143,7 @@ static void pca_tx_byte(struct i2c_algo_pca_data *adap,
143143 sta &= ~(I2C_PCA_CON_STO |I2C_PCA_CON_STA |I2C_PCA_CON_SI );
144144 pca_set_con (adap , sta );
145145
146- pca_wait (adap );
146+ return pca_wait (adap );
147147}
148148
149149/*
@@ -163,7 +163,7 @@ static void pca_rx_byte(struct i2c_algo_pca_data *adap,
163163 *
164164 * Returns after next byte has arrived.
165165 */
166- static void pca_rx_ack (struct i2c_algo_pca_data * adap ,
166+ static int pca_rx_ack (struct i2c_algo_pca_data * adap ,
167167 int ack )
168168{
169169 int sta = pca_get_con (adap );
@@ -174,7 +174,7 @@ static void pca_rx_ack(struct i2c_algo_pca_data *adap,
174174 sta |= I2C_PCA_CON_AA ;
175175
176176 pca_set_con (adap , sta );
177- pca_wait (adap );
177+ return pca_wait (adap );
178178}
179179
180180static int pca_xfer (struct i2c_adapter * i2c_adap ,
@@ -187,6 +187,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
187187 int numbytes = 0 ;
188188 int state ;
189189 int ret ;
190+ int completed = 1 ;
190191 unsigned long timeout = jiffies + i2c_adap -> timeout ;
191192
192193 while (pca_status (adap ) != 0xf8 ) {
@@ -232,26 +233,27 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
232233
233234 switch (state ) {
234235 case 0xf8 : /* On reset or stop the bus is idle */
235- pca_start (adap );
236+ completed = pca_start (adap );
236237 break ;
237238
238239 case 0x08 : /* A START condition has been transmitted */
239240 case 0x10 : /* A repeated start condition has been transmitted */
240- pca_address (adap , msg );
241+ completed = pca_address (adap , msg );
241242 break ;
242243
243244 case 0x18 : /* SLA+W has been transmitted; ACK has been received */
244245 case 0x28 : /* Data byte in I2CDAT has been transmitted; ACK has been received */
245246 if (numbytes < msg -> len ) {
246- pca_tx_byte (adap , msg -> buf [numbytes ]);
247+ completed = pca_tx_byte (adap ,
248+ msg -> buf [numbytes ]);
247249 numbytes ++ ;
248250 break ;
249251 }
250252 curmsg ++ ; numbytes = 0 ;
251253 if (curmsg == num )
252254 pca_stop (adap );
253255 else
254- pca_repeated_start (adap );
256+ completed = pca_repeated_start (adap );
255257 break ;
256258
257259 case 0x20 : /* SLA+W has been transmitted; NOT ACK has been received */
@@ -260,21 +262,22 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
260262 goto out ;
261263
262264 case 0x40 : /* SLA+R has been transmitted; ACK has been received */
263- pca_rx_ack (adap , msg -> len > 1 );
265+ completed = pca_rx_ack (adap , msg -> len > 1 );
264266 break ;
265267
266268 case 0x50 : /* Data bytes has been received; ACK has been returned */
267269 if (numbytes < msg -> len ) {
268270 pca_rx_byte (adap , & msg -> buf [numbytes ], 1 );
269271 numbytes ++ ;
270- pca_rx_ack (adap , numbytes < msg -> len - 1 );
272+ completed = pca_rx_ack (adap ,
273+ numbytes < msg -> len - 1 );
271274 break ;
272275 }
273276 curmsg ++ ; numbytes = 0 ;
274277 if (curmsg == num )
275278 pca_stop (adap );
276279 else
277- pca_repeated_start (adap );
280+ completed = pca_repeated_start (adap );
278281 break ;
279282
280283 case 0x48 : /* SLA+R has been transmitted; NOT ACK has been received */
@@ -297,7 +300,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
297300 if (curmsg == num )
298301 pca_stop (adap );
299302 else
300- pca_repeated_start (adap );
303+ completed = pca_repeated_start (adap );
301304 } else {
302305 DEB2 ("NOT ACK sent after data byte received. "
303306 "Not final byte. numbytes %d. len %d\n" ,
@@ -323,6 +326,8 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
323326 break ;
324327 }
325328
329+ if (!completed )
330+ goto out ;
326331 }
327332
328333 ret = curmsg ;
0 commit comments