brintos

brintos / linux-shallow public Read only

0
0
Text · 7.4 KiB · f649cde Raw
247 lines · c
1/* SPDX-License-Identifier: GPL-2.0-or-later */2/*3 *  Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.4 */5 6#ifndef __SSP_SENSORHUB_H__7#define __SSP_SENSORHUB_H__8 9#include <linux/delay.h>10#include <linux/gpio/consumer.h>11#include <linux/iio/common/ssp_sensors.h>12#include <linux/iio/iio.h>13#include <linux/spi/spi.h>14 15#define SSP_DEVICE_ID		0x5516 17#ifdef SSP_DBG18#define ssp_dbg(format, ...) pr_info("[SSP] "format, ##__VA_ARGS__)19#else20#define ssp_dbg(format, ...)21#endif22 23#define SSP_SW_RESET_TIME		300024/* Sensor polling in ms */25#define SSP_DEFAULT_POLLING_DELAY	20026#define SSP_DEFAULT_RETRIES		327#define SSP_DATA_PACKET_SIZE		96028#define SSP_HEADER_BUFFER_SIZE		429 30enum {31	SSP_KERNEL_BINARY = 0,32	SSP_KERNEL_CRASHED_BINARY,33};34 35enum {36	SSP_INITIALIZATION_STATE = 0,37	SSP_NO_SENSOR_STATE,38	SSP_ADD_SENSOR_STATE,39	SSP_RUNNING_SENSOR_STATE,40};41 42/* Firmware download STATE */43enum {44	SSP_FW_DL_STATE_FAIL = -1,45	SSP_FW_DL_STATE_NONE = 0,46	SSP_FW_DL_STATE_NEED_TO_SCHEDULE,47	SSP_FW_DL_STATE_SCHEDULED,48	SSP_FW_DL_STATE_DOWNLOADING,49	SSP_FW_DL_STATE_SYNC,50	SSP_FW_DL_STATE_DONE,51};52 53#define SSP_INVALID_REVISION			9999954#define SSP_INVALID_REVISION2			0xffffff55 56/* AP -> SSP Instruction */57#define SSP_MSG2SSP_INST_BYPASS_SENSOR_ADD	0xa158#define SSP_MSG2SSP_INST_BYPASS_SENSOR_RM	0xa259#define SSP_MSG2SSP_INST_REMOVE_ALL		0xa360#define SSP_MSG2SSP_INST_CHANGE_DELAY		0xa461#define SSP_MSG2SSP_INST_LIBRARY_ADD		0xb162#define SSP_MSG2SSP_INST_LIBRARY_REMOVE		0xb263#define SSP_MSG2SSP_INST_LIB_NOTI		0xb464#define SSP_MSG2SSP_INST_LIB_DATA		0xc165 66#define SSP_MSG2SSP_AP_MCU_SET_GYRO_CAL		0xcd67#define SSP_MSG2SSP_AP_MCU_SET_ACCEL_CAL	0xce68#define SSP_MSG2SSP_AP_STATUS_SHUTDOWN		0xd069#define SSP_MSG2SSP_AP_STATUS_WAKEUP		0xd170#define SSP_MSG2SSP_AP_STATUS_SLEEP		0xd271#define SSP_MSG2SSP_AP_STATUS_RESUME		0xd372#define SSP_MSG2SSP_AP_STATUS_SUSPEND		0xd473#define SSP_MSG2SSP_AP_STATUS_RESET		0xd574#define SSP_MSG2SSP_AP_STATUS_POW_CONNECTED	0xd675#define SSP_MSG2SSP_AP_STATUS_POW_DISCONNECTED	0xd776#define SSP_MSG2SSP_AP_TEMPHUMIDITY_CAL_DONE	0xda77#define SSP_MSG2SSP_AP_MCU_SET_DUMPMODE		0xdb78#define SSP_MSG2SSP_AP_MCU_DUMP_CHECK		0xdc79#define SSP_MSG2SSP_AP_MCU_BATCH_FLUSH		0xdd80#define SSP_MSG2SSP_AP_MCU_BATCH_COUNT		0xdf81 82#define SSP_MSG2SSP_AP_WHOAMI				0x0f83#define SSP_MSG2SSP_AP_FIRMWARE_REV			0xf084#define SSP_MSG2SSP_AP_SENSOR_FORMATION			0xf185#define SSP_MSG2SSP_AP_SENSOR_PROXTHRESHOLD		0xf286#define SSP_MSG2SSP_AP_SENSOR_BARCODE_EMUL		0xf387#define SSP_MSG2SSP_AP_SENSOR_SCANNING			0xf488#define SSP_MSG2SSP_AP_SET_MAGNETIC_HWOFFSET		0xf589#define SSP_MSG2SSP_AP_GET_MAGNETIC_HWOFFSET		0xf690#define SSP_MSG2SSP_AP_SENSOR_GESTURE_CURRENT		0xf791#define SSP_MSG2SSP_AP_GET_THERM			0xf892#define SSP_MSG2SSP_AP_GET_BIG_DATA			0xf993#define SSP_MSG2SSP_AP_SET_BIG_DATA			0xfa94#define SSP_MSG2SSP_AP_START_BIG_DATA			0xfb95#define SSP_MSG2SSP_AP_SET_MAGNETIC_STATIC_MATRIX	0xfd96#define SSP_MSG2SSP_AP_SENSOR_TILT			0xea97#define SSP_MSG2SSP_AP_MCU_SET_TIME			0xfe98#define SSP_MSG2SSP_AP_MCU_GET_TIME			0xff99 100#define SSP_MSG2SSP_AP_FUSEROM				0x01101 102/* voice data */103#define SSP_TYPE_WAKE_UP_VOICE_SERVICE			0x01104#define SSP_TYPE_WAKE_UP_VOICE_SOUND_SOURCE_AM		0x01105#define SSP_TYPE_WAKE_UP_VOICE_SOUND_SOURCE_GRAMMER	0x02106 107/* Factory Test */108#define SSP_ACCELEROMETER_FACTORY			0x80109#define SSP_GYROSCOPE_FACTORY				0x81110#define SSP_GEOMAGNETIC_FACTORY				0x82111#define SSP_PRESSURE_FACTORY				0x85112#define SSP_GESTURE_FACTORY				0x86113#define SSP_TEMPHUMIDITY_CRC_FACTORY			0x88114#define SSP_GYROSCOPE_TEMP_FACTORY			0x8a115#define SSP_GYROSCOPE_DPS_FACTORY			0x8b116#define SSP_MCU_FACTORY					0x8c117#define SSP_MCU_SLEEP_FACTORY				0x8d118 119/* SSP -> AP ACK about write CMD */120#define SSP_MSG_ACK		0x80	/* ACK from SSP to AP */121#define SSP_MSG_NAK		0x70	/* NAK from SSP to AP */122 123struct ssp_sensorhub_info {124	char *fw_name;125	char *fw_crashed_name;126	unsigned int fw_rev;127	const u8 * const mag_table;128	const unsigned int mag_length;129};130 131/* ssp_msg options bit */132#define SSP_RW		0133#define SSP_INDEX	3134 135#define SSP_AP2HUB_READ		0136#define SSP_AP2HUB_WRITE	1137#define SSP_HUB2AP_WRITE	2138#define SSP_AP2HUB_READY	3139#define SSP_AP2HUB_RETURN	4140 141/**142 * struct ssp_data - ssp platformdata structure143 * @spi:		spi device144 * @sensorhub_info:	info about sensorhub board specific features145 * @wdt_timer:		watchdog timer146 * @work_wdt:		watchdog work147 * @work_firmware:	firmware upgrade work queue148 * @work_refresh:	refresh work queue for reset request from MCU149 * @shut_down:		shut down flag150 * @mcu_dump_mode:	mcu dump mode for debug151 * @time_syncing:	time syncing indication flag152 * @timestamp:		previous time in ns calculated for time syncing153 * @check_status:	status table for each sensor154 * @com_fail_cnt:	communication fail count155 * @reset_cnt:		reset count156 * @timeout_cnt:	timeout count157 * @available_sensors:	available sensors seen by sensorhub (bit array)158 * @cur_firm_rev:	cached current firmware revision159 * @last_resume_state:	last AP resume/suspend state used to handle the PM160 *                      state of ssp161 * @last_ap_state:	(obsolete) sleep notification for MCU162 * @sensor_enable:	sensor enable mask163 * @delay_buf:		data acquisition intervals table164 * @batch_latency_buf:	yet unknown but existing in communication protocol165 * @batch_opt_buf:	yet unknown but existing in communication protocol166 * @accel_position:	yet unknown but existing in communication protocol167 * @mag_position:	yet unknown but existing in communication protocol168 * @fw_dl_state:	firmware download state169 * @comm_lock:		lock protecting the handshake170 * @pending_lock:	lock protecting pending list and completion171 * @mcu_reset_gpiod:	mcu reset line172 * @ap_mcu_gpiod:	ap to mcu gpio line173 * @mcu_ap_gpiod:	mcu to ap gpio line174 * @pending_list:	pending list for messages queued to be sent/read175 * @sensor_devs:	registered IIO devices table176 * @enable_refcount:	enable reference count for wdt (watchdog timer)177 * @header_buffer:	cache aligned buffer for packet header178 */179struct ssp_data {180	struct spi_device *spi;181	const struct ssp_sensorhub_info *sensorhub_info;182	struct timer_list wdt_timer;183	struct work_struct work_wdt;184	struct delayed_work work_refresh;185 186	bool shut_down;187	bool mcu_dump_mode;188	bool time_syncing;189	int64_t timestamp;190 191	int check_status[SSP_SENSOR_MAX];192 193	unsigned int com_fail_cnt;194	unsigned int reset_cnt;195	unsigned int timeout_cnt;196 197	unsigned int available_sensors;198	unsigned int cur_firm_rev;199 200	char last_resume_state;201	char last_ap_state;202 203	unsigned int sensor_enable;204	u32 delay_buf[SSP_SENSOR_MAX];205	s32 batch_latency_buf[SSP_SENSOR_MAX];206	s8 batch_opt_buf[SSP_SENSOR_MAX];207 208	int accel_position;209	int mag_position;210	int fw_dl_state;211 212	struct mutex comm_lock;213	struct mutex pending_lock;214 215	struct gpio_desc *mcu_reset_gpiod;216	struct gpio_desc *ap_mcu_gpiod;217	struct gpio_desc *mcu_ap_gpiod;218 219	struct list_head pending_list;220 221	struct iio_dev *sensor_devs[SSP_SENSOR_MAX];222	atomic_t enable_refcount;223 224	__le16 header_buffer[SSP_HEADER_BUFFER_SIZE / sizeof(__le16)] __aligned(IIO_DMA_MINALIGN);225};226 227void ssp_clean_pending_list(struct ssp_data *data);228 229int ssp_command(struct ssp_data *data, char command, int arg);230 231int ssp_send_instruction(struct ssp_data *data, u8 inst, u8 sensor_type,232			 u8 *send_buf, u8 length);233 234int ssp_irq_msg(struct ssp_data *data);235 236int ssp_get_chipid(struct ssp_data *data);237 238int ssp_set_magnetic_matrix(struct ssp_data *data);239 240unsigned int ssp_get_sensor_scanning_info(struct ssp_data *data);241 242unsigned int ssp_get_firmware_rev(struct ssp_data *data);243 244int ssp_queue_ssp_refresh_task(struct ssp_data *data, unsigned int delay);245 246#endif /* __SSP_SENSORHUB_H__ */247