Linux 4.13.16
[linux/fpc-iii.git] / include / media / i2c / adp1653.h
blob8a79f7200f5d64f7e0ca6b5a4d3b900a1623f976
1 /*
2 * include/media/i2c/adp1653.h
4 * Copyright (C) 2008--2011 Nokia Corporation
6 * Contact: Sakari Ailus <sakari.ailus@iki.fi>
8 * Contributors:
9 * Sakari Ailus <sakari.ailus@iki.fi>
10 * Tuukka Toivonen <tuukkat76@gmail.com>
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.
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.
23 #ifndef ADP1653_H
24 #define ADP1653_H
26 #include <linux/i2c.h>
27 #include <linux/mutex.h>
28 #include <linux/videodev2.h>
29 #include <media/v4l2-ctrls.h>
30 #include <media/v4l2-subdev.h>
32 #define ADP1653_NAME "adp1653"
33 #define ADP1653_I2C_ADDR (0x60 >> 1)
35 /* Register definitions */
36 #define ADP1653_REG_OUT_SEL 0x00
37 #define ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN 0x01
38 #define ADP1653_REG_OUT_SEL_HPLED_TORCH_MAX 0x0b
39 #define ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN 0x0c
40 #define ADP1653_REG_OUT_SEL_HPLED_FLASH_MAX 0x1f
41 #define ADP1653_REG_OUT_SEL_HPLED_SHIFT 3
42 #define ADP1653_REG_OUT_SEL_ILED_MAX 0x07
43 #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
50 #define ADP1653_REG_SW_STROBE 0x02
51 #define ADP1653_REG_SW_STROBE_SW_STROBE (1 << 0)
53 #define ADP1653_REG_FAULT 0x03
54 #define ADP1653_REG_FAULT_FLT_SCP (1 << 3)
55 #define ADP1653_REG_FAULT_FLT_OT (1 << 2)
56 #define ADP1653_REG_FAULT_FLT_TMR (1 << 1)
57 #define ADP1653_REG_FAULT_FLT_OV (1 << 0)
59 #define ADP1653_INDICATOR_INTENSITY_MIN 0
60 #define ADP1653_INDICATOR_INTENSITY_STEP 2500
61 #define ADP1653_INDICATOR_INTENSITY_MAX \
62 (ADP1653_REG_OUT_SEL_ILED_MAX * ADP1653_INDICATOR_INTENSITY_STEP)
63 #define ADP1653_INDICATOR_INTENSITY_uA_TO_REG(a) \
64 ((a) / ADP1653_INDICATOR_INTENSITY_STEP)
65 #define ADP1653_INDICATOR_INTENSITY_REG_TO_uA(a) \
66 ((a) * ADP1653_INDICATOR_INTENSITY_STEP)
68 #define ADP1653_FLASH_INTENSITY_BASE 35
69 #define ADP1653_FLASH_INTENSITY_STEP 15
70 #define ADP1653_FLASH_INTENSITY_MIN \
71 (ADP1653_FLASH_INTENSITY_BASE \
72 + ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN * ADP1653_FLASH_INTENSITY_STEP)
73 #define ADP1653_FLASH_INTENSITY_MAX \
74 (ADP1653_FLASH_INTENSITY_MIN + \
75 (ADP1653_REG_OUT_SEL_HPLED_FLASH_MAX - \
76 ADP1653_REG_OUT_SEL_HPLED_FLASH_MIN + 1) * \
77 ADP1653_FLASH_INTENSITY_STEP)
79 #define ADP1653_FLASH_INTENSITY_mA_TO_REG(a) \
80 ((a) < ADP1653_FLASH_INTENSITY_BASE ? 0 : \
81 (((a) - ADP1653_FLASH_INTENSITY_BASE) / ADP1653_FLASH_INTENSITY_STEP))
82 #define ADP1653_FLASH_INTENSITY_REG_TO_mA(a) \
83 ((a) * ADP1653_FLASH_INTENSITY_STEP + ADP1653_FLASH_INTENSITY_BASE)
85 #define ADP1653_TORCH_INTENSITY_MIN \
86 (ADP1653_FLASH_INTENSITY_BASE \
87 + ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN * ADP1653_FLASH_INTENSITY_STEP)
88 #define ADP1653_TORCH_INTENSITY_MAX \
89 (ADP1653_TORCH_INTENSITY_MIN + \
90 (ADP1653_REG_OUT_SEL_HPLED_TORCH_MAX - \
91 ADP1653_REG_OUT_SEL_HPLED_TORCH_MIN + 1) * \
92 ADP1653_FLASH_INTENSITY_STEP)
94 struct adp1653_platform_data {
95 int (*power)(struct v4l2_subdev *sd, int on);
97 u32 max_flash_timeout; /* flash light timeout in us */
98 u32 max_flash_intensity; /* led intensity, flash mode, mA */
99 u32 max_torch_intensity; /* led intensity, torch mode, mA */
100 u32 max_indicator_intensity; /* indicator led intensity, uA */
102 struct gpio_desc *enable_gpio; /* for device-tree based boot */
105 #define to_adp1653_flash(sd) container_of(sd, struct adp1653_flash, subdev)
107 struct adp1653_flash {
108 struct v4l2_subdev subdev;
109 struct adp1653_platform_data *platform_data;
111 struct v4l2_ctrl_handler ctrls;
112 struct v4l2_ctrl *led_mode;
113 struct v4l2_ctrl *flash_timeout;
114 struct v4l2_ctrl *flash_intensity;
115 struct v4l2_ctrl *torch_intensity;
116 struct v4l2_ctrl *indicator_intensity;
118 struct mutex power_lock;
119 int power_count;
120 int fault;
123 #endif /* ADP1653_H */