lsm6dsl_gyro.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 <linux/init.h>
  16. #include <linux/module.h>
  17. #include "adsp.h"
  18. #define VENDOR "STM"
  19. #define CHIP_ID "LSM6DSL"
  20. #define ST_PASS 1
  21. #define ST_FAIL 0
  22. #define ST_ZRO_MIN (-40)
  23. #define ST_ZRO_MAX 40
  24. #define SELFTEST_REVISED 1
  25. static ssize_t gyro_vendor_show(struct device *dev,
  26. struct device_attribute *attr, char *buf)
  27. {
  28. return snprintf(buf, PAGE_SIZE, "%s\n", VENDOR);
  29. }
  30. static ssize_t gyro_name_show(struct device *dev,
  31. struct device_attribute *attr, char *buf)
  32. {
  33. return snprintf(buf, PAGE_SIZE, "%s\n", CHIP_ID);
  34. }
  35. static ssize_t selftest_revised_show(struct device *dev,
  36. struct device_attribute *attr, char *buf)
  37. {
  38. return snprintf(buf, PAGE_SIZE, "%d\n", SELFTEST_REVISED);
  39. }
  40. static ssize_t gyro_power_off(struct device *dev,
  41. struct device_attribute *attr, char *buf)
  42. {
  43. pr_info("[FACTORY]: %s\n", __func__);
  44. return snprintf(buf, PAGE_SIZE, "%d\n", 1);
  45. }
  46. static ssize_t gyro_power_on(struct device *dev,
  47. struct device_attribute *attr, char *buf)
  48. {
  49. pr_info("[FACTORY]: %s\n", __func__);
  50. return snprintf(buf, PAGE_SIZE, "%d\n", 1);
  51. }
  52. static ssize_t gyro_temp_show(struct device *dev,
  53. struct device_attribute *attr, char *buf)
  54. {
  55. struct adsp_data *data = dev_get_drvdata(dev);
  56. uint8_t cnt = 0;
  57. adsp_unicast(NULL, 0, MSG_GYRO_TEMP, 0, MSG_TYPE_GET_RAW_DATA);
  58. while (!(data->ready_flag[MSG_TYPE_GET_RAW_DATA] & 1 << MSG_GYRO_TEMP)
  59. && cnt++ < TIMEOUT_CNT)
  60. msleep(20);
  61. data->ready_flag[MSG_TYPE_GET_RAW_DATA] &= ~(1 << MSG_GYRO_TEMP);
  62. if (cnt >= TIMEOUT_CNT) {
  63. pr_err("[FACTORY] %s: Timeout!!!\n", __func__);
  64. return snprintf(buf, PAGE_SIZE, "-99\n");
  65. }
  66. pr_info("[FACTORY] %s: gyro_temp = %d\n", __func__,
  67. data->msg_buf[MSG_GYRO_TEMP][0]);
  68. return snprintf(buf, PAGE_SIZE, "%d\n",
  69. data->msg_buf[MSG_GYRO_TEMP][0]);
  70. }
  71. static ssize_t gyro_selftest_show(struct device *dev,
  72. struct device_attribute *attr, char *buf)
  73. {
  74. struct adsp_data *data = dev_get_drvdata(dev);
  75. uint8_t cnt = 0;
  76. int st_diff_res = ST_FAIL;
  77. int st_zro_res = ST_FAIL;
  78. pr_info("[FACTORY] %s - start", __func__);
  79. adsp_unicast(NULL, 0, MSG_GYRO, 0, MSG_TYPE_ST_SHOW_DATA);
  80. while (!(data->ready_flag[MSG_TYPE_ST_SHOW_DATA] & 1 << MSG_GYRO) &&
  81. cnt++ < TIMEOUT_CNT)
  82. msleep(25);
  83. data->ready_flag[MSG_TYPE_ST_SHOW_DATA] &= ~(1 << MSG_GYRO);
  84. if (cnt >= TIMEOUT_CNT) {
  85. pr_err("[FACTORY] %s: Timeout!!!\n", __func__);
  86. return snprintf(buf, PAGE_SIZE,
  87. "0,0,0,0,0,0,0,0,0,0,0,0,%d,%d\n",
  88. ST_FAIL, ST_FAIL);
  89. }
  90. if (data->msg_buf[MSG_GYRO][1] != 0) {
  91. pr_info("[FACTORY] %s - failed(%d, %d)\n", __func__,
  92. data->msg_buf[MSG_GYRO][1],
  93. data->msg_buf[MSG_GYRO][5]);
  94. pr_info("[FACTORY]: %s - %d,%d,%d\n", __func__,
  95. data->msg_buf[MSG_GYRO][2],
  96. data->msg_buf[MSG_GYRO][3],
  97. data->msg_buf[MSG_GYRO][4]);
  98. return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n",
  99. data->msg_buf[MSG_GYRO][2],
  100. data->msg_buf[MSG_GYRO][3],
  101. data->msg_buf[MSG_GYRO][4]);
  102. }
  103. if (!data->msg_buf[MSG_GYRO][5])
  104. st_diff_res = ST_PASS;
  105. if((ST_ZRO_MIN <= data->msg_buf[MSG_GYRO][6])
  106. && (data->msg_buf[MSG_GYRO][6] <= ST_ZRO_MAX)
  107. && (ST_ZRO_MIN <= data->msg_buf[MSG_GYRO][7])
  108. && (data->msg_buf[MSG_GYRO][7] <= ST_ZRO_MAX)
  109. && (ST_ZRO_MIN <= data->msg_buf[MSG_GYRO][8])
  110. && (data->msg_buf[MSG_GYRO][8]<= ST_ZRO_MAX))
  111. st_zro_res = ST_PASS;
  112. pr_info("[FACTORY]: %s - %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
  113. __func__,
  114. data->msg_buf[MSG_GYRO][2], data->msg_buf[MSG_GYRO][3],
  115. data->msg_buf[MSG_GYRO][4], data->msg_buf[MSG_GYRO][6],
  116. data->msg_buf[MSG_GYRO][7], data->msg_buf[MSG_GYRO][8],
  117. data->msg_buf[MSG_GYRO][9], data->msg_buf[MSG_GYRO][10],
  118. data->msg_buf[MSG_GYRO][11], data->msg_buf[MSG_GYRO][12],
  119. data->msg_buf[MSG_GYRO][13], data->msg_buf[MSG_GYRO][14],
  120. st_diff_res, st_zro_res);
  121. return snprintf(buf, PAGE_SIZE,
  122. "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
  123. data->msg_buf[MSG_GYRO][2], data->msg_buf[MSG_GYRO][3],
  124. data->msg_buf[MSG_GYRO][4], data->msg_buf[MSG_GYRO][6],
  125. data->msg_buf[MSG_GYRO][7], data->msg_buf[MSG_GYRO][8],
  126. data->msg_buf[MSG_GYRO][9], data->msg_buf[MSG_GYRO][10],
  127. data->msg_buf[MSG_GYRO][11], data->msg_buf[MSG_GYRO][12],
  128. data->msg_buf[MSG_GYRO][13], data->msg_buf[MSG_GYRO][14],
  129. st_diff_res, st_zro_res);
  130. }
  131. static DEVICE_ATTR(name, 0444, gyro_name_show, NULL);
  132. static DEVICE_ATTR(vendor, 0444, gyro_vendor_show, NULL);
  133. static DEVICE_ATTR(selftest, 0440, gyro_selftest_show, NULL);
  134. static DEVICE_ATTR(power_on, 0444, gyro_power_on, NULL);
  135. static DEVICE_ATTR(power_off, 0444, gyro_power_off, NULL);
  136. static DEVICE_ATTR(temperature, 0440, gyro_temp_show, NULL);
  137. static DEVICE_ATTR(selftest_revised, 0440, selftest_revised_show, NULL);
  138. static struct device_attribute *gyro_attrs[] = {
  139. &dev_attr_name,
  140. &dev_attr_vendor,
  141. &dev_attr_selftest,
  142. &dev_attr_power_on,
  143. &dev_attr_power_off,
  144. &dev_attr_temperature,
  145. &dev_attr_selftest_revised,
  146. NULL,
  147. };
  148. int __init lsm6dsl_gyro_factory_init(void)
  149. {
  150. adsp_factory_register(MSG_GYRO, gyro_attrs);
  151. pr_info("[FACTORY] %s\n", __func__);
  152. return 0;
  153. }
  154. void __exit lsm6dsl_gyro_factory_exit(void)
  155. {
  156. adsp_factory_unregister(MSG_GYRO);
  157. pr_info("[FACTORY] %s\n", __func__);
  158. }