Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 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 | |
| 20 | #include <linux/kernel.h> |
Krzysztof Hałasa | ae69b22 | 2011-02-11 13:36:27 +0100 | [diff] [blame] | 21 | #include "solo6x10.h" |
| 22 | #include "osd-font.h" |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 23 | |
facugaich | afabbe6 | 2010-11-10 10:39:33 -0300 | [diff] [blame] | 24 | #define CAPTURE_MAX_BANDWIDTH 32 /* D1 4channel (D1 == 4) */ |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 25 | #define OSG_BUFFER_SIZE 1024 |
| 26 | |
| 27 | #define VI_PROG_HSIZE (1280 - 16) |
| 28 | #define VI_PROG_VSIZE (1024 - 16) |
| 29 | |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 30 | static void solo_capture_config(struct solo_dev *solo_dev) |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 31 | { |
| 32 | int i, j; |
| 33 | unsigned long height; |
| 34 | unsigned long width; |
| 35 | unsigned char *buf; |
| 36 | |
| 37 | solo_reg_write(solo_dev, SOLO_CAP_BASE, |
| 38 | SOLO_CAP_MAX_PAGE(SOLO_CAP_EXT_MAX_PAGE * |
| 39 | solo_dev->nr_chans) | |
| 40 | SOLO_CAP_BASE_ADDR(SOLO_CAP_EXT_ADDR(solo_dev) >> 16)); |
| 41 | solo_reg_write(solo_dev, SOLO_CAP_BTW, |
| 42 | (1 << 17) | SOLO_CAP_PROG_BANDWIDTH(2) | |
| 43 | SOLO_CAP_MAX_BANDWIDTH(CAPTURE_MAX_BANDWIDTH)); |
| 44 | |
| 45 | /* Set scale 1, 9 dimension */ |
| 46 | width = solo_dev->video_hsize; |
| 47 | height = solo_dev->video_vsize; |
| 48 | solo_reg_write(solo_dev, SOLO_DIM_SCALE1, |
| 49 | SOLO_DIM_H_MB_NUM(width / 16) | |
| 50 | SOLO_DIM_V_MB_NUM_FRAME(height / 8) | |
| 51 | SOLO_DIM_V_MB_NUM_FIELD(height / 16)); |
| 52 | |
| 53 | /* Set scale 2, 10 dimension */ |
| 54 | width = solo_dev->video_hsize / 2; |
| 55 | height = solo_dev->video_vsize; |
| 56 | solo_reg_write(solo_dev, SOLO_DIM_SCALE2, |
| 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 | |
| 61 | /* Set scale 3, 11 dimension */ |
| 62 | width = solo_dev->video_hsize / 2; |
| 63 | height = solo_dev->video_vsize / 2; |
| 64 | solo_reg_write(solo_dev, SOLO_DIM_SCALE3, |
| 65 | SOLO_DIM_H_MB_NUM(width / 16) | |
| 66 | SOLO_DIM_V_MB_NUM_FRAME(height / 8) | |
| 67 | SOLO_DIM_V_MB_NUM_FIELD(height / 16)); |
| 68 | |
| 69 | /* Set scale 4, 12 dimension */ |
| 70 | width = solo_dev->video_hsize / 3; |
| 71 | height = solo_dev->video_vsize / 3; |
| 72 | solo_reg_write(solo_dev, SOLO_DIM_SCALE4, |
| 73 | SOLO_DIM_H_MB_NUM(width / 16) | |
| 74 | SOLO_DIM_V_MB_NUM_FRAME(height / 8) | |
| 75 | SOLO_DIM_V_MB_NUM_FIELD(height / 16)); |
| 76 | |
| 77 | /* Set scale 5, 13 dimension */ |
| 78 | width = solo_dev->video_hsize / 4; |
| 79 | height = solo_dev->video_vsize / 2; |
| 80 | solo_reg_write(solo_dev, SOLO_DIM_SCALE5, |
| 81 | SOLO_DIM_H_MB_NUM(width / 16) | |
| 82 | SOLO_DIM_V_MB_NUM_FRAME(height / 8) | |
| 83 | SOLO_DIM_V_MB_NUM_FIELD(height / 16)); |
| 84 | |
| 85 | /* Progressive */ |
| 86 | width = VI_PROG_HSIZE; |
| 87 | height = VI_PROG_VSIZE; |
| 88 | solo_reg_write(solo_dev, SOLO_DIM_PROG, |
| 89 | SOLO_DIM_H_MB_NUM(width / 16) | |
| 90 | SOLO_DIM_V_MB_NUM_FRAME(height / 16) | |
| 91 | SOLO_DIM_V_MB_NUM_FIELD(height / 16)); |
| 92 | |
| 93 | /* Clear OSD */ |
| 94 | solo_reg_write(solo_dev, SOLO_VE_OSD_CH, 0); |
Krzysztof Hałasa | 43d1136 | 2011-02-11 13:33:26 +0100 | [diff] [blame] | 95 | solo_reg_write(solo_dev, SOLO_VE_OSD_BASE, SOLO_EOSD_EXT_ADDR >> 16); |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 96 | solo_reg_write(solo_dev, SOLO_VE_OSD_CLR, |
| 97 | 0xF0 << 16 | 0x80 << 8 | 0x80); |
| 98 | solo_reg_write(solo_dev, SOLO_VE_OSD_OPT, 0); |
| 99 | |
| 100 | /* Clear OSG buffer */ |
| 101 | buf = kzalloc(OSG_BUFFER_SIZE, GFP_KERNEL); |
| 102 | if (!buf) |
| 103 | return; |
| 104 | |
| 105 | for (i = 0; i < solo_dev->nr_chans; i++) { |
| 106 | for (j = 0; j < SOLO_EOSD_EXT_SIZE; j += OSG_BUFFER_SIZE) { |
| 107 | solo_p2m_dma(solo_dev, SOLO_P2M_DMA_ID_MP4E, 1, buf, |
Krzysztof Hałasa | 43d1136 | 2011-02-11 13:33:26 +0100 | [diff] [blame] | 108 | SOLO_EOSD_EXT_ADDR + |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 109 | (i * SOLO_EOSD_EXT_SIZE) + j, |
| 110 | OSG_BUFFER_SIZE); |
| 111 | } |
| 112 | } |
| 113 | kfree(buf); |
| 114 | } |
| 115 | |
| 116 | int solo_osd_print(struct solo_enc_dev *solo_enc) |
| 117 | { |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 118 | struct solo_dev *solo_dev = solo_enc->solo_dev; |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 119 | char *str = solo_enc->osd_text; |
| 120 | u8 *buf; |
| 121 | u32 reg = solo_reg_read(solo_dev, SOLO_VE_OSD_CH); |
| 122 | int len = strlen(str); |
| 123 | int i, j; |
| 124 | int x = 1, y = 1; |
| 125 | |
| 126 | if (len == 0) { |
| 127 | reg &= ~(1 << solo_enc->ch); |
| 128 | solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg); |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | buf = kzalloc(SOLO_EOSD_EXT_SIZE, GFP_KERNEL); |
| 133 | if (!buf) |
| 134 | return -ENOMEM; |
| 135 | |
| 136 | for (i = 0; i < len; i++) { |
| 137 | for (j = 0; j < 16; j++) { |
| 138 | buf[(j*2) + (i%2) + ((x + (i/2)) * 32) + (y * 2048)] = |
| 139 | (solo_osd_font[(str[i] * 4) + (j / 4)] |
| 140 | >> ((3 - (j % 4)) * 8)) & 0xff; |
| 141 | } |
| 142 | } |
| 143 | |
Krzysztof Hałasa | 43d1136 | 2011-02-11 13:33:26 +0100 | [diff] [blame] | 144 | solo_p2m_dma(solo_dev, 0, 1, buf, SOLO_EOSD_EXT_ADDR + |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 145 | (solo_enc->ch * SOLO_EOSD_EXT_SIZE), SOLO_EOSD_EXT_SIZE); |
Ben Collins | 98e2d5a | 2010-11-04 22:37:15 -0400 | [diff] [blame] | 146 | reg |= (1 << solo_enc->ch); |
| 147 | solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg); |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 148 | |
| 149 | kfree(buf); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 154 | static void solo_jpeg_config(struct solo_dev *solo_dev) |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 155 | { |
Krzysztof Hałasa | 908113d | 2011-02-11 13:32:11 +0100 | [diff] [blame] | 156 | u32 reg; |
| 157 | if (solo_dev->flags & FLAGS_6110) |
| 158 | reg = (4 << 24) | (3 << 16) | (2 << 8) | (1 << 0); |
| 159 | else |
| 160 | reg = (2 << 24) | (2 << 16) | (2 << 8) | (2 << 0); |
| 161 | solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_TBL, reg); |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 162 | solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_L, 0); |
| 163 | solo_reg_write(solo_dev, SOLO_VE_JPEG_QP_CH_H, 0); |
| 164 | solo_reg_write(solo_dev, SOLO_VE_JPEG_CFG, |
| 165 | (SOLO_JPEG_EXT_SIZE(solo_dev) & 0xffff0000) | |
| 166 | ((SOLO_JPEG_EXT_ADDR(solo_dev) >> 16) & 0x0000ffff)); |
| 167 | solo_reg_write(solo_dev, SOLO_VE_JPEG_CTRL, 0xffffffff); |
Krzysztof Hałasa | 908113d | 2011-02-11 13:32:11 +0100 | [diff] [blame] | 168 | /* que limit, samp limit, pos limit */ |
| 169 | solo_reg_write(solo_dev, 0x0688, (0 << 16) | (30 << 8) | 60); |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 172 | static void solo_mp4e_config(struct solo_dev *solo_dev) |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 173 | { |
| 174 | int i; |
Krzysztof Hałasa | 908113d | 2011-02-11 13:32:11 +0100 | [diff] [blame] | 175 | u32 reg; |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 176 | |
| 177 | /* We can only use VE_INTR_CTRL(0) if we want to support mjpeg */ |
| 178 | solo_reg_write(solo_dev, SOLO_VE_CFG0, |
| 179 | SOLO_VE_INTR_CTRL(0) | |
| 180 | SOLO_VE_BLOCK_SIZE(SOLO_MP4E_EXT_SIZE(solo_dev) >> 16) | |
| 181 | SOLO_VE_BLOCK_BASE(SOLO_MP4E_EXT_ADDR(solo_dev) >> 16)); |
| 182 | |
| 183 | solo_reg_write(solo_dev, SOLO_VE_CFG1, |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 184 | SOLO_VE_INSERT_INDEX | SOLO_VE_MOTION_MODE(0)); |
| 185 | |
| 186 | solo_reg_write(solo_dev, SOLO_VE_WMRK_POLY, 0); |
| 187 | solo_reg_write(solo_dev, SOLO_VE_VMRK_INIT_KEY, 0); |
| 188 | solo_reg_write(solo_dev, SOLO_VE_WMRK_STRL, 0); |
| 189 | solo_reg_write(solo_dev, SOLO_VE_ENCRYP_POLY, 0); |
| 190 | solo_reg_write(solo_dev, SOLO_VE_ENCRYP_INIT, 0); |
| 191 | |
Krzysztof Hałasa | 908113d | 2011-02-11 13:32:11 +0100 | [diff] [blame] | 192 | reg = SOLO_VE_LITTLE_ENDIAN | SOLO_COMP_ATTR_FCODE(1) | |
| 193 | SOLO_COMP_TIME_INC(0) | SOLO_COMP_TIME_WIDTH(15); |
| 194 | if (solo_dev->flags & FLAGS_6110) |
| 195 | reg |= SOLO_DCT_INTERVAL(10); |
| 196 | else |
| 197 | reg |= SOLO_DCT_INTERVAL(36 / 4); |
| 198 | solo_reg_write(solo_dev, SOLO_VE_ATTR, reg); |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 199 | |
| 200 | for (i = 0; i < solo_dev->nr_chans; i++) |
| 201 | solo_reg_write(solo_dev, SOLO_VE_CH_REF_BASE(i), |
| 202 | (SOLO_EREF_EXT_ADDR(solo_dev) + |
| 203 | (i * SOLO_EREF_EXT_SIZE)) >> 16); |
Krzysztof Hałasa | 908113d | 2011-02-11 13:32:11 +0100 | [diff] [blame] | 204 | |
| 205 | if (solo_dev->flags & FLAGS_6110) |
| 206 | solo_reg_write(solo_dev, 0x0634, 0x00040008); /* ? */ |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 209 | int solo_enc_init(struct solo_dev *solo_dev) |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 210 | { |
| 211 | int i; |
| 212 | |
| 213 | solo_capture_config(solo_dev); |
| 214 | solo_mp4e_config(solo_dev); |
| 215 | solo_jpeg_config(solo_dev); |
| 216 | |
| 217 | for (i = 0; i < solo_dev->nr_chans; i++) { |
| 218 | solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(i), 0); |
| 219 | solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0); |
| 220 | } |
| 221 | |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 222 | solo_irq_on(solo_dev, SOLO_IRQ_ENCODER); |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 227 | void solo_enc_exit(struct solo_dev *solo_dev) |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 228 | { |
| 229 | int i; |
| 230 | |
Krzysztof Hałasa | decebab | 2011-02-11 13:38:20 +0100 | [diff] [blame] | 231 | solo_irq_off(solo_dev, SOLO_IRQ_ENCODER); |
Ben Collins | faa4fd2 | 2010-06-17 13:27:26 -0400 | [diff] [blame] | 232 | |
| 233 | for (i = 0; i < solo_dev->nr_chans; i++) { |
| 234 | solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(i), 0); |
| 235 | solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(i), 0); |
| 236 | } |
| 237 | } |