Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Sony Computer Entertainment Inc. |
| 3 | * Copyright 2006, 2007 Sony Corporation |
| 4 | * |
| 5 | * AV backend support for PS3 |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <asm/ps3av.h> |
Geert Uytterhoeven | 0465f790 | 2007-02-12 00:55:25 -0800 | [diff] [blame] | 25 | #include <asm/ps3fb.h> |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 26 | #include <asm/ps3.h> |
| 27 | |
| 28 | #include "vuart.h" |
| 29 | |
| 30 | static const struct video_fmt { |
| 31 | u32 format; |
| 32 | u32 order; |
| 33 | } ps3av_video_fmt_table[] = { |
| 34 | { PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_RGB }, |
| 35 | { PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_BGR }, |
| 36 | }; |
| 37 | |
| 38 | static const struct { |
| 39 | int cs; |
| 40 | u32 av; |
| 41 | u32 bl; |
| 42 | } ps3av_cs_video2av_table[] = { |
| 43 | { |
| 44 | .cs = PS3AV_CMD_VIDEO_CS_RGB_8, |
| 45 | .av = PS3AV_CMD_AV_CS_RGB_8, |
| 46 | .bl = PS3AV_CMD_AV_CS_8 |
| 47 | }, { |
| 48 | .cs = PS3AV_CMD_VIDEO_CS_RGB_10, |
| 49 | .av = PS3AV_CMD_AV_CS_RGB_8, |
| 50 | .bl = PS3AV_CMD_AV_CS_8 |
| 51 | }, { |
| 52 | .cs = PS3AV_CMD_VIDEO_CS_RGB_12, |
| 53 | .av = PS3AV_CMD_AV_CS_RGB_8, |
| 54 | .bl = PS3AV_CMD_AV_CS_8 |
| 55 | }, { |
| 56 | .cs = PS3AV_CMD_VIDEO_CS_YUV444_8, |
| 57 | .av = PS3AV_CMD_AV_CS_YUV444_8, |
| 58 | .bl = PS3AV_CMD_AV_CS_8 |
| 59 | }, { |
| 60 | .cs = PS3AV_CMD_VIDEO_CS_YUV444_10, |
| 61 | .av = PS3AV_CMD_AV_CS_YUV444_8, |
| 62 | .bl = PS3AV_CMD_AV_CS_10 |
| 63 | }, { |
| 64 | .cs = PS3AV_CMD_VIDEO_CS_YUV444_12, |
| 65 | .av = PS3AV_CMD_AV_CS_YUV444_8, |
| 66 | .bl = PS3AV_CMD_AV_CS_10 |
| 67 | }, { |
| 68 | .cs = PS3AV_CMD_VIDEO_CS_YUV422_8, |
| 69 | .av = PS3AV_CMD_AV_CS_YUV422_8, |
| 70 | .bl = PS3AV_CMD_AV_CS_10 |
| 71 | }, { |
| 72 | .cs = PS3AV_CMD_VIDEO_CS_YUV422_10, |
| 73 | .av = PS3AV_CMD_AV_CS_YUV422_8, |
| 74 | .bl = PS3AV_CMD_AV_CS_10 |
| 75 | }, { |
| 76 | .cs = PS3AV_CMD_VIDEO_CS_YUV422_12, |
| 77 | .av = PS3AV_CMD_AV_CS_YUV422_8, |
| 78 | .bl = PS3AV_CMD_AV_CS_12 |
| 79 | }, { |
| 80 | .cs = PS3AV_CMD_VIDEO_CS_XVYCC_8, |
| 81 | .av = PS3AV_CMD_AV_CS_XVYCC_8, |
| 82 | .bl = PS3AV_CMD_AV_CS_12 |
| 83 | }, { |
| 84 | .cs = PS3AV_CMD_VIDEO_CS_XVYCC_10, |
| 85 | .av = PS3AV_CMD_AV_CS_XVYCC_8, |
| 86 | .bl = PS3AV_CMD_AV_CS_12 |
| 87 | }, { |
| 88 | .cs = PS3AV_CMD_VIDEO_CS_XVYCC_12, |
| 89 | .av = PS3AV_CMD_AV_CS_XVYCC_8, |
| 90 | .bl = PS3AV_CMD_AV_CS_12 |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | static u32 ps3av_cs_video2av(int cs) |
| 95 | { |
| 96 | unsigned int i; |
| 97 | |
| 98 | for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++) |
| 99 | if (ps3av_cs_video2av_table[i].cs == cs) |
| 100 | return ps3av_cs_video2av_table[i].av; |
| 101 | |
| 102 | return PS3AV_CMD_AV_CS_RGB_8; |
| 103 | } |
| 104 | |
| 105 | static u32 ps3av_cs_video2av_bitlen(int cs) |
| 106 | { |
| 107 | unsigned int i; |
| 108 | |
| 109 | for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++) |
| 110 | if (ps3av_cs_video2av_table[i].cs == cs) |
| 111 | return ps3av_cs_video2av_table[i].bl; |
| 112 | |
| 113 | return PS3AV_CMD_AV_CS_8; |
| 114 | } |
| 115 | |
| 116 | static const struct { |
| 117 | int vid; |
| 118 | u32 av; |
| 119 | } ps3av_vid_video2av_table[] = { |
| 120 | { PS3AV_CMD_VIDEO_VID_480I, PS3AV_CMD_AV_VID_480I }, |
| 121 | { PS3AV_CMD_VIDEO_VID_480P, PS3AV_CMD_AV_VID_480P }, |
| 122 | { PS3AV_CMD_VIDEO_VID_576I, PS3AV_CMD_AV_VID_576I }, |
| 123 | { PS3AV_CMD_VIDEO_VID_576P, PS3AV_CMD_AV_VID_576P }, |
| 124 | { PS3AV_CMD_VIDEO_VID_1080I_60HZ, PS3AV_CMD_AV_VID_1080I_60HZ }, |
| 125 | { PS3AV_CMD_VIDEO_VID_720P_60HZ, PS3AV_CMD_AV_VID_720P_60HZ }, |
| 126 | { PS3AV_CMD_VIDEO_VID_1080P_60HZ, PS3AV_CMD_AV_VID_1080P_60HZ }, |
| 127 | { PS3AV_CMD_VIDEO_VID_1080I_50HZ, PS3AV_CMD_AV_VID_1080I_50HZ }, |
| 128 | { PS3AV_CMD_VIDEO_VID_720P_50HZ, PS3AV_CMD_AV_VID_720P_50HZ }, |
| 129 | { PS3AV_CMD_VIDEO_VID_1080P_50HZ, PS3AV_CMD_AV_VID_1080P_50HZ }, |
| 130 | { PS3AV_CMD_VIDEO_VID_WXGA, PS3AV_CMD_AV_VID_WXGA }, |
| 131 | { PS3AV_CMD_VIDEO_VID_SXGA, PS3AV_CMD_AV_VID_SXGA }, |
| 132 | { PS3AV_CMD_VIDEO_VID_WUXGA, PS3AV_CMD_AV_VID_WUXGA } |
| 133 | }; |
| 134 | |
| 135 | static u32 ps3av_vid_video2av(int vid) |
| 136 | { |
| 137 | unsigned int i; |
| 138 | |
| 139 | for (i = 0; i < ARRAY_SIZE(ps3av_vid_video2av_table); i++) |
| 140 | if (ps3av_vid_video2av_table[i].vid == vid) |
| 141 | return ps3av_vid_video2av_table[i].av; |
| 142 | |
| 143 | return PS3AV_CMD_AV_VID_480P; |
| 144 | } |
| 145 | |
Masashi Kimoto | dc23fba | 2007-06-16 07:19:10 +1000 | [diff] [blame] | 146 | static int ps3av_hdmi_range(void) |
| 147 | { |
| 148 | if (ps3_compare_firmware_version(1, 8, 0) < 0) |
| 149 | return 0; |
| 150 | else |
| 151 | return 1; /* supported */ |
| 152 | } |
| 153 | |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 154 | int ps3av_cmd_init(void) |
| 155 | { |
| 156 | int res; |
| 157 | struct ps3av_pkt_av_init av_init; |
| 158 | struct ps3av_pkt_video_init video_init; |
| 159 | struct ps3av_pkt_audio_init audio_init; |
| 160 | |
| 161 | /* video init */ |
| 162 | memset(&video_init, 0, sizeof(video_init)); |
| 163 | |
| 164 | res = ps3av_do_pkt(PS3AV_CID_VIDEO_INIT, sizeof(video_init.send_hdr), |
| 165 | sizeof(video_init), &video_init.send_hdr); |
| 166 | if (res < 0) |
| 167 | return res; |
| 168 | |
| 169 | res = get_status(&video_init); |
| 170 | if (res) { |
| 171 | printk(KERN_ERR "PS3AV_CID_VIDEO_INIT: failed %x\n", res); |
| 172 | return res; |
| 173 | } |
| 174 | |
| 175 | /* audio init */ |
| 176 | memset(&audio_init, 0, sizeof(audio_init)); |
| 177 | |
| 178 | res = ps3av_do_pkt(PS3AV_CID_AUDIO_INIT, sizeof(audio_init.send_hdr), |
| 179 | sizeof(audio_init), &audio_init.send_hdr); |
| 180 | if (res < 0) |
| 181 | return res; |
| 182 | |
| 183 | res = get_status(&audio_init); |
| 184 | if (res) { |
| 185 | printk(KERN_ERR "PS3AV_CID_AUDIO_INIT: failed %x\n", res); |
| 186 | return res; |
| 187 | } |
| 188 | |
| 189 | /* av init */ |
| 190 | memset(&av_init, 0, sizeof(av_init)); |
| 191 | av_init.event_bit = 0; |
| 192 | |
| 193 | res = ps3av_do_pkt(PS3AV_CID_AV_INIT, sizeof(av_init), sizeof(av_init), |
| 194 | &av_init.send_hdr); |
| 195 | if (res < 0) |
| 196 | return res; |
| 197 | |
| 198 | res = get_status(&av_init); |
| 199 | if (res) |
| 200 | printk(KERN_ERR "PS3AV_CID_AV_INIT: failed %x\n", res); |
| 201 | |
| 202 | return res; |
| 203 | } |
| 204 | |
| 205 | int ps3av_cmd_fin(void) |
| 206 | { |
| 207 | int res; |
| 208 | struct ps3av_pkt_av_fin av_fin; |
| 209 | |
| 210 | memset(&av_fin, 0, sizeof(av_fin)); |
| 211 | |
| 212 | res = ps3av_do_pkt(PS3AV_CID_AV_FIN, sizeof(av_fin.send_hdr), |
| 213 | sizeof(av_fin), &av_fin.send_hdr); |
| 214 | if (res < 0) |
| 215 | return res; |
| 216 | |
| 217 | res = get_status(&av_fin); |
| 218 | if (res) |
| 219 | printk(KERN_ERR "PS3AV_CID_AV_FIN: failed %x\n", res); |
| 220 | |
| 221 | return res; |
| 222 | } |
| 223 | |
| 224 | int ps3av_cmd_av_video_mute(int num_of_port, u32 *port, u32 mute) |
| 225 | { |
| 226 | int i, send_len, res; |
| 227 | struct ps3av_pkt_av_video_mute av_video_mute; |
| 228 | |
| 229 | if (num_of_port > PS3AV_MUTE_PORT_MAX) |
| 230 | return -EINVAL; |
| 231 | |
| 232 | memset(&av_video_mute, 0, sizeof(av_video_mute)); |
| 233 | for (i = 0; i < num_of_port; i++) { |
| 234 | av_video_mute.mute[i].avport = port[i]; |
| 235 | av_video_mute.mute[i].mute = mute; |
| 236 | } |
| 237 | |
| 238 | send_len = sizeof(av_video_mute.send_hdr) + |
| 239 | sizeof(struct ps3av_av_mute) * num_of_port; |
| 240 | res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_MUTE, send_len, |
| 241 | sizeof(av_video_mute), &av_video_mute.send_hdr); |
| 242 | if (res < 0) |
| 243 | return res; |
| 244 | |
| 245 | res = get_status(&av_video_mute); |
| 246 | if (res) |
| 247 | printk(KERN_ERR "PS3AV_CID_AV_VIDEO_MUTE: failed %x\n", res); |
| 248 | |
| 249 | return res; |
| 250 | } |
| 251 | |
| 252 | int ps3av_cmd_av_video_disable_sig(u32 port) |
| 253 | { |
| 254 | int res; |
| 255 | struct ps3av_pkt_av_video_disable_sig av_video_sig; |
| 256 | |
| 257 | memset(&av_video_sig, 0, sizeof(av_video_sig)); |
| 258 | av_video_sig.avport = port; |
| 259 | |
| 260 | res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_DISABLE_SIG, |
| 261 | sizeof(av_video_sig), sizeof(av_video_sig), |
| 262 | &av_video_sig.send_hdr); |
| 263 | if (res < 0) |
| 264 | return res; |
| 265 | |
| 266 | res = get_status(&av_video_sig); |
| 267 | if (res) |
| 268 | printk(KERN_ERR |
| 269 | "PS3AV_CID_AV_VIDEO_DISABLE_SIG: failed %x port:%x\n", |
| 270 | res, port); |
| 271 | |
| 272 | return res; |
| 273 | } |
| 274 | |
| 275 | int ps3av_cmd_av_tv_mute(u32 avport, u32 mute) |
| 276 | { |
| 277 | int res; |
| 278 | struct ps3av_pkt_av_tv_mute tv_mute; |
| 279 | |
| 280 | memset(&tv_mute, 0, sizeof(tv_mute)); |
| 281 | tv_mute.avport = avport; |
| 282 | tv_mute.mute = mute; |
| 283 | |
| 284 | res = ps3av_do_pkt(PS3AV_CID_AV_TV_MUTE, sizeof(tv_mute), |
| 285 | sizeof(tv_mute), &tv_mute.send_hdr); |
| 286 | if (res < 0) |
| 287 | return res; |
| 288 | |
| 289 | res = get_status(&tv_mute); |
| 290 | if (res) |
| 291 | printk(KERN_ERR "PS3AV_CID_AV_TV_MUTE: failed %x port:%x\n", |
| 292 | res, avport); |
| 293 | |
| 294 | return res; |
| 295 | } |
| 296 | |
| 297 | int ps3av_cmd_enable_event(void) |
| 298 | { |
| 299 | int res; |
| 300 | struct ps3av_pkt_av_event av_event; |
| 301 | |
| 302 | memset(&av_event, 0, sizeof(av_event)); |
| 303 | av_event.event_bit = PS3AV_CMD_EVENT_BIT_UNPLUGGED | |
| 304 | PS3AV_CMD_EVENT_BIT_PLUGGED | PS3AV_CMD_EVENT_BIT_HDCP_DONE; |
| 305 | |
| 306 | res = ps3av_do_pkt(PS3AV_CID_AV_ENABLE_EVENT, sizeof(av_event), |
| 307 | sizeof(av_event), &av_event.send_hdr); |
| 308 | if (res < 0) |
| 309 | return res; |
| 310 | |
| 311 | res = get_status(&av_event); |
| 312 | if (res) |
| 313 | printk(KERN_ERR "PS3AV_CID_AV_ENABLE_EVENT: failed %x\n", res); |
| 314 | |
| 315 | return res; |
| 316 | } |
| 317 | |
| 318 | int ps3av_cmd_av_hdmi_mode(u8 mode) |
| 319 | { |
| 320 | int res; |
| 321 | struct ps3av_pkt_av_hdmi_mode hdmi_mode; |
| 322 | |
| 323 | memset(&hdmi_mode, 0, sizeof(hdmi_mode)); |
| 324 | hdmi_mode.mode = mode; |
| 325 | |
| 326 | res = ps3av_do_pkt(PS3AV_CID_AV_HDMI_MODE, sizeof(hdmi_mode), |
| 327 | sizeof(hdmi_mode), &hdmi_mode.send_hdr); |
| 328 | if (res < 0) |
| 329 | return res; |
| 330 | |
| 331 | res = get_status(&hdmi_mode); |
| 332 | if (res && res != PS3AV_STATUS_UNSUPPORTED_HDMI_MODE) |
| 333 | printk(KERN_ERR "PS3AV_CID_AV_HDMI_MODE: failed %x\n", res); |
| 334 | |
| 335 | return res; |
| 336 | } |
| 337 | |
| 338 | u32 ps3av_cmd_set_av_video_cs(void *p, u32 avport, int video_vid, int cs_out, |
| 339 | int aspect, u32 id) |
| 340 | { |
| 341 | struct ps3av_pkt_av_video_cs *av_video_cs; |
| 342 | |
| 343 | av_video_cs = (struct ps3av_pkt_av_video_cs *)p; |
| 344 | if (video_vid == -1) |
| 345 | video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ; |
| 346 | if (cs_out == -1) |
| 347 | cs_out = PS3AV_CMD_VIDEO_CS_YUV444_8; |
| 348 | if (aspect == -1) |
| 349 | aspect = 0; |
| 350 | |
| 351 | memset(av_video_cs, 0, sizeof(*av_video_cs)); |
| 352 | ps3av_set_hdr(PS3AV_CID_AV_VIDEO_CS, sizeof(*av_video_cs), |
| 353 | &av_video_cs->send_hdr); |
| 354 | av_video_cs->avport = avport; |
| 355 | /* should be same as video_mode.resolution */ |
| 356 | av_video_cs->av_vid = ps3av_vid_video2av(video_vid); |
| 357 | av_video_cs->av_cs_out = ps3av_cs_video2av(cs_out); |
| 358 | /* should be same as video_mode.video_cs_out */ |
| 359 | av_video_cs->av_cs_in = ps3av_cs_video2av(PS3AV_CMD_VIDEO_CS_RGB_8); |
| 360 | av_video_cs->bitlen_out = ps3av_cs_video2av_bitlen(cs_out); |
Masashi Kimoto | dc23fba | 2007-06-16 07:19:10 +1000 | [diff] [blame] | 361 | if ((id & PS3AV_MODE_WHITE) && ps3av_hdmi_range()) |
| 362 | av_video_cs->super_white = PS3AV_CMD_AV_SUPER_WHITE_ON; |
| 363 | else /* default off */ |
| 364 | av_video_cs->super_white = PS3AV_CMD_AV_SUPER_WHITE_OFF; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 365 | av_video_cs->aspect = aspect; |
| 366 | if (id & PS3AV_MODE_DITHER) { |
| 367 | av_video_cs->dither = PS3AV_CMD_AV_DITHER_ON |
| 368 | | PS3AV_CMD_AV_DITHER_8BIT; |
| 369 | } else { |
| 370 | /* default off */ |
| 371 | av_video_cs->dither = PS3AV_CMD_AV_DITHER_OFF; |
| 372 | } |
| 373 | |
| 374 | return sizeof(*av_video_cs); |
| 375 | } |
| 376 | |
| 377 | u32 ps3av_cmd_set_video_mode(void *p, u32 head, int video_vid, int video_fmt, |
| 378 | u32 id) |
| 379 | { |
| 380 | struct ps3av_pkt_video_mode *video_mode; |
| 381 | u32 x, y; |
| 382 | |
| 383 | video_mode = (struct ps3av_pkt_video_mode *)p; |
| 384 | if (video_vid == -1) |
| 385 | video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ; |
| 386 | if (video_fmt == -1) |
| 387 | video_fmt = PS3AV_CMD_VIDEO_FMT_X8R8G8B8; |
| 388 | |
| 389 | if (ps3av_video_mode2res(id, &x, &y)) |
| 390 | return 0; |
| 391 | |
| 392 | /* video mode */ |
| 393 | memset(video_mode, 0, sizeof(*video_mode)); |
| 394 | ps3av_set_hdr(PS3AV_CID_VIDEO_MODE, sizeof(*video_mode), |
| 395 | &video_mode->send_hdr); |
| 396 | video_mode->video_head = head; |
| 397 | if (video_vid == PS3AV_CMD_VIDEO_VID_480I |
| 398 | && head == PS3AV_CMD_VIDEO_HEAD_B) |
| 399 | video_mode->video_vid = PS3AV_CMD_VIDEO_VID_480I_A; |
| 400 | else |
| 401 | video_mode->video_vid = video_vid; |
| 402 | video_mode->width = (u16) x; |
| 403 | video_mode->height = (u16) y; |
| 404 | video_mode->pitch = video_mode->width * 4; /* line_length */ |
| 405 | video_mode->video_out_format = PS3AV_CMD_VIDEO_OUT_FORMAT_RGB_12BIT; |
| 406 | video_mode->video_format = ps3av_video_fmt_table[video_fmt].format; |
Masashi Kimoto | dc23fba | 2007-06-16 07:19:10 +1000 | [diff] [blame] | 407 | if ((id & PS3AV_MODE_COLOR) && ps3av_hdmi_range()) |
| 408 | video_mode->video_cl_cnv = PS3AV_CMD_VIDEO_CL_CNV_DISABLE_LUT; |
| 409 | else /* default enable */ |
| 410 | video_mode->video_cl_cnv = PS3AV_CMD_VIDEO_CL_CNV_ENABLE_LUT; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 411 | video_mode->video_order = ps3av_video_fmt_table[video_fmt].order; |
| 412 | |
| 413 | pr_debug("%s: video_mode:vid:%x width:%d height:%d pitch:%d out_format:%d format:%x order:%x\n", |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 414 | __func__, video_vid, video_mode->width, video_mode->height, |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 415 | video_mode->pitch, video_mode->video_out_format, |
| 416 | video_mode->video_format, video_mode->video_order); |
| 417 | return sizeof(*video_mode); |
| 418 | } |
| 419 | |
| 420 | int ps3av_cmd_video_format_black(u32 head, u32 video_fmt, u32 mute) |
| 421 | { |
| 422 | int res; |
| 423 | struct ps3av_pkt_video_format video_format; |
| 424 | |
| 425 | memset(&video_format, 0, sizeof(video_format)); |
| 426 | video_format.video_head = head; |
| 427 | if (mute != PS3AV_CMD_MUTE_OFF) |
| 428 | video_format.video_format = PS3AV_CMD_VIDEO_FORMAT_BLACK; |
| 429 | else |
| 430 | video_format.video_format = |
| 431 | ps3av_video_fmt_table[video_fmt].format; |
| 432 | video_format.video_order = ps3av_video_fmt_table[video_fmt].order; |
| 433 | |
| 434 | res = ps3av_do_pkt(PS3AV_CID_VIDEO_FORMAT, sizeof(video_format), |
| 435 | sizeof(video_format), &video_format.send_hdr); |
| 436 | if (res < 0) |
| 437 | return res; |
| 438 | |
| 439 | res = get_status(&video_format); |
| 440 | if (res) |
| 441 | printk(KERN_ERR "PS3AV_CID_VIDEO_FORMAT: failed %x\n", res); |
| 442 | |
| 443 | return res; |
| 444 | } |
| 445 | |
| 446 | |
| 447 | int ps3av_cmd_av_audio_mute(int num_of_port, u32 *port, u32 mute) |
| 448 | { |
| 449 | int i, res; |
| 450 | struct ps3av_pkt_av_audio_mute av_audio_mute; |
| 451 | |
| 452 | if (num_of_port > PS3AV_MUTE_PORT_MAX) |
| 453 | return -EINVAL; |
| 454 | |
| 455 | /* audio mute */ |
| 456 | memset(&av_audio_mute, 0, sizeof(av_audio_mute)); |
| 457 | for (i = 0; i < num_of_port; i++) { |
| 458 | av_audio_mute.mute[i].avport = port[i]; |
| 459 | av_audio_mute.mute[i].mute = mute; |
| 460 | } |
| 461 | |
| 462 | res = ps3av_do_pkt(PS3AV_CID_AV_AUDIO_MUTE, |
| 463 | sizeof(av_audio_mute.send_hdr) + |
| 464 | sizeof(struct ps3av_av_mute) * num_of_port, |
| 465 | sizeof(av_audio_mute), &av_audio_mute.send_hdr); |
| 466 | if (res < 0) |
| 467 | return res; |
| 468 | |
| 469 | res = get_status(&av_audio_mute); |
| 470 | if (res) |
| 471 | printk(KERN_ERR "PS3AV_CID_AV_AUDIO_MUTE: failed %x\n", res); |
| 472 | |
| 473 | return res; |
| 474 | } |
| 475 | |
| 476 | static const struct { |
| 477 | u32 fs; |
| 478 | u8 mclk; |
| 479 | } ps3av_cnv_mclk_table[] = { |
| 480 | { PS3AV_CMD_AUDIO_FS_44K, PS3AV_CMD_AV_MCLK_512 }, |
| 481 | { PS3AV_CMD_AUDIO_FS_48K, PS3AV_CMD_AV_MCLK_512 }, |
| 482 | { PS3AV_CMD_AUDIO_FS_88K, PS3AV_CMD_AV_MCLK_256 }, |
| 483 | { PS3AV_CMD_AUDIO_FS_96K, PS3AV_CMD_AV_MCLK_256 }, |
| 484 | { PS3AV_CMD_AUDIO_FS_176K, PS3AV_CMD_AV_MCLK_128 }, |
| 485 | { PS3AV_CMD_AUDIO_FS_192K, PS3AV_CMD_AV_MCLK_128 } |
| 486 | }; |
| 487 | |
| 488 | static u8 ps3av_cnv_mclk(u32 fs) |
| 489 | { |
| 490 | unsigned int i; |
| 491 | |
| 492 | for (i = 0; i < ARRAY_SIZE(ps3av_cnv_mclk_table); i++) |
| 493 | if (ps3av_cnv_mclk_table[i].fs == fs) |
| 494 | return ps3av_cnv_mclk_table[i].mclk; |
| 495 | |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 496 | printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | #define BASE PS3AV_CMD_AUDIO_FS_44K |
| 501 | |
| 502 | static const u32 ps3av_ns_table[][5] = { |
| 503 | /* D1, D2, D3, D4, D5 */ |
Al Viro | dfdcbcc | 2007-03-14 09:19:30 +0000 | [diff] [blame] | 504 | [PS3AV_CMD_AUDIO_FS_44K-BASE] = { 6272, 6272, 17836, 17836, 8918 }, |
| 505 | [PS3AV_CMD_AUDIO_FS_48K-BASE] = { 6144, 6144, 11648, 11648, 5824 }, |
| 506 | [PS3AV_CMD_AUDIO_FS_88K-BASE] = { 12544, 12544, 35672, 35672, 17836 }, |
| 507 | [PS3AV_CMD_AUDIO_FS_96K-BASE] = { 12288, 12288, 23296, 23296, 11648 }, |
| 508 | [PS3AV_CMD_AUDIO_FS_176K-BASE] = { 25088, 25088, 71344, 71344, 35672 }, |
| 509 | [PS3AV_CMD_AUDIO_FS_192K-BASE] = { 24576, 24576, 46592, 46592, 23296 } |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 510 | }; |
| 511 | |
| 512 | static void ps3av_cnv_ns(u8 *ns, u32 fs, u32 video_vid) |
| 513 | { |
| 514 | u32 av_vid, ns_val; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 515 | int d; |
| 516 | |
| 517 | d = ns_val = 0; |
| 518 | av_vid = ps3av_vid_video2av(video_vid); |
| 519 | switch (av_vid) { |
| 520 | case PS3AV_CMD_AV_VID_480I: |
| 521 | case PS3AV_CMD_AV_VID_576I: |
| 522 | d = 0; |
| 523 | break; |
| 524 | case PS3AV_CMD_AV_VID_480P: |
| 525 | case PS3AV_CMD_AV_VID_576P: |
| 526 | d = 1; |
| 527 | break; |
| 528 | case PS3AV_CMD_AV_VID_1080I_60HZ: |
| 529 | case PS3AV_CMD_AV_VID_1080I_50HZ: |
| 530 | d = 2; |
| 531 | break; |
| 532 | case PS3AV_CMD_AV_VID_720P_60HZ: |
| 533 | case PS3AV_CMD_AV_VID_720P_50HZ: |
| 534 | d = 3; |
| 535 | break; |
| 536 | case PS3AV_CMD_AV_VID_1080P_60HZ: |
| 537 | case PS3AV_CMD_AV_VID_1080P_50HZ: |
| 538 | case PS3AV_CMD_AV_VID_WXGA: |
| 539 | case PS3AV_CMD_AV_VID_SXGA: |
| 540 | case PS3AV_CMD_AV_VID_WUXGA: |
| 541 | d = 4; |
| 542 | break; |
| 543 | default: |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 544 | printk(KERN_ERR "%s failed, vid:%x\n", __func__, video_vid); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 545 | break; |
| 546 | } |
| 547 | |
| 548 | if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K) |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 549 | printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 550 | else |
| 551 | ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d]; |
| 552 | |
Geert Uytterhoeven | 828b23f | 2007-10-16 01:29:40 -0700 | [diff] [blame] | 553 | *ns++ = ns_val & 0x000000FF; |
| 554 | *ns++ = (ns_val & 0x0000FF00) >> 8; |
| 555 | *ns = (ns_val & 0x00FF0000) >> 16; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | #undef BASE |
| 559 | |
Al Viro | dfdcbcc | 2007-03-14 09:19:30 +0000 | [diff] [blame] | 560 | static u8 ps3av_cnv_enable(u32 source, const u8 *enable) |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 561 | { |
Al Viro | dfdcbcc | 2007-03-14 09:19:30 +0000 | [diff] [blame] | 562 | u8 ret = 0; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 563 | |
| 564 | if (source == PS3AV_CMD_AUDIO_SOURCE_SPDIF) { |
| 565 | ret = 0x03; |
| 566 | } else if (source == PS3AV_CMD_AUDIO_SOURCE_SERIAL) { |
Geert Uytterhoeven | 828b23f | 2007-10-16 01:29:40 -0700 | [diff] [blame] | 567 | ret = ((enable[0] << 4) + (enable[1] << 5) + (enable[2] << 6) + |
| 568 | (enable[3] << 7)) | 0x01; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 569 | } else |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 570 | printk(KERN_ERR "%s failed, source:%x\n", __func__, source); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 571 | return ret; |
| 572 | } |
| 573 | |
Al Viro | dfdcbcc | 2007-03-14 09:19:30 +0000 | [diff] [blame] | 574 | static u8 ps3av_cnv_fifomap(const u8 *map) |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 575 | { |
Al Viro | dfdcbcc | 2007-03-14 09:19:30 +0000 | [diff] [blame] | 576 | u8 ret = 0; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 577 | |
Geert Uytterhoeven | 828b23f | 2007-10-16 01:29:40 -0700 | [diff] [blame] | 578 | ret = map[0] + (map[1] << 2) + (map[2] << 4) + (map[3] << 6); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | static u8 ps3av_cnv_inputlen(u32 word_bits) |
| 583 | { |
| 584 | u8 ret = 0; |
| 585 | |
| 586 | switch (word_bits) { |
| 587 | case PS3AV_CMD_AUDIO_WORD_BITS_16: |
| 588 | ret = PS3AV_CMD_AV_INPUTLEN_16; |
| 589 | break; |
| 590 | case PS3AV_CMD_AUDIO_WORD_BITS_20: |
| 591 | ret = PS3AV_CMD_AV_INPUTLEN_20; |
| 592 | break; |
| 593 | case PS3AV_CMD_AUDIO_WORD_BITS_24: |
| 594 | ret = PS3AV_CMD_AV_INPUTLEN_24; |
| 595 | break; |
| 596 | default: |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 597 | printk(KERN_ERR "%s failed, word_bits:%x\n", __func__, |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 598 | word_bits); |
| 599 | break; |
| 600 | } |
| 601 | return ret; |
| 602 | } |
| 603 | |
| 604 | static u8 ps3av_cnv_layout(u32 num_of_ch) |
| 605 | { |
| 606 | if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) { |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 607 | printk(KERN_ERR "%s failed, num_of_ch:%x\n", __func__, |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 608 | num_of_ch); |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | return num_of_ch == PS3AV_CMD_AUDIO_NUM_OF_CH_2 ? 0x0 : 0x1; |
| 613 | } |
| 614 | |
| 615 | static void ps3av_cnv_info(struct ps3av_audio_info_frame *info, |
| 616 | const struct ps3av_pkt_audio_mode *mode) |
| 617 | { |
| 618 | info->pb1.cc = mode->audio_num_of_ch + 1; /* CH2:0x01 --- CH8:0x07 */ |
| 619 | info->pb1.ct = 0; |
| 620 | info->pb2.sf = 0; |
| 621 | info->pb2.ss = 0; |
| 622 | |
| 623 | info->pb3 = 0; /* check mode->audio_format ?? */ |
| 624 | info->pb4 = mode->audio_layout; |
| 625 | info->pb5.dm = mode->audio_downmix; |
| 626 | info->pb5.lsv = mode->audio_downmix_level; |
| 627 | } |
| 628 | |
Al Viro | dfdcbcc | 2007-03-14 09:19:30 +0000 | [diff] [blame] | 629 | static void ps3av_cnv_chstat(u8 *chstat, const u8 *cs_info) |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 630 | { |
| 631 | memcpy(chstat, cs_info, 5); |
| 632 | } |
| 633 | |
| 634 | u32 ps3av_cmd_set_av_audio_param(void *p, u32 port, |
| 635 | const struct ps3av_pkt_audio_mode *audio_mode, |
| 636 | u32 video_vid) |
| 637 | { |
| 638 | struct ps3av_pkt_av_audio_param *param; |
| 639 | |
| 640 | param = (struct ps3av_pkt_av_audio_param *)p; |
| 641 | |
| 642 | memset(param, 0, sizeof(*param)); |
| 643 | ps3av_set_hdr(PS3AV_CID_AV_AUDIO_PARAM, sizeof(*param), |
| 644 | ¶m->send_hdr); |
| 645 | |
| 646 | param->avport = port; |
| 647 | param->mclk = ps3av_cnv_mclk(audio_mode->audio_fs) | 0x80; |
| 648 | ps3av_cnv_ns(param->ns, audio_mode->audio_fs, video_vid); |
| 649 | param->enable = ps3av_cnv_enable(audio_mode->audio_source, |
| 650 | audio_mode->audio_enable); |
| 651 | param->swaplr = 0x09; |
| 652 | param->fifomap = ps3av_cnv_fifomap(audio_mode->audio_map); |
| 653 | param->inputctrl = 0x49; |
| 654 | param->inputlen = ps3av_cnv_inputlen(audio_mode->audio_word_bits); |
| 655 | param->layout = ps3av_cnv_layout(audio_mode->audio_num_of_ch); |
| 656 | ps3av_cnv_info(¶m->info, audio_mode); |
| 657 | ps3av_cnv_chstat(param->chstat, audio_mode->audio_cs_info); |
| 658 | |
| 659 | return sizeof(*param); |
| 660 | } |
| 661 | |
| 662 | /* default cs val */ |
Takashi Iwai | 64931a4 | 2008-10-20 08:05:10 +0200 | [diff] [blame] | 663 | u8 ps3av_mode_cs_info[] = { |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 664 | 0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00 |
| 665 | }; |
Takashi Iwai | 64931a4 | 2008-10-20 08:05:10 +0200 | [diff] [blame] | 666 | EXPORT_SYMBOL_GPL(ps3av_mode_cs_info); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 667 | |
| 668 | #define CS_44 0x00 |
| 669 | #define CS_48 0x02 |
| 670 | #define CS_88 0x08 |
| 671 | #define CS_96 0x0a |
| 672 | #define CS_176 0x0c |
| 673 | #define CS_192 0x0e |
| 674 | #define CS_MASK 0x0f |
| 675 | #define CS_BIT 0x40 |
| 676 | |
| 677 | void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport, |
| 678 | u32 ch, u32 fs, u32 word_bits, u32 format, |
| 679 | u32 source) |
| 680 | { |
Takashi Iwai | 64931a4 | 2008-10-20 08:05:10 +0200 | [diff] [blame] | 681 | int spdif_through; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 682 | int i; |
| 683 | |
| 684 | if (!(ch | fs | format | word_bits | source)) { |
| 685 | ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2; |
| 686 | fs = PS3AV_CMD_AUDIO_FS_48K; |
| 687 | word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16; |
| 688 | format = PS3AV_CMD_AUDIO_FORMAT_PCM; |
| 689 | source = PS3AV_CMD_AUDIO_SOURCE_SERIAL; |
| 690 | } |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 691 | |
| 692 | /* audio mode */ |
| 693 | memset(audio, 0, sizeof(*audio)); |
| 694 | ps3av_set_hdr(PS3AV_CID_AUDIO_MODE, sizeof(*audio), &audio->send_hdr); |
| 695 | |
| 696 | audio->avport = (u8) avport; |
| 697 | audio->mask = 0x0FFF; /* XXX set all */ |
| 698 | audio->audio_num_of_ch = ch; |
| 699 | audio->audio_fs = fs; |
| 700 | audio->audio_word_bits = word_bits; |
| 701 | audio->audio_format = format; |
| 702 | audio->audio_source = source; |
| 703 | |
| 704 | switch (ch) { |
| 705 | case PS3AV_CMD_AUDIO_NUM_OF_CH_8: |
| 706 | audio->audio_enable[3] = 1; |
| 707 | /* fall through */ |
| 708 | case PS3AV_CMD_AUDIO_NUM_OF_CH_6: |
| 709 | audio->audio_enable[2] = 1; |
| 710 | audio->audio_enable[1] = 1; |
| 711 | /* fall through */ |
| 712 | case PS3AV_CMD_AUDIO_NUM_OF_CH_2: |
| 713 | default: |
| 714 | audio->audio_enable[0] = 1; |
| 715 | } |
| 716 | |
| 717 | /* audio swap L/R */ |
| 718 | for (i = 0; i < 4; i++) |
| 719 | audio->audio_swap[i] = PS3AV_CMD_AUDIO_SWAP_0; /* no swap */ |
| 720 | |
| 721 | /* audio serial input mapping */ |
| 722 | audio->audio_map[0] = PS3AV_CMD_AUDIO_MAP_OUTPUT_0; |
| 723 | audio->audio_map[1] = PS3AV_CMD_AUDIO_MAP_OUTPUT_1; |
| 724 | audio->audio_map[2] = PS3AV_CMD_AUDIO_MAP_OUTPUT_2; |
| 725 | audio->audio_map[3] = PS3AV_CMD_AUDIO_MAP_OUTPUT_3; |
| 726 | |
| 727 | /* audio speaker layout */ |
| 728 | if (avport == PS3AV_CMD_AVPORT_HDMI_0 || |
| 729 | avport == PS3AV_CMD_AVPORT_HDMI_1) { |
| 730 | switch (ch) { |
| 731 | case PS3AV_CMD_AUDIO_NUM_OF_CH_8: |
| 732 | audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_8CH; |
| 733 | break; |
| 734 | case PS3AV_CMD_AUDIO_NUM_OF_CH_6: |
| 735 | audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_6CH; |
| 736 | break; |
| 737 | case PS3AV_CMD_AUDIO_NUM_OF_CH_2: |
| 738 | default: |
| 739 | audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH; |
| 740 | break; |
| 741 | } |
| 742 | } else { |
| 743 | audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH; |
| 744 | } |
| 745 | |
| 746 | /* audio downmix permission */ |
| 747 | audio->audio_downmix = PS3AV_CMD_AUDIO_DOWNMIX_PERMITTED; |
| 748 | /* audio downmix level shift (0:0dB to 15:15dB) */ |
| 749 | audio->audio_downmix_level = 0; /* 0dB */ |
| 750 | |
| 751 | /* set ch status */ |
| 752 | for (i = 0; i < 8; i++) |
| 753 | audio->audio_cs_info[i] = ps3av_mode_cs_info[i]; |
| 754 | |
| 755 | switch (fs) { |
| 756 | case PS3AV_CMD_AUDIO_FS_44K: |
| 757 | audio->audio_cs_info[3] &= ~CS_MASK; |
| 758 | audio->audio_cs_info[3] |= CS_44; |
| 759 | break; |
| 760 | case PS3AV_CMD_AUDIO_FS_88K: |
| 761 | audio->audio_cs_info[3] &= ~CS_MASK; |
| 762 | audio->audio_cs_info[3] |= CS_88; |
| 763 | break; |
| 764 | case PS3AV_CMD_AUDIO_FS_96K: |
| 765 | audio->audio_cs_info[3] &= ~CS_MASK; |
| 766 | audio->audio_cs_info[3] |= CS_96; |
| 767 | break; |
| 768 | case PS3AV_CMD_AUDIO_FS_176K: |
| 769 | audio->audio_cs_info[3] &= ~CS_MASK; |
| 770 | audio->audio_cs_info[3] |= CS_176; |
| 771 | break; |
| 772 | case PS3AV_CMD_AUDIO_FS_192K: |
| 773 | audio->audio_cs_info[3] &= ~CS_MASK; |
| 774 | audio->audio_cs_info[3] |= CS_192; |
| 775 | break; |
| 776 | default: |
| 777 | break; |
| 778 | } |
| 779 | |
Takashi Iwai | 64931a4 | 2008-10-20 08:05:10 +0200 | [diff] [blame] | 780 | /* non-audio bit */ |
| 781 | spdif_through = audio->audio_cs_info[0] & 0x02; |
| 782 | |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 783 | /* pass through setting */ |
| 784 | if (spdif_through && |
| 785 | (avport == PS3AV_CMD_AVPORT_SPDIF_0 || |
Takashi Iwai | 64931a4 | 2008-10-20 08:05:10 +0200 | [diff] [blame] | 786 | avport == PS3AV_CMD_AVPORT_SPDIF_1 || |
| 787 | avport == PS3AV_CMD_AVPORT_HDMI_0 || |
| 788 | avport == PS3AV_CMD_AVPORT_HDMI_1)) { |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 789 | audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16; |
Takashi Iwai | 64931a4 | 2008-10-20 08:05:10 +0200 | [diff] [blame] | 790 | audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM; |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
| 794 | int ps3av_cmd_audio_mode(struct ps3av_pkt_audio_mode *audio_mode) |
| 795 | { |
| 796 | int res; |
| 797 | |
| 798 | res = ps3av_do_pkt(PS3AV_CID_AUDIO_MODE, sizeof(*audio_mode), |
| 799 | sizeof(*audio_mode), &audio_mode->send_hdr); |
| 800 | if (res < 0) |
| 801 | return res; |
| 802 | |
| 803 | res = get_status(audio_mode); |
| 804 | if (res) |
| 805 | printk(KERN_ERR "PS3AV_CID_AUDIO_MODE: failed %x\n", res); |
| 806 | |
| 807 | return res; |
| 808 | } |
| 809 | |
| 810 | int ps3av_cmd_audio_mute(int num_of_port, u32 *port, u32 mute) |
| 811 | { |
| 812 | int i, res; |
| 813 | struct ps3av_pkt_audio_mute audio_mute; |
| 814 | |
| 815 | if (num_of_port > PS3AV_OPT_PORT_MAX) |
| 816 | return -EINVAL; |
| 817 | |
| 818 | /* audio mute */ |
| 819 | memset(&audio_mute, 0, sizeof(audio_mute)); |
| 820 | for (i = 0; i < num_of_port; i++) { |
| 821 | audio_mute.mute[i].avport = port[i]; |
| 822 | audio_mute.mute[i].mute = mute; |
| 823 | } |
| 824 | |
| 825 | res = ps3av_do_pkt(PS3AV_CID_AUDIO_MUTE, |
| 826 | sizeof(audio_mute.send_hdr) + |
| 827 | sizeof(struct ps3av_audio_mute) * num_of_port, |
| 828 | sizeof(audio_mute), &audio_mute.send_hdr); |
| 829 | if (res < 0) |
| 830 | return res; |
| 831 | |
| 832 | res = get_status(&audio_mute); |
| 833 | if (res) |
| 834 | printk(KERN_ERR "PS3AV_CID_AUDIO_MUTE: failed %x\n", res); |
| 835 | |
| 836 | return res; |
| 837 | } |
| 838 | |
| 839 | int ps3av_cmd_audio_active(int active, u32 port) |
| 840 | { |
| 841 | int res; |
| 842 | struct ps3av_pkt_audio_active audio_active; |
| 843 | u32 cid; |
| 844 | |
| 845 | /* audio active */ |
| 846 | memset(&audio_active, 0, sizeof(audio_active)); |
| 847 | audio_active.audio_port = port; |
| 848 | cid = active ? PS3AV_CID_AUDIO_ACTIVE : PS3AV_CID_AUDIO_INACTIVE; |
| 849 | |
| 850 | res = ps3av_do_pkt(cid, sizeof(audio_active), sizeof(audio_active), |
| 851 | &audio_active.send_hdr); |
| 852 | if (res < 0) |
| 853 | return res; |
| 854 | |
| 855 | res = get_status(&audio_active); |
| 856 | if (res) |
| 857 | printk(KERN_ERR "PS3AV_CID_AUDIO_ACTIVE:%x failed %x\n", cid, |
| 858 | res); |
| 859 | |
| 860 | return res; |
| 861 | } |
| 862 | |
| 863 | int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len) |
| 864 | { |
| 865 | int res; |
| 866 | |
Geert Uytterhoeven | 9b82f3e | 2008-10-30 08:12:58 +0000 | [diff] [blame] | 867 | mutex_lock(&ps3_gpu_mutex); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 868 | |
Geert Uytterhoeven | 0465f790 | 2007-02-12 00:55:25 -0800 | [diff] [blame] | 869 | /* avb packet */ |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 870 | res = ps3av_do_pkt(PS3AV_CID_AVB_PARAM, send_len, sizeof(*avb), |
| 871 | &avb->send_hdr); |
| 872 | if (res < 0) |
| 873 | goto out; |
| 874 | |
| 875 | res = get_status(avb); |
| 876 | if (res) |
Geert Uytterhoeven | 253f04e | 2007-05-02 14:48:38 +0200 | [diff] [blame] | 877 | pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __func__, |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 878 | res); |
| 879 | |
| 880 | out: |
Geert Uytterhoeven | 9b82f3e | 2008-10-30 08:12:58 +0000 | [diff] [blame] | 881 | mutex_unlock(&ps3_gpu_mutex); |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 882 | return res; |
| 883 | } |
| 884 | |
| 885 | int ps3av_cmd_av_get_hw_conf(struct ps3av_pkt_av_get_hw_conf *hw_conf) |
| 886 | { |
| 887 | int res; |
| 888 | |
| 889 | memset(hw_conf, 0, sizeof(*hw_conf)); |
| 890 | |
| 891 | res = ps3av_do_pkt(PS3AV_CID_AV_GET_HW_CONF, sizeof(hw_conf->send_hdr), |
| 892 | sizeof(*hw_conf), &hw_conf->send_hdr); |
| 893 | if (res < 0) |
| 894 | return res; |
| 895 | |
| 896 | res = get_status(hw_conf); |
| 897 | if (res) |
| 898 | printk(KERN_ERR "PS3AV_CID_AV_GET_HW_CONF: failed %x\n", res); |
| 899 | |
| 900 | return res; |
| 901 | } |
| 902 | |
| 903 | int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *info, |
| 904 | u32 avport) |
| 905 | { |
| 906 | int res; |
| 907 | |
| 908 | memset(info, 0, sizeof(*info)); |
| 909 | info->avport = avport; |
| 910 | |
| 911 | res = ps3av_do_pkt(PS3AV_CID_AV_GET_MONITOR_INFO, |
| 912 | sizeof(info->send_hdr) + sizeof(info->avport) + |
| 913 | sizeof(info->reserved), |
| 914 | sizeof(*info), &info->send_hdr); |
| 915 | if (res < 0) |
| 916 | return res; |
| 917 | |
| 918 | res = get_status(info); |
| 919 | if (res) |
| 920 | printk(KERN_ERR "PS3AV_CID_AV_GET_MONITOR_INFO: failed %x\n", |
| 921 | res); |
| 922 | |
| 923 | return res; |
| 924 | } |
| 925 | |
Geert Uytterhoeven | 11227fd | 2007-02-12 00:55:16 -0800 | [diff] [blame] | 926 | #define PS3AV_AV_LAYOUT_0 (PS3AV_CMD_AV_LAYOUT_32 \ |
| 927 | | PS3AV_CMD_AV_LAYOUT_44 \ |
| 928 | | PS3AV_CMD_AV_LAYOUT_48) |
| 929 | |
| 930 | #define PS3AV_AV_LAYOUT_1 (PS3AV_AV_LAYOUT_0 \ |
| 931 | | PS3AV_CMD_AV_LAYOUT_88 \ |
| 932 | | PS3AV_CMD_AV_LAYOUT_96 \ |
| 933 | | PS3AV_CMD_AV_LAYOUT_176 \ |
| 934 | | PS3AV_CMD_AV_LAYOUT_192) |
| 935 | |