mpu6500_accel.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 <linux/timer.h>
  18. #include "adsp.h"
  19. #define VENDOR "BOSCH"
  20. #define CHIP_ID "MPU6500"
  21. /*static void adsp_timer_expire(unsigned long timer_var)
  22. {
  23. pr_err("[FACTORY]: %s - adsp_timer_expire() Called\n", __func__);
  24. adsp_unicast(ADSP_FACTORY_MODE_ACCEL,NETLINK_MESSAGE_STOP_RAW_DATA,0,0);
  25. }*/
  26. static ssize_t accel_vendor_show(struct device *dev,
  27. struct device_attribute *attr, char *buf)
  28. {
  29. return sprintf(buf, "%s\n", VENDOR);
  30. }
  31. static ssize_t accel_name_show(struct device *dev,
  32. struct device_attribute *attr, char *buf)
  33. {
  34. return sprintf(buf, "%s\n", CHIP_ID);
  35. }
  36. static ssize_t accel_calibration_show(struct device *dev,
  37. struct device_attribute *attr, char *buf)
  38. {
  39. struct adsp_data *data = dev_get_drvdata(dev);
  40. int iCount = 0;
  41. adsp_unicast(ADSP_FACTORY_MODE_ACCEL,NETLINK_MESSAGE_GET_CALIB_DATA,0,0);
  42. while( !(data->calib_ready_flag & 1 << ADSP_FACTORY_MODE_ACCEL) )
  43. msleep(20);
  44. iCount = snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", data->sensor_calib_data[ADSP_FACTORY_MODE_ACCEL].result,
  45. data->sensor_calib_data[ADSP_FACTORY_MODE_ACCEL].x,
  46. data->sensor_calib_data[ADSP_FACTORY_MODE_ACCEL].y,
  47. data->sensor_calib_data[ADSP_FACTORY_MODE_ACCEL].z);
  48. data->calib_ready_flag = 0;
  49. return iCount;
  50. }
  51. static ssize_t accel_calibration_store(struct device *dev,
  52. struct device_attribute *attr, const char *buf, size_t size)
  53. {
  54. struct adsp_data *data = dev_get_drvdata(dev);
  55. adsp_unicast(ADSP_FACTORY_MODE_ACCEL,NETLINK_MESSAGE_CALIB_STORE_DATA,0,0);
  56. while( !(data->calib_store_ready_flag & 1 << ADSP_FACTORY_MODE_ACCEL) )
  57. msleep(20);
  58. if(data->sensor_calib_result[ADSP_FACTORY_MODE_ACCEL].nCalibstoreresult < 0)
  59. pr_err("[FACTORY]: %s - accel_do_calibrate() failed\n", __func__);
  60. data->calib_store_ready_flag = 0;
  61. return size;
  62. }
  63. static ssize_t raw_data_read(struct device *dev,
  64. struct device_attribute *attr, char *buf)
  65. {
  66. struct adsp_data *data = dev_get_drvdata(dev);
  67. // data->our_timer.expires = 2000 +jiffies;
  68. // data->our_timer.function = adsp_timer_expire;
  69. // mod_timer(&data->our_timer, jiffies + 2000);
  70. if( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_ACCEL) ){
  71. adsp_unicast(ADSP_FACTORY_MODE_ACCEL,NETLINK_MESSAGE_GET_RAW_DATA,0,0);
  72. }
  73. while( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_ACCEL) )
  74. msleep(20);
  75. return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n",
  76. data->sensor_data[ADSP_FACTORY_MODE_ACCEL].x,
  77. data->sensor_data[ADSP_FACTORY_MODE_ACCEL].y,
  78. data->sensor_data[ADSP_FACTORY_MODE_ACCEL].z);
  79. }
  80. int accel_factory_init(struct adsp_data *data)
  81. {
  82. return 0;
  83. }
  84. int accel_factory_exit(struct adsp_data *data)
  85. {
  86. return 0;
  87. }
  88. int accel_factory_receive_data(struct adsp_data *data)
  89. {
  90. pr_err("(%s): factory \n", __func__);
  91. return 0;
  92. }
  93. static struct adsp_fac_ctl adsp_fact_cb = {
  94. .init_fnc = accel_factory_init,
  95. .exit_fnc = accel_factory_exit,
  96. .receive_data_fnc = accel_factory_receive_data
  97. };
  98. static DEVICE_ATTR(name, S_IRUGO, accel_name_show, NULL);
  99. static DEVICE_ATTR(vendor, S_IRUGO, accel_vendor_show, NULL);
  100. static DEVICE_ATTR(calibration, S_IRUGO | S_IWUSR | S_IWGRP,
  101. accel_calibration_show, accel_calibration_store);
  102. static DEVICE_ATTR(raw_data, S_IRUGO, raw_data_read, NULL);
  103. static struct device_attribute *acc_attrs[] = {
  104. &dev_attr_name,
  105. &dev_attr_vendor,
  106. &dev_attr_calibration,
  107. &dev_attr_raw_data,
  108. NULL,
  109. };
  110. static int __devinit mpu6500accel_factory_init(void)
  111. {
  112. adsp_factory_register("accelerometer_sensor",ADSP_FACTORY_MODE_ACCEL,acc_attrs,&adsp_fact_cb);
  113. pr_err("(%s): factory \n", __func__);
  114. return 0;
  115. }
  116. static void __devexit mpu6500accel_factory_exit(void)
  117. {
  118. pr_err("(%s): factory \n", __func__);
  119. }
  120. module_init(mpu6500accel_factory_init);
  121. module_exit(mpu6500accel_factory_exit);