18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2011-2016 Synaptics Incorporated
48c2ecf20Sopenharmony_ci * Copyright (c) 2011 Unixphere
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _RMI_DRIVER_H
88c2ecf20Sopenharmony_ci#define _RMI_DRIVER_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/ctype.h>
118c2ecf20Sopenharmony_ci#include <linux/hrtimer.h>
128c2ecf20Sopenharmony_ci#include <linux/ktime.h>
138c2ecf20Sopenharmony_ci#include <linux/input.h>
148c2ecf20Sopenharmony_ci#include "rmi_bus.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define SYNAPTICS_INPUT_DEVICE_NAME "Synaptics RMI4 Touch Sensor"
178c2ecf20Sopenharmony_ci#define SYNAPTICS_VENDOR_ID 0x06cb
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define GROUP(_attrs) { \
208c2ecf20Sopenharmony_ci	.attrs = _attrs,  \
218c2ecf20Sopenharmony_ci}
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define PDT_PROPERTIES_LOCATION 0x00EF
248c2ecf20Sopenharmony_ci#define BSR_LOCATION 0x00FE
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define RMI_PDT_PROPS_HAS_BSR 0x02
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define NAME_BUFFER_SIZE 256
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define RMI_PDT_ENTRY_SIZE 6
318c2ecf20Sopenharmony_ci#define RMI_PDT_FUNCTION_VERSION_MASK   0x60
328c2ecf20Sopenharmony_ci#define RMI_PDT_INT_SOURCE_COUNT_MASK   0x07
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define PDT_START_SCAN_LOCATION 0x00e9
358c2ecf20Sopenharmony_ci#define PDT_END_SCAN_LOCATION	0x0005
368c2ecf20Sopenharmony_ci#define RMI4_END_OF_PDT(id) ((id) == 0x00 || (id) == 0xff)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct pdt_entry {
398c2ecf20Sopenharmony_ci	u16 page_start;
408c2ecf20Sopenharmony_ci	u8 query_base_addr;
418c2ecf20Sopenharmony_ci	u8 command_base_addr;
428c2ecf20Sopenharmony_ci	u8 control_base_addr;
438c2ecf20Sopenharmony_ci	u8 data_base_addr;
448c2ecf20Sopenharmony_ci	u8 interrupt_source_count;
458c2ecf20Sopenharmony_ci	u8 function_version;
468c2ecf20Sopenharmony_ci	u8 function_number;
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define RMI_REG_DESC_PRESENSE_BITS	(32 * BITS_PER_BYTE)
508c2ecf20Sopenharmony_ci#define RMI_REG_DESC_SUBPACKET_BITS	(37 * BITS_PER_BYTE)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* describes a single packet register */
538c2ecf20Sopenharmony_cistruct rmi_register_desc_item {
548c2ecf20Sopenharmony_ci	u16 reg;
558c2ecf20Sopenharmony_ci	unsigned long reg_size;
568c2ecf20Sopenharmony_ci	u8 num_subpackets;
578c2ecf20Sopenharmony_ci	unsigned long subpacket_map[BITS_TO_LONGS(
588c2ecf20Sopenharmony_ci				RMI_REG_DESC_SUBPACKET_BITS)];
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/*
628c2ecf20Sopenharmony_ci * describes the packet registers for a particular type
638c2ecf20Sopenharmony_ci * (ie query, control, data)
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_cistruct rmi_register_descriptor {
668c2ecf20Sopenharmony_ci	unsigned long struct_size;
678c2ecf20Sopenharmony_ci	unsigned long presense_map[BITS_TO_LONGS(RMI_REG_DESC_PRESENSE_BITS)];
688c2ecf20Sopenharmony_ci	u8 num_registers;
698c2ecf20Sopenharmony_ci	struct rmi_register_desc_item *registers;
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciint rmi_read_register_desc(struct rmi_device *d, u16 addr,
738c2ecf20Sopenharmony_ci				struct rmi_register_descriptor *rdesc);
748c2ecf20Sopenharmony_ciconst struct rmi_register_desc_item *rmi_get_register_desc_item(
758c2ecf20Sopenharmony_ci				struct rmi_register_descriptor *rdesc, u16 reg);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/*
788c2ecf20Sopenharmony_ci * Calculate the total size of all of the registers described in the
798c2ecf20Sopenharmony_ci * descriptor.
808c2ecf20Sopenharmony_ci */
818c2ecf20Sopenharmony_cisize_t rmi_register_desc_calc_size(struct rmi_register_descriptor *rdesc);
828c2ecf20Sopenharmony_ciint rmi_register_desc_calc_reg_offset(
838c2ecf20Sopenharmony_ci			struct rmi_register_descriptor *rdesc, u16 reg);
848c2ecf20Sopenharmony_cibool rmi_register_desc_has_subpacket(const struct rmi_register_desc_item *item,
858c2ecf20Sopenharmony_ci			u8 subpacket);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cibool rmi_is_physical_driver(struct device_driver *);
888c2ecf20Sopenharmony_ciint rmi_register_physical_driver(void);
898c2ecf20Sopenharmony_civoid rmi_unregister_physical_driver(void);
908c2ecf20Sopenharmony_civoid rmi_free_function_list(struct rmi_device *rmi_dev);
918c2ecf20Sopenharmony_cistruct rmi_function *rmi_find_function(struct rmi_device *rmi_dev, u8 number);
928c2ecf20Sopenharmony_ciint rmi_enable_sensor(struct rmi_device *rmi_dev);
938c2ecf20Sopenharmony_ciint rmi_scan_pdt(struct rmi_device *rmi_dev, void *ctx,
948c2ecf20Sopenharmony_ci		 int (*callback)(struct rmi_device *rmi_dev, void *ctx,
958c2ecf20Sopenharmony_ci		 const struct pdt_entry *entry));
968c2ecf20Sopenharmony_ciint rmi_probe_interrupts(struct rmi_driver_data *data);
978c2ecf20Sopenharmony_civoid rmi_enable_irq(struct rmi_device *rmi_dev, bool clear_wake);
988c2ecf20Sopenharmony_civoid rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake);
998c2ecf20Sopenharmony_ciint rmi_init_functions(struct rmi_driver_data *data);
1008c2ecf20Sopenharmony_ciint rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx,
1018c2ecf20Sopenharmony_ci		      const struct pdt_entry *pdt);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ciconst char *rmi_f01_get_product_ID(struct rmi_function *fn);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#ifdef CONFIG_RMI4_F03
1068c2ecf20Sopenharmony_ciint rmi_f03_overwrite_button(struct rmi_function *fn, unsigned int button,
1078c2ecf20Sopenharmony_ci			     int value);
1088c2ecf20Sopenharmony_civoid rmi_f03_commit_buttons(struct rmi_function *fn);
1098c2ecf20Sopenharmony_ci#else
1108c2ecf20Sopenharmony_cistatic inline int rmi_f03_overwrite_button(struct rmi_function *fn,
1118c2ecf20Sopenharmony_ci					   unsigned int button, int value)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	return 0;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_cistatic inline void rmi_f03_commit_buttons(struct rmi_function *fn) {}
1168c2ecf20Sopenharmony_ci#endif
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#ifdef CONFIG_RMI4_F34
1198c2ecf20Sopenharmony_ciint rmi_f34_create_sysfs(struct rmi_device *rmi_dev);
1208c2ecf20Sopenharmony_civoid rmi_f34_remove_sysfs(struct rmi_device *rmi_dev);
1218c2ecf20Sopenharmony_ci#else
1228c2ecf20Sopenharmony_cistatic inline int rmi_f34_create_sysfs(struct rmi_device *rmi_dev)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	return 0;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic inline void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci#endif /* CONFIG_RMI_F34 */
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f01_handler;
1338c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f03_handler;
1348c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f11_handler;
1358c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f12_handler;
1368c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f30_handler;
1378c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f34_handler;
1388c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f3a_handler;
1398c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f54_handler;
1408c2ecf20Sopenharmony_ciextern struct rmi_function_handler rmi_f55_handler;
1418c2ecf20Sopenharmony_ci#endif
142