hwmsen_helper.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright(C)2014 MediaTek Inc.
  3. * Modification based on code covered by the below mentioned copyright
  4. * and/or permission notice(S).
  5. */
  6. #include <linux/types.h>
  7. #include <linux/i2c.h>
  8. #include "hwmsensor.h"
  9. #ifndef __HWMSEN_HELPER_H__
  10. #define __HWMSEN_HELPER_H__
  11. /******************************************************************************
  12. * MACRO & DEFINITION
  13. ******************************************************************************/
  14. #define C_I2C_FIFO_SIZE 8 /*according i2c_mt6516.c */
  15. #define HWM_TAG "<HWMSEN> "
  16. #define HWM_FUN(f) printk(HWM_TAG"%s\n", __func__)
  17. #define HWM_ERR(fmt, args...) printk(HWM_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  18. #define HWM_LOG(fmt, args...) printk(HWM_TAG fmt, ##args)
  19. #define HWM_VER(fmt, args...) printk(HWM_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
  20. /******************************************************************************
  21. * STRUCTURE & ENUMERATION
  22. ******************************************************************************/
  23. struct hwmsen_reg {
  24. const char *name;
  25. u16 addr;
  26. u16 mode;
  27. u16 mask;
  28. u16 len;
  29. };
  30. /*----------------------------------------------------------------------------*/
  31. #define HWMSEN_DUMMY_REG(X) {NULL, X, REG_NA, 0x00, 0}
  32. /*----------------------------------------------------------------------------*/
  33. struct hwmsen_reg_test_multi {
  34. u8 addr;
  35. u8 len;
  36. u8 mode;
  37. u8 _align;
  38. };
  39. /*----------------------------------------------------------------------------*/
  40. enum {
  41. REG_NA = 0x0000,
  42. REG_RO = 0x0001,
  43. REG_WO = 0x0002,
  44. REG_LK = 0x0004, /*lcoked, register test will by-pass this register */
  45. REG_RW = REG_RO | REG_WO,
  46. };
  47. /*----------------------------------------------------------------------------*/
  48. /*
  49. * @sign, map: only used in accelerometer/magnetic field
  50. * sometimes, the sensor output need to be remapped before reporting to framework.
  51. * the 'sign' is only -1 or +1 to align the sign for framework's coordinate system
  52. * the 'map' align the value for framework's coordinate system. Take accelerometer
  53. * as an example:
  54. * assume HAL receives original acceleration: acc[] = {100, 0, 100}
  55. * sign[] = {1, -1, 1, 0};
  56. * map[] = {HWM_CODE_ACC_Y, HWM_CODE_ACC_X, HWM_CODE_ACC_Z, 0};
  57. * according to the above 'sign' & 'map', the sensor output need to remap as {y, -x, z}:
  58. * float resolution = unit_numerator*GRAVITY_EARTH/unit_denominator;
  59. * acc_x = sign[0]*acc[map[0]]*resolution;
  60. * acc_y = sign[1]*acc[map[1]]*resolution;
  61. * acc_z = sign[2]*acc[map[2]]*resolution;
  62. */
  63. struct hwmsen_convert {
  64. s8 sign[C_MAX_HWMSEN_EVENT_NUM];
  65. u8 map[C_MAX_HWMSEN_EVENT_NUM];
  66. };
  67. /*----------------------------------------------------------------------------*/
  68. struct hwmsen_conf {
  69. s32 sensitivity[C_MAX_HWMSEN_EVENT_NUM]; /*output sensitivity of sensor data */
  70. int num;
  71. };
  72. /*----------------------------------------------------------------------------*/
  73. typedef struct hwmsen_reg *(*find_reg_t) (int reg_idx);
  74. /*----------------------------------------------------------------------------*/
  75. extern int hwmsen_set_bits(struct i2c_client *client, u8 addr, u8 bits);
  76. extern int hwmsen_clr_bits(struct i2c_client *client, u8 addr, u8 bits);
  77. extern int hwmsen_read_byte(struct i2c_client *client, u8 addr, u8 *data);
  78. extern int hwmsen_write_byte(struct i2c_client *client, u8 addr, u8 data);
  79. extern int hwmsen_read_block(struct i2c_client *client, u8 addr, u8 *data, u8 len);
  80. extern int hwmsen_write_block(struct i2c_client *client, u8 addr, u8 *data, u8 len);
  81. extern void hwmsen_single_rw(struct i2c_client *client, struct hwmsen_reg *regs, int num);
  82. extern void hwmsen_multi_rw(struct i2c_client *client, find_reg_t findreg,
  83. struct hwmsen_reg_test_multi *items, int inum);
  84. extern ssize_t hwmsen_show_dump(struct i2c_client *client, u8 startAddr, u8 *regtbl, u32 regnum,
  85. find_reg_t findreg, char *buf, u32 buflen);
  86. extern ssize_t hwmsen_read_all_regs(struct i2c_client *client, struct hwmsen_reg *regs, u32 num,
  87. char *buf, u32 buflen);
  88. extern ssize_t hwmsen_show_reg(struct i2c_client *client, u8 addr, char *buf, u32 buflen);
  89. extern ssize_t hwmsen_store_reg(struct i2c_client *client, u8 addr, const char *buf, size_t count);
  90. extern ssize_t hwmsen_show_byte(struct device *dev, struct device_attribute *attr, char *buf,
  91. u32 buflen);
  92. extern ssize_t hwmsen_store_byte(struct device *dev, struct device_attribute *attr, const char *buf,
  93. size_t count);
  94. extern ssize_t hwmsen_show_word(struct device *dev, struct device_attribute *attr, char *buf,
  95. u32 buflen);
  96. extern ssize_t hwmsen_store_word(struct device *dev, struct device_attribute *attr, const char *buf,
  97. size_t count);
  98. extern int hwmsen_get_convert(int direction, struct hwmsen_convert *cvt);
  99. /*----------------------------------------------------------------------------*/
  100. #endif