^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2011-2016 Synaptics Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2011 Unixphere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef _RMI_DRIVER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define _RMI_DRIVER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "rmi_bus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define SYNAPTICS_INPUT_DEVICE_NAME "Synaptics RMI4 Touch Sensor"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define SYNAPTICS_VENDOR_ID 0x06cb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define GROUP(_attrs) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) .attrs = _attrs, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PDT_PROPERTIES_LOCATION 0x00EF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define BSR_LOCATION 0x00FE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define RMI_PDT_PROPS_HAS_BSR 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define NAME_BUFFER_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define RMI_PDT_ENTRY_SIZE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define RMI_PDT_FUNCTION_VERSION_MASK 0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define RMI_PDT_INT_SOURCE_COUNT_MASK 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define PDT_START_SCAN_LOCATION 0x00e9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define PDT_END_SCAN_LOCATION 0x0005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define RMI4_END_OF_PDT(id) ((id) == 0x00 || (id) == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct pdt_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u16 page_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u8 query_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u8 command_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u8 control_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u8 data_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u8 interrupt_source_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u8 function_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u8 function_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define RMI_REG_DESC_PRESENSE_BITS (32 * BITS_PER_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define RMI_REG_DESC_SUBPACKET_BITS (37 * BITS_PER_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* describes a single packet register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct rmi_register_desc_item {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u16 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned long reg_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 num_subpackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned long subpacket_map[BITS_TO_LONGS(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) RMI_REG_DESC_SUBPACKET_BITS)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * describes the packet registers for a particular type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * (ie query, control, data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct rmi_register_descriptor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned long struct_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned long presense_map[BITS_TO_LONGS(RMI_REG_DESC_PRESENSE_BITS)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u8 num_registers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct rmi_register_desc_item *registers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int rmi_read_register_desc(struct rmi_device *d, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct rmi_register_descriptor *rdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) const struct rmi_register_desc_item *rmi_get_register_desc_item(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct rmi_register_descriptor *rdesc, u16 reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Calculate the total size of all of the registers described in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) size_t rmi_register_desc_calc_size(struct rmi_register_descriptor *rdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int rmi_register_desc_calc_reg_offset(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct rmi_register_descriptor *rdesc, u16 reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) bool rmi_register_desc_has_subpacket(const struct rmi_register_desc_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u8 subpacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) bool rmi_is_physical_driver(struct device_driver *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int rmi_register_physical_driver(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void rmi_unregister_physical_driver(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) void rmi_free_function_list(struct rmi_device *rmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct rmi_function *rmi_find_function(struct rmi_device *rmi_dev, u8 number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int rmi_enable_sensor(struct rmi_device *rmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int rmi_scan_pdt(struct rmi_device *rmi_dev, void *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int (*callback)(struct rmi_device *rmi_dev, void *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const struct pdt_entry *entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int rmi_probe_interrupts(struct rmi_driver_data *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) void rmi_enable_irq(struct rmi_device *rmi_dev, bool clear_wake);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int rmi_init_functions(struct rmi_driver_data *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) const struct pdt_entry *pdt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) const char *rmi_f01_get_product_ID(struct rmi_function *fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #ifdef CONFIG_RMI4_F03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int rmi_f03_overwrite_button(struct rmi_function *fn, unsigned int button,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void rmi_f03_commit_buttons(struct rmi_function *fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline int rmi_f03_overwrite_button(struct rmi_function *fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned int button, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static inline void rmi_f03_commit_buttons(struct rmi_function *fn) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #ifdef CONFIG_RMI4_F34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int rmi_f34_create_sysfs(struct rmi_device *rmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline int rmi_f34_create_sysfs(struct rmi_device *rmi_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static inline void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #endif /* CONFIG_RMI_F34 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) extern struct rmi_function_handler rmi_f01_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) extern struct rmi_function_handler rmi_f03_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) extern struct rmi_function_handler rmi_f11_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) extern struct rmi_function_handler rmi_f12_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) extern struct rmi_function_handler rmi_f30_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) extern struct rmi_function_handler rmi_f34_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) extern struct rmi_function_handler rmi_f3a_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) extern struct rmi_function_handler rmi_f54_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) extern struct rmi_function_handler rmi_f55_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #endif