aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/rmi.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/rmi.h')
-rw-r--r--include/linux/rmi.h656
1 files changed, 656 insertions, 0 deletions
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
new file mode 100644
index 00000000000..84e121d936a
--- /dev/null
+++ b/include/linux/rmi.h
@@ -0,0 +1,656 @@
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#ifdef CONFIG_TOUCHSCREEN_SYN_RMI4_SPI
38
39#define CONFIG_RMI4_BUS
40#define CONFIG_RMI4_SPI
41#define CONFIG_RMI4_GENERIC
42#define CONFIG_RMI4_F09
43#define CONFIG_RMI4_F11
44#define CONFIG_RMI4_F19
45#define CONFIG_RMI4_F34
46#define CONFIG_RMI4_F54
47#define CONFIG_RMI4_DEV
48
49#endif
50
51// #define SYNAPTICS_SENSOR_POLL 1
52
53/* Permissions for sysfs attributes. Since the permissions policy will change
54 * on a global basis in the future, rather than edit all sysfs attrs everywhere
55 * in the driver (and risk screwing that up in the process), we use this handy
56 * set of #defines. That way when we change the policy for sysfs permissions,
57 * we only need to change them here.
58 */
59#define RMI_RO_ATTR S_IRUGO
60#define RMI_RW_ATTR (S_IRUGO | S_IWUGO)
61#define RMI_WO_ATTR S_IWUGO
62
63#define PDT_START_SCAN_LOCATION 0x00e9
64
65enum rmi_irq_polarity {
66 RMI_IRQ_ACTIVE_LOW = 0,
67 RMI_IRQ_ACTIVE_HIGH = 1
68};
69
70/**
71 * struct rmi_f11_axis_alignmen - target axis alignment
72 * @swap_axes: set to TRUE if desired to swap x- and y-axis
73 * @flip_x: set to TRUE if desired to flip direction on x-axis
74 * @flip_y: set to TRUE if desired to flip direction on y-axis
75 */
76struct rmi_f11_2d_axis_alignment {
77 bool swap_axes;
78 bool flip_x;
79 bool flip_y;
80 int clip_X_low;
81 int clip_Y_low;
82 int clip_X_high;
83 int clip_Y_high;
84 int offset_X;
85 int offset_Y;
86 int rel_report_enabled;
87};
88
89/**
90 * RMI F11 - function control register parameters
91 * Each register that has a specific bit-field setup has an accompanied
92 * register definition so that the setting can be chosen as a one-word
93 * register setting or per-bit setting.
94 */
95union rmi_f11_2d_ctrl0 {
96 struct {
97 u8 reporting_mode:3;
98 u8 abs_pos_filt:1;
99 u8 rel_pos_filt:1;
100 u8 rel_ballistics:1;
101 u8 dribble:1;
102 u8 report_beyond_clip:1;
103 };
104 u8 reg;
105};
106
107union rmi_f11_2d_ctrl1 {
108 struct {
109 u8 palm_detect_thres:4;
110 u8 motion_sensitivity:2;
111 u8 man_track_en:1;
112 u8 man_tracked_finger:1;
113 };
114 u8 reg;
115};
116
117union rmi_f11_2d_ctrl2__3 {
118 struct {
119 u8 delta_x_threshold:8;
120 u8 delta_y_threshold:8;
121 };
122 u8 regs[2];
123};
124
125union rmi_f11_2d_ctrl4 {
126 struct {
127 u8 velocity:8;
128 };
129 u8 reg;
130};
131
132union rmi_f11_2d_ctrl5 {
133 struct {
134 u8 acceleration:8;
135 };
136 u8 reg;
137};
138
139union rmi_f11_2d_ctrl6__7 {
140 struct {
141 u16 sensor_max_x_pos:12;
142 };
143 u8 regs[2];
144};
145
146union rmi_f11_2d_ctrl8__9 {
147 struct {
148 u16 sensor_max_y_pos:12;
149 };
150 u8 regs[2];
151};
152
153union rmi_f11_2d_ctrl10 {
154 struct {
155 u8 single_tap_int_enable:1;
156 u8 tap_n_hold_int_enable:1;
157 u8 double_tap_int_enable:1;
158 u8 early_tap_int_enable:1;
159 u8 flick_int_enable:1;
160 u8 press_int_enable:1;
161 u8 pinch_int_enable:1;
162 };
163 u8 reg;
164};
165
166union rmi_f11_2d_ctrl11 {
167 struct {
168 u8 palm_detect_int_enable:1;
169 u8 rotate_int_enable:1;
170 u8 touch_shape_int_enable:1;
171 u8 scroll_zone_int_enable:1;
172 u8 multi_finger_scroll_int_enable:1;
173 };
174 u8 reg;
175};
176
177union rmi_f11_2d_ctrl12 {
178 struct {
179 u8 sensor_map:7;
180 u8 xy_sel:1;
181 };
182 u8 reg;
183};
184
185union rmi_f11_2d_ctrl14 {
186 struct {
187 u8 sens_adjustment:5;
188 u8 hyst_adjustment:3;
189 };
190 u8 reg;
191};
192
193/* The configuation is controlled as per register which means that if a register
194 * is allocated for ctrl configuration one must make sure that all the bits are
195 * set accordingly for that particular register.
196 */
197struct rmi_f11_2d_ctrl {
198 union rmi_f11_2d_ctrl0 *ctrl0;
199 union rmi_f11_2d_ctrl1 *ctrl1;
200 union rmi_f11_2d_ctrl2__3 *ctrl2__3;
201 union rmi_f11_2d_ctrl4 *ctrl4;
202 union rmi_f11_2d_ctrl5 *ctrl5;
203 union rmi_f11_2d_ctrl6__7 *ctrl6__7;
204 union rmi_f11_2d_ctrl8__9 *ctrl8__9;
205 union rmi_f11_2d_ctrl10 *ctrl10;
206 union rmi_f11_2d_ctrl11 *ctrl11;
207 union rmi_f11_2d_ctrl12 *ctrl12;
208 u8 ctrl12_size;
209 union rmi_f11_2d_ctrl14 *ctrl14;
210 u8 *ctrl15;
211 u8 *ctrl16;
212 u8 *ctrl17;
213 u8 *ctrl18;
214 u8 *ctrl19;
215};
216
217struct rmi_f19_button_map {
218 unsigned char nbuttons;
219 unsigned char *map;
220};
221
222struct rmi_device_platform_data_spi {
223 int block_delay_us;
224 int split_read_block_delay_us;
225 int read_delay_us;
226 int write_delay_us;
227 int split_read_byte_delay_us;
228 int pre_delay_us;
229 int post_delay_us;
230
231 void *cs_assert_data;
232 int (*cs_assert) (const void *cs_assert_data, const bool assert);
233};
234
235struct rmi_device_platform_data {
236 char *driver_name;
237
238 int irq;
239 enum rmi_irq_polarity irq_polarity;
240 int (*gpio_config)(void *gpio_data, bool configure);
241
242 struct rmi_device_platform_data_spi spi_data;
243
244 /* function handler pdata */
245 struct rmi_f11_2d_ctrl *f11_ctrl;
246 struct rmi_f11_2d_axis_alignment axis_align;
247 struct rmi_f19_button_map *button_map;
248
249#ifdef CONFIG_PM
250 void *pm_data;
251 int (*pre_suspend) (const void *pm_data);
252 int (*post_resume) (const void *pm_data);
253#endif
254};
255
256/**
257 * struct rmi_function_descriptor - RMI function base addresses
258 * @query_base_addr: The RMI Query base address
259 * @command_base_addr: The RMI Command base address
260 * @control_base_addr: The RMI Control base address
261 * @data_base_addr: The RMI Data base address
262 * @interrupt_source_count: The number of irqs this RMI function needs
263 * @function_number: The RMI function number
264 *
265 * This struct is used when iterating the Page Description Table. The addresses
266 * are 16-bit values to include the current page address.
267 *
268 */
269struct rmi_function_descriptor {
270 u16 query_base_addr;
271 u16 command_base_addr;
272 u16 control_base_addr;
273 u16 data_base_addr;
274 u8 interrupt_source_count;
275 u8 function_number;
276 u8 function_version;
277};
278
279struct rmi_function_container;
280struct rmi_device;
281
282/**
283 * struct rmi_function_handler - an RMI function handler
284 * @func: The RMI function number
285 * @init: Callback for RMI function init
286 * @attention: Callback for RMI function attention
287 * @suspend: Callback for function suspend, returns 0 for success.
288 * @resume: Callback for RMI function resume, returns 0 for success.
289 * @remove: Callback for RMI function removal
290 *
291 * This struct describes the interface of an RMI function. These are
292 * registered to the bus using the rmi_register_function_driver() call.
293 *
294 */
295struct rmi_function_handler {
296 int func;
297 int (*init)(struct rmi_function_container *fc);
298 int (*attention)(struct rmi_function_container *fc, u8 *irq_bits);
299#ifdef CONFIG_PM
300 int (*suspend)(struct rmi_function_container *fc);
301 int (*resume)(struct rmi_function_container *fc);
302#endif
303 void (*remove)(struct rmi_function_container *fc);
304};
305
306/**
307 * struct rmi_function_device - represent an RMI function device
308 * @dev: The device created
309 *
310 * The RMI function device implements the "psuedo" device that represents
311 * an RMI4 function like function 0x11, function 0x34, etc. and is really
312 * a placeholder to be able to create sysfs attributes for each function
313 * in order to facilitate communication between user code and RMI4 functions.
314 *
315 */
316struct rmi_function_device {
317 struct device dev;
318};
319
320/**
321 * struct rmi_function_container - an element in a function handler list
322 * @list: The list
323 * @fd: The function descriptor of the RMI function
324 * @rmi_dev: Pointer to the RMI device associated with this function container
325 * @fh: The callbacks connected to this function
326 * @num_of_irqs: The number of irqs needed by this function
327 * @irq_pos: The position in the irq bitfield this function holds
328 * @data: Private data pointer
329 *
330 */
331struct rmi_function_container {
332 struct list_head list;
333
334 struct rmi_function_descriptor fd;
335 struct rmi_device *rmi_dev;
336 struct rmi_function_handler *fh;
337 struct device dev;
338
339 int num_of_irqs;
340 int irq_pos;
341 u8 *irq_mask;
342
343 void *data;
344};
345#define to_rmi_function_container(d) \
346 container_of(d, struct rmi_function_container, dev);
347#define to_rmi_function_device(d) \
348 container_of(d, struct rmi_function_device, dev);
349
350
351#ifdef CONFIG_RMI4_DEV
352
353#define RMI_CHAR_DEV_TMPBUF_SZ 128
354#define RMI_REG_ADDR_PAGE_SELECT 0xFF
355
356struct rmi_char_dev {
357 /* mutex for file operation*/
358 struct mutex mutex_file_op;
359 /* main char dev structure */
360 struct cdev main_dev;
361
362 /* register address for RMI protocol */
363 /* filp->f_pos */
364
365 /* pointer to the corresponding phys device info for this sensor */
366 /* The phys device has the pointers to read, write, etc. */
367 struct rmi_phys_device *phys;
368 /* reference count */
369 int ref_count;
370};
371
372int rmi_char_dev_register(struct rmi_phys_device *phys);
373void rmi_char_dev_unregister(struct rmi_phys_device *phys);
374
375#endif /*CONFIG_RMI4_DEV*/
376
377
378
379/**
380 * struct rmi_driver - represents an RMI driver
381 * @driver: Device driver model driver
382 * @probe: Callback for device probe
383 * @remove: Callback for device removal
384 * @shutdown: Callback for device shutdown
385 * @irq_handler: Callback for handling irqs
386 * @fh_add: Callback for function handler add
387 * @fh_remove: Callback for function handler remove
388 * @get_func_irq_mask: Callback for calculating interrupt mask
389 * @store_irq_mask: Callback for storing and replacing interrupt mask
390 * @restore_irq_mask: Callback for restoring previously stored interrupt mask
391 * @data: Private data pointer
392 *
393 * The RMI driver implements a driver on the RMI bus.
394 *
395 */
396struct rmi_driver {
397 struct device_driver driver;
398
399 int (*probe)(struct rmi_device *rmi_dev);
400 int (*remove)(struct rmi_device *rmi_dev);
401 void (*shutdown)(struct rmi_device *rmi_dev);
402 int (*irq_handler)(struct rmi_device *rmi_dev, int irq);
403 void (*fh_add)(struct rmi_device *rmi_dev,
404 struct rmi_function_handler *fh);
405 void (*fh_remove)(struct rmi_device *rmi_dev,
406 struct rmi_function_handler *fh);
407 u8* (*get_func_irq_mask)(struct rmi_device *rmi_dev,
408 struct rmi_function_container *fc);
409 int (*store_irq_mask)(struct rmi_device *rmi_dev, u8* new_interupts);
410 int (*restore_irq_mask)(struct rmi_device *rmi_dev);
411 void *data;
412};
413#define to_rmi_driver(d) \
414 container_of(d, struct rmi_driver, driver);
415
416/** struct rmi_phys_info - diagnostic information about the RMI physical
417 * device, used in the phys sysfs file.
418 * @proto String indicating the protocol being used.
419 * @tx_count Number of transmit operations.
420 * @tx_bytes Number of bytes transmitted.
421 * @tx_errs Number of errors encountered during transmit operations.
422 * @rx_count Number of receive operations.
423 * @rx_bytes Number of bytes received.
424 * @rx_errs Number of errors encountered during receive operations.
425 * @att_count Number of times ATTN assertions have been handled.
426 */
427struct rmi_phys_info {
428 char *proto;
429 long tx_count;
430 long tx_bytes;
431 long tx_errs;
432 long rx_count;
433 long rx_bytes;
434 long rx_errs;
435 long attn_count;
436};
437
438/**
439 * struct rmi_phys_device - represent an RMI physical device
440 * @dev: Pointer to the communication device, e.g. i2c or spi
441 * @rmi_dev: Pointer to the RMI device
442 * @write: Callback for write
443 * @write_block: Callback for writing a block of data
444 * @read: Callback for read
445 * @read_block: Callback for reading a block of data
446 * @data: Private data pointer
447 *
448 * The RMI physical device implements the glue between different communication
449 * buses such as I2C and SPI.
450 *
451 */
452struct rmi_phys_device {
453 struct device *dev;
454 struct rmi_device *rmi_dev;
455
456 int (*write)(struct rmi_phys_device *phys, u16 addr, u8 data);
457 int (*write_block)(struct rmi_phys_device *phys, u16 addr, u8 *buf,
458 int len);
459 int (*read)(struct rmi_phys_device *phys, u16 addr, u8 *buf);
460 int (*read_block)(struct rmi_phys_device *phys, u16 addr, u8 *buf,
461 int len);
462
463 int (*enable_device) (struct rmi_phys_device *phys);
464 void (*disable_device) (struct rmi_phys_device *phys);
465
466 void *data;
467
468 struct rmi_phys_info info;
469
470#ifdef CONFIG_RMI4_DEV
471 /* pointer to attention char device and char device */
472 struct rmi_char_dev *char_dev;
473 struct class *rmi_char_device_class;
474#endif /*CONFIG_RMI4_DEV*/
475};
476
477/**
478 * struct rmi_device - represents an RMI device
479 * @dev: The device created for the RMI bus
480 * @driver: Pointer to associated driver
481 * @phys: Pointer to the physical interface
482 * @early_suspend_handler: Pointers to early_suspend and late_resume, if
483 * configured.
484 *
485 * This structs represent an RMI device.
486 *
487 */
488struct rmi_device {
489 struct device dev;
490
491 struct rmi_driver *driver;
492 struct rmi_phys_device *phys;
493
494#ifdef CONFIG_HAS_EARLYSUSPEND
495 struct early_suspend early_suspend_handler;
496#endif
497};
498#define to_rmi_device(d) container_of(d, struct rmi_device, dev);
499#define to_rmi_platform_data(d) ((d)->phys->dev->platform_data);
500
501static inline void rmi_set_driverdata(struct rmi_device *d, void *data)
502{
503 dev_set_drvdata(&d->dev, data);
504}
505
506static inline void *rmi_get_driverdata(struct rmi_device *d)
507{
508 return dev_get_drvdata(&d->dev);
509}
510
511/**
512 * rmi_read - RMI read byte
513 * @d: Pointer to an RMI device
514 * @addr: The address to read from
515 * @buf: The read buffer
516 *
517 * Reads a byte of data using the underlaying physical protocol in to buf. It
518 * returns zero or a negative error code.
519 */
520static inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf)
521{
522 return d->phys->read(d->phys, addr, buf);
523}
524
525/**
526 * rmi_read_block - RMI read block
527 * @d: Pointer to an RMI device
528 * @addr: The start address to read from
529 * @buf: The read buffer
530 * @len: Length of the read buffer
531 *
532 * Reads a block of byte data using the underlaying physical protocol in to buf.
533 * It returns the amount of bytes read or a negative error code.
534 */
535static inline int rmi_read_block(struct rmi_device *d, u16 addr, u8 *buf,
536 int len)
537{
538 return d->phys->read_block(d->phys, addr, buf, len);
539}
540
541/**
542 * rmi_write - RMI write byte
543 * @d: Pointer to an RMI device
544 * @addr: The address to write to
545 * @data: The data to write
546 *
547 * Writes a byte from buf using the underlaying physical protocol. It
548 * returns zero or a negative error code.
549 */
550static inline int rmi_write(struct rmi_device *d, u16 addr, u8 data)
551{
552 return d->phys->write(d->phys, addr, data);
553}
554
555/**
556 * rmi_write_block - RMI write block
557 * @d: Pointer to an RMI device
558 * @addr: The start address to write to
559 * @buf: The write buffer
560 * @len: Length of the write buffer
561 *
562 * Writes a block of byte data from buf using the underlaying physical protocol.
563 * It returns the amount of bytes written or a negative error code.
564 */
565static inline int rmi_write_block(struct rmi_device *d, u16 addr, u8 *buf,
566 int len)
567{
568 return d->phys->write_block(d->phys, addr, buf, len);
569}
570
571/**
572 * rmi_register_driver - register rmi driver
573 * @driver: the driver to register
574 *
575 * This function registers an RMI driver to the RMI bus.
576 */
577int rmi_register_driver(struct rmi_driver *driver);
578
579/**
580 * rmi_unregister_driver - unregister rmi driver
581 * @driver: the driver to unregister
582 *
583 * This function unregisters an RMI driver to the RMI bus.
584 */
585void rmi_unregister_driver(struct rmi_driver *driver);
586
587/**
588 * rmi_register_phys_device - register a physical device connection
589 * @phys: the physical driver to register
590 *
591 * This function registers a physical driver to the RMI bus. These drivers
592 * provide a communication layer for the drivers connected to the bus, e.g.
593 * I2C, SPI and so on.
594 */
595int rmi_register_phys_device(struct rmi_phys_device *phys);
596
597/**
598 * rmi_unregister_phys_device - unregister a physical device connection
599 * @phys: the physical driver to unregister
600 *
601 * This function unregisters a physical driver from the RMI bus.
602 */
603void rmi_unregister_phys_device(struct rmi_phys_device *phys);
604
605/**
606 * rmi_register_function_driver - register an RMI function driver
607 * @fh: the function handler to register
608 *
609 * This function registers support for a new RMI function to the bus. All
610 * drivers on the bus will be notified of the presence of the new function
611 * driver.
612 */
613int rmi_register_function_driver(struct rmi_function_handler *fh);
614
615/**
616 * rmi_unregister_function_driver - unregister an RMI function driver
617 * @fh: the function handler to unregister
618 *
619 * This function unregisters a RMI function from the RMI bus. All drivers on
620 * the bus will be notified of the removal of a function driver.
621 */
622void rmi_unregister_function_driver(struct rmi_function_handler *fh);
623
624/**
625 * rmi_get_function_handler - get a pointer to specified RMI function
626 * @id: the RMI function id
627 *
628 * This function gets the specified RMI function handler from the list of
629 * supported functions.
630 */
631struct rmi_function_handler *rmi_get_function_handler(int id);
632
633/* Utility routine to handle writes to read-only attributes. Hopefully
634 * this will never happen, but if the user does something stupid, we
635 * don't want to accept it quietly.
636 */
637ssize_t rmi_store_error(struct device *dev,
638 struct device_attribute *attr,
639 const char *buf, size_t count);
640
641/* Utility routine to handle reads to write-only attributes. Hopefully
642 * this will never happen, but if the user does something stupid, we
643 * don't want to accept it quietly.
644 */
645ssize_t rmi_show_error(struct device *dev,
646 struct device_attribute *attr,
647 char *buf);
648
649/* utility function for bit access of u8*'s */
650void u8_set_bit(u8 *target, int pos);
651void u8_clear_bit(u8 *target, int pos);
652bool u8_is_set(u8 *target, int pos);
653bool u8_is_any_set(u8 *target, int size);
654void u8_or(u8 *dest, u8* target1, u8* target2, int size);
655void u8_and(u8 *dest, u8* target1, u8* target2, int size);
656#endif