Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 1 | /* |
| 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 Maloche | 1a53b61 | 2013-01-18 15:25:15 -0800 | [diff] [blame] | 8 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 9 | * |
| 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 Chin | 5d2999d | 2013-02-22 15:09:29 -0800 | [diff] [blame] | 24 | #define SYNAPTICS_DS4 (1 << 0) |
| 25 | #define SYNAPTICS_DS5 (1 << 1) |
| 26 | #define SYNAPTICS_DSX_DRIVER_PRODUCT SYNAPTICS_DS4 |
Alexandra Chin | c556cf0 | 2013-03-19 17:46:05 -0700 | [diff] [blame] | 27 | #define SYNAPTICS_DSX_DRIVER_VERSION 0x1004 |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 28 | |
| 29 | #include <linux/version.h> |
| 30 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 31 | #include <linux/earlysuspend.h> |
| 32 | #endif |
| 33 | |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 34 | #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 | */ |
| 76 | struct 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 | */ |
| 92 | struct 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 | */ |
| 113 | struct 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 | */ |
| 140 | struct 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 Chin | d5591a6 | 2013-02-07 12:59:15 -0800 | [diff] [blame] | 151 | unsigned char config_id[3]; |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 152 | 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 |
Alexandra Chin | fb798fa | 2013-03-26 17:15:38 -0700 | [diff] [blame] | 180 | * @flip_x: set to TRUE if desired to flip direction on x-axis |
| 181 | * @flip_y: set to TRUE if desired to flip direction on y-axis |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 182 | * @sensor_sleep: flag to indicate sleep state of sensor |
| 183 | * @wait: wait queue for touch data polling in interrupt thread |
| 184 | * @i2c_read: pointer to i2c read function |
| 185 | * @i2c_write: pointer to i2c write function |
| 186 | * @irq_enable: pointer to irq enable function |
| 187 | */ |
| 188 | struct synaptics_rmi4_data { |
| 189 | struct i2c_client *i2c_client; |
| 190 | struct input_dev *input_dev; |
| 191 | const struct synaptics_rmi4_platform_data *board; |
| 192 | struct synaptics_rmi4_device_info rmi4_mod_info; |
Amy Maloche | 1a53b61 | 2013-01-18 15:25:15 -0800 | [diff] [blame] | 193 | struct regulator *vdd; |
| 194 | struct regulator *vcc_i2c; |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 195 | struct mutex rmi4_io_ctrl_mutex; |
| 196 | struct delayed_work det_work; |
| 197 | struct workqueue_struct *det_workqueue; |
Anurag Singh | f85607a | 2013-03-10 18:29:40 -0700 | [diff] [blame] | 198 | #ifdef CONFIG_HAS_EARLYSUSPEND |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 199 | struct early_suspend early_suspend; |
Anurag Singh | f85607a | 2013-03-10 18:29:40 -0700 | [diff] [blame] | 200 | #endif |
Amy Maloche | cb83583 | 2013-03-26 18:06:05 -0700 | [diff] [blame] | 201 | const char *fw_image_name; |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 202 | unsigned char current_page; |
| 203 | unsigned char button_0d_enabled; |
| 204 | unsigned char full_pm_cycle; |
| 205 | unsigned char num_of_rx; |
| 206 | unsigned char num_of_tx; |
| 207 | unsigned char num_of_fingers; |
| 208 | unsigned char intr_mask[MAX_INTR_REGISTERS]; |
| 209 | unsigned short num_of_intr_regs; |
| 210 | unsigned short f01_query_base_addr; |
| 211 | unsigned short f01_cmd_base_addr; |
| 212 | unsigned short f01_ctrl_base_addr; |
| 213 | unsigned short f01_data_base_addr; |
| 214 | int irq; |
| 215 | int sensor_max_x; |
| 216 | int sensor_max_y; |
| 217 | bool irq_enabled; |
| 218 | bool touch_stopped; |
| 219 | bool fingers_on_2d; |
| 220 | bool sensor_sleep; |
Alexandra Chin | fb798fa | 2013-03-26 17:15:38 -0700 | [diff] [blame] | 221 | bool flip_x; |
| 222 | bool flip_y; |
Alexandra Chin | 669d27c | 2012-12-24 15:42:30 +0800 | [diff] [blame] | 223 | wait_queue_head_t wait; |
| 224 | int (*i2c_read)(struct synaptics_rmi4_data *pdata, unsigned short addr, |
| 225 | unsigned char *data, unsigned short length); |
| 226 | int (*i2c_write)(struct synaptics_rmi4_data *pdata, unsigned short addr, |
| 227 | unsigned char *data, unsigned short length); |
| 228 | int (*irq_enable)(struct synaptics_rmi4_data *rmi4_data, bool enable); |
| 229 | int (*reset_device)(struct synaptics_rmi4_data *rmi4_data); |
| 230 | }; |
| 231 | |
| 232 | enum exp_fn { |
| 233 | RMI_DEV = 0, |
| 234 | RMI_F34, |
| 235 | RMI_F54, |
| 236 | RMI_FW_UPDATER, |
| 237 | RMI_LAST, |
| 238 | }; |
| 239 | |
| 240 | struct synaptics_rmi4_exp_fn_ptr { |
| 241 | int (*read)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr, |
| 242 | unsigned char *data, unsigned short length); |
| 243 | int (*write)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr, |
| 244 | unsigned char *data, unsigned short length); |
| 245 | int (*enable)(struct synaptics_rmi4_data *rmi4_data, bool enable); |
| 246 | }; |
| 247 | |
| 248 | void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert, |
| 249 | int (*func_init)(struct synaptics_rmi4_data *rmi4_data), |
| 250 | void (*func_remove)(struct synaptics_rmi4_data *rmi4_data), |
| 251 | void (*func_attn)(struct synaptics_rmi4_data *rmi4_data, |
| 252 | unsigned char intr_mask)); |
| 253 | |
| 254 | static inline ssize_t synaptics_rmi4_show_error(struct device *dev, |
| 255 | struct device_attribute *attr, char *buf) |
| 256 | { |
| 257 | dev_warn(dev, "%s Attempted to read from write-only attribute %s\n", |
| 258 | __func__, attr->attr.name); |
| 259 | return -EPERM; |
| 260 | } |
| 261 | |
| 262 | static inline ssize_t synaptics_rmi4_store_error(struct device *dev, |
| 263 | struct device_attribute *attr, const char *buf, size_t count) |
| 264 | { |
| 265 | dev_warn(dev, "%s Attempted to write to read-only attribute %s\n", |
| 266 | __func__, attr->attr.name); |
| 267 | return -EPERM; |
| 268 | } |
| 269 | |
| 270 | static inline void batohs(unsigned short *dest, unsigned char *src) |
| 271 | { |
| 272 | *dest = src[1] * 0x100 + src[0]; |
| 273 | } |
| 274 | |
| 275 | static inline void hstoba(unsigned char *dest, unsigned short src) |
| 276 | { |
| 277 | dest[0] = src % 0x100; |
| 278 | dest[1] = src / 0x100; |
| 279 | } |
| 280 | |
| 281 | #endif |