@@ -142,24 +142,23 @@ static int idtcm_strverscmp(const char *ver1, const char *ver2)
142
142
return result ;
143
143
}
144
144
145
- static int idtcm_xfer (struct idtcm * idtcm ,
146
- u8 regaddr ,
147
- u8 * buf ,
148
- u16 count ,
149
- bool write )
145
+ static int idtcm_xfer_read (struct idtcm * idtcm ,
146
+ u8 regaddr ,
147
+ u8 * buf ,
148
+ u16 count )
150
149
{
151
150
struct i2c_client * client = idtcm -> client ;
152
151
struct i2c_msg msg [2 ];
153
152
int cnt ;
154
- char * fmt = "i2c_transfer failed at %d in %s for %s , at addr: %04X!\n" ;
153
+ char * fmt = "i2c_transfer failed at %d in %s, at addr: %04X!\n" ;
155
154
156
155
msg [0 ].addr = client -> addr ;
157
156
msg [0 ].flags = 0 ;
158
157
msg [0 ].len = 1 ;
159
158
msg [0 ].buf = & regaddr ;
160
159
161
160
msg [1 ].addr = client -> addr ;
162
- msg [1 ].flags = write ? 0 : I2C_M_RD ;
161
+ msg [1 ].flags = I2C_M_RD ;
163
162
msg [1 ].len = count ;
164
163
msg [1 ].buf = buf ;
165
164
@@ -170,7 +169,6 @@ static int idtcm_xfer(struct idtcm *idtcm,
170
169
fmt ,
171
170
__LINE__ ,
172
171
__func__ ,
173
- write ? "write" : "read" ,
174
172
regaddr );
175
173
return cnt ;
176
174
} else if (cnt != 2 ) {
@@ -182,6 +180,37 @@ static int idtcm_xfer(struct idtcm *idtcm,
182
180
return 0 ;
183
181
}
184
182
183
+ static int idtcm_xfer_write (struct idtcm * idtcm ,
184
+ u8 regaddr ,
185
+ u8 * buf ,
186
+ u16 count )
187
+ {
188
+ struct i2c_client * client = idtcm -> client ;
189
+ /* we add 1 byte for device register */
190
+ u8 msg [IDTCM_MAX_WRITE_COUNT + 1 ];
191
+ int cnt ;
192
+ char * fmt = "i2c_master_send failed at %d in %s, at addr: %04X!\n" ;
193
+
194
+ if (count > IDTCM_MAX_WRITE_COUNT )
195
+ return - EINVAL ;
196
+
197
+ msg [0 ] = regaddr ;
198
+ memcpy (& msg [1 ], buf , count );
199
+
200
+ cnt = i2c_master_send (client , msg , count + 1 );
201
+
202
+ if (cnt < 0 ) {
203
+ dev_err (& client -> dev ,
204
+ fmt ,
205
+ __LINE__ ,
206
+ __func__ ,
207
+ regaddr );
208
+ return cnt ;
209
+ }
210
+
211
+ return 0 ;
212
+ }
213
+
185
214
static int idtcm_page_offset (struct idtcm * idtcm , u8 val )
186
215
{
187
216
u8 buf [4 ];
@@ -195,7 +224,7 @@ static int idtcm_page_offset(struct idtcm *idtcm, u8 val)
195
224
buf [2 ] = 0x10 ;
196
225
buf [3 ] = 0x20 ;
197
226
198
- err = idtcm_xfer (idtcm , PAGE_ADDR , buf , sizeof (buf ), 1 );
227
+ err = idtcm_xfer_write (idtcm , PAGE_ADDR , buf , sizeof (buf ));
199
228
200
229
if (err ) {
201
230
idtcm -> page_offset = 0xff ;
@@ -223,11 +252,12 @@ static int _idtcm_rdwr(struct idtcm *idtcm,
223
252
err = idtcm_page_offset (idtcm , hi );
224
253
225
254
if (err )
226
- goto out ;
255
+ return err ;
227
256
228
- err = idtcm_xfer (idtcm , lo , buf , count , write );
229
- out :
230
- return err ;
257
+ if (write )
258
+ return idtcm_xfer_write (idtcm , lo , buf , count );
259
+
260
+ return idtcm_xfer_read (idtcm , lo , buf , count );
231
261
}
232
262
233
263
static int idtcm_read (struct idtcm * idtcm ,
0 commit comments