gesture_max88920.c 4.2 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 iRet = 0;
  43. char chTempBuf[4] = { 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. raw_A = chTempBuf[0];
  57. raw_B = chTempBuf[1];
  58. raw_C = chTempBuf[2];
  59. raw_D = chTempBuf[3];
  60. pr_info("[SSP] %s: self test A = %d, B = %d, C = %d, D = %d\n",
  61. __func__, raw_A, raw_B, raw_C, raw_D);
  62. exit: return sprintf(buf, "%d,%d,%d,%d\n", raw_A, raw_B, raw_C, raw_D);
  63. }
  64. static ssize_t ir_current_show(struct device *dev,
  65. struct device_attribute *attr, char *buf)
  66. {
  67. struct ssp_data *data = dev_get_drvdata(dev);
  68. ssp_dbg("[SSP]: %s - Ir_Current Setting = %d\n",
  69. __func__, data->uIr_Current);
  70. return sprintf(buf, "%d\n", data->uIr_Current);
  71. }
  72. static ssize_t ir_current_store(struct device *dev,
  73. struct device_attribute *attr, const char *buf, size_t size)
  74. {
  75. u16 uNewIrCurrent = DEFUALT_IR_CURRENT;
  76. int iRet = 0;
  77. u16 current_index = 0;
  78. struct ssp_data *data = dev_get_drvdata(dev);
  79. static u16 set_current[2][16] = { {0, 25, 50, 75, 100, 125, 150, 175, 225, 250, 275, 300, 325, 350, 375, 400},
  80. {2, 28, 34, 50, 66, 82, 98, 114, 130, 146, 162, 178, 194, 210, 226, 242} };
  81. iRet = kstrtou16(buf, 10, &uNewIrCurrent);
  82. if (iRet < 0)
  83. pr_err("[SSP]: %s - kstrtoint failed.(%d)\n", __func__, iRet);
  84. else {
  85. for(current_index = 0; current_index < 16; current_index++) {
  86. if (set_current[0][current_index] == uNewIrCurrent) {
  87. data->uIr_Current = set_current[1][current_index];
  88. break;
  89. }
  90. }
  91. if(current_index == 16) // current setting value wrong.
  92. {
  93. return ERROR;
  94. }
  95. set_gesture_current(data, data->uIr_Current);
  96. data->uIr_Current= uNewIrCurrent;
  97. }
  98. ssp_dbg("[SSP]: %s - new Ir_Current Setting : %d\n",
  99. __func__, data->uIr_Current);
  100. return size;
  101. }
  102. static DEVICE_ATTR(vendor, S_IRUGO, gestrue_vendor_show, NULL);
  103. static DEVICE_ATTR(name, S_IRUGO, gestrue_name_show, NULL);
  104. static DEVICE_ATTR(raw_data, S_IRUGO, raw_data_read, NULL);
  105. static DEVICE_ATTR(selftest, S_IRUGO, gesture_get_selftest_show, NULL);
  106. static DEVICE_ATTR(ir_current, S_IRUGO | S_IWUSR | S_IWGRP,
  107. ir_current_show, ir_current_store);
  108. static struct device_attribute *gesture_attrs[] = {
  109. &dev_attr_vendor,
  110. &dev_attr_name,
  111. &dev_attr_raw_data,
  112. &dev_attr_selftest,
  113. &dev_attr_ir_current,
  114. NULL,
  115. };
  116. void initialize_gesture_factorytest(struct ssp_data *data)
  117. {
  118. sensors_register(data->ges_device, data,
  119. gesture_attrs, "gesture_sensor");
  120. }
  121. void remove_gesture_factorytest(struct ssp_data *data)
  122. {
  123. sensors_unregister(data->ges_device, gesture_attrs);
  124. }