amcm.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Color Management
  3. *
  4. * Author: Lin Xu <lin.xu@amlogic.com>
  5. * Bobby Yang <bo.yang@amlogic.com>
  6. *
  7. * Copyright (C) 2010 Amlogic Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <mach/am_regs.h>
  14. #include "linux/amports/vframe.h"
  15. #include "linux/amports/cm.h"
  16. #include "cm_regs.h"
  17. #include "amcm.h"
  18. #if 0
  19. struct cm_region_s cm_region;
  20. struct cm_top_s cm_top;
  21. struct cm_demo_s cm_demo;
  22. #endif
  23. static inline ulong read_cm_reg_bits(ulong reg, ulong bit, ulong wid)
  24. {
  25. WRITE_CBUS_REG(VPP_CHROMA_ADDR_PORT, reg);
  26. return((READ_CBUS_REG(VPP_CHROMA_DATA_PORT) >> bit) & ((1 << wid) - 1));
  27. }
  28. static inline void write_cm_reg_bits(ulong reg, ulong val, ulong bit, ulong wid)
  29. {
  30. ulong mask = (1 << wid) - 1;
  31. ulong data = read_cm_reg_bits(reg, 0, 31);
  32. if (val > mask) {
  33. val = mask;
  34. }
  35. data &= ~(mask << bit);
  36. data |= (val << bit);
  37. WRITE_CBUS_REG(VPP_CHROMA_ADDR_PORT, reg);
  38. WRITE_CBUS_REG(VPP_CHROMA_DATA_PORT, val);
  39. }
  40. // ***************************************************************************
  41. // *** IOCTL-oriented functions *********************************************
  42. // ***************************************************************************
  43. void cm_set_region(struct cm_region_s *p)
  44. {
  45. ulong reg_off = (p->region_idx) * 6;
  46. ulong hue_shf_ran_inv = ((1 << 20) / (p->hue_shf_ran) + 1) >> 1;
  47. write_cm_reg_bits(HUE_HUE_RANGE_REG00 + reg_off, p->sym_en , SYM_EN_BIT , SYM_EN_WID);
  48. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->sat_en , SAT_EN_BIT , SAT_EN_WID);
  49. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->sat_central_en , SAT_CENTRAL_EN_BIT , SAT_CENTRAL_EN_WID);
  50. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->sat_shape , SAT_SHAPE_BIT , SAT_SHAPE_WID);
  51. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->sat_gain , SAT_GAIN_BIT , SAT_GAIN_WID);
  52. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->sat_inc , SAT_INC_BIT , SAT_INC_WID);
  53. write_cm_reg_bits(SAT_SAT_RANGE_REG00 + reg_off, p->sat_lum_h_slope, SAT_LUM_H_SLOPE_BIT, SAT_LUM_H_SLOPE_WID);
  54. write_cm_reg_bits(SAT_SAT_RANGE_REG00 + reg_off, p->sat_lum_l_slope, SAT_LUM_L_SLOPE_BIT, SAT_LUM_L_SLOPE_WID);
  55. write_cm_reg_bits(HUE_SAT_RANGE_REG00 + reg_off, p->sat_lum_h , SAT_LUM_H_BIT , SAT_LUM_H_WID);
  56. write_cm_reg_bits(HUE_LUM_RANGE_REG00 + reg_off, p->sat_lum_l , SAT_LUM_L_BIT , SAT_LUM_L_WID);
  57. write_cm_reg_bits(SAT_SAT_RANGE_REG00 + reg_off, p->sat_sat_h_slope, SAT_SAT_H_SLOPE_BIT, SAT_SAT_H_SLOPE_WID);
  58. write_cm_reg_bits(SAT_SAT_RANGE_REG00 + reg_off, p->sat_sat_l_slope, SAT_SAT_L_SLOPE_BIT, SAT_SAT_L_SLOPE_WID);
  59. write_cm_reg_bits(SAT_SAT_RANGE_REG00 + reg_off, p->sat_sat_h , SAT_SAT_H_BIT , SAT_SAT_H_WID);
  60. write_cm_reg_bits(SAT_SAT_RANGE_REG00 + reg_off, p->sat_sat_l , SAT_SAT_L_BIT , SAT_SAT_L_WID);
  61. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->hue_en , HUE_EN_BIT , HUE_EN_WID);
  62. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->hue_central_en , HUE_CENTRAL_EN_BIT , HUE_CENTRAL_EN_WID);
  63. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->hue_shape , HUE_SHAPE_BIT , HUE_SHAPE_WID);
  64. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->hue_gain , HUE_GAIN_BIT , HUE_GAIN_WID);
  65. write_cm_reg_bits(CHROMA_GAIN_REG00 + reg_off, p->hue_clockwise , HUE_CLOCKWISE_BIT , HUE_CLOCKWISE_WID);
  66. write_cm_reg_bits(HUE_HUE_RANGE_REG00 + reg_off, p->hue_shf_ran , HUE_SHF_RAN_BIT , HUE_SHF_RAN_WID);
  67. write_cm_reg_bits(HUE_RANGE_INV_REG00 + reg_off, hue_shf_ran_inv , HUE_SHF_RAN_INV_BIT, HUE_SHF_RAN_INV_WID);
  68. write_cm_reg_bits(HUE_HUE_RANGE_REG00 + reg_off, p->hue_shf_sta , HUE_SHF_STA_BIT , HUE_SHF_STA_WID);
  69. write_cm_reg_bits(HUE_LUM_RANGE_REG00 + reg_off, p->hue_lum_h_slope, HUE_LUM_H_SLOPE_BIT, HUE_LUM_H_SLOPE_WID);
  70. write_cm_reg_bits(HUE_LUM_RANGE_REG00 + reg_off, p->hue_lum_l_slope, HUE_LUM_L_SLOPE_BIT, HUE_LUM_L_SLOPE_WID);
  71. write_cm_reg_bits(HUE_LUM_RANGE_REG00 + reg_off, p->hue_lum_h , HUE_LUM_H_BIT , HUE_LUM_H_WID);
  72. write_cm_reg_bits(HUE_LUM_RANGE_REG00 + reg_off, p->hue_lum_l , HUE_LUM_L_BIT , HUE_LUM_L_WID);
  73. write_cm_reg_bits(HUE_SAT_RANGE_REG00 + reg_off, p->hue_sat_h_slope, HUE_SAT_H_SLOPE_BIT, HUE_SAT_H_SLOPE_WID);
  74. write_cm_reg_bits(HUE_SAT_RANGE_REG00 + reg_off, p->hue_sat_l_slope, HUE_SAT_L_SLOPE_BIT, HUE_SAT_L_SLOPE_WID);
  75. write_cm_reg_bits(HUE_SAT_RANGE_REG00 + reg_off, p->hue_sat_h , HUE_SAT_H_BIT , HUE_SAT_H_WID);
  76. write_cm_reg_bits(HUE_SAT_RANGE_REG00 + reg_off, p->hue_sat_l , HUE_SAT_L_BIT , HUE_SAT_L_WID);
  77. }
  78. void cm_set_top(struct cm_top_s *p)
  79. {
  80. write_cm_reg_bits(REG_CHROMA_CONTROL, p->chroma_en , CHROMA_EN_BIT , CHROMA_EN_WID);
  81. write_cm_reg_bits(REG_CHROMA_CONTROL, p->sat_sel , SAT_SEL_BIT , SAT_SEL_WID);
  82. write_cm_reg_bits(REG_CHROMA_CONTROL, p->uv_adj_en , UV_ADJ_EN_BIT , UV_ADJ_EN_WID);
  83. write_cm_reg_bits(REG_CHROMA_CONTROL, p->rgb_to_hue_en, RGB_TO_HUE_EN_BIT, RGB_TO_HUE_EN_WID);
  84. write_cm_reg_bits(REG_CHROMA_CONTROL, p->csc_sel , CSC_SEL_BIT , CSC_SEL_WID);
  85. }
  86. void cm_set_demo(struct cm_demo_s *p)
  87. {
  88. write_cm_reg_bits(REG_CHROMA_CONTROL, p->en , DEMO_EN_BIT , DEMO_EN_WID);
  89. write_cm_reg_bits(REG_CHROMA_CONTROL, p->pos , CM_DEMO_POS_BIT , CM_DEMO_POS_WID);
  90. write_cm_reg_bits(REG_CHROMA_CONTROL, p->hlight_adj, DEMO_HLIGHT_ADJ_BIT, DEMO_HLIGHT_ADJ_WID);
  91. write_cm_reg_bits(REG_CHROMA_CONTROL, p->wid , CM_DEMO_WID_BIT , CM_DEMO_WID_WID);
  92. }
  93. void cm_set_regs(struct cm_regs_s *p)
  94. {
  95. if (!(p->mode)) { // read
  96. switch (p->port) {
  97. case 0: // reserved
  98. break;
  99. case 1: // CM port registers
  100. p->val = read_cm_reg_bits(p->reg, p->bit, p->wid);
  101. break;
  102. case 2: // reserved
  103. break;
  104. case 3: // reserved
  105. break;
  106. default: // NA
  107. break;
  108. }
  109. } else { // write
  110. switch (p->port) {
  111. case 0: // reserved
  112. break;
  113. case 1: // CM port registers
  114. write_cm_reg_bits(p->reg, p->val, p->bit, p->wid);
  115. break;
  116. case 2: // reserved
  117. break;
  118. case 3: // reserved
  119. break;
  120. default: // NA
  121. break;
  122. }
  123. }
  124. }