├── .gitignore ├── Makefile ├── README.md ├── LICENSE └── silead.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.cmd 2 | *.o 3 | *.ko 4 | *.mod* 5 | Module.symvers 6 | modules.order 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | MODULE_NAME = silead 2 | 3 | #CROSS_COMPILE ?= arm-linux-gnueabihf- 4 | #ARCH ?= arm 5 | ARCH := $(shell uname -m | sed -e s/i.86/i386/) 6 | KVER := $(shell uname -r) 7 | KSRC := /lib/modules/$(KVER)/build 8 | PWD = $(shell pwd) 9 | MODDESTDIR := /lib/modules/$(KVER)/kernel/drivers/input/touchscreen 10 | 11 | obj-m += silead.o 12 | 13 | .PHONY: all modules clean 14 | 15 | all: modules 16 | 17 | modules: 18 | make -C $(KSRC) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) modules 19 | 20 | install: 21 | install -p -m 644 $(MODULE_NAME).ko $(MODDESTDIR) 22 | /sbin/depmod -a $(KVER) 23 | 24 | uninstall: 25 | rm -f $(MODDESTDIR)/$(MODULE_NAME).ko 26 | /sbin/depmod -a $(KVER) 27 | 28 | clean: 29 | make -C $(KSRC) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) clean 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gslX68X 2 | Kernel space driver for Silead touch screen digitizers. Forked from Robert Dolca's driver originally posted to [lkml](https://lkml.org/lkml/2015/8/25/738). 3 | 4 | ## Compilation 5 | First you should get your kernel headers and build dependencies. Assuming debian based operating systems like Ubuntu 6 | ``` 7 | sudo apt-get install kernel-headers-$(uname -r) 8 | sudo apt-get build-dep linux-image-$(uname -r) 9 | ``` 10 | Then you can simply fetch this repository and compile it using 11 | ``` 12 | sudo apt-get install -y git 13 | git clone https://github.com/sigboe/gslX68X.git && cd gslX68X 14 | make 15 | ``` 16 | 17 | ## Firmware 18 | You will need to place a firmware file at `/lib/firmware/[hid].fw` where you replace [hid] with the lower case hardware ID of your device. 19 | In most cases, this is `mssl1680` or the exact part name such as `gsl1680`, `gsl1688`, `gsl3670`, `gsl3675` or `gsl3692`. 20 | 21 | If `mssl1680.fw` does not work, watch the `dmesg` output for a message similar to this one: 22 | ``` 23 | [ 5.124400] silead_ts i2c-MSSL1680:00: Direct firmware load for mssl1680.fw failed with error -2 24 | ``` 25 | This inidicates that the firmware should be named `mssl1680.fw`. 26 | 27 | Firmware for some devices can be obtained from [gsl-firmware](https://github.com/onitake/gsl-firmware). 28 | You can also find conversion tools there to create your own firmware image from Windows or Android drivers. 29 | Note that `silead.ko` requires firmware in 'plain' format. 30 | 31 | ## Using the driver 32 | You can start using the driver by `sudo insmod silead.ko` in the working directory where you compiled the driver. 33 | 34 | In most cases, some calibration is required before the driver produces accurate results. 35 | Use [xinput_calibrator](https://www.freedesktop.org/wiki/Software/xinput_calibrator/) for this purpose. 36 | 37 | ## Installation 38 | To install the driver permanently, type `sudo make install`. This will copy the `silead.ko` to `/lib/modules//kernel/drivers/input/touchscreen`. You may have to run `sudo update-initramfs -k all -u` or similar afterwards to update the initial ramdisk. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /silead.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * Copyright (C) 2014-2015, Intel Corporation 3 | * 4 | * Derived from: 5 | * gslX68X.c 6 | * Copyright (C) 2010-2015, Shanghai Sileadinc Co.Ltd 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * ------------------------------------------------------------------------- */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define SILEAD_TS_NAME "silead_ts" 32 | 33 | #define SILEAD_REG_RESET 0xE0 34 | #define SILEAD_REG_DATA 0x80 35 | #define SILEAD_REG_TOUCH_NR 0x80 36 | #define SILEAD_REG_POWER 0xBC 37 | #define SILEAD_REG_CLOCK 0xE4 38 | #define SILEAD_REG_STATUS 0xB0 39 | #define SILEAD_REG_ID 0xFC 40 | #define SILEAD_REG_MEM_CHECK 0xB0 41 | 42 | #define SILEAD_STATUS_OK 0x5A5A5A5A 43 | #define SILEAD_TS_DATA_LEN 44 44 | #define SILEAD_CLOCK 0x04 45 | 46 | #define SILEAD_CMD_RESET 0x88 47 | #define SILEAD_CMD_START 0x00 48 | 49 | #define SILEAD_POINT_DATA_LEN 0x04 50 | #define SILEAD_POINT_Y_OFF 0x00 51 | #define SILEAD_POINT_Y_MSB_OFF 0x01 52 | #define SILEAD_POINT_X_OFF 0x02 53 | #define SILEAD_POINT_X_MSB_OFF 0x03 54 | #define SILEAD_POINT_HSB_MASK 0x0F 55 | #define SILEAD_TOUCH_ID_MASK 0xF0 56 | #define SILEAD_EXTRA_DATA_MASK 0xF0 57 | 58 | #define SILEAD_DP_X_INVERT "touchscreen-inverted-x" 59 | #define SILEAD_DP_Y_INVERT "touchscreen-inverted-y" 60 | #define SILEAD_DP_XY_SWAP "touchscreen-swapped-x-y" 61 | #define SILEAD_DP_X_MAX "touchscreen-size-x" 62 | #define SILEAD_DP_Y_MAX "touchscreen-size-y" 63 | #define SILEAD_DP_MAX_FINGERS "silead,max-fingers" 64 | #define SILEAD_DP_FW_NAME "touchscreen-fw-name" 65 | #define SILEAD_DP_HOME_BUTTON "silead,home-button" 66 | #define SILEAD_PWR_GPIO_NAME "power" 67 | 68 | #define SILEAD_CMD_SLEEP_MIN 10000 69 | #define SILEAD_CMD_SLEEP_MAX 20000 70 | #define SILEAD_POWER_SLEEP 20 71 | #define SILEAD_STARTUP_SLEEP 30 72 | 73 | #define SILEAD_MAX_FINGERS 10 74 | #define SILEAD_MAX_X 4096 75 | #define SILEAD_MAX_Y 4096 76 | 77 | 78 | enum silead_ts_power { 79 | SILEAD_POWER_ON = 1, 80 | SILEAD_POWER_OFF = 0 81 | }; 82 | 83 | struct silead_ts_data { 84 | struct i2c_client *client; 85 | struct gpio_desc *gpio_power; 86 | struct input_dev *input; 87 | const char *custom_fw_name; 88 | char fw_name[I2C_NAME_SIZE]; 89 | u32 x_max; 90 | u32 y_max; 91 | u32 max_fingers; 92 | bool x_invert; 93 | bool y_invert; 94 | bool xy_swap; 95 | bool home_button; 96 | u32 chip_id; 97 | struct input_mt_pos pos[SILEAD_MAX_FINGERS]; 98 | int slots[SILEAD_MAX_FINGERS]; 99 | }; 100 | 101 | struct silead_fw_data { 102 | u32 offset; 103 | u32 val; 104 | }; 105 | 106 | static int silead_ts_request_input_dev(struct silead_ts_data *data) 107 | { 108 | struct device *dev = &data->client->dev; 109 | int error; 110 | 111 | data->input = devm_input_allocate_device(dev); 112 | if (!data->input) { 113 | dev_err(dev, 114 | "Failed to allocate input device\n"); 115 | return -ENOMEM; 116 | } 117 | 118 | if (!data->xy_swap) { 119 | input_set_abs_params(data->input, ABS_MT_POSITION_X, 0, 120 | data->x_max, 0, 0); 121 | input_set_abs_params(data->input, ABS_MT_POSITION_Y, 0, 122 | data->y_max, 0, 0); 123 | } else { 124 | input_set_abs_params(data->input, ABS_MT_POSITION_X, 0, 125 | data->y_max, 0, 0); 126 | input_set_abs_params(data->input, ABS_MT_POSITION_Y, 0, 127 | data->x_max, 0, 0); 128 | } 129 | 130 | input_mt_init_slots(data->input, data->max_fingers, 131 | INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED | 132 | INPUT_MT_TRACK); 133 | 134 | if(data->home_button) 135 | { 136 | input_set_capability(data->input, EV_KEY, KEY_LEFTMETA); 137 | } 138 | 139 | data->input->name = SILEAD_TS_NAME; 140 | data->input->phys = "input/ts"; 141 | data->input->id.bustype = BUS_I2C; 142 | 143 | error = input_register_device(data->input); 144 | if (error) { 145 | dev_err(dev, "Failed to register input device: %d\n", error); 146 | return error; 147 | } 148 | 149 | return 0; 150 | } 151 | 152 | static void silead_ts_report_touch(struct silead_ts_data *data, u16 x, u16 y, 153 | u8 id) 154 | { 155 | if (data->x_invert) 156 | x = data->x_max - x; 157 | 158 | if (data->y_invert) 159 | y = data->y_max - y; 160 | 161 | if (data->xy_swap) 162 | swap(x, y); 163 | 164 | input_mt_slot(data->input, id); 165 | input_mt_report_slot_state(data->input, MT_TOOL_FINGER, true); 166 | input_report_abs(data->input, ABS_MT_POSITION_X, x); 167 | input_report_abs(data->input, ABS_MT_POSITION_Y, y); 168 | } 169 | 170 | static void silead_ts_set_power(struct i2c_client *client, 171 | enum silead_ts_power state) 172 | { 173 | struct silead_ts_data *data = i2c_get_clientdata(client); 174 | 175 | if (data->gpio_power) { 176 | gpiod_set_value_cansleep(data->gpio_power, state); 177 | msleep(SILEAD_POWER_SLEEP); 178 | } 179 | } 180 | 181 | static void silead_ts_read_data(struct i2c_client *client) 182 | { 183 | struct silead_ts_data *data = i2c_get_clientdata(client); 184 | struct device *dev = &client->dev; 185 | u8 buf[SILEAD_TS_DATA_LEN]; 186 | int x, y, id, touch_nr, error, i, offset, index; 187 | int softbutton; 188 | bool softbutton_pressed; 189 | 190 | error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_DATA, 191 | SILEAD_TS_DATA_LEN, buf); 192 | if (error < 0) { 193 | dev_err(dev, "Data read error %d\n", error); 194 | return; 195 | } 196 | 197 | touch_nr = buf[0]; 198 | 199 | if (touch_nr < 0) 200 | return; 201 | if (touch_nr > data->max_fingers) 202 | return; 203 | 204 | dev_dbg(dev, "Touch number: %d\n", touch_nr); 205 | 206 | for (i = 1; i <= touch_nr; i++) { 207 | offset = i * SILEAD_POINT_DATA_LEN; 208 | 209 | softbutton = (buf[offset + SILEAD_POINT_Y_MSB_OFF] & 210 | SILEAD_EXTRA_DATA_MASK) >> 4; 211 | if (softbutton) { 212 | 213 | /* 214 | * For now only respond to softbutton == 0x01, some 215 | * tablets *without* a capacative button send 0x04 216 | * when crossing the edges of the screen. 217 | */ 218 | 219 | if (softbutton == 0x01) softbutton_pressed = true; 220 | 221 | continue; 222 | } 223 | 224 | 225 | /* Bits 4-7 are the touch id */ 226 | id = (buf[offset + SILEAD_POINT_X_MSB_OFF] & 227 | SILEAD_TOUCH_ID_MASK) >> 4; 228 | 229 | /* Bits 0-3 are MSB of X */ 230 | buf[offset + SILEAD_POINT_X_MSB_OFF] = 231 | buf[offset + SILEAD_POINT_X_MSB_OFF] & 232 | SILEAD_POINT_HSB_MASK; 233 | 234 | /* Bits 0-3 are MSB of Y */ 235 | buf[offset + SILEAD_POINT_Y_MSB_OFF] = 236 | buf[offset + SILEAD_POINT_Y_MSB_OFF] & 237 | SILEAD_POINT_HSB_MASK; 238 | 239 | y = le16_to_cpup((__le16 *)(buf + offset + SILEAD_POINT_Y_OFF)); 240 | x = le16_to_cpup((__le16 *)(buf + offset + SILEAD_POINT_X_OFF)); 241 | 242 | index = i - 1; 243 | data->pos[index].x = x; 244 | data->pos[index].y = y; 245 | 246 | #ifdef SOFTTRACKING 247 | input_mt_assign_slots(data->input, data->slots, data->pos, index, 0); 248 | #else 249 | data->slots[index] = id; 250 | //data->slots[index] = 0; 251 | #endif 252 | silead_ts_report_touch(data, x, y, data->slots[index]); 253 | 254 | dev_dbg(dev, "x=%d y=%d hw_id=%d sw_id=%d\n", x, y, id, data->slots[index]); 255 | } 256 | 257 | input_mt_sync_frame(data->input); 258 | 259 | if(data->home_button) 260 | input_report_key(data->input, KEY_LEFTMETA, softbutton_pressed); 261 | 262 | input_sync(data->input); 263 | } 264 | 265 | static int silead_ts_init(struct i2c_client *client) 266 | { 267 | struct silead_ts_data *data = i2c_get_clientdata(client); 268 | int error; 269 | 270 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET, 271 | SILEAD_CMD_RESET); 272 | if (error) 273 | goto i2c_write_err; 274 | usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX); 275 | 276 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_TOUCH_NR, 277 | data->max_fingers); 278 | if (error) 279 | goto i2c_write_err; 280 | usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX); 281 | 282 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_CLOCK, 283 | SILEAD_CLOCK); 284 | if (error) 285 | goto i2c_write_err; 286 | usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX); 287 | 288 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET, 289 | SILEAD_CMD_START); 290 | if (error) 291 | goto i2c_write_err; 292 | usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX); 293 | 294 | return 0; 295 | 296 | i2c_write_err: 297 | dev_err(&client->dev, "Registers clear error %d\n", error); 298 | return error; 299 | } 300 | 301 | static int silead_ts_reset(struct i2c_client *client) 302 | { 303 | int error; 304 | 305 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET, 306 | SILEAD_CMD_RESET); 307 | if (error) 308 | goto i2c_write_err; 309 | usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX); 310 | 311 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_CLOCK, 312 | SILEAD_CLOCK); 313 | if (error) 314 | goto i2c_write_err; 315 | usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX); 316 | 317 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_POWER, 318 | SILEAD_CMD_START); 319 | if (error) 320 | goto i2c_write_err; 321 | usleep_range(SILEAD_CMD_SLEEP_MIN, SILEAD_CMD_SLEEP_MAX); 322 | 323 | return 0; 324 | 325 | i2c_write_err: 326 | dev_err(&client->dev, "Chip reset error %d\n", error); 327 | return error; 328 | } 329 | 330 | static int silead_ts_startup(struct i2c_client *client) 331 | { 332 | int error; 333 | 334 | error = i2c_smbus_write_byte_data(client, SILEAD_REG_RESET, 0x00); 335 | if (error) { 336 | dev_err(&client->dev, "Startup error %d\n", error); 337 | return error; 338 | } 339 | msleep(SILEAD_STARTUP_SLEEP); 340 | 341 | return 0; 342 | } 343 | 344 | static int silead_ts_load_fw(struct i2c_client *client) 345 | { 346 | struct device *dev = &client->dev; 347 | struct silead_ts_data *data = i2c_get_clientdata(client); 348 | unsigned int fw_size, i; 349 | const struct firmware *fw; 350 | struct silead_fw_data *fw_data; 351 | int error; 352 | 353 | dev_dbg(dev, "Firmware file name: %s", data->fw_name); 354 | 355 | if (data->custom_fw_name) 356 | error = request_firmware(&fw, data->custom_fw_name, dev); 357 | else 358 | error = request_firmware(&fw, data->fw_name, dev); 359 | 360 | if (error) { 361 | dev_err(dev, "Firmware request error %d\n", error); 362 | return error; 363 | } 364 | 365 | fw_size = fw->size / sizeof(*fw_data); 366 | fw_data = (struct silead_fw_data *)fw->data; 367 | 368 | for (i = 0; i < fw_size; i++) { 369 | error = i2c_smbus_write_i2c_block_data(client, 370 | fw_data[i].offset, 371 | 4, 372 | (u8 *)&fw_data[i].val); 373 | if (error) { 374 | dev_err(dev, "Firmware load error %d\n", error); 375 | goto release_fw_err; 376 | } 377 | } 378 | 379 | release_firmware(fw); 380 | return 0; 381 | 382 | release_fw_err: 383 | release_firmware(fw); 384 | return error; 385 | } 386 | 387 | static u32 silead_ts_get_status(struct i2c_client *client) 388 | { 389 | int error; 390 | u32 status; 391 | 392 | error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_STATUS, 4, 393 | (u8 *)&status); 394 | if (error < 0) { 395 | dev_err(&client->dev, "Status read error %d\n", error); 396 | return error; 397 | } 398 | 399 | return le32_to_cpu(status); 400 | } 401 | 402 | static int silead_ts_get_id(struct i2c_client *client) 403 | { 404 | struct silead_ts_data *data = i2c_get_clientdata(client); 405 | int error; 406 | 407 | error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_ID, 4, 408 | (u8 *)&data->chip_id); 409 | 410 | data->chip_id = le32_to_cpu(data->chip_id); 411 | 412 | if (error < 0) { 413 | dev_err(&client->dev, "Chip ID read error %d\n", error); 414 | return error; 415 | } 416 | 417 | return 0; 418 | } 419 | 420 | static int silead_ts_setup(struct i2c_client *client) 421 | { 422 | struct silead_ts_data *data = i2c_get_clientdata(client); 423 | struct device *dev = &client->dev; 424 | int error; 425 | u32 status; 426 | 427 | silead_ts_set_power(client, SILEAD_POWER_OFF); 428 | silead_ts_set_power(client, SILEAD_POWER_ON); 429 | 430 | error = silead_ts_get_id(client); 431 | if (error) 432 | return error; 433 | dev_dbg(dev, "Chip ID: 0x%8X", data->chip_id); 434 | 435 | error = silead_ts_init(client); 436 | if (error) 437 | return error; 438 | 439 | error = silead_ts_reset(client); 440 | if (error) 441 | return error; 442 | 443 | error = silead_ts_load_fw(client); 444 | if (error) 445 | return error; 446 | 447 | error = silead_ts_startup(client); 448 | if (error) 449 | return error; 450 | 451 | status = silead_ts_get_status(client); 452 | if (status != SILEAD_STATUS_OK) { 453 | dev_err(dev, "Initialization error, status: 0x%X\n", status); 454 | return -ENODEV; 455 | } 456 | 457 | return 0; 458 | } 459 | 460 | static irqreturn_t silead_ts_threaded_irq_handler(int irq, void *id) 461 | { 462 | struct silead_ts_data *data = id; 463 | struct i2c_client *client = data->client; 464 | 465 | silead_ts_read_data(client); 466 | 467 | return IRQ_HANDLED; 468 | } 469 | 470 | static int silead_ts_read_props(struct i2c_client *client) 471 | { 472 | struct silead_ts_data *data = i2c_get_clientdata(client); 473 | struct device *dev = &client->dev; 474 | int error; 475 | 476 | error = device_property_read_u32(dev, SILEAD_DP_X_MAX, &data->x_max); 477 | if (error) { 478 | dev_dbg(dev, "Resolution X read error %d\n", error); 479 | data->x_max = SILEAD_MAX_X; 480 | } 481 | data->x_max--; /* Property contains size not max */ 482 | 483 | error = device_property_read_u32(dev, SILEAD_DP_Y_MAX, &data->y_max); 484 | if (error) { 485 | dev_dbg(dev, "Resolution Y read error %d\n", error); 486 | data->y_max = SILEAD_MAX_Y; 487 | } 488 | data->y_max--; /* Property contains size not max */ 489 | 490 | error = device_property_read_u32(dev, SILEAD_DP_MAX_FINGERS, 491 | &data->max_fingers); 492 | if (error) { 493 | dev_dbg(dev, "Max fingers read error %d\n", error); 494 | data->max_fingers = SILEAD_MAX_FINGERS; 495 | } 496 | 497 | error = device_property_read_string(dev, SILEAD_DP_FW_NAME, 498 | &data->custom_fw_name); 499 | if (error) 500 | dev_dbg(dev, "Firmware file name read error. Using default."); 501 | 502 | data->x_invert = 0; 503 | data->y_invert = 0; 504 | data->xy_swap = 0; 505 | data->home_button = 0; 506 | 507 | data->x_invert = device_property_read_bool(dev, SILEAD_DP_X_INVERT); 508 | data->y_invert = device_property_read_bool(dev, SILEAD_DP_Y_INVERT); 509 | data->xy_swap = device_property_read_bool(dev, SILEAD_DP_XY_SWAP); 510 | data->home_button = device_property_read_bool(dev, SILEAD_DP_HOME_BUTTON); 511 | 512 | dev_dbg(dev, "x_max = %d, y_max = %d, max_fingers = %d, x_invert = %d, y_invert = %d, xy_swap = %d", 513 | data->x_max, data->y_max, data->max_fingers, data->x_invert, 514 | data->y_invert, data->xy_swap); 515 | 516 | return 0; 517 | } 518 | 519 | #ifdef CONFIG_ACPI 520 | static int silead_ts_set_default_fw_name(struct silead_ts_data *data, 521 | const struct i2c_device_id *id) 522 | { 523 | const struct acpi_device_id *acpi_id; 524 | struct device *dev = &data->client->dev; 525 | int i; 526 | 527 | if (ACPI_HANDLE(dev)) { 528 | acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); 529 | if (!acpi_id) 530 | return -ENODEV; 531 | 532 | snprintf(data->fw_name, sizeof(data->fw_name), "%s.fw", acpi_id->id); 533 | 534 | for (i = 0; i < strlen(data->fw_name); i++) 535 | data->fw_name[i] = tolower(data->fw_name[i]); 536 | } else { 537 | snprintf(data->fw_name, sizeof(data->fw_name), "%s.fw", id->name); 538 | } 539 | 540 | return 0; 541 | } 542 | #else 543 | static int silead_ts_set_default_fw_name(struct silead_ts_data *data, 544 | const struct i2c_device_id *id) 545 | { 546 | snprintf(data->fw_name, sizeof(data->fw_name), "%s.fw", id->name); 547 | return 0; 548 | } 549 | #endif 550 | 551 | static int silead_ts_probe(struct i2c_client *client, 552 | const struct i2c_device_id *id) 553 | { 554 | struct silead_ts_data *data; 555 | struct device *dev = &client->dev; 556 | int error; 557 | 558 | if (!i2c_check_functionality(client->adapter, 559 | I2C_FUNC_I2C | 560 | I2C_FUNC_SMBUS_READ_I2C_BLOCK | 561 | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { 562 | dev_err(dev, "I2C functionality check failed\n"); 563 | return -ENXIO; 564 | } 565 | 566 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 567 | if (!data) 568 | return -ENOMEM; 569 | 570 | i2c_set_clientdata(client, data); 571 | data->client = client; 572 | 573 | error = silead_ts_set_default_fw_name(data, id); 574 | if (error) 575 | return error; 576 | 577 | /* If the IRQ is not filled by DT or ACPI subsytem 578 | * we can't continue without it */ 579 | if (client->irq <= 0) 580 | return -ENODEV; 581 | 582 | /* Power GPIO pin */ 583 | data->gpio_power = devm_gpiod_get_index(dev, SILEAD_PWR_GPIO_NAME, 584 | 0, GPIOD_OUT_LOW); 585 | if (IS_ERR(data->gpio_power)) { 586 | dev_dbg(dev, "Shutdown GPIO request failed\n"); 587 | data->gpio_power = NULL; 588 | } 589 | 590 | error = silead_ts_read_props(client); 591 | if (error) 592 | return error; 593 | 594 | error = silead_ts_setup(client); 595 | if (error) 596 | return error; 597 | 598 | error = silead_ts_request_input_dev(data); 599 | if (error) 600 | return error; 601 | 602 | error = devm_request_threaded_irq(dev, client->irq, NULL, 603 | silead_ts_threaded_irq_handler, 604 | IRQF_ONESHOT | IRQ_TYPE_EDGE_RISING, 605 | client->name, data); 606 | if (error) { 607 | dev_err(dev, "IRQ request failed %d\n", error); 608 | return error; 609 | } 610 | 611 | dev_dbg(dev, "Probing succeded\n"); 612 | return 0; 613 | } 614 | 615 | static int __maybe_unused silead_ts_suspend(struct device *dev) 616 | { 617 | struct i2c_client *client = to_i2c_client(dev); 618 | 619 | silead_ts_set_power(client, SILEAD_POWER_OFF); 620 | return 0; 621 | } 622 | 623 | static int __maybe_unused silead_ts_resume(struct device *dev) 624 | { 625 | struct i2c_client *client = to_i2c_client(dev); 626 | int error, status; 627 | 628 | silead_ts_set_power(client, SILEAD_POWER_ON); 629 | 630 | error = silead_ts_reset(client); 631 | if (error) 632 | return error; 633 | 634 | error = silead_ts_startup(client); 635 | if (error) 636 | return error; 637 | 638 | status = silead_ts_get_status(client); 639 | if (status != SILEAD_STATUS_OK) { 640 | dev_err(dev, "Resume error, status: 0x%X\n", status); 641 | return -ENODEV; 642 | } 643 | 644 | return 0; 645 | } 646 | 647 | static SIMPLE_DEV_PM_OPS(silead_ts_pm, silead_ts_suspend, silead_ts_resume); 648 | 649 | static const struct i2c_device_id silead_ts_id[] = { 650 | { "gsl1680", 0 }, 651 | { "gsl1688", 0 }, 652 | { "gsl3670", 0 }, 653 | { "gsl3675", 0 }, 654 | { "gsl3692", 0 }, 655 | { "mssl1680", 0 }, 656 | { } 657 | }; 658 | MODULE_DEVICE_TABLE(i2c, silead_ts_id); 659 | 660 | #ifdef CONFIG_ACPI 661 | static const struct acpi_device_id silead_ts_acpi_match[] = { 662 | { "GSL1680", 0 }, 663 | { "GSL1688", 0 }, 664 | { "GSL3670", 0 }, 665 | { "GSL3675", 0 }, 666 | { "GSL3692", 0 }, 667 | { "MSSL1680", 0 }, 668 | { } 669 | }; 670 | MODULE_DEVICE_TABLE(acpi, silead_ts_acpi_match); 671 | #endif 672 | 673 | static struct i2c_driver silead_ts_driver = { 674 | .probe = silead_ts_probe, 675 | .id_table = silead_ts_id, 676 | .driver = { 677 | .name = SILEAD_TS_NAME, 678 | .owner = THIS_MODULE, 679 | .acpi_match_table = ACPI_PTR(silead_ts_acpi_match), 680 | .pm = &silead_ts_pm, 681 | }, 682 | }; 683 | module_i2c_driver(silead_ts_driver); 684 | 685 | MODULE_AUTHOR("Robert Dolca "); 686 | MODULE_DESCRIPTION("Silead I2C touchscreen driver"); 687 | MODULE_LICENSE("GPL"); 688 | --------------------------------------------------------------------------------