Skip to content

Commit 9ba1b2f

Browse files
Bring in nct6775 SMBus driver improvements from updated patch to Windows
1 parent caf1e5c commit 9ba1b2f

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

i2c_smbus/i2c_smbus_nct6775.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int size, i2c_smbus_data *data)
1414
{
1515
int i, len, status, cnt;
16+
i2c_smbus_data tmp_data;
17+
int timeout = 0;
18+
19+
tmp_data.word = 0;
20+
cnt = 0;
21+
len = 0;
1622

1723
Out32(SMBHSTCTL, NCT6775_SOFT_RESET);
1824

@@ -21,13 +27,14 @@ s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int
2127
case I2C_SMBUS_QUICK:
2228
Out32(SMBHSTADD, (addr << 1) | read_write);
2329
break;
24-
case I2C_SMBUS_BYTE:
2530
case I2C_SMBUS_BYTE_DATA:
31+
tmp_data.byte = data->byte;
32+
case I2C_SMBUS_BYTE:
2633
Out32(SMBHSTADD, (addr << 1) | read_write);
2734
Out32(SMBHSTIDX, command);
2835
if (read_write == I2C_SMBUS_WRITE)
2936
{
30-
Out32(SMBHSTDAT, data->byte);
37+
Out32(SMBHSTDAT, tmp_data.byte);
3138
Out32(SMBHSTCMD, NCT6775_WRITE_BYTE);
3239
}
3340
else
@@ -101,7 +108,16 @@ s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int
101108
{
102109
if (read_write == I2C_SMBUS_WRITE)
103110
{
104-
while ((Inp32(SMBHSTSTS) & NCT6775_FIFO_EMPTY) == 0);
111+
timeout = 0;
112+
while ((Inp32(SMBHSTSTS) & NCT6775_FIFO_EMPTY) == 0)
113+
{
114+
if(timeout > NCT6775_MAX_RETRIES)
115+
{
116+
return -ETIMEDOUT;
117+
}
118+
Sleep(1);
119+
timeout++;
120+
}
105121

106122
//Load more bytes into FIFO
107123
if (len >= 4)
@@ -124,10 +140,23 @@ s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int
124140
len = 0;
125141
}
126142
}
143+
else
144+
{
145+
return -ENOTSUP;
146+
}
127147
}
128148

129149
//wait for manual mode to complete
130-
while ((Inp32(SMBHSTSTS) & NCT6775_MANUAL_ACTIVE) != 0);
150+
timeout = 0;
151+
while ((Inp32(SMBHSTSTS) & NCT6775_MANUAL_ACTIVE) != 0)
152+
{
153+
if(timeout > NCT6775_MAX_RETRIES)
154+
{
155+
return -ETIMEDOUT;
156+
}
157+
Sleep(1);
158+
timeout++;
159+
}
131160

132161
if ((Inp32(SMBHSTERR) & NCT6775_NO_ACK) != 0)
133162
{

i2c_smbus/i2c_smbus_nct6775.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#define NCT6775_FIFO_FULL 2
4242
#define NCT6775_MANUAL_ACTIVE 4
4343

44+
/* Other settings */
45+
#define NCT6775_MAX_RETRIES 400
46+
47+
4448
class i2c_smbus_nct6775: public i2c_smbus_interface
4549
{
4650
public:
@@ -50,4 +54,4 @@ class i2c_smbus_nct6775: public i2c_smbus_interface
5054
s32 nct6775_access(u16 addr, char read_write, u8 command, int size, i2c_smbus_data *data);
5155
s32 i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data);
5256

53-
};
57+
};

0 commit comments

Comments
 (0)