linux/drivers/staging/media/atomisp/pci/sh_css_frac.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * Support for Intel Camera Imaging ISP subsystem.
   4 * Copyright (c) 2015, Intel Corporation.
   5 *
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms and conditions of the GNU General Public License,
   8 * version 2, as published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope it will be useful, but WITHOUT
  11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  13 * more details.
  14 */
  15
  16#ifndef __SH_CSS_FRAC_H
  17#define __SH_CSS_FRAC_H
  18
  19#include <math_support.h>
  20
  21#define sISP_REG_BIT                  ISP_VEC_ELEMBITS
  22#define uISP_REG_BIT                  ((unsigned int)(sISP_REG_BIT - 1))
  23#define sSHIFT                              (16 - sISP_REG_BIT)
  24#define uSHIFT                              ((unsigned int)(16 - uISP_REG_BIT))
  25#define sFRACTION_BITS_FITTING(a) (a - sSHIFT)
  26#define uFRACTION_BITS_FITTING(a) ((unsigned int)(a - uSHIFT))
  27#define sISP_VAL_MIN                  (-(1 << uISP_REG_BIT))
  28#define sISP_VAL_MAX                  ((1 << uISP_REG_BIT) - 1)
  29#define uISP_VAL_MIN                  (0U)
  30#define uISP_VAL_MAX                  ((unsigned int)((1 << uISP_REG_BIT) - 1))
  31
  32/* a:fraction bits for 16bit precision, b:fraction bits for ISP precision */
  33#define sDIGIT_FITTING(v, a, b) \
  34        min_t(int, max_t(int, (((v) >> sSHIFT) >> max(sFRACTION_BITS_FITTING(a) - (b), 0)), \
  35          sISP_VAL_MIN), sISP_VAL_MAX)
  36#define uDIGIT_FITTING(v, a, b) \
  37        min((unsigned int)max((unsigned)(((v) >> uSHIFT) \
  38        >> max((int)(uFRACTION_BITS_FITTING(a) - (b)), 0)), \
  39          uISP_VAL_MIN), uISP_VAL_MAX)
  40
  41#endif /* __SH_CSS_FRAC_H */
  42