adp1653.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * include/media/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. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  24. * 02110-1301 USA
  25. *
  26. */
  27. #ifndef ADP1653_H
  28. #define ADP1653_H
  29. #include <linux/i2c.h>
  30. #include <linux/mutex.h>
  31. #include <linux/videodev2.h>
  32. #include <media/v4l2-ctrls.h>
  33. #include <media/v4l2-subdev.h>
  34. #define ADP1653_NAME "adp1653"
  35. #define ADP1653_I2C_ADDR (0x60 >> 1)
  36. /* Register definitions */
  37. #define ADP1653_REG_OUT_SEL 0x00
  38. #define ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN 0x01
  39. #define ADP1653_REG_OUT_SEL_HPLED_TORCH_MAX 0x0b
  40. #define ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN 0x0c
  41. #define ADP1653_REG_OUT_SEL_HPLED_FLASH_MAX 0x1f
  42. #define ADP1653_REG_OUT_SEL_HPLED_SHIFT 3
  43. #define ADP1653_REG_OUT_SEL_ILED_MAX 0x07
  44. #define ADP1653_REG_OUT_SEL_ILED_SHIFT 0
  45. #define ADP1653_REG_CONFIG 0x01
  46. #define ADP1653_REG_CONFIG_TMR_CFG (1 << 4)
  47. #define ADP1653_REG_CONFIG_TMR_SET_MAX 0x0f
  48. #define ADP1653_REG_CONFIG_TMR_SET_SHIFT 0
  49. #define ADP1653_REG_SW_STROBE 0x02
  50. #define ADP1653_REG_SW_STROBE_SW_STROBE (1 << 0)
  51. #define ADP1653_REG_FAULT 0x03
  52. #define ADP1653_REG_FAULT_FLT_SCP (1 << 3)
  53. #define ADP1653_REG_FAULT_FLT_OT (1 << 2)
  54. #define ADP1653_REG_FAULT_FLT_TMR (1 << 1)
  55. #define ADP1653_REG_FAULT_FLT_OV (1 << 0)
  56. #define ADP1653_INDICATOR_INTENSITY_MIN 0
  57. #define ADP1653_INDICATOR_INTENSITY_STEP 2500
  58. #define ADP1653_INDICATOR_INTENSITY_MAX \
  59. (ADP1653_REG_OUT_SEL_ILED_MAX * ADP1653_INDICATOR_INTENSITY_STEP)
  60. #define ADP1653_INDICATOR_INTENSITY_uA_TO_REG(a) \
  61. ((a) / ADP1653_INDICATOR_INTENSITY_STEP)
  62. #define ADP1653_INDICATOR_INTENSITY_REG_TO_uA(a) \
  63. ((a) * ADP1653_INDICATOR_INTENSITY_STEP)
  64. #define ADP1653_FLASH_INTENSITY_BASE 35
  65. #define ADP1653_FLASH_INTENSITY_STEP 15
  66. #define ADP1653_FLASH_INTENSITY_MIN \
  67. (ADP1653_FLASH_INTENSITY_BASE \
  68. + ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN * ADP1653_FLASH_INTENSITY_STEP)
  69. #define ADP1653_FLASH_INTENSITY_MAX \
  70. (ADP1653_FLASH_INTENSITY_MIN + \
  71. (ADP1653_REG_OUT_SEL_HPLED_FLASH_MAX - \
  72. ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN + 1) * \
  73. ADP1653_FLASH_INTENSITY_STEP)
  74. #define ADP1653_FLASH_INTENSITY_mA_TO_REG(a) \
  75. ((a) < ADP1653_FLASH_INTENSITY_BASE ? 0 : \
  76. (((a) - ADP1653_FLASH_INTENSITY_BASE) / ADP1653_FLASH_INTENSITY_STEP))
  77. #define ADP1653_FLASH_INTENSITY_REG_TO_mA(a) \
  78. ((a) * ADP1653_FLASH_INTENSITY_STEP + ADP1653_FLASH_INTENSITY_BASE)
  79. #define ADP1653_TORCH_INTENSITY_MIN \
  80. (ADP1653_FLASH_INTENSITY_BASE \
  81. + ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN * ADP1653_FLASH_INTENSITY_STEP)
  82. #define ADP1653_TORCH_INTENSITY_MAX \
  83. (ADP1653_TORCH_INTENSITY_MIN + \
  84. (ADP1653_REG_OUT_SEL_HPLED_TORCH_MAX - \
  85. ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN + 1) * \
  86. ADP1653_FLASH_INTENSITY_STEP)
  87. struct adp1653_platform_data {
  88. int (*power)(struct v4l2_subdev *sd, int on);
  89. u32 max_flash_timeout; /* flash light timeout in us */
  90. u32 max_flash_intensity; /* led intensity, flash mode, mA */
  91. u32 max_torch_intensity; /* led intensity, torch mode, mA */
  92. u32 max_indicator_intensity; /* indicator led intensity, uA */
  93. struct gpio_desc *enable_gpio; /* for device-tree based boot */
  94. };
  95. #define to_adp1653_flash(sd) container_of(sd, struct adp1653_flash, subdev)
  96. struct adp1653_flash {
  97. struct v4l2_subdev subdev;
  98. struct adp1653_platform_data *platform_data;
  99. struct v4l2_ctrl_handler ctrls;
  100. struct v4l2_ctrl *led_mode;
  101. struct v4l2_ctrl *flash_timeout;
  102. struct v4l2_ctrl *flash_intensity;
  103. struct v4l2_ctrl *torch_intensity;
  104. struct v4l2_ctrl *indicator_intensity;
  105. struct mutex power_lock;
  106. int power_count;
  107. int fault;
  108. };
  109. #endif /* ADP1653_H */