adp1653.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * include/media/i2c/adp1653.h
  3. *
  4. * Copyright (C) 2008--2011 Nokia Corporation
  5. *
  6. * Contact: Sakari Ailus <sakari.ailus@iki.fi>
  7. *
  8. * Contributors:
  9. * Sakari Ailus <sakari.ailus@iki.fi>
  10. * Tuukka Toivonen <tuukkat76@gmail.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * version 2 as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. */
  22. #ifndef ADP1653_H
  23. #define ADP1653_H
  24. #include <linux/i2c.h>
  25. #include <linux/mutex.h>
  26. #include <linux/videodev2.h>
  27. #include <media/v4l2-ctrls.h>
  28. #include <media/v4l2-subdev.h>
  29. #define ADP1653_NAME "adp1653"
  30. #define ADP1653_I2C_ADDR (0x60 >> 1)
  31. /* Register definitions */
  32. #define ADP1653_REG_OUT_SEL 0x00
  33. #define ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN 0x01
  34. #define ADP1653_REG_OUT_SEL_HPLED_TORCH_MAX 0x0b
  35. #define ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN 0x0c
  36. #define ADP1653_REG_OUT_SEL_HPLED_FLASH_MAX 0x1f
  37. #define ADP1653_REG_OUT_SEL_HPLED_SHIFT 3
  38. #define ADP1653_REG_OUT_SEL_ILED_MAX 0x07
  39. #define ADP1653_REG_OUT_SEL_ILED_SHIFT 0
  40. #define ADP1653_REG_CONFIG 0x01
  41. #define ADP1653_REG_CONFIG_TMR_CFG (1 << 4)
  42. #define ADP1653_REG_CONFIG_TMR_SET_MAX 0x0f
  43. #define ADP1653_REG_CONFIG_TMR_SET_SHIFT 0
  44. #define ADP1653_REG_SW_STROBE 0x02
  45. #define ADP1653_REG_SW_STROBE_SW_STROBE (1 << 0)
  46. #define ADP1653_REG_FAULT 0x03
  47. #define ADP1653_REG_FAULT_FLT_SCP (1 << 3)
  48. #define ADP1653_REG_FAULT_FLT_OT (1 << 2)
  49. #define ADP1653_REG_FAULT_FLT_TMR (1 << 1)
  50. #define ADP1653_REG_FAULT_FLT_OV (1 << 0)
  51. #define ADP1653_INDICATOR_INTENSITY_MIN 0
  52. #define ADP1653_INDICATOR_INTENSITY_STEP 2500
  53. #define ADP1653_INDICATOR_INTENSITY_MAX \
  54. (ADP1653_REG_OUT_SEL_ILED_MAX * ADP1653_INDICATOR_INTENSITY_STEP)
  55. #define ADP1653_INDICATOR_INTENSITY_uA_TO_REG(a) \
  56. ((a) / ADP1653_INDICATOR_INTENSITY_STEP)
  57. #define ADP1653_INDICATOR_INTENSITY_REG_TO_uA(a) \
  58. ((a) * ADP1653_INDICATOR_INTENSITY_STEP)
  59. #define ADP1653_FLASH_INTENSITY_BASE 35
  60. #define ADP1653_FLASH_INTENSITY_STEP 15
  61. #define ADP1653_FLASH_INTENSITY_MIN \
  62. (ADP1653_FLASH_INTENSITY_BASE \
  63. + ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN * ADP1653_FLASH_INTENSITY_STEP)
  64. #define ADP1653_FLASH_INTENSITY_MAX \
  65. (ADP1653_FLASH_INTENSITY_MIN + \
  66. (ADP1653_REG_OUT_SEL_HPLED_FLASH_MAX - \
  67. ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN + 1) * \
  68. ADP1653_FLASH_INTENSITY_STEP)
  69. #define ADP1653_FLASH_INTENSITY_mA_TO_REG(a) \
  70. ((a) < ADP1653_FLASH_INTENSITY_BASE ? 0 : \
  71. (((a) - ADP1653_FLASH_INTENSITY_BASE) / ADP1653_FLASH_INTENSITY_STEP))
  72. #define ADP1653_FLASH_INTENSITY_REG_TO_mA(a) \
  73. ((a) * ADP1653_FLASH_INTENSITY_STEP + ADP1653_FLASH_INTENSITY_BASE)
  74. #define ADP1653_TORCH_INTENSITY_MIN \
  75. (ADP1653_FLASH_INTENSITY_BASE \
  76. + ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN * ADP1653_FLASH_INTENSITY_STEP)
  77. #define ADP1653_TORCH_INTENSITY_MAX \
  78. (ADP1653_TORCH_INTENSITY_MIN + \
  79. (ADP1653_REG_OUT_SEL_HPLED_TORCH_MAX - \
  80. ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN + 1) * \
  81. ADP1653_FLASH_INTENSITY_STEP)
  82. struct adp1653_platform_data {
  83. int (*power)(struct v4l2_subdev *sd, int on);
  84. u32 max_flash_timeout; /* flash light timeout in us */
  85. u32 max_flash_intensity; /* led intensity, flash mode, mA */
  86. u32 max_torch_intensity; /* led intensity, torch mode, mA */
  87. u32 max_indicator_intensity; /* indicator led intensity, uA */
  88. struct gpio_desc *enable_gpio; /* for device-tree based boot */
  89. };
  90. #define to_adp1653_flash(sd) container_of(sd, struct adp1653_flash, subdev)
  91. struct adp1653_flash {
  92. struct v4l2_subdev subdev;
  93. struct adp1653_platform_data *platform_data;
  94. struct v4l2_ctrl_handler ctrls;
  95. struct v4l2_ctrl *led_mode;
  96. struct v4l2_ctrl *flash_timeout;
  97. struct v4l2_ctrl *flash_intensity;
  98. struct v4l2_ctrl *torch_intensity;
  99. struct v4l2_ctrl *indicator_intensity;
  100. struct mutex power_lock;
  101. int power_count;
  102. int fault;
  103. };
  104. #endif /* ADP1653_H */