![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * NVEC: NVIDIA compliant embedded controller interface 0004 * 0005 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.launchpad.net> 0006 * 0007 * Authors: Pierre-Hugues Husson <phhusson@free.fr> 0008 * Ilya Petrov <ilya.muromec@gmail.com> 0009 * Marc Dietrich <marvin24@gmx.de> 0010 * Julian Andres Klode <jak@jak-linux.org> 0011 */ 0012 0013 #ifndef __LINUX_MFD_NVEC 0014 #define __LINUX_MFD_NVEC 0015 0016 #include <linux/atomic.h> 0017 #include <linux/clk.h> 0018 #include <linux/completion.h> 0019 #include <linux/list.h> 0020 #include <linux/mutex.h> 0021 #include <linux/notifier.h> 0022 #include <linux/reset.h> 0023 #include <linux/spinlock.h> 0024 #include <linux/workqueue.h> 0025 0026 /* NVEC_POOL_SIZE - Size of the pool in &struct nvec_msg */ 0027 #define NVEC_POOL_SIZE 64 0028 0029 /* 0030 * NVEC_MSG_SIZE - Maximum size of the data field of &struct nvec_msg. 0031 * 0032 * A message must store up to a SMBus block operation which consists of 0033 * one command byte, one count byte, and up to 32 payload bytes = 34 0034 * byte. 0035 */ 0036 #define NVEC_MSG_SIZE 34 0037 0038 /** 0039 * enum nvec_event_size - The size of an event message 0040 * @NVEC_2BYTES: The message has one command byte and one data byte 0041 * @NVEC_3BYTES: The message has one command byte and two data bytes 0042 * @NVEC_VAR_SIZE: The message has one command byte, one count byte, and has 0043 * up to as many bytes as the number in the count byte. The 0044 * maximum is 32 0045 * 0046 * Events can be fixed or variable sized. This is useless on other message 0047 * types, which are always variable sized. 0048 */ 0049 enum nvec_event_size { 0050 NVEC_2BYTES, 0051 NVEC_3BYTES, 0052 NVEC_VAR_SIZE, 0053 }; 0054 0055 /** 0056 * enum nvec_msg_type - The type of a message 0057 * @NVEC_SYS: A system request/response 0058 * @NVEC_BAT: A battery request/response 0059 * @NVEC_KBD: A keyboard request/response 0060 * @NVEC_PS2: A mouse request/response 0061 * @NVEC_CNTL: A EC control request/response 0062 * @NVEC_KB_EVT: An event from the keyboard 0063 * @NVEC_PS2_EVT: An event from the mouse 0064 * 0065 * Events can be fixed or variable sized. This is useless on other message 0066 * types, which are always variable sized. 0067 */ 0068 enum nvec_msg_type { 0069 NVEC_SYS = 1, 0070 NVEC_BAT, 0071 NVEC_GPIO, 0072 NVEC_SLEEP, 0073 NVEC_KBD, 0074 NVEC_PS2, 0075 NVEC_CNTL, 0076 NVEC_OEM0 = 0x0d, 0077 NVEC_KB_EVT = 0x80, 0078 NVEC_PS2_EVT, 0079 }; 0080 0081 /** 0082 * struct nvec_msg - A buffer for a single message 0083 * @node: Messages are part of various lists in a &struct nvec_chip 0084 * @data: The data of the message 0085 * @size: For TX messages, the number of bytes used in @data 0086 * @pos: For RX messages, the current position to write to. For TX messages, 0087 * the position to read from. 0088 * @used: Used for the message pool to mark a message as free/allocated. 0089 * 0090 * This structure is used to hold outgoing and incoming messages. Outgoing 0091 * messages have a different format than incoming messages, and that is not 0092 * documented yet. 0093 */ 0094 struct nvec_msg { 0095 struct list_head node; 0096 unsigned char data[NVEC_MSG_SIZE]; 0097 unsigned short size; 0098 unsigned short pos; 0099 atomic_t used; 0100 }; 0101 0102 /** 0103 * struct nvec_chip - A single connection to an NVIDIA Embedded controller 0104 * @dev: The device 0105 * @gpio: The same as for &struct nvec_platform_data 0106 * @irq: The IRQ of the I2C device 0107 * @i2c_addr: The address of the I2C slave 0108 * @base: The base of the memory mapped region of the I2C device 0109 * @i2c_clk: The clock of the I2C device 0110 * @rst: The reset of the I2C device 0111 * @notifier_list: Notifiers to be called on received messages, see 0112 * nvec_register_notifier() 0113 * @rx_data: Received messages that have to be processed 0114 * @tx_data: Messages waiting to be sent to the controller 0115 * @nvec_status_notifier: Internal notifier (see nvec_status_notifier()) 0116 * @rx_work: A work structure for the RX worker nvec_dispatch() 0117 * @tx_work: A work structure for the TX worker nvec_request_master() 0118 * @wq: The work queue in which @rx_work and @tx_work are executed 0119 * @rx: The message currently being retrieved or %NULL 0120 * @msg_pool: A pool of messages for allocation 0121 * @tx: The message currently being transferred 0122 * @tx_scratch: Used for building pseudo messages 0123 * @ec_transfer: A completion that will be completed once a message has been 0124 * received (see nvec_rx_completed()) 0125 * @tx_lock: Spinlock for modifications on @tx_data 0126 * @rx_lock: Spinlock for modifications on @rx_data 0127 * @sync_write_mutex: A mutex for nvec_write_sync() 0128 * @sync_write: A completion to signal that a synchronous message is complete 0129 * @sync_write_pending: The first two bytes of the request (type and subtype) 0130 * @last_sync_msg: The last synchronous message. 0131 * @state: State of our finite state machine used in nvec_interrupt() 0132 */ 0133 struct nvec_chip { 0134 struct device *dev; 0135 struct gpio_desc *gpiod; 0136 int irq; 0137 u32 i2c_addr; 0138 void __iomem *base; 0139 struct clk *i2c_clk; 0140 struct reset_control *rst; 0141 struct atomic_notifier_head notifier_list; 0142 struct list_head rx_data, tx_data; 0143 struct notifier_block nvec_status_notifier; 0144 struct work_struct rx_work, tx_work; 0145 struct workqueue_struct *wq; 0146 struct nvec_msg msg_pool[NVEC_POOL_SIZE]; 0147 struct nvec_msg *rx; 0148 0149 struct nvec_msg *tx; 0150 struct nvec_msg tx_scratch; 0151 struct completion ec_transfer; 0152 0153 spinlock_t tx_lock, rx_lock; 0154 0155 /* sync write stuff */ 0156 struct mutex sync_write_mutex; 0157 struct completion sync_write; 0158 u16 sync_write_pending; 0159 struct nvec_msg *last_sync_msg; 0160 0161 int state; 0162 }; 0163 0164 int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data, 0165 short size); 0166 0167 int nvec_write_sync(struct nvec_chip *nvec, 0168 const unsigned char *data, short size, 0169 struct nvec_msg **msg); 0170 0171 int nvec_register_notifier(struct nvec_chip *nvec, 0172 struct notifier_block *nb, 0173 unsigned int events); 0174 0175 int nvec_unregister_notifier(struct nvec_chip *dev, struct notifier_block *nb); 0176 0177 void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg); 0178 0179 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |