blob: 63d255538775da89744a9f3e5fd4d55ca279e716 [file] [log] [blame]
Taniya Das6f0884b2011-09-06 16:24:21 +05301/**
2 *
3 * Synaptics Register Mapped Interface (RMI4) - RMI Sensor Module Header.
4 * Copyright (C) 2007 - 2011, Synaptics Incorporated
5 *
6 */
7/*
8 *
9 * This file is licensed under the GPL2 license.
10 *
11 *############################################################################
12 * GPL
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License version 2 as published
16 * by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 *
23 *############################################################################
24 */
25
26#include <linux/device.h>
27
28#ifndef _RMI_SENSOR_H
29#define _RMI_SENSOR_H
30
31#include <linux/input/rmi_platformdata.h>
32
33struct rmi_sensor_driver {
34 struct module *module;
35 struct device_driver drv;
36 struct rmi_sensor_device *sensor_device;
37
38 /* Attention Function
39 * This function is called by the low level isr in the physical
40 * driver. It merely schedules work to be done.
41 */
42 void (*attention)(struct rmi_phys_driver *physdrvr, int instance);
43 /* Probe Function
44 * This function is called to give the sensor driver layer an
45 * opportunity to claim an RMI device. The sensor layer cannot
46 * read RMI registers at this point since the rmi physical driver
47 * has not been bound to it yet. Defer that to the config
48 * function call which occurs immediately after a successful probe.
49 */
50 int (*probe)(struct rmi_sensor_driver *sensor);
51 /* Config Function
52 * This function is called after a successful probe. It gives the
53 * sensor driver an opportunity to query and/or configure an RMI
54 * device before data starts flowing.
55 */
56 void (*config)(struct rmi_sensor_driver *sensor);
57
58 /* Functions can call this in order to dispatch IRQs. */
59 void (*dispatchIRQs)(struct rmi_sensor_driver *sensor,
60 unsigned int irqStatus);
61
62 /* Register Functions
63 * This function is called in the rmi bus
64 * driver to have the sensor driver scan for any supported
65 * functions on the sensor and add devices for each one.
66 */
67 void (*rmi_sensor_register_functions)(struct rmi_sensor_driver
68 *sensor);
69
70 unsigned int interruptRegisterCount;
71
72 bool polling_required;
73
74 /* pointer to the corresponding phys driver info for this sensor */
75 /* The phys driver has the pointers to read, write, etc. */
76 struct rmi_phys_driver *rpd;
77
78 struct hrtimer timer;
79 struct work_struct work;
80 bool workIsReady;
81
82 /* This list is for keeping around the list of sensors.
83 * Every time that a physical device is detected by the
84 * physical layer - be it i2c, spi, or some other - then
85 * we need to bind the physical layer to the device. When
86 * the Page Descriptor Table is scanned and when Function $01
87 * is found then a new sensor device is created. The corresponding
88 * rmi_phys_driver struct pointer needs to be bound to the new
89 * sensor since Function $01 will be used to control and get
90 * interrupt information about the particular data source that is
91 * doing the interrupt. The rmi_phys_driver contains the pointers
92 * to the particular read, write, read_multiple, write_multiple
93 * functions for this device. This rmi_phys_driver struct will
94 * have to be up-bound to any drivers upstream that need it.
95 */
96
97 /* Standard kernel linked list implementation.
98 * Documentation on how to use it can be found at
99 * http://isis.poly.edu/kulesh/stuff/src/klist/.
100 */
101 struct list_head sensor_drivers; /* link sensor drivers into list */
102
103 struct list_head functions; /* List of rmi_function_infos */
104 /* Per function initialization data. */
105 struct rmi_functiondata_list *perfunctiondata;
106};
107
108/* macro to get the pointer to the device_driver struct from the sensor */
109#define to_rmi_sensor_driver(drv) container_of(drv, \
110 struct rmi_sensor_driver, drv);
111
112struct rmi_sensor_device {
113 struct rmi_sensor_driver *driver;
114 struct device dev;
115
116 /* Standard kernel linked list implementation.
117 * Documentation on how to use it can be found at
118 * http://isis.poly.edu/kulesh/stuff/src/klist/.
119 */
120 struct list_head sensors; /* link sensors into list */
121};
122
123int rmi_sensor_register_device(struct rmi_sensor_device *dev, int index);
124int rmi_sensor_register_driver(struct rmi_sensor_driver *driver);
125int rmi_sensor_register_functions(struct rmi_sensor_driver *sensor);
126bool rmi_polling_required(struct rmi_sensor_driver *sensor);
127
128static inline void *rmi_sensor_get_functiondata(struct rmi_sensor_driver
129 *driver, unsigned char function_index)
130{
131 int i;
132 if (driver->perfunctiondata) {
133 for (i = 0; i < driver->perfunctiondata->count; i++) {
134 if (driver->perfunctiondata->functiondata[i].
135 function_index == function_index)
136 return driver->perfunctiondata->
137 functiondata[i].data;
138 }
139 }
140 return NULL;
141}
142
143#endif