/kern_oII/drivers/sensor/optical/isl29023.h

http://omnia2droid.googlecode.com/ · C Header · 175 lines · 75 code · 18 blank · 82 comment · 0 complexity · 3d8add122d93132436689b5895079f5a MD5 · raw file

  1. #ifndef __LIGHT_H__
  2. #define __LIGHT_H__
  3. /********************************************************************************
  4. * *
  5. * ILS2903 Light Sensor Driver for Samsung Omnia II GT-I8000 *
  6. * with backlight contol *
  7. ********************************************************************************
  8. *
  9. * Setup interface:
  10. * /sys/class/lightsensor/switch_cmd/lightsensor_file_cmd
  11. *
  12. * Turn on
  13. * default mode: (0x1a304)
  14. *
  15. * echo 1 > /sys/class/lightsensor/switch_cmd/lightsensor_file_cmd
  16. *
  17. * Turn on
  18. * timer mode, 1-4000 LUX range, 16 bit ADC, (0.06 lux/count) resolution
  19. *
  20. * echo 2001 > /sys/class/lightsensor/switch_cmd/lightsensor_file_cmd
  21. *
  22. * Turn off
  23. * echo 0 > /sys/class/lightsensor/switch_cmd/lightsensor_file_cmd
  24. *
  25. * To check current operation mode
  26. * cat /sys/class/lightsensor/switch_cmd/lightsensor_file_cmd
  27. *
  28. * Setup parameters: ICP0M (default: 0x1a304)
  29. * Operation modes:
  30. * timer I = 0
  31. * interrupt I = 1
  32. *
  33. * Conversion modes:
  34. * C: BITS 7 TO 4 OPERATION
  35. * 0000 Power-down the device C = 0
  36. * 0010 ALS once C = 2
  37. * 0100 IR once C = 4
  38. * 1000 Reserved (Do not use)
  39. * 1010 ALS continuous C = A
  40. * 1100 IR continuous C = E
  41. * 1110 Reserved (Do not use)
  42. *
  43. * INTERRUPT PERSIST (number of mesurement before set interrupt)
  44. * P: BIT 1:0 NUMBER OF INTEGRATION CYCLES
  45. * 0000 1 P = 0
  46. * 0001 4 P = 1
  47. * 0010 8 P = 2
  48. * 0011 16 P = 3
  49. *
  50. * ADC RESOLUTION DATA WIDTH
  51. * M: BITS 3:2 NUMBER OF CLOCK CYCLES n-BIT ADC
  52. * 00 2^16 = 65,536 16
  53. * 01 2^12 = 4,096 12
  54. * 10 2^8 = 256 8
  55. * 11 2^4 = 16 4
  56. *
  57. * RANGE/FSR LUX RESOLUTION
  58. * M: BITS 1:0 RANGE(k) FSR (MAX LUX)
  59. * 00 0 1,000
  60. * 01 1 4,000
  61. * 10 2 16,000
  62. * 11 3 64,000
  63. *
  64. * TO get ouput data (LUX) :
  65. * cat /sys/class/lightsensor/switch_cmd/get_lux
  66. * /dev/input/evenX
  67. */
  68. /* LUX calculation */
  69. static int adc_resolution[] = { 0xffff, 0x0fff, 0x00ff, 0x000f }; // 16, 12, 8, 4 bit ADC resolution
  70. static int FSR_LUX_range[] = { 1000, 4000, 16000, 64000 };
  71. /*
  72. * LUX = FSR_LUX_range[k] * sensor_data / adc_resolution[m]
  73. * k = op_mode & 3;
  74. * m = (op_mode >> 2) & 3;
  75. */
  76. #define LIGHT_PERIOD 1 // secs in timer operation mode
  77. #define USE_INPUT_DEVICE 1
  78. #define I2C_DF_NOTIFY 0x01 // for i2c
  79. #define IRQ_LIGHT_INT IRQ_EINT(27) // s3c64xx ext int
  80. #define LIGHT_ADDR 0x88 // i2c slave addr
  81. #define REGS_COMMAND_I 0x0
  82. #define REGS_COMMAND_II 0x1
  83. #define REGS_LBS_SENSOR 0x2
  84. #define REGS_MBS_SENSOR 0x3
  85. #define REGS_INT_LSB_TH_LO 0x4
  86. #define REGS_INT_MSB_TH_LO 0x5
  87. #define REGS_INT_LSB_TH_HI 0x6
  88. #define REGS_INT_MSB_TH_HI 0x7
  89. /* power control */
  90. #define ON 1
  91. #define OFF 0
  92. /* for state transition */
  93. struct _light_state {
  94. int lux_bottom_limit;
  95. int lux_top_limit;
  96. int brightness;
  97. };
  98. /* LCD brightness */
  99. #define STATE_0_BRIGHTNESS 40
  100. #define STATE_1_BRIGHTNESS 90
  101. #define STATE_2_BRIGHTNESS 140
  102. #define STATE_3_BRIGHTNESS 190
  103. #define STATE_4_BRIGHTNESS 255
  104. /* State threshold levels in LUX */
  105. #define STATE_0_1_TH 30
  106. #define STATE_1_2_TH 60
  107. #define STATE_2_3_TH 90
  108. #define STATE_3_4_TH 120
  109. #define CUT_GAP 20
  110. static struct _light_state light_state[] = {
  111. [0] = {
  112. //0~40
  113. .lux_bottom_limit = 0,
  114. .lux_top_limit = STATE_0_1_TH + CUT_GAP/2,
  115. .brightness = STATE_0_BRIGHTNESS,
  116. },
  117. [1] = {
  118. //20~70
  119. .lux_bottom_limit = STATE_0_1_TH - CUT_GAP/2,
  120. .lux_top_limit = STATE_1_2_TH + CUT_GAP/2,
  121. .brightness = STATE_1_BRIGHTNESS,
  122. },
  123. [2] = {
  124. //50~100
  125. .lux_bottom_limit = STATE_1_2_TH - CUT_GAP/2,
  126. .lux_top_limit = STATE_2_3_TH + CUT_GAP/2,
  127. .brightness = STATE_2_BRIGHTNESS,
  128. },
  129. [3] = {
  130. //80~130
  131. .lux_bottom_limit = STATE_2_3_TH - CUT_GAP/2,
  132. .lux_top_limit = STATE_3_4_TH + CUT_GAP/2,
  133. .brightness = STATE_3_BRIGHTNESS,
  134. },
  135. [4] = {
  136. // 110~unlimited
  137. .lux_bottom_limit = STATE_3_4_TH - CUT_GAP/2,
  138. .lux_top_limit = 0xffff, //unlimited
  139. .brightness = STATE_4_BRIGHTNESS,
  140. },
  141. };
  142. /* driver data */
  143. struct light_data {
  144. #if USE_INPUT_DEVICE
  145. struct input_dev *input_dev;
  146. #endif
  147. struct work_struct work_light;
  148. int irq;
  149. struct hrtimer timer;
  150. };
  151. struct workqueue_struct *light_wq;
  152. /* prototype */
  153. int isl_i2c_read(u8 reg);
  154. int isl_i2c_write( u8 reg, int val );
  155. extern void backlight_level_ctrl(s32 value);
  156. static int isl_attach_adapter(struct i2c_adapter *adap);
  157. #endif