diff options
author | Nick Dyer <nick@shmanahar.org> | 2016-07-18 17:10:31 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-08-23 15:29:09 -0400 |
commit | d6a39404984094c5e20e1d17a91036ac6b125731 (patch) | |
tree | cb3ee42f217ea9dcb51bda606c03f4a54445591c /drivers/input | |
parent | b2fe22d0cf64708c50c26f11b3da8b79809c699b (diff) |
[media] Input: atmel_mxt_ts - add support for T37 diagnostic data
Atmel maXTouch devices have a T37 object which can be used to read raw
touch deltas from the device. This consists of an array of 16-bit
integers, one for each node on the touchscreen matrix.
Signed-off-by: Nick Dyer <nick@shmanahar.org>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 6 | ||||
-rw-r--r-- | drivers/input/touchscreen/atmel_mxt_ts.c | 159 |
2 files changed, 165 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 2fb1f430a431..f0eef41e49e5 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -115,6 +115,12 @@ config TOUCHSCREEN_ATMEL_MXT | |||
115 | To compile this driver as a module, choose M here: the | 115 | To compile this driver as a module, choose M here: the |
116 | module will be called atmel_mxt_ts. | 116 | module will be called atmel_mxt_ts. |
117 | 117 | ||
118 | config TOUCHSCREEN_ATMEL_MXT_T37 | ||
119 | bool "Support T37 Diagnostic Data" | ||
120 | depends on TOUCHSCREEN_ATMEL_MXT | ||
121 | help | ||
122 | Say Y here if you want support for the T37 Diagnostic Data object. | ||
123 | |||
118 | config TOUCHSCREEN_AUO_PIXCIR | 124 | config TOUCHSCREEN_AUO_PIXCIR |
119 | tristate "AUO in-cell touchscreen using Pixcir ICs" | 125 | tristate "AUO in-cell touchscreen using Pixcir ICs" |
120 | depends on I2C | 126 | depends on I2C |
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 5af7907d0af4..0048233255f2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c | |||
@@ -124,6 +124,19 @@ struct t9_range { | |||
124 | #define MXT_COMMS_CTRL 0 | 124 | #define MXT_COMMS_CTRL 0 |
125 | #define MXT_COMMS_CMD 1 | 125 | #define MXT_COMMS_CMD 1 |
126 | 126 | ||
127 | /* MXT_DEBUG_DIAGNOSTIC_T37 */ | ||
128 | #define MXT_DIAGNOSTIC_PAGEUP 0x01 | ||
129 | #define MXT_DIAGNOSTIC_DELTAS 0x10 | ||
130 | #define MXT_DIAGNOSTIC_SIZE 128 | ||
131 | |||
132 | struct t37_debug { | ||
133 | #ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37 | ||
134 | u8 mode; | ||
135 | u8 page; | ||
136 | u8 data[MXT_DIAGNOSTIC_SIZE]; | ||
137 | #endif | ||
138 | }; | ||
139 | |||
127 | /* Define for MXT_GEN_COMMAND_T6 */ | 140 | /* Define for MXT_GEN_COMMAND_T6 */ |
128 | #define MXT_BOOT_VALUE 0xa5 | 141 | #define MXT_BOOT_VALUE 0xa5 |
129 | #define MXT_RESET_VALUE 0x01 | 142 | #define MXT_RESET_VALUE 0x01 |
@@ -205,6 +218,14 @@ struct mxt_object { | |||
205 | u8 num_report_ids; | 218 | u8 num_report_ids; |
206 | } __packed; | 219 | } __packed; |
207 | 220 | ||
221 | struct mxt_dbg { | ||
222 | u16 t37_address; | ||
223 | u16 diag_cmd_address; | ||
224 | struct t37_debug *t37_buf; | ||
225 | unsigned int t37_pages; | ||
226 | unsigned int t37_nodes; | ||
227 | }; | ||
228 | |||
208 | /* Each client has this additional data */ | 229 | /* Each client has this additional data */ |
209 | struct mxt_data { | 230 | struct mxt_data { |
210 | struct i2c_client *client; | 231 | struct i2c_client *client; |
@@ -233,6 +254,7 @@ struct mxt_data { | |||
233 | u8 num_touchids; | 254 | u8 num_touchids; |
234 | u8 multitouch; | 255 | u8 multitouch; |
235 | struct t7_config t7_cfg; | 256 | struct t7_config t7_cfg; |
257 | struct mxt_dbg dbg; | ||
236 | 258 | ||
237 | /* Cached parameters from object table */ | 259 | /* Cached parameters from object table */ |
238 | u16 T5_address; | 260 | u16 T5_address; |
@@ -2043,6 +2065,141 @@ recheck: | |||
2043 | return 0; | 2065 | return 0; |
2044 | } | 2066 | } |
2045 | 2067 | ||
2068 | #ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37 | ||
2069 | static u16 mxt_get_debug_value(struct mxt_data *data, unsigned int x, | ||
2070 | unsigned int y) | ||
2071 | { | ||
2072 | struct mxt_dbg *dbg = &data->dbg; | ||
2073 | unsigned int ofs, page; | ||
2074 | |||
2075 | ofs = (y + (x * data->info.matrix_ysize)) * sizeof(u16); | ||
2076 | page = ofs / MXT_DIAGNOSTIC_SIZE; | ||
2077 | ofs %= MXT_DIAGNOSTIC_SIZE; | ||
2078 | |||
2079 | return get_unaligned_le16(&dbg->t37_buf[page].data[ofs]); | ||
2080 | } | ||
2081 | |||
2082 | static int mxt_convert_debug_pages(struct mxt_data *data, u16 *outbuf) | ||
2083 | { | ||
2084 | struct mxt_dbg *dbg = &data->dbg; | ||
2085 | unsigned int x = 0; | ||
2086 | unsigned int y = 0; | ||
2087 | unsigned int i; | ||
2088 | |||
2089 | for (i = 0; i < dbg->t37_nodes; i++) { | ||
2090 | outbuf[i] = mxt_get_debug_value(data, x, y); | ||
2091 | |||
2092 | /* Next value */ | ||
2093 | if (++x >= data->info.matrix_xsize) { | ||
2094 | x = 0; | ||
2095 | y++; | ||
2096 | } | ||
2097 | } | ||
2098 | |||
2099 | return 0; | ||
2100 | } | ||
2101 | |||
2102 | static int mxt_read_diagnostic_debug(struct mxt_data *data, u8 mode, | ||
2103 | u16 *outbuf) | ||
2104 | { | ||
2105 | struct mxt_dbg *dbg = &data->dbg; | ||
2106 | int retries = 0; | ||
2107 | int page; | ||
2108 | int ret; | ||
2109 | u8 cmd = mode; | ||
2110 | struct t37_debug *p; | ||
2111 | u8 cmd_poll; | ||
2112 | |||
2113 | for (page = 0; page < dbg->t37_pages; page++) { | ||
2114 | p = dbg->t37_buf + page; | ||
2115 | |||
2116 | ret = mxt_write_reg(data->client, dbg->diag_cmd_address, | ||
2117 | cmd); | ||
2118 | if (ret) | ||
2119 | return ret; | ||
2120 | |||
2121 | retries = 0; | ||
2122 | msleep(20); | ||
2123 | wait_cmd: | ||
2124 | /* Read back command byte */ | ||
2125 | ret = __mxt_read_reg(data->client, dbg->diag_cmd_address, | ||
2126 | sizeof(cmd_poll), &cmd_poll); | ||
2127 | if (ret) | ||
2128 | return ret; | ||
2129 | |||
2130 | /* Field is cleared once the command has been processed */ | ||
2131 | if (cmd_poll) { | ||
2132 | if (retries++ > 100) | ||
2133 | return -EINVAL; | ||
2134 | |||
2135 | msleep(20); | ||
2136 | goto wait_cmd; | ||
2137 | } | ||
2138 | |||
2139 | /* Read T37 page */ | ||
2140 | ret = __mxt_read_reg(data->client, dbg->t37_address, | ||
2141 | sizeof(struct t37_debug), p); | ||
2142 | if (ret) | ||
2143 | return ret; | ||
2144 | |||
2145 | if (p->mode != mode || p->page != page) { | ||
2146 | dev_err(&data->client->dev, "T37 page mismatch\n"); | ||
2147 | return -EINVAL; | ||
2148 | } | ||
2149 | |||
2150 | dev_dbg(&data->client->dev, "%s page:%d retries:%d\n", | ||
2151 | __func__, page, retries); | ||
2152 | |||
2153 | /* For remaining pages, write PAGEUP rather than mode */ | ||
2154 | cmd = MXT_DIAGNOSTIC_PAGEUP; | ||
2155 | } | ||
2156 | |||
2157 | return mxt_convert_debug_pages(data, outbuf); | ||
2158 | } | ||
2159 | |||
2160 | static void mxt_debug_init(struct mxt_data *data) | ||
2161 | { | ||
2162 | struct mxt_dbg *dbg = &data->dbg; | ||
2163 | struct mxt_object *object; | ||
2164 | |||
2165 | object = mxt_get_object(data, MXT_GEN_COMMAND_T6); | ||
2166 | if (!object) | ||
2167 | goto error; | ||
2168 | |||
2169 | dbg->diag_cmd_address = object->start_address + MXT_COMMAND_DIAGNOSTIC; | ||
2170 | |||
2171 | object = mxt_get_object(data, MXT_DEBUG_DIAGNOSTIC_T37); | ||
2172 | if (!object) | ||
2173 | goto error; | ||
2174 | |||
2175 | if (mxt_obj_size(object) != sizeof(struct t37_debug)) { | ||
2176 | dev_warn(&data->client->dev, "Bad T37 size"); | ||
2177 | goto error; | ||
2178 | } | ||
2179 | |||
2180 | dbg->t37_address = object->start_address; | ||
2181 | |||
2182 | /* Calculate size of data and allocate buffer */ | ||
2183 | dbg->t37_nodes = data->info.matrix_xsize * data->info.matrix_ysize; | ||
2184 | dbg->t37_pages = DIV_ROUND_UP(dbg->t37_nodes * sizeof(u16), | ||
2185 | sizeof(dbg->t37_buf->data)); | ||
2186 | |||
2187 | dbg->t37_buf = devm_kmalloc_array(&data->client->dev, dbg->t37_pages, | ||
2188 | sizeof(struct t37_debug), GFP_KERNEL); | ||
2189 | if (!dbg->t37_buf) | ||
2190 | goto error; | ||
2191 | |||
2192 | return; | ||
2193 | |||
2194 | error: | ||
2195 | dev_warn(&data->client->dev, "Error initializing T37\n"); | ||
2196 | } | ||
2197 | #else | ||
2198 | static void mxt_debug_init(struct mxt_data *data) | ||
2199 | { | ||
2200 | } | ||
2201 | #endif | ||
2202 | |||
2046 | static int mxt_configure_objects(struct mxt_data *data, | 2203 | static int mxt_configure_objects(struct mxt_data *data, |
2047 | const struct firmware *cfg) | 2204 | const struct firmware *cfg) |
2048 | { | 2205 | { |
@@ -2070,6 +2227,8 @@ static int mxt_configure_objects(struct mxt_data *data, | |||
2070 | dev_warn(dev, "No touch object detected\n"); | 2227 | dev_warn(dev, "No touch object detected\n"); |
2071 | } | 2228 | } |
2072 | 2229 | ||
2230 | mxt_debug_init(data); | ||
2231 | |||
2073 | dev_info(dev, | 2232 | dev_info(dev, |
2074 | "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n", | 2233 | "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n", |
2075 | info->family_id, info->variant_id, info->version >> 4, | 2234 | info->family_id, info->variant_id, info->version >> 4, |