3434/* True if ACPI device is present */
3535static bool cros_ec_lpc_acpi_device_found ;
3636
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+
3745/**
3846 * struct lpc_driver_ops - LPC driver operations
3947 * @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,
290298static int cros_ec_lpc_readmem (struct cros_ec_device * ec , unsigned int offset ,
291299 unsigned int bytes , void * dest )
292300{
301+ struct cros_ec_lpc * ec_lpc = ec -> priv ;
293302 int i = offset ;
294303 char * s = dest ;
295304 int cnt = 0 ;
@@ -299,13 +308,13 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
299308
300309 /* fixed length */
301310 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 );
303312 return bytes ;
304313 }
305314
306315 /* string */
307316 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 );
309318 cnt ++ ;
310319 if (!* s )
311320 break ;
@@ -353,9 +362,16 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
353362 struct acpi_device * adev ;
354363 acpi_status status ;
355364 struct cros_ec_device * ec_dev ;
365+ struct cros_ec_lpc * ec_lpc ;
356366 u8 buf [2 ] = {};
357367 int irq , ret ;
358368
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+
359375 /*
360376 * The Framework Laptop (and possibly other non-ChromeOS devices)
361377 * 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)
380396 cros_ec_lpc_ops .write = cros_ec_lpc_mec_write_bytes ;
381397 cros_ec_lpc_ops .read (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID , 2 , buf );
382398 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 ,
384400 dev_name (dev ))) {
385401 dev_err (dev , "couldn't reserve memmap region\n" );
386402 return - EBUSY ;
@@ -389,7 +405,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
389405 /* Re-assign read/write operations for the non MEC variant */
390406 cros_ec_lpc_ops .read = cros_ec_lpc_read_bytes ;
391407 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 ,
393409 buf );
394410 if (buf [0 ] != 'E' || buf [1 ] != 'C' ) {
395411 dev_err (dev , "EC ID not detected\n" );
@@ -423,6 +439,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
423439 ec_dev -> din_size = sizeof (struct ec_host_response ) +
424440 sizeof (struct ec_response_get_protocol_info );
425441 ec_dev -> dout_size = sizeof (struct ec_host_request );
442+ ec_dev -> priv = ec_lpc ;
426443
427444 /*
428445 * Some boards do not have an IRQ allotted for cros_ec_lpc,
0 commit comments