2 * Copyright (C) 2006 Sony Computer Entertainment Inc.
3 * Copyright 2006, 2007 Sony Corporation
5 * AV backend support for PS3
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.
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.
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.
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/delay.h>
24 #include <asm/ps3av.h>
25 #include <asm/ps3fb.h>
30 static const struct video_fmt {
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 },
42 } ps3av_cs_video2av_table[] = {
44 .cs = PS3AV_CMD_VIDEO_CS_RGB_8,
45 .av = PS3AV_CMD_AV_CS_RGB_8,
46 .bl = PS3AV_CMD_AV_CS_8
48 .cs = PS3AV_CMD_VIDEO_CS_RGB_10,
49 .av = PS3AV_CMD_AV_CS_RGB_8,
50 .bl = PS3AV_CMD_AV_CS_8
52 .cs = PS3AV_CMD_VIDEO_CS_RGB_12,
53 .av = PS3AV_CMD_AV_CS_RGB_8,
54 .bl = PS3AV_CMD_AV_CS_8
56 .cs = PS3AV_CMD_VIDEO_CS_YUV444_8,
57 .av = PS3AV_CMD_AV_CS_YUV444_8,
58 .bl = PS3AV_CMD_AV_CS_8
60 .cs = PS3AV_CMD_VIDEO_CS_YUV444_10,
61 .av = PS3AV_CMD_AV_CS_YUV444_8,
62 .bl = PS3AV_CMD_AV_CS_10
64 .cs = PS3AV_CMD_VIDEO_CS_YUV444_12,
65 .av = PS3AV_CMD_AV_CS_YUV444_8,
66 .bl = PS3AV_CMD_AV_CS_10
68 .cs = PS3AV_CMD_VIDEO_CS_YUV422_8,
69 .av = PS3AV_CMD_AV_CS_YUV422_8,
70 .bl = PS3AV_CMD_AV_CS_10
72 .cs = PS3AV_CMD_VIDEO_CS_YUV422_10,
73 .av = PS3AV_CMD_AV_CS_YUV422_8,
74 .bl = PS3AV_CMD_AV_CS_10
76 .cs = PS3AV_CMD_VIDEO_CS_YUV422_12,
77 .av = PS3AV_CMD_AV_CS_YUV422_8,
78 .bl = PS3AV_CMD_AV_CS_12
80 .cs = PS3AV_CMD_VIDEO_CS_XVYCC_8,
81 .av = PS3AV_CMD_AV_CS_XVYCC_8,
82 .bl = PS3AV_CMD_AV_CS_12
84 .cs = PS3AV_CMD_VIDEO_CS_XVYCC_10,
85 .av = PS3AV_CMD_AV_CS_XVYCC_8,
86 .bl = PS3AV_CMD_AV_CS_12
88 .cs = PS3AV_CMD_VIDEO_CS_XVYCC_12,
89 .av = PS3AV_CMD_AV_CS_XVYCC_8,
90 .bl = PS3AV_CMD_AV_CS_12
94 static u32 ps3av_cs_video2av(int cs)
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;
102 return PS3AV_CMD_AV_CS_RGB_8;
105 static u32 ps3av_cs_video2av_bitlen(int cs)
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;
113 return PS3AV_CMD_AV_CS_8;
116 static const struct {
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 }
135 static u32 ps3av_vid_video2av(int vid)
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;
143 return PS3AV_CMD_AV_VID_480P;
146 static int ps3av_hdmi_range(void)
148 if (ps3_compare_firmware_version(1, 8, 0) < 0)
151 return 1; /* supported */
154 int ps3av_cmd_init(void)
157 struct ps3av_pkt_av_init av_init;
158 struct ps3av_pkt_video_init video_init;
159 struct ps3av_pkt_audio_init audio_init;
162 memset(&video_init, 0, sizeof(video_init));
164 res = ps3av_do_pkt(PS3AV_CID_VIDEO_INIT, sizeof(video_init.send_hdr),
165 sizeof(video_init), &video_init.send_hdr);
169 res = get_status(&video_init);
171 printk(KERN_ERR "PS3AV_CID_VIDEO_INIT: failed %x\n", res);
176 memset(&audio_init, 0, sizeof(audio_init));
178 res = ps3av_do_pkt(PS3AV_CID_AUDIO_INIT, sizeof(audio_init.send_hdr),
179 sizeof(audio_init), &audio_init.send_hdr);
183 res = get_status(&audio_init);
185 printk(KERN_ERR "PS3AV_CID_AUDIO_INIT: failed %x\n", res);
190 memset(&av_init, 0, sizeof(av_init));
191 av_init.event_bit = 0;
193 res = ps3av_do_pkt(PS3AV_CID_AV_INIT, sizeof(av_init), sizeof(av_init),
198 res = get_status(&av_init);
200 printk(KERN_ERR "PS3AV_CID_AV_INIT: failed %x\n", res);
205 int ps3av_cmd_fin(void)
208 struct ps3av_pkt_av_fin av_fin;
210 memset(&av_fin, 0, sizeof(av_fin));
212 res = ps3av_do_pkt(PS3AV_CID_AV_FIN, sizeof(av_fin.send_hdr),
213 sizeof(av_fin), &av_fin.send_hdr);
217 res = get_status(&av_fin);
219 printk(KERN_ERR "PS3AV_CID_AV_FIN: failed %x\n", res);
224 int ps3av_cmd_av_video_mute(int num_of_port, u32 *port, u32 mute)
226 int i, send_len, res;
227 struct ps3av_pkt_av_video_mute av_video_mute;
229 if (num_of_port > PS3AV_MUTE_PORT_MAX)
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;
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);
245 res = get_status(&av_video_mute);
247 printk(KERN_ERR "PS3AV_CID_AV_VIDEO_MUTE: failed %x\n", res);
252 int ps3av_cmd_av_video_disable_sig(u32 port)
255 struct ps3av_pkt_av_video_disable_sig av_video_sig;
257 memset(&av_video_sig, 0, sizeof(av_video_sig));
258 av_video_sig.avport = port;
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);
266 res = get_status(&av_video_sig);
269 "PS3AV_CID_AV_VIDEO_DISABLE_SIG: failed %x port:%x\n",
275 int ps3av_cmd_av_tv_mute(u32 avport, u32 mute)
278 struct ps3av_pkt_av_tv_mute tv_mute;
280 memset(&tv_mute, 0, sizeof(tv_mute));
281 tv_mute.avport = avport;
284 res = ps3av_do_pkt(PS3AV_CID_AV_TV_MUTE, sizeof(tv_mute),
285 sizeof(tv_mute), &tv_mute.send_hdr);
289 res = get_status(&tv_mute);
291 printk(KERN_ERR "PS3AV_CID_AV_TV_MUTE: failed %x port:%x\n",
297 int ps3av_cmd_enable_event(void)
300 struct ps3av_pkt_av_event av_event;
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;
306 res = ps3av_do_pkt(PS3AV_CID_AV_ENABLE_EVENT, sizeof(av_event),
307 sizeof(av_event), &av_event.send_hdr);
311 res = get_status(&av_event);
313 printk(KERN_ERR "PS3AV_CID_AV_ENABLE_EVENT: failed %x\n", res);
318 int ps3av_cmd_av_hdmi_mode(u8 mode)
321 struct ps3av_pkt_av_hdmi_mode hdmi_mode;
323 memset(&hdmi_mode, 0, sizeof(hdmi_mode));
324 hdmi_mode.mode = mode;
326 res = ps3av_do_pkt(PS3AV_CID_AV_HDMI_MODE, sizeof(hdmi_mode),
327 sizeof(hdmi_mode), &hdmi_mode.send_hdr);
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);
338 u32 ps3av_cmd_set_av_video_cs(void *p, u32 avport, int video_vid, int cs_out,
341 struct ps3av_pkt_av_video_cs *av_video_cs;
343 av_video_cs = (struct ps3av_pkt_av_video_cs *)p;
345 video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
347 cs_out = PS3AV_CMD_VIDEO_CS_YUV444_8;
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);
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;
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;
371 av_video_cs->dither = PS3AV_CMD_AV_DITHER_OFF;
374 return sizeof(*av_video_cs);
377 u32 ps3av_cmd_set_video_mode(void *p, u32 head, int video_vid, int video_fmt,
380 struct ps3av_pkt_video_mode *video_mode;
383 video_mode = (struct ps3av_pkt_video_mode *)p;
385 video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
387 video_fmt = PS3AV_CMD_VIDEO_FMT_X8R8G8B8;
389 if (ps3av_video_mode2res(id, &x, &y))
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;
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;
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;
411 video_mode->video_order = ps3av_video_fmt_table[video_fmt].order;
413 pr_debug("%s: video_mode:vid:%x width:%d height:%d pitch:%d out_format:%d format:%x order:%x\n",
414 __func__, video_vid, video_mode->width, video_mode->height,
415 video_mode->pitch, video_mode->video_out_format,
416 video_mode->video_format, video_mode->video_order);
417 return sizeof(*video_mode);
420 int ps3av_cmd_video_format_black(u32 head, u32 video_fmt, u32 mute)
423 struct ps3av_pkt_video_format video_format;
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;
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;
434 res = ps3av_do_pkt(PS3AV_CID_VIDEO_FORMAT, sizeof(video_format),
435 sizeof(video_format), &video_format.send_hdr);
439 res = get_status(&video_format);
441 printk(KERN_ERR "PS3AV_CID_VIDEO_FORMAT: failed %x\n", res);
447 int ps3av_cmd_av_audio_mute(int num_of_port, u32 *port, u32 mute)
450 struct ps3av_pkt_av_audio_mute av_audio_mute;
452 if (num_of_port > PS3AV_MUTE_PORT_MAX)
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;
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);
469 res = get_status(&av_audio_mute);
471 printk(KERN_ERR "PS3AV_CID_AV_AUDIO_MUTE: failed %x\n", res);
476 static const struct {
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 }
488 static u8 ps3av_cnv_mclk(u32 fs)
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;
496 printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs);
500 #define BASE PS3AV_CMD_AUDIO_FS_44K
502 static const u32 ps3av_ns_table[][5] = {
503 /* D1, D2, D3, D4, D5 */
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 }
512 static void ps3av_cnv_ns(u8 *ns, u32 fs, u32 video_vid)
519 av_vid = ps3av_vid_video2av(video_vid);
521 case PS3AV_CMD_AV_VID_480I:
522 case PS3AV_CMD_AV_VID_576I:
525 case PS3AV_CMD_AV_VID_480P:
526 case PS3AV_CMD_AV_VID_576P:
529 case PS3AV_CMD_AV_VID_1080I_60HZ:
530 case PS3AV_CMD_AV_VID_1080I_50HZ:
533 case PS3AV_CMD_AV_VID_720P_60HZ:
534 case PS3AV_CMD_AV_VID_720P_50HZ:
537 case PS3AV_CMD_AV_VID_1080P_60HZ:
538 case PS3AV_CMD_AV_VID_1080P_50HZ:
539 case PS3AV_CMD_AV_VID_WXGA:
540 case PS3AV_CMD_AV_VID_SXGA:
541 case PS3AV_CMD_AV_VID_WUXGA:
545 printk(KERN_ERR "%s failed, vid:%x\n", __func__, video_vid);
549 if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K)
550 printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs);
552 ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d];
554 *p++ = ns_val & 0x000000FF;
555 *p++ = (ns_val & 0x0000FF00) >> 8;
556 *p = (ns_val & 0x00FF0000) >> 16;
561 static u8 ps3av_cnv_enable(u32 source, const u8 *enable)
566 if (source == PS3AV_CMD_AUDIO_SOURCE_SPDIF) {
568 } else if (source == PS3AV_CMD_AUDIO_SOURCE_SERIAL) {
570 ret = ((p[0] << 4) + (p[1] << 5) + (p[2] << 6) + (p[3] << 7)) |
573 printk(KERN_ERR "%s failed, source:%x\n", __func__, source);
577 static u8 ps3av_cnv_fifomap(const u8 *map)
583 ret = p[0] + (p[1] << 2) + (p[2] << 4) + (p[3] << 6);
587 static u8 ps3av_cnv_inputlen(u32 word_bits)
592 case PS3AV_CMD_AUDIO_WORD_BITS_16:
593 ret = PS3AV_CMD_AV_INPUTLEN_16;
595 case PS3AV_CMD_AUDIO_WORD_BITS_20:
596 ret = PS3AV_CMD_AV_INPUTLEN_20;
598 case PS3AV_CMD_AUDIO_WORD_BITS_24:
599 ret = PS3AV_CMD_AV_INPUTLEN_24;
602 printk(KERN_ERR "%s failed, word_bits:%x\n", __func__,
609 static u8 ps3av_cnv_layout(u32 num_of_ch)
611 if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) {
612 printk(KERN_ERR "%s failed, num_of_ch:%x\n", __func__,
617 return num_of_ch == PS3AV_CMD_AUDIO_NUM_OF_CH_2 ? 0x0 : 0x1;
620 static void ps3av_cnv_info(struct ps3av_audio_info_frame *info,
621 const struct ps3av_pkt_audio_mode *mode)
623 info->pb1.cc = mode->audio_num_of_ch + 1; /* CH2:0x01 --- CH8:0x07 */
628 info->pb3 = 0; /* check mode->audio_format ?? */
629 info->pb4 = mode->audio_layout;
630 info->pb5.dm = mode->audio_downmix;
631 info->pb5.lsv = mode->audio_downmix_level;
634 static void ps3av_cnv_chstat(u8 *chstat, const u8 *cs_info)
636 memcpy(chstat, cs_info, 5);
639 u32 ps3av_cmd_set_av_audio_param(void *p, u32 port,
640 const struct ps3av_pkt_audio_mode *audio_mode,
643 struct ps3av_pkt_av_audio_param *param;
645 param = (struct ps3av_pkt_av_audio_param *)p;
647 memset(param, 0, sizeof(*param));
648 ps3av_set_hdr(PS3AV_CID_AV_AUDIO_PARAM, sizeof(*param),
651 param->avport = port;
652 param->mclk = ps3av_cnv_mclk(audio_mode->audio_fs) | 0x80;
653 ps3av_cnv_ns(param->ns, audio_mode->audio_fs, video_vid);
654 param->enable = ps3av_cnv_enable(audio_mode->audio_source,
655 audio_mode->audio_enable);
656 param->swaplr = 0x09;
657 param->fifomap = ps3av_cnv_fifomap(audio_mode->audio_map);
658 param->inputctrl = 0x49;
659 param->inputlen = ps3av_cnv_inputlen(audio_mode->audio_word_bits);
660 param->layout = ps3av_cnv_layout(audio_mode->audio_num_of_ch);
661 ps3av_cnv_info(¶m->info, audio_mode);
662 ps3av_cnv_chstat(param->chstat, audio_mode->audio_cs_info);
664 return sizeof(*param);
668 static const u8 ps3av_mode_cs_info[] = {
669 0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00
681 void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport,
682 u32 ch, u32 fs, u32 word_bits, u32 format,
685 int spdif_through, spdif_bitstream;
688 if (!(ch | fs | format | word_bits | source)) {
689 ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2;
690 fs = PS3AV_CMD_AUDIO_FS_48K;
691 word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
692 format = PS3AV_CMD_AUDIO_FORMAT_PCM;
693 source = PS3AV_CMD_AUDIO_SOURCE_SERIAL;
695 spdif_through = spdif_bitstream = 0; /* XXX not supported */
698 memset(audio, 0, sizeof(*audio));
699 ps3av_set_hdr(PS3AV_CID_AUDIO_MODE, sizeof(*audio), &audio->send_hdr);
701 audio->avport = (u8) avport;
702 audio->mask = 0x0FFF; /* XXX set all */
703 audio->audio_num_of_ch = ch;
704 audio->audio_fs = fs;
705 audio->audio_word_bits = word_bits;
706 audio->audio_format = format;
707 audio->audio_source = source;
710 case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
711 audio->audio_enable[3] = 1;
713 case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
714 audio->audio_enable[2] = 1;
715 audio->audio_enable[1] = 1;
717 case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
719 audio->audio_enable[0] = 1;
723 for (i = 0; i < 4; i++)
724 audio->audio_swap[i] = PS3AV_CMD_AUDIO_SWAP_0; /* no swap */
726 /* audio serial input mapping */
727 audio->audio_map[0] = PS3AV_CMD_AUDIO_MAP_OUTPUT_0;
728 audio->audio_map[1] = PS3AV_CMD_AUDIO_MAP_OUTPUT_1;
729 audio->audio_map[2] = PS3AV_CMD_AUDIO_MAP_OUTPUT_2;
730 audio->audio_map[3] = PS3AV_CMD_AUDIO_MAP_OUTPUT_3;
732 /* audio speaker layout */
733 if (avport == PS3AV_CMD_AVPORT_HDMI_0 ||
734 avport == PS3AV_CMD_AVPORT_HDMI_1) {
736 case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
737 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_8CH;
739 case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
740 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_6CH;
742 case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
744 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
748 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
751 /* audio downmix permission */
752 audio->audio_downmix = PS3AV_CMD_AUDIO_DOWNMIX_PERMITTED;
753 /* audio downmix level shift (0:0dB to 15:15dB) */
754 audio->audio_downmix_level = 0; /* 0dB */
757 for (i = 0; i < 8; i++)
758 audio->audio_cs_info[i] = ps3av_mode_cs_info[i];
761 case PS3AV_CMD_AUDIO_FS_44K:
762 audio->audio_cs_info[3] &= ~CS_MASK;
763 audio->audio_cs_info[3] |= CS_44;
765 case PS3AV_CMD_AUDIO_FS_88K:
766 audio->audio_cs_info[3] &= ~CS_MASK;
767 audio->audio_cs_info[3] |= CS_88;
769 case PS3AV_CMD_AUDIO_FS_96K:
770 audio->audio_cs_info[3] &= ~CS_MASK;
771 audio->audio_cs_info[3] |= CS_96;
773 case PS3AV_CMD_AUDIO_FS_176K:
774 audio->audio_cs_info[3] &= ~CS_MASK;
775 audio->audio_cs_info[3] |= CS_176;
777 case PS3AV_CMD_AUDIO_FS_192K:
778 audio->audio_cs_info[3] &= ~CS_MASK;
779 audio->audio_cs_info[3] |= CS_192;
785 /* pass through setting */
787 (avport == PS3AV_CMD_AVPORT_SPDIF_0 ||
788 avport == PS3AV_CMD_AVPORT_SPDIF_1)) {
789 audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
790 audio->audio_source = PS3AV_CMD_AUDIO_SOURCE_SPDIF;
791 if (spdif_bitstream) {
792 audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM;
793 audio->audio_cs_info[0] |= CS_BIT;
798 int ps3av_cmd_audio_mode(struct ps3av_pkt_audio_mode *audio_mode)
802 res = ps3av_do_pkt(PS3AV_CID_AUDIO_MODE, sizeof(*audio_mode),
803 sizeof(*audio_mode), &audio_mode->send_hdr);
807 res = get_status(audio_mode);
809 printk(KERN_ERR "PS3AV_CID_AUDIO_MODE: failed %x\n", res);
814 int ps3av_cmd_audio_mute(int num_of_port, u32 *port, u32 mute)
817 struct ps3av_pkt_audio_mute audio_mute;
819 if (num_of_port > PS3AV_OPT_PORT_MAX)
823 memset(&audio_mute, 0, sizeof(audio_mute));
824 for (i = 0; i < num_of_port; i++) {
825 audio_mute.mute[i].avport = port[i];
826 audio_mute.mute[i].mute = mute;
829 res = ps3av_do_pkt(PS3AV_CID_AUDIO_MUTE,
830 sizeof(audio_mute.send_hdr) +
831 sizeof(struct ps3av_audio_mute) * num_of_port,
832 sizeof(audio_mute), &audio_mute.send_hdr);
836 res = get_status(&audio_mute);
838 printk(KERN_ERR "PS3AV_CID_AUDIO_MUTE: failed %x\n", res);
843 int ps3av_cmd_audio_active(int active, u32 port)
846 struct ps3av_pkt_audio_active audio_active;
850 memset(&audio_active, 0, sizeof(audio_active));
851 audio_active.audio_port = port;
852 cid = active ? PS3AV_CID_AUDIO_ACTIVE : PS3AV_CID_AUDIO_INACTIVE;
854 res = ps3av_do_pkt(cid, sizeof(audio_active), sizeof(audio_active),
855 &audio_active.send_hdr);
859 res = get_status(&audio_active);
861 printk(KERN_ERR "PS3AV_CID_AUDIO_ACTIVE:%x failed %x\n", cid,
867 int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
871 ps3av_flip_ctl(0); /* flip off */
874 res = ps3av_do_pkt(PS3AV_CID_AVB_PARAM, send_len, sizeof(*avb),
879 res = get_status(avb);
881 pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __func__,
885 ps3av_flip_ctl(1); /* flip on */
889 int ps3av_cmd_av_get_hw_conf(struct ps3av_pkt_av_get_hw_conf *hw_conf)
893 memset(hw_conf, 0, sizeof(*hw_conf));
895 res = ps3av_do_pkt(PS3AV_CID_AV_GET_HW_CONF, sizeof(hw_conf->send_hdr),
896 sizeof(*hw_conf), &hw_conf->send_hdr);
900 res = get_status(hw_conf);
902 printk(KERN_ERR "PS3AV_CID_AV_GET_HW_CONF: failed %x\n", res);
907 int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *info,
912 memset(info, 0, sizeof(*info));
913 info->avport = avport;
915 res = ps3av_do_pkt(PS3AV_CID_AV_GET_MONITOR_INFO,
916 sizeof(info->send_hdr) + sizeof(info->avport) +
917 sizeof(info->reserved),
918 sizeof(*info), &info->send_hdr);
922 res = get_status(info);
924 printk(KERN_ERR "PS3AV_CID_AV_GET_MONITOR_INFO: failed %x\n",
931 void ps3av_cmd_av_hw_conf_dump(const struct ps3av_pkt_av_get_hw_conf *hw_conf)
933 printk("av_h_conf:num of hdmi:%d\n", hw_conf->num_of_hdmi);
934 printk("av_h_conf:num of avmulti:%d\n", hw_conf->num_of_avmulti);
935 printk("av_h_conf:num of spdif:%d\n", hw_conf->num_of_spdif);
938 void ps3av_cmd_av_monitor_info_dump(const struct ps3av_pkt_av_get_monitor_info *monitor_info)
940 const struct ps3av_info_monitor *info = &monitor_info->info;
941 const struct ps3av_info_audio *audio = info->audio;
944 printk("Monitor Info: size%d\n", monitor_info->send_hdr.size);
946 printk("avport:%02x\n", info->avport);
947 printk("monitor_id:");
948 for (i = 0; i < 10; i++)
949 printk("%02x ", info->monitor_id[i]);
950 printk("\nmonitor_type:%02x\n", info->monitor_type);
951 printk("monitor_name:");
952 for (i = 0; i < 16; i++)
953 printk("%c", info->monitor_name[i]);
956 printk("\nresolution_60: bits:%08x native:%08x\n",
957 info->res_60.res_bits, info->res_60.native);
958 printk("resolution_50: bits:%08x native:%08x\n",
959 info->res_50.res_bits, info->res_50.native);
960 printk("resolution_other: bits:%08x native:%08x\n",
961 info->res_other.res_bits, info->res_other.native);
962 printk("resolution_vesa: bits:%08x native:%08x\n",
963 info->res_vesa.res_bits, info->res_vesa.native);
966 printk("color space rgb:%02x\n", info->cs.rgb);
967 printk("color space yuv444:%02x\n", info->cs.yuv444);
968 printk("color space yuv422:%02x\n", info->cs.yuv422);
971 printk("color info red:X %04x Y %04x\n",
972 info->color.red_x, info->color.red_y);
973 printk("color info green:X %04x Y %04x\n",
974 info->color.green_x, info->color.green_y);
975 printk("color info blue:X %04x Y %04x\n",
976 info->color.blue_x, info->color.blue_y);
977 printk("color info white:X %04x Y %04x\n",
978 info->color.white_x, info->color.white_y);
979 printk("color info gamma: %08x\n", info->color.gamma);
982 printk("supported_AI:%02x\n", info->supported_ai);
983 printk("speaker_info:%02x\n", info->speaker_info);
984 printk("num of audio:%02x\n", info->num_of_audio_block);
987 for (i = 0; i < info->num_of_audio_block; i++) {
988 printk("audio[%d] type:%02x max_ch:%02x fs:%02x sbit:%02x\n",
989 i, audio->type, audio->max_num_of_ch, audio->fs,
994 #endif /* PS3AV_DEBUG */
996 #define PS3AV_AV_LAYOUT_0 (PS3AV_CMD_AV_LAYOUT_32 \
997 | PS3AV_CMD_AV_LAYOUT_44 \
998 | PS3AV_CMD_AV_LAYOUT_48)
1000 #define PS3AV_AV_LAYOUT_1 (PS3AV_AV_LAYOUT_0 \
1001 | PS3AV_CMD_AV_LAYOUT_88 \
1002 | PS3AV_CMD_AV_LAYOUT_96 \
1003 | PS3AV_CMD_AV_LAYOUT_176 \
1004 | PS3AV_CMD_AV_LAYOUT_192)