Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v5.1-rc4 101 lines 2.0 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2// LPC interface for ChromeOS Embedded Controller 3// 4// Copyright (C) 2016 Google, Inc 5 6#include <linux/io.h> 7#include <linux/mfd/cros_ec.h> 8#include <linux/mfd/cros_ec_commands.h> 9 10#include "cros_ec_lpc_mec.h" 11 12static u8 lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest) 13{ 14 int i; 15 int sum = 0; 16 17 for (i = 0; i < length; ++i) { 18 dest[i] = inb(offset + i); 19 sum += dest[i]; 20 } 21 22 /* Return checksum of all bytes read */ 23 return sum; 24} 25 26static u8 lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg) 27{ 28 int i; 29 int sum = 0; 30 31 for (i = 0; i < length; ++i) { 32 outb(msg[i], offset + i); 33 sum += msg[i]; 34 } 35 36 /* Return checksum of all bytes written */ 37 return sum; 38} 39 40#ifdef CONFIG_CROS_EC_LPC_MEC 41 42u8 cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest) 43{ 44 int in_range = cros_ec_lpc_mec_in_range(offset, length); 45 46 if (in_range < 0) 47 return 0; 48 49 return in_range ? 50 cros_ec_lpc_io_bytes_mec(MEC_IO_READ, 51 offset - EC_HOST_CMD_REGION0, 52 length, dest) : 53 lpc_read_bytes(offset, length, dest); 54} 55 56u8 cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg) 57{ 58 int in_range = cros_ec_lpc_mec_in_range(offset, length); 59 60 if (in_range < 0) 61 return 0; 62 63 return in_range ? 64 cros_ec_lpc_io_bytes_mec(MEC_IO_WRITE, 65 offset - EC_HOST_CMD_REGION0, 66 length, msg) : 67 lpc_write_bytes(offset, length, msg); 68} 69 70void cros_ec_lpc_reg_init(void) 71{ 72 cros_ec_lpc_mec_init(EC_HOST_CMD_REGION0, 73 EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE); 74} 75 76void cros_ec_lpc_reg_destroy(void) 77{ 78 cros_ec_lpc_mec_destroy(); 79} 80 81#else /* CONFIG_CROS_EC_LPC_MEC */ 82 83u8 cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest) 84{ 85 return lpc_read_bytes(offset, length, dest); 86} 87 88u8 cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg) 89{ 90 return lpc_write_bytes(offset, length, msg); 91} 92 93void cros_ec_lpc_reg_init(void) 94{ 95} 96 97void cros_ec_lpc_reg_destroy(void) 98{ 99} 100 101#endif /* CONFIG_CROS_EC_LPC_MEC */