drm/vkms: Move format arrays to vkms_plane.c
[linux-2.6-microblaze.git] / drivers / platform / chrome / cros_ec_lpc_reg.c
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
12 static 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
26 static 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
42 u8 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
56 u8 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
70 void 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
76 void cros_ec_lpc_reg_destroy(void)
77 {
78         cros_ec_lpc_mec_destroy();
79 }
80
81 #else /* CONFIG_CROS_EC_LPC_MEC */
82
83 u8 cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest)
84 {
85         return lpc_read_bytes(offset, length, dest);
86 }
87
88 u8 cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg)
89 {
90         return lpc_write_bytes(offset, length, msg);
91 }
92
93 void cros_ec_lpc_reg_init(void)
94 {
95 }
96
97 void cros_ec_lpc_reg_destroy(void)
98 {
99 }
100
101 #endif /* CONFIG_CROS_EC_LPC_MEC */