gesture_max88922.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (C) 2012, Samsung Electronics Co. Ltd. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include "../ssp.h"
  16. #define VENDOR "MAXIM"
  17. #define CHIP_ID "MAX88922"
  18. static ssize_t gestrue_vendor_show(struct device *dev,
  19. struct device_attribute *attr, char *buf)
  20. {
  21. return snprintf(buf, PAGE_SIZE, "%s\n", VENDOR);
  22. }
  23. static ssize_t gestrue_name_show(struct device *dev,
  24. struct device_attribute *attr, char *buf)
  25. {
  26. return snprintf(buf, PAGE_SIZE, "%s\n", CHIP_ID);
  27. }
  28. static ssize_t raw_data_read(struct device *dev,
  29. struct device_attribute *attr, char *buf)
  30. {
  31. struct ssp_data *data = dev_get_drvdata(dev);
  32. return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n",
  33. data->buf[GESTURE_SENSOR].data[1],
  34. data->buf[GESTURE_SENSOR].data[2],
  35. data->buf[GESTURE_SENSOR].data[3],
  36. data->buf[GESTURE_SENSOR].data[9]);
  37. }
  38. static ssize_t gesture_get_selftest_show(struct device *dev,
  39. struct device_attribute *attr, char *buf)
  40. {
  41. s16 raw_A = 0, raw_B = 0, raw_C = 0, raw_D = 0;
  42. int iRet = 0;
  43. char chTempBuf[8] = { 0, };
  44. struct ssp_data *data = dev_get_drvdata(dev);
  45. struct ssp_msg *msg = kzalloc(sizeof(*msg), GFP_KERNEL);
  46. msg->cmd = GESTURE_FACTORY;
  47. msg->length = 8;
  48. msg->options = AP2HUB_READ;
  49. msg->buffer = chTempBuf;
  50. msg->free_buffer = 0;
  51. iRet = ssp_spi_sync(data, msg, 2000);
  52. if (iRet != SUCCESS) {
  53. pr_err("[SSP]: %s - Gesture Selftest Timeout!!\n", __func__);
  54. goto exit;
  55. }
  56. printk("%x %x %x %x %x %x %x %x \n", chTempBuf[0], chTempBuf[1], chTempBuf[2], chTempBuf[3],
  57. chTempBuf[4], chTempBuf[5], chTempBuf[6], chTempBuf[7]);
  58. raw_A = ((((s16)chTempBuf[0]) << 8) + ((s16)chTempBuf[1])) - 1023;
  59. raw_B = ((((s16)chTempBuf[2]) << 8) + ((s16)chTempBuf[3])) - 1023;
  60. raw_C = ((((s16)chTempBuf[4]) << 8) + ((s16)chTempBuf[5])) - 1023;
  61. raw_D = ((((s16)chTempBuf[6]) << 8) + ((s16)chTempBuf[7])) - 1023;
  62. pr_info("[SSP] %s: self test A = %d, B = %d, C = %d, D = %d\n",
  63. __func__, raw_A, raw_B, raw_C, raw_D);
  64. exit:
  65. return sprintf(buf, "%d,%d,%d,%d\n",
  66. raw_A, raw_B, raw_C, raw_D);
  67. }
  68. static ssize_t ir_current_show(struct device *dev,
  69. struct device_attribute *attr, char *buf)
  70. {
  71. struct ssp_data *data = dev_get_drvdata(dev);
  72. ssp_dbg("[SSP]: %s - Ir_Current Setting = %d\n",
  73. __func__, data->uIr_Current);
  74. return sprintf(buf, "%d\n", data->uIr_Current);
  75. }
  76. static ssize_t ir_current_store(struct device *dev,
  77. struct device_attribute *attr, const char *buf, size_t size)
  78. {
  79. u16 uNewIrCurrent = DEFUALT_IR_CURRENT;
  80. int iRet = 0;
  81. u16 current_index = 0;
  82. struct ssp_data *data = dev_get_drvdata(dev);
  83. static u16 set_current[2][16] = { {0, 6, 13, 20, 26, 33, 40, 46, 53, 60, 66, 73, 80, 86, 93, 100},
  84. {0<<4, 1<<4, 2<<4, 3<<4, 4<<4, 5<<4, 6<<4, 7<<4, 8<<4, 9<<4, 10<<4, 11<<4, 12<<4, 13<<4, 14<<4, 15<<4} };
  85. iRet = kstrtou16(buf, 10, &uNewIrCurrent);
  86. if (iRet < 0)
  87. pr_err("[SSP]: %s - kstrtoint failed.(%d)\n", __func__, iRet);
  88. else {
  89. for(current_index = 0; current_index < 16; current_index++) {
  90. if (set_current[0][current_index] == uNewIrCurrent) {
  91. data->uIr_Current = set_current[1][current_index];
  92. break;
  93. }
  94. }
  95. if(current_index == 16) // current setting value wrong.
  96. {
  97. return ERROR;
  98. }
  99. set_gesture_current(data, data->uIr_Current);
  100. data->uIr_Current= uNewIrCurrent;
  101. }
  102. ssp_dbg("[SSP]: %s - new Ir_Current Setting : %d\n",
  103. __func__, data->uIr_Current);
  104. return size;
  105. }
  106. static DEVICE_ATTR(vendor, S_IRUGO, gestrue_vendor_show, NULL);
  107. static DEVICE_ATTR(name, S_IRUGO, gestrue_name_show, NULL);
  108. static DEVICE_ATTR(raw_data, S_IRUGO, raw_data_read, NULL);
  109. static DEVICE_ATTR(selftest, S_IRUGO, gesture_get_selftest_show, NULL);
  110. static DEVICE_ATTR(ir_current, S_IRUGO | S_IWUSR | S_IWGRP,
  111. ir_current_show, ir_current_store);
  112. static struct device_attribute *gesture_attrs[] = {
  113. &dev_attr_vendor,
  114. &dev_attr_name,
  115. &dev_attr_raw_data,
  116. &dev_attr_selftest,
  117. &dev_attr_ir_current,
  118. NULL,
  119. };
  120. void initialize_gesture_factorytest(struct ssp_data *data)
  121. {
  122. sensors_register(data->ges_device, data,
  123. gesture_attrs, "gesture_sensor");
  124. }
  125. void remove_gesture_factorytest(struct ssp_data *data)
  126. {
  127. sensors_unregister(data->ges_device, gesture_attrs);
  128. }