@@ -42,14 +42,17 @@ static int i2c_write_2b(struct eeprom *e, __s8 i2c_addr, __u8 buf[2])
42
42
int r ;
43
43
if ( ( r = ioctl (e -> fd , I2C_SLAVE , i2c_addr )) < 0 )
44
44
{
45
+ fprintf (stderr , "ioctl r=%d\n" , r );
45
46
fprintf (stderr , "Error i2c_write_2b: %s\n" , strerror (errno ));
46
47
return r ;
47
48
}
48
49
49
50
// we must simulate a plain I2C byte write with SMBus functions
50
51
r = i2c_smbus_write_byte_data (e -> fd , buf [0 ], buf [1 ]);
51
- if (r < 0 )
52
+ if (r < 0 ) {
53
+ fprintf (stderr , "i2c_smbus_write_word_data r=%d\n" , r );
52
54
fprintf (stderr , "Error i2c_write_2b: %s\n" , strerror (errno ));
55
+ }
53
56
usleep (10 );
54
57
return r ;
55
58
}
@@ -60,15 +63,18 @@ static int i2c_write_3b(struct eeprom *e, __s8 i2c_addr, __u8 buf[3])
60
63
int r ;
61
64
if ( ( r = ioctl (e -> fd , I2C_SLAVE , i2c_addr )) < 0 )
62
65
{
66
+ fprintf (stderr , "ioctl r=%d\n" , r );
63
67
fprintf (stderr , "Error i2c_write_3b: %s\n" , strerror (errno ));
64
68
return r ;
65
69
}
66
70
67
71
// we must simulate a plain I2C byte write with SMBus functions
68
72
// the __u16 data field will be byte swapped by the SMBus protocol
69
73
r = i2c_smbus_write_word_data (e -> fd , buf [0 ], buf [2 ] << 8 | buf [1 ]);
70
- if (r < 0 )
74
+ if (r < 0 ) {
75
+ fprintf (stderr , "i2c_smbus_write_word_data r=%d\n" , r );
71
76
fprintf (stderr , "Error i2c_write_3b: %s\n" , strerror (errno ));
77
+ }
72
78
usleep (10 );
73
79
return r ;
74
80
}
@@ -112,7 +118,7 @@ int eeprom_open(char *dev_fqn, int i2c_addr, int bits, int write_cycle_time, str
112
118
113
119
#if 0
114
120
// set working device
115
- if ( ( r = ioctl (fd , I2C_SLAVE , addr )) < 0 )
121
+ if ( ( r = ioctl (fd , I2C_SLAVE , i2c_addr )) < 0 )
116
122
{
117
123
fprintf (stderr , "Error eeprom_open: %s\n" , strerror (errno ));
118
124
return -1 ;
@@ -124,7 +130,7 @@ int eeprom_open(char *dev_fqn, int i2c_addr, int bits, int write_cycle_time, str
124
130
e -> bits = bits ;
125
131
e -> type = EEPROM_TYPE_8BIT_ADDR ;
126
132
if (bits > 16 ) e -> type = EEPROM_TYPE_16BIT_ADDR ;
127
- e -> bytes = 128 * bits ;
133
+ e -> bytes = ( __u32 ) 128 * ( __u32 ) bits ;
128
134
e -> write_cycle_time = write_cycle_time ;
129
135
//printf("bits=%d bytes=%d type=%d\n",e->bits, e->bytes, e->type);
130
136
return 0 ;
@@ -139,7 +145,7 @@ int eeprom_close(struct eeprom *e)
139
145
return 0 ;
140
146
}
141
147
142
- __u16 getEEPROMbytes (struct eeprom * e )
148
+ __u32 getEEPROMbytes (struct eeprom * e )
143
149
{
144
150
return (e -> bytes );
145
151
}
0 commit comments