gesture_tmg399x.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 "AMS"
  17. #define CHIP_ID "TMG3992"
  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[3],
  34. data->buf[GESTURE_SENSOR].data[4],
  35. data->buf[GESTURE_SENSOR].data[5],
  36. data->buf[GESTURE_SENSOR].data[6]);
  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 = 4;
  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. ssp_dbg("[SSP]: %s %d %d %d %d\n",
  57. __func__, chTempBuf[0], chTempBuf[1], chTempBuf[2], chTempBuf[3]);
  58. raw_A = chTempBuf[0];
  59. raw_B = chTempBuf[1];
  60. raw_C = chTempBuf[2];
  61. raw_D = chTempBuf[3];
  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. if(data->uIr_Current == 0)
  73. data->uIr_Current = DEFUALT_IR_CURRENT;
  74. ssp_dbg("[SSP]: %s - Ir_Current Setting = %d\n",
  75. __func__, data->uIr_Current);
  76. return sprintf(buf, "%d\n", data->uIr_Current);
  77. }
  78. static ssize_t ir_current_store(struct device *dev,
  79. struct device_attribute *attr, const char *buf, size_t size)
  80. {
  81. u16 uNewIrCurrent = DEFUALT_IR_CURRENT;
  82. int iRet = 0;
  83. u16 current_index = 0;
  84. struct ssp_data *data = dev_get_drvdata(dev);
  85. static u16 set_current[2][4] = { {12, 25, 50, 100},
  86. {24, 16, 8, 0} };
  87. iRet = kstrtou16(buf, 10, &uNewIrCurrent);
  88. if (iRet < 0)
  89. pr_err("[SSP]: %s - kstrtoint failed.(%d)\n", __func__, iRet);
  90. else {
  91. for(current_index = 0; current_index < 4; current_index++) {
  92. if (set_current[0][current_index] == uNewIrCurrent) {
  93. data->uIr_Current = set_current[1][current_index];
  94. break;
  95. }
  96. }
  97. if(current_index == 4) // current setting value wrong.
  98. {
  99. return ERROR;
  100. }
  101. set_gesture_current(data, data->uIr_Current);
  102. data->uIr_Current= uNewIrCurrent;
  103. }
  104. ssp_dbg("[SSP]: %s - new Ir_Current Setting : %d\n",
  105. __func__, data->uIr_Current);
  106. return size;
  107. }
  108. static DEVICE_ATTR(vendor, S_IRUGO, gestrue_vendor_show, NULL);
  109. static DEVICE_ATTR(name, S_IRUGO, gestrue_name_show, NULL);
  110. static DEVICE_ATTR(raw_data, S_IRUGO, raw_data_read, NULL);
  111. static DEVICE_ATTR(selftest, S_IRUGO, gesture_get_selftest_show, NULL);
  112. static DEVICE_ATTR(ir_current, S_IRUGO | S_IWUSR | S_IWGRP,
  113. ir_current_show, ir_current_store);
  114. static struct device_attribute *gesture_attrs[] = {
  115. &dev_attr_vendor,
  116. &dev_attr_name,
  117. &dev_attr_raw_data,
  118. &dev_attr_selftest,
  119. &dev_attr_ir_current,
  120. NULL,
  121. };
  122. void initialize_gesture_factorytest(struct ssp_data *data)
  123. {
  124. sensors_register(data->ges_device, data,
  125. gesture_attrs, "gesture_sensor");
  126. }
  127. void remove_gesture_factorytest(struct ssp_data *data)
  128. {
  129. sensors_unregister(data->ges_device, gesture_attrs);
  130. }