Merge tag 'xfs-for-linus-4.5-2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / staging / nvec / nvec.h
1 /*
2 * NVEC: NVIDIA compliant embedded controller interface
3 *
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
5 *
6 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
7 * Ilya Petrov <ilya.muromec@gmail.com>
8 * Marc Dietrich <marvin24@gmx.de>
9 * Julian Andres Klode <jak@jak-linux.org>
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 *
15 */
16
17 #ifndef __LINUX_MFD_NVEC
18 #define __LINUX_MFD_NVEC
19
20 #include <linux/atomic.h>
21 #include <linux/clk.h>
22 #include <linux/completion.h>
23 #include <linux/list.h>
24 #include <linux/mutex.h>
25 #include <linux/notifier.h>
26 #include <linux/reset.h>
27 #include <linux/spinlock.h>
28 #include <linux/workqueue.h>
29
30 /* NVEC_POOL_SIZE - Size of the pool in &struct nvec_msg */
31 #define NVEC_POOL_SIZE 64
32
33 /*
34 * NVEC_MSG_SIZE - Maximum size of the data field of &struct nvec_msg.
35 *
36 * A message must store up to a SMBus block operation which consists of
37 * one command byte, one count byte, and up to 32 payload bytes = 34
38 * byte.
39 */
40 #define NVEC_MSG_SIZE 34
41
42 /**
43 * enum nvec_event_size - The size of an event message
44 * @NVEC_2BYTES: The message has one command byte and one data byte
45 * @NVEC_3BYTES: The message has one command byte and two data bytes
46 * @NVEC_VAR_SIZE: The message has one command byte, one count byte, and has
47 * up to as many bytes as the number in the count byte. The
48 * maximum is 32
49 *
50 * Events can be fixed or variable sized. This is useless on other message
51 * types, which are always variable sized.
52 */
53 enum nvec_event_size {
54 NVEC_2BYTES,
55 NVEC_3BYTES,
56 NVEC_VAR_SIZE,
57 };
58
59 /**
60 * enum nvec_msg_type - The type of a message
61 * @NVEC_SYS: A system request/response
62 * @NVEC_BAT: A battery request/response
63 * @NVEC_KBD: A keyboard request/response
64 * @NVEC_PS2: A mouse request/response
65 * @NVEC_CNTL: A EC control request/response
66 * @NVEC_KB_EVT: An event from the keyboard
67 * @NVEC_PS2_EVT: An event from the mouse
68 *
69 * Events can be fixed or variable sized. This is useless on other message
70 * types, which are always variable sized.
71 */
72 enum nvec_msg_type {
73 NVEC_SYS = 1,
74 NVEC_BAT,
75 NVEC_GPIO,
76 NVEC_SLEEP,
77 NVEC_KBD,
78 NVEC_PS2,
79 NVEC_CNTL,
80 NVEC_OEM0 = 0x0d,
81 NVEC_KB_EVT = 0x80,
82 NVEC_PS2_EVT,
83 };
84
85 /**
86 * struct nvec_msg - A buffer for a single message
87 * @node: Messages are part of various lists in a &struct nvec_chip
88 * @data: The data of the message
89 * @size: For TX messages, the number of bytes used in @data
90 * @pos: For RX messages, the current position to write to. For TX messages,
91 * the position to read from.
92 * @used: Used for the message pool to mark a message as free/allocated.
93 *
94 * This structure is used to hold outgoing and incoming messages. Outgoing
95 * messages have a different format than incoming messages, and that is not
96 * documented yet.
97 */
98 struct nvec_msg {
99 struct list_head node;
100 unsigned char data[NVEC_MSG_SIZE];
101 unsigned short size;
102 unsigned short pos;
103 atomic_t used;
104 };
105
106 /**
107 * struct nvec_chip - A single connection to an NVIDIA Embedded controller
108 * @dev: The device
109 * @gpio: The same as for &struct nvec_platform_data
110 * @irq: The IRQ of the I2C device
111 * @i2c_addr: The address of the I2C slave
112 * @base: The base of the memory mapped region of the I2C device
113 * @i2c_clk: The clock of the I2C device
114 * @rst: The reset of the I2C device
115 * @notifier_list: Notifiers to be called on received messages, see
116 * nvec_register_notifier()
117 * @rx_data: Received messages that have to be processed
118 * @tx_data: Messages waiting to be sent to the controller
119 * @nvec_status_notifier: Internal notifier (see nvec_status_notifier())
120 * @rx_work: A work structure for the RX worker nvec_dispatch()
121 * @tx_work: A work structure for the TX worker nvec_request_master()
122 * @wq: The work queue in which @rx_work and @tx_work are executed
123 * @rx: The message currently being retrieved or %NULL
124 * @msg_pool: A pool of messages for allocation
125 * @tx: The message currently being transferred
126 * @tx_scratch: Used for building pseudo messages
127 * @ec_transfer: A completion that will be completed once a message has been
128 * received (see nvec_rx_completed())
129 * @tx_lock: Spinlock for modifications on @tx_data
130 * @rx_lock: Spinlock for modifications on @rx_data
131 * @sync_write_mutex: A mutex for nvec_write_sync()
132 * @sync_write: A completion to signal that a synchronous message is complete
133 * @sync_write_pending: The first two bytes of the request (type and subtype)
134 * @last_sync_msg: The last synchronous message.
135 * @state: State of our finite state machine used in nvec_interrupt()
136 */
137 struct nvec_chip {
138 struct device *dev;
139 int gpio;
140 int irq;
141 int i2c_addr;
142 void __iomem *base;
143 struct clk *i2c_clk;
144 struct reset_control *rst;
145 struct atomic_notifier_head notifier_list;
146 struct list_head rx_data, tx_data;
147 struct notifier_block nvec_status_notifier;
148 struct work_struct rx_work, tx_work;
149 struct workqueue_struct *wq;
150 struct nvec_msg msg_pool[NVEC_POOL_SIZE];
151 struct nvec_msg *rx;
152
153 struct nvec_msg *tx;
154 struct nvec_msg tx_scratch;
155 struct completion ec_transfer;
156
157 spinlock_t tx_lock, rx_lock;
158
159 /* sync write stuff */
160 struct mutex sync_write_mutex;
161 struct completion sync_write;
162 u16 sync_write_pending;
163 struct nvec_msg *last_sync_msg;
164
165 int state;
166 };
167
168 int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
169 short size);
170
171 struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
172 const unsigned char *data, short size);
173
174 int nvec_register_notifier(struct nvec_chip *nvec,
175 struct notifier_block *nb,
176 unsigned int events);
177
178 int nvec_unregister_notifier(struct nvec_chip *dev, struct notifier_block *nb);
179
180 void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg);
181
182 #endif
This page took 0.148465 seconds and 5 git commands to generate.