cm36283.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* include/linux/cm36283.h
  2. *
  3. * Copyright (C) 2012 Capella Microsystems Inc.
  4. * Author: Frank Hsieh <pengyueh@gmail.com>
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef __LINUX_CM36283_H
  17. #define __LINUX_CM36283_H
  18. #include <linux/bitops.h>
  19. #define CM36283_I2C_NAME "cm36283"
  20. /* Define Slave Address*/
  21. #define CM36283_slave_add 0xC0>>1
  22. #define ALS_CALIBRATED 0x6E9F
  23. #define PS_CALIBRATED 0x509F
  24. /*Define Command Code*/
  25. #define ALS_CONF 0x00
  26. #define ALS_THDH 0x01
  27. #define ALS_THDL 0x02
  28. #define PS_CONF1 0x03
  29. #define PS_CONF3 0x04
  30. #define PS_CANC 0x05
  31. #define PS_THD 0x06
  32. #define RESERVED 0x07
  33. #define PS_DATA 0x08
  34. #define ALS_DATA 0x09
  35. #define RESERVED2 0x0A
  36. #define INT_FLAG 0x0B
  37. #define ID_REG 0x0C
  38. /*cm36283*/
  39. /*for ALS CONF command*/
  40. #define CM36283_ALS_IT_80ms (0 << 6)
  41. #define CM36283_ALS_IT_160ms (1 << 6)
  42. #define CM36283_ALS_IT_320ms (2 << 6)
  43. #define CM36283_ALS_IT_640ms (3 << 6)
  44. #define CM36283_ALS_GAIN_1 (0 << 2)
  45. #define CM36283_ALS_GAIN_2 (1 << 2)
  46. #define CM36283_ALS_GAIN_4 (2 << 2)
  47. #define CM36283_ALS_GAIN_8 (3 << 2)
  48. #define CM36283_ALS_INT_EN (1 << 1) /*enable/disable Interrupt*/
  49. #define CM36283_ALS_INT_MASK 0xFFFD
  50. #define CM36283_ALS_SD (1 << 0) /*enable/disable ALS func, 1:disable , 0: enable*/
  51. #define CM36283_ALS_SD_MASK 0xFFFE
  52. /*for PS CONF1 command*/
  53. #define CM36283_PS_ITB_1_2 (0 << 14)
  54. #define CM36283_PS_ITB_1 (1 << 14)
  55. #define CM36283_PS_ITB_2 (2 << 14)
  56. #define CM36283_PS_ITB_4 (3 << 14)
  57. #define CM36283_PS_INT_OFF (0 << 8) /*enable/disable Interrupt*/
  58. #define CM36283_PS_INT_IN (1 << 8)
  59. #define CM36283_PS_INT_OUT (2 << 8)
  60. #define CM36283_PS_INT_IN_AND_OUT (3 << 8)
  61. #define CM36283_PS_INT_MASK 0xFCFF
  62. #define CM36283_PS_DR_1_40 (0 << 6)
  63. #define CM36283_PS_DR_1_80 (1 << 6)
  64. #define CM36283_PS_DR_1_160 (2 << 6)
  65. #define CM36283_PS_DR_1_320 (3 << 6)
  66. #define CM36283_PS_IT_1T (0 << 4)
  67. #define CM36283_PS_IT_1_3T (1 << 4)
  68. #define CM36283_PS_IT_1_6T (2 << 4)
  69. #define CM36283_PS_IT_2T (3 << 4)
  70. #define CM36283_PS_PERS_1 (0 << 2)
  71. #define CM36283_PS_PERS_2 (1 << 2)
  72. #define CM36283_PS_PERS_3 (2 << 2)
  73. #define CM36283_PS_PERS_4 (3 << 2)
  74. #define CM36283_PS_RES_1 (1 << 1)
  75. #define CM36283_PS_SD (1 << 0)/*enable/disable PS func, 1:disable , 0: enable*/
  76. #define CM36283_PS_SD_MASK 0xFFFE
  77. /*for PS CONF3 command*/
  78. #define CM36283_PS_MS_NORMAL (0 << 14)
  79. #define CM36283_PS_MS_LOGIC_ENABLE (1 << 14)
  80. #define CM36283_PS_PROL_63 (0 << 12)
  81. #define CM36283_PS_PROL_127 (1 << 12)
  82. #define CM36283_PS_PROL_191 (2 << 12)
  83. #define CM36283_PS_PROL_255 (3 << 12)
  84. #define CM36283_PS_SMART_PERS_ENABLE (1 << 4)
  85. #define CM36283_PS_ACTIVE_FORCE_MODE (1 << 3)
  86. #define CM36283_PS_ACTIVE_FORCE_TRIG (1 << 2)
  87. /*for INT FLAG*/
  88. #define INT_FLAG_PS_SPFLAG (1<<14)
  89. #define INT_FLAG_ALS_IF_L (1<<13)
  90. #define INT_FLAG_ALS_IF_H (1<<12)
  91. #define INT_FLAG_PS_IF_CLOSE (1<<9)
  92. #define INT_FLAG_PS_IF_AWAY (1<<8)
  93. #define LS_PWR_ON BIT(0)
  94. #define PS_PWR_ON BIT(1)
  95. #define CAPELLA_CM3602_IOCTL_MAGIC 'c'
  96. #define CAPELLA_CM3602_IOCTL_GET_ENABLED \
  97. _IOR(CAPELLA_CM3602_IOCTL_MAGIC, 1, int *)
  98. #define CAPELLA_CM3602_IOCTL_ENABLE \
  99. _IOW(CAPELLA_CM3602_IOCTL_MAGIC, 2, int *)
  100. #define LIGHTSENSOR_IOCTL_MAGIC 'l'
  101. #define LIGHTSENSOR_IOCTL_GET_ENABLED _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *)
  102. #define LIGHTSENSOR_IOCTL_ENABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *)
  103. extern unsigned int ps_kparam1;
  104. extern unsigned int ps_kparam2;
  105. #define CM36283_LEVELS_SIZE 10
  106. enum {
  107. CM36283_ALS_IT0 = 0,
  108. CM36283_ALS_IT1,
  109. CM36283_ALS_IT2,
  110. CM36283_ALS_IT3,
  111. };
  112. struct cm36283_platform_data {
  113. int intr;
  114. uint16_t levels[10];
  115. uint16_t golden_adc;
  116. int (*power)(int, uint8_t); /* power to the chip */
  117. uint8_t slave_addr;
  118. uint8_t ps_close_thd_set;
  119. uint8_t ps_away_thd_set;
  120. uint16_t ls_cmd;
  121. uint16_t ps_conf1_val;
  122. uint16_t ps_conf3_val;
  123. bool polling;
  124. };
  125. #endif