blob: eb8d5f2e0da1ec7164e4511c51a2c8224f699e64 [file] [log] [blame]
Alexandra Chin669d27c2012-12-24 15:42:30 +08001/*
2 * Synaptics RMI4 touchscreen driver
3 *
4 * Copyright (C) 2012 Synaptics Incorporated
5 *
6 * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com>
7 * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#ifndef _SYNAPTICS_DSX_RMI4_H_
21#define _SYNAPTICS_DSX_RMI4_H_
22
Alexandra Chind5591a62013-02-07 12:59:15 -080023#define SYNAPTICS_RMI4_DS4 0x0001
24#define SYNAPTICS_RMI4_DS5 0x0002
25#define SYNAPTICS_RMI4_DRIVER_PRODUCT SYNAPTICS_RMI4_DS4
26#define SYNAPTICS_RMI4_DRIVER_VERSION 0x1001
Shantanu Jain41f0d472013-01-04 12:14:37 +053027#define SYNAPTICS_RMI4_DRIVER_VERSION_STRING "0x1001"
Alexandra Chin669d27c2012-12-24 15:42:30 +080028
29#include <linux/version.h>
30#ifdef CONFIG_HAS_EARLYSUSPEND
31#include <linux/earlysuspend.h>
32#endif
33
Alexandra Chin669d27c2012-12-24 15:42:30 +080034#define PDT_PROPS (0x00EF)
35#define PDT_START (0x00E9)
36#define PDT_END (0x000A)
37#define PDT_ENTRY_SIZE (0x0006)
38#define PAGES_TO_SERVICE (10)
39#define PAGE_SELECT_LEN (2)
40
41#define SYNAPTICS_RMI4_F01 (0x01)
42#define SYNAPTICS_RMI4_F11 (0x11)
43#define SYNAPTICS_RMI4_F1A (0x1a)
44#define SYNAPTICS_RMI4_F34 (0x34)
45#define SYNAPTICS_RMI4_F54 (0x54)
46#define SYNAPTICS_RMI4_F55 (0x55)
47
48#define SYNAPTICS_RMI4_PRODUCT_INFO_SIZE 2
49#define SYNAPTICS_RMI4_DATE_CODE_SIZE 3
50#define SYNAPTICS_RMI4_PRODUCT_ID_SIZE 10
51#define SYNAPTICS_RMI4_BUILD_ID_SIZE 3
52
53#define MAX_NUMBER_OF_FINGERS 10
54#define MAX_NUMBER_OF_BUTTONS 4
55#define MAX_INTR_REGISTERS 4
56
57#define MASK_16BIT 0xFFFF
58#define MASK_8BIT 0xFF
59#define MASK_7BIT 0x7F
60#define MASK_6BIT 0x3F
61#define MASK_5BIT 0x1F
62#define MASK_4BIT 0x0F
63#define MASK_3BIT 0x07
64#define MASK_2BIT 0x03
65#define MASK_1BIT 0x01
66
67/*
68 * struct synaptics_rmi4_fn_desc - function descriptor fields in PDT
69 * @query_base_addr: base address for query registers
70 * @cmd_base_addr: base address for command registers
71 * @ctrl_base_addr: base address for control registers
72 * @data_base_addr: base address for data registers
73 * @intr_src_count: number of interrupt sources
74 * @fn_number: function number
75 */
76struct synaptics_rmi4_fn_desc {
77 unsigned char query_base_addr;
78 unsigned char cmd_base_addr;
79 unsigned char ctrl_base_addr;
80 unsigned char data_base_addr;
81 unsigned char intr_src_count;
82 unsigned char fn_number;
83};
84
85/*
86 * synaptics_rmi4_fn_full_addr - full 16-bit base addresses
87 * @query_base: 16-bit base address for query registers
88 * @cmd_base: 16-bit base address for data registers
89 * @ctrl_base: 16-bit base address for command registers
90 * @data_base: 16-bit base address for control registers
91 */
92struct synaptics_rmi4_fn_full_addr {
93 unsigned short query_base;
94 unsigned short cmd_base;
95 unsigned short ctrl_base;
96 unsigned short data_base;
97};
98
99/*
100 * struct synaptics_rmi4_fn - function handler data structure
101 * @fn_number: function number
102 * @num_of_data_sources: number of data sources
103 * @num_of_data_points: maximum number of fingers supported
104 * @size_of_data_register_block: data register block size
105 * @data1_offset: offset to data1 register from data base address
106 * @intr_reg_num: index to associated interrupt register
107 * @intr_mask: interrupt mask
108 * @full_addr: full 16-bit base addresses of function registers
109 * @link: linked list for function handlers
110 * @data_size: size of private data
111 * @data: pointer to private data
112 */
113struct synaptics_rmi4_fn {
114 unsigned char fn_number;
115 unsigned char num_of_data_sources;
116 unsigned char num_of_data_points;
117 unsigned char size_of_data_register_block;
118 unsigned char data1_offset;
119 unsigned char intr_reg_num;
120 unsigned char intr_mask;
121 struct synaptics_rmi4_fn_full_addr full_addr;
122 struct list_head link;
123 int data_size;
124 void *data;
125};
126
127/*
128 * struct synaptics_rmi4_device_info - device information
129 * @version_major: rmi protocol major version number
130 * @version_minor: rmi protocol minor version number
131 * @manufacturer_id: manufacturer id
132 * @product_props: product properties information
133 * @product_info: product info array
134 * @date_code: device manufacture date
135 * @tester_id: tester id array
136 * @serial_number: device serial number
137 * @product_id_string: device product id
138 * @support_fn_list: linked list for function handlers
139 */
140struct synaptics_rmi4_device_info {
141 unsigned int version_major;
142 unsigned int version_minor;
143 unsigned char manufacturer_id;
144 unsigned char product_props;
145 unsigned char product_info[SYNAPTICS_RMI4_PRODUCT_INFO_SIZE];
146 unsigned char date_code[SYNAPTICS_RMI4_DATE_CODE_SIZE];
147 unsigned short tester_id;
148 unsigned short serial_number;
149 unsigned char product_id_string[SYNAPTICS_RMI4_PRODUCT_ID_SIZE + 1];
150 unsigned char build_id[SYNAPTICS_RMI4_BUILD_ID_SIZE];
Alexandra Chind5591a62013-02-07 12:59:15 -0800151 unsigned char config_id[3];
Alexandra Chin669d27c2012-12-24 15:42:30 +0800152 struct list_head support_fn_list;
153};
154
155/*
156 * struct synaptics_rmi4_data - rmi4 device instance data
157 * @i2c_client: pointer to associated i2c client
158 * @input_dev: pointer to associated input device
159 * @board: constant pointer to platform data
160 * @rmi4_mod_info: device information
161 * @regulator: pointer to associated regulator
162 * @rmi4_io_ctrl_mutex: mutex for i2c i/o control
163 * @det_work: work thread instance for expansion function detection
164 * @det_workqueue: pointer to work queue for work thread instance
165 * @early_suspend: instance to support early suspend power management
166 * @current_page: current page in sensor to acess
167 * @button_0d_enabled: flag for 0d button support
168 * @full_pm_cycle: flag for full power management cycle in early suspend stage
169 * @num_of_intr_regs: number of interrupt registers
170 * @f01_query_base_addr: query base address for f01
171 * @f01_cmd_base_addr: command base address for f01
172 * @f01_ctrl_base_addr: control base address for f01
173 * @f01_data_base_addr: data base address for f01
174 * @irq: attention interrupt
175 * @sensor_max_x: sensor maximum x value
176 * @sensor_max_y: sensor maximum y value
177 * @irq_enabled: flag for indicating interrupt enable status
178 * @touch_stopped: flag to stop interrupt thread processing
179 * @fingers_on_2d: flag to indicate presence of fingers in 2d area
180 * @sensor_sleep: flag to indicate sleep state of sensor
181 * @wait: wait queue for touch data polling in interrupt thread
182 * @i2c_read: pointer to i2c read function
183 * @i2c_write: pointer to i2c write function
184 * @irq_enable: pointer to irq enable function
185 */
186struct synaptics_rmi4_data {
187 struct i2c_client *i2c_client;
188 struct input_dev *input_dev;
189 const struct synaptics_rmi4_platform_data *board;
190 struct synaptics_rmi4_device_info rmi4_mod_info;
191 struct regulator *regulator;
192 struct mutex rmi4_io_ctrl_mutex;
193 struct delayed_work det_work;
194 struct workqueue_struct *det_workqueue;
195 struct early_suspend early_suspend;
196 unsigned char current_page;
197 unsigned char button_0d_enabled;
198 unsigned char full_pm_cycle;
199 unsigned char num_of_rx;
200 unsigned char num_of_tx;
201 unsigned char num_of_fingers;
202 unsigned char intr_mask[MAX_INTR_REGISTERS];
203 unsigned short num_of_intr_regs;
204 unsigned short f01_query_base_addr;
205 unsigned short f01_cmd_base_addr;
206 unsigned short f01_ctrl_base_addr;
207 unsigned short f01_data_base_addr;
208 int irq;
209 int sensor_max_x;
210 int sensor_max_y;
211 bool irq_enabled;
212 bool touch_stopped;
213 bool fingers_on_2d;
214 bool sensor_sleep;
215 wait_queue_head_t wait;
216 int (*i2c_read)(struct synaptics_rmi4_data *pdata, unsigned short addr,
217 unsigned char *data, unsigned short length);
218 int (*i2c_write)(struct synaptics_rmi4_data *pdata, unsigned short addr,
219 unsigned char *data, unsigned short length);
220 int (*irq_enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
221 int (*reset_device)(struct synaptics_rmi4_data *rmi4_data);
222};
223
224enum exp_fn {
225 RMI_DEV = 0,
226 RMI_F34,
227 RMI_F54,
228 RMI_FW_UPDATER,
229 RMI_LAST,
230};
231
232struct synaptics_rmi4_exp_fn_ptr {
233 int (*read)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
234 unsigned char *data, unsigned short length);
235 int (*write)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
236 unsigned char *data, unsigned short length);
237 int (*enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
238};
239
240void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert,
241 int (*func_init)(struct synaptics_rmi4_data *rmi4_data),
242 void (*func_remove)(struct synaptics_rmi4_data *rmi4_data),
243 void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
244 unsigned char intr_mask));
245
246static inline ssize_t synaptics_rmi4_show_error(struct device *dev,
247 struct device_attribute *attr, char *buf)
248{
249 dev_warn(dev, "%s Attempted to read from write-only attribute %s\n",
250 __func__, attr->attr.name);
251 return -EPERM;
252}
253
254static inline ssize_t synaptics_rmi4_store_error(struct device *dev,
255 struct device_attribute *attr, const char *buf, size_t count)
256{
257 dev_warn(dev, "%s Attempted to write to read-only attribute %s\n",
258 __func__, attr->attr.name);
259 return -EPERM;
260}
261
262static inline void batohs(unsigned short *dest, unsigned char *src)
263{
264 *dest = src[1] * 0x100 + src[0];
265}
266
267static inline void hstoba(unsigned char *dest, unsigned short src)
268{
269 dest[0] = src % 0x100;
270 dest[1] = src / 0x100;
271}
272
273#endif