diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-11 16:22:22 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-11 16:22:22 -0400 |
| commit | de34f4da7f62ff59ac6e1ef320b0fcfa3296fce3 (patch) | |
| tree | 88b5db2fc7fbbb0353edd8447a832a5225a49d01 /drivers/input/touchscreen | |
| parent | 56e520c7a0a490b63b042b047ec9659fc08762a4 (diff) | |
| parent | 9fce0c226536fc36c7fb0a80000ca38a995be43e (diff) | |
Merge tag 'media/v4.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab:
- Documentation improvements: conversion of all non-DocBook documents
to Sphinx and lots of fixes to the uAPI media book
- New PCI driver for Techwell TW5864 media grabber boards
- New SoC driver for ATMEL Image Sensor Controller
- Removal of some obsolete SoC drivers (s5p-tv driver and soc_camera
drivers)
- Addition of ST CEC driver
- Lots of drivers fixes, improvements and additions
* tag 'media/v4.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (464 commits)
[media] ttusb_dec: avoid the risk of go past buffer
[media] cx23885: Fix some smatch warnings
[media] si2165: switch to regmap
[media] si2165: use i2c_client->dev instead of i2c_adapter->dev for logging
[media] si2165: Remove legacy attach
[media] cx231xx: attach si2165 driver via i2c_client
[media] cx231xx: Prepare for attaching new style i2c_client DVB demod drivers
[media] cx23885: attach si2165 driver via i2c_client
[media] si2165: support i2c_client attach
[media] si2165: avoid division by zero
[media] rcar-vin: add R-Car gen2 fallback compatibility string
[media] lgdt3306a: remove 20*50 msec unnecessary timeout
[media] cx25821: Remove deprecated create_singlethread_workqueue
[media] cx25821: Drop Freeing of Workqueue
[media] cxd2841er: force 8MHz bandwidth for DVB-C if specified bw not supported
[media] redrat3: hardware-specific parameters
[media] redrat3: remove hw_timeout member
[media] cxd2841er: BER and SNR reading for ISDB-T
[media] dvb-usb: avoid link error with dib3000m{b,c|
[media] dvb-usb: split out common parts of dibusb
...
Diffstat (limited to 'drivers/input/touchscreen')
| -rw-r--r-- | drivers/input/touchscreen/Kconfig | 9 | ||||
| -rw-r--r-- | drivers/input/touchscreen/atmel_mxt_ts.c | 521 | ||||
| -rw-r--r-- | drivers/input/touchscreen/sur40.c | 142 |
3 files changed, 638 insertions, 34 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 507981356921..efca0133e266 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
| @@ -115,6 +115,15 @@ 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 | depends on VIDEO_V4L2=y || (TOUCHSCREEN_ATMEL_MXT=m && VIDEO_V4L2=m) | ||
| 122 | select VIDEOBUF2_VMALLOC | ||
| 123 | help | ||
| 124 | Say Y here if you want support to output data from the T37 | ||
| 125 | Diagnostic Data object using a V4L device. | ||
| 126 | |||
| 118 | config TOUCHSCREEN_AUO_PIXCIR | 127 | config TOUCHSCREEN_AUO_PIXCIR |
| 119 | tristate "AUO in-cell touchscreen using Pixcir ICs" | 128 | tristate "AUO in-cell touchscreen using Pixcir ICs" |
| 120 | depends on I2C | 129 | depends on I2C |
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 5af7907d0af4..e5d185fe69b9 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd |
| 5 | * Copyright (C) 2011-2014 Atmel Corporation | 5 | * Copyright (C) 2011-2014 Atmel Corporation |
| 6 | * Copyright (C) 2012 Google, Inc. | 6 | * Copyright (C) 2012 Google, Inc. |
| 7 | * Copyright (C) 2016 Zodiac Inflight Innovations | ||
| 7 | * | 8 | * |
| 8 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | 9 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
| 9 | * | 10 | * |
| @@ -28,6 +29,10 @@ | |||
| 28 | #include <linux/of.h> | 29 | #include <linux/of.h> |
| 29 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
| 30 | #include <asm/unaligned.h> | 31 | #include <asm/unaligned.h> |
| 32 | #include <media/v4l2-device.h> | ||
| 33 | #include <media/v4l2-ioctl.h> | ||
| 34 | #include <media/videobuf2-v4l2.h> | ||
| 35 | #include <media/videobuf2-vmalloc.h> | ||
| 31 | 36 | ||
| 32 | /* Firmware files */ | 37 | /* Firmware files */ |
| 33 | #define MXT_FW_NAME "maxtouch.fw" | 38 | #define MXT_FW_NAME "maxtouch.fw" |
| @@ -99,6 +104,8 @@ struct t7_config { | |||
| 99 | 104 | ||
| 100 | /* MXT_TOUCH_MULTI_T9 field */ | 105 | /* MXT_TOUCH_MULTI_T9 field */ |
| 101 | #define MXT_T9_CTRL 0 | 106 | #define MXT_T9_CTRL 0 |
| 107 | #define MXT_T9_XSIZE 3 | ||
| 108 | #define MXT_T9_YSIZE 4 | ||
| 102 | #define MXT_T9_ORIENT 9 | 109 | #define MXT_T9_ORIENT 9 |
| 103 | #define MXT_T9_RANGE 18 | 110 | #define MXT_T9_RANGE 18 |
| 104 | 111 | ||
| @@ -119,11 +126,31 @@ struct t9_range { | |||
| 119 | 126 | ||
| 120 | /* MXT_TOUCH_MULTI_T9 orient */ | 127 | /* MXT_TOUCH_MULTI_T9 orient */ |
| 121 | #define MXT_T9_ORIENT_SWITCH (1 << 0) | 128 | #define MXT_T9_ORIENT_SWITCH (1 << 0) |
| 129 | #define MXT_T9_ORIENT_INVERTX (1 << 1) | ||
| 130 | #define MXT_T9_ORIENT_INVERTY (1 << 2) | ||
| 122 | 131 | ||
| 123 | /* MXT_SPT_COMMSCONFIG_T18 */ | 132 | /* MXT_SPT_COMMSCONFIG_T18 */ |
| 124 | #define MXT_COMMS_CTRL 0 | 133 | #define MXT_COMMS_CTRL 0 |
| 125 | #define MXT_COMMS_CMD 1 | 134 | #define MXT_COMMS_CMD 1 |
| 126 | 135 | ||
| 136 | /* MXT_DEBUG_DIAGNOSTIC_T37 */ | ||
| 137 | #define MXT_DIAGNOSTIC_PAGEUP 0x01 | ||
| 138 | #define MXT_DIAGNOSTIC_DELTAS 0x10 | ||
| 139 | #define MXT_DIAGNOSTIC_REFS 0x11 | ||
| 140 | #define MXT_DIAGNOSTIC_SIZE 128 | ||
| 141 | |||
| 142 | #define MXT_FAMILY_1386 160 | ||
| 143 | #define MXT1386_COLUMNS 3 | ||
| 144 | #define MXT1386_PAGES_PER_COLUMN 8 | ||
| 145 | |||
| 146 | struct t37_debug { | ||
| 147 | #ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37 | ||
| 148 | u8 mode; | ||
| 149 | u8 page; | ||
| 150 | u8 data[MXT_DIAGNOSTIC_SIZE]; | ||
| 151 | #endif | ||
| 152 | }; | ||
| 153 | |||
| 127 | /* Define for MXT_GEN_COMMAND_T6 */ | 154 | /* Define for MXT_GEN_COMMAND_T6 */ |
| 128 | #define MXT_BOOT_VALUE 0xa5 | 155 | #define MXT_BOOT_VALUE 0xa5 |
| 129 | #define MXT_RESET_VALUE 0x01 | 156 | #define MXT_RESET_VALUE 0x01 |
| @@ -133,10 +160,14 @@ struct t9_range { | |||
| 133 | #define MXT_T100_CTRL 0 | 160 | #define MXT_T100_CTRL 0 |
| 134 | #define MXT_T100_CFG1 1 | 161 | #define MXT_T100_CFG1 1 |
| 135 | #define MXT_T100_TCHAUX 3 | 162 | #define MXT_T100_TCHAUX 3 |
| 163 | #define MXT_T100_XSIZE 9 | ||
| 136 | #define MXT_T100_XRANGE 13 | 164 | #define MXT_T100_XRANGE 13 |
| 165 | #define MXT_T100_YSIZE 20 | ||
| 137 | #define MXT_T100_YRANGE 24 | 166 | #define MXT_T100_YRANGE 24 |
| 138 | 167 | ||
| 139 | #define MXT_T100_CFG_SWITCHXY BIT(5) | 168 | #define MXT_T100_CFG_SWITCHXY BIT(5) |
| 169 | #define MXT_T100_CFG_INVERTY BIT(6) | ||
| 170 | #define MXT_T100_CFG_INVERTX BIT(7) | ||
| 140 | 171 | ||
| 141 | #define MXT_T100_TCHAUX_VECT BIT(0) | 172 | #define MXT_T100_TCHAUX_VECT BIT(0) |
| 142 | #define MXT_T100_TCHAUX_AMPL BIT(1) | 173 | #define MXT_T100_TCHAUX_AMPL BIT(1) |
| @@ -205,6 +236,37 @@ struct mxt_object { | |||
| 205 | u8 num_report_ids; | 236 | u8 num_report_ids; |
| 206 | } __packed; | 237 | } __packed; |
| 207 | 238 | ||
| 239 | struct mxt_dbg { | ||
| 240 | u16 t37_address; | ||
| 241 | u16 diag_cmd_address; | ||
| 242 | struct t37_debug *t37_buf; | ||
| 243 | unsigned int t37_pages; | ||
| 244 | unsigned int t37_nodes; | ||
| 245 | |||
| 246 | struct v4l2_device v4l2; | ||
| 247 | struct v4l2_pix_format format; | ||
| 248 | struct video_device vdev; | ||
| 249 | struct vb2_queue queue; | ||
| 250 | struct mutex lock; | ||
| 251 | int input; | ||
| 252 | }; | ||
| 253 | |||
| 254 | enum v4l_dbg_inputs { | ||
| 255 | MXT_V4L_INPUT_DELTAS, | ||
| 256 | MXT_V4L_INPUT_REFS, | ||
| 257 | MXT_V4L_INPUT_MAX, | ||
| 258 | }; | ||
| 259 | |||
| 260 | static const struct v4l2_file_operations mxt_video_fops = { | ||
| 261 | .owner = THIS_MODULE, | ||
| 262 | .open = v4l2_fh_open, | ||
| 263 | .release = vb2_fop_release, | ||
| 264 | .unlocked_ioctl = video_ioctl2, | ||
| 265 | .read = vb2_fop_read, | ||
| 266 | .mmap = vb2_fop_mmap, | ||
| 267 | .poll = vb2_fop_poll, | ||
| 268 | }; | ||
| 269 | |||
| 208 | /* Each client has this additional data */ | 270 | /* Each client has this additional data */ |
| 209 | struct mxt_data { | 271 | struct mxt_data { |
| 210 | struct i2c_client *client; | 272 | struct i2c_client *client; |
| @@ -216,7 +278,11 @@ struct mxt_data { | |||
| 216 | unsigned int irq; | 278 | unsigned int irq; |
| 217 | unsigned int max_x; | 279 | unsigned int max_x; |
| 218 | unsigned int max_y; | 280 | unsigned int max_y; |
| 281 | bool invertx; | ||
| 282 | bool inverty; | ||
| 219 | bool xy_switch; | 283 | bool xy_switch; |
| 284 | u8 xsize; | ||
| 285 | u8 ysize; | ||
| 220 | bool in_bootloader; | 286 | bool in_bootloader; |
| 221 | u16 mem_size; | 287 | u16 mem_size; |
| 222 | u8 t100_aux_ampl; | 288 | u8 t100_aux_ampl; |
| @@ -233,6 +299,7 @@ struct mxt_data { | |||
| 233 | u8 num_touchids; | 299 | u8 num_touchids; |
| 234 | u8 multitouch; | 300 | u8 multitouch; |
| 235 | struct t7_config t7_cfg; | 301 | struct t7_config t7_cfg; |
| 302 | struct mxt_dbg dbg; | ||
| 236 | 303 | ||
| 237 | /* Cached parameters from object table */ | 304 | /* Cached parameters from object table */ |
| 238 | u16 T5_address; | 305 | u16 T5_address; |
| @@ -257,6 +324,11 @@ struct mxt_data { | |||
| 257 | struct completion crc_completion; | 324 | struct completion crc_completion; |
| 258 | }; | 325 | }; |
| 259 | 326 | ||
| 327 | struct mxt_vb2_buffer { | ||
| 328 | struct vb2_buffer vb; | ||
| 329 | struct list_head list; | ||
| 330 | }; | ||
| 331 | |||
| 260 | static size_t mxt_obj_size(const struct mxt_object *obj) | 332 | static size_t mxt_obj_size(const struct mxt_object *obj) |
| 261 | { | 333 | { |
| 262 | return obj->size_minus_one + 1; | 334 | return obj->size_minus_one + 1; |
| @@ -1503,6 +1575,11 @@ static void mxt_free_input_device(struct mxt_data *data) | |||
| 1503 | 1575 | ||
| 1504 | static void mxt_free_object_table(struct mxt_data *data) | 1576 | static void mxt_free_object_table(struct mxt_data *data) |
| 1505 | { | 1577 | { |
| 1578 | #ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37 | ||
| 1579 | video_unregister_device(&data->dbg.vdev); | ||
| 1580 | v4l2_device_unregister(&data->dbg.v4l2); | ||
| 1581 | #endif | ||
| 1582 | |||
| 1506 | kfree(data->object_table); | 1583 | kfree(data->object_table); |
| 1507 | data->object_table = NULL; | 1584 | data->object_table = NULL; |
| 1508 | kfree(data->msg_buf); | 1585 | kfree(data->msg_buf); |
| @@ -1661,6 +1738,18 @@ static int mxt_read_t9_resolution(struct mxt_data *data) | |||
| 1661 | return -EINVAL; | 1738 | return -EINVAL; |
| 1662 | 1739 | ||
| 1663 | error = __mxt_read_reg(client, | 1740 | error = __mxt_read_reg(client, |
| 1741 | object->start_address + MXT_T9_XSIZE, | ||
| 1742 | sizeof(data->xsize), &data->xsize); | ||
| 1743 | if (error) | ||
| 1744 | return error; | ||
| 1745 | |||
| 1746 | error = __mxt_read_reg(client, | ||
| 1747 | object->start_address + MXT_T9_YSIZE, | ||
| 1748 | sizeof(data->ysize), &data->ysize); | ||
| 1749 | if (error) | ||
| 1750 | return error; | ||
| 1751 | |||
| 1752 | error = __mxt_read_reg(client, | ||
| 1664 | object->start_address + MXT_T9_RANGE, | 1753 | object->start_address + MXT_T9_RANGE, |
| 1665 | sizeof(range), &range); | 1754 | sizeof(range), &range); |
| 1666 | if (error) | 1755 | if (error) |
| @@ -1676,6 +1765,8 @@ static int mxt_read_t9_resolution(struct mxt_data *data) | |||
| 1676 | return error; | 1765 | return error; |
| 1677 | 1766 | ||
| 1678 | data->xy_switch = orient & MXT_T9_ORIENT_SWITCH; | 1767 | data->xy_switch = orient & MXT_T9_ORIENT_SWITCH; |
| 1768 | data->invertx = orient & MXT_T9_ORIENT_INVERTX; | ||
| 1769 | data->inverty = orient & MXT_T9_ORIENT_INVERTY; | ||
| 1679 | 1770 | ||
| 1680 | return 0; | 1771 | return 0; |
| 1681 | } | 1772 | } |
| @@ -1710,6 +1801,18 @@ static int mxt_read_t100_config(struct mxt_data *data) | |||
| 1710 | 1801 | ||
| 1711 | data->max_y = get_unaligned_le16(&range_y); | 1802 | data->max_y = get_unaligned_le16(&range_y); |
| 1712 | 1803 | ||
| 1804 | error = __mxt_read_reg(client, | ||
| 1805 | object->start_address + MXT_T100_XSIZE, | ||
| 1806 | sizeof(data->xsize), &data->xsize); | ||
| 1807 | if (error) | ||
| 1808 | return error; | ||
| 1809 | |||
| 1810 | error = __mxt_read_reg(client, | ||
| 1811 | object->start_address + MXT_T100_YSIZE, | ||
| 1812 | sizeof(data->ysize), &data->ysize); | ||
| 1813 | if (error) | ||
| 1814 | return error; | ||
| 1815 | |||
| 1713 | /* read orientation config */ | 1816 | /* read orientation config */ |
| 1714 | error = __mxt_read_reg(client, | 1817 | error = __mxt_read_reg(client, |
| 1715 | object->start_address + MXT_T100_CFG1, | 1818 | object->start_address + MXT_T100_CFG1, |
| @@ -1718,6 +1821,8 @@ static int mxt_read_t100_config(struct mxt_data *data) | |||
| 1718 | return error; | 1821 | return error; |
| 1719 | 1822 | ||
| 1720 | data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY; | 1823 | data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY; |
| 1824 | data->invertx = cfg & MXT_T100_CFG_INVERTX; | ||
| 1825 | data->inverty = cfg & MXT_T100_CFG_INVERTY; | ||
| 1721 | 1826 | ||
| 1722 | /* allocate aux bytes */ | 1827 | /* allocate aux bytes */ |
| 1723 | error = __mxt_read_reg(client, | 1828 | error = __mxt_read_reg(client, |
| @@ -2043,6 +2148,420 @@ recheck: | |||
| 2043 | return 0; | 2148 | return 0; |
| 2044 | } | 2149 | } |
| 2045 | 2150 | ||
| 2151 | #ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37 | ||
| 2152 | static u16 mxt_get_debug_value(struct mxt_data *data, unsigned int x, | ||
| 2153 | unsigned int y) | ||
| 2154 | { | ||
| 2155 | struct mxt_info *info = &data->info; | ||
| 2156 | struct mxt_dbg *dbg = &data->dbg; | ||
| 2157 | unsigned int ofs, page; | ||
| 2158 | unsigned int col = 0; | ||
| 2159 | unsigned int col_width; | ||
| 2160 | |||
| 2161 | if (info->family_id == MXT_FAMILY_1386) { | ||
| 2162 | col_width = info->matrix_ysize / MXT1386_COLUMNS; | ||
| 2163 | col = y / col_width; | ||
| 2164 | y = y % col_width; | ||
| 2165 | } else { | ||
| 2166 | col_width = info->matrix_ysize; | ||
| 2167 | } | ||
| 2168 | |||
| 2169 | ofs = (y + (x * col_width)) * sizeof(u16); | ||
| 2170 | page = ofs / MXT_DIAGNOSTIC_SIZE; | ||
| 2171 | ofs %= MXT_DIAGNOSTIC_SIZE; | ||
| 2172 | |||
| 2173 | if (info->family_id == MXT_FAMILY_1386) | ||
| 2174 | page += col * MXT1386_PAGES_PER_COLUMN; | ||
| 2175 | |||
| 2176 | return get_unaligned_le16(&dbg->t37_buf[page].data[ofs]); | ||
| 2177 | } | ||
| 2178 | |||
| 2179 | static int mxt_convert_debug_pages(struct mxt_data *data, u16 *outbuf) | ||
| 2180 | { | ||
| 2181 | struct mxt_dbg *dbg = &data->dbg; | ||
| 2182 | unsigned int x = 0; | ||
| 2183 | unsigned int y = 0; | ||
| 2184 | unsigned int i, rx, ry; | ||
| 2185 | |||
| 2186 | for (i = 0; i < dbg->t37_nodes; i++) { | ||
| 2187 | /* Handle orientation */ | ||
| 2188 | rx = data->xy_switch ? y : x; | ||
| 2189 | ry = data->xy_switch ? x : y; | ||
| 2190 | rx = data->invertx ? (data->xsize - 1 - rx) : rx; | ||
| 2191 | ry = data->inverty ? (data->ysize - 1 - ry) : ry; | ||
| 2192 | |||
| 2193 | outbuf[i] = mxt_get_debug_value(data, rx, ry); | ||
| 2194 | |||
| 2195 | /* Next value */ | ||
| 2196 | if (++x >= (data->xy_switch ? data->ysize : data->xsize)) { | ||
| 2197 | x = 0; | ||
| 2198 | y++; | ||
| 2199 | } | ||
| 2200 | } | ||
| 2201 | |||
| 2202 | return 0; | ||
| 2203 | } | ||
| 2204 | |||
| 2205 | static int mxt_read_diagnostic_debug(struct mxt_data *data, u8 mode, | ||
| 2206 | u16 *outbuf) | ||
| 2207 | { | ||
| 2208 | struct mxt_dbg *dbg = &data->dbg; | ||
| 2209 | int retries = 0; | ||
| 2210 | int page; | ||
| 2211 | int ret; | ||
| 2212 | u8 cmd = mode; | ||
| 2213 | struct t37_debug *p; | ||
| 2214 | u8 cmd_poll; | ||
| 2215 | |||
| 2216 | for (page = 0; page < dbg->t37_pages; page++) { | ||
| 2217 | p = dbg->t37_buf + page; | ||
| 2218 | |||
| 2219 | ret = mxt_write_reg(data->client, dbg->diag_cmd_address, | ||
| 2220 | cmd); | ||
| 2221 | if (ret) | ||
| 2222 | return ret; | ||
| 2223 | |||
| 2224 | retries = 0; | ||
| 2225 | msleep(20); | ||
| 2226 | wait_cmd: | ||
| 2227 | /* Read back command byte */ | ||
| 2228 | ret = __mxt_read_reg(data->client, dbg->diag_cmd_address, | ||
| 2229 | sizeof(cmd_poll), &cmd_poll); | ||
| 2230 | if (ret) | ||
| 2231 | return ret; | ||
| 2232 | |||
| 2233 | /* Field is cleared once the command has been processed */ | ||
| 2234 | if (cmd_poll) { | ||
| 2235 | if (retries++ > 100) | ||
| 2236 | return -EINVAL; | ||
| 2237 | |||
| 2238 | msleep(20); | ||
| 2239 | goto wait_cmd; | ||
| 2240 | } | ||
| 2241 | |||
| 2242 | /* Read T37 page */ | ||
| 2243 | ret = __mxt_read_reg(data->client, dbg->t37_address, | ||
| 2244 | sizeof(struct t37_debug), p); | ||
| 2245 | if (ret) | ||
| 2246 | return ret; | ||
| 2247 | |||
| 2248 | if (p->mode != mode || p->page != page) { | ||
| 2249 | dev_err(&data->client->dev, "T37 page mismatch\n"); | ||
| 2250 | return -EINVAL; | ||
| 2251 | } | ||
| 2252 | |||
| 2253 | dev_dbg(&data->client->dev, "%s page:%d retries:%d\n", | ||
| 2254 | __func__, page, retries); | ||
| 2255 | |||
| 2256 | /* For remaining pages, write PAGEUP rather than mode */ | ||
| 2257 | cmd = MXT_DIAGNOSTIC_PAGEUP; | ||
| 2258 | } | ||
| 2259 | |||
| 2260 | return mxt_convert_debug_pages(data, outbuf); | ||
| 2261 | } | ||
| 2262 | |||
| 2263 | static int mxt_queue_setup(struct vb2_queue *q, | ||
| 2264 | unsigned int *nbuffers, unsigned int *nplanes, | ||
| 2265 | unsigned int sizes[], struct device *alloc_devs[]) | ||
| 2266 | { | ||
| 2267 | struct mxt_data *data = q->drv_priv; | ||
| 2268 | size_t size = data->dbg.t37_nodes * sizeof(u16); | ||
| 2269 | |||
| 2270 | if (*nplanes) | ||
| 2271 | return sizes[0] < size ? -EINVAL : 0; | ||
| 2272 | |||
| 2273 | *nplanes = 1; | ||
| 2274 | sizes[0] = size; | ||
| 2275 | |||
| 2276 | return 0; | ||
| 2277 | } | ||
| 2278 | |||
| 2279 | static void mxt_buffer_queue(struct vb2_buffer *vb) | ||
| 2280 | { | ||
| 2281 | struct mxt_data *data = vb2_get_drv_priv(vb->vb2_queue); | ||
| 2282 | u16 *ptr; | ||
| 2283 | int ret; | ||
| 2284 | u8 mode; | ||
| 2285 | |||
| 2286 | ptr = vb2_plane_vaddr(vb, 0); | ||
| 2287 | if (!ptr) { | ||
| 2288 | dev_err(&data->client->dev, "Error acquiring frame ptr\n"); | ||
| 2289 | goto fault; | ||
| 2290 | } | ||
| 2291 | |||
| 2292 | switch (data->dbg.input) { | ||
| 2293 | case MXT_V4L_INPUT_DELTAS: | ||
| 2294 | default: | ||
| 2295 | mode = MXT_DIAGNOSTIC_DELTAS; | ||
| 2296 | break; | ||
| 2297 | |||
| 2298 | case MXT_V4L_INPUT_REFS: | ||
| 2299 | mode = MXT_DIAGNOSTIC_REFS; | ||
| 2300 | break; | ||
| 2301 | } | ||
| 2302 | |||
| 2303 | ret = mxt_read_diagnostic_debug(data, mode, ptr); | ||
| 2304 | if (ret) | ||
| 2305 | goto fault; | ||
| 2306 | |||
| 2307 | vb2_set_plane_payload(vb, 0, data->dbg.t37_nodes * sizeof(u16)); | ||
| 2308 | vb2_buffer_done(vb, VB2_BUF_STATE_DONE); | ||
| 2309 | return; | ||
| 2310 | |||
| 2311 | fault: | ||
| 2312 | vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); | ||
| 2313 | } | ||
| 2314 | |||
| 2315 | /* V4L2 structures */ | ||
| 2316 | static const struct vb2_ops mxt_queue_ops = { | ||
| 2317 | .queue_setup = mxt_queue_setup, | ||
| 2318 | .buf_queue = mxt_buffer_queue, | ||
| 2319 | .wait_prepare = vb2_ops_wait_prepare, | ||
| 2320 | .wait_finish = vb2_ops_wait_finish, | ||
| 2321 | }; | ||
| 2322 | |||
| 2323 | static const struct vb2_queue mxt_queue = { | ||
| 2324 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, | ||
| 2325 | .io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ, | ||
| 2326 | .buf_struct_size = sizeof(struct mxt_vb2_buffer), | ||
| 2327 | .ops = &mxt_queue_ops, | ||
| 2328 | .mem_ops = &vb2_vmalloc_memops, | ||
| 2329 | .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC, | ||
| 2330 | .min_buffers_needed = 1, | ||
| 2331 | }; | ||
| 2332 | |||
| 2333 | static int mxt_vidioc_querycap(struct file *file, void *priv, | ||
| 2334 | struct v4l2_capability *cap) | ||
| 2335 | { | ||
| 2336 | struct mxt_data *data = video_drvdata(file); | ||
| 2337 | |||
| 2338 | strlcpy(cap->driver, "atmel_mxt_ts", sizeof(cap->driver)); | ||
| 2339 | strlcpy(cap->card, "atmel_mxt_ts touch", sizeof(cap->card)); | ||
| 2340 | snprintf(cap->bus_info, sizeof(cap->bus_info), | ||
| 2341 | "I2C:%s", dev_name(&data->client->dev)); | ||
| 2342 | return 0; | ||
| 2343 | } | ||
| 2344 | |||
| 2345 | static int mxt_vidioc_enum_input(struct file *file, void *priv, | ||
| 2346 | struct v4l2_input *i) | ||
| 2347 | { | ||
| 2348 | if (i->index >= MXT_V4L_INPUT_MAX) | ||
| 2349 | return -EINVAL; | ||
| 2350 | |||
| 2351 | i->type = V4L2_INPUT_TYPE_TOUCH; | ||
| 2352 | |||
| 2353 | switch (i->index) { | ||
| 2354 | case MXT_V4L_INPUT_REFS: | ||
| 2355 | strlcpy(i->name, "Mutual Capacitance References", | ||
| 2356 | sizeof(i->name)); | ||
| 2357 | break; | ||
| 2358 | case MXT_V4L_INPUT_DELTAS: | ||
| 2359 | strlcpy(i->name, "Mutual Capacitance Deltas", sizeof(i->name)); | ||
| 2360 | break; | ||
| 2361 | } | ||
| 2362 | |||
| 2363 | return 0; | ||
| 2364 | } | ||
| 2365 | |||
| 2366 | static int mxt_set_input(struct mxt_data *data, unsigned int i) | ||
| 2367 | { | ||
| 2368 | struct v4l2_pix_format *f = &data->dbg.format; | ||
| 2369 | |||
| 2370 | if (i >= MXT_V4L_INPUT_MAX) | ||
| 2371 | return -EINVAL; | ||
| 2372 | |||
| 2373 | if (i == MXT_V4L_INPUT_DELTAS) | ||
| 2374 | f->pixelformat = V4L2_TCH_FMT_DELTA_TD16; | ||
| 2375 | else | ||
| 2376 | f->pixelformat = V4L2_TCH_FMT_TU16; | ||
| 2377 | |||
| 2378 | f->width = data->xy_switch ? data->ysize : data->xsize; | ||
| 2379 | f->height = data->xy_switch ? data->xsize : data->ysize; | ||
| 2380 | f->field = V4L2_FIELD_NONE; | ||
| 2381 | f->colorspace = V4L2_COLORSPACE_RAW; | ||
| 2382 | f->bytesperline = f->width * sizeof(u16); | ||
| 2383 | f->sizeimage = f->width * f->height * sizeof(u16); | ||
| 2384 | |||
| 2385 | data->dbg.input = i; | ||
| 2386 | |||
| 2387 | return 0; | ||
| 2388 | } | ||
| 2389 | |||
| 2390 | static int mxt_vidioc_s_input(struct file *file, void *priv, unsigned int i) | ||
| 2391 | { | ||
| 2392 | return mxt_set_input(video_drvdata(file), i); | ||
| 2393 | } | ||
| 2394 | |||
| 2395 | static int mxt_vidioc_g_input(struct file *file, void *priv, unsigned int *i) | ||
| 2396 | { | ||
| 2397 | struct mxt_data *data = video_drvdata(file); | ||
| 2398 | |||
| 2399 | *i = data->dbg.input; | ||
| 2400 | |||
| 2401 | return 0; | ||
| 2402 | } | ||
| 2403 | |||
| 2404 | static int mxt_vidioc_fmt(struct file *file, void *priv, struct v4l2_format *f) | ||
| 2405 | { | ||
| 2406 | struct mxt_data *data = video_drvdata(file); | ||
| 2407 | |||
| 2408 | f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
| 2409 | f->fmt.pix = data->dbg.format; | ||
| 2410 | |||
| 2411 | return 0; | ||
| 2412 | } | ||
| 2413 | |||
| 2414 | static int mxt_vidioc_enum_fmt(struct file *file, void *priv, | ||
| 2415 | struct v4l2_fmtdesc *fmt) | ||
| 2416 | { | ||
| 2417 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 2418 | return -EINVAL; | ||
| 2419 | |||
| 2420 | switch (fmt->index) { | ||
| 2421 | case 0: | ||
| 2422 | fmt->pixelformat = V4L2_TCH_FMT_TU16; | ||
| 2423 | break; | ||
| 2424 | |||
| 2425 | case 1: | ||
| 2426 | fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD16; | ||
| 2427 | break; | ||
| 2428 | |||
| 2429 | default: | ||
| 2430 | return -EINVAL; | ||
| 2431 | } | ||
| 2432 | |||
| 2433 | return 0; | ||
| 2434 | } | ||
| 2435 | |||
| 2436 | static int mxt_vidioc_g_parm(struct file *file, void *fh, | ||
| 2437 | struct v4l2_streamparm *a) | ||
| 2438 | { | ||
| 2439 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 2440 | return -EINVAL; | ||
| 2441 | |||
| 2442 | a->parm.capture.readbuffers = 1; | ||
| 2443 | a->parm.capture.timeperframe.numerator = 1; | ||
| 2444 | a->parm.capture.timeperframe.denominator = 10; | ||
| 2445 | return 0; | ||
| 2446 | } | ||
| 2447 | |||
| 2448 | static const struct v4l2_ioctl_ops mxt_video_ioctl_ops = { | ||
| 2449 | .vidioc_querycap = mxt_vidioc_querycap, | ||
| 2450 | |||
| 2451 | .vidioc_enum_fmt_vid_cap = mxt_vidioc_enum_fmt, | ||
| 2452 | .vidioc_s_fmt_vid_cap = mxt_vidioc_fmt, | ||
| 2453 | .vidioc_g_fmt_vid_cap = mxt_vidioc_fmt, | ||
| 2454 | .vidioc_try_fmt_vid_cap = mxt_vidioc_fmt, | ||
| 2455 | .vidioc_g_parm = mxt_vidioc_g_parm, | ||
| 2456 | |||
| 2457 | .vidioc_enum_input = mxt_vidioc_enum_input, | ||
| 2458 | .vidioc_g_input = mxt_vidioc_g_input, | ||
| 2459 | .vidioc_s_input = mxt_vidioc_s_input, | ||
| 2460 | |||
| 2461 | .vidioc_reqbufs = vb2_ioctl_reqbufs, | ||
| 2462 | .vidioc_create_bufs = vb2_ioctl_create_bufs, | ||
| 2463 | .vidioc_querybuf = vb2_ioctl_querybuf, | ||
| 2464 | .vidioc_qbuf = vb2_ioctl_qbuf, | ||
| 2465 | .vidioc_dqbuf = vb2_ioctl_dqbuf, | ||
| 2466 | .vidioc_expbuf = vb2_ioctl_expbuf, | ||
| 2467 | |||
| 2468 | .vidioc_streamon = vb2_ioctl_streamon, | ||
| 2469 | .vidioc_streamoff = vb2_ioctl_streamoff, | ||
| 2470 | }; | ||
| 2471 | |||
| 2472 | static const struct video_device mxt_video_device = { | ||
| 2473 | .name = "Atmel maxTouch", | ||
| 2474 | .fops = &mxt_video_fops, | ||
| 2475 | .ioctl_ops = &mxt_video_ioctl_ops, | ||
| 2476 | .release = video_device_release_empty, | ||
| 2477 | .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH | | ||
| 2478 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING, | ||
| 2479 | }; | ||
| 2480 | |||
| 2481 | static void mxt_debug_init(struct mxt_data *data) | ||
| 2482 | { | ||
| 2483 | struct mxt_info *info = &data->info; | ||
| 2484 | struct mxt_dbg *dbg = &data->dbg; | ||
| 2485 | struct mxt_object *object; | ||
| 2486 | int error; | ||
| 2487 | |||
| 2488 | object = mxt_get_object(data, MXT_GEN_COMMAND_T6); | ||
| 2489 | if (!object) | ||
| 2490 | goto error; | ||
| 2491 | |||
| 2492 | dbg->diag_cmd_address = object->start_address + MXT_COMMAND_DIAGNOSTIC; | ||
| 2493 | |||
| 2494 | object = mxt_get_object(data, MXT_DEBUG_DIAGNOSTIC_T37); | ||
| 2495 | if (!object) | ||
| 2496 | goto error; | ||
| 2497 | |||
| 2498 | if (mxt_obj_size(object) != sizeof(struct t37_debug)) { | ||
| 2499 | dev_warn(&data->client->dev, "Bad T37 size"); | ||
| 2500 | goto error; | ||
| 2501 | } | ||
| 2502 | |||
| 2503 | dbg->t37_address = object->start_address; | ||
| 2504 | |||
| 2505 | /* Calculate size of data and allocate buffer */ | ||
| 2506 | dbg->t37_nodes = data->xsize * data->ysize; | ||
| 2507 | |||
| 2508 | if (info->family_id == MXT_FAMILY_1386) | ||
| 2509 | dbg->t37_pages = MXT1386_COLUMNS * MXT1386_PAGES_PER_COLUMN; | ||
| 2510 | else | ||
| 2511 | dbg->t37_pages = DIV_ROUND_UP(data->xsize * | ||
| 2512 | data->info.matrix_ysize * | ||
| 2513 | sizeof(u16), | ||
| 2514 | sizeof(dbg->t37_buf->data)); | ||
| 2515 | |||
| 2516 | dbg->t37_buf = devm_kmalloc_array(&data->client->dev, dbg->t37_pages, | ||
| 2517 | sizeof(struct t37_debug), GFP_KERNEL); | ||
| 2518 | if (!dbg->t37_buf) | ||
| 2519 | goto error; | ||
| 2520 | |||
| 2521 | /* init channel to zero */ | ||
| 2522 | mxt_set_input(data, 0); | ||
| 2523 | |||
| 2524 | /* register video device */ | ||
| 2525 | snprintf(dbg->v4l2.name, sizeof(dbg->v4l2.name), "%s", "atmel_mxt_ts"); | ||
| 2526 | error = v4l2_device_register(&data->client->dev, &dbg->v4l2); | ||
| 2527 | if (error) | ||
| 2528 | goto error; | ||
| 2529 | |||
| 2530 | /* initialize the queue */ | ||
| 2531 | mutex_init(&dbg->lock); | ||
| 2532 | dbg->queue = mxt_queue; | ||
| 2533 | dbg->queue.drv_priv = data; | ||
| 2534 | dbg->queue.lock = &dbg->lock; | ||
| 2535 | dbg->queue.dev = &data->client->dev; | ||
| 2536 | |||
| 2537 | error = vb2_queue_init(&dbg->queue); | ||
| 2538 | if (error) | ||
| 2539 | goto error_unreg_v4l2; | ||
| 2540 | |||
| 2541 | dbg->vdev = mxt_video_device; | ||
| 2542 | dbg->vdev.v4l2_dev = &dbg->v4l2; | ||
| 2543 | dbg->vdev.lock = &dbg->lock; | ||
| 2544 | dbg->vdev.vfl_dir = VFL_DIR_RX; | ||
| 2545 | dbg->vdev.queue = &dbg->queue; | ||
| 2546 | video_set_drvdata(&dbg->vdev, data); | ||
| 2547 | |||
| 2548 | error = video_register_device(&dbg->vdev, VFL_TYPE_TOUCH, -1); | ||
| 2549 | if (error) | ||
| 2550 | goto error_unreg_v4l2; | ||
| 2551 | |||
| 2552 | return; | ||
| 2553 | |||
| 2554 | error_unreg_v4l2: | ||
| 2555 | v4l2_device_unregister(&dbg->v4l2); | ||
| 2556 | error: | ||
| 2557 | dev_warn(&data->client->dev, "Error initializing T37\n"); | ||
| 2558 | } | ||
| 2559 | #else | ||
| 2560 | static void mxt_debug_init(struct mxt_data *data) | ||
| 2561 | { | ||
| 2562 | } | ||
| 2563 | #endif | ||
| 2564 | |||
| 2046 | static int mxt_configure_objects(struct mxt_data *data, | 2565 | static int mxt_configure_objects(struct mxt_data *data, |
| 2047 | const struct firmware *cfg) | 2566 | const struct firmware *cfg) |
| 2048 | { | 2567 | { |
| @@ -2070,6 +2589,8 @@ static int mxt_configure_objects(struct mxt_data *data, | |||
| 2070 | dev_warn(dev, "No touch object detected\n"); | 2589 | dev_warn(dev, "No touch object detected\n"); |
| 2071 | } | 2590 | } |
| 2072 | 2591 | ||
| 2592 | mxt_debug_init(data); | ||
| 2593 | |||
| 2073 | dev_info(dev, | 2594 | dev_info(dev, |
| 2074 | "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n", | 2595 | "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n", |
| 2075 | info->family_id, info->variant_id, info->version >> 4, | 2596 | info->family_id, info->variant_id, info->version >> 4, |
diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c index 4ea475775d58..aefb6e11f88a 100644 --- a/drivers/input/touchscreen/sur40.c +++ b/drivers/input/touchscreen/sur40.c | |||
| @@ -139,6 +139,27 @@ struct sur40_image_header { | |||
| 139 | #define SUR40_GET_STATE 0xc5 /* 4 bytes state (?) */ | 139 | #define SUR40_GET_STATE 0xc5 /* 4 bytes state (?) */ |
| 140 | #define SUR40_GET_SENSORS 0xb1 /* 8 bytes sensors */ | 140 | #define SUR40_GET_SENSORS 0xb1 /* 8 bytes sensors */ |
| 141 | 141 | ||
| 142 | static const struct v4l2_pix_format sur40_pix_format[] = { | ||
| 143 | { | ||
| 144 | .pixelformat = V4L2_TCH_FMT_TU08, | ||
| 145 | .width = SENSOR_RES_X / 2, | ||
| 146 | .height = SENSOR_RES_Y / 2, | ||
| 147 | .field = V4L2_FIELD_NONE, | ||
| 148 | .colorspace = V4L2_COLORSPACE_SRGB, | ||
| 149 | .bytesperline = SENSOR_RES_X / 2, | ||
| 150 | .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2), | ||
| 151 | }, | ||
| 152 | { | ||
| 153 | .pixelformat = V4L2_PIX_FMT_GREY, | ||
| 154 | .width = SENSOR_RES_X / 2, | ||
| 155 | .height = SENSOR_RES_Y / 2, | ||
| 156 | .field = V4L2_FIELD_NONE, | ||
| 157 | .colorspace = V4L2_COLORSPACE_SRGB, | ||
| 158 | .bytesperline = SENSOR_RES_X / 2, | ||
| 159 | .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2), | ||
| 160 | } | ||
| 161 | }; | ||
| 162 | |||
| 142 | /* master device state */ | 163 | /* master device state */ |
| 143 | struct sur40_state { | 164 | struct sur40_state { |
| 144 | 165 | ||
| @@ -149,6 +170,7 @@ struct sur40_state { | |||
| 149 | struct v4l2_device v4l2; | 170 | struct v4l2_device v4l2; |
| 150 | struct video_device vdev; | 171 | struct video_device vdev; |
| 151 | struct mutex lock; | 172 | struct mutex lock; |
| 173 | struct v4l2_pix_format pix_fmt; | ||
| 152 | 174 | ||
| 153 | struct vb2_queue queue; | 175 | struct vb2_queue queue; |
| 154 | struct list_head buf_list; | 176 | struct list_head buf_list; |
| @@ -169,7 +191,6 @@ struct sur40_buffer { | |||
| 169 | 191 | ||
| 170 | /* forward declarations */ | 192 | /* forward declarations */ |
| 171 | static const struct video_device sur40_video_device; | 193 | static const struct video_device sur40_video_device; |
| 172 | static const struct v4l2_pix_format sur40_video_format; | ||
| 173 | static const struct vb2_queue sur40_queue; | 194 | static const struct vb2_queue sur40_queue; |
| 174 | static void sur40_process_video(struct sur40_state *sur40); | 195 | static void sur40_process_video(struct sur40_state *sur40); |
| 175 | 196 | ||
| @@ -420,7 +441,7 @@ static void sur40_process_video(struct sur40_state *sur40) | |||
| 420 | goto err_poll; | 441 | goto err_poll; |
| 421 | } | 442 | } |
| 422 | 443 | ||
| 423 | if (le32_to_cpu(img->size) != sur40_video_format.sizeimage) { | 444 | if (le32_to_cpu(img->size) != sur40->pix_fmt.sizeimage) { |
| 424 | dev_err(sur40->dev, "image size mismatch\n"); | 445 | dev_err(sur40->dev, "image size mismatch\n"); |
| 425 | goto err_poll; | 446 | goto err_poll; |
| 426 | } | 447 | } |
| @@ -431,7 +452,7 @@ static void sur40_process_video(struct sur40_state *sur40) | |||
| 431 | 452 | ||
| 432 | result = usb_sg_init(&sgr, sur40->usbdev, | 453 | result = usb_sg_init(&sgr, sur40->usbdev, |
| 433 | usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0, | 454 | usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0, |
| 434 | sgt->sgl, sgt->nents, sur40_video_format.sizeimage, 0); | 455 | sgt->sgl, sgt->nents, sur40->pix_fmt.sizeimage, 0); |
| 435 | if (result < 0) { | 456 | if (result < 0) { |
| 436 | dev_err(sur40->dev, "error %d in usb_sg_init\n", result); | 457 | dev_err(sur40->dev, "error %d in usb_sg_init\n", result); |
| 437 | goto err_poll; | 458 | goto err_poll; |
| @@ -586,13 +607,14 @@ static int sur40_probe(struct usb_interface *interface, | |||
| 586 | if (error) | 607 | if (error) |
| 587 | goto err_unreg_v4l2; | 608 | goto err_unreg_v4l2; |
| 588 | 609 | ||
| 610 | sur40->pix_fmt = sur40_pix_format[0]; | ||
| 589 | sur40->vdev = sur40_video_device; | 611 | sur40->vdev = sur40_video_device; |
| 590 | sur40->vdev.v4l2_dev = &sur40->v4l2; | 612 | sur40->vdev.v4l2_dev = &sur40->v4l2; |
| 591 | sur40->vdev.lock = &sur40->lock; | 613 | sur40->vdev.lock = &sur40->lock; |
| 592 | sur40->vdev.queue = &sur40->queue; | 614 | sur40->vdev.queue = &sur40->queue; |
| 593 | video_set_drvdata(&sur40->vdev, sur40); | 615 | video_set_drvdata(&sur40->vdev, sur40); |
| 594 | 616 | ||
| 595 | error = video_register_device(&sur40->vdev, VFL_TYPE_GRABBER, -1); | 617 | error = video_register_device(&sur40->vdev, VFL_TYPE_TOUCH, -1); |
| 596 | if (error) { | 618 | if (error) { |
| 597 | dev_err(&interface->dev, | 619 | dev_err(&interface->dev, |
| 598 | "Unable to register video subdevice."); | 620 | "Unable to register video subdevice."); |
| @@ -647,14 +669,16 @@ static int sur40_queue_setup(struct vb2_queue *q, | |||
| 647 | unsigned int *nbuffers, unsigned int *nplanes, | 669 | unsigned int *nbuffers, unsigned int *nplanes, |
| 648 | unsigned int sizes[], struct device *alloc_devs[]) | 670 | unsigned int sizes[], struct device *alloc_devs[]) |
| 649 | { | 671 | { |
| 672 | struct sur40_state *sur40 = vb2_get_drv_priv(q); | ||
| 673 | |||
| 650 | if (q->num_buffers + *nbuffers < 3) | 674 | if (q->num_buffers + *nbuffers < 3) |
| 651 | *nbuffers = 3 - q->num_buffers; | 675 | *nbuffers = 3 - q->num_buffers; |
| 652 | 676 | ||
| 653 | if (*nplanes) | 677 | if (*nplanes) |
| 654 | return sizes[0] < sur40_video_format.sizeimage ? -EINVAL : 0; | 678 | return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0; |
| 655 | 679 | ||
| 656 | *nplanes = 1; | 680 | *nplanes = 1; |
| 657 | sizes[0] = sur40_video_format.sizeimage; | 681 | sizes[0] = sur40->pix_fmt.sizeimage; |
| 658 | 682 | ||
| 659 | return 0; | 683 | return 0; |
| 660 | } | 684 | } |
| @@ -666,7 +690,7 @@ static int sur40_queue_setup(struct vb2_queue *q, | |||
| 666 | static int sur40_buffer_prepare(struct vb2_buffer *vb) | 690 | static int sur40_buffer_prepare(struct vb2_buffer *vb) |
| 667 | { | 691 | { |
| 668 | struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue); | 692 | struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue); |
| 669 | unsigned long size = sur40_video_format.sizeimage; | 693 | unsigned long size = sur40->pix_fmt.sizeimage; |
| 670 | 694 | ||
| 671 | if (vb2_plane_size(vb, 0) < size) { | 695 | if (vb2_plane_size(vb, 0) < size) { |
| 672 | dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n", | 696 | dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n", |
| @@ -741,7 +765,7 @@ static int sur40_vidioc_querycap(struct file *file, void *priv, | |||
| 741 | strlcpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver)); | 765 | strlcpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver)); |
| 742 | strlcpy(cap->card, DRIVER_LONG, sizeof(cap->card)); | 766 | strlcpy(cap->card, DRIVER_LONG, sizeof(cap->card)); |
| 743 | usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info)); | 767 | usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info)); |
| 744 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | | 768 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH | |
| 745 | V4L2_CAP_READWRITE | | 769 | V4L2_CAP_READWRITE | |
| 746 | V4L2_CAP_STREAMING; | 770 | V4L2_CAP_STREAMING; |
| 747 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; | 771 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
| @@ -753,7 +777,7 @@ static int sur40_vidioc_enum_input(struct file *file, void *priv, | |||
| 753 | { | 777 | { |
| 754 | if (i->index != 0) | 778 | if (i->index != 0) |
| 755 | return -EINVAL; | 779 | return -EINVAL; |
| 756 | i->type = V4L2_INPUT_TYPE_CAMERA; | 780 | i->type = V4L2_INPUT_TYPE_TOUCH; |
| 757 | i->std = V4L2_STD_UNKNOWN; | 781 | i->std = V4L2_STD_UNKNOWN; |
| 758 | strlcpy(i->name, "In-Cell Sensor", sizeof(i->name)); | 782 | strlcpy(i->name, "In-Cell Sensor", sizeof(i->name)); |
| 759 | i->capabilities = 0; | 783 | i->capabilities = 0; |
| @@ -771,19 +795,70 @@ static int sur40_vidioc_g_input(struct file *file, void *priv, unsigned int *i) | |||
| 771 | return 0; | 795 | return 0; |
| 772 | } | 796 | } |
| 773 | 797 | ||
| 774 | static int sur40_vidioc_fmt(struct file *file, void *priv, | 798 | static int sur40_vidioc_try_fmt(struct file *file, void *priv, |
| 799 | struct v4l2_format *f) | ||
| 800 | { | ||
| 801 | switch (f->fmt.pix.pixelformat) { | ||
| 802 | case V4L2_PIX_FMT_GREY: | ||
| 803 | f->fmt.pix = sur40_pix_format[1]; | ||
| 804 | break; | ||
| 805 | |||
| 806 | default: | ||
| 807 | f->fmt.pix = sur40_pix_format[0]; | ||
| 808 | break; | ||
| 809 | } | ||
| 810 | |||
| 811 | return 0; | ||
| 812 | } | ||
| 813 | |||
| 814 | static int sur40_vidioc_s_fmt(struct file *file, void *priv, | ||
| 815 | struct v4l2_format *f) | ||
| 816 | { | ||
| 817 | struct sur40_state *sur40 = video_drvdata(file); | ||
| 818 | |||
| 819 | switch (f->fmt.pix.pixelformat) { | ||
| 820 | case V4L2_PIX_FMT_GREY: | ||
| 821 | sur40->pix_fmt = sur40_pix_format[1]; | ||
| 822 | break; | ||
| 823 | |||
| 824 | default: | ||
| 825 | sur40->pix_fmt = sur40_pix_format[0]; | ||
| 826 | break; | ||
| 827 | } | ||
| 828 | |||
| 829 | f->fmt.pix = sur40->pix_fmt; | ||
| 830 | return 0; | ||
| 831 | } | ||
| 832 | |||
| 833 | static int sur40_vidioc_g_fmt(struct file *file, void *priv, | ||
| 775 | struct v4l2_format *f) | 834 | struct v4l2_format *f) |
| 776 | { | 835 | { |
| 777 | f->fmt.pix = sur40_video_format; | 836 | struct sur40_state *sur40 = video_drvdata(file); |
| 837 | |||
| 838 | f->fmt.pix = sur40->pix_fmt; | ||
| 839 | return 0; | ||
| 840 | } | ||
| 841 | |||
| 842 | static int sur40_ioctl_parm(struct file *file, void *priv, | ||
| 843 | struct v4l2_streamparm *p) | ||
| 844 | { | ||
| 845 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 846 | return -EINVAL; | ||
| 847 | |||
| 848 | p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; | ||
| 849 | p->parm.capture.timeperframe.numerator = 1; | ||
| 850 | p->parm.capture.timeperframe.denominator = 60; | ||
| 851 | p->parm.capture.readbuffers = 3; | ||
| 778 | return 0; | 852 | return 0; |
| 779 | } | 853 | } |
| 780 | 854 | ||
| 781 | static int sur40_vidioc_enum_fmt(struct file *file, void *priv, | 855 | static int sur40_vidioc_enum_fmt(struct file *file, void *priv, |
| 782 | struct v4l2_fmtdesc *f) | 856 | struct v4l2_fmtdesc *f) |
| 783 | { | 857 | { |
| 784 | if (f->index != 0) | 858 | if (f->index >= ARRAY_SIZE(sur40_pix_format)) |
| 785 | return -EINVAL; | 859 | return -EINVAL; |
| 786 | f->pixelformat = V4L2_PIX_FMT_GREY; | 860 | |
| 861 | f->pixelformat = sur40_pix_format[f->index].pixelformat; | ||
| 787 | f->flags = 0; | 862 | f->flags = 0; |
| 788 | return 0; | 863 | return 0; |
| 789 | } | 864 | } |
| @@ -791,25 +866,31 @@ static int sur40_vidioc_enum_fmt(struct file *file, void *priv, | |||
| 791 | static int sur40_vidioc_enum_framesizes(struct file *file, void *priv, | 866 | static int sur40_vidioc_enum_framesizes(struct file *file, void *priv, |
| 792 | struct v4l2_frmsizeenum *f) | 867 | struct v4l2_frmsizeenum *f) |
| 793 | { | 868 | { |
| 794 | if ((f->index != 0) || (f->pixel_format != V4L2_PIX_FMT_GREY)) | 869 | struct sur40_state *sur40 = video_drvdata(file); |
| 870 | |||
| 871 | if ((f->index != 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08) | ||
| 872 | && (f->pixel_format != V4L2_PIX_FMT_GREY))) | ||
| 795 | return -EINVAL; | 873 | return -EINVAL; |
| 796 | 874 | ||
| 797 | f->type = V4L2_FRMSIZE_TYPE_DISCRETE; | 875 | f->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
| 798 | f->discrete.width = sur40_video_format.width; | 876 | f->discrete.width = sur40->pix_fmt.width; |
| 799 | f->discrete.height = sur40_video_format.height; | 877 | f->discrete.height = sur40->pix_fmt.height; |
| 800 | return 0; | 878 | return 0; |
| 801 | } | 879 | } |
| 802 | 880 | ||
| 803 | static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv, | 881 | static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv, |
| 804 | struct v4l2_frmivalenum *f) | 882 | struct v4l2_frmivalenum *f) |
| 805 | { | 883 | { |
| 806 | if ((f->index > 1) || (f->pixel_format != V4L2_PIX_FMT_GREY) | 884 | struct sur40_state *sur40 = video_drvdata(file); |
| 807 | || (f->width != sur40_video_format.width) | 885 | |
| 808 | || (f->height != sur40_video_format.height)) | 886 | if ((f->index > 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08) |
| 809 | return -EINVAL; | 887 | && (f->pixel_format != V4L2_PIX_FMT_GREY)) |
| 888 | || (f->width != sur40->pix_fmt.width) | ||
| 889 | || (f->height != sur40->pix_fmt.height)) | ||
| 890 | return -EINVAL; | ||
| 810 | 891 | ||
| 811 | f->type = V4L2_FRMIVAL_TYPE_DISCRETE; | 892 | f->type = V4L2_FRMIVAL_TYPE_DISCRETE; |
| 812 | f->discrete.denominator = 60/(f->index+1); | 893 | f->discrete.denominator = 60; |
| 813 | f->discrete.numerator = 1; | 894 | f->discrete.numerator = 1; |
| 814 | return 0; | 895 | return 0; |
| 815 | } | 896 | } |
| @@ -862,13 +943,16 @@ static const struct v4l2_ioctl_ops sur40_video_ioctl_ops = { | |||
| 862 | .vidioc_querycap = sur40_vidioc_querycap, | 943 | .vidioc_querycap = sur40_vidioc_querycap, |
| 863 | 944 | ||
| 864 | .vidioc_enum_fmt_vid_cap = sur40_vidioc_enum_fmt, | 945 | .vidioc_enum_fmt_vid_cap = sur40_vidioc_enum_fmt, |
| 865 | .vidioc_try_fmt_vid_cap = sur40_vidioc_fmt, | 946 | .vidioc_try_fmt_vid_cap = sur40_vidioc_try_fmt, |
| 866 | .vidioc_s_fmt_vid_cap = sur40_vidioc_fmt, | 947 | .vidioc_s_fmt_vid_cap = sur40_vidioc_s_fmt, |
| 867 | .vidioc_g_fmt_vid_cap = sur40_vidioc_fmt, | 948 | .vidioc_g_fmt_vid_cap = sur40_vidioc_g_fmt, |
| 868 | 949 | ||
| 869 | .vidioc_enum_framesizes = sur40_vidioc_enum_framesizes, | 950 | .vidioc_enum_framesizes = sur40_vidioc_enum_framesizes, |
| 870 | .vidioc_enum_frameintervals = sur40_vidioc_enum_frameintervals, | 951 | .vidioc_enum_frameintervals = sur40_vidioc_enum_frameintervals, |
| 871 | 952 | ||
| 953 | .vidioc_g_parm = sur40_ioctl_parm, | ||
| 954 | .vidioc_s_parm = sur40_ioctl_parm, | ||
| 955 | |||
| 872 | .vidioc_enum_input = sur40_vidioc_enum_input, | 956 | .vidioc_enum_input = sur40_vidioc_enum_input, |
| 873 | .vidioc_g_input = sur40_vidioc_g_input, | 957 | .vidioc_g_input = sur40_vidioc_g_input, |
| 874 | .vidioc_s_input = sur40_vidioc_s_input, | 958 | .vidioc_s_input = sur40_vidioc_s_input, |
| @@ -891,16 +975,6 @@ static const struct video_device sur40_video_device = { | |||
| 891 | .release = video_device_release_empty, | 975 | .release = video_device_release_empty, |
| 892 | }; | 976 | }; |
| 893 | 977 | ||
| 894 | static const struct v4l2_pix_format sur40_video_format = { | ||
| 895 | .pixelformat = V4L2_PIX_FMT_GREY, | ||
| 896 | .width = SENSOR_RES_X / 2, | ||
| 897 | .height = SENSOR_RES_Y / 2, | ||
| 898 | .field = V4L2_FIELD_NONE, | ||
| 899 | .colorspace = V4L2_COLORSPACE_SRGB, | ||
| 900 | .bytesperline = SENSOR_RES_X / 2, | ||
| 901 | .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2), | ||
| 902 | }; | ||
| 903 | |||
| 904 | /* USB-specific object needed to register this driver with the USB subsystem. */ | 978 | /* USB-specific object needed to register this driver with the USB subsystem. */ |
| 905 | static struct usb_driver sur40_driver = { | 979 | static struct usb_driver sur40_driver = { |
| 906 | .name = DRIVER_SHORT, | 980 | .name = DRIVER_SHORT, |
