GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / media / atomisp / include / media / lm3642.h
1 /*
2  * include/media/lm3642.h
3  *
4  * Copyright (c) 2010-2012 Intel Corporation. All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version
8  * 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.
17  */
18
19 #ifndef _LM3642_H_
20 #define _LM3642_H_
21
22 #include <linux/videodev2.h>
23 #include <media/v4l2-subdev.h>
24
25 #define LM3642_NAME    "lm3642"
26 #define LM3642_ID      3642
27
28 #define v4l2_queryctrl_entry_integer(_id, _name,\
29                 _minimum, _maximum, _step, \
30                 _default_value, _flags) \
31         {\
32                 .id = (_id), \
33                 .type = V4L2_CTRL_TYPE_INTEGER, \
34                 .name = _name, \
35                 .minimum = (_minimum), \
36                 .maximum = (_maximum), \
37                 .step = (_step), \
38                 .default_value = (_default_value),\
39                 .flags = (_flags),\
40         }
41 #define v4l2_queryctrl_entry_boolean(_id, _name,\
42                 _default_value, _flags) \
43         {\
44                 .id = (_id), \
45                 .type = V4L2_CTRL_TYPE_BOOLEAN, \
46                 .name = _name, \
47                 .minimum = 0, \
48                 .maximum = 1, \
49                 .step = 1, \
50                 .default_value = (_default_value),\
51                 .flags = (_flags),\
52         }
53
54 #define s_ctrl_id_entry_integer(_id, _name, \
55                 _minimum, _maximum, _step, \
56                 _default_value, _flags, \
57                 _s_ctrl, _g_ctrl)       \
58         {\
59                 .qc = v4l2_queryctrl_entry_integer(_id, _name,\
60                                 _minimum, _maximum, _step,\
61                                 _default_value, _flags), \
62                 .s_ctrl = _s_ctrl, \
63                 .g_ctrl = _g_ctrl, \
64         }
65
66 #define s_ctrl_id_entry_boolean(_id, _name, \
67                 _default_value, _flags, \
68                 _s_ctrl, _g_ctrl)       \
69         {\
70                 .qc = v4l2_queryctrl_entry_boolean(_id, _name,\
71                                 _default_value, _flags), \
72                 .s_ctrl = _s_ctrl, \
73                 .g_ctrl = _g_ctrl, \
74         }
75
76
77 /* Default Values */
78 #define LM3642_DEFAULT_TIMEOUT           300U
79 #define LM3642_DEFAULT_RAMP_TIME         0x10 /* 1.024ms */
80 #define LM3642_DEFAULT_INDICATOR_CURRENT 0x01 /* 1.88A */
81 #define LM3642_DEFAULT_FLASH_CURRENT     0x0f /* 1500mA */
82
83 /* Value settings for Flash Time-out Duration*/
84 #define LM3642_MIN_TIMEOUT              100U
85 #define LM3642_MAX_TIMEOUT              800U
86 #define LM3642_TIMEOUT_STEPSIZE         100U
87
88 /* Flash modes */
89 #define LM3642_MODE_SHUTDOWN            0
90 #define LM3642_MODE_INDICATOR           1
91 #define LM3642_MODE_TORCH               2
92 #define LM3642_MODE_FLASH               3
93
94 /* timer delay time */
95 #define LM3642_TIMER_DELAY              5
96
97 /* Percentage <-> value macros */
98 #define LM3642_MIN_PERCENT                   0U
99 #define LM3642_MAX_PERCENT                   100U
100 #define LM3642_CLAMP_PERCENTAGE(val) \
101         clamp(val, LM3642_MIN_PERCENT, LM3642_MAX_PERCENT)
102
103 #define LM3642_VALUE_TO_PERCENT(v, step) \
104         (((((unsigned long)((v)+1))*(step))+50)/100)
105 #define LM3642_PERCENT_TO_VALUE(p, step) \
106         (((((unsigned long)(p))*100)+((step)>>1))/(step)-1)
107
108 /* Product specific limits
109  * TODO: get these from platform data */
110 #define LM3642_FLASH_MAX_LVL   0x0F /* 1500mA */
111 #define LM3642_TORCH_MAX_LVL   0x07 /* 187mA */
112 #define LM3642_INDICATOR_MAX_LVL   0x01 /* 1.88A */
113
114 /* Flash brightness, input is percentage, output is [0..15] */
115 #define LM3642_FLASH_STEP       \
116         ((100ul*(LM3642_MAX_PERCENT) \
117         +((LM3642_FLASH_MAX_LVL+1)>>1)) \
118         /((LM3642_FLASH_MAX_LVL+1)))
119 #define LM3642_FLASH_DEFAULT_BRIGHTNESS \
120         LM3642_VALUE_TO_PERCENT(15, LM3642_FLASH_STEP)
121
122 /* Torch brightness, input is percentage, output is [0..7] */
123 #define LM3642_TORCH_STEP       \
124         ((100ul*(LM3642_MAX_PERCENT) \
125         +((LM3642_TORCH_MAX_LVL+1)>>1)) \
126         /((LM3642_TORCH_MAX_LVL+1)))
127 #define LM3642_TORCH_DEFAULT_BRIGHTNESS \
128         LM3642_VALUE_TO_PERCENT(0, LM3642_TORCH_STEP)
129
130 /* Indicator brightness, input is percentage, output is [0..1] */
131 #define LM3642_INDICATOR_STEP   \
132         ((100ul*(LM3642_MAX_PERCENT) \
133         +((LM3642_INDICATOR_MAX_LVL+1)>>1)) \
134         /((LM3642_INDICATOR_MAX_LVL+1)))
135 #define LM3642_INDICATOR_DEFAULT_BRIGHTNESS \
136         LM3642_VALUE_TO_PERCENT(1, LM3642_INDICATOR_STEP)
137
138 /*
139  * lm3642_platform_data - Flash controller platform data
140  */
141 struct lm3642_platform_data {
142         int gpio_torch;
143         int gpio_strobe;
144         int (*power_ctrl)(struct v4l2_subdev *subdev, int on);
145
146         unsigned int torch_en;
147         unsigned int flash_en;
148         unsigned int tx_en;
149         unsigned int ivfm_en;
150 };
151
152 #endif /* _LM3642_H_ */
153