stmvl6180.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * stmvl6180.h - Linux kernel modules for STM VL6180 FlightSense Time-of-Flight sensor
  3. *
  4. * Copyright (C) 2014 STMicroelectronics Imaging Division
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. /*
  21. * Defines
  22. */
  23. #define STMVL6180_DRV_NAME "stmvl6180"
  24. #define DRIVER_VERSION "1.0"
  25. #define I2C_M_WR 0x00
  26. #define INT_POLLING_DELAY 5
  27. //if don't want to have output from vl6180_dbgmsg, comment out #DEBUG macro
  28. #define DEBUG
  29. //#define vl6180_dbgmsg(str, args...) pr_debug("%s: " str, __func__, ##args)
  30. #define vl6180_dbgmsg(str, args...) printk("%s: " str, __func__, ##args)
  31. /**
  32. * VL6180 register addresses
  33. */
  34. //Device Registers
  35. #define VL6180_MODEL_ID_REG 0x0000
  36. #define VL6180_MODEL_REV_MAJOR_REG 0x0001
  37. #define VL6180_MODEL_REV_MINOR_REG 0x0002
  38. #define VL6180_MODULE_REV_MAJOR_REG 0x0003
  39. #define VL6180_MODULE_REV_MINOR_REG 0x0004
  40. #define VL6180_REVISION_ID_REG 0x0005
  41. #define VL6180_REVISION_ID_REG_BYTES 1
  42. #define VL6180_DATE_HI_REG 0x0006
  43. #define VL6180_DATE_HI_REG_BYTES 1
  44. #define VL6180_DATE_LO_REG 0x0007
  45. #define VL6180_DATE_LO_REG_BYTES 1
  46. #define VL6180_TIME_REG 0x0008
  47. #define VL6180_TIME_REG_BYTES 2
  48. #define VL6180_CODE_REG 0x000a
  49. #define VL6180_CODE_REG_BYTES 1
  50. #define VL6180_FIRMWARE_REVISION_ID_REG 0x000b
  51. #define VL6180_FIRMWARE_REVISION_ID_REG_BYTES 1
  52. // Result Registers
  53. #define VL6180_RESULT__RANGE_RAW_REG 0x0064
  54. #define VL6180_RESULT__RANGE_RAW_REG_BYTES 1
  55. #define VL6180_RESULT__RANGE_RETURN_RATE_REG 0x0066
  56. #define VL6180_RESULT__RANGE_RETURN_RATE_REG_BYTES 2
  57. #define VL6180_RESULT__RANGE_REFERENCE_RATE_REG 0x0068
  58. #define VL6180_RESULT__RANGE_REFERENCE_RATE_REG_BYTES 2
  59. #define VL6180_RESULT__RANGE_RETURN_VCSEL_COUNT_REG 0x006c
  60. #define VL6180_RESULT__RANGE_RETURN_VCSEL_COUNT_REG_BYTES 4
  61. #define VL6180_RESULT__RANGE_REFERENCE_VCSEL_COUNT_REG 0x0070
  62. #define VL6180_RESULT__RANGE_REFERENCE_VCSEL_COUNT_REG_BYTES 4
  63. #define VL6180_RESULT__RANGE_RETURN_AMB_COUNT_REG 0x0074
  64. #define VL6180_RESULT__RANGE_RETURN_AMB_COUNT_REG_BYTES 4
  65. #define VL6180_RESULT__RANGE_REFERENCE_AMB_COUNT_REG 0x0078
  66. #define VL6180_RESULT__RANGE_REFERENCE_AMB_COUNT_REG_BYTES 4
  67. #define VL6180_RESULT__RANGE_RETURN_CONV_TIME_REG 0x007c
  68. #define VL6180_RESULT__RANGE_RETURN_CONV_TIME_REG_BYTES 4
  69. #define VL6180_RESULT__RANGE_REFERENCE_CONV_TIME_REG 0x0080
  70. #define VL6180_RESULT__RANGE_REFERENCE_CONV_TIME_REG_BYTES 4
  71. /*
  72. * driver data structs
  73. */
  74. struct stmvl6180_data {
  75. struct i2c_client *client;
  76. struct mutex update_lock;
  77. struct delayed_work dwork; /* for PS work handler */
  78. struct input_dev *input_dev_ps;
  79. int irq;
  80. unsigned int enable;
  81. /* control flag from HAL */
  82. unsigned int enable_ps_sensor;
  83. /* PS parameters */
  84. unsigned int ps_is_singleshot;
  85. unsigned int ps_data; /* to store PS data */
  86. unsigned int enable_distance_filter;
  87. /* Range Data */
  88. //RangeData rangeData;
  89. //sensor_RowRangeData rangeData;
  90. VL6180x_RangeData_t rangeData;
  91. struct mutex work_mutex;
  92. unsigned int ps_count;
  93. /* Debug */
  94. unsigned int enableDebug;
  95. };