@@ -62,14 +62,16 @@ struct cros_ec_lpc {
62
62
63
63
/**
64
64
* struct lpc_driver_ops - LPC driver operations
65
- * @read: Copy length bytes from EC address offset into buffer dest. Returns
66
- * the 8-bit checksum of all bytes read.
67
- * @write: Copy length bytes from buffer msg into EC address offset. Returns
68
- * the 8-bit checksum of all bytes written.
65
+ * @read: Copy length bytes from EC address offset into buffer dest.
66
+ * Returns a negative error code on error, or the 8-bit checksum
67
+ * of all bytes read.
68
+ * @write: Copy length bytes from buffer msg into EC address offset.
69
+ * Returns a negative error code on error, or the 8-bit checksum
70
+ * of all bytes written.
69
71
*/
70
72
struct lpc_driver_ops {
71
- u8 (* read )(unsigned int offset , unsigned int length , u8 * dest );
72
- u8 (* write )(unsigned int offset , unsigned int length , const u8 * msg );
73
+ int (* read )(unsigned int offset , unsigned int length , u8 * dest );
74
+ int (* write )(unsigned int offset , unsigned int length , const u8 * msg );
73
75
};
74
76
75
77
static struct lpc_driver_ops cros_ec_lpc_ops = { };
@@ -78,10 +80,10 @@ static struct lpc_driver_ops cros_ec_lpc_ops = { };
78
80
* A generic instance of the read function of struct lpc_driver_ops, used for
79
81
* the LPC EC.
80
82
*/
81
- static u8 cros_ec_lpc_read_bytes (unsigned int offset , unsigned int length ,
82
- u8 * dest )
83
+ static int cros_ec_lpc_read_bytes (unsigned int offset , unsigned int length ,
84
+ u8 * dest )
83
85
{
84
- int sum = 0 ;
86
+ u8 sum = 0 ;
85
87
int i ;
86
88
87
89
for (i = 0 ; i < length ; ++ i ) {
@@ -97,10 +99,10 @@ static u8 cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length,
97
99
* A generic instance of the write function of struct lpc_driver_ops, used for
98
100
* the LPC EC.
99
101
*/
100
- static u8 cros_ec_lpc_write_bytes (unsigned int offset , unsigned int length ,
101
- const u8 * msg )
102
+ static int cros_ec_lpc_write_bytes (unsigned int offset , unsigned int length ,
103
+ const u8 * msg )
102
104
{
103
- int sum = 0 ;
105
+ u8 sum = 0 ;
104
106
int i ;
105
107
106
108
for (i = 0 ; i < length ; ++ i ) {
@@ -116,8 +118,8 @@ static u8 cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length,
116
118
* An instance of the read function of struct lpc_driver_ops, used for the
117
119
* MEC variant of LPC EC.
118
120
*/
119
- static u8 cros_ec_lpc_mec_read_bytes (unsigned int offset , unsigned int length ,
120
- u8 * dest )
121
+ static int cros_ec_lpc_mec_read_bytes (unsigned int offset , unsigned int length ,
122
+ u8 * dest )
121
123
{
122
124
int in_range = cros_ec_lpc_mec_in_range (offset , length );
123
125
@@ -135,8 +137,8 @@ static u8 cros_ec_lpc_mec_read_bytes(unsigned int offset, unsigned int length,
135
137
* An instance of the write function of struct lpc_driver_ops, used for the
136
138
* MEC variant of LPC EC.
137
139
*/
138
- static u8 cros_ec_lpc_mec_write_bytes (unsigned int offset , unsigned int length ,
139
- const u8 * msg )
140
+ static int cros_ec_lpc_mec_write_bytes (unsigned int offset , unsigned int length ,
141
+ const u8 * msg )
140
142
{
141
143
int in_range = cros_ec_lpc_mec_in_range (offset , length );
142
144
@@ -154,11 +156,14 @@ static int ec_response_timed_out(void)
154
156
{
155
157
unsigned long one_second = jiffies + HZ ;
156
158
u8 data ;
159
+ int ret ;
157
160
158
161
usleep_range (200 , 300 );
159
162
do {
160
- if (!(cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_CMD , 1 , & data ) &
161
- EC_LPC_STATUS_BUSY_MASK ))
163
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_CMD , 1 , & data );
164
+ if (ret < 0 )
165
+ return ret ;
166
+ if (!(data & EC_LPC_STATUS_BUSY_MASK ))
162
167
return 0 ;
163
168
usleep_range (100 , 200 );
164
169
} while (time_before (jiffies , one_second ));
@@ -179,28 +184,41 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
179
184
goto done ;
180
185
181
186
/* Write buffer */
182
- cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_PACKET , ret , ec -> dout );
187
+ ret = cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_PACKET , ret , ec -> dout );
188
+ if (ret < 0 )
189
+ goto done ;
183
190
184
191
/* Here we go */
185
192
sum = EC_COMMAND_PROTOCOL_3 ;
186
- cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_CMD , 1 , & sum );
193
+ ret = cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_CMD , 1 , & sum );
194
+ if (ret < 0 )
195
+ goto done ;
187
196
188
- if (ec_response_timed_out ()) {
197
+ ret = ec_response_timed_out ();
198
+ if (ret < 0 )
199
+ goto done ;
200
+ if (ret ) {
189
201
dev_warn (ec -> dev , "EC response timed out\n" );
190
202
ret = - EIO ;
191
203
goto done ;
192
204
}
193
205
194
206
/* Check result */
195
- msg -> result = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_DATA , 1 , & sum );
207
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_DATA , 1 , & sum );
208
+ if (ret < 0 )
209
+ goto done ;
210
+ msg -> result = ret ;
196
211
ret = cros_ec_check_result (ec , msg );
197
212
if (ret )
198
213
goto done ;
199
214
200
215
/* Read back response */
201
216
dout = (u8 * )& response ;
202
- sum = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_PACKET , sizeof (response ),
217
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_PACKET , sizeof (response ),
203
218
dout );
219
+ if (ret < 0 )
220
+ goto done ;
221
+ sum = ret ;
204
222
205
223
msg -> result = response .result ;
206
224
@@ -213,9 +231,12 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
213
231
}
214
232
215
233
/* Read response and process checksum */
216
- sum += cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_PACKET +
217
- sizeof (response ), response .data_len ,
218
- msg -> data );
234
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_PACKET +
235
+ sizeof (response ), response .data_len ,
236
+ msg -> data );
237
+ if (ret < 0 )
238
+ goto done ;
239
+ sum += ret ;
219
240
220
241
if (sum ) {
221
242
dev_err (ec -> dev ,
@@ -255,32 +276,47 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
255
276
sum = msg -> command + args .flags + args .command_version + args .data_size ;
256
277
257
278
/* Copy data and update checksum */
258
- sum += cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_PARAM , msg -> outsize ,
259
- msg -> data );
279
+ ret = cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_PARAM , msg -> outsize ,
280
+ msg -> data );
281
+ if (ret < 0 )
282
+ goto done ;
283
+ sum += ret ;
260
284
261
285
/* Finalize checksum and write args */
262
286
args .checksum = sum ;
263
- cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_ARGS , sizeof (args ),
264
- (u8 * )& args );
287
+ ret = cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_ARGS , sizeof (args ),
288
+ (u8 * )& args );
289
+ if (ret < 0 )
290
+ goto done ;
265
291
266
292
/* Here we go */
267
293
sum = msg -> command ;
268
- cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_CMD , 1 , & sum );
294
+ ret = cros_ec_lpc_ops .write (EC_LPC_ADDR_HOST_CMD , 1 , & sum );
295
+ if (ret < 0 )
296
+ goto done ;
269
297
270
- if (ec_response_timed_out ()) {
298
+ ret = ec_response_timed_out ();
299
+ if (ret < 0 )
300
+ goto done ;
301
+ if (ret ) {
271
302
dev_warn (ec -> dev , "EC response timed out\n" );
272
303
ret = - EIO ;
273
304
goto done ;
274
305
}
275
306
276
307
/* Check result */
277
- msg -> result = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_DATA , 1 , & sum );
308
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_DATA , 1 , & sum );
309
+ if (ret < 0 )
310
+ goto done ;
311
+ msg -> result = ret ;
278
312
ret = cros_ec_check_result (ec , msg );
279
313
if (ret )
280
314
goto done ;
281
315
282
316
/* Read back args */
283
- cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_ARGS , sizeof (args ), (u8 * )& args );
317
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_ARGS , sizeof (args ), (u8 * )& args );
318
+ if (ret < 0 )
319
+ goto done ;
284
320
285
321
if (args .data_size > msg -> insize ) {
286
322
dev_err (ec -> dev ,
@@ -294,8 +330,11 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
294
330
sum = msg -> command + args .flags + args .command_version + args .data_size ;
295
331
296
332
/* Read response and update checksum */
297
- sum += cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_PARAM , args .data_size ,
298
- msg -> data );
333
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_HOST_PARAM , args .data_size ,
334
+ msg -> data );
335
+ if (ret < 0 )
336
+ goto done ;
337
+ sum += ret ;
299
338
300
339
/* Verify checksum */
301
340
if (args .checksum != sum ) {
@@ -320,19 +359,24 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
320
359
int i = offset ;
321
360
char * s = dest ;
322
361
int cnt = 0 ;
362
+ int ret ;
323
363
324
364
if (offset >= EC_MEMMAP_SIZE - bytes )
325
365
return - EINVAL ;
326
366
327
367
/* fixed length */
328
368
if (bytes ) {
329
- cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + offset , bytes , s );
369
+ ret = cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + offset , bytes , s );
370
+ if (ret < 0 )
371
+ return ret ;
330
372
return bytes ;
331
373
}
332
374
333
375
/* string */
334
376
for (; i < EC_MEMMAP_SIZE ; i ++ , s ++ ) {
335
- cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + i , 1 , s );
377
+ ret = cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + i , 1 , s );
378
+ if (ret < 0 )
379
+ return ret ;
336
380
cnt ++ ;
337
381
if (!* s )
338
382
break ;
@@ -425,7 +469,9 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
425
469
*/
426
470
cros_ec_lpc_ops .read = cros_ec_lpc_mec_read_bytes ;
427
471
cros_ec_lpc_ops .write = cros_ec_lpc_mec_write_bytes ;
428
- cros_ec_lpc_ops .read (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID , 2 , buf );
472
+ ret = cros_ec_lpc_ops .read (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID , 2 , buf );
473
+ if (ret < 0 )
474
+ return ret ;
429
475
if (buf [0 ] != 'E' || buf [1 ] != 'C' ) {
430
476
if (!devm_request_region (dev , ec_lpc -> mmio_memory_base , EC_MEMMAP_SIZE ,
431
477
dev_name (dev ))) {
@@ -436,8 +482,10 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
436
482
/* Re-assign read/write operations for the non MEC variant */
437
483
cros_ec_lpc_ops .read = cros_ec_lpc_read_bytes ;
438
484
cros_ec_lpc_ops .write = cros_ec_lpc_write_bytes ;
439
- cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + EC_MEMMAP_ID , 2 ,
440
- buf );
485
+ ret = cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + EC_MEMMAP_ID , 2 ,
486
+ buf );
487
+ if (ret < 0 )
488
+ return ret ;
441
489
if (buf [0 ] != 'E' || buf [1 ] != 'C' ) {
442
490
dev_err (dev , "EC ID not detected\n" );
443
491
return - ENODEV ;
0 commit comments