]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/nvec/nvec.h
Staging: bcm: Fix double free of 'pReadData' in IOCTL_BCM_NVM_WRITE.
[mirror_ubuntu-artful-kernel.git] / drivers / staging / nvec / nvec.h
CommitLineData
162c7d8c
MD
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>
bdf034d9 9 * Julian Andres Klode <jak@jak-linux.org>
162c7d8c
MD
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
32890b98
MD
17#ifndef __LINUX_MFD_NVEC
18#define __LINUX_MFD_NVEC
19
0b1076c4 20#include <linux/atomic.h>
12b5a55d
JAK
21#include <linux/clk.h>
22#include <linux/completion.h>
23#include <linux/list.h>
24#include <linux/mutex.h>
7974035c 25#include <linux/notifier.h>
12b5a55d
JAK
26#include <linux/spinlock.h>
27#include <linux/workqueue.h>
32890b98 28
0b1076c4
JAK
29/* NVEC_POOL_SIZE - Size of the pool in &struct nvec_msg */
30#define NVEC_POOL_SIZE 64
31
0cab4cb8
JAK
32/*
33 * NVEC_MSG_SIZE - Maximum size of the data field of &struct nvec_msg.
34 *
35 * A message must store up to a SMBus block operation which consists of
36 * one command byte, one count byte, and up to 32 payload bytes = 34
37 * byte.
38 */
39#define NVEC_MSG_SIZE 34
40
bdf034d9
JAK
41/**
42 * enum nvec_event_size - The size of an event message
43 * @NVEC_2BYTES: The message has one command byte and one data byte
44 * @NVEC_3BYTES: The message has one command byte and two data bytes
45 * @NVEC_VAR_SIZE: The message has one command byte, one count byte, and as
46 * up to as many bytes as the number in the count byte. The
47 * maximum is 32
48 *
49 * Events can be fixed or variable sized. This is useless on other message
50 * types, which are always variable sized.
51 */
52enum nvec_event_size {
32890b98
MD
53 NVEC_2BYTES,
54 NVEC_3BYTES,
0cab4cb8
JAK
55 NVEC_VAR_SIZE,
56};
32890b98 57
bdf034d9
JAK
58/**
59 * enum nvec_msg_type - The type of a message
60 * @NVEC_SYS: A system request/response
61 * @NVEC_BAT: A battery request/response
62 * @NVEC_KBD: A keyboard request/response
63 * @NVEC_PS2: A mouse request/response
64 * @NVEC_CNTL: A EC control request/response
65 * @NVEC_KB_EVT: An event from the keyboard
66 * @NVEC_PS2_EVT: An event from the mouse
67 *
68 * Events can be fixed or variable sized. This is useless on other message
69 * types, which are always variable sized.
70 */
71enum nvec_msg_type {
162c7d8c 72 NVEC_SYS = 1,
32890b98
MD
73 NVEC_BAT,
74 NVEC_KBD = 5,
75 NVEC_PS2,
76 NVEC_CNTL,
77 NVEC_KB_EVT = 0x80,
0cab4cb8
JAK
78 NVEC_PS2_EVT,
79};
32890b98 80
bdf034d9
JAK
81/**
82 * struct nvec_msg - A buffer for a single message
83 * @node: Messages are part of various lists in a &struct nvec_chip
84 * @data: The data of the message
85 * @size: For TX messages, the number of bytes used in @data
86 * @pos: For RX messages, the current position to write to. For TX messages,
87 * the position to read from.
88 * @used: Used for the message pool to mark a message as free/allocated.
89 *
90 * This structure is used to hold outgoing and incoming messages. Outgoing
91 * messages have a different format than incoming messages, and that is not
92 * documented yet.
93 */
32890b98 94struct nvec_msg {
0cab4cb8
JAK
95 struct list_head node;
96 unsigned char data[NVEC_MSG_SIZE];
32890b98
MD
97 unsigned short size;
98 unsigned short pos;
0b1076c4 99 atomic_t used;
32890b98
MD
100};
101
bdf034d9
JAK
102/**
103 * struct nvec_subdev - A subdevice of nvec, such as nvec_kbd
104 * @name: The name of the sub device
105 * @platform_data: Platform data
106 * @id: Identifier of the sub device
107 */
32890b98
MD
108struct nvec_subdev {
109 const char *name;
110 void *platform_data;
111 int id;
112};
113
bdf034d9
JAK
114/**
115 * struct nvec_platform_data - platform data for a tegra slave controller
116 * @i2c_addr: number of i2c slave adapter the ec is connected to
117 * @gpio: gpio number for the ec request line
118 *
119 * Platform data, to be used in board definitions. For an example, take a
120 * look at the paz00 board in arch/arm/mach-tegra/board-paz00.c
121 */
32890b98 122struct nvec_platform_data {
32890b98
MD
123 int i2c_addr;
124 int gpio;
32890b98
MD
125};
126
bdf034d9
JAK
127/**
128 * struct nvec_chip - A single connection to an NVIDIA Embedded controller
129 * @dev: The device
130 * @gpio: The same as for &struct nvec_platform_data
131 * @irq: The IRQ of the I2C device
132 * @i2c_addr: The address of the I2C slave
133 * @base: The base of the memory mapped region of the I2C device
134 * @clk: The clock of the I2C device
135 * @notifier_list: Notifiers to be called on received messages, see
136 * nvec_register_notifier()
137 * @rx_data: Received messages that have to be processed
138 * @tx_data: Messages waiting to be sent to the controller
139 * @nvec_status_notifier: Internal notifier (see nvec_status_notifier())
140 * @rx_work: A work structure for the RX worker nvec_dispatch()
141 * @tx_work: A work structure for the TX worker nvec_request_master()
142 * @wq: The work queue in which @rx_work and @tx_work are executed
143 * @rx: The message currently being retrieved or %NULL
144 * @msg_pool: A pool of messages for allocation
145 * @tx: The message currently being transferred
146 * @tx_scratch: Used for building pseudo messages
147 * @ec_transfer: A completion that will be completed once a message has been
148 * received (see nvec_rx_completed())
149 * @tx_lock: Spinlock for modifications on @tx_data
150 * @rx_lock: Spinlock for modifications on @rx_data
151 * @sync_write_mutex: A mutex for nvec_write_sync()
152 * @sync_write: A completion to signal that a synchronous message is complete
153 * @sync_write_pending: The first two bytes of the request (type and subtype)
154 * @last_sync_msg: The last synchronous message.
155 * @state: State of our finite state machine used in nvec_interrupt()
156 */
32890b98
MD
157struct nvec_chip {
158 struct device *dev;
159 int gpio;
160 int irq;
f686e9af
MD
161 int i2c_addr;
162 void __iomem *base;
163 struct clk *i2c_clk;
32890b98
MD
164 struct atomic_notifier_head notifier_list;
165 struct list_head rx_data, tx_data;
166 struct notifier_block nvec_status_notifier;
167 struct work_struct rx_work, tx_work;
0cab4cb8 168 struct workqueue_struct *wq;
0b1076c4 169 struct nvec_msg msg_pool[NVEC_POOL_SIZE];
0cab4cb8
JAK
170 struct nvec_msg *rx;
171
172 struct nvec_msg *tx;
173 struct nvec_msg tx_scratch;
174 struct completion ec_transfer;
175
176 spinlock_t tx_lock, rx_lock;
32890b98 177
162c7d8c 178 /* sync write stuff */
0cab4cb8 179 struct mutex sync_write_mutex;
32890b98
MD
180 struct completion sync_write;
181 u16 sync_write_pending;
182 struct nvec_msg *last_sync_msg;
0cab4cb8
JAK
183
184 int state;
32890b98
MD
185};
186
1b9bf629 187extern int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
162c7d8c 188 short size);
32890b98 189
0cab4cb8
JAK
190extern struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
191 const unsigned char *data, short size);
192
32890b98 193extern int nvec_register_notifier(struct nvec_chip *nvec,
162c7d8c
MD
194 struct notifier_block *nb,
195 unsigned int events);
32890b98
MD
196
197extern int nvec_unregister_notifier(struct device *dev,
162c7d8c
MD
198 struct notifier_block *nb,
199 unsigned int events);
198dd267
JAK
200
201extern void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg);
202
32890b98 203#endif