Flemmard | ce3c2c3 | 2013-05-23 16:53:44 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2011 Synaptics Incorporated |
| 3 | * Copyright (c) 2011 Unixphere |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | #ifndef _RMI_H |
| 20 | #define _RMI_H |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/lockdep.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/device.h> |
| 26 | #include <linux/cdev.h> |
| 27 | #include <linux/mutex.h> |
| 28 | #include <linux/stat.h> |
| 29 | #include <linux/wait.h> |
| 30 | #include <linux/list.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | |
| 33 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 34 | #include <linux/earlysuspend.h> |
| 35 | #endif |
| 36 | |
| 37 | |
| 38 | #define RMI_RO_ATTR S_IRUGO |
| 39 | #define RMI_RW_ATTR (S_IRUGO | S_IWUGO) |
| 40 | #define RMI_WO_ATTR S_IWUGO |
| 41 | |
| 42 | #define PDT_START_SCAN_LOCATION 0x00e9 |
| 43 | |
| 44 | enum rmi_irq_polarity { |
| 45 | RMI_IRQ_ACTIVE_LOW = 0, |
| 46 | RMI_IRQ_ACTIVE_HIGH = 1 |
| 47 | }; |
| 48 | |
| 49 | struct rmi_f11_2d_axis_alignment { |
| 50 | bool swap_axes; |
| 51 | bool flip_x; |
| 52 | bool flip_y; |
| 53 | int clip_X_low; |
| 54 | int clip_Y_low; |
| 55 | int clip_X_high; |
| 56 | int clip_Y_high; |
| 57 | int offset_X; |
| 58 | int offset_Y; |
| 59 | int rel_report_enabled; |
| 60 | }; |
| 61 | |
| 62 | union rmi_f11_2d_ctrl0 { |
| 63 | struct { |
| 64 | u8 reporting_mode:3; |
| 65 | u8 abs_pos_filt:1; |
| 66 | u8 rel_pos_filt:1; |
| 67 | u8 rel_ballistics:1; |
| 68 | u8 dribble:1; |
| 69 | u8 report_beyond_clip:1; |
| 70 | }; |
| 71 | u8 reg; |
| 72 | }; |
| 73 | |
| 74 | union rmi_f11_2d_ctrl1 { |
| 75 | struct { |
| 76 | u8 palm_detect_thres:4; |
| 77 | u8 motion_sensitivity:2; |
| 78 | u8 man_track_en:1; |
| 79 | u8 man_tracked_finger:1; |
| 80 | }; |
| 81 | u8 reg; |
| 82 | }; |
| 83 | |
| 84 | union rmi_f11_2d_ctrl2__3 { |
| 85 | struct { |
| 86 | u8 delta_x_threshold:8; |
| 87 | u8 delta_y_threshold:8; |
| 88 | }; |
| 89 | u8 regs[2]; |
| 90 | }; |
| 91 | |
| 92 | union rmi_f11_2d_ctrl4 { |
| 93 | struct { |
| 94 | u8 velocity:8; |
| 95 | }; |
| 96 | u8 reg; |
| 97 | }; |
| 98 | |
| 99 | union rmi_f11_2d_ctrl5 { |
| 100 | struct { |
| 101 | u8 acceleration:8; |
| 102 | }; |
| 103 | u8 reg; |
| 104 | }; |
| 105 | |
| 106 | union rmi_f11_2d_ctrl6__7 { |
| 107 | struct { |
| 108 | u16 sensor_max_x_pos:12; |
| 109 | }; |
| 110 | u8 regs[2]; |
| 111 | }; |
| 112 | |
| 113 | union rmi_f11_2d_ctrl8__9 { |
| 114 | struct { |
| 115 | u16 sensor_max_y_pos:12; |
| 116 | }; |
| 117 | u8 regs[2]; |
| 118 | }; |
| 119 | |
| 120 | union rmi_f11_2d_ctrl10 { |
| 121 | struct { |
| 122 | u8 single_tap_int_enable:1; |
| 123 | u8 tap_n_hold_int_enable:1; |
| 124 | u8 double_tap_int_enable:1; |
| 125 | u8 early_tap_int_enable:1; |
| 126 | u8 flick_int_enable:1; |
| 127 | u8 press_int_enable:1; |
| 128 | u8 pinch_int_enable:1; |
| 129 | }; |
| 130 | u8 reg; |
| 131 | }; |
| 132 | |
| 133 | union rmi_f11_2d_ctrl11 { |
| 134 | struct { |
| 135 | u8 palm_detect_int_enable:1; |
| 136 | u8 rotate_int_enable:1; |
| 137 | u8 touch_shape_int_enable:1; |
| 138 | u8 scroll_zone_int_enable:1; |
| 139 | u8 multi_finger_scroll_int_enable:1; |
| 140 | }; |
| 141 | u8 reg; |
| 142 | }; |
| 143 | |
| 144 | union rmi_f11_2d_ctrl12 { |
| 145 | struct { |
| 146 | u8 sensor_map:7; |
| 147 | u8 xy_sel:1; |
| 148 | }; |
| 149 | u8 reg; |
| 150 | }; |
| 151 | |
| 152 | union rmi_f11_2d_ctrl14 { |
| 153 | struct { |
| 154 | u8 sens_adjustment:5; |
| 155 | u8 hyst_adjustment:3; |
| 156 | }; |
| 157 | u8 reg; |
| 158 | }; |
| 159 | |
| 160 | struct rmi_f11_2d_ctrl { |
| 161 | union rmi_f11_2d_ctrl0 *ctrl0; |
| 162 | union rmi_f11_2d_ctrl1 *ctrl1; |
| 163 | union rmi_f11_2d_ctrl2__3 *ctrl2__3; |
| 164 | union rmi_f11_2d_ctrl4 *ctrl4; |
| 165 | union rmi_f11_2d_ctrl5 *ctrl5; |
| 166 | union rmi_f11_2d_ctrl6__7 *ctrl6__7; |
| 167 | union rmi_f11_2d_ctrl8__9 *ctrl8__9; |
| 168 | union rmi_f11_2d_ctrl10 *ctrl10; |
| 169 | union rmi_f11_2d_ctrl11 *ctrl11; |
| 170 | union rmi_f11_2d_ctrl12 *ctrl12; |
| 171 | u8 ctrl12_size; |
| 172 | union rmi_f11_2d_ctrl14 *ctrl14; |
| 173 | u8 *ctrl15; |
| 174 | u8 *ctrl16; |
| 175 | u8 *ctrl17; |
| 176 | u8 *ctrl18; |
| 177 | u8 *ctrl19; |
| 178 | }; |
| 179 | |
| 180 | struct rmi_f19_button_map { |
| 181 | unsigned char nbuttons; |
| 182 | unsigned char *map; |
| 183 | }; |
| 184 | |
| 185 | struct rmi_device_platform_data_spi { |
| 186 | int block_delay_us; |
| 187 | int split_read_block_delay_us; |
| 188 | int byte_delay_us; |
| 189 | int split_read_byte_delay_us; |
| 190 | int pre_delay_us; |
| 191 | int post_delay_us; |
| 192 | |
| 193 | void *cs_assert_data; |
| 194 | int (*cs_assert) (const void *cs_assert_data, const bool assert); |
| 195 | }; |
| 196 | |
| 197 | struct rmi_device_platform_data { |
| 198 | char *driver_name; |
| 199 | |
| 200 | int irq_no; |
| 201 | int irq; |
| 202 | enum rmi_irq_polarity irq_polarity; |
| 203 | int (*gpio_config)(void); |
| 204 | |
| 205 | struct rmi_device_platform_data_spi spi_v2; |
| 206 | |
| 207 | |
| 208 | struct rmi_f11_2d_ctrl *f11_ctrl; |
| 209 | struct rmi_f11_2d_axis_alignment axis_align; |
| 210 | struct rmi_f19_button_map *button_map; |
| 211 | |
| 212 | #ifdef CONFIG_PM |
| 213 | void *pm_data; |
| 214 | int (*pre_suspend) (const void *pm_data); |
| 215 | int (*post_resume) (const void *pm_data); |
| 216 | #endif |
| 217 | }; |
| 218 | |
| 219 | struct rmi_function_descriptor { |
| 220 | u16 query_base_addr; |
| 221 | u16 command_base_addr; |
| 222 | u16 control_base_addr; |
| 223 | u16 data_base_addr; |
| 224 | u8 interrupt_source_count; |
| 225 | u8 function_number; |
| 226 | u8 function_version; |
| 227 | }; |
| 228 | |
| 229 | struct rmi_function_container; |
| 230 | struct rmi_device; |
| 231 | |
| 232 | struct rmi_function_handler { |
| 233 | int func; |
| 234 | int (*init)(struct rmi_function_container *fc); |
| 235 | int (*attention)(struct rmi_function_container *fc, u8 *irq_bits); |
| 236 | #ifdef CONFIG_PM |
| 237 | int (*suspend)(struct rmi_function_container *fc); |
| 238 | int (*resume)(struct rmi_function_container *fc); |
| 239 | #endif |
| 240 | void (*remove)(struct rmi_function_container *fc); |
| 241 | }; |
| 242 | |
| 243 | struct rmi_function_device { |
| 244 | struct device dev; |
| 245 | }; |
| 246 | |
| 247 | struct rmi_function_container { |
| 248 | struct list_head list; |
| 249 | |
| 250 | struct rmi_function_descriptor fd; |
| 251 | struct rmi_device *rmi_dev; |
| 252 | struct rmi_function_handler *fh; |
| 253 | struct device dev; |
| 254 | |
| 255 | int num_of_irqs; |
| 256 | int irq_pos; |
| 257 | u8 *irq_mask; |
| 258 | |
| 259 | void *data; |
| 260 | }; |
| 261 | #define to_rmi_function_container(d) \ |
| 262 | container_of(d, struct rmi_function_container, dev); |
| 263 | #define to_rmi_function_device(d) \ |
| 264 | container_of(d, struct rmi_function_device, dev); |
| 265 | |
| 266 | |
| 267 | |
| 268 | #define RMI_CHAR_DEV_TMPBUF_SZ 128 |
| 269 | #define RMI_REG_ADDR_PAGE_SELECT 0xFF |
| 270 | |
| 271 | struct rmi_char_dev { |
| 272 | |
| 273 | struct mutex mutex_file_op; |
| 274 | |
| 275 | struct cdev main_dev; |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | struct rmi_phys_device *phys; |
| 283 | |
| 284 | int ref_count; |
| 285 | }; |
| 286 | |
| 287 | int rmi_char_dev_register(void); |
| 288 | void rmi_char_dev_unregister(struct rmi_phys_device *phys); |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | struct rmi_driver { |
| 294 | struct device_driver driver; |
| 295 | |
| 296 | int (*probe)(struct rmi_device *rmi_dev); |
| 297 | int (*remove)(struct rmi_device *rmi_dev); |
| 298 | void (*shutdown)(struct rmi_device *rmi_dev); |
| 299 | int (*irq_handler)(struct rmi_device *rmi_dev, int irq); |
| 300 | void (*fh_add)(struct rmi_device *rmi_dev, |
| 301 | struct rmi_function_handler *fh); |
| 302 | void (*fh_remove)(struct rmi_device *rmi_dev, |
| 303 | struct rmi_function_handler *fh); |
| 304 | u8* (*get_func_irq_mask)(struct rmi_device *rmi_dev, |
| 305 | struct rmi_function_container *fc); |
| 306 | int (*store_irq_mask)(struct rmi_device *rmi_dev, u8* new_interupts); |
| 307 | int (*restore_irq_mask)(struct rmi_device *rmi_dev); |
| 308 | void *data; |
| 309 | }; |
| 310 | #define to_rmi_driver(d) \ |
| 311 | container_of(d, struct rmi_driver, driver); |
| 312 | |
| 313 | struct rmi_phys_info { |
| 314 | char *proto; |
| 315 | long tx_count; |
| 316 | long tx_bytes; |
| 317 | long tx_errs; |
| 318 | long rx_count; |
| 319 | long rx_bytes; |
| 320 | long rx_errs; |
| 321 | long attn_count; |
| 322 | long attn; |
| 323 | }; |
| 324 | |
| 325 | struct rmi_phys_device { |
| 326 | struct device *dev; |
| 327 | struct rmi_device *rmi_dev; |
| 328 | |
| 329 | int (*write)(struct rmi_phys_device *phys, u16 addr, u8 data); |
| 330 | int (*write_block)(struct rmi_phys_device *phys, u16 addr, u8 *buf, |
| 331 | int len); |
| 332 | int (*read)(struct rmi_phys_device *phys, u16 addr, u8 *buf); |
| 333 | int (*read_block)(struct rmi_phys_device *phys, u16 addr, u8 *buf, |
| 334 | int len); |
| 335 | |
| 336 | int (*enable_device) (struct rmi_phys_device *phys); |
| 337 | void (*disable_device) (struct rmi_phys_device *phys); |
| 338 | |
| 339 | void *data; |
| 340 | |
| 341 | struct rmi_phys_info info; |
| 342 | |
| 343 | |
| 344 | struct rmi_char_dev *char_dev; |
| 345 | struct class *rmi_char_device_class; |
| 346 | }; |
| 347 | |
| 348 | struct rmi_device { |
| 349 | struct device dev; |
| 350 | |
| 351 | struct rmi_driver *driver; |
| 352 | struct rmi_phys_device *phys; |
| 353 | |
| 354 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 355 | struct early_suspend early_suspend_handler; |
| 356 | #endif |
| 357 | }; |
| 358 | #define to_rmi_device(d) container_of(d, struct rmi_device, dev); |
| 359 | #define to_rmi_platform_data(d) ((d)->phys->dev->platform_data); |
| 360 | |
| 361 | int i2c_rmi_read(uint16_t addr, uint8_t *data, uint16_t length); |
| 362 | int i2c_rmi_write(uint16_t addr, uint8_t *data, uint16_t length); |
| 363 | |
| 364 | static inline void rmi_set_driverdata(struct rmi_device *d, void *data) |
| 365 | { |
| 366 | dev_set_drvdata(&d->dev, data); |
| 367 | } |
| 368 | |
| 369 | static inline void *rmi_get_driverdata(struct rmi_device *d) |
| 370 | { |
| 371 | return dev_get_drvdata(&d->dev); |
| 372 | } |
| 373 | |
| 374 | static inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf) |
| 375 | { |
| 376 | return d->phys->read(d->phys, addr, buf); |
| 377 | } |
| 378 | |
| 379 | static inline int rmi_read_block(struct rmi_device *d, u16 addr, u8 *buf, |
| 380 | int len) |
| 381 | { |
| 382 | return d->phys->read_block(d->phys, addr, buf, len); |
| 383 | } |
| 384 | |
| 385 | static inline int rmi_write(struct rmi_device *d, u16 addr, u8 data) |
| 386 | { |
| 387 | return d->phys->write(d->phys, addr, data); |
| 388 | } |
| 389 | |
| 390 | static inline int rmi_write_block(struct rmi_device *d, u16 addr, u8 *buf, |
| 391 | int len) |
| 392 | { |
| 393 | return d->phys->write_block(d->phys, addr, buf, len); |
| 394 | } |
| 395 | |
| 396 | int rmi_register_driver(struct rmi_driver *driver); |
| 397 | |
| 398 | void rmi_unregister_driver(struct rmi_driver *driver); |
| 399 | |
| 400 | int rmi_register_phys_device(struct rmi_phys_device *phys); |
| 401 | |
| 402 | void rmi_unregister_phys_device(struct rmi_phys_device *phys); |
| 403 | |
| 404 | int rmi_register_function_driver(struct rmi_function_handler *fh); |
| 405 | |
| 406 | void rmi_unregister_function_driver(struct rmi_function_handler *fh); |
| 407 | |
| 408 | struct rmi_function_handler *rmi_get_function_handler(int id); |
| 409 | |
| 410 | ssize_t rmi_store_error(struct device *dev, |
| 411 | struct device_attribute *attr, |
| 412 | const char *buf, size_t count); |
| 413 | |
| 414 | ssize_t rmi_show_error(struct device *dev, |
| 415 | struct device_attribute *attr, |
| 416 | char *buf); |
| 417 | |
| 418 | void u8_set_bit(u8 *target, int pos); |
| 419 | void u8_clear_bit(u8 *target, int pos); |
| 420 | bool u8_is_set(u8 *target, int pos); |
| 421 | bool u8_is_any_set(u8 *target, int size); |
| 422 | void u8_or(u8 *dest, u8* target1, u8* target2, int size); |
| 423 | void u8_and(u8 *dest, u8* target1, u8* target2, int size); |
| 424 | #endif |