linux/drivers/staging/media/atomisp/include/media/lm3554.h
<<
>>
Prefs
   1/*
   2 * include/media/lm3554.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; if not, write to the Free Software
  17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18 * 02110-1301, USA.
  19 *
  20 */
  21#ifndef _LM3554_H_
  22#define _LM3554_H_
  23
  24#include <linux/videodev2.h>
  25#include <media/v4l2-subdev.h>
  26
  27#define LM3554_NAME    "lm3554"
  28#define LM3554_ID      3554
  29
  30#define v4l2_queryctrl_entry_integer(_id, _name,\
  31                _minimum, _maximum, _step, \
  32                _default_value, _flags) \
  33        {\
  34                .id = (_id), \
  35                .type = V4L2_CTRL_TYPE_INTEGER, \
  36                .name = _name, \
  37                .minimum = (_minimum), \
  38                .maximum = (_maximum), \
  39                .step = (_step), \
  40                .default_value = (_default_value),\
  41                .flags = (_flags),\
  42        }
  43#define v4l2_queryctrl_entry_boolean(_id, _name,\
  44                _default_value, _flags) \
  45        {\
  46                .id = (_id), \
  47                .type = V4L2_CTRL_TYPE_BOOLEAN, \
  48                .name = _name, \
  49                .minimum = 0, \
  50                .maximum = 1, \
  51                .step = 1, \
  52                .default_value = (_default_value),\
  53                .flags = (_flags),\
  54        }
  55
  56#define s_ctrl_id_entry_integer(_id, _name, \
  57                _minimum, _maximum, _step, \
  58                _default_value, _flags, \
  59                _s_ctrl, _g_ctrl)       \
  60        {\
  61                .qc = v4l2_queryctrl_entry_integer(_id, _name,\
  62                                _minimum, _maximum, _step,\
  63                                _default_value, _flags), \
  64                .s_ctrl = _s_ctrl, \
  65                .g_ctrl = _g_ctrl, \
  66        }
  67
  68#define s_ctrl_id_entry_boolean(_id, _name, \
  69                _default_value, _flags, \
  70                _s_ctrl, _g_ctrl)       \
  71        {\
  72                .qc = v4l2_queryctrl_entry_boolean(_id, _name,\
  73                                _default_value, _flags), \
  74                .s_ctrl = _s_ctrl, \
  75                .g_ctrl = _g_ctrl, \
  76        }
  77
  78/* Value settings for Flash Time-out Duration*/
  79#define LM3554_DEFAULT_TIMEOUT          512U
  80#define LM3554_MIN_TIMEOUT              32U
  81#define LM3554_MAX_TIMEOUT              1024U
  82#define LM3554_TIMEOUT_STEPSIZE         32U
  83
  84/* Flash modes */
  85#define LM3554_MODE_SHUTDOWN            0
  86#define LM3554_MODE_INDICATOR           1
  87#define LM3554_MODE_TORCH               2
  88#define LM3554_MODE_FLASH               3
  89
  90/* timer delay time */
  91#define LM3554_TIMER_DELAY              5
  92
  93/* Percentage <-> value macros */
  94#define LM3554_MIN_PERCENT                   0U
  95#define LM3554_MAX_PERCENT                   100U
  96#define LM3554_CLAMP_PERCENTAGE(val) \
  97        clamp(val, LM3554_MIN_PERCENT, LM3554_MAX_PERCENT)
  98
  99#define LM3554_VALUE_TO_PERCENT(v, step)     (((((unsigned long)(v))*(step))+50)/100)
 100#define LM3554_PERCENT_TO_VALUE(p, step)     (((((unsigned long)(p))*100)+(step>>1))/(step))
 101
 102/* Product specific limits
 103 * TODO: get these from platform data */
 104#define LM3554_FLASH_MAX_LVL   0x0F /* 1191mA */
 105
 106/* Flash brightness, input is percentage, output is [0..15] */
 107#define LM3554_FLASH_STEP       \
 108        ((100ul*(LM3554_MAX_PERCENT)+((LM3554_FLASH_MAX_LVL)>>1))/((LM3554_FLASH_MAX_LVL)))
 109#define LM3554_FLASH_DEFAULT_BRIGHTNESS \
 110        LM3554_VALUE_TO_PERCENT(13, LM3554_FLASH_STEP)
 111
 112/* Torch brightness, input is percentage, output is [0..7] */
 113#define LM3554_TORCH_STEP                    1250
 114#define LM3554_TORCH_DEFAULT_BRIGHTNESS \
 115        LM3554_VALUE_TO_PERCENT(2, LM3554_TORCH_STEP)
 116
 117/* Indicator brightness, input is percentage, output is [0..3] */
 118#define LM3554_INDICATOR_STEP                2500
 119#define LM3554_INDICATOR_DEFAULT_BRIGHTNESS \
 120        LM3554_VALUE_TO_PERCENT(1, LM3554_INDICATOR_STEP)
 121
 122/*
 123 * lm3554_platform_data - Flash controller platform data
 124 */
 125struct lm3554_platform_data {
 126        int gpio_torch;
 127        int gpio_strobe;
 128        int gpio_reset;
 129
 130        unsigned int current_limit;
 131        unsigned int envm_tx2;
 132        unsigned int tx2_polarity;
 133};
 134
 135#endif /* _LM3554_H_ */
 136
 137