isp_rgbgamma.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #ifdef __KERNEL__
  54. #include <linux/io.h>
  55. #include <linux/module.h>
  56. #else
  57. #endif
  58. #include "mrv_all_bits.h"
  59. #include "isp_ioctl.h"
  60. #include "isp_types.h"
  61. extern MrvAllRegister_t *all_regs;
  62. int isp_enable_rgbgamma(struct isp_ic_dev *dev)
  63. {
  64. #ifndef ISP_RGBGC_RY
  65. pr_err("unsupported function %s\n", __func__);
  66. return -1;
  67. #else
  68. if (dev->rgbgamma.changed) {
  69. u32 isp_ctrl = isp_read_reg(dev, REG_ADDR(isp_ctrl));
  70. REG_SET_SLICE(isp_ctrl, ISP_RGBGC_ENABLE, 1);
  71. isp_write_reg(dev, REG_ADDR(isp_ctrl), isp_ctrl);
  72. dev->rgbgamma.changed = false;
  73. } else {
  74. dev->rgbgamma.changed = true;
  75. }
  76. dev->rgbgamma.enable = true;
  77. return 0;
  78. #endif
  79. }
  80. int isp_disable_rgbgamma(struct isp_ic_dev *dev)
  81. {
  82. #ifndef ISP_RGBGC_RY
  83. pr_err("unsupported function %s\n", __func__);
  84. return -1;
  85. #else
  86. if (dev->rgbgamma.changed) {
  87. u32 isp_ctrl = isp_read_reg(dev, REG_ADDR(isp_ctrl));
  88. REG_SET_SLICE(isp_ctrl, ISP_RGBGC_ENABLE, 0);
  89. isp_write_reg(dev, REG_ADDR(isp_ctrl), isp_ctrl);
  90. dev->rgbgamma.changed = false;
  91. } else {
  92. dev->rgbgamma.enable = true;
  93. }
  94. dev->rgbgamma.enable = false;
  95. return 0;
  96. #endif
  97. }
  98. #ifdef ISP_RGBGC_RY
  99. static int isp_s_rgbgammapx(struct isp_ic_dev *dev, struct isp_rgbgamma_data *data)
  100. {
  101. u32 isp_gc_px_reg = REG_ADDR(isp_gcrgb_r_px_0);
  102. u32 *p_table = NULL;
  103. int i;
  104. u32 gc_px_data = 0;
  105. p_table = (u32 *)&data->rgbgc_r_px;
  106. for (i = 0; i < 64; i++) {
  107. gc_px_data |= (*(p_table + i) << (i % 6 * 5));
  108. if (i % 6 == 5 || i == 63) {
  109. isp_write_reg(dev, isp_gc_px_reg, gc_px_data);
  110. isp_gc_px_reg += 4;
  111. gc_px_data = 0;
  112. }
  113. }
  114. isp_gc_px_reg = REG_ADDR(isp_gcrgb_g_px_0);
  115. p_table = (u32 *)&data->rgbgc_g_px;
  116. for (i = 0; i < 64; i++) {
  117. gc_px_data |= (*(p_table + i) << (i % 6 * 5));
  118. if (i % 6 == 5 || i == 63) {
  119. isp_write_reg(dev, isp_gc_px_reg, gc_px_data);
  120. isp_gc_px_reg += 4;
  121. gc_px_data = 0;
  122. }
  123. }
  124. isp_gc_px_reg = REG_ADDR(isp_gcrgb_b_px_0);
  125. p_table = (u32 *)&data->rgbgc_b_px;
  126. for (i = 0; i < 64; i++) {
  127. gc_px_data |= (*(p_table + i) << (i % 6 * 5));
  128. if (i % 6 == 5 || i == 63) {
  129. isp_write_reg(dev, isp_gc_px_reg, gc_px_data);
  130. isp_gc_px_reg += 4;
  131. gc_px_data = 0;
  132. }
  133. }
  134. return 0;
  135. }
  136. #endif
  137. #ifdef ISP_RGBGC_RY
  138. static int isp_s_rgbgammaWriteData(struct isp_ic_dev *dev,
  139. struct isp_rgbgamma_data *data)
  140. {
  141. u32 isp_gc_y_data, isp_gc_x_data;
  142. int i;
  143. u32 *tblX, *tblY;
  144. isp_write_reg(dev, REG_ADDR(isp_gcrgb_r_x_addr), 0);
  145. isp_write_reg(dev, REG_ADDR(isp_gcrgb_r_y_addr), 0);
  146. isp_write_reg(dev, REG_ADDR(isp_gcrgb_g_x_addr), 0);
  147. isp_write_reg(dev, REG_ADDR(isp_gcrgb_g_y_addr), 0);
  148. isp_write_reg(dev, REG_ADDR(isp_gcrgb_b_x_addr), 0);
  149. isp_write_reg(dev, REG_ADDR(isp_gcrgb_b_y_addr), 0);
  150. tblX = data->rgbgc_r_datax;
  151. tblY = data->rgbgc_r_datay;
  152. for (i = 0; i < 64; i++) {
  153. isp_gc_y_data = *(tblY + i);
  154. isp_write_reg(dev, REG_ADDR(isp_gcrgb_r_y_write_data),
  155. isp_gc_y_data);
  156. }
  157. for (i = 0; i < 63; i++) {
  158. isp_gc_x_data = *(tblX + i);
  159. isp_write_reg(dev, REG_ADDR(isp_gcrgb_r_x_write_data),
  160. isp_gc_x_data);
  161. }
  162. tblX = data->rgbgc_g_datax;
  163. tblY = data->rgbgc_g_datay;
  164. for (i = 0; i < 64; i++) {
  165. isp_gc_y_data = *(tblY + i);
  166. isp_write_reg(dev, REG_ADDR(isp_gcrgb_g_y_write_data),
  167. isp_gc_y_data);
  168. }
  169. for (i = 0; i < 63; i++) {
  170. isp_gc_x_data = *(tblX + i);
  171. isp_write_reg(dev, REG_ADDR(isp_gcrgb_g_x_write_data),
  172. isp_gc_x_data);
  173. }
  174. tblX = data->rgbgc_b_datax;
  175. tblY = data->rgbgc_b_datay;
  176. for (i = 0; i < 64; i++) {
  177. isp_gc_y_data = *(tblY + i);
  178. isp_write_reg(dev, REG_ADDR(isp_gcrgb_b_y_write_data),
  179. isp_gc_y_data);
  180. }
  181. for (i = 0; i < 63; i++) {
  182. isp_gc_x_data = *(tblX + i);
  183. isp_write_reg(dev, REG_ADDR(isp_gcrgb_b_x_write_data),
  184. isp_gc_x_data);
  185. }
  186. return 0;
  187. }
  188. #endif
  189. int isp_s_rgbgamma(struct isp_ic_dev *dev)
  190. {
  191. #ifndef ISP_RGBGC_RY
  192. pr_err("unsupported function %s", __func__);
  193. return -1;
  194. #else
  195. u8 ret;
  196. if (dev->rgbgamma.data_changed) {
  197. u32 isp_ctrl = isp_read_reg(dev, REG_ADDR(isp_ctrl));
  198. isp_s_rgbgammapx(dev, dev->rgbgamma.data);
  199. isp_s_rgbgammaWriteData(dev, dev->rgbgamma.data);
  200. ret = 0;
  201. if (dev->rgbgamma.enable) {
  202. ret = isp_enable_rgbgamma(dev);
  203. }
  204. dev->rgbgamma.data_changed = false;
  205. kfree(dev->rgbgamma.data);
  206. } else {
  207. dev->rgbgamma.data_changed = true;
  208. }
  209. return ret;
  210. #endif
  211. }