ps3av_cmd.c 24 KB

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