gesture_max88920.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 "MAX88920"
  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[0],
  34. data->buf[GESTURE_SENSOR].data[1],
  35. data->buf[GESTURE_SENSOR].data[2],
  36. data->buf[GESTURE_SENSOR].data[3]);
  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 iDelayCnt = 0, iRet = 0;
  43. char chTempBuf[2] = { 0, 10 };
  44. struct ssp_data *data = dev_get_drvdata(dev);
  45. iDelayCnt = 0;
  46. data->uFactorydataReady = 0;
  47. memset(data->uFactorydata, 0, sizeof(char) * FACTORY_DATA_MAX);
  48. iRet = send_instruction(data, FACTORY_MODE, GESTURE_FACTORY,
  49. chTempBuf, 2);
  50. while (!(data->uFactorydataReady & (1 << GESTURE_FACTORY))
  51. && (iDelayCnt++ < 100)
  52. && (iRet == SUCCESS))
  53. msleep(20);
  54. if ((iDelayCnt >= 100) || (iRet != SUCCESS)) {
  55. pr_err("[SSP]: %s - Gesture Selftest Timeout!!\n", __func__);
  56. goto exit;
  57. }
  58. raw_A = data->uFactorydata[0];
  59. raw_B = data->uFactorydata[1];
  60. raw_C = data->uFactorydata[2];
  61. raw_D = data->uFactorydata[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. 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, 25, 50, 75, 100, 125, 150, 175, 225, 250, 275, 300, 325, 350, 375, 400},
  84. {2, 28, 34, 50, 66, 82, 98, 114, 130, 146, 162, 178, 194, 210, 226, 242} };
  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. }
  93. }
  94. set_gesture_current(data, data->uIr_Current);
  95. data->uIr_Current = uNewIrCurrent;
  96. }
  97. ssp_dbg("[SSP]: %s - new Ir_Current Setting : %d\n",
  98. __func__, data->uIr_Current);
  99. return size;
  100. }
  101. static DEVICE_ATTR(vendor, S_IRUGO, gestrue_vendor_show, NULL);
  102. static DEVICE_ATTR(name, S_IRUGO, gestrue_name_show, NULL);
  103. static DEVICE_ATTR(raw_data, S_IRUGO, raw_data_read, NULL);
  104. static DEVICE_ATTR(selftest, S_IRUGO, gesture_get_selftest_show, NULL);
  105. static DEVICE_ATTR(ir_current, S_IRUGO | S_IWUSR | S_IWGRP,
  106. ir_current_show, ir_current_store);
  107. static struct device_attribute *gesture_attrs[] = {
  108. &dev_attr_vendor,
  109. &dev_attr_name,
  110. &dev_attr_raw_data,
  111. &dev_attr_selftest,
  112. &dev_attr_ir_current,
  113. NULL,
  114. };
  115. void initialize_gesture_factorytest(struct ssp_data *data)
  116. {
  117. sensors_register(data->ges_device, data,
  118. gesture_attrs, "gesture_sensor");
  119. }
  120. void remove_gesture_factorytest(struct ssp_data *data)
  121. {
  122. sensors_unregister(data->ges_device, gesture_attrs);
  123. }