1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * include/media/lm3554.h 4 * 5 * Copyright (c) 2010-2012 Intel Corporation. All Rights Reserved. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License version 9 * 2 as published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * 17 */ 18 #ifndef _LM3554_H_ 19 #define _LM3554_H_ 20 21 #include <linux/gpio/consumer.h> 22 #include <linux/videodev2.h> 23 #include <media/v4l2-subdev.h> 24 25 #define LM3554_ID 3554 26 27 #define v4l2_queryctrl_entry_integer(_id, _name,\ 28 _minimum, _maximum, _step, \ 29 _default_value, _flags) \ 30 {\ 31 .id = (_id), \ 32 .type = V4L2_CTRL_TYPE_INTEGER, \ 33 .name = _name, \ 34 .minimum = (_minimum), \ 35 .maximum = (_maximum), \ 36 .step = (_step), \ 37 .default_value = (_default_value),\ 38 .flags = (_flags),\ 39 } 40 #define v4l2_queryctrl_entry_boolean(_id, _name,\ 41 _default_value, _flags) \ 42 {\ 43 .id = (_id), \ 44 .type = V4L2_CTRL_TYPE_BOOLEAN, \ 45 .name = _name, \ 46 .minimum = 0, \ 47 .maximum = 1, \ 48 .step = 1, \ 49 .default_value = (_default_value),\ 50 .flags = (_flags),\ 51 } 52 53 #define s_ctrl_id_entry_integer(_id, _name, \ 54 _minimum, _maximum, _step, \ 55 _default_value, _flags, \ 56 _s_ctrl, _g_ctrl) \ 57 {\ 58 .qc = v4l2_queryctrl_entry_integer(_id, _name,\ 59 _minimum, _maximum, _step,\ 60 _default_value, _flags), \ 61 .s_ctrl = _s_ctrl, \ 62 .g_ctrl = _g_ctrl, \ 63 } 64 65 #define s_ctrl_id_entry_boolean(_id, _name, \ 66 _default_value, _flags, \ 67 _s_ctrl, _g_ctrl) \ 68 {\ 69 .qc = v4l2_queryctrl_entry_boolean(_id, _name,\ 70 _default_value, _flags), \ 71 .s_ctrl = _s_ctrl, \ 72 .g_ctrl = _g_ctrl, \ 73 } 74 75 /* Value settings for Flash Time-out Duration*/ 76 #define LM3554_DEFAULT_TIMEOUT 512U 77 #define LM3554_MIN_TIMEOUT 32U 78 #define LM3554_MAX_TIMEOUT 1024U 79 #define LM3554_TIMEOUT_STEPSIZE 32U 80 81 /* Flash modes */ 82 #define LM3554_MODE_SHUTDOWN 0 83 #define LM3554_MODE_INDICATOR 1 84 #define LM3554_MODE_TORCH 2 85 #define LM3554_MODE_FLASH 3 86 87 /* timer delay time */ 88 #define LM3554_TIMER_DELAY 5 89 90 /* Percentage <-> value macros */ 91 #define LM3554_MIN_PERCENT 0U 92 #define LM3554_MAX_PERCENT 100U 93 #define LM3554_CLAMP_PERCENTAGE(val) \ 94 clamp(val, LM3554_MIN_PERCENT, LM3554_MAX_PERCENT) 95 96 #define LM3554_VALUE_TO_PERCENT(v, step) (((((unsigned long)(v)) * (step)) + 50) / 100) 97 #define LM3554_PERCENT_TO_VALUE(p, step) (((((unsigned long)(p)) * 100) + (step >> 1)) / (step)) 98 99 /* Product specific limits 100 * TODO: get these from platform data */ 101 #define LM3554_FLASH_MAX_LVL 0x0F /* 1191mA */ 102 103 /* Flash brightness, input is percentage, output is [0..15] */ 104 #define LM3554_FLASH_STEP \ 105 ((100ul * (LM3554_MAX_PERCENT) + ((LM3554_FLASH_MAX_LVL) >> 1)) / ((LM3554_FLASH_MAX_LVL))) 106 #define LM3554_FLASH_DEFAULT_BRIGHTNESS \ 107 LM3554_VALUE_TO_PERCENT(13, LM3554_FLASH_STEP) 108 109 /* Torch brightness, input is percentage, output is [0..7] */ 110 #define LM3554_TORCH_STEP 1250 111 #define LM3554_TORCH_DEFAULT_BRIGHTNESS \ 112 LM3554_VALUE_TO_PERCENT(2, LM3554_TORCH_STEP) 113 114 /* Indicator brightness, input is percentage, output is [0..3] */ 115 #define LM3554_INDICATOR_STEP 2500 116 #define LM3554_INDICATOR_DEFAULT_BRIGHTNESS \ 117 LM3554_VALUE_TO_PERCENT(1, LM3554_INDICATOR_STEP) 118 119 /* 120 * lm3554_platform_data - Flash controller platform data 121 */ 122 struct lm3554_platform_data { 123 struct gpio_desc *gpio_torch; 124 struct gpio_desc *gpio_strobe; 125 struct gpio_desc *gpio_reset; 126 127 unsigned int current_limit; 128 unsigned int envm_tx2; 129 unsigned int tx2_polarity; 130 }; 131 132 #endif /* _LM3554_H_ */ 133