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
|
/*
* Copyright (C) 2013 Gateworks Corporation
* Copyright (C) 2014 Lucas Stach, Pengutronix
* Author: Tim Harvey <tharvey@gateworks.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* The Gateworks System Controller will fail to ACK a master transaction if
* it is busy, which can occur during its 1HZ timer tick while reading ADC's.
* When this does occur, it will never be busy long enough to fail more than
* 2 back-to-back transfers. Thus we wrap i2c_read and i2c_write with
* 3 retries.
*/
#include <common.h>
#include <i2c/i2c.h>
#include "gsc.h"
int gsc_i2c_read(struct i2c_client *client, u32 addr, u8 *buf, u16 count)
{
int retry = 3;
int n = 0;
int ret;
while (n++ < retry) {
ret = i2c_read_reg(client, addr, buf, count);
if (!ret)
break;
pr_debug("GSC read failed\n");
if (ret != -ENODEV)
break;
mdelay(10);
}
return ret;
}
int gsc_i2c_write(struct i2c_client *client, u32 addr, const u8 *buf, u16 count)
{
int retry = 3;
int n = 0;
int ret;
while (n++ < retry) {
ret = i2c_write_reg(client, addr, buf, count);
if (!ret)
break;
pr_debug("GSC write failed\n");
if (ret != -ENODEV)
break;
mdelay(10);
}
mdelay(100);
return ret;
}
|