34
34
/* True if ACPI device is present */
35
35
static bool cros_ec_lpc_acpi_device_found ;
36
36
37
+ /**
38
+ * struct cros_ec_lpc - LPC device-specific data
39
+ * @mmio_memory_base: The first I/O port addressing EC mapped memory.
40
+ */
41
+ struct cros_ec_lpc {
42
+ u16 mmio_memory_base ;
43
+ };
44
+
37
45
/**
38
46
* struct lpc_driver_ops - LPC driver operations
39
47
* @read: Copy length bytes from EC address offset into buffer dest. Returns
@@ -290,6 +298,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
290
298
static int cros_ec_lpc_readmem (struct cros_ec_device * ec , unsigned int offset ,
291
299
unsigned int bytes , void * dest )
292
300
{
301
+ struct cros_ec_lpc * ec_lpc = ec -> priv ;
293
302
int i = offset ;
294
303
char * s = dest ;
295
304
int cnt = 0 ;
@@ -299,13 +308,13 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
299
308
300
309
/* fixed length */
301
310
if (bytes ) {
302
- cros_ec_lpc_ops .read (EC_LPC_ADDR_MEMMAP + offset , bytes , s );
311
+ cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + offset , bytes , s );
303
312
return bytes ;
304
313
}
305
314
306
315
/* string */
307
316
for (; i < EC_MEMMAP_SIZE ; i ++ , s ++ ) {
308
- cros_ec_lpc_ops .read (EC_LPC_ADDR_MEMMAP + i , 1 , s );
317
+ cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + i , 1 , s );
309
318
cnt ++ ;
310
319
if (!* s )
311
320
break ;
@@ -353,9 +362,16 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
353
362
struct acpi_device * adev ;
354
363
acpi_status status ;
355
364
struct cros_ec_device * ec_dev ;
365
+ struct cros_ec_lpc * ec_lpc ;
356
366
u8 buf [2 ] = {};
357
367
int irq , ret ;
358
368
369
+ ec_lpc = devm_kzalloc (dev , sizeof (* ec_lpc ), GFP_KERNEL );
370
+ if (!ec_lpc )
371
+ return - ENOMEM ;
372
+
373
+ ec_lpc -> mmio_memory_base = EC_LPC_ADDR_MEMMAP ;
374
+
359
375
/*
360
376
* The Framework Laptop (and possibly other non-ChromeOS devices)
361
377
* only exposes the eight I/O ports that are required for the Microchip EC.
@@ -380,7 +396,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
380
396
cros_ec_lpc_ops .write = cros_ec_lpc_mec_write_bytes ;
381
397
cros_ec_lpc_ops .read (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID , 2 , buf );
382
398
if (buf [0 ] != 'E' || buf [1 ] != 'C' ) {
383
- if (!devm_request_region (dev , EC_LPC_ADDR_MEMMAP , EC_MEMMAP_SIZE ,
399
+ if (!devm_request_region (dev , ec_lpc -> mmio_memory_base , EC_MEMMAP_SIZE ,
384
400
dev_name (dev ))) {
385
401
dev_err (dev , "couldn't reserve memmap region\n" );
386
402
return - EBUSY ;
@@ -389,7 +405,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
389
405
/* Re-assign read/write operations for the non MEC variant */
390
406
cros_ec_lpc_ops .read = cros_ec_lpc_read_bytes ;
391
407
cros_ec_lpc_ops .write = cros_ec_lpc_write_bytes ;
392
- cros_ec_lpc_ops .read (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID , 2 ,
408
+ cros_ec_lpc_ops .read (ec_lpc -> mmio_memory_base + EC_MEMMAP_ID , 2 ,
393
409
buf );
394
410
if (buf [0 ] != 'E' || buf [1 ] != 'C' ) {
395
411
dev_err (dev , "EC ID not detected\n" );
@@ -423,6 +439,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
423
439
ec_dev -> din_size = sizeof (struct ec_host_response ) +
424
440
sizeof (struct ec_response_get_protocol_info );
425
441
ec_dev -> dout_size = sizeof (struct ec_host_request );
442
+ ec_dev -> priv = ec_lpc ;
426
443
427
444
/*
428
445
* Some boards do not have an IRQ allotted for cros_ec_lpc,
0 commit comments