@@ -70,32 +70,26 @@ struct lpc_driver_data {
70
70
/**
71
71
* struct cros_ec_lpc - LPC device-specific data
72
72
* @mmio_memory_base: The first I/O port addressing EC mapped memory.
73
- */
74
- struct cros_ec_lpc {
75
- u16 mmio_memory_base ;
76
- };
77
-
78
- /**
79
- * struct lpc_driver_ops - LPC driver operations
80
73
* @read: Copy length bytes from EC address offset into buffer dest.
81
74
* Returns a negative error code on error, or the 8-bit checksum
82
75
* of all bytes read.
83
76
* @write: Copy length bytes from buffer msg into EC address offset.
84
77
* Returns a negative error code on error, or the 8-bit checksum
85
78
* of all bytes written.
86
79
*/
87
- struct lpc_driver_ops {
88
- int (* read )(unsigned int offset , unsigned int length , u8 * dest );
89
- int (* write )(unsigned int offset , unsigned int length , const u8 * msg );
80
+ struct cros_ec_lpc {
81
+ u16 mmio_memory_base ;
82
+ int (* read )(struct cros_ec_lpc * ec_lpc , unsigned int offset ,
83
+ unsigned int length , u8 * dest );
84
+ int (* write )(struct cros_ec_lpc * ec_lpc , unsigned int offset ,
85
+ unsigned int length , const u8 * msg );
90
86
};
91
87
92
- static struct lpc_driver_ops cros_ec_lpc_ops = { };
93
-
94
88
/*
95
89
* A generic instance of the read function of struct lpc_driver_ops, used for
96
90
* the LPC EC.
97
91
*/
98
- static int cros_ec_lpc_read_bytes (unsigned int offset , unsigned int length ,
92
+ static int cros_ec_lpc_read_bytes (struct cros_ec_lpc * _ , unsigned int offset , unsigned int length ,
99
93
u8 * dest )
100
94
{
101
95
u8 sum = 0 ;
@@ -114,7 +108,7 @@ static int cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length,
114
108
* A generic instance of the write function of struct lpc_driver_ops, used for
115
109
* the LPC EC.
116
110
*/
117
- static int cros_ec_lpc_write_bytes (unsigned int offset , unsigned int length ,
111
+ static int cros_ec_lpc_write_bytes (struct cros_ec_lpc * _ , unsigned int offset , unsigned int length ,
118
112
const u8 * msg )
119
113
{
120
114
u8 sum = 0 ;
@@ -133,8 +127,8 @@ static int cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length,
133
127
* An instance of the read function of struct lpc_driver_ops, used for the
134
128
* MEC variant of LPC EC.
135
129
*/
136
- static int cros_ec_lpc_mec_read_bytes (unsigned int offset , unsigned int length ,
137
- u8 * dest )
130
+ static int cros_ec_lpc_mec_read_bytes (struct cros_ec_lpc * ec_lpc , unsigned int offset ,
131
+ unsigned int length , u8 * dest )
138
132
{
139
133
int in_range = cros_ec_lpc_mec_in_range (offset , length );
140
134
@@ -145,15 +139,15 @@ static int cros_ec_lpc_mec_read_bytes(unsigned int offset, unsigned int length,
145
139
cros_ec_lpc_io_bytes_mec (MEC_IO_READ ,
146
140
offset - EC_HOST_CMD_REGION0 ,
147
141
length , dest ) :
148
- cros_ec_lpc_read_bytes (offset , length , dest );
142
+ cros_ec_lpc_read_bytes (ec_lpc , offset , length , dest );
149
143
}
150
144
151
145
/*
152
146
* An instance of the write function of struct lpc_driver_ops, used for the
153
147
* MEC variant of LPC EC.
154
148
*/
155
- static int cros_ec_lpc_mec_write_bytes (unsigned int offset , unsigned int length ,
156
- const u8 * msg )
149
+ static int cros_ec_lpc_mec_write_bytes (struct cros_ec_lpc * ec_lpc , unsigned int offset ,
150
+ unsigned int length , const u8 * msg )
157
151
{
158
152
int in_range = cros_ec_lpc_mec_in_range (offset , length );
159
153
@@ -164,18 +158,19 @@ static int cros_ec_lpc_mec_write_bytes(unsigned int offset, unsigned int length,
164
158
cros_ec_lpc_io_bytes_mec (MEC_IO_WRITE ,
165
159
offset - EC_HOST_CMD_REGION0 ,
166
160
length , (u8 * )msg ) :
167
- cros_ec_lpc_write_bytes (offset , length , msg );
161
+ cros_ec_lpc_write_bytes (ec_lpc , offset , length , msg );
162
+ }
168
163
}
169
164
170
- static int ec_response_timed_out (void )
165
+ static int ec_response_timed_out (struct cros_ec_lpc * ec_lpc )
171
166
{
172
167
unsigned long one_second = jiffies + HZ ;
173
168
u8 data ;
174
169
int ret ;
175
170
176
171
usleep_range (200 , 300 );
177
172
do {
178
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_HOST_CMD , 1 , & data );
173
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_HOST_CMD , 1 , & data );
179
174
if (ret < 0 )
180
175
return ret ;
181
176
if (!(data & EC_LPC_STATUS_BUSY_MASK ))
@@ -189,6 +184,7 @@ static int ec_response_timed_out(void)
189
184
static int cros_ec_pkt_xfer_lpc (struct cros_ec_device * ec ,
190
185
struct cros_ec_command * msg )
191
186
{
187
+ struct cros_ec_lpc * ec_lpc = ec -> priv ;
192
188
struct ec_host_response response ;
193
189
u8 sum ;
194
190
int ret = 0 ;
@@ -199,17 +195,17 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
199
195
goto done ;
200
196
201
197
/* Write buffer */
202
- ret = cros_ec_lpc_ops . write (EC_LPC_ADDR_HOST_PACKET , ret , ec -> dout );
198
+ ret = ec_lpc -> write (ec_lpc , EC_LPC_ADDR_HOST_PACKET , ret , ec -> dout );
203
199
if (ret < 0 )
204
200
goto done ;
205
201
206
202
/* Here we go */
207
203
sum = EC_COMMAND_PROTOCOL_3 ;
208
- ret = cros_ec_lpc_ops . write (EC_LPC_ADDR_HOST_CMD , 1 , & sum );
204
+ ret = ec_lpc -> write (ec_lpc , EC_LPC_ADDR_HOST_CMD , 1 , & sum );
209
205
if (ret < 0 )
210
206
goto done ;
211
207
212
- ret = ec_response_timed_out ();
208
+ ret = ec_response_timed_out (ec_lpc );
213
209
if (ret < 0 )
214
210
goto done ;
215
211
if (ret ) {
@@ -219,7 +215,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
219
215
}
220
216
221
217
/* Check result */
222
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_HOST_DATA , 1 , & sum );
218
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_HOST_DATA , 1 , & sum );
223
219
if (ret < 0 )
224
220
goto done ;
225
221
msg -> result = ret ;
@@ -229,7 +225,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
229
225
230
226
/* Read back response */
231
227
dout = (u8 * )& response ;
232
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_HOST_PACKET , sizeof (response ),
228
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_HOST_PACKET , sizeof (response ),
233
229
dout );
234
230
if (ret < 0 )
235
231
goto done ;
@@ -246,7 +242,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
246
242
}
247
243
248
244
/* Read response and process checksum */
249
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_HOST_PACKET +
245
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_HOST_PACKET +
250
246
sizeof (response ), response .data_len ,
251
247
msg -> data );
252
248
if (ret < 0 )
@@ -270,6 +266,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
270
266
static int cros_ec_cmd_xfer_lpc (struct cros_ec_device * ec ,
271
267
struct cros_ec_command * msg )
272
268
{
269
+ struct cros_ec_lpc * ec_lpc = ec -> priv ;
273
270
struct ec_lpc_host_args args ;
274
271
u8 sum ;
275
272
int ret = 0 ;
@@ -291,26 +288,26 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
291
288
sum = msg -> command + args .flags + args .command_version + args .data_size ;
292
289
293
290
/* Copy data and update checksum */
294
- ret = cros_ec_lpc_ops . write (EC_LPC_ADDR_HOST_PARAM , msg -> outsize ,
291
+ ret = ec_lpc -> write (ec_lpc , EC_LPC_ADDR_HOST_PARAM , msg -> outsize ,
295
292
msg -> data );
296
293
if (ret < 0 )
297
294
goto done ;
298
295
sum += ret ;
299
296
300
297
/* Finalize checksum and write args */
301
298
args .checksum = sum ;
302
- ret = cros_ec_lpc_ops . write (EC_LPC_ADDR_HOST_ARGS , sizeof (args ),
299
+ ret = ec_lpc -> write (ec_lpc , EC_LPC_ADDR_HOST_ARGS , sizeof (args ),
303
300
(u8 * )& args );
304
301
if (ret < 0 )
305
302
goto done ;
306
303
307
304
/* Here we go */
308
305
sum = msg -> command ;
309
- ret = cros_ec_lpc_ops . write (EC_LPC_ADDR_HOST_CMD , 1 , & sum );
306
+ ret = ec_lpc -> write (ec_lpc , EC_LPC_ADDR_HOST_CMD , 1 , & sum );
310
307
if (ret < 0 )
311
308
goto done ;
312
309
313
- ret = ec_response_timed_out ();
310
+ ret = ec_response_timed_out (ec_lpc );
314
311
if (ret < 0 )
315
312
goto done ;
316
313
if (ret ) {
@@ -320,7 +317,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
320
317
}
321
318
322
319
/* Check result */
323
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_HOST_DATA , 1 , & sum );
320
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_HOST_DATA , 1 , & sum );
324
321
if (ret < 0 )
325
322
goto done ;
326
323
msg -> result = ret ;
@@ -329,7 +326,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
329
326
goto done ;
330
327
331
328
/* Read back args */
332
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_HOST_ARGS , sizeof (args ), (u8 * )& args );
329
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_HOST_ARGS , sizeof (args ), (u8 * )& args );
333
330
if (ret < 0 )
334
331
goto done ;
335
332
@@ -345,7 +342,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
345
342
sum = msg -> command + args .flags + args .command_version + args .data_size ;
346
343
347
344
/* Read response and update checksum */
348
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_HOST_PARAM , args .data_size ,
345
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_HOST_PARAM , args .data_size ,
349
346
msg -> data );
350
347
if (ret < 0 )
351
348
goto done ;
@@ -381,15 +378,15 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
381
378
382
379
/* fixed length */
383
380
if (bytes ) {
384
- ret = cros_ec_lpc_ops . read (ec_lpc -> mmio_memory_base + offset , bytes , s );
381
+ ret = ec_lpc -> read (ec_lpc , ec_lpc -> mmio_memory_base + offset , bytes , s );
385
382
if (ret < 0 )
386
383
return ret ;
387
384
return bytes ;
388
385
}
389
386
390
387
/* string */
391
388
for (; i < EC_MEMMAP_SIZE ; i ++ , s ++ ) {
392
- ret = cros_ec_lpc_ops . read (ec_lpc -> mmio_memory_base + i , 1 , s );
389
+ ret = ec_lpc -> read (ec_lpc , ec_lpc -> mmio_memory_base + i , 1 , s );
393
390
if (ret < 0 )
394
391
return ret ;
395
392
cnt ++ ;
@@ -492,8 +489,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
492
489
}
493
490
494
491
if (quirks & CROS_EC_LPC_QUIRK_AML_MUTEX ) {
495
- const char * name
496
- = driver_data -> quirk_aml_mutex_name ;
492
+ const char * name = driver_data -> quirk_aml_mutex_name ;
497
493
ret = cros_ec_lpc_mec_acpi_mutex (ACPI_COMPANION (dev ), name );
498
494
if (ret ) {
499
495
dev_err (dev , "failed to get AML mutex '%s'" , name );
@@ -523,9 +519,9 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
523
519
* protocol fails, fallback to the non MEC variant and try to
524
520
* read again the ID.
525
521
*/
526
- cros_ec_lpc_ops . read = cros_ec_lpc_mec_read_bytes ;
527
- cros_ec_lpc_ops . write = cros_ec_lpc_mec_write_bytes ;
528
- ret = cros_ec_lpc_ops . read (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID , 2 , buf );
522
+ ec_lpc -> read = cros_ec_lpc_mec_read_bytes ;
523
+ ec_lpc -> write = cros_ec_lpc_mec_write_bytes ;
524
+ ret = ec_lpc -> read (ec_lpc , EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID , 2 , buf );
529
525
if (ret < 0 )
530
526
return ret ;
531
527
if (buf [0 ] != 'E' || buf [1 ] != 'C' ) {
@@ -536,9 +532,9 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
536
532
}
537
533
538
534
/* Re-assign read/write operations for the non MEC variant */
539
- cros_ec_lpc_ops . read = cros_ec_lpc_read_bytes ;
540
- cros_ec_lpc_ops . write = cros_ec_lpc_write_bytes ;
541
- ret = cros_ec_lpc_ops . read (ec_lpc -> mmio_memory_base + EC_MEMMAP_ID , 2 ,
535
+ ec_lpc -> read = cros_ec_lpc_read_bytes ;
536
+ ec_lpc -> write = cros_ec_lpc_write_bytes ;
537
+ ret = ec_lpc -> read (ec_lpc , ec_lpc -> mmio_memory_base + EC_MEMMAP_ID , 2 ,
542
538
buf );
543
539
if (ret < 0 )
544
540
return ret ;
0 commit comments