mpu6500_gyro.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "Invensense"
  19. #define CHIP_ID "MPU6500"
  20. static ssize_t gyro_vendor_show(struct device *dev,
  21. struct device_attribute *attr, char *buf)
  22. {
  23. adsp_unicast(ADSP_FACTORY_MODE_GYRO,NETLINK_MESSAGE_GET_RAW_DATA,0,0);
  24. return sprintf(buf, "%s\n", VENDOR);
  25. }
  26. static ssize_t gyro_name_show(struct device *dev,
  27. struct device_attribute *attr, char *buf)
  28. {
  29. return sprintf(buf, "%s\n", CHIP_ID);
  30. }
  31. static ssize_t gyro_calibration_show(struct device *dev,
  32. struct device_attribute *attr, char *buf)
  33. {
  34. struct adsp_data *data = dev_get_drvdata(dev);
  35. int iCount = 0;
  36. if( !(data->calib_ready_flag & 1 << ADSP_FACTORY_MODE_GYRO) ){
  37. adsp_unicast(ADSP_FACTORY_MODE_GYRO,NETLINK_MESSAGE_GET_CALIB_DATA,0,0);
  38. }
  39. while( !(data->calib_ready_flag & 1 << ADSP_FACTORY_MODE_GYRO) )
  40. msleep(20);
  41. iCount = snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", data->sensor_calib_data[ADSP_FACTORY_MODE_GYRO].result,
  42. data->sensor_calib_data[ADSP_FACTORY_MODE_GYRO].x,
  43. data->sensor_calib_data[ADSP_FACTORY_MODE_GYRO].y,
  44. data->sensor_calib_data[ADSP_FACTORY_MODE_GYRO].z);
  45. return iCount;
  46. }
  47. static ssize_t gyro_calibration_store(struct device *dev,
  48. struct device_attribute *attr, const char *buf, size_t size)
  49. {
  50. return size;
  51. }
  52. static ssize_t raw_data_read(struct device *dev,
  53. struct device_attribute *attr, char *buf)
  54. {
  55. struct adsp_data *data = dev_get_drvdata(dev);
  56. if( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_GYRO) ){
  57. adsp_unicast(ADSP_FACTORY_MODE_GYRO,NETLINK_MESSAGE_GET_RAW_DATA,0,0);
  58. }
  59. while( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_GYRO) )
  60. msleep(20);
  61. return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n",
  62. data->sensor_data[ADSP_FACTORY_MODE_GYRO].x,
  63. data->sensor_data[ADSP_FACTORY_MODE_GYRO].y,
  64. data->sensor_data[ADSP_FACTORY_MODE_GYRO].z);
  65. }
  66. int gyro_factory_init(struct adsp_data *data)
  67. {
  68. return 0;
  69. }
  70. int gyro_factory_exit(struct adsp_data *data)
  71. {
  72. return 0;
  73. }
  74. int gyro_factory_receive_data(struct adsp_data *data)
  75. {
  76. pr_err("(%s): factory \n", __func__);
  77. return 0;
  78. }
  79. static struct adsp_fac_ctl adsp_fact_cb = {
  80. .init_fnc = gyro_factory_init,
  81. .exit_fnc = gyro_factory_exit,
  82. .receive_data_fnc = gyro_factory_receive_data
  83. };
  84. static DEVICE_ATTR(name, S_IRUGO, gyro_name_show, NULL);
  85. static DEVICE_ATTR(vendor, S_IRUGO, gyro_vendor_show, NULL);
  86. static DEVICE_ATTR(calibration, S_IRUGO | S_IWUSR | S_IWGRP,
  87. gyro_calibration_show, gyro_calibration_store);
  88. static DEVICE_ATTR(raw_data, S_IRUGO, raw_data_read, NULL);
  89. static struct device_attribute *gyro_attrs[] = {
  90. &dev_attr_name,
  91. &dev_attr_vendor,
  92. &dev_attr_calibration,
  93. &dev_attr_raw_data,
  94. NULL,
  95. };
  96. static int __devinit mpu6500gyro_factory_init(void)
  97. {
  98. adsp_factory_register("gyro_sensor",ADSP_FACTORY_MODE_GYRO,gyro_attrs,&adsp_fact_cb);
  99. pr_err("(%s): factory \n", __func__);
  100. return 0;
  101. }
  102. static void __devexit mpu6500gyro_factory_exit(void)
  103. {
  104. pr_err("(%s): factory \n", __func__);
  105. }
  106. module_init(mpu6500gyro_factory_init);
  107. module_exit(mpu6500gyro_factory_exit);