bma250_accel.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "BMA250"
  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 << ADSP_FACTORY_MODE_ACCEL;
  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 << ADSP_FACTORY_MODE_ACCEL;
  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. if( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_ACCEL) ){
  68. adsp_unicast(ADSP_FACTORY_MODE_ACCEL,NETLINK_MESSAGE_GET_RAW_DATA,0,0);
  69. }
  70. while( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_ACCEL) )
  71. msleep(20);
  72. printk("raw_data_read x=%d y=%d z=%d \n",data->sensor_data[ADSP_FACTORY_MODE_ACCEL].x,data->sensor_data[ADSP_FACTORY_MODE_ACCEL].y,data->sensor_data[ADSP_FACTORY_MODE_ACCEL].y);
  73. return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n",
  74. data->sensor_data[ADSP_FACTORY_MODE_ACCEL].x,
  75. data->sensor_data[ADSP_FACTORY_MODE_ACCEL].y,
  76. data->sensor_data[ADSP_FACTORY_MODE_ACCEL].z);
  77. }
  78. int accel_factory_init(struct adsp_data *data)
  79. {
  80. return 0;
  81. }
  82. int accel_factory_exit(struct adsp_data *data)
  83. {
  84. return 0;
  85. }
  86. int accel_factory_receive_data(struct adsp_data *data)
  87. {
  88. pr_err("(%s): factory \n", __func__);
  89. return 0;
  90. }
  91. static struct adsp_fac_ctl adsp_fact_cb = {
  92. .init_fnc = accel_factory_init,
  93. .exit_fnc = accel_factory_exit,
  94. .receive_data_fnc = accel_factory_receive_data
  95. };
  96. static DEVICE_ATTR(name, S_IRUGO, accel_name_show, NULL);
  97. static DEVICE_ATTR(vendor, S_IRUGO, accel_vendor_show, NULL);
  98. static DEVICE_ATTR(calibration, S_IRUGO | S_IWUSR | S_IWGRP,
  99. accel_calibration_show, accel_calibration_store);
  100. static DEVICE_ATTR(raw_data, S_IRUGO, raw_data_read, NULL);
  101. static struct device_attribute *acc_attrs[] = {
  102. &dev_attr_name,
  103. &dev_attr_vendor,
  104. &dev_attr_calibration,
  105. &dev_attr_raw_data,
  106. NULL,
  107. };
  108. static int __devinit bma250accel_factory_init(void)
  109. {
  110. adsp_factory_register("accelerometer_sensor",ADSP_FACTORY_MODE_ACCEL,acc_attrs,&adsp_fact_cb);
  111. pr_err("(%s): factory \n", __func__);
  112. return 0;
  113. }
  114. static void __devexit bma250accel_factory_exit(void)
  115. {
  116. pr_err("(%s): factory \n", __func__);
  117. }
  118. module_init(bma250accel_factory_init);
  119. module_exit(bma250accel_factory_exit);