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