flicker_test.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2021 Samsung Electronics Co., Ltd. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef EOL_TEST_H
  17. #define EOL_TEST_H
  18. #include <linux/delay.h>
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/leds.h>
  24. #include <linux/types.h>
  25. #include <linux/gpio.h>
  26. #include <linux/pinctrl/consumer.h>
  27. #include <linux/of_gpio.h>
  28. #include <linux/of_device.h>
  29. #include <linux/version.h>
  30. /*
  31. * Flicker Sensor Self test module
  32. *
  33. * Uses LEDs in the system.
  34. * If you want to add a new LED,
  35. * add a header below and define dt node name.
  36. *
  37. * You can build this with CONFIG_EOL_TEST
  38. */
  39. #if IS_ENABLED(CONFIG_LEDS_S2MPB02)
  40. #include <linux/leds-s2mpb02.h>
  41. #elif IS_ENABLED(CONFIG_LEDS_KTD2692)
  42. #include <linux/leds-ktd2692.h>
  43. #elif IS_ENABLED(CONFIG_LEDS_AW36518_FLASH)
  44. #include <linux/leds-aw36518.h>
  45. #elif IS_ENABLED(CONFIG_LEDS_QTI_FLASH) && (IS_ENABLED(CONFIG_SENSORS_STK6D2X) || IS_ENABLED(CONFIG_SENSORS_TSL2511))
  46. #include <linux/leds.h>
  47. #include <linux/leds-qti-flash.h>
  48. DEFINE_LED_TRIGGER(torch2_trigger);
  49. DEFINE_LED_TRIGGER(torch3_trigger);
  50. DEFINE_LED_TRIGGER(switch3_trigger);
  51. #endif
  52. #define LED_DT_NODE_NAME "flicker_test"
  53. #define DEFAULT_DUTY_50HZ 5000
  54. #define DEFAULT_DUTY_60HZ 4166
  55. #define MAX_TEST_RESULT 256
  56. #if IS_ENABLED(CONFIG_SENSORS_STK6D2X)
  57. #define EOL_COUNT 4
  58. #define EOL_SKIP_COUNT 4
  59. #else
  60. #define EOL_COUNT 5
  61. #define EOL_SKIP_COUNT 5
  62. #endif
  63. #define EOL_FLICKER_SKIP_COUNT 2
  64. static int gpio_torch;
  65. static int led_curr;
  66. static int led_mode;
  67. static char result_str[MAX_TEST_RESULT];
  68. enum TEST_STATE {
  69. EOL_STATE_INIT = -1,
  70. EOL_STATE_100,
  71. EOL_STATE_120,
  72. EOL_STATE_DONE,
  73. };
  74. struct test_data {
  75. u8 eol_enable;
  76. s16 eol_state;
  77. u32 eol_count;
  78. u32 eol_sum_count;
  79. u32 eol_awb;
  80. u32 eol_clear;
  81. u32 eol_wideband;
  82. u32 eol_flicker;
  83. u32 eol_flicker_sum;
  84. u32 eol_flicker_sum_count;
  85. u32 eol_flicker_count;
  86. u32 eol_flicker_skip_count;
  87. u32 eol_pulse_count;
  88. u32 eol_uv;
  89. };
  90. struct result_data {
  91. int result;
  92. u32 flicker[EOL_STATE_DONE];
  93. u32 awb[EOL_STATE_DONE];
  94. u32 clear[EOL_STATE_DONE];
  95. u32 wideband[EOL_STATE_DONE];
  96. u32 ratio[EOL_STATE_DONE];
  97. u32 uv[EOL_STATE_DONE];
  98. };
  99. enum GPIO_TYPE {
  100. EOL_FLASH,
  101. EOL_TORCH,
  102. };
  103. void als_eol_set_env(bool torch, int intensity);
  104. struct result_data* als_eol_mode(void);
  105. void als_eol_update_als(int awb, int clear, int wideband, int uv);
  106. void als_eol_update_flicker(int Hz);
  107. void als_eol_set_err_handler(void (*handler)(void));
  108. #endif /* EOL_TEST_H */