ppp: mppe: Revert "ppp: mppe: Add softdep to arc4"
[linux-2.6-block.git] / drivers / platform / chrome / cros_ec_lpc_reg.c
CommitLineData
1058ca94
EBS
1// SPDX-License-Identifier: GPL-2.0
2// LPC interface for ChromeOS Embedded Controller
3//
4// Copyright (C) 2016 Google, Inc
bce70fef
SN
5
6#include <linux/io.h>
7#include <linux/mfd/cros_ec.h>
8#include <linux/mfd/cros_ec_commands.h>
cc8a4ea1
EBS
9
10#include "cros_ec_lpc_mec.h"
bce70fef
SN
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
8d4a3dc4
SN
40#ifdef CONFIG_CROS_EC_LPC_MEC
41
bce70fef
SN
42u8 cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest)
43{
6b7cb222 44 int in_range = cros_ec_lpc_mec_in_range(offset, length);
8d4a3dc4 45
6b7cb222 46 if (in_range < 0)
8d4a3dc4
SN
47 return 0;
48
6b7cb222
NC
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);
bce70fef
SN
54}
55
56u8 cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg)
57{
6b7cb222 58 int in_range = cros_ec_lpc_mec_in_range(offset, length);
8d4a3dc4 59
6b7cb222 60 if (in_range < 0)
8d4a3dc4
SN
61 return 0;
62
6b7cb222
NC
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);
bce70fef 68}
8d4a3dc4
SN
69
70void cros_ec_lpc_reg_init(void)
71{
6b7cb222
NC
72 cros_ec_lpc_mec_init(EC_HOST_CMD_REGION0,
73 EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE);
8d4a3dc4
SN
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 */