isp_wdr.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program;
  43. *
  44. *****************************************************************************
  45. *
  46. * Note: This software is released under dual MIT and GPL licenses. A
  47. * recipient may use this file under the terms of either the MIT license or
  48. * GPL License. If you wish to use only one license not the other, you can
  49. * indicate your decision by deleting one of the above license notices in your
  50. * version of this file.
  51. *
  52. *****************************************************************************/
  53. #include "isp_wdr.h"
  54. #include "mrv_all_bits.h"
  55. #include "isp_ioctl.h"
  56. #include "isp_types.h"
  57. #include "ic_dev.h"
  58. extern MrvAllRegister_t *all_regs;
  59. int isp_s_wdr(struct isp_ic_dev *dev)
  60. {
  61. isp_wdr_context_t* wdr = &dev->wdr;
  62. pr_info(" enter %s\n", __func__);
  63. /*update wdr configuration after frame end when isp enable*/
  64. if (!is_isp_enable(dev) || wdr->changed) {
  65. uint32_t isp_wdr_offset, isp_wdr_ctrl;
  66. isp_wdr_offset = isp_read_reg(dev, REG_ADDR(isp_wdr_offset));
  67. REG_SET_SLICE( isp_wdr_offset, MRV_WDR_LUM_OFFSET, wdr->LumOffset );
  68. REG_SET_SLICE( isp_wdr_offset, MRV_WDR_RGB_OFFSET, wdr->RgbOffset );
  69. isp_write_reg(dev, REG_ADDR(isp_wdr_offset), isp_wdr_offset);
  70. isp_wdr_ctrl = isp_read_reg(dev, REG_ADDR(isp_wdr_ctrl));
  71. REG_SET_SLICE(isp_wdr_ctrl, MRV_WDR_ENABLE, wdr->enabled);
  72. isp_write_reg(dev, REG_ADDR(isp_wdr_ctrl), isp_wdr_ctrl);
  73. wdr->changed = false;
  74. } else {
  75. wdr->changed = true;
  76. }
  77. pr_info(" %s wdr.changed %d \n", __func__, wdr->changed);
  78. return 0;
  79. }
  80. int isp_s_wdr_curve(struct isp_ic_dev *dev)
  81. {
  82. isp_wdr_context_t* wdr = &dev->wdr;
  83. int i, j;
  84. uint32_t dYi = 0U;
  85. for ( i=0; i<4; i++ )
  86. {
  87. for ( j=8; j>0; j-- )
  88. {
  89. dYi <<= 4;
  90. dYi += wdr->dY[ (i*8 + j) ];
  91. }
  92. if (i == 0)
  93. {
  94. isp_write_reg(dev, REG_ADDR(isp_wdr_tonecurve_1), dYi);
  95. }
  96. else if (i == 1)
  97. {
  98. isp_write_reg(dev, REG_ADDR(isp_wdr_tonecurve_2), dYi);
  99. }
  100. else if (i == 2)
  101. {
  102. isp_write_reg(dev, REG_ADDR(isp_wdr_tonecurve_3), dYi);
  103. }
  104. else /* if (i == 3) */
  105. {
  106. isp_write_reg(dev, REG_ADDR(isp_wdr_tonecurve_4), dYi);
  107. }
  108. }
  109. for ( i=0; i<33; i++ )
  110. {
  111. isp_write_reg(dev, REG_ADDR(wdr_tone_mapping_curve_y_block_arr[i]), wdr->Ym[i]);
  112. }
  113. dYi = 0x00000000;
  114. isp_write_reg(dev, REG_ADDR(isp_wdr_offset), dYi);
  115. isp_write_reg(dev, REG_ADDR(isp_wdr_deltamin), 0x00100000);
  116. return 0;
  117. }