louisliu | 923d320 | 2020-04-23 16:01:11 +0800 | [diff] [blame^] | 1 | #include <linux/module.h> |
| 2 | #include <linux/input.h> |
| 3 | #include <linux/input/mt.h> |
| 4 | #include <linux/interrupt.h> |
| 5 | #include <linux/platform_device.h> |
| 6 | #include <linux/async.h> |
| 7 | #include <linux/delay.h> |
| 8 | #include <linux/gpio.h> |
| 9 | #include <linux/kthread.h> |
| 10 | #include <linux/miscdevice.h> |
| 11 | #include <linux/uaccess.h> |
| 12 | #include <linux/version.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/wait.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/ioctl.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/syscalls.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/cdev.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/pm_wakeup.h> //#include <linux/wakelock.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/mutex.h> |
| 26 | #include <linux/pm.h> |
| 27 | #include <linux/time.h> |
| 28 | #include <linux/namei.h> |
| 29 | #include <linux/mount.h> |
| 30 | #include <linux/poll.h> |
| 31 | #include <linux/of_gpio.h> |
| 32 | #include "elan_fp_qcom_tee.h" |
| 33 | |
| 34 | #define VERSION_LOG "2.2.1" |
| 35 | |
| 36 | static int elan_debug = 1; |
| 37 | #define ELAN_DEBUG(format, args ...) \ |
| 38 | do { \ |
| 39 | if (elan_debug) \ |
| 40 | printk("[ELAN] " format, ##args); \ |
| 41 | } while(0) |
| 42 | |
| 43 | #define KEY_FP_INT KEY_POWER //KEY_WAKEUP // change by customer & framework support |
| 44 | #define KEY_FP_INT2 KEY_1 // change by customer & framework support |
| 45 | #define SET_SPI_OWNER (0) |
| 46 | #if SET_SPI_OWNER |
| 47 | #include <soc/qcom/scm.h> |
| 48 | #endif |
| 49 | |
| 50 | #if defined(CONFIG_FB) |
| 51 | #include <linux/notifier.h> |
| 52 | #include <linux/fb.h> |
| 53 | #include <linux/signal.h> |
| 54 | #endif |
| 55 | |
| 56 | static int factory_status = 0; |
| 57 | static DEFINE_MUTEX(elan_factory_mutex); |
| 58 | static DECLARE_WAIT_QUEUE_HEAD(elan_poll_wq); |
| 59 | static int elan_work_flag = 0; |
| 60 | #if defined(CONFIG_FB) |
| 61 | static struct notifier_block fb_notif; |
| 62 | static int pid_fp = -1; |
| 63 | static int display_status = -1; |
| 64 | #endif |
| 65 | //[Z20][fingerprint][Kent][17111801][begin]add power gpio for vdd |
| 66 | #define VDD_POWER_GPIO 1 |
| 67 | //[Z20][fingerprint][Kent][17111801][end]add power gpio for vdd |
| 68 | struct elan_data { |
| 69 | int int_gpio; |
| 70 | int irq; |
| 71 | int rst_gpio; |
| 72 | int irq_is_disable; |
| 73 | struct miscdevice elan_dev; /* char device for ioctl */ |
| 74 | struct platform_device *pdev; |
| 75 | struct input_dev *input_dev; |
| 76 | spinlock_t irq_lock; |
| 77 | struct wakeup_source wake_lock; //struct wake_lock wake_lock; |
| 78 | struct wakeup_source hal_wake_lock; //struct wake_lock hal_wake_lock; |
| 79 | //[Z20][fingerprint][Kent][17111802][begin]add power gpio for vdd |
| 80 | #if VDD_POWER_GPIO |
| 81 | int vdd_gpio; |
| 82 | #endif |
| 83 | //[Z20][fingerprint][Kent][17111802][end]add power gpio for vdd |
| 84 | }; |
| 85 | |
| 86 | void elan_irq_enable(void *_fp) |
| 87 | { |
| 88 | struct elan_data *fp = _fp; |
| 89 | unsigned long irqflags = 0; |
| 90 | ELAN_DEBUG("IRQ Enable = %d.\n", fp->irq); |
| 91 | |
| 92 | spin_lock_irqsave(&fp->irq_lock, irqflags); |
| 93 | if (fp->irq_is_disable) |
| 94 | { |
| 95 | enable_irq(fp->irq); |
| 96 | fp->irq_is_disable = 0; |
| 97 | } |
| 98 | spin_unlock_irqrestore(&fp->irq_lock, irqflags); |
| 99 | } |
| 100 | |
| 101 | void elan_irq_disable(void *_fp) |
| 102 | { |
| 103 | struct elan_data *fp = _fp; |
| 104 | unsigned long irqflags; |
| 105 | ELAN_DEBUG("IRQ Disable = %d.\n", fp->irq); |
| 106 | |
| 107 | spin_lock_irqsave(&fp->irq_lock, irqflags); |
| 108 | if (!fp->irq_is_disable) |
| 109 | { |
| 110 | fp->irq_is_disable = 1; |
| 111 | disable_irq_nosync(fp->irq); |
| 112 | } |
| 113 | spin_unlock_irqrestore(&fp->irq_lock, irqflags); |
| 114 | } |
| 115 | |
| 116 | static ssize_t show_drv_version_value(struct device *dev, struct device_attribute *attr, char *buf) |
| 117 | { |
| 118 | return sprintf(buf, "%s\n", VERSION_LOG); |
| 119 | } |
| 120 | static DEVICE_ATTR(drv_version, S_IRUGO, show_drv_version_value, NULL); |
| 121 | |
| 122 | static ssize_t elan_debug_value(struct device *dev, struct device_attribute *attr, char *buf) |
| 123 | { |
| 124 | if(elan_debug){ |
| 125 | elan_debug=0; |
| 126 | } else { |
| 127 | elan_debug=1; |
| 128 | } |
| 129 | return sprintf(buf, "[ELAN] elan debug %d\n", elan_debug); |
| 130 | } |
| 131 | static DEVICE_ATTR(elan_debug, S_IRUGO, elan_debug_value, NULL); |
| 132 | |
| 133 | static struct attribute *elan_attributes[] = { |
| 134 | &dev_attr_drv_version.attr, |
| 135 | &dev_attr_elan_debug.attr, |
| 136 | NULL |
| 137 | }; |
| 138 | |
| 139 | static struct attribute_group elan_attr_group = { |
| 140 | .attrs = elan_attributes, |
| 141 | }; |
| 142 | |
| 143 | static void elan_reset(struct elan_data *fp) |
| 144 | { |
| 145 | /* Developement platform */ |
| 146 | gpio_set_value(fp->rst_gpio, 0); |
| 147 | mdelay(5); |
| 148 | gpio_set_value(fp->rst_gpio, 1); |
| 149 | mdelay(50); |
| 150 | } |
| 151 | |
| 152 | #if defined(CONFIG_FB) |
| 153 | |
| 154 | static int send_sig_to_pid(int sig, pid_t pid) |
| 155 | { |
| 156 | struct siginfo info; |
| 157 | |
| 158 | info.si_signo = sig; |
| 159 | info.si_errno = 0; |
| 160 | info.si_code = SI_USER; |
| 161 | info.si_pid = get_current()->pid; |
| 162 | info.si_uid = from_kuid_munged(current_user_ns(), current_uid()); |
| 163 | |
| 164 | return kill_proc_info(sig, &info, pid); |
| 165 | } |
| 166 | |
| 167 | static int fb_notifier_callback(struct notifier_block *self, unsigned long event, void *data) |
| 168 | { |
| 169 | struct fb_event *evdata = data; |
| 170 | int *blank ; |
| 171 | |
| 172 | //[Z20][fingerprint][180123begin]void fb system crash |
| 173 | if (event != 0x10) |
| 174 | return 0; |
| 175 | //[Z20][fingerprint][180123end]void fb system crash |
| 176 | |
| 177 | //[Z20][fingerprint][180123begin]check the null pointer |
| 178 | if(evdata == NULL) |
| 179 | { |
| 180 | pr_err("%s data is NULL\n",__func__); |
| 181 | return 0; |
| 182 | } |
| 183 | blank = evdata->data; |
| 184 | if(blank == NULL) |
| 185 | { |
| 186 | pr_err("%s blank is NULL\n",__func__); |
| 187 | return 0; |
| 188 | } |
| 189 | //[Z20][fingerprint][180123end]check the null pointer |
| 190 | ELAN_DEBUG("%s fb notifier callback event = %lu, evdata->data = %d\n",__func__, event, *blank); |
| 191 | if (evdata && evdata->data) { |
| 192 | if (event == 0x10) { |
| 193 | if (*blank == FB_BLANK_UNBLANK) { |
| 194 | display_status = 0; |
| 195 | if(pid_fp != -1) |
| 196 | send_sig_to_pid(SIGUSR2,pid_fp); |
| 197 | ELAN_DEBUG("Display On\n"); |
| 198 | } |
| 199 | else if (*blank == FB_BLANK_POWERDOWN) { |
| 200 | display_status = 1; |
| 201 | if(pid_fp != -1) |
| 202 | send_sig_to_pid(SIGUSR2,pid_fp); |
| 203 | ELAN_DEBUG("Display Off\n"); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | return 0; |
| 208 | } |
| 209 | #endif |
| 210 | |
| 211 | static long elan_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
| 212 | { |
| 213 | struct elan_data *fp = filp->private_data; |
| 214 | int keycode; |
| 215 | int wake_lock_arg; |
| 216 | |
| 217 | ELAN_DEBUG("%s() : cmd = [%04X]\n", __func__, cmd); |
| 218 | |
| 219 | switch(cmd) |
| 220 | { |
| 221 | case ID_IOCTL_RESET: //6 |
| 222 | elan_reset(fp); |
| 223 | ELAN_DEBUG("[IOCTL] RESET\n"); |
| 224 | break; |
| 225 | |
| 226 | case ID_IOCTL_POLL_INIT: //20 |
| 227 | elan_work_flag = 0; |
| 228 | ELAN_DEBUG("[IOCTL] POLL INIT\n"); |
| 229 | break; |
| 230 | |
| 231 | case ID_IOCTL_POLL_EXIT: //23 |
| 232 | elan_work_flag = 1; |
| 233 | wake_up(&elan_poll_wq); |
| 234 | ELAN_DEBUG("[IOCTL] POLL EXIT\n"); |
| 235 | break; |
| 236 | |
| 237 | case ID_IOCTL_INPUT_KEYCODE: //22 |
| 238 | keycode =(int __user)arg; |
| 239 | ELAN_DEBUG("[IOCTL] KEYCODE DOWN & UP, keycode = %d \n", keycode); |
| 240 | if (!keycode) { |
| 241 | ELAN_DEBUG("Keycode %d not defined, ignored\n", (int __user)arg); |
| 242 | break ; |
| 243 | } |
| 244 | input_report_key(fp->input_dev, keycode, 1); // Added for KEY Event |
| 245 | input_sync(fp->input_dev); |
| 246 | input_report_key(fp->input_dev, keycode, 0); // Added for KEY Event |
| 247 | input_sync(fp->input_dev); |
| 248 | break; |
| 249 | |
| 250 | case ID_IOCTL_SET_KEYCODE: //24 |
| 251 | keycode =(int __user)arg; |
| 252 | ELAN_DEBUG("[IOCTL] SET KEYCODE, keycode = %d \n", keycode); |
| 253 | if (!keycode) { |
| 254 | ELAN_DEBUG("Keycode %d not defined, ignored\n", (int __user)arg); |
| 255 | break ; |
| 256 | } |
| 257 | input_set_capability(fp->input_dev, EV_KEY, keycode); |
| 258 | set_bit(keycode, fp->input_dev->keybit); |
| 259 | break; |
| 260 | |
| 261 | case ID_IOCTL_INPUT_KEYCODE_DOWN: //28 |
| 262 | keycode =(int __user)arg; |
| 263 | ELAN_DEBUG("[IOCTL] KEYCODE DOWN, keycode = %d \n", keycode); |
| 264 | if(!keycode) { |
| 265 | ELAN_DEBUG("Keycode %d not defined, ignored\n", (int __user)arg); |
| 266 | break ; |
| 267 | } |
| 268 | input_report_key(fp->input_dev, keycode, 1); |
| 269 | input_sync(fp->input_dev); |
| 270 | break; |
| 271 | |
| 272 | case ID_IOCTL_INPUT_KEYCODE_UP: //29 |
| 273 | keycode =(int __user)arg; |
| 274 | ELAN_DEBUG("[IOCTL] KEYCODE UP, keycode = %d \n", keycode); |
| 275 | if(!keycode) { |
| 276 | ELAN_DEBUG("Keycode %d not defined, ignored\n", (int __user)arg); |
| 277 | break ; |
| 278 | } |
| 279 | input_report_key(fp->input_dev, keycode, 0); |
| 280 | input_sync(fp->input_dev); |
| 281 | break; |
| 282 | |
| 283 | case ID_IOCTL_READ_FACTORY_STATUS: //26 |
| 284 | mutex_lock(&elan_factory_mutex); |
| 285 | ELAN_DEBUG("[IOCTL] READ factory_status = %d\n", factory_status); |
| 286 | mutex_unlock(&elan_factory_mutex); |
| 287 | return factory_status; |
| 288 | break; |
| 289 | |
| 290 | case ID_IOCTL_WRITE_FACTORY_STATUS: //27 |
| 291 | mutex_lock(&elan_factory_mutex); |
| 292 | factory_status = (int __user)arg; |
| 293 | ELAN_DEBUG("[IOCTL] WRITE factory_status = %d\n", factory_status); |
| 294 | mutex_unlock(&elan_factory_mutex); |
| 295 | break; |
| 296 | |
| 297 | case ID_IOCTL_INT_STATUS: //40 |
| 298 | return gpio_get_value(fp->int_gpio); |
| 299 | |
| 300 | case ID_IOCTL_WAKE_LOCK_UNLOCK: //41 |
| 301 | wake_lock_arg = (int __user)arg; |
| 302 | if(!wake_lock_arg) |
| 303 | { |
| 304 | __pm_relax(&fp->hal_wake_lock); //wake_unlock(&fp->hal_wake_lock); |
| 305 | ELAN_DEBUG("[IOCTL] HAL WAKE UNLOCK = %d\n", wake_lock_arg); |
| 306 | } |
| 307 | else if(wake_lock_arg) |
| 308 | { |
| 309 | __pm_stay_awake(&fp->hal_wake_lock); //wake_lock(&fp->hal_wake_lock); |
| 310 | ELAN_DEBUG("[IOCTL] HAL WAKE LOCK = %d\n", wake_lock_arg); |
| 311 | } |
| 312 | else |
| 313 | ELAN_DEBUG("[IOCTL] ERROR WAKE LOCK ARGUMENT\n"); |
| 314 | break; |
| 315 | |
| 316 | case ID_IOCTL_EN_IRQ: //55 |
| 317 | elan_irq_enable(fp); |
| 318 | ELAN_DEBUG("[IOCTL] ENABLE IRQ\n"); |
| 319 | break; |
| 320 | |
| 321 | case ID_IOCTL_DIS_IRQ: //66 |
| 322 | elan_irq_disable(fp); |
| 323 | ELAN_DEBUG("[IOCTL] DISABLE IRQ\n"); |
| 324 | break; |
| 325 | |
| 326 | case ID_IOCTL_SET_IRQ_TYPE: //91 |
| 327 | ELAN_DEBUG("[IOCTL] SET IRQ TYPE\n"); |
| 328 | irq_set_irq_type(fp->irq, IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND | IRQF_ONESHOT); |
| 329 | break; |
| 330 | |
| 331 | case ID_IOCTL_DISPLAY_STATUS: //93 |
| 332 | ELAN_DEBUG("[IOCTL] DISPLAY_STATUS = %d\n", display_status); |
| 333 | return display_status; |
| 334 | |
| 335 | case ID_IOCTL_DISPLAY_NOTIFY: //94 |
| 336 | break; |
| 337 | |
| 338 | case ID_IOCTL_SET_PID: //94 |
| 339 | pid_fp = (int __user)arg; |
| 340 | ELAN_DEBUG("[IOCTL] ID_IOCTL_SET_PID = %d\n", pid_fp); |
| 341 | break; |
| 342 | |
| 343 | default: |
| 344 | ELAN_DEBUG("INVALID COMMAND\n"); |
| 345 | break; |
| 346 | } |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static unsigned int elan_poll(struct file *file, poll_table *wait) |
| 351 | { |
| 352 | int mask=0; |
| 353 | ELAN_DEBUG("%s()\n",__func__); |
| 354 | |
| 355 | wait_event_interruptible(elan_poll_wq, elan_work_flag > 0); |
| 356 | if(elan_work_flag > 0) |
| 357 | mask = elan_work_flag; |
| 358 | |
| 359 | elan_work_flag = 0; |
| 360 | return mask; |
| 361 | } |
| 362 | |
| 363 | static int elan_open(struct inode *inode, struct file *filp) |
| 364 | { |
| 365 | struct elan_data *fp = container_of(filp->private_data, struct elan_data, elan_dev); |
| 366 | filp->private_data = fp; |
| 367 | ELAN_DEBUG("%s()\n", __func__); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | static int elan_close(struct inode *inode, struct file *filp) |
| 372 | { |
| 373 | ELAN_DEBUG("%s()\n", __func__); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static const struct file_operations elan_fops = { |
| 378 | .owner = THIS_MODULE, |
| 379 | .open = elan_open, |
| 380 | .unlocked_ioctl = elan_ioctl, |
| 381 | .poll = elan_poll, |
| 382 | .release = elan_close, |
| 383 | }; |
| 384 | |
| 385 | #if SET_SPI_OWNER |
| 386 | static int set_pipe_ownership(void) |
| 387 | { |
| 388 | const u32 TZ_BLSP_MODIFY_OWNERSHIP_ID = 3; |
| 389 | const u32 TZBSP_TZ_ID = 3; |
| 390 | int rc; |
| 391 | struct scm_desc desc = { |
| 392 | .arginfo = SCM_ARGS(2), |
| 393 | .args[0] = 3, |
| 394 | .args[1] = TZBSP_TZ_ID, |
| 395 | }; |
| 396 | |
| 397 | rc = scm_call2(SCM_SIP_FNID(SCM_SVC_TZ, TZ_BLSP_MODIFY_OWNERSHIP_ID), &desc); |
| 398 | |
| 399 | if(rc || desc.ret[0]) |
| 400 | { |
| 401 | ELAN_DEBUG("%s() FAIL\n", __func__); |
| 402 | return -EINVAL; |
| 403 | } |
| 404 | ELAN_DEBUG("%s() Success\n", __func__); |
| 405 | return 0; |
| 406 | } |
| 407 | #endif |
| 408 | |
| 409 | static irqreturn_t elan_irq_handler(int irq, void *dev_id) |
| 410 | { |
| 411 | struct elan_data *fp = (struct elan_data *)dev_id; |
| 412 | |
| 413 | ELAN_DEBUG("%s()\n", __func__); |
| 414 | __pm_wakeup_event(&fp->wake_lock, msecs_to_jiffies(1000)); //wake_lock_timeout(&fp->wake_lock, msecs_to_jiffies(1000)); |
| 415 | if(fp == NULL) |
| 416 | return IRQ_NONE; |
| 417 | elan_work_flag = 1; |
| 418 | wake_up(&elan_poll_wq); |
| 419 | |
| 420 | return IRQ_HANDLED; |
| 421 | } |
| 422 | |
| 423 | static int elan_setup_cdev(struct elan_data *fp) |
| 424 | { |
| 425 | |
| 426 | fp->elan_dev.minor = MISC_DYNAMIC_MINOR; |
| 427 | fp->elan_dev.name = "elan_fp"; |
| 428 | fp->elan_dev.fops = &elan_fops; |
| 429 | fp->elan_dev.mode = S_IFREG|S_IRWXUGO; |
| 430 | if (misc_register(&fp->elan_dev) < 0) { |
| 431 | ELAN_DEBUG("misc_register failed\n"); |
| 432 | return -1; |
| 433 | } |
| 434 | else { |
| 435 | ELAN_DEBUG("misc_register finished\n"); |
| 436 | } |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static int elan_sysfs_create(struct elan_data *sysfs) |
| 441 | { |
| 442 | struct elan_data *fp = platform_get_drvdata(sysfs->pdev); |
| 443 | int ret = 0; |
| 444 | |
| 445 | /* Register sysfs */ |
| 446 | ret = sysfs_create_group(&fp->pdev->dev.kobj, &elan_attr_group); |
| 447 | if (ret) { |
| 448 | ELAN_DEBUG("create sysfs attributes failed, ret = %d\n", ret); |
| 449 | goto fail_un; |
| 450 | } |
| 451 | return 0; |
| 452 | fail_un: |
| 453 | /* Remove sysfs */ |
| 454 | sysfs_remove_group(&fp->pdev->dev.kobj, &elan_attr_group); |
| 455 | |
| 456 | return ret; |
| 457 | } |
| 458 | |
| 459 | static int elan_gpio_config(struct elan_data *fp) |
| 460 | { |
| 461 | int ret = 0; |
| 462 | |
| 463 | // Configure INT GPIO (Input) |
| 464 | ret = gpio_request(fp->int_gpio, "elan-irq"); |
| 465 | if (ret < 0) |
| 466 | ELAN_DEBUG("interrupt pin request gpio failed, ret = %d\n", ret); |
| 467 | else { |
| 468 | gpio_direction_input(fp->int_gpio); |
| 469 | fp->irq = gpio_to_irq(fp->int_gpio); |
| 470 | if(fp->irq < 0) { |
| 471 | ELAN_DEBUG("gpio to irq failed, irq = %d\n", fp->irq); |
| 472 | ret = -1; |
| 473 | } |
| 474 | else |
| 475 | ELAN_DEBUG("gpio to irq success, irq = %d\n",fp->irq); |
| 476 | } |
| 477 | |
| 478 | // Configure RST GPIO (Output) |
| 479 | ret = gpio_request(fp->rst_gpio, "elan-rst"); |
| 480 | if (ret < 0) { |
| 481 | gpio_free(fp->int_gpio); |
| 482 | free_irq(fp->irq, fp); |
| 483 | ELAN_DEBUG("reset pin request gpio failed, ret = %d\n", ret); |
| 484 | } |
| 485 | else |
| 486 | gpio_direction_output(fp->rst_gpio, 1); |
| 487 | //[Z20][fingerprint][Kent][17111803][begin]add power gpio for vdd |
| 488 | #if VDD_POWER_GPIO |
| 489 | // Configure VDD GPIO (Output) |
| 490 | ret = gpio_request(fp->vdd_gpio, "elan-vdd"); |
| 491 | if (ret < 0) { |
| 492 | gpio_free(fp->rst_gpio); |
| 493 | gpio_free(fp->int_gpio); |
| 494 | free_irq(fp->irq, fp); |
| 495 | ELAN_DEBUG("reset pin request gpio failed, ret = %d\n", ret); |
| 496 | } |
| 497 | else |
| 498 | gpio_direction_output(fp->vdd_gpio, 1); |
| 499 | #endif |
| 500 | //[Z20][fingerprint][Kent][17111803][end]add power gpio for vdd |
| 501 | return ret; |
| 502 | } |
| 503 | |
| 504 | static int elan_dts_init(struct elan_data *fp, struct device_node *np) |
| 505 | { |
| 506 | fp->rst_gpio = of_get_named_gpio(np, "elan,rst-gpio", 0); |
| 507 | ELAN_DEBUG("rst_gpio = %d\n", fp->rst_gpio); |
| 508 | if (fp->rst_gpio < 0) |
| 509 | return fp->rst_gpio; |
| 510 | |
| 511 | fp->int_gpio = of_get_named_gpio(np, "elan,irq-gpio", 0); |
| 512 | ELAN_DEBUG("int_gpio = %d\n", fp->int_gpio); |
| 513 | if (fp->int_gpio < 0) |
| 514 | return fp->int_gpio; |
| 515 | //[Z20][fingerprint][Kent][17111804][begin]add power gpio for vdd |
| 516 | #if VDD_POWER_GPIO |
| 517 | fp->vdd_gpio = of_get_named_gpio(np, "elan,vdd-gpio", 0); |
| 518 | ELAN_DEBUG("vdd_gpio = %d\n", fp->vdd_gpio); |
| 519 | if (fp->vdd_gpio < 0) |
| 520 | return fp->vdd_gpio; |
| 521 | #endif |
| 522 | //[Z20][fingerprint][Kent][17111804][end]add power gpio for vdd |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | static int elan_probe(struct platform_device *pdev) |
| 527 | { |
| 528 | struct elan_data *fp = NULL; |
| 529 | struct input_dev *input_dev = NULL; |
| 530 | int ret = 0; |
| 531 | |
| 532 | ELAN_DEBUG("%s(), version = %s\n", __func__, VERSION_LOG); |
| 533 | |
| 534 | /* Allocate Device Data */ |
| 535 | fp = devm_kzalloc(&pdev->dev, sizeof(struct elan_data), GFP_KERNEL); |
| 536 | if(!fp) |
| 537 | ELAN_DEBUG("kzmalloc elan data failed\n"); |
| 538 | |
| 539 | /* Init Input Device */ |
| 540 | input_dev = input_allocate_device(); |
| 541 | if (!input_dev) |
| 542 | ELAN_DEBUG("alloc input_dev failed\n"); |
| 543 | |
| 544 | fp->pdev = pdev; |
| 545 | |
| 546 | platform_set_drvdata(pdev, fp); |
| 547 | |
| 548 | input_dev->name = "elan"; |
| 549 | input_dev->id.bustype = BUS_SPI; |
| 550 | input_dev->dev.parent = &pdev->dev; |
| 551 | input_set_drvdata(input_dev, fp); |
| 552 | |
| 553 | input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY); |
| 554 | input_set_capability(input_dev, EV_KEY, KEY_FP_INT); // change by customer, send key event to framework. KEY_xxx could be changed. |
| 555 | input_set_capability(input_dev, EV_KEY, KEY_FP_INT2); // change by customer, send key event to framework. KEY_xxx could be changed. |
| 556 | |
| 557 | fp->input_dev = input_dev; |
| 558 | |
| 559 | /* Init Sysfs */ |
| 560 | ret = elan_sysfs_create(fp); |
| 561 | if(ret < 0) |
| 562 | ELAN_DEBUG("sysfs create failed, ret = %d\n", ret); |
| 563 | |
| 564 | /* Init Char Device */ |
| 565 | ret = elan_setup_cdev(fp); |
| 566 | if(ret < 0) |
| 567 | ELAN_DEBUG("setup device failed, ret = %d\n", ret); |
| 568 | |
| 569 | /* Register Input Device */ |
| 570 | ret = input_register_device(input_dev); |
| 571 | if(ret) |
| 572 | ELAN_DEBUG("register input device failed, ret = %d\n", ret); |
| 573 | |
| 574 | ret = elan_dts_init(fp, pdev->dev.of_node); |
| 575 | if(ret < 0) |
| 576 | ELAN_DEBUG("device tree initial failed, ret = %d\n", ret); |
| 577 | |
| 578 | ret = elan_gpio_config(fp); |
| 579 | if(ret < 0) |
| 580 | ELAN_DEBUG("gpio config failed, ret = %d\n", ret); |
| 581 | |
| 582 | wakeup_source_init(&fp->wake_lock, "fp_wake_lock"); //wake_lock_init(&fp->wake_lock, WAKE_LOCK_SUSPEND, "fp_wake_lock"); |
| 583 | wakeup_source_init(&fp->hal_wake_lock, "hal_fp_wake_lock"); //wake_lock_init(&fp->hal_wake_lock, WAKE_LOCK_SUSPEND, "hal_fp_wake_lock"); |
| 584 | |
| 585 | ret = request_irq(fp->irq, elan_irq_handler, |
| 586 | IRQF_NO_SUSPEND | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
| 587 | pdev->dev.driver->name, fp); |
| 588 | if(ret) |
| 589 | ELAN_DEBUG("request irq failed, ret = %d\n", ret); |
| 590 | |
| 591 | irq_set_irq_wake(fp->irq, 1); |
| 592 | |
| 593 | spin_lock_init(&fp->irq_lock); |
| 594 | |
| 595 | #if defined(CONFIG_FB) |
| 596 | fb_notif.notifier_call = fb_notifier_callback; |
| 597 | fb_register_client(&fb_notif); |
| 598 | #endif |
| 599 | |
| 600 | /* Set Spi to TZ */ |
| 601 | #if SET_SPI_OWNER |
| 602 | ret = set_pipe_ownership(); |
| 603 | #endif |
| 604 | |
| 605 | ELAN_DEBUG("%s() End\n", __func__); |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int elan_remove(struct platform_device *pdev) |
| 610 | { |
| 611 | struct elan_data *fp = platform_get_drvdata(pdev); |
| 612 | |
| 613 | if (fp->irq) |
| 614 | free_irq(fp->irq, fp); |
| 615 | //[Z20][fingerprint][Kent][17111805][begin]add power gpio for vdd |
| 616 | #if VDD_POWER_GPIO |
| 617 | gpio_free(fp->vdd_gpio); |
| 618 | #endif |
| 619 | //[Z20][fingerprint][Kent][17111805][end]add power gpio for vdd |
| 620 | gpio_free(fp->int_gpio); |
| 621 | gpio_free(fp->rst_gpio); |
| 622 | |
| 623 | misc_deregister(&fp->elan_dev); |
| 624 | input_free_device(fp->input_dev); |
| 625 | |
| 626 | #if defined(CONFIG_FB) |
| 627 | fb_unregister_client(&fb_notif); |
| 628 | #endif |
| 629 | |
| 630 | kfree(fp); |
| 631 | |
| 632 | platform_set_drvdata(pdev, NULL); |
| 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | #ifdef CONFIG_PM_SLEEP |
| 638 | static int elan_suspend(struct device *dev) |
| 639 | { |
| 640 | ELAN_DEBUG("elan suspend!\n"); |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static int elan_resume(struct device *dev) |
| 645 | { |
| 646 | ELAN_DEBUG("elan resume!\n"); |
| 647 | return 0; |
| 648 | } |
| 649 | #endif |
| 650 | |
| 651 | static SIMPLE_DEV_PM_OPS(elan_pm_ops, elan_suspend, elan_resume); |
| 652 | |
| 653 | #ifdef CONFIG_OF |
| 654 | static struct of_device_id elan_metallica_table[] = { |
| 655 | { .compatible = "elan,elan_fp",}, |
| 656 | { }, |
| 657 | }; |
| 658 | #else |
| 659 | #define elan_metallica_table NULL |
| 660 | #endif |
| 661 | |
| 662 | static struct platform_driver elan_driver = { |
| 663 | .driver = { |
| 664 | .name = "elan", |
| 665 | .owner = THIS_MODULE, |
| 666 | .pm = &elan_pm_ops, |
| 667 | .of_match_table = elan_metallica_table, |
| 668 | }, |
| 669 | .probe = elan_probe, |
| 670 | .remove = elan_remove, |
| 671 | }; |
| 672 | |
| 673 | static int __init elan_init(void) |
| 674 | { |
| 675 | int ret = 0; |
| 676 | ELAN_DEBUG("%s() Start\n", __func__); |
| 677 | |
| 678 | ret = platform_driver_register(&elan_driver); |
| 679 | if(ret < 0) |
| 680 | ELAN_DEBUG("%s FAIL !\n", __func__); |
| 681 | |
| 682 | ELAN_DEBUG("%s() End\n", __func__); |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static void __exit elan_exist(void) |
| 687 | { |
| 688 | platform_driver_unregister(&elan_driver); |
| 689 | } |
| 690 | |
| 691 | module_init(elan_init); |
| 692 | module_exit(elan_exist); |
| 693 | |
| 694 | MODULE_AUTHOR("Elan"); |
| 695 | MODULE_DESCRIPTION("ELAN SPI FingerPrint driver"); |
| 696 | MODULE_VERSION(VERSION_LOG); |
| 697 | MODULE_LICENSE("GPL"); |