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