1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NVEC: NVIDIA compliant embedded controller interface
5 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net>
7 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
8 * Ilya Petrov <ilya.muromec@gmail.com>
9 * Marc Dietrich <marvin24@gmx.de>
10 * Julian Andres Klode <jak@jak-linux.org>
13 #ifndef __LINUX_MFD_NVEC
14 #define __LINUX_MFD_NVEC
16 #include <linux/atomic.h>
17 #include <linux/clk.h>
18 #include <linux/completion.h>
19 #include <linux/list.h>
20 #include <linux/mutex.h>
21 #include <linux/notifier.h>
22 #include <linux/reset.h>
23 #include <linux/spinlock.h>
24 #include <linux/workqueue.h>
26 /* NVEC_POOL_SIZE - Size of the pool in &struct nvec_msg */
27 #define NVEC_POOL_SIZE 64
30 * NVEC_MSG_SIZE - Maximum size of the data field of &struct nvec_msg.
32 * A message must store up to a SMBus block operation which consists of
33 * one command byte, one count byte, and up to 32 payload bytes = 34
36 #define NVEC_MSG_SIZE 34
39 * enum nvec_event_size - The size of an event message
40 * @NVEC_2BYTES: The message has one command byte and one data byte
41 * @NVEC_3BYTES: The message has one command byte and two data bytes
42 * @NVEC_VAR_SIZE: The message has one command byte, one count byte, and has
43 * up to as many bytes as the number in the count byte. The
46 * Events can be fixed or variable sized. This is useless on other message
47 * types, which are always variable sized.
49 enum nvec_event_size
{
56 * enum nvec_msg_type - The type of a message
57 * @NVEC_SYS: A system request/response
58 * @NVEC_BAT: A battery request/response
59 * @NVEC_KBD: A keyboard request/response
60 * @NVEC_PS2: A mouse request/response
61 * @NVEC_CNTL: A EC control request/response
62 * @NVEC_KB_EVT: An event from the keyboard
63 * @NVEC_PS2_EVT: An event from the mouse
65 * Events can be fixed or variable sized. This is useless on other message
66 * types, which are always variable sized.
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.
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
95 struct list_head node
;
96 unsigned char data
[NVEC_MSG_SIZE
];
103 * struct nvec_chip - A single connection to an NVIDIA Embedded controller
105 * @gpio: The same as for &struct nvec_platform_data
106 * @irq: The IRQ of the I2C device
107 * @i2c_addr: The address of the I2C slave
108 * @base: The base of the memory mapped region of the I2C device
109 * @i2c_clk: The clock of the I2C device
110 * @rst: The reset of the I2C device
111 * @notifier_list: Notifiers to be called on received messages, see
112 * nvec_register_notifier()
113 * @rx_data: Received messages that have to be processed
114 * @tx_data: Messages waiting to be sent to the controller
115 * @nvec_status_notifier: Internal notifier (see nvec_status_notifier())
116 * @rx_work: A work structure for the RX worker nvec_dispatch()
117 * @tx_work: A work structure for the TX worker nvec_request_master()
118 * @wq: The work queue in which @rx_work and @tx_work are executed
119 * @rx: The message currently being retrieved or %NULL
120 * @msg_pool: A pool of messages for allocation
121 * @tx: The message currently being transferred
122 * @tx_scratch: Used for building pseudo messages
123 * @ec_transfer: A completion that will be completed once a message has been
124 * received (see nvec_rx_completed())
125 * @tx_lock: Spinlock for modifications on @tx_data
126 * @rx_lock: Spinlock for modifications on @rx_data
127 * @sync_write_mutex: A mutex for nvec_write_sync()
128 * @sync_write: A completion to signal that a synchronous message is complete
129 * @sync_write_pending: The first two bytes of the request (type and subtype)
130 * @last_sync_msg: The last synchronous message.
131 * @state: State of our finite state machine used in nvec_interrupt()
135 struct gpio_desc
*gpiod
;
140 struct reset_control
*rst
;
141 struct atomic_notifier_head notifier_list
;
142 struct list_head rx_data
, tx_data
;
143 struct notifier_block nvec_status_notifier
;
144 struct work_struct rx_work
, tx_work
;
145 struct workqueue_struct
*wq
;
146 struct nvec_msg msg_pool
[NVEC_POOL_SIZE
];
150 struct nvec_msg tx_scratch
;
151 struct completion ec_transfer
;
153 spinlock_t tx_lock
, rx_lock
;
155 /* sync write stuff */
156 struct mutex sync_write_mutex
;
157 struct completion sync_write
;
158 u16 sync_write_pending
;
159 struct nvec_msg
*last_sync_msg
;
164 int nvec_write_async(struct nvec_chip
*nvec
, const unsigned char *data
,
167 int nvec_write_sync(struct nvec_chip
*nvec
,
168 const unsigned char *data
, short size
,
169 struct nvec_msg
**msg
);
171 int nvec_register_notifier(struct nvec_chip
*nvec
,
172 struct notifier_block
*nb
,
173 unsigned int events
);
175 int nvec_unregister_notifier(struct nvec_chip
*dev
, struct notifier_block
*nb
);
177 void nvec_msg_free(struct nvec_chip
*nvec
, struct nvec_msg
*msg
);