Linux 4.2.1
[linux/fpc-iii.git] / drivers / staging / nvec / nvec.h
blobe271375053faa01729e1a91f096a4491e148dba0
1 /*
2 * NVEC: NVIDIA compliant embedded controller interface
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
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>
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.
17 #ifndef __LINUX_MFD_NVEC
18 #define __LINUX_MFD_NVEC
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>
30 /* NVEC_POOL_SIZE - Size of the pool in &struct nvec_msg */
31 #define NVEC_POOL_SIZE 64
34 * NVEC_MSG_SIZE - Maximum size of the data field of &struct nvec_msg.
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.
40 #define NVEC_MSG_SIZE 34
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
50 * Events can be fixed or variable sized. This is useless on other message
51 * types, which are always variable sized.
53 enum nvec_event_size {
54 NVEC_2BYTES,
55 NVEC_3BYTES,
56 NVEC_VAR_SIZE,
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
69 * Events can be fixed or variable sized. This is useless on other message
70 * types, which are always variable sized.
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,
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.
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.
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;
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()
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;
153 struct nvec_msg *tx;
154 struct nvec_msg tx_scratch;
155 struct completion ec_transfer;
157 spinlock_t tx_lock, rx_lock;
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;
165 int state;
168 extern int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
169 short size);
171 extern struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
172 const unsigned char *data, short size);
174 extern int nvec_register_notifier(struct nvec_chip *nvec,
175 struct notifier_block *nb,
176 unsigned int events);
178 extern int nvec_unregister_notifier(struct nvec_chip *dev,
179 struct notifier_block *nb);
181 extern void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg);
183 #endif