mfd: cros_ec: cleanup: Remove EC wrapper functions
[deliverable/linux.git] / include / linux / mfd / cros_ec.h
CommitLineData
4ab6174e
SG
1/*
2 * ChromeOS EC multi-function device
3 *
4 * Copyright (C) 2012 Google, Inc
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef __LINUX_MFD_CROS_EC_H
17#define __LINUX_MFD_CROS_EC_H
18
7e6cb5b4 19#include <linux/notifier.h>
4ab6174e 20#include <linux/mfd/cros_ec_commands.h>
7e6cb5b4 21#include <linux/mutex.h>
4ab6174e
SG
22
23/*
24 * Command interface between EC and AP, for LPC, I2C and SPI interfaces.
25 */
26enum {
27 EC_MSG_TX_HEADER_BYTES = 3,
28 EC_MSG_TX_TRAILER_BYTES = 1,
29 EC_MSG_TX_PROTO_BYTES = EC_MSG_TX_HEADER_BYTES +
30 EC_MSG_TX_TRAILER_BYTES,
31 EC_MSG_RX_PROTO_BYTES = 3,
32
33 /* Max length of messages */
5271db29
BR
34 EC_MSG_BYTES = EC_PROTO2_MAX_PARAM_SIZE +
35 EC_MSG_TX_PROTO_BYTES,
4ab6174e
SG
36};
37
5d4773e2 38/*
4ab6174e 39 * @version: Command version number (often 0)
5d4773e2
BR
40 * @command: Command to send (EC_CMD_...)
41 * @outdata: Outgoing data to EC
42 * @outsize: Outgoing length in bytes
43 * @indata: Where to put the incoming data from EC
44 * @insize: Incoming length in bytes (filled in by EC)
45 * @result: EC's response to the command (separate from communication failure)
4ab6174e 46 */
5d4773e2
BR
47struct cros_ec_command {
48 uint32_t version;
49 uint32_t command;
50 uint8_t *outdata;
51 uint32_t outsize;
52 uint8_t *indata;
53 uint32_t insize;
54 uint32_t result;
4ab6174e
SG
55};
56
57/**
58 * struct cros_ec_device - Information about a ChromeOS EC device
59 *
7e6cb5b4
BR
60 * @ec_name: name of EC device (e.g. 'chromeos-ec')
61 * @phys_name: name of physical comms layer (e.g. 'i2c-4')
62 * @dev: Device pointer
63 * @was_wake_device: true if this device was set to wake the system from
64 * sleep at the last suspend
65 * @event_notifier: interrupt event notifier for transport devices
5799f95a
BR
66 * @cmd_xfer: send command to EC and get response
67 * Returns 0 if the communication succeeded, but that doesn't mean the EC
68 * was happy with the command it got. Caller should check msg.result for
69 * the EC's result code.
7e6cb5b4 70 *
4ab6174e
SG
71 * @priv: Private data
72 * @irq: Interrupt to use
7e6cb5b4
BR
73 * @din: input buffer (for data from EC)
74 * @dout: output buffer (for data to EC)
4ab6174e
SG
75 * \note
76 * These two buffers will always be dword-aligned and include enough
77 * space for up to 7 word-alignment bytes also, so we can ensure that
78 * the body of the message is always dword-aligned (64-bit).
4ab6174e
SG
79 * We use this alignment to keep ARM and x86 happy. Probably word
80 * alignment would be OK, there might be a small performance advantage
81 * to using dword.
2ce701ae
BR
82 * @din_size: size of din buffer to allocate (zero to use static din)
83 * @dout_size: size of dout buffer to allocate (zero to use static dout)
4ab6174e 84 * @parent: pointer to parent device (e.g. i2c or spi device)
4ab6174e 85 * @wake_enabled: true if this device can wake the system from sleep
7e6cb5b4 86 * @lock: one transaction at a time
4ab6174e
SG
87 */
88struct cros_ec_device {
7e6cb5b4
BR
89
90 /* These are used by other drivers that want to talk to the EC */
91 const char *ec_name;
92 const char *phys_name;
93 struct device *dev;
94 bool was_wake_device;
95 struct class *cros_class;
96 struct blocking_notifier_head event_notifier;
5799f95a
BR
97 int (*cmd_xfer)(struct cros_ec_device *ec,
98 struct cros_ec_command *msg);
7e6cb5b4
BR
99
100 /* These are used to implement the platform-specific interface */
4ab6174e
SG
101 void *priv;
102 int irq;
103 uint8_t *din;
104 uint8_t *dout;
105 int din_size;
106 int dout_size;
4ab6174e 107 struct device *parent;
4ab6174e 108 bool wake_enabled;
7e6cb5b4 109 struct mutex lock;
4ab6174e
SG
110};
111
112/**
113 * cros_ec_suspend - Handle a suspend operation for the ChromeOS EC device
114 *
115 * This can be called by drivers to handle a suspend event.
116 *
117 * ec_dev: Device to suspend
118 * @return 0 if ok, -ve on error
119 */
120int cros_ec_suspend(struct cros_ec_device *ec_dev);
121
122/**
123 * cros_ec_resume - Handle a resume operation for the ChromeOS EC device
124 *
125 * This can be called by drivers to handle a resume event.
126 *
127 * @ec_dev: Device to resume
128 * @return 0 if ok, -ve on error
129 */
130int cros_ec_resume(struct cros_ec_device *ec_dev);
131
132/**
133 * cros_ec_prepare_tx - Prepare an outgoing message in the output buffer
134 *
135 * This is intended to be used by all ChromeOS EC drivers, but at present
136 * only SPI uses it. Once LPC uses the same protocol it can start using it.
137 * I2C could use it now, with a refactor of the existing code.
138 *
139 * @ec_dev: Device to register
140 * @msg: Message to write
141 */
142int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
5d4773e2 143 struct cros_ec_command *msg);
4ab6174e
SG
144
145/**
146 * cros_ec_remove - Remove a ChromeOS EC
147 *
ee98662e 148 * Call this to deregister a ChromeOS EC, then clean up any private data.
4ab6174e
SG
149 *
150 * @ec_dev: Device to register
151 * @return 0 if ok, -ve on error
152 */
153int cros_ec_remove(struct cros_ec_device *ec_dev);
154
155/**
156 * cros_ec_register - Register a new ChromeOS EC, using the provided info
157 *
158 * Before calling this, allocate a pointer to a new device and then fill
159 * in all the fields up to the --private-- marker.
160 *
161 * @ec_dev: Device to register
162 * @return 0 if ok, -ve on error
163 */
164int cros_ec_register(struct cros_ec_device *ec_dev);
165
166#endif /* __LINUX_MFD_CROS_EC_H */
This page took 0.170061 seconds and 5 git commands to generate.