Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the NXP SAA7164 PCIe bridge |
| 3 | * |
Steven Toth | 9b8b019 | 2010-07-31 14:39:44 -0300 | [diff] [blame] | 4 | * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/wait.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 24 | |
| 25 | #include "saa7164.h" |
| 26 | |
Steven Toth | 0b62ceb | 2010-07-31 16:17:51 -0300 | [diff] [blame^] | 27 | int saa7164_api_collect_debug(struct saa7164_dev *dev) |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame] | 28 | { |
| 29 | tmComResDebugGetData_t d; |
| 30 | u8 more = 255; |
| 31 | int ret; |
| 32 | |
| 33 | dprintk(DBGLVL_API, "%s()\n", __func__); |
| 34 | |
| 35 | while (more--) { |
| 36 | |
| 37 | memset(&d, 0, sizeof(d)); |
| 38 | |
| 39 | ret = saa7164_cmd_send(dev, 0, GET_CUR, |
| 40 | GET_DEBUG_DATA_CONTROL, sizeof(d), &d); |
| 41 | if (ret != SAA_OK) { |
| 42 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 43 | } |
| 44 | |
| 45 | if (d.dwResult != SAA_OK) |
| 46 | break; |
| 47 | |
Steven Toth | 0b62ceb | 2010-07-31 16:17:51 -0300 | [diff] [blame^] | 48 | printk(KERN_INFO "saa7164[%d]-FWMSG: %s", dev->nr, d.ucDebugData); |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level) |
| 55 | { |
| 56 | tmComResDebugSetLevel_t lvl; |
| 57 | int ret; |
| 58 | |
| 59 | dprintk(DBGLVL_API, "%s(level=%d)\n", __func__, level); |
| 60 | |
| 61 | /* Retrieve current state */ |
| 62 | ret = saa7164_cmd_send(dev, 0, GET_CUR, |
| 63 | SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl); |
| 64 | if (ret != SAA_OK) { |
| 65 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 66 | } |
| 67 | dprintk(DBGLVL_API, "%s() Was %d\n", __func__, lvl.dwDebugLevel); |
| 68 | |
| 69 | lvl.dwDebugLevel = level; |
| 70 | |
| 71 | /* set new state */ |
| 72 | ret = saa7164_cmd_send(dev, 0, SET_CUR, |
| 73 | SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl); |
| 74 | if (ret != SAA_OK) { |
| 75 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 76 | } |
| 77 | |
| 78 | return ret; |
| 79 | } |
| 80 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 81 | int saa7164_api_set_vbi_format(struct saa7164_port *port) |
| 82 | { |
| 83 | struct saa7164_dev *dev = port->dev; |
| 84 | tmComResProbeCommit_t fmt, rsp; |
| 85 | int ret; |
| 86 | |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame] | 87 | dprintk(DBGLVL_API, "%s(nr=%d, unitid=0x%x)\n", __func__, |
| 88 | port->nr, port->hwcfg.unitid); |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 89 | |
| 90 | fmt.bmHint = 0; |
| 91 | fmt.bFormatIndex = 1; |
| 92 | fmt.bFrameIndex = 1; |
| 93 | |
| 94 | /* Probe, see if it can support this format */ |
| 95 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, |
| 96 | SET_CUR, SAA_PROBE_CONTROL, sizeof(fmt), &fmt); |
| 97 | if (ret != SAA_OK) |
| 98 | printk(KERN_ERR "%s() set error, ret = 0x%x\n", __func__, ret); |
| 99 | |
| 100 | /* See of the format change was successful */ |
| 101 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, |
| 102 | GET_CUR, SAA_PROBE_CONTROL, sizeof(rsp), &rsp); |
| 103 | if (ret != SAA_OK) { |
| 104 | printk(KERN_ERR "%s() get error, ret = 0x%x\n", __func__, ret); |
| 105 | } else { |
| 106 | /* Compare requested vs received, should be same */ |
| 107 | if (memcmp(&fmt, &rsp, sizeof(rsp)) == 0) { |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame] | 108 | dprintk(DBGLVL_API, "SET/PROBE Verified\n"); |
| 109 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 110 | /* Ask the device to select the negotiated format */ |
| 111 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, |
| 112 | SET_CUR, SAA_COMMIT_CONTROL, sizeof(fmt), &fmt); |
| 113 | if (ret != SAA_OK) |
| 114 | printk(KERN_ERR "%s() commit error, ret = 0x%x\n", |
| 115 | __func__, ret); |
| 116 | |
| 117 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, |
| 118 | GET_CUR, SAA_COMMIT_CONTROL, sizeof(rsp), &rsp); |
| 119 | if (ret != SAA_OK) |
| 120 | printk(KERN_ERR "%s() GET commit error, ret = 0x%x\n", |
| 121 | __func__, ret); |
| 122 | |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame] | 123 | if (memcmp(&fmt, &rsp, sizeof(rsp)) != 0) { |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 124 | printk(KERN_ERR "%s() memcmp error, ret = 0x%x\n", |
| 125 | __func__, ret); |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame] | 126 | } else |
| 127 | dprintk(DBGLVL_API, "SET/COMMIT Verified\n"); |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 128 | |
| 129 | dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint); |
| 130 | dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n", rsp.bFormatIndex); |
| 131 | dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n", rsp.bFrameIndex); |
| 132 | } else |
| 133 | printk(KERN_ERR "%s() compare failed\n", __func__); |
| 134 | } |
| 135 | |
| 136 | if (ret == SAA_OK) |
| 137 | dprintk(DBGLVL_API, "%s(nr=%d) Success\n", __func__, port->nr); |
| 138 | |
| 139 | return ret; |
| 140 | } |
| 141 | |
Steven Toth | eafea21 | 2010-07-31 14:48:45 -0300 | [diff] [blame] | 142 | int saa7164_api_set_gop_size(struct saa7164_port *port) |
| 143 | { |
| 144 | struct saa7164_dev *dev = port->dev; |
| 145 | tmComResEncVideoGopStructure_t gs; |
| 146 | int ret; |
| 147 | |
| 148 | dprintk(DBGLVL_ENC, "%s()\n", __func__); |
| 149 | |
Steven Toth | 3ed43cf | 2010-07-31 14:58:35 -0300 | [diff] [blame] | 150 | gs.ucRefFrameDist = port->encoder_params.refdist; |
Steven Toth | 5fa56cc | 2010-07-31 15:05:35 -0300 | [diff] [blame] | 151 | gs.ucGOPSize = port->encoder_params.gop_size; |
Steven Toth | eafea21 | 2010-07-31 14:48:45 -0300 | [diff] [blame] | 152 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, |
| 153 | EU_VIDEO_GOP_STRUCTURE_CONTROL, |
| 154 | sizeof(gs), &gs); |
| 155 | if (ret != SAA_OK) |
| 156 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 157 | |
| 158 | return ret; |
| 159 | } |
| 160 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 161 | int saa7164_api_set_encoder(struct saa7164_port *port) |
| 162 | { |
| 163 | struct saa7164_dev *dev = port->dev; |
| 164 | tmComResEncVideoBitRate_t vb; |
| 165 | tmComResEncAudioBitRate_t ab; |
| 166 | int ret; |
| 167 | |
Steven Toth | eafea21 | 2010-07-31 14:48:45 -0300 | [diff] [blame] | 168 | dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, |
| 169 | port->hwcfg.sourceid); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 170 | |
Steven Toth | f91d095 | 2010-07-31 15:03:31 -0300 | [diff] [blame] | 171 | if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS) |
| 172 | port->encoder_profile = EU_PROFILE_PS_DVD; |
| 173 | else |
| 174 | port->encoder_profile = EU_PROFILE_TS_HQ; |
| 175 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 176 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, |
| 177 | EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile); |
| 178 | if (ret != SAA_OK) |
| 179 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 180 | |
Steven Toth | f6eeece | 2010-07-31 15:28:18 -0300 | [diff] [blame] | 181 | /* Resolution */ |
| 182 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, |
| 183 | EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile); |
| 184 | if (ret != SAA_OK) |
| 185 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 186 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 187 | /* Establish video bitrates */ |
Steven Toth | 2600d71 | 2010-07-31 14:51:30 -0300 | [diff] [blame] | 188 | if (port->encoder_params.bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) |
| 189 | vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_CONSTANT; |
| 190 | else |
| 191 | vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 192 | vb.dwVideoBitRate = port->encoder_params.bitrate; |
Steven Toth | 968b11b | 2010-07-31 14:59:38 -0300 | [diff] [blame] | 193 | vb.dwVideoBitRatePeak = port->encoder_params.bitrate_peak; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 194 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, |
| 195 | EU_VIDEO_BIT_RATE_CONTROL, sizeof(tmComResEncVideoBitRate_t), &vb); |
| 196 | if (ret != SAA_OK) |
| 197 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 198 | |
| 199 | /* Establish audio bitrates */ |
| 200 | ab.ucAudioBitRateMode = 0; |
| 201 | ab.dwAudioBitRate = 384000; |
| 202 | ab.dwAudioBitRatePeak = ab.dwAudioBitRate; |
| 203 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, |
| 204 | EU_AUDIO_BIT_RATE_CONTROL, sizeof(tmComResEncAudioBitRate_t), &ab); |
| 205 | if (ret != SAA_OK) |
| 206 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 207 | |
| 208 | saa7164_api_set_aspect_ratio(port); |
Steven Toth | eafea21 | 2010-07-31 14:48:45 -0300 | [diff] [blame] | 209 | saa7164_api_set_gop_size(port); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 210 | |
| 211 | return ret; |
| 212 | } |
| 213 | |
| 214 | int saa7164_api_get_encoder(struct saa7164_port *port) |
| 215 | { |
| 216 | struct saa7164_dev *dev = port->dev; |
| 217 | tmComResEncVideoBitRate_t v; |
| 218 | tmComResEncAudioBitRate_t a; |
| 219 | tmComResEncVideoInputAspectRatio_t ar; |
| 220 | int ret; |
| 221 | |
| 222 | dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid); |
| 223 | |
| 224 | port->encoder_profile = 0; |
| 225 | port->video_format = 0; |
| 226 | port->video_resolution = 0; |
| 227 | port->audio_format = 0; |
| 228 | |
| 229 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, |
| 230 | EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile); |
| 231 | if (ret != SAA_OK) |
| 232 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 233 | |
| 234 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, |
Steven Toth | f6eeece | 2010-07-31 15:28:18 -0300 | [diff] [blame] | 235 | EU_VIDEO_RESOLUTION_CONTROL, sizeof(u8), &port->video_resolution); |
| 236 | if (ret != SAA_OK) |
| 237 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 238 | |
| 239 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 240 | EU_VIDEO_FORMAT_CONTROL, sizeof(u8), &port->video_format); |
| 241 | if (ret != SAA_OK) |
| 242 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 243 | |
| 244 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, |
| 245 | EU_VIDEO_BIT_RATE_CONTROL, sizeof(v), &v); |
| 246 | if (ret != SAA_OK) |
| 247 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 248 | |
| 249 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, |
| 250 | EU_AUDIO_FORMAT_CONTROL, sizeof(u8), &port->audio_format); |
| 251 | if (ret != SAA_OK) |
| 252 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 253 | |
| 254 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, |
| 255 | EU_AUDIO_BIT_RATE_CONTROL, sizeof(a), &a); |
| 256 | if (ret != SAA_OK) |
| 257 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 258 | |
| 259 | /* Aspect Ratio */ |
| 260 | ar.width = 0; |
| 261 | ar.height = 0; |
| 262 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, |
| 263 | EU_VIDEO_INPUT_ASPECT_CONTROL, |
| 264 | sizeof(tmComResEncVideoInputAspectRatio_t), &ar); |
| 265 | if (ret != SAA_OK) |
| 266 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 267 | |
| 268 | dprintk(DBGLVL_ENC, "encoder_profile = %d\n", port->encoder_profile); |
| 269 | dprintk(DBGLVL_ENC, "video_format = %d\n", port->video_format); |
| 270 | dprintk(DBGLVL_ENC, "audio_format = %d\n", port->audio_format); |
| 271 | dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution); |
| 272 | dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n", v.ucVideoBitRateMode); |
| 273 | dprintk(DBGLVL_ENC, "v.dwVideoBitRate = %d\n", v.dwVideoBitRate); |
| 274 | dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n", v.dwVideoBitRatePeak); |
| 275 | dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n", a.ucAudioBitRateMode); |
| 276 | dprintk(DBGLVL_ENC, "a.dwVideoBitRate = %d\n", a.dwAudioBitRate); |
| 277 | dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n", a.dwAudioBitRatePeak); |
| 278 | dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n", ar.width, ar.height); |
| 279 | |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | int saa7164_api_set_aspect_ratio(struct saa7164_port *port) |
| 284 | { |
| 285 | struct saa7164_dev *dev = port->dev; |
| 286 | tmComResEncVideoInputAspectRatio_t ar; |
| 287 | int ret; |
| 288 | |
| 289 | dprintk(DBGLVL_ENC, "%s(%d)\n", __func__, |
| 290 | port->encoder_params.ctl_aspect); |
| 291 | |
| 292 | switch (port->encoder_params.ctl_aspect) { |
| 293 | case V4L2_MPEG_VIDEO_ASPECT_1x1: |
| 294 | ar.width = 1; |
| 295 | ar.height = 1; |
| 296 | break; |
| 297 | case V4L2_MPEG_VIDEO_ASPECT_4x3: |
| 298 | ar.width = 4; |
| 299 | ar.height = 3; |
| 300 | break; |
| 301 | case V4L2_MPEG_VIDEO_ASPECT_16x9: |
| 302 | ar.width = 16; |
| 303 | ar.height = 9; |
| 304 | break; |
| 305 | case V4L2_MPEG_VIDEO_ASPECT_221x100: |
| 306 | ar.width = 221; |
| 307 | ar.height = 100; |
| 308 | break; |
| 309 | default: |
| 310 | BUG(); |
| 311 | } |
| 312 | |
| 313 | dprintk(DBGLVL_ENC, "%s(%d) now %d:%d\n", __func__, |
| 314 | port->encoder_params.ctl_aspect, |
| 315 | ar.width, ar.height); |
| 316 | |
| 317 | /* Aspect Ratio */ |
| 318 | ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, |
| 319 | EU_VIDEO_INPUT_ASPECT_CONTROL, |
| 320 | sizeof(tmComResEncVideoInputAspectRatio_t), &ar); |
| 321 | if (ret != SAA_OK) |
| 322 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 323 | |
| 324 | return ret; |
| 325 | } |
| 326 | |
| 327 | int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl) |
| 328 | { |
| 329 | struct saa7164_dev *dev = port->dev; |
| 330 | int ret; |
| 331 | u16 val; |
| 332 | |
| 333 | if (ctl == PU_BRIGHTNESS_CONTROL) |
| 334 | val = port->ctl_brightness; |
| 335 | else |
| 336 | if (ctl == PU_CONTRAST_CONTROL) |
| 337 | val = port->ctl_contrast; |
| 338 | else |
| 339 | if (ctl == PU_HUE_CONTROL) |
| 340 | val = port->ctl_hue; |
| 341 | else |
| 342 | if (ctl == PU_SATURATION_CONTROL) |
| 343 | val = port->ctl_saturation; |
| 344 | else |
| 345 | if (ctl == PU_SHARPNESS_CONTROL) |
| 346 | val = port->ctl_sharpness; |
| 347 | else |
| 348 | return -EINVAL; |
| 349 | |
| 350 | dprintk(DBGLVL_ENC, "%s() unitid=0x%x ctl=%d, val=%d\n", |
| 351 | __func__, port->encunit.vsourceid, ctl, val); |
| 352 | |
| 353 | ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, SET_CUR, |
| 354 | ctl, sizeof(u16), &val); |
| 355 | if (ret != SAA_OK) |
| 356 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 357 | |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl) |
| 362 | { |
| 363 | struct saa7164_dev *dev = port->dev; |
| 364 | int ret; |
| 365 | u16 val; |
| 366 | |
| 367 | ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, GET_CUR, |
| 368 | ctl, sizeof(u16), &val); |
| 369 | if (ret != SAA_OK) { |
| 370 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | dprintk(DBGLVL_ENC, "%s() ctl=%d, val=%d\n", |
| 375 | __func__, ctl, val); |
| 376 | |
| 377 | if (ctl == PU_BRIGHTNESS_CONTROL) |
| 378 | port->ctl_brightness = val; |
| 379 | else |
| 380 | if (ctl == PU_CONTRAST_CONTROL) |
| 381 | port->ctl_contrast = val; |
| 382 | else |
| 383 | if (ctl == PU_HUE_CONTROL) |
| 384 | port->ctl_hue = val; |
| 385 | else |
| 386 | if (ctl == PU_SATURATION_CONTROL) |
| 387 | port->ctl_saturation = val; |
| 388 | else |
| 389 | if (ctl == PU_SHARPNESS_CONTROL) |
| 390 | port->ctl_sharpness = val; |
| 391 | |
| 392 | return ret; |
| 393 | } |
| 394 | |
| 395 | int saa7164_api_set_videomux(struct saa7164_port *port) |
| 396 | { |
| 397 | struct saa7164_dev *dev = port->dev; |
| 398 | u8 inputs[] = { 1, 2, 2, 2, 5, 5, 5 }; |
| 399 | int ret; |
| 400 | |
| 401 | dprintk(DBGLVL_ENC, "%s() v_mux=%d a_mux=%d\n", |
| 402 | __func__, port->mux_input, inputs[ port->mux_input - 1 ]); |
| 403 | |
| 404 | /* Audio Mute */ |
| 405 | ret = saa7164_api_audio_mute(port, 1); |
| 406 | if (ret != SAA_OK) |
| 407 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 408 | |
| 409 | /* Video Mux */ |
| 410 | ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, SET_CUR, |
| 411 | SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input); |
| 412 | if (ret != SAA_OK) |
| 413 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 414 | /* Audio Mux */ |
| 415 | ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR, |
| 416 | SU_INPUT_SELECT_CONTROL, sizeof(u8), &inputs[ port->mux_input - 1 ]); |
| 417 | if (ret != SAA_OK) |
| 418 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 419 | /* Audio UnMute */ |
| 420 | ret = saa7164_api_audio_mute(port, 0); |
| 421 | if (ret != SAA_OK) |
| 422 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | int saa7164_api_audio_mute(struct saa7164_port *port, int mute) |
| 428 | { |
| 429 | struct saa7164_dev *dev = port->dev; |
| 430 | u8 v = mute; |
| 431 | int ret; |
| 432 | |
| 433 | dprintk(DBGLVL_API, "%s(%d)\n", __func__, mute); |
| 434 | |
| 435 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, |
| 436 | MUTE_CONTROL, sizeof(u8), &v); |
| 437 | if (ret != SAA_OK) |
| 438 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 439 | |
| 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | /* 0 = silence, 0xff = full */ |
| 444 | int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level) |
| 445 | { |
| 446 | struct saa7164_dev *dev = port->dev; |
| 447 | s16 v, min, max; |
| 448 | int ret; |
| 449 | |
| 450 | dprintk(DBGLVL_API, "%s(%d)\n", __func__, level); |
| 451 | |
| 452 | /* Obtain the min/max ranges */ |
| 453 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MIN, |
| 454 | VOLUME_CONTROL, sizeof(u16), &min); |
| 455 | if (ret != SAA_OK) |
| 456 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 457 | |
| 458 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MAX, |
| 459 | VOLUME_CONTROL, sizeof(u16), &max); |
| 460 | if (ret != SAA_OK) |
| 461 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 462 | |
| 463 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR, |
| 464 | ( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v); |
| 465 | if (ret != SAA_OK) |
| 466 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 467 | |
| 468 | dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v); |
| 469 | |
| 470 | v = level; |
| 471 | if (v < min) |
| 472 | v = min; |
| 473 | if (v > max) |
| 474 | v = max; |
| 475 | |
| 476 | /* Left */ |
| 477 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, |
| 478 | ( 0x01 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v); |
| 479 | if (ret != SAA_OK) |
| 480 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 481 | |
| 482 | /* Right */ |
| 483 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, |
| 484 | ( 0x02 << 8 ) | VOLUME_CONTROL, sizeof(s16), &v); |
| 485 | if (ret != SAA_OK) |
| 486 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 487 | |
| 488 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR, |
| 489 | ( 0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v); |
| 490 | if (ret != SAA_OK) |
| 491 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 492 | |
| 493 | dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v); |
| 494 | |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | int saa7164_api_set_audio_std(struct saa7164_port *port) |
| 499 | { |
| 500 | struct saa7164_dev *dev = port->dev; |
| 501 | tmComResAudioDefaults_t lvl; |
| 502 | tmComResTunerStandard_t tvaudio; |
| 503 | int ret; |
| 504 | |
| 505 | dprintk(DBGLVL_API, "%s()\n", __func__); |
| 506 | |
| 507 | /* Establish default levels */ |
| 508 | lvl.ucDecoderLevel = TMHW_LEV_ADJ_DECLEV_DEFAULT; |
| 509 | lvl.ucDecoderFM_Level = TMHW_LEV_ADJ_DECLEV_DEFAULT; |
| 510 | lvl.ucMonoLevel = TMHW_LEV_ADJ_MONOLEV_DEFAULT; |
| 511 | lvl.ucNICAM_Level = TMHW_LEV_ADJ_NICLEV_DEFAULT; |
| 512 | lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT; |
| 513 | lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT; |
| 514 | ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, |
| 515 | AUDIO_DEFAULT_CONTROL, sizeof(tmComResAudioDefaults_t), &lvl); |
| 516 | if (ret != SAA_OK) |
| 517 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 518 | |
| 519 | /* Manually select the appropriate TV audio standard */ |
| 520 | if (port->encodernorm.id & V4L2_STD_NTSC) { |
| 521 | tvaudio.std = TU_STANDARD_NTSC_M; |
| 522 | tvaudio.country = 1; |
| 523 | } else { |
| 524 | tvaudio.std = TU_STANDARD_PAL_I; |
| 525 | tvaudio.country = 44; |
| 526 | } |
| 527 | |
| 528 | ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR, |
| 529 | TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio); |
| 530 | if (ret != SAA_OK) |
| 531 | printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__, ret); |
| 532 | return ret; |
| 533 | } |
| 534 | |
| 535 | int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect) |
| 536 | { |
| 537 | struct saa7164_dev *dev = port->dev; |
| 538 | tmComResTunerStandardAuto_t p; |
| 539 | int ret; |
| 540 | |
| 541 | dprintk(DBGLVL_API, "%s(%d)\n", __func__, autodetect); |
| 542 | |
| 543 | /* Disable TV Audio autodetect if not already set (buggy) */ |
| 544 | if (autodetect) |
| 545 | p.mode = TU_STANDARD_AUTO; |
| 546 | else |
| 547 | p.mode = TU_STANDARD_MANUAL; |
| 548 | ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR, |
| 549 | TU_STANDARD_AUTO_CONTROL, sizeof(p), &p); |
| 550 | if (ret != SAA_OK) |
| 551 | printk(KERN_ERR "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__, ret); |
| 552 | |
| 553 | return ret; |
| 554 | } |
| 555 | |
| 556 | int saa7164_api_get_videomux(struct saa7164_port *port) |
| 557 | { |
| 558 | struct saa7164_dev *dev = port->dev; |
| 559 | int ret; |
| 560 | |
| 561 | ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, GET_CUR, |
| 562 | SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input); |
| 563 | if (ret != SAA_OK) |
| 564 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 565 | |
| 566 | dprintk(DBGLVL_ENC, "%s() v_mux=%d\n", |
| 567 | __func__, port->mux_input); |
| 568 | |
| 569 | return ret; |
| 570 | } |
| 571 | |
| 572 | int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val) |
| 573 | { |
| 574 | struct saa7164_dev *dev = port->dev; |
| 575 | |
| 576 | u16 len = 0; |
| 577 | u8 buf[256]; |
| 578 | int ret; |
| 579 | u8 mas; |
| 580 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 581 | dprintk(DBGLVL_API, "%s(nr=%d type=%d val=%x)\n", __func__, |
| 582 | port->nr, port->type, val); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 583 | |
| 584 | if (port->nr == 0) |
| 585 | mas = 0xd0; |
| 586 | else |
| 587 | mas = 0xe0; |
| 588 | |
| 589 | memset(buf, 0, sizeof(buf)); |
| 590 | |
| 591 | buf[0x00] = 0x04; |
| 592 | buf[0x01] = 0x00; |
| 593 | buf[0x02] = 0x00; |
| 594 | buf[0x03] = 0x00; |
| 595 | |
| 596 | buf[0x04] = 0x04; |
| 597 | buf[0x05] = 0x00; |
| 598 | buf[0x06] = 0x00; |
| 599 | buf[0x07] = 0x00; |
| 600 | |
| 601 | buf[0x08] = reg; |
| 602 | buf[0x09] = 0x26; |
| 603 | buf[0x0a] = mas; |
| 604 | buf[0x0b] = 0xb0; |
| 605 | |
| 606 | buf[0x0c] = val; |
| 607 | buf[0x0d] = 0x00; |
| 608 | buf[0x0e] = 0x00; |
| 609 | buf[0x0f] = 0x00; |
| 610 | |
| 611 | ret = saa7164_cmd_send(dev, port->ifunit.unitid, GET_LEN, |
| 612 | EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len); |
| 613 | if (ret != SAA_OK) { |
| 614 | printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret); |
| 615 | return -EIO; |
| 616 | } |
| 617 | |
| 618 | ret = saa7164_cmd_send(dev, port->ifunit.unitid, SET_CUR, |
| 619 | EXU_REGISTER_ACCESS_CONTROL, len, &buf); |
| 620 | if (ret != SAA_OK) |
| 621 | printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret); |
| 622 | |
| 623 | //saa7164_dumphex16(dev, buf, 16); |
| 624 | |
| 625 | return ret == SAA_OK ? 0 : -EIO; |
| 626 | } |
| 627 | |
| 628 | /* Disable the IF block AGC controls */ |
| 629 | int saa7164_api_configure_dif(struct saa7164_port *port, u32 std) |
| 630 | { |
| 631 | struct saa7164_dev *dev = port->dev; |
| 632 | int ret = 0; |
| 633 | u8 agc_disable; |
| 634 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 635 | dprintk(DBGLVL_API, "%s(nr=%d, 0x%x)\n", __func__, port->nr, std); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 636 | |
| 637 | if (std & V4L2_STD_NTSC) { |
| 638 | dprintk(DBGLVL_API, " NTSC\n"); |
| 639 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ |
| 640 | agc_disable = 0; |
| 641 | } else if (std & V4L2_STD_PAL_I) { |
| 642 | dprintk(DBGLVL_API, " PAL-I\n"); |
| 643 | saa7164_api_set_dif(port, 0x00, 0x08); /* Video Standard */ |
| 644 | agc_disable = 0; |
| 645 | } else if (std & V4L2_STD_PAL_M) { |
| 646 | dprintk(DBGLVL_API, " PAL-M\n"); |
| 647 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ |
| 648 | agc_disable = 0; |
| 649 | } else if (std & V4L2_STD_PAL_N) { |
| 650 | dprintk(DBGLVL_API, " PAL-N\n"); |
| 651 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ |
| 652 | agc_disable = 0; |
| 653 | } else if (std & V4L2_STD_PAL_Nc) { |
| 654 | dprintk(DBGLVL_API, " PAL-Nc\n"); |
| 655 | saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */ |
| 656 | agc_disable = 0; |
| 657 | } else if (std & V4L2_STD_PAL_B) { |
| 658 | dprintk(DBGLVL_API, " PAL-B\n"); |
| 659 | saa7164_api_set_dif(port, 0x00, 0x02); /* Video Standard */ |
| 660 | agc_disable = 0; |
| 661 | } else if (std & V4L2_STD_PAL_DK) { |
| 662 | dprintk(DBGLVL_API, " PAL-DK\n"); |
| 663 | saa7164_api_set_dif(port, 0x00, 0x10); /* Video Standard */ |
| 664 | agc_disable = 0; |
| 665 | } else if (std & V4L2_STD_SECAM_L) { |
| 666 | dprintk(DBGLVL_API, " SECAM-L\n"); |
| 667 | saa7164_api_set_dif(port, 0x00, 0x20); /* Video Standard */ |
| 668 | agc_disable = 0; |
| 669 | } else { |
| 670 | /* Unknown standard, assume DTV */ |
| 671 | dprintk(DBGLVL_API, " Unknown (assuming DTV)\n"); |
| 672 | saa7164_api_set_dif(port, 0x00, 0x80); /* Undefined Video Standard */ |
| 673 | agc_disable = 1; |
| 674 | } |
| 675 | |
| 676 | saa7164_api_set_dif(port, 0x48, 0xa0); /* AGC Functions 1 */ |
| 677 | saa7164_api_set_dif(port, 0xc0, agc_disable); /* AGC Output Disable */ |
| 678 | saa7164_api_set_dif(port, 0x7c, 0x04); /* CVBS EQ */ |
| 679 | saa7164_api_set_dif(port, 0x04, 0x01); /* Active */ |
| 680 | msleep(100); |
| 681 | saa7164_api_set_dif(port, 0x04, 0x00); /* Active (again) */ |
| 682 | msleep(100); |
| 683 | |
| 684 | return ret; |
| 685 | } |
| 686 | |
| 687 | /* Ensure the dif is in the correct state for the operating mode |
| 688 | * (analog / dtv). We only configure the diff through the analog encoder |
| 689 | * so when we're in digital mode we need to find the appropriate encoder |
| 690 | * and use it to configure the DIF. |
| 691 | */ |
| 692 | int saa7164_api_initialize_dif(struct saa7164_port *port) |
| 693 | { |
| 694 | struct saa7164_dev *dev = port->dev; |
| 695 | struct saa7164_port *p = 0; |
| 696 | int ret = -EINVAL; |
| 697 | u32 std = 0; |
| 698 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 699 | dprintk(DBGLVL_API, "%s(nr=%d type=%d)\n", __func__, |
| 700 | port->nr, port->type); |
| 701 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 702 | if (port->type == SAA7164_MPEG_ENCODER) { |
| 703 | /* Pick any analog standard to init the diff. |
| 704 | * we'll come back during encoder_init' |
| 705 | * and set the correct standard if requried. |
| 706 | */ |
| 707 | std = V4L2_STD_NTSC; |
| 708 | } else |
| 709 | if (port->type == SAA7164_MPEG_DVB) { |
| 710 | if (port->nr == SAA7164_PORT_TS1) |
| 711 | p = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 712 | else |
| 713 | p = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 714 | } else |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 715 | if (port->type == SAA7164_MPEG_VBI) { |
| 716 | std = V4L2_STD_NTSC; |
| 717 | if (port->nr == SAA7164_PORT_VBI1) |
| 718 | p = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 719 | else |
| 720 | p = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 721 | } else |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 722 | BUG(); |
| 723 | |
| 724 | if (p) |
| 725 | ret = saa7164_api_configure_dif(p, std); |
| 726 | |
| 727 | return ret; |
| 728 | } |
| 729 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 730 | int saa7164_api_transition_port(struct saa7164_port *port, u8 mode) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 731 | { |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 732 | struct saa7164_dev *dev = port->dev; |
| 733 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 734 | int ret; |
| 735 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 736 | dprintk(DBGLVL_API, "%s(nr=%d unitid=0x%x,%d)\n", |
| 737 | __func__, port->nr, port->hwcfg.unitid, mode); |
| 738 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 739 | ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR, |
| 740 | SAA_STATE_CONTROL, sizeof(mode), &mode); |
| 741 | if (ret != SAA_OK) |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 742 | printk(KERN_ERR "%s(portnr %d unitid 0x%x) error, ret = 0x%x\n", |
| 743 | __func__, port->nr, port->hwcfg.unitid, ret); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 744 | |
| 745 | return ret; |
| 746 | } |
| 747 | |
| 748 | int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version) |
| 749 | { |
| 750 | int ret; |
| 751 | |
| 752 | ret = saa7164_cmd_send(dev, 0, GET_CUR, |
| 753 | GET_FW_VERSION_CONTROL, sizeof(u32), version); |
| 754 | if (ret != SAA_OK) |
| 755 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 756 | |
| 757 | return ret; |
| 758 | } |
| 759 | |
| 760 | int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen) |
| 761 | { |
| 762 | u8 reg[] = { 0x0f, 0x00 }; |
| 763 | |
| 764 | if (buflen < 128) |
| 765 | return -ENOMEM; |
| 766 | |
| 767 | /* Assumption: Hauppauge eeprom is at 0xa0 on on bus 0 */ |
| 768 | /* TODO: Pull the details from the boards struct */ |
| 769 | return saa7164_api_i2c_read(&dev->i2c_bus[0], 0xa0 >> 1, sizeof(reg), |
| 770 | ®[0], 128, buf); |
| 771 | } |
| 772 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 773 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 774 | int saa7164_api_configure_port_vbi(struct saa7164_dev *dev, |
| 775 | struct saa7164_port *port) |
| 776 | { |
| 777 | tmComResVBIFormatDescrHeader_t *fmt = &port->vbi_fmt_ntsc; |
| 778 | |
| 779 | dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex); |
| 780 | dprintk(DBGLVL_API, " VideoStandard = 0x%x\n", fmt->VideoStandard); |
| 781 | dprintk(DBGLVL_API, " StartLine = %d\n", fmt->StartLine); |
| 782 | dprintk(DBGLVL_API, " EndLine = %d\n", fmt->EndLine); |
| 783 | dprintk(DBGLVL_API, " FieldRate = %d\n", fmt->FieldRate); |
| 784 | dprintk(DBGLVL_API, " bNumLines = %d\n", fmt->bNumLines); |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame] | 785 | |
| 786 | /* Cache the hardware configuration in the port */ |
| 787 | |
| 788 | port->bufcounter = port->hwcfg.BARLocation; |
| 789 | port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32)); |
| 790 | port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32)); |
| 791 | port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32)); |
| 792 | port->bufptr32l = port->hwcfg.BARLocation + |
| 793 | (4 * sizeof(u32)) + |
| 794 | (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32); |
| 795 | port->bufptr32h = port->hwcfg.BARLocation + |
| 796 | (4 * sizeof(u32)) + |
| 797 | (sizeof(u32) * port->hwcfg.buffercount); |
| 798 | port->bufptr64 = port->hwcfg.BARLocation + |
| 799 | (4 * sizeof(u32)) + |
| 800 | (sizeof(u32) * port->hwcfg.buffercount); |
| 801 | dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n", |
| 802 | port->hwcfg.BARLocation); |
| 803 | |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 804 | dprintk(DBGLVL_API, " = VS_FORMAT_VBI (becomes dev->en[%d])\n", |
| 805 | port->nr); |
| 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 810 | int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev, |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame] | 811 | struct saa7164_port *port, |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 812 | tmComResTSFormatDescrHeader_t *tsfmt) |
| 813 | { |
| 814 | dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", tsfmt->bFormatIndex); |
| 815 | dprintk(DBGLVL_API, " bDataOffset = 0x%x\n", tsfmt->bDataOffset); |
| 816 | dprintk(DBGLVL_API, " bPacketLength= 0x%x\n", tsfmt->bPacketLength); |
| 817 | dprintk(DBGLVL_API, " bStrideLength= 0x%x\n", tsfmt->bStrideLength); |
| 818 | dprintk(DBGLVL_API, " bguid = (....)\n"); |
| 819 | |
| 820 | /* Cache the hardware configuration in the port */ |
| 821 | |
| 822 | port->bufcounter = port->hwcfg.BARLocation; |
| 823 | port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32)); |
| 824 | port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32)); |
| 825 | port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32)); |
| 826 | port->bufptr32l = port->hwcfg.BARLocation + |
| 827 | (4 * sizeof(u32)) + |
| 828 | (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32); |
| 829 | port->bufptr32h = port->hwcfg.BARLocation + |
| 830 | (4 * sizeof(u32)) + |
| 831 | (sizeof(u32) * port->hwcfg.buffercount); |
| 832 | port->bufptr64 = port->hwcfg.BARLocation + |
| 833 | (4 * sizeof(u32)) + |
| 834 | (sizeof(u32) * port->hwcfg.buffercount); |
| 835 | dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n", |
| 836 | port->hwcfg.BARLocation); |
| 837 | |
| 838 | dprintk(DBGLVL_API, " = VS_FORMAT_MPEGTS (becomes dev->ts[%d])\n", |
| 839 | port->nr); |
| 840 | |
| 841 | return 0; |
| 842 | } |
| 843 | |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 844 | int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev *dev, |
| 845 | struct saa7164_port *port, |
| 846 | tmComResPSFormatDescrHeader_t *fmt) |
| 847 | { |
| 848 | dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex); |
| 849 | dprintk(DBGLVL_API, " wPacketLength= 0x%x\n", fmt->wPacketLength); |
| 850 | dprintk(DBGLVL_API, " wPackLength= 0x%x\n", fmt->wPackLength); |
| 851 | dprintk(DBGLVL_API, " bPackDataType= 0x%x\n", fmt->bPackDataType); |
| 852 | |
| 853 | /* Cache the hardware configuration in the port */ |
| 854 | /* TODO: CHECK THIS in the port config */ |
| 855 | port->bufcounter = port->hwcfg.BARLocation; |
| 856 | port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32)); |
| 857 | port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32)); |
| 858 | port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32)); |
| 859 | port->bufptr32l = port->hwcfg.BARLocation + |
| 860 | (4 * sizeof(u32)) + |
| 861 | (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32); |
| 862 | port->bufptr32h = port->hwcfg.BARLocation + |
| 863 | (4 * sizeof(u32)) + |
| 864 | (sizeof(u32) * port->hwcfg.buffercount); |
| 865 | port->bufptr64 = port->hwcfg.BARLocation + |
| 866 | (4 * sizeof(u32)) + |
| 867 | (sizeof(u32) * port->hwcfg.buffercount); |
| 868 | dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n", |
| 869 | port->hwcfg.BARLocation); |
| 870 | |
| 871 | dprintk(DBGLVL_API, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n", |
| 872 | port->nr); |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 877 | int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len) |
| 878 | { |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 879 | struct saa7164_port *tsport = 0; |
| 880 | struct saa7164_port *encport = 0; |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 881 | struct saa7164_port *vbiport = 0; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 882 | u32 idx, next_offset; |
| 883 | int i; |
| 884 | tmComResDescrHeader_t *hdr, *t; |
| 885 | tmComResExtDevDescrHeader_t *exthdr; |
| 886 | tmComResPathDescrHeader_t *pathhdr; |
| 887 | tmComResAntTermDescrHeader_t *anttermhdr; |
| 888 | tmComResTunerDescrHeader_t *tunerunithdr; |
| 889 | tmComResDMATermDescrHeader_t *vcoutputtermhdr; |
| 890 | tmComResTSFormatDescrHeader_t *tsfmt; |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 891 | tmComResPSFormatDescrHeader_t *psfmt; |
| 892 | tmComResSelDescrHeader_t *psel; |
| 893 | tmComResProcDescrHeader_t *pdh; |
| 894 | tmComResAFeatureDescrHeader_t *afd; |
| 895 | tmComResEncoderDescrHeader_t *edh; |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 896 | tmComResVBIFormatDescrHeader_t *vbifmt; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 897 | u32 currpath = 0; |
| 898 | |
| 899 | dprintk(DBGLVL_API, |
Steven Toth | 207b42c | 2009-05-09 21:30:05 -0300 | [diff] [blame] | 900 | "%s(?,?,%d) sizeof(tmComResDescrHeader_t) = %d bytes\n", |
| 901 | __func__, len, (u32)sizeof(tmComResDescrHeader_t)); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 902 | |
| 903 | for (idx = 0; idx < (len - sizeof(tmComResDescrHeader_t)); ) { |
| 904 | |
| 905 | hdr = (tmComResDescrHeader_t *)(buf + idx); |
| 906 | |
| 907 | if (hdr->type != CS_INTERFACE) |
| 908 | return SAA_ERR_NOT_SUPPORTED; |
| 909 | |
| 910 | dprintk(DBGLVL_API, "@ 0x%x = \n", idx); |
| 911 | switch (hdr->subtype) { |
| 912 | case GENERAL_REQUEST: |
| 913 | dprintk(DBGLVL_API, " GENERAL_REQUEST\n"); |
| 914 | break; |
| 915 | case VC_TUNER_PATH: |
| 916 | dprintk(DBGLVL_API, " VC_TUNER_PATH\n"); |
| 917 | pathhdr = (tmComResPathDescrHeader_t *)(buf + idx); |
| 918 | dprintk(DBGLVL_API, " pathid = 0x%x\n", |
| 919 | pathhdr->pathid); |
| 920 | currpath = pathhdr->pathid; |
| 921 | break; |
| 922 | case VC_INPUT_TERMINAL: |
| 923 | dprintk(DBGLVL_API, " VC_INPUT_TERMINAL\n"); |
| 924 | anttermhdr = |
| 925 | (tmComResAntTermDescrHeader_t *)(buf + idx); |
| 926 | dprintk(DBGLVL_API, " terminalid = 0x%x\n", |
| 927 | anttermhdr->terminalid); |
| 928 | dprintk(DBGLVL_API, " terminaltype = 0x%x\n", |
| 929 | anttermhdr->terminaltype); |
| 930 | switch (anttermhdr->terminaltype) { |
| 931 | case ITT_ANTENNA: |
| 932 | dprintk(DBGLVL_API, " = ITT_ANTENNA\n"); |
| 933 | break; |
| 934 | case LINE_CONNECTOR: |
| 935 | dprintk(DBGLVL_API, " = LINE_CONNECTOR\n"); |
| 936 | break; |
| 937 | case SPDIF_CONNECTOR: |
| 938 | dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n"); |
| 939 | break; |
| 940 | case COMPOSITE_CONNECTOR: |
| 941 | dprintk(DBGLVL_API, |
| 942 | " = COMPOSITE_CONNECTOR\n"); |
| 943 | break; |
| 944 | case SVIDEO_CONNECTOR: |
| 945 | dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n"); |
| 946 | break; |
| 947 | case COMPONENT_CONNECTOR: |
| 948 | dprintk(DBGLVL_API, |
| 949 | " = COMPONENT_CONNECTOR\n"); |
| 950 | break; |
| 951 | case STANDARD_DMA: |
| 952 | dprintk(DBGLVL_API, " = STANDARD_DMA\n"); |
| 953 | break; |
| 954 | default: |
| 955 | dprintk(DBGLVL_API, " = undefined (0x%x)\n", |
| 956 | anttermhdr->terminaltype); |
| 957 | } |
| 958 | dprintk(DBGLVL_API, " assocterminal= 0x%x\n", |
| 959 | anttermhdr->assocterminal); |
| 960 | dprintk(DBGLVL_API, " iterminal = 0x%x\n", |
| 961 | anttermhdr->iterminal); |
| 962 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", |
| 963 | anttermhdr->controlsize); |
| 964 | break; |
| 965 | case VC_OUTPUT_TERMINAL: |
| 966 | dprintk(DBGLVL_API, " VC_OUTPUT_TERMINAL\n"); |
| 967 | vcoutputtermhdr = |
| 968 | (tmComResDMATermDescrHeader_t *)(buf + idx); |
| 969 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
| 970 | vcoutputtermhdr->unitid); |
| 971 | dprintk(DBGLVL_API, " terminaltype = 0x%x\n", |
| 972 | vcoutputtermhdr->terminaltype); |
| 973 | switch (vcoutputtermhdr->terminaltype) { |
| 974 | case ITT_ANTENNA: |
| 975 | dprintk(DBGLVL_API, " = ITT_ANTENNA\n"); |
| 976 | break; |
| 977 | case LINE_CONNECTOR: |
| 978 | dprintk(DBGLVL_API, " = LINE_CONNECTOR\n"); |
| 979 | break; |
| 980 | case SPDIF_CONNECTOR: |
| 981 | dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n"); |
| 982 | break; |
| 983 | case COMPOSITE_CONNECTOR: |
| 984 | dprintk(DBGLVL_API, |
| 985 | " = COMPOSITE_CONNECTOR\n"); |
| 986 | break; |
| 987 | case SVIDEO_CONNECTOR: |
| 988 | dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n"); |
| 989 | break; |
| 990 | case COMPONENT_CONNECTOR: |
| 991 | dprintk(DBGLVL_API, |
| 992 | " = COMPONENT_CONNECTOR\n"); |
| 993 | break; |
| 994 | case STANDARD_DMA: |
| 995 | dprintk(DBGLVL_API, " = STANDARD_DMA\n"); |
| 996 | break; |
| 997 | default: |
| 998 | dprintk(DBGLVL_API, " = undefined (0x%x)\n", |
| 999 | vcoutputtermhdr->terminaltype); |
| 1000 | } |
| 1001 | dprintk(DBGLVL_API, " assocterminal= 0x%x\n", |
| 1002 | vcoutputtermhdr->assocterminal); |
| 1003 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", |
| 1004 | vcoutputtermhdr->sourceid); |
| 1005 | dprintk(DBGLVL_API, " iterminal = 0x%x\n", |
| 1006 | vcoutputtermhdr->iterminal); |
| 1007 | dprintk(DBGLVL_API, " BARLocation = 0x%x\n", |
| 1008 | vcoutputtermhdr->BARLocation); |
| 1009 | dprintk(DBGLVL_API, " flags = 0x%x\n", |
| 1010 | vcoutputtermhdr->flags); |
| 1011 | dprintk(DBGLVL_API, " interruptid = 0x%x\n", |
| 1012 | vcoutputtermhdr->interruptid); |
| 1013 | dprintk(DBGLVL_API, " buffercount = 0x%x\n", |
| 1014 | vcoutputtermhdr->buffercount); |
| 1015 | dprintk(DBGLVL_API, " metadatasize = 0x%x\n", |
| 1016 | vcoutputtermhdr->metadatasize); |
| 1017 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", |
| 1018 | vcoutputtermhdr->controlsize); |
| 1019 | dprintk(DBGLVL_API, " numformats = 0x%x\n", |
| 1020 | vcoutputtermhdr->numformats); |
| 1021 | |
| 1022 | t = (tmComResDescrHeader_t *) |
| 1023 | ((tmComResDMATermDescrHeader_t *)(buf + idx)); |
| 1024 | next_offset = idx + (vcoutputtermhdr->len); |
| 1025 | for (i = 0; i < vcoutputtermhdr->numformats; i++) { |
| 1026 | t = (tmComResDescrHeader_t *) |
| 1027 | (buf + next_offset); |
| 1028 | switch (t->subtype) { |
| 1029 | case VS_FORMAT_MPEG2TS: |
| 1030 | tsfmt = |
| 1031 | (tmComResTSFormatDescrHeader_t *)t; |
| 1032 | if (currpath == 1) |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1033 | tsport = &dev->ports[ SAA7164_PORT_TS1 ]; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1034 | else |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1035 | tsport = &dev->ports[ SAA7164_PORT_TS2 ]; |
| 1036 | memcpy(&tsport->hwcfg, vcoutputtermhdr, |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1037 | sizeof(*vcoutputtermhdr)); |
| 1038 | saa7164_api_configure_port_mpeg2ts(dev, |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1039 | tsport, tsfmt); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1040 | break; |
| 1041 | case VS_FORMAT_MPEG2PS: |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1042 | psfmt = |
| 1043 | (tmComResPSFormatDescrHeader_t *)t; |
| 1044 | if (currpath == 1) |
| 1045 | encport = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 1046 | else |
| 1047 | encport = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 1048 | memcpy(&encport->hwcfg, vcoutputtermhdr, |
| 1049 | sizeof(*vcoutputtermhdr)); |
| 1050 | saa7164_api_configure_port_mpeg2ps(dev, |
| 1051 | encport, psfmt); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1052 | break; |
| 1053 | case VS_FORMAT_VBI: |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 1054 | vbifmt = |
| 1055 | (tmComResVBIFormatDescrHeader_t *)t; |
| 1056 | if (currpath == 1) |
| 1057 | vbiport = &dev->ports[ SAA7164_PORT_VBI1 ]; |
| 1058 | else |
| 1059 | vbiport = &dev->ports[ SAA7164_PORT_VBI2 ]; |
| 1060 | memcpy(&vbiport->hwcfg, vcoutputtermhdr, |
| 1061 | sizeof(*vcoutputtermhdr)); |
| 1062 | memcpy(&vbiport->vbi_fmt_ntsc, vbifmt, sizeof(*vbifmt)); |
| 1063 | saa7164_api_configure_port_vbi(dev, |
| 1064 | vbiport); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1065 | break; |
| 1066 | case VS_FORMAT_RDS: |
| 1067 | dprintk(DBGLVL_API, |
| 1068 | " = VS_FORMAT_RDS\n"); |
| 1069 | break; |
| 1070 | case VS_FORMAT_UNCOMPRESSED: |
| 1071 | dprintk(DBGLVL_API, |
| 1072 | " = VS_FORMAT_UNCOMPRESSED\n"); |
| 1073 | break; |
| 1074 | case VS_FORMAT_TYPE: |
| 1075 | dprintk(DBGLVL_API, |
| 1076 | " = VS_FORMAT_TYPE\n"); |
| 1077 | break; |
| 1078 | default: |
| 1079 | dprintk(DBGLVL_API, |
| 1080 | " = undefined (0x%x)\n", |
| 1081 | t->subtype); |
| 1082 | } |
| 1083 | next_offset += t->len; |
| 1084 | } |
| 1085 | |
| 1086 | break; |
| 1087 | case TUNER_UNIT: |
| 1088 | dprintk(DBGLVL_API, " TUNER_UNIT\n"); |
| 1089 | tunerunithdr = |
| 1090 | (tmComResTunerDescrHeader_t *)(buf + idx); |
| 1091 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
| 1092 | tunerunithdr->unitid); |
| 1093 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", |
| 1094 | tunerunithdr->sourceid); |
| 1095 | dprintk(DBGLVL_API, " iunit = 0x%x\n", |
| 1096 | tunerunithdr->iunit); |
| 1097 | dprintk(DBGLVL_API, " tuningstandards = 0x%x\n", |
| 1098 | tunerunithdr->tuningstandards); |
| 1099 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", |
| 1100 | tunerunithdr->controlsize); |
| 1101 | dprintk(DBGLVL_API, " controls = 0x%x\n", |
| 1102 | tunerunithdr->controls); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1103 | |
| 1104 | if (tunerunithdr->unitid == tunerunithdr->iunit) { |
| 1105 | if (currpath == 1) |
| 1106 | encport = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 1107 | else |
| 1108 | encport = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 1109 | memcpy(&encport->tunerunit, tunerunithdr, |
| 1110 | sizeof(tmComResTunerDescrHeader_t)); |
| 1111 | dprintk(DBGLVL_API, " (becomes dev->enc[%d] tuner)\n", encport->nr); |
| 1112 | } |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1113 | break; |
| 1114 | case VC_SELECTOR_UNIT: |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1115 | psel = (tmComResSelDescrHeader_t *)(buf + idx); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1116 | dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n"); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1117 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
| 1118 | psel->unitid); |
| 1119 | dprintk(DBGLVL_API, " nrinpins = 0x%x\n", |
| 1120 | psel->nrinpins); |
| 1121 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", |
| 1122 | psel->sourceid); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1123 | break; |
| 1124 | case VC_PROCESSING_UNIT: |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1125 | pdh = (tmComResProcDescrHeader_t *)(buf + idx); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1126 | dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n"); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1127 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
| 1128 | pdh->unitid); |
| 1129 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", |
| 1130 | pdh->sourceid); |
| 1131 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", |
| 1132 | pdh->controlsize); |
| 1133 | if (pdh->controlsize == 0x04) { |
| 1134 | if (currpath == 1) |
| 1135 | encport = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 1136 | else |
| 1137 | encport = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 1138 | memcpy(&encport->vidproc, pdh, |
| 1139 | sizeof(tmComResProcDescrHeader_t)); |
| 1140 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); |
| 1141 | } |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1142 | break; |
| 1143 | case FEATURE_UNIT: |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1144 | afd = (tmComResAFeatureDescrHeader_t *)(buf + idx); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1145 | dprintk(DBGLVL_API, " FEATURE_UNIT\n"); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1146 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
| 1147 | afd->unitid); |
| 1148 | dprintk(DBGLVL_API, " sourceid = 0x%x\n", |
| 1149 | afd->sourceid); |
| 1150 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", |
| 1151 | afd->controlsize); |
| 1152 | if (currpath == 1) |
| 1153 | encport = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 1154 | else |
| 1155 | encport = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 1156 | memcpy(&encport->audfeat, afd, |
| 1157 | sizeof(tmComResAFeatureDescrHeader_t)); |
| 1158 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1159 | break; |
| 1160 | case ENCODER_UNIT: |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1161 | edh = (tmComResEncoderDescrHeader_t *)(buf + idx); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1162 | dprintk(DBGLVL_API, " ENCODER_UNIT\n"); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1163 | dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype); |
| 1164 | dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid); |
| 1165 | dprintk(DBGLVL_API, " vsourceid = 0x%x\n", edh->vsourceid); |
| 1166 | dprintk(DBGLVL_API, " asourceid = 0x%x\n", edh->asourceid); |
| 1167 | dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit); |
| 1168 | if (edh->iunit == edh->unitid) { |
| 1169 | if (currpath == 1) |
| 1170 | encport = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 1171 | else |
| 1172 | encport = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 1173 | memcpy(&encport->encunit, edh, |
| 1174 | sizeof(tmComResEncoderDescrHeader_t)); |
| 1175 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); |
| 1176 | } |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1177 | break; |
| 1178 | case EXTENSION_UNIT: |
| 1179 | dprintk(DBGLVL_API, " EXTENSION_UNIT\n"); |
| 1180 | exthdr = (tmComResExtDevDescrHeader_t *)(buf + idx); |
| 1181 | dprintk(DBGLVL_API, " unitid = 0x%x\n", |
| 1182 | exthdr->unitid); |
| 1183 | dprintk(DBGLVL_API, " deviceid = 0x%x\n", |
| 1184 | exthdr->deviceid); |
| 1185 | dprintk(DBGLVL_API, " devicetype = 0x%x\n", |
| 1186 | exthdr->devicetype); |
| 1187 | if (exthdr->devicetype & 0x1) |
| 1188 | dprintk(DBGLVL_API, " = Decoder Device\n"); |
| 1189 | if (exthdr->devicetype & 0x2) |
| 1190 | dprintk(DBGLVL_API, " = GPIO Source\n"); |
| 1191 | if (exthdr->devicetype & 0x4) |
| 1192 | dprintk(DBGLVL_API, " = Video Decoder\n"); |
| 1193 | if (exthdr->devicetype & 0x8) |
| 1194 | dprintk(DBGLVL_API, " = Audio Decoder\n"); |
| 1195 | if (exthdr->devicetype & 0x20) |
| 1196 | dprintk(DBGLVL_API, " = Crossbar\n"); |
| 1197 | if (exthdr->devicetype & 0x40) |
| 1198 | dprintk(DBGLVL_API, " = Tuner\n"); |
| 1199 | if (exthdr->devicetype & 0x80) |
| 1200 | dprintk(DBGLVL_API, " = IF PLL\n"); |
| 1201 | if (exthdr->devicetype & 0x100) |
| 1202 | dprintk(DBGLVL_API, " = Demodulator\n"); |
| 1203 | if (exthdr->devicetype & 0x200) |
| 1204 | dprintk(DBGLVL_API, " = RDS Decoder\n"); |
| 1205 | if (exthdr->devicetype & 0x400) |
| 1206 | dprintk(DBGLVL_API, " = Encoder\n"); |
| 1207 | if (exthdr->devicetype & 0x800) |
| 1208 | dprintk(DBGLVL_API, " = IR Decoder\n"); |
| 1209 | if (exthdr->devicetype & 0x1000) |
| 1210 | dprintk(DBGLVL_API, " = EEPROM\n"); |
| 1211 | if (exthdr->devicetype & 0x2000) |
| 1212 | dprintk(DBGLVL_API, |
| 1213 | " = VBI Decoder\n"); |
| 1214 | if (exthdr->devicetype & 0x10000) |
| 1215 | dprintk(DBGLVL_API, |
| 1216 | " = Streaming Device\n"); |
| 1217 | if (exthdr->devicetype & 0x20000) |
| 1218 | dprintk(DBGLVL_API, |
| 1219 | " = DRM Device\n"); |
| 1220 | if (exthdr->devicetype & 0x40000000) |
| 1221 | dprintk(DBGLVL_API, |
| 1222 | " = Generic Device\n"); |
| 1223 | if (exthdr->devicetype & 0x80000000) |
| 1224 | dprintk(DBGLVL_API, |
| 1225 | " = Config Space Device\n"); |
| 1226 | dprintk(DBGLVL_API, " numgpiopins = 0x%x\n", |
| 1227 | exthdr->numgpiopins); |
| 1228 | dprintk(DBGLVL_API, " numgpiogroups = 0x%x\n", |
| 1229 | exthdr->numgpiogroups); |
| 1230 | dprintk(DBGLVL_API, " controlsize = 0x%x\n", |
| 1231 | exthdr->controlsize); |
Steven Toth | 7615e43 | 2010-07-31 14:44:53 -0300 | [diff] [blame] | 1232 | if (exthdr->devicetype & 0x80) { |
| 1233 | if (currpath == 1) |
| 1234 | encport = &dev->ports[ SAA7164_PORT_ENC1 ]; |
| 1235 | else |
| 1236 | encport = &dev->ports[ SAA7164_PORT_ENC2 ]; |
| 1237 | memcpy(&encport->ifunit, exthdr, |
| 1238 | sizeof(tmComResExtDevDescrHeader_t)); |
| 1239 | dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); |
| 1240 | } |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1241 | break; |
| 1242 | case PVC_INFRARED_UNIT: |
| 1243 | dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n"); |
| 1244 | break; |
| 1245 | case DRM_UNIT: |
| 1246 | dprintk(DBGLVL_API, " DRM_UNIT\n"); |
| 1247 | break; |
| 1248 | default: |
| 1249 | dprintk(DBGLVL_API, "default %d\n", hdr->subtype); |
| 1250 | } |
| 1251 | |
| 1252 | dprintk(DBGLVL_API, " 1.%x\n", hdr->len); |
| 1253 | dprintk(DBGLVL_API, " 2.%x\n", hdr->type); |
| 1254 | dprintk(DBGLVL_API, " 3.%x\n", hdr->subtype); |
| 1255 | dprintk(DBGLVL_API, " 4.%x\n", hdr->unitid); |
| 1256 | |
| 1257 | idx += hdr->len; |
| 1258 | } |
| 1259 | |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | int saa7164_api_enum_subdevs(struct saa7164_dev *dev) |
| 1264 | { |
| 1265 | int ret; |
| 1266 | u32 buflen = 0; |
| 1267 | u8 *buf; |
| 1268 | |
| 1269 | dprintk(DBGLVL_API, "%s()\n", __func__); |
| 1270 | |
| 1271 | /* Get the total descriptor length */ |
| 1272 | ret = saa7164_cmd_send(dev, 0, GET_LEN, |
| 1273 | GET_DESCRIPTORS_CONTROL, sizeof(buflen), &buflen); |
| 1274 | if (ret != SAA_OK) |
| 1275 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 1276 | |
| 1277 | dprintk(DBGLVL_API, "%s() total descriptor size = %d bytes.\n", |
| 1278 | __func__, buflen); |
| 1279 | |
| 1280 | /* Allocate enough storage for all of the descs */ |
| 1281 | buf = kzalloc(buflen, GFP_KERNEL); |
| 1282 | if (buf == NULL) |
| 1283 | return SAA_ERR_NO_RESOURCES; |
| 1284 | |
| 1285 | /* Retrieve them */ |
| 1286 | ret = saa7164_cmd_send(dev, 0, GET_CUR, |
| 1287 | GET_DESCRIPTORS_CONTROL, buflen, buf); |
| 1288 | if (ret != SAA_OK) { |
| 1289 | printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); |
| 1290 | goto out; |
| 1291 | } |
| 1292 | |
Ingo Molnar | b1912a85 | 2009-09-21 15:23:45 -0300 | [diff] [blame] | 1293 | if (saa_debug & DBGLVL_API) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1294 | saa7164_dumphex16(dev, buf, (buflen/16)*16); |
| 1295 | |
| 1296 | saa7164_api_dump_subdevs(dev, buf, buflen); |
| 1297 | |
| 1298 | out: |
| 1299 | kfree(buf); |
| 1300 | return ret; |
| 1301 | } |
| 1302 | |
| 1303 | int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg, |
| 1304 | u32 datalen, u8 *data) |
| 1305 | { |
| 1306 | struct saa7164_dev *dev = bus->dev; |
| 1307 | u16 len = 0; |
| 1308 | int unitid; |
| 1309 | u32 regval; |
| 1310 | u8 buf[256]; |
| 1311 | int ret; |
| 1312 | |
| 1313 | dprintk(DBGLVL_API, "%s()\n", __func__); |
| 1314 | |
| 1315 | if (reglen > 4) |
| 1316 | return -EIO; |
| 1317 | |
| 1318 | if (reglen == 1) |
| 1319 | regval = *(reg); |
| 1320 | else |
| 1321 | if (reglen == 2) |
| 1322 | regval = ((*(reg) << 8) || *(reg+1)); |
| 1323 | else |
| 1324 | if (reglen == 3) |
| 1325 | regval = ((*(reg) << 16) | (*(reg+1) << 8) | *(reg+2)); |
| 1326 | else |
| 1327 | if (reglen == 4) |
| 1328 | regval = ((*(reg) << 24) | (*(reg+1) << 16) | |
| 1329 | (*(reg+2) << 8) | *(reg+3)); |
| 1330 | |
| 1331 | /* Prepare the send buffer */ |
| 1332 | /* Bytes 00-03 source register length |
| 1333 | * 04-07 source bytes to read |
| 1334 | * 08... register address |
| 1335 | */ |
| 1336 | memset(buf, 0, sizeof(buf)); |
| 1337 | memcpy((buf + 2 * sizeof(u32) + 0), reg, reglen); |
| 1338 | *((u32 *)(buf + 0 * sizeof(u32))) = reglen; |
| 1339 | *((u32 *)(buf + 1 * sizeof(u32))) = datalen; |
| 1340 | |
| 1341 | unitid = saa7164_i2caddr_to_unitid(bus, addr); |
| 1342 | if (unitid < 0) { |
| 1343 | printk(KERN_ERR |
| 1344 | "%s() error, cannot translate regaddr 0x%x to unitid\n", |
| 1345 | __func__, addr); |
| 1346 | return -EIO; |
| 1347 | } |
| 1348 | |
| 1349 | ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN, |
| 1350 | EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len); |
| 1351 | if (ret != SAA_OK) { |
| 1352 | printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret); |
| 1353 | return -EIO; |
| 1354 | } |
| 1355 | |
| 1356 | dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len); |
| 1357 | |
Ingo Molnar | b1912a85 | 2009-09-21 15:23:45 -0300 | [diff] [blame] | 1358 | if (saa_debug & DBGLVL_I2C) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1359 | saa7164_dumphex16(dev, buf, 2 * 16); |
| 1360 | |
| 1361 | ret = saa7164_cmd_send(bus->dev, unitid, GET_CUR, |
| 1362 | EXU_REGISTER_ACCESS_CONTROL, len, &buf); |
| 1363 | if (ret != SAA_OK) |
| 1364 | printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret); |
| 1365 | else { |
Ingo Molnar | b1912a85 | 2009-09-21 15:23:45 -0300 | [diff] [blame] | 1366 | if (saa_debug & DBGLVL_I2C) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1367 | saa7164_dumphex16(dev, buf, sizeof(buf)); |
| 1368 | memcpy(data, (buf + 2 * sizeof(u32) + reglen), datalen); |
| 1369 | } |
| 1370 | |
| 1371 | return ret == SAA_OK ? 0 : -EIO; |
| 1372 | } |
| 1373 | |
| 1374 | /* For a given 8 bit i2c address device, write the buffer */ |
| 1375 | int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen, |
| 1376 | u8 *data) |
| 1377 | { |
| 1378 | struct saa7164_dev *dev = bus->dev; |
| 1379 | u16 len = 0; |
| 1380 | int unitid; |
| 1381 | int reglen; |
| 1382 | u8 buf[256]; |
| 1383 | int ret; |
| 1384 | |
| 1385 | dprintk(DBGLVL_API, "%s()\n", __func__); |
| 1386 | |
| 1387 | if ((datalen == 0) || (datalen > 232)) |
| 1388 | return -EIO; |
| 1389 | |
| 1390 | memset(buf, 0, sizeof(buf)); |
| 1391 | |
| 1392 | unitid = saa7164_i2caddr_to_unitid(bus, addr); |
| 1393 | if (unitid < 0) { |
| 1394 | printk(KERN_ERR |
| 1395 | "%s() error, cannot translate regaddr 0x%x to unitid\n", |
| 1396 | __func__, addr); |
| 1397 | return -EIO; |
| 1398 | } |
| 1399 | |
| 1400 | reglen = saa7164_i2caddr_to_reglen(bus, addr); |
Roel Kluin | ad69551 | 2010-01-03 14:04:42 -0300 | [diff] [blame] | 1401 | if (reglen < 0) { |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1402 | printk(KERN_ERR |
| 1403 | "%s() error, cannot translate regaddr to reglen\n", |
| 1404 | __func__); |
| 1405 | return -EIO; |
| 1406 | } |
| 1407 | |
| 1408 | ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN, |
| 1409 | EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len); |
| 1410 | if (ret != SAA_OK) { |
| 1411 | printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret); |
| 1412 | return -EIO; |
| 1413 | } |
| 1414 | |
| 1415 | dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len); |
| 1416 | |
| 1417 | /* Prepare the send buffer */ |
| 1418 | /* Bytes 00-03 dest register length |
| 1419 | * 04-07 dest bytes to write |
| 1420 | * 08... register address |
| 1421 | */ |
| 1422 | *((u32 *)(buf + 0 * sizeof(u32))) = reglen; |
| 1423 | *((u32 *)(buf + 1 * sizeof(u32))) = datalen - reglen; |
| 1424 | memcpy((buf + 2 * sizeof(u32)), data, datalen); |
| 1425 | |
Ingo Molnar | b1912a85 | 2009-09-21 15:23:45 -0300 | [diff] [blame] | 1426 | if (saa_debug & DBGLVL_I2C) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1427 | saa7164_dumphex16(dev, buf, sizeof(buf)); |
| 1428 | |
| 1429 | ret = saa7164_cmd_send(bus->dev, unitid, SET_CUR, |
| 1430 | EXU_REGISTER_ACCESS_CONTROL, len, &buf); |
| 1431 | if (ret != SAA_OK) |
| 1432 | printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret); |
| 1433 | |
| 1434 | return ret == SAA_OK ? 0 : -EIO; |
| 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | int saa7164_api_modify_gpio(struct saa7164_dev *dev, u8 unitid, |
| 1439 | u8 pin, u8 state) |
| 1440 | { |
| 1441 | int ret; |
| 1442 | tmComResGPIO_t t; |
| 1443 | |
| 1444 | dprintk(DBGLVL_API, "%s(0x%x, %d, %d)\n", |
| 1445 | __func__, unitid, pin, state); |
| 1446 | |
| 1447 | if ((pin > 7) || (state > 2)) |
| 1448 | return SAA_ERR_BAD_PARAMETER; |
| 1449 | |
| 1450 | t.pin = pin; |
| 1451 | t.state = state; |
| 1452 | |
| 1453 | ret = saa7164_cmd_send(dev, unitid, SET_CUR, |
| 1454 | EXU_GPIO_CONTROL, sizeof(t), &t); |
| 1455 | if (ret != SAA_OK) |
| 1456 | printk(KERN_ERR "%s() error, ret = 0x%x\n", |
| 1457 | __func__, ret); |
| 1458 | |
| 1459 | return ret; |
| 1460 | } |
| 1461 | |
| 1462 | int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, |
| 1463 | u8 pin) |
| 1464 | { |
| 1465 | return saa7164_api_modify_gpio(dev, unitid, pin, 1); |
| 1466 | } |
| 1467 | |
| 1468 | int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, |
| 1469 | u8 pin) |
| 1470 | { |
| 1471 | return saa7164_api_modify_gpio(dev, unitid, pin, 0); |
| 1472 | } |
| 1473 | |
| 1474 | |
| 1475 | |