hscdtd008a_mag.c 5.4 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 "Alps"
  19. #define CHIP_ID "HSCDTD008A"
  20. static struct work_struct timer_stop_data_work;
  21. extern unsigned int raw_data_stream;
  22. static ssize_t mag_vendor_show(struct device *dev,
  23. struct device_attribute *attr, char *buf)
  24. {
  25. return sprintf(buf, "%s\n", VENDOR);
  26. }
  27. static ssize_t mag_name_show(struct device *dev,
  28. struct device_attribute *attr, char *buf)
  29. {
  30. return sprintf(buf, "%s\n", CHIP_ID);
  31. }
  32. static ssize_t raw_data_read(struct device *dev,
  33. struct device_attribute *attr, char *buf)
  34. {
  35. struct msg_data message;
  36. unsigned long timeout = jiffies + (2*HZ);
  37. struct adsp_data *data = dev_get_drvdata(dev);
  38. if( !(raw_data_stream & ADSP_RAW_MAG) ){
  39. pr_err("Starting raw data \n");
  40. raw_data_stream |= ADSP_RAW_MAG;
  41. message.sensor_type = ADSP_FACTORY_MODE_MAG;
  42. adsp_unicast(message,NETLINK_MESSAGE_GET_RAW_DATA,0,0);
  43. }
  44. while( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_MAG) ){
  45. msleep(20);
  46. if (time_after(jiffies, timeout)) {
  47. return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n",0,0,0);
  48. }
  49. }
  50. adsp_factory_start_timer(2000);
  51. return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n",
  52. data->sensor_data[ADSP_FACTORY_MODE_MAG].x,
  53. data->sensor_data[ADSP_FACTORY_MODE_MAG].y,
  54. data->sensor_data[ADSP_FACTORY_MODE_MAG].z);
  55. }
  56. static ssize_t dac_show(struct device *dev,
  57. struct device_attribute *attr, char *buf)
  58. {
  59. return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n", 0, 0, 0);
  60. }
  61. static ssize_t status_show(struct device *dev,
  62. struct device_attribute *attr, char *buf)
  63. {
  64. //struct adsp_data *data = dev_get_drvdata(dev);
  65. int result = 0;
  66. //adsp_unicast(ADSP_FACTORY_MODE_MAG,NETLINK_MESSAGE_CALIB_STORE_DATA,0,0);
  67. // while( !(data->calib_store_ready_flag & 1 << ADSP_FACTORY_MODE_MAG) )
  68. // msleep(20);
  69. // if(data->sensor_calib_result[ADSP_FACTORY_MODE_MAG].nCalibstoreresult < 0)
  70. // pr_err("[FACTORY]: %s - accel_do_calibrate() failed\n", __func__);
  71. // data->calib_store_ready_flag = 0;
  72. if (result == 0)
  73. result = 1;
  74. else
  75. result = 0;
  76. return snprintf(buf, PAGE_SIZE, "%d,%d\n", result, 0);
  77. }
  78. static void mag_stop_raw_data_worker(struct work_struct *work)
  79. {
  80. struct msg_data message;
  81. pr_err("(%s): \n", __func__);
  82. message.sensor_type = ADSP_FACTORY_MODE_MAG;
  83. adsp_unicast(message,NETLINK_MESSAGE_STOP_RAW_DATA,0,0);
  84. return;
  85. }
  86. static ssize_t selttest_show(struct device *dev,
  87. struct device_attribute *attr, char *buf)
  88. {
  89. struct adsp_data *data = dev_get_drvdata(dev);
  90. int result1 = 0;
  91. int result2 = 0;
  92. struct msg_data message;
  93. message.sensor_type = ADSP_FACTORY_MODE_MAG;
  94. adsp_unicast(message,NETLINK_MESSAGE_SELFTEST_SHOW_DATA,0,0);
  95. while( !(data->selftest_ready_flag & 1 << ADSP_FACTORY_MODE_MAG) )
  96. msleep(20);
  97. if(data->sensor_selftest_result[ADSP_FACTORY_MODE_MAG].nSelftestresult1< 0)
  98. pr_err("[FACTORY]: %s - accel_do_calibrate() failed\n", __func__);
  99. data->selftest_ready_flag = 0;
  100. if (data->sensor_selftest_result[ADSP_FACTORY_MODE_MAG].nSelftestresult1 == 0)
  101. result1 = 1;
  102. else
  103. result1 = 0;
  104. if (data->sensor_selftest_result[ADSP_FACTORY_MODE_MAG].nSelftestresult2 == 0)
  105. result2 = 1;
  106. else
  107. result2 = 0;
  108. return snprintf(buf, PAGE_SIZE, "%d, %d\n", result1, result2);
  109. }
  110. int mag_factory_init(struct adsp_data *data)
  111. {
  112. return 0;
  113. }
  114. int mag_factory_exit(struct adsp_data *data)
  115. {
  116. return 0;
  117. }
  118. int mag_factory_receive_data(struct adsp_data *data,int cmd)
  119. {
  120. pr_err("(%s): factory \n", __func__);
  121. switch(cmd)
  122. {
  123. case CALLBACK_REGISTER_SUCCESS:
  124. pr_info("[SENSOR] %s: mpu6515 registration success \n", __func__);
  125. break;
  126. case CALLBACK_TIMER_EXPIRED:
  127. pr_err("Raw data flag = %d\n", raw_data_stream);
  128. if( (raw_data_stream & ADSP_RAW_MAG) ){
  129. raw_data_stream &= ~ADSP_RAW_MAG;
  130. schedule_work(&timer_stop_data_work);
  131. }
  132. break;
  133. default:
  134. break;
  135. }
  136. return 0;
  137. }
  138. static struct adsp_fac_ctl adsp_fact_cb = {
  139. .init_fnc = mag_factory_init,
  140. .exit_fnc = mag_factory_exit,
  141. .receive_data_fnc = mag_factory_receive_data
  142. };
  143. static DEVICE_ATTR(selftest, 0664, selttest_show, NULL);
  144. static DEVICE_ATTR(status, 0664, status_show, NULL);
  145. static DEVICE_ATTR(dac, 0644, dac_show, NULL);
  146. static DEVICE_ATTR(adc, 0644, raw_data_read, NULL);
  147. static DEVICE_ATTR(name, 0440, mag_name_show, NULL);
  148. static DEVICE_ATTR(vendor, 0440, mag_vendor_show, NULL);
  149. static DEVICE_ATTR(raw_data, 0644, raw_data_read, NULL);
  150. static struct device_attribute *mag_attrs[] = {
  151. &dev_attr_selftest,
  152. &dev_attr_status,
  153. &dev_attr_dac,
  154. &dev_attr_adc,
  155. &dev_attr_name,
  156. &dev_attr_vendor,
  157. &dev_attr_raw_data,
  158. NULL,
  159. };
  160. static int __devinit hscdtd008amag_factory_init(void)
  161. {
  162. adsp_factory_register("magnetic_sensor",ADSP_FACTORY_MODE_MAG,mag_attrs,&adsp_fact_cb);
  163. pr_err("(%s): factory \n", __func__);
  164. INIT_WORK(&timer_stop_data_work,
  165. mag_stop_raw_data_worker );
  166. return 0;
  167. }
  168. static void __devexit hscdtd008amag_factory_exit(void)
  169. {
  170. pr_err("(%s): factory \n", __func__);
  171. }
  172. module_init(hscdtd008amag_factory_init);
  173. module_exit(hscdtd008amag_factory_exit);