enc.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
  3. * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include <linux/kernel.h>
  20. #include "solo6x10.h"
  21. #include "osd-font.h"
  22. #define CAPTURE_MAX_BANDWIDTH 32 /* D1 4channel (D1 == 4) */
  23. #define OSG_BUFFER_SIZE 1024
  24. #define VI_PROG_HSIZE (1280 - 16)
  25. #define VI_PROG_VSIZE (1024 - 16)
  26. static void solo_capture_config(struct solo_dev *solo_dev)
  27. {
  28. int i, j;
  29. unsigned long height;
  30. unsigned long width;
  31. unsigned char *buf;
  32. solo_reg_write(solo_dev, SOLO_CAP_BASE,
  33. SOLO_CAP_MAX_PAGE(SOLO_CAP_EXT_MAX_PAGE *
  34. solo_dev->nr_chans) |
  35. SOLO_CAP_BASE_ADDR(SOLO_CAP_EXT_ADDR(solo_dev) >> 16));
  36. solo_reg_write(solo_dev, SOLO_CAP_BTW,
  37. (1 << 17) | SOLO_CAP_PROG_BANDWIDTH(2) |
  38. SOLO_CAP_MAX_BANDWIDTH(CAPTURE_MAX_BANDWIDTH));
  39. /* Set scale 1, 9 dimension */
  40. width = solo_dev->video_hsize;
  41. height = solo_dev->video_vsize;
  42. solo_reg_write(solo_dev, SOLO_DIM_SCALE1,
  43. SOLO_DIM_H_MB_NUM(width / 16) |
  44. SOLO_DIM_V_MB_NUM_FRAME(height / 8) |
  45. SOLO_DIM_V_MB_NUM_FIELD(height / 16));
  46. /* Set scale 2, 10 dimension */
  47. width = solo_dev->video_hsize / 2;
  48. height = solo_dev->video_vsize;
  49. solo_reg_write(solo_dev, SOLO_DIM_SCALE2,
  50. SOLO_DIM_H_MB_NUM(width / 16) |
  51. SOLO_DIM_V_MB_NUM_FRAME(height / 8) |
  52. SOLO_DIM_V_MB_NUM_FIELD(height / 16));
  53. /* Set scale 3, 11 dimension */
  54. width = solo_dev->video_hsize / 2;
  55. height = solo_dev->video_vsize / 2;
  56. solo_reg_write(solo_dev, SOLO_DIM_SCALE3,
  57. SOLO_DIM_H_MB_NUM(width / 16) |
  58. SOLO_DIM_V_MB_NUM_FRAME(height / 8) |
  59. SOLO_DIM_V_MB_NUM_FIELD(height / 16));
  60. /* Set scale 4, 12 dimension */
  61. width = solo_dev->video_hsize / 3;
  62. height = solo_dev->video_vsize / 3;
  63. solo_reg_write(solo_dev, SOLO_DIM_SCALE4,
  64. SOLO_DIM_H_MB_NUM(width / 16) |
  65. SOLO_DIM_V_MB_NUM_FRAME(height / 8) |
  66. SOLO_DIM_V_MB_NUM_FIELD(height / 16));
  67. /* Set scale 5, 13 dimension */
  68. width = solo_dev->video_hsize / 4;
  69. height = solo_dev->video_vsize / 2;
  70. solo_reg_write(solo_dev, SOLO_DIM_SCALE5,
  71. SOLO_DIM_H_MB_NUM(width / 16) |
  72. SOLO_DIM_V_MB_NUM_FRAME(height / 8) |
  73. SOLO_DIM_V_MB_NUM_FIELD(height / 16));
  74. /* Progressive */
  75. width = VI_PROG_HSIZE;
  76. height = VI_PROG_VSIZE;
  77. solo_reg_write(solo_dev, SOLO_DIM_PROG,
  78. SOLO_DIM_H_MB_NUM(width / 16) |
  79. SOLO_DIM_V_MB_NUM_FRAME(height / 16) |
  80. SOLO_DIM_V_MB_NUM_FIELD(height / 16));
  81. /* Clear OSD */
  82. solo_reg_write(solo_dev, SOLO_VE_OSD_CH, 0);
  83. solo_reg_write(solo_dev, SOLO_VE_OSD_BASE, SOLO_EOSD_EXT_ADDR >> 16);
  84. solo_reg_write(solo_dev, SOLO_VE_OSD_CLR,
  85. 0xF0 << 16 | 0x80 << 8 | 0x80);
  86. solo_reg_write(solo_dev, SOLO_VE_OSD_OPT, 0);
  87. /* Clear OSG buffer */
  88. buf = kzalloc(OSG_BUFFER_SIZE, GFP_KERNEL);
  89. if (!buf)
  90. return;
  91. for (i = 0; i < solo_dev->nr_chans; i++) {
  92. for (j = 0; j < SOLO_EOSD_EXT_SIZE; j += OSG_BUFFER_SIZE) {
  93. solo_p2m_dma(solo_dev, SOLO_P2M_DMA_ID_MP4E, 1, buf,
  94. SOLO_EOSD_EXT_ADDR +
  95. (i * SOLO_EOSD_EXT_SIZE) + j,
  96. OSG_BUFFER_SIZE);
  97. }
  98. }
  99. kfree(buf);
  100. }
  101. int solo_osd_print(struct solo_enc_dev *solo_enc)
  102. {
  103. struct solo_dev *solo_dev = solo_enc->solo_dev;
  104. char *str = solo_enc->osd_text;
  105. u8 *buf;
  106. u32 reg = solo_reg_read(solo_dev, SOLO_VE_OSD_CH);
  107. int len = strlen(str);
  108. int i, j;
  109. int x = 1, y = 1;
  110. if (len == 0) {
  111. reg &= ~(1 << solo_enc->ch);
  112. solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg);
  113. return 0;
  114. }
  115. buf = kzalloc(SOLO_EOSD_EXT_SIZE, GFP_KERNEL);
  116. if (!buf)
  117. return -ENOMEM;
  118. for (i = 0; i < len; i++) {
  119. for (j = 0; j < 16; j++) {
  120. buf[(j*2) + (i%2) + ((x + (i/2)) * 32) + (y * 2048)] =
  121. (solo_osd_font[(str[i] * 4) + (j / 4)]
  122. >> ((3 - (j % 4)) * 8)) & 0xff;
  123. }
  124. }
  125. solo_p2m_dma(solo_dev, 0, 1, buf, SOLO_EOSD_EXT_ADDR +
  126. (solo_enc->ch * SOLO_EOSD_EXT_SIZE), SOLO_EOSD_EXT_SIZE);
  127. reg |= (1 << solo_enc->ch);
  128. solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg);
  129. kfree(buf);
  130. return 0;
  131. }
  132. static void solo_jpeg_config(struct solo_dev *solo_dev)
  133. {
  134. u32 reg;
  135. if (solo_dev->flags & FLAGS_6110)
  136. reg = (4 << 24) | (3 << 16) | (2 << 8) | (1 << 0);
  137. else
  138. reg = (2 << 24) | (2 << 16) | (2 << 8) | (2 << 0);
  139. solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_TBL, reg);
  140. solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_L, 0);
  141. solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_H, 0);
  142. solo_reg_write(solo_dev, SOLO_VE_JPEG_CFG,
  143. (SOLO_JPEG_EXT_SIZE(solo_dev) & 0xffff0000) |
  144. ((SOLO_JPEG_EXT_ADDR(solo_dev) >> 16) & 0x0000ffff));
  145. solo_reg_write(solo_dev, SOLO_VE_JPEG_CTRL, 0xffffffff);
  146. /* que limit, samp limit, pos limit */
  147. solo_reg_write(solo_dev, 0x0688, (0 << 16) | (30 << 8) | 60);
  148. }
  149. static void solo_mp4e_config(struct solo_dev *solo_dev)
  150. {
  151. int i;
  152. u32 reg;
  153. /* We can only use VE_INTR_CTRL(0) if we want to support mjpeg */
  154. solo_reg_write(solo_dev, SOLO_VE_CFG0,
  155. SOLO_VE_INTR_CTRL(0) |
  156. SOLO_VE_BLOCK_SIZE(SOLO_MP4E_EXT_SIZE(solo_dev) >> 16) |
  157. SOLO_VE_BLOCK_BASE(SOLO_MP4E_EXT_ADDR(solo_dev) >> 16));
  158. solo_reg_write(solo_dev, SOLO_VE_CFG1,
  159. SOLO_VE_INSERT_INDEX | SOLO_VE_MOTION_MODE(0));
  160. solo_reg_write(solo_dev, SOLO_VE_WMRK_POLY, 0);
  161. solo_reg_write(solo_dev, SOLO_VE_VMRK_INIT_KEY, 0);
  162. solo_reg_write(solo_dev, SOLO_VE_WMRK_STRL, 0);
  163. solo_reg_write(solo_dev, SOLO_VE_ENCRYP_POLY, 0);
  164. solo_reg_write(solo_dev, SOLO_VE_ENCRYP_INIT, 0);
  165. reg = SOLO_VE_LITTLE_ENDIAN | SOLO_COMP_ATTR_FCODE(1) |
  166. SOLO_COMP_TIME_INC(0) | SOLO_COMP_TIME_WIDTH(15);
  167. if (solo_dev->flags & FLAGS_6110)
  168. reg |= SOLO_DCT_INTERVAL(10);
  169. else
  170. reg |= SOLO_DCT_INTERVAL(36 / 4);
  171. solo_reg_write(solo_dev, SOLO_VE_ATTR, reg);
  172. for (i = 0; i < solo_dev->nr_chans; i++)
  173. solo_reg_write(solo_dev, SOLO_VE_CH_REF_BASE(i),
  174. (SOLO_EREF_EXT_ADDR(solo_dev) +
  175. (i * SOLO_EREF_EXT_SIZE)) >> 16);
  176. if (solo_dev->flags & FLAGS_6110)
  177. solo_reg_write(solo_dev, 0x0634, 0x00040008); /* ? */
  178. }
  179. int solo_enc_init(struct solo_dev *solo_dev)
  180. {
  181. int i;
  182. solo_capture_config(solo_dev);
  183. solo_mp4e_config(solo_dev);
  184. solo_jpeg_config(solo_dev);
  185. for (i = 0; i < solo_dev->nr_chans; i++) {
  186. solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(i), 0);
  187. solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0);
  188. }
  189. solo_irq_on(solo_dev, SOLO_IRQ_ENCODER);
  190. return 0;
  191. }
  192. void solo_enc_exit(struct solo_dev *solo_dev)
  193. {
  194. int i;
  195. solo_irq_off(solo_dev, SOLO_IRQ_ENCODER);
  196. for (i = 0; i < solo_dev->nr_chans; i++) {
  197. solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(i), 0);
  198. solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0);
  199. }
  200. }